]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/calctrl.cpp
Don't send event from ChangeValue
[wxWidgets.git] / src / msw / calctrl.cpp
index 69c5abeb6b858d51e3b59d4ab9a6bd765a822660..37bd62296f4cd327c1a38c68670583c76abea863 100644 (file)
@@ -56,6 +56,9 @@ wxCalendarCtrl::Create(wxWindow *parent,
     if ( !wxMSWDateControls::CheckInitialization() )
         return false;
 
+    // we need the arrows for the navigation
+    style |= wxWANTS_CHARS;
+
     // initialize the base class
     if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
         return false;
@@ -87,10 +90,15 @@ wxCalendarCtrl::Create(wxWindow *parent,
     if ( !MSWCreateControl(clsname, wxEmptyString, pos, size) )
         return false;
 
+    // initialize the control 
+    UpdateFirstDayOfWeek();
+
     SetDate(dt.IsValid() ? dt : wxDateTime::Today());
 
     UpdateMarks();
 
+    Connect(wxEVT_LEFT_DOWN,
+            wxMouseEventHandler(wxCalendarCtrl::MSWOnClick));
     Connect(wxEVT_LEFT_DCLICK,
             wxMouseEventHandler(wxCalendarCtrl::MSWOnDoubleClick));
 
@@ -115,12 +123,21 @@ WXDWORD wxCalendarCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const
     return styleMSW;
 }
 
-// TODO: handle WM_WININICHANGE
+void wxCalendarCtrl::SetWindowStyleFlag(long style)
+{
+    const bool hadMondayFirst = HasFlag(wxCAL_MONDAY_FIRST);
+
+    wxCalendarCtrlBase::SetWindowStyleFlag(style);
+
+    if ( HasFlag(wxCAL_MONDAY_FIRST) != hadMondayFirst )
+        UpdateFirstDayOfWeek();
+}
 
 // ----------------------------------------------------------------------------
 // wxCalendarCtrl geometry
 // ----------------------------------------------------------------------------
 
+// TODO: handle WM_WININICHANGE
 wxSize wxCalendarCtrl::DoGetBestSize() const
 {
     RECT rc;
@@ -313,7 +330,7 @@ void wxCalendarCtrl::UpdateMarks()
 {
     MONTHDAYSTATE states[3];
     const int nMonths = MonthCal_GetMonthRange(GetHwnd(), GMR_DAYSTATE, NULL);
-    wxCHECK_RET( nMonths <= WXSIZEOF(states), "unexpected months range" );
+    wxCHECK_RET( nMonths <= (int)WXSIZEOF(states), "unexpected months range" );
 
     for ( int i = 0; i < nMonths; i++ )
         states[i] = m_marks;
@@ -324,6 +341,11 @@ void wxCalendarCtrl::UpdateMarks()
     }
 }
 
+void wxCalendarCtrl::UpdateFirstDayOfWeek()
+{
+    MonthCal_SetFirstDayOfWeek(GetHwnd(), HasFlag(wxCAL_MONDAY_FIRST) ? 0 : 6);
+}
+
 // ----------------------------------------------------------------------------
 // wxCalendarCtrl events
 // ----------------------------------------------------------------------------
@@ -380,4 +402,13 @@ void wxCalendarCtrl::MSWOnDoubleClick(wxMouseEvent& event)
     event.Skip();
 }
 
+void wxCalendarCtrl::MSWOnClick(wxMouseEvent& event)
+{
+    // for some reason, the control doesn't get focus on its own when the user
+    // clicks in it
+    SetFocus();
+
+    event.Skip();
+}
+
 #endif // wxUSE_CALENDARCTRL