Generate scroll events for key presses in wxScrolledWindow.

Don't duplicate the existing wxScrolledWindow::CalcScrollInc() logic in
HandleOnChar(), simply generate scrolling events from it, this simplifies the
code and ensures that it is more correct.

Closes #11070.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61614 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-08-05 17:25:14 +00:00
parent a58804eae1
commit e2495f725c

View File

@@ -829,93 +829,70 @@ void wxScrollHelperBase::HandleOnPaint(wxPaintEvent& WXUNUSED(event))
// this they always have the priority // this they always have the priority
void wxScrollHelperBase::HandleOnChar(wxKeyEvent& event) void wxScrollHelperBase::HandleOnChar(wxKeyEvent& event)
{ {
int stx = 0, sty = 0, // view origin // prepare the event this key press maps to
szx = 0, szy = 0, // view size (total) wxScrollWinEvent newEvent;
clix = 0, cliy = 0; // view size (on screen)
GetViewStart(&stx, &sty); newEvent.SetPosition(0);
GetTargetSize(&clix, &cliy); newEvent.SetEventObject(m_win);
m_targetWindow->GetVirtualSize(&szx, &szy);
if( m_xScrollPixelsPerLine ) // this is the default, it's changed to wxHORIZONTAL below if needed
{ newEvent.SetOrientation(wxVERTICAL);
clix /= m_xScrollPixelsPerLine;
szx /= m_xScrollPixelsPerLine;
}
else
{
clix = 0;
szx = -1;
}
if( m_yScrollPixelsPerLine )
{
cliy /= m_yScrollPixelsPerLine;
szy /= m_yScrollPixelsPerLine;
}
else
{
cliy = 0;
szy = -1;
}
int xScrollOld = m_xScrollPosition, // some key events result in scrolling in both horizontal and vertical
yScrollOld = m_yScrollPosition; // direction, e.g. Ctrl-{Home,End}, if this flag is true we should generate
// a second event in horizontal direction in addition to the primary one
bool sendHorizontalToo = false;
int dsty;
switch ( event.GetKeyCode() ) switch ( event.GetKeyCode() )
{ {
case WXK_PAGEUP: case WXK_PAGEUP:
dsty = sty - (5 * cliy / 6); newEvent.SetEventType(wxEVT_SCROLLWIN_PAGEUP);
Scroll(-1, (dsty == -1) ? 0 : dsty);
break; break;
case WXK_PAGEDOWN: case WXK_PAGEDOWN:
Scroll(-1, sty + (5 * cliy / 6)); newEvent.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN);
break; break;
case WXK_HOME: case WXK_HOME:
Scroll(0, event.ControlDown() ? 0 : -1); newEvent.SetEventType(wxEVT_SCROLLWIN_TOP);
sendHorizontalToo = event.ControlDown();
break; break;
case WXK_END: case WXK_END:
Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1); newEvent.SetEventType(wxEVT_SCROLLWIN_BOTTOM);
break;
case WXK_UP: sendHorizontalToo = event.ControlDown();
Scroll(-1, sty - 1);
break;
case WXK_DOWN:
Scroll(-1, sty + 1);
break; break;
case WXK_LEFT: case WXK_LEFT:
Scroll(stx - 1, -1); newEvent.SetOrientation(wxHORIZONTAL);
// fall through
case WXK_UP:
newEvent.SetEventType(wxEVT_SCROLLWIN_LINEUP);
break; break;
case WXK_RIGHT: case WXK_RIGHT:
Scroll(stx + 1, -1); newEvent.SetOrientation(wxHORIZONTAL);
// fall through
case WXK_DOWN:
newEvent.SetEventType(wxEVT_SCROLLWIN_LINEDOWN);
break; break;
default: default:
// not for us // not a scrolling key
event.Skip(); event.Skip();
return;
} }
if ( m_xScrollPosition != xScrollOld ) m_win->ProcessWindowEvent(newEvent);
{
wxScrollWinEvent evt(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition,
wxHORIZONTAL);
evt.SetEventObject(m_win);
m_win->GetEventHandler()->ProcessEvent(evt);
}
if ( m_yScrollPosition != yScrollOld ) if ( sendHorizontalToo )
{ {
wxScrollWinEvent evt(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition, newEvent.SetOrientation(wxHORIZONTAL);
wxVERTICAL); m_win->ProcessWindowEvent(newEvent);
evt.SetEventObject(m_win);
m_win->GetEventHandler()->ProcessEvent(evt);
} }
} }