fix for multi-head DISPLAY problem
[bbkeys.git] / src / Basemenu.hh
blob47ee3eadd827136e4749dec69b2bc094ad1419aa
1 // Basemenu.hh for Blackbox - an X11 Window manager
2 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3 // Copyright (c) 2001 by Ben Jansens <xor@orodu.net>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
23 // $Id$
25 #ifndef __Basemenu_hh
26 #define __Basemenu_hh
28 #include <X11/Xlib.h>
30 // forward declarations
31 class Basemenu;
32 class BasemenuItem;
34 class ToolWindow;
35 class BImageControl;
37 #include "LinkedList.hh"
40 class Basemenu {
41 private:
42 LinkedList<BasemenuItem> *menuitems;
43 ToolWindow *bbtool;
44 Basemenu *parent;
45 BImageControl *image_ctrl;
47 Bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
48 hide_tree;
49 Display *display;
50 int which_sub, which_press, which_sbl, alignment;
52 struct _menu {
53 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap;
54 Window window, frame, title;
56 char *label;
57 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
58 grab_x, grab_y;
59 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
60 bevel_h;
61 } menu;
63 int selected_item;
65 protected:
66 inline BasemenuItem *find(int index) { return menuitems->find(index); }
67 inline void setTitleVisibility(Bool b) { title_vis = b; }
68 inline void setMovable(Bool b) { movable = b; }
69 inline void setHideTree(Bool h) { hide_tree = h; }
70 inline void setMinimumSublevels(int m) { menu.minsub = m; }
72 virtual void itemSelected(int, int) = 0;
73 virtual void drawItem(int, Bool = False, Bool = False,
74 int = -1, int = -1, unsigned int = 0, unsigned int = 0);
75 virtual void redrawTitle();
76 virtual void internal_hide(void);
79 public:
80 Basemenu(ToolWindow *);
81 virtual ~Basemenu(void);
83 inline const Bool &isTorn(void) const { return torn; }
84 inline const Bool &isVisible(void) const { return visible; }
86 // inline BScreen *getScreen(void) { return screen; }
88 inline const Window &getWindowID(void) const { return menu.window; }
90 inline const char *getLabel(void) const { return menu.label; }
92 int insert(const char *, int = 0, const char * = (const char *) 0, int = -1);
93 int insert(const char **, int = -1, int = 0);
94 int insert(const char *, Basemenu *, int = -1);
95 int remove(int);
97 inline const int &getX(void) const { return menu.x; }
98 inline const int &getY(void) const { return menu.y; }
99 inline int getCount(void) { return menuitems->count(); }
100 inline const int &getCurrentSubmenu(void) const { return which_sub; }
102 inline const unsigned int &getWidth(void) const { return menu.width; }
103 inline const unsigned int &getHeight(void) const { return menu.height; }
104 inline const unsigned int &getTitleHeight(void) const { return menu.title_h; }
106 inline void setInternalMenu(void) { internal_menu = True; }
107 inline void setAlignment(int a) { alignment = a; }
108 inline void setTorn(void) { torn = True; }
109 inline void removeParent(void)
110 { if (internal_menu) parent = (Basemenu *) 0; }
112 Bool hasSubmenu(int);
113 Bool isItemSelected(int);
114 Bool isItemEnabled(int);
116 void buttonPressEvent(XButtonEvent *);
117 void buttonReleaseEvent(XButtonEvent *);
118 void motionNotifyEvent(XMotionEvent *);
119 void enterNotifyEvent(XCrossingEvent *);
120 void leaveNotifyEvent(XCrossingEvent *);
121 void exposeEvent(XExposeEvent *);
122 void reconfigure(void);
123 void setLabel(const char *n);
124 void move(int, int);
125 void update(void);
126 void setItemSelected(int, Bool);
127 void setItemEnabled(int, Bool);
129 virtual void drawSubmenu(int);
130 virtual void show(void);
131 virtual void hide(void);
133 enum { AlignDontCare = 1, AlignTop, AlignBottom };
134 enum { Right = 1, Left };
135 enum { Empty = 0, Square, Triangle, Diamond };
136 enum { LeftJustify = 1, RightJustify, CenterJustify };
138 inline const void setHighlight(int i) { selected_item = i; }
142 class BasemenuItem {
143 private:
144 Basemenu *s;
145 const char **u, *l, *e;
146 int f, enabled, selected;
148 friend class Basemenu;
151 protected:
154 public:
155 BasemenuItem(const char *lp, int fp, const char *ep = (const char *) 0) {
156 l = lp;
157 e = ep;
158 s = 0;
159 f = fp;
160 u = 0;
161 enabled = 1;
162 selected = 0;
165 BasemenuItem(const char *lp, Basemenu *mp) {
166 l = lp;
167 s = mp;
168 e = 0;
169 f = 0;
170 u = 0;
171 enabled = 1;
172 selected = 0;
175 BasemenuItem(const char **up, int fp) {
176 u = up;
177 l = e = 0;
178 f = fp;
179 s = 0;
180 enabled = 1;
181 selected = 0;
184 inline const char *exec(void) const { return e; }
185 inline const char *label(void) const { return l; }
186 inline const char **ulabel(void) const { return u; }
187 inline const int &function(void) const { return f; }
188 inline Basemenu *submenu(void) { return s; }
190 inline const int &isEnabled(void) const { return enabled; }
191 inline void setEnabled(int e) { enabled = e; }
192 inline const int &isSelected(void) const { return selected; }
193 inline void setSelected(int s) { selected = s; }
197 #endif // __Basemenu_hh