LibreOffice Module svx (master) 1
fmexch.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_SVX_SOURCE_INC_FMEXCH_HXX
20#define INCLUDED_SVX_SOURCE_INC_FMEXCH_HXX
21
22#include <config_options.h>
23#include <sal/config.h>
24
25#include <set>
26
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>
35
36namespace svxform
37{
38 typedef ::std::set<std::unique_ptr<weld::TreeIter>> ListBoxEntrySet;
39
40 //= OLocalExchange
41 class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchange : public TransferDataContainer
42 {
43 private:
44 Link<OLocalExchange&,void> m_aClipboardListener;
45 bool m_bDragging : 1;
46 bool m_bClipboardOwner : 1;
47
48 public:
49 class GrantAccess
50 {
51 friend class OLocalExchangeHelper;
52 };
53
54 public:
55 OLocalExchange( );
56
57 bool isDragging() const { return m_bDragging; }
58 bool isClipboardOwner() const { return m_bClipboardOwner; }
59
60 void setDragging(bool bDragging);
61 SVXCORE_DLLPRIVATE void copyToClipboard(const weld::Widget& rWidget, const GrantAccess&);
62
63 void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { m_aClipboardListener = _rListener; }
64
65 SVXCORE_DLLPRIVATE void clear();
66
67 static bool hasFormat( const DataFlavorExVector& _rFormats, SotClipboardFormatId _nFormatId );
68
69 protected:
70 // XClipboardOwner
71 virtual void SAL_CALL lostOwnership( const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& _rxClipboard, const css::uno::Reference< css::datatransfer::XTransferable >& _rxTrans ) override;
72
73 // TransferableHelper
74 virtual void DragFinished( sal_Int8 nDropAction ) override;
75 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
76
77 private:
78 // don't allow this base class method to be called from outside
80 };
81
82
83 //= OLocalExchangeHelper
84
86 class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchangeHelper
87 {
88 protected:
89 rtl::Reference<OLocalExchange> m_xTransferable;
90
91 public:
92 OLocalExchangeHelper();
93 virtual ~OLocalExchangeHelper();
94
95 void prepareDrag( );
96
97 SVXCORE_DLLPRIVATE void copyToClipboard(const weld::Widget& rWidget) const;
98
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(); }
103
104 SVX_DLLPRIVATE void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { if ( m_xTransferable.is() ) m_xTransferable->setClipboardListener( _rListener ); }
105
106 protected:
107 SVX_DLLPRIVATE virtual rtl::Reference<OLocalExchange> createExchange() const = 0;
108
109 protected:
110 SVX_DLLPRIVATE void implReset();
111 };
112
114 {
115 private:
117
118 protected:
120 css::uno::Sequence< css::uno::Sequence< sal_uInt32 > >
122 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
124
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
128
130
131 protected:
132 // updates m_aCurrentFormats with all formats we currently could supply
133 void updateFormats( );
134
135 public:
137
138 // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
140 const css::uno::Reference< css::datatransfer::XTransferable >& _rxTransferable
141 );
142
143 inline const DataFlavorExVector& GetDataFlavorExVector() const;
144
145 void addSelectedEntry(std::unique_ptr<weld::TreeIter> xEntry);
146 void setFocusEntry(bool _bFocusEntry);
147
156 size_t onEntryRemoved(const weld::TreeView* pView, const weld::TreeIter* _pEntry);
157
159 const css::uno::Reference< css::form::XForms >& _rxFormsRoot
160 ) { m_xFormsRoot = _rxFormsRoot; }
161
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)
165
166
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
169
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)
174
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; }
178
179 const css::uno::Reference< css::form::XForms >&
180 getFormsRoot() const { return m_xFormsRoot; }
181 };
182
183
185 {
186 const_cast< OControlTransferData* >( this )->updateFormats( );
187 return m_aCurrentFormats;
188 }
189
190 class OControlExchange final : public OLocalExchange, public OControlTransferData
191 {
192 public:
194
195 public:
196 static SotClipboardFormatId getFieldExchangeFormatId( );
197 static SotClipboardFormatId getControlPathFormatId( );
198 static SotClipboardFormatId getHiddenControlModelsFormatId( );
199
200 inline static bool hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
201 inline static bool hasControlPathFormat( const DataFlavorExVector& _rFormats );
202 inline static bool hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
203
204 private:
205 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
206 virtual void AddSupportedFormats() override;
207 };
208
209 class OControlExchangeHelper final : public OLocalExchangeHelper
210 {
211 public:
212 OControlExchangeHelper() : OLocalExchangeHelper() { }
213
214 OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_xTransferable.get() ); }
215 OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_xTransferable.get() ); }
216
217 private:
218 virtual rtl::Reference<OLocalExchange> createExchange() const override;
219 };
220
221
223 {
224 return hasFormat( _rFormats, getFieldExchangeFormatId() );
225 }
226
228 {
229 return hasFormat( _rFormats, getControlPathFormatId() );
230 }
231
233 {
234 return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
235 }
236
237
238}
239
240
241#endif
242
243/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void StartDrag(vcl::Window *pWindow, sal_Int8 nDragSourceActions, const Link< sal_Int8, void > &rCallback)
OControlExchange * operator->() const
Definition: fmexch.hxx:214
OControlExchange & operator*() const
Definition: fmexch.hxx:215
static bool hasControlPathFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:227
static bool hasHiddenControlModelsFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:232
static bool hasFieldExchangeFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:222
const ListBoxEntrySet & selected() const
Definition: fmexch.hxx:175
DataFlavorExVector m_aCurrentFormats
Definition: fmexch.hxx:116
css::uno::Sequence< css::uno::Sequence< sal_uInt32 > > m_aControlPaths
Definition: fmexch.hxx:121
const css::uno::Reference< css::form::XForms > & getFormsRoot() const
Definition: fmexch.hxx:180
css::uno::Reference< css::form::XForms > m_xFormsRoot
Definition: fmexch.hxx:126
const DataFlavorExVector & GetDataFlavorExVector() const
Definition: fmexch.hxx:184
void setFormsRoot(const css::uno::Reference< css::form::XForms > &_rxFormsRoot)
Definition: fmexch.hxx:158
ListBoxEntrySet m_aSelectedEntries
Definition: fmexch.hxx:119
OControlTransferData(const css::uno::Reference< css::datatransfer::XTransferable > &_rxTransferable)
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > m_aHiddenControlModels
Definition: fmexch.hxx:123
const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > & hiddenControls() const
Definition: fmexch.hxx:177
::std::vector< DataFlavorEx > DataFlavorExVector
SotClipboardFormatId
class FmSearchEngine - Impl class for FmSearchDialog
::std::set< std::unique_ptr< weld::TreeIter > > ListBoxEntrySet
Definition: fmexch.hxx:38
#define SVX_DLLPRIVATE
Definition: svxdllapi.h:30
#define SVXCORE_DLLPRIVATE
Definition: svxdllapi.h:37
signed char sal_Int8