]> Dogcows Code - chaz/openbox/blob - otk/widget.cc
initial commit
[chaz/openbox] / otk / widget.cc
1 #include "widget.hh"
2 #include "display.hh"
3 #include "assassin.hh"
4 #include "screeninfo.hh"
5
6 namespace otk {
7
8 OtkWidget::OtkWidget(OtkWidget *parent)
9 : _parent(parent), _visible(false), _focused(false), _grabbed_mouse(false),
10 _grabbed_keyboard(false), _stretchable_vert(false),
11 _stretchable_horz(false), _texture(NULL), _screen(parent->getScreen()),
12 _cursor(parent->getCursor())
13 {
14 parent->addChild(this);
15 create();
16 }
17
18 OtkWidget::OtkWidget(unsigned int screen, Cursor cursor = 0)
19 : _parent(NULL), _visible(false), _focused(false), _grabbed_mouse(false),
20 _grabbed_keyboard(false), _stretchable_vert(false),
21 _stretchable_horz(false), _texture(NULL), _screen(screen),
22 _cursor(cursor)
23 {
24 create();
25 }
26
27 OtkWidget::~OtkWidget()
28 {
29 if (_visible)
30 hide();
31
32 std::for_each(_children.begin(), _children.end(), PointerAssassin());
33
34 if (_parent)
35 _parent->removeChild(this);
36
37 XDestroyWindow(otk::OBDisplay::display, _window);
38 }
39
40 void OtkWidget::create(void)
41 {
42 const ScreenInfo *scr_info = otk::OBDisplay::screenInfo(_screen);
43 Window p_window = _parent ? _parent->getWindow() : scr_info->getRootWindow();
44
45
46 _rect.setRect(10, 10, 20, 20);
47
48 XSetWindowAttributes attrib_create;
49 unsigned long create_mask = CWBackPixmap | CWBorderPixel | CWEventMask;
50
51 attrib_create.background_pixmap = None;
52 attrib_create.colormap = scr_info->getColormap();
53 attrib_create.event_mask = ButtonPressMask | ButtonReleaseMask |
54 ButtonMotionMask | ExposureMask;
55
56 if (_cursor) {
57 create_mask |= CWCursor;
58 attrib_create.cursor = _cursor;
59 }
60
61 _window = XCreateWindow(otk::OBDisplay::display, p_window, _rect.x(),
62 _rect.y(), _rect.width(), _rect.height(), 0,
63 scr_info->getDepth(), InputOutput,
64 scr_info->getVisual(), create_mask, &attrib_create);
65 }
66
67 void OtkWidget::move(const Point &to)
68 {
69 move(to.x(), to.y());
70 }
71
72 void OtkWidget::move(int x, int y)
73 {
74 _rect.setPos(x, y);
75 XMoveWindow(otk::OBDisplay::display, _window, x, y);
76 }
77
78 void OtkWidget::resize(const Point &to)
79 {
80 resize(to.x(), to.y());
81 }
82
83 void OtkWidget::resize(int x, int y)
84 {
85 assert(x >= _rect.x() && y >= _rect.y());
86
87 _rect.setWidth(x - _rect.x());
88 _rect.setHeight(y - _rect.y());
89 }
90
91 void OtkWidget::setGeometry(const Rect &new_geom)
92 {
93 setGeometry(new_geom.x(), new_geom.y(), new_geom.height(), new_geom.width());
94 }
95
96 void OtkWidget::setGeometry(const Point &topleft, int width, int height)
97 {
98 setGeometry(topleft.x(), topleft.y(), width, height);
99 }
100
101 void OtkWidget::setGeometry(int x, int y, int width, int height)
102 {
103 _rect = Rect(x, y, width, height);
104 XMoveResizeWindow(otk::OBDisplay::display, _window, x, y, width, height);
105 }
106
107 void OtkWidget::show(void)
108 {
109 if (_visible)
110 return;
111
112 OtkWidgetList::iterator it = _children.begin(), end = _children.end();
113 for (; it != end; ++it)
114 (*it)->show();
115
116 XMapWindow(otk::OBDisplay::display, _window);
117 _visible = true;
118 }
119
120 void OtkWidget::hide(void)
121 {
122 if (! _visible)
123 return;
124
125 OtkWidgetList::iterator it = _children.begin(), end = _children.end();
126 for (; it != end; ++it)
127 (*it)->hide();
128
129 XUnmapWindow(otk::OBDisplay::display, _window);
130 _visible = false;
131 }
132
133 void OtkWidget::focus(void)
134 {
135 if (! _visible)
136 return;
137
138 XSetInputFocus(otk::OBDisplay::display, _window, RevertToPointerRoot,
139 CurrentTime);
140 }
141
142 void OtkWidget::blur(void)
143 {
144 // ?
145 }
146
147 bool OtkWidget::grabMouse(void)
148 {
149 return true;
150 }
151
152 void OtkWidget::ungrabMouse(void)
153 {
154
155 }
156
157 bool OtkWidget::grabKeyboard(void)
158 {
159 return true;
160 }
161
162 void OtkWidget::ungrabKeyboard(void)
163 {
164
165 }
166
167 void OtkWidget::setTexture(BTexture *texture)
168 {
169 texture = texture;
170 }
171
172 void OtkWidget::addChild(OtkWidget *child)
173 {
174 child = child;
175 }
176
177 void OtkWidget::removeChild(OtkWidget *child)
178 {
179 child = child;
180 }
181
182 }
This page took 0.050953 seconds and 5 git commands to generate.