4 #include "screeninfo.hh"
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())
14 parent->addChild(this);
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),
27 OtkWidget::~OtkWidget()
32 std::for_each(_children.begin(), _children.end(), PointerAssassin());
35 _parent->removeChild(this);
37 XDestroyWindow(otk::OBDisplay::display, _window);
40 void OtkWidget::create(void)
42 const ScreenInfo *scr_info = otk::OBDisplay::screenInfo(_screen);
43 Window p_window = _parent ? _parent->getWindow() : scr_info->getRootWindow();
46 _rect.setRect(10, 10, 20, 20);
48 XSetWindowAttributes attrib_create;
49 unsigned long create_mask = CWBackPixmap | CWBorderPixel | CWEventMask;
51 attrib_create.background_pixmap = None;
52 attrib_create.colormap = scr_info->getColormap();
53 attrib_create.event_mask = ButtonPressMask | ButtonReleaseMask |
54 ButtonMotionMask | ExposureMask;
57 create_mask |= CWCursor;
58 attrib_create.cursor = _cursor;
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);
67 void OtkWidget::move(const Point &to)
72 void OtkWidget::move(int x, int y)
75 XMoveWindow(otk::OBDisplay::display, _window, x, y);
78 void OtkWidget::resize(const Point &to)
80 resize(to.x(), to.y());
83 void OtkWidget::resize(int x, int y)
85 assert(x >= _rect.x() && y >= _rect.y());
87 _rect.setWidth(x - _rect.x());
88 _rect.setHeight(y - _rect.y());
91 void OtkWidget::setGeometry(const Rect &new_geom)
93 setGeometry(new_geom.x(), new_geom.y(), new_geom.height(), new_geom.width());
96 void OtkWidget::setGeometry(const Point &topleft, int width, int height)
98 setGeometry(topleft.x(), topleft.y(), width, height);
101 void OtkWidget::setGeometry(int x, int y, int width, int height)
103 _rect = Rect(x, y, width, height);
104 XMoveResizeWindow(otk::OBDisplay::display, _window, x, y, width, height);
107 void OtkWidget::show(void)
112 OtkWidgetList::iterator it = _children.begin(), end = _children.end();
113 for (; it != end; ++it)
116 XMapWindow(otk::OBDisplay::display, _window);
120 void OtkWidget::hide(void)
125 OtkWidgetList::iterator it = _children.begin(), end = _children.end();
126 for (; it != end; ++it)
129 XUnmapWindow(otk::OBDisplay::display, _window);
133 void OtkWidget::focus(void)
138 XSetInputFocus(otk::OBDisplay::display, _window, RevertToPointerRoot,
142 void OtkWidget::blur(void)
147 bool OtkWidget::grabMouse(void)
152 void OtkWidget::ungrabMouse(void)
157 bool OtkWidget::grabKeyboard(void)
162 void OtkWidget::ungrabKeyboard(void)
167 void OtkWidget::setTexture(BTexture *texture)
172 void OtkWidget::addChild(OtkWidget *child)
177 void OtkWidget::removeChild(OtkWidget *child)