00001
00002
00003
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
00034
00035 protected:
00036 Style m_style;
00037
00038
00039
00040 public:
00041 HPane(HPane::Style style = STYLE_PLAIN) : base_class(), m_style(style)
00042 { }
00043
00044 virtual
00045 ~HPane(void)
00046 { }
00047
00048
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
00074
00075
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:
00084 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::LIGHTEN_2));
00085 (void) m_gc.DrawLine(nL, nT, nL, nB);
00086 (void) m_gc.DrawLine(nL, nT, nR, nT);
00087 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::DARKEN_2));
00088 (void) m_gc.DrawLine(nR, nT, nR, nB);
00089 (void) m_gc.DrawLine(nL, nB, nR, nB);
00090 (void) m_gc.SetForeColor(m_clrFG);
00091 break;
00092
00093 case STYLE_SUNKEN:
00094 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::DARKEN_2));
00095 (void) m_gc.DrawLine(nL, nT, nL, nB);
00096 (void) m_gc.DrawLine(nL, nT, nR, nT);
00097 (void) m_gc.SetForeColor(HColor::Tint(m_clrBG, Humble::LIGHTEN_2));
00098 (void) m_gc.DrawLine(nR, nT, nR, nB);
00099 (void) m_gc.DrawLine(nL, nB, nR, nB);
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
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
00151
00152 protected:
00153 HFont m_font;
00154 HString m_strText;
00155
00156
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
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
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
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276