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 "fmexch.hxx"
38 #include "sqlparserclient.hxx"
39 
40 class FmFormShell;
41 
42 
43 namespace svxform
44 {
45 
46 
47 class FmFilterItem;
48 class FmFilterItems;
49 class FmParentData;
50 class FmFilterAdapter;
51 
52 
53 // data structure for the filter model
54 
56 {
58  OUString m_aText;
59 
60 public:
61  FmFilterData(FmParentData* pParent, const OUString& rText)
62  :m_pParent( pParent )
63  ,m_aText( rText )
64  {}
65  virtual ~FmFilterData(){}
66 
67  void SetText( const OUString& rText ){ m_aText = rText; }
68  const OUString& GetText() const { return m_aText; }
69  FmParentData* GetParent() const {return m_pParent;}
70 
71  virtual Image GetImage() const;
72 };
73 
74 
75 class FmParentData : public FmFilterData
76 {
77 protected:
78  ::std::vector< std::unique_ptr<FmFilterData> > m_aChildren;
79 
80 public:
81  FmParentData(FmParentData* pParent, const OUString& rText)
82  : FmFilterData(pParent, rText)
83  {}
84  virtual ~FmParentData() override;
85 
86  ::std::vector< std::unique_ptr<FmFilterData> >& GetChildren() { return m_aChildren; }
87 };
88 
89 
90 // Item representing the forms and subforms
91 class FmFormItem : public FmParentData
92 {
93  css::uno::Reference< css::form::runtime::XFormController > m_xController;
94  css::uno::Reference< css::form::runtime::XFilterController > m_xFilterController;
95 
96 public:
97 
99  const css::uno::Reference< css::form::runtime::XFormController > & _xController,
100  const OUString& _rText)
101  :FmParentData( _pParent, _rText )
102  ,m_xController( _xController )
103  ,m_xFilterController( _xController, css::uno::UNO_QUERY_THROW )
104  {
105  }
106 
107  const css::uno::Reference< css::form::runtime::XFormController >&
108  GetController() const { return m_xController; }
109 
110  const css::uno::Reference< css::form::runtime::XFilterController >&
112 
113  virtual Image GetImage() const override;
114 };
115 
116 
118 {
119 public:
120  FmFilterItems(FmFormItem* pParent, const OUString& rText ) : FmParentData(pParent, rText) {}
121 
122  FmFilterItem* Find( const ::sal_Int32 _nFilterComponentIndex ) const;
123  virtual Image GetImage() const override;
124 };
125 
126 
128 {
129  OUString m_aFieldName;
130  sal_Int32 m_nComponentIndex;
131 
132 public:
133  FmFilterItem(
134  FmFilterItems* pParent,
135  const OUString& aFieldName,
136  const OUString& aCondition,
137  const sal_Int32 _nComponentIndex
138  );
139 
140  const OUString& GetFieldName() const {return m_aFieldName;}
141  sal_Int32 GetComponentIndex() const { return m_nComponentIndex; }
142 
143  virtual Image GetImage() const override;
144 };
145 
146 
147 class FmFilterModel final : public FmParentData
148  ,public SfxBroadcaster
149  ,public ::svxform::OSQLParserClient
150 {
151  friend class FmFilterAdapter;
152 
153  css::uno::Reference< css::container::XIndexAccess > m_xControllers;
154  css::uno::Reference< css::form::runtime::XFormController > m_xController;
157 
158 public:
159  FmFilterModel();
160  virtual ~FmFilterModel() override;
161 
162  void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, const css::uno::Reference< css::form::runtime::XFormController > & xCurrent);
163  void Clear();
164  bool ValidateText(FmFilterItem const * pItem, OUString& rText, OUString& rErrorMsg) const;
165  void Append(FmFilterItems* pItems, std::unique_ptr<FmFilterItem> pFilterItem);
166  void SetTextForItem(FmFilterItem* pItem, const OUString& rText);
167 
168  FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? static_cast<FmFormItem*>(m_pCurrentItems->GetParent()) : nullptr;}
170  void SetCurrentItems(FmFilterItems* pCurrent);
171 
172  const css::uno::Reference< css::form::runtime::XFormController > & GetCurrentController() const {return m_xController;}
173  void SetCurrentController(const css::uno::Reference< css::form::runtime::XFormController > & xController);
174 
175  void Remove(FmFilterData* pFilterItem);
176  static void AppendFilterItems( FmFormItem& _rItem );
177  void EnsureEmptyFilterRows( FmParentData& _rItem );
178 
179 private:
180  void Insert(const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos, std::unique_ptr<FmFilterData> pFilterItem);
181  void Remove( const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos );
182  FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::runtime::XFormController > & xController) const;
183  FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::XForm >& xForm) const;
184  void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, FmParentData* pParent);
185 };
186 
187 
188 class OFilterItemExchange : public OLocalExchange
189 {
190  ::std::vector<FmFilterItem*> m_aDraggedEntries;
191  FmFormItem* m_pFormItem; // ensure that we drop on the same form
192 
193 public:
195 
197  inline static bool hasFormat( const DataFlavorExVector& _rFormats );
198 
199  const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; }
200  void setDraggedEntries(const ::std::vector<FmFilterItem*>& _rList) { m_aDraggedEntries = _rList; }
201  FmFormItem* getFormItem() const { return m_pFormItem; }
202 
203  void setFormItem( FmFormItem* _pItem ) { m_pFormItem = _pItem; }
204 
205 protected:
206  virtual void AddSupportedFormats() override;
207 };
208 
209 inline bool OFilterItemExchange::hasFormat( const DataFlavorExVector& _rFormats )
210 {
211  return OLocalExchange::hasFormat( _rFormats, getFormatId() );
212 }
213 
214 class OFilterExchangeHelper : public OLocalExchangeHelper
215 {
216 public:
217  OFilterExchangeHelper(vcl::Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
218 
219  OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_xTransferable.get()); }
220 
221 protected:
222  virtual OLocalExchange* createExchange() const override;
223 };
224 
225 
226 class FmFilterNavigator final : public SvTreeListBox, public SfxListener
227 {
229 
230  std::unique_ptr<FmFilterModel> m_pModel;
233 
234 
236  unsigned short m_aTimerCounter;
237  Point m_aTimerTriggered; // position, where DropTimer was started
239 
240 public:
241  FmFilterNavigator( vcl::Window* pParent );
242  virtual ~FmFilterNavigator() override;
243  virtual void dispose() override;
244 
245  void UpdateContent(
246  const css::uno::Reference< css::container::XIndexAccess > & xControllers,
247  const css::uno::Reference< css::form::runtime::XFormController > & xCurrent
248  );
249 
250 private:
251 
252  virtual void KeyInput( const KeyEvent& rKEvt ) override;
253  virtual void Command( const CommandEvent& rEvt ) override;
254  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
255  virtual void InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2) override;
256  virtual bool Select( SvTreeListEntry* pEntry, bool bSelect=true ) override;
257  virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& rSelection ) override;
258  virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) override;
259 
260  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
261  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
262  virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
263 
264  void DeleteSelection();
265  SvTreeListEntry* FindEntry(const FmFilterData* pItem) const;
266  void Insert(FmFilterData* pItem, sal_uLong nPos);
267  void Remove(FmFilterData const * pItem);
268 
269  DECL_LINK(OnRemove, void*, void);
270  DECL_LINK(OnDropActionTimer, Timer*, void);
271 
278  FmFormItem* getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList);
288  void insertFilterItem(const ::std::vector<FmFilterItem*>& _rFilterList,FmFilterItems* _pTargetItems, bool _bCopy);
291 
292  using SvTreeListBox::Select;
294  using SvTreeListBox::Insert;
295 };
296 
297 
299 {
300 private:
302 
303 protected:
304  virtual void Resize() override;
305  virtual bool Close() override;
306  virtual Size CalcDockingSize( SfxChildAlignment ) override;
308 
309 public:
311  vcl::Window* pParent );
312  virtual ~FmFilterNavigatorWin() override;
313  virtual void dispose() override;
314 
315  void UpdateContent( FmFormShell const * pFormShell );
316  void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) override;
317  void FillInfo( SfxChildWinInfo& rInfo ) const override;
318 
320 
321  virtual void GetFocus() override;
322 };
323 
324 
326 {
327 public:
328  FmFilterNavigatorWinMgr( vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings,
329  SfxChildWinInfo *pInfo );
331 };
332 
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:475
DECL_LINK(OnRemove, void *, void)
virtual Image GetImage() const override
Definition: filtnav.cxx:167
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:1095
FmFilterItems(FmFormItem *pParent, const OUString &rText)
Definition: filtnav.hxx:120
virtual SfxChildAlignment CheckAlignment(SfxChildAlignment, SfxChildAlignment) override
Definition: filtnav.cxx:1876
void EnsureEmptyFilterRows(FmParentData &_rItem)
Definition: filtnav.cxx:904
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:1495
virtual bool EditedEntry(SvTreeListEntry *pEntry, const OUString &rNewText) override
Definition: filtnav.cxx:1132
css::uno::Reference< css::form::runtime::XFilterController > m_xFilterController
Definition: filtnav.hxx:94
FmFilterNavigator(vcl::Window *pParent)
Definition: filtnav.cxx:1056
SvTreeListEntry * FindEntry(const FmFilterData *pItem) const
Definition: filtnav.cxx:1420
FmFormItem(FmParentData *_pParent, const css::uno::Reference< css::form::runtime::XFormController > &_xController, const OUString &_rText)
Definition: filtnav.hxx:98
virtual Image GetImage() const override
Definition: filtnav.cxx:152
css::uno::Reference< css::form::runtime::XFormController > m_xController
Definition: filtnav.hxx:93
void Insert(FmFilterData *pItem, sal_uLong nPos)
Definition: filtnav.cxx:1436
virtual ~FmFilterNavigatorWin() override
Definition: filtnav.cxx:1791
void setDraggedEntries(const ::std::vector< FmFilterItem * > &_rList)
Definition: filtnav.hxx:200
signed char sal_Int8
static SotClipboardFormatId getFormatId()
Definition: filtnav.cxx:112
::std::vector< DataFlavorEx > DataFlavorExVector
sal_uIntPtr sal_uLong
unsigned short m_aTimerCounter
Definition: filtnav.hxx:236
void Remove(FmFilterData *pFilterItem)
Definition: filtnav.cxx:707
OFilterExchangeHelper(vcl::Window *_pDragSource)
Definition: filtnav.hxx:217
virtual ~FmFilterData()
Definition: filtnav.hxx:65
sal_Int16 nId
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: filtnav.cxx:1391
::std::vector< FmFilterItem * > m_aDraggedEntries
Definition: filtnav.hxx:190
virtual ~FmParentData() override
Definition: filtnav.cxx:132
virtual void Command(const CommandEvent &rEvt) override
Definition: filtnav.cxx:1538
void SetText(const OUString &rText)
Definition: filtnav.hxx:67
void setFormItem(FmFormItem *_pItem)
Definition: filtnav.hxx:203
FmFilterItem * Find(const ::sal_Int32 _nFilterComponentIndex) const
Definition: filtnav.cxx:141
SFX_DECL_CHILDWINDOW(FmFilterNavigatorWinMgr)
FmFilterData(FmParentData *pParent, const OUString &rText)
Definition: filtnav.hxx:61
void UpdateContent(FmFormShell const *pFormShell)
Definition: filtnav.cxx:1804
css::uno::Reference< css::container::XIndexAccess > m_xControllers
Definition: filtnav.hxx:153
virtual OLocalExchange * createExchange() const override
Definition: filtnav.cxx:121
virtual void Resize() override
Definition: filtnav.cxx:1892
void Append(FmFilterItems *pItems, std::unique_ptr< FmFilterItem > pFilterItem)
Definition: filtnav.cxx:831
SotClipboardFormatId
FmParentData(FmParentData *pParent, const OUString &rText)
Definition: filtnav.hxx:81
FmParentData * GetParent() const
Definition: filtnav.hxx:69
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:666
sal_Int32 m_nComponentIndex
Definition: filtnav.hxx:130
void FillInfo(SfxChildWinInfo &rInfo) const override
Definition: filtnav.cxx:1860
virtual void StartDrag(sal_Int8 nAction, const Point &rPosPixel) override
Definition: filtnav.cxx:1521
FmFilterNavigatorWinMgr(vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo *pInfo)
Definition: filtnav.cxx:1917
rtl::Reference< FmFilterAdapter > m_pAdapter
Definition: filtnav.hxx:155
void Remove(FmFilterData const *pItem)
Definition: filtnav.cxx:1448
OFilterItemExchange * operator->() const
Definition: filtnav.hxx:219
FmFormItem * getFormItem() const
Definition: filtnav.hxx:201
virtual void GetFocus() override
Definition: filtnav.cxx:1907
virtual void KeyInput(const KeyEvent &rKEvt) override
Definition: filtnav.cxx:1664
virtual void InitEntry(SvTreeListEntry *pEntry, const OUString &rStr, const Image &rImg1, const Image &rImg2) override
Definition: filtnav.cxx:1338
virtual void AddSupportedFormats() override
Definition: filtnav.cxx:106
bool ValidateText(FmFilterItem const *pItem, OUString &rText, OUString &rErrorMsg) const
Definition: filtnav.cxx:786
SvTreeListEntry * m_pEditingCurrently
Definition: filtnav.hxx:231
const ::std::vector< FmFilterItem * > & getDraggedEntries() const
Definition: filtnav.hxx:199
const css::uno::Reference< css::form::runtime::XFormController > & GetController() const
Definition: filtnav.hxx:108
virtual Image GetImage() const
Definition: filtnav.cxx:127
FmFilterItems * m_pCurrentItems
Definition: filtnav.hxx:156
SvTreeListEntry * getPrevEntry(SvTreeListEntry *_pStartWith)
Definition: filtnav.cxx:1649
const OUString & GetFieldName() const
Definition: filtnav.hxx:140
VclPtr< vcl::Window > pParent
void Insert(const ::std::vector< std::unique_ptr< FmFilterData >>::iterator &rPos, std::unique_ptr< FmFilterData > pFilterItem)
Definition: filtnav.cxx:686
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: filtnav.cxx:1213
virtual void StateChanged(StateChangedType nStateChange) override
OFilterExchangeHelper m_aControlExchange
Definition: filtnav.hxx:232
SvTreeListEntry * getNextEntry(SvTreeListEntry *_pStartWith)
Definition: filtnav.cxx:1639
FmFormItem * getSelectedFilterItems(::std::vector< FmFilterItem * > &_rItemList)
returns the first form item and the selected FilterItems in the vector
Definition: filtnav.cxx:1461
const OUString & GetText() const
Definition: filtnav.hxx:68
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: filtnav.cxx:1311
css::uno::Reference< css::form::runtime::XFormController > m_xController
Definition: filtnav.hxx:154
SfxItemState
SfxChildAlignment
void SetCurrentItems(FmFilterItems *pCurrent)
Definition: filtnav.cxx:858
FmParentData * m_pParent
Definition: filtnav.hxx:57
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:157
FmFormItem * GetCurrentForm() const
Definition: filtnav.hxx:168
FmFilterNavigatorWin(SfxBindings *pBindings, SfxChildWindow *pMgr, vcl::Window *pParent)
Definition: filtnav.cxx:1777
::std::vector< std::unique_ptr< FmFilterData > > m_aChildren
Definition: filtnav.hxx:78
virtual void dispose() override
Definition: filtnav.cxx:1087
virtual bool Close() override
Definition: filtnav.cxx:1846
virtual bool Select(SvTreeListEntry *pEntry, bool bSelect=true) override
Definition: filtnav.cxx:1357
void SetCurrentController(const css::uno::Reference< css::form::runtime::XFormController > &xController)
Definition: filtnav.cxx:639
virtual Size CalcDockingSize(SfxChildAlignment) override
Definition: filtnav.cxx:1867
DROP_ACTION m_aDropActionType
Definition: filtnav.hxx:238
std::unique_ptr< FmFilterModel > m_pModel
Definition: filtnav.hxx:230
const css::uno::Reference< css::form::runtime::XFilterController > & GetFilterController() const
Definition: filtnav.hxx:111
void SetTextForItem(FmFilterItem *pItem, const OUString &rText)
Definition: filtnav.cxx:837
::std::vector< std::unique_ptr< FmFilterData > > & GetChildren()
Definition: filtnav.hxx:86
virtual bool EditingEntry(SvTreeListEntry *pEntry, Selection &rSelection) override
Definition: filtnav.cxx:1122
const css::uno::Reference< css::form::runtime::XFormController > & GetCurrentController() const
Definition: filtnav.hxx:172
class FmSearchEngine - Impl class for FmSearchDialog
sal_Int32 GetComponentIndex() const
Definition: filtnav.hxx:141
FmFilterItems * GetCurrentItems() const
Definition: filtnav.hxx:169
virtual bool Select(SvTreeListEntry *pEntry, bool bSelect=true)
static bool hasFormat(const DataFlavorExVector &_rFormats)
Definition: filtnav.hxx:209
VclPtr< FmFilterNavigator > m_pNavigator
Definition: filtnav.hxx:301
void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: filtnav.cxx:1831
virtual sal_uLong Insert(SvTreeListEntry *pEnt, SvTreeListEntry *pPar, sal_uLong nPos=TREELIST_APPEND)
SfxChildWindow * pMgr
virtual Image GetImage() const override
Definition: filtnav.cxx:136
virtual ~FmFilterNavigator() override
Definition: filtnav.cxx:1082
SfxBindings * pBindings
virtual void dispose() override
Definition: filtnav.cxx:1796