]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/calctrlg.cpp
miscellaneous small enhancements
[wxWidgets.git] / src / generic / calctrlg.cpp
index cb153cce2894629f43e8ad3ee47a4460ee18abba..ec7a53158eb30b1539a350d7efc0628351bf9dda 100644 (file)
@@ -249,7 +249,6 @@ bool wxGenericCalendarCtrl::Create(wxWindow *parent,
         m_staticYear = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%Y")),
                                         wxDefaultPosition, wxDefaultSize,
                                         wxALIGN_CENTRE);
         m_staticYear = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%Y")),
                                         wxDefaultPosition, wxDefaultSize,
                                         wxALIGN_CENTRE);
-
         CreateMonthComboBox();
         m_staticMonth = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%B")),
                                          wxDefaultPosition, wxDefaultSize,
         CreateMonthComboBox();
         m_staticMonth = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%B")),
                                          wxDefaultPosition, wxDefaultSize,
@@ -339,6 +338,9 @@ void wxGenericCalendarCtrl::CreateYearSpinCtrl()
                                 wxDefaultSize,
                                 wxSP_ARROW_KEYS | wxCLIP_SIBLINGS,
                                 -4300, 10000, GetDate().GetYear());
                                 wxDefaultSize,
                                 wxSP_ARROW_KEYS | wxCLIP_SIBLINGS,
                                 -4300, 10000, GetDate().GetYear());
+#ifdef __WXMAC__
+    m_spinYear->SetSize( 90, -1 );
+#endif
 
     m_spinYear->Connect(m_spinYear->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
                         wxCommandEventHandler(wxGenericCalendarCtrl::OnYearTextChange),
 
     m_spinYear->Connect(m_spinYear->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
                         wxCommandEventHandler(wxGenericCalendarCtrl::OnYearTextChange),
@@ -777,16 +779,13 @@ size_t wxGenericCalendarCtrl::GetWeek(const wxDateTime& date) const
 // the same space
 
 // the constants used for the layout
 // the same space
 
 // the constants used for the layout
-#define VERT_MARGIN     5           // distance between combo and calendar
-#ifdef __WXMAC__
+#define VERT_MARGIN    5           // distance between combo and calendar
 #define HORZ_MARGIN    5           //                            spin
 #define HORZ_MARGIN    5           //                            spin
-#else
-#define HORZ_MARGIN    15           //                            spin
-#endif
+
 wxSize wxGenericCalendarCtrl::DoGetBestSize() const
 {
     // calc the size of the calendar
 wxSize wxGenericCalendarCtrl::DoGetBestSize() const
 {
     // calc the size of the calendar
-    wx_const_cast(wxGenericCalendarCtrl *, this)->RecalcGeometry();
+    const_cast<wxGenericCalendarCtrl *>(this)->RecalcGeometry();
 
     wxCoord width = 7*m_widthCol,
             height = 7*m_heightRow + m_rowOffset;
 
     wxCoord width = 7*m_widthCol,
             height = 7*m_heightRow + m_rowOffset;
@@ -797,6 +796,10 @@ wxSize wxGenericCalendarCtrl::DoGetBestSize() const
 
         height += wxMax(bestSizeCombo.y, m_spinYear->GetBestSize().y)
                     + VERT_MARGIN;
 
         height += wxMax(bestSizeCombo.y, m_spinYear->GetBestSize().y)
                     + VERT_MARGIN;
+#ifdef __WXMAC__
+        // the spin control get clipped otherwise
+        width += 10;
+#endif
 
         wxCoord w2 = bestSizeCombo.x + HORZ_MARGIN + GetCharWidth()*6;
         if ( width < w2 )
 
         wxCoord w2 = bestSizeCombo.x + HORZ_MARGIN + GetCharWidth()*6;
         if ( width < w2 )
@@ -810,6 +813,7 @@ wxSize wxGenericCalendarCtrl::DoGetBestSize() const
     }
 
     CacheBestSize(best);
     }
 
     CacheBestSize(best);
+    
     return best;
 }
 
     return best;
 }
 
@@ -825,12 +829,16 @@ void wxGenericCalendarCtrl::DoMoveWindow(int x, int y, int width, int height)
 
         int maxHeight = wxMax(sizeSpin.y, sizeCombo.y);
         int dy = (maxHeight - sizeStatic.y) / 2;
 
         int maxHeight = wxMax(sizeSpin.y, sizeCombo.y);
         int dy = (maxHeight - sizeStatic.y) / 2;
