]> git.saurik.com Git - wxWidgets.git/blame - samples/calendar/calendar.cpp
use wx.ART_NEW
[wxWidgets.git] / samples / calendar / calendar.cpp
CommitLineData
74a533f7
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: calendar.cpp
3// Purpose: wxCalendarCtrl sample
4// Author: Vadim Zeitlin
4e6bceff 5// Modified by:
74a533f7
VZ
6// Created: 02.01.00
7// RCS-ID: $Id$
8// Copyright: (c) Vadim Zeitlin
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
74a533f7
VZ
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
273b7ed9 27// for all others, include the necessary headers
74a533f7
VZ
28#ifndef WX_PRECOMP
29 #include "wx/app.h"
788233da 30 #include "wx/log.h"
74a533f7 31 #include "wx/frame.h"
273b7ed9
VZ
32 #include "wx/panel.h"
33 #include "wx/stattext.h"
34 #include "wx/menu.h"
35 #include "wx/layout.h"
36 #include "wx/msgdlg.h"
74a533f7
VZ
37#endif
38
9230b621 39#include "wx/sizer.h"
feb72429
VZ
40#include "wx/textctrl.h"
41
74a533f7 42#include "wx/calctrl.h"
7ff2dfba
VZ
43
44#if wxUSE_DATEPICKCTRL
45 #include "wx/datectrl.h"
46 #if wxUSE_DATEPICKCTRL_GENERIC
47 #include "wx/generic/datectrl.h"
48 #endif // wxUSE_DATEPICKCTRL_GENERIC
49#endif // wxUSE_DATEPICKCTRL
feb72429 50
48263511 51#include "../sample.xpm"
3200f37d 52
74a533f7
VZ
53// ----------------------------------------------------------------------------
54// private classes
55// ----------------------------------------------------------------------------
56
57// Define a new application type, each program should derive a class from wxApp
58class MyApp : public wxApp
59{
60public:
61 // override base class virtuals
62 // ----------------------------
63
64 // this one is called on application startup and is a good place for the app
65 // initialization (doing it here and not in the ctor allows to have an error
66 // return: if OnInit() returns false, the application terminates)
67 virtual bool OnInit();
68};
69
70class MyPanel : public wxPanel
71{
72public:
73 MyPanel(wxFrame *frame);
74
75 void OnCalendar(wxCalendarEvent& event);
76 void OnCalendarWeekDayClick(wxCalendarEvent& event);
77 void OnCalendarChange(wxCalendarEvent& event);
0de868d9
VZ
78 void OnCalMonthChange(wxCalendarEvent& event);
79 void OnCalYearChange(wxCalendarEvent& event);
74a533f7 80
bc385ba9
VZ
81 wxCalendarCtrl *GetCal() const { return m_calendar; }
82
37df1f33
VZ
83 // turn on/off the specified style bit on the calendar control
84 void ToggleCalStyle(bool on, int style);
85
74a533f7
VZ
86 void HighlightSpecial(bool on);
87
605dfd91
JS
88 void SetDate();
89 void Today();
a7c58211 90
74a533f7
VZ
91private:
92 wxCalendarCtrl *m_calendar;
93 wxStaticText *m_date;
94
95 DECLARE_EVENT_TABLE()
96};
97
98// Define a new frame type: this is going to be our main frame
99class MyFrame : public wxFrame
100{
101public:
102 // ctor(s)
103 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
104
105 // event handlers (these functions should _not_ be virtual)
106 void OnQuit(wxCommandEvent& event);
107 void OnAbout(wxCommandEvent& event);
108
ac78ab7b 109#if wxUSE_DATEPICKCTRL
feb72429 110 void OnAskDate(wxCommandEvent& event);
ac78ab7b 111#endif // wxUSE_DATEPICKCTRL
feb72429 112
74a533f7
VZ
113 void OnCalMonday(wxCommandEvent& event);
114 void OnCalHolidays(wxCommandEvent& event);
115 void OnCalSpecial(wxCommandEvent& event);
116
bc385ba9
VZ
117 void OnCalAllowMonth(wxCommandEvent& event);
118 void OnCalAllowYear(wxCommandEvent& event);
119
37df1f33
VZ
120 void OnCalSeqMonth(wxCommandEvent& event);
121 void OnCalShowSurroundingWeeks(wxCommandEvent& event);
122
605dfd91
JS
123 void OnSetDate(wxCommandEvent& event);
124 void OnToday(wxCommandEvent& event);
125
bc385ba9
VZ
126 void OnAllowYearUpdate(wxUpdateUIEvent& event);
127
74a533f7
VZ
128private:
129 MyPanel *m_panel;
130
be5a51fb 131 // any class wishing to process wxWidgets events must use this macro
74a533f7
VZ
132 DECLARE_EVENT_TABLE()
133};
134
ac78ab7b 135#if wxUSE_DATEPICKCTRL
feb72429
VZ
136
137// Define a simple modal dialog which asks the user for a date
138class MyDialog : public wxDialog
139{
140public:
d1fd3c26 141 MyDialog(wxWindow *parent, const wxDateTime& dt, int dtpStyle);
feb72429
VZ
142
143 wxDateTime GetDate() const { return m_datePicker->GetValue(); }
144
145private:
146 void OnDateChange(wxDateEvent& event);
147
148
7ff2dfba 149 wxDatePickerCtrlBase *m_datePicker;
feb72429
VZ
150 wxTextCtrl *m_text;
151
152
153 DECLARE_EVENT_TABLE()
154};
155
ac78ab7b 156#endif // wxUSE_DATEPICKCTRL
feb72429 157
74a533f7
VZ
158// ----------------------------------------------------------------------------
159// constants
160// ----------------------------------------------------------------------------
161
162// IDs for the controls and the menu commands
163enum
164{
165 // menu items
feb72429
VZ
166 Calendar_File_About = wxID_ABOUT,
167 Calendar_File_Quit = wxID_EXIT,
74a533f7
VZ
168 Calendar_Cal_Monday = 200,
169 Calendar_Cal_Holidays,
170 Calendar_Cal_Special,
bc385ba9
VZ
171 Calendar_Cal_Month,
172 Calendar_Cal_Year,
37df1f33
VZ
173 Calendar_Cal_SeqMonth,
174 Calendar_Cal_SurroundWeeks,
605dfd91
JS
175 Calendar_Cal_SetDate,
176 Calendar_Cal_Today,
d1fd3c26
VZ
177#if wxUSE_DATEPICKCTRL
178 Calendar_DatePicker_AskDate = 300,
179 Calendar_DatePicker_ShowCentury,
180 Calendar_DatePicker_DropDown,
3200f37d 181 Calendar_DatePicker_AllowNone,
7ff2dfba
VZ
182#if wxUSE_DATEPICKCTRL_GENERIC
183 Calendar_DatePicker_Generic,
184#endif // wxUSE_DATEPICKCTRL_GENERIC
d1fd3c26 185#endif // wxUSE_DATEPICKCTRL
e9561b3b 186 Calendar_CalCtrl = 1000
74a533f7
VZ
187};
188
189// ----------------------------------------------------------------------------
be5a51fb 190// event tables and other macros for wxWidgets
74a533f7
VZ
191// ----------------------------------------------------------------------------
192
be5a51fb 193// the event tables connect the wxWidgets events with the functions (event
74a533f7
VZ
194// handlers) which process them. It can be also done at run-time, but for the
195// simple menu events like this the static method is much simpler.
196BEGIN_EVENT_TABLE(MyFrame, wxFrame)
197 EVT_MENU(Calendar_File_Quit, MyFrame::OnQuit)
198 EVT_MENU(Calendar_File_About, MyFrame::OnAbout)
199
ac78ab7b 200#if wxUSE_DATEPICKCTRL
d1fd3c26 201 EVT_MENU(Calendar_DatePicker_AskDate, MyFrame::OnAskDate)
ac78ab7b 202#endif // wxUSE_DATEPICKCTRL
feb72429 203
74a533f7
VZ
204 EVT_MENU(Calendar_Cal_Monday, MyFrame::OnCalMonday)
205 EVT_MENU(Calendar_Cal_Holidays, MyFrame::OnCalHolidays)
206 EVT_MENU(Calendar_Cal_Special, MyFrame::OnCalSpecial)
bc385ba9
VZ
207
208 EVT_MENU(Calendar_Cal_Month, MyFrame::OnCalAllowMonth)
209 EVT_MENU(Calendar_Cal_Year, MyFrame::OnCalAllowYear)
210
37df1f33
VZ
211 EVT_MENU(Calendar_Cal_SeqMonth, MyFrame::OnCalSeqMonth)
212 EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks)
213
605dfd91
JS
214 EVT_MENU(Calendar_Cal_SetDate, MyFrame::OnSetDate)
215 EVT_MENU(Calendar_Cal_Today, MyFrame::OnToday)
216
217
bc385ba9 218 EVT_UPDATE_UI(Calendar_Cal_Year, MyFrame::OnAllowYearUpdate)
74a533f7
VZ
219END_EVENT_TABLE()
220
221BEGIN_EVENT_TABLE(MyPanel, wxPanel)
222 EVT_CALENDAR (Calendar_CalCtrl, MyPanel::OnCalendar)
0de868d9
VZ
223 EVT_CALENDAR_MONTH (Calendar_CalCtrl, MyPanel::OnCalMonthChange)
224 EVT_CALENDAR_YEAR (Calendar_CalCtrl, MyPanel::OnCalYearChange)
74a533f7
VZ
225 EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl, MyPanel::OnCalendarChange)
226 EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick)
227END_EVENT_TABLE()
228
ac78ab7b 229#if wxUSE_DATEPICKCTRL
feb72429
VZ
230
231BEGIN_EVENT_TABLE(MyDialog, wxDialog)
232 EVT_DATE_CHANGED(wxID_ANY, MyDialog::OnDateChange)
233END_EVENT_TABLE()
234
ac78ab7b 235#endif // wxUSE_DATEPICKCTRL
feb72429 236
be5a51fb 237// Create a new application object: this macro will allow wxWidgets to create
74a533f7
VZ
238// the application object during program execution (it's better than using a
239// static object for many reasons) and also declares the accessor function
240// wxGetApp() which will return the reference of the right type (i.e. MyApp and
241// not wxApp)
242IMPLEMENT_APP(MyApp)
243
244// ============================================================================
245// implementation
246// ============================================================================
247
248// ----------------------------------------------------------------------------
249// the application class
250// ----------------------------------------------------------------------------
251
252// `Main program' equivalent: the program execution "starts" here
253bool MyApp::OnInit()
254{
255 // Create the main application window
be5a51fb 256 MyFrame *frame = new MyFrame(_T("Calendar wxWidgets sample"),
4e6bceff 257 wxPoint(50, 50), wxSize(450, 340));
74a533f7 258
9230b621 259 frame->Show(true);
74a533f7
VZ
260
261 // success: wxApp::OnRun() will be called which will enter the main message
5014bb3a 262 // loop and the application will run. If we returned false here, the
74a533f7 263 // application would exit immediately.
9230b621 264 return true;
74a533f7
VZ
265}
266
267// ----------------------------------------------------------------------------
268// main frame
269// ----------------------------------------------------------------------------
270
271// frame constructor
272MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
9230b621 273 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
74a533f7 274{
3200f37d 275 // set the frame icon
48263511 276 SetIcon(sample_xpm);
3200f37d 277
74a533f7
VZ
278 // create a menu bar
279 wxMenu *menuFile = new wxMenu;
9f84eccd 280 menuFile->Append(Calendar_File_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
74a533f7 281 menuFile->AppendSeparator();
9f84eccd 282 menuFile->Append(Calendar_File_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
74a533f7
VZ
283
284 wxMenu *menuCal = new wxMenu;
285 menuCal->Append(Calendar_Cal_Monday,
9f84eccd
MB
286 _T("Monday &first weekday\tCtrl-F"),
287 _T("Toggle between Mon and Sun as the first week day"),
9230b621 288 true);
9f84eccd
MB
289 menuCal->Append(Calendar_Cal_Holidays, _T("Show &holidays\tCtrl-H"),
290 _T("Toggle highlighting the holidays"),
9230b621 291 true);
9f84eccd
MB
292 menuCal->Append(Calendar_Cal_Special, _T("Highlight &special dates\tCtrl-S"),
293 _T("Test custom highlighting"),
9230b621 294 true);
37df1f33 295 menuCal->Append(Calendar_Cal_SurroundWeeks,
9f84eccd
MB
296 _T("Show s&urrounding weeks\tCtrl-W"),
297 _T("Show the neighbouring weeks in the prev/next month"),
9230b621 298 true);
bc385ba9 299 menuCal->AppendSeparator();
37df1f33 300 menuCal->Append(Calendar_Cal_SeqMonth,
9f84eccd
MB
301 _T("To&ggle month selector style\tCtrl-G"),
302 _T("Use another style for the calendar controls"),
9230b621 303 true);
9f84eccd
MB
304 menuCal->Append(Calendar_Cal_Month, _T("&Month can be changed\tCtrl-M"),
305 _T("Allow changing the month in the calendar"),
9230b621 306 true);
9f84eccd
MB
307 menuCal->Append(Calendar_Cal_Year, _T("&Year can be changed\tCtrl-Y"),
308 _T("Allow changing the year in the calendar"),
9230b621 309 true);
605dfd91 310 menuCal->AppendSeparator();
529b7f71
JS
311 menuCal->Append(Calendar_Cal_SetDate, _T("SetDate()"), _T("Set date to 2005-12-24."));
312 menuCal->Append(Calendar_Cal_Today, _T("Today()"), _T("Set the current date."));
74a533f7 313
d1fd3c26
VZ
314#if wxUSE_DATEPICKCTRL
315 wxMenu *menuDate = new wxMenu;
316 menuDate->AppendCheckItem(Calendar_DatePicker_ShowCentury,
317 _T("Al&ways show century"));
318 menuDate->AppendCheckItem(Calendar_DatePicker_DropDown,
319 _T("Use &drop down control"));
3200f37d
VZ
320 menuDate->AppendCheckItem(Calendar_DatePicker_AllowNone,
321 _T("Allow &no date"));
7ff2dfba
VZ
322#if wxUSE_DATEPICKCTRL_GENERIC
323 menuDate->AppendCheckItem(Calendar_DatePicker_Generic,
324 _T("Use &generic version of the control"));
325#endif // wxUSE_DATEPICKCTRL_GENERIC
d1fd3c26
VZ
326 menuDate->AppendSeparator();
327 menuDate->Append(Calendar_DatePicker_AskDate, _T("&Choose date...\tCtrl-D"), _T("Show dialog with wxDatePickerCtrl"));
328#endif // wxUSE_DATEPICKCTRL
329
74a533f7
VZ
330 // now append the freshly created menu to the menu bar...
331 wxMenuBar *menuBar = new wxMenuBar;
9f84eccd
MB
332 menuBar->Append(menuFile, _T("&File"));
333 menuBar->Append(menuCal, _T("&Calendar"));
d1fd3c26
VZ
334#if wxUSE_DATEPICKCTRL
335 menuBar->Append(menuDate, _T("&Date picker"));
336#endif // wxUSE_DATEPICKCTRL
74a533f7 337
9230b621
VS
338 menuBar->Check(Calendar_Cal_Monday, true);
339 menuBar->Check(Calendar_Cal_Holidays, true);
340 menuBar->Check(Calendar_Cal_Month, true);
341 menuBar->Check(Calendar_Cal_Year, true);
74a533f7 342
d1fd3c26
VZ
343#if wxUSE_DATEPICKCTRL
344 menuBar->Check(Calendar_DatePicker_ShowCentury, true);
345#endif // wxUSE_DATEPICKCTRL
346
74a533f7
VZ
347 // ... and attach this menu bar to the frame
348 SetMenuBar(menuBar);
349
350 m_panel = new MyPanel(this);
351
352#if wxUSE_STATUSBAR
353 // create a status bar just for fun (by default with 1 pane only)
9898fcda 354 CreateStatusBar(2);
be5a51fb 355 SetStatusText(_T("Welcome to wxWidgets!"));
74a533f7
VZ
356#endif // wxUSE_STATUSBAR
357}
358
359void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
360{
5014bb3a 361 // true is to force the frame to close
9230b621 362 Close(true);
74a533f7
VZ
363}
364
365void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
366{
749bfe9a 367 wxMessageBox(_T("wxCalendarCtrl sample\n(c) 2000 Vadim Zeitlin"),
74a533f7
VZ
368 _T("About Calendar"), wxOK | wxICON_INFORMATION, this);
369}
370
371void MyFrame::OnCalMonday(wxCommandEvent& event)
372{
37df1f33
VZ
373 bool enable = GetMenuBar()->IsChecked(event.GetId());
374
375 m_panel->ToggleCalStyle(enable, wxCAL_MONDAY_FIRST);
74a533f7
VZ
376}
377
378void MyFrame::OnCalHolidays(wxCommandEvent& event)
379{
89a0a322 380 bool enable = GetMenuBar()->IsChecked(event.GetId());
37df1f33 381
bc385ba9 382 m_panel->GetCal()->EnableHolidayDisplay(enable);
74a533f7
VZ
383}
384
385void MyFrame::OnCalSpecial(wxCommandEvent& event)
386{
89a0a322 387 m_panel->HighlightSpecial(GetMenuBar()->IsChecked(event.GetId()));
bc385ba9
VZ
388}
389
390void MyFrame::OnCalAllowMonth(wxCommandEvent& event)
391{
89a0a322 392 bool allow = GetMenuBar()->IsChecked(event.GetId());
bc385ba9
VZ
393
394 m_panel->GetCal()->EnableMonthChange(allow);
395}
396
397void MyFrame::OnCalAllowYear(wxCommandEvent& event)
398{
89a0a322 399 bool allow = GetMenuBar()->IsChecked(event.GetId());
bc385ba9
VZ
400
401 m_panel->GetCal()->EnableYearChange(allow);
402}
403
37df1f33
VZ
404void MyFrame::OnCalSeqMonth(wxCommandEvent& event)
405{
406 bool allow = GetMenuBar()->IsChecked(event.GetId());
407
408 m_panel->ToggleCalStyle(allow, wxCAL_SEQUENTIAL_MONTH_SELECTION);
409}
410
411void MyFrame::OnCalShowSurroundingWeeks(wxCommandEvent& event)
412{
413 bool allow = GetMenuBar()->IsChecked(event.GetId());
414
415 m_panel->ToggleCalStyle(allow, wxCAL_SHOW_SURROUNDING_WEEKS);
416}
417
bc385ba9
VZ
418void MyFrame::OnAllowYearUpdate(wxUpdateUIEvent& event)
419{
420 event.Enable( GetMenuBar()->IsChecked(Calendar_Cal_Month));
74a533f7
VZ
421}
422
87728739 423void MyFrame::OnSetDate(wxCommandEvent &WXUNUSED(event))
605dfd91
JS
424{
425 m_panel->SetDate();
426}
427
87728739 428void MyFrame::OnToday(wxCommandEvent &WXUNUSED(event))
605dfd91
JS
429{
430 m_panel->Today();
431}
432
ac78ab7b 433#if wxUSE_DATEPICKCTRL
feb72429
VZ
434
435void MyFrame::OnAskDate(wxCommandEvent& WXUNUSED(event))
436{
d1fd3c26
VZ
437 int style = wxDP_DEFAULT;
438 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_ShowCentury) )
439 style |= wxDP_SHOWCENTURY;
440 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown) )
441 style |= wxDP_DROPDOWN;
3200f37d
VZ
442 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone) )
443 style |= wxDP_ALLOWNONE;
d1fd3c26
VZ
444
445 MyDialog dlg(this, m_panel->GetCal()->GetDate(), style);
feb72429
VZ
446 if ( dlg.ShowModal() == wxID_OK )
447 {
3200f37d
VZ
448 const wxDateTime dt = dlg.GetDate();
449 if ( dt.IsValid() )
feb72429 450 {
3200f37d 451 const wxDateTime today = wxDateTime::Today();
feb72429 452
3200f37d
VZ
453 if ( dt.GetDay() == today.GetDay() &&
454 dt.GetMonth() == today.GetMonth() )
455 {
456 wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
457 }
feb72429 458
3200f37d
VZ
459 m_panel->GetCal()->SetDate(dt);
460
461 wxLogStatus(_T("Changed the date to your input"));
462 }
463 else
464 {
465 wxLogStatus(_T("No date entered"));
466 }
feb72429
VZ
467 }
468}
469
ac78ab7b 470#endif // wxUSE_DATEPICKCTRL
feb72429 471
74a533f7
VZ
472// ----------------------------------------------------------------------------
473// MyPanel
474// ----------------------------------------------------------------------------
475
476MyPanel::MyPanel(wxFrame *frame)
9230b621 477 : wxPanel(frame, wxID_ANY)
74a533f7 478{
4e6bceff 479 wxString date;
4693b20c 480 date.Printf(wxT("Selected date: %s"),
74a533f7 481 wxDateTime::Today().FormatISODate().c_str());
9230b621 482 m_date = new wxStaticText(this, wxID_ANY, date);
74a533f7
VZ
483 m_calendar = new wxCalendarCtrl(this, Calendar_CalCtrl,
484 wxDefaultDateTime,
485 wxDefaultPosition,
486 wxDefaultSize,
bc385ba9
VZ
487 wxCAL_MONDAY_FIRST |
488 wxCAL_SHOW_HOLIDAYS |
489 wxRAISED_BORDER);
74a533f7 490
9230b621 491 wxBoxSizer *m_sizer = new wxBoxSizer( wxHORIZONTAL );
4e6bceff 492
9230b621
VS
493 m_sizer->Add(m_date, 0, wxALIGN_CENTER | wxALL, 10 );
494 m_sizer->Add(m_calendar, 0, wxALIGN_CENTER | wxALIGN_LEFT);
4e6bceff 495
9230b621
VS
496 SetSizer( m_sizer );
497 m_sizer->SetSizeHints( this );
74a533f7
VZ
498}
499
500void MyPanel::OnCalendar(wxCalendarEvent& event)
501{
4693b20c 502 wxLogMessage(wxT("Selected %s from calendar"),
74a533f7
VZ
503 event.GetDate().FormatISODate().c_str());
504}
505
506void MyPanel::OnCalendarChange(wxCalendarEvent& event)
507{
508 wxString s;
4693b20c 509 s.Printf(wxT("Selected date: %s"), event.GetDate().FormatISODate().c_str());
74a533f7
VZ
510
511 m_date->SetLabel(s);
512}
513
0de868d9
VZ
514void MyPanel::OnCalMonthChange(wxCalendarEvent& WXUNUSED(event))
515{
4693b20c 516 wxLogStatus(wxT("Calendar month changed"));
0de868d9
VZ
517}
518
519void MyPanel::OnCalYearChange(wxCalendarEvent& WXUNUSED(event))
520{
4693b20c 521 wxLogStatus(wxT("Calendar year changed"));
0de868d9
VZ
522}
523
74a533f7
VZ
524void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
525{
4693b20c 526 wxLogMessage(wxT("Clicked on %s"),
74a533f7
VZ
527 wxDateTime::GetWeekDayName(event.GetWeekDay()).c_str());
528}
529
37df1f33 530void MyPanel::ToggleCalStyle(bool on, int flag)
74a533f7
VZ
531{
532 long style = m_calendar->GetWindowStyle();
533 if ( on )
37df1f33 534 style |= flag;
74a533f7 535 else
37df1f33 536 style &= ~flag;
74a533f7
VZ
537
538 m_calendar->SetWindowStyle(style);
539
540 m_calendar->Refresh();
541}
542
74a533f7
VZ
543void MyPanel::HighlightSpecial(bool on)
544{
545 if ( on )
546 {
547 wxCalendarDateAttr
548 *attrRedCircle = new wxCalendarDateAttr(wxCAL_BORDER_ROUND, *wxRED),
549 *attrGreenSquare = new wxCalendarDateAttr(wxCAL_BORDER_SQUARE, *wxGREEN),
550 *attrHeaderLike = new wxCalendarDateAttr(*wxBLUE, *wxLIGHT_GREY);
551
552 m_calendar->SetAttr(17, attrRedCircle);
553 m_calendar->SetAttr(29, attrGreenSquare);
554 m_calendar->SetAttr(13, attrHeaderLike);
555 }
556 else // off
557 {
558 m_calendar->ResetAttr(17);
559 m_calendar->ResetAttr(29);
560 m_calendar->ResetAttr(13);
561 }
562
563 m_calendar->Refresh();
564}
605dfd91
JS
565
566void MyPanel::SetDate()
567{
568 wxDateTime date(24, wxDateTime::Dec, 2005, 23, 59, 59);
569 m_calendar->SetDate(date);
570}
571
572void MyPanel::Today()
573{
574 m_calendar->SetDate(wxDateTime::Today());
575}
feb72429
VZ
576
577// ----------------------------------------------------------------------------
578// MyDialog
579// ----------------------------------------------------------------------------
580
ac78ab7b 581#if wxUSE_DATEPICKCTRL
feb72429 582
d1fd3c26 583MyDialog::MyDialog(wxWindow *parent, const wxDateTime& dt, int dtpStyle)
a7c58211 584 : wxDialog(parent, wxID_ANY, wxString(_T("Calendar: Choose a date")))
feb72429
VZ
585{
586 wxStdDialogButtonSizer *sizerBtns = new wxStdDialogButtonSizer;
587 sizerBtns->AddButton(new wxButton(this, wxID_OK));
588 sizerBtns->AddButton(new wxButton(this, wxID_CANCEL));
718903fe 589 sizerBtns->Realize();
feb72429
VZ
590
591 wxSizer *sizerText = new wxBoxSizer(wxHORIZONTAL);
a7c58211 592 sizerText->Add(new wxStaticText(this, wxID_ANY, _T("Date in ISO format: ")),
b7e542be 593 wxSizerFlags().Border().Align(wxALIGN_CENTRE_VERTICAL));
a7c58211 594 m_text = new wxTextCtrl(this, wxID_ANY);
b7e542be
VZ
595 sizerText->Add(m_text, wxSizerFlags().
596 Expand().Border().Align(wxALIGN_CENTRE_VERTICAL));
feb72429
VZ
597
598 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
599 sizerTop->Add(new wxStaticText
600 (
a7c58211 601 this, wxID_ANY,
feb72429
VZ
602 _T("Enter your birthday date (not before 20th century):")
603 ),
604 wxSizerFlags().Border());
605
7ff2dfba
VZ
606#if wxUSE_DATEPICKCTRL_GENERIC
607 wxFrame *frame = (wxFrame *)wxGetTopLevelParent(parent);
608 if ( frame && frame->GetMenuBar()->IsChecked(Calendar_DatePicker_Generic) )
a7c58211 609 m_datePicker = new wxDatePickerCtrlGeneric(this, wxID_ANY, dt,
7ff2dfba
VZ
610 wxDefaultPosition,
611 wxDefaultSize,
612 dtpStyle);
613 else
614#endif // wxUSE_DATEPICKCTRL_GENERIC
a7c58211 615 m_datePicker = new wxDatePickerCtrl(this, wxID_ANY, dt,
d1fd3c26
VZ
616 wxDefaultPosition, wxDefaultSize,
617 dtpStyle);
feb72429
VZ
618 m_datePicker->SetRange(wxDateTime(1, wxDateTime::Jan, 1900),
619 wxDefaultDateTime);
620 sizerTop->Add(m_datePicker, wxSizerFlags().Expand().Border());
621
622 sizerTop->AddStretchSpacer(1);
623 sizerTop->Add(sizerText);
624
625 sizerTop->Add(sizerBtns, wxSizerFlags().Centre().Border());
626
627 SetSizerAndFit(sizerTop);
628 Layout();
629}
630
631void MyDialog::OnDateChange(wxDateEvent& event)
632{
b7e542be 633 const wxDateTime dt = event.GetDate();
a7c58211
WS
634 if(dt.IsValid())
635 m_text->SetValue(dt.FormatISODate());
636 else
637 m_text->SetValue(wxEmptyString);
feb72429
VZ
638}
639
ac78ab7b 640#endif // wxUSE_DATEPICKCTRL
feb72429 641