Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / inc / fmexch.hxx
blob42781aba8a777ee603f0c2ce2613cbb0994a9bbc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
28 #ifndef _SVX_FMEXCH_HXX
29 #define _SVX_FMEXCH_HXX
31 #include <comphelper/stl_types.hxx>
32 #include <svtools/transfer.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <tools/link.hxx>
37 #include <svx/svxdllapi.h>
39 class FmFormShell;
40 class FmFormPage;
41 class SvLBoxEntry;
43 //========================================================================
44 class SvTreeListBox;
46 //........................................................................
47 namespace svxform
49 //........................................................................
51 //====================================================================
53 typedef ::std::set< SvLBoxEntry* > ListBoxEntrySet;
55 //====================================================================
56 //= OLocalExchange
57 //====================================================================
58 class SVX_DLLPUBLIC OLocalExchange : public TransferableHelper
60 private:
61 Link m_aClipboardListener;
62 sal_Bool m_bDragging : 1;
63 sal_Bool m_bClipboardOwner : 1;
65 public:
66 class GrantAccess
68 friend class OLocalExchangeHelper;
71 public:
72 OLocalExchange( );
74 sal_Bool isDragging() const { return m_bDragging; }
75 sal_Bool isClipboardOwner() const { return m_bClipboardOwner; }
77 void startDrag( Window* pWindow, sal_Int8 nDragSourceActions, const GrantAccess& );
78 void copyToClipboard( Window* _pWindow, const GrantAccess& );
80 void setClipboardListener( const Link& _rListener ) { m_aClipboardListener = _rListener; }
82 void clear();
84 static sal_Bool hasFormat( const DataFlavorExVector& _rFormats, sal_uInt32 _nFormatId );
86 protected:
87 // XClipboardOwner
88 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);
90 // TransferableHelper
91 virtual void DragFinished( sal_Int8 nDropAction );
92 virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
94 private:
95 void StartDrag( Window* pWindow, sal_Int8 nDragSourceActions, sal_Int32 nDragPointer = DND_POINTER_NONE, sal_Int32 nDragImage = DND_IMAGE_NONE )
96 { // don't allow this base class method to be called from outside
97 TransferableHelper::StartDrag(pWindow, nDragSourceActions, nDragPointer, nDragImage);
101 //====================================================================
102 //= OLocalExchangeHelper
103 //====================================================================
104 /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
105 class SVX_DLLPUBLIC OLocalExchangeHelper
107 protected:
108 Window* m_pDragSource;
109 OLocalExchange* m_pTransferable;
111 public:
112 OLocalExchangeHelper( Window* _pDragSource );
113 virtual ~OLocalExchangeHelper();
115 void prepareDrag( );
117 void startDrag( sal_Int8 nDragSourceActions );
118 void copyToClipboard( ) const;
120 inline sal_Bool isDragSource() const { return m_pTransferable && m_pTransferable->isDragging(); }
121 inline sal_Bool isClipboardOwner() const { return m_pTransferable && m_pTransferable->isClipboardOwner(); }
122 inline sal_Bool isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
123 inline void clear() { if ( isDataExchangeActive() ) m_pTransferable->clear(); }
125 SVX_DLLPRIVATE void setClipboardListener( const Link& _rListener ) { if ( m_pTransferable ) m_pTransferable->setClipboardListener( _rListener ); }
127 protected:
128 SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
130 protected:
131 SVX_DLLPRIVATE void implReset();
134 //====================================================================
135 //= OControlTransferData
136 //====================================================================
137 class OControlTransferData
139 private:
140 typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_uInt32 > > ControlPaths;
142 private:
143 DataFlavorExVector m_aCurrentFormats;
145 protected:
146 ListBoxEntrySet m_aSelectedEntries;
147 ControlPaths m_aControlPaths;
148 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
149 m_aHiddenControlModels;
151 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
152 m_xFormsRoot; // the root of the forms collection where the entries we represent reside
153 // this uniquely identifies the page and the document
155 SvLBoxEntry* m_pFocusEntry;
157 protected:
158 // updates m_aCurrentFormats with all formats we currently could supply
159 void updateFormats( );
161 public:
162 OControlTransferData( );
164 // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
165 OControlTransferData(
166 const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _rxTransferable
169 inline const DataFlavorExVector& GetDataFlavorExVector() const;
171 void addSelectedEntry( SvLBoxEntry* _pEntry );
172 void setFocusEntry( SvLBoxEntry* _pFocusEntry );
174 /** notifies the data transfer object that a certain entry has been removed from the owning tree
176 In case the removed entry is part of the transfer object's selection, the entry is removed from
177 the selection.
179 @param _pEntry
180 @return the number of entries remaining in the selection.
182 size_t onEntryRemoved( SvLBoxEntry* _pEntry );
184 void setFormsRoot(
185 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxFormsRoot
186 ) { m_xFormsRoot = _rxFormsRoot; }
188 void buildPathFormat(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot);
189 // baut aus m_aSelectedEntries m_aControlPaths auf
190 // (es wird davon ausgegangen, dass die Eintraege in m_aSelectedEntries sortiert sind in Bezug auf die Nachbar-Beziehung)
193 void buildListFromPath(SvTreeListBox* pTreeBox, SvLBoxEntry* pRoot);
194 // der umgekehrte Weg : wirft alles aus m_aSelectedEntries weg und baut es mittels m_aControlPaths neu auf
196 void addHiddenControlsFormat(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > seqInterfaces);
197 // fuegt ein SVX_FML_HIDDEN_CONTROLS-Format hinzu und merk sich dafuer die uebergebenen Interfaces
198 // (es erfolgt KEINE Ueberpruefung, ob dadurch auch tatsaechlich nur hidden Controls bezeichnet werden, dass muss der
199 // Aufrufer sicherstellen)
201 SvLBoxEntry* focused() const { return m_pFocusEntry; }
202 const ListBoxEntrySet& selected() const { return m_aSelectedEntries; }
203 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
204 hiddenControls() const { return m_aHiddenControlModels; }
206 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
207 getFormsRoot() const { return m_xFormsRoot; }
210 //====================================================================
211 inline const DataFlavorExVector& OControlTransferData::GetDataFlavorExVector() const
213 const_cast< OControlTransferData* >( this )->updateFormats( );
214 return m_aCurrentFormats;
217 //====================================================================
218 //= OControlExchange
219 //====================================================================
220 class OControlExchange : public OLocalExchange, public OControlTransferData
222 public:
223 OControlExchange( );
225 public:
226 static sal_uInt32 getFieldExchangeFormatId( );
227 static sal_uInt32 getControlPathFormatId( );
228 static sal_uInt32 getHiddenControlModelsFormatId( );
230 inline static sal_Bool hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
231 inline static sal_Bool hasControlPathFormat( const DataFlavorExVector& _rFormats );
232 inline static sal_Bool hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
234 protected:
235 virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
236 virtual void AddSupportedFormats();
239 //====================================================================
240 //= OControlExchangeHelper
241 //====================================================================
242 class OControlExchangeHelper : public OLocalExchangeHelper
244 public:
245 OControlExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
247 OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_pTransferable ); }
248 OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_pTransferable ); }
250 protected:
251 virtual OLocalExchange* createExchange() const;
254 //====================================================================
255 //====================================================================
256 inline sal_Bool OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector& _rFormats )
258 return hasFormat( _rFormats, getFieldExchangeFormatId() );
261 inline sal_Bool OControlExchange::hasControlPathFormat( const DataFlavorExVector& _rFormats )
263 return hasFormat( _rFormats, getControlPathFormatId() );
266 inline sal_Bool OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats )
268 return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
271 //........................................................................
272 } // namespace svxform
273 //........................................................................
275 #endif
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */