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