tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / svx / source / inc / fmexch.hxx
blobb8878e76d4fafb811fd061db14c4fe3364fc3137
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 <config_options.h>
23 #include <sal/config.h>
25 #include <set>
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>
36 namespace svxform
38 typedef ::std::set<std::unique_ptr<weld::TreeIter>> ListBoxEntrySet;
40 //= OLocalExchange
41 class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchange : public TransferDataContainer
43 private:
44 Link<OLocalExchange&,void> m_aClipboardListener;
45 bool m_bDragging : 1;
46 bool m_bClipboardOwner : 1;
48 public:
49 class GrantAccess
51 friend class OLocalExchangeHelper;
54 public:
55 OLocalExchange( );
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 );
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;
73 // TransferableHelper
74 virtual void DragFinished( sal_Int8 nDropAction ) override;
75 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
77 private:
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
88 protected:
89 rtl::Reference<OLocalExchange> m_xTransferable;
91 public:
92 OLocalExchangeHelper();
93 virtual ~OLocalExchangeHelper();
95 void prepareDrag( );
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 ); }
106 protected:
107 SVX_DLLPRIVATE virtual rtl::Reference<OLocalExchange> createExchange() const = 0;
109 protected:
110 SVX_DLLPRIVATE void implReset();
113 class OControlTransferData
115 private:
116 DataFlavorExVector m_aCurrentFormats;
118 protected:
119 ListBoxEntrySet m_aSelectedEntries;
120 css::uno::Sequence< css::uno::Sequence< sal_uInt32 > >
121 m_aControlPaths;
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
129 bool m_bFocusEntry;
131 protected:
132 // updates m_aCurrentFormats with all formats we currently could supply
133 void updateFormats( );
135 public:
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
151 the selection.
153 @param _pEntry
154 @return the number of entries remaining in the selection.
156 size_t onEntryRemoved(const weld::TreeView* pView, const weld::TreeIter* _pEntry);
158 void setFormsRoot(
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
192 public:
193 OControlExchange( );
195 public:
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 );
204 private:
205 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
206 virtual void AddSupportedFormats() override;
209 class OControlExchangeHelper final : public OLocalExchangeHelper
211 public:
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() ); }
217 private:
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() );
241 #endif
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */