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 <vcl/window.hxx>
35 #include <svx/svxdllapi.h>
36 
37 namespace svxform
38 {
39  typedef ::std::set<std::unique_ptr<weld::TreeIter>> ListBoxEntrySet;
40 
41  //= OLocalExchange
42  class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchange : public TransferDataContainer
43  {
44  private:
45  Link<OLocalExchange&,void> m_aClipboardListener;
46  bool m_bDragging : 1;
47  bool m_bClipboardOwner : 1;
48 
49  public:
50  class GrantAccess
51  {
52  friend class OLocalExchangeHelper;
53  };
54 
55  public:
56  OLocalExchange( );
57 
58  bool isDragging() const { return m_bDragging; }
59  bool isClipboardOwner() const { return m_bClipboardOwner; }
60 
61  void setDragging(bool bDragging);
62  void startDrag( vcl::Window* pWindow, sal_Int8 nDragSourceActions, const GrantAccess& );
63  void copyToClipboard(const GrantAccess&);
64 
65  void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { m_aClipboardListener = _rListener; }
66 
67  void clear();
68 
69  static bool hasFormat( const DataFlavorExVector& _rFormats, SotClipboardFormatId _nFormatId );
70 
71  protected:
72  // XClipboardOwner
73  virtual void SAL_CALL lostOwnership( const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& _rxClipboard, const css::uno::Reference< css::datatransfer::XTransferable >& _rxTrans ) override;
74 
75  // TransferableHelper
76  virtual void DragFinished( sal_Int8 nDropAction ) override;
77  virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
78 
79  private:
80  // don't allow this base class method to be called from outside
82  };
83 
84 
85  //= OLocalExchangeHelper
86 
88  class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchangeHelper
89  {
90  protected:
91  rtl::Reference<OLocalExchange> m_xTransferable;
92 
93  public:
94  OLocalExchangeHelper();
95  virtual ~OLocalExchangeHelper();
96 
97  void prepareDrag( );
98 
99  void copyToClipboard( ) const;
100 
101  bool isDragSource() const { return m_xTransferable.is() && m_xTransferable->isDragging(); }
102  bool isClipboardOwner() const { return m_xTransferable.is() && m_xTransferable->isClipboardOwner(); }
103  bool isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
104  void clear() { if ( isDataExchangeActive() ) m_xTransferable->clear(); }
105 
106  SVX_DLLPRIVATE void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { if ( m_xTransferable.is() ) m_xTransferable->setClipboardListener( _rListener ); }
107 
108  protected:
109  SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
110 
111  protected:
112  SVX_DLLPRIVATE void implReset();
113  };
114 
116  {
117  private:
119 
120  protected:
121  ListBoxEntrySet m_aSelectedEntries;
122  css::uno::Sequence< css::uno::Sequence< sal_uInt32 > >
124  css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
126 
127  css::uno::Reference< css::form::XForms >
128  m_xFormsRoot; // the root of the forms collection where the entries we represent reside
129  // this uniquely identifies the page and the document
130 
132 
133  protected:
134  // updates m_aCurrentFormats with all formats we currently could supply
135  void updateFormats( );
136 
137  public:
139 
140  // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
142  const css::uno::Reference< css::datatransfer::XTransferable >& _rxTransferable
143  );
144 
145  inline const DataFlavorExVector& GetDataFlavorExVector() const;
146 
147  void addSelectedEntry(std::unique_ptr<weld::TreeIter> xEntry);
148  void setFocusEntry(bool _bFocusEntry);
149 
158  size_t onEntryRemoved(weld::TreeView* pView, weld::TreeIter* _pEntry);
159 
161  const css::uno::Reference< css::form::XForms >& _rxFormsRoot
162  ) { m_xFormsRoot = _rxFormsRoot; }
163 
164  void buildPathFormat(const weld::TreeView* pTreeBox, const weld::TreeIter* pRoot);
165  // assembles m_aControlPaths from m_aSelectedEntries
166  // (it is assumed that the entries are sorted in m_aSelectedEntries with respect to the neighbor relationship)
167 
168 
169  void buildListFromPath(const weld::TreeView* pTreeBox, weld::TreeIter* pRoot);
170  // The reverse way: throws everything out of m_aSelectedEntries and rebuilds it using m_aControlPaths
171 
172  void addHiddenControlsFormat(const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >& seqInterfaces);
173  // adds an SVX_FML_HIDDEN_CONTROLS format and remembers the passed interfaces for it
174  // (it is NOT checked whether actually only hidden controls are denominated
175  // by this - the caller must ensure that)
176 
177  const ListBoxEntrySet& selected() const { return m_aSelectedEntries; }
178  const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >&
179  hiddenControls() const { return m_aHiddenControlModels; }
180 
181  const css::uno::Reference< css::form::XForms >&
182  getFormsRoot() const { return m_xFormsRoot; }
183  };
184 
185 
187  {
188  const_cast< OControlTransferData* >( this )->updateFormats( );
189  return m_aCurrentFormats;
190  }
191 
192  class OControlExchange : public OLocalExchange, public OControlTransferData
193  {
194  public:
195  OControlExchange( );
196 
197  public:
198  static SotClipboardFormatId getFieldExchangeFormatId( );
199  static SotClipboardFormatId getControlPathFormatId( );
200  static SotClipboardFormatId getHiddenControlModelsFormatId( );
201 
202  inline static bool hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
203  inline static bool hasControlPathFormat( const DataFlavorExVector& _rFormats );
204  inline static bool hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
205 
206  protected:
207  virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
208  virtual void AddSupportedFormats() override;
209  };
210 
211  class OControlExchangeHelper : public OLocalExchangeHelper
212  {
213  public:
214  OControlExchangeHelper() : OLocalExchangeHelper() { }
215 
216  OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_xTransferable.get() ); }
217  OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_xTransferable.get() ); }
218 
219  protected:
220  virtual OLocalExchange* createExchange() const override;
221  };
222 
223 
225  {
226  return hasFormat( _rFormats, getFieldExchangeFormatId() );
227  }
228 
230  {
231  return hasFormat( _rFormats, getControlPathFormatId() );
232  }
233 
235  {
236  return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
237  }
238 
239 
240 }
241 
242 
243 #endif
244 
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::set< std::unique_ptr< weld::TreeIter > > ListBoxEntrySet
Definition: fmexch.hxx:39
signed char sal_Int8
::std::vector< DataFlavorEx > DataFlavorExVector
OControlExchange * operator->() const
Definition: fmexch.hxx:216
OControlExchange & operator*() const
Definition: fmexch.hxx:217
css::uno::Sequence< css::uno::Sequence< sal_uInt32 > > m_aControlPaths
Definition: fmexch.hxx:123
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > m_aHiddenControlModels
Definition: fmexch.hxx:125
const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > & hiddenControls() const
Definition: fmexch.hxx:179
SotClipboardFormatId
void StartDrag(vcl::Window *pWindow, sal_Int8 nDragSourceActions, const Link< sal_Int8, void > &rCallbck)
ListBoxEntrySet m_aSelectedEntries
Definition: fmexch.hxx:121
const css::uno::Reference< css::form::XForms > & getFormsRoot() const
Definition: fmexch.hxx:182
static bool hasFieldExchangeFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:224
static bool hasHiddenControlModelsFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:234
const ListBoxEntrySet & selected() const
Definition: fmexch.hxx:177
static bool hasControlPathFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:229
class FmSearchEngine - Impl class for FmSearchDialog
const DataFlavorExVector & GetDataFlavorExVector() const
Definition: fmexch.hxx:186
#define SVX_DLLPRIVATE
Definition: svxdllapi.h:30
void setFormsRoot(const css::uno::Reference< css::form::XForms > &_rxFormsRoot)
Definition: fmexch.hxx:160
css::uno::Reference< css::form::XForms > m_xFormsRoot
Definition: fmexch.hxx:128
DataFlavorExVector m_aCurrentFormats
Definition: fmexch.hxx:118