]> icculus.org git repositories - mikachu/openbox.git/blob - otk/widget.hh
add new shit
[mikachu/openbox.git] / otk / widget.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __widget_hh
3 #define __widget_hh
4
5 #include "surface.hh"
6 #include "rect.hh"
7 #include "point.hh"
8 #include "texture.hh"
9 #include "style.hh"
10 #include "eventdispatcher.hh"
11 #include "display.hh"
12
13 extern "C" {
14 #include <assert.h>
15 }
16
17 #include <string>
18 #include <list>
19
20 namespace otk {
21
22 class Widget : public Surface, public EventHandler {
23
24 public:
25
26   enum Direction { Horizontal, Vertical };
27
28   typedef std::list<Widget *> WidgetList;
29
30   Widget(Widget *parent, Direction = Horizontal);
31   Widget(EventDispatcher *event_dispatcher, Style *style,
32          Direction direction = Horizontal, Cursor cursor = 0,
33          int bevel_width = 1, bool override_redirect = false);
34
35   virtual ~Widget();
36
37   virtual void update(void);
38
39   void exposeHandler(const XExposeEvent &e);
40   void configureHandler(const XConfigureEvent &e);
41
42   inline Window window(void) const { return _window; }
43   inline const Widget *parent(void) const { return _parent; }
44   inline const WidgetList &children(void) const { return _children; }
45   inline unsigned int screen(void) const { return _screen; }
46   inline Rect rect(void) const { return Rect(_pos, size()); }
47
48   void move(const Point &to);
49   void move(int x, int y);
50
51   virtual void setWidth(int);
52   virtual void setHeight(int);
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 Texture *texture(void) const { return _texture; }
78   virtual void setTexture(Texture *texture)
79     { _texture = texture; _dirty = true; }
80
81   inline const Color *borderColor(void) const { return _bcolor; }
82   virtual void setBorderColor(const Color *color) {
83     assert(color); _bcolor = color;
84     XSetWindowBorder(**display, _window, color->pixel());
85   }
86
87   inline int borderWidth(void) const { return _bwidth; }
88   void setBorderWidth(int width) {
89     _bwidth = width;
90     XSetWindowBorderWidth(**display, _window, width);
91   }
92
93   virtual void addChild(Widget *child, bool front = false);
94   virtual void removeChild(Widget *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 cursor(void) const { return _cursor; }
103   void setCursor(Cursor cursor) {
104     _cursor = cursor;
105     XDefineCursor(**display, _window, _cursor);
106   }
107
108   inline int bevelWidth(void) const { return _bevel_width; }
109   void setBevelWidth(int bevel_width)
110     { assert(bevel_width > 0); _bevel_width = bevel_width; }
111
112   inline Direction direction(void) const { return _direction; }
113   void setDirection(Direction dir) { _direction = dir; }
114
115   inline Style *style(void) const { return _style; }
116   virtual void setStyle(Style *style);
117
118   inline EventDispatcher *eventDispatcher(void)
119     { return _event_dispatcher; }
120   void setEventDispatcher(EventDispatcher *disp);
121
122 protected:
123   
124   bool _dirty;
125   bool _focused;
126
127   virtual void adjust(void);
128   virtual void create(bool override_redirect = false);
129   virtual void adjustHorz(void);
130   virtual void adjustVert(void);
131   virtual void internalResize(int width, int height);
132   virtual void render(void);
133
134   Window _window;
135
136   Widget *_parent;
137   WidgetList _children;
138
139   Style *_style;
140   Direction _direction;
141   Cursor _cursor;
142   int _bevel_width;
143   int _ignore_config;
144
145   bool _visible;
146
147   bool _grabbed_mouse;
148   bool _grabbed_keyboard;
149
150   bool _stretchable_vert;
151   bool _stretchable_horz;
152
153   Texture *_texture;
154   Pixmap _bg_pixmap;
155   unsigned int _bg_pixel;
156
157   const Color *_bcolor;
158   unsigned int _bwidth;
159
160   Point _pos;
161   unsigned int _screen;
162
163   bool _fixed_width;
164   bool _fixed_height;
165
166   EventDispatcher *_event_dispatcher;
167 };
168
169 }
170
171 #endif // __widget_hh