split up widget and basewidget
[mikachu/openbox.git] / otk / focuswidget.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "focuswidget.hh"
8
9 namespace otk {
10
11 OtkFocusWidget::OtkFocusWidget(OtkWidget *parent, Direction direction)
12   : OtkWidget(parent, direction), _unfocus_texture(0), _focused(true)
13 {
14   _focus_texture = parent->getTexture();
15 }
16
17 OtkFocusWidget::~OtkFocusWidget()
18 {
19 }
20
21 void OtkFocusWidget::focus(void)
22 {
23   if (_focused)
24     return;
25
26   // XXX: what about OtkWidget::focus()
27
28   assert(_focus_texture);
29   OtkWidget::setTexture(_focus_texture);
30   OtkWidget::update();
31
32   OtkBaseWidgetList::iterator it = _children.begin(), end = _children.end();
33   OtkFocusWidget *tmp = 0;
34   for (; it != end; ++it) {
35     tmp = dynamic_cast<OtkFocusWidget*>(*it);
36     if (tmp) tmp->focus();
37   }
38 }
39
40 void OtkFocusWidget::unfocus(void)
41 {
42   if (! _focused)
43     return;
44
45   assert(_unfocus_texture);
46   OtkWidget::setTexture(_unfocus_texture);
47   OtkWidget::update();
48
49   OtkBaseWidgetList::iterator it = _children.begin(), end = _children.end();
50   OtkFocusWidget *tmp = 0;
51   for (; it != end; ++it) {
52     tmp = dynamic_cast<OtkFocusWidget*>(*it);
53     if (tmp) tmp->unfocus();
54   }
55 }
56
57 void OtkFocusWidget::setTexture(BTexture *texture)
58 {
59   OtkWidget::setTexture(texture);
60   _focus_texture = texture;
61 }
62
63 }