]>
git.saurik.com Git - wxWidgets.git/blob - samples/widgets/datepick.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Part of the widgets sample showing date picker
5 // Author: Dimitri Schoolwerth, Vadim Zeitlin
6 // Created: 27 Sep 2003
8 // Copyright: (c) 2003 wxWindows team
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_DATEPICKCTRL
29 // for all others, include the necessary headers
34 #include "wx/bitmap.h"
35 #include "wx/button.h"
36 #include "wx/checkbox.h"
37 #include "wx/radiobox.h"
38 #include "wx/statbox.h"
39 #include "wx/textctrl.h"
44 #include "wx/datectrl.h"
48 #include "icons/datepick.xpm"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
57 DatePickerPage_Reset
= wxID_HIGHEST
,
65 // ----------------------------------------------------------------------------
66 // CheckBoxWidgetsPage
67 // ----------------------------------------------------------------------------
69 class DatePickerWidgetsPage
: public WidgetsPage
72 DatePickerWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
73 virtual ~DatePickerWidgetsPage(){};
75 virtual wxControl
*GetWidget() const { return m_datePicker
; }
76 virtual void RecreateWidget() { CreateDatePicker(); }
80 void OnButtonSet(wxCommandEvent
& event
);
82 void OnButtonReset(wxCommandEvent
& event
);
84 // reset the date picker parameters
87 // (re)create the date picker
88 void CreateDatePicker();
93 // the checkbox itself and the sizer it is in
94 wxDatePickerCtrl
*m_datePicker
;
95 wxSizer
*m_sizerDatePicker
;
101 // the text entries for command parameters
102 wxTextCtrl
*m_textLabel
;
105 DECLARE_EVENT_TABLE()
106 DECLARE_WIDGETS_PAGE(DatePickerWidgetsPage
)
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 BEGIN_EVENT_TABLE(DatePickerWidgetsPage
, WidgetsPage
)
114 EVT_BUTTON(DatePickerPage_Reset
, DatePickerWidgetsPage::OnButtonReset
)
115 EVT_BUTTON(DatePickerPage_Set
, DatePickerWidgetsPage::OnButtonSet
)
118 // ============================================================================
120 // ============================================================================
122 IMPLEMENT_WIDGETS_PAGE(DatePickerWidgetsPage
, wxT("DatePicker"),
123 (int)wxPlatform(GENERIC_CTRLS
).If(wxMSW
,NATIVE_CTRLS
)
127 DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl
*book
,
128 wxImageList
*imaglist
)
131 imaglist
->Add(wxBitmap(datepick_xpm
));
133 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
136 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("Date details"));
138 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
140 sizerLeft
->Add( CreateSizerWithTextAndLabel( wxT("&Day:"), DatePickerPage_Day
, &m_day
),
141 0, wxALL
| wxALIGN_RIGHT
, 5 );
143 sizerLeft
->Add( CreateSizerWithTextAndLabel( wxT("&Month:"), DatePickerPage_Month
, &m_month
),
144 0, wxALL
| wxALIGN_RIGHT
, 5 );
146 sizerLeft
->Add( CreateSizerWithTextAndLabel( wxT("&Year:"), DatePickerPage_Year
, &m_year
),
147 0, wxALL
| wxALIGN_RIGHT
, 5 );
149 sizerLeft
->Add( new wxButton( this, wxID_ANY
, wxT("&Set date") ),
153 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
155 m_datePicker
= new wxDatePickerCtrl(this, DatePickerPage_Picker
);
157 sizerRight
->Add(0, 0, 1, wxCENTRE
);
158 sizerRight
->Add(m_datePicker
, 1, wxCENTRE
);
159 sizerRight
->Add(0, 0, 1, wxCENTRE
);
160 sizerRight
->SetMinSize(150, 0);
161 m_sizerDatePicker
= sizerRight
; // save it to modify it later
163 // the 3 panes panes compose the window
164 sizerTop
->Add(sizerLeft
, 0, (wxALL
& ~wxLEFT
), 10);
165 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
167 // final initializations
175 void DatePickerWidgetsPage::Reset()
177 const wxDateTime today
= wxDateTime::Today();
179 m_datePicker
->SetValue(today
);
180 m_day
->SetValue(wxString::Format(_T("%d"), today
.GetDay()));
181 m_month
->SetValue(wxString::Format(_T("%d"), today
.GetMonth()));
182 m_year
->SetValue(wxString::Format(_T("%d"), today
.GetYear()));
185 void DatePickerWidgetsPage::CreateDatePicker()
187 const wxDateTime value
= m_datePicker
->GetValue();
189 size_t count
= m_sizerDatePicker
->GetChildren().GetCount();
190 for ( size_t n
= 0; n
< count
; n
++ )
192 m_sizerDatePicker
->Remove(0);
197 m_datePicker
= new wxDatePickerCtrl(this, DatePickerPage_Picker
, value
);
199 m_sizerDatePicker
->Add(0, 0, 1, wxCENTRE
);
200 m_sizerDatePicker
->Add(m_datePicker
, 1, wxCENTRE
);
201 m_sizerDatePicker
->Add(0, 0, 1, wxCENTRE
);
202 m_sizerDatePicker
->Layout();
205 // ----------------------------------------------------------------------------
207 // ----------------------------------------------------------------------------
209 void DatePickerWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
216 void DatePickerWidgetsPage::OnButtonSet(wxCommandEvent
& WXUNUSED(event
))
220 #endif // wxUSE_DATEPICKCTRL