7124537: [macosx] Menu shortcuts for all menu items should be disabled if a menu itself is disabled

Reviewed-by: anthony, leonidr
This commit is contained in:
Sergey Bylokhov 2013-09-12 18:21:06 +04:00
parent fcb6d58798
commit d8c5dcc1fc
3 changed files with 34 additions and 5 deletions

View File

@ -26,9 +26,11 @@
package sun.lwawt.macosx;
import java.awt.*;
import java.awt.peer.MenuItemPeer;
import java.awt.peer.MenuPeer;
public class CMenu extends CMenuItem implements MenuPeer {
public CMenu(Menu target) {
super(target);
}
@ -40,6 +42,20 @@ public class CMenu extends CMenuItem implements MenuPeer {
setEnabled(target.isEnabled());
}
@Override
public final void setEnabled(final boolean b) {
super.setEnabled(b);
final Menu target = (Menu) getTarget();
final int count = target.getItemCount();
for (int i = 0; i < count; ++i) {
MenuItem item = target.getItem(i);
MenuItemPeer p = (MenuItemPeer) LWCToolkit.targetToPeer(item);
if (p != null) {
p.setEnabled(b && item.isEnabled());
}
}
}
@Override
protected long createModel() {
CMenuComponent parent = (CMenuComponent)

View File

@ -28,17 +28,20 @@ package sun.lwawt.macosx;
import sun.awt.SunToolkit;
import sun.lwawt.LWToolkit;
import java.awt.MenuContainer;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.*;
import java.awt.peer.MenuItemPeer;
import java.util.concurrent.atomic.AtomicBoolean;
public class CMenuItem extends CMenuComponent implements MenuItemPeer {
private final AtomicBoolean enabled = new AtomicBoolean(true);
public CMenuItem(MenuItem target) {
super(target);
initialize(target);
}
// This way we avoiding invocation of the setters twice
@ -124,9 +127,19 @@ public class CMenuItem extends CMenuComponent implements MenuItemPeer {
setEnabled(false);
}
public final boolean isEnabled() {
return enabled.get();
}
@Override
public void setEnabled(boolean b) {
nativeSetEnabled(getModel(), b);
final Object parent = LWToolkit.targetToPeer(getTarget().getParent());
if (parent instanceof CMenuItem) {
b &= ((CMenuItem) parent).isEnabled();
}
if (enabled.compareAndSet(!b, b)) {
nativeSetEnabled(getModel(), b);
}
}
private native long nativeCreate(long parentMenu, boolean isSeparator);

View File

@ -207,9 +207,9 @@ public final class LWCToolkit extends LWToolkit {
@Override
public MenuBarPeer createMenuBar(MenuBar target) {
MenuBarPeer peer = new CMenuBar(target);
targetCreatedPeer(target, peer);
return peer;
MenuBarPeer peer = new CMenuBar(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override