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/dockwin.hxx>
13 #include <vcl/timer.hxx>
14 #include <vcl/weld.hxx>
15 
16 #include <memory>
17 #include <unordered_set>
18 #include <map>
19 #include <set>
20 
21 class ScDocument;
22 
24 
25 struct ScCheckListMember;
26 
28 {
30  {
33  DAY,
34  };
35 
36  OUString maName; // node name
37  OUString maRealName;
38  bool mbVisible;
39  bool mbDate;
40  bool mbLeaf;
42  // To store Year and Month if the member if DAY type
43  std::vector<OUString> maDateParts;
45  std::unique_ptr<weld::TreeIter> mxParent;
46 };
47 
49 
51 {
52 public:
53  static constexpr size_t MENU_NOT_SELECTED = 999;
54 
59  class Action
60  {
61  public:
62  virtual ~Action() {}
63  virtual void execute() = 0;
64  };
65 
66  struct ResultEntry
67  {
68  OUString aName;
69  bool bValid;
70  bool bDate;
71 
72  bool operator<(const ResultEntry& rhs) const
73  {
74  return aName < rhs.aName;
75  }
76 
77  bool operator == (const ResultEntry& rhs) const
78  {
79  return aName == rhs.aName &&
80  bValid == rhs.bValid &&
81  bDate == rhs.bDate;
82  }
83  };
84  typedef std::set<ResultEntry> ResultType;
85 
86  struct MenuItemData
87  {
88  bool mbEnabled:1;
89  std::shared_ptr<Action> mxAction;
91 
92  MenuItemData();
93  };
94 
99  struct ExtendedData {
100 
101  virtual ~ExtendedData() {}
102 
103  };
104 
108  struct Config
109  {
111  bool mbRTL;
112  Config();
113  };
114 
116  bool bCanHaveSubMenu, bool bTreeMode, int nWidth);
118 
119  void addMenuItem(const OUString& rText, Action* pAction);
120  void addSeparator();
121  ScCheckListMenuWindow* addSubMenuItem(const OUString& rText, bool bEnabled);
122  void resizeToFitMenuItems();
123 
124  void selectMenuItem(size_t nPos, bool bSubMenuTimer);
125  void queueLaunchSubMenu(size_t nPos, ScCheckListMenuWindow* pMenu);
126 
127  void setMemberSize(size_t n);
128  void addDateMember(const OUString& rName, double nVal, bool bVisible);
129  void addMember(const OUString& rName, bool bVisible);
130  size_t initMembers(int nMaxMemberWidth = -1);
131  void setConfig(const Config& rConfig);
132 
133  bool isAllSelected() const;
134  void getResult(ResultType& rResult);
135  void launch(const tools::Rectangle& rRect);
136  void close(bool bOK);
137 
138  void StartPopupMode(const tools::Rectangle& rRect, FloatWinPopupFlags eFlags);
139  void EndPopupMode();
140 
141  size_t getSubMenuPos(const ScCheckListMenuControl* pSubMenu);
142  void setSubMenuFocused(const ScCheckListMenuControl* pSubMenu);
143  void queueCloseSubMenu();
144  void clearSelectedMenuItem();
145 
151  void setExtendedData(std::unique_ptr<ExtendedData> p);
152 
157 
158  void GrabFocus();
159 
160  void setOKAction(Action* p);
161  void setPopupEndAction(Action* p);
162 
163  int GetTextWidth(const OUString& rsName) const;
164  int IncreaseWindowWidthToFitText(int nMaxTextWidth);
165 
166 private:
167 
168  std::vector<MenuItemData> maMenuItems;
169 
173  void prepWindow();
174  void setAllMemberState(bool bSet);
175  void selectCurrentMemberOnly(bool bSet);
176  void updateMemberParents(const weld::TreeIter* pLeaf, size_t nIdx);
177 
178  std::unique_ptr<weld::TreeIter> ShowCheckEntry(const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true);
179  void CheckEntry(std::u16string_view sName, const weld::TreeIter* pParent, bool bCheck);
180  void CheckEntry(const weld::TreeIter& rEntry, bool bCheck);
181  void GetRecursiveChecked(const weld::TreeIter* pEntry, std::unordered_set<OUString>& vOut, OUString& rLabel);
182  std::unordered_set<OUString> GetAllChecked();
183  bool IsChecked(std::u16string_view sName, const weld::TreeIter* pParent);
184  int GetCheckedEntryCount() const;
185  void CheckAllChildren(const weld::TreeIter& rEntry, bool bCheck);
186 
187  void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer);
188 
189  std::unique_ptr<weld::TreeIter> FindEntry(const weld::TreeIter* pParent, std::u16string_view sNode);
190 
191  void executeMenuItem(size_t nPos);
192 
197  void terminateAllPopupMenus();
198 
199  void endSubMenu(ScCheckListMenuControl& rSubMenu);
200 
201  struct SubMenuItemData;
202 
203  void handleMenuTimeout(const SubMenuItemData* pTimer);
204 
205  void launchSubMenu(bool bSetMenuPos);
206 
207  void CreateDropDown();
208 
209  void NotifyCloseLOK();
210 
211  DECL_LINK(ButtonHdl, weld::Button&, void);
212  DECL_LINK(TriStateHdl, weld::ToggleButton&, void);
213 
214  void Check(const weld::TreeIter* pIter);
215 
216  DECL_LINK(CheckHdl, const weld::TreeView::iter_col&, void);
217 
218  DECL_LINK(PopupModeEndHdl, FloatingWindow*, void);
219 
220  DECL_LINK(EdModifyHdl, weld::Entry&, void);
221  DECL_LINK(EdActivateHdl, weld::Entry&, bool);
222 
223  DECL_LINK(FocusHdl, weld::Widget&, void);
224  DECL_LINK(RowActivatedHdl, weld::TreeView& rMEvt, bool);
225  DECL_LINK(SelectHdl, weld::TreeView&, void);
226  DECL_LINK(TreeSizeAllocHdl, const Size&, void);
227  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
228  DECL_LINK(MenuKeyInputHdl, const KeyEvent&, bool);
229 
230  DECL_LINK(PostPopdownHdl, void*, void);
231 
232 private:
234  std::unique_ptr<weld::Builder> mxBuilder;
235  std::unique_ptr<weld::Container> mxContainer;
236  std::unique_ptr<weld::TreeView> mxMenu;
237  std::unique_ptr<weld::TreeIter> mxScratchIter;
238  std::unique_ptr<weld::Entry> mxEdSearch;
239  std::unique_ptr<weld::Widget> mxBox;
240  std::unique_ptr<weld::TreeView> mxListChecks;
241  std::unique_ptr<weld::TreeView> mxTreeChecks;
243 
244  std::unique_ptr<weld::CheckButton> mxChkToggleAll;
245  std::unique_ptr<weld::Button> mxBtnSelectSingle;
246  std::unique_ptr<weld::Button> mxBtnUnselectSingle;
247 
248  std::unique_ptr<weld::Box> mxButtonBox;
249  std::unique_ptr<weld::Button> mxBtnOk;
250  std::unique_ptr<weld::Button> mxBtnCancel;
251 
253 
254  std::vector<ScCheckListMember> maMembers;
255  // For Dates
256  std::map<OUString, size_t> maYearMonthMap;
257 
258  std::unique_ptr<ExtendedData> mxExtendedData;
259  std::unique_ptr<Action> mxOKAction;
260  std::unique_ptr<Action> mxPopupEndAction;
261 
266 
268 
270 
272 
275 
277  {
280  size_t mnMenuPos;
281 
282  DECL_LINK( TimeoutHdl, Timer*, void );
283 
285  void reset();
286 
287  private:
289  };
290 
293 };
294 
299 {
300 public:
301  explicit ScCheckListMenuWindow(vcl::Window* pParent, ScDocument* pDoc,
302  bool bCanHaveSubMenu, bool bTreeMode, int nWidth = -1,
303  ScCheckListMenuWindow* pParentMenu = nullptr,
304  vcl::ILibreOfficeKitNotifier* pNotifier = nullptr);
305  virtual void dispose() override;
306  virtual ~ScCheckListMenuWindow() override;
307 
308  virtual void GetFocus() override;
309  virtual bool EventNotify(NotifyEvent& rNEvt) override;
310 
313 
314 private:
316  std::unique_ptr<ScCheckListMenuControl, o3tl::default_delete<ScCheckListMenuControl>> mxControl;
317 };
318 
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::set< ResultEntry > ResultType
std::unique_ptr< weld::Builder > mxBuilder
std::unique_ptr< weld::Button > mxBtnUnselectSingle
VclPtr< ScCheckListMenuWindow > mxParentMenu
void updateMemberParents(const weld::TreeIter *pLeaf, size_t nIdx)
void setOKAction(Action *p)
std::vector< MenuItemData > maMenuItems
void prepWindow()
Calculate the appropriate window size based on the menu items.
std::unique_ptr< weld::TreeIter > mxParent
std::unique_ptr< weld::Button > mxBtnSelectSingle
void executeMenuItem(size_t nPos)
int mnWndWidth
matching width request for mxChecks
void CheckEntry(std::u16string_view sName, const weld::TreeIter *pParent, bool bCheck)
VclPtr< ScCheckListMenuWindow > mxFrame
std::unique_ptr< weld::TreeView > mxMenu
virtual ~ScCheckListMenuWindow() override
ImplSVEvent * mnAsyncPostPopdownId
void queueLaunchSubMenu(size_t nPos, ScCheckListMenuWindow *pMenu)
std::unordered_set< OUString > GetAllChecked()
ScCheckListMenuWindow * GetParentMenu()
void selectMenuItem(size_t nPos, bool bSubMenuTimer)
FloatWinPopupFlags
void StartPopupMode(const tools::Rectangle &rRect, FloatWinPopupFlags eFlags)
std::unique_ptr< weld::TreeIter > FindEntry(const weld::TreeIter *pParent, std::u16string_view sNode)
TriState mePrevToggleAllState
whole window width.
void CheckAllChildren(const weld::TreeIter &rEntry, bool bCheck)
DECL_LINK(TimeoutHdl, Timer *, void)
void setPopupEndAction(Action *p)
Action to perform when an event takes place.
Configuration options for this popup window.
std::unique_ptr< weld::TreeIter > mxScratchIter
ScCheckListMenuControl(ScCheckListMenuWindow *pParent, vcl::Window *pContainer, ScDocument *pDoc, bool bCanHaveSubMenu, bool bTreeMode, int nWidth)
std::unique_ptr< weld::TreeIter > ShowCheckEntry(const OUString &sName, ScCheckListMember &rMember, bool bShow=true, bool bCheck=true)
std::pair< const TreeIter &, int > iter_col
VclPtr< ScCheckListMenuWindow > mpSubMenu
void setAllMemberState(bool bSet)
static constexpr size_t MENU_NOT_SELECTED
bool IsChecked(std::u16string_view sName, const weld::TreeIter *pParent)
void addMenuItem(const OUString &rText, Action *pAction)
void handleMenuTimeout(const SubMenuItemData *pTimer)
bool operator<(const ResultEntry &rhs) const
SubMenuItemData maOpenTimer
std::unique_ptr< Action > mxOKAction
bool operator==(const ResultEntry &rhs) const
void getResult(ResultType &rResult)
int IncreaseWindowWidthToFitText(int nMaxTextWidth)
std::vector< OUString > maDateParts
void setMemberSize(size_t n)
std::unique_ptr< weld::TreeView > mxTreeChecks
VclPtr< ScCheckListMenuWindow > mxSubMenuWin
int GetCheckedEntryCount() const
std::shared_ptr< Action > mxAction
std::unique_ptr< weld::CheckButton > mxChkToggleAll
std::vector< ScCheckListMember > maMembers
void setSubMenuFocused(const ScCheckListMenuControl *pSubMenu)
std::map< OUString, size_t > maYearMonthMap
std::unique_ptr< weld::Box > mxButtonBox
std::unique_ptr< weld::Button > mxBtnOk
size_t initMembers(int nMaxMemberWidth=-1)
virtual void GetFocus() override
ExtendedData * getExtendedData()
Get the store auxiliary data, or NULL if no such data is stored.
void setExtendedData(std::unique_ptr< ExtendedData > p)
Set auxiliary data that the client code might need.
virtual void dispose() override
ScCheckListMenuWindow * addSubMenuItem(const OUString &rText, bool bEnabled)
void endSubMenu(ScCheckListMenuControl &rSubMenu)
void setConfig(const Config &rConfig)
DatePartType meDatePartType
void launchSubMenu(bool bSetMenuPos)
std::unique_ptr< ExtendedData > mxExtendedData
SubMenuItemData(ScCheckListMenuControl *pParent)
void launch(const tools::Rectangle &rRect)
void addMember(const OUString &rName, bool bVisible)
ScopedVclPtr< VirtualDevice > mxDropDown
SubMenuItemData maCloseTimer
ScCheckListMenuWindow(vcl::Window *pParent, ScDocument *pDoc, bool bCanHaveSubMenu, bool bTreeMode, int nWidth=-1, ScCheckListMenuWindow *pParentMenu=nullptr, vcl::ILibreOfficeKitNotifier *pNotifier=nullptr)
weld::TreeView * mpChecks
int GetTextWidth(const OUString &rsName) const
std::unique_ptr< weld::Widget > mxBox
void terminateAllPopupMenus()
Dismiss all visible popup menus and set focus back to the application window.
std::unique_ptr< weld::Container > mxContainer
ScCheckListMenuControl & get_widget()
std::unique_ptr< Action > mxPopupEndAction
void selectCurrentMemberOnly(bool bSet)
This class implements a popup window for the auto filter dropdown.
void addDateMember(const OUString &rName, double nVal, bool bVisible)
void GetRecursiveChecked(const weld::TreeIter *pEntry, std::unordered_set< OUString > &vOut, OUString &rLabel)
std::unique_ptr< ScCheckListMenuControl, o3tl::default_delete< ScCheckListMenuControl > > mxControl
TriState
void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer)
Extended data that the client code may need to store.
std::unique_ptr< weld::TreeView > mxListChecks
DECL_LINK(ButtonHdl, weld::Button &, void)
void Check(const weld::TreeIter *pIter)
std::unique_ptr< weld::Button > mxBtnCancel
std::unique_ptr< weld::Entry > mxEdSearch
size_t getSubMenuPos(const ScCheckListMenuControl *pSubMenu)
virtual bool EventNotify(NotifyEvent &rNEvt) override