]> Dogcows Code - chaz/openbox/blob - otk/focuslabel.cc
actually add this shit. yay
[chaz/openbox] / otk / focuslabel.cc
1 #include <iostream>
2 #include "focuslabel.hh"
3
4 namespace otk {
5
6 OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
7 : OtkFocusWidget(parent), _text(""), _dirty(false)
8 {
9 setTexture(getStyle()->getLabelFocus());
10 setUnfocusTexture(getStyle()->getLabelUnfocus());
11 }
12
13 OtkFocusLabel::~OtkFocusLabel()
14 {
15 }
16
17 void OtkFocusLabel::update(void)
18 {
19 if (_dirty) {
20 const BFont &ft = getStyle()->getFont();
21 BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
22 : getStyle()->getTextUnfocus());
23 unsigned int bevel = getStyle()->getBevelWidth();
24
25 std::string t = _text; // the actual text to draw
26 int x = bevel; // x coord for the text
27
28 // find a string that will fit inside the area for text
29 int max_length = width() - getBevelWidth() * 2;
30 if (max_length <= 0) {
31 t = ""; // can't fit anything
32 } else {
33 size_t text_len = t.size();
34 int length;
35
36 do {
37 t.resize(text_len);
38 length = ft.measureString(t);
39 } while (length > max_length && text_len-- > 0);
40
41 // justify the text
42 switch (getStyle()->textJustify()) {
43 case Style::RightJustify:
44 x += max_length - length;
45 break;
46 case Style::CenterJustify:
47 x += (max_length - length) / 2;
48 break;
49 case Style::LeftJustify:
50 break;
51 }
52 }
53
54 OtkFocusWidget::update();
55
56 ft.drawString(getWindow(), x, bevel, *text_color, t);
57 } else
58 OtkFocusWidget::update();
59
60 _dirty = false;
61 }
62
63 int OtkFocusLabel::exposeHandler(const XExposeEvent &e)
64 {
65 _dirty = true;
66 return OtkFocusWidget::exposeHandler(e);
67 }
68
69 int OtkFocusLabel::configureHandler(const XConfigureEvent &e)
70 {
71 if (!(e.width == width() && e.height == height()))
72 _dirty = true;
73 return OtkFocusWidget::configureHandler(e);
74 }
75
76 }
This page took 0.040793 seconds and 5 git commands to generate.