1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "focuslabel.hh"
11 OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
12 : OtkFocusWidget(parent), _text("")
14 setTexture(getStyle()->getLabelFocus());
15 setUnfocusTexture(getStyle()->getLabelUnfocus());
18 OtkFocusLabel::~OtkFocusLabel()
22 void OtkFocusLabel::update(void)
25 const BFont &ft = getStyle()->getFont();
26 BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
27 : getStyle()->getTextUnfocus());
28 unsigned int bevel = getStyle()->getBevelWidth();
30 std::string t = _text; // the actual text to draw
31 int x = bevel; // x coord for the text
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
38 size_t text_len = t.size();
43 length = ft.measureString(t);
44 } while (length > max_length && text_len-- > 0);
47 switch (getStyle()->textJustify()) {
48 case Style::RightJustify:
49 x += max_length - length;
51 case Style::CenterJustify:
52 x += (max_length - length) / 2;
54 case Style::LeftJustify:
59 OtkFocusWidget::update();
61 ft.drawString(getWindow(), x, bevel, *text_color, t);
63 OtkFocusWidget::update();