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