]> git.saurik.com Git - wxWidgets.git/blame - src/common/calctrlcmn.cpp
Fix memory leak in wxPanel::SetBackgroundBirmap() in wxMSW.
[wxWidgets.git] / src / common / calctrlcmn.cpp
CommitLineData
628e155d 1///////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/common/calctrlcmn.cpp
628e155d
VZ
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
28953245
SC
32// ----------------------------------------------------------------------------
33// XTI
34// ----------------------------------------------------------------------------
35
36wxDEFINE_FLAGS( wxCalendarCtrlStyle )
37wxBEGIN_FLAGS( wxCalendarCtrlStyle )
38// new style border flags, we put them first to
39// use them for streaming out
40wxFLAGS_MEMBER(wxBORDER_SIMPLE)
41wxFLAGS_MEMBER(wxBORDER_SUNKEN)
42wxFLAGS_MEMBER(wxBORDER_DOUBLE)
43wxFLAGS_MEMBER(wxBORDER_RAISED)
44wxFLAGS_MEMBER(wxBORDER_STATIC)
45wxFLAGS_MEMBER(wxBORDER_NONE)
46
47// old style border flags
48wxFLAGS_MEMBER(wxSIMPLE_BORDER)
49wxFLAGS_MEMBER(wxSUNKEN_BORDER)
50wxFLAGS_MEMBER(wxDOUBLE_BORDER)
51wxFLAGS_MEMBER(wxRAISED_BORDER)
52wxFLAGS_MEMBER(wxSTATIC_BORDER)
53wxFLAGS_MEMBER(wxBORDER)
54
55// standard window styles
56wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
57wxFLAGS_MEMBER(wxCLIP_CHILDREN)
58wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
59wxFLAGS_MEMBER(wxWANTS_CHARS)
60wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
61wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
62wxFLAGS_MEMBER(wxVSCROLL)
63wxFLAGS_MEMBER(wxHSCROLL)
64
65wxFLAGS_MEMBER(wxCAL_SUNDAY_FIRST)
66wxFLAGS_MEMBER(wxCAL_MONDAY_FIRST)
67wxFLAGS_MEMBER(wxCAL_SHOW_HOLIDAYS)
68wxFLAGS_MEMBER(wxCAL_NO_YEAR_CHANGE)
69wxFLAGS_MEMBER(wxCAL_NO_MONTH_CHANGE)
70wxFLAGS_MEMBER(wxCAL_SEQUENTIAL_MONTH_SELECTION)
71wxFLAGS_MEMBER(wxCAL_SHOW_SURROUNDING_WEEKS)
72
73wxEND_FLAGS( wxCalendarCtrlStyle )
74
75wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxCalendarCtrl, wxControl, "wx/calctrl.h")
76
77wxBEGIN_PROPERTIES_TABLE(wxCalendarCtrl)
78wxEVENT_RANGE_PROPERTY( Updated, wxEVT_CALENDAR_SEL_CHANGED, \
79 wxEVT_CALENDAR_WEEKDAY_CLICKED, wxCalendarEvent )
80
81wxHIDE_PROPERTY( Children )
82
83wxPROPERTY( Date,wxDateTime, SetDate, GetDate, wxEMPTY_PARAMETER_VALUE, \
84 0 /*flags*/, wxT("Helpstring"), wxT("group"))
85wxPROPERTY_FLAGS( WindowStyle, wxCalendarCtrlStyle, long, \
86 SetWindowStyleFlag, GetWindowStyleFlag, \
87 wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), \
88 wxT("group")) // style
89wxEND_PROPERTIES_TABLE()
90
91wxEMPTY_HANDLERS_TABLE(wxCalendarCtrl)
92
93wxCONSTRUCTOR_6( wxCalendarCtrl, wxWindow*, Parent, wxWindowID, Id, \
94 wxDateTime, Date, wxPoint, Position, wxSize, Size, long, WindowStyle )
95
628e155d
VZ
96// ----------------------------------------------------------------------------
97// events
98// ----------------------------------------------------------------------------
99IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent, wxDateEvent)
100
9b11752c
VZ
101wxDEFINE_EVENT( wxEVT_CALENDAR_SEL_CHANGED, wxCalendarEvent );
102wxDEFINE_EVENT( wxEVT_CALENDAR_PAGE_CHANGED, wxCalendarEvent );
103wxDEFINE_EVENT( wxEVT_CALENDAR_DOUBLECLICKED, wxCalendarEvent );
104wxDEFINE_EVENT( wxEVT_CALENDAR_WEEKDAY_CLICKED, wxCalendarEvent );
105wxDEFINE_EVENT( wxEVT_CALENDAR_WEEK_CLICKED, wxCalendarEvent );
628e155d
VZ
106
107// deprecated events
9b11752c
VZ
108wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED, wxCalendarEvent );
109wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED, wxCalendarEvent );
110wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED, wxCalendarEvent );
628e155d
VZ
111
112
113wxCalendarDateAttr wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE);
114
115bool wxCalendarCtrlBase::EnableMonthChange(bool enable)
116{
117 const long styleOrig = GetWindowStyle();
118 long style = enable ? styleOrig & ~wxCAL_NO_MONTH_CHANGE
119 : styleOrig | wxCAL_NO_MONTH_CHANGE;
120 if ( style == styleOrig )
121 return false;
122
123 SetWindowStyle(style);
124
125 return true;
126}
127
6d9b6716 128bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime& dateOld)
a4fcd589
VZ
129{
130 const wxDateTime::Tm tm1 = dateOld.GetTm(),
131 tm2 = GetDate().GetTm();
132
6d9b6716
VZ
133 bool pageChanged = false;
134
a4fcd589
VZ
135 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED);
136 if ( tm1.year != tm2.year || tm1.mon != tm2.mon )
6d9b6716 137 {
a4fcd589
VZ
138 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED);
139
6d9b6716
VZ
140 pageChanged = true;
141 }
142
a4fcd589
VZ
143 // send also one of the deprecated events
144 if ( tm1.year != tm2.year )
145 GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED);
146 else if ( tm1.mon != tm2.mon )
147 GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED);
148 else
149 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED);
6d9b6716
VZ
150
151 return pageChanged;
152}
153
154void wxCalendarCtrlBase::EnableHolidayDisplay(bool display)
155{
156 long style = GetWindowStyle();
157 if ( display )
158 style |= wxCAL_SHOW_HOLIDAYS;
159 else
160 style &= ~wxCAL_SHOW_HOLIDAYS;
161
162 if ( style == GetWindowStyle() )
163 return;
164
165 SetWindowStyle(style);
166
167 if ( display )
168 SetHolidayAttrs();
169 else
170 ResetHolidayAttrs();
171
172 RefreshHolidays();
173}
174
175bool wxCalendarCtrlBase::SetHolidayAttrs()
176{
177 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS) )
178 return false;
179
180 ResetHolidayAttrs();
181
182 wxDateTime::Tm tm = GetDate().GetTm();
183 wxDateTime dtStart(1, tm.mon, tm.year),
184 dtEnd = dtStart.GetLastMonthDay();
185
186 wxDateTimeArray hol;
187 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
188
189 const size_t count = hol.GetCount();
190 for ( size_t n = 0; n < count; n++ )
191 {
192 SetHoliday(hol[n].GetDay());
193 }
194
195 return true;
a4fcd589
VZ
196}
197
628e155d
VZ
198#endif // wxUSE_CALENDARCTRL
199