diff options
author | fluxgen <fluxgen> | 2002-12-25 11:46:50 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-12-25 11:46:50 (GMT) |
commit | f2a4e6ae2ce6f1d88490a0873ac330b70b6f7d8f (patch) | |
tree | 14275c23d251d8f4f3661d058ea98884b9472e43 /src/FbTk/Menu.hh | |
parent | 61ec462e668056089d0085e90079196d12596236 (diff) | |
download | fluxbox_pavel-f2a4e6ae2ce6f1d88490a0873ac330b70b6f7d8f.zip fluxbox_pavel-f2a4e6ae2ce6f1d88490a0873ac330b70b6f7d8f.tar.bz2 |
moved from Basemenu to FbTk menu and starting to use MenuTheme with Commands
Diffstat (limited to 'src/FbTk/Menu.hh')
-rw-r--r-- | src/FbTk/Menu.hh | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh new file mode 100644 index 0000000..98684de --- /dev/null +++ b/src/FbTk/Menu.hh | |||
@@ -0,0 +1,242 @@ | |||
1 | // Menu.hh for FbTk - Fluxbox Toolkit | ||
2 | // Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Basemenu.hh for Blackbox - an X11 Window manager | ||
5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) | ||
6 | // | ||
7 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | // copy of this software and associated documentation files (the "Software"), | ||
9 | // to deal in the Software without restriction, including without limitation | ||
10 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | // and/or sell copies of the Software, and to permit persons to whom the | ||
12 | // Software is furnished to do so, subject to the following conditions: | ||
13 | // | ||
14 | // The above copyright notice and this permission notice shall be included in | ||
15 | // all copies or substantial portions of the Software. | ||
16 | // | ||
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
20 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
23 | // DEALINGS IN THE SOFTWARE. | ||
24 | |||
25 | // $Id: Menu.hh,v 1.1 2002/12/25 11:46:50 fluxgen Exp $ | ||
26 | |||
27 | #ifndef FBTK_MENU_HH | ||
28 | #define FBTK_MENU_HH | ||
29 | |||
30 | #include <X11/Xlib.h> | ||
31 | #include <vector> | ||
32 | #include <string> | ||
33 | |||
34 | #include "FbWindow.hh" | ||
35 | #include "EventHandler.hh" | ||
36 | #include "RefCount.hh" | ||
37 | #include "Command.hh" | ||
38 | |||
39 | class BImageControl; | ||
40 | |||
41 | namespace FbTk { | ||
42 | |||
43 | class MenuItem; | ||
44 | class MenuTheme; | ||
45 | |||
46 | /** | ||
47 | Base class for menus | ||
48 | */ | ||
49 | class Menu: public FbTk::EventHandler { | ||
50 | public: | ||
51 | enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; | ||
52 | enum { RIGHT = 1, LEFT }; | ||
53 | |||
54 | /** | ||
55 | Bullet type | ||
56 | */ | ||
57 | enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND }; | ||
58 | |||
59 | Menu(MenuTheme &tm, int screen_num, BImageControl &imgctrl); | ||
60 | virtual ~Menu(); | ||
61 | |||
62 | /** | ||
63 | @name manipulators | ||
64 | */ | ||
65 | //@{ | ||
66 | /// add a menu item with a label and a command | ||
67 | int insert(const char *label, RefCount<Command> &cmd, int pos=-1); | ||
68 | /// note: obsolete | ||
69 | int insert(const char *label, int function= 0, const char *exec = 0, int pos = -1); | ||
70 | /// add submenu | ||
71 | int insert(const char *label, Menu *submenu, int pos= -1); | ||
72 | /// remove item | ||
73 | int remove(unsigned int item); | ||
74 | inline void setInternalMenu() { internal_menu = true; } | ||
75 | inline void setAlignment(Alignment a) { m_alignment = a; } | ||
76 | inline void setTorn() { torn = true; } | ||
77 | inline void removeParent() { if (internal_menu) m_parent = 0; } | ||
78 | /// raise this window | ||
79 | void raise(); | ||
80 | /// lower this window | ||
81 | void lower(); | ||
82 | /** | ||
83 | @name event handlers | ||
84 | */ | ||
85 | //@{ | ||
86 | void buttonPressEvent(XButtonEvent &bp); | ||
87 | void buttonReleaseEvent(XButtonEvent &br); | ||
88 | void motionNotifyEvent(XMotionEvent &mn); | ||
89 | void enterNotifyEvent(XCrossingEvent &en); | ||
90 | void leaveNotifyEvent(XCrossingEvent &ce); | ||
91 | void exposeEvent(XExposeEvent &ee); | ||
92 | //@} | ||
93 | |||
94 | void reconfigure(); | ||
95 | /// set label string | ||
96 | void setLabel(const char *labelstr); | ||
97 | /// move menu to x,y | ||
98 | void move(int x, int y); | ||
99 | void update(); | ||
100 | void setItemSelected(unsigned int index, bool val); | ||
101 | void setItemEnabled(unsigned int index, bool val); | ||
102 | virtual void drawSubmenu(unsigned int index); | ||
103 | /// show menu | ||
104 | virtual void show(); | ||
105 | /// hide menu | ||
106 | virtual void hide(); | ||
107 | /*@}*/ | ||
108 | |||
109 | /** | ||
110 | @name accessors | ||
111 | */ | ||
112 | //@{ | ||
113 | bool isTorn() const { return torn; } | ||
114 | bool isVisible() const { return visible; } | ||
115 | int screenNumber() const { return m_screen_num; } | ||
116 | Window windowID() const { return menu.window.window(); } | ||
117 | const std::string &label() const { return menu.label; } | ||
118 | int x() const { return menu.x; } | ||
119 | int y() const { return menu.y; } | ||
120 | unsigned int width() const { return menu.width; } | ||
121 | unsigned int height() const { return menu.height; } | ||
122 | unsigned int numberOfItems() const { return menuitems.size(); } | ||
123 | int currentSubmenu() const { return which_sub; } | ||
124 | unsigned int titleHeight() const { return menu.title_h; } | ||
125 | bool hasSubmenu(unsigned int index) const; | ||
126 | bool isItemSelected(unsigned int index) const; | ||
127 | bool isItemEnabled(unsigned int index) const; | ||
128 | //@} | ||
129 | |||
130 | protected: | ||
131 | |||
132 | inline MenuItem *find(unsigned int index) const { return menuitems[index]; } | ||
133 | inline void setTitleVisibility(bool b) { title_vis = b; } | ||
134 | inline void setMovable(bool b) { movable = b; } | ||
135 | inline void setHideTree(bool h) { hide_tree = h; } | ||
136 | inline void setMinimumSublevels(int m) { menu.minsub = m; } | ||
137 | |||
138 | virtual void itemSelected(int button, unsigned int index) = 0; | ||
139 | virtual void drawItem(unsigned int index, bool highlight = false, | ||
140 | bool clear= false, | ||
141 | int x= -1, int y= -1, | ||
142 | unsigned int width= 0, unsigned int height= 0); | ||
143 | virtual void redrawTitle(); | ||
144 | virtual void internal_hide(); | ||
145 | inline Menu *parent() { return m_parent; } | ||
146 | inline const Menu *parent() const { return m_parent; } | ||
147 | |||
148 | private: | ||
149 | typedef std::vector<MenuItem *> Menuitems; | ||
150 | const MenuTheme &m_theme; | ||
151 | Display *m_display; | ||
152 | const int m_screen_num; | ||
153 | Menu *m_parent; | ||
154 | BImageControl &m_image_ctrl; | ||
155 | Menuitems menuitems; | ||
156 | |||
157 | const unsigned int m_screen_width, m_screen_height; | ||
158 | bool moving, visible, movable, torn, internal_menu, title_vis, shifted, | ||
159 | hide_tree; | ||
160 | |||
161 | int which_sub, which_press, which_sbl; | ||
162 | Alignment m_alignment; | ||
163 | int m_border_width; | ||
164 | struct _menu { | ||
165 | Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap; | ||
166 | FbTk::FbWindow window, frame, title; | ||
167 | |||
168 | std::string label; | ||
169 | int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub, | ||
170 | grab_x, grab_y; | ||
171 | unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w, | ||
172 | bevel_h; | ||
173 | } menu; | ||
174 | |||
175 | }; | ||
176 | |||
177 | /** | ||
178 | A menu item in Menu | ||
179 | */ | ||
180 | class MenuItem { | ||
181 | public: | ||
182 | MenuItem( | ||
183 | const char *label, | ||
184 | int function, | ||
185 | const char *exec = (const char *) 0) | ||
186 | : m_label(label ? label : "") | ||
187 | , m_exec(exec ? exec : "") | ||
188 | , m_submenu(0) | ||
189 | , m_function(function) | ||
190 | , m_enabled(true) | ||
191 | , m_selected(false) | ||
192 | { } | ||
193 | /// create a menu item with a specific command to be executed on click | ||
194 | MenuItem(const char *label, RefCount<Command> &cmd): | ||
195 | m_label(label ? label : ""), | ||
196 | m_submenu(0), | ||
197 | m_command(cmd), | ||
198 | m_function(0), | ||
199 | m_enabled(true), | ||
200 | m_selected(false) { | ||
201 | |||
202 | } | ||
203 | |||
204 | MenuItem(const char *label, Menu *submenu) | ||
205 | : m_label(label ? label : "") | ||
206 | , m_exec("") | ||
207 | , m_submenu(submenu) | ||
208 | , m_function(0) | ||
209 | , m_enabled(true) | ||
210 | , m_selected(false) | ||
211 | { } | ||
212 | |||
213 | void setSelected(bool selected) { m_selected = selected; } | ||
214 | void setEnabled(bool enabled) { m_enabled = enabled; } | ||
215 | Menu *submenu() { return m_submenu; } | ||
216 | /** | ||
217 | @name accessors | ||
218 | */ | ||
219 | //@{ | ||
220 | const std::string &exec() const { return m_exec; } | ||
221 | const std::string &label() const { return m_label; } | ||
222 | int function() const { return m_function; } | ||
223 | const Menu *submenu() const { return m_submenu; } | ||
224 | bool isEnabled() const { return m_enabled; } | ||
225 | bool isSelected() const { return m_selected; } | ||
226 | RefCount<Command> &command() { return m_command; } | ||
227 | const RefCount<Command> &command() const { return m_command; } | ||
228 | //@} | ||
229 | |||
230 | private: | ||
231 | std::string m_label; ///< label of this item | ||
232 | std::string m_exec; ///< command string to execute | ||
233 | Menu *m_submenu; ///< a submenu, 0 if we don't have one | ||
234 | RefCount<Command> m_command; ///< command to be executed | ||
235 | int m_function; | ||
236 | bool m_enabled, m_selected; | ||
237 | |||
238 | friend class Menu; | ||
239 | }; | ||
240 | |||
241 | }; // end namespace FbTk | ||
242 | #endif // FBTK_MENU_HH | ||