Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Backed out use of @autorelease keyword for now, since it's not suppor…
Browse files Browse the repository at this point in the history
…ted by older Xcode versions.
  • Loading branch information
slouken committed Feb 12, 2013
1 parent 659da0b commit f7ddc3c
Show file tree
Hide file tree
Showing 11 changed files with 763 additions and 692 deletions.
35 changes: 19 additions & 16 deletions src/file/cocoa/SDL_rwopsbundlesupport.m
Expand Up @@ -20,22 +20,25 @@
return fopen(file, mode);
}

@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])
{
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
}
else
{
fp = fopen(file, mode);
}
}
NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];


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])
{
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
}
else
{
fp = fopen(file, mode);
}

[autorelease_pool drain];

return fp;
}
Expand Down
70 changes: 39 additions & 31 deletions src/video/cocoa/SDL_cocoaclipboard.m
Expand Up @@ -45,46 +45,51 @@
Cocoa_SetClipboardText(_THIS, const char *text)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

NSAutoreleasePool *pool;
NSPasteboard *pasteboard;
NSString *format = GetTextFormat(_this);

@autoreleasepool {
pasteboard = [NSPasteboard generalPasteboard];
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
}

pool = [[NSAutoreleasePool alloc] init];

pasteboard = [NSPasteboard generalPasteboard];
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:text] forType:format];

[pool release];

return 0;
}

