src/video/cocoa/SDL_cocoaevents.m
author Sam Lantinga <slouken@libsdl.org>
Mon, 11 Feb 2013 17:39:52 -0800
changeset 6848 478ecc8a58b3
parent 6836 b0ca1571caf3
child 6885 700f1b25f77f
permissions -rw-r--r--
Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
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
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6091
diff changeset
     3
  Copyright (C) 1997-2012 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
1937
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    44
@interface SDLAppDelegate : NSObject
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    45
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    46
@end
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    47
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    48
@implementation SDLAppDelegate : NSObject
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    49
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    50
{
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    51
    SDL_SendQuit();
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    52
    return NSTerminateCancel;
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    53
}
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
    54
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
    55
- (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
    56
{
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
    57
    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
    58
}
1937
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    59
@end
05e88d266921 Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    60
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
static NSString *
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
GetApplicationName(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    NSDictionary *dict;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    NSString *appName = 0;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    /* Determine the application name */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
    dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
    if (dict)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
        appName = [dict objectForKey: @"CFBundleName"];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
    
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
    if (![appName length])
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
        appName = [[NSProcessInfo processInfo] processName];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
    return appName;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
static void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
CreateApplicationMenus(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
    NSString *appName;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    NSString *title;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    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
    84
    NSMenu *serviceMenu;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    NSMenu *windowMenu;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    NSMenuItem *menuItem;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    /* Create the main menu bar */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    [NSApp setMainMenu:[[NSMenu alloc] init]];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    /* Create the application menu */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
    appName = GetApplicationName();
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    appleMenu = [[NSMenu alloc] initWithTitle:@""];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
    
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    /* Add menu items */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    title = [@"About " stringByAppendingString:appName];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
    [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
    98
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
    [appleMenu addItem:[NSMenuItem separatorItem]];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
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
   101
    [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
   102
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
   103
    [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
   104
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
   105
    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
   106
    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
   107
    [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
   108
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
   109
    [NSApp setServicesMenu:serviceMenu];
6836
b0ca1571caf3 Fixed bug 1689 - Leaks galore in OS X Cocoa code.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   110
    [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
   111
6125f6da3dae Added disabled preferences menu option so it looks more like other application menus.
Sam Lantinga <slouken@libsdl.org>
parents: 5266
diff changeset
   112
    [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
   113
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    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
   115
    [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
   116
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
   117
    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
   118
    [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    [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
   121
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    [appleMenu addItem:[NSMenuItem separatorItem]];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
    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
   125
    [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
    /* Put menu into the menubar */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
    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
   129
    [menuItem setSubmenu:appleMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    [[NSApp mainMenu] addItem:menuItem];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    [menuItem release];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
    /* 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
   134
    [NSApp setAppleMenu:appleMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
    [appleMenu release];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    /* Create the window menu */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
    windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    
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
   141
    /* 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
   142
    [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    
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
   144
    [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
   145
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
    /* Put menu into the menubar */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
    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
   148
    [menuItem setSubmenu:windowMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
    [[NSApp mainMenu] addItem:menuItem];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    [menuItem release];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    /* 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
   153
    [NSApp setWindowsMenu:windowMenu];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    [windowMenu release];
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
Cocoa_RegisterApp(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
{
6639
c7e81fae23c4 Cocoa_ShowMessageBox() should call Cocoa_RegisterApp().
Ryan C. Gordon <icculus@icculus.org>
parents: 6515
diff changeset
   160
    /* 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
   161
    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
   162
    NSAutoreleasePool *pool;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    if (!GetCurrentProcess(&psn)) {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
        TransformProcessType(&psn, kProcessTransformToForegroundApplication);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
        SetFrontProcess(&psn);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
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
   169
    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
   170
    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
   171
        [NSApplication sharedApplication];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
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
   173
        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
   174
            CreateApplicationMenus();
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
        }
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
   176
        [NSApp finishLaunching];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    }
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
   178
    if ([NSApp delegate] == 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
   179
        [NSApp setDelegate:[[SDLAppDelegate 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
   180
    }
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
   181
    [pool release];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
Cocoa_PumpEvents(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
{
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
   187
    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
   188
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   189
    /* 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
   190
    if (_this->suspend_screensaver) {
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   191
        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
   192
        Uint32 now = SDL_GetTicks();
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   193
        if (!data->screensaver_activity ||
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   194
            (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
   195
            UpdateSystemActivity(UsrActivity);
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   196
            data->screensaver_activity = now;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   197
        }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   198
    }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   199
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
   200
    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
   201
    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
   202
        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
   203
        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
   204
            break;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
        }
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
   206
		
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
   207
        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
   208
        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
   209
        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
   210
        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
   211
        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
   212
        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
   213
        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
   214
        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
   215
        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
   216
        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
   217
        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
   218
        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
   219
            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
   220
            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
   221
        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
   222
        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
   223
        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
   224
            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
   225
            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
   226
        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
   227
            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
   228
        }
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
   229
        /* 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
   230
        [NSApp sendEvent:event];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
    }
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
   232
    [pool release];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   235
#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
   236
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
/* vi: set ts=4 sw=4 expandtab: */