added support for wxDP_ALLOWNONE in wxMSW; documented it; added test for it in the sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31987 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
b29ca6c2fe
commit
3200f37d25
@ -44,6 +44,9 @@ calendar drop down part from which the user can select a date.}
|
|||||||
\twocolitem{\windowstyle{wxDP\_DEFAULT}}{Creates a control with default style
|
\twocolitem{\windowstyle{wxDP\_DEFAULT}}{Creates a control with default style
|
||||||
which is the best supported for the current platform (currently wxDP\_SPIN
|
which is the best supported for the current platform (currently wxDP\_SPIN
|
||||||
under Windows and wxDP\_DROPDOWN elsewhere).}
|
under Windows and wxDP\_DROPDOWN elsewhere).}
|
||||||
|
\twocolitem{\windowstyle{wxDP\_ALLOWNONE}}{With this style, the control allows
|
||||||
|
the user to not enter any valid date at all. Without it -- which is by default
|
||||||
|
-- the control always has some valid date.}
|
||||||
\twocolitem{\windowstyle{wxDP\_SHOWCENTURY}}{Forces display of the century in
|
\twocolitem{\windowstyle{wxDP\_SHOWCENTURY}}{Forces display of the century in
|
||||||
the default date format. Without this flas the century could be displayed or
|
the default date format. Without this flas the century could be displayed or
|
||||||
not depending on the default date representation in the system.}
|
not depending on the default date representation in the system.}
|
||||||
|
@ -53,6 +53,12 @@
|
|||||||
#endif // wxUSE_DATEPICKCTRL_GENERIC
|
#endif // wxUSE_DATEPICKCTRL_GENERIC
|
||||||
#endif // wxUSE_DATEPICKCTRL
|
#endif // wxUSE_DATEPICKCTRL
|
||||||
|
|
||||||
|
// the application icon (under Windows and OS/2 it is in resources and even
|
||||||
|
// though we could still include the XPM here it would be unused)
|
||||||
|
#if !defined(__WXMSW__) && !defined(__WXPM__)
|
||||||
|
#include "../sample.xpm"
|
||||||
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// private classes
|
// private classes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -181,6 +187,7 @@ enum
|
|||||||
Calendar_DatePicker_AskDate = 300,
|
Calendar_DatePicker_AskDate = 300,
|
||||||
Calendar_DatePicker_ShowCentury,
|
Calendar_DatePicker_ShowCentury,
|
||||||
Calendar_DatePicker_DropDown,
|
Calendar_DatePicker_DropDown,
|
||||||
|
Calendar_DatePicker_AllowNone,
|
||||||
#if wxUSE_DATEPICKCTRL_GENERIC
|
#if wxUSE_DATEPICKCTRL_GENERIC
|
||||||
Calendar_DatePicker_Generic,
|
Calendar_DatePicker_Generic,
|
||||||
#endif // wxUSE_DATEPICKCTRL_GENERIC
|
#endif // wxUSE_DATEPICKCTRL_GENERIC
|
||||||
@ -274,6 +281,9 @@ bool MyApp::OnInit()
|
|||||||
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||||
: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
|
: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
|
||||||
{
|
{
|
||||||
|
// set the frame icon
|
||||||
|
SetIcon(wxICON(sample));
|
||||||
|
|
||||||
// create a menu bar
|
// create a menu bar
|
||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuFile = new wxMenu;
|
||||||
menuFile->Append(Calendar_File_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
|
menuFile->Append(Calendar_File_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
|
||||||
@ -316,6 +326,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
_T("Al&ways show century"));
|
_T("Al&ways show century"));
|
||||||
menuDate->AppendCheckItem(Calendar_DatePicker_DropDown,
|
menuDate->AppendCheckItem(Calendar_DatePicker_DropDown,
|
||||||
_T("Use &drop down control"));
|
_T("Use &drop down control"));
|
||||||
|
menuDate->AppendCheckItem(Calendar_DatePicker_AllowNone,
|
||||||
|
_T("Allow &no date"));
|
||||||
#if wxUSE_DATEPICKCTRL_GENERIC
|
#if wxUSE_DATEPICKCTRL_GENERIC
|
||||||
menuDate->AppendCheckItem(Calendar_DatePicker_Generic,
|
menuDate->AppendCheckItem(Calendar_DatePicker_Generic,
|
||||||
_T("Use &generic version of the control"));
|
_T("Use &generic version of the control"));
|
||||||
@ -436,22 +448,31 @@ void MyFrame::OnAskDate(wxCommandEvent& WXUNUSED(event))
|
|||||||
style |= wxDP_SHOWCENTURY;
|
style |= wxDP_SHOWCENTURY;
|
||||||
if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown) )
|
if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown) )
|
||||||
style |= wxDP_DROPDOWN;
|
style |= wxDP_DROPDOWN;
|
||||||
|
if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone) )
|
||||||
|
style |= wxDP_ALLOWNONE;
|
||||||
|
|
||||||
MyDialog dlg(this, m_panel->GetCal()->GetDate(), style);
|
MyDialog dlg(this, m_panel->GetCal()->GetDate(), style);
|
||||||
if ( dlg.ShowModal() == wxID_OK )
|
if ( dlg.ShowModal() == wxID_OK )
|
||||||
{
|
{
|
||||||
const wxDateTime dt = dlg.GetDate(),
|
const wxDateTime dt = dlg.GetDate();
|
||||||
today = wxDateTime::Today();
|
if ( dt.IsValid() )
|
||||||
|
|
||||||
if ( dt.GetDay() == today.GetDay() &&
|
|
||||||
dt.GetMonth() == today.GetMonth() )
|
|
||||||
{
|
{
|
||||||
wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
|
const wxDateTime today = wxDateTime::Today();
|
||||||
|
|
||||||
|
if ( dt.GetDay() == today.GetDay() &&
|
||||||
|
dt.GetMonth() == today.GetMonth() )
|
||||||
|
{
|
||||||
|
wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_panel->GetCal()->SetDate(dt);
|
||||||
|
|
||||||
|
wxLogStatus(_T("Changed the date to your input"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogStatus(_T("No date entered"));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_panel->GetCal()->SetDate(dt);
|
|
||||||
|
|
||||||
wxLogStatus(_T("Changed the date to your birthday"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,13 +40,22 @@
|
|||||||
#include "wx/msw/wrapcctl.h"
|
#include "wx/msw/wrapcctl.h"
|
||||||
#include "wx/msw/private.h"
|
#include "wx/msw/private.h"
|
||||||
|
|
||||||
#if defined(__GNUWIN32__) && ! wxCHECK_W32API_VERSION( 2, 4 )
|
#if defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 2, 4 )
|
||||||
typedef struct tagNMDATETIMECHANGE
|
typedef struct tagNMDATETIMECHANGE
|
||||||
{
|
{
|
||||||
NMHDR nmhdr;
|
NMHDR nmhdr;
|
||||||
DWORD dwFlags;
|
DWORD dwFlags;
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
} NMDATETIMECHANGE, FAR * LPNMDATETIMECHANGE;
|
} NMDATETIMECHANGE;
|
||||||
|
#endif // old gcc headers
|
||||||
|
|
||||||
|
// apparently some versions of mingw define these macros erroneously
|
||||||
|
#ifndef DateTime_GetSystemtime
|
||||||
|
#define DateTime_GetSystemtime DateTime_GetSystemTime
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DateTime_SetSystemtime
|
||||||
|
#define DateTime_SetSystemtime DateTime_SetSystemTime
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -162,6 +171,9 @@ WXDWORD wxDatePickerCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const
|
|||||||
#endif // DTS_SHORTDATECENTURYFORMAT
|
#endif // DTS_SHORTDATECENTURYFORMAT
|
||||||
styleMSW |= DTS_SHORTDATEFORMAT;
|
styleMSW |= DTS_SHORTDATEFORMAT;
|
||||||
|
|
||||||
|
if ( style & wxDP_ALLOWNONE )
|
||||||
|
styleMSW |= DTS_SHOWNONE;
|
||||||
|
|
||||||
return styleMSW;
|
return styleMSW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,24 +194,17 @@ wxSize wxDatePickerCtrl::DoGetBestSize() const
|
|||||||
// wxDatePickerCtrl operations
|
// wxDatePickerCtrl operations
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef DateTime_GetSystemtime
|
|
||||||
#define DateTime_GetSystemtime DateTime_GetSystemTime
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DateTime_SetSystemtime
|
|
||||||
#define DateTime_SetSystemtime DateTime_SetSystemTime
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void wxDatePickerCtrl::SetValue(const wxDateTime& dt)
|
void wxDatePickerCtrl::SetValue(const wxDateTime& dt)
|
||||||
{
|
{
|
||||||
// as we don't support DTS_SHOWNONE style so far, we don't allow setting
|
wxCHECK_RET( dt.IsValid() || HasFlag(wxDP_ALLOWNONE),
|
||||||
// the control to an invalid date, but this restriction may be lifted in
|
_T("this control requires a valid date") );
|
||||||
// the future
|
|
||||||
wxCHECK_RET( dt.IsValid(), _T("invalid date") );
|
|
||||||
|
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
wxToSystemTime(&st, dt);
|
if ( dt.IsValid() )
|
||||||
if ( !DateTime_SetSystemtime(GetHwnd(), GDT_VALID, &st) )
|
wxToSystemTime(&st, dt);
|
||||||
|
if ( !DateTime_SetSystemtime(GetHwnd(),
|
||||||
|
dt.IsValid() ? GDT_VALID : GDT_NONE,
|
||||||
|
&st) )
|
||||||
{
|
{
|
||||||
wxLogDebug(_T("DateTime_SetSystemtime() failed"));
|
wxLogDebug(_T("DateTime_SetSystemtime() failed"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user