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 <sal/config.h>
23 
24 #include <set>
25 
26 #include <sot/exchange.hxx>
27 #include <vcl/transfer.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/form/XForms.hpp>
30 #include <rtl/ref.hxx>
31 #include <tools/link.hxx>
32 #include <vcl/window.hxx>
33 #include <svx/svxdllapi.h>
34 
35 class SvTreeListEntry;
36 class SvTreeListBox;
37 
38 namespace svxform
39 {
40 
41 
42  typedef ::std::set< SvTreeListEntry* > ListBoxEntrySet;
43 
44 
45  //= OLocalExchange
46 
48  {
49  private:
51  bool m_bDragging : 1;
52  bool m_bClipboardOwner : 1;
53 
54  public:
56  {
57  friend class OLocalExchangeHelper;
58  };
59 
60  public:
61  OLocalExchange( );
62 
63  bool isDragging() const { return m_bDragging; }
64  bool isClipboardOwner() const { return m_bClipboardOwner; }
65 
66  void startDrag( vcl::Window* pWindow, sal_Int8 nDragSourceActions, const GrantAccess& );
67  void copyToClipboard( vcl::Window* _pWindow, const GrantAccess& );
68 
69  void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { m_aClipboardListener = _rListener; }
70 
71  void clear();
72 
73  static bool hasFormat( const DataFlavorExVector& _rFormats, SotClipboardFormatId _nFormatId );
74 
75  protected:
76  // XClipboardOwner
77  virtual void SAL_CALL lostOwnership( const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& _rxClipboard, const css::uno::Reference< css::datatransfer::XTransferable >& _rxTrans ) override;
78 
79  // TransferableHelper
80  virtual void DragFinished( sal_Int8 nDropAction ) override;
81  virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
82 
83  private:
84  // don't allow this base class method to be called from outside
86  };
87 
88 
89  //= OLocalExchangeHelper
90 
93  {
94  protected:
97 
98  public:
99  OLocalExchangeHelper( vcl::Window* _pDragSource );
100  virtual ~OLocalExchangeHelper();
101 
102  void prepareDrag( );
103 
104  void startDrag( sal_Int8 nDragSourceActions );
105  void copyToClipboard( ) const;
106 
107  bool isDragSource() const { return m_xTransferable.is() && m_xTransferable->isDragging(); }
108  bool isClipboardOwner() const { return m_xTransferable.is() && m_xTransferable->isClipboardOwner(); }
109  bool isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
110  void clear() { if ( isDataExchangeActive() ) m_xTransferable->clear(); }
111 
112  SVX_DLLPRIVATE void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { if ( m_xTransferable.is() ) m_xTransferable->setClipboardListener( _rListener ); }
113 
114  protected:
115  SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
116 
117  protected:
118  SVX_DLLPRIVATE void implReset();
119  };
120 
122  {
123  private:
125 
126  protected:
127  ListBoxEntrySet m_aSelectedEntries;
128  css::uno::Sequence< css::uno::Sequence< sal_uInt32 > >
130  css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
132 
133  css::uno::Reference< css::form::XForms >
134  m_xFormsRoot; // the root of the forms collection where the entries we represent reside
135  // this uniquely identifies the page and the document
136 
138 
139  protected:
140  // updates m_aCurrentFormats with all formats we currently could supply
141  void updateFormats( );
142 
143  public:
145 
146  // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
148  const css::uno::Reference< css::datatransfer::XTransferable >& _rxTransferable
149  );
150 
151  inline const DataFlavorExVector& GetDataFlavorExVector() const;
152 
153  void addSelectedEntry( SvTreeListEntry* _pEntry );
154  void setFocusEntry( SvTreeListEntry* _pFocusEntry );
155 
164  size_t onEntryRemoved( SvTreeListEntry* _pEntry );
165 
167  const css::uno::Reference< css::form::XForms >& _rxFormsRoot
168  ) { m_xFormsRoot = _rxFormsRoot; }
169 
170  void buildPathFormat(SvTreeListBox const * pTreeBox, SvTreeListEntry const * pRoot);
171  // assembles m_aControlPaths from m_aSelectedEntries
172  // (it is assumed that the entries are sorted in m_aSelectedEntries with respect to the neighbor relationship)
173 
174 
175  void buildListFromPath(SvTreeListBox const * pTreeBox, SvTreeListEntry* pRoot);
176  // The reverse way: throws everything out of m_aSelectedEntries and rebuilds it using m_aControlPaths
177 
178  void addHiddenControlsFormat(const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >& seqInterfaces);
179  // adds an SVX_FML_HIDDEN_CONTROLS format and remembers the passed interfaces for it
180  // (it is NOT checked whether actually only hidden controls are denominated
181  // by this - the caller must ensure that)
182 
183  const ListBoxEntrySet& selected() const { return m_aSelectedEntries; }
184  const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >&
186 
187  const css::uno::Reference< css::form::XForms >&
188  getFormsRoot() const { return m_xFormsRoot; }
189  };
190 
191 
193  {
194  const_cast< OControlTransferData* >( this )->updateFormats( );
195  return m_aCurrentFormats;
196  }
197 
199  {
200  public:
201  OControlExchange( );
202 
203  public:
207 
208  inline static bool hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
209  inline static bool hasControlPathFormat( const DataFlavorExVector& _rFormats );
210  inline static bool hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
211 
212  protected:
213  virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
214  virtual void AddSupportedFormats() override;
215  };
216 
218  {
219  public:
220  OControlExchangeHelper(vcl::Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
221 
222  OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_xTransferable.get() ); }
223  OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_xTransferable.get() ); }
224 
225  protected:
226  virtual OLocalExchange* createExchange() const override;
227  };
228 
229 
231  {
232  return hasFormat( _rFormats, getFieldExchangeFormatId() );
233  }
234 
236  {
237  return hasFormat( _rFormats, getControlPathFormatId() );
238  }
239 
241  {
242  return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
243  }
244 
245 
246 }
247 
248 
249 #endif
250 
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void AddSupportedFormats() override
Definition: fmexch.cxx:294
SvTreeListEntry * m_pFocusEntry
Definition: fmexch.hxx:137
static SotClipboardFormatId getHiddenControlModelsFormatId()
Definition: fmexch.cxx:316
signed char sal_Int8
::std::vector< DataFlavorEx > DataFlavorExVector
OControlExchange * operator->() const
Definition: fmexch.hxx:222
Link< OLocalExchange &, void > m_aClipboardListener
Definition: fmexch.hxx:50
OControlExchange & operator*() const
Definition: fmexch.hxx:223
css::uno::Sequence< css::uno::Sequence< sal_uInt32 > > m_aControlPaths
Definition: fmexch.hxx:129
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
Definition: fmexch.cxx:268
::std::set< SvTreeListEntry * > ListBoxEntrySet
Definition: fmexch.hxx:42
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > m_aHiddenControlModels
Definition: fmexch.hxx:131
VclPtr< vcl::Window > m_pDragSource
Definition: fmexch.hxx:95
bool isDataExchangeActive() const
Definition: fmexch.hxx:109
const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > & hiddenControls() const
Definition: fmexch.hxx:185
SotClipboardFormatId
static SotClipboardFormatId getFieldExchangeFormatId()
Definition: fmexch.cxx:325
virtual OLocalExchange * createExchange() const override
Definition: fmexch.cxx:336
OControlExchangeHelper(vcl::Window *_pDragSource)
Definition: fmexch.hxx:220
ListBoxEntrySet m_aSelectedEntries
Definition: fmexch.hxx:127
SVX_DLLPRIVATE void setClipboardListener(const Link< OLocalExchange &, void > &_rListener)
Definition: fmexch.hxx:112
bool isDragSource() const
Definition: fmexch.hxx:107
void addHiddenControlsFormat(const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > &seqInterfaces)
Definition: fmexch.cxx:203
rtl::Reference< OLocalExchange > m_xTransferable
Definition: fmexch.hxx:96
const css::uno::Reference< css::form::XForms > & getFormsRoot() const
Definition: fmexch.hxx:188
void buildPathFormat(SvTreeListBox const *pTreeBox, SvTreeListEntry const *pRoot)
Definition: fmexch.cxx:209
void StartDrag(vcl::Window *pWindow, sal_Int8 nDragSourceActions)
static bool hasFieldExchangeFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:230
static bool hasHiddenControlModelsFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:240
a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself ...
Definition: fmexch.hxx:92
bool isClipboardOwner() const
Definition: fmexch.hxx:108
const ListBoxEntrySet & selected() const
Definition: fmexch.hxx:183
void setFocusEntry(SvTreeListEntry *_pFocusEntry)
Definition: fmexch.cxx:197
static bool hasControlPathFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:235
size_t onEntryRemoved(SvTreeListEntry *_pEntry)
notifies the data transfer object that a certain entry has been removed from the owning tree ...
Definition: fmexch.cxx:184
bool isClipboardOwner() const
Definition: fmexch.hxx:64
void setClipboardListener(const Link< OLocalExchange &, void > &_rListener)
Definition: fmexch.hxx:69
class FmSearchEngine - Impl class for FmSearchDialog
const DataFlavorExVector & GetDataFlavorExVector() const
Definition: fmexch.hxx:192
void buildListFromPath(SvTreeListBox const *pTreeBox, SvTreeListEntry *pRoot)
Definition: fmexch.cxx:248
static SotClipboardFormatId getControlPathFormatId()
Definition: fmexch.cxx:307
#define SVX_DLLPRIVATE
Definition: svxdllapi.h:30
void setFormsRoot(const css::uno::Reference< css::form::XForms > &_rxFormsRoot)
Definition: fmexch.hxx:166
css::uno::Reference< css::form::XForms > m_xFormsRoot
Definition: fmexch.hxx:134
bool isDragging() const
Definition: fmexch.hxx:63
static bool hasFormat(const DataFlavorExVector &_rFormats, SotClipboardFormatId _nFormatId)
Definition: fmexch.cxx:100
void addSelectedEntry(SvTreeListEntry *_pEntry)
Definition: fmexch.cxx:191
DataFlavorExVector m_aCurrentFormats
Definition: fmexch.hxx:124