Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ob::LabelWidget Class Reference

#include <labelwidget.hh>

Inheritance diagram for ob::LabelWidget:

Inheritance graph
[legend]
Collaboration diagram for ob::LabelWidget:

Collaboration graph
[legend]
List of all members.

Public Methods

 LabelWidget (otk::Widget *parent, WidgetBase::WidgetType type)
virtual ~LabelWidget ()
virtual void setStyle (otk::RenderStyle *style)
virtual void adjust ()
virtual void focus ()
virtual void unfocus ()
virtual void renderForeground ()
const otk::ustringtext () const
void setText (const otk::ustring &text)

Private Methods

void setTextures ()

Private Attributes

const otk::Font_font
otk::RenderColor_text_color
int _sidemargin
otk::RenderStyle::TextJustify _justify
otk::ustring _text

Constructor & Destructor Documentation

ob::LabelWidget::LabelWidget otk::Widget   parent,
WidgetBase::WidgetType    type
 

Definition at line 13 of file labelwidget.cc.

00014   : otk::Widget(parent),
00015     WidgetBase(type)
00016 {
00017 }

ob::LabelWidget::~LabelWidget   [virtual]
 

Definition at line 20 of file labelwidget.cc.

00021 {
00022 }


Member Function Documentation

void ob::LabelWidget::adjust   [virtual]
 

Reimplemented from otk::Widget.

Definition at line 112 of file labelwidget.cc.

00113 {
00114   // nothing to adjust. no children.
00115 }

void ob::LabelWidget::focus   [virtual]
 

Reimplemented from otk::Widget.

Definition at line 56 of file labelwidget.cc.

References otk::Widget::focus(), and setTextures().

00057 {
00058   otk::Widget::focus();
00059   setTextures();
00060 }

void ob::LabelWidget::renderForeground   [virtual]
 

Reimplemented from otk::Widget.

Definition at line 70 of file labelwidget.cc.

References otk::Widget::_dirty, _font, _sidemargin, otk::Widget::_surface, _text, _text_color, otk::RenderStyle::CenterJustify, otk::RenderStyle::LeftJustify, otk::Font::measureString(), otk::Widget::renderForeground(), otk::ustring::resize(), otk::RenderStyle::RightJustify, otk::ustring::size(), and otk::Widget::width().

00071 {
00072   bool draw = _dirty;
00073 
00074   otk::Widget::renderForeground();
00075 
00076   if (draw) {
00077     otk::ustring t = _text;
00078     int x = _sidemargin;    // x coord for the text
00079 
00080     // find a string that will fit inside the area for text
00081     int max_length = width() - _sidemargin * 2;
00082     if (max_length <= 0) {
00083       t = ""; // can't fit anything
00084     } else {
00085       size_t text_len = t.size();
00086       int length;
00087       
00088       do {
00089         t.resize(text_len);
00090         length = _font->measureString(t);
00091       } while (length > max_length && text_len-- > 0);
00092 
00093       // justify the text
00094       switch (_justify) {
00095       case otk::RenderStyle::RightJustify:
00096         x += max_length - length;
00097         break;
00098       case otk::RenderStyle::CenterJustify:
00099         x += (max_length - length) / 2;
00100         break;
00101       case otk::RenderStyle::LeftJustify:
00102         break;
00103       }
00104     }
00105 
00106     otk::display->renderControl(_screen)->drawString
00107       (*_surface, *_font, x, 0, *_text_color, t);
00108   }
00109 }

void ob::LabelWidget::setStyle otk::RenderStyle   style [virtual]
 

Reimplemented from otk::Widget.

Definition at line 44 of file labelwidget.cc.

References _font, _justify, _sidemargin, otk::RenderStyle::bevelWidth(), otk::RenderStyle::labelFont(), otk::RenderStyle::labelTextJustify(), otk::Widget::setStyle(), and setTextures().

00045 {
00046   otk::Widget::setStyle(style);
00047   setTextures();
00048   _font = style->labelFont();
00049   _sidemargin = style->bevelWidth() * 2;
00050   _justify = style->labelTextJustify();
00051 
00052   assert(_font);
00053 }

void ob::LabelWidget::setText const otk::ustring   text
 

Definition at line 25 of file labelwidget.cc.

References otk::Widget::_dirty, and _text.

Referenced by ob::Frame::Frame(), and ob::Frame::setTitle().

00026 {
00027   _text = text;
00028   _dirty = true;
00029 }

void ob::LabelWidget::setTextures   [private]
 

Definition at line 32 of file labelwidget.cc.

References otk::Widget::_style, _text_color, and otk::Widget::setTexture().

Referenced by focus(), setStyle(), and unfocus().

00033 {
00034   if (_focused) {
00035     setTexture(_style->labelFocusBackground());
00036     _text_color = _style->textFocusColor();
00037   } else {
00038     setTexture(_style->labelUnfocusBackground());
00039     _text_color = _style->textUnfocusColor();
00040   }
00041 }

const otk::ustring& ob::LabelWidget::text   const [inline]
 

Definition at line 36 of file labelwidget.hh.

00036 { return _text; }

void ob::LabelWidget::unfocus   [virtual]
 

Reimplemented from otk::Widget.

Definition at line 63 of file labelwidget.cc.

References setTextures(), and otk::Widget::unfocus().

00064 {
00065   otk::Widget::unfocus();
00066   setTextures();
00067 }


Member Data Documentation

const otk::Font* ob::LabelWidget::_font [private]
 

Definition at line 17 of file labelwidget.hh.

Referenced by renderForeground(), and setStyle().

otk::RenderStyle::TextJustify ob::LabelWidget::_justify [private]
 

Definition at line 20 of file labelwidget.hh.

Referenced by setStyle().

int ob::LabelWidget::_sidemargin [private]
 

Definition at line 19 of file labelwidget.hh.

Referenced by renderForeground(), and setStyle().

otk::ustring ob::LabelWidget::_text [private]
 

Definition at line 21 of file labelwidget.hh.

Referenced by renderForeground(), and setText().

otk::RenderColor* ob::LabelWidget::_text_color [private]
 

Definition at line 18 of file labelwidget.hh.

Referenced by renderForeground(), and setTextures().


The documentation for this class was generated from the following files:
Generated on Tue Feb 4 23:00:18 2003 for Openbox by doxygen1.3-rc2