2#include "control/SDateTimePicker.h" 
    3#include "helper/STime.h" 
   17    , 
m_crCue(RGBA(0xcc, 0xcc, 0xcc, 0xff))
 
   20    m_evtSet.addEvent(EVENTID(EventDateTimeChanged));
 
   21    m_pNcSkin = GETBUILTINSKIN(SKIN_SYS_BORDER);
 
   22    m_style.SetAttribute(L
"margin", L
"1", TRUE);
 
 
   55    m_pCalendar->SetAttribute(L
"pos", L
"0,0,-0,-0", TRUE);
 
 
   74    EventDateTimeChanged e(
this);
 
 
  100    SSLOGI() << 
"rc=" << rc.left << 
"," << rc.top << 
"," << rc.right << 
"," << rc.bottom;
 
 
  125    pBtnRc->left = pBtnRc->right - (pBtnRc->bottom - pBtnRc->top); 
 
  130    int n = (pBtnRc->bottom - pBtnRc->top - szBtn.cy) / 2; 
 
  132    pSkinRc->right = pBtnRc->right - n;
 
  133    pSkinRc->left = pSkinRc->right - szBtn.cx;
 
  135    pSkinRc->top = pBtnRc->top + n;
 
  136    pSkinRc->bottom = pSkinRc->top + szBtn.cy;
 
 
  144        if (eDT_Year == eType)
 
  147                szNum.Format(_T(
"%d"), wNum);
 
  149                szNum.Format(_T(
"%02d"), wNum);
 
  151                szNum.Format(_T(
"%03d"), wNum);
 
  153                szNum.Format(_T(
"%04d"), wNum);
 
  158                szNum.Format(_T(
"%d"), wNum);
 
  160                szNum.Format(_T(
"%02d"), wNum);
 
  165        if (eDT_Year == eType)
 
  167            szNum.Format(_T(
"%04d"), wNum);
 
  171            szNum.Format(_T(
"%02d"), wNum);
 
 
  222        rcText.OffsetRect(0, (rcText.Height() - 
m_nNumHeight) / 2 + 1);
 
  229        rcText.left = rcText.right;
 
  234        rcText.left = rcText.right;
 
  238        rcText.left = rcText.right;
 
  243        rcText.left = rcText.right;
 
  254            rcText.left = rcText.right;
 
  256            pRT->
