From: Vadim Zeitlin Date: Thu, 22 May 2008 00:49:27 +0000 (+0000) Subject: added wxDateTime::SetFrom/GetAsMSWSysTime() (#9161) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/154014d68152d7dcca9ee08c593a3d89fc8fe488 added wxDateTime::SetFrom/GetAsMSWSysTime() (#9161) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53697 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/datetime.h b/include/wx/datetime.h index 7677de54ed..3fddea3f9a 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -30,6 +30,9 @@ class WXDLLIMPEXP_FWD_BASE wxDateTime; class WXDLLIMPEXP_FWD_BASE wxTimeSpan; class WXDLLIMPEXP_FWD_BASE wxDateSpan; +#ifdef __WXMSW__ +struct _SYSTEMTIME; +#endif #include "wx/dynarray.h" @@ -598,6 +601,12 @@ public: wxDateTime_t minute = 0, wxDateTime_t second = 0, wxDateTime_t millisec = 0); +#ifdef __WXMSW__ + wxDateTime(const struct _SYSTEMTIME& st) + { + SetFromMSWSysTime(st); + } +#endif // default copy ctor ok @@ -912,6 +921,17 @@ public: // pack the date in DOS format unsigned long GetAsDOS() const; + // SYSTEMTIME format + // ------------------------------------------------------------------------ +#ifdef __WXMSW__ + + // convert SYSTEMTIME to wxDateTime + wxDateTime& SetFromMSWSysTime(const struct _SYSTEMTIME&); + + // convert wxDateTime to SYSTEMTIME + void GetAsMSWSysTime(struct _SYSTEMTIME*) const; +#endif // __WXMSW__ + // comparison (see also functions below for operator versions) // ------------------------------------------------------------------------ diff --git a/include/wx/msw/private/datecontrols.h b/include/wx/msw/private/datecontrols.h index b56e2962bc..08889d51c5 100644 --- a/include/wx/msw/private/datecontrols.h +++ b/include/wx/msw/private/datecontrols.h @@ -24,32 +24,8 @@ namespace wxMSWDateControls // happen with a very old version of common controls DLL, i.e. before 4.70) extern bool CheckInitialization(); -// convert SYSTEMTIME to wxDateTime -inline void FromSystemTime(wxDateTime *dt, const SYSTEMTIME& st) -{ - dt->Set(st.wDay, - wx_static_cast(wxDateTime::Month, wxDateTime::Jan + st.wMonth - 1), - st.wYear, - 0, 0, 0); -} - -// convert wxDateTime to SYSTEMTIME -inline void ToSystemTime(SYSTEMTIME *st, const wxDateTime& dt) -{ - const wxDateTime::Tm tm(dt.GetTm()); - - st->wYear = (WXWORD)tm.year; - st->wMonth = (WXWORD)(tm.mon - wxDateTime::Jan + 1); - st->wDay = tm.mday; - - st->wDayOfWeek = - st->wHour = - st->wMinute = - st->wSecond = - st->wMilliseconds = 0; -} - } // namespace wxMSWDateControls #endif // _MSW_PRIVATE_DATECONTROLS_H_ + diff --git a/interface/datetime.h b/interface/datetime.h index b76b7b7025..ce9810ebb6 100644 --- a/interface/datetime.h +++ b/interface/datetime.h @@ -285,6 +285,17 @@ public: wxDateTime_t minute = 0, wxDateTime_t second = 0, wxDateTime_t millisec = 0); + /** + Same as SetFromMSWSysTime. + + @param st + Input, Windows SYSTEMTIME reference + @since 2.9.0 + @remarks MSW only + */ + wxDateTime(const struct _SYSTEMTIME& st); + + /** Reset time to midnight (00:00:00) without changing the date. */ @@ -410,6 +421,24 @@ public: */ long unsigned int GetAsDOS() const; + /** + Initialize using the Windows SYSTEMTIME structure. + @param st + Input, Windows SYSTEMTIME reference + @since 2.9.0 + @remarks MSW only + */ + wxDateTime& SetFromMSWSysTime(const struct _SYSTEMTIME& st); + + /** + Returns the date and time in the Windows SYSTEMTIME format. + @param st + Output, pointer to Windows SYSTEMTIME + @since 2.9.0 + @remarks MSW only + */ + void GetAsMSWSysTime(struct _SYSTEMTIME* st) const; + /** Returns the century of this date. */ diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 3d131c9503..297258a17b 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -4588,4 +4588,30 @@ WXDLLIMPEXP_BASE void wxPrevWDay(wxDateTime::WeekDay& wd) : (wxDateTime::WeekDay)(wd - 1); } +#ifdef __WXMSW__ + +wxDateTime& wxDateTime::SetFromMSWSysTime(const SYSTEMTIME& st) +{ + return Set(st.wDay, + wx_static_cast(wxDateTime::Month, wxDateTime::Jan + st.wMonth - 1), + st.wYear, + 0, 0, 0); +} + +void wxDateTime::GetAsMSWSysTime(SYSTEMTIME* st) const +{ + const wxDateTime::Tm tm(GetTm()); + + st->wYear = (WXWORD)tm.year; + st->wMonth = (WXWORD)(tm.mon - wxDateTime::Jan + 1); + st->wDay = tm.mday; + + st->wDayOfWeek = + st->wHour = + st->wMinute = + st->wSecond = + st->wMilliseconds = 0; +} +#endif // __WXMSW__ + #endif // wxUSE_DATETIME diff --git a/src/msw/calctrl.cpp b/src/msw/calctrl.cpp index 2f2feb40a4..90faa55f47 100644 --- a/src/msw/calctrl.cpp +++ b/src/msw/calctrl.cpp @@ -177,7 +177,7 @@ wxCalendarCtrl::HitTest(const wxPoint& pos, case MCHT_CALENDARDATE: if ( date ) - wxMSWDateControls::FromSystemTime(date, hti.st); + date->SetFromMSWSysTime(hti.st); return wxCAL_HITTEST_DAY; case MCHT_CALENDARDAY: @@ -208,7 +208,7 @@ bool wxCalendarCtrl::SetDate(const wxDateTime& dt) wxCHECK_MSG( dt.IsValid(), false, "invalid date" ); SYSTEMTIME st; - wxMSWDateControls::ToSystemTime(&st, dt); + dt.GetAsMSWSysTime(&st); if ( !MonthCal_SetCurSel(GetHwnd(), &st) ) { wxLogDebug(_T("DateTime_SetSystemtime() failed")); @@ -232,8 +232,7 @@ wxDateTime wxCalendarCtrl::GetDate() const return wxDefaultDateTime; } - wxDateTime dt; - wxMSWDateControls::FromSystemTime(&dt, st); + wxDateTime dt(st); wxASSERT_MSG( dt == m_date, "mismatch between data and control" ); #endif // __WXDEBUG__ @@ -248,13 +247,13 @@ bool wxCalendarCtrl::SetDateRange(const wxDateTime& dt1, const wxDateTime& dt2) DWORD flags = 0; if ( dt1.IsValid() ) { - wxMSWDateControls::ToSystemTime(&st[0], dt1); + dt1.GetAsMSWSysTime(st + 0); flags |= GDTR_MIN; } if ( dt2.IsValid() ) { - wxMSWDateControls::ToSystemTime(&st[1], dt2); + dt2.GetAsMSWSysTime(st + 1); flags |= GDTR_MAX; } @@ -274,7 +273,7 @@ bool wxCalendarCtrl::GetDateRange(wxDateTime *dt1, wxDateTime *dt2) const if ( dt1 ) { if ( flags & GDTR_MIN ) - wxMSWDateControls::FromSystemTime(dt1, st[0]); + dt1->SetFromMSWSysTime(st[0]); else *dt1 = wxDefaultDateTime; } @@ -282,7 +281,7 @@ bool wxCalendarCtrl::GetDateRange(wxDateTime *dt1, wxDateTime *dt2) const if ( dt2 ) { if ( flags & GDTR_MAX ) - wxMSWDateControls::FromSystemTime(dt2, st[1]); + dt2->SetFromMSWSysTime(st[1]); else *dt2 = wxDefaultDateTime; } @@ -363,7 +362,7 @@ bool wxCalendarCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // which expects GetDate() to return the new date const wxDateTime dateOld = m_date; const NMSELCHANGE * const sch = (NMSELCHANGE *)lParam; - wxMSWDateControls::FromSystemTime(&m_date, sch->stSelStart); + m_date.SetFromMSWSysTime(sch->stSelStart); // changing the year or the month results in a second dummy // MCN_SELCHANGE event on this system which doesn't really diff --git a/src/msw/datectrl.cpp b/src/msw/datectrl.cpp index 27ed885258..692f0462d4 100644 --- a/src/msw/datectrl.cpp +++ b/src/msw/datectrl.cpp @@ -178,7 +178,7 @@ void wxDatePickerCtrl::SetValue(const wxDateTime& dt) SYSTEMTIME st; if ( dt.IsValid() ) - wxMSWDateControls::ToSystemTime(&st, dt); + dt.GetAsMSWSysTime(&st); if ( !DateTime_SetSystemtime(GetHwnd(), dt.IsValid() ? GDT_VALID : GDT_NONE, &st) ) @@ -200,7 +200,7 @@ wxDateTime wxDatePickerCtrl::GetValue() const SYSTEMTIME st; if ( DateTime_GetSystemtime(GetHwnd(), &st) == GDT_VALID ) { - wxMSWDateControls::FromSystemTime(&dt, st); + dt.SetFromMSWSysTime(st); } wxASSERT_MSG( m_date.IsValid() == dt.IsValid() && @@ -218,13 +218,13 @@ void wxDatePickerCtrl::SetRange(const wxDateTime& dt1, const wxDateTime& dt2) DWORD flags = 0; if ( dt1.IsValid() ) { - wxMSWDateControls::ToSystemTime(&st[0], dt1); + dt1.GetAsMSWSysTime(st + 0); flags |= GDTR_MIN; } if ( dt2.IsValid() ) { - wxMSWDateControls::ToSystemTime(&st[1], dt2); + dt2.GetAsMSWSysTime(st + 1); flags |= GDTR_MAX; } @@ -242,7 +242,7 @@ bool wxDatePickerCtrl::GetRange(wxDateTime *dt1, wxDateTime *dt2) const if ( dt1 ) { if ( flags & GDTR_MIN ) - wxMSWDateControls::FromSystemTime(dt1, st[0]); + dt1->SetFromMSWSysTime(st[0]); else *dt1 = wxDefaultDateTime; } @@ -250,7 +250,7 @@ bool wxDatePickerCtrl::GetRange(wxDateTime *dt1, wxDateTime *dt2) const if ( dt2 ) { if ( flags & GDTR_MAX ) - wxMSWDateControls::FromSystemTime(dt2, st[1]); + dt2->SetFromMSWSysTime(st[1]); else *dt2 = wxDefaultDateTime; } @@ -273,7 +273,7 @@ wxDatePickerCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) NMDATETIMECHANGE *dtch = (NMDATETIMECHANGE *)hdr; wxDateTime dt; if ( dtch->dwFlags == GDT_VALID ) - wxMSWDateControls::FromSystemTime(&dt, dtch->st); + dt.SetFromMSWSysTime(dtch->st); // filter out duplicate DTN_DATETIMECHANGE events which the native // control sends us when using wxDP_DROPDOWN style