1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _SVX_FMEXCH_HXX
20 #define _SVX_FMEXCH_HXX
22 #include <comphelper/stl_types.hxx>
23 #include <svtools/transfer.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <com/sun/star/form/XForms.hpp>
27 #include <tools/link.hxx>
29 #include <svx/svxdllapi.h>
31 class SvTreeListEntry
;
33 //========================================================================
36 //........................................................................
39 //........................................................................
41 //====================================================================
43 typedef ::std::set
< SvTreeListEntry
* > ListBoxEntrySet
;
45 //====================================================================
47 //====================================================================
48 class SVX_DLLPUBLIC OLocalExchange
: public TransferableHelper
51 Link m_aClipboardListener
;
52 sal_Bool m_bDragging
: 1;
53 sal_Bool m_bClipboardOwner
: 1;
58 friend class OLocalExchangeHelper
;
64 sal_Bool
isDragging() const { return m_bDragging
; }
65 sal_Bool
isClipboardOwner() const { return m_bClipboardOwner
; }
67 void startDrag( Window
* pWindow
, sal_Int8 nDragSourceActions
, const GrantAccess
& );
68 void copyToClipboard( Window
* _pWindow
, const GrantAccess
& );
70 void setClipboardListener( const Link
& _rListener
) { m_aClipboardListener
= _rListener
; }
74 static sal_Bool
hasFormat( const DataFlavorExVector
& _rFormats
, sal_uInt32 _nFormatId
);
78 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
);
81 virtual void DragFinished( sal_Int8 nDropAction
);
82 virtual sal_Bool
GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
);
85 void StartDrag( Window
* pWindow
, sal_Int8 nDragSourceActions
, sal_Int32 nDragPointer
= DND_POINTER_NONE
, sal_Int32 nDragImage
= DND_IMAGE_NONE
)
86 { // don't allow this base class method to be called from outside
87 TransferableHelper::StartDrag(pWindow
, nDragSourceActions
, nDragPointer
, nDragImage
);
91 //====================================================================
92 //= OLocalExchangeHelper
93 //====================================================================
94 /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
95 class SVX_DLLPUBLIC OLocalExchangeHelper
98 Window
* m_pDragSource
;
99 OLocalExchange
* m_pTransferable
;
102 OLocalExchangeHelper( Window
* _pDragSource
);
103 virtual ~OLocalExchangeHelper();
107 void startDrag( sal_Int8 nDragSourceActions
);
108 void copyToClipboard( ) const;
110 inline sal_Bool
isDragSource() const { return m_pTransferable
&& m_pTransferable
->isDragging(); }
111 inline sal_Bool
isClipboardOwner() const { return m_pTransferable
&& m_pTransferable
->isClipboardOwner(); }
112 inline sal_Bool
isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
113 inline void clear() { if ( isDataExchangeActive() ) m_pTransferable
->clear(); }
115 SVX_DLLPRIVATE
void setClipboardListener( const Link
& _rListener
) { if ( m_pTransferable
) m_pTransferable
->setClipboardListener( _rListener
); }
118 SVX_DLLPRIVATE
virtual OLocalExchange
* createExchange() const = 0;
121 SVX_DLLPRIVATE
void implReset();
124 //====================================================================
125 //= OControlTransferData
126 //====================================================================
127 class OControlTransferData
130 typedef ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< sal_uInt32
> > ControlPaths
;
133 DataFlavorExVector m_aCurrentFormats
;
136 ListBoxEntrySet m_aSelectedEntries
;
137 ControlPaths m_aControlPaths
;
138 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> >
139 m_aHiddenControlModels
;
141 ::com::sun::star::uno::Reference
< ::com::sun::star::form::XForms
>
142 m_xFormsRoot
; // the root of the forms collection where the entries we represent reside
143 // this uniquely identifies the page and the document
145 SvTreeListEntry
* m_pFocusEntry
;
148 // updates m_aCurrentFormats with all formats we currently could supply
149 void updateFormats( );
152 OControlTransferData( );
154 // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
155 OControlTransferData(
156 const ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XTransferable
>& _rxTransferable
159 inline const DataFlavorExVector
& GetDataFlavorExVector() const;
161 void addSelectedEntry( SvTreeListEntry
* _pEntry
);
162 void setFocusEntry( SvTreeListEntry
* _pFocusEntry
);
164 /** notifies the data transfer object that a certain entry has been removed from the owning tree
166 In case the removed entry is part of the transfer object's selection, the entry is removed from
170 @return the number of entries remaining in the selection.
172 size_t onEntryRemoved( SvTreeListEntry
* _pEntry
);
175 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XForms
>& _rxFormsRoot
176 ) { m_xFormsRoot
= _rxFormsRoot
; }
178 void buildPathFormat(SvTreeListBox
* pTreeBox
, SvTreeListEntry
* pRoot
);
179 // baut aus m_aSelectedEntries m_aControlPaths auf
180 // (es wird davon ausgegangen, dass die Eintraege in m_aSelectedEntries sortiert sind in Bezug auf die Nachbar-Beziehung)
183 void buildListFromPath(SvTreeListBox
* pTreeBox
, SvTreeListEntry
* pRoot
);
184 // der umgekehrte Weg : wirft alles aus m_aSelectedEntries weg und baut es mittels m_aControlPaths neu auf
186 void addHiddenControlsFormat(const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> > seqInterfaces
);
187 // fuegt ein SVX_FML_HIDDEN_CONTROLS-Format hinzu und merk sich dafuer die uebergebenen Interfaces
188 // (es erfolgt KEINE Ueberpruefung, ob dadurch auch tatsaechlich nur hidden Controls bezeichnet werden, dass muss der
189 // Aufrufer sicherstellen)
191 SvTreeListEntry
* focused() const { return m_pFocusEntry
; }
192 const ListBoxEntrySet
& selected() const { return m_aSelectedEntries
; }
193 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> >
194 hiddenControls() const { return m_aHiddenControlModels
; }
196 ::com::sun::star::uno::Reference
< ::com::sun::star::form::XForms
>
197 getFormsRoot() const { return m_xFormsRoot
; }
200 //====================================================================
201 inline const DataFlavorExVector
& OControlTransferData::GetDataFlavorExVector() const
203 const_cast< OControlTransferData
* >( this )->updateFormats( );
204 return m_aCurrentFormats
;
207 //====================================================================
209 //====================================================================
210 class OControlExchange
: public OLocalExchange
, public OControlTransferData
216 static sal_uInt32
getFieldExchangeFormatId( );
217 static sal_uInt32
getControlPathFormatId( );
218 static sal_uInt32
getHiddenControlModelsFormatId( );
220 inline static sal_Bool
hasFieldExchangeFormat( const DataFlavorExVector
& _rFormats
);
221 inline static sal_Bool
hasControlPathFormat( const DataFlavorExVector
& _rFormats
);
222 inline static sal_Bool
hasHiddenControlModelsFormat( const DataFlavorExVector
& _rFormats
);
225 virtual sal_Bool
GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
);
226 virtual void AddSupportedFormats();
229 //====================================================================
230 //= OControlExchangeHelper
231 //====================================================================
232 class OControlExchangeHelper
: public OLocalExchangeHelper
235 OControlExchangeHelper(Window
* _pDragSource
) : OLocalExchangeHelper(_pDragSource
) { }
237 OControlExchange
* operator->() const { return static_cast< OControlExchange
* >( m_pTransferable
); }
238 OControlExchange
& operator*() const { return *static_cast< OControlExchange
* >( m_pTransferable
); }
241 virtual OLocalExchange
* createExchange() const;
244 //====================================================================
245 //====================================================================
246 inline sal_Bool
OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector
& _rFormats
)
248 return hasFormat( _rFormats
, getFieldExchangeFormatId() );
251 inline sal_Bool
OControlExchange::hasControlPathFormat( const DataFlavorExVector
& _rFormats
)
253 return hasFormat( _rFormats
, getControlPathFormatId() );
256 inline sal_Bool
OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector
& _rFormats
)
258 return hasFormat( _rFormats
, getHiddenControlModelsFormatId() );
261 //........................................................................
262 } // namespace svxform
263 //........................................................................
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */