aboutsummaryrefslogtreecommitdiff
path: root/src/Basemenu.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Basemenu.hh')
-rw-r--r--src/Basemenu.hh313
1 files changed, 165 insertions, 148 deletions
diff --git a/src/Basemenu.hh b/src/Basemenu.hh
index 27aed54..29bb3ac 100644
--- a/src/Basemenu.hh
+++ b/src/Basemenu.hh
@@ -1,3 +1,6 @@
1// Basemenu.hh for Fluxbox Window manager
2// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
3//
1// Basemenu.hh for Blackbox - an X11 Window manager 4// Basemenu.hh for Blackbox - an X11 Window manager
2// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) 5// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3// 6//
@@ -19,174 +22,188 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
21 24
22#ifndef __Basemenu_hh 25// $Id: Basemenu.hh,v 1.16 2002/08/04 15:55:13 fluxgen Exp $
23#define __Basemenu_hh 26
27#ifndef BASEMENU_HH
28#define BASEMENU_HH
24 29
25#include <X11/Xlib.h> 30#include <X11/Xlib.h>
31#include <vector>
32#include <string>
26 33
27// forward declarations
28class Basemenu; 34class Basemenu;
29class BasemenuItem; 35class BasemenuItem;
30
31class Fluxbox; 36class Fluxbox;
32class BImageControl; 37class BImageControl;
33class BScreen; 38class BScreen;
34 39/**
35#include "LinkedList.hh" 40 Base class for menus
36 41*/
37
38class Basemenu { 42class Basemenu {
39private: 43public:
40 LinkedList<BasemenuItem> *menuitems; 44 enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM };
41 Fluxbox *fluxbox; 45 enum { RIGHT = 1, LEFT };
42 Basemenu *parent; 46
43 BImageControl *image_ctrl; 47 /**
44 BScreen *screen; 48 Bullet type
45 49 */
46 Bool moving, visible, movable, torn, internal_menu, title_vis, shifted, 50 enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND };
47 hide_tree; 51
48 Display *display; 52 explicit Basemenu(BScreen *screen);
49 int which_sub, which_press, which_sbl, alignment; 53 virtual ~Basemenu();
50 54
51 struct _menu { 55 /**
52 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap; 56 @name manipulators
53 Window window, frame, title; 57 */
58 //@{
59 int insert(const char *label, int function= 0, const char *exec = 0, int pos = -1);
60 int insert(const char *label, Basemenu *submenu, int pos= -1);
61 int remove(unsigned int item);
62 inline void setInternalMenu() { internal_menu = true; }
63 inline void setAlignment(Alignment a) { m_alignment = a; }
64 inline void setTorn() { torn = true; }
65 inline void removeParent() { if (internal_menu) m_parent = 0; }
66 /**
67 @name event handlers
68 */
69 //@{
70 void buttonPressEvent(XButtonEvent *bp);
71 void buttonReleaseEvent(XButtonEvent *br);
72 void motionNotifyEvent(XMotionEvent *mn);
73 void enterNotifyEvent(XCrossingEvent *en);
74 void leaveNotifyEvent(XCrossingEvent *ce);
75 void exposeEvent(XExposeEvent *ee);
76 //@}
77
78 void reconfigure();
79 /// set label string
80 void setLabel(const char *labelstr);
81 /// move menu to x,y
82 void move(int x, int y);
83 void update();
84 void setItemSelected(unsigned int index, bool val);
85 void setItemEnabled(unsigned int index, bool val);
86 virtual void drawSubmenu(unsigned int index);
87 virtual void show();
88 virtual void hide();
89 /*@}*/
90
91 /**
92 @name accessors
93 */
94 //@{
95 inline bool isTorn() const { return torn; }
96 inline bool isVisible() const { return visible; }
97 inline BScreen *screen() const { return m_screen; }
98 inline Window windowID() const { return menu.window; }
99 inline const std::string &label() const { return menu.label; }
100 inline int x() const { return menu.x; }
101 inline int y() const { return menu.y; }
102 inline unsigned int width() const { return menu.width; }
103 inline unsigned int height() const { return menu.height; }
104 inline unsigned int numberOfItems() const { return menuitems.size(); }
105 inline int currentSubmenu() const { return which_sub; }
106 inline unsigned int titleHeight() const { return menu.title_h; }
107 bool hasSubmenu(unsigned int index) const;
108 bool isItemSelected(unsigned int index) const;
109 bool isItemEnabled(unsigned int index) const;
110 //@}
54 111
55 char *label; 112protected:
56 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
57 grab_x, grab_y;
58 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
59 bevel_h;
60 } menu;
61 113
114 inline BasemenuItem *find(unsigned int index) const { return menuitems[index]; }
115 inline void setTitleVisibility(bool b) { title_vis = b; }
116 inline void setMovable(bool b) { movable = b; }
117 inline void setHideTree(bool h) { hide_tree = h; }
118 inline void setMinimumSublevels(int m) { menu.minsub = m; }
62 119
63protected: 120 virtual void itemSelected(int button, unsigned int index) = 0;
64 inline BasemenuItem *find(int index) { return menuitems->find(index); } 121 virtual void drawItem(unsigned int index, bool highlight= false, bool clear= false,
65 inline void setTitleVisibility(Bool b) { title_vis = b; } 122 int x= -1, int y= -1, unsigned int width= 0, unsigned int height= 0);
66 inline void setMovable(Bool b) { movable = b; } 123 virtual void redrawTitle();
67 inline void setHideTree(Bool h) { hide_tree = h; } 124 virtual void internal_hide();
68 inline void setMinimumSublevels(int m) { menu.minsub = m; } 125 inline Basemenu *parent() { return m_parent; }
126 inline const Basemenu *GetParent() const { return m_parent; }
69 127
70 virtual void itemSelected(int, int) = 0; 128private:
71 virtual void drawItem(int, Bool = False, Bool = False,
72 int = -1, int = -1, unsigned int = 0, unsigned int = 0);
73 virtual void redrawTitle();
74 virtual void internal_hide(void);
75 129
130 typedef std::vector<BasemenuItem *> Menuitems;
131 Fluxbox *m_fluxbox; //< fluxbox object, obsolete
132 BScreen *m_screen;
133 Display *m_display;
134 Basemenu *m_parent;
135 BImageControl *m_image_ctrl;
136 Menuitems menuitems;
137
138 bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
139 hide_tree;
140
141 int which_sub, which_press, which_sbl;
142 Alignment m_alignment;
143
144 struct _menu {
145 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap;
146 Window window, frame, title;
147
148 std::string label;
149 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
150 grab_x, grab_y;
151 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
152 bevel_h;
153 } menu;
76 154
77public:
78 Basemenu(BScreen *);
79 virtual ~Basemenu(void);
80
81 inline const Bool &isTorn(void) const { return torn; }
82 inline const Bool &isVisible(void) const { return visible; }
83
84 inline BScreen *getScreen(void) { return screen; }
85
86 inline const Window &getWindowID(void) const { return menu.window; }
87
88 inline const char *getLabel(void) const { return menu.label; }
89
90 int insert(const char *, int = 0, const char * = (const char *) 0, int = -1);
91 int insert(const char **, int = -1, int = 0);
92 int insert(const char *, Basemenu *, int = -1);
93 int remove(int);
94
95 inline const int &getX(void) const { return menu.x; }
96 inline const int &getY(void) const { return menu.y; }
97 inline int getCount(void) { return menuitems->count(); }
98 inline const int &getCurrentSubmenu(void) const { return which_sub; }
99
100 inline const unsigned int &getWidth(void) const { return menu.width; }
101 inline const unsigned int &getHeight(void) const { return menu.height; }
102 inline const unsigned int &getTitleHeight(void) const { return menu.title_h; }
103
104 inline void setInternalMenu(void) { internal_menu = True; }
105 inline void setAlignment(int a) { alignment = a; }
106 inline void setTorn(void) { torn = True; }
107 inline void removeParent(void)
108 { if (internal_menu) parent = (Basemenu *) 0; }
109
110 Bool hasSubmenu(int);
111 Bool isItemSelected(int);
112 Bool isItemEnabled(int);
113
114 void buttonPressEvent(XButtonEvent *);
115 void buttonReleaseEvent(XButtonEvent *);
116 void motionNotifyEvent(XMotionEvent *);
117 void enterNotifyEvent(XCrossingEvent *);
118 void leaveNotifyEvent(XCrossingEvent *);
119 void exposeEvent(XExposeEvent *);
120 void reconfigure(void);
121 void setLabel(const char *n);
122 void move(int, int);
123 void update(void);
124 void setItemSelected(int, Bool);
125 void setItemEnabled(int, Bool);
126
127 virtual void drawSubmenu(int);
128 virtual void show(void);
129 virtual void hide(void);
130
131 enum { AlignDontCare = 1, AlignTop, AlignBottom };
132 enum { Right = 1, Left };
133 enum { Empty = 0, Square, Triangle, Diamond };
134}; 155};
135 156
136 157/**
158 A menu item
159*/
137class BasemenuItem { 160class BasemenuItem {
161public:
162 BasemenuItem(
163 const char *label,
164 int function,
165 const char *exec = (const char *) 0)
166 : m_label(label ? label : "")
167 , m_exec(exec ? exec : "")
168 , m_submenu(0)
169 , m_function(function)
170 , m_enabled(true)
171 , m_selected(false)
172 { }
173
174 BasemenuItem(const char *label, Basemenu *submenu)
175 : m_label(label ? label : "")
176 , m_exec("")
177 , m_submenu(submenu)
178 , m_function(0)
179 , m_enabled(true)
180 , m_selected(false)
181 { }
182
183 void setSelected(bool selected) { m_selected = selected; }
184 void setEnabled(bool enabled) { m_enabled = enabled; }
185 Basemenu *submenu() { return m_submenu; }
186 /**
187 @name accessors
188 */
189 //@{
190 const std::string &exec() const { return m_exec; }
191 const std::string &label() const { return m_label; }
192 int function() const { return m_function; }
193 const Basemenu *submenu() const { return m_submenu; }
194 bool isEnabled() const { return m_enabled; }
195 bool isSelected() const { return m_selected; }
196 //@}
197
138private: 198private:
139 Basemenu *s; 199 std::string m_label; ///< label of this item
140 const char **u, *l, *e; 200 std::string m_exec; ///< command string to execute
141 int f, enabled, selected; 201 Basemenu *m_submenu; ///< a submenu, 0 if we don't have one
142 202 int m_function;
143 friend class Basemenu; 203 bool m_enabled, m_selected;
144 204
145 205 friend class Basemenu;
146protected:
147
148
149public:
150 BasemenuItem(const char *lp, int fp, const char *ep = (const char *) 0) {
151 l = lp;
152 e = ep;
153 s = 0;
154 f = fp;
155 u = 0;
156 enabled = 1;
157 selected = 0;
158 }
159
160 BasemenuItem(const char *lp, Basemenu *mp) {
161 l = lp;
162 s = mp;
163 e = 0;
164 f = 0;
165 u = 0;
166 enabled = 1;
167 selected = 0;
168 }
169
170 BasemenuItem(const char **up, int fp) {
171 u = up;
172 l = e = 0;
173 f = fp;
174 s = 0;
175 enabled = 1;
176 selected = 0;
177 }
178
179 inline const char *exec(void) const { return e; }
180 inline const char *label(void) const { return l; }
181 inline const char **ulabel(void) const { return u; }
182 inline const int &function(void) const { return f; }
183 inline Basemenu *submenu(void) { return s; }
184
185 inline const int &isEnabled(void) const { return enabled; }
186 inline void setEnabled(int e) { enabled = e; }
187 inline const int &isSelected(void) const { return selected; }
188 inline void setSelected(int s) { selected = s; }
189}; 206};
190 207
191 208
192#endif // __Basemenu_hh 209#endif // BASEMENU_HH