]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/datectrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/datectrl.cpp
3 // Purpose: wxDatePickerCtrl implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
29 #if wxUSE_DATEPICKCTRL
31 #include "wx/datectrl.h"
33 #define _WX_DEFINE_DATE_EVENTS_
34 #include "wx/dateevt.h"
36 #include "wx/msw/wrapwin.h"
37 #include "wx/msw/wrapcctl.h"
38 #include "wx/msw/private.h"
40 // ============================================================================
42 // ============================================================================
44 // ----------------------------------------------------------------------------
45 // helpers for wxDateTime <-> SYSTEMTIME conversion
46 // ----------------------------------------------------------------------------
48 static inline void wxFromSystemTime(wxDateTime
*dt
, const SYSTEMTIME
& st
)
51 wx_static_cast(wxDateTime::Month
, wxDateTime::Jan
+ st
.wMonth
- 1),
56 static inline void wxToSystemTime(SYSTEMTIME
*st
, const wxDateTime
& dt
)
58 const wxDateTime::Tm
tm(dt
.GetTm());
61 st
->wMonth
= tm
.mon
- wxDateTime::Jan
+ 1;
68 st
->wMilliseconds
= 0;
71 // ----------------------------------------------------------------------------
72 // wxDatePickerCtrl creation
73 // ----------------------------------------------------------------------------
76 wxDatePickerCtrl::Create(wxWindow
*parent
,
82 const wxValidator
& validator
,
85 // initialize the base class
86 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
89 // create the native control
90 if ( !MSWCreateControl(DATETIMEPICK_CLASS
, _T(""), pos
, size
) )
99 WXDWORD
wxDatePickerCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
101 WXDWORD styleMSW
= wxDatePickerCtrlBase::MSWGetStyle(style
, exstyle
);
103 // for now this is unconditional, but we should support drop down control
104 // style as well later
105 styleMSW
|= DTS_UPDOWN
| DTS_SHORTDATEFORMAT
;
110 // TODO: handle WM_WININICHANGE
112 // ----------------------------------------------------------------------------
113 // wxDatePickerCtrl geometry
114 // ----------------------------------------------------------------------------
116 wxSize
wxDatePickerCtrl::DoGetBestSize() const
118 const int y
= GetCharHeight();
120 return wxSize(DEFAULT_ITEM_WIDTH
, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y
));
123 // ----------------------------------------------------------------------------
124 // wxDatePickerCtrl operations
125 // ----------------------------------------------------------------------------
127 void wxDatePickerCtrl::SetValue(const wxDateTime
& dt
)
129 // as we don't support DTS_SHOWNONE style so far, we don't allow setting
130 // the control to an invalid date, but this restriction may be lifted in
132 wxCHECK_RET( dt
.IsValid(), _T("invalid date") );
135 wxToSystemTime(&st
, dt
);
136 if ( !DateTime_SetSystemtime(GetHwnd(), GDT_VALID
, &st
) )
138 wxLogDebug(_T("DateTime_SetSystemtime() failed"));
142 wxDateTime
wxDatePickerCtrl::GetValue() const
146 if ( DateTime_GetSystemtime(GetHwnd(), &st
) == GDT_VALID
)
148 wxFromSystemTime(&dt
, st
);
154 void wxDatePickerCtrl::SetRange(const wxDateTime
& dt1
, const wxDateTime
& dt2
)
161 wxToSystemTime(&st
[0], dt1
);
167 wxToSystemTime(&st
[1], dt2
);
171 if ( !DateTime_SetRange(GetHwnd(), flags
, st
) )
173 wxLogDebug(_T("DateTime_SetRange() failed"));
177 bool wxDatePickerCtrl::GetRange(wxDateTime
*dt1
, wxDateTime
*dt2
) const
181 DWORD flags
= DateTime_GetRange(GetHwnd(), st
);
184 if ( flags
& GDTR_MIN
)
185 wxFromSystemTime(dt1
, st
[0]);
187 *dt1
= wxDefaultDateTime
;
192 if ( flags
& GDTR_MAX
)
193 wxFromSystemTime(dt2
, st
[1]);
195 *dt2
= wxDefaultDateTime
;
201 // ----------------------------------------------------------------------------
202 // wxDatePickerCtrl events
203 // ----------------------------------------------------------------------------
206 wxDatePickerCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
208 NMHDR
* hdr
= (NMHDR
*)lParam
;
211 case DTN_DATETIMECHANGE
:
212 NMDATETIMECHANGE
*dtch
= (NMDATETIMECHANGE
*)hdr
;
214 if ( dtch
->dwFlags
== GDT_VALID
)
215 wxFromSystemTime(&dt
, dtch
->st
);
217 wxDateEvent
event(this, dt
, wxEVT_DATE_CHANGED
);
218 if ( GetEventHandler()->ProcessEvent(event
) )
225 return wxDatePickerCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
228 #endif // wxUSE_DATEPICKCTRL