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