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>
29 #include <vcl/window.hxx>
30 #include <sfx2/childwin.hxx>
31 #include <svl/poolitem.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dockwin.hxx>
34 #include <sfx2/ctrlitem.hxx>
37 #include "sqlparserclient.hxx"
47 class FmFilterAdapter
;
49 // data structure for the filter model
52 FmParentData
* m_pParent
;
56 FmFilterData(FmParentData
* pParent
, OUString aText
)
58 ,m_aText(std::move( aText
))
60 virtual ~FmFilterData(){}
62 void SetText( const OUString
& rText
){ m_aText
= rText
; }
63 const OUString
& GetText() const { return m_aText
; }
64 FmParentData
* GetParent() const {return m_pParent
;}
66 virtual OUString
GetImage() const;
69 class FmParentData
: public FmFilterData
72 ::std::vector
< std::unique_ptr
<FmFilterData
> > m_aChildren
;
75 FmParentData(FmParentData
* pParent
, const OUString
& rText
)
76 : FmFilterData(pParent
, rText
)
78 virtual ~FmParentData() override
;
80 ::std::vector
< std::unique_ptr
<FmFilterData
> >& GetChildren() { return m_aChildren
; }
83 // Item representing the forms and subforms
84 class FmFormItem final
: public FmParentData
86 css::uno::Reference
< css::form::runtime::XFormController
> m_xController
;
87 css::uno::Reference
< css::form::runtime::XFilterController
> m_xFilterController
;
91 FmFormItem( FmParentData
* _pParent
,
92 const css::uno::Reference
< css::form::runtime::XFormController
> & _xController
,
93 const OUString
& _rText
)
94 :FmParentData( _pParent
, _rText
)
95 ,m_xController( _xController
)
96 ,m_xFilterController( _xController
, css::uno::UNO_QUERY_THROW
)
100 const css::uno::Reference
< css::form::runtime::XFormController
>&
101 GetController() const { return m_xController
; }
103 const css::uno::Reference
< css::form::runtime::XFilterController
>&
104 GetFilterController() const { return m_xFilterController
; }
106 virtual OUString
GetImage() const override
;
109 class FmFilterItems final
: public FmParentData
112 FmFilterItems(FmFormItem
* pParent
, const OUString
& rText
) : FmParentData(pParent
, rText
) {}
114 FmFilterItem
* Find( const ::sal_Int32 _nFilterComponentIndex
) const;
115 virtual OUString
GetImage() const override
;
118 class FmFilterItem final
: public FmFilterData
120 OUString m_aFieldName
;
121 sal_Int32 m_nComponentIndex
;
125 FmFilterItems
* pParent
,
127 const OUString
& aCondition
,
128 const sal_Int32 _nComponentIndex
131 const OUString
& GetFieldName() const {return m_aFieldName
;}
132 sal_Int32
GetComponentIndex() const { return m_nComponentIndex
; }
134 virtual OUString
GetImage() const override
;
137 class FmFilterModel final
: public FmParentData
138 ,public SfxBroadcaster
139 ,public ::svxform::OSQLParserClient
141 friend class FmFilterAdapter
;
143 css::uno::Reference
< css::container::XIndexAccess
> m_xControllers
;
144 css::uno::Reference
< css::form::runtime::XFormController
> m_xController
;
145 rtl::Reference
<FmFilterAdapter
> m_pAdapter
;
146 FmFilterItems
* m_pCurrentItems
;
150 virtual ~FmFilterModel() override
;
152 void Update(const css::uno::Reference
< css::container::XIndexAccess
> & xControllers
, const css::uno::Reference
< css::form::runtime::XFormController
> & xCurrent
);
154 bool ValidateText(FmFilterItem
const * pItem
, OUString
& rText
, OUString
& rErrorMsg
) const;
155 void Append(FmFilterItems
* pItems
, std::unique_ptr
<FmFilterItem
> pFilterItem
);
156 void SetTextForItem(FmFilterItem
* pItem
, const OUString
& rText
);
158 FmFormItem
* GetCurrentForm() const {return m_pCurrentItems
? static_cast<FmFormItem
*>(m_pCurrentItems
->GetParent()) : nullptr;}
159 FmFilterItems
* GetCurrentItems() const {return m_pCurrentItems
;}
160 void SetCurrentItems(FmFilterItems
* pCurrent
);
162 const css::uno::Reference
< css::form::runtime::XFormController
> & GetCurrentController() const {return m_xController
;}
163 void SetCurrentController(const css::uno::Reference
< css::form::runtime::XFormController
> & xController
);
165 void Remove(FmFilterData
* pFilterItem
);
166 static void AppendFilterItems( FmFormItem
& _rItem
);
167 void EnsureEmptyFilterRows( FmParentData
& _rItem
);
170 void Insert(const ::std::vector
<std::unique_ptr
<FmFilterData
>>::iterator
& rPos
, std::unique_ptr
<FmFilterData
> pFilterItem
);
171 void Remove( const ::std::vector
<std::unique_ptr
<FmFilterData
>>::iterator
& rPos
);
172 FmFormItem
* Find(const ::std::vector
<std::unique_ptr
<FmFilterData
>>& rItems
, const css::uno::Reference
< css::form::runtime::XFormController
> & xController
) const;
173 FmFormItem
* Find(const ::std::vector
<std::unique_ptr
<FmFilterData
>>& rItems
, const css::uno::Reference
< css::form::XForm
>& xForm
) const;
174 void Update(const css::uno::Reference
< css::container::XIndexAccess
> & xControllers
, FmParentData
* pParent
);
178 class OFilterItemExchange final
: public OLocalExchange
180 ::std::vector
<FmFilterItem
*> m_aDraggedEntries
;
181 FmFormItem
* m_pFormItem
; // ensure that we drop on the same form
184 OFilterItemExchange();
186 static SotClipboardFormatId
getFormatId( );
187 inline static bool hasFormat( const DataFlavorExVector
& _rFormats
);
189 const ::std::vector
<FmFilterItem
*>& getDraggedEntries() const { return m_aDraggedEntries
; }
190 void setDraggedEntries(::std::vector
<FmFilterItem
*>&& _rList
) { m_aDraggedEntries
= std::move(_rList
); }
191 FmFormItem
* getFormItem() const { return m_pFormItem
; }
193 void setFormItem( FmFormItem
* _pItem
) { m_pFormItem
= _pItem
; }
196 virtual void AddSupportedFormats() override
;
199 inline bool OFilterItemExchange::hasFormat( const DataFlavorExVector
& _rFormats
)
201 return OLocalExchange::hasFormat( _rFormats
, getFormatId() );
204 class OFilterExchangeHelper final
: public OLocalExchangeHelper
207 OFilterExchangeHelper() : OLocalExchangeHelper() { }
209 OFilterItemExchange
* operator->() const { return static_cast<OFilterItemExchange
*>(m_xTransferable
.get()); }
210 OFilterItemExchange
& operator*() const { return *static_cast<OFilterItemExchange
*>(m_xTransferable
.get()); }
213 virtual rtl::Reference
<OLocalExchange
> createExchange() const override
;
216 class FmFilterNavigator
;
218 class FmFilterNavigatorDropTarget final
: public DropTargetHelper
221 FmFilterNavigator
& m_rTreeView
;
223 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
224 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
227 FmFilterNavigatorDropTarget(FmFilterNavigator
& rTreeView
);
230 class FmFilterNavigator final
: public SfxListener
232 VclPtr
<vcl::Window
> m_xTopLevel
;
233 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
234 FmFilterNavigatorDropTarget m_aDropTargetHelper
;
236 std::unique_ptr
<FmFilterModel
> m_pModel
;
237 std::unique_ptr
<weld::TreeIter
> m_xEditingCurrently
;
238 OFilterExchangeHelper m_aControlExchange
;
240 ImplSVEvent
* m_nAsyncRemoveEvent
;
243 FmFilterNavigator(vcl::Window
* pTopLevel
, std::unique_ptr
<weld::TreeView
> xTreeView
);
244 virtual ~FmFilterNavigator() override
;
246 void GrabFocus() { m_xTreeView
->grab_focus(); }
251 const css::uno::Reference
< css::container::XIndexAccess
> & xControllers
,
252 const css::uno::Reference
< css::form::runtime::XFormController
> & xCurrent
255 weld::TreeView
& get_widget() { return *m_xTreeView
; }
257 sal_Int8
AcceptDrop(const AcceptDropEvent
& rEvt
);
258 sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
);
261 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
262 DECL_LINK(PopupMenuHdl
, const CommandEvent
&, bool);
263 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
265 DECL_STATIC_LINK(FmFilterNavigator
, CustomGetSizeHdl
, weld::TreeView::get_size_args
, Size
);
266 DECL_STATIC_LINK(FmFilterNavigator
, CustomRenderHdl
, weld::TreeView::render_args
, void);
268 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
269 DECL_LINK(EditingEntryHdl
, const weld::TreeIter
&, bool);
270 typedef std::pair
<const weld::TreeIter
&, OUString
> IterString
;
271 DECL_LINK(EditedEntryHdl
, const IterString
&, bool);
273 DECL_LINK(DragBeginHdl
, bool&, bool);
275 void DeleteSelection();
276 std::unique_ptr
<weld::TreeIter
> FindEntry(const FmFilterData
* pItem
) const;
277 void Insert(const FmFilterData
* pItem
, int nPos
);
278 void Remove(FmFilterData
const * pItem
);
280 DECL_LINK(OnRemove
, void*, void);
282 /** returns the first form item and the selected FilterItems in the vector
284 Is filled inside. <OUT/>
288 FmFormItem
* getSelectedFilterItems(::std::vector
<FmFilterItem
*>& _rItemList
);
291 * inserts the filter items into the tree model and creates new FilterItems if needed.
292 * @param _rFilterList
293 * The items which should be inserted.
294 * @param _pTargetItems
295 * The target where to insert the items.
297 * If <TRUE/> the items will not be removed from the model, otherwise they will.
299 void insertFilterItem(const ::std::vector
<FmFilterItem
*>& _rFilterList
,FmFilterItems
* _pTargetItems
, bool _bCopy
);
301 bool getPrevEntry(weld::TreeIter
& rEntry
);
302 bool getNextEntry(weld::TreeIter
& rEntry
);
305 class FmFilterNavigatorWin final
: public SfxDockingWindow
, public SfxControllerItem
308 std::unique_ptr
<FmFilterNavigator
> m_xNavigatorTree
;
310 virtual bool Close() override
;
311 virtual void GetFocus() override
;
312 virtual Size
CalcDockingSize( SfxChildAlignment
) override
;
313 virtual SfxChildAlignment
CheckAlignment( SfxChildAlignment
, SfxChildAlignment
) override
;
315 using SfxDockingWindow::StateChanged
;
318 FmFilterNavigatorWin( SfxBindings
*pBindings
, SfxChildWindow
*pMgr
,
319 vcl::Window
* pParent
);
320 virtual ~FmFilterNavigatorWin() override
;
321 virtual void dispose() override
;
323 void UpdateContent( FmFormShell
const * pFormShell
);
324 void StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
) override
;
325 void FillInfo( SfxChildWinInfo
& rInfo
) const override
;
328 class FmFilterNavigatorWinMgr final
: public SfxChildWindow
331 FmFilterNavigatorWinMgr( vcl::Window
*pParent
, sal_uInt16 nId
, SfxBindings
*pBindings
,
332 SfxChildWinInfo
*pInfo
);
333 SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr
);
338 #endif // INCLUDED_SVX_SOURCE_INC_FILTNAV_HXX
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */