X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cf7d6329530d0a9f181ac24dcc722d276885f05e..034957673ccd2006aee3937c5b86245e51d4bf62:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index aa52fab013..f0c58c61b8 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -74,7 +74,7 @@ wxCoord wxVScrolledWindow::GetLinesHeight(size_t lineMin, size_t lineMax) const return height; } -size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast) +size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast, bool full) { const wxCoord hWindow = GetClientSize().y; @@ -88,7 +88,13 @@ size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast) if ( h > hWindow ) { - lineFirst++; + // for this line to be fully visible we need to go one line + // down, but if it is enough for it to be only partly visible then + // this line will do as well + if ( full ) + { + lineFirst++; + } break; } @@ -164,15 +170,87 @@ void wxVScrolledWindow::SetLineCount(size_t count) count/2 + NUM_LINES_TO_SAMPLE/2); // use the height of the lines we looked as the average - m_heightTotal = ((float)m_heightTotal / (3*NUM_LINES_TO_SAMPLE)) * - m_lineMax; + m_heightTotal = (wxCoord) + (((float)m_heightTotal / (3*NUM_LINES_TO_SAMPLE)) * m_lineMax); } // recalculate the scrollbars parameters + m_lineFirst = 1; // make sure it is != 0 ScrollToLine(0); } +void wxVScrolledWindow::RefreshLine(size_t line) +{ + // is this line visible? + if ( !IsVisible(line) ) + { + // no, it is useless to do anything + return; + } + + // calculate the rect occupied by this line on screen + wxRect rect; + rect.width = GetClientSize().x; + rect.height = OnGetLineHeight(line); + for ( size_t n = GetFirstVisibleLine(); n < line; n++ ) + { + rect.y += OnGetLineHeight(n); + } + + // do refresh it + RefreshRect(rect); +} + +void wxVScrolledWindow::RefreshLines(size_t from, size_t to) +{ + wxASSERT_MSG( from <= to, _T("RefreshLines(): empty range") ); + + // clump the range to just the visible lines -- it is useless to refresh + // the other ones + if ( from < GetFirstVisibleLine() ) + from = GetFirstVisibleLine(); + + if ( to > GetLastVisibleLine() ) + to = GetLastVisibleLine(); + + // calculate the rect occupied by these lines on screen + wxRect rect; + rect.width = GetClientSize().x; + for ( size_t nBefore = GetFirstVisibleLine(); nBefore < from; nBefore++ ) + { + rect.y += OnGetLineHeight(nBefore); + } + + for ( size_t nBetween = from; nBetween <= to; nBetween++ ) + { + rect.height += OnGetLineHeight(nBetween); + } + + // do refresh it + RefreshRect(rect); +} + +void wxVScrolledWindow::RefreshAll() +{ + UpdateScrollbar(); + + Refresh(); +} + +int wxVScrolledWindow::HitTest(wxCoord WXUNUSED(x), wxCoord y) const +{ + const size_t lineMax = GetLastVisibleLine(); + for ( size_t line = GetFirstVisibleLine(); line <= lineMax; line++ ) + { + y -= OnGetLineHeight(line); + if ( y < 0 ) + return line; + } + + return wxNOT_FOUND; +} + // ---------------------------------------------------------------------------- // scrolling // ---------------------------------------------------------------------------- @@ -187,7 +265,7 @@ bool wxVScrolledWindow::ScrollToLine(size_t line) // determine the real first line to scroll to: we shouldn't scroll beyond // the end - size_t lineFirstLast = FindFirstFromBottom(m_lineMax - 1); + size_t lineFirstLast = FindFirstFromBottom(m_lineMax - 1, true); if ( line > lineFirstLast ) line = lineFirstLast; @@ -318,5 +396,9 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event) } ScrollToLine(lineFirstNew); + +#ifdef __WXMAC__ + Update(); +#endif // __WXMAC__ }