]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxCAL_MONDAY/SUNDAY_FIRST flags and Ctrl-Home/Right/Left and Home/End keys
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 30 Dec 1999 00:31:36 +0000 (00:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 30 Dec 1999 00:31:36 +0000 (00:31 +0000)
handling

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5150 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/defs.h
src/common/datetime.cpp
src/generic/calctrl.cpp

index 06570522943d19933eb8f8c6493504d0a67a0998..31b582e513e8b099bcd59eddd7c89e271fd7e299 100644 (file)
@@ -1111,6 +1111,13 @@ enum wxStretch
 #define wxHW_SCROLLBAR_NEVER    0x0002
 #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
  * flag and thus do not overlap with other style flags. note that these
index 53e4d8be68245a5e0843e7392c7d6963fe233c1d..1f48f3022dcec6f73941ce3d9c454092ddffef14 100644 (file)
@@ -1379,7 +1379,10 @@ wxDateTime& wxDateTime::SetToLastMonthDay(Month month,
                                           int year)
 {
     // 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);
 }
index ed540c9dd43c6af015c1f6af992b826924ac95b5..d2aa7c21a01d7b760c1bd85cd7156001dd10d96d 100644 (file)
@@ -296,14 +296,13 @@ wxDateTime wxCalendarCtrl::GetStartDate() const
     wxDateTime::Tm tm = m_date.GetTm();
 
     wxDateTime date = wxDateTime(1, tm.mon, tm.year);
-    if ( date.GetWeekDay() != wxDateTime::Sun )
-    {
-        date.SetToPrevWeekDay(wxDateTime::Sun);
 
-        // be sure to do it or it might gain 1 hour if DST changed in between
-        date.ResetTime();
-    }
-    //else: we already have it
+    // rewind back
+    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
+    date.ResetTime();
 
     return date;
 }
@@ -315,7 +314,9 @@ bool wxCalendarCtrl::IsDateShown(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);
 
-    wxDateTime::WeekDay wd;
-
     dc.SetFont(m_font);
 
     RecalcGeometry();
@@ -449,9 +448,17 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& event)
         dc.SetBackgroundMode(wxTRANSPARENT);
         dc.SetPen(*wxLIGHT_GREY_PEN);
         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);
         }
     }
 
@@ -478,11 +485,11 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& event)
             continue;
         }
 
-#if DEBUG_PAINT        
+#if DEBUG_PAINT
         printf("painting week %d at y = %d\n", nWeek, y);
 #endif
 
-        for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) )
+        for ( size_t wd = 0; wd < 7; wd++ )
         {
             if ( IsDateShown(date) )
             {
@@ -645,11 +652,21 @@ void wxCalendarCtrl::OnChar(wxKeyEvent& event)
             break;
 
         case WXK_RIGHT:
-            SetDateAndNotify(m_date + wxDateSpan::Day());
+            if ( event.ControlDown() )
+                SetDateAndNotify(wxDateTime(m_date).SetToNextWeekDay(
+                                 GetWindowStyle() & wxCAL_MONDAY_FIRST
+                                 ? wxDateTime::Sun : wxDateTime::Sat));
+            else
+                SetDateAndNotify(m_date + wxDateSpan::Day());
             break;
 
         case WXK_LEFT:
-            SetDateAndNotify(m_date - wxDateSpan::Day());
+            if ( event.ControlDown() )
+                SetDateAndNotify(wxDateTime(m_date).SetToPrevWeekDay(
+                                 GetWindowStyle() & wxCAL_MONDAY_FIRST
+                                 ? wxDateTime::Mon : wxDateTime::Sun));
+            else
+                SetDateAndNotify(m_date - wxDateSpan::Day());
             break;
 
         case WXK_UP:
@@ -661,7 +678,14 @@ void wxCalendarCtrl::OnChar(wxKeyEvent& event)
             break;
 
         case WXK_HOME:
-            SetDateAndNotify(wxDateTime::Today());
+            if ( event.ControlDown() )
+                SetDateAndNotify(wxDateTime::Today());
+            else
+                SetDateAndNotify(wxDateTime(1, m_date.GetMonth(), m_date.GetYear()));
+            break;
+
+        case WXK_END:
+            SetDateAndNotify(wxDateTime(m_date).SetToLastMonthDay());
             break;
 
         default: