soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SDateTimePicker.h
1#ifndef __SDATETIMEPICKER__H__
2#define __SDATETIMEPICKER__H__
3
4#include <core/SWnd.h>
5#include <proxy/SWindowProxy.h>
6#include <interface/SCtrl-i.h>
7#include <control/SDropDown.h>
8#include <control/SCalendar.h>
9
10SNSBEGIN
11
12/**
13 * @class SDateTimePicker
14 * @brief DateTime Picker Control
15 * @details A DateTime picker control that allows users to select a date and optionally time.
16 */
17class SOUI_EXP SDateTimePicker
18 : public TWindowProxy<IDateTimePicker>
19 , public ISDropDownOwner {
20 DEF_SOBJECT(SWindow, L"dateTimePicker")
21
22 public:
23 /**
24 * @enum EnDateType
25 * @brief Enumeration for date types
26 */
28 {
29 eDT_NULL = 0,
30 eDT_Year,
31 eDT_Month,
32 eDT_Day,
33 eDT_Hour,
34 eDT_Minute,
35 eDT_Second,
36 };
37
38 /**
39 * @brief Constructor
40 */
42
43 /**
44 * @brief Destructor
45 */
47
48 public:
49 /**
50 * @brief Set the time
51 * @param wYear Year
52 * @param wMonth Month
53 * @param wDay Day
54 * @param wHour Hour
55 * @param wMinute Minute
56 * @param wSecond Second
57 */
58 STDMETHOD_(void, SetTime)
59 (THIS_ WORD wYear, WORD wMonth, WORD wDay, WORD wHour, WORD wMinute, WORD wSecond) OVERRIDE;
60
61 /**
62 * @brief Get the time
63 * @param wYear Output year
64 * @param wMonth Output month
65 * @param wDay Output day
66 * @param wHour Output hour
67 * @param wMinute Output minute
68 * @param wSecond Output second
69 */
70 STDMETHOD_(void, GetTime)
71 (THIS_ WORD *wYear, WORD *wMonth, WORD *wDay, WORD *wHour, WORD *wMinute, WORD *wSecond) SCONST OVERRIDE;
72
73 /**
74 * @brief Close the dropdown
75 */
76 STDMETHOD_(void, CloseUp)(THIS) OVERRIDE;
77
78 /**
79 * @brief Drop down the list
80 */
81 STDMETHOD_(void, DropDown)(THIS) OVERRIDE;
82
83 /**
84 * @brief Clear the selected date and time
85 */
86 STDMETHOD_(void, Clear)(THIS) OVERRIDE;
87
88 public:
89 /**
90 * @brief Get the window text
91 * @param bRawText Whether to get raw text
92 * @return Window text
93 */
94 SStringT GetWindowText(BOOL bRawText = FALSE);
95
96 /**
97 * @brief Set the time using SYSTEMTIME structure
98 * @param sysTime SYSTEMTIME structure
99 */
100 void SetTime(const SYSTEMTIME &sysTime);
101
102 /**
103 * @brief Get the time using SYSTEMTIME structure
104 * @param sysTime SYSTEMTIME structure
105 */
106 void GetTime(SYSTEMTIME &sysTime);
107
108 protected:
109 /**
110 * @brief Get the owner window for the dropdown
111 * @return Owner window pointer
112 */
113 virtual SWindow *GetDropDownOwner();
114
115 /**
116 * @brief Handle creation of the dropdown window
117 * @param pDropDown Dropdown window pointer
118 */
119 virtual void OnCreateDropDown(SDropDownWnd *pDropDown);
120
121 /**
122 * @brief Handle destruction of the dropdown window
123 * @param pDropDown Dropdown window pointer
124 */
125 virtual void OnDestroyDropDown(SDropDownWnd *pDropDown);
126
127 protected:
128 /**
129 * @brief Hit test to determine the date type at a given point
130 * @param pt Mouse coordinates
131 * @return Date type at the point
132 */
133 EnDateType HitTest(CPoint pt);
134
135 /**
136 * @brief Create child controls
137 * @param xmlNode XML node for the child controls
138 * @return TRUE if successful, FALSE otherwise
139 */
140 virtual BOOL CreateChildren(SXmlNode xmlNode);
141
142 /**
143 * @brief Handle date change event
144 * @param pEvt Event object
145 * @return TRUE if handled, FALSE otherwise
146 */
147 BOOL OnDateChanged(EventCalendarExChanged *pEvt);
148
149 /**
150 * @brief Handle date command event
151 * @param pEvt Event object
152 * @return TRUE if handled, FALSE otherwise
153 */
154 BOOL OnDateCmd(EventCmd *pEvt);
155
156 /**
157 * @brief Get the rectangle of the dropdown button
158 * @param pBtnRc Output rectangle for the button
159 * @param pSkinRc Output rectangle for the skin
160 */
161 void GetDropBtnRect(LPRECT pBtnRc, LPRECT pSkinRc = NULL);
162
163 /**
164 * @brief Convert a number to formatted text based on the date type
165 * @param eType Date type
166 * @param wNum Number to format
167 * @return Formatted text
168 */
169 SStringT ToFormatText(EnDateType eType, WORD wNum);
170
171 /**
172 * @brief Calculate the popup rectangle
173 * @param nHeight Height of the popup
174 * @param rcPopup Output rectangle for the popup
175 * @return TRUE if successful, FALSE otherwise
176 */
177 bool CalcPopupRect(int nHeight, CRect &rcPopup);
178
179 /**
180 * @brief Draw the date/time component
181 * @param eType Date type
182 * @param pRT Rendering target handle
183 * @param wNum Number to draw
184 * @param rcText Rectangle for the text
185 */
186 void Draw(EnDateType eType, IRenderTarget *pRT, WORD wNum, CRect &rcText);
187
188 protected:
189 /**
190 * @brief Paint the control
191 * @param pRT Rendering target handle
192 */
193 void OnPaint(IRenderTarget *pRT);
194
195 /**
196 * @brief Handle left mouse button down event
197 * @param nFlags Flags
198 * @param pt Mouse coordinates
199 */
200 void OnLButtonDown(UINT nFlags, CPoint pt);
201
202 /**
203 * @brief Handle mouse move event
204 * @param nFlags Flags
205 * @param pt Mouse coordinates
206 */
207 void OnMouseMove(UINT nFlags, CPoint pt);
208
209 /**
210 * @brief Handle mouse leave event
211 */
212 void OnMouseLeave();
213
214 /**
215 * @brief Handle mouse wheel event
216 * @param nFlags Flags
217 * @param zDelta Wheel delta
218 * @param pt Mouse coordinates
219 * @return TRUE if handled, FALSE otherwise
220 */
221 BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
222
223 /**
224 * @brief Handle key down event
225 * @param nChar Key code
226 * @param nRepCnt Repeat count
227 * @param nFlags Flags
228 */
229 void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags);
230
231 /**
232 * @brief Handle character input event
233 * @param nChar Character code
234 * @param nRepCnt Repeat count
235 * @param nFlags Flags
236 */
237 void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
238
239 /**
240 * @brief Handle destroy event
241 */
242 void OnDestroy();
243
244 /**
245 * @brief Handle set focus event
246 * @param wndOld Previous focus window handle
247 */
248 void OnSetFocus(SWND wndOld);
249
250 /**
251 * @brief Handle kill focus event
252 * @param wndFocus New focus window handle
253 */
254 void OnKillFocus(SWND wndFocus);
255
256 /**
257 * @brief Handle time wheel event
258 * @param bUp Whether the wheel is scrolled up
259 */
260 void TimeWheel(bool bUp);
261
262 /**
263 * @brief Handle circular number increment/decrement
264 * @param bUp Whether to increment
265 * @param wNum Current number
266 * @param wMin Minimum number
267 * @param wMax Maximum number
268 */
269 void CircluNum(bool bUp, WORD &wNum, WORD wMin, WORD wMax);
270
271 /**
272 * @brief Handle custom attribute "cueText"
273 * @param strValue Attribute value
274 * @param bLoading Loading flag
275 * @return HRESULT
276 */
277 HRESULT OnAttrCueText(const SStringW &strValue, BOOL bLoading);
278
279 SOUI_ATTRS_BEGIN()
280 ATTR_SKIN(L"btnSkin", m_pSkinBtn, TRUE)
281 ATTR_BOOL(L"timeEnable", m_bTimeEnable, TRUE)
282 ATTR_INT(L"dropWidth", m_nDropWidth, TRUE)
283 ATTR_COLOR(L"cueColor", m_crCue, TRUE)
284 ATTR_CUSTOM(L"cueText", OnAttrCueText)
285 SOUI_ATTRS_END()
286
287 SOUI_MSG_MAP_BEGIN()
288 MSG_WM_PAINT_EX(OnPaint)
289 MSG_WM_LBUTTONDOWN(OnLButtonDown)
290 MSG_WM_MOUSEMOVE(OnMouseMove)
291 MSG_WM_MOUSELEAVE(OnMouseLeave)
292 MSG_WM_MOUSEWHEEL(OnMouseWheel)
293 MSG_WM_KEYDOWN(OnKeyDown)
294 MSG_WM_CHAR(OnChar)
295 MSG_WM_DESTROY(OnDestroy)
296 MSG_WM_SETFOCUS_EX(OnSetFocus)
297 MSG_WM_KILLFOCUS_EX(OnKillFocus)
298 SOUI_MSG_MAP_END()
299
300 protected:
301 DWORD m_dwBtnState; /**< Button state */
302 SAutoRefPtr<ISkinObj> m_pSkinBtn; /**< Button skin object */
303 SDropDownWnd *m_pDropDownWnd; /**< Dropdown window pointer */
304 EnDateType m_eSelDateType; /**< Selected date type */
305 int m_nNumWidth; /**< Width of number display */
306 int m_nNumHeight; /**< Height of number display */
307 int m_nCharWidth; /**< Width of character display */
308 COLORREF m_crSelBg; /**< Selection background color */
309 COLORREF m_crSelText; /**< Selection text color */
310 SYSTEMTIME m_sysTime; /**< System time */
311 SStringT m_sKey; /**< Key string */
312
313 int m_nDropWidth; /**< Dropdown width */
314 bool m_bTimeEnable; /**< Whether time (hour, minute, second) is enabled */
315 SCalendar *m_pCalendar; /**< Calendar pointer */
316 WORD m_wCharNum; /**< Character number */
317 STrText m_strCue; /**< Cue text */
318 COLORREF m_crCue; /**< Cue text color */
319};
320
321SNSEND
322
323#endif // __SDATETIMEPICKER__H__
Calendar Control.
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
Calendar Control Class.
Definition SCalendar.h:135
DateTime Picker Control.
HRESULT OnAttrCueText(const SStringW &strValue, BOOL bLoading)
Handle custom attribute "cueText".
void CircluNum(bool bUp, WORD &wNum, WORD wMin, WORD wMax)
Handle circular number increment/decrement.
SAutoRefPtr< ISkinObj > m_pSkinBtn
EnDateType HitTest(CPoint pt)
Hit test to determine the date type at a given point.
void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle character input event.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handle mouse wheel event.
void GetTime(WORD *wYear, WORD *wMonth, WORD *wDay, WORD *wHour, WORD *wMinute, WORD *wSecond) SCONST OVERRIDE
Get the time.
void SetTime(WORD wYear, WORD wMonth, WORD wDay, WORD wHour, WORD wMinute, WORD wSecond) OVERRIDE
Set the time.
bool CalcPopupRect(int nHeight, CRect &rcPopup)
Calculate the popup rectangle.
SDateTimePicker()
Constructor.
EnDateType
Enumeration for date types.
void Clear() OVERRIDE
Clear the selected date and time.
void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags)
Handle key down event.
SCalendar * m_pCalendar
void OnPaint(IRenderTarget *pRT)
Paint the control.
void OnMouseMove(UINT nFlags, CPoint pt)
Handle mouse move event.
void GetDropBtnRect(LPRECT pBtnRc, LPRECT pSkinRc=NULL)
Get the rectangle of the dropdown button.
void OnSetFocus(SWND wndOld)
Handle set focus event.
SDropDownWnd * m_pDropDownWnd
EnDateType m_eSelDateType
BOOL OnDateCmd(EventCmd *pEvt)
Handle date command event.
void OnKillFocus(SWND wndFocus)
Handle kill focus event.
void OnMouseLeave()
Handle mouse leave event.
void Draw(EnDateType eType, IRenderTarget *pRT, WORD wNum, CRect &rcText)
Draw the date/time component.
void OnLButtonDown(UINT nFlags, CPoint pt)
Handle left mouse button down event.
void DropDown() OVERRIDE
Drop down the list.
SStringT ToFormatText(EnDateType eType, WORD wNum)
Convert a number to formatted text based on the date type.
void OnDestroy()
Handle destroy event.
void TimeWheel(bool bUp)
Handle time wheel event.
BOOL OnDateChanged(EventCalendarExChanged *pEvt)
Handle date change event.
void CloseUp() OVERRIDE
Close the dropdown.
Dropdown Window Class.
Definition SDropDown.h:43
A class representing an ASCII string.
Definition sstringw.h:96
Class for handling text with translation support.
Definition SWnd.h:230
void OnMouseMove(UINT nFlags, CPoint pt)
Handles the mouse move event.
Definition Swnd.cpp:2131
void OnDestroy()
Handles the destruction of the window.
Definition Swnd.cpp:1701
int GetWindowText(TCHAR *pBuf, int nBufLen, BOOL bRawText) OVERRIDE
Retrieves the window text.
Definition Swnd.cpp:263
void OnKillFocus(SWND wndFocus)
Handles losing focus.
Definition Swnd.cpp:2274
void OnPaint(IRenderTarget *pRT)
Handles the painting of the window.
Definition Swnd.cpp:1785
void OnMouseLeave()
Handles the mouse leave event.
Definition Swnd.cpp:2147
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the mouse wheel event.
Definition Swnd.cpp:2159
SWindow()
Constructor.
Definition Swnd.cpp:104
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
Definition Swnd.cpp:2092
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child windows from XML node.
Definition Swnd.cpp:823
void OnSetFocus(SWND wndOld)
Handles gaining focus.
Definition Swnd.cpp:2265
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440
Interface for Dropdown Owner.
Definition SDropDown.h:16
virtual void OnDestroyDropDown(SDropDownWnd *pDropDown)=0
Notify that the dropdown window is being destroyed.
virtual SWindow * GetDropDownOwner()=0
Get the dropdown owner window.
virtual void OnCreateDropDown(SDropDownWnd *pDropDown)=0
Notify that the dropdown window has been created.
Interface for Skin Objects.
Definition SSkinobj-i.h:29