1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filtnav.hxx,v $
10 * $Revision: 1.19.216.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SVX_FILTNAV_HXX
31 #define _SVX_FILTNAV_HXX
33 #include <com/sun/star/awt/XTextComponent.hpp>
34 #include <com/sun/star/form/XForm.hpp>
35 #include <svtools/lstner.hxx>
36 #include <svtools/brdcst.hxx>
37 #include <vcl/window.hxx>
38 #include <sfx2/childwin.hxx>
39 #include <svtools/poolitem.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <sfx2/dockwin.hxx>
42 #include <sfx2/ctrlitem.hxx>
43 #include <vcl/image.hxx>
44 #include <svtools/svtreebx.hxx>
46 #include <vcl/dialog.hxx>
47 #include <vcl/group.hxx>
48 #include <vcl/dockwin.hxx>
49 #include "fmtools.hxx"
51 #include <connectivity/sqlparse.hxx>
53 #include "sqlparserclient.hxx"
57 //........................................................................
60 //........................................................................
65 class FmFilterAdapter
;
67 //========================================================================
68 // data structure for the filter model
69 //========================================================================
72 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xORB
;
73 FmParentData
* m_pParent
;
74 ::rtl::OUString m_aText
;
78 FmFilterData(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,FmParentData
* pParent
= NULL
, const ::rtl::OUString
& rText
= ::rtl::OUString())
83 virtual ~FmFilterData(){}
85 void SetText( const ::rtl::OUString
& rText
){ m_aText
= rText
; }
86 ::rtl::OUString
GetText() const { return m_aText
; }
87 FmParentData
* GetParent() const {return m_pParent
;}
89 virtual Image
GetImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
92 //========================================================================
93 class FmParentData
: public FmFilterData
96 ::std::vector
<FmFilterData
*> m_aChilds
;
101 FmParentData(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,FmParentData
* pParent
, const ::rtl::OUString
& rText
)
102 : FmFilterData(_rxFactory
,pParent
, rText
)
104 virtual ~FmParentData();
106 ::std::vector
<FmFilterData
*>& GetChilds() {return m_aChilds
;}
109 //========================================================================
110 // Item representing the forms and subforms
111 class FmFormItem
: public FmParentData
113 ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> m_xController
;
114 sal_Int32 m_nCurrent
;
118 FmFormItem(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
):FmParentData(_rxFactory
,NULL
, ::rtl::OUString()){}
119 FmFormItem(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,FmParentData
* _pParent
,
120 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> & _xController
,
121 const ::rtl::OUString
& _rText
):FmParentData(_rxFactory
,_pParent
, _rText
)
122 ,m_xController(_xController
)
125 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> & GetController(){return m_xController
;}
126 void SetCurrentPosition(sal_Int32 nCurrent
){m_nCurrent
= nCurrent
;}
127 sal_Int32
GetCurrentPosition() const {return m_nCurrent
;}
128 virtual Image
GetImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
131 //========================================================================
132 class FmFilterItems
: public FmParentData
136 FmFilterItems(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
):FmParentData(_rxFactory
,NULL
, ::rtl::OUString()){}
137 FmFilterItems(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,FmFormItem
* pParent
, const ::rtl::OUString
& rText
):FmParentData(_rxFactory
,pParent
, rText
){}
139 FmFilterItem
* Find(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextComponent
> & xText
) const;
140 virtual Image
GetImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
143 //========================================================================
144 class FmFilterItem
: public FmFilterData
146 ::rtl::OUString m_aFieldName
;
147 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextComponent
> m_xText
;
151 FmFilterItem(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,
152 FmFilterItems
* pParent
,
153 const ::rtl::OUString
& aFieldName
,
154 const ::rtl::OUString
& aCondition
,
155 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextComponent
> & xText
);
157 const ::rtl::OUString
& GetFieldName() const {return m_aFieldName
;}
158 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextComponent
> & GetTextComponent() const {return m_xText
;}
160 virtual Image
GetImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
163 //========================================================================
164 class FmFilterModel
: public FmParentData
165 ,public SfxBroadcaster
166 ,public ::svxform::OSQLParserClient
168 friend class FmFilterAdapter
;
170 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
> m_xControllers
;
171 ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> m_xController
;
172 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xORB
;
173 FmFilterAdapter
* m_pAdapter
;
174 FmFilterItems
* m_pCurrentItems
;
178 FmFilterModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
);
179 virtual ~FmFilterModel();
181 void Update(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
> & xControllers
, const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> & xCurrent
);
183 sal_Bool
ValidateText(FmFilterItem
* pItem
, UniString
& rText
, UniString
& rErrorMsg
) const;
184 void Append(FmFilterItems
* pItems
, FmFilterItem
* pFilterItem
);
185 void SetTextForItem(FmFilterItem
* pItem
, const ::rtl::OUString
& rText
);
187 FmFormItem
* GetCurrentForm() const {return m_pCurrentItems
? (FmFormItem
*)m_pCurrentItems
->GetParent() : NULL
;}
188 FmFilterItems
* GetCurrentItems() const {return m_pCurrentItems
;}
189 void SetCurrentItems(FmFilterItems
* pCurrent
);
190 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> getORB() const { return m_xORB
; }
192 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
> & GetControllers() const {return m_xControllers
;}
193 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> & GetCurrentController() const {return m_xController
;}
194 void SetCurrentController(const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> & xController
);
196 void Remove(FmFilterData
* pFilterItem
);
197 void AppendFilterItems(FmFormItem
* pItem
);
198 void CheckIntegrity(FmParentData
* pItem
);
201 void Insert(const ::std::vector
<FmFilterData
*>::iterator
& rPos
, FmFilterData
* pFilterItem
);
202 void Remove(const ::std::vector
<FmFilterData
*>::iterator
& rPos
, FmFilterData
* pFilterItem
);
203 FmFormItem
* Find(const ::std::vector
<FmFilterData
*>& rItems
, const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> & xController
) const;
204 FmFormItem
* Find(const ::std::vector
<FmFilterData
*>& rItems
, const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XForm
>& xForm
) const;
205 void Update(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
> & xControllers
, FmParentData
* pParent
);
208 //========================================================================
209 //========================================================================
210 class OFilterItemExchange
: public OLocalExchange
212 ::std::vector
<FmFilterItem
*> m_aDraggedEntries
;
213 FmFormItem
* m_pFormItem
; // ensure that we drop on the same form
216 OFilterItemExchange();
218 static sal_uInt32
getFormatId( );
219 inline static sal_Bool
hasFormat( const DataFlavorExVector
& _rFormats
);
221 const ::std::vector
<FmFilterItem
*>& getDraggedEntries() const { return m_aDraggedEntries
; }
222 void setDraggedEntries(const ::std::vector
<FmFilterItem
*>& _rList
) { m_aDraggedEntries
= _rList
; }
223 FmFormItem
* getFormItem() const { return m_pFormItem
; }
225 void setFormItem( FmFormItem
* _pItem
) { m_pFormItem
= _pItem
; }
226 void addSelectedItem( FmFilterItem
* _pItem
) { m_aDraggedEntries
.push_back(_pItem
); }
229 virtual void AddSupportedFormats();
232 inline sal_Bool
OFilterItemExchange::hasFormat( const DataFlavorExVector
& _rFormats
)
234 return OLocalExchange::hasFormat( _rFormats
, getFormatId() );
237 //====================================================================
238 //= OFilterExchangeHelper
239 //====================================================================
240 class OFilterExchangeHelper
: public OLocalExchangeHelper
243 OFilterExchangeHelper(Window
* _pDragSource
) : OLocalExchangeHelper(_pDragSource
) { }
245 OFilterItemExchange
* operator->() const { return static_cast<OFilterItemExchange
*>(m_pTransferable
); }
248 virtual OLocalExchange
* createExchange() const;
251 //========================================================================
252 class FmFilterNavigator
: public SvTreeListBox
, public SfxListener
254 enum DROP_ACTION
{ DA_SCROLLUP
, DA_SCROLLDOWN
, DA_EXPANDNODE
};
256 FmFilterModel
* m_pModel
;
257 SvLBoxEntry
* m_pEditingCurrently
;
258 OFilterExchangeHelper m_aControlExchange
;
261 AutoTimer m_aDropActionTimer
;
262 unsigned short m_aTimerCounter
;
263 Point m_aTimerTriggered
; // die Position, an der der DropTimer angeschaltet wurde
264 DROP_ACTION m_aDropActionType
;
267 FmFilterNavigator( Window
* pParent
);
268 virtual ~FmFilterNavigator();
270 void UpdateContent(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
> & xControllers
, const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
> & xCurrent
);
271 const FmFilterModel
* GetFilterModel() const {return m_pModel
;}
274 using Control::Notify
;
276 virtual void KeyInput( const KeyEvent
& rKEvt
);
277 virtual void Command( const CommandEvent
& rEvt
);
278 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
279 virtual void InitEntry(SvLBoxEntry
* pEntry
, const XubString
& rStr
, const Image
& rImg1
, const Image
& rImg2
, SvLBoxButtonKind eButtonKind
);
280 virtual sal_Bool
Select( SvLBoxEntry
* pEntry
, sal_Bool bSelect
=sal_True
);
281 virtual sal_Bool
EditingEntry( SvLBoxEntry
* pEntry
, Selection
& rSelection
);
282 virtual sal_Bool
EditedEntry( SvLBoxEntry
* pEntry
, const XubString
& rNewText
);
284 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
);
285 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
);
286 virtual void StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
);
288 void DeleteSelection();
290 SvLBoxEntry
* FindEntry(const FmFilterData
* pItem
) const;
291 void Insert(FmFilterData
* pItem
, sal_Int32 nPos
);
292 void Remove(FmFilterData
* pItem
);
294 DECL_LINK(OnRemove
, SvLBoxEntry
*);
295 DECL_LINK(OnEdited
, SvLBoxEntry
*);
296 DECL_LINK(OnDropActionTimer
, void*);
299 /** returns the first form item and the selected FilterItems in the vector
301 Is filled inside. <OUT/>
305 FmFormItem
* getSelectedFilterItems(::std::vector
<FmFilterItem
*>& _rItemList
);
306 /* inserts the filter items into the tree model and creates new FilterItems if needed.
308 The items which should be inserted.
310 The target where to insert the items.
312 If <TRUE/> the items will not be removed from the model, otherwise they will.
314 void insertFilterItem(const ::std::vector
<FmFilterItem
*>& _rFilterList
,FmFilterItems
* _pTargetItems
,sal_Bool _bCopy
= sal_False
);
315 SvLBoxEntry
* getPrevEntry(SvLBoxEntry
* _pStartWith
= NULL
);
316 SvLBoxEntry
* getNextEntry(SvLBoxEntry
* _pStartWith
= NULL
);
318 using SvTreeListBox::Select
;
319 using SvTreeListBox::ExecuteDrop
;
320 using SvTreeListBox::Insert
;
323 //========================================================================
324 class FmFilterNavigatorWin
: public SfxDockingWindow
, public SfxControllerItem
327 FmFilterNavigator
* m_pNavigator
;
330 virtual void Resize();
331 virtual sal_Bool
Close();
332 virtual Size
CalcDockingSize( SfxChildAlignment
);
333 virtual SfxChildAlignment
CheckAlignment( SfxChildAlignment
, SfxChildAlignment
);
336 FmFilterNavigatorWin( SfxBindings
*pBindings
, SfxChildWindow
*pMgr
,
338 virtual ~FmFilterNavigatorWin();
340 void UpdateContent( FmFormShell
* pFormShell
);
341 void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
342 void FillInfo( SfxChildWinInfo
& rInfo
) const;
344 using SfxDockingWindow::StateChanged
;
346 virtual void GetFocus();
349 //========================================================================
350 class FmFilterNavigatorWinMgr
: public SfxChildWindow
353 FmFilterNavigatorWinMgr( Window
*pParent
, sal_uInt16 nId
, SfxBindings
*pBindings
,
354 SfxChildWinInfo
*pInfo
);
355 SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr
);
358 //........................................................................
359 } // namespace svxform
360 //........................................................................
362 #endif // _SVX_FILTNAV_HXX