src/video/cocoa/SDL_cocoawindow.m
changeset 5374 dacb4f5e0dd3
parent 5371 fc3d3d580777
child 5375 16877f74123c
equal deleted inserted replaced
5373:02007fd16991 5374:dacb4f5e0dd3
    46 
    46 
    47     _data = data;
    47     _data = data;
    48 
    48 
    49     center = [NSNotificationCenter defaultCenter];
    49     center = [NSNotificationCenter defaultCenter];
    50 
    50 
    51     [center addObserver:self selector:@selector(windowDisExpose:) name:NSWindowDidExposeNotification object:window];
    51     if ([window delegate] != nil) {
    52     [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
    52         [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
    53     [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
    53         [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
    54     [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
    54         [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
    55     [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
    55         [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
    56     [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
    56         [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
    57     [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
    57         [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
       
    58         [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
       
    59     } else {
       
    60         [window setDelegate:self];
       
    61     }
    58     [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
    62     [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
    59     [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
    63     [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
    60 
    64 
    61     [window setNextResponder:self];
    65     [window setNextResponder:self];
    62     [window setAcceptsMouseMovedEvents:YES];
    66     [window setAcceptsMouseMovedEvents:YES];
    74     NSWindow *window = _data->nswindow;
    78     NSWindow *window = _data->nswindow;
    75     NSView *view = [window contentView];
    79     NSView *view = [window contentView];
    76 
    80 
    77     center = [NSNotificationCenter defaultCenter];
    81     center = [NSNotificationCenter defaultCenter];
    78 
    82 
    79     [center removeObserver:self name:NSWindowDidExposeNotification object:window];
    83     if ([window delegate] != self) {
    80     [center removeObserver:self name:NSWindowDidMoveNotification object:window];
    84         [center removeObserver:self name:NSWindowDidExposeNotification object:window];
    81     [center removeObserver:self name:NSWindowDidResizeNotification object:window];
    85         [center removeObserver:self name:NSWindowDidMoveNotification object:window];
    82     [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
    86         [center removeObserver:self name:NSWindowDidResizeNotification object:window];
    83     [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
    87         [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
    84     [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
    88         [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
    85     [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
    89         [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
       
    90         [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
       
    91     } else {
       
    92         [window setDelegate:nil];
       
    93     }
    86     [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
    94     [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
    87     [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
    95     [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
    88 
    96 
    89     [window setNextResponder:nil];
    97     if ([window nextResponder] == self) {
    90     [view setNextResponder:nil];
    98         [window setNextResponder:nil];
       
    99     }
       
   100     if ([view nextResponder] == self) {
       
   101         [view setNextResponder:nil];
       
   102     }
    91 }
   103 }
    92 
   104 
    93 - (BOOL)windowShouldClose:(id)sender
   105 - (BOOL)windowShouldClose:(id)sender
    94 {
   106 {
    95     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
   107     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);