LibreOffice Module svx (master)  1
filtnav.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_FILTNAV_HXX
20 #define INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX
21 
22 #include <com/sun/star/form/XForm.hpp>
23 #include <com/sun/star/form/runtime/XFormController.hpp>
24 #include <com/sun/star/form/runtime/XFilterController.hpp>
25 #include <svl/lstner.hxx>
26 #include <svl/SfxBroadcaster.hxx>
27 
28 #include <vcl/window.hxx>
29 #include <sfx2/childwin.hxx>
30 #include <svl/poolitem.hxx>
31 #include <sfx2/bindings.hxx>
32 #include <sfx2/dockwin.hxx>
33 #include <sfx2/ctrlitem.hxx>
34 #include <vcl/image.hxx>
35 #include <vcl/treelistbox.hxx>
36 
37 #include <svx/fmtools.hxx>
38 #include "fmexch.hxx"
39 #include "sqlparserclient.hxx"
40 
41 class FmFormShell;
42 
43 
44 namespace svxform
45 {
46 
47 
48 class FmFilterItem;
49 class FmFilterItems;
50 class FmParentData;
51 class FmFilterAdapter;
52 
53 
54 // data structure for the filter model
55 
57 {
59  OUString m_aText;
60 
61 public:
62  FmFilterData(FmParentData* pParent, const OUString& rText)
63  :m_pParent( pParent )
64  ,m_aText( rText )
65  {}
66  virtual ~FmFilterData(){}
67 
68  void SetText( const OUString& rText ){ m_aText = rText; }
69  const OUString& GetText() const { return m_aText; }
70  FmParentData* GetParent() const {return m_pParent;}
71 
72  virtual Image GetImage() const;
73 };
74 
75 
76 class FmParentData : public FmFilterData
77 {
78 protected:
79  ::std::vector< std::unique_ptr<FmFilterData> > m_aChildren;
80 
81 public:
82  FmParentData(FmParentData* pParent, const OUString& rText)
83  : FmFilterData(pParent, rText)
84  {}
85  virtual ~FmParentData() override;
86 
87  ::std::vector< std::unique_ptr<FmFilterData> >& GetChildren() { return m_aChildren; }
88 };
89 
90 
91 // Item representing the forms and subforms
92 class FmFormItem : public FmParentData
93 {
94  css::uno::Reference< css::form::runtime::XFormController > m_xController;
95  css::uno::Reference< css::form::runtime::XFilterController > m_xFilterController;
96 
97 public:
98 
100  const css::uno::Reference< css::form::runtime::XFormController > & _xController,
101  const OUString& _rText)
102  :FmParentData( _pParent, _rText )
103  ,m_xController( _xController )
104  ,m_xFilterController( _xController, css::uno::UNO_QUERY_THROW )
105  {
106  }
107 
108  const css::uno::Reference< css::form::runtime::XFormController >&
109  GetController() const { return m_xController; }
110 
111  const css::uno::Reference< css::form::runtime::XFilterController >&
113 
114  virtual Image GetImage() const override;
115 };
116 
117 
119 {
120 public:
121  FmFilterItems(FmFormItem* pParent, const OUString& rText ) : FmParentData(pParent, rText) {}
122 
123  FmFilterItem* Find( const ::sal_Int32 _nFilterComponentIndex ) const;
124  virtual Image GetImage() const override;
125 };
126 
127 
129 {
130  OUString const m_aFieldName;
131  const sal_Int32 m_nComponentIndex;
132 
133 public:
134  FmFilterItem(
135  FmFilterItems* pParent,
136  const OUString& aFieldName,
137  const OUString& aCondition,
138  const sal_Int32 _nComponentIndex
139  );
140 
141  const OUString& GetFieldName() const {return m_aFieldName;}
142  sal_Int32 GetComponentIndex() const { return m_nComponentIndex; }
143 
144  virtual Image GetImage() const override;
145 };
146 
147 
148 class FmFilterModel final : public FmParentData
149  ,public SfxBroadcaster
151 {
152  friend class FmFilterAdapter;
153 
154  css::uno::Reference< css::container::XIndexAccess > m_xControllers;
155  css::uno::Reference< css::form::runtime::XFormController > m_xController;
158 
159 public:
160  FmFilterModel();
161  virtual ~FmFilterModel() override;
162 
163  void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, const css::uno::Reference< css::form::runtime::XFormController > & xCurrent);
164  void Clear();
165  bool ValidateText(FmFilterItem const * pItem, OUString& rText, OUString& rErrorMsg) const;
166  void Append(FmFilterItems* pItems, std::unique_ptr<FmFilterItem> pFilterItem);
167  void SetTextForItem(FmFilterItem* pItem, const OUString& rText);
168 
169  FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? static_cast<FmFormItem*>(m_pCurrentItems->GetParent()) : nullptr;}
171  void SetCurrentItems(FmFilterItems* pCurrent);
172 
173  const css::uno::Reference< css::form::runtime::XFormController > & GetCurrentController() const {return m_xController;}
174  void SetCurrentController(const css::uno::Reference< css::form::runtime::XFormController > & xController);
175 
176  void Remove(FmFilterData* pFilterItem);
177  static void AppendFilterItems( FmFormItem& _rItem );
178  void EnsureEmptyFilterRows( FmParentData& _rItem );
179 
180 private:
181  void Insert(const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos, std::unique_ptr<FmFilterData> pFilterItem);
182  void Remove( const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos );
183  FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::runtime::XFormController > & xController) const;
184  FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::XForm >& xForm) const;
185  void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, FmParentData* pParent);
186 };
187 
188 
190 {
191  ::std::vector<FmFilterItem*> m_aDraggedEntries;
192  FmFormItem* m_pFormItem; // ensure that we drop on the same form
193 
194 public:
196 
198  inline static bool hasFormat( const DataFlavorExVector& _rFormats );
199 
200  const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; }
201  void setDraggedEntries(const ::std::vector<FmFilterItem*>& _rList) { m_aDraggedEntries = _rList; }
202  FmFormItem* getFormItem() const { return m_pFormItem; }
203 
204  void setFormItem( FmFormItem* _pItem ) { m_pFormItem = _pItem; }
205 
206 protected:
207  virtual void AddSupportedFormats() override;
208 };
209 
210 inline bool OFilterItemExchange::hasFormat( const DataFlavorExVector& _rFormats )
211 {
212  return OLocalExchange::hasFormat( _rFormats, getFormatId() );
213 }
214 
216 {
217 public:
218  OFilterExchangeHelper(vcl::Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
219 
220  OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_xTransferable.get()); }
221 
222 protected:
223  virtual OLocalExchange* createExchange() const override;
224 };
225 
226 
227 class FmFilterNavigator final : public SvTreeListBox, public SfxListener
228 {
230 
231  std::unique_ptr<FmFilterModel> m_pModel;
234 
235 
237  unsigned short m_aTimerCounter;
238  Point m_aTimerTriggered; // position, where DropTimer was started
240 
241 public:
242  FmFilterNavigator( vcl::Window* pParent );
243  virtual ~FmFilterNavigator() override;
244  virtual void dispose() override;
245 
246  void UpdateContent(
247  const css::uno::Reference< css::container::XIndexAccess > & xControllers,
248  const css::uno::Reference< css::form::runtime::XFormController > & xCurrent
249  );
250  const FmFilterModel* GetFilterModel() const {return m_pModel.get();}
251 
252 private:
253 
254  virtual void KeyInput( const KeyEvent& rKEvt ) override;
255  virtual void Command( const CommandEvent& rEvt ) override;
256  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
257  virtual void InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2) override;
258  virtual bool Select( SvTreeListEntry* pEntry, bool bSelect=true ) override;
259  virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& rSelection ) override;
260  virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) override;
261 
262  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
263  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
264  virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
265 
266  void DeleteSelection();
267  SvTreeListEntry* FindEntry(const FmFilterData* pItem) const;
268  void Insert(FmFilterData* pItem, sal_uLong nPos);
269  void Remove(FmFilterData const * pItem);
270 
271  DECL_LINK(OnRemove, void*, void);
272  DECL_LINK(OnDropActionTimer, Timer*, void);
273 
280  FmFormItem* getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList);
290  void insertFilterItem(const ::std::vector<FmFilterItem*>& _rFilterList,FmFilterItems* _pTargetItems, bool _bCopy);
293 
294  using SvTreeListBox::Select;
296  using SvTreeListBox::Insert;
297 };
298 
299 
301 {
302 private:
304 
305 protected:
306  virtual void Resize() override;
307  virtual bool Close() override;
308  virtual Size CalcDockingSize( SfxChildAlignment ) override;
310 
311 public:
313  vcl::Window* pParent );
314  virtual ~FmFilterNavigatorWin() override;
315  virtual void dispose() override;
316 
317  void UpdateContent( FmFormShell const * pFormShell );
318  void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) override;
319  void FillInfo( SfxChildWinInfo& rInfo ) const override;
320 
322 
323  virtual void GetFocus() override;
324 };
325 
326 
328 {
329 public:
330  FmFilterNavigatorWinMgr( vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings,
331  SfxChildWinInfo *pInfo );
333 };
334 
335 
336 }
337 
338 
339 #endif // INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX
340 
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~FmFilterModel() override
Definition: filtnav.cxx:481
DECL_LINK(OnRemove, void *, void)
virtual Image GetImage() const override
Definition: filtnav.cxx:173
FmParentData *const m_pParent
Definition: filtnav.hxx:58
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
void UpdateContent(const css::uno::Reference< css::container::XIndexAccess > &xControllers, const css::uno::Reference< css::form::runtime::XFormController > &xCurrent)
Definition: filtnav.cxx:1101
FmFilterItems(FmFormItem *pParent, const OUString &rText)
Definition: filtnav.hxx:121
virtual SfxChildAlignment CheckAlignment(SfxChildAlignment, SfxChildAlignment) override
Definition: filtnav.cxx:1882
void EnsureEmptyFilterRows(FmParentData &_rItem)
Definition: filtnav.cxx:910
void insertFilterItem(const ::std::vector< FmFilterItem * > &_rFilterList, FmFilterItems *_pTargetItems, bool _bCopy)
inserts the filter items into the tree model and creates new FilterItems if needed.
Definition: filtnav.cxx:1501
virtual bool EditedEntry(SvTreeListEntry *pEntry, const OUString &rNewText) override
Definition: filtnav.cxx:1138
css::uno::Reference< css::form::runtime::XFilterController > m_xFilterController
Definition: filtnav.hxx:95
FmFilterNavigator(vcl::Window *pParent)
Definition: filtnav.cxx:1062
SvTreeListEntry * FindEntry(const FmFilterData *pItem) const
Definition: filtnav.cxx:1426
FmFormItem(FmParentData *_pParent, const css::uno::Reference< css::form::runtime::XFormController > &_xController, const OUString &_rText)
Definition: filtnav.hxx:99
virtual Image GetImage() const override
Definition: filtnav.cxx:158
css::uno::Reference< css::form::runtime::XFormController > m_xController
Definition: filtnav.hxx:94
void Insert(FmFilterData *pItem, sal_uLong nPos)
Definition: filtnav.cxx:1442
virtual ~FmFilterNavigatorWin() override
Definition: filtnav.cxx:1797
void setDraggedEntries(const ::std::vector< FmFilterItem * > &_rList)
Definition: filtnav.hxx:201
signed char sal_Int8
static SotClipboardFormatId getFormatId()
Definition: filtnav.cxx:118
::std::vector< DataFlavorEx > DataFlavorExVector
sal_uIntPtr sal_uLong
unsigned short m_aTimerCounter
Definition: filtnav.hxx:237
void Remove(FmFilterData *pFilterItem)
Definition: filtnav.cxx:713
OUString const m_aFieldName
Definition: filtnav.hxx:130
OFilterExchangeHelper(vcl::Window *_pDragSource)
Definition: filtnav.hxx:218
virtual ~FmFilterData()
Definition: filtnav.hxx:66
sal_Int16 nId
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: filtnav.cxx:1397
::std::vector< FmFilterItem * > m_aDraggedEntries
Definition: filtnav.hxx:191
virtual ~FmParentData() override
Definition: filtnav.cxx:138
virtual void Command(const CommandEvent &rEvt) override
Definition: filtnav.cxx:1544
void SetText(const OUString &rText)
Definition: filtnav.hxx:68
void setFormItem(FmFormItem *_pItem)
Definition: filtnav.hxx:204
FmFilterItem * Find(const ::sal_Int32 _nFilterComponentIndex) const
Definition: filtnav.cxx:147
SFX_DECL_CHILDWINDOW(FmFilterNavigatorWinMgr)
FmFilterData(FmParentData *pParent, const OUString &rText)
Definition: filtnav.hxx:62
void UpdateContent(FmFormShell const *pFormShell)
Definition: filtnav.cxx:1810
css::uno::Reference< css::container::XIndexAccess > m_xControllers
Definition: filtnav.hxx:154
virtual OLocalExchange * createExchange() const override
Definition: filtnav.cxx:127
virtual void Resize() override
Definition: filtnav.cxx:1898
const FmFilterModel * GetFilterModel() const
Definition: filtnav.hxx:250
void Append(FmFilterItems *pItems, std::unique_ptr< FmFilterItem > pFilterItem)
Definition: filtnav.cxx:837
SotClipboardFormatId
FmParentData(FmParentData *pParent, const OUString &rText)
Definition: filtnav.hxx:82
FmParentData * GetParent() const
Definition: filtnav.hxx:70
void Update(const css::uno::Reference< css::container::XIndexAccess > &xControllers, const css::uno::Reference< css::form::runtime::XFormController > &xCurrent)
static void AppendFilterItems(FmFormItem &_rItem)
Definition: filtnav.cxx:672
void FillInfo(SfxChildWinInfo &rInfo) const override
Definition: filtnav.cxx:1866
virtual void StartDrag(sal_Int8 nAction, const Point &rPosPixel) override
Definition: filtnav.cxx:1527
FmFilterNavigatorWinMgr(vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo *pInfo)
Definition: filtnav.cxx:1923
rtl::Reference< FmFilterAdapter > m_pAdapter
Definition: filtnav.hxx:156
void Remove(FmFilterData const *pItem)
Definition: filtnav.cxx:1454
OFilterItemExchange * operator->() const
Definition: filtnav.hxx:220
FmFormItem * getFormItem() const
Definition: filtnav.hxx:202
virtual void GetFocus() override
Definition: filtnav.cxx:1913
virtual void KeyInput(const KeyEvent &rKEvt) override
Definition: filtnav.cxx:1670
virtual void InitEntry(SvTreeListEntry *pEntry, const OUString &rStr, const Image &rImg1, const Image &rImg2) override
Definition: filtnav.cxx:1344
virtual void AddSupportedFormats() override
Definition: filtnav.cxx:112
bool ValidateText(FmFilterItem const *pItem, OUString &rText, OUString &rErrorMsg) const
Definition: filtnav.cxx:792
SvTreeListEntry * m_pEditingCurrently
Definition: filtnav.hxx:232
const ::std::vector< FmFilterItem * > & getDraggedEntries() const
Definition: filtnav.hxx:200
const css::uno::Reference< css::form::runtime::XFormController > & GetController() const
Definition: filtnav.hxx:109
rtl::Reference< OLocalExchange > m_xTransferable
Definition: fmexch.hxx:97
virtual Image GetImage() const
Definition: filtnav.cxx:133
FmFilterItems * m_pCurrentItems
Definition: filtnav.hxx:157
SvTreeListEntry * getPrevEntry(SvTreeListEntry *_pStartWith)
Definition: filtnav.cxx:1655
const OUString & GetFieldName() const
Definition: filtnav.hxx:141
VclPtr< vcl::Window > pParent
void Insert(const ::std::vector< std::unique_ptr< FmFilterData >>::iterator &rPos, std::unique_ptr< FmFilterData > pFilterItem)
Definition: filtnav.cxx:692
const sal_Int32 m_nComponentIndex
Definition: filtnav.hxx:131
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: filtnav.cxx:1219
virtual void StateChanged(StateChangedType nStateChange) override
OFilterExchangeHelper m_aControlExchange
Definition: filtnav.hxx:233
SvTreeListEntry * getNextEntry(SvTreeListEntry *_pStartWith)
Definition: filtnav.cxx:1645
FmFormItem * getSelectedFilterItems(::std::vector< FmFilterItem * > &_rItemList)
returns the first form item and the selected FilterItems in the vector
Definition: filtnav.cxx:1467
const OUString & GetText() const
Definition: filtnav.hxx:69
a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself ...
Definition: fmexch.hxx:93
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: filtnav.cxx:1317
css::uno::Reference< css::form::runtime::XFormController > m_xController
Definition: filtnav.hxx:155
SfxItemState
SfxChildAlignment
void SetCurrentItems(FmFilterItems *pCurrent)
Definition: filtnav.cxx:864
FmFormItem * Find(const ::std::vector< std::unique_ptr< FmFilterData >> &rItems, const css::uno::Reference< css::form::runtime::XFormController > &xController) const
FmFilterItem(FmFilterItems *pParent, const OUString &aFieldName, const OUString &aCondition, const sal_Int32 _nComponentIndex)
Definition: filtnav.cxx:163
FmFormItem * GetCurrentForm() const
Definition: filtnav.hxx:169
FmFilterNavigatorWin(SfxBindings *pBindings, SfxChildWindow *pMgr, vcl::Window *pParent)
Definition: filtnav.cxx:1783
::std::vector< std::unique_ptr< FmFilterData > > m_aChildren
Definition: filtnav.hxx:79
virtual void dispose() override
Definition: filtnav.cxx:1093
virtual bool Close() override
Definition: filtnav.cxx:1852
virtual bool Select(SvTreeListEntry *pEntry, bool bSelect=true) override
Definition: filtnav.cxx:1363
void SetCurrentController(const css::uno::Reference< css::form::runtime::XFormController > &xController)
Definition: filtnav.cxx:645
virtual Size CalcDockingSize(SfxChildAlignment) override
Definition: filtnav.cxx:1873
DROP_ACTION m_aDropActionType
Definition: filtnav.hxx:239
std::unique_ptr< FmFilterModel > m_pModel
Definition: filtnav.hxx:231
const css::uno::Reference< css::form::runtime::XFilterController > & GetFilterController() const
Definition: filtnav.hxx:112
void SetTextForItem(FmFilterItem *pItem, const OUString &rText)
Definition: filtnav.cxx:843
::std::vector< std::unique_ptr< FmFilterData > > & GetChildren()
Definition: filtnav.hxx:87
virtual bool EditingEntry(SvTreeListEntry *pEntry, Selection &rSelection) override
Definition: filtnav.cxx:1128
const css::uno::Reference< css::form::runtime::XFormController > & GetCurrentController() const
Definition: filtnav.hxx:173
class FmSearchEngine - Impl class for FmSearchDialog
sal_Int32 GetComponentIndex() const
Definition: filtnav.hxx:142
FmFilterItems * GetCurrentItems() const
Definition: filtnav.hxx:170
virtual bool Select(SvTreeListEntry *pEntry, bool bSelect=true)
static bool hasFormat(const DataFlavorExVector &_rFormats)
Definition: filtnav.hxx:210
VclPtr< FmFilterNavigator > m_pNavigator
Definition: filtnav.hxx:303
void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: filtnav.cxx:1837
virtual sal_uLong Insert(SvTreeListEntry *pEnt, SvTreeListEntry *pPar, sal_uLong nPos=TREELIST_APPEND)
SfxChildWindow * pMgr
virtual Image GetImage() const override
Definition: filtnav.cxx:142
virtual ~FmFilterNavigator() override
Definition: filtnav.cxx:1088
SfxBindings * pBindings
static bool hasFormat(const DataFlavorExVector &_rFormats, SotClipboardFormatId _nFormatId)
Definition: fmexch.cxx:100
virtual void dispose() override
Definition: filtnav.cxx:1802