]> Dogcows Code - chaz/openbox/blob - otk/widget.hh
add an adjustable event mask
[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();
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 long eventMask(void) const { return _event_mask; }
122 void setEventMask(long e);
123
124 inline EventDispatcher *eventDispatcher(void)
125 { return _event_dispatcher; }
126 void setEventDispatcher(EventDispatcher *disp);
127
128 protected:
129
130 bool _dirty;
131 bool _focused;
132
133 virtual void adjust(void);
134 virtual void create(bool override_redirect = false);
135 virtual void adjustHorz(void);
136 virtual void adjustVert(void);
137 virtual void internalResize(int width, int height);
138 virtual void render(void);
139 virtual void renderForeground() {} // for overriding
140
141 Window _window;
142
143 Widget *_parent;
144 WidgetList _children;
145
146 RenderStyle *_style;
147 Direction _direction;
148 Cursor _cursor;
149 int _bevel_width;
150 int _ignore_config;
151
152 bool _visible;
153
154 bool _grabbed_mouse;
155 bool _grabbed_keyboard;
156
157 bool _stretchable_vert;
158 bool _stretchable_horz;
159
160 RenderTexture *_texture;
161 Pixmap _bg_pixmap;
162 unsigned int _bg_pixel;
163
164 const RenderColor *_bcolor;
165 unsigned int _bwidth;
166
167 Rect _rect;
168 unsigned int _screen;
169
170 bool _fixed_width;
171 bool _fixed_height;
172
173 long _event_mask;
174
175 Surface *_surface;
176
177 EventDispatcher *_event_dispatcher;
178 };
179
180 }
181
182 #endif // __widget_hh
This page took 0.043738 seconds and 5 git commands to generate.