]> git.saurik.com Git - wxWidgets.git/commitdiff
Slightly improve the date/time dialogs in the calendar sample.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 4 Nov 2012 23:55:22 +0000 (23:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 4 Nov 2012 23:55:22 +0000 (23:55 +0000)
Use CreateStdDialogButtonSizer() instead of constructing
wxStdDialogButtonSizer directly, not only this is shorter but it also makes
the "OK" button default correctly.

Also initialize the labels instead of leaving them initially empty.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72898 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/calendar/calendar.cpp

index 509af17c275e8e3198deb45d8314e32c1c655358..d7b5c2094faf866f51d2fb5d89d55d45a3a117d3 100644 (file)
@@ -914,7 +914,9 @@ MyDateDialog::MyDateDialog(wxWindow *parent, const wxDateTime& dt, int dtpStyle)
                                         dtpStyle);
     m_datePicker->SetRange(wxDateTime(1, wxDateTime::Jan, 1900),
                             wxDefaultDateTime);
                                         dtpStyle);
     m_datePicker->SetRange(wxDateTime(1, wxDateTime::Jan, 1900),
                             wxDefaultDateTime);
-    m_dateText = new wxStaticText(this, wxID_ANY, wxString());
+    m_dateText = new wxStaticText(this, wxID_ANY,
+                                  dt.IsValid() ? dt.FormatISODate()
+                                               : wxString());
 
     const wxSizerFlags flags = wxSizerFlags().Centre().Border();
     wxFlexGridSizer* const sizerMain = new wxFlexGridSizer(2);
 
     const wxSizerFlags flags = wxSizerFlags().Centre().Border();
     wxFlexGridSizer* const sizerMain = new wxFlexGridSizer(2);
@@ -925,14 +927,9 @@ MyDateDialog::MyDateDialog(wxWindow *parent, const wxDateTime& dt, int dtpStyle)
                    flags);
     sizerMain->Add(m_dateText, flags);
 
                    flags);
     sizerMain->Add(m_dateText, flags);
 
-    wxStdDialogButtonSizer *sizerBtns = new wxStdDialogButtonSizer;
-    sizerBtns->AddButton(new wxButton(this, wxID_OK));
-    sizerBtns->AddButton(new wxButton(this, wxID_CANCEL));
-    sizerBtns->Realize();
-
     wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
     sizerTop->Add(sizerMain, flags);
     wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
     sizerTop->Add(sizerMain, flags);
-    sizerTop->Add(sizerBtns, flags);
+    sizerTop->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), flags);
 
     SetSizerAndFit(sizerTop);
 }
 
     SetSizerAndFit(sizerTop);
 }
@@ -968,7 +965,8 @@ MyTimeDialog::MyTimeDialog(wxWindow *parent)
     else
 #endif // wxUSE_TIMEPICKCTRL_GENERIC
     m_timePicker = new wxTimePickerCtrl(this, wxID_ANY);
     else
 #endif // wxUSE_TIMEPICKCTRL_GENERIC
     m_timePicker = new wxTimePickerCtrl(this, wxID_ANY);
-    m_timeText = new wxStaticText(this, wxID_ANY, wxString());
+    m_timeText = new wxStaticText(this, wxID_ANY,
+                                  m_timePicker->GetValue().FormatISOTime());
 
     const wxSizerFlags flags = wxSizerFlags().Centre().Border();
     wxFlexGridSizer* const sizerMain = new wxFlexGridSizer(2);
 
     const wxSizerFlags flags = wxSizerFlags().Centre().Border();
     wxFlexGridSizer* const sizerMain = new wxFlexGridSizer(2);
@@ -979,14 +977,9 @@ MyTimeDialog::MyTimeDialog(wxWindow *parent)
                    flags);
     sizerMain->Add(m_timeText, flags);
 
                    flags);
     sizerMain->Add(m_timeText, flags);
 
-    wxStdDialogButtonSizer* sizerBtns = new wxStdDialogButtonSizer;
-    sizerBtns->AddButton(new wxButton(this, wxID_OK));
-    sizerBtns->AddButton(new wxButton(this, wxID_CANCEL));
-    sizerBtns->Realize();
-
     wxSizer* sizerTop = new wxBoxSizer(wxVERTICAL);
     sizerTop->Add(sizerMain, flags);
     wxSizer* sizerTop = new wxBoxSizer(wxVERTICAL);
     sizerTop->Add(sizerMain, flags);
-    sizerTop->Add(sizerBtns, flags);
+    sizerTop->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), flags);
 
     SetSizerAndFit(sizerTop);
 }
 
     SetSizerAndFit(sizerTop);
 }