Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / inc / checklistmenu.hxx
blobf324482fee41f0c72106fd6dedf0bf32b266b7d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef __SC_CHECKLISTMENU_HXX__
11 #define __SC_CHECKLISTMENU_HXX__
13 #include "vcl/popupmenuwindow.hxx"
14 #include "vcl/button.hxx"
15 #include "vcl/scrbar.hxx"
16 #include "vcl/timer.hxx"
17 #include "svx/checklbx.hxx"
19 #include <boost/unordered_map.hpp>
20 #include <boost/scoped_ptr.hpp>
22 namespace com { namespace sun { namespace star {
24 namespace accessibility {
25 class XAccessible;
28 }}}
30 class ScDocument;
31 class ScAccessibleFilterMenu;
33 class ScMenuFloatingWindow : public PopupMenuFloatingWindow
35 public:
36 static size_t MENU_NOT_SELECTED;
37 /**
38 * Action to perform when an event takes place. Create a sub-class of
39 * this to implement the desired action.
41 class Action
43 public:
44 virtual ~Action() {}
45 virtual void execute() = 0;
48 explicit ScMenuFloatingWindow(Window* pParent, ScDocument* pDoc, sal_uInt16 nMenuStackLevel = 0);
49 virtual ~ScMenuFloatingWindow();
51 virtual void PopupModeEnd();
52 virtual void MouseMove(const MouseEvent& rMEvt);
53 virtual void MouseButtonDown(const MouseEvent& rMEvt);
54 virtual void MouseButtonUp(const MouseEvent& rMEvt);
55 virtual void KeyInput(const KeyEvent& rKEvt);
56 virtual void Paint(const Rectangle& rRect);
57 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
59 void addMenuItem(const OUString& rText, bool bEnabled, Action* pAction);
60 void addSeparator();
62 ScMenuFloatingWindow* addSubMenuItem(const OUString& rText, bool bEnabled);
63 void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer, bool bEnsureSubMenu);
64 void selectMenuItem(size_t nPos, bool bSelected, bool bSubMenuTimer);
65 void clearSelectedMenuItem();
66 ScMenuFloatingWindow* getSubMenuWindow(size_t nPos) const;
67 bool isMenuItemSelected(size_t nPos) const;
68 size_t getSelectedMenuItem() const;
70 void setName(const OUString& rName);
71 const OUString& getName() const;
73 void executeMenuItem(size_t nPos);
74 void getMenuItemPosSize(size_t nPos, Point& rPos, Size& rSize) const;
75 ScMenuFloatingWindow* getParentMenuWindow() const;
77 protected:
78 virtual void handlePopupEnd();
80 Size getMenuSize() const;
81 void drawMenuItem(size_t nPos);
82 void drawSeparator(size_t nPos);
83 void drawAllMenuItems();
84 const Font& getLabelFont() const;
86 void queueLaunchSubMenu(size_t nPos, ScMenuFloatingWindow* pMenu);
87 void queueCloseSubMenu();
88 void launchSubMenu(bool bSetMenuPos);
89 void endSubMenu(ScMenuFloatingWindow* pSubMenu);
91 void fillMenuItemsToAccessible(ScAccessibleFilterMenu* pAccMenu) const;
93 ScDocument* getDoc();
95 protected:
96 ::com::sun::star::uno::Reference<
97 ::com::sun::star::accessibility::XAccessible > mxAccessible;
99 private:
100 struct SubMenuItemData;
101 void handleMenuTimeout(SubMenuItemData* pTimer);
103 void resizeToFitMenuItems();
104 void highlightMenuItem(size_t nPos, bool bSelected);
106 size_t getEnclosingMenuItem(const Point& rPos) const;
107 size_t getSubMenuPos(ScMenuFloatingWindow* pSubMenu);
110 * Fire a menu highlight event since the accessibility framework needs
111 * this to track focus on menu items.
113 void fireMenuHighlightedEvent();
116 * Make sure that the specified submenu is permanently up, the submenu
117 * close timer is not active, and the correct menu item associated with
118 * the submenu is highlighted.
120 void setSubMenuFocused(ScMenuFloatingWindow* pSubMenu);
123 * When a menu item of an invisible submenu is selected, we need to make
124 * sure that all its parent menu(s) are visible, with the right menu item
125 * highlighted in each of the parents. Calling this method ensures it.
127 void ensureSubMenuVisible(ScMenuFloatingWindow* pSubMenu);
130 * Dismiss any visible child submenus when a menu item of a parent menu is
131 * selected.
133 void ensureSubMenuNotVisible();
136 * Dismiss all visible popup menus and set focus back to the application
137 * window. This method is called e.g. when a menu action is fired.
139 void terminateAllPopupMenus();
141 private:
143 struct MenuItemData
145 OUString maText;
146 bool mbEnabled:1;
147 bool mbSeparator:1;
149 ::boost::shared_ptr<Action> mpAction;
150 ::boost::shared_ptr<ScMenuFloatingWindow> mpSubMenuWin;
152 MenuItemData();
155 ::std::vector<MenuItemData> maMenuItems;
157 struct SubMenuItemData
159 Timer maTimer;
160 ScMenuFloatingWindow* mpSubMenu;
161 size_t mnMenuPos;
163 DECL_LINK( TimeoutHdl, void* );
165 SubMenuItemData(ScMenuFloatingWindow* pParent);
166 void reset();
168 private:
169 ScMenuFloatingWindow* mpParent;
171 SubMenuItemData maOpenTimer;
172 SubMenuItemData maCloseTimer;
174 Font maLabelFont;
176 // Name of this menu window, taken from the menu item of the parent window
177 // that launches it (if this is a sub menu). If this is a top-level menu
178 // window, then this name can be anything.
179 OUString maName;
181 size_t mnSelectedMenu;
182 size_t mnClickedMenu;
184 ScDocument* mpDoc;
186 ScMenuFloatingWindow* mpParentMenu;
190 class ScCheckListBox : public SvTreeListBox
192 SvLBoxButtonData* mpCheckButton;
193 SvTreeListEntry* CountCheckedEntries( SvTreeListEntry* pParent, sal_uLong& nCount ) const;
194 void CheckAllChildren( SvTreeListEntry* pEntry, sal_Bool bCheck = sal_True );
196 public:
198 ScCheckListBox( Window* pParent, WinBits nWinStyle = 0 );
199 ~ScCheckListBox() { delete mpCheckButton; }
200 void Init();
201 void CheckEntry( OUString& sName, SvTreeListEntry* pParent, sal_Bool bCheck = sal_True );
202 void CheckEntry( SvTreeListEntry* pEntry, sal_Bool bCheck = sal_True );
203 sal_Bool IsChecked( OUString& sName, SvTreeListEntry* pParent );
204 SvTreeListEntry* FindEntry( SvTreeListEntry* pParent, const OUString& sNode );
205 sal_uInt16 GetCheckedEntryCount() const;
206 void ExpandChildren( SvTreeListEntry* pParent );
207 virtual void KeyInput( const KeyEvent& rKEvt );
210 * This class implements a popup window for field button, for quick access
211 * of hide-item list, and possibly more stuff related to field options.
213 class ScCheckListMenuWindow : public ScMenuFloatingWindow
215 public:
216 typedef boost::unordered_map<OUString, bool, OUStringHash> ResultType;
219 * Extended data that the client code may need to store. Create a
220 * sub-class of this and store data there.
222 struct ExtendedData {
224 virtual ~ExtendedData() {}
229 * Configuration options for this popup window.
231 struct Config
233 bool mbAllowEmptySet;
234 bool mbRTL;
235 Config();
238 explicit ScCheckListMenuWindow(Window* pParent, ScDocument* pDoc);
239 virtual ~ScCheckListMenuWindow();
241 virtual void MouseMove(const MouseEvent& rMEvt);
242 virtual long Notify(NotifyEvent& rNEvt);
243 virtual void Paint(const Rectangle& rRect);
244 virtual Window* GetPreferredKeyInputWindow();
245 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
247 void setMemberSize(size_t n);
248 void addDateMember(const OUString& rName, double nVal, bool bVisible);
249 void addMember(const OUString& rName, bool bVisible);
250 void initMembers();
251 void setConfig(const Config& rConfig);
253 bool isAllSelected() const;
254 void getResult(ResultType& rResult);
255 void launch(const Rectangle& rRect);
256 void close(bool bOK);
259 * Set auxiliary data that the client code might need. Note that this
260 * popup window class manages its life time; no explicit deletion of the
261 * instance is needed in the client code.
263 void setExtendedData(ExtendedData* p);
266 * Get the store auxiliary data, or NULL if no such data is stored.
268 ExtendedData* getExtendedData();
270 void setOKAction(Action* p);
271 void setPopupEndAction(Action* p);
273 protected:
274 virtual void handlePopupEnd();
276 private:
277 struct Member
279 OUString maName; // node name
280 OUString maRealName;
281 bool mbVisible;
282 bool mbDate;
283 bool mbLeaf;
285 Member();
286 SvTreeListEntry* mpParent;
289 class CancelButton : public ::CancelButton
291 public:
292 CancelButton(ScCheckListMenuWindow* pParent);
294 virtual void Click();
296 private:
297 ScCheckListMenuWindow* mpParent;
300 enum SectionType {
301 WHOLE, // entire window
302 LISTBOX_AREA_OUTER, // box enclosing the check box items.
303 LISTBOX_AREA_INNER, // box enclosing the check box items.
304 SINGLE_BTN_AREA, // box enclosing the single-action buttons.
305 CHECK_TOGGLE_ALL, // check box for toggling all items.
306 BTN_SINGLE_SELECT,
307 BTN_SINGLE_UNSELECT,
308 BTN_OK, // OK button
309 BTN_CANCEL, // Cancel button
311 void getSectionPosSize(Point& rPos, Size& rSize, SectionType eType) const;
314 * Calculate the appropriate window size, the position and size of each
315 * control based on the menu items.
317 void packWindow();
318 void setAllMemberState(bool bSet);
319 void selectCurrentMemberOnly(bool bSet);
320 void cycleFocus(bool bReverse = false);
322 DECL_LINK( ButtonHdl, Button* );
323 DECL_LINK( TriStateHdl, void* );
324 DECL_LINK( CheckHdl, SvTreeListBox* );
326 private:
327 SvTreeListEntry* findEntry( SvTreeListEntry* pParent, const OUString& rText );
329 ScCheckListBox maChecks;
331 TriStateBox maChkToggleAll;
332 ImageButton maBtnSelectSingle;
333 ImageButton maBtnUnselectSingle;
335 OKButton maBtnOk;
336 CancelButton maBtnCancel;
338 ::std::vector<Window*> maTabStopCtrls;
339 size_t mnCurTabStop;
341 ::std::vector<Member> maMembers;
342 boost::scoped_ptr<ExtendedData> mpExtendedData;
343 boost::scoped_ptr<Action> mpOKAction;
344 boost::scoped_ptr<Action> mpPopupEndAction;
346 Config maConfig;
347 Size maWndSize; /// whole window size.
348 Size maMenuSize; /// size of all menu items combined.
349 TriState mePrevToggleAllState;
352 #endif
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */