]> Dogcows Code - chaz/openbox/blob - otk/widget.hh
fix indenting
[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 "texture.hh"
8 #include "style.hh"
9 #include "eventdispatcher.hh"
10 #include "display.hh"
11
12 extern "C" {
13 #include <assert.h>
14 }
15
16 #include <string>
17 #include <list>
18
19 namespace otk {
20
21 class Widget : public EventHandler {
22
23 public:
24
25 enum Direction { Horizontal, Vertical };
26
27 typedef std::list<Widget *> WidgetList;
28
29 Widget(Widget *parent, Direction = Horizontal);
30 Widget(EventDispatcher *event_dispatcher, Style *style,
31 Direction direction = Horizontal, Cursor cursor = 0,
32 int bevel_width = 1, bool override_redirect = false);
33
34 virtual ~Widget();
35
36 virtual void update(void);
37
38 void exposeHandler(const XExposeEvent &e);
39 void configureHandler(const XConfigureEvent &e);
40
41 inline Window window(void) const { return _window; }
42 inline const Widget *parent(void) const { return _parent; }
43 inline const WidgetList &children(void) const { return _children; }
44 inline unsigned int screen(void) const { return _screen; }
45 inline const Rect &rect(void) const { return _rect; }
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 int width() const { return _rect.width(); }
54 virtual int height() const { return _rect.height(); }
55
56 virtual void resize(const Point &to);
57 virtual void resize(int x, int y);
58
59 virtual void setGeometry(const Rect &new_geom);
60 virtual void setGeometry(const Point &topleft, int width, int height);
61 virtual void setGeometry(int x, int y, int width, int height);
62
63 inline bool isVisible(void) const { return _visible; };
64 virtual void show(bool recursive = false);
65 virtual void hide(bool recursive = false);
66
67 inline bool isFocused(void) const { return _focused; };
68 virtual void focus(void);
69 virtual void unfocus(void);
70
71 inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
72 bool grabMouse(void);
73 void ungrabMouse(void);
74
75 inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
76 bool grabKeyboard(void);
77 void ungrabKeyboard(void);
78
79 inline Texture *texture(void) const { return _texture; }
80 virtual void setTexture(Texture *texture)
81 { _texture = texture; _dirty = true; }
82
83 inline const Color *borderColor(void) const { return _bcolor; }
84 virtual void setBorderColor(const Color *color) {
85 assert(color); _bcolor = color;
86 XSetWindowBorder(**display, _window, color->pixel());
87 }
88
89 inline int borderWidth(void) const { return _bwidth; }
90 void setBorderWidth(int width) {
91 _bwidth = width;
92 XSetWindowBorderWidth(**display, _window, width);
93 }
94
95 virtual void addChild(Widget *child, bool front = false);
96 virtual void removeChild(Widget *child);
97
98 inline bool isStretchableHorz(void) const { return _stretchable_horz; }
99 void setStretchableHorz(bool s_horz = true) { _stretchable_horz = s_horz; }
100
101 inline bool isStretchableVert(void) const { return _stretchable_vert; }
102 void setStretchableVert(bool s_vert = true) { _stretchable_vert = s_vert; }
103
104 inline Cursor cursor(void) const { return _cursor; }
105 void setCursor(Cursor cursor) {
106 _cursor = cursor;
107 XDefineCursor(**display, _window, _cursor);
108 }
109
110 inline int bevelWidth(void) const { return _bevel_width; }
111 void setBevelWidth(int bevel_width)
112 { assert(bevel_width > 0); _bevel_width = bevel_width; }
113
114 inline Direction direction(void) const { return _direction; }
115 void setDirection(Direction dir) { _direction = dir; }
116
117 inline Style *style(void) const { return _style; }
118 virtual void setStyle(Style *style);
119
120 inline EventDispatcher *eventDispatcher(void)
121 { return _event_dispatcher; }
122 void setEventDispatcher(EventDispatcher *disp);
123
124 protected:
125
126 bool _dirty;
127 bool _focused;
128
129 virtual void adjust(void);
130 virtual void create(bool override_redirect = false);
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 Widget *_parent;
139 WidgetList _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 Texture *_texture;
156 Pixmap _bg_pixmap;
157 unsigned int _bg_pixel;
158
159 const Color *_bcolor;
160 unsigned int _bwidth;
161
162 Rect _rect;
163 unsigned int _screen;
164
165 bool _fixed_width;
166 bool _fixed_height;
167
168 EventDispatcher *_event_dispatcher;
169 };
170
171 }
172
173 #endif // __widget_hh
This page took 0.044376 seconds and 4 git commands to generate.