Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef _SVX_FMEXCH_HXX
20 : #define _SVX_FMEXCH_HXX
21 :
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>
28 :
29 : #include <svx/svxdllapi.h>
30 :
31 : class SvTreeListEntry;
32 :
33 : //========================================================================
34 : class SvTreeListBox;
35 :
36 : //........................................................................
37 : namespace svxform
38 : {
39 : //........................................................................
40 :
41 : //====================================================================
42 :
43 : typedef ::std::set< SvTreeListEntry* > ListBoxEntrySet;
44 :
45 : //====================================================================
46 : //= OLocalExchange
47 : //====================================================================
48 0 : class SVX_DLLPUBLIC OLocalExchange : public TransferableHelper
49 : {
50 : private:
51 : Link m_aClipboardListener;
52 : sal_Bool m_bDragging : 1;
53 : sal_Bool m_bClipboardOwner : 1;
54 :
55 : public:
56 : class GrantAccess
57 : {
58 : friend class OLocalExchangeHelper;
59 : };
60 :
61 : public:
62 : OLocalExchange( );
63 :
64 0 : sal_Bool isDragging() const { return m_bDragging; }
65 0 : sal_Bool isClipboardOwner() const { return m_bClipboardOwner; }
66 :
67 : void startDrag( Window* pWindow, sal_Int8 nDragSourceActions, const GrantAccess& );
68 : void copyToClipboard( Window* _pWindow, const GrantAccess& );
69 :
70 0 : void setClipboardListener( const Link& _rListener ) { m_aClipboardListener = _rListener; }
71 :
72 : void clear();
73 :
74 : static sal_Bool hasFormat( const DataFlavorExVector& _rFormats, sal_uInt32 _nFormatId );
75 :
76 : protected:
77 : // XClipboardOwner
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);
79 :
80 : // TransferableHelper
81 : virtual void DragFinished( sal_Int8 nDropAction );
82 : virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
83 :
84 : private:
85 0 : 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 0 : TransferableHelper::StartDrag(pWindow, nDragSourceActions, nDragPointer, nDragImage);
88 0 : }
89 : };
90 :
91 : //====================================================================
92 : //= OLocalExchangeHelper
93 : //====================================================================
94 : /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
95 : class SVX_DLLPUBLIC OLocalExchangeHelper
96 : {
97 : protected:
98 : Window* m_pDragSource;
99 : OLocalExchange* m_pTransferable;
100 :
101 : public:
102 : OLocalExchangeHelper( Window* _pDragSource );
103 : virtual ~OLocalExchangeHelper();
104 :
105 : void prepareDrag( );
106 :
107 : void startDrag( sal_Int8 nDragSourceActions );
108 : void copyToClipboard( ) const;
109 :
110 0 : inline sal_Bool isDragSource() const { return m_pTransferable && m_pTransferable->isDragging(); }
111 0 : inline sal_Bool isClipboardOwner() const { return m_pTransferable && m_pTransferable->isClipboardOwner(); }
112 0 : inline sal_Bool isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
113 0 : inline void clear() { if ( isDataExchangeActive() ) m_pTransferable->clear(); }
114 :
115 0 : SVX_DLLPRIVATE void setClipboardListener( const Link& _rListener ) { if ( m_pTransferable ) m_pTransferable->setClipboardListener( _rListener ); }
116 :
117 : protected:
118 : SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
119 :
120 : protected:
121 : SVX_DLLPRIVATE void implReset();
122 : };
123 :
124 : //====================================================================
125 : //= OControlTransferData
126 : //====================================================================
127 0 : class OControlTransferData
128 : {
129 : private:
130 : typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_uInt32 > > ControlPaths;
131 :
132 : private:
133 : DataFlavorExVector m_aCurrentFormats;
134 :
135 : protected:
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;
140 :
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
144 :
145 : SvTreeListEntry* m_pFocusEntry;
146 :
147 : protected:
148 : // updates m_aCurrentFormats with all formats we currently could supply
149 : void updateFormats( );
150 :
151 : public:
152 : OControlTransferData( );
153 :
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
157 : );
158 :
159 : inline const DataFlavorExVector& GetDataFlavorExVector() const;
160 :
161 : void addSelectedEntry( SvTreeListEntry* _pEntry );
162 : void setFocusEntry( SvTreeListEntry* _pFocusEntry );
163 :
164 : /** notifies the data transfer object that a certain entry has been removed from the owning tree
165 :
166 : In case the removed entry is part of the transfer object's selection, the entry is removed from
167 : the selection.
168 :
169 : @param _pEntry
170 : @return the number of entries remaining in the selection.
171 : */
172 : size_t onEntryRemoved( SvTreeListEntry* _pEntry );
173 :
174 0 : void setFormsRoot(
175 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForms >& _rxFormsRoot
176 0 : ) { m_xFormsRoot = _rxFormsRoot; }
177 :
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)
181 :
182 :
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
185 :
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)
190 :
191 : SvTreeListEntry* focused() const { return m_pFocusEntry; }
192 0 : const ListBoxEntrySet& selected() const { return m_aSelectedEntries; }
193 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
194 0 : hiddenControls() const { return m_aHiddenControlModels; }
195 :
196 : ::com::sun::star::uno::Reference< ::com::sun::star::form::XForms >
197 0 : getFormsRoot() const { return m_xFormsRoot; }
198 : };
199 :
200 : //====================================================================
201 0 : inline const DataFlavorExVector& OControlTransferData::GetDataFlavorExVector() const
202 : {
203 0 : const_cast< OControlTransferData* >( this )->updateFormats( );
204 0 : return m_aCurrentFormats;
205 : }
206 :
207 : //====================================================================
208 : //= OControlExchange
209 : //====================================================================
210 0 : class OControlExchange : public OLocalExchange, public OControlTransferData
211 : {
212 : public:
213 : OControlExchange( );
214 :
215 : public:
216 : static sal_uInt32 getFieldExchangeFormatId( );
217 : static sal_uInt32 getControlPathFormatId( );
218 : static sal_uInt32 getHiddenControlModelsFormatId( );
219 :
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 );
223 :
224 : protected:
225 : virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
226 : virtual void AddSupportedFormats();
227 : };
228 :
229 : //====================================================================
230 : //= OControlExchangeHelper
231 : //====================================================================
232 0 : class OControlExchangeHelper : public OLocalExchangeHelper
233 : {
234 : public:
235 0 : OControlExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
236 :
237 0 : OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_pTransferable ); }
238 0 : OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_pTransferable ); }
239 :
240 : protected:
241 : virtual OLocalExchange* createExchange() const;
242 : };
243 :
244 : //====================================================================
245 : //====================================================================
246 0 : inline sal_Bool OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector& _rFormats )
247 : {
248 0 : return hasFormat( _rFormats, getFieldExchangeFormatId() );
249 : }
250 :
251 0 : inline sal_Bool OControlExchange::hasControlPathFormat( const DataFlavorExVector& _rFormats )
252 : {
253 0 : return hasFormat( _rFormats, getControlPathFormatId() );
254 : }
255 :
256 0 : inline sal_Bool OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats )
257 : {
258 0 : return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
259 : }
260 :
261 : //........................................................................
262 : } // namespace svxform
263 : //........................................................................
264 :
265 : #endif
266 :
267 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|