]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/calctrl.cpp
avoid assert when creating the control with wxCAL_SEQUENTIAL_MONTH_SELECTION style...
[wxWidgets.git] / src / generic / calctrl.cpp
index cb0b01b5f8b6e01cb5b7d0eb52751eb37da9d20e..1b4e84226fbe88cc7d946f28964c98d16a26e02d 100644 (file)
@@ -202,6 +202,9 @@ bool wxCalendarCtrl::Create(wxWindow *parent,
                             long style,
                             const wxString& name)
 {
+    // set the style first to avoid assert in our SetWindowStyleFlag()
+    m_windowStyle = style;
+
     if ( !wxControl::Create(parent, id, pos, size,
                             style | wxCLIP_CHILDREN | wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE,
                             wxDefaultValidator, name) )
@@ -235,7 +238,7 @@ bool wxCalendarCtrl::Create(wxWindow *parent,
     // we need to set the position as well because the main control position
     // is not the same as the one specified in pos if we have the controls
     // above it
-    SetBestSize(size);
+    SetInitialSize(size);
     SetPosition(pos);
 
     // Since we don't paint the whole background make sure that the platform
@@ -255,6 +258,17 @@ wxCalendarCtrl::~wxCalendarCtrl()
     }
 }
 
+void wxCalendarCtrl::SetWindowStyleFlag(long style)
+{
+    // changing this style doesn't work because the controls are not
+    // created/shown/hidden accordingly
+    wxASSERT_MSG( (style & wxCAL_SEQUENTIAL_MONTH_SELECTION) ==
+                    (m_windowStyle & wxCAL_SEQUENTIAL_MONTH_SELECTION),
+                  _T("wxCAL_SEQUENTIAL_MONTH_SELECTION can't be changed after creation") );
+
+    wxControl::SetWindowStyleFlag(style);
+}
+
 // ----------------------------------------------------------------------------
 // Create the wxComboBox and wxSpinCtrl
 // ----------------------------------------------------------------------------
@@ -394,6 +408,7 @@ void wxCalendarCtrl::ShowCurrentControls()
         m_spinYear->Hide();
         m_staticYear->Show();
     }
+    //else: these controls are not even created, don't show/hide them
 }
 
 wxControl *wxCalendarCtrl::GetMonthControl() const
@@ -790,19 +805,30 @@ void wxCalendarCtrl::DoMoveWindow(int x, int y, int width, int height)
 
     if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) && m_staticMonth )
     {
-        wxSize sizeCombo = m_comboMonth->GetSize();
+        wxSize sizeCombo = m_comboMonth->GetEffectiveMinSize();
         wxSize sizeStatic = m_staticMonth->GetSize();
         wxSize sizeSpin = m_spinYear->GetSize();
-        int dy = (sizeCombo.y - sizeStatic.y) / 2;
+
+        // wxMSW sometimes reports the wrong combo height,
+        // so on this platform we'll use the spin control
+        // height instead.
+#ifdef __WXMSW__
+        int maxHeight = sizeSpin.y;
+        int requiredSpinHeight = -1;
+#else
+        int maxHeight = sizeCombo.y;
+        int requiredSpinHeight = sizeCombo.y;
+#endif
+        int dy = (maxHeight - sizeStatic.y) / 2;
         m_comboMonth->Move(x, y);
-        m_staticMonth->SetSize(x, y + dy, sizeCombo.x, sizeStatic.y);
+        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, sizeCombo.y);
+        m_spinYear->SetSize(x + xDiff, y, width - xDiff, requiredSpinHeight);
         m_staticYear->SetSize(x + xDiff, y + dy, width - xDiff, sizeStatic.y);
 
-        yDiff = wxMax(sizeSpin.y, sizeCombo.y) + VERT_MARGIN;
+        yDiff = wxMax(sizeSpin.y, maxHeight) + VERT_MARGIN;
     }
     else // no controls on the top
     {
@@ -815,7 +841,7 @@ void wxCalendarCtrl::DoMoveWindow(int x, int y, int width, int height)
 void wxCalendarCtrl::DoGetPosition(int *x, int *y) const
 {
     wxControl::DoGetPosition(x, y);
-
+#ifndef __WXPM__
     if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) && GetMonthControl() )
     {
         // our real top corner is not in this position
@@ -824,13 +850,14 @@ void wxCalendarCtrl::DoGetPosition(int *x, int *y) const
             *y -= GetMonthControl()->GetSize().y + VERT_MARGIN;
         }
     }
+#endif
 }
 
 void wxCalendarCtrl::DoGetSize(int *width, int *height) const
 {
     wxControl::DoGetSize(width, height);
-
-    if ( !(GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION) )
+#ifndef __WXPM__
+    if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) )
     {
         // our real height is bigger
         if ( height && GetMonthControl())
@@ -838,6 +865,7 @@ void wxCalendarCtrl::DoGetSize(int *width, int *height) const
             *height += GetMonthControl()->GetSize().y + VERT_MARGIN;
         }
     }
+#endif
 }
 
 void wxCalendarCtrl::RecalcGeometry()
@@ -875,7 +903,7 @@ void wxCalendarCtrl::RecalcGeometry()
     m_widthCol += 2;
     m_heightRow += 2;
 
-    m_rowOffset = (GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION) ? m_heightRow : 0; // conditional in relation to style
+    m_rowOffset = HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) ? m_heightRow : 0; // conditional in relation to style
 }
 
 // ----------------------------------------------------------------------------