From 2d17efa94e68c37fb415cf530daa558692ab7c2d Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 2 Mar 2005 17:45:49 +0000 Subject: [PATCH] unicode character events git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32559 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/app.h | 4 ++-- src/mac/carbon/app.cpp | 10 ++++++++-- src/mac/carbon/toplevel.cpp | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/include/wx/mac/carbon/app.h b/include/wx/mac/carbon/app.h index e9d0760bb9..ca6ecad5cb 100644 --- a/include/wx/mac/carbon/app.h +++ b/include/wx/mac/carbon/app.h @@ -135,8 +135,8 @@ public: // For embedded use. By default does nothing. virtual void MacHandleUnhandledEvent( WXEVENTREF ev ); - bool MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey ) ; - bool MacSendKeyUpEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey ) ; + bool MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) ; + bool MacSendKeyUpEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) ; virtual short MacHandleAEODoc(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; virtual short MacHandleAEPDoc(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index adb56a068c..bcff118fb6 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -1196,7 +1196,7 @@ bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below #endif -bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) +bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) { if ( !focus ) return false ; @@ -1231,6 +1231,9 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; event.m_keyCode = keyval ; +#if wxUSE_UNICODE + event.m_uniChar = uniChar ; +#endif event.m_x = wherex; event.m_y = wherey; @@ -1341,7 +1344,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi return handled ; } -bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) +bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) { if ( !focus ) return false ; @@ -1373,6 +1376,9 @@ bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifier event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; event.m_keyCode = keyval ; +#if wxUSE_UNICODE + event.m_uniChar = uniChar ; +#endif event.m_x = wherex; event.m_y = wherey; diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 3c6fa41f2c..7f7bc298af 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -36,6 +36,7 @@ #include "wx/log.h" #include "wx/intl.h" #include "wx/settings.h" + #include "wx/strconv.h" #include "wx/control.h" #endif //WX_PRECOMP @@ -167,17 +168,40 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event return result ; char charCode ; + wxChar uniChar = 0 ; UInt32 keyCode ; UInt32 modifiers ; Point point ; UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; +#if wxUSE_UNICODE + UInt32 dataSize = 0 ; + if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize , NULL ) == noErr ) + { + UniChar buf[2] ; + + UniChar* charBuf = buf ; + + if ( dataSize > 4 ) + charBuf = new UniChar[ dataSize / sizeof( UniChar) ] ; + GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; +#if SIZEOF_WCHAR_T == 2 + uniChar = charBuf[0] ; +#else + wxMBConvUTF16BE converter ; + converter.MB2WC( &uniChar , (const char*)charBuf , 1 ) ; +#endif + if ( dataSize > 4 ) + delete[] charBuf ; + } +#endif + GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof( Point ), NULL, &point ); - + UInt32 message = (keyCode << 8) + charCode; switch( GetEventKind( event ) ) { @@ -188,7 +212,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; wxTheApp->MacSetCurrentEvent( event , handler ) ; if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( - focus , message , modifiers , when , point.h , point.v ) ) + focus , message , modifiers , when , point.h , point.v , uniChar ) ) { result = noErr ; } @@ -197,7 +221,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event break ; case kEventRawKeyUp : if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( - focus , message , modifiers , when , point.h , point.v ) ) + focus , message , modifiers , when , point.h , point.v , uniChar ) ) { result = noErr ; } @@ -210,7 +234,9 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event event.m_controlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; - +#if wxUSE_UNICODE + event.m_uniChar = uniChar ; +#endif event.m_x = point.h; event.m_y = point.v; event.SetTimestamp(when); -- 2.45.2