- SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable...
- GetClientSize(&ClientWidth, &ClientHeight);
- m_Cell->Layout(ClientWidth); // ...and relayout
+ // If the content doesn't fit into the window by only a small
+ // margin, chances are that it may fit fully with scrollbar turned
+ // off. It's something worth trying but on the other hand, we don't
+ // want to waste too much time redoing the layout (twice!) for
+ // long -- and thus expensive to layout -- pages. The cut-off value
+ // is an arbitrary heuristics.
+ static const int SMALL_OVERLAP = 60;
+ if ( m_Cell->GetHeight() <= clientHeight + SMALL_OVERLAP )
+ {
+ m_Cell->Layout(clientWidth);
+
+ if ( m_Cell->GetHeight() <= clientHeight )
+ {
+ // Great, we fit in. Hide the scrollbar.
+ SetScrollbars
+ (
+ wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP,
+ ScrollSteps(m_Cell->GetWidth(), clientWidth),
+ 0
+ );
+ return;
+ }
+ else
+ {
+ // That didn't work out, go back to previous layout. Note
+ // that redoing the layout once again here isn't as bad as
+ // it looks -- thanks to the small cut-off value, it's a
+ // reasonably small page.
+ m_Cell->Layout(clientWidth - vscrollbar);
+ }
+ }
+ // else: the page is very long, it will certainly need scrollbar
+
+ SetScrollbars
+ (
+ wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP,
+ ScrollSteps(m_Cell->GetWidth(), clientWidth - vscrollbar),
+ ScrollSteps(m_Cell->GetHeight(), clientHeight)
+ );