]> git.saurik.com Git - wxWidgets.git/blob - src/common/calctrlcmn.cpp
reset the tooltip text before changing it, this apparently prevents a spurious redraw...
[wxWidgets.git] / src / common / calctrlcmn.cpp
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"
22 IMPLEMENT_DYNAMIC_CLASS(wxDateEvent, wxCommandEvent)
23 wxDEFINE_EVENT(wxEVT_DATE_CHANGED, wxDateEvent);
24
25 #endif // wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL
26
27
28 #if wxUSE_CALENDARCTRL
29
30 #include "wx/calctrl.h"
31
32 // ----------------------------------------------------------------------------
33 // events
34 // ----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent, wxDateEvent)
36
37 wxDEFINE_EVENT( wxEVT_CALENDAR_SEL_CHANGED, wxCalendarEvent );
38 wxDEFINE_EVENT( wxEVT_CALENDAR_PAGE_CHANGED, wxCalendarEvent );
39 wxDEFINE_EVENT( wxEVT_CALENDAR_DOUBLECLICKED, wxCalendarEvent );
40 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEKDAY_CLICKED, wxCalendarEvent );
41 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEK_CLICKED, wxCalendarEvent );
42
43 // deprecated events
44 wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED, wxCalendarEvent );
45 wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED, wxCalendarEvent );
46 wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED, wxCalendarEvent );
47
48
49 wxCalendarDateAttr wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE);
50
51 bool wxCalendarCtrlBase::EnableMonthChange(bool enable)
52 {
53 const long styleOrig = GetWindowStyle();
54 long style = enable ? styleOrig & ~wxCAL_NO_MONTH_CHANGE
55 : styleOrig | wxCAL_NO_MONTH_CHANGE;
56 if ( style == styleOrig )
57 return false;
58
59 SetWindowStyle(style);
60
61 return true;
62 }
63
64 bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime& dateOld)
65 {
66 const wxDateTime::Tm tm1 = dateOld.GetTm(),
67 tm2 = GetDate().GetTm();
68
69 bool pageChanged = false;
70
71 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED);
72 if ( tm1.year != tm2.year || tm1.mon != tm2.mon )
73 {
74 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED);
75
76 pageChanged = true;
77 }
78
79 // send also one of the deprecated events
80 if ( tm1.year != tm2.year )
81 GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED);
82 else if ( tm1.mon != tm2.mon )
83 GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED);
84 else
85 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED);
86
87 return pageChanged;
88 }
89
90 void wxCalendarCtrlBase::EnableHolidayDisplay(bool display)
91 {
92 long style = GetWindowStyle();
93 if ( display )
94 style |= wxCAL_SHOW_HOLIDAYS;
95 else
96 style &= ~wxCAL_SHOW_HOLIDAYS;
97
98 if ( style == GetWindowStyle() )
99 return;
100
101 SetWindowStyle(style);
102
103 if ( display )
104 SetHolidayAttrs();
105 else
106 ResetHolidayAttrs();
107
108 RefreshHolidays();
109 }
110
111 bool wxCalendarCtrlBase::SetHolidayAttrs()
112 {
113 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS) )
114 return false;
115
116 ResetHolidayAttrs();
117
118 wxDateTime::Tm tm = GetDate().GetTm();
119 wxDateTime dtStart(1, tm.mon, tm.year),
120 dtEnd = dtStart.GetLastMonthDay();
121
122 wxDateTimeArray hol;
123 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
124
125 const size_t count = hol.GetCount();
126 for ( size_t n = 0; n < count; n++ )
127 {
128 SetHoliday(hol[n].GetDay());
129 }
130
131 return true;
132 }
133
134 #endif // wxUSE_CALENDARCTRL
135