]> icculus.org git repositories - dana/openbox.git/blob - otk/focuslabel.cc
add the config header and emacs comment to all the .cc's
[dana/openbox.git] / otk / focuslabel.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 "focuslabel.hh"
8
9 namespace otk {
10
11 OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
12   : OtkFocusWidget(parent), _text("")
13 {
14   setTexture(getStyle()->getLabelFocus());
15   setUnfocusTexture(getStyle()->getLabelUnfocus());
16 }
17
18 OtkFocusLabel::~OtkFocusLabel()
19 {
20 }
21
22 void OtkFocusLabel::update(void)
23 {
24   if (_dirty) {
25     const BFont &ft = getStyle()->getFont();
26     BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
27                           : getStyle()->getTextUnfocus());
28     unsigned int bevel = getStyle()->getBevelWidth();
29
30     std::string t = _text; // the actual text to draw
31     int x = bevel;         // x coord for the text
32
33     // find a string that will fit inside the area for text
34     int max_length = width() - getBevelWidth() * 2;
35     if (max_length <= 0) {
36       t = ""; // can't fit anything
37     } else {
38       size_t text_len = t.size();
39       int length;
40       
41       do {
42         t.resize(text_len);
43         length = ft.measureString(t);
44       } while (length > max_length && text_len-- > 0);
45
46       // justify the text
47       switch (getStyle()->textJustify()) {
48       case Style::RightJustify:
49         x += max_length - length;
50         break;
51       case Style::CenterJustify:
52         x += (max_length - length) / 2;
53         break;
54       case Style::LeftJustify:
55         break;
56       }
57     }
58
59     OtkFocusWidget::update();
60
61     ft.drawString(getWindow(), x, bevel, *text_color, t);
62   } else
63     OtkFocusWidget::update();
64 }
65
66 }