DrawText(_T(
":"), -1, rcText, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
 
  259            rcText.left = rcText.right;
 
  263            rcText.left = rcText.right;
 
  265            pRT->
DrawText(_T(
":"), -1, rcText, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
 
  268            rcText.left = rcText.right;
 
  281        rcBtn += CRect(1, 1, 1, 1);
 
 
  300        MONITORINFO mi = { 
sizeof(MONITORINFO) };
 
  301        ::GetMonitorInfo(hMonitor, &mi);
 
  302        rcMonitor = mi.rcMonitor;
 
  306        rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
 
  307        rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
 
  310    int nHeight = nWidth * 4 / 5;
 
  312    if (rcWnd.bottom + nHeight <= rcMonitor.bottom)
 
  314        rcPopup.SetRect(rcWnd.right - nWidth, rcWnd.bottom, rcWnd.right, rcWnd.bottom + nHeight);
 
  318    rcPopup.SetRect(rcWnd.right - nWidth, rcWnd.top - nHeight, rcWnd.right, rcWnd.top);
 
 
  326    int nWidth = pt.x - rcText.left;
 
  336        eSelType = eDT_Month; 
 
  348        eSelType = eDT_Minute; 
 
  352        eSelType = eDT_Second; 
 
 
  380void SDateTimePicker::GetTime(WORD *wYear, WORD *wMonth, WORD *wDay, WORD *wHour, WORD *wMinute, WORD *wSecond)
 const 
  409    __baseCls::OnLButtonDown(nFlags, pt);
 
  418    if (!rcBtn.PtInRect(pt)) 
 
 
  438    __baseCls::OnMouseHover(nFlags, pt);
 
  443    if (rcBtn.PtInRect(pt))
 
 
  461        __baseCls::OnMouseLeave();
 
 
  555    else if (39 == nChar)
 
  564    else if (38 == nChar)
 
  566    else if (40 == nChar)
 
 
  572    if (nChar > 
'9' || nChar < 
'0')
 
  578    int nNum = nChar - 48;
 
 
  644    __baseCls::OnDestroy();
 
 
  649    __baseCls::OnSetFocus(wndOld);
 
 
  654    __baseCls::OnKillFocus(wndFocus);
 
 
  684    SStringW strTmp = GETSTRING(strValue);
 
  687    return bLoading ? S_FALSE : S_OK;
 
 
  701    m_pDropDownWnd->SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
 
 
static BOOL DateCheck(WORD wYear, WORD wMonth, WORD wDay)
Validates the year, month, and day.
static WORD GetDaysOfMonth(WORD wYear, WORD wMonth)
Returns the number of days in a specified month.
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.
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child controls.
SDateTimePicker()
Constructor.
EnDateType
Enumeration for date types.
void Clear() OVERRIDE
Clear the selected date and time.
virtual SWindow * GetDropDownOwner()
Get the owner window for the dropdown.
virtual void OnDestroyDropDown(SDropDownWnd *pDropDown)
Handle destruction of the dropdown window.
void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags)
Handle key down event.
void OnPaint(IRenderTarget *pRT)
Paint the control.
void OnMouseMove(UINT nFlags, CPoint pt)
Handle mouse move event.
virtual void OnCreateDropDown(SDropDownWnd *pDropDown)
Handle creation of the dropdown window.
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.
~SDateTimePicker()
Destructor.
SStringT GetWindowText(BOOL bRawText=FALSE)
Get the window text.
void TimeWheel(bool bUp)
Handle time wheel event.
BOOL OnDateChanged(EventCalendarExChanged *pEvt)
Handle date change event.
void CloseUp() OVERRIDE
Close the dropdown.
SWindow * GetRoot() const
Gets the root window.
int toPixelSize(int scale) const
将大小转换为像素值
void setSize(float fSize, Unit unit)
设置指定大小
static LPCWSTR GetClassName()
Helper class for painting.
A class representing an ASCII string.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
SAutoRefPtr< ISkinObj > m_pNcSkin
DWORD GetState() SCONST OVERRIDE
Retrieves the current state of the window.
UINT GetTextAlign() const
Retrieves the text alignment of the window.
BOOL RemoveChild(SWindow *pChild)
Removes a child window from the window tree.
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
CRect GetWindowRect() const
Retrieves the bounding rectangle of the window.
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
void InsertChild(SWindow *pNewChild, SWindow *pInsertAfter=NULL)
Inserts a child window into the window tree.
virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter)
Prepare rendering environment.
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
void UpdateChildrenPosition() OVERRIDE
Updates the position of child windows.
virtual SWindow * CreateChildByName(LPCWSTR pszName)
Create child window by name.
virtual void GetTextRect(LPRECT pRect)
Calculate text display rectangle.
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter)
Restore rendering environment.
void Invalidate() OVERRIDE
Invalidates the entire window.
HWND GetHostHwnd() OVERRIDE
Retrieves the host window handle.
BOOL ReleaseCapture() OVERRIDE
Releases the mouse capture from the window.
Class representing an XML node.
SXmlNode child(const wchar_t *name, bool bCaseSensitive=false) const
Gets the child node, attribute, or next/previous sibling with the specified name.
Interface for rendering target objects.
HRESULT DrawText(LPCTSTR pszText, int cchLen, LPRECT pRc, UINT uFormat) PURE
Draw text within a rectangle.
HRESULT FillSolidRect(LPCRECT pRect, COLORREF cr) PURE
Fill a rectangle with a solid color.
COLORREF SetTextColor(COLORREF color) PURE
Sets the current text color.
HRESULT MeasureText(LPCTSTR pszText, int cchLen, SIZE *psz) PURE
Measure the size of the text.
void FrameToHost(RECT *rc) SCONST PURE
Converts the rectangle coordinates of the current frame to the final host coordinates.