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