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>
43 //========================================================================
46 //........................................................................
49 //........................................................................
51 //====================================================================
53 typedef ::std::set
< SvLBoxEntry
* > ListBoxEntrySet
;
55 //====================================================================
57 //====================================================================
58 class SVX_DLLPUBLIC OLocalExchange
: public TransferableHelper
61 Link m_aClipboardListener
;
62 sal_Bool m_bDragging
: 1;
63 sal_Bool m_bClipboardOwner
: 1;
68 friend class OLocalExchangeHelper
;
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
; }
84 static sal_Bool
hasFormat( const DataFlavorExVector
& _rFormats
, sal_uInt32 _nFormatId
);
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
);
91 virtual void DragFinished( sal_Int8 nDropAction
);
92 virtual sal_Bool
GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
);
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
108 Window
* m_pDragSource
;
109 OLocalExchange
* m_pTransferable
;
112 OLocalExchangeHelper( Window
* _pDragSource
);
113 virtual ~OLocalExchangeHelper();
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
); }
128 SVX_DLLPRIVATE
virtual OLocalExchange
* createExchange() const = 0;
131 SVX_DLLPRIVATE
void implReset();
134 //====================================================================
135 //= OControlTransferData
136 //====================================================================
137 class OControlTransferData
140 typedef ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< sal_uInt32
> > ControlPaths
;
143 DataFlavorExVector m_aCurrentFormats
;
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
;
158 // updates m_aCurrentFormats with all formats we currently could supply
159 void updateFormats( );
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
180 @return the number of entries remaining in the selection.
182 size_t onEntryRemoved( SvLBoxEntry
* _pEntry
);
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 //====================================================================
219 //====================================================================
220 class OControlExchange
: public OLocalExchange
, public OControlTransferData
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
);
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
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
); }
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 //........................................................................
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */