+static ibool MGLAPI wxWindowKeybHandler(window_t *wnd, event_t *e)
+{
+ wxWindowMGL *win = (wxWindowMGL*)MGL_wmGetWindowUserData(wnd);
+
+ if ( !win->IsEnabled() ) return FALSE;
+
+ wxPoint where;
+ MGL_wmCoordGlobalToLocal(win->GetHandle(),
+ e->where_x, e->where_y, &where.x, &where.y);
+
+ wxKeyEvent event;
+ event.SetEventObject(win);
+ event.SetTimestamp(e->when);
+ event.m_keyCode = wxScanToKeyCode(e, TRUE);
+ event.m_scanCode = 0; // not used by wx at all
+ event.m_x = where.x;
+ event.m_y = where.y;
+ event.m_shiftDown = e->modifiers & EVT_SHIFTKEY;
+ event.m_controlDown = e->modifiers & EVT_CTRLSTATE;
+ event.m_altDown = e->modifiers & EVT_LEFTALT;
+ event.m_metaDown = e->modifiers & EVT_RIGHTALT;
+
+ if ( e->what == EVT_KEYUP )
+ {
+ event.SetEventType(wxEVT_KEY_UP);
+ return win->GetEventHandler()->ProcessEvent(event);
+ }
+ else
+ {
+ bool ret;
+ wxKeyEvent event2;
+
+ event.SetEventType(wxEVT_KEY_DOWN);
+ event2 = event;
+
+ ret = win->GetEventHandler()->ProcessEvent(event);
+
+
+#ifdef __WXDEBUG__
+ // Add an easy way to capture screenshots:
+ if ( event.m_keyCode == WXK_F1 &&
+ event.m_shiftDown && event.m_controlDown )
+ CaptureScreenshot();
+#endif
+
+#if wxUSE_ACCEL
+ if ( !ret )
+ {
+ for (wxWindowMGL *w = win; w; w = w->GetParent())
+ {
+ int command = w->GetAcceleratorTable()->GetCommand(event);
+ if ( command != -1 )
+ {
+ wxCommandEvent eventc(wxEVT_COMMAND_MENU_SELECTED, command);
+ ret = w->GetEventHandler()->ProcessEvent(eventc);
+ break;
+ }
+ if ( w->IsTopLevel() )
+ break;
+ }
+ }
+#endif // wxUSE_ACCEL
+
+ // wxMSW doesn't send char events with Alt pressed
+ // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
+ // will only be sent if it is not in an accelerator table.
+ event2.m_keyCode = wxScanToKeyCode(e, FALSE);
+ if ( !ret && event2.m_keyCode != 0 )
+ {
+ event2.SetEventType(wxEVT_CHAR);
+ ret = win->GetEventHandler()->ProcessEvent(event2);
+ }
+
+ // Synthetize navigation key event, but do it only if the TAB key
+ // wasn't handled yet.
+ if ( !ret && event.m_keyCode == WXK_TAB &&
+ win->GetParent() && win->GetParent()->HasFlag(wxTAB_TRAVERSAL) )
+ {
+ wxNavigationKeyEvent navEvent;
+ navEvent.SetEventObject(win->GetParent());
+ // Shift-TAB goes in reverse direction:
+ navEvent.SetDirection(!event.m_shiftDown);
+ // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
+ navEvent.SetWindowChange(event.m_controlDown);
+ navEvent.SetCurrentFocus(wxStaticCast(win, wxWindow));
+ ret = win->GetParent()->GetEventHandler()->ProcessEvent(navEvent);
+ }
+
+ return ret;
+ }
+}