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/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>
35 
36 class SvTreeListEntry;
37 class SvTreeListBox;
38 
39 namespace svxform
40 {
41 
42 
43  typedef ::std::set< SvTreeListEntry* > ListBoxEntrySet;
44 
45 
46  //= OLocalExchange
47 
49  {
50  private:
52  bool m_bDragging : 1;
53  bool m_bClipboardOwner : 1;
54 
55  public:
57  {
58  friend class OLocalExchangeHelper;
59  };
60 
61  public:
62  OLocalExchange( );
63 
64  bool isDragging() const { return m_bDragging; }
65  bool isClipboardOwner() const { return m_bClipboardOwner; }
66 
67  void startDrag( vcl::Window* pWindow, sal_Int8 nDragSourceActions, const GrantAccess& );
68  void copyToClipboard( vcl::Window* _pWindow, const GrantAccess& );
69 
70  void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { m_aClipboardListener = _rListener; }
71 
72  void clear();
73 
74  static bool hasFormat( const DataFlavorExVector& _rFormats, SotClipboardFormatId _nFormatId );
75 
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;
79 
80  // TransferableHelper
81  virtual void DragFinished( sal_Int8 nDropAction ) override;
82  virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
83 
84  private:
85  // don't allow this base class method to be called from outside
87  };
88 
89 
90  //= OLocalExchangeHelper
91 
94  {
95  protected:
98 
99  public:
100  OLocalExchangeHelper( vcl::Window* _pDragSource );
101  virtual ~OLocalExchangeHelper();
102 
103  void prepareDrag( );
104 
105  void startDrag( sal_Int8 nDragSourceActions );
106  void copyToClipboard( ) const;
107 
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(); }
112 
113  SVX_DLLPRIVATE void setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { if ( m_xTransferable.is() ) m_xTransferable->setClipboardListener( _rListener ); }
114 
115  protected:
116  SVX_DLLPRIVATE virtual OLocalExchange* createExchange() const = 0;
117 
118  protected:
119  SVX_DLLPRIVATE void implReset();
120  };
121 
123  {
124  private:
126 
127  protected:
128  ListBoxEntrySet m_aSelectedEntries;
129  css::uno::Sequence< css::uno::Sequence< sal_uInt32 > >
131  css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
133 
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
137 
139 
140  protected:
141  // updates m_aCurrentFormats with all formats we currently could supply
142  void updateFormats( );
143 
144  public:
146 
147  // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
149  const css::uno::Reference< css::datatransfer::XTransferable >& _rxTransferable
150  );
151 
152  inline const DataFlavorExVector& GetDataFlavorExVector() const;
153 
154  void addSelectedEntry( SvTreeListEntry* _pEntry );
155  void setFocusEntry( SvTreeListEntry* _pFocusEntry );
156 
165  size_t onEntryRemoved( SvTreeListEntry* _pEntry );
166 
168  const css::uno::Reference< css::form::XForms >& _rxFormsRoot
169  ) { m_xFormsRoot = _rxFormsRoot; }
170 
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)
174 
175 
176  void buildListFromPath(SvTreeListBox const * pTreeBox, SvTreeListEntry* pRoot);
177  // The reverse way: throws everything out of m_aSelectedEntries and rebuilds it using m_aControlPaths
178 
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)
183 
184  const ListBoxEntrySet& selected() const { return m_aSelectedEntries; }
185  const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >&
187 
188  const css::uno::Reference< css::form::XForms >&
189  getFormsRoot() const { return m_xFormsRoot; }
190  };
191 
192 
194  {
195  const_cast< OControlTransferData* >( this )->updateFormats( );
196  return m_aCurrentFormats;
197  }
198 
200  {
201  public:
202  OControlExchange( );
203 
204  public:
208 
209  inline static bool hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
210  inline static bool hasControlPathFormat( const DataFlavorExVector& _rFormats );
211  inline static bool hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
212 
213  protected:
214  virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
215  virtual void AddSupportedFormats() override;
216  };
217 
219  {
220  public:
221  OControlExchangeHelper(vcl::Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
222 
223  OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_xTransferable.get() ); }
224  OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_xTransferable.get() ); }
225 
226  protected:
227  virtual OLocalExchange* createExchange() const override;
228  };
229 
230 
232  {
233  return hasFormat( _rFormats, getFieldExchangeFormatId() );
234  }
235 
237  {
238  return hasFormat( _rFormats, getControlPathFormatId() );
239  }
240 
242  {
243  return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
244  }
245 
246 
247 }
248 
249 
250 #endif
251 
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void AddSupportedFormats() override
Definition: fmexch.cxx:294
SvTreeListEntry * m_pFocusEntry
Definition: fmexch.hxx:138
static SotClipboardFormatId getHiddenControlModelsFormatId()
Definition: fmexch.cxx:316
signed char sal_Int8
::std::vector< DataFlavorEx > DataFlavorExVector
OControlExchange * operator->() const
Definition: fmexch.hxx:223
Link< OLocalExchange &, void > m_aClipboardListener
Definition: fmexch.hxx:51
OControlExchange & operator*() const
Definition: fmexch.hxx:224
css::uno::Sequence< css::uno::Sequence< sal_uInt32 > > m_aControlPaths
Definition: fmexch.hxx:130
#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:43
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > m_aHiddenControlModels
Definition: fmexch.hxx:132
VclPtr< vcl::Window > m_pDragSource
Definition: fmexch.hxx:96
bool isDataExchangeActive() const
Definition: fmexch.hxx:110
const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > & hiddenControls() const
Definition: fmexch.hxx:186
SotClipboardFormatId
static SotClipboardFormatId getFieldExchangeFormatId()
Definition: fmexch.cxx:325
virtual OLocalExchange * createExchange() const override
Definition: fmexch.cxx:336
OControlExchangeHelper(vcl::Window *_pDragSource)
Definition: fmexch.hxx:221
ListBoxEntrySet m_aSelectedEntries
Definition: fmexch.hxx:128
SVX_DLLPRIVATE void setClipboardListener(const Link< OLocalExchange &, void > &_rListener)
Definition: fmexch.hxx:113
bool isDragSource() const
Definition: fmexch.hxx:108
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:97
const css::uno::Reference< css::form::XForms > & getFormsRoot() const
Definition: fmexch.hxx:189
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:231
static bool hasHiddenControlModelsFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:241
a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself ...
Definition: fmexch.hxx:93
bool isClipboardOwner() const
Definition: fmexch.hxx:109
const ListBoxEntrySet & selected() const
Definition: fmexch.hxx:184
void setFocusEntry(SvTreeListEntry *_pFocusEntry)
Definition: fmexch.cxx:197
static bool hasControlPathFormat(const DataFlavorExVector &_rFormats)
Definition: fmexch.hxx:236
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:65
void setClipboardListener(const Link< OLocalExchange &, void > &_rListener)
Definition: fmexch.hxx:70
class FmSearchEngine - Impl class for FmSearchDialog
const DataFlavorExVector & GetDataFlavorExVector() const
Definition: fmexch.hxx:193
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:167
css::uno::Reference< css::form::XForms > m_xFormsRoot
Definition: fmexch.hxx:135
bool isDragging() const
Definition: fmexch.hxx:64
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:125