-
- switch (key) {
- case 0x7e:
- case 0x3e:
- key = WXK_UP;
- break;
- case 0x7d:
- case 0x3d:
- key = WXK_DOWN;
- break;
- case 0x7b:
- case 0x3b:
- key = WXK_LEFT;
- break;
- case 0x7c:
- case 0x3c:
- key = WXK_RIGHT;
- break;
- case 0x24:
- case 0x4c:
- key = WXK_RETURN;
- break;
- case 0x30:
- key = WXK_TAB;
- break;
- case 0x33:
- key = WXK_BACK;
- break;
- case 0x75:
- key = WXK_DELETE;
- break;
- case 0x73:
- key = WXK_HOME;
- break;
- case 0x77:
- key = WXK_END;
- break;
- case 0x74:
- key = WXK_PAGEUP;
- break;
- case 0x79:
- key = WXK_PAGEDOWN;
- break;
- default:
- if (!transH) {
- transH = GetIndResource('KCHR', 1);
- HNoPurge(transH);
- }
-#if 0 //Tom replaces
- if (transH) {
- // Only let shift & option modify the key:
- HLock(transH);
- key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
- HUnlock(transH);
-#else
- if (0) { // tom fettig@dfki.uni-sb.de
- // why if(0):
- // code is not correct, see inside Macintosh: Text 1-87
- // and 'itlk'-resource!!
- // and it is not necessary, as the translated char is in
- // cCurrrentEvent.message!!
- // Only let shift & option modify the key:
- HLock(transH);
- key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
- HUnlock(transH);
-#endif
- }
- } // end switch
-
- return key;
+ long keyval = wxMacTranslateKey(keychar, keycode) ;
+ long realkeyval = keyval ;
+ if ( keyval == keychar )
+ {
+ // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first)
+ realkeyval = short(keymessage & charCodeMask) ;
+ keyval = wxToupper( keyval ) ;
+ }
+
+ wxKeyEvent event(wxEVT_KEY_DOWN);
+ bool handled = false ;
+ 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 ) ;
+ if ( handled && event.GetSkipped() )
+ handled = false ;
+ if ( !handled )
+ {
+#if wxUSE_ACCEL
+ if (!handled)
+ {
+ wxWindow *ancestor = focus;
+ while (ancestor)
+ {
+ int command = ancestor->GetAcceleratorTable()->GetCommand( event );
+ if (command != -1)
+ {
+ wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
+ handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
+ break;
+ }
+ if (ancestor->IsTopLevel())
+ break;
+ ancestor = ancestor->GetParent();
+ }
+ }
+#endif // wxUSE_ACCEL
+ }
+ if (!handled)
+ {
+ event.Skip( FALSE ) ;
+ event.SetEventType( wxEVT_CHAR ) ;
+ // raw value again
+ event.m_keyCode = realkeyval ;
+
+ handled = focus->GetEventHandler()->ProcessEvent( event ) ;
+ if ( handled && event.GetSkipped() )
+ handled = false ;
+ }
+ if ( !handled && (keyval == WXK_TAB) )
+ {
+ wxWindow* iter = focus->GetParent() ;
+ while( iter && !handled )
+ {
+ if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
+ {
+ wxNavigationKeyEvent new_event;
+ new_event.SetEventObject( focus );
+ new_event.SetDirection( !event.ShiftDown() );
+ /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
+ new_event.SetWindowChange( event.ControlDown() );
+ new_event.SetCurrentFocus( focus );
+ handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
+ if ( handled && new_event.GetSkipped() )
+ handled = false ;
+ }
+ iter = iter->GetParent() ;
+ }
+ }
+ // 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
+ wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
+ if ( focus )
+ {
+ if ( keyval == WXK_RETURN )
+ {
+ wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
+ wxButton);
+ if ( def && def->IsEnabled() )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
+ event.SetEventObject(def);
+ def->Command(event);
+ return true ;
+ }
+ }
+ /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
+ else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
+ {
+ wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
+ new_event.SetEventObject( focus );
+ handled = focus->GetEventHandler()->ProcessEvent( new_event );
+ }
+ }
+ }
+ return handled ;