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);
// 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
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
Reset();
SetSizer(sizerTop);
-
- sizerTop->Fit(this);
}
void DatePickerWidgetsPage::Reset()
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(_T("Date is invalid"));
+ }
+ }
+ else
+ {
+ wxLogError(_T("One of inputs is not number"));
+ }
}
#endif // wxUSE_DATEPICKCTRL