]> icculus.org git repositories - dana/openbox.git/blob - src/Basemenu.hh
bindable/disableable root/workspace menus
[dana/openbox.git] / src / Basemenu.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // Basemenu.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifndef   __Basemenu_hh
25 #define   __Basemenu_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29 }
30
31 #include <string>
32 #include <vector>
33
34 class Blackbox;
35 class BImageControl;
36 class BScreen;
37 class BasemenuItem;
38
39
40 class Basemenu {
41 private:
42   typedef std::vector<BasemenuItem*> MenuItems;
43   MenuItems menuitems;
44   Blackbox *blackbox;
45   Basemenu *parent;
46   BImageControl *image_ctrl;
47   BScreen *screen;
48
49   bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
50     hide_tree;
51   Display *display;
52   int which_sub, which_press, which_sbl, alignment;
53
54   struct _menu {
55     Pixmap frame_pixmap, title_pixmap, hilite_pixmap;
56     Window window, frame, title;
57
58     std::string label;
59     int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub;
60     unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
61       bevel_h;
62   } menu;
63
64   Basemenu(const Basemenu&);
65   Basemenu& operator=(const Basemenu&);
66
67 protected:
68   inline void setTitleVisibility(bool b) { title_vis = b; }
69   inline void setMovable(bool b) { movable = b; }
70   inline void setHideTree(bool h) { hide_tree = h; }
71   inline void setMinimumSublevels(int m) { menu.minsub = m; }
72
73   virtual void itemSelected(int button, unsigned int index) = 0;
74   virtual void drawItem(int index, bool highlight = False, bool clear = False,
75                         int x = -1, int y = -1,
76                         unsigned int w = 0, unsigned int h = 0);
77   virtual void redrawTitle(void);
78   virtual void internal_hide(void);
79
80
81 public:
82   Basemenu(BScreen *scrn);
83   virtual ~Basemenu(void);
84
85   inline bool isTorn(void) const { return torn; }
86   inline bool isVisible(void) const { return visible; }
87
88   inline BScreen *getScreen(void) { return screen; }
89
90   inline Window getWindowID(void) const { return menu.window; }
91
92   inline const char *getLabel(void) const { return menu.label.c_str(); }
93
94   int insert(BasemenuItem *item, int pos);
95   int insert(const std::string& label, int function = 0,
96              const std::string& exec = "", int pos = -1);
97   int insert(const std::string &label, Basemenu *submenu, int pos = -1);
98   int remove(int index);
99
100   void changeItemLabel(unsigned int index, const std::string& label);
101
102   inline int getX(void) const { return menu.x; }
103   inline int getY(void) const { return menu.y; }
104   inline unsigned int getCount(void) { return menuitems.size(); }
105   inline int getCurrentSubmenu(void) const { return which_sub; }
106   BasemenuItem *find(int index);
107
108   inline unsigned int getWidth(void) const { return menu.width; }
109   inline unsigned int getHeight(void) const { return menu.height; }
110   inline unsigned int getTitleHeight(void) const
111   { return menu.title_h; }
112
113   inline void setInternalMenu(void) { internal_menu = True; }
114   inline void setAlignment(int a) { alignment = a; }
115   inline void setTorn(void) { torn = True; }
116   inline void removeParent(void)
117   { if (internal_menu) parent = (Basemenu *) 0; }
118
119   bool hasSubmenu(int index);
120   bool isItemSelected(int index);
121   bool isItemEnabled(int index);
122
123   void buttonPressEvent(XButtonEvent *be);
124   void buttonReleaseEvent(XButtonEvent *be);
125   void motionNotifyEvent(XMotionEvent *me);
126   void enterNotifyEvent(XCrossingEvent *ce);
127   void leaveNotifyEvent(XCrossingEvent *ce);
128   void exposeEvent(XExposeEvent *ee);
129   void reconfigure(void);
130   void setLabel(const std::string& label);
131   void move(int x, int y);
132   void update(void);
133   void setItemSelected(int index, bool sel);
134   void setItemEnabled(int index, bool enable);
135
136   virtual void drawSubmenu(int index);
137   virtual void show(void);
138   virtual void hide(void);
139
140   enum { AlignDontCare = 1, AlignTop, AlignBottom };
141   enum { Right = 1, Left };
142   enum { Empty = 0, Square, Triangle, Diamond };
143 };
144
145
146 class BasemenuItem {
147 private:
148   Basemenu *sub;
149   std::string l, e;
150   int f, enabled, selected;
151
152   friend class Basemenu;
153
154 protected:
155
156 public:
157   BasemenuItem(const std::string& lp, int fp = 0, const std::string& ep = ""):
158     sub(0), l(lp), e(ep), f(fp), enabled(1), selected(0) {}
159
160   BasemenuItem(const std::string& lp, Basemenu *mp): sub(mp), l(lp),
161                                                      f(0), enabled(1),
162                                                      selected(0) {}
163
164   inline const char *exec(void) const { return e.c_str(); }
165   inline const char *label(void) const { return l.c_str(); }
166   inline int function(void) const { return f; }
167   inline Basemenu *submenu(void) { return sub; }
168
169   inline void newLabel(const std::string& label) { l = label; }
170
171   inline int isEnabled(void) const { return enabled; }
172   inline void setEnabled(int e) { enabled = e; }
173   inline int isSelected(void) const { return selected; }
174   inline void setSelected(int s) { selected = s; }
175 };
176
177
178 #endif // __Basemenu_hh