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;
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));
return true;
// unconditionally for now
styleMSW |= MCS_NOTODAY;
+ // we also need this style for Mark() to work
+ styleMSW |= MCS_DAYSTATE;
+
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;
void wxCalendarCtrl::Mark(size_t day, bool mark)
{
- wxFAIL_MSG( "not implemented" );
+ wxCHECK_RET( day > 0 && day < 32, "invalid day" );
+
+ int mask = 1 << (day - 1);
+ if ( mark )
+ m_marks |= mask;
+ else
+ m_marks &= ~mask;
+
+ // calling Refresh() here is not enough to change the day appearance
+ UpdateMarks();
+}
+
+void wxCalendarCtrl::UpdateMarks()
+{
+ MONTHDAYSTATE states[3];
+ const int nMonths = MonthCal_GetMonthRange(GetHwnd(), GMR_DAYSTATE, NULL);
+ wxCHECK_RET( nMonths <= (int)WXSIZEOF(states), "unexpected months range" );
+
+ for ( int i = 0; i < nMonths; i++ )
+ states[i] = m_marks;
+
+ if ( !MonthCal_SetDayState(GetHwnd(), nMonths, states) )
+ {
+ wxLogLastError(_T("MonthCal_SetDayState"));
+ }
+}
+
+void wxCalendarCtrl::UpdateFirstDayOfWeek()
+{
+ MonthCal_SetFirstDayOfWeek(GetHwnd(), HasFlag(wxCAL_MONDAY_FIRST) ? 0 : 6);
}
// ----------------------------------------------------------------------------
switch ( hdr->code )
{
case MCN_SELCHANGE:
- // we need to update m_date first, before calling the user code
- // 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);
-
- // changing the year or the month results in a second dummy
- // MCN_SELCHANGE event on this system which doesn't really change
- // anything -- filter it out
- if ( m_date != dateOld )
{
- GenerateAllChangeEvents(dateOld);
+ // we need to update m_date first, before calling the user code
+ // 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);
+
+ // changing the year or the month results in a second dummy
+ // MCN_SELCHANGE event on this system which doesn't really
+ // change anything -- filter it out
+ if ( m_date != dateOld )
+ {
+ GenerateAllChangeEvents(dateOld);
+ }
+ }
+ break;
- *result = 0;
- return true;
+ case MCN_GETDAYSTATE:
+ {
+ const NMDAYSTATE * const ds = (NMDAYSTATE *)lParam;
+ for ( int i = 0; i < ds->cDayState; i++ )
+ {
+ ds->prgDayState[i] = m_marks;
+ }
}
+ break;
+
+ default:
+ return wxCalendarCtrlBase::MSWOnNotify(idCtrl, lParam, result);
}
- return wxCalendarCtrlBase::MSWOnNotify(idCtrl, lParam, result);
+ *result = 0;
+ return true;
}
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