2 #include "focuslabel.hh"
6 OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
7 : OtkFocusWidget(parent), _text(""), _dirty(false)
9 setTexture(getStyle()->getLabelFocus());
10 setUnfocusTexture(getStyle()->getLabelUnfocus());
13 OtkFocusLabel::~OtkFocusLabel()
17 void OtkFocusLabel::update(void)
20 const BFont &ft = getStyle()->getFont();
21 BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
22 : getStyle()->getTextUnfocus());
23 unsigned int bevel = getStyle()->getBevelWidth();
25 std::string t = _text; // the actual text to draw
26 int x = bevel; // x coord for the text
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
33 size_t text_len = t.size();
38 length = ft.measureString(t);
39 } while (length > max_length && text_len-- > 0);
42 switch (getStyle()->textJustify()) {
43 case Style::RightJustify:
44 x += max_length - length;
46 case Style::CenterJustify:
47 x += (max_length - length) / 2;
49 case Style::LeftJustify:
54 OtkFocusWidget::update();
56 ft.drawString(getWindow(), x, bevel, *text_color, t);
58 OtkFocusWidget::update();
63 int OtkFocusLabel::exposeHandler(const XExposeEvent &e)
66 return OtkFocusWidget::exposeHandler(e);
69 int OtkFocusLabel::configureHandler(const XConfigureEvent &e)
71 if (!(e.width == width() && e.height == height()))
73 return OtkFocusWidget::configureHandler(e);