summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/cocoa
diff options
context:
space:
mode:
authorKevin Barnes <krbarnes>2008-02-25 19:34:19 +0000
committerKevin Barnes <krbarnes>2008-02-25 19:34:19 +0000
commitbb7d6277c4df65eeb3d89017add0f14480095c41 (patch)
treed75b541a37f14efc4641860319442994cea4ec44 /bundles/org.eclipse.swt/Eclipse SWT/cocoa
parent0262f2043050ffa95129a1b98153a0304c364772 (diff)
downloadeclipse.platform.swt-bb7d6277c4df65eeb3d89017add0f14480095c41.tar.gz
eclipse.platform.swt-bb7d6277c4df65eeb3d89017add0f14480095c41.tar.xz
eclipse.platform.swt-bb7d6277c4df65eeb3d89017add0f14480095c41.zip
210430 - Shell.setMenuBar() does not work
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/cocoa')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java19
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java10
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java22
3 files changed, 43 insertions, 8 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
index f1d9d1e741..72a2a929da 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
@@ -2706,10 +2706,21 @@ void setMenuBar (Menu menu) {
*/
if (menu == menuBar) return;
menuBar = menu;
-// NSMenu.setMenuBarVisible(true);
-// application.setMenu(menu.nsMenu);
-// application.setWindowsMenu(menu.nsMenu);
-// application.setServicesMenu(menu.nsMenu);
+ //remove all existing menu items except the application menu
+ NSMenu menubar = application.mainMenu();
+ int count = menubar.numberOfItems();
+ while (count > 1) {
+ menubar.removeItemAtIndex(count - 1);
+ count--;
+ }
+ //set parent of each item to NULL and add them to menubar
+ if (menu != null) {
+ MenuItem[] items = menu.getItems();
+ for (int i = 0; i < items.length; i++) {
+ items[i].nsItem.setMenu(null);
+ menubar.addItem(items[i].nsItem);
+ }
+ }
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java
index c5fe0d8261..e2c44cc4ba 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java
@@ -290,6 +290,16 @@ void createItem (MenuItem item, int index) {
}
System.arraycopy (items, index, items, index + 1, itemCount++ - index);
items [index] = item;
+
+ /*
+ * Feature in Cocoa. If the NSMenuItem has NSMenu, it will not be shown in
+ * the menu bar. The fix is to create an empty menu then add it to the MenuItem.
+ */
+ if (((style & SWT.BAR) != 0) && item.getMenu () == null) {
+ Menu emptyMenu = new Menu (parent, SWT.DROP_DOWN);
+ item.setMenu (emptyMenu);
+ }
+
}
void createWidget () {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java
index 9ff8756848..79400c2eec 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java
@@ -637,6 +637,11 @@ public void setMenu (Menu menu) {
if (menu.parent != parent.parent) {
error (SWT.ERROR_INVALID_PARENT);
}
+ menu.cascade = this;
+ } else {
+ if ((parent.style & SWT.BAR) != 0) {
+ menu = new Menu (parent.parent, SWT.DROP_DOWN);
+ }
}
/* Assign the new menu */
@@ -646,8 +651,12 @@ public void setMenu (Menu menu) {
this.menu = menu;
/* Update the menu in the OS */
- ((NSMenuItem)nsItem).setSubmenu(menu.nsMenu);
-
+ NSMenuItem menuItem = (NSMenuItem) nsItem;
+ if (menu != null) menuItem.setSubmenu (menu.nsMenu);
+ else menuItem.setSubmenu (null);
+
+ /* Update menu title with parent item title */
+ updateText ();
}
boolean setRadioSelection (boolean value) {
@@ -721,7 +730,7 @@ public void setText (String string) {
if ((style & SWT.SEPARATOR) != 0) return;
if (text.equals (string)) return;
super.setText (string);
- updateText();
+ updateText ();
}
void updateText() {
@@ -736,7 +745,12 @@ void updateText() {
j--;
}
}
- ((NSMenuItem)nsItem).setTitle(NSString.stringWithCharacters(buffer, j));
+ String text = new String (buffer, 0, j);
+ if(menu != null && ((parent.getStyle () | SWT.BAR) != 0)) {
+ menu.nsMenu.setTitle (NSString.stringWith (text));
+ } else {
+ ((NSMenuItem) nsItem).setTitle (NSString.stringWith (text));
+ }
}
}