]> icculus.org git repositories - mikachu/openbox.git/blob - src/Basemenu.h
fixed memory leak in screen::load()
[mikachu/openbox.git] / src / Basemenu.h
1 // Basemenu.h for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.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:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
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.
22
23 #ifndef   __Basemenu_hh
24 #define   __Basemenu_hh
25
26 #include <X11/Xlib.h>
27
28 class Openbox;
29 class BImageControl;
30 class BScreen;
31 class Basemenu;
32 class BasemenuItem;
33 #include "LinkedList.h"
34
35
36 class Basemenu {
37 private:
38   LinkedList<BasemenuItem> *menuitems;
39   Openbox &openbox;
40   Basemenu *parent;
41   BImageControl *image_ctrl;
42   BScreen &screen;
43
44   Bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
45     hide_tree;
46   Display *display;
47   int which_sub, which_press, which_sbl, alignment;
48
49   struct _menu {
50     Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap;
51     Window window, frame, title;
52
53     char *label;
54     int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
55       grab_x, grab_y;
56     unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
57       bevel_h;
58   } menu;
59
60
61 protected:
62   inline BasemenuItem *find(int index) { return menuitems->find(index); }
63   inline void setTitleVisibility(Bool b) { title_vis = b; }
64   inline void setMovable(Bool b) { movable = b; }
65   inline void setHideTree(Bool h) { hide_tree = h; }
66   inline void setMinimumSublevels(int m) { menu.minsub = m; }
67
68   virtual void itemSelected(int, int) = 0;
69   virtual void drawItem(int, Bool = False, Bool = False,
70                         int = -1, int = -1, unsigned int = 0,
71                         unsigned int = 0);
72   virtual void redrawTitle();
73   virtual void internal_hide(void);
74
75
76 public:
77   Basemenu(BScreen &);
78   virtual ~Basemenu(void);
79
80   inline const Bool &isTorn(void) const { return torn; }
81   inline const Bool &isVisible(void) const { return visible; }
82
83   inline BScreen &getScreen(void) { return screen; }
84
85   inline const Window &getWindowID(void) const { return menu.window; }
86
87   inline const char *getLabel(void) const { return menu.label; }
88
89   int insert(const char *, int = 0, const char * = (const char *) 0, int = -1);
90   int insert(const char **, int = -1, int = 0);
91   int insert(const char *, Basemenu *, int = -1);
92   int remove(int);
93
94   inline const int &getX(void) const { return menu.x; }
95   inline const int &getY(void) const { return menu.y; }
96   inline int getCount(void) { return menuitems->count(); }
97   inline const int &getCurrentSubmenu(void) const { return which_sub; }
98
99   inline const unsigned int &getWidth(void) const { return menu.width; }
100   inline const unsigned int &getHeight(void) const { return menu.height; }
101   inline const unsigned int &getTitleHeight(void) const
102   { 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 };
135
136
137 class BasemenuItem {
138 private:
139   Basemenu *s;
140   const char **u, *l, *e;
141   int f, enabled, selected;
142
143   friend class Basemenu;
144
145 protected:
146
147 public:
148   BasemenuItem(const char *lp, int fp, const char *ep = (const char *) 0):
149     s(0), u(0), l(lp), e(ep), f(fp), enabled(1), selected(0) {}
150
151   BasemenuItem(const char *lp, Basemenu *mp): s(mp), u(0), l(lp), e(0), f(0),
152                                               enabled(1), selected(0) {}
153
154   BasemenuItem(const char **up, int fp): s(0), u(up), l(0), e(0), f(fp),
155                                          enabled(1), selected(0) {}
156
157   inline const char *exec(void) const { return e; }
158   inline const char *label(void) const { return l; }
159   inline const char **ulabel(void) const { return u; }
160   inline const int &function(void) const { return f; }
161   inline Basemenu *submenu(void) { return s; }
162
163   inline const int &isEnabled(void) const { return enabled; }
164   inline void setEnabled(int e) { enabled = e; }
165   inline const int &isSelected(void) const { return selected; }
166   inline void setSelected(int s) { selected = s; }
167 };
168
169
170 #endif // __Basemenu_hh