]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/datetimectrl.cpp
320da622b0685512850f38ceaf967a9557cf0579
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
31 #include "wx/msw/wrapwin.h"
32 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
33 #include "wx/msw/private.h"
34 #include "wx/dcclient.h"
37 #include "wx/msw/private/datecontrols.h"
39 // apparently some versions of mingw define these macros erroneously
40 #ifndef DateTime_GetSystemtime
41 #define DateTime_GetSystemtime DateTime_GetSystemTime
44 #ifndef DateTime_SetSystemtime
45 #define DateTime_SetSystemtime DateTime_SetSystemTime
48 // ============================================================================
49 // wxDateTimePickerCtrl implementation
50 // ============================================================================
53 wxDateTimePickerCtrl::MSWCreateDateTimePicker(wxWindow
*parent
,
59 const wxValidator
& validator
,
62 if ( !wxMSWDateControls::CheckInitialization() )
65 // initialize the base class
66 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
69 // create the native control
70 if ( !MSWCreateControl(DATETIMEPICK_CLASS
, wxString(), pos
, size
) )
73 if ( dt
.IsValid() || MSWAllowsNone() )
76 SetValue(wxDateTime::Now());
81 void wxDateTimePickerCtrl::SetValue(const wxDateTime
& dt
)
83 wxCHECK_RET( dt
.IsValid() || MSWAllowsNone(),
84 wxT("this control requires a valid date") );
88 dt
.GetAsMSWSysTime(&st
);
90 if ( !DateTime_SetSystemtime(GetHwnd(),
91 dt
.IsValid() ? GDT_VALID
: GDT_NONE
,
94 // The only expected failure is when the date is out of range but we
95 // already checked for this above.
96 wxFAIL_MSG( wxT("Setting the calendar date unexpectedly failed.") );
98 // In any case, skip updating m_date below.
105 wxDateTime
wxDateTimePickerCtrl::GetValue() const
110 wxSize
wxDateTimePickerCtrl::DoGetBestSize() const
112 wxClientDC
dc(const_cast<wxDateTimePickerCtrl
*>(this));
114 // Use the same native format as this as the underlying native control.
115 wxString s
= wxDateTime::Now().Format(wxLocale::GetInfo(MSWGetFormat()));
117 // the best size for the control is bigger than just the string
118 // representation of the current value because the control must accommodate
119 // any date and while the widths of all digits are usually about the same,
120 // the width of the month string varies a lot, so try to account for it
124 dc
.GetTextExtent(s
, &x
, &y
);
126 // account for the drop-down arrow or spin arrows
127 x
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X
);
129 // and for the checkbox if we have it
130 if ( MSWAllowsNone() )
131 x
+= 3*GetCharWidth();
133 wxSize
best(x
, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y
));
139 wxDateTimePickerCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
141 NMHDR
* hdr
= (NMHDR
*)lParam
;
144 case DTN_DATETIMECHANGE
:
145 if ( MSWOnDateTimeChange(*(NMDATETIMECHANGE
*)(hdr
)) )
153 return wxDateTimePickerCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
156 #endif // wxNEEDS_DATETIMEPICKCTRL