xref: /trunk/main/svx/source/inc/fmexch.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef _SVX_FMEXCH_HXX
28 #define _SVX_FMEXCH_HXX
29 
30 #include <comphelper/stl_types.hxx>
31 #include <svtools/transfer.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <tools/link.hxx>
35 
36 #include <svx/svxdllapi.h>
37 
38 class FmFormShell;
39 class FmFormPage;
40 class SvLBoxEntry;
41 
42 //========================================================================
43 // Exchange types
44 #define SVX_FM_FIELD_EXCH           String("SvxFormFieldExch",              sizeof("SvxFormFieldExch"))
45 #define SVX_FM_CONTROL_EXCH         String("SvxFormExplCtrlExch",           sizeof("SvxFormExplCtrlExch"))
46 #define SVX_FM_CONTROLS_AS_PATH     String("SvxFormControlsAsPathExchange", sizeof("SvxFormControlsAsPathExchange"))
47 #define SVX_FM_HIDDEN_CONTROLS      String("SvxFormHiddenControlsExchange", sizeof("SvxFormHiddenControlsExchange"))
48 #define SVX_FM_FILTER_FIELDS        String("SvxFilterFieldExchange",        sizeof("SvxFilterFieldExchange"))
49 
50 //========================================================================
51 class SvTreeListBox;
52 
53 //........................................................................
54 namespace svxform
55 {
56 //........................................................................
57 
58     //====================================================================
59 
60     typedef ::std::set< SvLBoxEntry* >  ListBoxEntrySet;
61 
62     //====================================================================
63     //= OLocalExchange
64     //====================================================================
65     class SVX_DLLPUBLIC OLocalExchange : public TransferableHelper
66     {
67     private:
68         Link                m_aClipboardListener;
69         sal_Bool            m_bDragging         : 1;
70         sal_Bool            m_bClipboardOwner   : 1;
71 
72     public:
73         class GrantAccess
74         {
75             friend class OLocalExchangeHelper;
76         };
77 
78     public:
79         OLocalExchange( );
80 
81         sal_Bool    isDragging() const { return m_bDragging; }
82         sal_Bool    isClipboardOwner() const { return m_bClipboardOwner; }
83 
84         void        startDrag( Window* pWindow, sal_Int8 nDragSourceActions, const GrantAccess& );
85         void        copyToClipboard( Window* _pWindow, const GrantAccess& );
86 
87         void        setClipboardListener( const Link& _rListener ) { m_aClipboardListener = _rListener; }
88 
89         void        clear();
90 
91         static  sal_Bool    hasFormat( const DataFlavorExVector& _rFormats, sal_uInt32 _nFormatId );
92 
93     protected:
94         // XClipboardOwner
95         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);
96 
97         // TransferableHelper
98         virtual void        DragFinished( sal_Int8 nDropAction );
99         virtual sal_Bool    GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
100 
101     private:
102         void StartDrag( Window* pWindow, sal_Int8 nDragSourceActions, sal_Int32 nDragPointer = DND_POINTER_NONE, sal_Int32 nDragImage = DND_IMAGE_NONE )
103         {   // don't allow this base class method to be called from outside
104             TransferableHelper::StartDrag(pWindow, nDragSourceActions, nDragPointer, nDragImage);
105         }
106     };
107 
108     //====================================================================
109     //= OLocalExchangeHelper
110     //====================================================================
111     /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
112     class SVX_DLLPUBLIC OLocalExchangeHelper
113     {
114     protected:
115         Window*             m_pDragSource;
116         OLocalExchange*     m_pTransferable;
117 
118     public:
119         OLocalExchangeHelper( Window* _pDragSource );
120         virtual ~OLocalExchangeHelper();
121 
122         void        prepareDrag( );
123 
124         void        startDrag( sal_Int8 nDragSourceActions );
125         void        copyToClipboard( ) const;
126 
127         inline  sal_Bool    isDragSource() const { return m_pTransferable && m_pTransferable->isDragging(); }
128         inline  sal_Bool    isClipboardOwner() const { return m_pTransferable && m_pTransferable->isClipboardOwner(); }
129         inline  sal_Bool    isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
130         inline  void        clear() { if ( isDataExchangeActive() ) m_pTransferable->clear(); }
131 
132         SVX_DLLPRIVATE void     setClipboardListener( const Link& _rListener ) { if ( m_pTransferable ) m_pTransferable->setClipboardListener( _rListener ); }
133 
134     protected:
135         SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
136 
137     protected:
138         SVX_DLLPRIVATE void implReset();
139     };
140 
141     //====================================================================
142     //= OControlTransferData
143     //====================================================================
144     class OControlTransferData
145     {
146     private:
147         typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_uInt32 > > ControlPaths;
148 
149     private:
150         DataFlavorExVector  m_aCurrentFormats;
151 
152     protected:
153         ListBoxEntrySet     m_aSelectedEntries;
154         ControlPaths        m_aControlPaths;
155         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
156                             m_aHiddenControlModels;
157 
158         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
159                             m_xFormsRoot;       // the root of the forms collection where the entries we represent reside
160                                                 // this uniquely identifies the page and the document
161 
162         SvLBoxEntry*        m_pFocusEntry;
163 
164     protected:
165         // updates m_aCurrentFormats with all formats we currently could supply
166         void    updateFormats( );
167 
168     public:
169         OControlTransferData( );
170 
171         // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
172         OControlTransferData(
173             const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _rxTransferable
174         );
175 
176         inline const DataFlavorExVector&    GetDataFlavorExVector() const;
177 
178         void addSelectedEntry( SvLBoxEntry* _pEntry );
179         void setFocusEntry( SvLBoxEntry* _pFocusEntry );
180 
181         /** notifies the data transfer object that a certain entry has been removed from the owning tree
182 
183             In case the removed entry is part of the transfer object's selection, the entry is removed from
184             the selection.
185 
186             @param  _pEntry
187             @return the number of entries remaining in the selection.
188         */
189         size_t  onEntryRemoved( SvLBoxEntry* _pEntry );
190 
191         void setFormsRoot(
192             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxFormsRoot
193             ) { m_xFormsRoot = _rxFormsRoot; }
194 
195         void buildPathFormat(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot);
196             // baut aus m_aSelectedEntries m_aControlPaths auf
197             // (es wird davon ausgegangen, dass die Eintraege in m_aSelectedEntries sortiert sind in Bezug auf die Nachbar-Beziehung)
198 
199 
200         void buildListFromPath(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot);
201             // der umgekehrte Weg : wirft alles aus m_aSelectedEntries weg und baut es mittels m_aControlPaths neu auf
202 
203         void addHiddenControlsFormat(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > seqInterfaces);
204             // fuegt ein SVX_FML_HIDDEN_CONTROLS-Format hinzu und merk sich dafuer die uebergebenen Interfaces
205             // (es erfolgt KEINE Ueberpruefung, ob dadurch auch tatsaechlich nur hidden Controls bezeichnet werden, dass muss der
206             // Aufrufer sicherstellen)
207 
208         SvLBoxEntry*                focused() const { return m_pFocusEntry; }
209         const ListBoxEntrySet&      selected() const { return m_aSelectedEntries; }
210         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
211                                     hiddenControls() const { return m_aHiddenControlModels; }
212 
213         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
214                                 getFormsRoot() const { return m_xFormsRoot; }
215     };
216 
217     //====================================================================
218     inline const DataFlavorExVector& OControlTransferData::GetDataFlavorExVector() const
219     {
220         const_cast< OControlTransferData* >( this )->updateFormats( );
221         return m_aCurrentFormats;
222     }
223 
224     //====================================================================
225     //= OControlExchange
226     //====================================================================
227     class OControlExchange : public OLocalExchange, public OControlTransferData
228     {
229     public:
230         OControlExchange( );
231 
232     public:
233         static sal_uInt32       getFieldExchangeFormatId( );
234         static sal_uInt32       getControlPathFormatId( );
235         static sal_uInt32       getHiddenControlModelsFormatId( );
236 
237         inline static sal_Bool  hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
238         inline static sal_Bool  hasControlPathFormat( const DataFlavorExVector& _rFormats );
239         inline static sal_Bool  hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
240 
241     protected:
242         virtual sal_Bool    GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
243         virtual void        AddSupportedFormats();
244     };
245 
246     //====================================================================
247     //= OControlExchangeHelper
248     //====================================================================
249     class OControlExchangeHelper : public OLocalExchangeHelper
250     {
251     public:
252         OControlExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
253 
254         OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_pTransferable ); }
255         OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_pTransferable ); }
256 
257     protected:
258         virtual OLocalExchange* createExchange() const;
259     };
260 
261     //====================================================================
262     //====================================================================
263     inline sal_Bool OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector& _rFormats )
264     {
265         return hasFormat( _rFormats, getFieldExchangeFormatId() );
266     }
267 
268     inline sal_Bool OControlExchange::hasControlPathFormat( const DataFlavorExVector& _rFormats )
269     {
270         return hasFormat( _rFormats, getControlPathFormatId() );
271     }
272 
273     inline sal_Bool OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats )
274     {
275         return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
276     }
277 
278 //........................................................................
279 }   // namespace svxform
280 //........................................................................
281 
282 #endif
283 
284