From ddbc8ac9ca91a8dfb26b9a4b4307a52bfe5754d7 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 26 Sep 2009 10:39:26 +0000 Subject: [PATCH] cleaning up key handling, closes #10406 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62137 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private.h | 4 ++++ src/osx/cocoa/listbox.mm | 2 +- src/osx/cocoa/window.mm | 23 ++++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index a1df421303..291a549dc4 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -132,6 +132,10 @@ public : virtual bool DoHandleKeyEvent(NSEvent *event); virtual bool DoHandleCharEvent(NSEvent *event, NSString *text); virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow); + + virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL); + virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent); + void SetFlipped(bool flipped); virtual bool IsFlipped() const { return m_isFlipped; } diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index 79389e8306..2ba3fde0e2 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -512,7 +512,7 @@ void wxListWidgetCocoaImpl::controlDoubleAction(WXWidget WXUNUSED(slf),void* WXU list->HandleLineEvent( sel, true ); } -bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) +bool wxListWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) { wxKeyEvent wxevent(wxEVT_KEY_DOWN); SetupKeyEvent( wxevent, event ); diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 7bf085d65b..064d7ab234 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -271,7 +271,7 @@ long wxOSXTranslateCocoaKey( NSEvent* event ) return retval; } -void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString = NULL ) +void wxWidgetCocoaImpl::SetupKeyEvent(wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString) { UInt32 modifiers = [nsEvent modifierFlags] ; int eventType = [nsEvent type]; @@ -350,12 +350,19 @@ void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charStrin wxevent.m_uniChar = aunichar; #endif wxevent.m_keyCode = keyval; + + wxWindowMac* peer = GetWXPeer(); + if ( peer ) + { + wxevent.SetEventObject(peer); + wxevent.SetId(peer->GetId()) ; + } } UInt32 g_lastButton = 0 ; bool g_lastButtonWasFakeRight = false ; -void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) +void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) { int eventType = [nsEvent type]; UInt32 modifiers = [nsEvent modifierFlags] ; @@ -521,7 +528,12 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) } wxevent.m_clickCount = clickCount; - + wxWindowMac* peer = GetWXPeer(); + if ( peer ) + { + wxevent.SetEventObject(peer); + wxevent.SetId(peer->GetId()) ; + } } @implementation wxNSView @@ -1554,7 +1566,6 @@ bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text) { wxKeyEvent wxevent(wxEVT_CHAR); SetupKeyEvent( wxevent, event, text ); - wxevent.SetEventObject(GetWXPeer()); return GetWXPeer()->OSXHandleKeyEvent(wxevent); } @@ -1563,7 +1574,6 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) { wxKeyEvent wxevent(wxEVT_KEY_DOWN); SetupKeyEvent( wxevent, event ); - wxevent.SetEventObject(GetWXPeer()); bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent); // this will fire higher level events, like insertText, to help @@ -1589,8 +1599,7 @@ bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event) clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil]; wxPoint pt = wxFromNSPoint( m_osxView, clickLocation ); wxMouseEvent wxevent(wxEVT_LEFT_DOWN); - SetupMouseEvent( wxevent , event ) ; - wxevent.SetEventObject(GetWXPeer()); + SetupMouseEvent(wxevent , event) ; wxevent.m_x = pt.x; wxevent.m_y = pt.y;