Bump version to 6.4-15
[LibreOffice.git] / svx / source / inc / fmexch.hxx
blob62f0c6cb682cfe6265ebcc18a9265b63d82f0fed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <set>
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;
37 class SvTreeListBox;
39 namespace svxform
43 typedef ::std::set< SvTreeListEntry* > ListBoxEntrySet;
46 //= OLocalExchange
48 class SVX_DLLPUBLIC OLocalExchange : public TransferableHelper
50 private:
51 Link<OLocalExchange&,void> m_aClipboardListener;
52 bool m_bDragging : 1;
53 bool m_bClipboardOwner : 1;
55 public:
56 class GrantAccess
58 friend class OLocalExchangeHelper;
61 public:
62 OLocalExchange( );
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; }
72 void clear();
74 static bool hasFormat( const DataFlavorExVector& _rFormats, SotClipboardFormatId _nFormatId );
76 protected:
77 // XClipboardOwner
78 virtual void SAL_CALL lostOwnership( const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& _rxClipboard, const css::uno::Reference< css::datatransfer::XTransferable >& _rxTrans ) override;
80 // TransferableHelper
81 virtual void DragFinished( sal_Int8 nDropAction ) override;
82 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
84 private:
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
95 protected:
96 VclPtr<vcl::Window> m_pDragSource;
97 rtl::Reference<OLocalExchange> m_xTransferable;
99 public:
100 OLocalExchangeHelper( vcl::Window* _pDragSource );
101 virtual ~OLocalExchangeHelper();
103 void prepareDrag( );
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 ); }
115 protected:
116 SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
118 protected:
119 SVX_DLLPRIVATE void implReset();
122 class OControlTransferData
124 private:
125 DataFlavorExVector m_aCurrentFormats;
127 protected:
128 ListBoxEntrySet m_aSelectedEntries;
129 css::uno::Sequence< css::uno::Sequence< sal_uInt32 > >
130 m_aControlPaths;
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;
140 protected:
141 // updates m_aCurrentFormats with all formats we currently could supply
142 void updateFormats( );
144 public:
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
160 the selection.
162 @param _pEntry
163 @return the number of entries remaining in the selection.
165 size_t onEntryRemoved( SvTreeListEntry* _pEntry );
167 void setFormsRoot(
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
201 public:
202 OControlExchange( );
204 public:
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 );
213 protected:
214 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
215 virtual void AddSupportedFormats() override;
218 class OControlExchangeHelper : public OLocalExchangeHelper
220 public:
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() ); }
226 protected:
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() );
250 #endif
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */