bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / inc / filtnav.hxx
bloba71bacc0af3c9deec40acf1bf1a215dc7f2cd910
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _SVX_FILTNAV_HXX
20 #define _SVX_FILTNAV_HXX
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>
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>
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"
44 class FmFormShell;
46 //........................................................................
47 namespace svxform
49 //........................................................................
51 class FmFilterItem;
52 class FmFilterItems;
53 class FmParentData;
54 class FmFilterAdapter;
56 //========================================================================
57 // data structure for the filter model
58 //========================================================================
59 class FmFilterData
61 FmParentData* m_pParent;
62 OUString m_aText;
64 public:
65 TYPEINFO();
66 FmFilterData(FmParentData* pParent = NULL, const OUString& rText = OUString())
67 :m_pParent( pParent )
68 ,m_aText( rText )
70 virtual ~FmFilterData(){}
72 void SetText( const OUString& rText ){ m_aText = rText; }
73 OUString GetText() const { return m_aText; }
74 FmParentData* GetParent() const {return m_pParent;}
76 virtual Image GetImage() const;
79 //========================================================================
80 class FmParentData : public FmFilterData
82 protected:
83 ::std::vector< FmFilterData* > m_aChildren;
85 public:
86 TYPEINFO();
87 FmParentData(FmParentData* pParent, const OUString& rText)
88 : FmFilterData(pParent, rText)
90 virtual ~FmParentData();
92 ::std::vector< FmFilterData* >& GetChildren() { return m_aChildren; }
95 //========================================================================
96 // Item representing the forms and subforms
97 class FmFormItem : public FmParentData
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;
102 public:
103 TYPEINFO();
105 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 ,m_xFilterController( _xController, ::com::sun::star::uno::UNO_QUERY_THROW )
114 inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >&
115 GetController() { return m_xController; }
117 inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFilterController >&
118 GetFilterController() { return m_xFilterController; }
120 virtual Image GetImage() const;
123 //========================================================================
124 class FmFilterItems : public FmParentData
126 public:
127 TYPEINFO();
128 FmFilterItems() : FmParentData(NULL, OUString()) {}
129 FmFilterItems(FmFormItem* pParent, const OUString& rText ) : FmParentData(pParent, rText) {}
131 FmFilterItem* Find( const ::sal_Int32 _nFilterComponentIndex ) const;
132 virtual Image GetImage() const;
135 //========================================================================
136 class FmFilterItem : public FmFilterData
138 OUString m_aFieldName;
139 const sal_Int32 m_nComponentIndex;
141 public:
142 TYPEINFO();
143 FmFilterItem(
144 FmFilterItems* pParent,
145 const OUString& aFieldName,
146 const OUString& aCondition,
147 const sal_Int32 _nComponentIndex
150 const OUString& GetFieldName() const {return m_aFieldName;}
151 sal_Int32 GetComponentIndex() const { return m_nComponentIndex; }
153 virtual Image GetImage() const;
156 //========================================================================
157 class FmFilterModel : public FmParentData
158 ,public SfxBroadcaster
159 ,public ::svxform::OSQLParserClient
161 friend class FmFilterAdapter;
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;
168 public:
169 TYPEINFO();
170 FmFilterModel();
171 virtual ~FmFilterModel();
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);
179 FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? (FmFormItem*)m_pCurrentItems->GetParent() : NULL;}
180 FmFilterItems* GetCurrentItems() const {return m_pCurrentItems;}
181 void SetCurrentItems(FmFilterItems* pCurrent);
183 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & GetControllers() const {return m_xControllers;}
184 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);
187 void Remove(FmFilterData* pFilterItem);
188 void AppendFilterItems( FmFormItem& _rItem );
189 void EnsureEmptyFilterRows( FmParentData& _rItem );
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);
199 //========================================================================
200 //========================================================================
201 class OFilterItemExchange : public OLocalExchange
203 ::std::vector<FmFilterItem*> m_aDraggedEntries;
204 FmFormItem* m_pFormItem; // ensure that we drop on the same form
206 public:
207 OFilterItemExchange();
209 static sal_uInt32 getFormatId( );
210 inline static sal_Bool hasFormat( const DataFlavorExVector& _rFormats );
212 const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; }
213 void setDraggedEntries(const ::std::vector<FmFilterItem*>& _rList) { m_aDraggedEntries = _rList; }
214 FmFormItem* getFormItem() const { return m_pFormItem; }
216 void setFormItem( FmFormItem* _pItem ) { m_pFormItem = _pItem; }
217 void addSelectedItem( FmFilterItem* _pItem) { m_aDraggedEntries.push_back(_pItem); }
219 protected:
220 virtual void AddSupportedFormats();
223 inline sal_Bool OFilterItemExchange::hasFormat( const DataFlavorExVector& _rFormats )
225 return OLocalExchange::hasFormat( _rFormats, getFormatId() );
228 //====================================================================
229 //= OFilterExchangeHelper
230 //====================================================================
231 class OFilterExchangeHelper : public OLocalExchangeHelper
233 public:
234 OFilterExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
236 OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_pTransferable); }
238 protected:
239 virtual OLocalExchange* createExchange() const;
242 //========================================================================
243 class FmFilterNavigator : public SvTreeListBox, public SfxListener
245 enum DROP_ACTION{ DA_SCROLLUP, DA_SCROLLDOWN, DA_EXPANDNODE };
247 FmFilterModel* m_pModel;
248 SvTreeListEntry* m_pEditingCurrently;
249 OFilterExchangeHelper m_aControlExchange;
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;
257 public:
258 FmFilterNavigator( Window* pParent );
259 virtual ~FmFilterNavigator();
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
265 const FmFilterModel* GetFilterModel() const {return m_pModel;}
267 protected:
268 using Control::Notify;
270 virtual void KeyInput( const KeyEvent& rKEvt );
271 virtual void Command( const CommandEvent& rEvt );
272 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
273 virtual void InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind);
274 virtual sal_Bool Select( SvTreeListEntry* pEntry, sal_Bool bSelect=sal_True );
275 virtual sal_Bool EditingEntry( SvTreeListEntry* pEntry, Selection& rSelection );
276 virtual sal_Bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText );
278 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
279 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
280 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel );
282 void DeleteSelection();
283 SvTreeListEntry* FindEntry(const FmFilterData* pItem) const;
284 void Insert(FmFilterData* pItem, sal_uLong nPos);
285 void Remove(FmFilterData* pItem);
287 DECL_LINK(OnRemove, SvTreeListEntry*);
288 DECL_LINK(OnEdited, SvTreeListEntry*);
289 DECL_LINK(OnDropActionTimer, void*);
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.
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.
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);
311 using SvTreeListBox::Select;
312 using SvTreeListBox::ExecuteDrop;
313 using SvTreeListBox::Insert;
316 //========================================================================
317 class FmFilterNavigatorWin : public SfxDockingWindow, public SfxControllerItem
319 private:
320 FmFilterNavigator* m_pNavigator;
322 protected:
323 virtual void Resize();
324 virtual sal_Bool Close();
325 virtual Size CalcDockingSize( SfxChildAlignment );
326 virtual SfxChildAlignment CheckAlignment( SfxChildAlignment, SfxChildAlignment );
328 public:
329 FmFilterNavigatorWin( SfxBindings *pBindings, SfxChildWindow *pMgr,
330 Window* pParent );
331 virtual ~FmFilterNavigatorWin();
333 void UpdateContent( FmFormShell* pFormShell );
334 void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
335 void FillInfo( SfxChildWinInfo& rInfo ) const;
337 using SfxDockingWindow::StateChanged;
339 virtual void GetFocus();
342 //========================================================================
343 class FmFilterNavigatorWinMgr : public SfxChildWindow
345 public:
346 FmFilterNavigatorWinMgr( Window *pParent, sal_uInt16 nId, SfxBindings *pBindings,
347 SfxChildWinInfo *pInfo );
348 SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr );
351 //........................................................................
352 } // namespace svxform
353 //........................................................................
355 #endif // _SVX_FILTNAV_HXX
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */