]> icculus.org git repositories - mikachu/openbox.git/blob - src/Basemenu.h
new nls from bb-cvs
[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 <vector>
34 typedef std::vector<BasemenuItem *> menuitemList;
35
36 class Basemenu {
37 private:
38   menuitemList 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[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 int getX(void) const { return menu.x; }
95   inline int getY(void) const { return menu.y; }
96   inline unsigned int getCount(void) { return menuitems.size(); }
97   inline int getCurrentSubmenu(void) const { return which_sub; }
98
99   inline unsigned int getWidth(void) const { return menu.width; }
100   inline unsigned int getHeight(void) const { return menu.height; }
101   inline unsigned int getTitleHeight(void) const { return menu.title_h; }
102
103   inline void setInternalMenu(void) { internal_menu = True; }
104   inline void setAlignment(int a) { alignment = a; }
105   inline void setTorn(void) { torn = True; }
106   inline void removeParent(void)
107     { if (internal_menu) parent = (Basemenu *) 0; }
108
109   bool hasSubmenu(int);
110   bool isItemSelected(int);
111   bool isItemEnabled(int);
112
113   void buttonPressEvent(XButtonEvent *);
114   void buttonReleaseEvent(XButtonEvent *);
115   void motionNotifyEvent(XMotionEvent *);
116   void enterNotifyEvent(XCrossingEvent *);
117   void leaveNotifyEvent(XCrossingEvent *);
118   void exposeEvent(XExposeEvent *);
119   void reconfigure(void);
120   void setLabel(const char *n);
121   void move(int, int);
122   void update(void);
123   void setItemSelected(int, bool);
124   void setItemEnabled(int, bool);
125
126   virtual void drawSubmenu(int);
127   virtual void show(void);
128   virtual void hide(void);
129
130   enum { AlignDontCare = 1, AlignTop, AlignBottom };
131   enum { Right = 1, Left };
132   enum { Empty = 0, Square, Triangle, Diamond };
133 };
134
135
136 class BasemenuItem {
137 private:
138   Basemenu *s;
139   const char **u, *l, *e;
140   int f, enabled, selected;
141
142   friend class Basemenu;
143
144 protected:
145
146 public:
147   BasemenuItem(const char *lp, int fp, const char *ep = (const char *) 0):
148     s(0), u(0), l(lp), e(ep), f(fp), enabled(1), selected(0) {}
149
150   BasemenuItem(const char *lp, Basemenu *mp): s(mp), u(0), l(lp), e(0), f(0),
151                                               enabled(1), selected(0) {}
152
153   BasemenuItem(const char **up, int fp): s(0), u(up), l(0), e(0), f(fp),
154                                          enabled(1), selected(0) {}
155
156   inline const char *exec(void) const { return e; }
157   inline const char *label(void) const { return l; }
158   inline const char **ulabel(void) const { return u; }
159   inline const int &function(void) const { return f; }
160   inline Basemenu *submenu(void) { return s; }
161
162   inline const int &isEnabled(void) const { return enabled; }
163   inline void setEnabled(int e) { enabled = e; }
164   inline const int &isSelected(void) const { return selected; }
165   inline void setSelected(int s) { selected = s; }
166 };
167
168
169 #endif // __Basemenu_hh