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