X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/028285e4af7232447cbb88caec61a3129cde02a7..e333075415c35d2e869ea585fa41f01a2c938897:/src/generic/calctrl.cpp?ds=sidebyside diff --git a/src/generic/calctrl.cpp b/src/generic/calctrl.cpp index e5e98717bc..80e1bb4a00 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 @@ -790,7 +810,7 @@ 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(); @@ -826,7 +846,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 @@ -835,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()) @@ -849,6 +870,7 @@ void wxCalendarCtrl::DoGetSize(int *width, int *height) const *height += GetMonthControl()->GetSize().y + VERT_MARGIN; } } +#endif } void wxCalendarCtrl::RecalcGeometry() @@ -886,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 } // ---------------------------------------------------------------------------- @@ -914,10 +936,10 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) { // draw the sequential month-selector - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); dc.SetTextForeground(*wxBLACK); - dc.SetBrush(wxBrush(m_colHeaderBg, wxSOLID)); - dc.SetPen(wxPen(m_colHeaderBg, 1, wxSOLID)); + dc.SetBrush(wxBrush(m_colHeaderBg, wxBRUSHSTYLE_SOLID)); + dc.SetPen(wxPen(m_colHeaderBg, 1, wxPENSTYLE_SOLID)); dc.DrawRectangle(0, y, GetClientSize().x, m_heightRow); // Get extent of month-name + year @@ -986,10 +1008,10 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) wxLogDebug("painting the header"); #endif - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); dc.SetTextForeground(m_colHeaderFg); - dc.SetBrush(wxBrush(m_colHeaderBg, wxSOLID)); - dc.SetPen(wxPen(m_colHeaderBg, 1, wxSOLID)); + dc.SetBrush(wxBrush(m_colHeaderBg, wxBRUSHSTYLE_SOLID)); + dc.SetPen(wxPen(m_colHeaderBg, 1, wxPENSTYLE_SOLID)); dc.DrawRectangle(0, y, GetClientSize().x, m_heightRow); bool startOnMonday = (GetWindowStyle() & wxCAL_MONDAY_FIRST) != 0; @@ -1018,7 +1040,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) date.Format("%a %d-%m-%Y %H:%M:%S").c_str()); #endif - dc.SetBackgroundMode(wxSOLID); + dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID); for ( size_t nWeek = 1; nWeek <= 6; nWeek++, y += m_heightRow ) { // if the update region doesn't intersect this row, don't paint it @@ -1119,7 +1141,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) colBorder = GetForegroundColour(); } - wxPen pen(colBorder, 1, wxSOLID); + wxPen pen(colBorder, 1, wxPENSTYLE_SOLID); dc.SetPen(pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); @@ -1166,7 +1188,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) wxDateTime firstOOR = GetLowerDateLimit() - wxDateSpan::Day(); // first out-of-range wxBrush oorbrush = *wxLIGHT_GREY_BRUSH; - oorbrush.SetStyle(wxFDIAGONAL_HATCH); + oorbrush.SetStyle(wxBRUSHSTYLE_FDIAGONAL_HATCH); HighlightRange(&dc, date, firstOOR, wxTRANSPARENT_PEN, &oorbrush); } @@ -1177,7 +1199,7 @@ void wxCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) wxDateTime firstOOR = GetUpperDateLimit() + wxDateSpan::Day(); // first out-of-range wxBrush oorbrush = *wxLIGHT_GREY_BRUSH; - oorbrush.SetStyle(wxFDIAGONAL_HATCH); + oorbrush.SetStyle(wxBRUSHSTYLE_FDIAGONAL_HATCH); HighlightRange(&dc, firstOOR, date, wxTRANSPARENT_PEN, &oorbrush); } @@ -1462,21 +1484,17 @@ wxCalendarHitTestResult wxCalendarCtrl::HitTest(const wxPoint& pos, wxDateTime::WeekDay *wd) { RecalcGeometry(); - // use the correct x-pos - wxCoord x0 = wxMax((GetSize().x - m_widthCol*7) /2, 0); - wxPoint pos_corr = pos; - pos_corr.x -= x0; - wxCoord y = pos_corr.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_corr) == wxInRegion ) + if ( m_leftArrowRect.Contains(pos) ) { if ( date ) { @@ -1493,7 +1511,7 @@ wxCalendarHitTestResult wxCalendarCtrl::HitTest(const wxPoint& pos, return wxCAL_HITTEST_DECMONTH; } - if ( wxRegion(m_rightArrowRect).Contains(pos_corr) == wxInRegion ) + if ( m_rightArrowRect.Contains(pos) ) { if ( date ) { @@ -1512,14 +1530,11 @@ wxCalendarHitTestResult wxCalendarCtrl::HitTest(const wxPoint& pos, } -/////////////////////////////////////////////////////////////////////////////////////////////////////// - // Header: Days - - int wday = pos_corr.x / 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 ) { @@ -1539,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;