1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: document.hxx,v $
10 * $Revision: 1.115.36.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_DPCONTROL_HXX
32 #define SC_DPCONTROL_HXX
34 #include "rtl/ustring.hxx"
35 #include "tools/gen.hxx"
36 #include "tools/fract.hxx"
37 #include "vcl/popupmenuwindow.hxx"
38 #include "vcl/button.hxx"
39 #include "vcl/scrbar.hxx"
40 #include "vcl/timer.hxx"
41 #include "svx/checklbx.hxx"
43 #include <boost/shared_ptr.hpp>
47 namespace com
{ namespace sun
{ namespace star
{
49 namespace accessibility
{
61 class ScAccessibleFilterMenu
;
64 * This class takes care of physically drawing field button controls inside
70 ScDPFieldButton(OutputDevice
* pOutDev
, const StyleSettings
* pStyle
, const Fraction
* pZoomX
= NULL
, const Fraction
* pZoomY
= NULL
);
73 void setText(const ::rtl::OUString
& rText
);
74 void setBoundingBox(const Point
& rPos
, const Size
& rSize
);
75 void setDrawBaseButton(bool b
);
76 void setDrawPopupButton(bool b
);
77 void setHasHiddenMember(bool b
);
78 void setPopupPressed(bool b
);
81 void getPopupBoundingBox(Point
& rPos
, Size
& rSize
) const;
82 bool isPopupButton() const;
85 void drawPopupButton();
90 ::rtl::OUString maText
;
93 OutputDevice
* mpOutDev
;
94 const StyleSettings
* mpStyle
;
97 bool mbHasHiddenMember
;
101 // ============================================================================
103 class ScMenuFloatingWindow
: public PopupMenuFloatingWindow
106 static size_t MENU_NOT_SELECTED
;
108 * Action to perform when an event takes place. Create a sub-class of
109 * this to implement the desired action.
114 virtual void execute() = 0;
117 explicit ScMenuFloatingWindow(Window
* pParent
, ScDocument
* pDoc
, USHORT nMenuStackLevel
= 0);
118 virtual ~ScMenuFloatingWindow();
120 virtual void MouseMove(const MouseEvent
& rMEvt
);
121 virtual void MouseButtonDown(const MouseEvent
& rMEvt
);
122 virtual void MouseButtonUp(const MouseEvent
& rMEvt
);
123 virtual void KeyInput(const KeyEvent
& rKEvt
);
124 virtual void Paint(const Rectangle
& rRect
);
125 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> CreateAccessible();
127 void addMenuItem(const ::rtl::OUString
& rText
, bool bEnabled
, Action
* pAction
);
128 ScMenuFloatingWindow
* addSubMenuItem(const ::rtl::OUString
& rText
, bool bEnabled
);
129 void setSelectedMenuItem(size_t nPos
, bool bSubMenuTimer
, bool bEnsureSubMenu
);
130 void selectMenuItem(size_t nPos
, bool bSelected
, bool bSubMenuTimer
);
131 void clearSelectedMenuItem();
132 ScMenuFloatingWindow
* getSubMenuWindow(size_t nPos
) const;
133 size_t getMenuItemCount() const;
134 ::rtl::OUString
getMenuItemName(size_t nPos
) const;
135 bool isMenuItemEnabled(size_t nPos
) const;
136 bool isMenuItemSelected(size_t nPos
) const;
137 size_t getSelectedMenuItem() const;
139 void setName(const ::rtl::OUString
& rName
);
140 const ::rtl::OUString
& getName() const;
142 void executeMenuItem(size_t nPos
);
143 void getMenuItemPosSize(size_t nPos
, Point
& rPos
, Size
& rSize
) const;
144 ScMenuFloatingWindow
* getParentMenuWindow() const;
148 void drawMenuItem(size_t nPos
);
149 void drawAllMenuItems();
150 const Font
& getLabelFont() const;
152 void queueLaunchSubMenu(size_t nPos
, ScMenuFloatingWindow
* pMenu
);
153 void queueCloseSubMenu();
154 void launchSubMenu(bool bSetMenuPos
);
155 void endSubMenu(ScMenuFloatingWindow
* pSubMenu
);
157 void fillMenuItemsToAccessible(ScAccessibleFilterMenu
* pAccMenu
) const;
159 ScDocument
* getDoc();
162 ::com::sun::star::uno::Reference
<
163 ::com::sun::star::accessibility::XAccessible
> mxAccessible
;
166 struct SubMenuItemData
;
167 void handleMenuTimeout(SubMenuItemData
* pTimer
);
169 void resizeToFitMenuItems();
170 void highlightMenuItem(size_t nPos
, bool bSelected
);
172 size_t getEnclosingMenuItem(const Point
& rPos
) const;
173 size_t getSubMenuPos(ScMenuFloatingWindow
* pSubMenu
);
176 * Fire a menu highlight event since the accessibility framework needs
177 * this to track focus on menu items.
179 void fireMenuHighlightedEvent();
182 * Make sure that the specified submenu is permanently up, the submenu
183 * close timer is not active, and the correct menu item associated with
184 * the submenu is highlighted.
186 void setSubMenuFocused(ScMenuFloatingWindow
* pSubMenu
);
189 * When a menu item of an invisible submenu is selected, we need to make
190 * sure that all its parent menu(s) are visible, with the right menu item
191 * highlighted in each of the parents. Calling this method ensures it.
193 void ensureSubMenuVisible(ScMenuFloatingWindow
* pSubMenu
);
196 * Dismiss any visible child submenus when a menu item of a parent menu is
199 void ensureSubMenuNotVisible();
202 * Dismiss all visible popup menus and set focus back to the application
203 * window. This method is called e.g. when a menu action is fired.
205 void terminateAllPopupMenus();
207 DECL_LINK( PopupEndHdl
, void* );
213 ::rtl::OUString maText
;
216 ::boost::shared_ptr
<Action
> mpAction
;
217 ::boost::shared_ptr
<ScMenuFloatingWindow
> mpSubMenuWin
;
222 ::std::vector
<MenuItemData
> maMenuItems
;
224 struct SubMenuItemData
227 ScMenuFloatingWindow
* mpSubMenu
;
230 DECL_LINK( TimeoutHdl
, void* );
232 SubMenuItemData(ScMenuFloatingWindow
* pParent
);
236 ScMenuFloatingWindow
* mpParent
;
238 SubMenuItemData maOpenTimer
;
239 SubMenuItemData maCloseTimer
;
243 // Name of this menu window, taken from the menu item of the parent window
244 // that launches it (if this is a sub menu). If this is a top-level menu
245 // window, then this name can be anything.
246 ::rtl::OUString maName
;
248 size_t mnSelectedMenu
;
249 size_t mnClickedMenu
;
253 ScMenuFloatingWindow
* mpParentMenu
;
254 ScMenuFloatingWindow
* mpActiveSubMenu
;
257 // ============================================================================
260 * This class implements a popup window for field button, for quick access
261 * of hide-item list, and possibly more stuff related to field options.
263 class ScDPFieldPopupWindow
: public ScMenuFloatingWindow
267 * Extended data that the client code may need to store. Create a
268 * sub-class of this and store data there.
270 struct ExtendedData
{};
272 explicit ScDPFieldPopupWindow(Window
* pParent
, ScDocument
* pDoc
);
273 virtual ~ScDPFieldPopupWindow();
275 virtual void MouseMove(const MouseEvent
& rMEvt
);
276 virtual long Notify(NotifyEvent
& rNEvt
);
277 virtual void Paint(const Rectangle
& rRect
);
278 virtual Window
* GetPreferredKeyInputWindow();
279 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> CreateAccessible();
281 void setMemberSize(size_t n
);
282 void addMember(const ::rtl::OUString
& rName
, bool bVisible
);
285 const Size
& getWindowSize() const;
287 void getResult(::std::hash_map
< ::rtl::OUString
, bool, ::rtl::OUStringHash
>& rResult
);
288 void close(bool bOK
);
291 * Set auxiliary data that the client code might need. Note that this
292 * popup window class manages its life time; no explicit deletion of the
293 * instance is needed in the client code.
295 void setExtendedData(ExtendedData
* p
);
298 * Get the store auxiliary data, or NULL if no such data is stored.
300 ExtendedData
* getExtendedData();
302 void setOKAction(Action
* p
);
307 ::rtl::OUString maName
;
313 class CancelButton
: public ::CancelButton
316 CancelButton(ScDPFieldPopupWindow
* pParent
);
318 virtual void Click();
321 ScDPFieldPopupWindow
* mpParent
;
325 WHOLE
, // entire window
326 LISTBOX_AREA_OUTER
, // box enclosing the check box items.
327 LISTBOX_AREA_INNER
, // box enclosing the check box items.
328 SINGLE_BTN_AREA
, // box enclosing the single-action buttons.
329 CHECK_TOGGLE_ALL
, // check box for toggling all items.
333 BTN_CANCEL
, // Cancel button
335 void getSectionPosSize(Point
& rPos
, Size
& rSize
, SectionType eType
) const;
337 void setAllMemberState(bool bSet
);
338 void selectCurrentMemberOnly(bool bSet
);
339 void cycleFocus(bool bReverse
= false);
341 DECL_LINK( ButtonHdl
, Button
* );
342 DECL_LINK( TriStateHdl
, TriStateBox
* );
343 DECL_LINK( CheckHdl
, SvTreeListBox
* );
346 SvxCheckListBox maChecks
;
348 TriStateBox maChkToggleAll
;
349 ImageButton maBtnSelectSingle
;
350 ImageButton maBtnUnselectSingle
;
353 CancelButton maBtnCancel
;
355 ::std::vector
<Window
*> maTabStopCtrls
;
358 ::std::vector
<Member
> maMembers
;
359 ::std::auto_ptr
<ExtendedData
> mpExtendedData
;
360 ::std::auto_ptr
<Action
> mpOKAction
;
362 const Size maWndSize
; /// hard-coded window size.
363 TriState mePrevToggleAllState
;