backported: when a window inside scrolled window receives focus, make sure the parent is scrolled so that the window with focus is visible
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@50864 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -105,6 +105,7 @@ All (GUI):
|
|||||||
- wxRichTextCtrl performance has been improved considerably.
|
- wxRichTextCtrl performance has been improved considerably.
|
||||||
- wxNotebook RTTI corrected, so now wxDynamicCast(notebook, wxBookCtrlBase)
|
- wxNotebook RTTI corrected, so now wxDynamicCast(notebook, wxBookCtrlBase)
|
||||||
works.
|
works.
|
||||||
|
- When focus is set to wxScrolledWindow child, scroll it into view.
|
||||||
|
|
||||||
All (Unix):
|
All (Unix):
|
||||||
|
|
||||||
|
@@ -163,6 +163,10 @@ public:
|
|||||||
void HandleOnMouseWheel(wxMouseEvent& event);
|
void HandleOnMouseWheel(wxMouseEvent& event);
|
||||||
#endif // wxUSE_MOUSEWHEEL
|
#endif // wxUSE_MOUSEWHEEL
|
||||||
|
|
||||||
|
#if wxABI_VERSION >= 20808
|
||||||
|
void HandleOnChildFocus(wxChildFocusEvent& event);
|
||||||
|
#endif
|
||||||
|
|
||||||
// FIXME: this is needed for now for wxPlot compilation, should be removed
|
// FIXME: this is needed for now for wxPlot compilation, should be removed
|
||||||
// once it is fixed!
|
// once it is fixed!
|
||||||
void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); }
|
void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); }
|
||||||
|
@@ -245,6 +245,12 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( evType == wxEVT_CHILD_FOCUS )
|
||||||
|
{
|
||||||
|
m_scrollHelper->HandleOnChildFocus((wxChildFocusEvent &)event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( evType == wxEVT_SCROLLWIN_TOP ||
|
if ( evType == wxEVT_SCROLLWIN_TOP ||
|
||||||
evType == wxEVT_SCROLLWIN_BOTTOM ||
|
evType == wxEVT_SCROLLWIN_BOTTOM ||
|
||||||
evType == wxEVT_SCROLLWIN_LINEUP ||
|
evType == wxEVT_SCROLLWIN_LINEUP ||
|
||||||
@@ -1339,6 +1345,75 @@ void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event)
|
|||||||
|
|
||||||
#endif // wxUSE_MOUSEWHEEL
|
#endif // wxUSE_MOUSEWHEEL
|
||||||
|
|
||||||
|
void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
|
||||||
|
{
|
||||||
|
// this event should be processed by all windows in parenthood chain,
|
||||||
|
// e.g. so that nested wxScrolledWindows work correctly
|
||||||
|
event.Skip();
|
||||||
|
|
||||||
|
// find the immediate child under which the window receiving focus is:
|
||||||
|
wxWindow *win = event.GetWindow();
|
||||||
|
while ( win->GetParent() != m_targetWindow )
|
||||||
|
{
|
||||||
|
win = win->GetParent();
|
||||||
|
wxCHECK_RET( win, "incorrectly sent wxChildFocusEvent - not our child" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the child is not fully visible, try to scroll it into view:
|
||||||
|
int stepx, stepy;
|
||||||
|
GetScrollPixelsPerUnit(&stepx, &stepy);
|
||||||
|
|
||||||
|
// NB: we don't call CalcScrolledPosition() on win->GetPosition() here,
|
||||||
|
// because children' positions are already scrolled
|
||||||
|
wxRect winrect(win->GetPosition(), win->GetSize());
|
||||||
|
wxSize view(m_targetWindow->GetClientSize());
|
||||||
|
|
||||||
|
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() > view.y )
|
||||||
|
{
|
||||||
|
diff = winrect.GetBottom() - view.y + 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() > view.x )
|
||||||
|
{
|
||||||
|
diff = winrect.GetRight() - view.x + 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);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxScrolledWindow implementation
|
// wxScrolledWindow implementation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
# public symbols added in 2.8.8 (please keep in alphabetical order):
|
# public symbols added in 2.8.8 (please keep in alphabetical order):
|
||||||
@WX_VERSION_TAG@.8 {
|
@WX_VERSION_TAG@.8 {
|
||||||
global:
|
global:
|
||||||
|
*wxScrollHelper*HandleOnChildFocus*;
|
||||||
*wxWindowBase*Get*Sibling*;
|
*wxWindowBase*Get*Sibling*;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user