From: Vadim Zeitlin Date: Mon, 12 Jul 2010 22:50:23 +0000 (+0000) Subject: Remove scroll units duplication in wxGrid to fix setting them. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fd76c6a77d9b0965534ed08e4aab979235370a44 Remove scroll units duplication in wxGrid to fix setting them. For some unknown reason wxGrid decided to store its scroll units in its own m_scrollLine[XY] variables instead of just using the base wxScrollWindow class m_[xy]ScrollPixelsPerLine ones. And, of course, the two could get out of sync because wxGrid didn't update the base class version correctly. Just don't duplicate these values at all and use the base class fields. This makes the code simpler and also fixes changing the size of the scroll units. Closes #12221. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64918 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 59b1e541e0..b42e57e7ca 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1595,10 +1595,10 @@ public: } // Allow adjustment of scroll increment. The default is (15, 15). - void SetScrollLineX(int x) { m_scrollLineX = x; } - void SetScrollLineY(int y) { m_scrollLineY = y; } - int GetScrollLineX() const { return m_scrollLineX; } - int GetScrollLineY() const { return m_scrollLineY; } + void SetScrollLineX(int x) { m_xScrollPixelsPerLine = x; } + void SetScrollLineY(int y) { m_yScrollPixelsPerLine = y; } + int GetScrollLineX() const { return m_xScrollPixelsPerLine; } + int GetScrollLineY() const { return m_yScrollPixelsPerLine; } // ------- drag and drop #if wxUSE_DRAG_AND_DROP @@ -2046,9 +2046,6 @@ protected: bool m_editable; // applies to whole grid bool m_cellEditCtrlEnabled; // is in-place edit currently shown? - int m_scrollLineX; // X scroll increment - int m_scrollLineY; // Y scroll increment - void Init(); // common part of all ctors void Create(); void CreateColumnWindow(); diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 106a57a06e..edb709d706 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1911,7 +1911,6 @@ bool wxGrid::Create(wxWindow *parent, wxWindowID id, Create(); SetInitialSize(size); - SetScrollRate(m_scrollLineX, m_scrollLineY); CalcDimensions(); return true; @@ -2249,8 +2248,11 @@ void wxGrid::Init() m_extraWidth = m_extraHeight = 0; - m_scrollLineX = GRID_SCROLL_LINE_X; - m_scrollLineY = GRID_SCROLL_LINE_Y; + // we can't call SetScrollRate() as the window isn't created yet but OTOH + // we don't need to call it neither as the scroll position is (0, 0) right + // now anyhow, so just set the parameters directly + m_xScrollPixelsPerLine = GRID_SCROLL_LINE_X; + m_yScrollPixelsPerLine = GRID_SCROLL_LINE_Y; } // ---------------------------------------------------------------------------- @@ -6405,7 +6407,7 @@ void wxGrid::MakeCellVisible( int row, int col ) // // Sometimes GRID_SCROLL_LINE / 2 is not enough, // so just add a full scroll unit... - ypos += m_scrollLineY; + ypos += m_yScrollPixelsPerLine; } // special handling for wide cells - show always left part of the cell! @@ -6424,15 +6426,15 @@ void wxGrid::MakeCellVisible( int row, int col ) xpos = x0 + (right - cw); // see comment for ypos above - xpos += m_scrollLineX; + xpos += m_xScrollPixelsPerLine; } if ( xpos != -1 || ypos != -1 ) { if ( xpos != -1 ) - xpos /= m_scrollLineX; + xpos /= m_xScrollPixelsPerLine; if ( ypos != -1 ) - ypos /= m_scrollLineY; + ypos /= m_yScrollPixelsPerLine; Scroll( xpos, ypos ); AdjustScrollbars(); } @@ -8115,10 +8117,8 @@ void wxGrid::AutoSize() // we know that we're not going to have scrollbars so disable them now to // avoid trouble in SetClientSize() which can otherwise set the correct // client size but also leave space for (not needed any more) scrollbars - SetScrollbars(0, 0, 0, 0, 0, 0, true); - - // restore the scroll rate parameters overwritten by SetScrollbars() - SetScrollRate(m_scrollLineX, m_scrollLineY); + SetScrollbars(m_xScrollPixelsPerLine, m_yScrollPixelsPerLine, + 0, 0, 0, 0, true); SetClientSize(size.x + m_rowLabelWidth, size.y + m_colLabelHeight); }