Update ooo320-m1
[ooovba.git] / svx / source / inc / fmexch.hxx
blob410addcf31970310faed8f42c6a441778b2b69c0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmexch.hxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SVX_FMEXCH_HXX
31 #define _SVX_FMEXCH_HXX
33 #include <comphelper/stl_types.hxx>
34 #include <svtools/transfer.hxx>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <com/sun/star/container/XNameContainer.hpp>
37 #include <tools/link.hxx>
39 #include <svx/svxdllapi.h>
41 class FmFormShell;
42 class FmFormPage;
43 class SvLBoxEntry;
45 //========================================================================
46 // Exchange types
47 #define SVX_FM_FIELD_EXCH String("SvxFormFieldExch", sizeof("SvxFormFieldExch"))
48 #define SVX_FM_CONTROL_EXCH String("SvxFormExplCtrlExch", sizeof("SvxFormExplCtrlExch"))
49 #define SVX_FM_CONTROLS_AS_PATH String("SvxFormControlsAsPathExchange", sizeof("SvxFormControlsAsPathExchange"))
50 #define SVX_FM_HIDDEN_CONTROLS String("SvxFormHiddenControlsExchange", sizeof("SvxFormHiddenControlsExchange"))
51 #define SVX_FM_FILTER_FIELDS String("SvxFilterFieldExchange", sizeof("SvxFilterFieldExchange"))
53 //========================================================================
54 class SvTreeListBox;
56 //........................................................................
57 namespace svxform
59 //........................................................................
61 //====================================================================
63 typedef ::std::set< SvLBoxEntry* > ListBoxEntrySet;
65 //====================================================================
66 //= OLocalExchange
67 //====================================================================
68 class SVX_DLLPUBLIC OLocalExchange : public TransferableHelper
70 private:
71 Link m_aClipboardListener;
72 sal_Bool m_bDragging : 1;
73 sal_Bool m_bClipboardOwner : 1;
75 public:
76 class GrantAccess
78 friend class OLocalExchangeHelper;
81 public:
82 OLocalExchange( );
84 sal_Bool isDragging() const { return m_bDragging; }
85 sal_Bool isClipboardOwner() const { return m_bClipboardOwner; }
87 void startDrag( Window* pWindow, sal_Int8 nDragSourceActions, const GrantAccess& );
88 void copyToClipboard( Window* _pWindow, const GrantAccess& );
90 void setClipboardListener( const Link& _rListener ) { m_aClipboardListener = _rListener; }
92 void clear();
94 static sal_Bool hasFormat( const DataFlavorExVector& _rFormats, sal_uInt32 _nFormatId );
96 protected:
97 // XClipboardOwner
98 virtual void SAL_CALL lostOwnership( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& _rxClipboard, const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _rxTrans ) throw(::com::sun::star::uno::RuntimeException);
100 // TransferableHelper
101 virtual void DragFinished( sal_Int8 nDropAction );
102 virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
104 private:
105 void StartDrag( Window* pWindow, sal_Int8 nDragSourceActions, sal_Int32 nDragPointer = DND_POINTER_NONE, sal_Int32 nDragImage = DND_IMAGE_NONE )
106 { // don't allow this base class method to be called from outside
107 TransferableHelper::StartDrag(pWindow, nDragSourceActions, nDragPointer, nDragImage);
111 //====================================================================
112 //= OLocalExchangeHelper
113 //====================================================================
114 /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
115 class SVX_DLLPUBLIC OLocalExchangeHelper
117 protected:
118 Window* m_pDragSource;
119 OLocalExchange* m_pTransferable;
121 public:
122 OLocalExchangeHelper( Window* _pDragSource );
123 virtual ~OLocalExchangeHelper();
125 void prepareDrag( );
127 void startDrag( sal_Int8 nDragSourceActions );
128 void copyToClipboard( ) const;
130 inline sal_Bool isDragSource() const { return m_pTransferable && m_pTransferable->isDragging(); }
131 inline sal_Bool isClipboardOwner() const { return m_pTransferable && m_pTransferable->isClipboardOwner(); }
132 inline sal_Bool isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
133 inline void clear() { if ( isDataExchangeActive() ) m_pTransferable->clear(); }
135 SVX_DLLPRIVATE void setClipboardListener( const Link& _rListener ) { if ( m_pTransferable ) m_pTransferable->setClipboardListener( _rListener ); }
137 protected:
138 SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
140 protected:
141 SVX_DLLPRIVATE void implReset();
144 //====================================================================
145 //= OControlTransferData
146 //====================================================================
147 class OControlTransferData
149 private:
150 typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_uInt32 > > ControlPaths;
152 private:
153 DataFlavorExVector m_aCurrentFormats;
155 protected:
156 ListBoxEntrySet m_aSelectedEntries;
157 ControlPaths m_aControlPaths;
158 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
159 m_aHiddenControlModels;
161 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
162 m_xFormsRoot; // the root of the forms collection where the entries we represent reside
163 // this uniquely identifies the page and the document
165 SvLBoxEntry* m_pFocusEntry;
167 protected:
168 // updates m_aCurrentFormats with all formats we currently could supply
169 void updateFormats( );
171 public:
172 OControlTransferData( );
174 // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
175 OControlTransferData(
176 const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _rxTransferable
179 inline const DataFlavorExVector& GetDataFlavorExVector() const;
181 void addSelectedEntry( SvLBoxEntry* _pEntry );
182 void setFocusEntry( SvLBoxEntry* _pFocusEntry );
184 /** notifies the data transfer object that a certain entry has been removed from the owning tree
186 In case the removed entry is part of the transfer object's selection, the entry is removed from
187 the selection.
189 @param _pEntry
190 @return the number of entries remaining in the selection.
192 size_t onEntryRemoved( SvLBoxEntry* _pEntry );
194 void setFormsRoot(
195 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxFormsRoot
196 ) { m_xFormsRoot = _rxFormsRoot; }
198 void buildPathFormat(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot);
199 // baut aus m_aSelectedEntries m_aControlPaths auf
200 // (es wird davon ausgegangen, dass die Eintraege in m_aSelectedEntries sortiert sind in Bezug auf die Nachbar-Beziehung)
203 void buildListFromPath(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot);
204 // der umgekehrte Weg : wirft alles aus m_aSelectedEntries weg und baut es mittels m_aControlPaths neu auf
206 void addHiddenControlsFormat(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > seqInterfaces);
207 // fuegt ein SVX_FML_HIDDEN_CONTROLS-Format hinzu und merk sich dafuer die uebergebenen Interfaces
208 // (es erfolgt KEINE Ueberpruefung, ob dadurch auch tatsaechlich nur hidden Controls bezeichnet werden, dass muss der
209 // Aufrufer sicherstellen)
211 SvLBoxEntry* focused() const { return m_pFocusEntry; }
212 const ListBoxEntrySet& selected() const { return m_aSelectedEntries; }
213 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
214 hiddenControls() const { return m_aHiddenControlModels; }
216 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
217 getFormsRoot() const { return m_xFormsRoot; }
220 //====================================================================
221 inline const DataFlavorExVector& OControlTransferData::GetDataFlavorExVector() const
223 const_cast< OControlTransferData* >( this )->updateFormats( );
224 return m_aCurrentFormats;
227 //====================================================================
228 //= OControlExchange
229 //====================================================================
230 class OControlExchange : public OLocalExchange, public OControlTransferData
232 public:
233 OControlExchange( );
235 public:
236 static sal_uInt32 getFieldExchangeFormatId( );
237 static sal_uInt32 getControlPathFormatId( );
238 static sal_uInt32 getHiddenControlModelsFormatId( );
240 inline static sal_Bool hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
241 inline static sal_Bool hasControlPathFormat( const DataFlavorExVector& _rFormats );
242 inline static sal_Bool hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
244 protected:
245 virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
246 virtual void AddSupportedFormats();
249 //====================================================================
250 //= OControlExchangeHelper
251 //====================================================================
252 class OControlExchangeHelper : public OLocalExchangeHelper
254 public:
255 OControlExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
257 OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_pTransferable ); }
258 OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_pTransferable ); }
260 protected:
261 virtual OLocalExchange* createExchange() const;
264 //====================================================================
265 //====================================================================
266 inline sal_Bool OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector& _rFormats )
268 return hasFormat( _rFormats, getFieldExchangeFormatId() );
271 inline sal_Bool OControlExchange::hasControlPathFormat( const DataFlavorExVector& _rFormats )
273 return hasFormat( _rFormats, getControlPathFormatId() );
276 inline sal_Bool OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats )
278 return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
281 //........................................................................
282 } // namespace svxform
283 //........................................................................
285 #endif