src/video/cocoa/SDL_cocoawindow.m
changeset 7087 5639ac726076
parent 7085 152cc7ddfa57
child 7098 f4b2c6fb0258
equal deleted inserted replaced
7086:141ffce8bb59 7087:5639ac726076
    48     NSNotificationCenter *center;
    48     NSNotificationCenter *center;
    49     NSWindow *window = data->nswindow;
    49     NSWindow *window = data->nswindow;
    50     NSView *view = [window contentView];
    50     NSView *view = [window contentView];
    51 
    51 
    52     _data = data;
    52     _data = data;
       
    53     observingVisible = YES;
       
    54     wasVisible = [window isVisible];
    53 
    55 
    54     center = [NSNotificationCenter defaultCenter];
    56     center = [NSNotificationCenter defaultCenter];
    55 
    57 
    56     if ([window delegate] != nil) {
    58     if ([window delegate] != nil) {
    57         [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
    59         [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
    88 - (void)observeValueForKeyPath:(NSString *)keyPath
    90 - (void)observeValueForKeyPath:(NSString *)keyPath
    89                       ofObject:(id)object
    91                       ofObject:(id)object
    90                         change:(NSDictionary *)change
    92                         change:(NSDictionary *)change
    91                        context:(void *)context
    93                        context:(void *)context
    92 {
    94 {
       
    95     if (!observingVisible) {
       
    96         return;
       
    97     }
       
    98 
    93     if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
    99     if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
    94         int newVisibility = [[change objectForKey:@"new"] intValue];
   100         int newVisibility = [[change objectForKey:@"new"] intValue];
    95         if (newVisibility) {
   101         if (newVisibility) {
    96             SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
   102             SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
    97         } else {
   103         } else {
    98             SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   104             SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
    99         }
   105         }
       
   106     }
       
   107 }
       
   108 
       
   109 -(void) pauseVisibleObservation
       
   110 {
       
   111     observingVisible = NO;
       
   112     wasVisible = [_data->nswindow isVisible];
       
   113 }
       
   114 
       
   115 -(void) resumeVisibleObservation
       
   116 {
       
   117     BOOL isVisible = [_data->nswindow isVisible];
       
   118     observingVisible = YES;
       
   119     if (wasVisible != isVisible) {
       
   120         if (isVisible) {
       
   121             SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
       
   122         } else {
       
   123             SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
       
   124         }
       
   125 
       
   126         wasVisible = isVisible;
   100     }
   127     }
   101 }
   128 }
   102 
   129 
   103 - (void)close
   130 - (void)close
   104 {
   131 {
   783 
   810 
   784 void
   811 void
   785 Cocoa_ShowWindow(_THIS, SDL_Window * window)
   812 Cocoa_ShowWindow(_THIS, SDL_Window * window)
   786 {
   813 {
   787     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   814     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       
   815     SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
       
   816     NSWindow *nswindow = windowData->nswindow;
       
   817 
       
   818     if (![nswindow isMiniaturized]) {
       
   819         [windowData->listener pauseVisibleObservation];
       
   820         [nswindow makeKeyAndOrderFront:nil];
       
   821         [windowData->listener resumeVisibleObservation];
       
   822     }
       
   823     [pool release];
       
   824 }
       
   825 
       
   826 void
       
   827 Cocoa_HideWindow(_THIS, SDL_Window * window)
       
   828 {
       
   829     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   788     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   830     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   789 
   831 
   790     if (![nswindow isMiniaturized]) {
       
   791         [nswindow makeKeyAndOrderFront:nil];
       
   792     }
       
   793     [pool release];
       
   794 }
       
   795 
       
   796 void
       
   797 Cocoa_HideWindow(_THIS, SDL_Window * window)
       
   798 {
       
   799     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       
   800     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
       
   801 
       
   802     [nswindow orderOut:nil];
   832     [nswindow orderOut:nil];
   803     [pool release];
   833     [pool release];
   804 }
   834 }
   805 
   835 
   806 void
   836 void
   807 Cocoa_RaiseWindow(_THIS, SDL_Window * window)
   837 Cocoa_RaiseWindow(_THIS, SDL_Window * window)
   808 {
   838 {
   809     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   839     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   810     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   840     SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
   811 
   841     NSWindow *nswindow = windowData->nswindow;
       
   842 
       
   843     [windowData->listener pauseVisibleObservation];
   812     [nswindow makeKeyAndOrderFront:nil];
   844     [nswindow makeKeyAndOrderFront:nil];
       
   845     [windowData->listener resumeVisibleObservation];
       
   846 
   813     [pool release];
   847     [pool release];
   814 }
   848 }
   815 
   849 
   816 void
   850 void
   817 Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
   851 Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
   958         [nswindow setLevel:CGShieldingWindowLevel()];
   992         [nswindow setLevel:CGShieldingWindowLevel()];
   959     } else {
   993     } else {
   960         [nswindow setLevel:kCGNormalWindowLevel];
   994         [nswindow setLevel:kCGNormalWindowLevel];
   961     }
   995     }
   962 #endif
   996 #endif
       
   997 
       
   998     [data->listener pauseVisibleObservation];
   963     [nswindow makeKeyAndOrderFront:nil];
   999     [nswindow makeKeyAndOrderFront:nil];
       
  1000     [data->listener resumeVisibleObservation];
   964 
  1001 
   965     if (window == _this->current_glwin) {
  1002     if (window == _this->current_glwin) {
   966         [((NSOpenGLContext *) _this->current_glctx) update];
  1003         [((NSOpenGLContext *) _this->current_glctx) update];
   967     }
  1004     }
   968 
  1005