]>
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 #if defined(__WXMSW__)
123 #define FAMILY_CTRLS NATIVE_CTRLS
125 #define FAMILY_CTRLS GENERIC_CTRLS
128 IMPLEMENT_WIDGETS_PAGE(DatePickerWidgetsPage
, wxT("DatePicker"),
129 FAMILY_CTRLS
| PICKER_CTRLS
132 DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl
*book
,
133 wxImageList
*imaglist
)
134 :WidgetsPage(book
, imaglist
, datepick_xpm
)
136 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
139 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("Date details"));
141 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
143 sizerLeft
->Add( CreateSizerWithTextAndLabel( wxT("&Day:"), DatePickerPage_Day
, &m_day
),
144 0, wxALL
| wxALIGN_RIGHT
, 5 );
146 sizerLeft
->Add( CreateSizerWithTextAndLabel( wxT("&Month:"), DatePickerPage_Month
, &m_month
),
147 0, wxALL
| wxALIGN_RIGHT
, 5 );
149 sizerLeft
->Add( CreateSizerWithTextAndLabel( wxT("&Year:"), DatePickerPage_Year
, &m_year
),
150 0, wxALL
| wxALIGN_RIGHT
, 5 );
152 sizerLeft
->Add( new wxButton( this, wxID_ANY
, wxT("&Set date") ),
156 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
158 m_datePicker
= new wxDatePickerCtrl(this, DatePickerPage_Picker
);
160 sizerRight
->Add(0, 0, 1, wxCENTRE
);
161 sizerRight
->Add(m_datePicker
, 1, wxCENTRE
);
162 sizerRight
->Add(0, 0, 1, wxCENTRE
);
163 sizerRight
->SetMinSize(150, 0);
164 m_sizerDatePicker
= sizerRight
; // save it to modify it later
166 // the 3 panes panes compose the window
167 sizerTop
->Add(sizerLeft
, 0, (wxALL
& ~wxLEFT
), 10);
168 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
170 // final initializations
178 void DatePickerWidgetsPage::Reset()
180 const wxDateTime today
= wxDateTime::Today();
182 m_datePicker
->SetValue(today
);
183 m_day
->SetValue(wxString::Format(_T("%d"), today
.GetDay()));
184 m_month
->SetValue(wxString::Format(_T("%d"), today
.GetMonth()));
185 m_year
->SetValue(wxString::Format(_T("%d"), today
.GetYear()));
188 void DatePickerWidgetsPage::CreateDatePicker()
190 const wxDateTime value
= m_datePicker
->GetValue();
192 size_t count
= m_sizerDatePicker
->GetChildren().GetCount();
193 for ( size_t n
= 0; n
< count
; n
++ )
195 m_sizerDatePicker
->Remove(0);
200 m_datePicker
= new wxDatePickerCtrl(this, DatePickerPage_Picker
, value
);
202 m_sizerDatePicker
->Add(0, 0, 1, wxCENTRE
);
203 m_sizerDatePicker
->Add(m_datePicker
, 1, wxCENTRE
);
204 m_sizerDatePicker
->Add(0, 0, 1, wxCENTRE
);
205 m_sizerDatePicker
->Layout();
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 void DatePickerWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
219 void DatePickerWidgetsPage::OnButtonSet(wxCommandEvent
& WXUNUSED(event
))
223 #endif // wxUSE_DATEPICKCTRL