summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Northover <steve>2002-12-07 01:27:24 +0000
committerSteve Northover <steve>2002-12-07 01:27:24 +0000
commit70da199786c4d7e70af41fd8ac5342b8e07a51aa (patch)
treedd95a52df4004d71458643cb62080af88411f636
parent4c353897941995ea06af97abf6874674f15f5378 (diff)
downloadeclipse.platform.swt-70da199786c4d7e70af41fd8ac5342b8e07a51aa.tar.gz
eclipse.platform.swt-70da199786c4d7e70af41fd8ac5342b8e07a51aa.tar.xz
eclipse.platform.swt-70da199786c4d7e70af41fd8ac5342b8e07a51aa.zip
*** empty log message ***
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java74
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java29
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java21
5 files changed, 97 insertions, 38 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java
index 91590333bc..5fe339e3ff 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java
@@ -159,9 +159,8 @@ public void setMenuBar (Menu menu) {
if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
}
menuBar = menu;
- //NOT DONE
Display display = getDisplay ();
-// display.setMenuBar (menuBar);
+ display.updateMenuBar ();
}
public void setMinimized (boolean minimized) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
index 9301baf7ff..34f2981da8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
@@ -70,7 +70,8 @@ public class Display extends Device {
Menu menuBar;
Menu [] menus, popups;
MenuItem [] items;
- static final int ID_START = 1000;
+ static final int ID_TEMPORARY = 1000;
+ static final int ID_START = 1001;
/* Insets */
Rect buttonInset, tabFolderInset, comboInset;
@@ -870,15 +871,7 @@ int mouseProc (int nextHandler, int theEvent, int userData) {
switch (part) {
case OS.inMenuBar: {
if (eventKind == OS.kEventMouseDown) {
- //WRONG - doesn't work for nested modal windows and modal windows with menu bars
- boolean modal = false;
- int activeWindow = OS.ActiveNonFloatingWindow ();
- if (activeWindow != 0) {
- int [] outModalityKind = new int [1], outUnavailableWindow = new int [1];
- OS.GetWindowModality (activeWindow, outModalityKind, outUnavailableWindow);
- modal = outModalityKind [0] != OS.kWindowModalityNone;
- }
- if (!modal) OS.MenuSelect (where);
+ OS.MenuSelect (where);
return OS.noErr;
}
break;
@@ -1336,10 +1329,29 @@ public void setSynchronizer (Synchronizer synchronizer) {
}
void setMenuBar (Menu menu) {
+ /*
+ * Feature in the Macintosh. SetRootMenu() does not
+ * accept NULL to indicate that their should be no
+ * menu bar. The fix is to create a temporary empty
+ * menu, set that to be the menu bar, clear the menu
+ * bar and then delete the temporary menu.
+ */
+ if (menu == menuBar) return;
+ int theMenu = 0;
+ if (menu == null) {
+ int outMenuRef [] = new int [1];
+ OS.CreateNewMenu ((short) ID_TEMPORARY, 0, outMenuRef);
+ theMenu = outMenuRef [0];
+ } else {
+ theMenu = menu.handle;
+ }
+ OS.SetRootMenu (theMenu);
+ if (menu == null) {
+ OS.ClearMenuBar ();
+ OS.DeleteMenu (OS.GetMenuID (theMenu));
+ OS.DisposeMenu (theMenu);
+ }
menuBar = menu;
- //NOT DONE
- int inMenu = menuBar != null ? menu.handle : 0;
- OS.SetRootMenu (inMenu);
}
public boolean sleep () {
@@ -1424,6 +1436,42 @@ public void update () {
}
}
+void updateMenuBar () {
+ updateMenuBar (getActiveShell ());
+}
+
+void updateMenuBar (Shell shell) {
+ if (shell == null) shell = getActiveShell ();
+ boolean modal = false;
+ int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
+ while (shell != null) {
+ if (shell.menuBar != null) break;
+ if ((shell.style & mask) != 0) modal = true;
+ shell = (Shell) shell.parent;
+ }
+ /*
+ * Feature in the Macintosh. For some reason, when a modal shell
+ * is active, DisableMenuItem() when called with zero (indicating
+ * that the entire menu is to be disabled) will not disable the
+ * current menu bar. The fix is to disable each individual menu
+ * item.
+ */
+ Menu menu = null;
+ if (menuBar != null) {
+ int theMenu = menuBar.handle;
+ MenuItem [] items = menuBar.getItems ();
+ for (int i=0; i<items.length; i++) {
+ if (items [i].getEnabled ()) items [i]._setEnabled (true);
+ }
+ }
+ setMenuBar (shell != null ? shell.menuBar : null);
+ if (menuBar != null && modal) {
+ int theMenu = menuBar.handle;
+ MenuItem [] items = menuBar.getItems ();
+ for (int i=0; i<items.length; i++) items [i]._setEnabled (false);
+ }
+}
+
public void wake () {
if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
if (thread == Thread.currentThread ()) return;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java
index 424f647813..396e1dd8ef 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java
@@ -159,8 +159,8 @@ public Display getDisplay () {
}
public boolean getEnabled () {
- checkWidget ();
- return OS.IsMenuItemEnabled (handle, (short)0);
+ checkWidget();
+ return (state & DISABLED) == 0;
}
public MenuItem getItem (int index) {
@@ -332,10 +332,12 @@ public void setDefaultItem (MenuItem item) {
}
public void setEnabled (boolean enabled) {
- checkWidget ();
+ checkWidget();
if (enabled) {
+ state &= ~DISABLED;
OS.EnableMenuItem (handle, (short)0);
} else {
+ state |= DISABLED;
OS.DisableMenuItem (handle, (short)0);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java
index 72e30b296e..1bfba74015 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java
@@ -28,6 +28,20 @@ public MenuItem (Menu parent, int style, int index) {
parent.createItem (this, index);
}
+public void _setEnabled (boolean enabled) {
+ short [] outIndex = new short [1];
+ OS.GetIndMenuItemWithCommandID (parent.handle, id, 1, null, outIndex);
+ int outMenuRef [] = new int [1];
+ OS.GetMenuItemHierarchicalMenu (parent.handle, outIndex [0], outMenuRef);
+ if (enabled) {
+ if (outMenuRef [0] != 0) OS.EnableMenuItem (outMenuRef [0], (short) 0);
+ OS.EnableMenuCommand (parent.handle, id);
+ } else {
+ if (outMenuRef [0] != 0) OS.DisableMenuItem (outMenuRef [0], (short) 0);
+ OS.DisableMenuCommand (parent.handle, id);
+ }
+}
+
public void addArmListener (ArmListener listener) {
checkWidget ();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
@@ -70,8 +84,8 @@ public Display getDisplay () {
}
public boolean getEnabled () {
- checkWidget ();
- return OS.IsMenuCommandEnabled (parent.handle, id);
+ checkWidget();
+ return (state & DISABLED) == 0;
}
public Menu getMenu () {
@@ -260,17 +274,12 @@ public void setAccelerator (int accelerator) {
public void setEnabled (boolean enabled) {
checkWidget ();
- short [] outIndex = new short [1];
- OS.GetIndMenuItemWithCommandID (parent.handle, id, 1, null, outIndex);
- int outMenuRef [] = new int [1];
- OS.GetMenuItemHierarchicalMenu (parent.handle, outIndex [0], outMenuRef);
if (enabled) {
- if (outMenuRef [0] != 0) OS.EnableMenuItem (outMenuRef [0], (short) 0);
- OS.EnableMenuCommand (parent.handle, id);
+ state &= ~DISABLED;
} else {
- if (outMenuRef [0] != 0) OS.DisableMenuItem (outMenuRef [0], (short) 0);
- OS.DisableMenuCommand (parent.handle, id);
+ state |= DISABLED;
}
+ _setEnabled (enabled);
}
public void setImage (Image image) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java
index adc2cc49ea..7be4e2acec 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java
@@ -317,9 +317,8 @@ public boolean isVisible () {
int kEventWindowActivated (int nextHandler, int theEvent, int userData) {
int result = super.kEventWindowActivated (nextHandler, theEvent, userData);
if (result == OS.noErr) return result;
- //NOT DONE
Display display = getDisplay ();
- display.setMenuBar (menuBar);
+ display.updateMenuBar (this);
sendEvent (SWT.Activate);
restoreFocus ();
return result;
@@ -372,6 +371,8 @@ int kEventWindowDeactivated (int nextHandler, int theEvent, int userData) {
display.ignoreFocus = false;
savedFocus.sendFocusEvent (false);
}
+ Display display = getDisplay ();
+ display.updateMenuBar (null);
return result;
}
@@ -580,14 +581,14 @@ void setWindowVisible (boolean visible) {
}
sendEvent (SWT.Show);
if (isDisposed ()) return;
- int inputMode = OS.kWindowModalityNone;
- if ((style & SWT.PRIMARY_MODAL) != 0) inputMode = OS.kWindowModalityWindowModal;
- if ((style & SWT.APPLICATION_MODAL) != 0) inputMode = OS.kWindowModalityAppModal;
- if ((style & SWT.SYSTEM_MODAL) != 0) inputMode = OS.kWindowModalitySystemModal;
- if (inputMode != OS.kWindowModalityNone) {
- int parentHandle = 0;
- if (parent != null) parentHandle = parent.getShell ().shellHandle;
- OS.SetWindowModality (shellHandle, inputMode, parentHandle);
+ int inModalKind = OS.kWindowModalityNone;
+ if ((style & SWT.PRIMARY_MODAL) != 0) inModalKind = OS.kWindowModalityWindowModal;
+ if ((style & SWT.APPLICATION_MODAL) != 0) inModalKind = OS.kWindowModalityAppModal;
+ if ((style & SWT.SYSTEM_MODAL) != 0) inModalKind = OS.kWindowModalitySystemModal;
+ if (inModalKind != OS.kWindowModalityNone) {
+ int inUnavailableWindow = 0;
+ if (parent != null) inUnavailableWindow = OS.GetControlOwner (parent.handle);
+ OS.SetWindowModality (shellHandle, inModalKind, inUnavailableWindow);
}
OS.ShowWindow (shellHandle);
} else {