summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt11
-rw-r--r--src/SDLMain.h5
-rw-r--r--src/SDLMain.m124
-rw-r--r--src/gui/truetypefont.h4
-rw-r--r--src/resources/music.h4
-rw-r--r--src/resources/soundeffect.h4
-rw-r--r--src/sound.h4
7 files changed, 75 insertions, 81 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b9aa6bb7..f7483cfa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -650,7 +650,16 @@ IF (WIN32)
utils/specialfolder.h
mana.rc
)
-ENDIF ()
+ENDIF (WIN32)
+
+IF (APPLE)
+ SET(SRCS
+ ${SRCS}
+ log.mm
+ SDLMain.h
+ SDLMain.m
+ )
+ENDIF (APPLE)
SET (PROGRAMS mana)
diff --git a/src/SDLMain.h b/src/SDLMain.h
index 4683df57..c56d90cb 100644
--- a/src/SDLMain.h
+++ b/src/SDLMain.h
@@ -5,7 +5,12 @@
Feel free to customize this file to suit your needs
*/
+#ifndef _SDLMain_h_
+#define _SDLMain_h_
+
#import <Cocoa/Cocoa.h>
@interface SDLMain : NSObject
@end
+
+#endif /* _SDLMain_h_ */
diff --git a/src/SDLMain.m b/src/SDLMain.m
index d7e9273b..2434f81a 100644
--- a/src/SDLMain.m
+++ b/src/SDLMain.m
@@ -1,14 +1,14 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
- Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
- Non-NIB-Code & other changes: Max Horn <max@quendi.de>
-
- Feel free to customize this file to suit your needs
- */
+ Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
+ Non-NIB-Code & other changes: Max Horn <max@quendi.de>
+
+ Feel free to customize this file to suit your needs
+*/
-#import "SDL.h"
-#import "SDLMain.h"
-#import <sys/param.h> /* for MAXPATHLEN */
-#import <unistd.h>
+#include "SDL.h"
+#include "SDLMain.h"
+#include <sys/param.h> /* for MAXPATHLEN */
+#include <unistd.h>
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
@@ -25,10 +25,10 @@
#ifdef SDL_USE_CPS
/* Portions of CPS.h */
typedef struct CPSProcessSerNum
- {
- UInt32 lo;
- UInt32 hi;
- } CPSProcessSerNum;
+{
+ UInt32 lo;
+ UInt32 hi;
+} CPSProcessSerNum;
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
@@ -43,17 +43,17 @@ static BOOL gCalledAppMainline = FALSE;
static NSString *getApplicationName(void)
{
- NSDictionary *dict;
+ const NSDictionary *dict;
NSString *appName = 0;
-
+
/* Determine the application name */
- dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
+ dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];
if (![appName length])
appName = [[NSProcessInfo processInfo] processName];
-
+
return appName;
}
@@ -64,10 +64,10 @@ static NSString *getApplicationName(void)
@end
#endif
-@interface SDLApplication : NSApplication
+@interface NSApplication (SDLApplication)
@end
-@implementation SDLApplication
+@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
@@ -87,15 +87,14 @@ static NSString *getApplicationName(void)
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
- CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
- CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
- if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
- assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
- }
- CFRelease(url);
- CFRelease(url2);
- }
-
+ CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
+ CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
+ if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
+ chdir(parentdir); /* chdir to the binary app's parent */
+ }
+ CFRelease(url);
+ CFRelease(url2);
+ }
}
#if SDL_USE_NIB_FILE
@@ -106,11 +105,11 @@ static NSString *getApplicationName(void)
NSRange aRange;
NSEnumerator *enumerator;
NSMenuItem *menuItem;
-
+
aRange = [[aMenu title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
-
+
enumerator = [[aMenu itemArray] objectEnumerator];
while ((menuItem = [enumerator nextObject]))
{
@@ -120,7 +119,6 @@ static NSString *getApplicationName(void)
if ([menuItem hasSubmenu])
[self fixMenu:[menuItem submenu] withAppName:appName];
}
- [ aMenu sizeToFit ];
}
#else
@@ -139,31 +137,31 @@ static void setApplicationMenu(void)
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
-
+
[appleMenu addItem:[NSMenuItem separatorItem]];
-
+
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
-
+
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
-
+
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
-
+
[appleMenu addItem:[NSMenuItem separatorItem]];
-
+
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
-
+
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
-
+
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
-
+
/* Finally give up our references to the objects */
[appleMenu release];
[menuItem release];
@@ -175,7 +173,7 @@ static void setupWindowMenu(void)
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
-
+
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* "Minimize" item */
@@ -190,7 +188,7 @@ static void setupWindowMenu(void)
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
-
+
/* Finally give up our references to the objects */
[windowMenu release];
[windowMenuItem release];
@@ -201,9 +199,9 @@ static void CustomApplicationMain (int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;
-
+
/* Ensure the application object is initialised */
- [SDLApplication sharedApplication];
+ [NSApplication sharedApplication];
#ifdef SDL_USE_CPS
{
@@ -212,15 +210,15 @@ static void CustomApplicationMain (int argc, char **argv)
if (!CPSGetCurrentProcess(&PSN))
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
- [SDLApplication sharedApplication];
+ [NSApplication sharedApplication];
}
#endif /* SDL_USE_CPS */
-
+
/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
setApplicationMenu();
setupWindowMenu();
-
+
/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];
@@ -256,19 +254,19 @@ static void CustomApplicationMain (int argc, char **argv)
size_t arglen;
char *arg;
char **newargv;
-
+
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
-
+
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
-
+
temparg = [filename UTF8String];
arglen = SDL_strlen(temparg) + 1;
arg = (char *) SDL_malloc(arglen);
if (arg == NULL)
return FALSE;
-
+
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
if (newargv == NULL)
{
@@ -276,7 +274,7 @@ static void CustomApplicationMain (int argc, char **argv)
return FALSE;
}
gArgv = newargv;
-
+
SDL_strlcpy(arg, temparg, arglen);
gArgv[gArgc++] = arg;
gArgv[gArgc] = NULL;
@@ -288,19 +286,19 @@ static void CustomApplicationMain (int argc, char **argv)
- (void) applicationDidFinishLaunching: (NSNotification *) note
{
int status;
-
+
/* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch];
-
+
#if SDL_USE_NIB_FILE
/* Set the main menu to contain the real app name instead of "SDL App" */
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
#endif
-
+
/* Hand off to main application code */
gCalledAppMainline = TRUE;
status = SDL_main (gArgc, gArgv);
-
+
/* We're done, thank you for playing */
exit(status);
}
@@ -317,9 +315,9 @@ static void CustomApplicationMain (int argc, char **argv)
unichar *buffer;
NSRange localRange;
NSString *result;
-
+
bufferSize = selfLen + aStringLen - aRange.length;
- buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
+ buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
/* Get first part into buffer */
localRange.location = 0;
@@ -330,7 +328,7 @@ static void CustomApplicationMain (int argc, char **argv)
localRange.location = 0;
localRange.length = aStringLen;
[aString getCharacters:(buffer+aRange.location) range:localRange];
-
+
/* Get last part into buffer */
localRange.location = aRange.location + aRange.length;
localRange.length = selfLen - localRange.location;
@@ -364,9 +362,7 @@ int main (int argc, char **argv)
gArgv[1] = NULL;
gArgc = 1;
gFinderLaunch = YES;
- }
- else
- {
+ } else {
int i;
gArgc = argc;
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
@@ -374,12 +370,12 @@ int main (int argc, char **argv)
gArgv[i] = argv[i];
gFinderLaunch = NO;
}
-
+
#if SDL_USE_NIB_FILE
- [SDLApplication poseAsClass:[NSApplication class]];
NSApplicationMain (argc, argv);
#else
CustomApplicationMain (argc, argv);
#endif
return 0;
}
+
diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h
index 97fd7f08..a01e2a62 100644
--- a/src/gui/truetypefont.h
+++ b/src/gui/truetypefont.h
@@ -25,15 +25,11 @@
#include <guichan/font.hpp>
-#ifdef __APPLE__
-#include <SDL/SDL_ttf.h>
-#else
#ifdef __WIN32__
#include <SDL/SDL_ttf.h>
#else
#include <SDL_ttf.h>
#endif
-#endif
#include <list>
#include <string>
diff --git a/src/resources/music.h b/src/resources/music.h
index bc2a56ae..d370f0a5 100644
--- a/src/resources/music.h
+++ b/src/resources/music.h
@@ -24,11 +24,7 @@
#include "resources/resource.h"
-#ifdef __APPLE__
-#include <SDL/SDL_mixer.h>
-#else
#include <SDL_mixer.h>
-#endif
/**
* Defines a class for loading and storing music.
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index decc60a0..38d58681 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -24,11 +24,7 @@
#include "resources/resource.h"
-#ifdef __APPLE__
-#include <SDL/SDL_mixer.h>
-#else
#include <SDL_mixer.h>
-#endif
/**
* Defines a class for loading and storing sound effects.
diff --git a/src/sound.h b/src/sound.h
index 180bca62..d4d0e8da 100644
--- a/src/sound.h
+++ b/src/sound.h
@@ -22,11 +22,7 @@
#ifndef SOUND_H
#define SOUND_H
-#ifdef __APPLE__
-#include <SDL/SDL_mixer.h>
-#else
#include <SDL_mixer.h>
-#endif
#include <string>