]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxDateTime::SetFrom/GetAsMSWSysTime() (#9161)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 22 May 2008 00:49:27 +0000 (00:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 22 May 2008 00:49:27 +0000 (00:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53697 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/datetime.h
include/wx/msw/private/datecontrols.h
interface/datetime.h
src/common/datetime.cpp
src/msw/calctrl.cpp
src/msw/datectrl.cpp

index 7677de54eda156e8cfb33cfe2d53144aa8829ad9..3fddea3f9a10f6025349fc2a839d3632d6200d80 100644 (file)
@@ -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)
     // ------------------------------------------------------------------------
 
index b56e2962bc2c23e552fab54767c89ee19604f373..08889d51c51ec5c03956fa10ec88b75deac0290c 100644 (file)
@@ -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_
 
+
index b76b7b70257d1945f56acd3ab30f262bef96e168..ce9810ebb63a1f3b00d9bc30396b221f1131803d 100644 (file)
@@ -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.
     */
index 3d131c9503867dcc1f7cac73ab11e54061759d98..297258a17b9a854f132939ee30d578fb27d71aa2 100644 (file)
@@ -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
index 2f2feb40a4245112786f7fe894c90f9b64bb248e..90faa55f4736a7e3ca6cf250d7797b862c20a41e 100644 (file)
@@ -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
index 27ed885258c4a449227b45307af8166ff3b7eb78..692f0462d4828f1084495232dbc851c45ff616b1 100644 (file)
@@ -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