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 <config_options.h>
23 #include <sal/config.h>
27 #include <sot/exchange.hxx>
28 #include <vcl/transfer.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/form/XForms.hpp>
31 #include <rtl/ref.hxx>
32 #include <tools/link.hxx>
33 #include <vcl/weld.hxx>
34 #include <svx/svxdllapi.h>
38 typedef ::std::set
<std::unique_ptr
<weld::TreeIter
>> ListBoxEntrySet
;
41 class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC
) OLocalExchange
: public TransferDataContainer
44 Link
<OLocalExchange
&,void> m_aClipboardListener
;
46 bool m_bClipboardOwner
: 1;
51 friend class OLocalExchangeHelper
;
57 bool isDragging() const { return m_bDragging
; }
58 bool isClipboardOwner() const { return m_bClipboardOwner
; }
60 void setDragging(bool bDragging
);
61 SVXCORE_DLLPRIVATE
void copyToClipboard(const weld::Widget
& rWidget
, const GrantAccess
&);
63 void setClipboardListener( const Link
<OLocalExchange
&,void>& _rListener
) { m_aClipboardListener
= _rListener
; }
65 SVXCORE_DLLPRIVATE
void clear();
67 static bool hasFormat( const DataFlavorExVector
& _rFormats
, SotClipboardFormatId _nFormatId
);
71 virtual void SAL_CALL
lostOwnership( const css::uno::Reference
< css::datatransfer::clipboard::XClipboard
>& _rxClipboard
, const css::uno::Reference
< css::datatransfer::XTransferable
>& _rxTrans
) override
;
74 virtual void DragFinished( sal_Int8 nDropAction
) override
;
75 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
78 // don't allow this base class method to be called from outside
79 using TransferDataContainer::StartDrag
;
83 //= OLocalExchangeHelper
85 /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
86 class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC
) OLocalExchangeHelper
89 rtl::Reference
<OLocalExchange
> m_xTransferable
;
92 OLocalExchangeHelper();
93 virtual ~OLocalExchangeHelper();
97 SVXCORE_DLLPRIVATE
void copyToClipboard(const weld::Widget
& rWidget
) const;
99 bool isDragSource() const { return m_xTransferable
.is() && m_xTransferable
->isDragging(); }
100 bool isClipboardOwner() const { return m_xTransferable
.is() && m_xTransferable
->isClipboardOwner(); }
101 bool isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
102 void clear() { if ( isDataExchangeActive() ) m_xTransferable
->clear(); }
104 SVX_DLLPRIVATE
void setClipboardListener( const Link
<OLocalExchange
&,void>& _rListener
) { if ( m_xTransferable
.is() ) m_xTransferable
->setClipboardListener( _rListener
); }
107 SVX_DLLPRIVATE
virtual rtl::Reference
<OLocalExchange
> createExchange() const = 0;
110 SVX_DLLPRIVATE
void implReset();
113 class OControlTransferData
116 DataFlavorExVector m_aCurrentFormats
;
119 ListBoxEntrySet m_aSelectedEntries
;
120 css::uno::Sequence
< css::uno::Sequence
< sal_uInt32
> >
122 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >
123 m_aHiddenControlModels
;
125 css::uno::Reference
< css::form::XForms
>
126 m_xFormsRoot
; // the root of the forms collection where the entries we represent reside
127 // this uniquely identifies the page and the document
132 // updates m_aCurrentFormats with all formats we currently could supply
133 void updateFormats( );
136 OControlTransferData( );
138 // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
139 OControlTransferData(
140 const css::uno::Reference
< css::datatransfer::XTransferable
>& _rxTransferable
143 inline const DataFlavorExVector
& GetDataFlavorExVector() const;
145 void addSelectedEntry(std::unique_ptr
<weld::TreeIter
> xEntry
);
146 void setFocusEntry(bool _bFocusEntry
);
148 /** notifies the data transfer object that a certain entry has been removed from the owning tree
150 In case the removed entry is part of the transfer object's selection, the entry is removed from
154 @return the number of entries remaining in the selection.
156 size_t onEntryRemoved(const weld::TreeView
* pView
, const weld::TreeIter
* _pEntry
);
159 const css::uno::Reference
< css::form::XForms
>& _rxFormsRoot
160 ) { m_xFormsRoot
= _rxFormsRoot
; }
162 void buildPathFormat(const weld::TreeView
* pTreeBox
, const weld::TreeIter
* pRoot
);
163 // assembles m_aControlPaths from m_aSelectedEntries
164 // (it is assumed that the entries are sorted in m_aSelectedEntries with respect to the neighbor relationship)
167 void buildListFromPath(const weld::TreeView
* pTreeBox
, const weld::TreeIter
* pRoot
);
168 // The reverse way: throws everything out of m_aSelectedEntries and rebuilds it using m_aControlPaths
170 void addHiddenControlsFormat(const css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >& seqInterfaces
);
171 // adds an SVX_FML_HIDDEN_CONTROLS format and remembers the passed interfaces for it
172 // (it is NOT checked whether actually only hidden controls are denominated
173 // by this - the caller must ensure that)
175 const ListBoxEntrySet
& selected() const { return m_aSelectedEntries
; }
176 const css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >&
177 hiddenControls() const { return m_aHiddenControlModels
; }
179 const css::uno::Reference
< css::form::XForms
>&
180 getFormsRoot() const { return m_xFormsRoot
; }
184 inline const DataFlavorExVector
& OControlTransferData::GetDataFlavorExVector() const
186 const_cast< OControlTransferData
* >( this )->updateFormats( );
187 return m_aCurrentFormats
;
190 class OControlExchange final
: public OLocalExchange
, public OControlTransferData
196 static SotClipboardFormatId
getFieldExchangeFormatId( );
197 static SotClipboardFormatId
getControlPathFormatId( );
198 static SotClipboardFormatId
getHiddenControlModelsFormatId( );
200 inline static bool hasFieldExchangeFormat( const DataFlavorExVector
& _rFormats
);
201 inline static bool hasControlPathFormat( const DataFlavorExVector
& _rFormats
);
202 inline static bool hasHiddenControlModelsFormat( const DataFlavorExVector
& _rFormats
);
205 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
206 virtual void AddSupportedFormats() override
;
209 class OControlExchangeHelper final
: public OLocalExchangeHelper
212 OControlExchangeHelper() : OLocalExchangeHelper() { }
214 OControlExchange
* operator->() const { return static_cast< OControlExchange
* >( m_xTransferable
.get() ); }
215 OControlExchange
& operator*() const { return *static_cast< OControlExchange
* >( m_xTransferable
.get() ); }
218 virtual rtl::Reference
<OLocalExchange
> createExchange() const override
;
222 inline bool OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector
& _rFormats
)
224 return hasFormat( _rFormats
, getFieldExchangeFormatId() );
227 inline bool OControlExchange::hasControlPathFormat( const DataFlavorExVector
& _rFormats
)
229 return hasFormat( _rFormats
, getControlPathFormatId() );
232 inline bool OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector
& _rFormats
)
234 return hasFormat( _rFormats
, getHiddenControlModelsFormatId() );
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */