]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/datepick.cpp
Use template class instead of template function in wxVectorSort().
[wxWidgets.git] / samples / widgets / datepick.cpp
index 65c5f84b8732b8689ec52743b02741e7873c0e0a..80261da8f5c2082bda7283cdcbd2a37b24a2bbf1 100644 (file)
@@ -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);
@@ -132,6 +135,10 @@ IMPLEMENT_WIDGETS_PAGE(DatePickerWidgetsPage, wxT("DatePicker"),
 DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl *book,
                                          wxImageList *imaglist)
                       :WidgetsPage(book, imaglist, datepick_xpm)
+{
+}
+
+void DatePickerWidgetsPage::CreateContent()
 {
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
@@ -149,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
@@ -171,8 +178,6 @@ DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl *book,
     Reset();
 
     SetSizer(sizerTop);
-
-    sizerTop->Fit(this);
 }
 
 void DatePickerWidgetsPage::Reset()
@@ -180,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()));
+    m_year->SetValue(wxString::Format(wxT("%d"), today.GetYear()));
 }
 
 void DatePickerWidgetsPage::CreateDatePicker()
@@ -218,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