Don't eagerly set wxKeyEvent position fields.

This results in a noticeable delay when using wxGTK via a remote X11
connection for every key event as a round trip to server is needed to get the
mouse pointer position every time a key is pressed or released.

Only provide the position on demand. And explain that it's actually not very
useful as it's simply the same as the current mouse position.

Closes #14361.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72207 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-07-24 20:45:52 +00:00
parent 7ce6da52a1
commit 2f7baaeccf
10 changed files with 78 additions and 49 deletions

View File

@@ -736,6 +736,10 @@ wxKeyEvent::wxKeyEvent(wxEventType type)
m_uniChar = WXK_NONE;
#endif
m_x =
m_y = wxDefaultCoord;
m_hasPosition = false;
InitPropagation();
}
@@ -759,6 +763,42 @@ wxKeyEvent::wxKeyEvent(wxEventType eventType, const wxKeyEvent& evt)
InitPropagation();
}
void wxKeyEvent::InitPositionIfNecessary() const
{
if ( m_hasPosition )
return;
// We're const because we're called from const Get[XY]() methods but we
// need to update the "cached" values.
wxKeyEvent& self = const_cast<wxKeyEvent&>(*this);
self.m_hasPosition = true;
// The only position we can possibly associate with the keyboard event on
// the platforms where it doesn't carry it already is the mouse position.
wxGetMousePosition(&self.m_x, &self.m_y);
// If this event is associated with a window, the position should be in its
// client coordinates, but otherwise leave it in screen coordinates as what
// else can we use?
wxWindow* const win = wxDynamicCast(GetEventObject(), wxWindow);
if ( win )
win->ScreenToClient(&self.m_x, &self.m_y);
}
wxCoord wxKeyEvent::GetX() const
{
InitPositionIfNecessary();
return m_x;
}
wxCoord wxKeyEvent::GetY() const
{
InitPositionIfNecessary();
return m_y;
}
bool wxKeyEvent::IsKeyInCategory(int category) const
{
switch ( GetKeyCode() )