]> icculus.org git repositories - mikachu/openbox.git/blob - otk/basewidget.hh
move event handling into basewidget again <FLINCH>
[mikachu/openbox.git] / otk / basewidget.hh
1 #ifndef __basewidget_hh
2 #define __basewidget_hh
3
4 #include "rect.hh"
5 #include "point.hh"
6 #include "texture.hh"
7 #include "style.hh"
8 #include "display.hh"
9 #include "eventdispatcher.hh"
10
11 extern "C" {
12 #include <assert.h>
13 }
14
15 #include <list>
16
17 namespace otk {
18
19 class OtkBaseWidget : public OtkEventHandler {
20
21 public:
22
23   typedef std::list<OtkBaseWidget *> OtkBaseWidgetList;
24
25   OtkBaseWidget(OtkBaseWidget *parent);
26   OtkBaseWidget(Style *style, Cursor cursor = 0, int bevel_width = 1);
27
28   virtual ~OtkBaseWidget();
29
30   //! Redraw the widget and all of its children
31   virtual void update(void);
32
33   void exposeHandler(const XExposeEvent &e);
34   void configureHandler(const XConfigureEvent &e);
35
36   inline Window getWindow(void) const { return _window; }
37   inline const OtkBaseWidget *getParent(void) const { return _parent; }
38   inline const OtkBaseWidgetList &getChildren(void) const { return _children; }
39   inline unsigned int getScreen(void) const { return _screen; }
40   inline const Rect &getRect(void) const { return _rect; }
41
42   void move(const Point &to);
43   void move(int x, int y);
44
45   virtual void setWidth(int);
46   virtual void setHeight(int);
47
48   virtual int width() const { return _rect.width(); }
49   virtual int height() const { return _rect.height(); }
50
51   virtual void resize(const Point &to);
52   virtual void resize(int x, int y);
53
54   virtual void setGeometry(const Rect &new_geom);
55   virtual void setGeometry(const Point &topleft, int width, int height);
56   virtual void setGeometry(int x, int y, int width, int height);
57
58   inline bool isVisible(void) const { return _visible; };
59   virtual void show(bool recursive = false);
60   virtual void hide(bool recursive = false);
61
62   inline bool isFocused(void) const { return _focused; };
63   virtual void focus(void);
64
65   inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
66   bool grabMouse(void);
67   void ungrabMouse(void);
68
69   inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
70   bool grabKeyboard(void);
71   void ungrabKeyboard(void);
72
73   inline BTexture *getTexture(void) const { return _texture; }
74   virtual void setTexture(BTexture *texture)
75   { _texture = texture; _dirty = true; }
76
77   virtual void addChild(OtkBaseWidget *child, bool front = false);
78   virtual void removeChild(OtkBaseWidget *child);
79
80   inline Cursor getCursor(void) const { return _cursor; }
81   void setCursor(Cursor cursor) {
82     _cursor = cursor;
83     XDefineCursor(OBDisplay::display, _window, _cursor);
84   }
85
86   inline int getBevelWidth(void) const { return _bevel_width; }
87   void setBevelWidth(int bevel_width)
88   { assert(bevel_width > 0); _bevel_width = bevel_width; }
89
90   inline Style *getStyle(void) const { return _style; }
91   virtual void setStyle(Style *style);
92
93 protected:
94
95   //! If the widget needs to redraw itself. Watched by all subclasses too!
96   bool _dirty;
97
98   Window _window;
99
100   OtkBaseWidget *_parent;
101   OtkBaseWidgetList _children;
102
103   Style *_style;
104   Cursor _cursor;
105   int _bevel_width;
106   int _ignore_config;
107
108   bool _visible;
109   bool _focused;
110
111   bool _grabbed_mouse;
112   bool _grabbed_keyboard;
113
114   BTexture *_texture;
115   Pixmap _bg_pixmap;
116   unsigned int _bg_pixel;
117
118   Rect _rect;
119   unsigned int _screen;
120
121 private:
122
123   void create(void);
124   void render(void);
125 };
126
127 }
128
129 #endif // __basewidget_hh