- iterationCount ++;
-
- GetTargetSize(&w, 0);
-
- // scroll lines per page: if 0, no scrolling is needed
- int linesPerPage;
-
- if ( m_xScrollPixelsPerLine == 0 )
- {
- // scrolling is disabled
- m_xScrollLines = 0;
- m_xScrollPosition = 0;
- linesPerPage = 0;
- }
- else // might need scrolling
- {
- // Round up integer division to catch any "leftover" client space.
- const int wVirt = m_targetWindow->GetVirtualSize().GetWidth();
- m_xScrollLines = (wVirt + m_xScrollPixelsPerLine - 1) / m_xScrollPixelsPerLine;
-
- // Calculate page size i.e. number of scroll units you get on the
- // current client window.
- linesPerPage = w / m_xScrollPixelsPerLine;
-
- // Special case. When client and virtual size are very close but
- // the client is big enough, kill scrollbar.
- if ((linesPerPage < m_xScrollLines) && (w >= wVirt)) ++linesPerPage;
-
- if (linesPerPage >= m_xScrollLines)
- {
- // we're big enough to not need scrolling
- linesPerPage =
- m_xScrollLines =
- m_xScrollPosition = 0;
- }
- else // we do need a scrollbar
- {
- if ( linesPerPage < 1 )
- linesPerPage = 1;
-
- // Correct position if greater than extent of canvas minus
- // the visible portion of it or if below zero
- const int posMax = m_xScrollLines - linesPerPage;
- if ( m_xScrollPosition > posMax )
- m_xScrollPosition = posMax;
- else if ( m_xScrollPosition < 0 )
- m_xScrollPosition = 0;
- }
- }
-
- m_win->SetScrollbar(wxHORIZONTAL, m_xScrollPosition,
- linesPerPage, m_xScrollLines);
-
- // The amount by which we scroll when paging
- SetScrollPageSize(wxHORIZONTAL, linesPerPage);
-
- GetTargetSize(0, &h);
-
- if ( m_yScrollPixelsPerLine == 0 )
- {
- // scrolling is disabled
- m_yScrollLines = 0;
- m_yScrollPosition = 0;
- linesPerPage = 0;
- }
- else // might need scrolling
+ wxSize clientSize = GetTargetSize();
+ const wxSize virtSize = m_targetWindow->GetVirtualSize();
+
+ // this block of code tries to work around the following problem: the
+ // window could have been just resized to have enough space to show its
+ // full contents without the scrollbars, but its client size could be
+ // not big enough because it does have the scrollbars right now and so
+ // the scrollbars would remain even though we don't need them any more
+ //
+ // to prevent this from happening, check if we have enough space for
+ // everything without the scrollbars and explicitly disable them then
+ const wxSize availSize = GetSizeAvailableForScrollTarget(
+ m_win->GetSize() - m_win->GetWindowBorderSize());
+ if ( availSize != clientSize )