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 INCLUDED_SVX_SOURCE_INC_FMEXCH_HXX
20 #define INCLUDED_SVX_SOURCE_INC_FMEXCH_HXX
22 #include <sal/config.h>
26 #include <sot/exchange.hxx>
27 #include <vcl/transfer.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <com/sun/star/form/XForms.hpp>
31 #include <rtl/ref.hxx>
32 #include <tools/link.hxx>
33 #include <vcl/window.hxx>
34 #include <svx/svxdllapi.h>
36 class SvTreeListEntry
;
43 typedef ::std::set
< SvTreeListEntry
* > ListBoxEntrySet
;
48 class SVX_DLLPUBLIC OLocalExchange
: public TransferableHelper
51 Link
<OLocalExchange
&,void> m_aClipboardListener
;
53 bool m_bClipboardOwner
: 1;
58 friend class OLocalExchangeHelper
;
64 bool isDragging() const { return m_bDragging
; }
65 bool isClipboardOwner() const { return m_bClipboardOwner
; }
67 void startDrag( vcl::Window
* pWindow
, sal_Int8 nDragSourceActions
, const GrantAccess
& );
68 void copyToClipboard( vcl::Window
* _pWindow
, const GrantAccess
& );
70 void setClipboardListener( const Link
<OLocalExchange
&,void>& _rListener
) { m_aClipboardListener
= _rListener
; }
74 static bool hasFormat( const DataFlavorExVector
& _rFormats
, SotClipboardFormatId _nFormatId
);
78 virtual void SAL_CALL
lostOwnership( const css::uno::Reference
< css::datatransfer::clipboard::XClipboard
>& _rxClipboard
, const css::uno::Reference
< css::datatransfer::XTransferable
>& _rxTrans
) override
;
81 virtual void DragFinished( sal_Int8 nDropAction
) override
;
82 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
85 // don't allow this base class method to be called from outside
86 using TransferableHelper::StartDrag
;
90 //= OLocalExchangeHelper
92 /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
93 class SVX_DLLPUBLIC OLocalExchangeHelper
96 VclPtr
<vcl::Window
> m_pDragSource
;
97 rtl::Reference
<OLocalExchange
> m_xTransferable
;
100 OLocalExchangeHelper( vcl::Window
* _pDragSource
);
101 virtual ~OLocalExchangeHelper();
105 void startDrag( sal_Int8 nDragSourceActions
);
106 void copyToClipboard( ) const;
108 bool isDragSource() const { return m_xTransferable
.is() && m_xTransferable
->isDragging(); }
109 bool isClipboardOwner() const { return m_xTransferable
.is() && m_xTransferable
->isClipboardOwner(); }
110 bool isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
111 void clear() { if ( isDataExchangeActive() ) m_xTransferable
->clear(); }
113 SVX_DLLPRIVATE
void setClipboardListener( const Link
<OLocalExchange
&,void>& _rListener
) { if ( m_xTransferable
.is() ) m_xTransferable
->setClipboardListener( _rListener
); }
116 SVX_DLLPRIVATE
virtual OLocalExchange
* createExchange() const = 0;
119 SVX_DLLPRIVATE
void implReset();
122 class OControlTransferData
125 DataFlavorExVector m_aCurrentFormats
;
128 ListBoxEntrySet m_aSelectedEntries
;
129 css::uno::Sequence
< css::uno::Sequence
< sal_uInt32
> >
131 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >
132 m_aHiddenControlModels
;
134 css::uno::Reference
< css::form::XForms
>
135 m_xFormsRoot
; // the root of the forms collection where the entries we represent reside
136 // this uniquely identifies the page and the document
138 SvTreeListEntry
* m_pFocusEntry
;
141 // updates m_aCurrentFormats with all formats we currently could supply
142 void updateFormats( );
145 OControlTransferData( );
147 // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
148 OControlTransferData(
149 const css::uno::Reference
< css::datatransfer::XTransferable
>& _rxTransferable
152 inline const DataFlavorExVector
& GetDataFlavorExVector() const;
154 void addSelectedEntry( SvTreeListEntry
* _pEntry
);
155 void setFocusEntry( SvTreeListEntry
* _pFocusEntry
);
157 /** notifies the data transfer object that a certain entry has been removed from the owning tree
159 In case the removed entry is part of the transfer object's selection, the entry is removed from
163 @return the number of entries remaining in the selection.
165 size_t onEntryRemoved( SvTreeListEntry
* _pEntry
);
168 const css::uno::Reference
< css::form::XForms
>& _rxFormsRoot
169 ) { m_xFormsRoot
= _rxFormsRoot
; }
171 void buildPathFormat(SvTreeListBox
const * pTreeBox
, SvTreeListEntry
const * pRoot
);
172 // assembles m_aControlPaths from m_aSelectedEntries
173 // (it is assumed that the entries are sorted in m_aSelectedEntries with respect to the neighbor relationship)
176 void buildListFromPath(SvTreeListBox
const * pTreeBox
, SvTreeListEntry
* pRoot
);
177 // The reverse way: throws everything out of m_aSelectedEntries and rebuilds it using m_aControlPaths
179 void addHiddenControlsFormat(const css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >& seqInterfaces
);
180 // adds an SVX_FML_HIDDEN_CONTROLS format and remembers the passed interfaces for it
181 // (it is NOT checked whether actually only hidden controls are denominated
182 // by this - the caller must ensure that)
184 const ListBoxEntrySet
& selected() const { return m_aSelectedEntries
; }
185 const css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >&
186 hiddenControls() const { return m_aHiddenControlModels
; }
188 const css::uno::Reference
< css::form::XForms
>&
189 getFormsRoot() const { return m_xFormsRoot
; }
193 inline const DataFlavorExVector
& OControlTransferData::GetDataFlavorExVector() const
195 const_cast< OControlTransferData
* >( this )->updateFormats( );
196 return m_aCurrentFormats
;
199 class OControlExchange
: public OLocalExchange
, public OControlTransferData
205 static SotClipboardFormatId
getFieldExchangeFormatId( );
206 static SotClipboardFormatId
getControlPathFormatId( );
207 static SotClipboardFormatId
getHiddenControlModelsFormatId( );
209 inline static bool hasFieldExchangeFormat( const DataFlavorExVector
& _rFormats
);
210 inline static bool hasControlPathFormat( const DataFlavorExVector
& _rFormats
);
211 inline static bool hasHiddenControlModelsFormat( const DataFlavorExVector
& _rFormats
);
214 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
215 virtual void AddSupportedFormats() override
;
218 class OControlExchangeHelper
: public OLocalExchangeHelper
221 OControlExchangeHelper(vcl::Window
* _pDragSource
) : OLocalExchangeHelper(_pDragSource
) { }
223 OControlExchange
* operator->() const { return static_cast< OControlExchange
* >( m_xTransferable
.get() ); }
224 OControlExchange
& operator*() const { return *static_cast< OControlExchange
* >( m_xTransferable
.get() ); }
227 virtual OLocalExchange
* createExchange() const override
;
231 inline bool OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector
& _rFormats
)
233 return hasFormat( _rFormats
, getFieldExchangeFormatId() );
236 inline bool OControlExchange::hasControlPathFormat( const DataFlavorExVector
& _rFormats
)
238 return hasFormat( _rFormats
, getControlPathFormatId() );
241 inline bool OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector
& _rFormats
)
243 return hasFormat( _rFormats
, getHiddenControlModelsFormatId() );
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */