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