Bug 316238-Main menu lost when using "open in new window"
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java
index 77e5faf..e59acb4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java
@@ -367,6 +367,7 @@
 	public static final int kDragTrackingLeaveWindow = 4;
 	public static final int kDragTrackingLeaveHandler = 5;
 	public static final int kEventAppleEvent = 1;
+	public static final int kEventAppDeactivated = 2;
 	public static final int kEventAppAvailableWindowBoundsChanged = 110;
 	public static final int kEventAttributeUserEvent = 1 << 0;
 	public static final int kEventClassAppleEvent = ('e'<<24) + ('p'<<16) + ('p'<<8) + 'c';
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 e67cfd0..73e66b6 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
@@ -375,6 +375,14 @@
 	switch (eventClass) {
 		case OS.kEventClassApplication: 
 			switch (eventKind) {
+				case OS.kEventAppDeactivated: {
+					Shell [] shells = getShells ();
+					for (int i = 0; i < shells.length; i++) {
+						Shell shell = shells [i];
+						if (shell.active && !shell.isDisposed ()) shell.kEventWindowDeactivated ();
+					}
+					break;
+				}
 				case OS.kEventAppAvailableWindowBoundsChanged: {
 					/* Reset the dock image in case the dock has been restarted */
 					if (dockImage != 0) {
@@ -2182,6 +2190,7 @@
 	};
 	OS.InstallEventHandler (appTarget, mouseProc, mask2.length / 2, mask2, 0, null);
 	int [] mask3 = new int[] {
+		OS.kEventClassApplication, OS.kEventAppDeactivated,
 		OS.kEventClassApplication, OS.kEventAppAvailableWindowBoundsChanged,
 		OS.kEventClassAppleEvent, OS.kEventAppleEvent,
 	};
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 f1f5d7f..b404a62 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
@@ -993,6 +993,11 @@
 	OS.GetWindowActivationScope (shellHandle, outScope); 
 	if (outScope [0] == OS.kWindowActivationScopeNone) return result;
 	if (!active) {
+		Shell[] shells = display.getShells ();
+		for (int i = 0; i < shells.length; i++) {
+			Shell shell = shells [i];
+			if (shell.active && !shell.isDisposed ()) shell.kEventWindowDeactivated ();
+		}
 		active = true;
 		deferDispose = true;
 		Display display = this.display;
@@ -1074,15 +1079,20 @@
 int kEventWindowDeactivated (int nextHandler, int theEvent, int userData) {
 	int result = super.kEventWindowDeactivated (nextHandler, theEvent, userData);
 	if (result == OS.noErr) return result;
+	kEventWindowDeactivated ();
+	return result;
+}
+
+void kEventWindowDeactivated () {
 	if (active) {
 		active = false;
 		deferDispose = true;
 		Display display = this.display;
 		display.activeShell = this;
 		sendEvent (SWT.Deactivate);
-		if (isDisposed ()) return result;
+		if (isDisposed ()) return;
 		setActiveControl (null);
-		if (isDisposed ()) return result;
+		if (isDisposed ()) return;
 		display.activeShell = null;
 		saveFocus ();
 		if (savedFocus != null) {
@@ -1100,7 +1110,6 @@
 		display.setMenuBar (null);
 		deferDispose = false;
 	}
-	return result;
 }
 
 int kEventWindowDrawContent (int nextHandler, int theEvent, int userData) {