char *
Cocoa_GetClipboardText(_THIS)
{
NSAutoreleasePool *pool;
NSPasteboard *pasteboard;
NSString *format = GetTextFormat(_this);
NSString *available;
char *text;

@autoreleasepool {
pasteboard = [NSPasteboard generalPasteboard];
available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
if ([available isEqualToString:format]) {
NSString* string;
const char *utf8;

string = [pasteboard stringForType:format];
if (string == nil) {
utf8 = "";
} else {
utf8 = [string UTF8String];
}
text = SDL_strdup(utf8);
pool = [[NSAutoreleasePool alloc] init];

pasteboard = [NSPasteboard generalPasteboard];
available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
if ([available isEqualToString:format]) {
NSString* string;
const char *utf8;

string = [pasteboard stringForType:format];
if (string == nil) {
utf8 = "";
} else {
text = SDL_strdup("");
utf8 = [string UTF8String];
}
text = SDL_strdup(utf8);
} else {
text = SDL_strdup("");
}


[pool release];

return text;
}

Expand All @@ -103,19 +108,22 @@
void
Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
{
NSAutoreleasePool *pool;
NSPasteboard *pasteboard;
NSInteger count;

@autoreleasepool {
pasteboard = [NSPasteboard generalPasteboard];
count = [pasteboard changeCount];
if (count != data->clipboard_count) {
if (data->clipboard_count) {
SDL_SendClipboardUpdate();
}
data->clipboard_count = count;
pool = [[NSAutoreleasePool alloc] init];

pasteboard = [NSPasteboard generalPasteboard];
count = [pasteboard changeCount];
if (count != data->clipboard_count) {
if (data->clipboard_count) {
SDL_SendClipboardUpdate();
}
data->clipboard_count = count;
}

[pool release];
}

#endif /* SDL_VIDEO_DRIVER_COCOA */
Expand Down
85 changes: 44 additions & 41 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -159,30 +159,33 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
{
/* This can get called more than once! Be careful what you initialize! */
ProcessSerialNumber psn;
NSAutoreleasePool *pool;

if (!GetCurrentProcess(&psn)) {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
SetFrontProcess(&psn);
}

@autoreleasepool {
if (NSApp == nil) {
[NSApplication sharedApplication];
pool = [[NSAutoreleasePool alloc] init];
if (NSApp == nil) {
[NSApplication sharedApplication];

if ([NSApp mainMenu] == nil) {
CreateApplicationMenus();
}
[NSApp finishLaunching];
}
if ([NSApp delegate] == nil) {
[NSApp setDelegate:[[SDLAppDelegate alloc] init]];
if ([NSApp mainMenu] == nil) {
CreateApplicationMenus();
}
[NSApp finishLaunching];
}
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;
Expand All @@ -194,39 +197,39 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
}
}

@autoreleasepool {
for ( ; ; ) {
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
if ( event == nil ) {
break;
}

switch ([event type]) {
case NSLeftMouseDown:
case NSOtherMouseDown:
case NSRightMouseDown:
case NSLeftMouseUp:
case NSOtherMouseUp:
case NSRightMouseUp:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */
case NSMouseMoved:
case NSScrollWheel:
Cocoa_HandleMouseEvent(_this, event);
break;
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
Cocoa_HandleKeyEvent(_this, event);
break;
default:
break;
}
/* Pass through to NSApp to make sure everything stays in sync */
[NSApp sendEvent:event];
pool = [[NSAutoreleasePool alloc] init];
for ( ; ; ) {
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
if ( event == nil ) {
break;
}

switch ([event type]) {
case NSLeftMouseDown:
case NSOtherMouseDown:
case NSRightMouseDown:
case NSLeftMouseUp:
case NSOtherMouseUp:
case NSRightMouseUp:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */
case NSMouseMoved:
case NSScrollWheel:
Cocoa_HandleMouseEvent(_this, event);
break;
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
Cocoa_HandleKeyEvent(_this, event);
break;
default:
break;
}
/* Pass through to NSApp to make sure everything stays in sync */
[NSApp sendEvent:event];
}
[pool release];
}

#endif /* SDL_VIDEO_DRIVER_COCOA */
Expand Down
49 changes: 25 additions & 24 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -625,27 +625,28 @@ - (NSArray *) validAttributesForMarkedText
Cocoa_StartTextInput(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
@autoreleasepool {
NSView *parentView = [[NSApp keyWindow] contentView];

/* We only keep one field editor per process, since only the front most
* window can receive text input events, so it make no sense to keep more
* than one copy. When we switched to another window and requesting for
* text input, simply remove the field editor from its superview then add
* it to the front most window's content view */
if (!data->fieldEdit) {
data->fieldEdit =
[[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSView *parentView = [[NSApp keyWindow] contentView];

/* We only keep one field editor per process, since only the front most
* window can receive text input events, so it make no sense to keep more
* than one copy. When we switched to another window and requesting for
* text input, simply remove the field editor from its superview then add
* it to the front most window's content view */
if (!data->fieldEdit) {
data->fieldEdit =
[[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
}

if (![[data->fieldEdit superview] isEqual: parentView])
{
// DEBUG_IME(@"add fieldEdit to window contentView");
[data->fieldEdit removeFromSuperview];
[parentView addSubview: data->fieldEdit];
[[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
}
if (![[data->fieldEdit superview] isEqual: parentView])
{
// DEBUG_IME(@"add fieldEdit to window contentView");
[data->fieldEdit removeFromSuperview];
[parentView addSubview: data->fieldEdit];
[[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
}

[pool release];
}

void
Expand All @@ -654,11 +655,11 @@ - (NSArray *) validAttributesForMarkedText
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

if (data && data->fieldEdit) {
@autoreleasepool {
[data->fieldEdit removeFromSuperview];
[data->fieldEdit release];
data->fieldEdit = nil;
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[data->fieldEdit removeFromSuperview];
[data->fieldEdit release];
data->fieldEdit = nil;
[pool release];
}
}

Expand Down
56 changes: 29 additions & 27 deletions src/video/cocoa/SDL_cocoamessagebox.m
Expand Up @@ -39,38 +39,40 @@
{
Cocoa_RegisterApp();

@autoreleasepool {
NSAlert* alert = [[NSAlert alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
[alert setAlertStyle:NSCriticalAlertStyle];
} else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
[alert setAlertStyle:NSWarningAlertStyle];
NSAlert* alert = [[NSAlert alloc] init];

if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
[alert setAlertStyle:NSCriticalAlertStyle];
} else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
[alert setAlertStyle:NSWarningAlertStyle];
} else {
[alert setAlertStyle:NSInformationalAlertStyle];
}

[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];

const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
int i;
for (i = 0; i < messageboxdata->numbuttons; ++i) {
NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
[button setKeyEquivalent:@"\r"];
} else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
[button setKeyEquivalent:@"\033"];
} else {
[alert setAlertStyle:NSInformationalAlertStyle];
[button setKeyEquivalent:@""];
}
}

[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];

const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
int i;
for (i = 0; i < messageboxdata->numbuttons; ++i) {
NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
[button setKeyEquivalent:@"\r"];
} else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
[button setKeyEquivalent:@"\033"];
} else {
[button setKeyEquivalent:@""];
}
}
NSInteger clicked = [alert runModal];
clicked -= NSAlertFirstButtonReturn;
*buttonid = buttons[clicked].buttonid;
[alert release];

NSInteger clicked = [alert runModal];
clicked -= NSAlertFirstButtonReturn;
*buttonid = buttons[clicked].buttonid;
[alert release];
}
[pool release];

return 0;
}
Expand Down

0 comments on commit f7ddc3c

Please sign in to comment.