We still want the delegate functionality for windowShouldClose()
authorSam Lantinga <slouken@libsdl.org>
Mon, 21 Feb 2011 15:25:49 -0800
changeset 5374dacb4f5e0dd3
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
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Mon Feb 21 15:08:36 2011 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Mon Feb 21 15:25:49 2011 -0800
     1.3 @@ -29,7 +29,11 @@
     1.4  typedef struct SDL_WindowData SDL_WindowData;
     1.5  
     1.6  /* *INDENT-OFF* */
     1.7 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
     1.8 +@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
     1.9 +#else
    1.10  @interface Cocoa_WindowListener : NSResponder {
    1.11 +#endif
    1.12      SDL_WindowData *_data;
    1.13  }
    1.14  
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 21 15:08:36 2011 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 21 15:25:49 2011 -0800
     2.3 @@ -48,13 +48,17 @@
     2.4  
     2.5      center = [NSNotificationCenter defaultCenter];
     2.6  
     2.7 -    [center addObserver:self selector:@selector(windowDisExpose:) name:NSWindowDidExposeNotification object:window];
     2.8 -    [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
     2.9 -    [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
    2.10 -    [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
    2.11 -    [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
    2.12 -    [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
    2.13 -    [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
    2.14 +    if ([window delegate] != nil) {
    2.15 +        [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
    2.16 +        [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
    2.17 +        [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
    2.18 +        [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
    2.19 +        [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
    2.20 +        [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
    2.21 +        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
    2.22 +    } else {
    2.23 +        [window setDelegate:self];
    2.24 +    }
    2.25      [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
    2.26      [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
    2.27  
    2.28 @@ -76,18 +80,26 @@
    2.29  
    2.30      center = [NSNotificationCenter defaultCenter];
    2.31  
    2.32 -    [center removeObserver:self name:NSWindowDidExposeNotification object:window];
    2.33 -    [center removeObserver:self name:NSWindowDidMoveNotification object:window];
    2.34 -    [center removeObserver:self name:NSWindowDidResizeNotification object:window];
    2.35 -    [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
    2.36 -    [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
    2.37 -    [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
    2.38 -    [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
    2.39 +    if ([window delegate] != self) {
    2.40 +        [center removeObserver:self name:NSWindowDidExposeNotification object:window];
    2.41 +        [center removeObserver:self name:NSWindowDidMoveNotification object:window];
    2.42 +        [center removeObserver:self name:NSWindowDidResizeNotification object:window];
    2.43 +        [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
    2.44 +        [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
    2.45 +        [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
    2.46 +        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
    2.47 +    } else {
    2.48 +        [window setDelegate:nil];
    2.49 +    }
    2.50      [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
    2.51      [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
    2.52  
    2.53 -    [window setNextResponder:nil];
    2.54 -    [view setNextResponder:nil];
    2.55 +    if ([window nextResponder] == self) {
    2.56 +        [window setNextResponder:nil];
    2.57 +    }
    2.58 +    if ([view nextResponder] == self) {
    2.59 +        [view setNextResponder:nil];
    2.60 +    }
    2.61  }
    2.62  
    2.63  - (BOOL)windowShouldClose:(id)sender