]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/calctrl.cpp
Make easier to compile with MSVC5.
[wxWidgets.git] / src / generic / calctrl.cpp
index dca2a4e76da8f3c22c3619f55f79f48863a147f4..04facbffb19ee93513f206be31730f78277fe602 100644 (file)
@@ -36,6 +36,8 @@
     #include "wx/stattext.h"
 #endif //WX_PRECOMP
 
     #include "wx/stattext.h"
 #endif //WX_PRECOMP
 
+#if wxUSE_CALENDARCTRL
+
 #include "wx/calctrl.h"
 
 #define DEBUG_PAINT 0
 #include "wx/calctrl.h"
 
 #define DEBUG_PAINT 0
@@ -81,9 +83,6 @@ BEGIN_EVENT_TABLE(wxCalendarCtrl, wxControl)
 
     EVT_LEFT_DOWN(wxCalendarCtrl::OnClick)
     EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick)
 
     EVT_LEFT_DOWN(wxCalendarCtrl::OnClick)
     EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick)
-
-    EVT_CALENDAR_MONTH(-1, wxCalendarCtrl::OnCalMonthChange)
-    EVT_CALENDAR_YEAR(-1, wxCalendarCtrl::OnCalMonthChange)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxMonthComboBox, wxComboBox)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxMonthComboBox, wxComboBox)
@@ -95,6 +94,18 @@ BEGIN_EVENT_TABLE(wxYearSpinCtrl, wxSpinCtrl)
 END_EVENT_TABLE()
 
 IMPLEMENT_DYNAMIC_CLASS(wxCalendarCtrl, wxControl)
 END_EVENT_TABLE()
 
 IMPLEMENT_DYNAMIC_CLASS(wxCalendarCtrl, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent, wxCommandEvent)
+
+// ----------------------------------------------------------------------------
+// events
+// ----------------------------------------------------------------------------
+
+DEFINE_EVENT_TYPE(wxEVT_CALENDAR_SEL_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DAY_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_CALENDAR_MONTH_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_CALENDAR_YEAR_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DOUBLECLICKED)
+DEFINE_EVENT_TYPE(wxEVT_CALENDAR_WEEKDAY_CLICKED)
 
 // ============================================================================
 // implementation
 
 // ============================================================================
 // implementation
@@ -121,6 +132,7 @@ wxMonthComboBox::wxMonthComboBox(wxCalendarCtrl *cal)
     }
 
     SetSelection(m_cal->GetDate().GetMonth());
     }
 
     SetSelection(m_cal->GetDate().GetMonth());
+    SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT);
 }
 
 wxYearSpinCtrl::wxYearSpinCtrl(wxCalendarCtrl *cal)
 }
 
 wxYearSpinCtrl::wxYearSpinCtrl(wxCalendarCtrl *cal)
@@ -288,12 +300,12 @@ void wxCalendarCtrl::ShowCurrentControls()
 
 wxControl *wxCalendarCtrl::GetMonthControl() const
 {
 
 wxControl *wxCalendarCtrl::GetMonthControl() const
 {
-    return AllowMonthChange() ? m_comboMonth : m_staticMonth;
+    return AllowMonthChange() ? (wxControl *)m_comboMonth : (wxControl *)m_staticMonth;
 }
 
 wxControl *wxCalendarCtrl::GetYearControl() const
 {
 }
 
 wxControl *wxCalendarCtrl::GetYearControl() const
 {
-    return AllowYearChange() ? m_spinYear : m_staticYear;
+    return AllowYearChange() ? (wxControl *)m_spinYear : (wxControl *)m_staticYear;
 }
 
 void wxCalendarCtrl::EnableYearChange(bool enable)
 }
 
 void wxCalendarCtrl::EnableYearChange(bool enable)
@@ -359,6 +371,9 @@ void wxCalendarCtrl::SetDate(const wxDateTime& date)
             m_spinYear->SetValue(m_date.Format(_T("%Y")));
         }
 
             m_spinYear->SetValue(m_date.Format(_T("%Y")));
         }
 
+        // as the month changed, holidays did too
+        SetHolidayAttrs();
+
         // update the calendar
         Refresh();
     }
         // update the calendar
         Refresh();
     }
@@ -456,15 +471,14 @@ wxSize wxCalendarCtrl::DoGetBestSize() const
     wxCoord width = 7*m_widthCol,
             height = 7*m_heightRow;
 
     wxCoord width = 7*m_widthCol,
             height = 7*m_heightRow;
 
-    wxSize sizeCombo = m_comboMonth->GetBestSize(),
-           sizeSpin = m_spinYear->GetBestSize();
-
-    height += VERT_MARGIN + wxMax(sizeCombo.y, sizeSpin.y);
+    // the combobox doesn't report its height correctly (it returns the
+    // height including the drop down list) so don't use it
+    height += VERT_MARGIN + m_spinYear->GetBestSize().y;
 
     if ( GetWindowStyle() & (wxRAISED_BORDER | wxSUNKEN_BORDER) )
     {
         // the border would clip the last line otherwise
 
     if ( GetWindowStyle() & (wxRAISED_BORDER | wxSUNKEN_BORDER) )
     {
         // the border would clip the last line otherwise
-        height += 4;
+        height += 6;
     }
 
     return wxSize(width, height);
     }
 
     return wxSize(width, height);
@@ -559,7 +573,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
     RecalcGeometry();
 
 #if DEBUG_PAINT
     RecalcGeometry();
 
 #if DEBUG_PAINT
-    printf("--- starting to paint, selection: %s, week %u\n",
+    wxLogDebug("--- starting to paint, selection: %s, week %u\n",
            m_date.Format("%a %d-%m-%Y %H:%M:%S").c_str(),
            GetWeek(m_date));
 #endif
            m_date.Format("%a %d-%m-%Y %H:%M:%S").c_str(),
            GetWeek(m_date));
 #endif
