1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
{
31 class ScAccessibleFilterMenu
;
33 class ScMenuFloatingWindow
: public PopupMenuFloatingWindow
36 static size_t MENU_NOT_SELECTED
;
38 * Action to perform when an event takes place. Create a sub-class of
39 * this to implement the desired 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
);
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;
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;
96 ::com::sun::star::uno::Reference
<
97 ::com::sun::star::accessibility::XAccessible
> mxAccessible
;
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
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();
149 ::boost::shared_ptr
<Action
> mpAction
;
150 ::boost::shared_ptr
<ScMenuFloatingWindow
> mpSubMenuWin
;
155 ::std::vector
<MenuItemData
> maMenuItems
;
157 struct SubMenuItemData
160 ScMenuFloatingWindow
* mpSubMenu
;
163 DECL_LINK( TimeoutHdl
, void* );
165 SubMenuItemData(ScMenuFloatingWindow
* pParent
);
169 ScMenuFloatingWindow
* mpParent
;
171 SubMenuItemData maOpenTimer
;
172 SubMenuItemData maCloseTimer
;
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.
181 size_t mnSelectedMenu
;
182 size_t mnClickedMenu
;
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
);
198 ScCheckListBox( Window
* pParent
, WinBits nWinStyle
= 0 );
199 ~ScCheckListBox() { delete mpCheckButton
; }
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
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.
233 bool mbAllowEmptySet
;
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
);
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
);
274 virtual void handlePopupEnd();
279 OUString maName
; // node name
286 SvTreeListEntry
* mpParent
;
289 class CancelButton
: public ::CancelButton
292 CancelButton(ScCheckListMenuWindow
* pParent
);
294 virtual void Click();
297 ScCheckListMenuWindow
* mpParent
;
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.
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.
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
* );
327 SvTreeListEntry
* findEntry( SvTreeListEntry
* pParent
, const OUString
& rText
);
329 ScCheckListBox maChecks
;
331 TriStateBox maChkToggleAll
;
332 ImageButton maBtnSelectSingle
;
333 ImageButton maBtnUnselectSingle
;
336 CancelButton maBtnCancel
;
338 ::std::vector
<Window
*> maTabStopCtrls
;
341 ::std::vector
<Member
> maMembers
;
342 boost::scoped_ptr
<ExtendedData
> mpExtendedData
;
343 boost::scoped_ptr
<Action
> mpOKAction
;
344 boost::scoped_ptr
<Action
> mpPopupEndAction
;
347 Size maWndSize
; /// whole window size.
348 Size maMenuSize
; /// size of all menu items combined.
349 TriState mePrevToggleAllState
;
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */