xref: /AOO41X/main/sc/source/ui/inc/dpcontrol.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef SC_DPCONTROL_HXX
29*cdf0e10cSrcweir #define SC_DPCONTROL_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "rtl/ustring.hxx"
32*cdf0e10cSrcweir #include "tools/gen.hxx"
33*cdf0e10cSrcweir #include "tools/fract.hxx"
34*cdf0e10cSrcweir #include "vcl/popupmenuwindow.hxx"
35*cdf0e10cSrcweir #include "vcl/button.hxx"
36*cdf0e10cSrcweir #include "vcl/scrbar.hxx"
37*cdf0e10cSrcweir #include "vcl/timer.hxx"
38*cdf0e10cSrcweir #include "svx/checklbx.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
41*cdf0e10cSrcweir #include <memory>
42*cdf0e10cSrcweir #include <hash_map>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace com { namespace sun { namespace star {
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir     namespace accessibility {
47*cdf0e10cSrcweir         class XAccessible;
48*cdf0e10cSrcweir     }
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir }}}
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir class OutputDevice;
53*cdf0e10cSrcweir class Point;
54*cdf0e10cSrcweir class Size;
55*cdf0e10cSrcweir class StyleSettings;
56*cdf0e10cSrcweir class Window;
57*cdf0e10cSrcweir class ScDocument;
58*cdf0e10cSrcweir class ScAccessibleFilterMenu;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir /**
61*cdf0e10cSrcweir  * This class takes care of physically drawing field button controls inside
62*cdf0e10cSrcweir  * data pilot tables.
63*cdf0e10cSrcweir  */
64*cdf0e10cSrcweir class ScDPFieldButton
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir public:
67*cdf0e10cSrcweir     ScDPFieldButton(OutputDevice* pOutDev, const StyleSettings* pStyle, const Fraction* pZoomX = NULL, const Fraction* pZoomY = NULL,
68*cdf0e10cSrcweir                     ScDocument* pDoc = NULL);
69*cdf0e10cSrcweir     ~ScDPFieldButton();
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     void setText(const ::rtl::OUString& rText);
72*cdf0e10cSrcweir     void setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL);
73*cdf0e10cSrcweir     void setDrawBaseButton(bool b);
74*cdf0e10cSrcweir     void setDrawPopupButton(bool b);
75*cdf0e10cSrcweir     void setHasHiddenMember(bool b);
76*cdf0e10cSrcweir     void setPopupPressed(bool b);
77*cdf0e10cSrcweir     void setPopupLeft(bool b);
78*cdf0e10cSrcweir     void draw();
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     void getPopupBoundingBox(Point& rPos, Size& rSize) const;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir private:
83*cdf0e10cSrcweir     void drawPopupButton();
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir private:
86*cdf0e10cSrcweir     Point                   maPos;
87*cdf0e10cSrcweir     Size                    maSize;
88*cdf0e10cSrcweir     ::rtl::OUString         maText;
89*cdf0e10cSrcweir     Fraction                maZoomX;
90*cdf0e10cSrcweir     Fraction                maZoomY;
91*cdf0e10cSrcweir     ScDocument*             mpDoc;
92*cdf0e10cSrcweir     OutputDevice*           mpOutDev;
93*cdf0e10cSrcweir     const StyleSettings*    mpStyle;
94*cdf0e10cSrcweir     bool                    mbBaseButton;
95*cdf0e10cSrcweir     bool                    mbPopupButton;
96*cdf0e10cSrcweir     bool                    mbHasHiddenMember;
97*cdf0e10cSrcweir     bool                    mbPopupPressed;
98*cdf0e10cSrcweir     bool                    mbPopupLeft;
99*cdf0e10cSrcweir };
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir // ============================================================================
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir class ScMenuFloatingWindow : public PopupMenuFloatingWindow
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir public:
106*cdf0e10cSrcweir     static size_t MENU_NOT_SELECTED;
107*cdf0e10cSrcweir     /**
108*cdf0e10cSrcweir      * Action to perform when an event takes place.  Create a sub-class of
109*cdf0e10cSrcweir      * this to implement the desired action.
110*cdf0e10cSrcweir      */
111*cdf0e10cSrcweir     class Action
112*cdf0e10cSrcweir     {
113*cdf0e10cSrcweir     public:
114*cdf0e10cSrcweir         virtual void execute() = 0;
115*cdf0e10cSrcweir     };
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     explicit ScMenuFloatingWindow(Window* pParent, ScDocument* pDoc, sal_uInt16 nMenuStackLevel = 0);
118*cdf0e10cSrcweir     virtual ~ScMenuFloatingWindow();
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     virtual void MouseMove(const MouseEvent& rMEvt);
121*cdf0e10cSrcweir     virtual void MouseButtonDown(const MouseEvent& rMEvt);
122*cdf0e10cSrcweir     virtual void MouseButtonUp(const MouseEvent& rMEvt);
123*cdf0e10cSrcweir     virtual void KeyInput(const KeyEvent& rKEvt);
124*cdf0e10cSrcweir     virtual void Paint(const Rectangle& rRect);
125*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     void addMenuItem(const ::rtl::OUString& rText, bool bEnabled, Action* pAction);
128*cdf0e10cSrcweir     ScMenuFloatingWindow* addSubMenuItem(const ::rtl::OUString& rText, bool bEnabled);
129*cdf0e10cSrcweir     void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer, bool bEnsureSubMenu);
130*cdf0e10cSrcweir     void selectMenuItem(size_t nPos, bool bSelected, bool bSubMenuTimer);
131*cdf0e10cSrcweir     void clearSelectedMenuItem();
132*cdf0e10cSrcweir     ScMenuFloatingWindow* getSubMenuWindow(size_t nPos) const;
133*cdf0e10cSrcweir     bool isMenuItemSelected(size_t nPos) const;
134*cdf0e10cSrcweir     size_t getSelectedMenuItem() const;
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     void setName(const ::rtl::OUString& rName);
137*cdf0e10cSrcweir     const ::rtl::OUString& getName() const;
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     void executeMenuItem(size_t nPos);
140*cdf0e10cSrcweir     void getMenuItemPosSize(size_t nPos, Point& rPos, Size& rSize) const;
141*cdf0e10cSrcweir     ScMenuFloatingWindow* getParentMenuWindow() const;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir protected:
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     void drawMenuItem(size_t nPos);
146*cdf0e10cSrcweir     void drawAllMenuItems();
147*cdf0e10cSrcweir     const Font& getLabelFont() const;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     void queueLaunchSubMenu(size_t nPos, ScMenuFloatingWindow* pMenu);
150*cdf0e10cSrcweir     void queueCloseSubMenu();
151*cdf0e10cSrcweir     void launchSubMenu(bool bSetMenuPos);
152*cdf0e10cSrcweir     void endSubMenu(ScMenuFloatingWindow* pSubMenu);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     void fillMenuItemsToAccessible(ScAccessibleFilterMenu* pAccMenu) const;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     ScDocument* getDoc();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir protected:
159*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
160*cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible > mxAccessible;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir private:
163*cdf0e10cSrcweir     struct SubMenuItemData;
164*cdf0e10cSrcweir     void handleMenuTimeout(SubMenuItemData* pTimer);
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     void resizeToFitMenuItems();
167*cdf0e10cSrcweir     void highlightMenuItem(size_t nPos, bool bSelected);
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     size_t getEnclosingMenuItem(const Point& rPos) const;
170*cdf0e10cSrcweir     size_t getSubMenuPos(ScMenuFloatingWindow* pSubMenu);
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     /**
173*cdf0e10cSrcweir      * Fire a menu highlight event since the accessibility framework needs
174*cdf0e10cSrcweir      * this to track focus on menu items.
175*cdf0e10cSrcweir      */
176*cdf0e10cSrcweir     void fireMenuHighlightedEvent();
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     /**
179*cdf0e10cSrcweir      * Make sure that the specified submenu is permanently up, the submenu
180*cdf0e10cSrcweir      * close timer is not active, and the correct menu item associated with
181*cdf0e10cSrcweir      * the submenu is highlighted.
182*cdf0e10cSrcweir      */
183*cdf0e10cSrcweir     void setSubMenuFocused(ScMenuFloatingWindow* pSubMenu);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     /**
186*cdf0e10cSrcweir      * When a menu item of an invisible submenu is selected, we need to make
187*cdf0e10cSrcweir      * sure that all its parent menu(s) are visible, with the right menu item
188*cdf0e10cSrcweir      * highlighted in each of the parents.  Calling this method ensures it.
189*cdf0e10cSrcweir      */
190*cdf0e10cSrcweir     void ensureSubMenuVisible(ScMenuFloatingWindow* pSubMenu);
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     /**
193*cdf0e10cSrcweir      * Dismiss any visible child submenus when a menu item of a parent menu is
194*cdf0e10cSrcweir      * selected.
195*cdf0e10cSrcweir      */
196*cdf0e10cSrcweir     void ensureSubMenuNotVisible();
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     /**
199*cdf0e10cSrcweir      * Dismiss all visible popup menus and set focus back to the application
200*cdf0e10cSrcweir      * window.  This method is called e.g. when a menu action is fired.
201*cdf0e10cSrcweir      */
202*cdf0e10cSrcweir     void terminateAllPopupMenus();
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     DECL_LINK( PopupEndHdl, void* );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir private:
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     struct MenuItemData
209*cdf0e10cSrcweir     {
210*cdf0e10cSrcweir         ::rtl::OUString maText;
211*cdf0e10cSrcweir         bool            mbEnabled;
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir         ::boost::shared_ptr<Action> mpAction;
214*cdf0e10cSrcweir         ::boost::shared_ptr<ScMenuFloatingWindow> mpSubMenuWin;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir         MenuItemData();
217*cdf0e10cSrcweir     };
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     ::std::vector<MenuItemData>         maMenuItems;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     struct SubMenuItemData
222*cdf0e10cSrcweir     {
223*cdf0e10cSrcweir         Timer                   maTimer;
224*cdf0e10cSrcweir         ScMenuFloatingWindow*   mpSubMenu;
225*cdf0e10cSrcweir         size_t                  mnMenuPos;
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         DECL_LINK( TimeoutHdl, void* );
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir         SubMenuItemData(ScMenuFloatingWindow* pParent);
230*cdf0e10cSrcweir         void reset();
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     private:
233*cdf0e10cSrcweir         ScMenuFloatingWindow* mpParent;
234*cdf0e10cSrcweir     };
235*cdf0e10cSrcweir     SubMenuItemData   maOpenTimer;
236*cdf0e10cSrcweir     SubMenuItemData   maCloseTimer;
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     Font    maLabelFont;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     // Name of this menu window, taken from the menu item of the parent window
241*cdf0e10cSrcweir     // that launches it (if this is a sub menu).  If this is a top-level menu
242*cdf0e10cSrcweir     // window, then this name can be anything.
243*cdf0e10cSrcweir     ::rtl::OUString maName;
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     size_t  mnSelectedMenu;
246*cdf0e10cSrcweir     size_t  mnClickedMenu;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     ScDocument* mpDoc;
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     ScMenuFloatingWindow* mpParentMenu;
251*cdf0e10cSrcweir     ScMenuFloatingWindow* mpActiveSubMenu;
252*cdf0e10cSrcweir };
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // ============================================================================
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir /**
257*cdf0e10cSrcweir  * This class implements a popup window for field button, for quick access
258*cdf0e10cSrcweir  * of hide-item list, and possibly more stuff related to field options.
259*cdf0e10cSrcweir  */
260*cdf0e10cSrcweir class ScDPFieldPopupWindow : public ScMenuFloatingWindow
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir public:
263*cdf0e10cSrcweir     /**
264*cdf0e10cSrcweir      * Extended data that the client code may need to store.  Create a
265*cdf0e10cSrcweir      * sub-class of this and store data there.
266*cdf0e10cSrcweir      */
267*cdf0e10cSrcweir     struct ExtendedData {};
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir     explicit ScDPFieldPopupWindow(Window* pParent, ScDocument* pDoc);
270*cdf0e10cSrcweir     virtual ~ScDPFieldPopupWindow();
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     virtual void MouseMove(const MouseEvent& rMEvt);
273*cdf0e10cSrcweir     virtual long Notify(NotifyEvent& rNEvt);
274*cdf0e10cSrcweir     virtual void Paint(const Rectangle& rRect);
275*cdf0e10cSrcweir     virtual Window* GetPreferredKeyInputWindow();
276*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     void setMemberSize(size_t n);
279*cdf0e10cSrcweir     void addMember(const ::rtl::OUString& rName, bool bVisible);
280*cdf0e10cSrcweir     void initMembers();
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     const Size& getWindowSize() const;
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     void getResult(::std::hash_map< ::rtl::OUString, bool, ::rtl::OUStringHash>& rResult);
285*cdf0e10cSrcweir     void close(bool bOK);
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     /**
288*cdf0e10cSrcweir      * Set auxiliary data that the client code might need.  Note that this
289*cdf0e10cSrcweir      * popup window class manages its life time; no explicit deletion of the
290*cdf0e10cSrcweir      * instance is needed in the client code.
291*cdf0e10cSrcweir      */
292*cdf0e10cSrcweir     void setExtendedData(ExtendedData* p);
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir     /**
295*cdf0e10cSrcweir      * Get the store auxiliary data, or NULL if no such data is stored.
296*cdf0e10cSrcweir      */
297*cdf0e10cSrcweir     ExtendedData* getExtendedData();
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     void setOKAction(Action* p);
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir private:
302*cdf0e10cSrcweir     struct Member
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir         ::rtl::OUString maName;
305*cdf0e10cSrcweir         bool            mbVisible;
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir         Member();
308*cdf0e10cSrcweir     };
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     class CancelButton : public ::CancelButton
311*cdf0e10cSrcweir     {
312*cdf0e10cSrcweir     public:
313*cdf0e10cSrcweir         CancelButton(ScDPFieldPopupWindow* pParent);
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir         virtual void Click();
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir     private:
318*cdf0e10cSrcweir         ScDPFieldPopupWindow* mpParent;
319*cdf0e10cSrcweir     };
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     enum SectionType {
322*cdf0e10cSrcweir         WHOLE,                // entire window
323*cdf0e10cSrcweir         LISTBOX_AREA_OUTER,   // box enclosing the check box items.
324*cdf0e10cSrcweir         LISTBOX_AREA_INNER,   // box enclosing the check box items.
325*cdf0e10cSrcweir         SINGLE_BTN_AREA,      // box enclosing the single-action buttons.
326*cdf0e10cSrcweir         CHECK_TOGGLE_ALL,     // check box for toggling all items.
327*cdf0e10cSrcweir         BTN_SINGLE_SELECT,
328*cdf0e10cSrcweir         BTN_SINGLE_UNSELECT,
329*cdf0e10cSrcweir         BTN_OK,               // OK button
330*cdf0e10cSrcweir         BTN_CANCEL,           // Cancel button
331*cdf0e10cSrcweir     };
332*cdf0e10cSrcweir     void getSectionPosSize(Point& rPos, Size& rSize, SectionType eType) const;
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     void setAllMemberState(bool bSet);
335*cdf0e10cSrcweir     void selectCurrentMemberOnly(bool bSet);
336*cdf0e10cSrcweir     void cycleFocus(bool bReverse = false);
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir     DECL_LINK( ButtonHdl, Button* );
339*cdf0e10cSrcweir     DECL_LINK( TriStateHdl, TriStateBox* );
340*cdf0e10cSrcweir     DECL_LINK( CheckHdl, SvTreeListBox* );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir private:
343*cdf0e10cSrcweir     SvxCheckListBox maChecks;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     TriStateBox     maChkToggleAll;
346*cdf0e10cSrcweir     ImageButton     maBtnSelectSingle;
347*cdf0e10cSrcweir     ImageButton     maBtnUnselectSingle;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir     OKButton        maBtnOk;
350*cdf0e10cSrcweir     CancelButton    maBtnCancel;
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     ::std::vector<Window*>          maTabStopCtrls;
353*cdf0e10cSrcweir     size_t                          mnCurTabStop;
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir     ::std::vector<Member>           maMembers;
356*cdf0e10cSrcweir     ::std::auto_ptr<ExtendedData>   mpExtendedData;
357*cdf0e10cSrcweir     ::std::auto_ptr<Action>         mpOKAction;
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir     const Size      maWndSize;  /// hard-coded window size.
360*cdf0e10cSrcweir     TriState mePrevToggleAllState;
361*cdf0e10cSrcweir };
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir #endif
364