Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

HLabel.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 **  $Header: /SkyOS.root/HFramework/HLabel.h 3     4/17/05 12:29p Lee Neuse $
00004 **
00005 ****************************************************************************/
00012 #ifndef HLABEL_H
00013 #   define  HLABEL_H
00014 
00015 #ifndef HWINDOW_H
00016 #   include "HWindow.h"
00017 #endif
00018 
00026 class HPane :   public HWindow<HPane>
00027     {
00028     typedef HWindow<HPane>  base_class;
00029     static StringPtr        ClassName(void) { return "HPane"; }
00030 public:
00031     typedef enum { STYLE_PLAIN = 0, STYLE_FRAMED, STYLE_RAISED, STYLE_SUNKEN } Style;
00032 /*  ----------------------------------------------------------------------
00033     VARIABLES
00034     ----------------------------------------------------------------------  */
00035 protected:
00036     Style               m_style;        
00037 /*  ----------------------------------------------------------------------
00038     CTOR / DTOR
00039     ----------------------------------------------------------------------  */
00040 public:
00041     HPane(HPane::Style style = STYLE_PLAIN) : base_class(), m_style(style)
00042         { /* STUB CTOR */ }
00043 
00044     virtual             
00045     ~HPane(void)
00046         { /* STUB DTOR */ }
00047 /*  ----------------------------------------------------------------------
00048     METHODS
00049     ----------------------------------------------------------------------  */
00050 public:
00060     virtual ErrCode
00061     Draw(HRect & rDirty)
00062         {
00063         ErrCode     ec = HError::NoError();
00064         
00065         const int32     nT = 0,
00066                         nL = 0,
00067                         nR = GetWidth(),
00068                         nB = GetHeight();
00069 
00070         (void) m_gc.SetColors(m_clrBG, m_clrFG);
00071         (void) m_gc.FillRect(nT, nL, nR, nB);
00072         //
00073         //  See if we're using a fancy style...if so, draw the lines as 
00074         //  needed.  Don't use the dirty rectangle because we're drawing
00075         //  probably isn't the same and we need to draw the edges.
00076         //
00077         switch (m_style)
00078             {
00079             case STYLE_FRAMED:
00080                 (void) m_gc.DrawRect(nL, nT, nR, nB);
00081                 break;
00082                 
00083             case STYLE_RAISED:  // L+T hi R+B lo
00084                 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::LIGHTEN_2));
00085                 (void) m_gc.DrawLine(nL, nT, nL, nB);   // left
00086                 (void) m_gc.DrawLine(nL, nT, nR, nT);   // top
00087                 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::DARKEN_2));
00088                 (void) m_gc.DrawLine(nR, nT, nR, nB);   // right
00089                 (void) m_gc.DrawLine(nL, nB, nR, nB);   // bottom
00090                 (void) m_gc.SetForeColor(m_clrFG);
00091                 break;
00092 
00093             case STYLE_SUNKEN:  // L+T lo R+B hi
00094                 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::DARKEN_2));
00095                 (void) m_gc.DrawLine(nL, nT, nL, nB);   // left
00096                 (void) m_gc.DrawLine(nL, nT, nR, nT);   // top
00097                 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::LIGHTEN_2));
00098                 (void) m_gc.DrawLine(nR, nT, nR, nB);   // right
00099                 (void) m_gc.DrawLine(nL, nB, nR, nB);   // bottom
00100                 (void) m_gc.SetForeColor(m_clrFG);
00101                 break;
00102             
00103             default:
00104                 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00105             }
00106 
00107         return ec;
00108         }
00109 /*  ----------------------------------------------------------------------
00110     GETTERS & SETTERS
00111     ----------------------------------------------------------------------  */
00112 public:
00117     HPane::Style        GetStyle(void) const
00118                             { return m_style; }
00124     HPane::Style        SetStyle(HPane::Style styleNew)
00125                             {
00126                             const HPane::Style  styleOld = m_style;
00127                             
00128                             if (styleNew != styleOld)
00129                                 {       
00130                                 m_style = styleNew;
00131                                 Smudge();
00132                                 }
00133                                 
00134                             return styleOld;
00135                             }
00136     };
00145 class HLabel : public HPane
00146     {
00147     typedef HPane           base_class;
00148     static StringPtr        ClassName(void) { return "HLabel"; }
00149 /*  ----------------------------------------------------------------------
00150     VARIABLES
00151     ----------------------------------------------------------------------  */
00152 protected:
00153     HFont               m_font;
00154     HString             m_strText;
00155 /*  ----------------------------------------------------------------------
00156     CTOR / DTOR
00157     ----------------------------------------------------------------------  */
00158 public:
00159     HLabel(HPane::Style style = STYLE_PLAIN, StringPtr pstr = NULL) : base_class(style)
00160         { 
00161         m_font.SetDefault();
00162         m_strText = STR_SAFE(pstr); 
00163         }
00164 
00165     virtual             
00166     ~HLabel(void)
00167         { (void) m_font.Destroy(); }
00168 /*  ----------------------------------------------------------------------
00169     METHODS
00170     ----------------------------------------------------------------------  */
00171 public:
00184     virtual ErrCode
00185     Create( HANDLE          hParent, 
00186             StringPtr       pstrText = NULL, 
00187             HRect const *   prFrame = NULL, 
00188             uint32          uStyle = 0)
00189         {
00190         ErrCode         ec = HError::NoError();
00191 
00192         m_strText = STR_SAFE(pstrText);
00193         ec = base_class::Create(hParent, pstrText, prFrame, uStyle);
00194         
00195         return ec;
00196         }
00206     ErrCode
00207     Draw(HRect & rDirty)
00208         {
00209         HRect       rBounds;
00210         ErrCode     ec = HError::NoError();
00211         
00212         if ((ec = base_class::Draw(rDirty)) == NO_ERROR &&
00213             GetBounds(rBounds))
00214             {
00215             ASSERT( m_gc.IsValid() );
00216             
00217             (void) m_gc.SetFont(m_font);
00218             (void) m_gc.DrawText(rBounds, StringPtr(m_strText));
00219             }
00220 
00221         return ec;
00222         }
00223 /*  ----------------------------------------------------------------------
00224     GETTERS & SETTERS
00225     ----------------------------------------------------------------------  */
00230     StringPtr           GetText(void) const
00231                             { return StringPtr(m_strText); }
00237     ErrCode             SetFont(StringPtr pstrFont)
00238                             { return m_font.Set(NULL, NULL, pstrFont); }
00244     ErrCode             SetText(StringPtr pstrNew)
00245                             {
00246                             ErrCode     ec = HError::NoError();
00247                             
00248                             m_strText = STR_SAFE(pstrNew);
00249                             ec = Smudge();
00250                             return ec;
00251                             }
00252     };
00253 #endif  // HLABEL_H
00254 /****************************************************************************
00255 **
00256 **  $History: HLabel.h $
00257  * 
00258  * *****************  Version 3  *****************
00259  * User: Lee Neuse    Date: 4/17/05    Time: 12:29p
00260  * Updated in $/SkyOS.root/HFramework
00261  * Development snapshot 050417
00262  * 
00263  * *****************  Version 2  *****************
00264  * User: Neusel       Date: 2/04/05    Time: 10:45a
00265  * Updated in $/SkyOS.root/pig/Humble
00266  * 
00267  * *****************  Version 1  *****************
00268  * User: Neusel       Date: 12/23/04   Time: 1:34p
00269  * Created in $/SkyOS.root/pig/Humble
00270  * Posted as HFramework-debug 20041223
00271 **
00272 **  -------------------------------------------------------------------------
00273 **
00274 **  End of HLabel.h
00275 **
00276 ****************************************************************************/