]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/datetimectrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/datetimectrl.cpp
3 // Purpose: Implementation of wxDateTimePickerCtrl for MSW.
4 // Author: Vadim Zeitlin
5 // Created: 2011-09-22 (extracted from src/msw/datectrl.cpp)
6 // Copyright: (c) 2005-2011 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
25 #include "wx/datetimectrl.h"
27 #ifdef wxNEEDS_DATETIMEPICKCTRL
30 #include "wx/msw/wrapwin.h"
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/private.h"
33 #include "wx/dcclient.h"
36 #include "wx/msw/private/datecontrols.h"
38 // apparently some versions of mingw define these macros erroneously
39 #ifndef DateTime_GetSystemtime
40 #define DateTime_GetSystemtime DateTime_GetSystemTime
43 #ifndef DateTime_SetSystemtime
44 #define DateTime_SetSystemtime DateTime_SetSystemTime
47 // ============================================================================
48 // wxDateTimePickerCtrl implementation
49 // ============================================================================
52 wxDateTimePickerCtrl::MSWCreateDateTimePicker(wxWindow
*parent
,
58 const wxValidator
& validator
,
61 if ( !wxMSWDateControls::CheckInitialization() )
64 // initialize the base class
65 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
68 // create the native control
69 if ( !MSWCreateControl(DATETIMEPICK_CLASS
, wxString(), pos
, size
) )
72 if ( dt
.IsValid() || MSWAllowsNone() )
75 SetValue(wxDateTime::Now());
80 void wxDateTimePickerCtrl::SetValue(const wxDateTime
& dt
)
82 wxCHECK_RET( dt
.IsValid() || MSWAllowsNone(),
83 wxT("this control requires a valid date") );
87 dt
.GetAsMSWSysTime(&st
);
89 if ( !DateTime_SetSystemtime(GetHwnd(),
90 dt
.IsValid() ? GDT_VALID
: GDT_NONE
,
93 // The only expected failure is when the date is out of range but we
94 // already checked for this above.
95 wxFAIL_MSG( wxT("Setting the calendar date unexpectedly failed.") );
97 // In any case, skip updating m_date below.
104 wxDateTime
wxDateTimePickerCtrl::GetValue() const
109 wxSize
wxDateTimePickerCtrl::DoGetBestSize() const
111 wxClientDC
dc(const_cast<wxDateTimePickerCtrl
*>(this));
113 // Use the same native format as this as the underlying native control.
114 wxString s
= wxDateTime::Now().Format(wxLocale::GetInfo(MSWGetFormat()));
116 // the best size for the control is bigger than just the string
117 // representation of the current value because the control must accommodate
118 // any date and while the widths of all digits are usually about the same,
119 // the width of the month string varies a lot, so try to account for it
123 dc
.GetTextExtent(s
, &x
, &y
);
125 // account for the drop-down arrow or spin arrows
126 x
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X
);
128 // and for the checkbox if we have it
129 if ( MSWAllowsNone() )
130 x
+= 3*GetCharWidth();
132 wxSize
best(x
, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y
));
138 wxDateTimePickerCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
140 NMHDR
* hdr
= (NMHDR
*)lParam
;
143 case DTN_DATETIMECHANGE
:
144 if ( MSWOnDateTimeChange(*(NMDATETIMECHANGE
*)(hdr
)) )
152 return wxDateTimePickerCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
155 #endif // wxNEEDS_DATETIMEPICKCTRL