aboutsummaryrefslogtreecommitdiff
path: root/src/Basemenu.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Basemenu.hh')
-rw-r--r--src/Basemenu.hh280
1 files changed, 131 insertions, 149 deletions
diff --git a/src/Basemenu.hh b/src/Basemenu.hh
index 27aed54..137eb8e 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,153 @@
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.14 2002/05/19 12:57:47 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"
36
37
38class Basemenu { 40class Basemenu {
39private: 41public:
40 LinkedList<BasemenuItem> *menuitems; 42 enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM };
41 Fluxbox *fluxbox; 43 enum { RIGHT = 1, LEFT };
42 Basemenu *parent; 44 enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND };
43 BImageControl *image_ctrl; 45
44 BScreen *screen; 46 explicit Basemenu(BScreen *screen);
45 47 virtual ~Basemenu();
46 Bool moving, visible, movable, torn, internal_menu, title_vis, shifted, 48
47 hide_tree; 49 //manipulators
48 Display *display; 50 int insert(const char *label, int function= 0, const char *exec = 0, int pos = -1);
49 int which_sub, which_press, which_sbl, alignment; 51 int insert(const char *label, Basemenu *submenu, int pos= -1);
50 52 int remove(unsigned int item);
51 struct _menu { 53 inline void setInternalMenu() { internal_menu = true; }
52 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap; 54 inline void setAlignment(Alignment a) { m_alignment = a; }
53 Window window, frame, title; 55 inline void setTorn() { torn = true; }
56 inline void removeParent() { if (internal_menu) m_parent = 0; }
57 void buttonPressEvent(XButtonEvent *);
58 void buttonReleaseEvent(XButtonEvent *);
59 void motionNotifyEvent(XMotionEvent *);
60 void enterNotifyEvent(XCrossingEvent *);
61 void leaveNotifyEvent(XCrossingEvent *);
62 void exposeEvent(XExposeEvent *);
63 void reconfigure();
64 void setLabel(const char *labelstr);
65 void move(int x, int y);
66 void update();
67 void setItemSelected(unsigned int index, bool val);
68 void setItemEnabled(unsigned int index, bool val);
69 virtual void drawSubmenu(unsigned int index);
70 virtual void show();
71 virtual void hide();
72
73 //accessors
74 inline bool isTorn() const { return torn; }
75 inline bool isVisible() const { return visible; }
76 inline BScreen *screen() const { return m_screen; }
77 inline Window windowID() const { return menu.window; }
78 inline const std::string &label() const { return menu.label; }
79 inline int x() const { return menu.x; }
80 inline int y() const { return menu.y; }
81 inline unsigned int width() const { return menu.width; }
82 inline unsigned int height() const { return menu.height; }
83 inline unsigned int numberOfItems() const { return menuitems.size(); }
84 inline int currentSubmenu() const { return which_sub; }
85 inline unsigned int titleHeight() const { return menu.title_h; }
86 bool hasSubmenu(unsigned int index) const;
87 bool isItemSelected(unsigned int index) const;
88 bool isItemEnabled(unsigned int index) const;
54 89
55 char *label; 90private:
56 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub, 91 typedef std::vector<BasemenuItem *> Menuitems;
57 grab_x, grab_y; 92 Fluxbox *m_fluxbox;
58 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w, 93 BScreen *m_screen;
59 bevel_h; 94 Display *m_display;
60 } menu; 95 Basemenu *m_parent;
96 BImageControl *m_image_ctrl;
97 Menuitems menuitems;
98
99 bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
100 hide_tree;
101
102 int which_sub, which_press, which_sbl;
103 Alignment m_alignment;
104
105 struct _menu {
106 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap;
107 Window window, frame, title;
108
109 std::string label;
110 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
111 grab_x, grab_y;
112 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
113 bevel_h;
114 } menu;
61 115
62 116
63protected: 117protected:
64 inline BasemenuItem *find(int index) { return menuitems->find(index); } 118 inline BasemenuItem *find(unsigned int index) const { return menuitems[index]; }
65 inline void setTitleVisibility(Bool b) { title_vis = b; } 119 inline void setTitleVisibility(bool b) { title_vis = b; }
66 inline void setMovable(Bool b) { movable = b; } 120 inline void setMovable(bool b) { movable = b; }
67 inline void setHideTree(Bool h) { hide_tree = h; } 121 inline void setHideTree(bool h) { hide_tree = h; }
68 inline void setMinimumSublevels(int m) { menu.minsub = m; } 122 inline void setMinimumSublevels(int m) { menu.minsub = m; }
69 123
70 virtual void itemSelected(int, int) = 0; 124 virtual void itemSelected(int button, unsigned int index) = 0;
71 virtual void drawItem(int, Bool = False, Bool = False, 125 virtual void drawItem(unsigned int index, bool highlight= false, bool clear= false,
72 int = -1, int = -1, unsigned int = 0, unsigned int = 0); 126 int x= -1, int y= -1, unsigned int width= 0, unsigned int height= 0);
73 virtual void redrawTitle(); 127 virtual void redrawTitle();
74 virtual void internal_hide(void); 128 virtual void internal_hide();
75
76
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}; 129};
135 130
136
137class BasemenuItem { 131class BasemenuItem {
138private: 132public:
139 Basemenu *s; 133 BasemenuItem(
140 const char **u, *l, *e; 134 const char *label,
141 int f, enabled, selected; 135 int function,
142 136 const char *exec = (const char *) 0)
143 friend class Basemenu; 137 : m_label(label ? label : "")
144 138 , m_exec(exec ? exec : "")
145 139 , m_submenu(0)
146protected: 140 , m_function(function)
141 , m_enabled(true)
142 , m_selected(false)
143 { }
144
145 BasemenuItem(const char *label, Basemenu *submenu)
146 : m_label(label ? label : "")
147 , m_exec("")
148 , m_submenu(submenu)
149 , m_function(0)
150 , m_enabled(true)
151 , m_selected(false)
152 { }
153
154 inline const std::string &exec() const { return m_exec; }
155 inline const std::string &label() const { return m_label; }
156 inline int function() const { return m_function; }
157 inline Basemenu *submenu() const { return m_submenu; }
158
159 inline bool isEnabled() const { return m_enabled; }
160 inline void setEnabled(bool enabled) { m_enabled = enabled; }
161 inline bool isSelected() const { return m_selected; }
162 inline void setSelected(bool selected) { m_selected = selected; }
147 163
164private:
165 std::string m_label, m_exec;
166 Basemenu *m_submenu;
167 int m_function;
168 bool m_enabled, m_selected;
148 169
149public: 170 friend class Basemenu;
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}; 171};
190 172
191 173
192#endif // __Basemenu_hh 174#endif // _BASEMENU_HH_