]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/calctrl.cpp
added and documented wxTE_NOHIDESEL
[wxWidgets.git] / src / generic / calctrl.cpp
index 9a31b5a86da742f3966b6c052bbecd3167f9ff7a..37a0ab77135e94be97185edaf0bdd7656f0e6a49 100644 (file)
@@ -36,8 +36,7 @@
     #include "wx/stattext.h"
 #endif //WX_PRECOMP
 
-// Can only use wxSpinEvent if this is enabled
-#if wxUSE_SPINBTN
+#if wxUSE_CALENDARCTRL
 
 #include "wx/calctrl.h"
 
@@ -95,6 +94,18 @@ BEGIN_EVENT_TABLE(wxYearSpinCtrl, wxSpinCtrl)
 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
@@ -121,6 +132,7 @@ wxMonthComboBox::wxMonthComboBox(wxCalendarCtrl *cal)
     }
 
     SetSelection(m_cal->GetDate().GetMonth());
+    SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT);
 }
 
 wxYearSpinCtrl::wxYearSpinCtrl(wxCalendarCtrl *cal)
@@ -151,7 +163,7 @@ void wxCalendarCtrl::Init()
     {
         m_weekdays[wd] = wxDateTime::GetWeekDayName(wd, wxDateTime::Name_Abbr);
     }
-    m_weekdaysLen = m_weekdays[0].Length();   // mj10777 : length of Day name
+
     for ( size_t n = 0; n < WXSIZEOF(m_attrs); n++ )
     {
         m_attrs[n] = NULL;
@@ -168,14 +180,20 @@ void wxCalendarCtrl::Init()
     m_colHeaderBg = *wxLIGHT_GREY;
 }
 
-bool wxCalendarCtrl::Create(wxWindow * WXUNUSED(parent),
-                            wxWindowID WXUNUSED(id),
+bool wxCalendarCtrl::Create(wxWindow *parent,
+                            wxWindowID id,
                             const wxDateTime& date,
-                            const wxPoint& WXUNUSED(pos),
+                            const wxPoint& pos,
                             const wxSize& size,
                             long style,
-                            const wxString& WXUNUSED(name))
+                            const wxString& name)
 {
+    if ( !wxControl::Create(parent, id, pos, size,
+                            style | wxWANTS_CHARS, wxDefaultValidator, name) )
+    {
+        return FALSE;
+    }
+
     // needed to get the arrow keys normally used for the dialog navigation
     SetWindowStyle(style | wxWANTS_CHARS);
 
@@ -459,15 +477,14 @@ wxSize wxCalendarCtrl::DoGetBestSize() const
     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
-        height += 4;
+        height += 6;
     }
 
     return wxSize(width, height);
@@ -527,7 +544,9 @@ void wxCalendarCtrl::RecalcGeometry()
         return;
 
     wxClientDC dc(this);
+
     dc.SetFont(m_font);
+
     // determine the column width (we assume that the weekday names are always
     // wider (in any language) than the numbers)
     m_widthCol = 0;
@@ -541,6 +560,7 @@ void wxCalendarCtrl::RecalcGeometry()
             m_widthCol = width;
         }
     }
+
     // leave some margins
     m_widthCol += 2;
     m_heightRow += 2;
@@ -552,41 +572,14 @@ void wxCalendarCtrl::RecalcGeometry()
 
 void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
-    wxCoord width;          // mj10777 : moved to top of function
-    RecalcGeometry();       // mj10777 : needed for wxDefaultSize
-    wxSize size;            // mj10777 : size of Ctrl
-
     wxPaintDC dc(this);
-    size = GetSize();
-    m_font.SetPointSize(size.y/14); // Font in proportion to height
+
     dc.SetFont(m_font);
-    if ((m_widthCol != size.x/7) || (m_heightRow != size.y/9))
-    {  // mj10777 : only if size has changed
-        // ShowCurrentControls();        // Turn off ?
-        m_widthCol = size.x/7;
-        m_heightRow = size.y/9;
-        SetSize(m_widthCol*7,m_heightRow*9);  // mj10777 : Set to fit full number
-        m_weekdaysLen = m_weekdays[0].Length();
-        dc.GetTextExtent(m_weekdays[0], &width, (wxCoord *)NULL);
-        while (width >= m_widthCol)
-        { // mj10777 : how many letters fit in the Column ?
-#if DEBUG_PAINT
-            printf("%d) : m_widthCol(%d) ; width(%d)\n",m_weekdaysLen,m_widthCol,width);
-#endif
-            m_weekdaysLen--;
-            dc.GetTextExtent(m_weekdays[0].Mid(0, m_weekdaysLen), &width, (wxCoord *)NULL);
-        }
-        // ShowCurrentControls();        // Turn on ?
-        wxSize combosize = m_comboMonth->GetSize();
-        combosize.x = size.x / 2;  // When small, the Year cannot not be seen if the month is to big
-        m_comboMonth->SetSize(combosize);
-    }  // mj10777 : only if size has changed
 
-    if (m_weekdaysLen < 1)
-        m_weekdaysLen = 1;  // mj10777 : must never be less that 1
+    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
@@ -595,7 +588,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
     if ( IsExposed(0, 0, 7*m_widthCol, m_heightRow) )
     {
 #if DEBUG_PAINT
-        puts("painting the header");
+        wxLogDebug("painting the header");
 #endif
 
         dc.SetBackgroundMode(wxTRANSPARENT);
@@ -613,9 +606,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
             else
                 n = wd;
 
-            dc.GetTextExtent(m_weekdays[n].Mid(0,m_weekdaysLen), &width, (wxCoord *)NULL); // mj10777
-            width = wd*m_widthCol + (m_widthCol - width) / 2;       // mj10777
-            dc.DrawText(m_weekdays[n].Mid(0,m_weekdaysLen), width, 0); // mj10777
+            dc.DrawText(m_weekdays[n], wd*m_widthCol + 1, 0);
         }
     }
 
@@ -627,7 +618,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
 
     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
 
@@ -643,7 +634,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
         }
 
 #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++ )
@@ -653,6 +644,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
                 // don't use wxDate::Format() which prepends 0s
                 unsigned int day = date.GetDay();
                 wxString dayStr = wxString::Format(_T("%u"), day);
+                wxCoord width;
                 dc.GetTextExtent(dayStr, &width, (wxCoord *)NULL);
 
                 bool changedColours = FALSE,
@@ -660,7 +652,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
 
                 wxCalendarDateAttr *attr = m_attrs[day - 1];
 
-                bool isSel = m_date == date;
+                bool isSel = date.IsSameDate(m_date);
                 if ( isSel )
                 {
                     dc.SetTextForeground(m_colHighlightFg);
@@ -755,7 +747,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
         }
     }
 #if DEBUG_PAINT
-    puts("+++ finished painting");
+    wxLogDebug("+++ finished painting");
 #endif
 }
 
@@ -773,8 +765,17 @@ void wxCalendarCtrl::RefreshDate(const wxDateTime& date)
     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
-    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);
@@ -1062,5 +1063,5 @@ wxCalendarEvent::wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type)
     m_date = cal->GetDate();
 }
 
-#endif // wxUSE_SPINBTN
+#endif // wxUSE_CALENDARCTRL