]> Dogcows Code - chaz/openbox/blob - otk/widget.hh
33c6e99f98670cce38aadcd658649ded3f4fd0cb
[chaz/openbox] / 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 Rect rect(void) const { return Rect(_pos, size()); }
46
47 void move(const Point &to);
48 void move(int x, int y);
49
50 virtual void setWidth(int);
51 virtual void setHeight(int);
52
53 virtual void resize(const Point &to);
54 virtual void resize(int x, int y);
55
56 virtual void setGeometry(const Rect &new_geom);
57 virtual void setGeometry(const Point &topleft, int width, int height);
58 virtual void setGeometry(int x, int y, int width, int height);
59
60 inline bool isVisible(void) const { return _visible; };
61 virtual void show(bool recursive = false);
62 virtual void hide(bool recursive = false);
63
64 inline bool isFocused(void) const { return _focused; };
65 virtual void focus(void);
66 virtual void unfocus(void);
67
68 inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
69 bool grabMouse(void);
70 void ungrabMouse(void);
71
72 inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
73 bool grabKeyboard(void);
74 void ungrabKeyboard(void);
75
76 inline Texture *texture(void) const { return _texture; }
77 virtual void setTexture(Texture *texture)
78 { _texture = texture; _dirty = true; }
79
80 inline const Color *borderColor(void) const { return _bcolor; }
81 virtual void setBorderColor(const Color *color) {
82 assert(color); _bcolor = color;
83 XSetWindowBorder(**display, _window, color->pixel());
84 }
85
86 inline int borderWidth(void) const { return _bwidth; }
87 void setBorderWidth(int width) {
88 _bwidth = width;
89 XSetWindowBorderWidth(**display, _window, width);
90 }
91
92 virtual void addChild(Widget *child, bool front = false);
93 virtual void removeChild(Widget *child);
94
95 inline bool isStretchableHorz(void) const { return _stretchable_horz; }
96 void setStretchableHorz(bool s_horz = true) { _stretchable_horz = s_horz; }
97
98 inline bool isStretchableVert(void) const { return _stretchable_vert; }
99 void setStretchableVert(bool s_vert = true) { _stretchable_vert = s_vert; }
100
101 inline Cursor cursor(void) const { return _cursor; }
102 void setCursor(Cursor cursor) {
103 _cursor = cursor;
104 XDefineCursor(**display, _window, _cursor);
105 }
106
107 inline int bevelWidth(void) const { return _bevel_width; }
108 void setBevelWidth(int bevel_width)
109 { assert(bevel_width > 0); _bevel_width = bevel_width; }
110
111 inline Direction direction(void) const { return _direction; }
112 void setDirection(Direction dir) { _direction = dir; }
113
114 inline Style *style(void) const { return _style; }
115 virtual void setStyle(Style *style);
116
117 inline EventDispatcher *eventDispatcher(void)
118 { return _event_dispatcher; }
119 void setEventDispatcher(EventDispatcher *disp);
120
121 protected:
122
123 bool _dirty;
124 bool _focused;
125
126 virtual void adjust(void);
127 virtual void create(bool override_redirect = false);
128 virtual void adjustHorz(void);
129 virtual void adjustVert(void);
130 virtual void internalResize(int width, int height);
131 virtual void render(void);
132
133 Window _window;
134
135 Widget *_parent;
136 WidgetList _children;
137
138 Style *_style;
139 Direction _direction;
140 Cursor _cursor;
141 int _bevel_width;
142 int _ignore_config;
143
144 bool _visible;
145
146 bool _grabbed_mouse;
147 bool _grabbed_keyboard;
148
149 bool _stretchable_vert;
150 bool _stretchable_horz;
151
152 Texture *_texture;
153 Pixmap _bg_pixmap;
154 unsigned int _bg_pixel;
155
156 const Color *_bcolor;
157 unsigned int _bwidth;
158
159 Point _pos;
160 unsigned int _screen;
161
162 bool _fixed_width;
163 bool _fixed_height;
164
165 EventDispatcher *_event_dispatcher;
166 };
167
168 }
169
170 #endif // __widget_hh
This page took 0.045494 seconds and 4 git commands to generate.