]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/datepick.cpp
more wxFD_XXX renamings (patch 1488371)
[wxWidgets.git] / samples / widgets / datepick.cpp
CommitLineData
f2fdc4d5
WS
1/////////////////////////////////////////////////////////////////////////////
2// Program: wxWidgets Widgets Sample
3// Name: datepick.cpp
4// Purpose: Part of the widgets sample showing date picker
5// Author: Dimitri Schoolwerth, Vadim Zeitlin
6// Created: 27 Sep 2003
7// Id: $Id$
8// Copyright: (c) 2003 wxWindows team
9// License: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_DATEPICKCTRL
28
29// for all others, include the necessary headers
30#ifndef WX_PRECOMP
31 #include "wx/app.h"
32 #include "wx/log.h"
33
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"
40
41 #include "wx/sizer.h"
42#endif
43
44#include "wx/datectrl.h"
45
46#include "widgets.h"
47
48#include "icons/datepick.xpm"
49
50// ----------------------------------------------------------------------------
51// constants
52// ----------------------------------------------------------------------------
53
54// control ids
55enum
56{
57 DatePickerPage_Reset = wxID_HIGHEST,
58 DatePickerPage_Day,
59 DatePickerPage_Month,
60 DatePickerPage_Year,
61 DatePickerPage_Set,
62 DatePickerPage_Picker
63};
64
65// ----------------------------------------------------------------------------
66// CheckBoxWidgetsPage
67// ----------------------------------------------------------------------------
68
69class DatePickerWidgetsPage : public WidgetsPage
70{
71public:
72 DatePickerWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
73 virtual ~DatePickerWidgetsPage(){};
74
75 virtual wxControl *GetWidget() const { return m_datePicker; }
76 virtual void RecreateWidget() { CreateDatePicker(); }
77
78protected:
79 // event handlers
80 void OnButtonSet(wxCommandEvent& event);
81
82 void OnButtonReset(wxCommandEvent& event);
83
84 // reset the date picker parameters
85 void Reset();
86
87 // (re)create the date picker
88 void CreateDatePicker();
89
90 // the controls
91 // ------------
92
93 // the checkbox itself and the sizer it is in
94 wxDatePickerCtrl *m_datePicker;
95 wxSizer *m_sizerDatePicker;
96
97 wxTextCtrl *m_day;
98 wxTextCtrl *m_month;
99 wxTextCtrl *m_year;
100
101 // the text entries for command parameters
102 wxTextCtrl *m_textLabel;
103
104private:
105 DECLARE_EVENT_TABLE()
106 DECLARE_WIDGETS_PAGE(DatePickerWidgetsPage)
107};
108
109// ----------------------------------------------------------------------------
110// event tables
111// ----------------------------------------------------------------------------
112
113BEGIN_EVENT_TABLE(DatePickerWidgetsPage, WidgetsPage)
114 EVT_BUTTON(DatePickerPage_Reset, DatePickerWidgetsPage::OnButtonReset)
115 EVT_BUTTON(DatePickerPage_Set, DatePickerWidgetsPage::OnButtonSet)
116END_EVENT_TABLE()
117
118// ============================================================================
119// implementation
120// ============================================================================
121
f0fa4312
WS
122#if defined(__WXMSW__)
123 #define FAMILY_CTRLS NATIVE_CTRLS
124#else
125 #define FAMILY_CTRLS GENERIC_CTRLS
126#endif
127
f2fdc4d5 128IMPLEMENT_WIDGETS_PAGE(DatePickerWidgetsPage, wxT("DatePicker"),
f0fa4312 129 FAMILY_CTRLS | PICKER_CTRLS
f2fdc4d5
WS
130 );
131
132DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl *book,
133 wxImageList *imaglist)
261357eb 134 :WidgetsPage(book, imaglist, datepick_xpm)
f2fdc4d5 135{
f2fdc4d5
WS
136 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
137
138 // left pane
139 wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Date details"));
140
141 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
142
d8d07a79
WS
143 sizerLeft->Add( CreateSizerWithTextAndLabel( wxT("&Day:"), DatePickerPage_Day , &m_day ),
144 0, wxALL | wxALIGN_RIGHT , 5 );
f2fdc4d5 145
d8d07a79
WS
146 sizerLeft->Add( CreateSizerWithTextAndLabel( wxT("&Month:"), DatePickerPage_Month , &m_month ),
147 0, wxALL | wxALIGN_RIGHT , 5 );
f2fdc4d5 148
d8d07a79
WS
149 sizerLeft->Add( CreateSizerWithTextAndLabel( wxT("&Year:"), DatePickerPage_Year , &m_year ),
150 0, wxALL | wxALIGN_RIGHT , 5 );
f2fdc4d5
WS
151
152 sizerLeft->Add( new wxButton( this, wxID_ANY, wxT("&Set date") ),
d8d07a79 153 0, wxALL , 5 );
f2fdc4d5
WS
154
155 // right pane
156 wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
157
158 m_datePicker = new wxDatePickerCtrl(this, DatePickerPage_Picker);
159
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
165
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);
169
170 // final initializations
171 Reset();
172
173 SetSizer(sizerTop);
174
175 sizerTop->Fit(this);
176}
177
178void DatePickerWidgetsPage::Reset()
179{
180 const wxDateTime today = wxDateTime::Today();
181
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()));
186}
187
188void DatePickerWidgetsPage::CreateDatePicker()
189{
190 const wxDateTime value = m_datePicker->GetValue();
191
192 size_t count = m_sizerDatePicker->GetChildren().GetCount();
193 for ( size_t n = 0; n < count; n++ )
194 {
195 m_sizerDatePicker->Remove(0);
196 }
197
198 delete m_datePicker;
199
200 m_datePicker = new wxDatePickerCtrl(this, DatePickerPage_Picker, value);
201
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();
206}
207
208// ----------------------------------------------------------------------------
209// event handlers
210// ----------------------------------------------------------------------------
211
212void DatePickerWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
213{
214 Reset();
215
216 CreateDatePicker();
217}
218
219void DatePickerWidgetsPage::OnButtonSet(wxCommandEvent& WXUNUSED(event))
220{
221}
222
223#endif // wxUSE_DATEPICKCTRL