routing key events to new app routine
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15912 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f11afffe01
commit
ac2d1ca6c6
115
src/mac/app.cpp
115
src/mac/app.cpp
@ -1031,7 +1031,7 @@ bool wxApp::OnInit()
|
||||
if ( ! wxAppBase::OnInit() )
|
||||
return FALSE ;
|
||||
|
||||
#if TARGET_CARBON
|
||||
#if 0 // TARGET_CARBON
|
||||
static const EventTypeSpec eventList[] =
|
||||
{
|
||||
{ kEventClassKeyboard, kEventRawKeyDown } ,
|
||||
@ -1726,26 +1726,39 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
short keychar ;
|
||||
keychar = short(ev->message & charCodeMask);
|
||||
keycode = short(ev->message & keyCodeMask) >> 8 ;
|
||||
// it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
|
||||
if ( ev->modifiers & controlKey && keychar >= 0 && keychar < 0x20 )
|
||||
{
|
||||
keychar += 0x40 ;
|
||||
}
|
||||
long keyval = wxMacTranslateKey(keychar, keycode) ;
|
||||
bool handled = false ;
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
if ( focus )
|
||||
{
|
||||
|
||||
if ( MacSendKeyDownEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false )
|
||||
{
|
||||
// has not been handled -> perform default
|
||||
wxControl* control = wxDynamicCast( focus , wxControl ) ;
|
||||
if ( control && control->GetMacControl() != NULL )
|
||||
{
|
||||
::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey )
|
||||
{
|
||||
bool handled = false ;
|
||||
// it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
|
||||
if ( modifiers & controlKey && keyval >= 0 && keyval < 0x20 )
|
||||
{
|
||||
keyval += 0x40 ;
|
||||
}
|
||||
wxKeyEvent event(wxEVT_KEY_DOWN);
|
||||
event.m_shiftDown = ev->modifiers & shiftKey;
|
||||
event.m_controlDown = ev->modifiers & controlKey;
|
||||
event.m_altDown = ev->modifiers & optionKey;
|
||||
event.m_metaDown = ev->modifiers & cmdKey;
|
||||
event.m_shiftDown = modifiers & shiftKey;
|
||||
event.m_controlDown = modifiers & controlKey;
|
||||
event.m_altDown = modifiers & optionKey;
|
||||
event.m_metaDown = modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
event.m_x = ev->where.h;
|
||||
event.m_y = ev->where.v;
|
||||
event.m_timeStamp = ev->when;
|
||||
|
||||
event.m_x = wherex;
|
||||
event.m_y = wherey;
|
||||
event.m_timeStamp = when;
|
||||
event.SetEventObject(focus);
|
||||
handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
if ( handled && event.GetSkipped() )
|
||||
@ -1774,16 +1787,9 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
}
|
||||
if (!handled)
|
||||
{
|
||||
wxKeyEvent event(wxEVT_CHAR);
|
||||
event.m_shiftDown = ev->modifiers & shiftKey;
|
||||
event.m_controlDown = ev->modifiers & controlKey;
|
||||
event.m_altDown = ev->modifiers & optionKey;
|
||||
event.m_metaDown = ev->modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
event.m_x = ev->where.h;
|
||||
event.m_y = ev->where.v;
|
||||
event.m_timeStamp = ev->when;
|
||||
event.SetEventObject(focus);
|
||||
event.Skip( FALSE ) ;
|
||||
event.SetEventType( wxEVT_CHAR ) ;
|
||||
|
||||
handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
if ( handled && event.GetSkipped() )
|
||||
handled = false ;
|
||||
@ -1810,12 +1816,12 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
if ( handled && new_event.GetSkipped() )
|
||||
handled = false ;
|
||||
}
|
||||
}
|
||||
if ( !handled )
|
||||
// backdoor handler for default return and command escape
|
||||
if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
|
||||
{
|
||||
// if window is not having a focus still testing for default enter or cancel
|
||||
// TODO add the UMA version for ActiveNonFloatingWindow
|
||||
focus = wxFindWinFromMacWindow( FrontWindow() ) ;
|
||||
wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
|
||||
if ( focus )
|
||||
{
|
||||
if ( keyval == WXK_RETURN )
|
||||
@ -1827,11 +1833,11 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
|
||||
event.SetEventObject(def);
|
||||
def->Command(event);
|
||||
return ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
/* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
|
||||
else if (keyval == WXK_ESCAPE || (keyval == '.' && ev->modifiers & cmdKey ) )
|
||||
else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
|
||||
{
|
||||
wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
|
||||
new_event.SetEventObject( focus );
|
||||
@ -1839,8 +1845,9 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
}
|
||||
}
|
||||
}
|
||||
return handled ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
|
||||
{
|
||||
@ -1857,27 +1864,39 @@ void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
|
||||
short keychar ;
|
||||
keychar = short(ev->message & charCodeMask);
|
||||
keycode = short(ev->message & keyCodeMask) >> 8 ;
|
||||
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
if ( focus )
|
||||
{
|
||||
long keyval = wxMacTranslateKey(keychar, keycode) ;
|
||||
|
||||
wxKeyEvent event(wxEVT_KEY_UP);
|
||||
event.m_shiftDown = ev->modifiers & shiftKey;
|
||||
event.m_controlDown = ev->modifiers & controlKey;
|
||||
event.m_altDown = ev->modifiers & optionKey;
|
||||
event.m_metaDown = ev->modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
event.m_x = ev->where.h;
|
||||
event.m_y = ev->where.v;
|
||||
event.m_timeStamp = ev->when;
|
||||
event.SetEventObject(focus);
|
||||
bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
}
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
bool handled = MacSendKeyUpEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
|
||||
// we don't have to do anything under classic here
|
||||
}
|
||||
}
|
||||
|
||||
bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey )
|
||||
{
|
||||
bool handled = false ;
|
||||
// it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
|
||||
if ( modifiers & controlKey && keyval >= 0 && keyval < 0x20 )
|
||||
{
|
||||
keyval += 0x40 ;
|
||||
}
|
||||
if ( focus )
|
||||
{
|
||||
wxKeyEvent event(wxEVT_KEY_UP);
|
||||
event.m_shiftDown = modifiers & shiftKey;
|
||||
event.m_controlDown = modifiers & controlKey;
|
||||
event.m_altDown = modifiers & optionKey;
|
||||
event.m_metaDown = modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
|
||||
event.m_x = wherex;
|
||||
event.m_y = wherey;
|
||||
event.m_timeStamp = when;
|
||||
event.SetEventObject(focus);
|
||||
handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
}
|
||||
return handled ;
|
||||
}
|
||||
void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
|
||||
{
|
||||
EventRecord* ev = (EventRecord*) evr ;
|
||||
|
@ -1031,7 +1031,7 @@ bool wxApp::OnInit()
|
||||
if ( ! wxAppBase::OnInit() )
|
||||
return FALSE ;
|
||||
|
||||
#if TARGET_CARBON
|
||||
#if 0 // TARGET_CARBON
|
||||
static const EventTypeSpec eventList[] =
|
||||
{
|
||||
{ kEventClassKeyboard, kEventRawKeyDown } ,
|
||||
@ -1726,26 +1726,39 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
short keychar ;
|
||||
keychar = short(ev->message & charCodeMask);
|
||||
keycode = short(ev->message & keyCodeMask) >> 8 ;
|
||||
// it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
|
||||
if ( ev->modifiers & controlKey && keychar >= 0 && keychar < 0x20 )
|
||||
{
|
||||
keychar += 0x40 ;
|
||||
}
|
||||
long keyval = wxMacTranslateKey(keychar, keycode) ;
|
||||
bool handled = false ;
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
if ( focus )
|
||||
{
|
||||
|
||||
if ( MacSendKeyDownEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false )
|
||||
{
|
||||
// has not been handled -> perform default
|
||||
wxControl* control = wxDynamicCast( focus , wxControl ) ;
|
||||
if ( control && control->GetMacControl() != NULL )
|
||||
{
|
||||
::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey )
|
||||
{
|
||||
bool handled = false ;
|
||||
// it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
|
||||
if ( modifiers & controlKey && keyval >= 0 && keyval < 0x20 )
|
||||
{
|
||||
keyval += 0x40 ;
|
||||
}
|
||||
wxKeyEvent event(wxEVT_KEY_DOWN);
|
||||
event.m_shiftDown = ev->modifiers & shiftKey;
|
||||
event.m_controlDown = ev->modifiers & controlKey;
|
||||
event.m_altDown = ev->modifiers & optionKey;
|
||||
event.m_metaDown = ev->modifiers & cmdKey;
|
||||
event.m_shiftDown = modifiers & shiftKey;
|
||||
event.m_controlDown = modifiers & controlKey;
|
||||
event.m_altDown = modifiers & optionKey;
|
||||
event.m_metaDown = modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
event.m_x = ev->where.h;
|
||||
event.m_y = ev->where.v;
|
||||
event.m_timeStamp = ev->when;
|
||||
|
||||
event.m_x = wherex;
|
||||
event.m_y = wherey;
|
||||
event.m_timeStamp = when;
|
||||
event.SetEventObject(focus);
|
||||
handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
if ( handled && event.GetSkipped() )
|
||||
@ -1774,16 +1787,9 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
}
|
||||
if (!handled)
|
||||
{
|
||||
wxKeyEvent event(wxEVT_CHAR);
|
||||
event.m_shiftDown = ev->modifiers & shiftKey;
|
||||
event.m_controlDown = ev->modifiers & controlKey;
|
||||
event.m_altDown = ev->modifiers & optionKey;
|
||||
event.m_metaDown = ev->modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
event.m_x = ev->where.h;
|
||||
event.m_y = ev->where.v;
|
||||
event.m_timeStamp = ev->when;
|
||||
event.SetEventObject(focus);
|
||||
event.Skip( FALSE ) ;
|
||||
event.SetEventType( wxEVT_CHAR ) ;
|
||||
|
||||
handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
if ( handled && event.GetSkipped() )
|
||||
handled = false ;
|
||||
@ -1810,12 +1816,12 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
if ( handled && new_event.GetSkipped() )
|
||||
handled = false ;
|
||||
}
|
||||
}
|
||||
if ( !handled )
|
||||
// backdoor handler for default return and command escape
|
||||
if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
|
||||
{
|
||||
// if window is not having a focus still testing for default enter or cancel
|
||||
// TODO add the UMA version for ActiveNonFloatingWindow
|
||||
focus = wxFindWinFromMacWindow( FrontWindow() ) ;
|
||||
wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
|
||||
if ( focus )
|
||||
{
|
||||
if ( keyval == WXK_RETURN )
|
||||
@ -1827,11 +1833,11 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
|
||||
event.SetEventObject(def);
|
||||
def->Command(event);
|
||||
return ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
/* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
|
||||
else if (keyval == WXK_ESCAPE || (keyval == '.' && ev->modifiers & cmdKey ) )
|
||||
else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
|
||||
{
|
||||
wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
|
||||
new_event.SetEventObject( focus );
|
||||
@ -1839,8 +1845,9 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
|
||||
}
|
||||
}
|
||||
}
|
||||
return handled ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
|
||||
{
|
||||
@ -1857,27 +1864,39 @@ void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
|
||||
short keychar ;
|
||||
keychar = short(ev->message & charCodeMask);
|
||||
keycode = short(ev->message & keyCodeMask) >> 8 ;
|
||||
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
if ( focus )
|
||||
{
|
||||
long keyval = wxMacTranslateKey(keychar, keycode) ;
|
||||
|
||||
wxKeyEvent event(wxEVT_KEY_UP);
|
||||
event.m_shiftDown = ev->modifiers & shiftKey;
|
||||
event.m_controlDown = ev->modifiers & controlKey;
|
||||
event.m_altDown = ev->modifiers & optionKey;
|
||||
event.m_metaDown = ev->modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
event.m_x = ev->where.h;
|
||||
event.m_y = ev->where.v;
|
||||
event.m_timeStamp = ev->when;
|
||||
event.SetEventObject(focus);
|
||||
bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
}
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
bool handled = MacSendKeyUpEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
|
||||
// we don't have to do anything under classic here
|
||||
}
|
||||
}
|
||||
|
||||
bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey )
|
||||
{
|
||||
bool handled = false ;
|
||||
// it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
|
||||
if ( modifiers & controlKey && keyval >= 0 && keyval < 0x20 )
|
||||
{
|
||||
keyval += 0x40 ;
|
||||
}
|
||||
if ( focus )
|
||||
{
|
||||
wxKeyEvent event(wxEVT_KEY_UP);
|
||||
event.m_shiftDown = modifiers & shiftKey;
|
||||
event.m_controlDown = modifiers & controlKey;
|
||||
event.m_altDown = modifiers & optionKey;
|
||||
event.m_metaDown = modifiers & cmdKey;
|
||||
event.m_keyCode = keyval;
|
||||
|
||||
event.m_x = wherex;
|
||||
event.m_y = wherey;
|
||||
event.m_timeStamp = when;
|
||||
event.SetEventObject(focus);
|
||||
handled = focus->GetEventHandler()->ProcessEvent( event ) ;
|
||||
}
|
||||
return handled ;
|
||||
}
|
||||
void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
|
||||
{
|
||||
EventRecord* ev = (EventRecord*) evr ;
|
||||
|
@ -234,6 +234,8 @@ void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
|
||||
|
||||
EventHandlerUPP wxMacWindowEventHandlerUPP = NULL ;
|
||||
|
||||
extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
|
||||
|
||||
pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
|
||||
{
|
||||
OSStatus result = eventNotHandledErr ;
|
||||
@ -243,9 +245,19 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef
|
||||
case kEventClassTextInput :
|
||||
if ( wxMacConvertEventToRecord( event , &rec ) )
|
||||
{
|
||||
wxTheApp->MacHandleOneEvent( &rec ) ;
|
||||
short keycode ;
|
||||
short keychar ;
|
||||
keychar = short(rec.message & charCodeMask);
|
||||
keycode = short(rec.message & keyCodeMask) >> 8 ;
|
||||
long keyval = wxMacTranslateKey(keychar, keycode) ;
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
|
||||
if ( wxTheApp->MacSendKeyDownEvent( focus , keyval , rec.modifiers , rec.when , rec.where.h , rec.where.v ) )
|
||||
{
|
||||
// was handled internally
|
||||
result = noErr ;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
|
@ -234,6 +234,8 @@ void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
|
||||
|
||||
EventHandlerUPP wxMacWindowEventHandlerUPP = NULL ;
|
||||
|
||||
extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
|
||||
|
||||
pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
|
||||
{
|
||||
OSStatus result = eventNotHandledErr ;
|
||||
@ -243,9 +245,19 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef
|
||||
case kEventClassTextInput :
|
||||
if ( wxMacConvertEventToRecord( event , &rec ) )
|
||||
{
|
||||
wxTheApp->MacHandleOneEvent( &rec ) ;
|
||||
short keycode ;
|
||||
short keychar ;
|
||||
keychar = short(rec.message & charCodeMask);
|
||||
keycode = short(rec.message & keyCodeMask) >> 8 ;
|
||||
long keyval = wxMacTranslateKey(keychar, keycode) ;
|
||||
wxWindow* focus = wxWindow::FindFocus() ;
|
||||
|
||||
if ( wxTheApp->MacSendKeyDownEvent( focus , keyval , rec.modifiers , rec.when , rec.where.h , rec.where.v ) )
|
||||
{
|
||||
// was handled internally
|
||||
result = noErr ;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
|
Loading…
Reference in New Issue
Block a user