00001
00002
00003
00004
00005
00012 #ifndef HCHECKBOX_H
00013 # define HCHECKBOX_H
00014
00015 #ifndef HWIDGET_H
00016 # include "HWidget.h"
00017 #endif
00018
00024 class HCheckbox : public HWidget,
00025 public HID
00026 {
00027 typedef HWidget base_class;
00028 static StringPtr ClassName(void) { return "HCheckbox"; }
00029
00030
00031
00032 public:
00033 HCheckbox(int32 id = 0) : HWidget(), HID(id)
00034 { }
00035
00036 virtual
00037 ~HCheckbox(void)
00038 { Destroy(); }
00039
00040
00041
00042 protected:
00043 BEGIN_MSG_MAP("HCheckbox")
00044 CHAIN_MAP( base_class )
00045 END_MSG_MAP
00046
00047
00048
00049 public:
00060 ErrCode
00061 Create(HANDLE hParent, int32 id, StringPtr pstrLabel,
00062 HRect * prBounds = NULL, uint32 uStyle = 0)
00063 {
00064 HRect rBounds;
00065 ErrCode ec = HError::NoError();
00066
00067 if (GOOD_HND(m_hMe))
00068 ec = HError::Set(ERR_DUPLICATE, __FILE__, __LINE__);
00069 else if (NULL_HND(hParent) || id == 0)
00070 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00071 else
00072 {
00073 int32 nX, nY,
00074 nXDim, nYDim;
00075
00076 if (NULL_PTR(prBounds) || prBounds->IsEmpty())
00077 nX = nY = nXDim = nYDim = 0;
00078 else
00079 {
00080 nX = prBounds->x1;
00081 nY = prBounds->y1;
00082 nXDim = prBounds->GetWidth();
00083 nYDim = prBounds->GetHeight();
00084 }
00085
00086 m_hMe = GI_create_widget_check(hParent, TEXT(pstrLabel),
00087 nX, nY, nXDim, nYDim,
00088 uStyle, id);
00089 if (NULL_HND(m_hMe))
00090 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00091 else
00092 {
00093 m_id = id;
00094 DEBUG_LOG( "HCheckbox[%p]::Create() => m_hMe = 0x%08lX\n",
00095 this, int32(m_hMe));
00096 }
00097 }
00098
00099 return ec;
00100 }
00101
00102
00103
00104 public:
00109 COLOR GetBackColor(void) const
00110 {
00111 widget_check * pwc = getWidgetData();
00112 return GOOD_PTR(pwc) ? pwc->ulBackGround : cWhite;
00113 }
00118 static inline int32 GetPreferredHeight(void)
00119 { return 20; }
00124 inline int32 GetState(void) const
00125 { return IsValid() ? GI_widget_check_get(m_hMe) : 0; }
00130 ErrCode SetEnabled(const bool bEnable = true)
00131 {
00132 ErrCode ec = HError::NoError();
00133
00134 if (IsValid())
00135 {
00136 HRESULT hr = (bEnable) ? GI_widget_check_enable(m_hMe) :
00137 GI_widget_check_disable(m_hMe);
00138
00139 if (hr != S_OK)
00140 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00141 }
00142 else
00143 ec = HError::Set(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00144
00145 return ec;
00146 }
00153 ErrCode SetState(int32 nState)
00154 {
00155 ErrCode ec = HError::NoError();
00156
00157 if (IsValid())
00158 {
00159 if (widget_check_set(m_hMe, nState) != S_OK)
00160 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00161 }
00162 else
00163 ec = HError::Set(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00164
00165 return ec;
00166 }
00173 ErrCode SetText(StringPtr pstrLabel)
00174 {
00175 ErrCode ec = HError::NoError();
00176
00177 if (!IsValid())
00178 ec = HError::Set(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00179 else if (STR_EMPTY(pstrLabel))
00180 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00181 else if (GI_widget_check_set_text(m_hMe, TEXT(pstrLabel)) != S_OK)
00182 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00183
00184 return ec;
00185 }
00186 protected:
00191 widget_check * getWidgetData(void) const
00192 {
00193 s_window * pw = GetWindow();
00194 return GOOD_PTR(pw) ? reinterpret_cast<widget_check *>(pw->windowData) : NULL;
00195 }
00196
00197
00198
00199 public:
00202 inline bool IsChecked(void) const
00203 { return (GetState() != 0); }
00204 };
00205
00206 #endif // HCHECKBOX_H
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225