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