]>
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 // RCS-ID: $Id: wxhead.cpp,v 1.11 2010-04-22 12:44:51 zeitlin Exp $
7 // Copyright: (c) 2005-2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/datetimectrl.h"
28 #ifdef wxNEEDS_DATETIMEPICKCTRL
33 #include "wx/msw/private/datecontrols.h"
35 // apparently some versions of mingw define these macros erroneously
36 #ifndef DateTime_GetSystemtime
37 #define DateTime_GetSystemtime DateTime_GetSystemTime
40 #ifndef DateTime_SetSystemtime
41 #define DateTime_SetSystemtime DateTime_SetSystemTime
44 // ============================================================================
45 // wxDateTimePickerCtrl implementation
46 // ============================================================================
49 wxDateTimePickerCtrl::MSWCreateDateTimePicker(wxWindow
*parent
,
55 const wxValidator
& validator
,
58 if ( !wxMSWDateControls::CheckInitialization() )
61 // initialize the base class
62 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
65 // create the native control
66 if ( !MSWCreateControl(DATETIMEPICK_CLASS
, wxString(), pos
, size
) )
69 if ( dt
.IsValid() || MSWAllowsNone() )
72 SetValue(wxDateTime::Now());
77 void wxDateTimePickerCtrl::SetValue(const wxDateTime
& dt
)
79 wxCHECK_RET( dt
.IsValid() || MSWAllowsNone(),
80 wxT("this control requires a valid date") );
84 dt
.GetAsMSWSysTime(&st
);
86 if ( !DateTime_SetSystemtime(GetHwnd(),
87 dt
.IsValid() ? GDT_VALID
: GDT_NONE
,
90 // The only expected failure is when the date is out of range but we
91 // already checked for this above.
92 wxFAIL_MSG( wxT("Setting the calendar date unexpectedly failed.") );
94 // In any case, skip updating m_date below.
101 wxDateTime
wxDateTimePickerCtrl::GetValue() const
106 wxSize
wxDateTimePickerCtrl::DoGetBestSize() const
108 wxClientDC
dc(const_cast<wxDateTimePickerCtrl
*>(this));
110 // Use the same native format as this as the underlying native control.
111 wxString s
= wxDateTime::Now().Format(wxLocale::GetInfo(MSWGetFormat()));
113 // the best size for the control is bigger than just the string
114 // representation of the current value because the control must accommodate
115 // any date and while the widths of all digits are usually about the same,
116 // the width of the month string varies a lot, so try to account for it
120 dc
.GetTextExtent(s
, &x
, &y
);
122 // account for the drop-down arrow or spin arrows
123 x
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X
);
125 // and for the checkbox if we have it
126 if ( MSWAllowsNone() )
127 x
+= 3*GetCharWidth();
129 wxSize
best(x
, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y
));
135 wxDateTimePickerCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
137 NMHDR
* hdr
= (NMHDR
*)lParam
;
140 case DTN_DATETIMECHANGE
:
141 if ( MSWOnDateTimeChange(*(NMDATETIMECHANGE
*)(hdr
)) )
149 return wxDateTimePickerCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
152 #endif // wxNEEDS_DATETIMEPICKCTRL