< prev index next >
src/java.desktop/macosx/classes/com/apple/eawt/_AppMenuBarHandler.java
Print this page
rev 51321 : bug fix and test
*** 44,53 ****
--- 44,54 ----
private static final int MENU_ABOUT = 1;
private static final int MENU_PREFS = 2;
private static native void nativeSetMenuState(final int menu, final boolean visible, final boolean enabled);
private static native void nativeSetDefaultMenuBar(final long menuBarPeer);
+ private static native void nativeActivateDefaultMenuBar(final long menuBarPeer);
static final _AppMenuBarHandler instance = new _AppMenuBarHandler();
static _AppMenuBarHandler getInstance() {
return instance;
}
*** 76,105 ****
boolean prefsMenuItemEnabled;
boolean prefsMenuItemExplicitlySet;
void setDefaultMenuBar(final JMenuBar menuBar) {
installDefaultMenuBar(menuBar);
- if (menuBar == null) {
- return;
}
// scan the current frames, and see if any are foreground
final Frame[] frames = Frame.getFrames();
for (final Frame frame : frames) {
if (frame.isVisible() && !isFrameMinimized(frame)) {
! return;
}
}
! // if we have no foreground frames, then we have to "kick" the menubar
! final JFrame pingFrame = new JFrame();
! pingFrame.getRootPane().putClientProperty("Window.alpha", Float.valueOf(0.0f));
! pingFrame.setUndecorated(true);
! pingFrame.setVisible(true);
! pingFrame.toFront();
! pingFrame.setVisible(false);
! pingFrame.dispose();
}
static boolean isFrameMinimized(final Frame frame) {
return (frame.getExtendedState() & Frame.ICONIFIED) != 0;
}
--- 77,98 ----
boolean prefsMenuItemEnabled;
boolean prefsMenuItemExplicitlySet;
void setDefaultMenuBar(final JMenuBar menuBar) {
installDefaultMenuBar(menuBar);
}
+ static boolean isMenuBarActivationNeeded() {
// scan the current frames, and see if any are foreground
final Frame[] frames = Frame.getFrames();
for (final Frame frame : frames) {
if (frame.isVisible() && !isFrameMinimized(frame)) {
! return false;
}
}
! return true;
}
static boolean isFrameMinimized(final Frame frame) {
return (frame.getExtendedState() & Frame.ICONIFIED) != 0;
}
*** 148,157 ****
--- 141,155 ----
throw new IllegalStateException("Unable to determine native menu bar from provided JMenuBar");
}
// grab the pointer to the CMenuBar, and retain it in native
((CMenuBar) peer).execute(_AppMenuBarHandler::nativeSetDefaultMenuBar);
+
+ // if there is no currently active frame, install the default menu bar in the application main menu
+ if (isMenuBarActivationNeeded()) {
+ ((CMenuBar) peer).execute(_AppMenuBarHandler::nativeActivateDefaultMenuBar);
+ }
}
void setAboutMenuItemVisible(final boolean present) {
synchronized (this) {
if (aboutMenuItemVisible == present) return;
< prev index next >