+ const wxRect viewRect(m_targetWindow->GetClientRect());
+
+ // For composite controls such as wxComboCtrl we should try to fit the
+ // entire control inside the visible area of the target window, not just
+ // the focused child of the control. Otherwise we'd make only the textctrl
+ // part of a wxComboCtrl visible and the button would still be outside the
+ // scrolled area. But do so only if the parent fits *entirely* inside the
+ // scrolled window. In other situations, such as nested wxPanel or
+ // wxScrolledWindows, the parent might be way to big to fit inside the
+ // scrolled window. If that is the case, then make only the focused window
+ // visible
+ if ( win->GetParent() != m_targetWindow)
+ {
+ wxWindow *parent=win->GetParent();
+ wxSize parent_size=parent->GetSize();
+ if (parent_size.GetWidth() <= viewRect.GetWidth() &&
+ parent_size.GetHeight() <= viewRect.GetHeight())
+ // make the immediate parent visible instead of the focused control
+ win=parent;
+ }
+
+ // make win position relative to the m_targetWindow viewing area instead of
+ // its parent
+ const wxRect
+ winRect(m_targetWindow->ScreenToClient(win->GetScreenPosition()),
+ win->GetSize());
+
+ // check if it's fully visible
+ if ( viewRect.Contains(winRect) )
+ {
+ // it is, nothing to do
+ return;
+ }
+
+ // check if we can make it fully visible: this is only possible if it's not
+ // larger than our view area
+ if ( winRect.GetWidth() > viewRect.GetWidth() ||
+ winRect.GetHeight() > viewRect.GetHeight() )
+ {
+ // we can't make it fit so avoid scrolling it at all, this is only
+ // going to be confusing and not helpful
+ return;
+ }
+
+
+ // do make the window fit inside the view area by scrolling to it
+ int stepx, stepy;
+ GetScrollPixelsPerUnit(&stepx, &stepy);
+
+ int startx, starty;
+ GetViewStart(&startx, &starty);
+
+ // first in vertical direction:
+ if ( stepy > 0 )
+ {
+ int diff = 0;
+
+ if ( winRect.GetTop() < 0 )
+ {
+ diff = winRect.GetTop();
+ }
+ else if ( winRect.GetBottom() > viewRect.GetHeight() )
+ {
+ diff = winRect.GetBottom() - viewRect.GetHeight() + 1;
+ // round up to next scroll step if we can't get exact position,
+ // so that the window is fully visible:
+ diff += stepy - 1;
+ }
+
+ starty = (starty * stepy + diff) / stepy;
+ }
+
+ // then horizontal:
+ if ( stepx > 0 )
+ {
+ int diff = 0;
+
+ if ( winRect.GetLeft() < 0 )
+ {
+ diff = winRect.GetLeft();
+ }
+ else if ( winRect.GetRight() > viewRect.GetWidth() )
+ {
+ diff = winRect.GetRight() - viewRect.GetWidth() + 1;
+ // round up to next scroll step if we can't get exact position,
+ // so that the window is fully visible:
+ diff += stepx - 1;
+ }
+
+ startx = (startx * stepx + diff) / stepx;
+ }
+
+ Scroll(startx, starty);
+}
+
+
+#ifdef wxHAS_GENERIC_SCROLLWIN
+
+// ----------------------------------------------------------------------------
+// wxScrollHelper implementation
+// ----------------------------------------------------------------------------
+
+wxScrollHelper::wxScrollHelper(wxWindow *winToScroll)
+ : wxScrollHelperBase(winToScroll)