]> icculus.org git repositories - mikachu/openbox.git/blob - src/Basemenu.hh
merging in netwm changes at merge point "netwm-merge1". This add the XAtom class...
[mikachu/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 <deque>
33
34 class Blackbox;
35 class BImageControl;
36 class BScreen;
37 class Basemenu;
38 class BasemenuItem;
39
40
41 class Basemenu {
42 private:
43   typedef std::deque<BasemenuItem*> MenuItems;
44   MenuItems menuitems;
45   Blackbox *blackbox;
46   Basemenu *parent;
47   BImageControl *image_ctrl;
48   BScreen *screen;
49
50   bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
51     hide_tree;
52   Display *display;
53   int which_sub, which_press, which_sbl, alignment;
54
55   struct _menu {
56     Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap;
57     Window window, frame, title;
58
59     std::string label;
60     int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
61       grab_x, grab_y;
62     unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
63       bevel_h;
64   } menu;
65
66   Basemenu(const Basemenu&);
67   Basemenu& operator=(const Basemenu&);
68
69 protected:
70   BasemenuItem *find(int index);
71   inline void setTitleVisibility(bool b) { title_vis = b; }
72   inline void setMovable(bool b) { movable = b; }
73   inline void setHideTree(bool h) { hide_tree = h; }
74   inline void setMinimumSublevels(int m) { menu.minsub = m; }
75
76   virtual void itemSelected(int button, unsigned int index) = 0;
77   virtual void drawItem(int index, bool highlight = False, bool clear = False,
78                         int x = -1, int y = -1,
79                         unsigned int w = 0, unsigned int h = 0);
80   virtual void redrawTitle(void);
81   virtual void internal_hide(void);
82
83
84 public:
85   Basemenu(BScreen *scrn);
86   virtual ~Basemenu(void);
87
88   inline bool isTorn(void) const { return torn; }
89   inline bool isVisible(void) const { return visible; }
90
91   inline BScreen *getScreen(void) { return screen; }
92
93   inline Window getWindowID(void) const { return menu.window; }
94
95   inline const char *getLabel(void) const { return menu.label.c_str(); }
96
97   int insert(BasemenuItem *item, int pos);
98   int insert(const std::string& label, int function = 0,
99              const std::string& exec = "", int pos = -1);
100   int insert(const std::string &label, Basemenu *submenu, int pos = -1);
101   int remove(int index);
102
103   void changeItemLabel(unsigned int index, const std::string& label);
104
105   inline int getX(void) const { return menu.x; }
106   inline int getY(void) const { return menu.y; }
107   inline unsigned int getCount(void) { return menuitems.size(); }
108   inline int getCurrentSubmenu(void) const { return which_sub; }
109
110   inline unsigned int getWidth(void) const { return menu.width; }
111   inline unsigned int getHeight(void) const { return menu.height; }
112   inline unsigned int getTitleHeight(void) const
113   { return menu.title_h; }
114
115   inline void setInternalMenu(void) { internal_menu = True; }
116   inline void setAlignment(int a) { alignment = a; }
117   inline void setTorn(void) { torn = True; }
118   inline void removeParent(void)
119   { if (internal_menu) parent = (Basemenu *) 0; }
120
121   bool hasSubmenu(int index);
122   bool isItemSelected(int index);
123   bool isItemEnabled(int index);
124
125   void buttonPressEvent(XButtonEvent *be);
126   void buttonReleaseEvent(XButtonEvent *be);
127   void motionNotifyEvent(XMotionEvent *me);
128   void enterNotifyEvent(XCrossingEvent *ce);
129   void leaveNotifyEvent(XCrossingEvent *ce);
130   void exposeEvent(XExposeEvent *ee);
131   void reconfigure(void);
132   void setLabel(const std::string& label);
133   void move(int x, int y);
134   void update(void);
135   void setItemSelected(int index, bool sel);
136   void setItemEnabled(int index, bool enable);
137
138   virtual void drawSubmenu(int index);
139   virtual void show(void);
140   virtual void hide(void);
141
142   enum { AlignDontCare = 1, AlignTop, AlignBottom };
143   enum { Right = 1, Left };
144   enum { Empty = 0, Square, Triangle, Diamond };
145 };
146
147
148 class BasemenuItem {
149 private:
150   Basemenu *sub;
151   std::string l, e;
152   int f, enabled, selected;
153
154   friend class Basemenu;
155
156 protected:
157
158 public:
159   BasemenuItem(const std::string& lp, int fp = 0, const std::string& ep = ""):
160     sub(0), l(lp), e(ep), f(fp), enabled(1), selected(0) {}
161
162   BasemenuItem(const std::string& lp, Basemenu *mp): sub(mp), l(lp),
163                                                      f(0), enabled(1),
164                                                      selected(0) {}
165
166   ~BasemenuItem(void);
167
168   inline const char *exec(void) const { return e.c_str(); }
169   inline const char *label(void) const { return l.c_str(); }
170   inline int function(void) const { return f; }
171   inline Basemenu *submenu(void) { return sub; }
172
173   inline void newLabel(const std::string& label) { l = label; }
174
175   inline int isEnabled(void) const { return enabled; }
176   inline void setEnabled(int e) { enabled = e; }
177   inline int isSelected(void) const { return selected; }
178   inline void setSelected(int s) { selected = s; }
179 };
180
181
182 #endif // __Basemenu_hh