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