xref: /aoo41x/main/svx/source/inc/filtnav.hxx (revision 3334a7e6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SVX_FILTNAV_HXX
24 #define _SVX_FILTNAV_HXX
25 
26 #include <com/sun/star/form/XForm.hpp>
27 #include <com/sun/star/form/runtime/XFormController.hpp>
28 #include <com/sun/star/form/runtime/XFilterController.hpp>
29 #include <svl/lstner.hxx>
30 #include <svl/brdcst.hxx>
31 
32 #include <vcl/window.hxx>
33 #include <sfx2/childwin.hxx>
34 #include <svl/poolitem.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/dockwin.hxx>
37 #include <sfx2/ctrlitem.hxx>
38 #include <vcl/image.hxx>
39 #include <svtools/svtreebx.hxx>
40 
41 #include <vcl/dialog.hxx>
42 #include <vcl/group.hxx>
43 #include <vcl/dockwin.hxx>
44 #include "svx/fmtools.hxx"
45 #include "fmexch.hxx"
46 #include <connectivity/sqlparse.hxx>
47 #include "fmexch.hxx"
48 #include "sqlparserclient.hxx"
49 
50 class FmFormShell;
51 
52 //........................................................................
53 namespace svxform
54 {
55 //........................................................................
56 
57 class FmFilterItem;
58 class FmFilterItems;
59 class FmParentData;
60 class FmFilterAdapter;
61 
62 //========================================================================
63 // data structure for the filter model
64 //========================================================================
65 class FmFilterData
66 {
67 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xORB;
68 	FmParentData*			m_pParent;
69 	::rtl::OUString			m_aText;
70 
71 public:
72 	TYPEINFO();
FmFilterData(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory,FmParentData * pParent=NULL,const::rtl::OUString & rText=::rtl::OUString ())73 	FmFilterData(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmParentData* pParent = NULL, const ::rtl::OUString& rText = ::rtl::OUString())
74 		:m_xORB( _rxFactory )
75         ,m_pParent( pParent )
76 		,m_aText( rText )
77 	{}
~FmFilterData()78 	virtual ~FmFilterData(){}
79 
SetText(const::rtl::OUString & rText)80 	void    SetText( const ::rtl::OUString& rText ){ m_aText = rText; }
GetText() const81 	::rtl::OUString  GetText() const { return m_aText; }
GetParent() const82 	FmParentData* GetParent() const {return m_pParent;}
83 
84 	virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
85 };
86 
87 //========================================================================
88 class FmParentData : public FmFilterData
89 {
90 protected:
91 	::std::vector< FmFilterData* >  m_aChildren;
92 
93 public:
94 	TYPEINFO();
FmParentData(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory,FmParentData * pParent,const::rtl::OUString & rText)95 	FmParentData(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmParentData* pParent, const ::rtl::OUString& rText)
96 		: FmFilterData(_rxFactory,pParent, rText)
97 	{}
98 	virtual ~FmParentData();
99 
GetChildren()100 	::std::vector< FmFilterData* >& GetChildren() { return m_aChildren; }
101 };
102 
103 //========================================================================
104 // Item representing the forms and subforms
105 class FmFormItem : public FmParentData
106 {
107     ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >    m_xController;
108     ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFilterController >  m_xFilterController;
109 
110 public:
111 	TYPEINFO();
112 
FmFormItem(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory,FmParentData * _pParent,const::com::sun::star::uno::Reference<::com::sun::star::form::runtime::XFormController> & _xController,const::rtl::OUString & _rText)113     FmFormItem(  const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmParentData* _pParent,
114                  const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & _xController,
115 				 const ::rtl::OUString& _rText)
116         :FmParentData( _rxFactory, _pParent, _rText )
117 		,m_xController( _xController )
118         ,m_xFilterController( _xController, ::com::sun::star::uno::UNO_QUERY_THROW )
119     {
120     }
121 
122 	inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >&
GetController()123         GetController() { return m_xController; }
124 
125 	inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFilterController >&
GetFilterController()126         GetFilterController() { return m_xFilterController; }
127 
128 	virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
129 };
130 
131 //========================================================================
132 class FmFilterItems : public FmParentData
133 {
134 public:
135 	TYPEINFO();
FmFilterItems(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)136 	FmFilterItems(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory):FmParentData(_rxFactory,NULL, ::rtl::OUString()){}
FmFilterItems(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory,FmFormItem * pParent,const::rtl::OUString & rText)137 	FmFilterItems(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmFormItem* pParent, const ::rtl::OUString& rText ):FmParentData(_rxFactory,pParent, rText){}
138 
139     FmFilterItem* Find( const ::sal_Int32 _nFilterComponentIndex ) const;
140 	virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
141 };
142 
143 //========================================================================
144 class FmFilterItem : public FmFilterData
145 {
146 	::rtl::OUString     m_aFieldName;
147     const sal_Int32     m_nComponentIndex;
148 
149 public:
150 	TYPEINFO();
151 	FmFilterItem(
152         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,
153 		FmFilterItems* pParent,
154 		const ::rtl::OUString& aFieldName,
155 		const ::rtl::OUString& aCondition,
156         const sal_Int32 _nComponentIndex
157     );
158 
GetFieldName() const159 	const ::rtl::OUString& GetFieldName() const {return m_aFieldName;}
GetComponentIndex() const160     sal_Int32 GetComponentIndex() const { return m_nComponentIndex; }
161 
162 	virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
163 };
164 
165 //========================================================================
166 class FmFilterModel : public FmParentData
167 					 ,public SfxBroadcaster
168 					 ,public ::svxform::OSQLParserClient
169 {
170 	friend class FmFilterAdapter;
171 
172     ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >           m_xControllers;
173     ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >    m_xController;
174     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >        m_xORB;
175 	FmFilterAdapter*		m_pAdapter;
176 	FmFilterItems*			m_pCurrentItems;
177 
178 public:
179 	TYPEINFO();
180 	FmFilterModel(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory);
181 	virtual ~FmFilterModel();
182 
183 	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);
184 	void Clear();
185 	sal_Bool ValidateText(FmFilterItem* pItem, UniString& rText, UniString& rErrorMsg) const;
186 	void Append(FmFilterItems* pItems, FmFilterItem* pFilterItem);
187 	void SetTextForItem(FmFilterItem* pItem, const ::rtl::OUString& rText);
188 
GetCurrentForm() const189 	FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? (FmFormItem*)m_pCurrentItems->GetParent() : NULL;}
GetCurrentItems() const190 	FmFilterItems* GetCurrentItems() const {return m_pCurrentItems;}
191 	void SetCurrentItems(FmFilterItems* pCurrent);
getORB() const192 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getORB() const { return m_xORB; }
193 
GetControllers() const194 	const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & GetControllers() const {return m_xControllers;}
GetCurrentController() const195 	const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & GetCurrentController() const {return m_xController;}
196 	void SetCurrentController(const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xController);
197 
198 	void Remove(FmFilterData* pFilterItem);
199 	void AppendFilterItems( FmFormItem& _rItem );
200 	void EnsureEmptyFilterRows( FmParentData& _rItem );
201 
202 protected:
203 	void Insert(const ::std::vector<FmFilterData*>::iterator& rPos, FmFilterData* pFilterItem);
204 	void Remove( const ::std::vector<FmFilterData*>::iterator& rPos );
205 	FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xController) const;
206 	FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& xForm) const;
207 	void Update(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers, FmParentData* pParent);
208 };
209 
210 //========================================================================
211 //========================================================================
212 class OFilterItemExchange : public OLocalExchange
213 {
214 	::std::vector<FmFilterItem*>	m_aDraggedEntries;
215 	FmFormItem*				m_pFormItem;		// ensure that we drop on the same form
216 
217 public:
218 	OFilterItemExchange();
219 
220 	static sal_uInt32		getFormatId( );
221 	inline static sal_Bool	hasFormat( const DataFlavorExVector& _rFormats );
222 
getDraggedEntries() const223 	const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; }
setDraggedEntries(const::std::vector<FmFilterItem * > & _rList)224 	void setDraggedEntries(const ::std::vector<FmFilterItem*>& _rList) { m_aDraggedEntries = _rList; }
getFormItem() const225 	FmFormItem* getFormItem() const { return m_pFormItem; }
226 
setFormItem(FmFormItem * _pItem)227 	void setFormItem( FmFormItem* _pItem ) { m_pFormItem = _pItem; }
addSelectedItem(FmFilterItem * _pItem)228 	void addSelectedItem( FmFilterItem* _pItem) { m_aDraggedEntries.push_back(_pItem); }
229 
230 protected:
231 	virtual void AddSupportedFormats();
232 };
233 
hasFormat(const DataFlavorExVector & _rFormats)234 inline sal_Bool OFilterItemExchange::hasFormat( const DataFlavorExVector& _rFormats )
235 {
236 	return OLocalExchange::hasFormat( _rFormats, getFormatId() );
237 }
238 
239 //====================================================================
240 //= OFilterExchangeHelper
241 //====================================================================
242 class OFilterExchangeHelper : public OLocalExchangeHelper
243 {
244 public:
OFilterExchangeHelper(Window * _pDragSource)245 	OFilterExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { }
246 
operator ->() const247 	OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_pTransferable); }
248 
249 protected:
250 	virtual OLocalExchange* createExchange() const;
251 };
252 
253 //========================================================================
254 class FmFilterNavigator : public SvTreeListBox, public SfxListener
255 {
256 	enum DROP_ACTION{ DA_SCROLLUP, DA_SCROLLDOWN, DA_EXPANDNODE };
257 
258 	FmFilterModel*			m_pModel;
259 	SvLBoxEntry*			m_pEditingCurrently;
260 	OFilterExchangeHelper	m_aControlExchange;
261 
262 
263 	AutoTimer           m_aDropActionTimer;
264 	unsigned short      m_aTimerCounter;
265 	Point               m_aTimerTriggered;      // die Position, an der der DropTimer angeschaltet wurde
266 	DROP_ACTION         m_aDropActionType;
267 
268 public:
269 	FmFilterNavigator( Window* pParent );
270 	virtual ~FmFilterNavigator();
271 
272 	void UpdateContent(
273             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers,
274             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xCurrent
275         );
GetFilterModel() const276 	const FmFilterModel* GetFilterModel() const {return m_pModel;}
277 
278 protected:
279     using Control::Notify;
280 
281 	virtual void KeyInput( const KeyEvent& rKEvt );
282 	virtual void Command( const CommandEvent& rEvt );
283 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
284 	virtual void InitEntry(SvLBoxEntry* pEntry, const XubString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind);
285 	virtual sal_Bool Select( SvLBoxEntry* pEntry, sal_Bool bSelect=sal_True );
286 	virtual sal_Bool EditingEntry( SvLBoxEntry* pEntry, Selection& rSelection );
287 	virtual sal_Bool EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText );
288 
289 	virtual sal_Int8	AcceptDrop( const AcceptDropEvent& rEvt );
290 	virtual sal_Int8	ExecuteDrop( const ExecuteDropEvent& rEvt );
291 	virtual void		StartDrag( sal_Int8 nAction, const Point& rPosPixel );
292 
293 	void DeleteSelection();
294 	void Clear();
295 	SvLBoxEntry* FindEntry(const FmFilterData* pItem) const;
296 	void Insert(FmFilterData* pItem, sal_Int32 nPos);
297 	void Remove(FmFilterData* pItem);
298 
299 	DECL_LINK(OnRemove, SvLBoxEntry*);
300 	DECL_LINK(OnEdited, SvLBoxEntry*);
301 	DECL_LINK(OnDropActionTimer, void*);
302 
303 private:
304 	/** returns the first form item and the selected FilterItems in the vector
305 		@param	_rItemList
306 			Is filled inside. <OUT/>
307 		@return
308 			The first form item.
309 	*/
310 	FmFormItem* getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList);
311 	/* inserts the filter items into the tree model and creates new FilterItems if needed.
312 		@param	_rFilterList
313 			The items which should be inserted.
314 		@param	_pTargetItems
315 			The target where to insert the items.
316 		@param	_bCopy
317 			If <TRUE/> the items will not be removed from the model, otherwise they will.
318 	*/
319 	void insertFilterItem(const ::std::vector<FmFilterItem*>& _rFilterList,FmFilterItems* _pTargetItems,sal_Bool _bCopy = sal_False);
320 	SvLBoxEntry* getPrevEntry(SvLBoxEntry* _pStartWith = NULL);
321 	SvLBoxEntry* getNextEntry(SvLBoxEntry* _pStartWith = NULL);
322 
323     using SvTreeListBox::Select;
324     using SvTreeListBox::ExecuteDrop;
325     using SvTreeListBox::Insert;
326 };
327 
328 //========================================================================
329 class FmFilterNavigatorWin : public SfxDockingWindow, public SfxControllerItem
330 {
331 private:
332 	FmFilterNavigator* m_pNavigator;
333 
334 protected:
335 	virtual void Resize();
336 	virtual sal_Bool Close();
337 	virtual Size CalcDockingSize( SfxChildAlignment );
338 	virtual SfxChildAlignment CheckAlignment( SfxChildAlignment, SfxChildAlignment );
339 
340 public:
341 	FmFilterNavigatorWin( SfxBindings *pBindings, SfxChildWindow *pMgr,
342 				   Window* pParent );
343 	virtual ~FmFilterNavigatorWin();
344 
345 	void UpdateContent( FmFormShell* pFormShell );
346 	void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
347 	void FillInfo( SfxChildWinInfo& rInfo ) const;
348 
349     using SfxDockingWindow::StateChanged;
350 
351 	virtual void GetFocus();
352 };
353 
354 //========================================================================
355 class FmFilterNavigatorWinMgr : public SfxChildWindow
356 {
357 public:
358 	FmFilterNavigatorWinMgr( Window *pParent, sal_uInt16 nId, SfxBindings *pBindings,
359 					  SfxChildWinInfo *pInfo );
360 	SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr );
361 };
362 
363 //........................................................................
364 }	// namespace svxform
365 //........................................................................
366 
367 #endif // _SVX_FILTNAV_HXX
368 
369