WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
return;
}
MenuSelectionManager msm =
MenuSelectionManager.defaultManager();
if (msm.getSelectedPath().length == 0) {
// if no menu is active, we try activating the menubar
JMenuBar mbar = root != null ? root.getJMenuBar() : null;
if(mbar == null && winAncestor instanceof JFrame) {
mbar = ((JFrame)winAncestor).getJMenuBar();
}
JMenu menu = mbar != null ? mbar.getMenu(0) : null;
// It might happen that the altRelease event is processed
// with a reasonable delay since it has been generated.
// Here we check the last deactivation time of the containing
// window. If this time appears to be greater than the altRelease
// event time the event is skipped to avoid unexpected menu
// activation. See 7121442.
// Also we must ensure that original source of key event belongs
// to the same window object as winAncestor. See 8001633.
boolean skip = false;
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
Component originalSource = AWTAccessor.getKeyEventAccessor()
.getOriginalSource(ev);
skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
}
if (menu != null && !skip) {
MenuElement[] path = new MenuElement[2];
path[0] = mbar;
path[1] = menu;
msm.setSelectedPath(path);
} else if(!WindowsLookAndFeel.isMnemonicHidden()) {
WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
} else {
if((msm.getSelectedPath())[0] instanceof ComboPopup) {
WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
}