1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX
20 #define INCLUDED_SVX_SOURCE_INC_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/SfxBroadcaster.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"
42 #include "sqlparserclient.hxx"
54 class FmFilterAdapter
;
57 // data structure for the filter model
61 FmParentData
* m_pParent
;
66 FmFilterData(FmParentData
* pParent
= NULL
, const OUString
& rText
= OUString())
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;
80 class FmParentData
: public FmFilterData
83 ::std::vector
< FmFilterData
* > m_aChildren
;
87 FmParentData(FmParentData
* pParent
, const OUString
& rText
)
88 : FmFilterData(pParent
, rText
)
90 virtual ~FmParentData();
92 ::std::vector
< FmFilterData
* >& GetChildren() { return m_aChildren
; }
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
;
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 SAL_OVERRIDE
;
124 class FmFilterItems
: public FmParentData
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 SAL_OVERRIDE
;
136 class FmFilterItem
: public FmFilterData
138 OUString m_aFieldName
;
139 const sal_Int32 m_nComponentIndex
;
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 SAL_OVERRIDE
;
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
;
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
);
175 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
? static_cast<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 static void AppendFilterItems( FmFormItem
& _rItem
);
189 void EnsureEmptyFilterRows( FmParentData
& _rItem
);
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
);
201 class OFilterItemExchange
: public OLocalExchange
203 ::std::vector
<FmFilterItem
*> m_aDraggedEntries
;
204 FmFormItem
* m_pFormItem
; // ensure that we drop on the same form
207 OFilterItemExchange();
209 static SotClipboardFormatId
getFormatId( );
210 inline static 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
); }
220 virtual void AddSupportedFormats() SAL_OVERRIDE
;
223 inline bool OFilterItemExchange::hasFormat( const DataFlavorExVector
& _rFormats
)
225 return OLocalExchange::hasFormat( _rFormats
, getFormatId() );
228 class OFilterExchangeHelper
: public OLocalExchangeHelper
231 OFilterExchangeHelper(vcl::Window
* _pDragSource
) : OLocalExchangeHelper(_pDragSource
) { }
233 OFilterItemExchange
* operator->() const { return static_cast<OFilterItemExchange
*>(m_pTransferable
); }
236 virtual OLocalExchange
* createExchange() const SAL_OVERRIDE
;
240 class FmFilterNavigator
: public SvTreeListBox
, public SfxListener
242 enum DROP_ACTION
{ DA_SCROLLUP
, DA_SCROLLDOWN
, DA_EXPANDNODE
};
244 FmFilterModel
* m_pModel
;
245 SvTreeListEntry
* m_pEditingCurrently
;
246 OFilterExchangeHelper m_aControlExchange
;
249 AutoTimer m_aDropActionTimer
;
250 unsigned short m_aTimerCounter
;
251 Point m_aTimerTriggered
; // position, where DropTimer was started
252 DROP_ACTION m_aDropActionType
;
255 FmFilterNavigator( vcl::Window
* pParent
);
256 virtual ~FmFilterNavigator();
257 virtual void dispose() SAL_OVERRIDE
;
260 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
> & xControllers
,
261 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
> & xCurrent
263 const FmFilterModel
* GetFilterModel() const {return m_pModel
;}
266 using Control::Notify
;
268 virtual void KeyInput( const KeyEvent
& rKEvt
) SAL_OVERRIDE
;
269 virtual void Command( const CommandEvent
& rEvt
) SAL_OVERRIDE
;
270 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) SAL_OVERRIDE
;
271 virtual void InitEntry(SvTreeListEntry
* pEntry
, const OUString
& rStr
, const Image
& rImg1
, const Image
& rImg2
, SvLBoxButtonKind eButtonKind
) SAL_OVERRIDE
;
272 virtual bool Select( SvTreeListEntry
* pEntry
, bool bSelect
=true ) SAL_OVERRIDE
;
273 virtual bool EditingEntry( SvTreeListEntry
* pEntry
, Selection
& rSelection
) SAL_OVERRIDE
;
274 virtual bool EditedEntry( SvTreeListEntry
* pEntry
, const OUString
& rNewText
) SAL_OVERRIDE
;
276 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) SAL_OVERRIDE
;
277 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) SAL_OVERRIDE
;
278 virtual void StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
) SAL_OVERRIDE
;
280 void DeleteSelection();
281 SvTreeListEntry
* FindEntry(const FmFilterData
* pItem
) const;
282 void Insert(FmFilterData
* pItem
, sal_uLong nPos
);
283 void Remove(FmFilterData
* pItem
);
285 DECL_LINK(OnRemove
, SvTreeListEntry
*);
286 DECL_LINK(OnEdited
, SvTreeListEntry
*);
287 DECL_LINK_TYPED(OnDropActionTimer
, Timer
*, void);
290 /** returns the first form item and the selected FilterItems in the vector
292 Is filled inside. <OUT/>
296 FmFormItem
* getSelectedFilterItems(::std::vector
<FmFilterItem
*>& _rItemList
);
298 * inserts the filter items into the tree model and creates new FilterItems if needed.
299 * @param _rFilterList
300 * The items which should be inserted.
301 * @param _pTargetItems
302 * The target where to insert the items.
304 * If <TRUE/> the items will not be removed from the model, otherwise they will.
306 void insertFilterItem(const ::std::vector
<FmFilterItem
*>& _rFilterList
,FmFilterItems
* _pTargetItems
, bool _bCopy
= false);
307 SvTreeListEntry
* getPrevEntry(SvTreeListEntry
* _pStartWith
= NULL
);
308 SvTreeListEntry
* getNextEntry(SvTreeListEntry
* _pStartWith
= NULL
);
310 using SvTreeListBox::Select
;
311 using SvTreeListBox::ExecuteDrop
;
312 using SvTreeListBox::Insert
;
316 class FmFilterNavigatorWin
: public SfxDockingWindow
, public SfxControllerItem
319 VclPtr
<FmFilterNavigator
> m_pNavigator
;
322 virtual void Resize() SAL_OVERRIDE
;
323 virtual bool Close() SAL_OVERRIDE
;
324 virtual Size
CalcDockingSize( SfxChildAlignment
) SAL_OVERRIDE
;
325 virtual SfxChildAlignment
CheckAlignment( SfxChildAlignment
, SfxChildAlignment
) SAL_OVERRIDE
;
328 FmFilterNavigatorWin( SfxBindings
*pBindings
, SfxChildWindow
*pMgr
,
329 vcl::Window
* pParent
);
330 virtual ~FmFilterNavigatorWin();
331 virtual void dispose() SAL_OVERRIDE
;
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
;
337 using SfxDockingWindow::StateChanged
;
339 virtual void GetFocus() SAL_OVERRIDE
;
343 class FmFilterNavigatorWinMgr
: public SfxChildWindow
346 FmFilterNavigatorWinMgr( vcl::Window
*pParent
, sal_uInt16 nId
, SfxBindings
*pBindings
,
347 SfxChildWinInfo
*pInfo
);
348 SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr
);
355 #endif // INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */