summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Kovatch <skovatch>2011-02-17 23:07:59 +0000
committerScott Kovatch <skovatch>2011-02-17 23:07:59 +0000
commit9559d48b4912b67ace5428d33abe4c7215a1d5a0 (patch)
tree986bcd54f2d0a12992cf6a87abc3d723e36a6092
parentdd4423d6a25e296b3131820cf1f98771823ddd19 (diff)
downloadeclipse.platform.swt-9559d48b4912b67ace5428d33abe4c7215a1d5a0.tar.gz
eclipse.platform.swt-9559d48b4912b67ace5428d33abe4c7215a1d5a0.tar.xz
eclipse.platform.swt-9559d48b4912b67ace5428d33abe4c7215a1d5a0.zip
337499 - handle embedded shell moving from one window to another.
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java4
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java3
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java129
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java6
4 files changed, 92 insertions, 50 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
index 5652edf832..d1a920475d 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
@@ -1416,7 +1416,9 @@ public boolean forceFocus () {
}
boolean forceFocus (NSView focusView) {
- return view.window ().makeFirstResponder (focusView);
+ NSWindow window = view.window ();
+ if(window == null) { return false; }
+ return window.makeFirstResponder (focusView);
}
boolean gestureEvent(int /*long*/ id, int /*long*/ eventPtr, int detail) {
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 0f10788faf..bca5bab759 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
@@ -2405,6 +2405,7 @@ void initClasses () {
OS.class_addMethod(cls, OS.sel_validRequestorForSendType_returnType_, proc4, "@:@@");
OS.class_addMethod(cls, OS.sel_readSelectionFromPasteboard_, proc3, "@:@");
OS.class_addMethod(cls, OS.sel_writeSelectionToPasteboard_types_, proc4, "@:@@");
+ OS.class_addMethod(cls, OS.sel_viewWillMoveToWindow_, proc3, "@:@");
addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
@@ -5581,6 +5582,8 @@ static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ a
return (widget.validateMenuItem(id, sel, arg0) ? 1 : 0);
} else if (sel == OS.sel_readSelectionFromPasteboard_) {
return (widget.readSelectionFromPasteboard(id, sel, arg0) ? 1 : 0);
+ } else if (sel == OS.sel_viewWillMoveToWindow_) {
+ widget.viewWillMoveToWindow(id, sel, arg0);
} else if (sel == OS.sel_cancelOperation_) {
widget.cancelOperation(id, sel, arg0);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
index 736c69d8b2..443c3d11e2 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
@@ -119,7 +119,8 @@ import org.eclipse.swt.internal.cocoa.*;
public class Shell extends Decorations {
NSWindow window;
SWTWindowDelegate windowDelegate;
- int /*long*/ currWindowClass;
+ int /*long*/ hostWindowClass;
+ NSWindow hostWindow;
int /*long*/ tooltipOwner, tooltipTag, tooltipUserData;
boolean opened, moved, resized, fullScreen, center, deferFlushing, scrolling, isPopup;
Control lastActive;
@@ -488,6 +489,37 @@ public void addShellListener(ShellListener listener) {
addListener(SWT.Deiconify,typedListener);
}
+void attachObserversToWindow(NSWindow newWindow) {
+ if (newWindow == null || newWindow.id == 0) return;
+ hostWindow = newWindow;
+ hostWindow.retain();
+ int /*long*/ newHostWindowClass = OS.object_getClass(newWindow.id);
+ int /*long*/ embeddedSubclass = display.createWindowSubclass(newHostWindowClass, "SWTAWTWindow", true);
+ if (newHostWindowClass != embeddedSubclass) {
+ OS.object_setClass(hostWindow.id, embeddedSubclass);
+ hostWindowClass = newHostWindowClass;
+ }
+
+ if (windowEmbedCounts == null) windowEmbedCounts = new HashMap();
+ Integer embedCount = (Integer) windowEmbedCounts.get(hostWindow);
+ if (embedCount == null) {
+ embedCount = new Integer(0);
+ }
+ embedCount = new Integer(embedCount.intValue() + 1);
+ windowEmbedCounts.put(hostWindow, embedCount);
+
+ // Register for notifications. An embedded shell has no control over the host window,
+ // so it isn't correct to install a delegate.
+ NSNotificationCenter defaultCenter = NSNotificationCenter.defaultCenter();
+ defaultCenter.addObserver(windowDelegate, OS.sel_windowDidBecomeKey_, OS.NSWindowDidBecomeKeyNotification, hostWindow);
+ defaultCenter.addObserver(windowDelegate, OS.sel_windowDidDeminiaturize_, OS.NSWindowDidDeminiaturizeNotification, hostWindow);
+ defaultCenter.addObserver(windowDelegate, OS.sel_windowDidMiniaturize_, OS.NSWindowDidMiniaturizeNotification, hostWindow);
+ defaultCenter.addObserver(windowDelegate, OS.sel_windowDidMove_, OS.NSWindowDidMoveNotification, hostWindow);
+ defaultCenter.addObserver(windowDelegate, OS.sel_windowDidResize_, OS.NSWindowDidResizeNotification, hostWindow);
+ defaultCenter.addObserver(windowDelegate, OS.sel_windowDidResignKey_, OS.NSWindowDidResignKeyNotification, hostWindow);
+ defaultCenter.addObserver(windowDelegate, OS.sel_windowWillClose_, OS.NSWindowWillCloseNotification, hostWindow);
+}
+
void becomeKeyWindow (int /*long*/ id, int /*long*/ sel) {
Display display = this.display;
display.keyWindow = view.window();
@@ -684,29 +716,7 @@ void createHandle () {
if (window == null) {
NSWindow hostWindow = view.window();
- currWindowClass = OS.object_getClass(hostWindow.id);
- int /*long*/ sendEventImpl = OS.class_getMethodImplementation(currWindowClass, OS.sel_sendEvent_);
- if (sendEventImpl != Display.windowCallback3.getAddress()) {
- int /*long*/ embeddedSubclass = display.createWindowSubclass(currWindowClass, "SWTAWTWindow", true);
- OS.object_setClass(hostWindow.id, embeddedSubclass);
- }
-
- if (windowEmbedCounts == null) windowEmbedCounts = new HashMap();
- Integer embedCount = (Integer) windowEmbedCounts.get(hostWindow);
- if (embedCount == null) embedCount = new Integer(0);
- embedCount = new Integer(embedCount.intValue() + 1);
- windowEmbedCounts.put(hostWindow, embedCount);
-
- // Register for notifications. An embedded shell has no control over the host window,
- // so it isn't correct to install a delegate.
- NSNotificationCenter defaultCenter = NSNotificationCenter.defaultCenter();
- defaultCenter.addObserver(windowDelegate, OS.sel_windowDidBecomeKey_, OS.NSWindowDidBecomeKeyNotification, hostWindow);
- defaultCenter.addObserver(windowDelegate, OS.sel_windowDidDeminiaturize_, OS.NSWindowDidDeminiaturizeNotification, hostWindow);
- defaultCenter.addObserver(windowDelegate, OS.sel_windowDidMiniaturize_, OS.NSWindowDidMiniaturizeNotification, hostWindow);
- defaultCenter.addObserver(windowDelegate, OS.sel_windowDidMove_, OS.NSWindowDidMoveNotification, hostWindow);
- defaultCenter.addObserver(windowDelegate, OS.sel_windowDidResize_, OS.NSWindowDidResizeNotification, hostWindow);
- defaultCenter.addObserver(windowDelegate, OS.sel_windowDidResignKey_, OS.NSWindowDidResignKeyNotification, hostWindow);
- defaultCenter.addObserver(windowDelegate, OS.sel_windowWillClose_, OS.NSWindowWillCloseNotification, hostWindow);
+ attachObserversToWindow(hostWindow);
} else {
if (parent != null) window.setCollectionBehavior(OS.NSWindowCollectionBehaviorMoveToActiveSpace);
window.setAcceptsMouseMovedEvents(true);
@@ -735,18 +745,17 @@ void deferFlushing () {
void deregister () {
super.deregister ();
- if (window != null) {
- display.removeWidget (window);
- } else {
- display.removeWidget (view.window());
- }
+ if (window != null) display.removeWidget (window);
+ if (hostWindow != null) display.removeWidget (hostWindow);
if (windowDelegate != null) display.removeWidget (windowDelegate);
}
void destroyWidget () {
NSWindow window = this.window;
+ if (window != null) window.retain();
Display display = this.display;
NSView view = topView();
+ if (view != null) view.retain();
boolean sheet = (style & (SWT.SHEET)) != 0;
releaseHandle ();
@@ -758,6 +767,7 @@ void destroyWidget () {
window.close();
} else if (view != null) {
view.removeFromSuperview();
+ view.release();
}
// If another shell is not going to become active, clear the menu bar.
@@ -766,6 +776,7 @@ void destroyWidget () {
if (!display.isDisposed () && display.getShells ().length == 0) {
display.setMenuBar (null);
}
+ window.release();
}
}
@@ -1341,11 +1352,8 @@ void register () {
* all of the NSWindow overrides operate on the entire window.
*/
super.register ();
- if (window != null) {
- display.addWidget (window, this);
- } else {
- display.addWidget (view.window(), this);
- }
+ if (window != null) display.addWidget (window, this);
+ if (hostWindow != null) display.addWidget (hostWindow, this);
if (windowDelegate != null) display.addWidget (windowDelegate, this);
}
@@ -1362,22 +1370,10 @@ void releaseChildren (boolean destroy) {
void releaseHandle () {
if (window != null) window.setDelegate(null);
- NSNotificationCenter.defaultCenter().removeObserver(windowDelegate);
+ removeObserversFromWindow();
if (windowDelegate != null) windowDelegate.release();
windowDelegate = null;
-
- if (window == null && currWindowClass != 0) {
- Integer embedCount = (Integer) windowEmbedCounts.get(view.window());
- if (embedCount == null) embedCount = new Integer(0);
- embedCount = new Integer(embedCount.intValue() - 1);
- windowEmbedCounts.put(view.window(), embedCount);
-
- if (embedCount.intValue() <= 0) {
- windowEmbedCounts.remove(view.window());
- OS.object_setClass(view.window().id, currWindowClass);
- }
- }
-
+
super.releaseHandle ();
window = null;
}
@@ -1394,6 +1390,29 @@ void releaseWidget () {
lastActive = null;
}
+void removeObserversFromWindow () {
+ NSNotificationCenter.defaultCenter().removeObserver(windowDelegate);
+
+ if (hostWindow != null) {
+ Integer embedCount = (Integer) windowEmbedCounts.get(hostWindow);
+ if (embedCount == null) {
+ embedCount = new Integer(0);
+ }
+ embedCount = new Integer(embedCount.intValue() - 1);
+ windowEmbedCounts.put(hostWindow, embedCount);
+
+ if (embedCount.intValue() <= 0) {
+ windowEmbedCounts.remove(hostWindow);
+ OS.object_setClass(hostWindow.id, hostWindowClass);
+ display.removeWidget(hostWindow);
+ hostWindow.release();
+ hostWindow = null;
+ hostWindowClass = 0;
+ }
+ }
+}
+
+
/**
* Removes the listener from the collection of listeners who will
* be notified when operations are performed on the receiver.
@@ -2055,6 +2074,20 @@ int /*long*/ view_stringForToolTip_point_userData (int /*long*/ id, int /*long*/
return NSString.stringWithCharacters (chars, length).id;
}
+void viewWillMoveToWindow(int /*long*/ id, int /*long*/ sel, int /*long*/ newWindow) {
+ if (window == null) {
+ int /*long*/ currentWindow = hostWindow != null ? hostWindow.id : 0;
+ if (currentWindow != 0) {
+ removeObserversFromWindow();
+ display.removeWidget(hostWindow);
+ }
+ if (newWindow != 0) {
+ attachObserversToWindow(new NSWindow(newWindow));
+ display.addWidget(hostWindow, this);
+ }
+ }
+}
+
void windowDidBecomeKey(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
if (window != null) {
Display display = this.display;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
index 0bb593b926..8ea4570086 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
@@ -1016,7 +1016,11 @@ public void setDisabledImage (Image image) {
boolean setFocus () {
if (button == null) return false;
if (!isEnabled ()) return false;
- return view.window ().makeFirstResponder (button);
+ NSWindow window = view.window ();
+ if(window == null) {
+ return false;
+ }
+ return window.makeFirstResponder (button);
}
/**