X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33a037495e38443c8f4ae9e46b45b3c8f1c4c176..118322a3dfcc1803bd13df8193ea1be9ae39e653:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index f0c58c61b8..30b888bb2e 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -17,6 +17,17 @@ // headers // ---------------------------------------------------------------------------- +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) +#pragma implementation "vscroll.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + #include "wx/vscroll.h" // ---------------------------------------------------------------------------- @@ -33,6 +44,8 @@ END_EVENT_TABLE() // implementation // ============================================================================ +IMPLEMENT_ABSTRACT_CLASS(wxVScrolledWindow, wxPanel) + // ---------------------------------------------------------------------------- // initialization // ---------------------------------------------------------------------------- @@ -53,6 +66,38 @@ void wxVScrolledWindow::Init() // various helpers // ---------------------------------------------------------------------------- +wxCoord wxVScrolledWindow::EstimateTotalHeight() const +{ + // estimate the total height: it is impossible to call + // OnGetLineHeight() for every line because there may be too many of + // them, so we just make a guess using some lines in the beginning, + // some in the end and some in the middle + static const size_t NUM_LINES_TO_SAMPLE = 10; + + wxCoord heightTotal; + if ( m_lineMax < 3*NUM_LINES_TO_SAMPLE ) + { + // in this case calculating exactly is faster and more correct than + // guessing + heightTotal = GetLinesHeight(0, m_lineMax); + } + else // too many lines to calculate exactly + { + // look at some lines in the beginning/middle/end + heightTotal = + GetLinesHeight(0, NUM_LINES_TO_SAMPLE) + + GetLinesHeight(m_lineMax - NUM_LINES_TO_SAMPLE, m_lineMax) + + GetLinesHeight(m_lineMax/2 - NUM_LINES_TO_SAMPLE/2, + m_lineMax/2 + NUM_LINES_TO_SAMPLE/2); + + // use the height of the lines we looked as the average + heightTotal = (wxCoord) + (((float)heightTotal / (3*NUM_LINES_TO_SAMPLE)) * m_lineMax); + } + + return heightTotal; +} + wxCoord wxVScrolledWindow::GetLinesHeight(size_t lineMin, size_t lineMax) const { if ( lineMin == lineMax ) @@ -147,33 +192,8 @@ void wxVScrolledWindow::SetLineCount(size_t count) // save the number of lines m_lineMax = count; - - // estimate the total height: it is impossible to call - // OnGetLineHeight() for every line because there may be too many of - // them, so we just make a guess using some lines in the beginning, - // some in the end and some in the middle - static const size_t NUM_LINES_TO_SAMPLE = 10; - - if ( count < 3*NUM_LINES_TO_SAMPLE ) - { - // in this case calculating exactly is faster and more correct than - // guessing - m_heightTotal = GetLinesHeight(0, m_lineMax); - } - else // too many lines to calculate exactly - { - // look at some lines in the beginning/middle/end - m_heightTotal = - GetLinesHeight(0, NUM_LINES_TO_SAMPLE) + - GetLinesHeight(count - NUM_LINES_TO_SAMPLE, count) + - GetLinesHeight(count/2 - NUM_LINES_TO_SAMPLE/2, - count/2 + NUM_LINES_TO_SAMPLE/2); - - // use the height of the lines we looked as the average - m_heightTotal = (wxCoord) - (((float)m_heightTotal / (3*NUM_LINES_TO_SAMPLE)) * m_lineMax); - } - + // and our estimate for their total height + m_heightTotal = EstimateTotalHeight(); // recalculate the scrollbars parameters m_lineFirst = 1; // make sure it is != 0 @@ -354,6 +374,7 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event) size_t lineFirstNew; const wxEventType evtType = event.GetEventType(); + if ( evtType == wxEVT_SCROLLWIN_TOP ) { lineFirstNew = 0; @@ -378,21 +399,19 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event) { lineFirstNew = GetLastVisibleLine(); } - else // unknown scroll event? + else if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE ) { - if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE ) - { - lineFirstNew = event.GetPosition(); - } - else - { - wxASSERT_MSG( evtType == wxEVT_SCROLLWIN_THUMBTRACK, - _T("unknown scroll event type?") ); + lineFirstNew = event.GetPosition(); + } + else if ( evtType == wxEVT_SCROLLWIN_THUMBTRACK ) + { + lineFirstNew = event.GetPosition(); + } - // don't do anything, otherwise dragging the thumb around would - // be too slow - return; - } + else // unknown scroll event? + { + wxFAIL_MSG( _T("unknown scroll event type?") ); + return; } ScrollToLine(lineFirstNew);