]>
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"
36 #include "wx/msw/private.h"
38 // ============================================================================
40 // ============================================================================
42 // ----------------------------------------------------------------------------
43 // helpers for wxDateTime <-> SYSTEMTIME conversion
44 // ----------------------------------------------------------------------------
46 static inline void wxFromSystemTime(wxDateTime
*dt
, const SYSTEMTIME
& st
)
49 wx_static_cast(wxDateTime::Month
, wxDateTime::Jan
+ st
.wMonth
- 1),
54 static inline void wxToSystemTime(SYSTEMTIME
*st
, const wxDateTime
& dt
)
56 const wxDateTime::Tm
tm(dt
.GetTm());
59 st
->wMonth
= tm
.mon
- wxDateTime::Jan
+ 1;
66 st
->wMilliseconds
= 0;
69 // ----------------------------------------------------------------------------
70 // wxDatePickerCtrl creation
71 // ----------------------------------------------------------------------------
74 wxDatePickerCtrl::Create(wxWindow
*parent
,
80 const wxValidator
& validator
,
83 // initialize the base class
84 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
87 // create the native control
88 if ( !MSWCreateControl(DATETIMEPICK_CLASS
, _T(""), pos
, size
) )
97 WXDWORD
wxDatePickerCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
99 WXDWORD styleMSW
= wxDatePickerCtrlBase::MSWGetStyle(style
, exstyle
);
101 // for now this is unconditional, but we should support drop down control
102 // style as well later
103 styleMSW
|= DTS_UPDOWN
| DTS_SHORTDATEFORMAT
;
108 // TODO: handle WM_WININICHANGE
110 // ----------------------------------------------------------------------------
111 // wxDatePickerCtrl geometry
112 // ----------------------------------------------------------------------------
114 wxSize
wxDatePickerCtrl::DoGetBestSize() const
116 const int y
= GetCharHeight();
118 return wxSize(DEFAULT_ITEM_WIDTH
, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y
));
121 // ----------------------------------------------------------------------------
122 // wxDatePickerCtrl operations
123 // ----------------------------------------------------------------------------
125 void wxDatePickerCtrl::SetValue(const wxDateTime
& dt
)
127 // as we don't support DTS_SHOWNONE style so far, we don't allow setting
128 // the control to an invalid date, but this restriction may be lifted in
130 wxCHECK_RET( dt
.IsValid(), _T("invalid date") );
133 wxToSystemTime(&st
, dt
);
134 if ( !DateTime_SetSystemtime(GetHwnd(), GDT_VALID
, &st
) )
136 wxLogDebug(_T("DateTime_SetSystemtime() failed"));
140 wxDateTime
wxDatePickerCtrl::GetValue() const
144 if ( DateTime_GetSystemtime(GetHwnd(), &st
) == GDT_VALID
)
146 wxFromSystemTime(&dt
, st
);
152 void wxDatePickerCtrl::SetRange(const wxDateTime
& dt1
, const wxDateTime
& dt2
)
159 wxToSystemTime(&st
[0], dt1
);
165 wxToSystemTime(&st
[1], dt2
);
169 if ( !DateTime_SetRange(GetHwnd(), flags
, st
) )
171 wxLogDebug(_T("DateTime_SetRange() failed"));
175 bool wxDatePickerCtrl::GetRange(wxDateTime
*dt1
, wxDateTime
*dt2
) const
179 DWORD flags
= DateTime_GetRange(GetHwnd(), st
);
182 if ( flags
& GDTR_MIN
)
183 wxFromSystemTime(dt1
, st
[0]);
185 *dt1
= wxDefaultDateTime
;
190 if ( flags
& GDTR_MAX
)
191 wxFromSystemTime(dt2
, st
[1]);
193 *dt2
= wxDefaultDateTime
;
199 // ----------------------------------------------------------------------------
200 // wxDatePickerCtrl events
201 // ----------------------------------------------------------------------------
204 wxDatePickerCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
206 NMHDR
* hdr
= (NMHDR
*)lParam
;
209 case DTN_DATETIMECHANGE
:
210 NMDATETIMECHANGE
*dtch
= (NMDATETIMECHANGE
*)hdr
;
212 if ( dtch
->dwFlags
== GDT_VALID
)
213 wxFromSystemTime(&dt
, dtch
->st
);
215 wxDateEvent
event(this, dt
, wxEVT_DATE_CHANGED
);
216 if ( GetEventHandler()->ProcessEvent(event
) )
223 return wxDatePickerCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);