src/video/cocoa/SDL_cocoaevents.m
author Jørgen P. Tjernø <jorgen@valvesoftware.com>
Mon, 07 Oct 2013 16:01:40 -0700
changeset 7801 f00cc0a8cd5d
parent 7739 329c9da4bfeb
child 7857 6388f5229bb7
permissions -rw-r--r--
Mac: Better handling when someone else is the app delegate.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6848
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
     7
  arising from the use of this software.
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    11
  freely, subject to the following restrictions:
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5377
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    22
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#if SDL_VIDEO_DRIVER_COCOA
3120
1282a042d530 Temporary workaround for building on 64-bit Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
    24
#include "SDL_timer.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_cocoavideo.h"
2738
79c1bd651f04 Fixed a bunch of compile warnings on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
    27
#include "../../events/SDL_events_c.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
3624
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    29
#if !defined(UsrActivity) && defined(__LP64__) && !defined(__POWER__)
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    30
/*
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    31
 * Workaround for a bug in the 10.5 SDK: By accident, OSService.h does
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    32
 * not include Power.h at all when compiling in 64bit mode. This has
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    33
 * been fixed in 10.6, but for 10.5, we manually define UsrActivity
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    34
 * to ensure compilation works.
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    35
 */
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    36
#define UsrActivity 1
9b1af1049f66 Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3517
diff changeset
    37
#endif
3120
1282a042d530 Temporary workaround for building on 64-bit Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
    38
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
/* setAppleMenu disappeared from the headers in 10.4 */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
@interface NSApplication(NSAppleMenu)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
- (void)setAppleMenu:(NSMenu *)menu;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
@end
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
7469
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    44
@interface SDLAppDelegate : NSObject {
7801
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    45
@public
7469
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    46
    BOOL seenFirstActivate;
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    47
}
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    48
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    49
- (id)init;
1937
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    50
@end
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    51
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    52
@implementation SDLAppDelegate : NSObject
7469
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    53
- (id)init
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    54
{
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    55
    self = [super init];
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    56
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    57
    if (self) {
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    58
        seenFirstActivate = NO;
7801
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    59
        [[NSNotificationCenter defaultCenter] addObserver:self
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    60
                                                 selector:@selector(focusSomeWindow:)
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    61
                                                     name:NSApplicationDidBecomeActiveNotification
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    62
                                                   object:nil];
7469
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    63
    }
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    64
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    65
    return self;
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    66
}
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    67
7801
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    68
- (void)dealloc
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    69
{
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    70
    [[NSNotificationCenter defaultCenter] removeObserver:self];
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    71
    [super dealloc];
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    72
}
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    73
1937
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    74
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    75
{
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    76
    SDL_SendQuit();
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    77
    return NSTerminateCancel;
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    78
}
6091
61fa4f3238c5 First pass at a simple drag and drop API, allowing you to accept files dropped into your application.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    79
7801
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
    80
- (void)focusSomeWindow:(NSNotification *)aNotification
7466
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    81
{
7469
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    82
    /* HACK: Ignore the first call. The application gets a
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    83
     * applicationDidBecomeActive: a little bit after the first window is
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    84
     * created, and if we don't ignore it, a window that has been created with
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    85
     * SDL_WINDOW_MINIZED will ~immediately be restored.
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    86
     */
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    87
    if (!seenFirstActivate) {
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    88
        seenFirstActivate = YES;
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    89
        return;
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    90
    }
4310d5aee6fe Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7466
diff changeset
    91
7466
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    92
    SDL_VideoDevice *device = SDL_GetVideoDevice();
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    93
    if (device && device->windows)
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    94
    {
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    95
        SDL_Window *window = device->windows;
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    96
        int i;
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    97
        for (i = 0; i < device->num_displays; ++i)
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    98
        {
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
    99
            SDL_Window *fullscreen_window = device->displays[i].fullscreen_window;
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   100
            if (fullscreen_window)
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   101
            {
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   102
                if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   103
                    SDL_RestoreWindow(fullscreen_window);
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   104
                }
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   105
                return;
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   106
            }
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   107
        }
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   108
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   109
        if (window->flags & SDL_WINDOW_MINIMIZED) {
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   110
            SDL_RestoreWindow(window);
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   111
        } else {
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   112
            SDL_RaiseWindow(window);
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   113
        }
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   114
    }
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   115
}
3416e8cfbaf0 Mac: Bring back FS windows when appropriate
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7191
diff changeset
   116
6091
61fa4f3238c5 First pass at a simple drag and drop API, allowing you to accept files dropped into your application.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   117
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
61fa4f3238c5 First pass at a simple drag and drop API, allowing you to accept files dropped into your application.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   118
{
61fa4f3238c5 First pass at a simple drag and drop API, allowing you to accept files dropped into your application.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   119
    return (BOOL)SDL_SendDropFile([filename UTF8String]);
61fa4f3238c5 First pass at a simple drag and drop API, allowing you to accept files dropped into your application.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   120
}
1937
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   121
@end
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   122
7801
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   123
static SDLAppDelegate *appDelegate = nil;
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   124
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
static NSString *
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
GetApplicationName(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
    NSDictionary *dict;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
    NSString *appName = 0;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    /* Determine the application name */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
    dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
    if (dict)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
        appName = [dict objectForKey: @"CFBundleName"];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   135
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
    if (![appName length])
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
        appName = [[NSProcessInfo processInfo] processName];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
    return appName;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
static void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
CreateApplicationMenus(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    NSString *appName;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
    NSString *title;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
    NSMenu *appleMenu;
6515
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   148
    NSMenu *serviceMenu;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
    NSMenu *windowMenu;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    NSMenuItem *menuItem;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   151
7511
4ce3cc948a00 A little cleanup on the cleanup, just for consistency.
Sam Lantinga <slouken@libsdl.org>
parents: 7508
diff changeset
   152
    if (NSApp == nil) {
7508
1f64c6874619 Fix some clang analyzer warnings.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7469
diff changeset
   153
        return;
1f64c6874619 Fix some clang analyzer warnings.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7469
diff changeset
   154
    }
1f64c6874619 Fix some clang analyzer warnings.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7469
diff changeset
   155
    
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    /* Create the main menu bar */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
    [NSApp setMainMenu:[[NSMenu alloc] init]];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    /* Create the application menu */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    appName = GetApplicationName();
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    appleMenu = [[NSMenu alloc] initWithTitle:@""];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   162
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
    /* Add menu items */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    title = [@"About " stringByAppendingString:appName];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    [appleMenu addItem:[NSMenuItem separatorItem]];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
6515
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   169
    [appleMenu addItemWithTitle:@"Preferences…" action:nil keyEquivalent:@","];
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   170
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   171
    [appleMenu addItem:[NSMenuItem separatorItem]];
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   172
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   173
    serviceMenu = [[NSMenu alloc] initWithTitle:@""];
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   174
    menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   175
    [menuItem setSubmenu:serviceMenu];
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   176
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   177
    [NSApp setServicesMenu:serviceMenu];
6836
b0ca1571caf3 Fixed bug 1689 - Leaks galore in OS X Cocoa code.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   178
    [serviceMenu release];
5377
6125f6da3dae Added disabled preferences menu option so it looks more like other application menus.
Sam Lantinga <slouken@libsdl.org>
parents: 5266
diff changeset
   179
6125f6da3dae Added disabled preferences menu option so it looks more like other application menus.
Sam Lantinga <slouken@libsdl.org>
parents: 5266
diff changeset
   180
    [appleMenu addItem:[NSMenuItem separatorItem]];
6125f6da3dae Added disabled preferences menu option so it looks more like other application menus.
Sam Lantinga <slouken@libsdl.org>
parents: 5266
diff changeset
   181
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
    title = [@"Hide " stringByAppendingString:appName];
6515
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   183
    [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
6515
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   185
    menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
    [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
    [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
    [appleMenu addItem:[NSMenuItem separatorItem]];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
    title = [@"Quit " stringByAppendingString:appName];
6515
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   193
    [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   194
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
    /* Put menu into the menubar */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
    menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
    [menuItem setSubmenu:appleMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
    [[NSApp mainMenu] addItem:menuItem];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
    [menuItem release];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
    /* Tell the application object that this is now the application menu */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
    [NSApp setAppleMenu:appleMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
    [appleMenu release];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
    /* Create the window menu */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
    windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   208
6515
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   209
    /* Add menu items */
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   210
    [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   211
6515
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   212
    [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
f750d9ecae1e Bring Cocoa application menus up to par with the OS X Human Interface Guidelines, including supporting key equivalents.
Sam Lantinga <slouken@libsdl.org>
parents: 6461
diff changeset
   213
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
    /* Put menu into the menubar */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
    menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
    [menuItem setSubmenu:windowMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
    [[NSApp mainMenu] addItem:menuItem];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
    [menuItem release];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   219
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
    /* Tell the application object that this is now the window menu */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
    [NSApp setWindowsMenu:windowMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
    [windowMenu release];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
Cocoa_RegisterApp(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
{
6639
c7e81fae23c4 Cocoa_ShowMessageBox() should call Cocoa_RegisterApp().
Ryan C. Gordon <icculus@icculus.org>
parents: 6515
diff changeset
   228
    /* This can get called more than once! Be careful what you initialize! */
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
    ProcessSerialNumber psn;
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   230
    NSAutoreleasePool *pool;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
    if (!GetCurrentProcess(&psn)) {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
        TransformProcessType(&psn, kProcessTransformToForegroundApplication);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
        SetFrontProcess(&psn);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
    }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   237
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   238
    if (NSApp == nil) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   239
        [NSApplication sharedApplication];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   241
        if ([NSApp mainMenu] == nil) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   242
            CreateApplicationMenus();
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
        }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   244
        [NSApp finishLaunching];
7739
329c9da4bfeb Mac: Turn off momentum-based scrolling.
Sam Lantinga <slouken@libsdl.org>
parents: 7511
diff changeset
   245
        NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"AppleMomentumScrollSupported"];
329c9da4bfeb Mac: Turn off momentum-based scrolling.
Sam Lantinga <slouken@libsdl.org>
parents: 7511
diff changeset
   246
        [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
329c9da4bfeb Mac: Turn off momentum-based scrolling.
Sam Lantinga <slouken@libsdl.org>
parents: 7511
diff changeset
   247
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
    }
7801
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   249
    if (NSApp && !appDelegate) {
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   250
        appDelegate = [[SDLAppDelegate alloc] init];
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   251
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   252
        /* If someone else has an app delegate, it means we can't turn a
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   253
         * termination into SDL_Quit, and we can't handle application:openFile:
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   254
         */
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   255
        if (![NSApp delegate]) {
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   256
            [NSApp setDelegate:appDelegate];
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   257
        } else {
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   258
            appDelegate->seenFirstActivate = YES;
f00cc0a8cd5d Mac: Better handling when someone else is the app delegate.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7739
diff changeset
   259
        }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   260
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   261
    [pool release];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
Cocoa_PumpEvents(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   267
    NSAutoreleasePool *pool;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   268
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   269
    /* Update activity every 30 seconds to prevent screensaver */
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   270
    if (_this->suspend_screensaver) {
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   271
        SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   272
        Uint32 now = SDL_GetTicks();
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   273
        if (!data->screensaver_activity ||
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   274
            (int)(now-data->screensaver_activity) >= 30000) {
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   275
            UpdateSystemActivity(UsrActivity);
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   276
            data->screensaver_activity = now;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   277
        }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   278
    }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   279
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   280
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   281
    for ( ; ; ) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   282
        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   283
        if ( event == nil ) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   284
            break;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
        }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   286
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   287
        switch ([event type]) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   288
        case NSLeftMouseDown:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   289
        case NSOtherMouseDown:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   290
        case NSRightMouseDown:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   291
        case NSLeftMouseUp:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   292
        case NSOtherMouseUp:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   293
        case NSRightMouseUp:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   294
        case NSLeftMouseDragged:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   295
        case NSRightMouseDragged:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   296
        case NSOtherMouseDragged: /* usually middle mouse dragged */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   297
        case NSMouseMoved:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   298
        case NSScrollWheel:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   299
            Cocoa_HandleMouseEvent(_this, event);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   300
            break;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   301
        case NSKeyDown:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   302
        case NSKeyUp:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   303
        case NSFlagsChanged:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   304
            Cocoa_HandleKeyEvent(_this, event);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   305
            break;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   306
        default:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   307
            break;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   308
        }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   309
        /* Pass through to NSApp to make sure everything stays in sync */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   310
        [NSApp sendEvent:event];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
    }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   312
    [pool release];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   315
#endif /* SDL_VIDEO_DRIVER_COCOA */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   316
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
/* vi: set ts=4 sw=4 expandtab: */