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