Replaced manual NSAutoreleasePool handing with @autorelease
This commit is contained in:
parent
e1f76ef0ea
commit
929560081c
11 changed files with 699 additions and 769 deletions
|
@ -20,9 +20,7 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
|
|||
return fopen(file, mode);
|
||||
}
|
||||
|
||||
NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
@autoreleasepool {
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
NSString* resource_path = [[NSBundle mainBundle] resourcePath];
|
||||
|
||||
|
@ -37,8 +35,7 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
|
|||
{
|
||||
fp = fopen(file, mode);
|
||||
}
|
||||
|
||||
[autorelease_pool drain];
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
|
|
@ -45,17 +45,15 @@ int
|
|||
Cocoa_SetClipboardText(_THIS, const char *text)
|
||||
{
|
||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
NSPasteboard *pasteboard;
|
||||
NSString *format = GetTextFormat(_this);
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
pasteboard = [NSPasteboard generalPasteboard];
|
||||
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
|
||||
[pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -63,14 +61,12 @@ Cocoa_SetClipboardText(_THIS, const char *text)
|
|||
char *
|
||||
Cocoa_GetClipboardText(_THIS)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSPasteboard *pasteboard;
|
||||
NSString *format = GetTextFormat(_this);
|
||||
NSString *available;
|
||||
char *text;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
pasteboard = [NSPasteboard generalPasteboard];
|
||||
available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
|
||||
if ([available isEqualToString:format]) {
|
||||
|
@ -87,8 +83,7 @@ Cocoa_GetClipboardText(_THIS)
|
|||
} else {
|
||||
text = SDL_strdup("");
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
@ -108,12 +103,10 @@ Cocoa_HasClipboardText(_THIS)
|
|||
void
|
||||
Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSPasteboard *pasteboard;
|
||||
NSInteger count;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
pasteboard = [NSPasteboard generalPasteboard];
|
||||
count = [pasteboard changeCount];
|
||||
if (count != data->clipboard_count) {
|
||||
|
@ -122,8 +115,7 @@ Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
|
|||
}
|
||||
data->clipboard_count = count;
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
|
|
@ -158,14 +158,13 @@ Cocoa_RegisterApp(void)
|
|||
{
|
||||
/* This can get called more than once! Be careful what you initialize! */
|
||||
ProcessSerialNumber psn;
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
if (!GetCurrentProcess(&psn)) {
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
SetFrontProcess(&psn);
|
||||
}
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
if (NSApp == nil) {
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
|
@ -177,14 +176,12 @@ Cocoa_RegisterApp(void)
|
|||
if ([NSApp delegate] == nil) {
|
||||
[NSApp setDelegate:[[SDLAppDelegate alloc] init]];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_PumpEvents(_THIS)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
/* Update activity every 30 seconds to prevent screensaver */
|
||||
if (_this->suspend_screensaver) {
|
||||
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
|
||||
|
@ -196,7 +193,7 @@ Cocoa_PumpEvents(_THIS)
|
|||
}
|
||||
}
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
for ( ; ; ) {
|
||||
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
|
||||
if ( event == nil ) {
|
||||
|
@ -228,7 +225,7 @@ Cocoa_PumpEvents(_THIS)
|
|||
/* Pass through to NSApp to make sure everything stays in sync */
|
||||
[NSApp sendEvent:event];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
|
|
@ -625,7 +625,7 @@ void
|
|||
Cocoa_StartTextInput(_THIS)
|
||||
{
|
||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSView *parentView = [[NSApp keyWindow] contentView];
|
||||
|
||||
/* We only keep one field editor per process, since only the front most
|
||||
|
@ -645,8 +645,7 @@ Cocoa_StartTextInput(_THIS)
|
|||
[parentView addSubview: data->fieldEdit];
|
||||
[[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -655,11 +654,11 @@ Cocoa_StopTextInput(_THIS)
|
|||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||
|
||||
if (data && data->fieldEdit) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
[data->fieldEdit removeFromSuperview];
|
||||
[data->fieldEdit release];
|
||||
data->fieldEdit = nil;
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,7 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
{
|
||||
Cocoa_RegisterApp();
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
NSAlert* alert = [[NSAlert alloc] init];
|
||||
|
||||
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
|
||||
|
@ -71,8 +70,7 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
clicked -= NSAlertFirstButtonReturn;
|
||||
*buttonid = buttons[clicked].buttonid;
|
||||
[alert release];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
static SDL_Cursor *
|
||||
Cocoa_CreateDefaultCursor()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSCursor *nscursor;
|
||||
SDL_Cursor *cursor = NULL;
|
||||
|
||||
|
@ -46,15 +46,14 @@ Cocoa_CreateDefaultCursor()
|
|||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
return cursor;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSImage *nsimage;
|
||||
NSCursor *nscursor = NULL;
|
||||
SDL_Cursor *cursor = NULL;
|
||||
|
@ -71,15 +70,14 @@ Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
|||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
return cursor;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Cocoa_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSCursor *nscursor = NULL;
|
||||
SDL_Cursor *cursor = NULL;
|
||||
|
||||
|
@ -133,28 +131,25 @@ Cocoa_CreateSystemCursor(SDL_SystemCursor id)
|
|||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
return cursor;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Cocoa_FreeCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSCursor *nscursor = (NSCursor *)cursor->driverdata;
|
||||
|
||||
[nscursor release];
|
||||
SDL_free(cursor);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Cocoa_ShowCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
if (cursor) {
|
||||
NSCursor *nscursor = (NSCursor *)cursor->driverdata;
|
||||
|
||||
|
@ -163,8 +158,7 @@ Cocoa_ShowCursor(SDL_Cursor * cursor)
|
|||
} else {
|
||||
[NSCursor hide];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,6 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
const int wantver = (_this->gl_config.major_version << 8) |
|
||||
(_this->gl_config.minor_version);
|
||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||
NSAutoreleasePool *pool;
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
NSOpenGLPixelFormatAttribute attr[32];
|
||||
|
@ -100,8 +99,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
/* specify a profile if we're on Lion (10.7) or later. */
|
||||
if (data->osversion >= 0x1070) {
|
||||
NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
|
||||
|
@ -114,11 +112,11 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
attr[i++] = profile;
|
||||
}
|
||||
|
||||
#ifndef FULLSCREEN_TOGGLEABLE
|
||||
#ifndef FULLSCREEN_TOGGLEABLE
|
||||
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
||||
attr[i++] = NSOpenGLPFAFullScreen;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
attr[i++] = NSOpenGLPFAColorSize;
|
||||
attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
|
||||
|
@ -174,7 +172,6 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
||||
if (fmt == nil) {
|
||||
SDL_SetError ("Failed creating OpenGL pixel format");
|
||||
[pool release];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -184,7 +181,6 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
|
||||
if (context == nil) {
|
||||
SDL_SetError ("Failed creating OpenGL context");
|
||||
[pool release];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -210,11 +206,9 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
|
||||
CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
|
||||
}
|
||||
|
||||
}
|
||||
/* End Wisdom from Apple Engineer section. --ryan. */
|
||||
|
||||
[pool release];
|
||||
|
||||
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
|
||||
Cocoa_GL_DeleteContext(_this, context);
|
||||
return NULL;
|
||||
|
@ -226,20 +220,17 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
int
|
||||
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
if (context) {
|
||||
SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
|
||||
NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
|
||||
|
||||
if (window->flags & SDL_WINDOW_SHOWN) {
|
||||
#ifndef FULLSCREEN_TOGGLEABLE
|
||||
#ifndef FULLSCREEN_TOGGLEABLE
|
||||
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
||||
[nscontext setFullScreen];
|
||||
} else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
[nscontext setView:[windowdata->nswindow contentView]];
|
||||
[nscontext update];
|
||||
|
@ -249,21 +240,19 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
|||
} else {
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Cocoa_GL_SetSwapInterval(_THIS, int interval)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSOpenGLContext *nscontext;
|
||||
GLint value;
|
||||
int status;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
nscontext = [NSOpenGLContext currentContext];
|
||||
if (nscontext != nil) {
|
||||
value = interval;
|
||||
|
@ -273,60 +262,52 @@ Cocoa_GL_SetSwapInterval(_THIS, int interval)
|
|||
SDL_SetError("No current OpenGL context");
|
||||
status = -1;
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
Cocoa_GL_GetSwapInterval(_THIS)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSOpenGLContext *nscontext;
|
||||
GLint value;
|
||||
int status = 0;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
nscontext = [NSOpenGLContext currentContext];
|
||||
if (nscontext != nil) {
|
||||
[nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
|
||||
status = (int)value;
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSOpenGLContext *nscontext;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
/* FIXME: Do we need to get the context for the window? */
|
||||
nscontext = [NSOpenGLContext currentContext];
|
||||
if (nscontext != nil) {
|
||||
[nscontext flushBuffer];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
[nscontext clearDrawable];
|
||||
[nscontext release];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_OPENGL_CGL */
|
||||
|
|
|
@ -74,7 +74,7 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape
|
|||
SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
|
||||
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
|
||||
SDL_CocoaClosure closure;
|
||||
NSAutoreleasePool *pool = NULL;
|
||||
|
||||
if(data->saved == SDL_TRUE) {
|
||||
[data->context restoreGraphicsState];
|
||||
data->saved = SDL_FALSE;
|
||||
|
@ -88,12 +88,13 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape
|
|||
NSRectFill([[windata->nswindow contentView] frame]);
|
||||
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
closure.view = [windata->nswindow contentView];
|
||||
closure.path = [[NSBezierPath bezierPath] autorelease];
|
||||
closure.window = shaper->window;
|
||||
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
|
||||
[closure.path addClip];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -250,8 +250,7 @@ SDL_PromptAssertion_cocoa(const SDL_assert_data *data)
|
|||
}
|
||||
}
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
NSString *msg = [NSString stringWithFormat:
|
||||
@"Assertion failure at %s (%s:%d), triggered %u time%s:\n '%s'",
|
||||
data->function, data->filename, data->linenum,
|
||||
|
@ -274,13 +273,13 @@ SDL_PromptAssertion_cocoa(const SDL_assert_data *data)
|
|||
[alert addButtonWithTitle:@"Ignore"];
|
||||
[alert addButtonWithTitle:@"Always Ignore"];
|
||||
const NSInteger clicked = [alert runModal];
|
||||
[pool release];
|
||||
|
||||
if (!initialized) {
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
}
|
||||
|
||||
return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
|
|
@ -507,7 +507,6 @@ GetWindowStyle(SDL_Window * window)
|
|||
static int
|
||||
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
||||
SDL_WindowData *data;
|
||||
|
||||
|
@ -522,8 +521,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
|||
data->created = created;
|
||||
data->videodata = videodata;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
/* Create an event listener for the window */
|
||||
data->listener = [[Cocoa_WindowListener alloc] init];
|
||||
|
||||
|
@ -576,15 +574,15 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
|||
}
|
||||
|
||||
/* All done! */
|
||||
[pool release];
|
||||
window->driverdata = data;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow;
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
NSRect rect;
|
||||
|
@ -625,31 +623,27 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
|||
[nswindow setContentView: contentView];
|
||||
[contentView release];
|
||||
|
||||
[pool release];
|
||||
|
||||
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
|
||||
[nswindow release];
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSWindow *nswindow = (NSWindow *) data;
|
||||
NSString *title;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
/* Query the title from the existing window */
|
||||
title = [nswindow title];
|
||||
if (title) {
|
||||
window->title = SDL_strdup([title UTF8String]);
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
return SetupWindowData(_this, window, nswindow, SDL_FALSE);
|
||||
}
|
||||
|
@ -657,7 +651,7 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
|||
void
|
||||
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
NSString *string;
|
||||
|
||||
|
@ -668,27 +662,25 @@ Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
|
|||
}
|
||||
[nswindow setTitle:string];
|
||||
[string release];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSImage *nsimage = Cocoa_CreateImage(icon);
|
||||
|
||||
if (nsimage) {
|
||||
[NSApp setApplicationIconImage:nsimage];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
NSRect rect;
|
||||
Uint32 moveHack;
|
||||
|
@ -707,14 +699,13 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
|
|||
if (window == _this->current_glwin) {
|
||||
[((NSOpenGLContext *) _this->current_glctx) update];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = windata->nswindow;
|
||||
NSSize size;
|
||||
|
@ -726,14 +717,13 @@ Cocoa_SetWindowSize(_THIS, SDL_Window * window)
|
|||
if (window == _this->current_glwin) {
|
||||
[((NSOpenGLContext *) _this->current_glctx) update];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
NSSize minSize;
|
||||
|
@ -741,14 +731,13 @@ Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
|||
minSize.height = window->min_h;
|
||||
|
||||
[windata->nswindow setContentMinSize:minSize];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
NSSize maxSize;
|
||||
|
@ -756,71 +745,65 @@ Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
|
|||
maxSize.height = window->max_h;
|
||||
|
||||
[windata->nswindow setContentMaxSize:maxSize];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_ShowWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
if (![nswindow isMiniaturized]) {
|
||||
[nswindow makeKeyAndOrderFront:nil];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_HideWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
[nswindow orderOut:nil];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
[nswindow makeKeyAndOrderFront:nil];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
[nswindow zoom:nil];
|
||||
|
||||
if (window == _this->current_glwin) {
|
||||
[((NSOpenGLContext *) _this->current_glctx) update];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
[nswindow miniaturize:nil];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
if ([nswindow isMiniaturized]) {
|
||||
|
@ -828,7 +811,7 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window)
|
|||
} else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
||||
[nswindow zoom:nil];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
static NSWindow *
|
||||
|
@ -854,7 +837,7 @@ Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
|||
{
|
||||
/* this message arrived in 10.6. You're out of luck on older OSes. */
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
|
||||
[nswindow setStyleMask:GetWindowStyle(window)];
|
||||
|
@ -862,14 +845,14 @@ Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
|||
Cocoa_SetWindowTitle(_this, window); // this got blanked out.
|
||||
}
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = data->nswindow;
|
||||
NSRect rect;
|
||||
|
@ -929,21 +912,20 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
|||
Cocoa_SetWindowTitle(_this, window);
|
||||
}
|
||||
|
||||
#ifdef FULLSCREEN_TOGGLEABLE
|
||||
#ifdef FULLSCREEN_TOGGLEABLE
|
||||
if (SDL_ShouldAllowTopmost() && fullscreen) {
|
||||
/* OpenGL is rendering to the window, so make it visible! */
|
||||
[nswindow setLevel:CGShieldingWindowLevel()];
|
||||
} else {
|
||||
[nswindow setLevel:kCGNormalWindowLevel];
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
[nswindow makeKeyAndOrderFront:nil];
|
||||
|
||||
if (window == _this->current_glwin) {
|
||||
[((NSOpenGLContext *) _this->current_glctx) update];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1027,7 +1009,7 @@ Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
|
|||
void
|
||||
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if (data) {
|
||||
|
@ -1038,7 +1020,7 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
|||
}
|
||||
SDL_free(data);
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
|
|
|
@ -21,30 +21,23 @@ FILE* TestSupportRWops_OpenFPFromReadDir(const char *file, const char *mode)
|
|||
FILE* fp = NULL;
|
||||
|
||||
// If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only.
|
||||
if(strcmp("r", mode) && strcmp("rb", mode))
|
||||
{
|
||||
if (strcmp("r", mode) && strcmp("rb", mode)) {
|
||||
return fopen(file, mode);
|
||||
}
|
||||
|
||||
NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
@autoreleasepool {
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
NSString* resource_path = [[NSBundle mainBundle] resourcePath];
|
||||
|
||||
NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
|
||||
|
||||
NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
|
||||
if([file_manager fileExistsAtPath:full_path_with_file_to_try])
|
||||
{
|
||||
if ([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
|
||||
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fp = fopen(file, mode);
|
||||
}
|
||||
|
||||
[autorelease_pool drain];
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
@ -53,15 +46,13 @@ FILE* TestSupportRWops_OpenFPFromWriteDir(const char *file, const char *mode)
|
|||
{
|
||||
FILE* fp = NULL;
|
||||
|
||||
NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
|
||||
NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
|
||||
|
||||
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
|
||||
|
||||
[autorelease_pool drain];
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
@ -75,15 +66,14 @@ SDL_RWops* TestSupportRWops_OpenRWopsFromWriteDir(const char *file, const char *
|
|||
{
|
||||
SDL_RWops* rw = NULL;
|
||||
|
||||
NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
|
||||
NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
|
||||
|
||||
rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
|
||||
}
|
||||
|
||||
[autorelease_pool drain];
|
||||
return rw;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue