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 
35 #include "fmexch.hxx"
36 #include "sqlparserclient.hxx"
37 
38 class FmFormShell;
39 
40 namespace svxform
41 {
42 
43 class FmFilterItem;
44 class FmFilterItems;
45 class FmParentData;
46 class FmFilterAdapter;
47 
48 // data structure for the filter model
50 {
52  OUString m_aText;
53 
54 public:
55  FmFilterData(FmParentData* pParent, const OUString& rText)
56  :m_pParent( pParent )
57  ,m_aText( rText )
58  {}
59  virtual ~FmFilterData(){}
60 
61  void SetText( const OUString& rText ){ m_aText = rText; }
62  const OUString& GetText() const { return m_aText; }
63  FmParentData* GetParent() const {return m_pParent;}
64 
65  virtual OUString GetImage() const;
66 };
67 
68 class FmParentData : public FmFilterData
69 {
70 protected:
71  ::std::vector< std::unique_ptr<FmFilterData> > m_aChildren;
72 
73 public:
74  FmParentData(FmParentData* pParent, const OUString& rText)
75  : FmFilterData(pParent, rText)
76  {}
77  virtual ~FmParentData() override;
78 
79  ::std::vector< std::unique_ptr<FmFilterData> >& GetChildren() { return m_aChildren; }
80 };
81 
82 // Item representing the forms and subforms
83 class FmFormItem final : public FmParentData
84 {
85  css::uno::Reference< css::form::runtime::XFormController > m_xController;
86  css::uno::Reference< css::form::runtime::XFilterController > m_xFilterController;
87 
88 public:
89 
91  const css::uno::Reference< css::form::runtime::XFormController > & _xController,
92  const OUString& _rText)
93  :FmParentData( _pParent, _rText )
94  ,m_xController( _xController )
95  ,m_xFilterController( _xController, css::uno::UNO_QUERY_THROW )
96  {
97  }
98 
99  const css::uno::Reference< css::form::runtime::XFormController >&
100  GetController() const { return m_xController; }
101 
102  const css::uno::Reference< css::form::runtime::XFilterController >&
104 
105  virtual OUString GetImage() const override;
106 };
107 
108 class FmFilterItems final : public FmParentData
109 {
110 public:
111  FmFilterItems(FmFormItem* pParent, const OUString& rText ) : FmParentData(pParent, rText) {}
112 
113  FmFilterItem* Find( const ::sal_Int32 _nFilterComponentIndex ) const;
114  virtual OUString GetImage() const override;
115 };
116 
117 class FmFilterItem final : public FmFilterData
118 {
119  OUString m_aFieldName;
120  sal_Int32 m_nComponentIndex;
121 
122 public:
123  FmFilterItem(
124  FmFilterItems* pParent,
125  const OUString& aFieldName,
126  const OUString& aCondition,
127  const sal_Int32 _nComponentIndex
128  );
129 
130  const OUString& GetFieldName() const {return m_aFieldName;}
131  sal_Int32 GetComponentIndex() const { return m_nComponentIndex; }
132 
133  virtual OUString GetImage() const override;
134 };
135 
136 class FmFilterModel final : public FmParentData
137  ,public SfxBroadcaster
138  ,public ::svxform::OSQLParserClient
139 {
140  friend class FmFilterAdapter;
141 
142  css::uno::Reference< css::container::XIndexAccess > m_xControllers;
143  css::uno::Reference< css::form::runtime::XFormController > m_xController;
146 
147 public:
148  FmFilterModel();
149  virtual ~FmFilterModel() override;
150 
151  void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, const css::uno::Reference< css::form::runtime::XFormController > & xCurrent);
152  void Clear();
153  bool ValidateText(FmFilterItem const * pItem, OUString& rText, OUString& rErrorMsg) const;
154  void Append(FmFilterItems* pItems, std::unique_ptr<FmFilterItem> pFilterItem);
155  void SetTextForItem(FmFilterItem* pItem, const OUString& rText);
156 
157  FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? static_cast<FmFormItem*>(m_pCurrentItems->GetParent()) : nullptr;}
159  void SetCurrentItems(FmFilterItems* pCurrent);
160 
161  const css::uno::Reference< css::form::runtime::XFormController > & GetCurrentController() const {return m_xController;}
162  void SetCurrentController(const css::uno::Reference< css::form::runtime::XFormController > & xController);
163 
164  void Remove(FmFilterData* pFilterItem);
165  static void AppendFilterItems( FmFormItem& _rItem );
166  void EnsureEmptyFilterRows( FmParentData& _rItem );
167 
168 private:
169  void Insert(const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos, std::unique_ptr<FmFilterData> pFilterItem);
170  void Remove( const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos );
171  FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::runtime::XFormController > & xController) const;
172  FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::XForm >& xForm) const;
173  void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, FmParentData* pParent);
174 };
175 
176 
177 class OFilterItemExchange final : public OLocalExchange
178 {
179  ::std::vector<FmFilterItem*> m_aDraggedEntries;
180  FmFormItem* m_pFormItem; // ensure that we drop on the same form
181 
182 public:
184 
186  inline static bool hasFormat( const DataFlavorExVector& _rFormats );
187 
188  const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; }
189  void setDraggedEntries(::std::vector<FmFilterItem*>&& _rList) { m_aDraggedEntries = std::move(_rList); }
190  FmFormItem* getFormItem() const { return m_pFormItem; }
191 
192  void setFormItem( FmFormItem* _pItem ) { m_pFormItem = _pItem; }
193 
194 private:
195  virtual void AddSupportedFormats() override;
196 };
197 
198 inline bool OFilterItemExchange::hasFormat( const DataFlavorExVector& _rFormats )
199 {
200  return OLocalExchange::hasFormat( _rFormats, getFormatId() );
201 }
202 
203 class OFilterExchangeHelper final : public OLocalExchangeHelper
204 {
205 public:
206  OFilterExchangeHelper() : OLocalExchangeHelper() { }
207 
208  OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_xTransferable.get()); }
209  OFilterItemExchange& operator*() const { return *static_cast<OFilterItemExchange*>(m_xTransferable.get()); }
210 
211 private:
212  virtual rtl::Reference<OLocalExchange> createExchange() const override;
213 };
214 
215 class FmFilterNavigator;
216 
218 {
219 private:
221 
222  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
223  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
224 
225 public:
227 };
228 
229 class FmFilterNavigator final : public SfxListener
230 {
232  std::unique_ptr<weld::TreeView> m_xTreeView;
234 
235  std::unique_ptr<FmFilterModel> m_pModel;
236  std::unique_ptr<weld::TreeIter> m_xEditingCurrently;
238 
240 
241 public:
242  FmFilterNavigator(vcl::Window* pTopLevel, std::unique_ptr<weld::TreeView> xTreeView);
243  virtual ~FmFilterNavigator() override;
244 
245  void GrabFocus() { m_xTreeView->grab_focus(); }
246 
247  void EndEditing();
248 
249  void UpdateContent(
250  const css::uno::Reference< css::container::XIndexAccess > & xControllers,
251  const css::uno::Reference< css::form::runtime::XFormController > & xCurrent
252  );
253 
255 
256  sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt);
258 
259 private:
260  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
261  DECL_LINK(PopupMenuHdl, const CommandEvent&, bool);
262  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
263 
266 
267  DECL_LINK(SelectHdl, weld::TreeView&, void);
268  DECL_LINK(EditingEntryHdl, const weld::TreeIter&, bool);
269  typedef std::pair<const weld::TreeIter&, OUString> IterString;
270  DECL_LINK(EditedEntryHdl, const IterString&, bool);
271 
272  DECL_LINK(DragBeginHdl, bool&, bool);
273 
274  void DeleteSelection();
275  std::unique_ptr<weld::TreeIter> FindEntry(const FmFilterData* pItem) const;
276  void Insert(FmFilterData* pItem, int nPos);
277  void Remove(FmFilterData const * pItem);
278 
279  DECL_LINK(OnRemove, void*, void);
280 
287  FmFormItem* getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList);
288 
298  void insertFilterItem(const ::std::vector<FmFilterItem*>& _rFilterList,FmFilterItems* _pTargetItems, bool _bCopy);
299 
300  bool getPrevEntry(weld::TreeIter& rEntry);
301  bool getNextEntry(weld::TreeIter& rEntry);
302 };
303 
305 {
306 private:
307  std::unique_ptr<FmFilterNavigator> m_xNavigatorTree;
308 
309  virtual bool Close() override;
310  virtual void GetFocus() override;
311  virtual Size CalcDockingSize( SfxChildAlignment ) override;
313 
315 
316 public:
318  vcl::Window* pParent );
319  virtual ~FmFilterNavigatorWin() override;
320  virtual void dispose() override;
321 
322  void UpdateContent( FmFormShell const * pFormShell );
323  void StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) override;
324  void FillInfo( SfxChildWinInfo& rInfo ) const override;
325 };
326 
328 {
329 public:
330  FmFilterNavigatorWinMgr( vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings,
331  SfxChildWinInfo *pInfo );
333 };
334 
335 }
336 
337 #endif // INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX
338 
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~FmFilterModel() override
Definition: filtnav.cxx:459
FmFilterNavigator & m_rTreeView
Definition: filtnav.hxx:220
void UpdateContent(const css::uno::Reference< css::container::XIndexAccess > &xControllers, const css::uno::Reference< css::form::runtime::XFormController > &xCurrent)
Definition: filtnav.cxx:1082
FmFilterItems(FmFormItem *pParent, const OUString &rText)
Definition: filtnav.hxx:111
void setDraggedEntries(::std::vector< FmFilterItem * > &&_rList)
Definition: filtnav.hxx:189
virtual SfxChildAlignment CheckAlignment(SfxChildAlignment, SfxChildAlignment) override
Definition: filtnav.cxx:1810
void EnsureEmptyFilterRows(FmParentData &_rItem)
Definition: filtnav.cxx:886
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:1398
css::uno::Reference< css::form::runtime::XFilterController > m_xFilterController
Definition: filtnav.hxx:86
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: filtnav.cxx:1030
FmFormItem(FmParentData *_pParent, const css::uno::Reference< css::form::runtime::XFormController > &_xController, const OUString &_rText)
Definition: filtnav.hxx:90
void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: filtnav.cxx:1773
css::uno::Reference< css::form::runtime::XFormController > m_xController
Definition: filtnav.hxx:85
bool getPrevEntry(weld::TreeIter &rEntry)
Definition: filtnav.cxx:1578
virtual ~FmFilterNavigatorWin() override
Definition: filtnav.cxx:1735
signed char sal_Int8
static SotClipboardFormatId getFormatId()
Definition: filtnav.cxx:99
FmFilterNavigatorDropTarget(FmFilterNavigator &rTreeView)
Definition: filtnav.cxx:1024
::std::vector< DataFlavorEx > DataFlavorExVector
void Remove(FmFilterData *pFilterItem)
Definition: filtnav.cxx:689
virtual ~FmFilterData()
Definition: filtnav.hxx:59
sal_Int16 nId
DECL_STATIC_LINK(FmFilterNavigator, CustomGetSizeHdl, weld::TreeView::get_size_args, Size)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: filtnav.cxx:1278
::std::vector< FmFilterItem * > m_aDraggedEntries
Definition: filtnav.hxx:179
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
Definition: filtnav.cxx:1172
virtual ~FmParentData() override
Definition: filtnav.cxx:117
void SetText(const OUString &rText)
Definition: filtnav.hxx:61
void setFormItem(FmFormItem *_pItem)
Definition: filtnav.hxx:192
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: filtnav.cxx:1044
FmFilterItem * Find(const ::sal_Int32 _nFilterComponentIndex) const
Definition: filtnav.cxx:126
SFX_DECL_CHILDWINDOW(FmFilterNavigatorWinMgr)
FmFilterData(FmParentData *pParent, const OUString &rText)
Definition: filtnav.hxx:55
void UpdateContent(FmFormShell const *pFormShell)
Definition: filtnav.cxx:1747
css::uno::Reference< css::container::XIndexAccess > m_xControllers
Definition: filtnav.hxx:142
virtual OUString GetImage() const override
Definition: filtnav.cxx:137
ImplSVEvent * m_nAsyncRemoveEvent
Definition: filtnav.hxx:239
bool getNextEntry(weld::TreeIter &rEntry)
Definition: filtnav.cxx:1561
void Append(FmFilterItems *pItems, std::unique_ptr< FmFilterItem > pFilterItem)
Definition: filtnav.cxx:813
virtual OUString GetImage() const override
Definition: filtnav.cxx:121
SotClipboardFormatId
OFilterItemExchange & operator*() const
Definition: filtnav.hxx:209
FmParentData(FmParentData *pParent, const OUString &rText)
Definition: filtnav.hxx:74
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: filtnav.hxx:232
FmParentData * GetParent() const
Definition: filtnav.hxx:63
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:648
sal_Int32 m_nComponentIndex
Definition: filtnav.hxx:120
std::unique_ptr< weld::TreeIter > FindEntry(const FmFilterData *pItem) const
Definition: filtnav.cxx:1304
void FillInfo(SfxChildWinInfo &rInfo) const override
Definition: filtnav.cxx:1796
FmFilterNavigatorWinMgr(vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo *pInfo)
Definition: filtnav.cxx:1837
rtl::Reference< FmFilterAdapter > m_pAdapter
Definition: filtnav.hxx:144
void Remove(FmFilterData const *pItem)
Definition: filtnav.cxx:1350
OFilterItemExchange * operator->() const
Definition: filtnav.hxx:208
FmFormItem * getFormItem() const
Definition: filtnav.hxx:190
virtual void GetFocus() override
Definition: filtnav.cxx:1825
virtual void AddSupportedFormats() override
Definition: filtnav.cxx:94
bool ValidateText(FmFilterItem const *pItem, OUString &rText, OUString &rErrorMsg) const
Definition: filtnav.cxx:768
FmFilterNavigator(vcl::Window *pTopLevel, std::unique_ptr< weld::TreeView > xTreeView)
Definition: filtnav.cxx:1049
const ::std::vector< FmFilterItem * > & getDraggedEntries() const
Definition: filtnav.hxx:188
const css::uno::Reference< css::form::runtime::XFormController > & GetController() const
Definition: filtnav.hxx:100
void Insert(FmFilterData *pItem, int nPos)
Definition: filtnav.cxx:1322
weld::TreeView & get_widget()
Definition: filtnav.hxx:254
std::unique_ptr< FmFilterNavigator > m_xNavigatorTree
Definition: filtnav.hxx:307
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
Definition: filtnav.cxx:1225
FmFilterItems * m_pCurrentItems
Definition: filtnav.hxx:145
const OUString & GetFieldName() const
Definition: filtnav.hxx:130
VclPtr< vcl::Window > pParent
void Insert(const ::std::vector< std::unique_ptr< FmFilterData >>::iterator &rPos, std::unique_ptr< FmFilterData > pFilterItem)
Definition: filtnav.cxx:668
FmFilterNavigatorDropTarget m_aDropTargetHelper
Definition: filtnav.hxx:233
virtual void StateChanged(StateChangedType nStateChange) override
OFilterExchangeHelper m_aControlExchange
Definition: filtnav.hxx:237
std::pair< const weld::TreeIter &, OUString > IterString
Definition: filtnav.hxx:269
FmFormItem * getSelectedFilterItems(::std::vector< FmFilterItem * > &_rItemList)
returns the first form item and the selected FilterItems in the vector
Definition: filtnav.cxx:1363
const OUString & GetText() const
Definition: filtnav.hxx:62
css::uno::Reference< css::form::runtime::XFormController > m_xController
Definition: filtnav.hxx:143
SfxItemState
SfxChildAlignment
virtual OUString GetImage() const override
Definition: filtnav.cxx:152
void SetCurrentItems(FmFilterItems *pCurrent)
Definition: filtnav.cxx:840
FmParentData * m_pParent
Definition: filtnav.hxx:51
FmFormItem * Find(const ::std::vector< std::unique_ptr< FmFilterData >> &rItems, const css::uno::Reference< css::form::runtime::XFormController > &xController) const
std::tuple< vcl::RenderContext &, const tools::Rectangle &, bool, const OUString & > render_args
virtual rtl::Reference< OLocalExchange > createExchange() const override
Definition: filtnav.cxx:107
FmFilterItem(FmFilterItems *pParent, const OUString &aFieldName, const OUString &aCondition, const sal_Int32 _nComponentIndex)
Definition: filtnav.cxx:142
FmFormItem * GetCurrentForm() const
Definition: filtnav.hxx:157
FmFilterNavigatorWin(SfxBindings *pBindings, SfxChildWindow *pMgr, vcl::Window *pParent)
Definition: filtnav.cxx:1723
::std::vector< std::unique_ptr< FmFilterData > > m_aChildren
Definition: filtnav.hxx:71
virtual bool Close() override
Definition: filtnav.cxx:1787
VclPtr< vcl::Window > m_xTopLevel
Definition: filtnav.hxx:231
void SetCurrentController(const css::uno::Reference< css::form::runtime::XFormController > &xController)
Definition: filtnav.cxx:622
virtual Size CalcDockingSize(SfxChildAlignment) override
Definition: filtnav.cxx:1802
std::unique_ptr< FmFilterModel > m_pModel
Definition: filtnav.hxx:235
const css::uno::Reference< css::form::runtime::XFilterController > & GetFilterController() const
Definition: filtnav.hxx:103
void SetTextForItem(FmFilterItem *pItem, const OUString &rText)
Definition: filtnav.cxx:819
::std::vector< std::unique_ptr< FmFilterData > > & GetChildren()
Definition: filtnav.hxx:79
std::unique_ptr< weld::TreeIter > m_xEditingCurrently
Definition: filtnav.hxx:236
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
const css::uno::Reference< css::form::runtime::XFormController > & GetCurrentController() const
Definition: filtnav.hxx:161
class FmSearchEngine - Impl class for FmSearchDialog
sal_Int32 GetComponentIndex() const
Definition: filtnav.hxx:131
FmFilterItems * GetCurrentItems() const
Definition: filtnav.hxx:158
static bool hasFormat(const DataFlavorExVector &_rFormats)
Definition: filtnav.hxx:198
std::pair< vcl::RenderContext &, const OUString & > get_size_args
virtual OUString GetImage() const
Definition: filtnav.cxx:112
SfxChildWindow * pMgr
virtual ~FmFilterNavigator() override
Definition: filtnav.cxx:1074
SfxBindings * pBindings
virtual void dispose() override
Definition: filtnav.cxx:1740