]> git.saurik.com Git - wxWidgets.git/blame - src/common/calctrlcmn.cpp
Forgot header with OSX prefix
[wxWidgets.git] / src / common / calctrlcmn.cpp
CommitLineData
628e155d
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: common/calctrlcmn.cpp
3// Author: Marcin Wojdyr
4// Created: 2008-03-26
5// RCS-ID: $Id$
6// Copyright: (C) Marcin Wojdyr
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#include "wx/wxprec.h"
11
12#ifdef __BORLANDC__
13 #pragma hdrstop
14#endif
15
16#ifndef WX_PRECOMP
17#endif //WX_PRECOMP
18
19#if wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL
20
21#include "wx/dateevt.h"
22IMPLEMENT_DYNAMIC_CLASS(wxDateEvent, wxCommandEvent)
3c778901 23wxDEFINE_EVENT(wxEVT_DATE_CHANGED, wxDateEvent);
628e155d
VZ
24
25#endif // wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL
26
27
28#if wxUSE_CALENDARCTRL
29
30#include "wx/calctrl.h"
31
32// ----------------------------------------------------------------------------
33// events
34// ----------------------------------------------------------------------------
35IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent, wxDateEvent)
36
3c778901
VZ
37wxDEFINE_EVENT( wxEVT_CALENDAR_SEL_CHANGED, wxCalendarEvent )
38wxDEFINE_EVENT( wxEVT_CALENDAR_PAGE_CHANGED, wxCalendarEvent )
39wxDEFINE_EVENT( wxEVT_CALENDAR_DOUBLECLICKED, wxCalendarEvent )
40wxDEFINE_EVENT( wxEVT_CALENDAR_WEEKDAY_CLICKED, wxCalendarEvent )
628e155d
VZ
41
42// deprecated events
3c778901
VZ
43wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED, wxCalendarEvent )
44wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED, wxCalendarEvent )
45wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED, wxCalendarEvent )
628e155d
VZ
46
47
48wxCalendarDateAttr wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE);
49
50bool wxCalendarCtrlBase::EnableMonthChange(bool enable)
51{
52 const long styleOrig = GetWindowStyle();
53 long style = enable ? styleOrig & ~wxCAL_NO_MONTH_CHANGE
54 : styleOrig | wxCAL_NO_MONTH_CHANGE;
55 if ( style == styleOrig )
56 return false;
57
58 SetWindowStyle(style);
59
60 return true;
61}
62
6d9b6716 63bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime& dateOld)
a4fcd589
VZ
64{
65 const wxDateTime::Tm tm1 = dateOld.GetTm(),
66 tm2 = GetDate().GetTm();
67
6d9b6716
VZ
68 bool pageChanged = false;
69
a4fcd589
VZ
70 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED);
71 if ( tm1.year != tm2.year || tm1.mon != tm2.mon )
6d9b6716 72 {
a4fcd589
VZ
73 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED);
74
6d9b6716
VZ
75 pageChanged = true;
76 }
77
a4fcd589
VZ
78 // send also one of the deprecated events
79 if ( tm1.year != tm2.year )
80 GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED);
81 else if ( tm1.mon != tm2.mon )
82 GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED);
83 else
84 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED);
6d9b6716
VZ
85
86 return pageChanged;
87}
88
89void wxCalendarCtrlBase::EnableHolidayDisplay(bool display)
90{
91 long style = GetWindowStyle();
92 if ( display )
93 style |= wxCAL_SHOW_HOLIDAYS;
94 else
95 style &= ~wxCAL_SHOW_HOLIDAYS;
96
97 if ( style == GetWindowStyle() )
98 return;
99
100 SetWindowStyle(style);
101
102 if ( display )
103 SetHolidayAttrs();
104 else
105 ResetHolidayAttrs();
106
107 RefreshHolidays();
108}
109
110bool wxCalendarCtrlBase::SetHolidayAttrs()
111{
112 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS) )
113 return false;
114
115 ResetHolidayAttrs();
116
117 wxDateTime::Tm tm = GetDate().GetTm();
118 wxDateTime dtStart(1, tm.mon, tm.year),
119 dtEnd = dtStart.GetLastMonthDay();
120
121 wxDateTimeArray hol;
122 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
123
124 const size_t count = hol.GetCount();
125 for ( size_t n = 0; n < count; n++ )
126 {
127 SetHoliday(hol[n].GetDay());
128 }
129
130 return true;
a4fcd589
VZ
131}
132
628e155d
VZ
133#endif // wxUSE_CALENDARCTRL
134