Mac OS X updates: Fixed typing in Mac print dialogs. Fixed endian issue so that printing from an Intel-based Mac no longer messes up colors. Added automatic scaling and orientation of image for Mac printing. Added menu items to Mac menu bar - New, Open, Save, Print, Page Setup, Undo, Redo. Use standard Mac arrow cursror rather than custom Tux Paint arrow cursor for more consistent look and feel.
This commit is contained in:
parent
0d7887897b
commit
9a8fc843d3
9 changed files with 388 additions and 137 deletions
13
macosx/English.lproj/SDLMain.nib/classes.nib
generated
13
macosx/English.lproj/SDLMain.nib/classes.nib
generated
|
|
@ -2,7 +2,18 @@
|
||||||
IBClasses = (
|
IBClasses = (
|
||||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||||
{
|
{
|
||||||
ACTIONS = {makeFullscreen = id; quit = id; };
|
ACTIONS = {
|
||||||
|
makeFullscreen = id;
|
||||||
|
onHelp = id;
|
||||||
|
onNew = id;
|
||||||
|
onOpen = id;
|
||||||
|
onPageSetup = id;
|
||||||
|
onPrint = id;
|
||||||
|
onQuit = id;
|
||||||
|
onRedo = id;
|
||||||
|
onSave = id;
|
||||||
|
onUndo = id;
|
||||||
|
};
|
||||||
CLASS = SDLMain;
|
CLASS = SDLMain;
|
||||||
LANGUAGE = ObjC;
|
LANGUAGE = ObjC;
|
||||||
SUPERCLASS = NSObject;
|
SUPERCLASS = NSObject;
|
||||||
|
|
|
||||||
12
macosx/English.lproj/SDLMain.nib/info.nib
generated
12
macosx/English.lproj/SDLMain.nib/info.nib
generated
|
|
@ -3,15 +3,19 @@
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>IBDocumentLocation</key>
|
<key>IBDocumentLocation</key>
|
||||||
<string>186 88 356 240 0 0 1440 878 </string>
|
<string>71 160 356 240 0 0 1440 878 </string>
|
||||||
<key>IBEditorPositions</key>
|
<key>IBEditorPositions</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>29</key>
|
<key>29</key>
|
||||||
<string>184 416 205 44 0 0 1440 878 </string>
|
<string>201 387 286 44 0 0 1440 878 </string>
|
||||||
</dict>
|
</dict>
|
||||||
<key>IBFramework Version</key>
|
<key>IBFramework Version</key>
|
||||||
<string>443.0</string>
|
<string>446.1</string>
|
||||||
|
<key>IBOpenObjects</key>
|
||||||
|
<array>
|
||||||
|
<integer>29</integer>
|
||||||
|
</array>
|
||||||
<key>IBSystem Version</key>
|
<key>IBSystem Version</key>
|
||||||
<string>8F46</string>
|
<string>8P135</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
||||||
BIN
macosx/English.lproj/SDLMain.nib/objects.nib
generated
BIN
macosx/English.lproj/SDLMain.nib/objects.nib
generated
Binary file not shown.
|
|
@ -12,4 +12,20 @@
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface SDLMain : NSObject
|
@interface SDLMain : NSObject
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)onNew:(id)sender;
|
||||||
|
- (IBAction)onOpen:(id)sender;
|
||||||
|
- (IBAction)onSave:(id)sender;
|
||||||
|
- (IBAction)onPrint:(id)sender;
|
||||||
|
- (IBAction)onPageSetup:(id)sender;
|
||||||
|
- (IBAction)onUndo:(id)sender;
|
||||||
|
- (IBAction)onRedo:(id)sender;
|
||||||
|
- (IBAction)onHelp:(id)sender;
|
||||||
|
- (IBAction)onQuit:(id)sender;
|
||||||
|
|
||||||
|
- (void) sendSDLControlKeystroke:(int)key;
|
||||||
|
- (void) setupBridge;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
234
macosx/SDLMain.m
234
macosx/SDLMain.m
|
|
@ -10,47 +10,57 @@
|
||||||
#import <sys/param.h> /* for MAXPATHLEN */
|
#import <sys/param.h> /* for MAXPATHLEN */
|
||||||
#import <unistd.h>
|
#import <unistd.h>
|
||||||
|
|
||||||
#include "wrapperdata.h"
|
#import "macosx_print.h"
|
||||||
|
#import "wrapperdata.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
|
||||||
|
it ourselves here. */
|
||||||
|
@interface NSApplication(SDL_Missing_Methods)
|
||||||
|
- (void)setAppleMenu:(NSMenu *)menu;
|
||||||
|
@end
|
||||||
|
|
||||||
/* Use this flag to determine whether we use SDLMain.nib or not */
|
/* Use this flag to determine whether we use SDLMain.nib or not */
|
||||||
#define SDL_USE_NIB_FILE 0
|
#define SDL_USE_NIB_FILE 1
|
||||||
|
|
||||||
/* Use this flag to determine whether we use CPS (docking) or not */
|
/* Use this flag to determine whether we use CPS (docking) or not */
|
||||||
#define SDL_USE_CPS 1
|
#define SDL_USE_CPS 1
|
||||||
|
|
||||||
#ifdef SDL_USE_CPS
|
#ifdef SDL_USE_CPS
|
||||||
/* Portions of CPS.h */
|
/* Portions of CPS.h */
|
||||||
typedef struct CPSProcessSerNum
|
typedef struct CPSProcessSerNum
|
||||||
{
|
{
|
||||||
UInt32 lo;
|
UInt32 lo;
|
||||||
UInt32 hi;
|
UInt32 hi;
|
||||||
} CPSProcessSerNum;
|
} CPSProcessSerNum;
|
||||||
|
|
||||||
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
|
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
|
||||||
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
|
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
|
||||||
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
|
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
|
||||||
|
|
||||||
#endif /* SDL_USE_CPS */
|
#endif /* SDL_USE_CPS */
|
||||||
|
|
||||||
static int gArgc;
|
static int gArgc;
|
||||||
static char **gArgv;
|
static char **gArgv;
|
||||||
static BOOL gFinderLaunch;
|
static BOOL gFinderLaunch;
|
||||||
|
static BOOL gCalledAppMainline = FALSE;
|
||||||
|
|
||||||
WrapperData macosx;
|
WrapperData macosx;
|
||||||
|
|
||||||
static NSString *getApplicationName(void)
|
static NSString *getApplicationName(void)
|
||||||
{
|
{
|
||||||
NSDictionary *dict;
|
NSDictionary *dict;
|
||||||
NSString *appName = 0;
|
NSString *appName = 0;
|
||||||
|
|
||||||
/* Determine the application name */
|
/* Determine the application name */
|
||||||
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
|
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
|
||||||
if (dict)
|
if (dict)
|
||||||
appName = [dict objectForKey: @"CFBundleName"];
|
appName = [dict objectForKey: @"CFBundleName"];
|
||||||
|
|
||||||
if (![appName length])
|
if (![appName length])
|
||||||
appName = [[NSProcessInfo processInfo] processName];
|
appName = [[NSProcessInfo processInfo] processName];
|
||||||
|
|
||||||
return appName;
|
return appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_USE_NIB_FILE
|
#if SDL_USE_NIB_FILE
|
||||||
|
|
@ -64,6 +74,20 @@ static NSString *getApplicationName(void)
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDLApplication
|
@implementation SDLApplication
|
||||||
|
|
||||||
|
- (void)sendEvent:(NSEvent *)anEvent
|
||||||
|
{
|
||||||
|
if (!macosx.cocoaKeystrokes)
|
||||||
|
{
|
||||||
|
if (NSKeyDown == [anEvent type] || NSKeyUp == [anEvent type])
|
||||||
|
{
|
||||||
|
if( ( [anEvent modifierFlags] & NSCommandKeyMask ) == 0 )
|
||||||
|
return; // do not intercept keystrokes intended for SDL layer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[super sendEvent: anEvent];
|
||||||
|
}
|
||||||
|
|
||||||
/* Invoked from the Quit menu item */
|
/* Invoked from the Quit menu item */
|
||||||
- (void)terminate:(id)sender
|
- (void)terminate:(id)sender
|
||||||
{
|
{
|
||||||
|
|
@ -73,15 +97,6 @@ static NSString *getApplicationName(void)
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendEvent:(NSEvent *)anEvent {
|
|
||||||
if( NSKeyDown == [anEvent type] || NSKeyUp ==
|
|
||||||
[anEvent type] ) {
|
|
||||||
if( [anEvent modifierFlags] & NSCommandKeyMask )
|
|
||||||
[super sendEvent: anEvent];
|
|
||||||
} else
|
|
||||||
[super sendEvent: anEvent];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)tuxpaintHelp:(id)sender
|
- (void)tuxpaintHelp:(id)sender
|
||||||
{
|
{
|
||||||
NSString* helpPath = [[NSBundle mainBundle] pathForResource:@"README" ofType:@"html" inDirectory:@"html"];
|
NSString* helpPath = [[NSBundle mainBundle] pathForResource:@"README" ofType:@"html" inDirectory:@"html"];
|
||||||
|
|
@ -132,6 +147,78 @@ static NSString *getApplicationName(void)
|
||||||
/* The main class of the application, the application's delegate */
|
/* The main class of the application, the application's delegate */
|
||||||
@implementation SDLMain
|
@implementation SDLMain
|
||||||
|
|
||||||
|
- (IBAction) onNew:(id)sender
|
||||||
|
{
|
||||||
|
[self sendSDLControlKeystroke:SDLK_n];
|
||||||
|
/*
|
||||||
|
[NSApp beginSheet:nameWindow
|
||||||
|
modalForWindow:[NSApp mainWindow]
|
||||||
|
modalDelegate:nil
|
||||||
|
didEndSelector:nil
|
||||||
|
contextInfo:nil];
|
||||||
|
|
||||||
|
[NSApp runModalForWindow:nameWindow];
|
||||||
|
|
||||||
|
[NSApp endSheet:nameWindow];
|
||||||
|
[nameWindow orderOut:self];
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) onOpen:(id)sender
|
||||||
|
{
|
||||||
|
[self sendSDLControlKeystroke:SDLK_o];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) onSave:(id)sender
|
||||||
|
{
|
||||||
|
[self sendSDLControlKeystroke:SDLK_s];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) onPrint:(id)sender
|
||||||
|
{
|
||||||
|
macosx.menuAction = 1;
|
||||||
|
do_print();
|
||||||
|
macosx.menuAction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) onPageSetup:(id)sender
|
||||||
|
{
|
||||||
|
DisplayPageSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) onUndo:(id)sender
|
||||||
|
{
|
||||||
|
[self sendSDLControlKeystroke:SDLK_z];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) onRedo:(id)sender
|
||||||
|
{
|
||||||
|
[self sendSDLControlKeystroke:SDLK_r];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)onHelp:(id)sender
|
||||||
|
{
|
||||||
|
NSString* helpPath = [[NSBundle mainBundle] pathForResource:@"README" ofType:@"html" inDirectory:@"html"];
|
||||||
|
[[NSWorkspace sharedWorkspace] openFile:helpPath];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) onQuit:(id)sender
|
||||||
|
{
|
||||||
|
/* Post a SDL_QUIT event */
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = SDL_QUIT;
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) sendSDLControlKeystroke:(int)key
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = SDL_KEYDOWN;
|
||||||
|
event.key.keysym.sym = key;
|
||||||
|
event.key.keysym.mod = KMOD_CTRL;
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the working directory to the .app's parent directory */
|
/* Set the working directory to the .app's parent directory */
|
||||||
- (void) setupWorkingDirectory:(BOOL)shouldChdir
|
- (void) setupWorkingDirectory:(BOOL)shouldChdir
|
||||||
{
|
{
|
||||||
|
|
@ -140,13 +227,12 @@ static NSString *getApplicationName(void)
|
||||||
char parentdir[MAXPATHLEN];
|
char parentdir[MAXPATHLEN];
|
||||||
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
||||||
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
|
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
|
||||||
if (CFURLGetFileSystemRepresentation(url2, true, parentdir, MAXPATHLEN)) {
|
if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
|
||||||
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
|
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
|
||||||
}
|
}
|
||||||
CFRelease(url);
|
CFRelease(url);
|
||||||
CFRelease(url2);
|
CFRelease(url2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_USE_NIB_FILE
|
#if SDL_USE_NIB_FILE
|
||||||
|
|
@ -207,7 +293,6 @@ static void setApplicationMenu(void)
|
||||||
title = [@"Quit " stringByAppendingString:appName];
|
title = [@"Quit " stringByAppendingString:appName];
|
||||||
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
||||||
|
|
||||||
|
|
||||||
/* Put menu into the menubar */
|
/* Put menu into the menubar */
|
||||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
||||||
[menuItem setSubmenu:appleMenu];
|
[menuItem setSubmenu:appleMenu];
|
||||||
|
|
@ -279,7 +364,6 @@ static void CustomApplicationMain (argc, argv)
|
||||||
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
SDLMain *sdlMain;
|
SDLMain *sdlMain;
|
||||||
CocoaToSDLBridge *bridge;
|
|
||||||
|
|
||||||
/* Ensure the application object is initialised */
|
/* Ensure the application object is initialised */
|
||||||
[SDLApplication sharedApplication];
|
[SDLApplication sharedApplication];
|
||||||
|
|
@ -299,12 +383,7 @@ static void CustomApplicationMain (argc, argv)
|
||||||
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
||||||
setApplicationMenu();
|
setApplicationMenu();
|
||||||
setupWindowMenu();
|
setupWindowMenu();
|
||||||
setupHelpMenu();
|
setupHelpMenu();
|
||||||
|
|
||||||
/* Pass information to SDL application */
|
|
||||||
bridge = [[CocoaToSDLBridge alloc] init];
|
|
||||||
[bridge autorelease];
|
|
||||||
[bridge fontsPath];
|
|
||||||
|
|
||||||
/* Create SDLMain and make it the app delegate */
|
/* Create SDLMain and make it the app delegate */
|
||||||
sdlMain = [[SDLMain alloc] init];
|
sdlMain = [[SDLMain alloc] init];
|
||||||
|
|
@ -319,12 +398,75 @@ static void CustomApplicationMain (argc, argv)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Make Mac-specific information available to SDL app */
|
||||||
|
- (void) setupBridge
|
||||||
|
{
|
||||||
|
CocoaToSDLBridge *bridge;
|
||||||
|
bridge = [[CocoaToSDLBridge alloc] init];
|
||||||
|
[bridge autorelease];
|
||||||
|
[bridge fontsPath];
|
||||||
|
[bridge preferencesPath];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Catch document open requests...this lets us notice files when the app
|
||||||
|
* was launched by double-clicking a document, or when a document was
|
||||||
|
* dragged/dropped on the app's icon. You need to have a
|
||||||
|
* CFBundleDocumentsType section in your Info.plist to get this message,
|
||||||
|
* apparently.
|
||||||
|
*
|
||||||
|
* Files are added to gArgv, so to the app, they'll look like command line
|
||||||
|
* arguments. Previously, apps launched from the finder had nothing but
|
||||||
|
* an argv[0].
|
||||||
|
*
|
||||||
|
* This message may be received multiple times to open several docs on launch.
|
||||||
|
*
|
||||||
|
* This message is ignored once the app's mainline has been called.
|
||||||
|
*/
|
||||||
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||||
|
{
|
||||||
|
const char *temparg;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
SDL_free(arg);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
gArgv = newargv;
|
||||||
|
|
||||||
|
SDL_strlcpy(arg, temparg, arglen);
|
||||||
|
gArgv[gArgc++] = arg;
|
||||||
|
gArgv[gArgc] = NULL;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Called when the internal event loop has just started running */
|
/* Called when the internal event loop has just started running */
|
||||||
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
||||||
{
|
{
|
||||||
setenv ("SDL_ENABLEAPPEVENTS", "1", 1);
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
/* Allow Cocoa events to be processed */
|
||||||
|
setenv ("SDL_ENABLEAPPEVENTS", "1", 1);
|
||||||
|
|
||||||
|
/* Set up Cocoa to SDL bridge */
|
||||||
|
[self setupBridge];
|
||||||
|
|
||||||
/* Set the working directory to the .app's parent directory */
|
/* Set the working directory to the .app's parent directory */
|
||||||
[self setupWorkingDirectory:gFinderLaunch];
|
[self setupWorkingDirectory:gFinderLaunch];
|
||||||
|
|
||||||
|
|
@ -334,6 +476,7 @@ static void CustomApplicationMain (argc, argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Hand off to main application code */
|
/* Hand off to main application code */
|
||||||
|
gCalledAppMainline = TRUE;
|
||||||
status = SDL_main (gArgc, gArgv);
|
status = SDL_main (gArgc, gArgv);
|
||||||
|
|
||||||
/* We're done, thank you for playing */
|
/* We're done, thank you for playing */
|
||||||
|
|
@ -392,20 +535,25 @@ static void CustomApplicationMain (argc, argv)
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* Copy the arguments into a global variable */
|
/* Copy the arguments into a global variable */
|
||||||
gArgv = argv;
|
|
||||||
|
|
||||||
/* This is passed if we are launched by double-clicking */
|
/* This is passed if we are launched by double-clicking */
|
||||||
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
|
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
|
||||||
|
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
|
||||||
|
gArgv[0] = argv[0];
|
||||||
|
gArgv[1] = NULL;
|
||||||
gArgc = 1;
|
gArgc = 1;
|
||||||
gFinderLaunch = YES;
|
gFinderLaunch = YES;
|
||||||
} else {
|
} else {
|
||||||
|
int i;
|
||||||
gArgc = argc;
|
gArgc = argc;
|
||||||
gFinderLaunch = NO;
|
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
|
||||||
|
for (i = 0; i <= argc; i++)
|
||||||
|
gArgv[i] = argv[i];
|
||||||
|
gFinderLaunch = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_USE_NIB_FILE
|
#if SDL_USE_NIB_FILE
|
||||||
[SDLApplication poseAsClass:[NSApplication class]];
|
[SDLApplication poseAsClass:[NSApplication class]];
|
||||||
NSApplicationMain (argc, argv);
|
NSApplicationMain (argc, (const char**) argv);
|
||||||
#else
|
#else
|
||||||
CustomApplicationMain (argc, argv);
|
CustomApplicationMain (argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* wrapperdata.h
|
* wrapperdata.h
|
||||||
* TuxPaint
|
* Tux Paint
|
||||||
*
|
*
|
||||||
* Created by Martin Fuhrer on Wed May 12 2004.
|
* Created by Martin Fuhrer on Wed May 12 2004.
|
||||||
* Copyright (c) 2004 __MyCompanyName__. All rights reserved.
|
* Copyright (c) 2004 __MyCompanyName__. All rights reserved.
|
||||||
|
|
@ -14,12 +14,14 @@
|
||||||
|
|
||||||
struct WrapperDataStruct
|
struct WrapperDataStruct
|
||||||
{
|
{
|
||||||
char dataPath[2048]; // path to data folder inside application bundle
|
char dataPath[2048]; // path to data folder inside application bundle
|
||||||
char preferencesPath[2048]; // path to the user's preferences folder
|
char preferencesPath[2048]; // path to the user's preferences folder
|
||||||
char fontsPath[2048]; // path to the user's fonts folder
|
char fontsPath[2048]; // path to the user's fonts folder
|
||||||
int foundSDL; // was SDL.framework found?
|
int foundSDL; // was SDL.framework found?
|
||||||
int foundSDL_image; // was SDL_image.framework found?
|
int foundSDL_image; // was SDL_image.framework found?
|
||||||
int foundSDL_mixer; // was SDL_mixer.framework found?
|
int foundSDL_mixer; // was SDL_mixer.framework found?
|
||||||
|
int cocoaKeystrokes; // should keystrokes be intercepted by Cocoa wrapper?
|
||||||
|
int menuAction; // was the action initiated by a Mac OS X menu selection?
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct WrapperDataStruct WrapperData;
|
typedef struct WrapperDataStruct WrapperData;
|
||||||
|
|
|
||||||
|
|
@ -25,3 +25,18 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
const char *SurfacePrint(SDL_Surface * surface, int showDialog);
|
const char *SurfacePrint(SDL_Surface * surface, int showDialog);
|
||||||
|
|
||||||
|
#ifdef OBJECTIVEC
|
||||||
|
|
||||||
|
BOOL DisplayPageSetup();
|
||||||
|
|
||||||
|
@interface PrintSheetController : NSObject
|
||||||
|
{
|
||||||
|
bool displayPrintSetupSheet;
|
||||||
|
bool displayPrintSheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
-
|
||||||
|
@end
|
||||||
|
|
||||||
|
#endif OBJECTIVEC
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,11 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "macosx_print.h"
|
#import "macosx_print.h"
|
||||||
|
#import "wrapperdata.h"
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
extern WrapperData macosx;
|
||||||
|
|
||||||
// this object presents the image to the printing layer
|
// this object presents the image to the printing layer
|
||||||
@interface ImageView : NSView
|
@interface ImageView : NSView
|
||||||
{
|
{
|
||||||
|
|
@ -43,8 +46,14 @@
|
||||||
|
|
||||||
- (void) drawRect:(NSRect)rect
|
- (void) drawRect:(NSRect)rect
|
||||||
{
|
{
|
||||||
[ _image compositeToPoint: NSMakePoint (0, 0) operation: NSCompositeCopy ];
|
[ _image compositeToPoint: NSMakePoint( 0, 0 ) operation: NSCompositeCopy ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) scalesWhenResized
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// this object waits for the print dialog to go away
|
// this object waits for the print dialog to go away
|
||||||
|
|
@ -112,23 +121,27 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static NSImage* CreateImage (SDL_Surface *surface)
|
static NSImage* CreateImage( SDL_Surface *surface )
|
||||||
{
|
{
|
||||||
NSBitmapImageRep* imageRep;
|
NSBitmapImageRep* imageRep;
|
||||||
NSSize imageSize;
|
NSSize imageSize;
|
||||||
NSImage* image;
|
NSImage* image;
|
||||||
SDL_Surface* surface32RGBA;
|
SDL_Surface* surface32RGBA;
|
||||||
|
|
||||||
|
|
||||||
// convert surface to 32bit RGBA
|
// convert surface to 32bit RGBA
|
||||||
surface32RGBA = SDL_CreateRGBSurface (SDL_SWSURFACE, surface->w, surface->h,
|
#ifdef BIG_ENDIAN_ARCH
|
||||||
32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
|
surface32RGBA = SDL_CreateRGBSurface( SDL_SWSURFACE, surface->w, surface->h,
|
||||||
if (surface32RGBA == NULL) {
|
32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0 );
|
||||||
|
#else
|
||||||
|
surface32RGBA = SDL_CreateRGBSurface( SDL_SWSURFACE, surface->w, surface->h,
|
||||||
|
32, 0xff<<0, 0xff<<8, 0xff<<16, 0xff<<24 );
|
||||||
|
#endif
|
||||||
|
if( surface32RGBA == NULL ) {
|
||||||
NSLog (@"CreateImage: Cannot allocate conversion surface");
|
NSLog (@"CreateImage: Cannot allocate conversion surface");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_BlitSurface (surface, NULL, surface32RGBA, NULL);
|
SDL_BlitSurface( surface, NULL, surface32RGBA, NULL );
|
||||||
|
|
||||||
// convert surface to an NSBitmapImageRep
|
// convert surface to an NSBitmapImageRep
|
||||||
imageRep = [ [ NSBitmapImageRep alloc]
|
imageRep = [ [ NSBitmapImageRep alloc]
|
||||||
|
|
@ -142,30 +155,69 @@ static NSImage* CreateImage (SDL_Surface *surface)
|
||||||
colorSpaceName:NSDeviceRGBColorSpace
|
colorSpaceName:NSDeviceRGBColorSpace
|
||||||
bytesPerRow:surface->w * 4
|
bytesPerRow:surface->w * 4
|
||||||
bitsPerPixel:32 ];
|
bitsPerPixel:32 ];
|
||||||
if (imageRep == nil) {
|
if( imageRep == nil ) {
|
||||||
NSLog (@"CreateImage: Could not create image representation.");
|
NSLog (@"CreateImage: Could not create image representation.");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
imageSize = NSMakeSize (surface->w, surface->h);
|
imageSize = NSMakeSize( surface->w, surface->h );
|
||||||
|
|
||||||
image = [ [ NSImage alloc ] initWithSize:imageSize ];
|
image = [ [ NSImage alloc ] initWithSize:imageSize ];
|
||||||
if (image == nil) {
|
if( image == nil ) {
|
||||||
NSLog (@"CreateImage: Could not allocate image");
|
NSLog (@"CreateImage: Could not allocate image");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ image addRepresentation:imageRep ];
|
[ image addRepresentation:imageRep ];
|
||||||
|
[ image setScalesWhenResized:YES ];
|
||||||
|
[ image setDataRetained:YES ];
|
||||||
|
|
||||||
[ image autorelease ];
|
[ image autorelease ];
|
||||||
[ imageRep release ];
|
[ imageRep release ];
|
||||||
free (surface32RGBA);
|
free( surface32RGBA );
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL DisplayPageSetup()
|
||||||
|
{
|
||||||
|
NSPageLayout* pageLayout;
|
||||||
|
NSPrintInfo* printInfo;
|
||||||
|
ModalDelegate* delegate;
|
||||||
|
BOOL result;
|
||||||
|
|
||||||
const char* SurfacePrint (SDL_Surface *surface, int showDialog)
|
macosx.cocoaKeystrokes = 1;
|
||||||
|
printInfo = [ NSPrintInfo sharedPrintInfo ];
|
||||||
|
delegate = [ [ [ ModalDelegate alloc ] init ] autorelease ];
|
||||||
|
pageLayout = [ NSPageLayout pageLayout ];
|
||||||
|
[ pageLayout beginSheetWithPrintInfo:printInfo
|
||||||
|
modalForWindow:[ NSApp mainWindow ]
|
||||||
|
delegate:delegate
|
||||||
|
didEndSelector:@selector(pageLayoutEnded:returnCode:contextInfo:)
|
||||||
|
contextInfo:nil ];
|
||||||
|
|
||||||
|
result = [ delegate wait ];
|
||||||
|
macosx.cocoaKeystrokes = 0;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DefaultPrintSettings( SDL_Surface *surface )
|
||||||
|
{
|
||||||
|
NSPrintInfo* printInfo = [ NSPrintInfo sharedPrintInfo ];
|
||||||
|
|
||||||
|
if( surface->w > surface->h )
|
||||||
|
[ printInfo setOrientation:NSLandscapeOrientation ];
|
||||||
|
else
|
||||||
|
[ printInfo setOrientation:NSPortraitOrientation ];
|
||||||
|
|
||||||
|
[ printInfo setHorizontallyCentered:true ];
|
||||||
|
[ printInfo setVerticallyCentered:true ];
|
||||||
|
[ printInfo setVerticalPagination:NSFitPagination ];
|
||||||
|
[ printInfo setHorizontalPagination:NSFitPagination ];
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* SurfacePrint( SDL_Surface *surface, int showDialog )
|
||||||
{
|
{
|
||||||
NSImage* image;
|
NSImage* image;
|
||||||
ImageView* printView;
|
ImageView* printView;
|
||||||
|
|
@ -173,60 +225,58 @@ const char* SurfacePrint (SDL_Surface *surface, int showDialog)
|
||||||
NSPrintOperation* printOperation;
|
NSPrintOperation* printOperation;
|
||||||
NSPrintInfo* printInfo;
|
NSPrintInfo* printInfo;
|
||||||
ModalDelegate* delegate;
|
ModalDelegate* delegate;
|
||||||
|
static BOOL firstTime = YES;
|
||||||
BOOL ok = YES;
|
BOOL ok = YES;
|
||||||
const char* error = NULL;
|
const char* error = NULL;
|
||||||
|
|
||||||
// create image for surface
|
// create image for surface
|
||||||
image = CreateImage (surface);
|
image = CreateImage( surface );
|
||||||
if (image == nil)
|
if( image == nil )
|
||||||
return "Could not create image";
|
return "Could not create image";
|
||||||
|
|
||||||
// create print view
|
if( firstTime == YES ) {
|
||||||
printView = [ [ ImageView alloc ] initWithFrame: NSMakeRect (0, 0, surface->w, surface->h) ];
|
DefaultPrintSettings( surface );
|
||||||
if (printView == nil)
|
firstTime = NO;
|
||||||
return "Could not create print view";
|
}
|
||||||
[ printView setImage:image ];
|
|
||||||
|
|
||||||
// attach view to offscreen window
|
|
||||||
printWindow = [ [ NSWindow alloc ]
|
|
||||||
initWithContentRect: NSMakeRect (0, 0, surface->w, surface->h)
|
|
||||||
styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered
|
|
||||||
defer:NO ];
|
|
||||||
if (printWindow == nil)
|
|
||||||
return "Could not create offscreen window";
|
|
||||||
|
|
||||||
[ printWindow setContentView:printView ];
|
|
||||||
|
|
||||||
// create print control objects
|
// create print control objects
|
||||||
printInfo = [ NSPrintInfo sharedPrintInfo ];
|
printInfo = [ NSPrintInfo sharedPrintInfo ];
|
||||||
|
|
||||||
delegate = [ [ ModalDelegate alloc ] init ];
|
NSRect pageRect = [ printInfo imageablePageBounds ];
|
||||||
|
NSSize pageSize = pageRect.size;
|
||||||
|
NSPoint pageOrigin = pageRect.origin;
|
||||||
|
|
||||||
// run page layout dialog
|
[ printInfo setTopMargin:pageOrigin.y ];
|
||||||
if (showDialog) {
|
[ printInfo setLeftMargin:pageOrigin.x ];
|
||||||
|
[ printInfo setRightMargin:pageOrigin.x ];
|
||||||
|
[ printInfo setBottomMargin:pageOrigin.y ];
|
||||||
|
|
||||||
NSPageLayout* pageLayout;
|
float surfaceRatio = surface->w / surface->h;
|
||||||
|
float pageRatio = pageSize.width / pageSize.height;
|
||||||
|
|
||||||
pageLayout = [ NSPageLayout pageLayout ];
|
NSSize imageSize = pageSize;
|
||||||
[ pageLayout beginSheetWithPrintInfo:printInfo
|
if( pageRatio > surfaceRatio ) // wide page
|
||||||
modalForWindow:[ NSApp mainWindow ]
|
{
|
||||||
delegate:delegate
|
imageSize.width = surface->w * pageSize.height / surface->h;
|
||||||
didEndSelector:@selector(pageLayoutEnded:returnCode:contextInfo:)
|
}
|
||||||
contextInfo:nil ];
|
else // tall page
|
||||||
|
{
|
||||||
|
imageSize.height = surface->h * pageSize.width / surface->w;
|
||||||
|
}
|
||||||
|
|
||||||
ok = [ delegate wait ];
|
// create print view
|
||||||
[ delegate reset ];
|
printView = [ [ [ ImageView alloc ] initWithFrame: NSMakeRect( 0, 0, imageSize.width, imageSize.height ) ] autorelease ];
|
||||||
}
|
if (printView == nil)
|
||||||
|
return "Could not create print view";
|
||||||
if (!ok) {
|
[ image setSize:imageSize ];
|
||||||
error = "Canceled printing at page layout";
|
[ printView setImage:image ];
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// run printing
|
// run printing
|
||||||
printOperation = [ NSPrintOperation printOperationWithView:printView printInfo:printInfo ];
|
printOperation = [ NSPrintOperation printOperationWithView:printView printInfo:printInfo ];
|
||||||
[ printOperation setShowPanels:showDialog ];
|
[ printOperation setShowPanels:showDialog ];
|
||||||
|
|
||||||
|
macosx.cocoaKeystrokes = 1;
|
||||||
|
delegate = [ [ [ ModalDelegate alloc ] init ] autorelease ];
|
||||||
[ printOperation runOperationModalForWindow:[ NSApp mainWindow ]
|
[ printOperation runOperationModalForWindow:[ NSApp mainWindow ]
|
||||||
delegate:delegate didRunSelector:@selector(printDidRun:success:contextInfo:) contextInfo:nil ];
|
delegate:delegate didRunSelector:@selector(printDidRun:success:contextInfo:) contextInfo:nil ];
|
||||||
|
|
||||||
|
|
@ -234,12 +284,8 @@ const char* SurfacePrint (SDL_Surface *surface, int showDialog)
|
||||||
if (!ok)
|
if (!ok)
|
||||||
error = "Canceled or error when printing";
|
error = "Canceled or error when printing";
|
||||||
|
|
||||||
bail:
|
macosx.cocoaKeystrokes = 0;
|
||||||
// cleanup
|
|
||||||
[ delegate release ];
|
|
||||||
[ image release ];
|
[ image release ];
|
||||||
[ printView release ];
|
|
||||||
[ printWindow release ];
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ char *strcasestr(const char *haystack, const char *needle)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* kluge; 2006.01.15 */
|
/* kludge; 2006.01.15 */
|
||||||
//#define __APPLE_10_2_8__
|
//#define __APPLE_10_2_8__
|
||||||
|
|
||||||
/* (Trouble building this for 10.2.8 target; bjk & mf 2006.01.14) */
|
/* (Trouble building this for 10.2.8 target; bjk & mf 2006.01.14) */
|
||||||
|
|
@ -288,6 +288,8 @@ typedef struct safer_dirent
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "macosx_print.h"
|
#include "macosx_print.h"
|
||||||
|
#include "wrapperdata.h"
|
||||||
|
extern WrapperData macosx;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
@ -1244,7 +1246,7 @@ static void hsvtorgb(float h, float s, float v, Uint8 * r8, Uint8 * g8,
|
||||||
SDL_Surface *flip_surface(SDL_Surface * s);
|
SDL_Surface *flip_surface(SDL_Surface * s);
|
||||||
SDL_Surface *mirror_surface(SDL_Surface * s);
|
SDL_Surface *mirror_surface(SDL_Surface * s);
|
||||||
|
|
||||||
static void do_print(void);
|
void do_print(void);
|
||||||
static void strip_trailing_whitespace(char *buf);
|
static void strip_trailing_whitespace(char *buf);
|
||||||
static void do_render_cur_text(int do_blit);
|
static void do_render_cur_text(int do_blit);
|
||||||
static char *uppercase(char *str);
|
static char *uppercase(char *str);
|
||||||
|
|
@ -7235,6 +7237,10 @@ static void setup(int argc, char *argv[])
|
||||||
scale = 2;
|
scale = 2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
cursor_arrow = SDL_GetCursor(); // use standard system cursor
|
||||||
|
#endif
|
||||||
|
|
||||||
// this one first, because we need it yesterday
|
// this one first, because we need it yesterday
|
||||||
cursor_watch = get_cursor(watch_bits, watch_mask_bits,
|
cursor_watch = get_cursor(watch_bits, watch_mask_bits,
|
||||||
watch_width, watch_height,
|
watch_width, watch_height,
|
||||||
|
|
@ -7251,6 +7257,12 @@ static void setup(int argc, char *argv[])
|
||||||
|
|
||||||
// continuing on with the rest of the cursors...
|
// continuing on with the rest of the cursors...
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
cursor_arrow = get_cursor(arrow_bits, arrow_mask_bits,
|
||||||
|
arrow_width, arrow_height, 0, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
cursor_hand = get_cursor(hand_bits, hand_mask_bits,
|
cursor_hand = get_cursor(hand_bits, hand_mask_bits,
|
||||||
hand_width, hand_height, 12 / scale, 1 / scale);
|
hand_width, hand_height, 12 / scale, 1 / scale);
|
||||||
|
|
||||||
|
|
@ -7272,9 +7284,6 @@ static void setup(int argc, char *argv[])
|
||||||
rotate_width, rotate_height,
|
rotate_width, rotate_height,
|
||||||
15 / scale, 15 / scale);
|
15 / scale, 15 / scale);
|
||||||
|
|
||||||
cursor_arrow = get_cursor(arrow_bits, arrow_mask_bits,
|
|
||||||
arrow_width, arrow_height, 0, 0);
|
|
||||||
|
|
||||||
cursor_up = get_cursor(up_bits, up_mask_bits,
|
cursor_up = get_cursor(up_bits, up_mask_bits,
|
||||||
up_width, up_height, 15 / scale, 1 / scale);
|
up_width, up_height, 15 / scale, 1 / scale);
|
||||||
|
|
||||||
|
|
@ -15079,7 +15088,7 @@ static void hsvtorgb(float h, float s, float v, Uint8 * r8, Uint8 * g8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void do_print(void)
|
void do_print(void)
|
||||||
{
|
{
|
||||||
#if !defined(WIN32) && !defined(__BEOS__) && !defined(__APPLE__)
|
#if !defined(WIN32) && !defined(__BEOS__) && !defined(__APPLE__)
|
||||||
char *pcmd;
|
char *pcmd;
|
||||||
|
|
@ -15134,15 +15143,15 @@ static void do_print(void)
|
||||||
SurfacePrint(canvas);
|
SurfacePrint(canvas);
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
/* Mac OS X */
|
/* Mac OS X */
|
||||||
|
int show = ( ( want_alt_printcommand || macosx.menuAction ) && !fullscreen);
|
||||||
int show = (want_alt_printcommand && !fullscreen);
|
|
||||||
|
|
||||||
const char *error = SurfacePrint(canvas, show);
|
const char *error = SurfacePrint(canvas, show);
|
||||||
|
/*
|
||||||
if (error)
|
if (error)
|
||||||
fprintf(stderr, "Cannot print: %s\n", error);
|
fprintf(stderr, "Cannot print: %s\n", error);
|
||||||
else
|
else
|
||||||
do_prompt_snd(PROMPT_PRINT_TXT, PROMPT_PRINT_YES, "", SND_TUXOK);
|
do_prompt_snd(PROMPT_PRINT_TXT, PROMPT_PRINT_YES, "", SND_TUXOK);
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue