X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8d07a796ff8e372e1f851d65d96f060dd05e0e1..c052f780a4d89bad64b22bb1ad594b0bc7790e82:/samples/widgets/datepick.cpp diff --git a/samples/widgets/datepick.cpp b/samples/widgets/datepick.cpp index b9aab44eeb..1ce550538b 100644 --- a/samples/widgets/datepick.cpp +++ b/samples/widgets/datepick.cpp @@ -6,7 +6,7 @@ // Created: 27 Sep 2003 // Id: $Id$ // Copyright: (c) 2003 wxWindows team -// License: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -75,6 +75,9 @@ public: virtual wxControl *GetWidget() const { return m_datePicker; } virtual void RecreateWidget() { CreateDatePicker(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonSet(wxCommandEvent& event); @@ -119,17 +122,24 @@ END_EVENT_TABLE() // implementation // ============================================================================ +#if defined(__WXMSW__) + #define FAMILY_CTRLS NATIVE_CTRLS +#else + #define FAMILY_CTRLS GENERIC_CTRLS +#endif + IMPLEMENT_WIDGETS_PAGE(DatePickerWidgetsPage, wxT("DatePicker"), - (int)wxPlatform(GENERIC_CTRLS).If(wxMSW,NATIVE_CTRLS) - | PICKER_CTRLS + FAMILY_CTRLS | PICKER_CTRLS ); DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) - :WidgetsPage(book) + :WidgetsPage(book, imaglist, datepick_xpm) { - imaglist->Add(wxBitmap(datepick_xpm)); +} +void DatePickerWidgetsPage::CreateContent() +{ wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); // left pane @@ -146,7 +156,7 @@ DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl *book, sizerLeft->Add( CreateSizerWithTextAndLabel( wxT("&Year:"), DatePickerPage_Year , &m_year ), 0, wxALL | wxALIGN_RIGHT , 5 ); - sizerLeft->Add( new wxButton( this, wxID_ANY, wxT("&Set date") ), + sizerLeft->Add( new wxButton( this, DatePickerPage_Set, wxT("&Set date") ), 0, wxALL , 5 ); // right pane @@ -168,8 +178,6 @@ DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl *book, Reset(); SetSizer(sizerTop); - - sizerTop->Fit(this); } void DatePickerWidgetsPage::Reset() @@ -177,9 +185,9 @@ void DatePickerWidgetsPage::Reset() const wxDateTime today = wxDateTime::Today(); m_datePicker->SetValue(today); - m_day->SetValue(wxString::Format(_T("%d"), today.GetDay())); - m_month->SetValue(wxString::Format(_T("%d"), today.GetMonth())); - m_year->SetValue(wxString::Format(_T("%d"), today.GetYear())); + m_day->SetValue(wxString::Format(wxT("%d"), today.GetDay())); + m_month->SetValue(wxString::Format(wxT("%d"), today.GetMonth() + 1)); + m_year->SetValue(wxString::Format(wxT("%d"), today.GetYear())); } void DatePickerWidgetsPage::CreateDatePicker() @@ -215,6 +223,27 @@ void DatePickerWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) void DatePickerWidgetsPage::OnButtonSet(wxCommandEvent& WXUNUSED(event)) { + long day = 0, + month = 0, + year = 0; + if ( m_day->GetValue().ToLong(&day) && + m_month->GetValue().ToLong(&month) && + m_year->GetValue().ToLong(&year) ) + { + const wxDateTime someDay(day, wxDateTime::Month(month - 1), year); + if ( someDay.IsValid() ) + { + m_datePicker->SetValue(someDay); + } + else + { + wxLogError(wxT("Date is invalid")); + } + } + else + { + wxLogError(wxT("One of inputs is not number")); + } } #endif // wxUSE_DATEPICKCTRL