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

otk::FocusLabel Class Reference

#include <focuslabel.hh>

Inheritance diagram for otk::FocusLabel:

Inheritance graph
[legend]
Collaboration diagram for otk::FocusLabel:

Collaboration graph
[legend]
List of all members.

Public Methods

 FocusLabel (Widget *parent)
 ~FocusLabel ()
const ustringgetText (void) const
void setText (const ustring &text)
virtual void renderForeground ()
virtual void update ()
void fitString (const std::string &str)
void fitSize (int w, int h)
virtual void setStyle (RenderStyle *style)

Private Attributes

ustring _text
 Text displayed in the label.


Constructor & Destructor Documentation

otk::FocusLabel::FocusLabel Widget   parent
 

Definition at line 13 of file focuslabel.cc.

References setStyle().

00014   : FocusWidget(parent), _text("")
00015 {
00016   setStyle(_style);
00017 }

otk::FocusLabel::~FocusLabel  
 

Definition at line 19 of file focuslabel.cc.

00020 {
00021 }


Member Function Documentation

void otk::FocusLabel::fitSize int    w,
int    h
 

Definition at line 38 of file focuslabel.cc.

References otk::RenderStyle::bevelWidth(), otk::Widget::resize(), and otk::Widget::style().

Referenced by fitString().

00039 {
00040   unsigned int sidemargin = style()->bevelWidth() * 2;
00041   resize(w + sidemargin * 2, h);
00042 }

void otk::FocusLabel::fitString const std::string &    str
 

Definition at line 32 of file focuslabel.cc.

References fitSize(), otk::Font::height(), otk::RenderStyle::labelFont(), otk::Font::measureString(), and otk::Widget::style().

00033 {
00034   const Font *ft = style()->labelFont();
00035   fitSize(ft->measureString(str), ft->height());
00036 }

const ustring& otk::FocusLabel::getText void    const [inline]
 

Definition at line 16 of file focuslabel.hh.

References _text.

00016 { return _text; }

void otk::FocusLabel::renderForeground   [virtual]
 

Reimplemented from otk::Widget.

Definition at line 68 of file focuslabel.cc.

References _text, otk::RenderStyle::bevelWidth(), otk::display, otk::FocusWidget::isFocused(), otk::RenderStyle::labelFont(), otk::RenderStyle::labelTextJustify(), otk::Font::measureString(), otk::Display::renderControl(), otk::ustring::resize(), otk::ustring::size(), otk::Widget::style(), otk::RenderStyle::textFocusColor(), otk::RenderStyle::textUnfocusColor(), and otk::Widget::width().

00069 {
00070   FocusWidget::renderForeground();
00071 
00072   const Font *ft = style()->labelFont();
00073   RenderColor *text_color = (isFocused() ? style()->textFocusColor()
00074                              : style()->textUnfocusColor());
00075   unsigned int sidemargin = style()->bevelWidth() * 2;
00076 
00077   ustring t = _text; // the actual text to draw
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 = ft->measureString(t);
00091     } while (length > max_length && text_len-- > 0);
00092 
00093     // justify the text
00094     switch (style()->labelTextJustify()) {
00095     case RenderStyle::RightJustify:
00096       x += max_length - length;
00097       break;
00098     case RenderStyle::CenterJustify:
00099       x += (max_length - length) / 2;
00100       break;
00101     case RenderStyle::LeftJustify:
00102       break;
00103     }
00104   }
00105 
00106   display->renderControl(_screen)->
00107     drawString(*_surface, *ft, x, 0, *text_color, t);
00108 }

void otk::FocusLabel::setStyle RenderStyle   style [virtual]
 

Reimplemented from otk::Widget.

Reimplemented in otk::Button.

Definition at line 24 of file focuslabel.cc.

References otk::RenderStyle::labelFocusBackground(), otk::RenderStyle::labelUnfocusBackground(), otk::FocusWidget::setTexture(), and otk::FocusWidget::setUnfocusTexture().

Referenced by FocusLabel().

00025 {
00026   FocusWidget::setStyle(style);
00027 
00028   setTexture(style->labelFocusBackground());
00029   setUnfocusTexture(style->labelUnfocusBackground());
00030 }

void otk::FocusLabel::setText const ustring   text [inline]
 

Definition at line 17 of file focuslabel.hh.

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

Referenced by main().

00017 { _text = text; _dirty = true; }

void otk::FocusLabel::update   [virtual]
 

Reimplemented from otk::Widget.

Definition at line 44 of file focuslabel.cc.

References otk::Widget::_fixed_height, otk::Widget::_fixed_width, otk::Widget::_rect, otk::RenderStyle::bevelWidth(), otk::Font::height(), otk::Rect::height(), otk::Widget::internalResize(), otk::RenderStyle::labelFont(), otk::Font::measureString(), otk::Widget::style(), and otk::Rect::width().

Referenced by otk::Button::buttonPressHandler(), and otk::Button::buttonReleaseHandler().

00045 {
00046   if (_dirty) {
00047     int w = _rect.width(), h = _rect.height();
00048     const Font *ft = style()->labelFont();
00049     unsigned int sidemargin = style()->bevelWidth() * 2;
00050     if (!_fixed_width)
00051       w = ft->measureString(_text) + sidemargin * 2;
00052     if (!_fixed_height)
00053       h = ft->height();
00054 
00055     // enforce a minimum size
00056     if (w > _rect.width()) {
00057       if (h > _rect.height())
00058         internalResize(w, h);
00059       else
00060         internalResize(w, _rect.height());
00061     } else if (h > _rect.height())
00062       internalResize(_rect.width(), h);
00063   }
00064   FocusWidget::update();
00065 }


Member Data Documentation

ustring otk::FocusLabel::_text [private]
 

Text displayed in the label.

Definition at line 30 of file focuslabel.hh.

Referenced by getText(), renderForeground(), and setText().


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