src/video/cocoa/SDL_cocoawindow.m
changeset 1956 ba0d62354872
parent 1952 420716272158
child 1957 c7803e4c21d3
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 29 03:57:55 2006 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 29 21:51:00 2006 +0000
     1.3 @@ -195,6 +195,7 @@
     1.4  
     1.5  - (void)mouseMoved:(NSEvent *)theEvent
     1.6  {
     1.7 +    SDL_Window *window = SDL_GetWindowFromID(_data->windowID);
     1.8      int index;
     1.9      SDL_Mouse *mouse;
    1.10      NSPoint point;
    1.11 @@ -207,6 +208,18 @@
    1.12      }
    1.13  
    1.14      point = [NSEvent mouseLocation];
    1.15 +    if (point.x < rect.origin.x ||
    1.16 +        point.x > (rect.origin.x + rect.size.width) ||
    1.17 +        point.y < rect.origin.y ||
    1.18 +        point.y > (rect.origin.y + rect.size.height)) {
    1.19 +        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    1.20 +            SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
    1.21 +        }
    1.22 +    } else {
    1.23 +        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
    1.24 +            SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
    1.25 +        }
    1.26 +    }
    1.27      point.x = point.x - rect.origin.x;
    1.28      point.y = rect.size.height - (point.y - rect.origin.y);
    1.29      SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
    1.30 @@ -217,18 +230,6 @@
    1.31  fprintf(stderr, "scrollWheel\n");
    1.32  }
    1.33  
    1.34 -- (void)mouseEntered:(NSEvent *)theEvent
    1.35 -{
    1.36 -fprintf(stderr, "mouseEntered\n");
    1.37 -    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
    1.38 -}
    1.39 -
    1.40 -- (void)mouseExited:(NSEvent *)theEvent
    1.41 -{
    1.42 -fprintf(stderr, "mouseExited\n");
    1.43 -    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
    1.44 -}
    1.45 -
    1.46  - (void)keyDown:(NSEvent *)theEvent
    1.47  {
    1.48  fprintf(stderr, "keyDown\n");
    1.49 @@ -282,7 +283,7 @@
    1.50      {
    1.51          unsigned int style = [nswindow styleMask];
    1.52  
    1.53 -        if (style == NSBorderlessWindowMask) {
    1.54 +        if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) {
    1.55              window->flags |= SDL_WINDOW_BORDERLESS;
    1.56          } else {
    1.57              window->flags &= ~SDL_WINDOW_BORDERLESS;
    1.58 @@ -331,16 +332,14 @@
    1.59  
    1.60      pool = [[NSAutoreleasePool alloc] init];
    1.61  
    1.62 -    if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
    1.63 -        window->x == SDL_WINDOWPOS_CENTERED) {
    1.64 +    if (window->x == SDL_WINDOWPOS_CENTERED) {
    1.65          rect.origin.x = (CGDisplayPixelsWide(kCGDirectMainDisplay) - window->w) / 2;
    1.66      } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
    1.67          rect.origin.x = 0;
    1.68      } else {
    1.69          rect.origin.x = window->x;
    1.70      }
    1.71 -    if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
    1.72 -        window->y == SDL_WINDOWPOS_CENTERED) {
    1.73 +    if (window->y == SDL_WINDOWPOS_CENTERED) {
    1.74          rect.origin.y = (CGDisplayPixelsHigh(kCGDirectMainDisplay) - window->h) / 2;
    1.75      } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
    1.76          rect.origin.y = 0;
    1.77 @@ -362,23 +361,6 @@
    1.78  
    1.79      nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
    1.80  
    1.81 -    if (window->flags & SDL_WINDOW_SHOWN) {
    1.82 -        [nswindow makeKeyAndOrderFront:nil];
    1.83 -    }
    1.84 -    if (window->flags & SDL_WINDOW_MAXIMIZED) {
    1.85 -        [nswindow performZoom:nil];
    1.86 -    }
    1.87 -    if (window->flags & SDL_WINDOW_MINIMIZED) {
    1.88 -        [nswindow performMiniaturize:nil];
    1.89 -    }
    1.90 -
    1.91 -    if (window->title) {
    1.92 -        title = [[NSString alloc] initWithUTF8String:window->title];
    1.93 -        [nswindow setTitle:title];
    1.94 -        [nswindow setMiniwindowTitle:title];
    1.95 -        [title release];
    1.96 -    }
    1.97 -
    1.98      [pool release];
    1.99  
   1.100      if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
   1.101 @@ -424,10 +406,14 @@
   1.102      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.103      NSString *string;
   1.104  
   1.105 -    string = [[NSString alloc] initWithUTF8String:window->title];
   1.106 +    if(window->title) {
   1.107 +        string = [[NSString alloc] initWithUTF8String:window->title];
   1.108 +    } else {
   1.109 +        string = [[NSString alloc] init];
   1.110 +    }
   1.111      [nswindow setTitle:string];
   1.112 -    [nswindow setMiniwindowTitle:string];
   1.113      [string release];
   1.114 +
   1.115      [pool release];
   1.116  }
   1.117  
   1.118 @@ -467,16 +453,20 @@
   1.119      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.120      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.121  
   1.122 -    [nswindow makeKeyAndOrderFront:nil];
   1.123 +    if (![nswindow isMiniaturized]) {
   1.124 +        [nswindow makeKeyAndOrderFront:nil];
   1.125 +    }
   1.126      [pool release];
   1.127  }
   1.128  
   1.129  void
   1.130  Cocoa_HideWindow(_THIS, SDL_Window * window)
   1.131  {
   1.132 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.133      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.134  
   1.135 -    /* FIXME */
   1.136 +    [nswindow orderOut:nil];
   1.137 +    [pool release];
   1.138  }
   1.139  
   1.140  void
   1.141 @@ -495,7 +485,7 @@
   1.142      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.143      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.144  
   1.145 -    [nswindow performZoom:nil];
   1.146 +    [nswindow zoom:nil];
   1.147      [pool release];
   1.148  }
   1.149  
   1.150 @@ -505,16 +495,22 @@
   1.151      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.152      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.153  
   1.154 -    [nswindow performMiniaturize:nil];
   1.155 +    [nswindow miniaturize:nil];
   1.156      [pool release];
   1.157  }
   1.158  
   1.159  void
   1.160  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
   1.161  {
   1.162 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.163      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.164  
   1.165 -    /* FIXME */
   1.166 +    if ([nswindow isMiniaturized]) {
   1.167 +        [nswindow deminiaturize:nil];
   1.168 +    } else if ([nswindow isZoomed]) {
   1.169 +        [nswindow zoom:nil];
   1.170 +    }
   1.171 +    [pool release];
   1.172  }
   1.173  
   1.174  void