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 #ifndef INCLUDED_SC_SOURCE_UI_INC_CHECKLISTMENU_HXX
11 #define INCLUDED_SC_SOURCE_UI_INC_CHECKLISTMENU_HXX
12 
14 #include <vcl/dockwin.hxx>
15 #include <vcl/timer.hxx>
16 #include <vcl/weld.hxx>
17 
18 #include <memory>
19 #include <unordered_set>
20 #include <unordered_map>
21 #include <map>
22 #include <set>
23 
24 class ScDocument;
25 
27 
28 struct ScCheckListMember;
29 
31 {
33  {
36  DAY,
37  };
38 
39  OUString maName; // node name
40  OUString maRealName;
41  bool mbVisible;
42  bool mbDate;
43  bool mbLeaf;
45  // To store Year and Month if the member if DAY type
46  std::vector<OUString> maDateParts;
48  std::unique_ptr<weld::TreeIter> mxParent;
49 };
50 
52 
54 {
55 public:
56  static constexpr size_t MENU_NOT_SELECTED = 999;
57 
62  class Action
63  {
64  public:
65  virtual ~Action() {}
66  virtual void execute() = 0;
67  };
68 
69  struct ResultEntry
70  {
71  OUString aName;
72  bool bValid;
73  bool bDate;
74 
75  bool operator<(const ResultEntry& rhs) const
76  {
77  return aName < rhs.aName;
78  }
79 
80  bool operator == (const ResultEntry& rhs) const
81  {
82  return aName == rhs.aName &&
83  bValid == rhs.bValid &&
84  bDate == rhs.bDate;
85  }
86  };
87  typedef std::set<ResultEntry> ResultType;
88 
89  struct MenuItemData
90  {
91  bool mbEnabled:1;
92  std::shared_ptr<Action> mxAction;
94 
95  MenuItemData();
96  };
97 
102  struct ExtendedData {
103 
104  virtual ~ExtendedData() {}
105 
106  };
107 
111  struct Config
112  {
114  bool mbRTL;
115  Config();
116  };
117 
118  explicit ScCheckListMenuControl(ScCheckListMenuWindow* pParent, vcl::Window* pContainer, ScDocument* pDoc,
119  bool bCanHaveSubMenu, int nWidth);
121 
122  void addMenuItem(const OUString& rText, Action* pAction);
123  void addSeparator();
124  ScCheckListMenuWindow* addSubMenuItem(const OUString& rText, bool bEnabled);
125  void resizeToFitMenuItems();
126 
127  void selectMenuItem(size_t nPos, bool bSubMenuTimer);
128  void queueLaunchSubMenu(size_t nPos, ScCheckListMenuWindow* pMenu);
129 
130  void setMemberSize(size_t n);
131  void addDateMember(const OUString& rName, double nVal, bool bVisible);
132  void addMember(const OUString& rName, bool bVisible);
133  size_t initMembers();
134  void setConfig(const Config& rConfig);
135 
136  bool isAllSelected() const;
137  void getResult(ResultType& rResult);
138  void launch(const tools::Rectangle& rRect);
139  void close(bool bOK);
140 
141  void StartPopupMode(const tools::Rectangle& rRect, FloatWinPopupFlags eFlags);
142  void EndPopupMode();
143 
144  size_t getSubMenuPos(const ScCheckListMenuControl* pSubMenu);
145  void setSubMenuFocused(const ScCheckListMenuControl* pSubMenu);
146  void queueCloseSubMenu();
147  void clearSelectedMenuItem();
148 
154  void setExtendedData(std::unique_ptr<ExtendedData> p);
155 
160 
161  void GrabFocus();
162 
163  void setOKAction(Action* p);
164  void setPopupEndAction(Action* p);
165 
166  void setHasDates(bool bHasDates);
167 
168 private:
169 
170  std::vector<MenuItemData> maMenuItems;
171 
175  void prepWindow();
176  void setAllMemberState(bool bSet);
177  void selectCurrentMemberOnly(bool bSet);
178  void updateMemberParents(const weld::TreeIter* pLeaf, size_t nIdx);
179 
180  std::unique_ptr<weld::TreeIter> ShowCheckEntry(const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true);
181  void CheckEntry(const OUString& sName, const weld::TreeIter* pParent, bool bCheck);
182  void CheckEntry(const weld::TreeIter* pEntry, bool bCheck);
183  void GetRecursiveChecked(const weld::TreeIter* pEntry, std::unordered_set<OUString>& vOut, OUString& rLabel);
184  std::unordered_set<OUString> GetAllChecked();
185  bool IsChecked(const OUString& sName, const weld::TreeIter* pParent);
186  int GetCheckedEntryCount() const;
187  void CheckAllChildren(const weld::TreeIter* pEntry, bool bCheck);
188 
189  void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer);
190 
191  std::unique_ptr<weld::TreeIter> FindEntry(const weld::TreeIter* pParent, const OUString& sNode);
192 
193  void executeMenuItem(size_t nPos);
194 
199  void terminateAllPopupMenus();
200 
201  void endSubMenu(ScCheckListMenuControl& rSubMenu);
202 
203  struct SubMenuItemData;
204 
205  void handleMenuTimeout(const SubMenuItemData* pTimer);
206 
207  void launchSubMenu(bool bSetMenuPos);
208 
209  void CreateDropDown();
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> mxChecks;
241 
242  std::unique_ptr<weld::CheckButton> mxChkToggleAll;
243  std::unique_ptr<weld::Button> mxBtnSelectSingle;
244  std::unique_ptr<weld::Button> mxBtnUnselectSingle;
245 
246  std::unique_ptr<weld::Box> mxButtonBox;
247  std::unique_ptr<weld::Button> mxBtnOk;
248  std::unique_ptr<weld::Button> mxBtnCancel;
249 
251 
252  std::vector<ScCheckListMember> maMembers;
253  // For Dates
254  std::map<OUString, size_t> maYearMonthMap;
255 
256  std::unique_ptr<ExtendedData> mxExtendedData;
257  std::unique_ptr<Action> mxOKAction;
258  std::unique_ptr<Action> mxPopupEndAction;
259 
264 
266 
268 
270 
273 
275  {
278  size_t mnMenuPos;
279 
280  DECL_LINK( TimeoutHdl, Timer*, void );
281 
283  void reset();
284 
285  private:
287  };
288 
291 };
292 
298 {
299 public:
300  explicit ScCheckListMenuWindow(vcl::Window* pParent, ScDocument* pDoc, bool bCanHaveSubMenu, int nWidth = -1,
301  ScCheckListMenuWindow* pParentMenu = nullptr);
302  virtual void dispose() override;
303  virtual ~ScCheckListMenuWindow() override;
304 
305  virtual void GetFocus() override;
306  virtual bool EventNotify(NotifyEvent& rNEvt) override;
307 
310 
311 private:
314  std::unique_ptr<ScCheckListMenuControl, o3tl::default_delete<ScCheckListMenuControl>> mxControl;
315 };
316 
317 #endif
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
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)
VclPtr< vcl::Window > mxBox
bool IsChecked(const OUString &sName, const weld::TreeIter *pParent)
void StartPopupMode(const tools::Rectangle &rRect, FloatWinPopupFlags eFlags)
TriState mePrevToggleAllState
whole window width.
void CheckAllChildren(const weld::TreeIter *pEntry, bool bCheck)
DECL_LINK(TimeoutHdl, Timer *, void)
void CheckEntry(const OUString &sName, const weld::TreeIter *pParent, bool bCheck)
void setPopupEndAction(Action *p)
Action to perform when an event takes place.
Configuration options for this popup window.
std::unique_ptr< weld::TreeIter > mxScratchIter
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
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)
std::vector< OUString > maDateParts
void setMemberSize(size_t n)
ScCheckListMenuControl(ScCheckListMenuWindow *pParent, vcl::Window *pContainer, ScDocument *pDoc, bool bCanHaveSubMenu, int nWidth)
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
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
FloatWinPopupFlags
void launchSubMenu(bool bSetMenuPos)
std::unique_ptr< weld::TreeIter > FindEntry(const weld::TreeIter *pParent, const OUString &sNode)
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
std::unique_ptr< weld::Widget > mxBox
void terminateAllPopupMenus()
Dismiss all visible popup menus and set focus back to the application window.
ScCheckListMenuWindow(vcl::Window *pParent, ScDocument *pDoc, bool bCanHaveSubMenu, int nWidth=-1, ScCheckListMenuWindow *pParentMenu=nullptr)
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 field button, for quick access of hide-item list...
void addDateMember(const OUString &rName, double nVal, bool bVisible)
void GetRecursiveChecked(const weld::TreeIter *pEntry, std::unordered_set< OUString > &vOut, OUString &rLabel)
void setHasDates(bool bHasDates)
std::unique_ptr< ScCheckListMenuControl, o3tl::default_delete< ScCheckListMenuControl > > mxControl
std::unique_ptr< weld::TreeView > mxChecks
TriState
void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer)
Extended data that the client code may need to store.
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