]>
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 // use wxDP_SPIN if wxDP_DEFAULT (0) was given as style
86 if ( !(style
& wxDP_DROPDOWN
) )
89 // initialize the base class
90 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
93 // create the native control
94 if ( !MSWCreateControl(DATETIMEPICK_CLASS
, _T(""), pos
, size
) )
103 WXDWORD
wxDatePickerCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
105 WXDWORD styleMSW
= wxDatePickerCtrlBase::MSWGetStyle(style
, exstyle
);
107 if ( style
& wxDP_SPIN
)
108 styleMSW
|= DTS_UPDOWN
;
109 //else: drop down by default
111 styleMSW
|= DTS_SHORTDATEFORMAT
;
116 // TODO: handle WM_WININICHANGE
118 // ----------------------------------------------------------------------------
119 // wxDatePickerCtrl geometry
120 // ----------------------------------------------------------------------------
122 wxSize
wxDatePickerCtrl::DoGetBestSize() const
124 const int y
= GetCharHeight();
126 return wxSize(DEFAULT_ITEM_WIDTH
, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y
));
129 // ----------------------------------------------------------------------------
130 // wxDatePickerCtrl operations
131 // ----------------------------------------------------------------------------
133 void wxDatePickerCtrl::SetValue(const wxDateTime
& dt
)
135 // as we don't support DTS_SHOWNONE style so far, we don't allow setting
136 // the control to an invalid date, but this restriction may be lifted in
138 wxCHECK_RET( dt
.IsValid(), _T("invalid date") );
141 wxToSystemTime(&st
, dt
);
142 if ( !DateTime_SetSystemtime(GetHwnd(), GDT_VALID
, &st
) )
144 wxLogDebug(_T("DateTime_SetSystemtime() failed"));
148 wxDateTime
wxDatePickerCtrl::GetValue() const
152 if ( DateTime_GetSystemtime(GetHwnd(), &st
) == GDT_VALID
)
154 wxFromSystemTime(&dt
, st
);
160 void wxDatePickerCtrl::SetRange(const wxDateTime
& dt1
, const wxDateTime
& dt2
)
167 wxToSystemTime(&st
[0], dt1
);
173 wxToSystemTime(&st
[1], dt2
);
177 if ( !DateTime_SetRange(GetHwnd(), flags
, st
) )
179 wxLogDebug(_T("DateTime_SetRange() failed"));
183 bool wxDatePickerCtrl::GetRange(wxDateTime
*dt1
, wxDateTime
*dt2
) const
187 DWORD flags
= DateTime_GetRange(GetHwnd(), st
);
190 if ( flags
& GDTR_MIN
)
191 wxFromSystemTime(dt1
, st
[0]);
193 *dt1
= wxDefaultDateTime
;
198 if ( flags
& GDTR_MAX
)
199 wxFromSystemTime(dt2
, st
[1]);
201 *dt2
= wxDefaultDateTime
;
207 // ----------------------------------------------------------------------------
208 // wxDatePickerCtrl events
209 // ----------------------------------------------------------------------------
212 wxDatePickerCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
214 NMHDR
* hdr
= (NMHDR
*)lParam
;
217 case DTN_DATETIMECHANGE
:
218 NMDATETIMECHANGE
*dtch
= (NMDATETIMECHANGE
*)hdr
;
220 if ( dtch
->dwFlags
== GDT_VALID
)
221 wxFromSystemTime(&dt
, dtch
->st
);
223 wxDateEvent
event(this, dt
, wxEVT_DATE_CHANGED
);
224 if ( GetEventHandler()->ProcessEvent(event
) )
231 return wxDatePickerCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
234 #endif // wxUSE_DATEPICKCTRL