added wxCAL_MONDAY/SUNDAY_FIRST flags and Ctrl-Home/Right/Left and Home/End keys

handling


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5150 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-12-30 00:31:36 +00:00
parent 882a8f40e2
commit 1a8557b143
3 changed files with 52 additions and 18 deletions

View File

@@ -1111,6 +1111,13 @@ enum wxStretch
#define wxHW_SCROLLBAR_NEVER 0x0002 #define wxHW_SCROLLBAR_NEVER 0x0002
#define wxHW_SCROLLBAR_AUTO 0x0004 #define wxHW_SCROLLBAR_AUTO 0x0004
/*
* wxCalendarCtrl flags
*/
#define wxCAL_SUNDAY_FIRST 0x0000
#define wxCAL_MONDAY_FIRST 0x0001
#define wxCAL_SHOW_HOLIDAYS 0x0002
/* /*
* extended dialog specifiers. these values are stored in a different * extended dialog specifiers. these values are stored in a different
* flag and thus do not overlap with other style flags. note that these * flag and thus do not overlap with other style flags. note that these

View File

@@ -1379,7 +1379,10 @@ wxDateTime& wxDateTime::SetToLastMonthDay(Month month,
int year) int year)
{ {
// take the current month/year if none specified // take the current month/year if none specified
ReplaceDefaultYearMonthWithCurrent(&year, &month); if ( year == Inv_Year )
year = GetYear();
if ( month == Inv_Month )
month = GetMonth();
return Set(GetNumOfDaysInMonth(year, month), month, year); return Set(GetNumOfDaysInMonth(year, month), month, year);
} }

View File

@@ -296,14 +296,13 @@ wxDateTime wxCalendarCtrl::GetStartDate() const
wxDateTime::Tm tm = m_date.GetTm(); wxDateTime::Tm tm = m_date.GetTm();
wxDateTime date = wxDateTime(1, tm.mon, tm.year); wxDateTime date = wxDateTime(1, tm.mon, tm.year);
if ( date.GetWeekDay() != wxDateTime::Sun )
{ // rewind back
date.SetToPrevWeekDay(wxDateTime::Sun); date.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST
? wxDateTime::Mon : wxDateTime::Sun);
// be sure to do it or it might gain 1 hour if DST changed in between // be sure to do it or it might gain 1 hour if DST changed in between
date.ResetTime(); date.ResetTime();
}
//else: we already have it
return date; return date;
} }
@@ -315,7 +314,9 @@ bool wxCalendarCtrl::IsDateShown(const wxDateTime& date) const
size_t wxCalendarCtrl::GetWeek(const wxDateTime& date) const size_t wxCalendarCtrl::GetWeek(const wxDateTime& date) const
{ {
return date.GetWeekOfMonth(wxDateTime::Sunday_First); return date.GetWeekOfMonth(GetWindowStyle() & wxCAL_MONDAY_FIRST
? wxDateTime::Monday_First
: wxDateTime::Sunday_First);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -425,8 +426,6 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& event)
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
wxDateTime::WeekDay wd;
dc.SetFont(m_font); dc.SetFont(m_font);
RecalcGeometry(); RecalcGeometry();
@@ -449,9 +448,17 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& event)
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetPen(*wxLIGHT_GREY_PEN);
dc.DrawRectangle(0, 0, 7*m_widthCol, m_heightRow); dc.DrawRectangle(0, 0, 7*m_widthCol, m_heightRow);
for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) )
bool startOnMonday = (GetWindowStyle() & wxCAL_MONDAY_FIRST) != 0;
for ( size_t wd = 0; wd < 7; wd++ )
{ {
dc.DrawText(m_weekdays[wd], wd*m_widthCol + 1, 0); size_t n;
if ( startOnMonday )
n = wd == 6 ? 0 : wd + 1;
else
n = wd;
dc.DrawText(m_weekdays[n], wd*m_widthCol + 1, 0);
} }
} }
@@ -482,7 +489,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& event)
printf("painting week %d at y = %d\n", nWeek, y); printf("painting week %d at y = %d\n", nWeek, y);
#endif #endif
for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) ) for ( size_t wd = 0; wd < 7; wd++ )
{ {
if ( IsDateShown(date) ) if ( IsDateShown(date) )
{ {
@@ -645,10 +652,20 @@ void wxCalendarCtrl::OnChar(wxKeyEvent& event)
break; break;
case WXK_RIGHT: case WXK_RIGHT:
if ( event.ControlDown() )
SetDateAndNotify(wxDateTime(m_date).SetToNextWeekDay(
GetWindowStyle() & wxCAL_MONDAY_FIRST
? wxDateTime::Sun : wxDateTime::Sat));
else
SetDateAndNotify(m_date + wxDateSpan::Day()); SetDateAndNotify(m_date + wxDateSpan::Day());
break; break;
case WXK_LEFT: case WXK_LEFT:
if ( event.ControlDown() )
SetDateAndNotify(wxDateTime(m_date).SetToPrevWeekDay(
GetWindowStyle() & wxCAL_MONDAY_FIRST
? wxDateTime::Mon : wxDateTime::Sun));
else
SetDateAndNotify(m_date - wxDateSpan::Day()); SetDateAndNotify(m_date - wxDateSpan::Day());
break; break;
@@ -661,7 +678,14 @@ void wxCalendarCtrl::OnChar(wxKeyEvent& event)
break; break;
case WXK_HOME: case WXK_HOME:
if ( event.ControlDown() )
SetDateAndNotify(wxDateTime::Today()); SetDateAndNotify(wxDateTime::Today());
else
SetDateAndNotify(wxDateTime(1, m_date.GetMonth(), m_date.GetYear()));
break;
case WXK_END:
SetDateAndNotify(wxDateTime(m_date).SetToLastMonthDay());
break; break;
default: default: