]> icculus.org git repositories - mikachu/openbox.git/blob - otk/focuswidget.cc
initial commit of focus widget
[mikachu/openbox.git] / otk / focuswidget.cc
1 #include "focuswidget.hh"
2
3 namespace otk {
4
5 OtkFocusWidget::OtkFocusWidget(OtkWidget *parent, Direction direction)
6   : OtkWidget(parent, direction), _unfocus_texture(0), _focused(true)
7 {
8   _focus_texture = parent->getTexture();
9 }
10
11 OtkFocusWidget::OtkFocusWidget(Style *style, Direction direction,
12                                Cursor cursor, int bevel_width)
13   : OtkWidget(style, direction, cursor, bevel_width),
14     _unfocus_texture(0), _focused(true)
15 {
16 }
17
18 void OtkFocusWidget::focus(void)
19 {
20   if (_focused)
21     return;
22
23   assert(_focus_texture);
24   OtkWidget::setTexture(_focus_texture);
25   OtkWidget::update();
26
27   OtkWidget::OtkWidgetList children = OtkWidget::getChildren();
28
29   OtkWidget::OtkWidgetList::iterator it = children.begin(),
30     end = children.end();
31
32   OtkFocusWidget *tmp = 0;
33   for (; it != end; ++it) {
34     tmp = dynamic_cast<OtkFocusWidget*>(*it);
35     if (tmp) tmp->focus();
36   }
37 }
38
39 void OtkFocusWidget::unfocus(void)
40 {
41   if (! _focused)
42     return;
43
44   assert(_unfocus_texture);
45   OtkWidget::setTexture(_unfocus_texture);
46   OtkWidget::update();
47
48   OtkWidget::OtkWidgetList children = OtkWidget::getChildren();
49
50   OtkWidget::OtkWidgetList::iterator it = children.begin(),
51     end = children.end();
52
53   OtkFocusWidget *tmp = 0;
54   for (; it != end; ++it) {
55     tmp = dynamic_cast<OtkFocusWidget*>(*it);
56     if (tmp) tmp->unfocus();
57   }
58 }
59
60 void OtkFocusWidget::setTexture(BTexture *texture)
61 {
62   OtkWidget::setTexture(texture);
63   _focus_texture = texture;
64 }
65
66 }