]> icculus.org git repositories - mikachu/openbox.git/blob - otk/widget.hh
make setStyle() recursive
[mikachu/openbox.git] / otk / widget.hh
1 #ifndef __widget_hh
2 #define __widget_hh
3
4 #include "rect.hh"
5 #include "point.hh"
6 #include "texture.hh"
7 #include "style.hh"
8 #include "eventdispatcher.hh"
9 #include "application.hh"
10
11 extern "C" {
12 #include <assert.h>
13 }
14
15 #include <string>
16 #include <list>
17
18 namespace otk {
19
20 class OtkWidget : public OtkEventHandler {
21
22 public:
23
24   enum Direction { Horizontal, Vertical };
25
26   typedef std::list<OtkWidget *> OtkWidgetList;
27
28   OtkWidget(OtkWidget *parent, Direction = Horizontal);
29   OtkWidget(OtkEventDispatcher *event_dispatcher, Style *style,
30             Direction direction = Horizontal, Cursor cursor = 0,
31             int bevel_width = 1);
32
33   virtual ~OtkWidget();
34
35   virtual void update(void);
36
37   void exposeHandler(const XExposeEvent &e);
38   void configureHandler(const XConfigureEvent &e);
39
40   inline Window getWindow(void) const { return _window; }
41   inline const OtkWidget *getParent(void) const { return _parent; }
42   inline const OtkWidgetList &getChildren(void) const { return _children; }
43   inline unsigned int getScreen(void) const { return _screen; }
44   inline const Rect &getRect(void) const { return _rect; }
45
46   void move(const Point &to);
47   void move(int x, int y);
48
49   virtual void setWidth(int);
50   virtual void setHeight(int);
51
52   virtual int width() const { return _rect.width(); }
53   virtual int height() const { return _rect.height(); }
54
55   virtual void resize(const Point &to);
56   virtual void resize(int x, int y);
57
58   virtual void setGeometry(const Rect &new_geom);
59   virtual void setGeometry(const Point &topleft, int width, int height);
60   virtual void setGeometry(int x, int y, int width, int height);
61
62   inline bool isVisible(void) const { return _visible; };
63   virtual void show(bool recursive = false);
64   virtual void hide(bool recursive = false);
65
66   inline bool isFocused(void) const { return _focused; };
67   virtual void focus(void);
68
69   inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
70   bool grabMouse(void);
71   void ungrabMouse(void);
72
73   inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
74   bool grabKeyboard(void);
75   void ungrabKeyboard(void);
76
77   inline BTexture *getTexture(void) const { return _texture; }
78   virtual void setTexture(BTexture *texture)
79   { _texture = texture; _dirty = true; }
80
81   virtual void addChild(OtkWidget *child, bool front = false);
82   virtual void removeChild(OtkWidget *child);
83
84   inline bool isStretchableHorz(void) const { return _stretchable_horz; }
85   void setStretchableHorz(bool s_horz = true) { _stretchable_horz = s_horz; }
86
87   inline bool isStretchableVert(void) const { return _stretchable_vert; }
88   void setStretchableVert(bool s_vert = true)  { _stretchable_vert = s_vert; }
89
90   inline Cursor getCursor(void) const { return _cursor; }
91   void setCursor(Cursor cursor) {
92     _cursor = cursor;
93     XDefineCursor(OBDisplay::display, _window, _cursor);
94   }
95
96   inline int getBevelWidth(void) const { return _bevel_width; }
97   void setBevelWidth(int bevel_width)
98   { assert(bevel_width > 0); _bevel_width = bevel_width; }
99
100   inline Direction getDirection(void) const { return _direction; }
101   void setDirection(Direction dir) { _direction = dir; }
102
103   inline Style *getStyle(void) const { return _style; }
104   virtual void setStyle(Style *style);
105
106   inline OtkEventDispatcher *getEventDispatcher(void)
107   { return _event_dispatcher; }
108   void setEventDispatcher(OtkEventDispatcher *disp);
109
110   void unmanaged(void) { _unmanaged = true; }
111
112 protected:
113   
114   bool _dirty;
115
116 private:
117
118   void create(void);
119   void adjust(void);
120   void adjustHorz(void);
121   void adjustVert(void);
122   void internalResize(int width, int height);
123   void render(void);
124
125   Window _window;
126
127   OtkWidget *_parent;
128   OtkWidgetList _children;
129
130   Style *_style;
131   Direction _direction;
132   Cursor _cursor;
133   int _bevel_width;
134   int _ignore_config;
135
136   bool _visible;
137   bool _focused;
138
139   bool _grabbed_mouse;
140   bool _grabbed_keyboard;
141
142   bool _stretchable_vert;
143   bool _stretchable_horz;
144
145   BTexture *_texture;
146   Pixmap _bg_pixmap;
147   unsigned int _bg_pixel;
148
149   Rect _rect;
150   unsigned int _screen;
151
152   bool _fixed_width;
153   bool _fixed_height;
154
155   bool _unmanaged;
156
157   OtkEventDispatcher *_event_dispatcher;
158   OtkApplication *_application;
159 };
160
161 }
162
163 #endif // __widget_hh