xref: /aoo42x/main/svx/source/form/fmexch.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir #include "fmexch.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <sot/storage.hxx>
33*cdf0e10cSrcweir #include <svl/itempool.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #ifndef _SVX_DBEXCH_HRC
36*cdf0e10cSrcweir #include <svx/dbexch.hrc>
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #include <sot/formats.hxx>
39*cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
40*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #define _SVSTDARR_ULONGS
43*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //........................................................................
46*cdf0e10cSrcweir namespace svxform
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir //........................................................................
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
51*cdf0e10cSrcweir 	using namespace ::com::sun::star::datatransfer;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 	//====================================================================
54*cdf0e10cSrcweir 	//= OLocalExchange
55*cdf0e10cSrcweir 	//====================================================================
56*cdf0e10cSrcweir 	//--------------------------------------------------------------------
57*cdf0e10cSrcweir 	OLocalExchange::OLocalExchange( )
58*cdf0e10cSrcweir 		:m_bDragging( sal_False )
59*cdf0e10cSrcweir 		,m_bClipboardOwner( sal_False )
60*cdf0e10cSrcweir 	{
61*cdf0e10cSrcweir 	}
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	//--------------------------------------------------------------------
64*cdf0e10cSrcweir 	void OLocalExchange::copyToClipboard( Window* _pWindow, const GrantAccess& )
65*cdf0e10cSrcweir 	{
66*cdf0e10cSrcweir 		if ( m_bClipboardOwner )
67*cdf0e10cSrcweir 		{	// simulate a lostOwnership to notify parties interested in
68*cdf0e10cSrcweir 			if ( m_aClipboardListener.IsSet() )
69*cdf0e10cSrcweir 				m_aClipboardListener.Call( this );
70*cdf0e10cSrcweir 		}
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 		m_bClipboardOwner = sal_True;
73*cdf0e10cSrcweir 		CopyToClipboard( _pWindow );
74*cdf0e10cSrcweir 	}
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	//--------------------------------------------------------------------
77*cdf0e10cSrcweir 	void OLocalExchange::clear()
78*cdf0e10cSrcweir 	{
79*cdf0e10cSrcweir 		if ( isClipboardOwner() )
80*cdf0e10cSrcweir 		{
81*cdf0e10cSrcweir 			try
82*cdf0e10cSrcweir 			{
83*cdf0e10cSrcweir 				Reference< clipboard::XClipboard > xClipBoard( getOwnClipboard() );
84*cdf0e10cSrcweir 				if ( xClipBoard.is() )
85*cdf0e10cSrcweir 					xClipBoard->setContents( NULL, NULL );
86*cdf0e10cSrcweir 			}
87*cdf0e10cSrcweir 			catch( const Exception& )
88*cdf0e10cSrcweir 			{
89*cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
90*cdf0e10cSrcweir 			}
91*cdf0e10cSrcweir 			m_bClipboardOwner = sal_False;
92*cdf0e10cSrcweir 		}
93*cdf0e10cSrcweir 	}
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	//--------------------------------------------------------------------
96*cdf0e10cSrcweir     void SAL_CALL OLocalExchange::lostOwnership( const Reference< clipboard::XClipboard >& _rxClipboard, const Reference< XTransferable >& _rxTrans ) throw(RuntimeException)
97*cdf0e10cSrcweir 	{
98*cdf0e10cSrcweir 		TransferableHelper::implCallOwnLostOwnership( _rxClipboard, _rxTrans );
99*cdf0e10cSrcweir 		m_bClipboardOwner = sal_False;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 		if ( m_aClipboardListener.IsSet() )
102*cdf0e10cSrcweir 			m_aClipboardListener.Call( this );
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	//--------------------------------------------------------------------
106*cdf0e10cSrcweir 	void OLocalExchange::startDrag( Window* _pWindow, sal_Int8 _nDragSourceActions, const GrantAccess& )
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir 		m_bDragging = sal_True;
109*cdf0e10cSrcweir 		StartDrag( _pWindow, _nDragSourceActions );
110*cdf0e10cSrcweir 	}
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	//--------------------------------------------------------------------
113*cdf0e10cSrcweir 	void OLocalExchange::DragFinished( sal_Int8 nDropAction )
114*cdf0e10cSrcweir 	{
115*cdf0e10cSrcweir 		TransferableHelper::DragFinished( nDropAction );
116*cdf0e10cSrcweir 		m_bDragging = sal_False;
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	//--------------------------------------------------------------------
120*cdf0e10cSrcweir 	sal_Bool OLocalExchange::hasFormat( const DataFlavorExVector& _rFormats, sal_uInt32 _nFormatId )
121*cdf0e10cSrcweir 	{
122*cdf0e10cSrcweir 		DataFlavorExVector::const_iterator aSearch;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 		for	( aSearch = _rFormats.begin(); aSearch != _rFormats.end(); ++aSearch )
125*cdf0e10cSrcweir 			if ( aSearch->mnSotId == _nFormatId )
126*cdf0e10cSrcweir 				break;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 		return aSearch != _rFormats.end();
129*cdf0e10cSrcweir 	}
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	//--------------------------------------------------------------------
132*cdf0e10cSrcweir 	sal_Bool OLocalExchange::GetData( const ::com::sun::star::datatransfer::DataFlavor& /*_rFlavor*/ )
133*cdf0e10cSrcweir 	{
134*cdf0e10cSrcweir 		return sal_False;	// do not have any formats by default
135*cdf0e10cSrcweir 	}
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	//====================================================================
138*cdf0e10cSrcweir 	//= OControlTransferData
139*cdf0e10cSrcweir 	//====================================================================
140*cdf0e10cSrcweir 	//--------------------------------------------------------------------
141*cdf0e10cSrcweir 	OControlTransferData::OControlTransferData( )
142*cdf0e10cSrcweir 		:m_pFocusEntry( NULL )
143*cdf0e10cSrcweir 	{
144*cdf0e10cSrcweir 	}
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	//--------------------------------------------------------------------
147*cdf0e10cSrcweir 	OControlTransferData::OControlTransferData( const Reference< XTransferable >& _rxTransferable )
148*cdf0e10cSrcweir 		:m_pFocusEntry( NULL )
149*cdf0e10cSrcweir 	{
150*cdf0e10cSrcweir 		TransferableDataHelper aExchangedData( _rxTransferable );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 		// try the formats we know
153*cdf0e10cSrcweir 		if ( OControlExchange::hasControlPathFormat( aExchangedData.GetDataFlavorExVector() ) )
154*cdf0e10cSrcweir 		{	// paths to the controls, relative to a root
155*cdf0e10cSrcweir 			Sequence< Any > aControlPathData;
156*cdf0e10cSrcweir 			if ( aExchangedData.GetAny( OControlExchange::getControlPathFormatId() ) >>= aControlPathData )
157*cdf0e10cSrcweir 			{
158*cdf0e10cSrcweir 				DBG_ASSERT( aControlPathData.getLength() >= 2, "OControlTransferData::OControlTransferData: invalid data for the control path format!" );
159*cdf0e10cSrcweir 				if ( aControlPathData.getLength() >= 2 )
160*cdf0e10cSrcweir 				{
161*cdf0e10cSrcweir 					aControlPathData[0] >>= m_xFormsRoot;
162*cdf0e10cSrcweir 					aControlPathData[1] >>= m_aControlPaths;
163*cdf0e10cSrcweir 				}
164*cdf0e10cSrcweir 			}
165*cdf0e10cSrcweir 			else
166*cdf0e10cSrcweir 			{
167*cdf0e10cSrcweir 				DBG_ERROR( "OControlTransferData::OControlTransferData: invalid data for the control path format (2)!" );
168*cdf0e10cSrcweir 			}
169*cdf0e10cSrcweir 		}
170*cdf0e10cSrcweir 		if ( OControlExchange::hasHiddenControlModelsFormat( aExchangedData.GetDataFlavorExVector() ) )
171*cdf0e10cSrcweir 		{	// sequence of models of hidden controls
172*cdf0e10cSrcweir 			aExchangedData.GetAny( OControlExchange::getHiddenControlModelsFormatId() ) >>= m_aHiddenControlModels;
173*cdf0e10cSrcweir 		}
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 		updateFormats( );
176*cdf0e10cSrcweir 	}
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	//--------------------------------------------------------------------
179*cdf0e10cSrcweir 	static sal_Bool lcl_fillDataFlavorEx( SotFormatStringId nId, DataFlavorEx& _rFlavor )
180*cdf0e10cSrcweir 	{
181*cdf0e10cSrcweir 		_rFlavor.mnSotId = nId;
182*cdf0e10cSrcweir 		return SotExchange::GetFormatDataFlavor( _rFlavor.mnSotId, _rFlavor );
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	//--------------------------------------------------------------------
186*cdf0e10cSrcweir 	void OControlTransferData::updateFormats( )
187*cdf0e10cSrcweir 	{
188*cdf0e10cSrcweir 		m_aCurrentFormats.clear();
189*cdf0e10cSrcweir 		m_aCurrentFormats.reserve( 3 );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 		DataFlavorEx aFlavor;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		if ( m_aHiddenControlModels.getLength() )
194*cdf0e10cSrcweir 		{
195*cdf0e10cSrcweir 			if ( lcl_fillDataFlavorEx( OControlExchange::getHiddenControlModelsFormatId(), aFlavor ) )
196*cdf0e10cSrcweir 				m_aCurrentFormats.push_back( aFlavor );
197*cdf0e10cSrcweir 		}
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 		if ( m_xFormsRoot.is() && m_aControlPaths.getLength() )
200*cdf0e10cSrcweir 		{
201*cdf0e10cSrcweir 			if ( lcl_fillDataFlavorEx( OControlExchange::getControlPathFormatId(), aFlavor ) )
202*cdf0e10cSrcweir 				m_aCurrentFormats.push_back( aFlavor );
203*cdf0e10cSrcweir 		}
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 		if ( !m_aSelectedEntries.empty() )
206*cdf0e10cSrcweir 		{
207*cdf0e10cSrcweir 			if ( lcl_fillDataFlavorEx( OControlExchange::getFieldExchangeFormatId(), aFlavor ) )
208*cdf0e10cSrcweir 				m_aCurrentFormats.push_back( aFlavor );
209*cdf0e10cSrcweir 		}
210*cdf0e10cSrcweir 	}
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	//--------------------------------------------------------------------
213*cdf0e10cSrcweir 	size_t OControlTransferData::onEntryRemoved( SvLBoxEntry* _pEntry )
214*cdf0e10cSrcweir 	{
215*cdf0e10cSrcweir         m_aSelectedEntries.erase( _pEntry );
216*cdf0e10cSrcweir         return m_aSelectedEntries.size();
217*cdf0e10cSrcweir 	}
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 	//--------------------------------------------------------------------
220*cdf0e10cSrcweir 	void OControlTransferData::addSelectedEntry( SvLBoxEntry* _pEntry )
221*cdf0e10cSrcweir 	{
222*cdf0e10cSrcweir 		m_aSelectedEntries.insert( _pEntry );
223*cdf0e10cSrcweir 	}
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	//--------------------------------------------------------------------
226*cdf0e10cSrcweir 	void OControlTransferData::setFocusEntry( SvLBoxEntry* _pFocusEntry )
227*cdf0e10cSrcweir 	{
228*cdf0e10cSrcweir 		m_pFocusEntry = _pFocusEntry;
229*cdf0e10cSrcweir 	}
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	//------------------------------------------------------------------------
232*cdf0e10cSrcweir 	void OControlTransferData::addHiddenControlsFormat(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > seqInterfaces)
233*cdf0e10cSrcweir 	{
234*cdf0e10cSrcweir 		m_aHiddenControlModels = seqInterfaces;
235*cdf0e10cSrcweir 	}
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 	//------------------------------------------------------------------------
238*cdf0e10cSrcweir 	void OControlTransferData::buildPathFormat(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot)
239*cdf0e10cSrcweir 	{
240*cdf0e10cSrcweir 		m_aControlPaths.realloc(0);
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 		sal_Int32 nEntryCount = m_aSelectedEntries.size();
243*cdf0e10cSrcweir 		if (nEntryCount == 0)
244*cdf0e10cSrcweir 			return;
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 		m_aControlPaths.realloc(nEntryCount);
247*cdf0e10cSrcweir 		::com::sun::star::uno::Sequence<sal_uInt32>* pAllPaths = m_aControlPaths.getArray();
248*cdf0e10cSrcweir         for (   ListBoxEntrySet::const_iterator loop = m_aSelectedEntries.begin();
249*cdf0e10cSrcweir                 loop != m_aSelectedEntries.end();
250*cdf0e10cSrcweir                 ++loop, ++pAllPaths
251*cdf0e10cSrcweir             )
252*cdf0e10cSrcweir 		{
253*cdf0e10cSrcweir 			// erst mal sammeln wir den Pfad in einem Array ein
254*cdf0e10cSrcweir 			::std::vector< sal_uInt32 > aCurrentPath;
255*cdf0e10cSrcweir 			SvLBoxEntry* pCurrentEntry = *loop;
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 			SvLBoxEntry* pLoop = pCurrentEntry;
258*cdf0e10cSrcweir 			while (pLoop != pRoot)
259*cdf0e10cSrcweir 			{
260*cdf0e10cSrcweir 				aCurrentPath.push_back(pLoop->GetChildListPos());
261*cdf0e10cSrcweir 				pLoop = pTreeBox->GetParent(pLoop);
262*cdf0e10cSrcweir 				DBG_ASSERT((pLoop != NULL) || (pRoot == 0), "OControlTransferData::buildPathFormat: invalid root or entry !");
263*cdf0e10cSrcweir 					// pLoop == NULL heisst, dass ich am oberen Ende angelangt bin, dann sollte das Ganze abbrechen, was nur bei pRoot == NULL der Fall sein wird
264*cdf0e10cSrcweir 			}
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 			// dann koennen wir ihn in die ::com::sun::star::uno::Sequence uebertragen
267*cdf0e10cSrcweir 			Sequence<sal_uInt32>& rCurrentPath = *pAllPaths;
268*cdf0e10cSrcweir 			sal_Int32 nDepth = aCurrentPath.size();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 			rCurrentPath.realloc(nDepth);
271*cdf0e10cSrcweir 			sal_uInt32* pSeq = rCurrentPath.getArray();
272*cdf0e10cSrcweir 			sal_Int32 j,k;
273*cdf0e10cSrcweir 			for (j = nDepth - 1, k = 0; k<nDepth; --j, ++k)
274*cdf0e10cSrcweir 				pSeq[j] = aCurrentPath[k];
275*cdf0e10cSrcweir 		}
276*cdf0e10cSrcweir 	}
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 	//------------------------------------------------------------------------
279*cdf0e10cSrcweir 	void OControlTransferData::buildListFromPath(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot)
280*cdf0e10cSrcweir 	{
281*cdf0e10cSrcweir         ListBoxEntrySet aEmpty;
282*cdf0e10cSrcweir 		m_aSelectedEntries.swap( aEmpty );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 		sal_Int32 nControls = m_aControlPaths.getLength();
285*cdf0e10cSrcweir 		const ::com::sun::star::uno::Sequence<sal_uInt32>* pPaths = m_aControlPaths.getConstArray();
286*cdf0e10cSrcweir 		for (sal_Int32 i=0; i<nControls; ++i)
287*cdf0e10cSrcweir 		{
288*cdf0e10cSrcweir 			sal_Int32 nThisPatLength = pPaths[i].getLength();
289*cdf0e10cSrcweir 			const sal_uInt32* pThisPath = pPaths[i].getConstArray();
290*cdf0e10cSrcweir 			SvLBoxEntry* pSearch = pRoot;
291*cdf0e10cSrcweir 			for (sal_Int32 j=0; j<nThisPatLength; ++j)
292*cdf0e10cSrcweir 				pSearch = pTreeBox->GetEntry(pSearch, pThisPath[j]);
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 			m_aSelectedEntries.insert( pSearch );
295*cdf0e10cSrcweir 		}
296*cdf0e10cSrcweir 	}
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	//====================================================================
299*cdf0e10cSrcweir 	//= OControlExchange
300*cdf0e10cSrcweir 	//====================================================================
301*cdf0e10cSrcweir 	//--------------------------------------------------------------------
302*cdf0e10cSrcweir 	OControlExchange::OControlExchange( )
303*cdf0e10cSrcweir 	{
304*cdf0e10cSrcweir 	}
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 	//--------------------------------------------------------------------
307*cdf0e10cSrcweir 	sal_Bool OControlExchange::GetData( const DataFlavor& _rFlavor )
308*cdf0e10cSrcweir 	{
309*cdf0e10cSrcweir 		const sal_uInt32 nFormatId = SotExchange::GetFormat( _rFlavor );
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 		if ( getControlPathFormatId( ) == nFormatId )
312*cdf0e10cSrcweir 		{
313*cdf0e10cSrcweir 			// ugly. We have to pack all the info into one object
314*cdf0e10cSrcweir 			Sequence< Any > aCompleteInfo( 2 );
315*cdf0e10cSrcweir 			OSL_ENSURE( m_xFormsRoot.is(), "OLocalExchange::GetData: invalid forms root for this format!" );
316*cdf0e10cSrcweir 			aCompleteInfo.getArray()[ 0 ] <<= m_xFormsRoot;
317*cdf0e10cSrcweir 			aCompleteInfo.getArray()[ 1 ] <<= m_aControlPaths;
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 			SetAny( makeAny( aCompleteInfo ), _rFlavor );
320*cdf0e10cSrcweir 		}
321*cdf0e10cSrcweir 		else if ( getHiddenControlModelsFormatId() == nFormatId )
322*cdf0e10cSrcweir 		{
323*cdf0e10cSrcweir 			// just need to transfer the models
324*cdf0e10cSrcweir 			SetAny( makeAny( m_aHiddenControlModels ), _rFlavor );
325*cdf0e10cSrcweir 		}
326*cdf0e10cSrcweir 		else
327*cdf0e10cSrcweir 			return OLocalExchange::GetData( _rFlavor );
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 		return sal_True;
330*cdf0e10cSrcweir 	}
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 	//--------------------------------------------------------------------
333*cdf0e10cSrcweir 	void OControlExchange::AddSupportedFormats()
334*cdf0e10cSrcweir 	{
335*cdf0e10cSrcweir 		if (m_pFocusEntry && !m_aSelectedEntries.empty())
336*cdf0e10cSrcweir 			AddFormat(getFieldExchangeFormatId());
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 		if (m_aControlPaths.getLength())
339*cdf0e10cSrcweir 			AddFormat(getControlPathFormatId());
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir 		if (m_aHiddenControlModels.getLength())
342*cdf0e10cSrcweir 			AddFormat(getHiddenControlModelsFormatId());
343*cdf0e10cSrcweir 	}
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	//--------------------------------------------------------------------
346*cdf0e10cSrcweir 	sal_uInt32 OControlExchange::getControlPathFormatId()
347*cdf0e10cSrcweir 	{
348*cdf0e10cSrcweir 		static sal_uInt32 s_nFormat = (sal_uInt32)-1;
349*cdf0e10cSrcweir 		if ((sal_uInt32)-1 == s_nFormat)
350*cdf0e10cSrcweir 		{
351*cdf0e10cSrcweir 			s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"svxform.ControlPathExchange\""));
352*cdf0e10cSrcweir 			DBG_ASSERT((sal_uInt32)-1 != s_nFormat, "OControlExchange::getControlPathFormatId: bad exchange id!");
353*cdf0e10cSrcweir 		}
354*cdf0e10cSrcweir 		return s_nFormat;
355*cdf0e10cSrcweir 	}
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 	//--------------------------------------------------------------------
358*cdf0e10cSrcweir 	sal_uInt32 OControlExchange::getHiddenControlModelsFormatId()
359*cdf0e10cSrcweir 	{
360*cdf0e10cSrcweir 		static sal_uInt32 s_nFormat = (sal_uInt32)-1;
361*cdf0e10cSrcweir 		if ((sal_uInt32)-1 == s_nFormat)
362*cdf0e10cSrcweir 		{
363*cdf0e10cSrcweir 			s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"svxform.HiddenControlModelsExchange\""));
364*cdf0e10cSrcweir 			DBG_ASSERT((sal_uInt32)-1 != s_nFormat, "OControlExchange::getHiddenControlModelsFormatId: bad exchange id!");
365*cdf0e10cSrcweir 		}
366*cdf0e10cSrcweir 		return s_nFormat;
367*cdf0e10cSrcweir 	}
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 	//--------------------------------------------------------------------
370*cdf0e10cSrcweir 	sal_uInt32 OControlExchange::getFieldExchangeFormatId()
371*cdf0e10cSrcweir 	{
372*cdf0e10cSrcweir 		static sal_uInt32 s_nFormat = (sal_uInt32)-1;
373*cdf0e10cSrcweir 		if ((sal_uInt32)-1 == s_nFormat)
374*cdf0e10cSrcweir 		{
375*cdf0e10cSrcweir 			s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"svxform.FieldNameExchange\""));
376*cdf0e10cSrcweir 			DBG_ASSERT((sal_uInt32)-1 != s_nFormat, "OControlExchange::getFieldExchangeFormatId: bad exchange id!");
377*cdf0e10cSrcweir 		}
378*cdf0e10cSrcweir 		return s_nFormat;
379*cdf0e10cSrcweir 	}
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 	//====================================================================
382*cdf0e10cSrcweir 	//= OControlExchangeHelper
383*cdf0e10cSrcweir 	//====================================================================
384*cdf0e10cSrcweir 	OLocalExchange* OControlExchangeHelper::createExchange() const
385*cdf0e10cSrcweir 	{
386*cdf0e10cSrcweir 		return new OControlExchange;
387*cdf0e10cSrcweir 	}
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 	//====================================================================
390*cdf0e10cSrcweir 	//= OLocalExchangeHelper
391*cdf0e10cSrcweir 	//====================================================================
392*cdf0e10cSrcweir 	//--------------------------------------------------------------------
393*cdf0e10cSrcweir 	OLocalExchangeHelper::OLocalExchangeHelper(Window* _pDragSource)
394*cdf0e10cSrcweir 		:m_pDragSource(_pDragSource)
395*cdf0e10cSrcweir 		,m_pTransferable(NULL)
396*cdf0e10cSrcweir 	{
397*cdf0e10cSrcweir 	}
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	//--------------------------------------------------------------------
400*cdf0e10cSrcweir 	OLocalExchangeHelper::~OLocalExchangeHelper()
401*cdf0e10cSrcweir 	{
402*cdf0e10cSrcweir 		implReset();
403*cdf0e10cSrcweir 	}
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 	//--------------------------------------------------------------------
406*cdf0e10cSrcweir 	void OLocalExchangeHelper::startDrag( sal_Int8 nDragSourceActions )
407*cdf0e10cSrcweir 	{
408*cdf0e10cSrcweir 		DBG_ASSERT(m_pTransferable, "OLocalExchangeHelper::startDrag: not prepared!");
409*cdf0e10cSrcweir 		m_pTransferable->startDrag( m_pDragSource, nDragSourceActions, OLocalExchange::GrantAccess() );
410*cdf0e10cSrcweir 	}
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	//--------------------------------------------------------------------
413*cdf0e10cSrcweir 	void OLocalExchangeHelper::copyToClipboard( ) const
414*cdf0e10cSrcweir 	{
415*cdf0e10cSrcweir 		DBG_ASSERT( m_pTransferable, "OLocalExchangeHelper::copyToClipboard: not prepared!" );
416*cdf0e10cSrcweir 		m_pTransferable->copyToClipboard( m_pDragSource, OLocalExchange::GrantAccess() );
417*cdf0e10cSrcweir 	}
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 	//--------------------------------------------------------------------
420*cdf0e10cSrcweir 	void OLocalExchangeHelper::implReset()
421*cdf0e10cSrcweir 	{
422*cdf0e10cSrcweir 		if (m_pTransferable)
423*cdf0e10cSrcweir 		{
424*cdf0e10cSrcweir 			m_pTransferable->setClipboardListener( Link() );
425*cdf0e10cSrcweir 			m_pTransferable->release();
426*cdf0e10cSrcweir 			m_pTransferable = NULL;
427*cdf0e10cSrcweir 		}
428*cdf0e10cSrcweir 	}
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 	//--------------------------------------------------------------------
431*cdf0e10cSrcweir 	void OLocalExchangeHelper::prepareDrag( )
432*cdf0e10cSrcweir 	{
433*cdf0e10cSrcweir 		DBG_ASSERT(!m_pTransferable || !m_pTransferable->isDragging(), "OLocalExchangeHelper::prepareDrag: recursive DnD?");
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 		implReset();
436*cdf0e10cSrcweir 		m_pTransferable = createExchange();
437*cdf0e10cSrcweir 		m_pTransferable->acquire();
438*cdf0e10cSrcweir 	}
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir //........................................................................
441*cdf0e10cSrcweir }
442*cdf0e10cSrcweir //........................................................................
443*cdf0e10cSrcweir 
444