update dev300-m57
[ooovba.git] / sc / source / ui / inc / dpcontrol.hxx
blob64d56d3f9b878cd3a0f2e494d38c2ca1d4bc81b7
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 "vcl/floatwin.hxx"
37 #include "vcl/button.hxx"
38 #include "vcl/scrbar.hxx"
39 #include "vcl/timer.hxx"
41 #include <boost/shared_ptr.hpp>
42 #include <memory>
43 #include <hash_map>
45 class OutputDevice;
46 class Point;
47 class Size;
48 class StyleSettings;
49 class Window;
51 /**
52 * This class takes care of physically drawing field button controls inside
53 * data pilot tables.
55 class ScDPFieldButton
57 public:
58 ScDPFieldButton(OutputDevice* pOutDev, const StyleSettings* pStyle);
59 ~ScDPFieldButton();
61 void setText(const ::rtl::OUString& rText);
62 void setBoundingBox(const Point& rPos, const Size& rSize);
63 void setDrawPopupButton(bool b);
64 void setHasHiddenMember(bool b);
65 void draw();
67 void getPopupBoundingBox(Point& rPos, Size& rSize) const;
68 bool isPopupButton() const;
70 private:
71 void drawPopupButton();
73 private:
74 Point maPos;
75 Size maSize;
76 ::rtl::OUString maText;
77 OutputDevice* mpOutDev;
78 const StyleSettings* mpStyle;
79 bool mbPopupButton;
80 bool mbHasHiddenMember;
83 // ============================================================================
85 class ScMenuFloatingWindow : public FloatingWindow
87 public:
88 /**
89 * Action to perform when an event takes place. Create a sub-class of
90 * this to implement the desired action.
92 class Action
94 public:
95 virtual void execute() = 0;
98 explicit ScMenuFloatingWindow(Window* pParent);
99 virtual ~ScMenuFloatingWindow();
101 virtual void MouseMove(const MouseEvent& rMEvt);
102 virtual void MouseButtonDown(const MouseEvent& rMEvt);
103 virtual void MouseButtonUp(const MouseEvent& rMEvt);
104 virtual void KeyInput(const KeyEvent& rKEvt);
105 virtual void Paint(const Rectangle& rRect);
107 void addMenuItem(const ::rtl::OUString& rText, bool bEnabled, Action* pAction);
108 ScMenuFloatingWindow* addSubMenuItem(const ::rtl::OUString& rText, bool bEnabled);
110 protected:
111 void drawMenuItem(size_t nPos);
112 void drawAllMenuItems();
113 const Font& getLabelFont() const;
115 void executeMenu(size_t nPos);
116 void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer = true);
117 size_t getSelectedMenuItem() const;
118 void queueLaunchSubMenu(size_t nPos, ScMenuFloatingWindow* pMenu);
119 void queueCloseSubMenu();
120 void launchSubMenu(bool bSetMenuPos);
121 void endSubMenu();
123 private:
124 struct SubMenuItem;
125 void handleMenuTimeout(SubMenuItem* pTimer);
127 enum NotificationType { SUBMENU_FOCUSED };
128 void notify(NotificationType eType);
130 void resetMenu(bool bSetMenuPos);
131 void resizeToFitMenuItems();
132 void selectMenuItem(size_t nPos, bool bSelected, bool bSubMenuTimer);
133 void highlightMenuItem(size_t nPos, bool bSelected);
135 void getMenuItemPosSize(Point& rPos, Size& rSize, size_t nPos) const;
136 size_t getEnclosingMenuItem(const Point& rPos) const;
138 DECL_LINK( EndPopupHdl, void* );
140 private:
141 struct MenuItem
143 ::rtl::OUString maText;
144 bool mbEnabled;
146 ::boost::shared_ptr<Action> mpAction;
147 ::boost::shared_ptr<ScMenuFloatingWindow> mpSubMenuWin;
149 MenuItem();
152 ::std::vector<MenuItem> maMenuItems;
154 struct SubMenuItem
156 Timer maTimer;
157 ScMenuFloatingWindow* mpSubMenu;
158 size_t mnMenuPos;
160 DECL_LINK( TimeoutHdl, void* );
162 SubMenuItem(ScMenuFloatingWindow* pParent);
163 void reset();
165 private:
166 ScMenuFloatingWindow* mpParent;
168 SubMenuItem maOpenTimer;
169 SubMenuItem maCloseTimer;
171 Font maLabelFont;
173 size_t mnSelectedMenu;
174 size_t mnClickedMenu;
176 ScMenuFloatingWindow* mpParentMenu;
177 ScMenuFloatingWindow* mpActiveSubMenu;
179 bool mbActionFired;
182 // ============================================================================
184 /**
185 * This class implements a popup window for field button, for quick access
186 * of hide-item list, and possibly more stuff related to field options.
188 class ScDPFieldPopupWindow : public ScMenuFloatingWindow
190 public:
191 /**
192 * Extended data that the client code may need to store. Create a
193 * sub-class of this and store data there.
195 struct ExtendedData {};
197 explicit ScDPFieldPopupWindow(Window* pParent);
198 virtual ~ScDPFieldPopupWindow();
200 virtual void MouseMove(const MouseEvent& rMEvt);
201 virtual void Paint(const Rectangle& rRect);
203 void setMemberSize(size_t n);
204 void addMember(const ::rtl::OUString& rName, bool bVisible);
205 void initMembers();
207 void getResult(::std::hash_map< ::rtl::OUString, bool, ::rtl::OUStringHash>& rResult);
208 void close(bool bOK);
210 /**
211 * Set auxiliary data that the client code might need. Note that this
212 * popup window class manages its life time; no explicit deletion of the
213 * instance is needed in the client code.
215 void setExtendedData(ExtendedData* p);
217 /**
218 * Get the store auxiliary data, or NULL if no such data is stored.
220 ExtendedData* getExtendedData();
222 void setOKAction(Action* p);
224 private:
225 struct Member
227 ::rtl::OUString maName;
228 bool mbVisible;
230 Member();
233 class CancelButton : public ::CancelButton
235 public:
236 CancelButton(ScDPFieldPopupWindow* pParent);
238 virtual void Click();
240 private:
241 ScDPFieldPopupWindow* mpParent;
244 ::std::vector<Member>& getMembers();
246 enum SectionType {
247 WHOLE, // entire window
248 LISTBOX_AREA, // box enclosing the check box items.
249 FIRST_LISTITEM, // first list item at the top
250 BTN_OK, // OK button
251 BTN_CANCEL, // Cancel button
252 SCROLL_BAR_V, // vertical scroll bar along the right edge of the list box.
254 void getSectionPosSize(Point& rPos, Size& rSize, SectionType eType) const;
256 void resetDisplayedItems();
258 DECL_LINK( CheckBoxHdl, CheckBox* );
259 DECL_LINK( OKButtonHdl, OKButton* );
260 DECL_LINK( ScrollHdl, ScrollBar* );
262 private:
264 CheckBox maCheck0;
265 CheckBox maCheck1;
266 CheckBox maCheck2;
267 CheckBox maCheck3;
268 CheckBox maCheck4;
269 CheckBox maCheck5;
270 CheckBox maCheck6;
271 CheckBox maCheck7;
272 CheckBox maCheck8;
273 CheckBox maCheck9;
275 ScrollBar maScrollBar;
277 OKButton maBtnOk;
278 CancelButton maBtnCancel;
280 ::std::vector<CheckBox*> mpCheckPtr;
282 ::std::vector<Member> maMembers;
283 ::std::auto_ptr<ExtendedData> mpExtendedData;
284 ::std::auto_ptr<Action> mpOKAction;
286 size_t mnScrollPos;
289 #endif