Make default keyboard handling available in wxVarScrollHelperEvtHandler too.
Factor out the keyboard handling code in wxAnyScrollHelperBase allowing its reuse in wxVarScrollHelperEvtHandler. Now wxVarScrollHelperBase handles cursor keys in a sane way by default too and also allows disabling their handling, just as wxScrolledWindow. See #15357. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74815 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
dc2513650d
commit
4706252347
@ -66,6 +66,17 @@ class WXDLLIMPEXP_CORE wxAnyScrollHelperBase
|
|||||||
public:
|
public:
|
||||||
wxEXPLICIT wxAnyScrollHelperBase(wxWindow* win);
|
wxEXPLICIT wxAnyScrollHelperBase(wxWindow* win);
|
||||||
|
|
||||||
|
// Disable use of keyboard keys for scrolling. By default cursor movement
|
||||||
|
// keys (including Home, End, Page Up and Down) are used to scroll the
|
||||||
|
// window appropriately. If the derived class uses these keys for something
|
||||||
|
// else, e.g. changing the currently selected item, this function can be
|
||||||
|
// used to disable this behaviour as it's not only not necessary then but
|
||||||
|
// can actually be actively harmful if another object forwards a keyboard
|
||||||
|
// event corresponding to one of the above keys to us using
|
||||||
|
// ProcessWindowEvent() because the event will always be processed which
|
||||||
|
// can be undesirable.
|
||||||
|
void DisableKeyboardScrolling() { m_kbdScrollingEnabled = false; }
|
||||||
|
|
||||||
// Override this function to draw the graphic (or just process EVT_PAINT)
|
// Override this function to draw the graphic (or just process EVT_PAINT)
|
||||||
virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
|
virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
|
||||||
|
|
||||||
@ -77,6 +88,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// The methods called from the window event handlers.
|
// The methods called from the window event handlers.
|
||||||
|
void HandleOnChar(wxKeyEvent& event);
|
||||||
void HandleOnPaint(wxPaintEvent& event);
|
void HandleOnPaint(wxPaintEvent& event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -84,6 +96,9 @@ protected:
|
|||||||
// scroll, respectively
|
// scroll, respectively
|
||||||
wxWindow *m_win,
|
wxWindow *m_win,
|
||||||
*m_targetWindow;
|
*m_targetWindow;
|
||||||
|
|
||||||
|
// whether cursor keys should scroll the window
|
||||||
|
bool m_kbdScrollingEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the class containing the guts of (uniform) scrolling logic.
|
// This is the class containing the guts of (uniform) scrolling logic.
|
||||||
@ -146,17 +161,6 @@ public:
|
|||||||
// which it is implemented to not use wxWindow::ScrollWindow().
|
// which it is implemented to not use wxWindow::ScrollWindow().
|
||||||
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
|
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
|
||||||
|
|
||||||
// Disable use of keyboard keys for scrolling. By default cursor movement
|
|
||||||
// keys (including Home, End, Page Up and Down) are used to scroll the
|
|
||||||
// window appropriately. If the derived class uses these keys for something
|
|
||||||
// else, e.g. changing the currently selected item, this function can be
|
|
||||||
// used to disable this behaviour as it's not only not necessary then but
|
|
||||||
// can actually be actively harmful if another object forwards a keyboard
|
|
||||||
// event corresponding to one of the above keys to us using
|
|
||||||
// ProcessWindowEvent() because the event will always be processed which
|
|
||||||
// can be undesirable.
|
|
||||||
void DisableKeyboardScrolling() { m_kbdScrollingEnabled = false; }
|
|
||||||
|
|
||||||
// Get the view start
|
// Get the view start
|
||||||
void GetViewStart(int *x, int *y) const { DoGetViewStart(x, y); }
|
void GetViewStart(int *x, int *y) const { DoGetViewStart(x, y); }
|
||||||
|
|
||||||
@ -228,7 +232,6 @@ public:
|
|||||||
// the methods to be called from the window event handlers
|
// the methods to be called from the window event handlers
|
||||||
void HandleOnScroll(wxScrollWinEvent& event);
|
void HandleOnScroll(wxScrollWinEvent& event);
|
||||||
void HandleOnSize(wxSizeEvent& event);
|
void HandleOnSize(wxSizeEvent& event);
|
||||||
void HandleOnChar(wxKeyEvent& event);
|
|
||||||
void HandleOnMouseEnter(wxMouseEvent& event);
|
void HandleOnMouseEnter(wxMouseEvent& event);
|
||||||
void HandleOnMouseLeave(wxMouseEvent& event);
|
void HandleOnMouseLeave(wxMouseEvent& event);
|
||||||
#if wxUSE_MOUSEWHEEL
|
#if wxUSE_MOUSEWHEEL
|
||||||
@ -324,8 +327,6 @@ protected:
|
|||||||
bool m_xScrollingEnabled;
|
bool m_xScrollingEnabled;
|
||||||
bool m_yScrollingEnabled;
|
bool m_yScrollingEnabled;
|
||||||
|
|
||||||
bool m_kbdScrollingEnabled;
|
|
||||||
|
|
||||||
#if wxUSE_MOUSEWHEEL
|
#if wxUSE_MOUSEWHEEL
|
||||||
int m_wheelRotation;
|
int m_wheelRotation;
|
||||||
#endif // wxUSE_MOUSEWHEEL
|
#endif // wxUSE_MOUSEWHEEL
|
||||||
|
@ -326,6 +326,8 @@ wxAnyScrollHelperBase::wxAnyScrollHelperBase(wxWindow* win)
|
|||||||
|
|
||||||
m_win = win;
|
m_win = win;
|
||||||
m_targetWindow = NULL;
|
m_targetWindow = NULL;
|
||||||
|
|
||||||
|
m_kbdScrollingEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -347,8 +349,6 @@ wxScrollHelperBase::wxScrollHelperBase(wxWindow *win)
|
|||||||
m_xScrollingEnabled =
|
m_xScrollingEnabled =
|
||||||
m_yScrollingEnabled = true;
|
m_yScrollingEnabled = true;
|
||||||
|
|
||||||
m_kbdScrollingEnabled = true;
|
|
||||||
|
|
||||||
m_scaleX =
|
m_scaleX =
|
||||||
m_scaleY = 1.0;
|
m_scaleY = 1.0;
|
||||||
#if wxUSE_MOUSEWHEEL
|
#if wxUSE_MOUSEWHEEL
|
||||||
@ -833,7 +833,7 @@ void wxAnyScrollHelperBase::HandleOnPaint(wxPaintEvent& WXUNUSED(event))
|
|||||||
// compatibility here - if we used OnKeyDown(), the programs which process
|
// compatibility here - if we used OnKeyDown(), the programs which process
|
||||||
// arrows themselves in their OnChar() would never get the message and like
|
// arrows themselves in their OnChar() would never get the message and like
|
||||||
// this they always have the priority
|
// this they always have the priority
|
||||||
void wxScrollHelperBase::HandleOnChar(wxKeyEvent& event)
|
void wxAnyScrollHelperBase::HandleOnChar(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
if ( !m_kbdScrollingEnabled )
|
if ( !m_kbdScrollingEnabled )
|
||||||
{
|
{
|
||||||
|
@ -142,6 +142,16 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event);
|
m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event);
|
||||||
}
|
}
|
||||||
#endif // wxUSE_MOUSEWHEEL
|
#endif // wxUSE_MOUSEWHEEL
|
||||||
|
else if ( evType == wxEVT_CHAR &&
|
||||||
|
(m_scrollHelper->GetOrientation() == wxVERTICAL) )
|
||||||
|
{
|
||||||
|
m_scrollHelper->HandleOnChar((wxKeyEvent &)event);
|
||||||
|
if ( !event.GetSkipped() )
|
||||||
|
{
|
||||||
|
processed = true;
|
||||||
|
wasSkipped = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event.Skip(wasSkipped);
|
event.Skip(wasSkipped);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user