+ /**
+ * Dispatch one event to the appropriate widget or application-level
+ * event handler.
+ *
+ * @param event the input event to consume
+ */
+ private final void handleEvent(TInputEvent event) {
+
+ /*
+ // std.stdio.stderr.writefln("Handle event: %s", event);
+
+ // Special application-wide events -----------------------------------
+
+ // Peek at the mouse position
+ if (auto mouse = cast(TMouseEvent)event) {
+ // See if we need to switch focus to another window or the menu
+ checkSwitchFocus(mouse);
+ }
+
+ // Handle menu events
+ if ((activeMenu !is null) && (!cast(TCommandEvent)event)) {
+ TMenu menu = activeMenu;
+ if (auto mouse = cast(TMouseEvent)event) {
+
+ while (subMenus.length > 0) {
+ TMenu subMenu = subMenus[$ - 1];
+ if (subMenu.mouseWouldHit(mouse)) {
+ break;
+ }
+ if ((mouse.type == TMouseEvent.Type.MOUSE_MOTION) &&
+ (!mouse.mouse1) &&
+ (!mouse.mouse2) &&
+ (!mouse.mouse3) &&
+ (!mouse.mouseWheelUp) &&
+ (!mouse.mouseWheelDown)
+ ) {
+ break;
+ }
+ // We navigated away from a sub-menu, so close it
+ closeSubMenu();
+ }
+
+ // Convert the mouse relative x/y to menu coordinates
+ assert(mouse.x == mouse.absoluteX);
+ assert(mouse.y == mouse.absoluteY);
+ if (subMenus.length > 0) {
+ menu = subMenus[$ - 1];
+ }
+ mouse.x -= menu.x;
+ mouse.y -= menu.y;
+ }
+ menu.handleEvent(event);
+ return;
+ }
+
+ if (auto keypress = cast(TKeypressEvent)event) {
+ // See if this key matches an accelerator, and if so dispatch the
+ // menu event.
+ TKeypress keypressLowercase = toLower(keypress.key);
+ TMenuItem *item = (keypressLowercase in accelerators);
+ if (item !is null) {
+ // Let the menu item dispatch
+ item.dispatch();
+ return;
+ } else {
+ // Handle the keypress
+ if (onKeypress(keypress)) {
+ return;
+ }
+ }
+ }
+
+ if (auto cmd = cast(TCommandEvent)event) {
+ if (onCommand(cmd)) {
+ return;
+ }
+ }
+
+ if (auto menu = cast(TMenuEvent)event) {
+ if (onMenu(menu)) {
+ return;
+ }
+ }
+ */
+
+ // Dispatch events to the active window -------------------------------
+ for (TWindow window: windows) {
+ if (window.active) {
+ if (event instanceof TMouseEvent) {
+ TMouseEvent mouse = (TMouseEvent) event;
+ // Convert the mouse relative x/y to window coordinates
+ assert (mouse.getX() == mouse.getAbsoluteX());
+ assert (mouse.getY() == mouse.getAbsoluteY());
+ mouse.setX(mouse.getX() - window.x);
+ mouse.setY(mouse.getY() - window.y);
+ }
+ // System.err("TApplication dispatch event: %s\n", event);
+ window.handleEvent(event);
+ break;
+ }
+ }
+ }
+