]> icculus.org git repositories - mikachu/openbox.git/blob - otk/focuswidget.cc
label and focuslabel update their textures automatically on a style change
[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   OtkWidget::OtkWidgetList children = OtkWidget::getChildren();
33
34   OtkWidget::OtkWidgetList::iterator it = children.begin(),
35     end = children.end();
36
37   OtkFocusWidget *tmp = 0;
38   for (; it != end; ++it) {
39     tmp = dynamic_cast<OtkFocusWidget*>(*it);
40     if (tmp) tmp->focus();
41   }
42 }
43
44 void OtkFocusWidget::unfocus(void)
45 {
46   if (! _focused)
47     return;
48
49   assert(_unfocus_texture);
50   OtkWidget::setTexture(_unfocus_texture);
51   OtkWidget::update();
52
53   OtkWidget::OtkWidgetList children = OtkWidget::getChildren();
54
55   OtkWidget::OtkWidgetList::iterator it = children.begin(),
56     end = children.end();
57
58   OtkFocusWidget *tmp = 0;
59   for (; it != end; ++it) {
60     tmp = dynamic_cast<OtkFocusWidget*>(*it);
61     if (tmp) tmp->unfocus();
62   }
63 }
64
65 void OtkFocusWidget::setTexture(BTexture *texture)
66 {
67   OtkWidget::setTexture(texture);
68   _focus_texture = texture;
69 }
70
71 }