@@ -568,7 +582,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
     if ( IsExposed(0, 0, 7*m_widthCol, m_heightRow) )
     {
 #if DEBUG_PAINT
     if ( IsExposed(0, 0, 7*m_widthCol, m_heightRow) )
     {
 #if DEBUG_PAINT
-        puts("painting the header");
+        wxLogDebug("painting the header");
 #endif
 
         dc.SetBackgroundMode(wxTRANSPARENT);
 #endif
 
         dc.SetBackgroundMode(wxTRANSPARENT);
@@ -598,7 +612,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
 
     wxDateTime date = GetStartDate();
 #if DEBUG_PAINT
 
     wxDateTime date = GetStartDate();
 #if DEBUG_PAINT
-    printf("starting calendar from %s\n",
+    wxLogDebug("starting calendar from %s\n",
             date.Format("%a %d-%m-%Y %H:%M:%S").c_str());
 #endif
 
             date.Format("%a %d-%m-%Y %H:%M:%S").c_str());
 #endif
 
@@ -614,7 +628,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
         }
 
 #if DEBUG_PAINT
         }
 
 #if DEBUG_PAINT
-        printf("painting week %d at y = %d\n", nWeek, y);
+        wxLogDebug("painting week %d at y = %d\n", nWeek, y);
 #endif
 
         for ( size_t wd = 0; wd < 7; wd++ )
 #endif
 
         for ( size_t wd = 0; wd < 7; wd++ )
@@ -632,7 +646,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
 
                 wxCalendarDateAttr *attr = m_attrs[day - 1];
 
 
                 wxCalendarDateAttr *attr = m_attrs[day - 1];
 
-                bool isSel = m_date == date;
+                bool isSel = date.IsSameDate(m_date);
                 if ( isSel )
                 {
                     dc.SetTextForeground(m_colHighlightFg);
                 if ( isSel )
                 {
                     dc.SetTextForeground(m_colHighlightFg);
@@ -727,7 +741,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
         }
     }
 #if DEBUG_PAINT
         }
     }
 #if DEBUG_PAINT
-    puts("+++ finished painting");
+    wxLogDebug("+++ finished painting");
 #endif
 }
 
 #endif
 }
 
@@ -745,8 +759,17 @@ void wxCalendarCtrl::RefreshDate(const wxDateTime& date)
     rect.width = 7*m_widthCol;
     rect.height = m_heightRow;
 
     rect.width = 7*m_widthCol;
     rect.height = m_heightRow;
 
+#ifdef __WXMSW__
+    // VZ: for some reason, the selected date seems to occupy more space under
+    //     MSW - this is probably some bug in the font size calculations, but I
+    //     don't know where exactly. This fix is ugly and leads to more
+    //     refreshes than really needed, but without it the selected days
+    //     leaves even more ugly underscores on screen.
+    rect.Inflate(0, 1);
+#endif // MSW
+
 #if DEBUG_PAINT
 #if DEBUG_PAINT
-    printf("*** refreshing week %d at (%d, %d)-(%d, %d)\n",
+    wxLogDebug("*** refreshing week %d at (%d, %d)-(%d, %d)\n",
            GetWeek(date),
            rect.x, rect.y,
            rect.x + rect.width, rect.y + rect.height);
            GetWeek(date),
            rect.x, rect.y,
            rect.x + rect.width, rect.y + rect.height);
@@ -861,9 +884,7 @@ void wxCalendarCtrl::OnMonthChange(wxCommandEvent& event)
         tm.mday = wxDateTime::GetNumberOfDays(mon, tm.year);
     }
 
         tm.mday = wxDateTime::GetNumberOfDays(mon, tm.year);
     }
 
-    SetDate(wxDateTime(tm.mday, mon, tm.year));
-
-    GenerateEvents(wxEVT_CALENDAR_MONTH_CHANGED, wxEVT_CALENDAR_SEL_CHANGED);
+    SetDateAndNotify(wxDateTime(tm.mday, mon, tm.year));
 }
 
 void wxCalendarCtrl::OnYearChange(wxSpinEvent& event)
 }
 
 void wxCalendarCtrl::OnYearChange(wxSpinEvent& event)
@@ -876,9 +897,7 @@ void wxCalendarCtrl::OnYearChange(wxSpinEvent& event)
         tm.mday = wxDateTime::GetNumberOfDays(tm.mon, year);
     }
 
         tm.mday = wxDateTime::GetNumberOfDays(tm.mon, year);
     }
 
-    SetDate(wxDateTime(tm.mday, tm.mon, year));
-
-    GenerateEvents(wxEVT_CALENDAR_YEAR_CHANGED, wxEVT_CALENDAR_SEL_CHANGED);
+    SetDateAndNotify(wxDateTime(tm.mday, tm.mon, year));
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
@@ -957,13 +976,6 @@ void wxCalendarCtrl::OnChar(wxKeyEvent& event)
 // holidays handling
 // ----------------------------------------------------------------------------
 
 // holidays handling
 // ----------------------------------------------------------------------------
 
-void wxCalendarCtrl::OnCalMonthChange(wxCalendarEvent& event)
-{
-    SetHolidayAttrs();
-
-    event.Skip();
-}
-
 void wxCalendarCtrl::EnableHolidayDisplay(bool display)
 {
     long style = GetWindowStyle();
 void wxCalendarCtrl::EnableHolidayDisplay(bool display)
 {
     long style = GetWindowStyle();
@@ -1044,3 +1056,6 @@ wxCalendarEvent::wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type)
 {
     m_date = cal->GetDate();
 }
 {
     m_date = cal->GetDate();
 }
+
+#endif // wxUSE_CALENDARCTRL
+