1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 #ifndef DBAUI_JOINEXCHANGE_HXX
31 #include "JoinExchange.hxx"
32 #endif
33 #ifndef _SOT_FORMATS_HXX
34 #include <sot/formats.hxx>
35 #endif
36 #ifndef _SVX_DBEXCH_HRC
37 #include <svx/dbexch.hrc>
38 #endif
39 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
40 #include <cppuhelper/typeprovider.hxx>
41 #endif
42 #ifndef _SOT_FORMATS_HXX
43 #include <sot/formats.hxx>
44 #endif
45 
46 namespace dbaui
47 {
48 	using namespace ::com::sun::star::uno;
49 	using namespace ::com::sun::star::util;
50 	using namespace ::com::sun::star::lang;
51 	using namespace ::com::sun::star::datatransfer;
52 
53 	String OJoinExchObj::m_sJoinFormat;
54 	//==================================================================
55 	// class OJoinExchObj
56 	//==================================================================
57 	DBG_NAME(OJoinExchObj)
58 	//------------------------------------------------------------------------
59 	OJoinExchObj::OJoinExchObj(const OJoinExchangeData& jxdSource,sal_Bool _bFirstEntry)
60         :m_bFirstEntry(_bFirstEntry)
61 		,m_jxdSourceDescription(jxdSource)
62 		,m_pDragListener(NULL)
63 	{
64 		DBG_CTOR(OJoinExchObj,NULL);
65 		// Verfuegbare Typen in Liste einfuegen
66 	}
67 
68 	//------------------------------------------------------------------------
69 	OJoinExchObj::~OJoinExchObj()
70 	{
71 		DBG_DTOR(OJoinExchObj,NULL);
72 	}
73 
74 	//------------------------------------------------------------------------
75 	void OJoinExchObj::StartDrag( Window* _pWindow, sal_Int8 _nDragSourceActions, IDragTransferableListener* _pListener )
76 	{
77 		m_pDragListener = _pListener;
78 		TransferableHelper::StartDrag(_pWindow, _nDragSourceActions);
79 	}
80 
81 	//------------------------------------------------------------------------
82 	void OJoinExchObj::DragFinished( sal_Int8 /*nDropAction*/ )
83 	{
84 		if (m_pDragListener)
85 			m_pDragListener->dragFinished();
86 		m_pDragListener = NULL;
87 	}
88 
89 	//------------------------------------------------------------------------
90 	sal_Bool OJoinExchObj::isFormatAvailable( const DataFlavorExVector& _rFormats ,SotFormatStringId _nSlotID)
91 	{
92         DataFlavorExVector::const_iterator aCheckEnd = _rFormats.end();
93 		for	(	DataFlavorExVector::const_iterator aCheck = _rFormats.begin();
94 				aCheck != aCheckEnd;
95 				++aCheck
96 			)
97 		{
98 			if ( _nSlotID == aCheck->mnSotId )
99 				return sal_True;
100 		}
101 		return sal_False;
102 	}
103 
104 	//------------------------------------------------------------------------
105 	OJoinExchangeData OJoinExchObj::GetSourceDescription(const Reference< XTransferable >& _rxObject)
106 	{
107 		OJoinExchangeData aReturn;
108 		Reference< XUnoTunnel > xTunnel(_rxObject, UNO_QUERY);
109 		if (xTunnel.is())
110 		{
111 			OJoinExchObj* pImplementation = reinterpret_cast<OJoinExchObj*>(xTunnel->getSomething(getUnoTunnelImplementationId()));
112 			if (pImplementation)
113 				aReturn = pImplementation->m_jxdSourceDescription;
114 		}
115 		return aReturn;
116 	}
117 
118 	//------------------------------------------------------------------------
119 	Sequence< sal_Int8 > OJoinExchObj::getUnoTunnelImplementationId()
120 	{
121 		static ::cppu::OImplementationId * pId = 0;
122 		if (! pId)
123 		{
124 			::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
125 			if (! pId)
126 			{
127 				static ::cppu::OImplementationId aId;
128 				pId = &aId;
129 			}
130 		}
131 		return pId->getImplementationId();
132 	}
133 
134 	//------------------------------------------------------------------------
135     sal_Int64 SAL_CALL OJoinExchObj::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
136 	{
137 		if (_rIdentifier.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  _rIdentifier.getConstArray(), 16 ) )
138 			return reinterpret_cast<sal_Int64>(this);
139 
140 		return 0;
141 	}
142 
143 	//------------------------------------------------------------------------
144 	void OJoinExchObj::AddSupportedFormats()
145 	{
146 		AddFormat( SOT_FORMATSTR_ID_SBA_JOIN );
147 		if ( m_bFirstEntry )
148 			AddFormat( SOT_FORMATSTR_ID_SBA_TABID );
149 	}
150 
151 	//------------------------------------------------------------------------
152 	sal_Bool OJoinExchObj::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
153 	{
154 		sal_uInt32 nFormat = SotExchange::GetFormat(rFlavor);
155 		if ( SOT_FORMATSTR_ID_SBA_JOIN == nFormat )
156 			// this is a HACK
157 			// we don't really copy our data, the instances using us have to call GetSourceDescription ....
158 			// if, one day, we have a _lot_ of time, this hack should be removed ....
159 			return sal_True;
160 
161 		return sal_False;
162 	}
163 
164 	//------------------------------------------------------------------------
165 	Any SAL_CALL OJoinExchObj::queryInterface( const Type& _rType ) throw(RuntimeException)
166 	{
167 		Any aReturn = TransferableHelper::queryInterface(_rType);
168 		if (!aReturn.hasValue())
169 			aReturn = OJoinExchObj_Base::queryInterface(_rType);
170 		return aReturn;
171 	}
172 
173 	//------------------------------------------------------------------------
174 	void SAL_CALL OJoinExchObj::acquire(  ) throw()
175 	{
176 		TransferableHelper::acquire( );
177 	}
178 
179 	//------------------------------------------------------------------------
180 	void SAL_CALL OJoinExchObj::release(  ) throw()
181 	{
182 		TransferableHelper::release( );
183 	}
184 
185 
186 }	// namespace dbaui
187