src/video/cocoa/SDL_cocoawindow.m
changeset 1933 7ee5297340f7
child 1936 83946ee0ff1f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 24 05:03:02 2006 +0000
     1.3 @@ -0,0 +1,557 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2006 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#include "SDL_syswm.h"
    1.28 +#include "../SDL_sysvideo.h"
    1.29 +#include "../../events/SDL_keyboard_c.h"
    1.30 +#include "../../events/SDL_mouse_c.h"
    1.31 +#include "../../events/SDL_windowevents_c.h"
    1.32 +
    1.33 +#include "SDL_cocoavideo.h"
    1.34 +
    1.35 +static __inline__ void ConvertNSRect(NSRect *r)
    1.36 +{
    1.37 +    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
    1.38 +}
    1.39 +
    1.40 +@implementation Cocoa_WindowListener
    1.41 +
    1.42 +- (void)listen:(SDL_WindowData *)data
    1.43 +{
    1.44 +    NSNotificationCenter *center;
    1.45 +
    1.46 +    _data = data;
    1.47 +
    1.48 +    center = [NSNotificationCenter defaultCenter];
    1.49 +
    1.50 +    [_data->window setNextResponder:self];
    1.51 +    if ([_data->window delegate] != nil) {
    1.52 +        [center addObserver:self selector:@selector(windowDisExpose:) name:NSWindowDidExposeNotification object:_data->window];
    1.53 +        [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:_data->window];
    1.54 +        [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:_data->window];
    1.55 +        [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:_data->window];
    1.56 +        [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:_data->window];
    1.57 +        [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:_data->window];
    1.58 +        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:_data->window];
    1.59 +    } else {
    1.60 +        [_data->window setDelegate:self];
    1.61 +    }
    1.62 +    [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
    1.63 +    [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
    1.64 +
    1.65 +    [_data->window setAcceptsMouseMovedEvents:YES];
    1.66 +}
    1.67 +
    1.68 +- (void)close
    1.69 +{
    1.70 +    NSNotificationCenter *center;
    1.71 +
    1.72 +    center = [NSNotificationCenter defaultCenter];
    1.73 +
    1.74 +    [_data->window setNextResponder:nil];
    1.75 +    if ([_data->window delegate] != self) {
    1.76 +        [center removeObserver:self name:NSWindowDidExposeNotification object:_data->window];
    1.77 +        [center removeObserver:self name:NSWindowDidMoveNotification object:_data->window];
    1.78 +        [center removeObserver:self name:NSWindowDidResizeNotification object:_data->window];
    1.79 +        [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:_data->window];
    1.80 +        [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:_data->window];
    1.81 +        [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:_data->window];
    1.82 +        [center removeObserver:self name:NSWindowDidResignKeyNotification object:_data->window];
    1.83 +    } else {
    1.84 +        [_data->window setDelegate:nil];
    1.85 +    }
    1.86 +    [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
    1.87 +    [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
    1.88 +}
    1.89 +
    1.90 +- (BOOL)windowShouldClose:(id)sender
    1.91 +{
    1.92 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_CLOSE, 0, 0);
    1.93 +    return NO;
    1.94 +}
    1.95 +
    1.96 +- (void)windowDidExpose:(NSNotification *)aNotification
    1.97 +{
    1.98 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_EXPOSED, 0, 0);
    1.99 +}
   1.100 +
   1.101 +- (void)windowDidMove:(NSNotification *)aNotification
   1.102 +{
   1.103 +    int x, y;
   1.104 +    NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
   1.105 +    ConvertNSRect(&rect);
   1.106 +    x = (int)rect.origin.x;
   1.107 +    y = (int)rect.origin.y;
   1.108 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MOVED, x, y);
   1.109 +}
   1.110 +
   1.111 +- (void)windowDidResize:(NSNotification *)aNotification
   1.112 +{
   1.113 +    int w, h;
   1.114 +    NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
   1.115 +    w = (int)rect.size.width;
   1.116 +    h = (int)rect.size.height;
   1.117 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_RESIZED, w, h);
   1.118 +}
   1.119 +
   1.120 +- (void)windowDidMiniaturize:(NSNotification *)aNotification
   1.121 +{
   1.122 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   1.123 +}
   1.124 +
   1.125 +- (void)windowDidDeminiaturize:(NSNotification *)aNotification
   1.126 +{
   1.127 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_RESTORED, 0, 0);
   1.128 +}
   1.129 +
   1.130 +- (void)windowDidBecomeKey:(NSNotification *)aNotification
   1.131 +{
   1.132 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   1.133 +}
   1.134 +
   1.135 +- (void)windowDidResignKey:(NSNotification *)aNotification
   1.136 +{
   1.137 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
   1.138 +}
   1.139 +
   1.140 +- (void)windowDidHide:(NSNotification *)aNotification
   1.141 +{
   1.142 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   1.143 +}
   1.144 +
   1.145 +- (void)windowDidUnhide:(NSNotification *)aNotification
   1.146 +{
   1.147 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_SHOWN, 0, 0);
   1.148 +}
   1.149 +
   1.150 +- (void)mouseDown:(NSEvent *)theEvent
   1.151 +{
   1.152 +    int index;
   1.153 +
   1.154 +    index = _data->videodata->mouse;
   1.155 +    SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_LEFT);
   1.156 +}
   1.157 +
   1.158 +- (void)rightMouseDown:(NSEvent *)theEvent
   1.159 +{
   1.160 +    int index;
   1.161 +
   1.162 +    index = _data->videodata->mouse;
   1.163 +    SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_RIGHT);
   1.164 +}
   1.165 +
   1.166 +- (void)otherMouseDown:(NSEvent *)theEvent
   1.167 +{
   1.168 +    int index;
   1.169 +
   1.170 +    index = _data->videodata->mouse;
   1.171 +    SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_MIDDLE);
   1.172 +}
   1.173 +
   1.174 +- (void)mouseUp:(NSEvent *)theEvent
   1.175 +{
   1.176 +    int index;
   1.177 +
   1.178 +    index = _data->videodata->mouse;
   1.179 +    SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_LEFT);
   1.180 +}
   1.181 +
   1.182 +- (void)rightMouseUp:(NSEvent *)theEvent
   1.183 +{
   1.184 +    int index;
   1.185 +
   1.186 +    index = _data->videodata->mouse;
   1.187 +    SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_RIGHT);
   1.188 +}
   1.189 +
   1.190 +- (void)otherMouseUp:(NSEvent *)theEvent
   1.191 +{
   1.192 +    int index;
   1.193 +
   1.194 +    index = _data->videodata->mouse;
   1.195 +    SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_MIDDLE);
   1.196 +}
   1.197 +
   1.198 +- (void)mouseMoved:(NSEvent *)theEvent
   1.199 +{
   1.200 +    int index;
   1.201 +    SDL_Mouse *mouse;
   1.202 +    NSPoint point;
   1.203 +    NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
   1.204 +
   1.205 +    index = _data->videodata->mouse;
   1.206 +    mouse = SDL_GetMouse(index);
   1.207 +    if (mouse->focus != _data->windowID) {
   1.208 +        SDL_SetMouseFocus(index, _data->windowID);
   1.209 +    }
   1.210 +
   1.211 +    point = [NSEvent mouseLocation];
   1.212 +    point.x = point.x - rect.origin.x;
   1.213 +    point.y = rect.size.height - (point.y - rect.origin.y);
   1.214 +    SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
   1.215 +}
   1.216 +
   1.217 +- (void)scrollWheel:(NSEvent *)theEvent
   1.218 +{
   1.219 +fprintf(stderr, "scrollWheel\n");
   1.220 +}
   1.221 +
   1.222 +- (void)mouseEntered:(NSEvent *)theEvent
   1.223 +{
   1.224 +fprintf(stderr, "mouseEntered\n");
   1.225 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
   1.226 +}
   1.227 +
   1.228 +- (void)mouseExited:(NSEvent *)theEvent
   1.229 +{
   1.230 +fprintf(stderr, "mouseExited\n");
   1.231 +    SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
   1.232 +}
   1.233 +
   1.234 +- (void)keyDown:(NSEvent *)theEvent
   1.235 +{
   1.236 +fprintf(stderr, "keyDown\n");
   1.237 +}
   1.238 +
   1.239 +- (void)keyUp:(NSEvent *)theEvent
   1.240 +{
   1.241 +fprintf(stderr, "keyUp\n");
   1.242 +}
   1.243 +
   1.244 +@end
   1.245 +
   1.246 +static int
   1.247 +SetupWindowData(SDL_Window * window, NSWindow *nswindow, BOOL created)
   1.248 +{
   1.249 +    NSAutoreleasePool *pool;
   1.250 +    SDL_WindowData *data;
   1.251 +
   1.252 +    /* Allocate the window data */
   1.253 +    data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
   1.254 +    if (!data) {
   1.255 +        SDL_OutOfMemory();
   1.256 +        return -1;
   1.257 +    }
   1.258 +    data->windowID = window->id;
   1.259 +    data->window = nswindow;
   1.260 +    data->created = created;
   1.261 +    data->videodata = (SDL_VideoData *) SDL_GetVideoDevice()->driverdata;
   1.262 +
   1.263 +    pool = [[NSAutoreleasePool alloc] init];
   1.264 +
   1.265 +    /* Create an event listener for the window */
   1.266 +    data->listener = [[Cocoa_WindowListener alloc] init];
   1.267 +    [data->listener listen:data];
   1.268 +
   1.269 +    /* Fill in the SDL window with the window data */
   1.270 +    {
   1.271 +        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   1.272 +        ConvertNSRect(&rect);
   1.273 +        window->x = (int)rect.origin.x;
   1.274 +        window->y = (int)rect.origin.y;
   1.275 +        window->w = (int)rect.size.width;
   1.276 +        window->h = (int)rect.size.height;
   1.277 +    }
   1.278 +    if ([nswindow isVisible]) {
   1.279 +        window->flags |= SDL_WINDOW_SHOWN;
   1.280 +    } else {
   1.281 +        window->flags &= ~SDL_WINDOW_SHOWN;
   1.282 +    }
   1.283 +    {
   1.284 +        unsigned int style = [nswindow styleMask];
   1.285 +
   1.286 +        if (style == NSBorderlessWindowMask) {
   1.287 +            window->flags |= SDL_WINDOW_BORDERLESS;
   1.288 +        } else {
   1.289 +            window->flags &= ~SDL_WINDOW_BORDERLESS;
   1.290 +        }
   1.291 +        if (style & NSResizableWindowMask) {
   1.292 +            window->flags |= SDL_WINDOW_RESIZABLE;
   1.293 +        } else {
   1.294 +            window->flags &= ~SDL_WINDOW_RESIZABLE;
   1.295 +        }
   1.296 +    }
   1.297 +    if ([nswindow isZoomed]) {
   1.298 +        window->flags |= SDL_WINDOW_MAXIMIZED;
   1.299 +    } else {
   1.300 +        window->flags &= ~SDL_WINDOW_MAXIMIZED;
   1.301 +    }
   1.302 +    if ([nswindow isMiniaturized]) {
   1.303 +        window->flags |= SDL_WINDOW_MINIMIZED;
   1.304 +    } else {
   1.305 +        window->flags &= ~SDL_WINDOW_MINIMIZED;
   1.306 +    }
   1.307 +    if ([nswindow isKeyWindow]) {
   1.308 +        int index = data->videodata->keyboard;
   1.309 +        window->flags |= SDL_WINDOW_INPUT_FOCUS;
   1.310 +        SDL_SetKeyboardFocus(index, data->windowID);
   1.311 +
   1.312 +        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
   1.313 +            /* FIXME */
   1.314 +        }
   1.315 +    }
   1.316 +
   1.317 +    /* All done! */
   1.318 +    [pool release];
   1.319 +    window->driverdata = data;
   1.320 +    return 0;
   1.321 +}
   1.322 +
   1.323 +int
   1.324 +Cocoa_CreateWindow(_THIS, SDL_Window * window)
   1.325 +{
   1.326 +    NSAutoreleasePool *pool;
   1.327 +    NSWindow *nswindow;
   1.328 +    NSRect rect;
   1.329 +    unsigned int style;
   1.330 +    NSString *title;
   1.331 +
   1.332 +    pool = [[NSAutoreleasePool alloc] init];
   1.333 +
   1.334 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
   1.335 +        window->x == SDL_WINDOWPOS_CENTERED) {
   1.336 +        rect.origin.x = (CGDisplayPixelsWide(kCGDirectMainDisplay) - window->w) / 2;
   1.337 +    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   1.338 +        rect.origin.x = 0;
   1.339 +    } else {
   1.340 +        rect.origin.x = window->x;
   1.341 +    }
   1.342 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
   1.343 +        window->y == SDL_WINDOWPOS_CENTERED) {
   1.344 +        rect.origin.y = (CGDisplayPixelsHigh(kCGDirectMainDisplay) - window->h) / 2;
   1.345 +    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   1.346 +        rect.origin.y = 0;
   1.347 +    } else {
   1.348 +        rect.origin.y = window->y;
   1.349 +    }
   1.350 +    rect.size.width = window->w;
   1.351 +    rect.size.height = window->h;
   1.352 +    ConvertNSRect(&rect);
   1.353 +
   1.354 +    if (window->flags & SDL_WINDOW_BORDERLESS) {
   1.355 +        style = NSBorderlessWindowMask;
   1.356 +    } else {
   1.357 +        style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
   1.358 +    }
   1.359 +    if (window->flags & SDL_WINDOW_RESIZABLE) {
   1.360 +        style |= NSResizableWindowMask;
   1.361 +    }
   1.362 +
   1.363 +    nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
   1.364 +
   1.365 +    if (window->flags & SDL_WINDOW_SHOWN) {
   1.366 +        [nswindow makeKeyAndOrderFront:nil];
   1.367 +    }
   1.368 +    if (window->flags & SDL_WINDOW_MAXIMIZED) {
   1.369 +        [nswindow performZoom:nil];
   1.370 +    }
   1.371 +    if (window->flags & SDL_WINDOW_MINIMIZED) {
   1.372 +        [nswindow performMiniaturize:nil];
   1.373 +    }
   1.374 +
   1.375 +    if (window->title) {
   1.376 +        title = [[NSString alloc] initWithUTF8String:window->title];
   1.377 +        [nswindow setTitle:title];
   1.378 +        [nswindow setMiniwindowTitle:title];
   1.379 +        [title release];
   1.380 +    }
   1.381 +
   1.382 +    [pool release];
   1.383 +
   1.384 +    if (SetupWindowData(window, nswindow, YES) < 0) {
   1.385 +        [nswindow release];
   1.386 +        [pool release];
   1.387 +        return -1;
   1.388 +    }
   1.389 +#ifdef SDL_VIDEO_OPENGL
   1.390 +    /*
   1.391 +    if (window->flags & SDL_WINDOW_OPENGL) {
   1.392 +        if (Cocoa_GL_SetupWindow(_this, window) < 0) {
   1.393 +            Cocoa_DestroyWindow(_this, window);
   1.394 +            return -1;
   1.395 +        }
   1.396 +    }
   1.397 +    */
   1.398 +#endif
   1.399 +    return 0;
   1.400 +}
   1.401 +
   1.402 +int
   1.403 +Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   1.404 +{
   1.405 +    NSAutoreleasePool *pool;
   1.406 +    NSWindow *nswindow = (NSWindow *) data;
   1.407 +    NSString *title;
   1.408 +    int status;
   1.409 +
   1.410 +    pool = [[NSAutoreleasePool alloc] init];
   1.411 +
   1.412 +    /* Query the title from the existing window */
   1.413 +    title = [nswindow title];
   1.414 +    if (title) {
   1.415 +        window->title = SDL_strdup([title UTF8String]);
   1.416 +    }
   1.417 +
   1.418 +    [pool release];
   1.419 +
   1.420 +    return SetupWindowData(window, nswindow, NO);
   1.421 +}
   1.422 +
   1.423 +void
   1.424 +Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
   1.425 +{
   1.426 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.427 +    NSString *string;
   1.428 +
   1.429 +    string = [[NSString alloc] initWithUTF8String:window->title];
   1.430 +    [nswindow setTitle:string];
   1.431 +    [nswindow setMiniwindowTitle:string];
   1.432 +    [string release];
   1.433 +}
   1.434 +
   1.435 +void
   1.436 +Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
   1.437 +{
   1.438 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.439 +    NSRect rect;
   1.440 +
   1.441 +    rect.origin.x = window->x;
   1.442 +    rect.origin.y = window->y;
   1.443 +    rect.size.width = window->w;
   1.444 +    rect.size.height = window->h;
   1.445 +    ConvertNSRect(&rect);
   1.446 +    rect = [nswindow frameRectForContentRect:rect];
   1.447 +    [nswindow setFrameOrigin:rect.origin];
   1.448 +}
   1.449 +
   1.450 +void
   1.451 +Cocoa_SetWindowSize(_THIS, SDL_Window * window)
   1.452 +{
   1.453 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.454 +    NSSize size;
   1.455 +
   1.456 +    size.width = window->w;
   1.457 +    size.height = window->h;
   1.458 +    [nswindow setContentSize:size];
   1.459 +}
   1.460 +
   1.461 +void
   1.462 +Cocoa_ShowWindow(_THIS, SDL_Window * window)
   1.463 +{
   1.464 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.465 +
   1.466 +    [nswindow makeKeyAndOrderFront:nil];
   1.467 +}
   1.468 +
   1.469 +void
   1.470 +Cocoa_HideWindow(_THIS, SDL_Window * window)
   1.471 +{
   1.472 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.473 +
   1.474 +    /* FIXME */
   1.475 +}
   1.476 +
   1.477 +void
   1.478 +Cocoa_RaiseWindow(_THIS, SDL_Window * window)
   1.479 +{
   1.480 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.481 +
   1.482 +    [nswindow makeKeyAndOrderFront:nil];
   1.483 +}
   1.484 +
   1.485 +void
   1.486 +Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
   1.487 +{
   1.488 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.489 +
   1.490 +    [nswindow performZoom:nil];
   1.491 +}
   1.492 +
   1.493 +void
   1.494 +Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
   1.495 +{
   1.496 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.497 +
   1.498 +    [nswindow performMiniaturize:nil];
   1.499 +}
   1.500 +
   1.501 +void
   1.502 +Cocoa_RestoreWindow(_THIS, SDL_Window * window)
   1.503 +{
   1.504 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.505 +
   1.506 +    /* FIXME */
   1.507 +}
   1.508 +
   1.509 +void
   1.510 +Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
   1.511 +{
   1.512 +    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
   1.513 +        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   1.514 +        /* FIXME: Grab mouse */
   1.515 +    } else {
   1.516 +        /* FIXME: Release mouse */
   1.517 +    }
   1.518 +}
   1.519 +
   1.520 +void
   1.521 +Cocoa_DestroyWindow(_THIS, SDL_Window * window)
   1.522 +{
   1.523 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.524 +
   1.525 +    if (data) {
   1.526 +        NSAutoreleasePool *pool;
   1.527 +#ifdef SDL_VIDEO_OPENGL
   1.528 +        /*
   1.529 +        if (window->flags & SDL_WINDOW_OPENGL) {
   1.530 +            Cocoa_GL_CleanupWindow(_this, window);
   1.531 +        }
   1.532 +        */
   1.533 +#endif
   1.534 +        pool = [[NSAutoreleasePool alloc] init];
   1.535 +        [data->listener close];
   1.536 +        [data->listener release];
   1.537 +        if (data->created) {
   1.538 +            [data->window close];
   1.539 +        }
   1.540 +        SDL_free(data);
   1.541 +        [pool release];
   1.542 +    }
   1.543 +}
   1.544 +
   1.545 +SDL_bool
   1.546 +Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   1.547 +{
   1.548 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
   1.549 +
   1.550 +    if (info->version.major <= SDL_MAJOR_VERSION) {
   1.551 +        //info->window = nswindow;
   1.552 +        return SDL_TRUE;
   1.553 +    } else {
   1.554 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
   1.555 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   1.556 +        return SDL_FALSE;
   1.557 +    }
   1.558 +}
   1.559 +
   1.560 +/* vi: set ts=4 sw=4 expandtab: */