src/video/cocoa/SDL_cocoamessagebox.m
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Feb 2013 00:54:08 -0800
changeset 6836 b0ca1571caf3
parent 6832 156e608ec4ef
child 6848 478ecc8a58b3
permissions -rw-r--r--
Fixed bug 1689 - Leaks galore in OS X Cocoa code.

Edward Rudd

This is to document the various leaks I'm finding in the Cocoa code in SDL 2.
slouken@6617
     1
/*
slouken@6617
     2
  Simple DirectMedia Layer
slouken@6617
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@6617
     4
slouken@6617
     5
  This software is provided 'as-is', without any express or implied
slouken@6617
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@6617
     7
  arising from the use of this software.
slouken@6617
     8
slouken@6617
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@6617
    10
  including commercial applications, and to alter it and redistribute it
slouken@6617
    11
  freely, subject to the following restrictions:
slouken@6617
    12
slouken@6617
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@6617
    14
     claim that you wrote the original software. If you use this software
slouken@6617
    15
     in a product, an acknowledgment in the product documentation would be
slouken@6617
    16
     appreciated but is not required.
slouken@6617
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@6617
    18
     misrepresented as being the original software.
slouken@6617
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@6617
    20
*/
slouken@6617
    21
#include "SDL_config.h"
slouken@6617
    22
slouken@6617
    23
#if SDL_VIDEO_DRIVER_COCOA
slouken@6617
    24
icculus@6624
    25
#if defined(__APPLE__) && defined(__POWERPC__)
icculus@6624
    26
#include <altivec.h>
icculus@6624
    27
#undef bool
icculus@6624
    28
#undef vector
icculus@6626
    29
#undef pixel
icculus@6624
    30
#endif
icculus@6624
    31
slouken@6623
    32
#include "SDL_messagebox.h"
slouken@6617
    33
#include "SDL_cocoavideo.h"
slouken@6617
    34
slouken@6617
    35
slouken@6617
    36
/* Display a Cocoa message box */
slouken@6617
    37
int
slouken@6617
    38
Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
slouken@6617
    39
{
icculus@6639
    40
    Cocoa_RegisterApp();
icculus@6639
    41
alexey@6832
    42
    @autoreleasepool {
alexey@6832
    43
        NSAlert* alert = [[NSAlert alloc] init];
slouken@6617
    44
alexey@6832
    45
        if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
alexey@6832
    46
            [alert setAlertStyle:NSCriticalAlertStyle];
alexey@6832
    47
        } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
alexey@6832
    48
            [alert setAlertStyle:NSWarningAlertStyle];
alexey@6832
    49
        } else {
alexey@6832
    50
            [alert setAlertStyle:NSInformationalAlertStyle];
alexey@6832
    51
        }
slouken@6617
    52
alexey@6832
    53
        [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
alexey@6832
    54
        [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
alexey@6832
    55
alexey@6832
    56
        const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
alexey@6832
    57
        int i;
alexey@6832
    58
        for (i = 0; i < messageboxdata->numbuttons; ++i) {
slouken@6836
    59
            NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
alexey@6832
    60
            if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
alexey@6832
    61
                [button setKeyEquivalent:@"\r"];
alexey@6832
    62
            } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
alexey@6832
    63
                [button setKeyEquivalent:@"\033"];
alexey@6832
    64
            } else {
alexey@6832
    65
                [button setKeyEquivalent:@""];
alexey@6832
    66
            }
alexey@6832
    67
        }
alexey@6832
    68
alexey@6832
    69
        NSInteger clicked = [alert runModal];
alexey@6832
    70
        clicked -= NSAlertFirstButtonReturn;
alexey@6832
    71
        *buttonid = buttons[clicked].buttonid;
alexey@6832
    72
        [alert release];
slouken@6617
    73
    }
slouken@6617
    74
slouken@6617
    75
    return 0;
slouken@6617
    76
}
slouken@6617
    77
slouken@6617
    78
#endif /* SDL_VIDEO_DRIVER_COCOA */
slouken@6617
    79
slouken@6617
    80
/* vi: set ts=4 sw=4 expandtab: */