]>
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 #include "wx/datectrl.h"
31 #define _WX_DEFINE_DATE_EVENTS_
32 #include "wx/dateevt.h"
34 #include "wx/msw/wrapwin.h"
35 #include "wx/msw/wrapcctl.h"
37 // ============================================================================
39 // ============================================================================
41 // ----------------------------------------------------------------------------
42 // helpers for wxDateTime <-> SYSTEMTIME conversion
43 // ----------------------------------------------------------------------------
45 static inline void wxFromSystemTime(wxDateTime
*dt
, const SYSTEMTIME
& st
)
48 wx_static_cast(wxDateTime::Month
, wxDateTime::Jan
+ st
.wMonth
- 1),
53 static inline void wxToSystemTime(SYSTEMTIME
*st
, const wxDateTime
& dt
)
55 const wxDateTime::Tm
tm(dt
.GetTm());
58 st
->wMonth
= tm
.mon
- wxDateTime::Jan
+ 1;
65 st
->wMilliseconds
= 0;
68 // ----------------------------------------------------------------------------
69 // wxDatePickerCtrl creation
70 // ----------------------------------------------------------------------------
73 wxDatePickerCtrl::Create(wxWindow
*parent
,
79 const wxValidator
& validator
,
82 // initialize the base class
83 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
86 // create the native control
87 if ( !MSWCreateControl(DATETIMEPICK_CLASS
, _T(""), pos
, size
) )
96 WXDWORD
wxDatePickerCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
98 WXDWORD styleMSW
= wxDatePickerCtrlBase::MSWGetStyle(style
, exstyle
);
100 // for now this is unconditional, but we should support drop down control
101 // style as well later
102 styleMSW
|= DTS_UPDOWN
| DTS_SHORTDATEFORMAT
;
107 // TODO: handle WM_WININICHANGE
109 // ----------------------------------------------------------------------------
110 // wxDatePickerCtrl geometry
111 // ----------------------------------------------------------------------------
113 wxSize
wxDatePickerCtrl::DoGetBestSize() const
115 const int y
= GetCharHeight();
117 return wxSize(DEFAULT_ITEM_WIDTH
, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y
));
120 // ----------------------------------------------------------------------------
121 // wxDatePickerCtrl operations
122 // ----------------------------------------------------------------------------
124 void wxDatePickerCtrl::SetValue(const wxDateTime
& dt
)
126 // as we don't support DTS_SHOWNONE style so far, we don't allow setting
127 // the control to an invalid date, but this restriction may be lifted in
129 wxCHECK_RET( dt
.IsValid(), _T("invalid date") );
132 wxToSystemTime(&st
, dt
);
133 if ( !DateTime_SetSystemtime(GetHwnd(), GDT_VALID
, &st
) )
135 wxLogDebug(_T("DateTime_SetSystemtime() failed"));
139 wxDateTime
wxDatePickerCtrl::GetValue() const
143 if ( DateTime_GetSystemtime(GetHwnd(), &st
) == GDT_VALID
)
145 wxFromSystemTime(&dt
, st
);
151 void wxDatePickerCtrl::SetRange(const wxDateTime
& dt1
, const wxDateTime
& dt2
)
158 wxToSystemTime(&st
[0], dt1
);
164 wxToSystemTime(&st
[1], dt2
);
168 if ( !DateTime_SetRange(GetHwnd(), flags
, st
) )
170 wxLogDebug(_T("DateTime_SetRange() failed"));
174 bool wxDatePickerCtrl::GetRange(wxDateTime
*dt1
, wxDateTime
*dt2
) const
178 DWORD flags
= DateTime_GetRange(GetHwnd(), st
);
181 if ( flags
& GDTR_MIN
)
182 wxFromSystemTime(dt1
, st
[0]);
184 *dt1
= wxDefaultDateTime
;
189 if ( flags
& GDTR_MAX
)
190 wxFromSystemTime(dt2
, st
[1]);
192 *dt2
= wxDefaultDateTime
;
198 // ----------------------------------------------------------------------------
199 // wxDatePickerCtrl events
200 // ----------------------------------------------------------------------------
203 wxDatePickerCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
205 NMHDR
* hdr
= (NMHDR
*)lParam
;
208 case DTN_DATETIMECHANGE
:
209 NMDATETIMECHANGE
*dtch
= (NMDATETIMECHANGE
*)hdr
;
211 if ( dtch
->dwFlags
== GDT_VALID
)
212 wxFromSystemTime(&dt
, dtch
->st
);
214 wxDateEvent
event(this, dt
, wxEVT_DATE_CHANGED
);
215 if ( GetEventHandler()->ProcessEvent(event
) )
222 return wxDatePickerCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);