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"
32 #include "wx/calctrl.h"
34 #include "wx/msw/private/datecontrols.h"
36 IMPLEMENT_DYNAMIC_CLASS(wxCalendarCtrl
, wxControl
)
38 // ============================================================================
40 // ============================================================================
42 // ----------------------------------------------------------------------------
43 // wxCalendarCtrl creation
44 // ----------------------------------------------------------------------------
47 wxCalendarCtrl::Create(wxWindow
*parent
,
55 if ( !wxMSWDateControls::CheckInitialization() )
58 // initialize the base class
59 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
62 // create the native control
63 if ( !MSWCreateControl(MONTHCAL_CLASS
, wxEmptyString
, pos
, size
) )
66 SetDate(dt
.IsValid() ? dt
: wxDateTime::Today());
71 WXDWORD
wxCalendarCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
73 WXDWORD styleMSW
= wxCalendarCtrlBase::MSWGetStyle(style
, exstyle
);
75 // right now we don't support any native styles but we should add wx styles
76 // corresponding to MCS_NOTODAY, MCS_NOTODAYCIRCLE and MCS_WEEKNUMBERS
79 // for compatibility with the other versions, just turn off today display
80 // unconditionally for now
81 styleMSW
|= MCS_NOTODAY
;
86 // TODO: handle WM_WININICHANGE
88 // ----------------------------------------------------------------------------
89 // wxCalendarCtrl geometry
90 // ----------------------------------------------------------------------------
92 wxSize
wxCalendarCtrl::DoGetBestSize() const
95 if ( !GetHwnd() || !MonthCal_GetMinReqRect(GetHwnd(), &rc
) )
97 return wxCalendarCtrlBase::DoGetBestSize();
100 const wxSize best
= wxRectFromRECT(rc
).GetSize() + GetWindowBorderSize();
105 // ----------------------------------------------------------------------------
106 // wxCalendarCtrl operations
107 // ----------------------------------------------------------------------------
109 bool wxCalendarCtrl::SetDate(const wxDateTime
& dt
)
111 wxCHECK_MSG( dt
.IsValid(), false, "invalid date" );
114 wxMSWDateControls::ToSystemTime(&st
, dt
);
115 if ( !MonthCal_SetCurSel(GetHwnd(), &st
) )
117 wxLogDebug(_T("DateTime_SetSystemtime() failed"));
125 wxDateTime
wxCalendarCtrl::GetDate() const
128 if ( !MonthCal_GetCurSel(GetHwnd(), &st
) )
129 return wxDefaultDateTime
;
132 wxMSWDateControls::FromSystemTime(&dt
, st
);
136 bool wxCalendarCtrl::SetDateRange(const wxDateTime
& dt1
, const wxDateTime
& dt2
)
143 wxMSWDateControls::ToSystemTime(&st
[0], dt1
);
149 wxMSWDateControls::ToSystemTime(&st
[1], dt2
);
153 if ( !MonthCal_SetRange(GetHwnd(), flags
, st
) )
155 wxLogDebug(_T("MonthCal_SetRange() failed"));
161 bool wxCalendarCtrl::GetDateRange(wxDateTime
*dt1
, wxDateTime
*dt2
) const
165 DWORD flags
= MonthCal_GetRange(GetHwnd(), st
);
168 if ( flags
& GDTR_MIN
)
169 wxMSWDateControls::FromSystemTime(dt1
, st
[0]);
171 *dt1
= wxDefaultDateTime
;
176 if ( flags
& GDTR_MAX
)
177 wxMSWDateControls::FromSystemTime(dt2
, st
[1]);
179 *dt2
= wxDefaultDateTime
;
185 // ----------------------------------------------------------------------------
186 // other wxCalendarCtrl operations
187 // ----------------------------------------------------------------------------
189 bool wxCalendarCtrl::EnableMonthChange(bool enable
)
191 wxFAIL_MSG( "not implemented" );
196 void wxCalendarCtrl::Mark(size_t day
, bool mark
)
198 wxFAIL_MSG( "not implemented" );
201 // ----------------------------------------------------------------------------
202 // wxCalendarCtrl events
203 // ----------------------------------------------------------------------------
205 bool wxCalendarCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
207 NMHDR
* hdr
= (NMHDR
*)lParam
;
211 NMSELCHANGE
*sch
= (NMSELCHANGE
*)hdr
;
212 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
217 return wxCalendarCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
220 #endif // wxUSE_CALENDARCTRL