Line data Source code
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/brdcst.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 <svtools/treelistbox.hxx>
36 :
37 : #include <vcl/dialog.hxx>
38 : #include <vcl/group.hxx>
39 : #include <vcl/dockwin.hxx>
40 : #include "svx/fmtools.hxx"
41 : #include "fmexch.hxx"
42 : #include "sqlparserclient.hxx"
43 :
44 : class FmFormShell;
45 :
46 :
47 : namespace svxform
48 : {
49 :
50 :
51 : class FmFilterItem;
52 : class FmFilterItems;
53 : class FmParentData;
54 : class FmFilterAdapter;
55 :
56 :
57 : // data structure for the filter model
58 :
59 : class FmFilterData
60 : {
61 : FmParentData* m_pParent;
62 : OUString m_aText;
63 :
64 : public:
65 : TYPEINFO();
66 0 : FmFilterData(FmParentData* pParent = NULL, const OUString& rText = OUString())
67 : :m_pParent( pParent )
68 0 : ,m_aText( rText )
69 0 : {}
70 0 : virtual ~FmFilterData(){}
71 :
72 0 : void SetText( const OUString& rText ){ m_aText = rText; }
73 0 : OUString GetText() const { return m_aText; }
74 0 : FmParentData* GetParent() const {return m_pParent;}
75 :
76 : virtual Image GetImage() const;
77 : };
78 :
79 :
80 : class FmParentData : public FmFilterData
81 : {
82 : protected:
83 : ::std::vector< FmFilterData* > m_aChildren;
84 :
85 : public:
86 : TYPEINFO_OVERRIDE();
87 0 : FmParentData(FmParentData* pParent, const OUString& rText)
88 0 : : FmFilterData(pParent, rText)
89 0 : {}
90 : virtual ~FmParentData();
91 :
92 0 : ::std::vector< FmFilterData* >& GetChildren() { return m_aChildren; }
93 : };
94 :
95 :
96 : // Item representing the forms and subforms
97 0 : class FmFormItem : public FmParentData
98 : {
99 : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > m_xController;
100 : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFilterController > m_xFilterController;
101 :
102 : public:
103 : TYPEINFO_OVERRIDE();
104 :
105 0 : FmFormItem( FmParentData* _pParent,
106 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & _xController,
107 : const OUString& _rText)
108 : :FmParentData( _pParent, _rText )
109 : ,m_xController( _xController )
110 0 : ,m_xFilterController( _xController, ::com::sun::star::uno::UNO_QUERY_THROW )
111 : {
112 0 : }
113 :
114 : inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >&
115 0 : GetController() { return m_xController; }
116 :
117 : inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFilterController >&
118 0 : GetFilterController() { return m_xFilterController; }
119 :
120 : virtual Image GetImage() const SAL_OVERRIDE;
121 : };
122 :
123 :
124 0 : class FmFilterItems : public FmParentData
125 : {
126 : public:
127 : TYPEINFO_OVERRIDE();
128 : FmFilterItems() : FmParentData(NULL, OUString()) {}
129 0 : FmFilterItems(FmFormItem* pParent, const OUString& rText ) : FmParentData(pParent, rText) {}
130 :
131 : FmFilterItem* Find( const ::sal_Int32 _nFilterComponentIndex ) const;
132 : virtual Image GetImage() const SAL_OVERRIDE;
133 : };
134 :
135 :
136 0 : class FmFilterItem : public FmFilterData
137 : {
138 : OUString m_aFieldName;
139 : const sal_Int32 m_nComponentIndex;
140 :
141 : public:
142 : TYPEINFO_OVERRIDE();
143 : FmFilterItem(
144 : FmFilterItems* pParent,
145 : const OUString& aFieldName,
146 : const OUString& aCondition,
147 : const sal_Int32 _nComponentIndex
148 : );
149 :
150 0 : const OUString& GetFieldName() const {return m_aFieldName;}
151 0 : sal_Int32 GetComponentIndex() const { return m_nComponentIndex; }
152 :
153 : virtual Image GetImage() const SAL_OVERRIDE;
154 : };
155 :
156 :
157 : class FmFilterModel : public FmParentData
158 : ,public SfxBroadcaster
159 : ,public ::svxform::OSQLParserClient
160 : {
161 : friend class FmFilterAdapter;
162 :
163 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > m_xControllers;
164 : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > m_xController;
165 : FmFilterAdapter* m_pAdapter;
166 : FmFilterItems* m_pCurrentItems;
167 :
168 : public:
169 : TYPEINFO_OVERRIDE();
170 : FmFilterModel();
171 : virtual ~FmFilterModel();
172 :
173 : void Update(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers, const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xCurrent);
174 : void Clear();
175 : sal_Bool ValidateText(FmFilterItem* pItem, OUString& rText, OUString& rErrorMsg) const;
176 : void Append(FmFilterItems* pItems, FmFilterItem* pFilterItem);
177 : void SetTextForItem(FmFilterItem* pItem, const OUString& rText);
178 :
179 0 : FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? (FmFormItem*)m_pCurrentItems->GetParent() : NULL;}
180 0 : FmFilterItems* GetCurrentItems() const {return m_pCurrentItems;}
181 : void SetCurrentItems(FmFilterItems* pCurrent);
182 :
183 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & GetControllers() const {return m_xControllers;}
184 0 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & GetCurrentController() const {return m_xController;}
185 : void SetCurrentController(const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xController);
186 :
187 : void Remove(FmFilterData* pFilterItem);
188 : void AppendFilterItems( FmFormItem& _rItem );
189 : void EnsureEmptyFilterRows( FmParentData& _rItem );
190 :
191 : protected:
192 : void Insert(const ::std::vector<FmFilterData*>::iterator& rPos, FmFilterData* pFilterItem);
193 : void Remove( const ::std::vector<FmFilterData*>::iterator& rPos );
194 : FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xController) const;
195 : FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& xForm) const;
196 : void Update(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers, FmParentData* pParent);
197 : };
198 :
199 :
200 :
201 0 : class OFilterItemExchange : public OLocalExchange
202 : {
203 : ::std::vector<FmFilterItem*> m_aDraggedEntries;
204 : FmFormItem* m_pFormItem; // ensure that we drop on the same form
205 :
206 : public:
207 : OFilterItemExchange();
208 :
209 : static sal_uInt32 getFormatId( );
210 : inline static sal_Bool hasFormat( const DataFlavorExVector& _rFormats );
211 :
212 0 : const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; }
213 0 : void setDraggedEntries(const ::std::vector<FmFilterItem*>& _rList) { m_aDraggedEntries = _rList; }
214 0 : FmFormItem* getFormItem() const { return m_pFormItem; }
215 :
216 0 : void setFormItem( FmFormItem* _pItem ) { m_pFormItem = _pItem; }
217 : void addSelectedItem( FmFilterItem* _pItem) { m_aDraggedEntries.push_back(_pItem); }
218 :
219 : protected:
220 : virtual void AddSupportedFormats() SAL_OVERRIDE;
221 : };
222 :
223 0 : inline sal_Bool OFilterItemExchange::hasFormat( const DataFlavorExVector& _rFormats )
224 : {
225 0 : return OLocalExchange::hasFormat( _rFormats, getFormatId() );
226 : }
227 :
228 :
229 : //= OFilterExchangeHelper
230 :
231 0 : class OFilterExchangeHelper : public OLocalExchangeHelper
232 : {
233 : public:
234 0 : OFilterExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
235 :
236 0 : OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_pTransferable); }
237 :
238 : protected:
239 : virtual OLocalExchange* createExchange() const SAL_OVERRIDE;
240 : };
241 :
242 :
243 : class FmFilterNavigator : public SvTreeListBox, public SfxListener
244 : {
245 : enum DROP_ACTION{ DA_SCROLLUP, DA_SCROLLDOWN, DA_EXPANDNODE };
246 :
247 : FmFilterModel* m_pModel;
248 : SvTreeListEntry* m_pEditingCurrently;
249 : OFilterExchangeHelper m_aControlExchange;
250 :
251 :
252 : AutoTimer m_aDropActionTimer;
253 : unsigned short m_aTimerCounter;
254 : Point m_aTimerTriggered; // die Position, an der der DropTimer angeschaltet wurde
255 : DROP_ACTION m_aDropActionType;
256 :
257 : public:
258 : FmFilterNavigator( Window* pParent );
259 : virtual ~FmFilterNavigator();
260 :
261 : void UpdateContent(
262 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers,
263 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xCurrent
264 : );
265 0 : const FmFilterModel* GetFilterModel() const {return m_pModel;}
266 :
267 : protected:
268 : using Control::Notify;
269 :
270 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
271 : virtual void Command( const CommandEvent& rEvt ) SAL_OVERRIDE;
272 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
273 : virtual void InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind) SAL_OVERRIDE;
274 : virtual sal_Bool Select( SvTreeListEntry* pEntry, sal_Bool bSelect=sal_True );
275 : virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& rSelection ) SAL_OVERRIDE;
276 : virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) SAL_OVERRIDE;
277 :
278 : virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) SAL_OVERRIDE;
279 : virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) SAL_OVERRIDE;
280 : virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) SAL_OVERRIDE;
281 :
282 : void DeleteSelection();
283 : SvTreeListEntry* FindEntry(const FmFilterData* pItem) const;
284 : void Insert(FmFilterData* pItem, sal_uLong nPos);
285 : void Remove(FmFilterData* pItem);
286 :
287 : DECL_LINK(OnRemove, SvTreeListEntry*);
288 : DECL_LINK(OnEdited, SvTreeListEntry*);
289 : DECL_LINK(OnDropActionTimer, void*);
290 :
291 : private:
292 : /** returns the first form item and the selected FilterItems in the vector
293 : @param _rItemList
294 : Is filled inside. <OUT/>
295 : @return
296 : The first form item.
297 : */
298 : FmFormItem* getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList);
299 : /* inserts the filter items into the tree model and creates new FilterItems if needed.
300 : @param _rFilterList
301 : The items which should be inserted.
302 : @param _pTargetItems
303 : The target where to insert the items.
304 : @param _bCopy
305 : If <TRUE/> the items will not be removed from the model, otherwise they will.
306 : */
307 : void insertFilterItem(const ::std::vector<FmFilterItem*>& _rFilterList,FmFilterItems* _pTargetItems,sal_Bool _bCopy = sal_False);
308 : SvTreeListEntry* getPrevEntry(SvTreeListEntry* _pStartWith = NULL);
309 : SvTreeListEntry* getNextEntry(SvTreeListEntry* _pStartWith = NULL);
310 :
311 : using SvTreeListBox::Select;
312 : using SvTreeListBox::ExecuteDrop;
313 : using SvTreeListBox::Insert;
314 : };
315 :
316 :
317 : class FmFilterNavigatorWin : public SfxDockingWindow, public SfxControllerItem
318 : {
319 : private:
320 : FmFilterNavigator* m_pNavigator;
321 :
322 : protected:
323 : virtual void Resize() SAL_OVERRIDE;
324 : virtual bool Close() SAL_OVERRIDE;
325 : virtual Size CalcDockingSize( SfxChildAlignment ) SAL_OVERRIDE;
326 : virtual SfxChildAlignment CheckAlignment( SfxChildAlignment, SfxChildAlignment ) SAL_OVERRIDE;
327 :
328 : public:
329 : FmFilterNavigatorWin( SfxBindings *pBindings, SfxChildWindow *pMgr,
330 : Window* pParent );
331 : virtual ~FmFilterNavigatorWin();
332 :
333 : void UpdateContent( FmFormShell* pFormShell );
334 : void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) SAL_OVERRIDE;
335 : void FillInfo( SfxChildWinInfo& rInfo ) const SAL_OVERRIDE;
336 :
337 : using SfxDockingWindow::StateChanged;
338 :
339 : virtual void GetFocus() SAL_OVERRIDE;
340 : };
341 :
342 :
343 0 : class FmFilterNavigatorWinMgr : public SfxChildWindow
344 : {
345 : public:
346 : FmFilterNavigatorWinMgr( Window *pParent, sal_uInt16 nId, SfxBindings *pBindings,
347 : SfxChildWinInfo *pInfo );
348 : SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr );
349 : };
350 :
351 :
352 : } // namespace svxform
353 :
354 :
355 : #endif // INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX
356 :
357 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|