X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d9170b47d153c4f7835a41c4b7698bda34905724..3e1924dd5f5744c3e2a8973de9b3e4f372b7fd85:/src/generic/calctrl.cpp diff --git a/src/generic/calctrl.cpp b/src/generic/calctrl.cpp index aa8032ad76..a76d41f1b8 100644 --- a/src/generic/calctrl.cpp +++ b/src/generic/calctrl.cpp @@ -235,7 +235,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 @@ -253,6 +253,25 @@ wxCalendarCtrl::~wxCalendarCtrl() { delete m_attrs[n]; } + + if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) ) + { + delete m_comboMonth; + delete m_staticMonth; + delete m_spinYear; + delete m_staticYear; + } +} + +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); } // ---------------------------------------------------------------------------- @@ -394,6 +413,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 @@ -788,21 +808,32 @@ void wxCalendarCtrl::DoMoveWindow(int x, int y, int width, int height) { int yDiff; - if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) ) + 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,8 +846,8 @@ void wxCalendarCtrl::DoMoveWindow(int x, int y, int width, int height) void wxCalendarCtrl::DoGetPosition(int *x, int *y) const { wxControl::DoGetPosition(x, y); - - if ( !(GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION) ) +#ifndef __WXPM__ + if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) && GetMonthControl() ) { // our real top corner is not in this position if ( y ) @@ -824,13 +855,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 +870,7 @@ void wxCalendarCtrl::DoGetSize(int *width, int *height) const *height += GetMonthControl()->GetSize().y + VERT_MARGIN; } } +#endif } void wxCalendarCtrl::RecalcGeometry() @@ -875,7 +908,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 } // ---------------------------------------------------------------------------- @@ -1211,7 +1244,7 @@ void wxCalendarCtrl::RefreshDate(const wxDateTime& date) Refresh(true, &rect); } -void wxCalendarCtrl::HighlightRange(wxPaintDC* pDC, const wxDateTime& fromdate, const wxDateTime& todate, wxPen* pPen, wxBrush* pBrush) +void wxCalendarCtrl::HighlightRange(wxPaintDC* pDC, const wxDateTime& fromdate, const wxDateTime& todate, const wxPen* pPen, const wxBrush* pBrush) { // Highlights the given range using pen and brush // Does nothing if todate < fromdate @@ -1452,16 +1485,16 @@ wxCalendarHitTestResult wxCalendarCtrl::HitTest(const wxPoint& pos, { RecalcGeometry(); - wxCoord y = pos.y; + // the position where the calendar really begins + wxCoord x0 = wxMax((GetSize().x - m_widthCol*7)/2, 0); -/////////////////////////////////////////////////////////////////////////////////////////////////////// - if ( (GetWindowStyle() & wxCAL_SEQUENTIAL_MONTH_SELECTION) ) + if ( HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) ) { // Header: month // we need to find out if the hit is on left arrow, on month or on right arrow // left arrow? - if ( wxRegion(m_leftArrowRect).Contains(pos) == wxInRegion ) + if ( m_leftArrowRect.Contains(pos) ) { if ( date ) { @@ -1478,7 +1511,7 @@ wxCalendarHitTestResult wxCalendarCtrl::HitTest(const wxPoint& pos, return wxCAL_HITTEST_DECMONTH; } - if ( wxRegion(m_rightArrowRect).Contains(pos) == wxInRegion ) + if ( m_rightArrowRect.Contains(pos) ) { if ( date ) { @@ -1497,16 +1530,11 @@ wxCalendarHitTestResult wxCalendarCtrl::HitTest(const wxPoint& pos, } -/////////////////////////////////////////////////////////////////////////////////////////////////////// - // Header: Days - - wxCoord x0 = wxMax( (GetSize().x - m_widthCol*7) /2 , 0 ); - - int wday = ( pos.x - x0 ) / m_widthCol; -// if ( y < m_heightRow ) - if ( y < (m_heightRow + m_rowOffset) ) + // header: week days + int wday = (pos.x - x0) / m_widthCol; + if ( pos.y < (m_heightRow + m_rowOffset) ) { - if ( y > m_rowOffset ) + if ( pos.y > m_rowOffset ) { if ( wd ) { @@ -1526,8 +1554,7 @@ wxCalendarHitTestResult wxCalendarCtrl::HitTest(const wxPoint& pos, } } -// int week = (y - m_heightRow) / m_heightRow; - int week = (y - (m_heightRow + m_rowOffset)) / m_heightRow; + int week = (pos.y - (m_heightRow + m_rowOffset)) / m_heightRow; if ( week >= 6 || wday >= 7 ) { return wxCAL_HITTEST_NOWHERE; @@ -1653,13 +1680,13 @@ void wxCalendarCtrl::OnChar(wxKeyEvent& event) } break; - case WXK_PRIOR: + case WXK_PAGEUP: target = m_date - wxDateSpan::Month(); ChangeMonth(&target); SetDateAndNotify(target); // always break; - case WXK_NEXT: + case WXK_PAGEDOWN: target = m_date + wxDateSpan::Month(); ChangeMonth(&target); SetDateAndNotify(target); // always