We still want the delegate functionality for windowShouldClose()
authorSam Lantinga <slouken@libsdl.org>
Mon, 21 Feb 2011 15:25:49 -0800
changeset 5374 dacb4f5e0dd3
parent 5373 02007fd16991
child 5375 16877f74123c
We still want the delegate functionality for windowShouldClose()
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.h	Mon Feb 21 15:08:36 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.h	Mon Feb 21 15:25:49 2011 -0800
@@ -29,7 +29,11 @@
 typedef struct SDL_WindowData SDL_WindowData;
 
 /* *INDENT-OFF* */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
+@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
+#else
 @interface Cocoa_WindowListener : NSResponder {
+#endif
     SDL_WindowData *_data;
 }
 
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 21 15:08:36 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 21 15:25:49 2011 -0800
@@ -48,13 +48,17 @@
 
     center = [NSNotificationCenter defaultCenter];
 
-    [center addObserver:self selector:@selector(windowDisExpose:) name:NSWindowDidExposeNotification object:window];
-    [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
-    [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
-    [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
-    [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
-    [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
-    [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
+    if ([window delegate] != nil) {
+        [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
+        [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
+        [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
+        [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
+        [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
+        [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
+        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
+    } else {
+        [window setDelegate:self];
+    }
     [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
     [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
 
@@ -76,18 +80,26 @@
 
     center = [NSNotificationCenter defaultCenter];
 
-    [center removeObserver:self name:NSWindowDidExposeNotification object:window];
-    [center removeObserver:self name:NSWindowDidMoveNotification object:window];
-    [center removeObserver:self name:NSWindowDidResizeNotification object:window];
-    [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
-    [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
-    [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
-    [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
+    if ([window delegate] != self) {
+        [center removeObserver:self name:NSWindowDidExposeNotification object:window];
+        [center removeObserver:self name:NSWindowDidMoveNotification object:window];
+        [center removeObserver:self name:NSWindowDidResizeNotification object:window];
+        [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
+        [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
+        [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
+        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
+    } else {
+        [window setDelegate:nil];
+    }
     [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
     [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
 
-    [window setNextResponder:nil];
-    [view setNextResponder:nil];
+    if ([window nextResponder] == self) {
+        [window setNextResponder:nil];
+    }
+    if ([view nextResponder] == self) {
+        [view setNextResponder:nil];
+    }
 }
 
 - (BOOL)windowShouldClose:(id)sender