1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/calctrl.cpp
3 // Purpose: wxCalendarCtrl implementation
4 // Author: Vadim Zeitlin
7 // Copyright: (C) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/wxprec.h"
25 #if wxUSE_CALENDARCTRL
28 #include "wx/msw/wrapwin.h"
29 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
30 #include "wx/msw/private.h"
33 #include "wx/calctrl.h"
35 #include "wx/msw/private/datecontrols.h"
37 IMPLEMENT_DYNAMIC_CLASS(wxCalendarCtrl
, wxControl
)
39 // ============================================================================
41 // ============================================================================
43 // ----------------------------------------------------------------------------
44 // wxCalendarCtrl creation
45 // ----------------------------------------------------------------------------
48 wxCalendarCtrl::Create(wxWindow
*parent
,
56 if ( !wxMSWDateControls::CheckInitialization() )
59 // initialize the base class
60 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
63 // create the native control
64 if ( !MSWCreateControl(MONTHCAL_CLASS
, wxEmptyString
, pos
, size
) )
67 SetDate(dt
.IsValid() ? dt
: wxDateTime::Today());
72 WXDWORD
wxCalendarCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
74 WXDWORD styleMSW
= wxCalendarCtrlBase::MSWGetStyle(style
, exstyle
);
76 // right now we don't support any native styles but we should add wx styles
77 // corresponding to MCS_NOTODAY, MCS_NOTODAYCIRCLE and MCS_WEEKNUMBERS
80 // for compatibility with the other versions, just turn off today display
81 // unconditionally for now
82 styleMSW
|= MCS_NOTODAY
;
87 // TODO: handle WM_WININICHANGE
89 // ----------------------------------------------------------------------------
90 // wxCalendarCtrl geometry
91 // ----------------------------------------------------------------------------
93 wxSize
wxCalendarCtrl::DoGetBestSize() const
96 if ( !GetHwnd() || !MonthCal_GetMinReqRect(GetHwnd(), &rc
) )
98 return wxCalendarCtrlBase::DoGetBestSize();
101 const wxSize best
= wxRectFromRECT(rc
).GetSize() + GetWindowBorderSize();
106 // ----------------------------------------------------------------------------
107 // wxCalendarCtrl operations
108 // ----------------------------------------------------------------------------
110 bool wxCalendarCtrl::SetDate(const wxDateTime
& dt
)
112 wxCHECK_MSG( dt
.IsValid(), false, "invalid date" );
115 wxMSWDateControls::ToSystemTime(&st
, dt
);
116 if ( !MonthCal_SetCurSel(GetHwnd(), &st
) )
118 wxLogDebug(_T("DateTime_SetSystemtime() failed"));
126 wxDateTime
wxCalendarCtrl::GetDate() const
129 if ( !MonthCal_GetCurSel(GetHwnd(), &st
) )
130 return wxDefaultDateTime
;
133 wxMSWDateControls::FromSystemTime(&dt
, st
);
137 bool wxCalendarCtrl::SetDateRange(const wxDateTime
& dt1
, const wxDateTime
& dt2
)
144 wxMSWDateControls::ToSystemTime(&st
[0], dt1
);
150 wxMSWDateControls::ToSystemTime(&st
[1], dt2
);
154 if ( !MonthCal_SetRange(GetHwnd(), flags
, st
) )
156 wxLogDebug(_T("MonthCal_SetRange() failed"));
162 bool wxCalendarCtrl::GetDateRange(wxDateTime
*dt1
, wxDateTime
*dt2
) const
166 DWORD flags
= MonthCal_GetRange(GetHwnd(), st
);
169 if ( flags
& GDTR_MIN
)
170 wxMSWDateControls::FromSystemTime(dt1
, st
[0]);
172 *dt1
= wxDefaultDateTime
;
177 if ( flags
& GDTR_MAX
)
178 wxMSWDateControls::FromSystemTime(dt2
, st
[1]);
180 *dt2
= wxDefaultDateTime
;
186 // ----------------------------------------------------------------------------
187 // other wxCalendarCtrl operations
188 // ----------------------------------------------------------------------------
190 bool wxCalendarCtrl::EnableMonthChange(bool enable
)
192 if ( !wxCalendarCtrlBase::EnableMonthChange(enable
) )
195 wxDateTime dtStart
, dtEnd
;
201 dtEnd
= dtStart
.GetLastMonthDay();
203 //else: leave them invalid to remove the restriction
205 SetDateRange(dtStart
, dtEnd
);
210 void wxCalendarCtrl::Mark(size_t day
, bool mark
)
212 wxFAIL_MSG( "not implemented" );
215 // ----------------------------------------------------------------------------
216 // wxCalendarCtrl events
217 // ----------------------------------------------------------------------------
219 bool wxCalendarCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
221 NMHDR
* hdr
= (NMHDR
*)lParam
;
225 NMSELCHANGE
*sch
= (NMSELCHANGE
*)hdr
;
226 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
231 return wxCalendarCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
234 #endif // wxUSE_CALENDARCTRL