/src/libreoffice/svx/source/inc/filtnav.hxx
Line | Count | Source |
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 <utility> |
29 | | #include <vcl/window.hxx> |
30 | | #include <sfx2/childwin.hxx> |
31 | | #include <svl/poolitem.hxx> |
32 | | #include <sfx2/bindings.hxx> |
33 | | #include <sfx2/dockwin.hxx> |
34 | | #include <sfx2/ctrlitem.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 FmParentData; |
46 | | class FmFilterAdapter; |
47 | | |
48 | | // data structure for the filter model |
49 | | class FmFilterData |
50 | | { |
51 | | FmParentData* m_pParent; |
52 | | OUString m_aText; |
53 | | |
54 | | public: |
55 | | FmFilterData(FmParentData* pParent, OUString aText) |
56 | | :m_pParent( pParent ) |
57 | | ,m_aText(std::move( aText )) |
58 | 0 | {} |
59 | 0 | virtual ~FmFilterData(){} |
60 | | |
61 | 0 | void SetText( const OUString& rText ){ m_aText = rText; } |
62 | 0 | const OUString& GetText() const { return m_aText; } |
63 | 0 | 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 | 0 | {} |
77 | | virtual ~FmParentData() override; |
78 | | |
79 | 0 | ::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 | | |
90 | | FmFormItem( FmParentData* _pParent, |
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 | 0 | { |
97 | 0 | } |
98 | | |
99 | | const css::uno::Reference< css::form::runtime::XFormController >& |
100 | 0 | GetController() const { return m_xController; } |
101 | | |
102 | | const css::uno::Reference< css::form::runtime::XFilterController >& |
103 | 0 | GetFilterController() const { return m_xFilterController; } |
104 | | |
105 | | virtual OUString GetImage() const override; |
106 | | }; |
107 | | |
108 | | class FmFilterItems final : public FmParentData |
109 | | { |
110 | | public: |
111 | 0 | 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 | | OUString aFieldName, |
126 | | const OUString& aCondition, |
127 | | const sal_Int32 _nComponentIndex |
128 | | ); |
129 | | |
130 | 0 | const OUString& GetFieldName() const {return m_aFieldName;} |
131 | 0 | 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; |
144 | | rtl::Reference<FmFilterAdapter> m_pAdapter; |
145 | | FmFilterItems* m_pCurrentItems; |
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 | 0 | FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? static_cast<FmFormItem*>(m_pCurrentItems->GetParent()) : nullptr;} |
158 | 0 | FmFilterItems* GetCurrentItems() const {return m_pCurrentItems;} |
159 | | void SetCurrentItems(FmFilterItems* pCurrent); |
160 | | |
161 | 0 | 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: |
183 | | OFilterItemExchange(); |
184 | | |
185 | | static SotClipboardFormatId getFormatId( ); |
186 | | inline static bool hasFormat( const DataFlavorExVector& _rFormats ); |
187 | | |
188 | 0 | const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; } |
189 | 0 | void setDraggedEntries(::std::vector<FmFilterItem*>&& _rList) { m_aDraggedEntries = std::move(_rList); } |
190 | 0 | FmFormItem* getFormItem() const { return m_pFormItem; } |
191 | | |
192 | 0 | 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 | 0 | { |
200 | 0 | return OLocalExchange::hasFormat( _rFormats, getFormatId() ); |
201 | 0 | } |
202 | | |
203 | | class OFilterExchangeHelper final : public OLocalExchangeHelper |
204 | | { |
205 | | public: |
206 | 0 | OFilterExchangeHelper() : OLocalExchangeHelper() { } |
207 | | |
208 | 0 | OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_xTransferable.get()); } |
209 | 0 | 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 | | |
217 | | class FmFilterNavigatorDropTarget final : public DropTargetHelper |
218 | | { |
219 | | private: |
220 | | FmFilterNavigator& m_rTreeView; |
221 | | |
222 | | virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; |
223 | | virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; |
224 | | |
225 | | public: |
226 | | FmFilterNavigatorDropTarget(FmFilterNavigator& rTreeView); |
227 | | }; |
228 | | |
229 | | class FmFilterNavigator final : public SfxListener |
230 | | { |
231 | | VclPtr<vcl::Window> m_xTopLevel; |
232 | | std::unique_ptr<weld::TreeView> m_xTreeView; |
233 | | FmFilterNavigatorDropTarget m_aDropTargetHelper; |
234 | | |
235 | | std::unique_ptr<FmFilterModel> m_pModel; |
236 | | std::unique_ptr<weld::TreeIter> m_xEditingCurrently; |
237 | | OFilterExchangeHelper m_aControlExchange; |
238 | | |
239 | | ImplSVEvent* m_nAsyncRemoveEvent; |
240 | | |
241 | | public: |
242 | | FmFilterNavigator(vcl::Window* pTopLevel, std::unique_ptr<weld::TreeView> xTreeView); |
243 | | virtual ~FmFilterNavigator() override; |
244 | | |
245 | 0 | 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 | | |
254 | 0 | weld::TreeView& get_widget() { return *m_xTreeView; } |
255 | | |
256 | | sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt); |
257 | | sal_Int8 ExecuteDrop(const ExecuteDropEvent& 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 | | |
264 | | DECL_STATIC_LINK(FmFilterNavigator, CustomGetSizeHdl, weld::TreeView::get_size_args, Size); |
265 | | DECL_STATIC_LINK(FmFilterNavigator, CustomRenderHdl, weld::TreeView::render_args, void); |
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(const FmFilterData* pItem, int nPos); |
277 | | void Remove(FmFilterData const * pItem); |
278 | | |
279 | | DECL_LINK(OnRemove, void*, void); |
280 | | |
281 | | /** returns the first form item and the selected FilterItems in the vector |
282 | | @param _rItemList |
283 | | Is filled inside. <OUT/> |
284 | | @return |
285 | | The first form item. |
286 | | */ |
287 | | FmFormItem* getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList); |
288 | | |
289 | | /** |
290 | | * inserts the filter items into the tree model and creates new FilterItems if needed. |
291 | | * @param _rFilterList |
292 | | * The items which should be inserted. |
293 | | * @param _pTargetItems |
294 | | * The target where to insert the items. |
295 | | * @param _bCopy |
296 | | * If <TRUE/> the items will not be removed from the model, otherwise they will. |
297 | | */ |
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 | | |
304 | | class FmFilterNavigatorWin final : public SfxDockingWindow, public SfxControllerItem |
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; |
312 | | virtual SfxChildAlignment CheckAlignment( SfxChildAlignment, SfxChildAlignment ) override; |
313 | | |
314 | | using SfxDockingWindow::StateChanged; |
315 | | |
316 | | public: |
317 | | FmFilterNavigatorWin( SfxBindings *pBindings, SfxChildWindow *pMgr, |
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 | | |
327 | | class FmFilterNavigatorWinMgr final : public SfxChildWindow |
328 | | { |
329 | | public: |
330 | | FmFilterNavigatorWinMgr( vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, |
331 | | SfxChildWinInfo *pInfo ); |
332 | | SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr ); |
333 | | }; |
334 | | |
335 | | } |
336 | | |
337 | | #endif // INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX |
338 | | |
339 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |