#2015 Bug with Window.menuBar and Widget.onKeyDown?

mike Wed 29 Aug 2012

I have discovered that if I add an onKeyDown event anywhere in an Fwt application, then it doesn't work when I try to use the Alt key to bring up items from the application's menuBar.

For instance, in the following app, if I press Alt+F, then the File menu should pop up on the menu bar, and if I press Alt+M, then the Misc menu should pop up.

However, this only works if I comment out the line that adds an onKeyDown event to the Label. It seems like any onKeyDown event on any child widget of the main Window causes this problem.

Is this really a bug or am I doing something wrong? I'm running Windows as my OS if that makes any difference.

using gfx
using fwt

class MenuBug
{
  Void main()
  {
    Window
    {
      it.title = "Menu Bug"
      it.size = Size(300, 100)
      it.menuBar = Menu
      {
        Menu
        {
          text = "File";
          MenuItem { text = "Exit"; onAction.add |->| { Env.cur.exit(0) } },
        },
        Menu
        {
          text = "Misc";
          MenuItem { text = "Foo"; onAction.add |->| { echo("Foo") } },
          MenuItem { text = "Bar"; onAction.add |->| { echo("Bar") } },
        },
      }

      label := Label() { text = "This is a Label." }

      // commenting out this line makes the problem go away
      label.onKeyDown.add |event| { }

      it.content = label

    }.open
  }
}

andy Wed 29 Aug 2012

Not sure how SWT works - but either that even needs to be captured before it goes down widget tree. Or its always getting consumed in onKeyDown handler - and not bubbling back up. Probably need to poke around the FWT native code to debug.

mike Wed 29 Aug 2012

Yeah, I could understand if a menu didn't pop up when I consume something like Alt+F explictly in onKeyDown, in fact I would expect that behavior.

But it doesn't seem to make any difference if the event is consumed or not in the application. Apparently the mere presence of any onKeyDown or onKeyUp listener is enough to trigger the problem. Btw, none of the other Widget.onXxx listeners cause the problem

// commenting out the onKeyXxx listeners makes the problem go away
label.onBlur       .add |event| {}
label.onFocus      .add |event| {}
//label.onKeyDown    .add |event| {}
//label.onKeyUp      .add |event| {}
label.onMouseDown  .add |event| {}
label.onMouseEnter .add |event| {}
label.onMouseExit  .add |event| {}
label.onMouseHover .add |event| {}
label.onMouseMove  .add |event| {}
label.onMouseUp    .add |event| {}
label.onMouseWheel .add |event| {}

andy Wed 29 Aug 2012

I meant you might want to check WidgetPeer.java to see if something funky going on with how onKeyDown ties into SWT.

yliu Thu 30 Aug 2012

Tried this out, Alt+F,M still work for me but you have to press Alt once and let go, then you can the letter.

Something to note is also your code written as is has the Desktop.focus on the Label, so I believe the key listeners for the label will fire first, before any listeners for the Window can fire (such as the built in listener to control the menuBar. I believe listeners fire synchronously (but don't quote me)? So that could explain the delay.

Note: Tested on Windows 7

Login or Signup to reply.