1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/calctrlg.cpp
3 // Purpose: implementation of the wxGenericCalendarCtrl
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/dcclient.h"
29 #include "wx/settings.h"
31 #include "wx/combobox.h"
32 #include "wx/listbox.h"
33 #include "wx/stattext.h"
34 #include "wx/textctrl.h"
38 #if wxUSE_CALENDARCTRL
40 #include "wx/spinctrl.h"
41 #include "wx/calctrl.h"
42 #include "wx/generic/calctrlg.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 #ifdef wxHAS_NATIVE_CALENDARCTRL
52 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxGenericCalendarCtrl
, wxControl
,"wx/calctrl.h")
56 BEGIN_EVENT_TABLE(wxGenericCalendarCtrl
, wxControl
)
57 EVT_PAINT(wxGenericCalendarCtrl::OnPaint
)
59 EVT_CHAR(wxGenericCalendarCtrl::OnChar
)
61 EVT_LEFT_DOWN(wxGenericCalendarCtrl::OnClick
)
62 EVT_LEFT_DCLICK(wxGenericCalendarCtrl::OnDClick
)
64 EVT_SYS_COLOUR_CHANGED(wxGenericCalendarCtrl::OnSysColourChanged
)
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
78 // add attributes that are set in attr
79 void AddAttr(wxCalendarDateAttr
*self
, const wxCalendarDateAttr
& attr
)
81 if (attr
.HasTextColour())
82 self
->SetTextColour(attr
.GetTextColour());
83 if (attr
.HasBackgroundColour())
84 self
->SetBackgroundColour(attr
.GetBackgroundColour());
85 if (attr
.HasBorderColour())
86 self
->SetBorderColour(attr
.GetBorderColour());
88 self
->SetFont(attr
.GetFont());
90 self
->SetBorder(attr
.GetBorder());
92 self
->SetHoliday(true);
95 // remove attributes that are set in attr
96 void DelAttr(wxCalendarDateAttr
*self
, const wxCalendarDateAttr
&attr
)
98 if (attr
.HasTextColour())
99 self
->SetTextColour(wxNullColour
);
100 if (attr
.HasBackgroundColour())
101 self
->SetBackgroundColour(wxNullColour
);
102 if (attr
.HasBorderColour())
103 self
->SetBorderColour(wxNullColour
);
105 self
->SetFont(wxNullFont
);
106 if (attr
.HasBorder())
107 self
->SetBorder(wxCAL_BORDER_NONE
);
108 if (attr
.IsHoliday())
109 self
->SetHoliday(false);
112 } // anonymous namespace
114 // ----------------------------------------------------------------------------
115 // wxGenericCalendarCtrl
116 // ----------------------------------------------------------------------------
118 wxGenericCalendarCtrl::wxGenericCalendarCtrl(wxWindow
*parent
,
120 const wxDateTime
& date
,
124 const wxString
& name
)
128 (void)Create(parent
, id
, date
, pos
, size
, style
, name
);
131 void wxGenericCalendarCtrl::Init()
136 m_staticMonth
= NULL
;
138 m_userChangedYear
= false;
142 m_calendarWeekWidth
= 0;
144 wxDateTime::WeekDay wd
;
145 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
147 m_weekdays
[wd
] = wxDateTime::GetWeekDayName(wd
, wxDateTime::Name_Abbr
);
150 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
158 void wxGenericCalendarCtrl::InitColours()
160 m_colHighlightFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
161 m_colHighlightBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
162 m_colBackground
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
163 m_colSurrounding
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
165 m_colHolidayFg
= *wxRED
;
166 // don't set m_colHolidayBg - by default, same as our bg colour
168 m_colHeaderFg
= *wxBLUE
;
169 m_colHeaderBg
= *wxLIGHT_GREY
;
172 bool wxGenericCalendarCtrl::Create(wxWindow
*parent
,
174 const wxDateTime
& date
,
178 const wxString
& name
)
180 if ( !wxControl::Create(parent
, id
, pos
, size
,
181 style
| wxCLIP_CHILDREN
| wxWANTS_CHARS
| wxFULL_REPAINT_ON_RESIZE
,
182 wxDefaultValidator
, name
) )
187 // needed to get the arrow keys normally used for the dialog navigation
188 SetWindowStyle(style
| wxWANTS_CHARS
);
190 m_date
= date
.IsValid() ? date
: wxDateTime::Today();
192 m_lowdate
= wxDefaultDateTime
;
193 m_highdate
= wxDefaultDateTime
;
195 if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
197 CreateYearSpinCtrl();
198 m_staticYear
= new wxStaticText(GetParent(), wxID_ANY
, m_date
.Format(wxT("%Y")),
199 wxDefaultPosition
, wxDefaultSize
,
201 CreateMonthComboBox();
202 m_staticMonth
= new wxStaticText(GetParent(), wxID_ANY
, m_date
.Format(wxT("%B")),
203 wxDefaultPosition
, wxDefaultSize
,
207 ShowCurrentControls();
209 // we need to set the position as well because the main control position
210 // is not the same as the one specified in pos if we have the controls
212 SetInitialSize(size
);
215 // Since we don't paint the whole background make sure that the platform
216 // will use the right one.
217 SetBackgroundColour(m_colBackground
);
224 wxGenericCalendarCtrl::~wxGenericCalendarCtrl()
226 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
231 if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
234 delete m_staticMonth
;
240 void wxGenericCalendarCtrl::SetWindowStyleFlag(long style
)
242 // changing this style doesn't work because the controls are not
243 // created/shown/hidden accordingly
244 wxASSERT_MSG( (style
& wxCAL_SEQUENTIAL_MONTH_SELECTION
) ==
245 (m_windowStyle
& wxCAL_SEQUENTIAL_MONTH_SELECTION
),
246 wxT("wxCAL_SEQUENTIAL_MONTH_SELECTION can't be changed after creation") );
248 wxControl::SetWindowStyleFlag(style
);
251 // ----------------------------------------------------------------------------
252 // Create the wxComboBox and wxSpinCtrl
253 // ----------------------------------------------------------------------------
255 void wxGenericCalendarCtrl::CreateMonthComboBox()
257 m_comboMonth
= new wxComboBox(GetParent(), wxID_ANY
,
262 wxCB_READONLY
| wxCLIP_SIBLINGS
);
265 for ( m
= wxDateTime::Jan
; m
< wxDateTime::Inv_Month
; wxNextMonth(m
) )
267 m_comboMonth
->Append(wxDateTime::GetMonthName(m
));
270 m_comboMonth
->SetSelection(GetDate().GetMonth());
271 m_comboMonth
->SetSize(wxDefaultCoord
,
275 wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
277 m_comboMonth
->Connect(m_comboMonth
->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED
,
278 wxCommandEventHandler(wxGenericCalendarCtrl::OnMonthChange
),
282 void wxGenericCalendarCtrl::CreateYearSpinCtrl()
284 m_spinYear
= new wxSpinCtrl(GetParent(), wxID_ANY
,
285 GetDate().Format(wxT("%Y")),
288 wxSP_ARROW_KEYS
| wxCLIP_SIBLINGS
,
289 -4300, 10000, GetDate().GetYear());
291 m_spinYear
->SetSize( 90, -1 );
294 m_spinYear
->Connect(m_spinYear
->GetId(), wxEVT_COMMAND_TEXT_UPDATED
,
295 wxCommandEventHandler(wxGenericCalendarCtrl::OnYearTextChange
),
298 m_spinYear
->Connect(m_spinYear
->GetId(), wxEVT_COMMAND_SPINCTRL_UPDATED
,
299 wxSpinEventHandler(wxGenericCalendarCtrl::OnYearChange
),
303 // ----------------------------------------------------------------------------
304 // forward wxWin functions to subcontrols
305 // ----------------------------------------------------------------------------
307 bool wxGenericCalendarCtrl::Destroy()
310 m_staticYear
->Destroy();
312 m_spinYear
->Destroy();
314 m_comboMonth
->Destroy();
316 m_staticMonth
->Destroy();
321 m_staticMonth
= NULL
;
323 return wxControl::Destroy();
326 bool wxGenericCalendarCtrl::Show(bool show
)
328 if ( !wxControl::Show(show
) )
333 if ( !(GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
335 if ( GetMonthControl() )
337 GetMonthControl()->Show(show
);
338 GetYearControl()->Show(show
);
345 bool wxGenericCalendarCtrl::Enable(bool enable
)
347 if ( !wxControl::Enable(enable
) )
352 if ( !(GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
354 GetMonthControl()->Enable(enable
);
355 GetYearControl()->Enable(enable
);
361 // ----------------------------------------------------------------------------
362 // enable/disable month/year controls
363 // ----------------------------------------------------------------------------
365 void wxGenericCalendarCtrl::ShowCurrentControls()
367 if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
369 if ( AllowMonthChange() )
371 m_comboMonth
->Show();
372 m_staticMonth
->Hide();
374 if ( AllowYearChange() )
377 m_staticYear
->Hide();
385 m_comboMonth
->Hide();
386 m_staticMonth
->Show();
389 // year change not allowed here
391 m_staticYear
->Show();
393 //else: these controls are not even created, don't show/hide them
396 wxControl
*wxGenericCalendarCtrl::GetMonthControl() const
398 return AllowMonthChange() ? (wxControl
*)m_comboMonth
: (wxControl
*)m_staticMonth
;
401 wxControl
*wxGenericCalendarCtrl::GetYearControl() const
403 return AllowYearChange() ? (wxControl
*)m_spinYear
: (wxControl
*)m_staticYear
;
406 void wxGenericCalendarCtrl::EnableYearChange(bool enable
)
408 if ( enable
!= AllowYearChange() )
410 long style
= GetWindowStyle();
412 style
&= ~wxCAL_NO_YEAR_CHANGE
;
414 style
|= wxCAL_NO_YEAR_CHANGE
;
415 SetWindowStyle(style
);
417 ShowCurrentControls();
418 if ( GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION
)
425 bool wxGenericCalendarCtrl::EnableMonthChange(bool enable
)
427 if ( !wxCalendarCtrlBase::EnableMonthChange(enable
) )
430 ShowCurrentControls();
431 if ( GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION
)
437 // ----------------------------------------------------------------------------
439 // ----------------------------------------------------------------------------
441 bool wxGenericCalendarCtrl::SetDate(const wxDateTime
& date
)
445 bool sameMonth
= m_date
.GetMonth() == date
.GetMonth(),
446 sameYear
= m_date
.GetYear() == date
.GetYear();
448 if ( IsDateInRange(date
) )
450 if ( sameMonth
&& sameYear
)
452 // just change the day
457 if ( AllowMonthChange() && (AllowYearChange() || sameYear
) )
462 if ( !(GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
464 // update the controls
465 m_comboMonth
->SetSelection(m_date
.GetMonth());
467 if ( AllowYearChange() )
469 if ( !m_userChangedYear
)
470 m_spinYear
->SetValue(m_date
.Format(wxT("%Y")));
474 // as the month changed, holidays did too
477 // update the calendar
488 m_userChangedYear
= false;
493 void wxGenericCalendarCtrl::ChangeDay(const wxDateTime
& date
)
495 if ( m_date
!= date
)
497 // we need to refresh the row containing the old date and the one
498 // containing the new one
499 wxDateTime dateOld
= m_date
;
502 RefreshDate(dateOld
);
504 // if the date is in the same row, it was already drawn correctly
505 if ( GetWeek(m_date
) != GetWeek(dateOld
) )
512 void wxGenericCalendarCtrl::SetDateAndNotify(const wxDateTime
& date
)
514 const wxDateTime dateOld
= GetDate();
515 if ( date
!= dateOld
&& SetDate(date
) )
517 GenerateAllChangeEvents(dateOld
);
521 // ----------------------------------------------------------------------------
523 // ----------------------------------------------------------------------------
525 bool wxGenericCalendarCtrl::SetLowerDateLimit(const wxDateTime
& date
/* = wxDefaultDateTime */)
529 if ( !(date
.IsValid()) || ( ( m_highdate
.IsValid() ) ? ( date
<= m_highdate
) : true ) )
541 bool wxGenericCalendarCtrl::SetUpperDateLimit(const wxDateTime
& date
/* = wxDefaultDateTime */)
545 if ( !(date
.IsValid()) || ( ( m_lowdate
.IsValid() ) ? ( date
>= m_lowdate
) : true ) )
557 bool wxGenericCalendarCtrl::SetDateRange(const wxDateTime
& lowerdate
/* = wxDefaultDateTime */, const wxDateTime
& upperdate
/* = wxDefaultDateTime */)
562 ( !( lowerdate
.IsValid() ) || ( ( upperdate
.IsValid() ) ? ( lowerdate
<= upperdate
) : true ) ) &&
563 ( !( upperdate
.IsValid() ) || ( ( lowerdate
.IsValid() ) ? ( upperdate
>= lowerdate
) : true ) ) )
565 m_lowdate
= lowerdate
;
566 m_highdate
= upperdate
;
576 bool wxGenericCalendarCtrl::GetDateRange(wxDateTime
*lowerdate
,
577 wxDateTime
*upperdate
) const
580 *lowerdate
= m_lowdate
;
582 *upperdate
= m_highdate
;
584 return m_lowdate
.IsValid() || m_highdate
.IsValid();
587 // ----------------------------------------------------------------------------
589 // ----------------------------------------------------------------------------
591 wxDateTime
wxGenericCalendarCtrl::GetStartDate() const
593 wxDateTime::Tm tm
= m_date
.GetTm();
595 wxDateTime date
= wxDateTime(1, tm
.mon
, tm
.year
);
598 date
.SetToPrevWeekDay(GetWeekStart());
600 if ( GetWindowStyle() & wxCAL_SHOW_SURROUNDING_WEEKS
)
602 // We want to offset the calendar if we start on the first..
603 if ( date
.GetDay() == 1 )
605 date
-= wxDateSpan::Week();
612 bool wxGenericCalendarCtrl::IsDateShown(const wxDateTime
& date
) const
614 if ( !(GetWindowStyle() & wxCAL_SHOW_SURROUNDING_WEEKS
) )
616 return date
.GetMonth() == m_date
.GetMonth();
624 bool wxGenericCalendarCtrl::IsDateInRange(const wxDateTime
& date
) const
626 // Check if the given date is in the range specified
627 return ( ( ( m_lowdate
.IsValid() ) ? ( date
>= m_lowdate
) : true )
628 && ( ( m_highdate
.IsValid() ) ? ( date
<= m_highdate
) : true ) );
631 bool wxGenericCalendarCtrl::AdjustDateToRange(wxDateTime
*date
) const
633 if ( m_lowdate
.IsValid() && *date
< m_lowdate
)
639 if ( m_highdate
.IsValid() && *date
> m_highdate
)
648 size_t wxGenericCalendarCtrl::GetWeek(const wxDateTime
& date
) const
650 size_t retval
= date
.GetWeekOfMonth(HasFlag(wxCAL_MONDAY_FIRST
)
651 ? wxDateTime::Monday_First
652 : wxDateTime::Sunday_First
);
654 if ( (GetWindowStyle() & wxCAL_SHOW_SURROUNDING_WEEKS
) )
656 // we need to offset an extra week if we "start" on the 1st of the month
657 wxDateTime::Tm tm
= date
.GetTm();
659 wxDateTime datetest
= wxDateTime(1, tm
.mon
, tm
.year
);
662 datetest
.SetToPrevWeekDay(GetWeekStart());
664 if ( datetest
.GetDay() == 1 )
673 // ----------------------------------------------------------------------------
675 // ----------------------------------------------------------------------------
677 // this is a composite control and it must arrange its parts each time its
678 // size or position changes: the combobox and spinctrl are along the top of
679 // the available area and the calendar takes up the rest of the space
681 // the static controls are supposed to be always smaller than combo/spin so we
682 // always use the latter for size calculations and position the static to take
685 // the constants used for the layout
686 #define VERT_MARGIN 5 // distance between combo and calendar
687 #define HORZ_MARGIN 5 // spin
689 wxSize
wxGenericCalendarCtrl::DoGetBestSize() const
691 // calc the size of the calendar
692 const_cast<wxGenericCalendarCtrl
*>(this)->RecalcGeometry();
694 wxCoord width
= 7*m_widthCol
+ m_calendarWeekWidth
,
695 height
= 7*m_heightRow
+ m_rowOffset
+ VERT_MARGIN
;
697 if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
699 const wxSize bestSizeCombo
= m_comboMonth
->GetBestSize();
701 height
+= wxMax(bestSizeCombo
.y
, m_spinYear
->GetBestSize().y
)
704 // the spin control get clipped otherwise
708 wxCoord w2
= bestSizeCombo
.x
+ HORZ_MARGIN
+ GetCharWidth()*6;
713 wxSize
best(width
, height
);
714 if ( !HasFlag(wxBORDER_NONE
) )
716 best
+= GetWindowBorderSize();
724 void wxGenericCalendarCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
728 if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) && m_staticMonth
)
730 wxSize sizeCombo
= m_comboMonth
->GetEffectiveMinSize();
731 wxSize sizeStatic
= m_staticMonth
->GetSize();
732 wxSize sizeSpin
= m_spinYear
->GetSize();
734 int maxHeight
= wxMax(sizeSpin
.y
, sizeCombo
.y
);
735 int dy
= (maxHeight
- sizeStatic
.y
) / 2;
737 m_comboMonth
->Move(x
, y
+ (maxHeight
- sizeCombo
.y
)/2 + 2); // FIXME, something is reporting the wrong size..
739 m_comboMonth
->Move(x
, y
+ (maxHeight
- sizeCombo
.y
)/2);
741 m_staticMonth
->SetSize(x
, y
+ dy
, sizeCombo
.x
, -1, sizeStatic
.y
);
743 int xDiff
= sizeCombo
.x
+ HORZ_MARGIN
;
745 m_spinYear
->SetSize(x
+ xDiff
, y
+ (maxHeight
- sizeSpin
.y
)/2, width
- xDiff
, maxHeight
);
746 m_staticYear
->SetSize(x
+ xDiff
, y
+ dy
, width
- xDiff
, sizeStatic
.y
);
748 yDiff
= maxHeight
+ VERT_MARGIN
;
750 else // no controls on the top
755 wxControl::DoMoveWindow(x
, y
+ yDiff
, width
, height
- yDiff
);
758 void wxGenericCalendarCtrl::DoGetSize(int *width
, int *height
) const
761 wxControl::DoGetSize( width
, height
);
763 if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) && m_staticMonth
&& height
)
765 wxSize sizeCombo
= m_comboMonth
->GetEffectiveMinSize();
766 wxSize sizeSpin
= m_spinYear
->GetSize();
768 int maxHeight
= wxMax(sizeSpin
.y
, sizeCombo
.y
);
769 *height
+= maxHeight
+ VERT_MARGIN
;
772 wxControl::DoGetSize( width
, height
);
776 void wxGenericCalendarCtrl::RecalcGeometry()
780 dc
.SetFont(GetFont());
782 // determine the column width (weekday names are not necessarily wider
783 // than the numbers (in some languages), so let's not assume that they are)
785 for ( int day
= 10; day
<= 31; day
++)
788 dc
.GetTextExtent(wxString::Format(wxT("%d"), day
), &width
, &m_heightRow
);
789 if ( width
> m_widthCol
)
791 // 1.5 times the width gives nice margins even if the weekday
793 m_widthCol
= width
+width
/2;
796 wxDateTime::WeekDay wd
;
797 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
800 dc
.GetTextExtent(m_weekdays
[wd
], &width
, &m_heightRow
);
801 if ( width
> m_widthCol
)
807 m_calendarWeekWidth
= HasFlag( wxCAL_SHOW_WEEK_NUMBERS
)
808 ? dc
.GetTextExtent( wxString::Format( wxT( "%d" ), 42 )).GetWidth() + 4 : 0;
810 // leave some margins
814 m_rowOffset
= HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) ? m_heightRow
: 0; // conditional in relation to style
817 // ----------------------------------------------------------------------------
819 // ----------------------------------------------------------------------------
821 void wxGenericCalendarCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
825 dc
.SetFont(GetFont());
830 wxLogDebug("--- starting to paint, selection: %s, week %u\n",
831 m_date
.Format("%a %d-%m-%Y %H:%M:%S").c_str(),
836 wxCoord x0
= m_calendarWeekWidth
;
838 if ( HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
840 // draw the sequential month-selector
842 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
843 dc
.SetTextForeground(*wxBLACK
);
844 dc
.SetBrush(wxBrush(m_colHeaderBg
, wxBRUSHSTYLE_SOLID
));
845 dc
.SetPen(wxPen(m_colHeaderBg
, 1, wxPENSTYLE_SOLID
));
846 dc
.DrawRectangle(0, y
, GetClientSize().x
, m_heightRow
);
848 // Get extent of month-name + year
849 wxCoord monthw
, monthh
;
850 wxString headertext
= m_date
.Format(wxT("%B %Y"));
851 dc
.GetTextExtent(headertext
, &monthw
, &monthh
);
853 // draw month-name centered above weekdays
854 wxCoord monthx
= ((m_widthCol
* 7) - monthw
) / 2 + x0
;
855 wxCoord monthy
= ((m_heightRow
- monthh
) / 2) + y
;
856 dc
.DrawText(headertext
, monthx
, monthy
);
858 // calculate the "month-arrows"
859 wxPoint leftarrow
[3];
860 wxPoint rightarrow
[3];
862 int arrowheight
= monthh
/ 2;
864 leftarrow
[0] = wxPoint(0, arrowheight
/ 2);
865 leftarrow
[1] = wxPoint(arrowheight
/ 2, 0);
866 leftarrow
[2] = wxPoint(arrowheight
/ 2, arrowheight
- 1);
868 rightarrow
[0] = wxPoint(0,0);
869 rightarrow
[1] = wxPoint(arrowheight
/ 2, arrowheight
/ 2);
870 rightarrow
[2] = wxPoint(0, arrowheight
- 1);
872 // draw the "month-arrows"
874 wxCoord arrowy
= (m_heightRow
- arrowheight
) / 2;
875 wxCoord larrowx
= (m_widthCol
- (arrowheight
/ 2)) / 2 + x0
;
876 wxCoord rarrowx
= ((m_widthCol
- (arrowheight
/ 2)) / 2) + m_widthCol
*6 + x0
;
877 m_leftArrowRect
= m_rightArrowRect
= wxRect(0,0,0,0);
879 if ( AllowMonthChange() )
881 wxDateTime ldpm
= wxDateTime(1,m_date
.GetMonth(), m_date
.GetYear()) - wxDateSpan::Day(); // last day prev month
882 // Check if range permits change
883 if ( IsDateInRange(ldpm
) && ( ( ldpm
.GetYear() == m_date
.GetYear() ) ? true : AllowYearChange() ) )
885 m_leftArrowRect
= wxRect(larrowx
- 3, arrowy
- 3, (arrowheight
/ 2) + 8, (arrowheight
+ 6));
886 dc
.SetBrush(*wxBLACK_BRUSH
);
887 dc
.SetPen(*wxBLACK_PEN
);
888 dc
.DrawPolygon(3, leftarrow
, larrowx
, arrowy
, wxWINDING_RULE
);
889 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
890 dc
.DrawRectangle(m_leftArrowRect
);
892 wxDateTime fdnm
= wxDateTime(1,m_date
.GetMonth(), m_date
.GetYear()) + wxDateSpan::Month(); // first day next month
893 if ( IsDateInRange(fdnm
) && ( ( fdnm
.GetYear() == m_date
.GetYear() ) ? true : AllowYearChange() ) )
895 m_rightArrowRect
= wxRect(rarrowx
- 4, arrowy
- 3, (arrowheight
/ 2) + 8, (arrowheight
+ 6));
896 dc
.SetBrush(*wxBLACK_BRUSH
);
897 dc
.SetPen(*wxBLACK_PEN
);
898 dc
.DrawPolygon(3, rightarrow
, rarrowx
, arrowy
, wxWINDING_RULE
);
899 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
900 dc
.DrawRectangle(m_rightArrowRect
);
907 // first draw the week days
908 if ( IsExposed(x0
, y
, x0
+ 7*m_widthCol
, m_heightRow
) )
911 wxLogDebug("painting the header");
914 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
915 dc
.SetTextForeground(m_colHeaderFg
);
916 dc
.SetBrush(wxBrush(m_colHeaderBg
, wxBRUSHSTYLE_SOLID
));
917 dc
.SetPen(wxPen(m_colHeaderBg
, 1, wxPENSTYLE_SOLID
));
918 dc
.DrawRectangle(0, y
, GetClientSize().x
, m_heightRow
);
920 bool startOnMonday
= HasFlag(wxCAL_MONDAY_FIRST
);
921 for ( int wd
= 0; wd
< 7; wd
++ )
925 n
= wd
== 6 ? 0 : wd
+ 1;
929 dc
.GetTextExtent(m_weekdays
[n
], &dayw
, &dayh
);
930 dc
.DrawText(m_weekdays
[n
], x0
+ (wd
*m_widthCol
) + ((m_widthCol
- dayw
) / 2), y
); // center the day-name
934 // then the calendar itself
935 dc
.SetTextForeground(*wxBLACK
);
936 //dc.SetFont(*wxNORMAL_FONT);
940 // draw column with calendar week nr
941 if ( HasFlag( wxCAL_SHOW_WEEK_NUMBERS
) && IsExposed( 0, y
, m_calendarWeekWidth
, m_heightRow
* 6 ))
943 dc
.SetBackgroundMode(wxTRANSPARENT
);
944 dc
.SetBrush(wxBrush(m_colHeaderBg
, wxSOLID
));
945 dc
.SetPen(wxPen(m_colHeaderBg
, 1, wxSOLID
));
946 dc
.DrawRectangle( 0, y
, m_calendarWeekWidth
, m_heightRow
* 6 );
947 wxDateTime date
= GetStartDate();
948 for ( size_t i
= 0; i
< 6; ++i
)
950 const int weekNr
= date
.GetWeekOfYear();
951 wxString text
= wxString::Format( wxT( "%d" ), weekNr
);
952 dc
.DrawText( text
, m_calendarWeekWidth
- dc
.GetTextExtent( text
).GetWidth() - 2, y
+ m_heightRow
* i
);
953 date
+= wxDateSpan::Week();
957 wxDateTime date
= GetStartDate();
960 wxLogDebug("starting calendar from %s\n",
961 date
.Format("%a %d-%m-%Y %H:%M:%S").c_str());
964 dc
.SetBackgroundMode(wxBRUSHSTYLE_SOLID
);
965 for ( size_t nWeek
= 1; nWeek
<= 6; nWeek
++, y
+= m_heightRow
)
967 // if the update region doesn't intersect this row, don't paint it
968 if ( !IsExposed(x0
, y
, x0
+ 7*m_widthCol
, m_heightRow
- 1) )
970 date
+= wxDateSpan::Week();
976 wxLogDebug("painting week %d at y = %d\n", nWeek
, y
);
979 for ( int wd
= 0; wd
< 7; wd
++ )
981 dc
.SetTextBackground(m_colBackground
);
982 if ( IsDateShown(date
) )
984 // don't use wxDate::Format() which prepends 0s
985 unsigned int day
= date
.GetDay();
986 wxString dayStr
= wxString::Format(wxT("%u"), day
);
988 dc
.GetTextExtent(dayStr
, &width
, NULL
);
990 bool changedColours
= false,
994 wxCalendarDateAttr
*attr
= NULL
;
996 if ( date
.GetMonth() != m_date
.GetMonth() || !IsDateInRange(date
) )
998 // draw the days of adjacent months in different colour
999 dc
.SetTextForeground(m_colSurrounding
);
1000 changedColours
= true;
1004 isSel
= date
.IsSameDate(m_date
);
1005 attr
= m_attrs
[day
- 1];
1009 dc
.SetTextForeground(m_colHighlightFg
);
1010 dc
.SetTextBackground(m_colHighlightBg
);
1012 changedColours
= true;
1016 wxColour colFg
, colBg
;
1018 if ( attr
->IsHoliday() )
1020 colFg
= m_colHolidayFg
;
1021 colBg
= m_colHolidayBg
;
1025 colFg
= attr
->GetTextColour();
1026 colBg
= attr
->GetBackgroundColour();
1031 dc
.SetTextForeground(colFg
);
1032 changedColours
= true;
1037 dc
.SetTextBackground(colBg
);
1038 changedColours
= true;
1041 if ( attr
->HasFont() )
1043 dc
.SetFont(attr
->GetFont());
1049 wxCoord x
= wd
*m_widthCol
+ (m_widthCol
- width
) / 2 + x0
;
1050 dc
.DrawText(dayStr
, x
, y
+ 1);
1052 if ( !isSel
&& attr
&& attr
->HasBorder() )
1055 if ( attr
->HasBorderColour() )
1057 colBorder
= attr
->GetBorderColour();
1061 colBorder
= GetForegroundColour();
1064 wxPen
pen(colBorder
, 1, wxPENSTYLE_SOLID
);
1066 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1068 switch ( attr
->GetBorder() )
1070 case wxCAL_BORDER_SQUARE
:
1071 dc
.DrawRectangle(x
- 2, y
,
1072 width
+ 4, m_heightRow
);
1075 case wxCAL_BORDER_ROUND
:
1076 dc
.DrawEllipse(x
- 2, y
,
1077 width
+ 4, m_heightRow
);
1081 wxFAIL_MSG(wxT("unknown border type"));
1085 if ( changedColours
)
1087 dc
.SetTextForeground(GetForegroundColour());
1088 dc
.SetTextBackground(GetBackgroundColour());
1093 dc
.SetFont(GetFont());
1096 //else: just don't draw it
1098 date
+= wxDateSpan::Day();
1102 // Greying out out-of-range background
1103 bool showSurrounding
= (GetWindowStyle() & wxCAL_SHOW_SURROUNDING_WEEKS
) != 0;
1105 date
= ( showSurrounding
) ? GetStartDate() : wxDateTime(1, m_date
.GetMonth(), m_date
.GetYear());
1106 if ( !IsDateInRange(date
) )
1108 wxDateTime firstOOR
= GetLowerDateLimit() - wxDateSpan::Day(); // first out-of-range
1110 wxBrush oorbrush
= *wxLIGHT_GREY_BRUSH
;
1111 oorbrush
.SetStyle(wxBRUSHSTYLE_FDIAGONAL_HATCH
);
1113 HighlightRange(&dc
, date
, firstOOR
, wxTRANSPARENT_PEN
, &oorbrush
);
1116 date
= ( showSurrounding
) ? GetStartDate() + wxDateSpan::Weeks(6) - wxDateSpan::Day() : wxDateTime().SetToLastMonthDay(m_date
.GetMonth(), m_date
.GetYear());
1117 if ( !IsDateInRange(date
) )
1119 wxDateTime firstOOR
= GetUpperDateLimit() + wxDateSpan::Day(); // first out-of-range
1121 wxBrush oorbrush
= *wxLIGHT_GREY_BRUSH
;
1122 oorbrush
.SetStyle(wxBRUSHSTYLE_FDIAGONAL_HATCH
);
1124 HighlightRange(&dc
, firstOOR
, date
, wxTRANSPARENT_PEN
, &oorbrush
);
1128 wxLogDebug("+++ finished painting");
1132 void wxGenericCalendarCtrl::RefreshDate(const wxDateTime
& date
)
1138 // always refresh the whole row at once because our OnPaint() will draw
1139 // the whole row anyhow - and this allows the small optimization in
1140 // OnClick() below to work
1141 rect
.x
= m_calendarWeekWidth
;
1143 rect
.y
= (m_heightRow
* GetWeek(date
)) + m_rowOffset
;
1145 rect
.width
= 7*m_widthCol
;
1146 rect
.height
= m_heightRow
;
1149 // VZ: for some reason, the selected date seems to occupy more space under
1150 // MSW - this is probably some bug in the font size calculations, but I
1151 // don't know where exactly. This fix is ugly and leads to more
1152 // refreshes than really needed, but without it the selected days
1153 // leaves even more ugly underscores on screen.
1158 wxLogDebug("*** refreshing week %d at (%d, %d)-(%d, %d)\n",
1161 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
1164 Refresh(true, &rect
);
1167 void wxGenericCalendarCtrl::HighlightRange(wxPaintDC
* pDC
, const wxDateTime
& fromdate
, const wxDateTime
& todate
, const wxPen
* pPen
, const wxBrush
* pBrush
)
1169 // Highlights the given range using pen and brush
1170 // Does nothing if todate < fromdate
1174 wxLogDebug("+++ HighlightRange: (%s) - (%s) +++", fromdate
.Format("%d %m %Y"), todate
.Format("%d %m %Y"));
1177 if ( todate
>= fromdate
)
1184 // implicit: both dates must be currently shown - checked by GetDateCoord
1185 if ( GetDateCoord(fromdate
, &fd
, &fw
) && GetDateCoord(todate
, &td
, &tw
) )
1188 wxLogDebug("Highlight range: (%i, %i) - (%i, %i)", fd
, fw
, td
, tw
);
1190 if ( ( (tw
- fw
) == 1 ) && ( td
< fd
) )
1192 // special case: interval 7 days or less not in same week
1193 // split in two separate intervals
1194 wxDateTime tfd
= fromdate
+ wxDateSpan::Days(7-fd
);
1195 wxDateTime ftd
= tfd
+ wxDateSpan::Day();
1197 wxLogDebug("Highlight: Separate segments");
1200 HighlightRange(pDC
, fromdate
, tfd
, pPen
, pBrush
);
1201 HighlightRange(pDC
, ftd
, todate
, pPen
, pBrush
);
1206 wxPoint corners
[8]; // potentially 8 corners in polygon
1207 wxCoord x0
= m_calendarWeekWidth
;
1211 // simple case: same week
1213 corners
[0] = wxPoint(x0
+ (fd
- 1) * m_widthCol
, (fw
* m_heightRow
) + m_rowOffset
);
1214 corners
[1] = wxPoint(x0
+ (fd
- 1) * m_widthCol
, ((fw
+ 1 ) * m_heightRow
) + m_rowOffset
);
1215 corners
[2] = wxPoint(x0
+ td
* m_widthCol
, ((tw
+ 1) * m_heightRow
) + m_rowOffset
);
1216 corners
[3] = wxPoint(x0
+ td
* m_widthCol
, (tw
* m_heightRow
) + m_rowOffset
);
1221 // "complex" polygon
1222 corners
[cidx
] = wxPoint(x0
+ (fd
- 1) * m_widthCol
, (fw
* m_heightRow
) + m_rowOffset
); cidx
++;
1226 corners
[cidx
] = wxPoint(x0
+ (fd
- 1) * m_widthCol
, ((fw
+ 1) * m_heightRow
) + m_rowOffset
); cidx
++;
1227 corners
[cidx
] = wxPoint(x0
, ((fw
+ 1) * m_heightRow
) + m_rowOffset
); cidx
++;
1230 corners
[cidx
] = wxPoint(x0
, ((tw
+ 1) * m_heightRow
) + m_rowOffset
); cidx
++;
1231 corners
[cidx
] = wxPoint(x0
+ td
* m_widthCol
, ((tw
+ 1) * m_heightRow
) + m_rowOffset
); cidx
++;
1235 corners
[cidx
] = wxPoint(x0
+ td
* m_widthCol
, (tw
* m_heightRow
) + m_rowOffset
); cidx
++;
1236 corners
[cidx
] = wxPoint(x0
+ 7 * m_widthCol
, (tw
* m_heightRow
) + m_rowOffset
); cidx
++;
1239 corners
[cidx
] = wxPoint(x0
+ 7 * m_widthCol
, (fw
* m_heightRow
) + m_rowOffset
); cidx
++;
1245 pDC
->SetBrush(*pBrush
);
1247 pDC
->DrawPolygon(numpoints
, corners
);
1253 wxLogDebug("--- HighlightRange ---");
1257 bool wxGenericCalendarCtrl::GetDateCoord(const wxDateTime
& date
, int *day
, int *week
) const
1262 wxLogDebug("+++ GetDateCoord: (%s) +++", date
.Format("%d %m %Y"));
1265 if ( IsDateShown(date
) )
1267 bool startOnMonday
= HasFlag(wxCAL_MONDAY_FIRST
);
1270 *day
= date
.GetWeekDay();
1272 if ( *day
== 0 ) // sunday
1274 *day
= ( startOnMonday
) ? 7 : 1;
1278 *day
+= ( startOnMonday
) ? 0 : 1;
1281 int targetmonth
= date
.GetMonth() + (12 * date
.GetYear());
1282 int thismonth
= m_date
.GetMonth() + (12 * m_date
.GetYear());
1285 if ( targetmonth
== thismonth
)
1287 *week
= GetWeek(date
);
1291 if ( targetmonth
< thismonth
)
1293 *week
= 1; // trivial
1295 else // targetmonth > thismonth
1301 // get the datecoord of the last day in the month currently shown
1303 wxLogDebug(" +++ LDOM +++");
1305 GetDateCoord(ldcm
.SetToLastMonthDay(m_date
.GetMonth(), m_date
.GetYear()), &lastday
, &lastweek
);
1307 wxLogDebug(" --- LDOM ---");
1310 wxTimeSpan span
= date
- ldcm
;
1312 int daysfromlast
= span
.GetDays();
1314 wxLogDebug("daysfromlast: %i", daysfromlast
);
1316 if ( daysfromlast
+ lastday
> 7 ) // past week boundary
1318 int wholeweeks
= (daysfromlast
/ 7);
1319 *week
= wholeweeks
+ lastweek
;
1320 if ( (daysfromlast
- (7 * wholeweeks
) + lastday
) > 7 )
1340 wxLogDebug("--- GetDateCoord: (%s) = (%i, %i) ---", date
.Format("%d %m %Y"), *day
, *week
);
1346 // ----------------------------------------------------------------------------
1348 // ----------------------------------------------------------------------------
1350 void wxGenericCalendarCtrl::OnDClick(wxMouseEvent
& event
)
1352 if ( HitTest(event
.GetPosition()) != wxCAL_HITTEST_DAY
)
1358 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
1362 void wxGenericCalendarCtrl::OnClick(wxMouseEvent
& event
)
1365 wxDateTime::WeekDay wday
;
1366 switch ( HitTest(event
.GetPosition(), &date
, &wday
) )
1368 case wxCAL_HITTEST_DAY
:
1369 if ( IsDateInRange(date
) )
1373 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
1375 // we know that the month/year never change when the user
1376 // clicks on the control so there is no need to call
1377 // GenerateAllChangeEvents() here, we know which event to send
1378 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED
);
1382 case wxCAL_HITTEST_WEEK
:
1384 wxCalendarEvent
send( this, date
, wxEVT_CALENDAR_WEEK_CLICKED
);
1385 HandleWindowEvent( send
);
1389 case wxCAL_HITTEST_HEADER
:
1391 wxCalendarEvent
eventWd(this, GetDate(),
1392 wxEVT_CALENDAR_WEEKDAY_CLICKED
);
1393 eventWd
.SetWeekDay(wday
);
1394 (void)GetEventHandler()->ProcessEvent(eventWd
);
1398 case wxCAL_HITTEST_DECMONTH
:
1399 case wxCAL_HITTEST_INCMONTH
:
1400 case wxCAL_HITTEST_SURROUNDING_WEEK
:
1401 SetDateAndNotify(date
); // we probably only want to refresh the control. No notification.. (maybe as an option?)
1405 wxFAIL_MSG(wxT("unknown hittest code"));
1408 case wxCAL_HITTEST_NOWHERE
:
1413 // as we don't (always) skip the message, we're not going to receive the
1414 // focus on click by default if we don't do it ourselves
1418 wxCalendarHitTestResult
wxGenericCalendarCtrl::HitTest(const wxPoint
& pos
,
1420 wxDateTime::WeekDay
*wd
)
1424 // the position where the calendar really begins
1425 wxCoord x0
= m_calendarWeekWidth
;
1427 if ( HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION
) )
1431 // we need to find out if the hit is on left arrow, on month or on right arrow
1433 if ( m_leftArrowRect
.Contains(pos
) )
1437 if ( IsDateInRange(m_date
- wxDateSpan::Month()) )
1439 *date
= m_date
- wxDateSpan::Month();
1443 *date
= GetLowerDateLimit();
1447 return wxCAL_HITTEST_DECMONTH
;
1450 if ( m_rightArrowRect
.Contains(pos
) )
1454 if ( IsDateInRange(m_date
+ wxDateSpan::Month()) )
1456 *date
= m_date
+ wxDateSpan::Month();
1460 *date
= GetUpperDateLimit();
1464 return wxCAL_HITTEST_INCMONTH
;
1468 if ( pos
.x
- x0
< 0 )
1470 if ( pos
.x
>= 0 && pos
.y
> m_rowOffset
+ m_heightRow
&& pos
.y
<= m_rowOffset
+ m_heightRow
* 7 )
1474 *date
= GetStartDate();
1475 *date
+= wxDateSpan::Week() * (( pos
.y
- m_rowOffset
) / m_heightRow
- 1 );
1478 *wd
= GetWeekStart();
1479 return wxCAL_HITTEST_WEEK
;
1481 else // early exit -> the rest of the function checks for clicks on days
1482 return wxCAL_HITTEST_NOWHERE
;
1485 // header: week days
1486 int wday
= (pos
.x
- x0
) / m_widthCol
;
1488 return wxCAL_HITTEST_NOWHERE
;
1489 if ( pos
.y
< (m_heightRow
+ m_rowOffset
))
1491 if ( pos
.y
> m_rowOffset
)
1495 if ( HasFlag(wxCAL_MONDAY_FIRST
) )
1497 wday
= wday
== 6 ? 0 : wday
+ 1;
1500 *wd
= (wxDateTime::WeekDay
)wday
;
1503 return wxCAL_HITTEST_HEADER
;
1507 return wxCAL_HITTEST_NOWHERE
;
1511 int week
= (pos
.y
- (m_heightRow
+ m_rowOffset
)) / m_heightRow
;
1512 if ( week
>= 6 || wday
>= 7 )
1514 return wxCAL_HITTEST_NOWHERE
;
1517 wxDateTime dt
= GetStartDate() + wxDateSpan::Days(7*week
+ wday
);
1519 if ( IsDateShown(dt
) )
1524 if ( dt
.GetMonth() == m_date
.GetMonth() )
1527 return wxCAL_HITTEST_DAY
;
1531 return wxCAL_HITTEST_SURROUNDING_WEEK
;
1536 return wxCAL_HITTEST_NOWHERE
;
1540 // ----------------------------------------------------------------------------
1541 // subcontrols events handling
1542 // ----------------------------------------------------------------------------
1544 void wxGenericCalendarCtrl::OnMonthChange(wxCommandEvent
& event
)
1546 wxDateTime::Tm tm
= m_date
.GetTm();
1548 wxDateTime::Month mon
= (wxDateTime::Month
)event
.GetInt();
1549 if ( tm
.mday
> wxDateTime::GetNumberOfDays(mon
, tm
.year
) )
1551 tm
.mday
= wxDateTime::GetNumberOfDays(mon
, tm
.year
);
1554 wxDateTime
dt(tm
.mday
, mon
, tm
.year
);
1555 if ( AdjustDateToRange(&dt
) )
1557 // The date must have been changed to ensure it's in valid range,
1558 // reflect this in the month choice control.
1559 m_comboMonth
->SetSelection(dt
.GetMonth());
1562 SetDateAndNotify(dt
);
1565 void wxGenericCalendarCtrl::HandleYearChange(wxCommandEvent
& event
)
1567 int year
= (int)event
.GetInt();
1568 if ( year
== INT_MIN
)
1570 // invalid year in the spin control, ignore it
1574 wxDateTime::Tm tm
= m_date
.GetTm();
1576 if ( tm
.mday
> wxDateTime::GetNumberOfDays(tm
.mon
, year
) )
1578 tm
.mday
= wxDateTime::GetNumberOfDays(tm
.mon
, year
);
1581 wxDateTime
dt(tm
.mday
, tm
.mon
, year
);
1582 if ( AdjustDateToRange(&dt
) )
1584 // As above, if the date was changed to keep it in valid range, its
1585 // possibly changed year must be shown in the GUI.
1586 m_spinYear
->SetValue(dt
.GetYear());
1589 SetDateAndNotify(dt
);
1592 void wxGenericCalendarCtrl::OnYearChange(wxSpinEvent
& event
)
1594 HandleYearChange( event
);
1597 void wxGenericCalendarCtrl::OnYearTextChange(wxCommandEvent
& event
)
1599 SetUserChangedYear();
1600 HandleYearChange(event
);
1603 // Responds to colour changes, and passes event on to children.
1604 void wxGenericCalendarCtrl::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1609 // Propagate the event to the children
1610 wxControl::OnSysColourChanged(event
);
1612 // Redraw control area
1613 SetBackgroundColour(m_colBackground
);
1617 // ----------------------------------------------------------------------------
1618 // keyboard interface
1619 // ----------------------------------------------------------------------------
1621 void wxGenericCalendarCtrl::OnChar(wxKeyEvent
& event
)
1623 switch ( event
.GetKeyCode() )
1627 SetDateAndNotify(m_date
+ wxDateSpan::Year());
1632 SetDateAndNotify(m_date
- wxDateSpan::Year());
1636 SetDateAndNotify(m_date
- wxDateSpan::Month());
1640 SetDateAndNotify(m_date
+ wxDateSpan::Month());
1644 if ( event
.ControlDown() )
1646 wxDateTime target
= m_date
.SetToNextWeekDay(GetWeekEnd());
1647 AdjustDateToRange(&target
);
1648 SetDateAndNotify(target
);
1651 SetDateAndNotify(m_date
+ wxDateSpan::Day());
1655 if ( event
.ControlDown() )
1657 wxDateTime target
= m_date
.SetToPrevWeekDay(GetWeekStart());
1658 AdjustDateToRange(&target
);
1659 SetDateAndNotify(target
);
1662 SetDateAndNotify(m_date
- wxDateSpan::Day());
1666 SetDateAndNotify(m_date
- wxDateSpan::Week());
1670 SetDateAndNotify(m_date
+ wxDateSpan::Week());
1674 if ( event
.ControlDown() )
1675 SetDateAndNotify(wxDateTime::Today());
1677 SetDateAndNotify(wxDateTime(1, m_date
.GetMonth(), m_date
.GetYear()));
1681 SetDateAndNotify(wxDateTime(m_date
).SetToLastMonthDay());
1685 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
1693 // ----------------------------------------------------------------------------
1694 // holidays handling
1695 // ----------------------------------------------------------------------------
1697 void wxGenericCalendarCtrl::SetHoliday(size_t day
)
1699 wxCHECK_RET( day
> 0 && day
< 32, wxT("invalid day in SetHoliday") );
1701 wxCalendarDateAttr
*attr
= GetAttr(day
);
1704 attr
= new wxCalendarDateAttr
;
1707 attr
->SetHoliday(true);
1709 // can't use SetAttr() because it would delete this pointer
1710 m_attrs
[day
- 1] = attr
;
1713 void wxGenericCalendarCtrl::ResetHolidayAttrs()
1715 for ( size_t day
= 0; day
< 31; day
++ )
1719 m_attrs
[day
]->SetHoliday(false);
1724 void wxGenericCalendarCtrl::Mark(size_t day
, bool mark
)
1726 wxCHECK_RET( day
> 0 && day
< 32, wxT("invalid day in Mark") );
1728 const wxCalendarDateAttr
& m
= wxCalendarDateAttr::GetMark();
1730 if ( m_attrs
[day
- 1] )
1731 AddAttr(m_attrs
[day
- 1], m
);
1733 SetAttr(day
, new wxCalendarDateAttr(m
));
1736 if ( m_attrs
[day
- 1] )
1737 DelAttr(m_attrs
[day
- 1], m
);
1743 wxGenericCalendarCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
1745 // Use the same color scheme as wxListBox
1746 return wxListBox::GetClassDefaultAttributes(variant
);
1749 #endif // wxUSE_CALENDARCTRL