unicode character events

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32559 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2005-03-02 17:45:49 +00:00
parent e5ecf1fc24
commit 2d17efa94e
3 changed files with 40 additions and 8 deletions

View File

@ -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) ;

View File

@ -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;

View File

@ -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);