LibreOffice Module sc (master) 1
checklistmenu.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#pragma once
11
12#include <vcl/timer.hxx>
13#include <vcl/virdev.hxx>
14#include <vcl/weld.hxx>
15
16#include <memory>
17#include <unordered_set>
18#include <map>
19#include <set>
20
22class ScViewData;
24struct ImplSVEvent;
25
27{
29 {
33 };
34
35 OUString maName; // node name
36 OUString maRealName;
37 double mnValue; // number value of filter condition
40 bool mbDate;
41 bool mbLeaf;
42 bool mbValue; // true if the filter condition is value
44 // To store Year and Month if the member if DAY type
45 std::vector<OUString> maDateParts;
47 std::unique_ptr<weld::TreeIter> mxParent;
48};
49
50class ScCheckListMenuWindow;
52
57{
58public:
59 static constexpr size_t MENU_NOT_SELECTED = 999;
60
65 class Action
66 {
67 public:
68 virtual ~Action() {}
69 // return true to dismiss the popup
70 virtual bool execute() = 0;
71 };
72
74 {
75 OUString aName;
76 double nValue; // number value of filter condition
77 bool bValid;
78 bool bDate;
79 bool bValue; // true if the filter condition is value
80
81 bool operator<(const ResultEntry& rhs) const
82 {
83 return aName < rhs.aName;
84 }
85
86 bool operator == (const ResultEntry& rhs) const
87 {
88 return aName == rhs.aName &&
89 bValid == rhs.bValid &&
90 bDate == rhs.bDate &&
91 bValue == rhs.bValue &&
92 nValue == rhs.nValue;
93 }
94 };
95 typedef std::set<ResultEntry> ResultType;
96
98 {
99 bool mbEnabled:1;
100 std::shared_ptr<Action> mxAction;
101 std::unique_ptr<ScListSubMenuControl> mxSubMenuWin;
102
103 MenuItemData();
104 };
105
111
112 virtual ~ExtendedData() {}
113
114 };
115
119 struct Config
120 {
122 bool mbRTL;
123 Config();
124 };
125
127 bool bTreeMode, int nWidth, bool bIsMultiField = false);
129
130 void addMenuItem(const OUString& rText, Action* pAction);
131 void addSeparator();
132 ScListSubMenuControl* addSubMenuItem(const OUString& rText, bool bEnabled, bool bColorMenu);
133
134 void selectMenuItem(size_t nPos, bool bSubMenuTimer);
135 void queueLaunchSubMenu(size_t nPos, ScListSubMenuControl* pMenu);
136
137 void setMemberSize(size_t n);
138 void addDateMember(const OUString& rName, double nVal, bool bVisible, bool bHiddenByOtherFilter);
139 void addMember(const OUString& rName, const double nVal, bool bVisible, bool bHiddenByOtherFilter,
140 bool bValue = false);
141 void clearMembers();
142 size_t initMembers(int nMaxMemberWidth = -1);
143 void setConfig(const Config& rConfig);
144
145 bool isAllSelected() const;
146 void getResult(ResultType& rResult);
147 void launch(weld::Widget* pWidget, const tools::Rectangle& rRect);
148 void close(bool bOK);
149
150 void StartPopupMode(weld::Widget* pParent, const tools::Rectangle& rRect);
151 void EndPopupMode();
152
153 size_t getSubMenuPos(const ScListSubMenuControl* pSubMenu);
154 void setSubMenuFocused(const ScListSubMenuControl* pSubMenu);
155 void queueCloseSubMenu();
157
163 void setExtendedData(std::unique_ptr<ExtendedData> p);
164
169
170 ScViewData& GetViewData() const { return mrViewData; }
171
172 void GrabFocus();
173
174 void setOKAction(Action* p);
175 void setPopupEndAction(Action* p);
177
178 int GetTextWidth(const OUString& rsName) const;
179 int IncreaseWindowWidthToFitText(int nMaxTextWidth);
180
186
187 void endSubMenu(ScListSubMenuControl& rSubMenu);
188
189 void addFields(const std::vector<OUString>& aFields);
191private:
192
193 std::vector<MenuItemData> maMenuItems;
194
198 void prepWindow();
199 void setAllMemberState(bool bSet);
200 void selectCurrentMemberOnly(bool bSet);
201 void updateMemberParents(const weld::TreeIter* pLeaf, size_t nIdx);
202
203 std::unique_ptr<weld::TreeIter> ShowCheckEntry(const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true);
204 void CheckEntry(std::u16string_view sName, const weld::TreeIter* pParent, bool bCheck);
205 void CheckEntry(const weld::TreeIter& rEntry, bool bCheck);
206 void GetRecursiveChecked(const weld::TreeIter* pEntry, std::unordered_set<OUString>& vOut, OUString& rLabel);
207 std::unordered_set<OUString> GetAllChecked();
208 bool IsChecked(std::u16string_view sName, const weld::TreeIter* pParent);
209 int GetCheckedEntryCount() const;
210 void CheckAllChildren(const weld::TreeIter& rEntry, bool bCheck);
211
212 void setSelectedMenuItem(size_t nPos);
213
214 std::unique_ptr<weld::TreeIter> FindEntry(const weld::TreeIter* pParent, std::u16string_view sNode);
215
216 void executeMenuItem(size_t nPos);
217
223
224 struct SubMenuItemData;
225
226 void handleMenuTimeout(const SubMenuItemData* pTimer);
227
228 void launchSubMenu();
229
230 void CreateDropDown();
231
232 DECL_LINK(ButtonHdl, weld::Button&, void);
233 DECL_LINK(TriStateHdl, weld::Toggleable&, void);
234
235 void Check(const weld::TreeIter* pIter);
236
237 DECL_LINK(CheckHdl, const weld::TreeView::iter_col&, void);
238
239 DECL_LINK(PopupModeEndHdl, weld::Popover&, void);
240
241 DECL_LINK(SearchEditTimeoutHdl, Timer*, void);
242 DECL_LINK(ComboChangedHdl, weld::ComboBox&, void);
243
244 DECL_LINK(EdModifyHdl, weld::Entry&, void);
245 DECL_LINK(EdActivateHdl, weld::Entry&, bool);
246
247 DECL_LINK(RowActivatedHdl, weld::TreeView& rMEvt, bool);
248 DECL_LINK(SelectHdl, weld::TreeView&, void);
249 DECL_LINK(TreeSizeAllocHdl, const Size&, void);
250 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
251 DECL_LINK(MenuKeyInputHdl, const KeyEvent&, bool);
252 DECL_LINK(MouseEnterHdl, const MouseEvent&, bool);
253
254 DECL_LINK(PostPopdownHdl, void*, void);
255
256 void SetDropdownPos();
257
258 DECL_LINK(SetDropdownPosHdl, void*, void);
259
260 DECL_LINK(CommandHdl, const CommandEvent&, bool);
261
262 void ResizeToRequest();
263
264 void DropPendingEvents();
265
266private:
267 std::unique_ptr<weld::Builder> mxBuilder;
268 std::unique_ptr<weld::Popover> mxPopover;
269 std::unique_ptr<weld::Container> mxContainer;
270 std::unique_ptr<weld::TreeView> mxMenu;
271 std::unique_ptr<weld::TreeIter> mxScratchIter;
272 std::unique_ptr<weld::Widget> mxNonMenu;
273 std::unique_ptr<weld::Label> mxFieldsComboLabel;
274 std::unique_ptr<weld::ComboBox> mxFieldsCombo;
275 std::unique_ptr<weld::Entry> mxEdSearch;
276 std::unique_ptr<weld::Widget> mxBox;
277 std::unique_ptr<weld::TreeView> mxListChecks;
278 std::unique_ptr<weld::TreeView> mxTreeChecks;
280
281 std::unique_ptr<weld::CheckButton> mxChkToggleAll;
282 std::unique_ptr<weld::Button> mxBtnSelectSingle;
283 std::unique_ptr<weld::Button> mxBtnUnselectSingle;
284
285 std::unique_ptr<weld::Box> mxButtonBox;
286 std::unique_ptr<weld::Button> mxBtnOk;
287 std::unique_ptr<weld::Button> mxBtnCancel;
288 std::unique_ptr<weld::Menu> mxContextMenu;
289
291
292 std::vector<ScCheckListMember> maMembers;
293 // For Dates
294 std::map<OUString, size_t> maYearMonthMap;
295
296 std::unique_ptr<ExtendedData> mxExtendedData;
297 std::unique_ptr<Action> mxOKAction;
298 std::unique_ptr<Action> mxPopupEndAction;
299 std::unique_ptr<Action> mxFieldChangedAction;
300
307
309
311
314
317
319 {
322 size_t mnMenuPos;
323
324 DECL_LINK( TimeoutHdl, Timer*, void );
325
327 void reset();
328
329 private:
331 };
332
335
338};
339
341{
342public:
343 ScListSubMenuControl(weld::Widget* pParent, ScCheckListMenuControl& rParentControl, bool bColorMenu);
344
346
347 void GrabFocus();
348 bool IsVisible() const;
349
350 void StartPopupMode(weld::Widget* pParent, const tools::Rectangle& rRect);
351 void EndPopupMode();
352
353 void addMenuItem(const OUString& rText, ScCheckListMenuControl::Action* pAction);
354 // nMenu of 0 for background color, nMenu of 1 for text color
355 void addMenuColorItem(const OUString& rText, bool bActive, VirtualDevice& rImage,
356 int nMenu, ScCheckListMenuControl::Action* pAction);
357 void addSeparator();
358 void clearMenuItems();
360
363 VclPtr<VirtualDevice> create_virtual_device() const { return mxMenu->create_virtual_device(); }
364
370
371private:
372 std::unique_ptr<weld::Builder> mxBuilder;
373 std::unique_ptr<weld::Popover> mxPopover;
374 std::unique_ptr<weld::Container> mxContainer;
375 std::unique_ptr<weld::TreeView> mxMenu;
376 std::unique_ptr<weld::TreeView> mxBackColorMenu;
377 std::unique_ptr<weld::TreeView> mxTextColorMenu;
378 std::unique_ptr<weld::TreeIter> mxScratchIter;
379 std::unique_ptr<ScCheckListMenuControl::Action> mxPopupStartAction;
380 std::vector<ScCheckListMenuControl::MenuItemData> maMenuItems;
385
386 DECL_LINK(RowActivatedHdl, weld::TreeView& rMEvt, bool);
387 DECL_LINK(ColorSelChangedHdl, weld::TreeView&, void);
388 DECL_LINK(MenuKeyInputHdl, const KeyEvent&, bool);
389
390 void SetupMenu(weld::TreeView& rMenu);
391
394};
395
396/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Action to perform when an event takes place.
This class implements a popup window for the auto filter dropdown.
std::unique_ptr< Action > mxPopupEndAction
std::unordered_set< OUString > GetAllChecked()
void setAllMemberState(bool bSet)
ScViewData & GetViewData() const
std::unique_ptr< weld::Entry > mxEdSearch
void addMember(const OUString &rName, const double nVal, bool bVisible, bool bHiddenByOtherFilter, bool bValue=false)
std::unique_ptr< weld::TreeIter > ShowCheckEntry(const OUString &sName, ScCheckListMember &rMember, bool bShow=true, bool bCheck=true)
DECL_LINK(RowActivatedHdl, weld::TreeView &rMEvt, bool)
void StartPopupMode(weld::Widget *pParent, const tools::Rectangle &rRect)
void getResult(ResultType &rResult)
std::unique_ptr< Action > mxFieldChangedAction
void CheckEntry(std::u16string_view sName, const weld::TreeIter *pParent, bool bCheck)
DECL_LINK(CommandHdl, const CommandEvent &, bool)
std::unique_ptr< weld::Button > mxBtnUnselectSingle
ScCheckListMenuControl(weld::Widget *pParent, ScViewData &rViewData, bool bTreeMode, int nWidth, bool bIsMultiField=false)
std::unique_ptr< weld::Widget > mxNonMenu
std::unique_ptr< Action > mxOKAction
void handleMenuTimeout(const SubMenuItemData *pTimer)
void GetRecursiveChecked(const weld::TreeIter *pEntry, std::unordered_set< OUString > &vOut, OUString &rLabel)
void addMenuItem(const OUString &rText, Action *pAction)
void CheckAllChildren(const weld::TreeIter &rEntry, bool bCheck)
std::unique_ptr< weld::CheckButton > mxChkToggleAll
void setExtendedData(std::unique_ptr< ExtendedData > p)
Set auxiliary data that the client code might need.
DECL_LINK(PopupModeEndHdl, weld::Popover &, void)
weld::TreeView * mpChecks
std::unique_ptr< weld::Widget > mxBox
ScListSubMenuControl * addSubMenuItem(const OUString &rText, bool bEnabled, bool bColorMenu)
void setSelectedMenuItem(size_t nPos)
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
size_t getSubMenuPos(const ScListSubMenuControl *pSubMenu)
DECL_LINK(TreeSizeAllocHdl, const Size &, void)
std::unique_ptr< weld::Menu > mxContextMenu
std::unique_ptr< weld::Popover > mxPopover
void setFieldChangedAction(Action *p)
DECL_LINK(SelectHdl, weld::TreeView &, void)
void setConfig(const Config &rConfig)
void setPopupEndAction(Action *p)
std::unique_ptr< weld::Button > mxBtnSelectSingle
void endSubMenu(ScListSubMenuControl &rSubMenu)
std::unique_ptr< ExtendedData > mxExtendedData
void terminateAllPopupMenus()
Dismiss all visible popup menus and set focus back to the application window.
int mnCheckListVisibleRows
whole window width.
void executeMenuItem(size_t nPos)
std::unique_ptr< weld::TreeIter > FindEntry(const weld::TreeIter *pParent, std::u16string_view sNode)
DECL_LINK(EdModifyHdl, weld::Entry &, void)
ImplSVEvent * mnAsyncSetDropdownPosId
void prepWindow()
Calculate the appropriate window size based on the menu items.
void setMemberSize(size_t n)
size_t initMembers(int nMaxMemberWidth=-1)
void Check(const weld::TreeIter *pIter)
std::unique_ptr< weld::TreeView > mxMenu
std::unique_ptr< weld::Container > mxContainer
std::unique_ptr< weld::Label > mxFieldsComboLabel
DECL_LINK(SetDropdownPosHdl, void *, void)
tools::Rectangle GetSubMenuParentRect()
Get the area of the active row.
std::unique_ptr< weld::ComboBox > mxFieldsCombo
ScopedVclPtr< VirtualDevice > mxDropDown
void selectCurrentMemberOnly(bool bSet)
int IncreaseWindowWidthToFitText(int nMaxTextWidth)
bool IsChecked(std::u16string_view sName, const weld::TreeIter *pParent)
DECL_LINK(MenuKeyInputHdl, const KeyEvent &, bool)
ImplSVEvent * mnAsyncPostPopdownId
SubMenuItemData maOpenTimer
std::unique_ptr< weld::TreeView > mxTreeChecks
void updateMemberParents(const weld::TreeIter *pLeaf, size_t nIdx)
DECL_LINK(TriStateHdl, weld::Toggleable &, void)
std::map< OUString, size_t > maYearMonthMap
int mnWndWidth
matching width request for mxChecks
void selectMenuItem(size_t nPos, bool bSubMenuTimer)
DECL_LINK(MouseEnterHdl, const MouseEvent &, bool)
std::unique_ptr< weld::Button > mxBtnCancel
DECL_LINK(EdActivateHdl, weld::Entry &, bool)
int GetTextWidth(const OUString &rsName) const
DECL_LINK(ButtonHdl, weld::Button &, void)
DECL_LINK(SearchEditTimeoutHdl, Timer *, void)
std::unique_ptr< weld::TreeIter > mxScratchIter
void setOKAction(Action *p)
std::vector< ScCheckListMember > maMembers
void addFields(const std::vector< OUString > &aFields)
DECL_LINK(ComboChangedHdl, weld::ComboBox &, void)
DECL_LINK(PostPopdownHdl, void *, void)
ExtendedData * getExtendedData()
Get the store auxiliary data, or NULL if no such data is stored.
std::unique_ptr< weld::TreeView > mxListChecks
void launch(weld::Widget *pWidget, const tools::Rectangle &rRect)
std::unique_ptr< weld::Box > mxButtonBox
int GetCheckedEntryCount() const
static constexpr size_t MENU_NOT_SELECTED
std::unique_ptr< weld::Button > mxBtnOk
void setSubMenuFocused(const ScListSubMenuControl *pSubMenu)
std::vector< MenuItemData > maMenuItems
std::unique_ptr< weld::Builder > mxBuilder
std::set< ResultEntry > ResultType
DECL_LINK(CheckHdl, const weld::TreeView::iter_col &, void)
SubMenuItemData maCloseTimer
void queueLaunchSubMenu(size_t nPos, ScListSubMenuControl *pMenu)
void addDateMember(const OUString &rName, double nVal, bool bVisible, bool bHiddenByOtherFilter)
std::unique_ptr< weld::TreeIter > mxScratchIter
VclPtr< VirtualDevice > create_virtual_device() const
DECL_LINK(RowActivatedHdl, weld::TreeView &rMEvt, bool)
std::unique_ptr< weld::Popover > mxPopover
void addMenuItem(const OUString &rText, ScCheckListMenuControl::Action *pAction)
std::unique_ptr< weld::Container > mxContainer
std::unique_ptr< weld::TreeView > mxTextColorMenu
std::unique_ptr< ScCheckListMenuControl::Action > mxPopupStartAction
std::unique_ptr< weld::TreeView > mxMenu
void executeMenuItem(ScCheckListMenuControl::Action *pAction)
void SetupMenu(weld::TreeView &rMenu)
DECL_LINK(ColorSelChangedHdl, weld::TreeView &, void)
void StartPopupMode(weld::Widget *pParent, const tools::Rectangle &rRect)
std::vector< ScCheckListMenuControl::MenuItemData > maMenuItems
void setPopupStartAction(ScCheckListMenuControl::Action *p)
ScCheckListMenuControl::ExtendedData * getExtendedData()
ScCheckListMenuControl & mrParentControl
void terminateAllPopupMenus()
Dismiss all visible popup menus and set focus back to the application window.
std::unique_ptr< weld::Builder > mxBuilder
void addItem(ScCheckListMenuControl::Action *pAction)
std::unique_ptr< weld::TreeView > mxBackColorMenu
void addMenuColorItem(const OUString &rText, bool bActive, VirtualDevice &rImage, int nMenu, ScCheckListMenuControl::Action *pAction)
ScViewData & GetViewData() const
DECL_LINK(MenuKeyInputHdl, const KeyEvent &, bool)
ScListSubMenuControl(weld::Widget *pParent, ScCheckListMenuControl &rParentControl, bool bColorMenu)
std::pair< const TreeIter &, int > iter_col
TriState
void * p
long Long
std::vector< OUString > maDateParts
DatePartType meDatePartType
std::unique_ptr< weld::TreeIter > mxParent
Configuration options for this popup window.
Extended data that the client code may need to store.
std::unique_ptr< ScListSubMenuControl > mxSubMenuWin
std::shared_ptr< Action > mxAction
bool operator==(const ResultEntry &rhs) const
bool operator<(const ResultEntry &rhs) const
DECL_LINK(TimeoutHdl, Timer *, void)
SubMenuItemData(ScCheckListMenuControl *pParent)