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