]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/calctrl.cpp
Handle the case of NSNotFound result properly.
[wxWidgets.git] / src / msw / calctrl.cpp
index 5618ebf93334a058212151226357c69ba1ad9b4d..cf0de6e22309ea6bcbabbd06715855ffb324ba4e 100644 (file)
@@ -117,7 +117,7 @@ wxCalendarCtrl::Create(wxWindow *parent,
     if ( !MSWCreateControl(clsname, wxEmptyString, pos, size) )
         return false;
 
     if ( !MSWCreateControl(clsname, wxEmptyString, pos, size) )
         return false;
 
-    // initialize the control 
+    // initialize the control
     UpdateFirstDayOfWeek();
 
     SetDate(dt.IsValid() ? dt : wxDateTime::Today());
     UpdateFirstDayOfWeek();
 
     SetDate(dt.IsValid() ? dt : wxDateTime::Today());
@@ -220,7 +220,26 @@ wxCalendarCtrl::HitTest(const wxPoint& pos,
         case MCHT_CALENDARDAY:
             if ( wd )
             {
         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;
 
             }
             return wxCAL_HITTEST_HEADER;