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 
119  bool bCanHaveSubMenu, bool bTreeMode, 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(int nMaxMemberWidth = -1);
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  int GetTextWidth(const OUString& rsName) const;
167  int IncreaseWindowWidthToFitText(int nMaxTextWidth);
168 
169 private:
170 
171  std::vector<MenuItemData> maMenuItems;
172 
176  void prepWindow();
177  void setAllMemberState(bool bSet);
178  void selectCurrentMemberOnly(bool bSet);
179  void updateMemberParents(const weld::TreeIter* pLeaf, size_t nIdx);
180 
181  std::unique_ptr<weld::TreeIter> ShowCheckEntry(const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true);
182  void CheckEntry(const OUString& sName, const weld::TreeIter* pParent, bool bCheck);
183  void CheckEntry(const weld::TreeIter& rEntry, bool bCheck);
184  void GetRecursiveChecked(const weld::TreeIter* pEntry, std::unordered_set<OUString>& vOut, OUString& rLabel);
185  std::unordered_set<OUString> GetAllChecked();
186  bool IsChecked(const OUString& sName, const weld::TreeIter* pParent);
187  int GetCheckedEntryCount() const;
188  void CheckAllChildren(const weld::TreeIter& rEntry, bool bCheck);
189 
190  void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer);
191 
192  std::unique_ptr<weld::TreeIter> FindEntry(const weld::TreeIter* pParent, const OUString& sNode);
193 
194  void executeMenuItem(size_t nPos);
195 
200  void terminateAllPopupMenus();
201 
202  void endSubMenu(ScCheckListMenuControl& rSubMenu);
203 
204  struct SubMenuItemData;
205 
206  void handleMenuTimeout(const SubMenuItemData* pTimer);
207 
208  void launchSubMenu(bool bSetMenuPos);
209 
210  void CreateDropDown();
211 
212  DECL_LINK(ButtonHdl, weld::Button&, void);
213  DECL_LINK(TriStateHdl, weld::ToggleButton&, void);
214 
215  void Check(const weld::TreeIter* pIter);
216 
217  DECL_LINK(CheckHdl, const weld::TreeView::iter_col&, void);
218 
219  DECL_LINK(PopupModeEndHdl, FloatingWindow*, void);
220 
221  DECL_LINK(EdModifyHdl, weld::Entry&, void);
222  DECL_LINK(EdActivateHdl, weld::Entry&, bool);
223 
224  DECL_LINK(FocusHdl, weld::Widget&, void);
225  DECL_LINK(RowActivatedHdl, weld::TreeView& rMEvt, bool);
226  DECL_LINK(SelectHdl, weld::TreeView&, void);
227  DECL_LINK(TreeSizeAllocHdl, const Size&, void);
228  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
229  DECL_LINK(MenuKeyInputHdl, const KeyEvent&, bool);
230 
231  DECL_LINK(PostPopdownHdl, void*, void);
232 
233 private:
235  std::unique_ptr<weld::Builder> mxBuilder;
236  std::unique_ptr<weld::Container> mxContainer;
237  std::unique_ptr<weld::TreeView> mxMenu;
238  std::unique_ptr<weld::TreeIter> mxScratchIter;
239  std::unique_ptr<weld::Entry> mxEdSearch;
240  std::unique_ptr<weld::Widget> mxBox;
241  std::unique_ptr<weld::TreeView> mxListChecks;
242  std::unique_ptr<weld::TreeView> mxTreeChecks;
244 
245  std::unique_ptr<weld::CheckButton> mxChkToggleAll;
246  std::unique_ptr<weld::Button> mxBtnSelectSingle;
247  std::unique_ptr<weld::Button> mxBtnUnselectSingle;
248 
249  std::unique_ptr<weld::Box> mxButtonBox;
250  std::unique_ptr<weld::Button> mxBtnOk;
251  std::unique_ptr<weld::Button> mxBtnCancel;
252 
254 
255  std::vector<ScCheckListMember> maMembers;
256  // For Dates
257  std::map<OUString, size_t> maYearMonthMap;
258 
259  std::unique_ptr<ExtendedData> mxExtendedData;
260  std::unique_ptr<Action> mxOKAction;
261  std::unique_ptr<Action> mxPopupEndAction;
262 
267 
269 
271 
273 
276 
278  {
281  size_t mnMenuPos;
282 
283  DECL_LINK( TimeoutHdl, Timer*, void );
284 
286  void reset();
287 
288  private:
290  };
291 
294 };
295 
301 {
302 public:
303  explicit ScCheckListMenuWindow(vcl::Window* pParent, ScDocument* pDoc,
304  bool bCanHaveSubMenu, bool bTreeMode, int nWidth = -1,
305  ScCheckListMenuWindow* pParentMenu = nullptr);
306  virtual void dispose() override;
307  virtual ~ScCheckListMenuWindow() override;
308 
309  virtual void GetFocus() override;
310  virtual bool EventNotify(NotifyEvent& rNEvt) override;
311 
314 
315 private:
318  std::unique_ptr<ScCheckListMenuControl, o3tl::default_delete<ScCheckListMenuControl>> mxControl;
319 };
320 
321 #endif
322 
323 /* 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
ScCheckListMenuWindow(vcl::Window *pParent, ScDocument *pDoc, bool bCanHaveSubMenu, bool bTreeMode, int nWidth=-1, ScCheckListMenuWindow *pParentMenu=nullptr)
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 &rEntry, 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
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
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
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
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 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)
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