-        m_comboMonth->Move(x, y);
+#ifdef __WXMAC__
+        m_comboMonth->Move(x, y + (maxHeight - sizeCombo.y)/2 + 2); // FIXME, something is reporting the wrong size..
+#else
+        m_comboMonth->Move(x, y + (maxHeight - sizeCombo.y)/2);
+#endif
         m_staticMonth->SetSize(x, y + dy, sizeCombo.x, -1, sizeStatic.y);
 
         int xDiff = sizeCombo.x + HORZ_MARGIN;
 
         m_staticMonth->SetSize(x, y + dy, sizeCombo.x, -1, sizeStatic.y);
 
         int xDiff = sizeCombo.x + HORZ_MARGIN;
 
-        m_spinYear->SetSize(x + xDiff, y, width - xDiff, maxHeight);
+        m_spinYear->SetSize(x + xDiff, y + (maxHeight - sizeSpin.y)/2, width - xDiff, maxHeight);
         m_staticYear->SetSize(x + xDiff, y + dy, width - xDiff, sizeStatic.y);
 
         yDiff = maxHeight + VERT_MARGIN;
         m_staticYear->SetSize(x + xDiff, y + dy, width - xDiff, sizeStatic.y);
 
         yDiff = maxHeight + VERT_MARGIN;
@@ -843,6 +851,24 @@ void wxGenericCalendarCtrl::DoMoveWindow(int x, int y, int width, int height)
     wxControl::DoMoveWindow(x, y + yDiff, width, height - yDiff);
 }
 
     wxControl::DoMoveWindow(x, y + yDiff, width, height - yDiff);
 }
 
+void wxGenericCalendarCtrl::DoGetSize(int *width, int *height) const
+{
+#ifdef __WXMAC__
+    wxControl::DoGetSize( width, height );
+    
+    if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) && m_staticMonth && height )
+    {
+        wxSize sizeCombo = m_comboMonth->GetEffectiveMinSize();
+        wxSize sizeSpin = m_spinYear->GetSize();
+
+        int maxHeight = wxMax(sizeSpin.y, sizeCombo.y);
+        *height += maxHeight + VERT_MARGIN;
+    }
+#else
+    wxControl::DoGetSize( width, height );
+#endif
+}
+
 void wxGenericCalendarCtrl::RecalcGeometry()
 {
     wxClientDC dc(this);
 void wxGenericCalendarCtrl::RecalcGeometry()
 {
     wxClientDC dc(this);
@@ -1734,45 +1760,6 @@ void wxGenericCalendarCtrl::OnChar(wxKeyEvent& event)
 // holidays handling
 // ----------------------------------------------------------------------------
 
 // holidays handling
 // ----------------------------------------------------------------------------
 
-void wxGenericCalendarCtrl::EnableHolidayDisplay(bool display)
-{
-    long style = GetWindowStyle();
-    if ( display )
-        style |= wxCAL_SHOW_HOLIDAYS;
-    else
-        style &= ~wxCAL_SHOW_HOLIDAYS;
-
-    SetWindowStyle(style);
-
-    if ( display )
-        SetHolidayAttrs();
-    else
-        ResetHolidayAttrs();
-
-    Refresh();
-}
-
-void wxGenericCalendarCtrl::SetHolidayAttrs()
-{
-    if ( GetWindowStyle() & wxCAL_SHOW_HOLIDAYS )
-    {
-        ResetHolidayAttrs();
-
-        wxDateTime::Tm tm = m_date.GetTm();
-        wxDateTime dtStart(1, tm.mon, tm.year),
-                   dtEnd = dtStart.GetLastMonthDay();
-
-        wxDateTimeArray hol;
-        wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
-
-        size_t count = hol.GetCount();
-        for ( size_t n = 0; n < count; n++ )
-        {
-            SetHoliday(hol[n].GetDay());
-        }
-    }
-}
-
 void wxGenericCalendarCtrl::SetHoliday(size_t day)
 {
     wxCHECK_RET( day > 0 && day < 32, _T("invalid day in SetHoliday") );
 void wxGenericCalendarCtrl::SetHoliday(size_t day)
 {
     wxCHECK_RET( day > 0 && day < 32, _T("invalid day in SetHoliday") );