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);
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 size_t initMembers(int nMaxMemberWidth = -1);
142 void setConfig(const Config& rConfig);
143
144 bool isAllSelected() const;
145 void getResult(ResultType& rResult);
146 void launch(weld::Widget* pWidget, const tools::Rectangle& rRect);
147 void close(bool bOK);
148
149 void StartPopupMode(weld::Widget* pParent, const tools::Rectangle& rRect);
150 void EndPopupMode();
151
152 size_t getSubMenuPos(const ScListSubMenuControl* pSubMenu);
153 void setSubMenuFocused(const ScListSubMenuControl* pSubMenu);
154 void queueCloseSubMenu();
156
162 void setExtendedData(std::unique_ptr<ExtendedData> p);
163
168
169 ScViewData& GetViewData() const { return mrViewData; }
170
171 void GrabFocus();
172
173 void setOKAction(Action* p);
174 void setPopupEndAction(Action* p);
175
176 int GetTextWidth(const OUString& rsName) const;
177 int IncreaseWindowWidthToFitText(int nMaxTextWidth);
178
184
185 void endSubMenu(ScListSubMenuControl& rSubMenu);
186private:
187
188 std::vector<MenuItemData> maMenuItems;
189
193 void prepWindow();
194 void setAllMemberState(bool bSet);
195 void selectCurrentMemberOnly(bool bSet);
196 void updateMemberParents(const weld::TreeIter* pLeaf, size_t nIdx);
197
198 std::unique_ptr<weld::TreeIter> ShowCheckEntry(const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true);
199 void CheckEntry(std::u16string_view sName, const weld::TreeIter* pParent, bool bCheck);
200 void CheckEntry(const weld::TreeIter& rEntry, bool bCheck);
201 void GetRecursiveChecked(const weld::TreeIter* pEntry, std::unordered_set<OUString>& vOut, OUString& rLabel);
202 std::unordered_set<OUString> GetAllChecked();
203 bool IsChecked(std::u16string_view sName, const weld::TreeIter* pParent);
204 int GetCheckedEntryCount() const;
205 void CheckAllChildren(const weld::TreeIter& rEntry, bool bCheck);
206
207 void setSelectedMenuItem(size_t nPos);
208
209 std::unique_ptr<weld::TreeIter> FindEntry(const weld::TreeIter* pParent, std::u16string_view sNode);
210
211 void executeMenuItem(size_t nPos);
212
218
219 struct SubMenuItemData;
220
221 void handleMenuTimeout(const SubMenuItemData* pTimer);
222
223 void launchSubMenu();
224
225 void CreateDropDown();
226
227 DECL_LINK(ButtonHdl, weld::Button&, void);
228 DECL_LINK(TriStateHdl, weld::Toggleable&, void);
229
230 void Check(const weld::TreeIter* pIter);
231
232 DECL_LINK(CheckHdl, const weld::TreeView::iter_col&, void);
233
234 DECL_LINK(PopupModeEndHdl, weld::Popover&, void);
235
236 DECL_LINK(EdModifyHdl, weld::Entry&, void);
237 DECL_LINK(EdActivateHdl, weld::Entry&, bool);
238
239 DECL_LINK(RowActivatedHdl, weld::TreeView& rMEvt, bool);
240 DECL_LINK(SelectHdl, weld::TreeView&, void);
241 DECL_LINK(TreeSizeAllocHdl, const Size&, void);
242 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
243 DECL_LINK(MenuKeyInputHdl, const KeyEvent&, bool);
244 DECL_LINK(MouseEnterHdl, const MouseEvent&, bool);
245
246 DECL_LINK(PostPopdownHdl, void*, void);
247
248 void SetDropdownPos();
249
250 DECL_LINK(SetDropdownPosHdl, void*, void);
251
252 DECL_LINK(CommandHdl, const CommandEvent&, bool);
253
254 void ResizeToRequest();
255
256 void DropPendingEvents();
257
258private:
259 std::unique_ptr<weld::Builder> mxBuilder;
260 std::unique_ptr<weld::Popover> mxPopover;
261 std::unique_ptr<weld::Container> mxContainer;
262 std::unique_ptr<weld::TreeView> mxMenu;
263 std::unique_ptr<weld::TreeIter> mxScratchIter;
264 std::unique_ptr<weld::Widget> mxNonMenu;
265 std::unique_ptr<weld::Entry> mxEdSearch;
266 std::unique_ptr<weld::Widget> mxBox;
267 std::unique_ptr<weld::TreeView> mxListChecks;
268 std::unique_ptr<weld::TreeView> mxTreeChecks;
270
271 std::unique_ptr<weld::CheckButton> mxChkToggleAll;
272 std::unique_ptr<weld::Button> mxBtnSelectSingle;
273 std::unique_ptr<weld::Button> mxBtnUnselectSingle;
274
275 std::unique_ptr<weld::Box> mxButtonBox;
276 std::unique_ptr<weld::Button> mxBtnOk;
277 std::unique_ptr<weld::Button> mxBtnCancel;
278 std::unique_ptr<weld::Menu> mxContextMenu;
279
281
282 std::vector<ScCheckListMember> maMembers;
283 // For Dates
284 std::map<OUString, size_t> maYearMonthMap;
285
286 std::unique_ptr<ExtendedData> mxExtendedData;
287 std::unique_ptr<Action> mxOKAction;
288 std::unique_ptr<Action> mxPopupEndAction;
289
296
298
300
303
306
308 {
311 size_t mnMenuPos;
312
313 DECL_LINK( TimeoutHdl, Timer*, void );
314
316 void reset();
317
318 private:
320 };
321
324};
325
327{
328public:
329 ScListSubMenuControl(weld::Widget* pParent, ScCheckListMenuControl& rParentControl, bool bColorMenu);
330
332
333 void GrabFocus();
334 bool IsVisible() const;
335
336 void StartPopupMode(weld::Widget* pParent, const tools::Rectangle& rRect);
337 void EndPopupMode();
338
339 void addMenuItem(const OUString& rText, ScCheckListMenuControl::Action* pAction);
340 // nMenu of 0 for background color, nMenu of 1 for text color
341 void addMenuColorItem(const OUString& rText, bool bActive, VirtualDevice& rImage,
342 int nMenu, ScCheckListMenuControl::Action* pAction);
343 void addSeparator();
344 void clearMenuItems();
346
349 VclPtr<VirtualDevice> create_virtual_device() const { return mxMenu->create_virtual_device(); }
350
356
357private:
358 std::unique_ptr<weld::Builder> mxBuilder;
359 std::unique_ptr<weld::Popover> mxPopover;
360 std::unique_ptr<weld::Container> mxContainer;
361 std::unique_ptr<weld::TreeView> mxMenu;
362 std::unique_ptr<weld::TreeView> mxBackColorMenu;
363 std::unique_ptr<weld::TreeView> mxTextColorMenu;
364 std::unique_ptr<weld::TreeIter> mxScratchIter;
365 std::unique_ptr<ScCheckListMenuControl::Action> mxPopupStartAction;
366 std::vector<ScCheckListMenuControl::MenuItemData> maMenuItems;
371
372 DECL_LINK(RowActivatedHdl, weld::TreeView& rMEvt, bool);
373 DECL_LINK(ColorSelChangedHdl, weld::TreeView&, void);
374 DECL_LINK(MenuKeyInputHdl, const KeyEvent&, bool);
375
376 void SetupMenu(weld::TreeView& rMenu);
377
380};
381
382/* 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)
void CheckEntry(std::u16string_view sName, const weld::TreeIter *pParent, bool bCheck)
DECL_LINK(CommandHdl, const CommandEvent &, bool)
std::unique_ptr< weld::Button > mxBtnUnselectSingle
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
DECL_LINK(SelectHdl, weld::TreeView &, void)
ScCheckListMenuControl(weld::Widget *pParent, ScViewData &rViewData, bool bTreeMode, int nWidth)
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
DECL_LINK(SetDropdownPosHdl, void *, void)
tools::Rectangle GetSubMenuParentRect()
Get the area of the active row.
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)
std::unique_ptr< weld::TreeIter > mxScratchIter
void setOKAction(Action *p)
std::vector< ScCheckListMember > maMembers
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
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)