]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/calctrl.cpp
Removed comment
[wxWidgets.git] / src / msw / calctrl.cpp
index 239abf65cae39e83baa225cca7a44b94a9ff8559..cf0de6e22309ea6bcbabbd06715855ffb324ba4e 100644 (file)
 
 IMPLEMENT_DYNAMIC_CLASS(wxCalendarCtrl, wxControl)
 
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+namespace
+{
+
+// values of week days used by the native control
+enum
+{
+    MonthCal_Monday,
+    MonthCal_Tuesday,
+    MonthCal_Wednesday,
+    MonthCal_Thursday,
+    MonthCal_Friday,
+    MonthCal_Saturday,
+    MonthCal_Sunday
+};
+
+} // anonymous namespace
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -96,7 +117,7 @@ wxCalendarCtrl::Create(wxWindow *parent,
     if ( !MSWCreateControl(clsname, wxEmptyString, pos, size) )
         return false;
 
-    // initialize the control 
+    // initialize the control
     UpdateFirstDayOfWeek();
 
     SetDate(dt.IsValid() ? dt : wxDateTime::Today());
@@ -199,7 +220,26 @@ wxCalendarCtrl::HitTest(const wxPoint& pos,
         case MCHT_CALENDARDAY:
             if ( wd )
             {
-                *wd = static_cast<wxDateTime::WeekDay>(hti.st.wDayOfWeek);
+                int day = hti.st.wDayOfWeek;
+
+                // the native control returns incorrect day of the week when
+                // the first day isn't Monday, i.e. the first column is always
+                // "Monday" even if its label is "Sunday", compensate for it
+                const int first = LOWORD(MonthCal_GetFirstDayOfWeek(GetHwnd()));
+                if ( first == MonthCal_Monday )
+                {
+                    // as MonthCal_Monday is 0 while wxDateTime::Mon is 1,
+                    // normally we need to do this to transform from MSW
+                    // convention to wx one
+                    day++;
+                    day %= 7;
+                }
+                //else: but when the first day is MonthCal_Sunday, the native
+                //      control still returns 0 (i.e. MonthCal_Monday) for the
+                //      first column which looks like a bug in it but to work
+                //      around it it's enough to not apply the correction above
+
+                *wd = static_cast<wxDateTime::WeekDay>(day);
             }
             return wxCAL_HITTEST_HEADER;
 
@@ -376,7 +416,9 @@ void wxCalendarCtrl::UpdateMarks()
 
 void wxCalendarCtrl::UpdateFirstDayOfWeek()
 {
-    MonthCal_SetFirstDayOfWeek(GetHwnd(), HasFlag(wxCAL_MONDAY_FIRST) ? 0 : 6);
+    MonthCal_SetFirstDayOfWeek(GetHwnd(),
+                               HasFlag(wxCAL_MONDAY_FIRST) ? MonthCal_Monday
+                                                           : MonthCal_Sunday);
 }
 
 // ----------------------------------------------------------------------------