]> icculus.org git repositories - mikachu/openbox.git/blob - otk/focuswidget.cc
add an OBBackgroundWidget and use it for setting colors so far.
[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), _unfocus_bcolor(0)
13 {
14   _focused = true;
15   _focus_texture = parent->getTexture();
16   _focus_bcolor = parent->getBorderColor();
17 }
18
19 OtkFocusWidget::~OtkFocusWidget()
20 {
21 }
22
23 #include <stdio.h>
24 void OtkFocusWidget::focus(void)
25 {
26   if (!isVisible() || _focused)
27     return;
28
29   printf("FOCUS\n");
30   OtkWidget::focus();
31
32   if (_focus_bcolor)
33     OtkWidget::setBorderColor(_focus_bcolor);
34
35   OtkWidget::setTexture(_focus_texture);
36   OtkWidget::update();
37 }
38
39 void OtkFocusWidget::unfocus(void)
40 {
41   if (!isVisible() || !_focused)
42     return;
43
44   printf("UNFOCUS\n");
45   OtkWidget::unfocus();
46
47   if (_unfocus_bcolor)
48     OtkWidget::setBorderColor(_unfocus_bcolor);
49
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 void OtkFocusWidget::setBorderColor(const BColor *color)
72 {
73   OtkWidget::setBorderColor(color);
74   _focus_bcolor = color;
75 }
76
77 }