4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage sun.lwawt.macosx;
4632N/A
4632N/Aimport java.awt.*;
4873N/Aimport java.awt.peer.MenuItemPeer;
4632N/Aimport java.awt.peer.MenuPeer;
4632N/A
4632N/Apublic class CMenu extends CMenuItem implements MenuPeer {
4873N/A
4632N/A public CMenu(Menu target) {
4632N/A super(target);
4632N/A }
4632N/A
4632N/A // This way we avoiding invocation of the setters twice
4632N/A @Override
4632N/A protected void initialize(MenuItem target) {
4632N/A setLabel(target.getLabel());
4632N/A setEnabled(target.isEnabled());
4632N/A }
4632N/A
4632N/A @Override
4873N/A public final void setEnabled(final boolean b) {
4873N/A super.setEnabled(b);
4873N/A final Menu target = (Menu) getTarget();
4873N/A final int count = target.getItemCount();
4873N/A for (int i = 0; i < count; ++i) {
4873N/A MenuItem item = target.getItem(i);
4873N/A MenuItemPeer p = (MenuItemPeer) LWCToolkit.targetToPeer(item);
4873N/A if (p != null) {
4873N/A p.setEnabled(b && item.isEnabled());
4873N/A }
4873N/A }
4873N/A }
4873N/A
4873N/A @Override
4632N/A protected long createModel() {
4632N/A CMenuComponent parent = (CMenuComponent)
4632N/A LWCToolkit.targetToPeer(getTarget().getParent());
4632N/A
4632N/A if (parent instanceof CMenu ||
4632N/A parent instanceof CPopupMenu)
4632N/A {
4632N/A return nativeCreateSubMenu(parent.getModel());
4632N/A } else if (parent instanceof CMenuBar) {
4632N/A MenuBar parentContainer = (MenuBar)getTarget().getParent();
4632N/A boolean isHelpMenu = parentContainer.getHelpMenu() == getTarget();
4632N/A int insertionLocation = ((CMenuBar)parent).getNextInsertionIndex();
4632N/A return nativeCreateMenu(parent.getModel(),
4632N/A isHelpMenu, insertionLocation);
4632N/A } else {
4632N/A throw new InternalError("Parent must be CMenu or CMenuBar");
4632N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void addItem(MenuItem item) {
4632N/A // Nothing to do here -- we added it when we created the
4632N/A // menu item's peer.
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void delItem(int index) {
4632N/A nativeDeleteItem(getModel(), index);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setLabel(String label) {
4632N/A nativeSetMenuTitle(getModel(), label);
4632N/A super.setLabel(label);
4632N/A }
4632N/A
4632N/A // Note that addSeparator is never called directly from java.awt.Menu,
4632N/A // though it is required in the MenuPeer interface.
4632N/A @Override
4632N/A public void addSeparator() {
4632N/A nativeAddSeparator(getModel());
4632N/A }
4632N/A
4632N/A // Used by ScreenMenuBar to get to the native menu for event handling.
4632N/A public long getNativeMenu() {
4632N/A return nativeGetNSMenu(getModel());
4632N/A }
4632N/A
4632N/A private native long nativeCreateMenu(long parentMenuPtr,
4632N/A boolean isHelpMenu,
4632N/A int insertionLocation);
4632N/A private native long nativeCreateSubMenu(long parentMenuPtr);
4632N/A private native void nativeSetMenuTitle(long menuPtr, String title);
4632N/A private native void nativeAddSeparator(long menuPtr);
4632N/A private native void nativeDeleteItem(long menuPtr, int index);
4632N/A
4632N/A // Returns a retained NSMenu object! We have to explicitly
4632N/A // release at some point!
4632N/A private native long nativeGetNSMenu(long menuPtr);
4632N/A}