Print configuration is now saved between Tux Paint sessions on Mac OS X.
This commit is contained in:
parent
23f586a668
commit
c0962bf16e
5 changed files with 98 additions and 37 deletions
|
|
@ -26,6 +26,7 @@
|
||||||
- (IBAction)onQuit:(id)sender;
|
- (IBAction)onQuit:(id)sender;
|
||||||
|
|
||||||
- (void) sendSDLControlKeystroke:(int)key;
|
- (void) sendSDLControlKeystroke:(int)key;
|
||||||
|
- (void) sendSDLControlShiftKeystroke:(int)key;
|
||||||
- (void) setupBridge;
|
- (void) setupBridge;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ static NSString *getApplicationName(void)
|
||||||
|
|
||||||
- (IBAction) onPageSetup:(id)sender
|
- (IBAction) onPageSetup:(id)sender
|
||||||
{
|
{
|
||||||
DisplayPageSetup();
|
[self sendSDLControlShiftKeystroke:SDLK_p];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction) onUndo:(id)sender
|
- (IBAction) onUndo:(id)sender
|
||||||
|
|
@ -204,6 +204,8 @@ static NSString *getApplicationName(void)
|
||||||
|
|
||||||
- (IBAction) onQuit:(id)sender
|
- (IBAction) onQuit:(id)sender
|
||||||
{
|
{
|
||||||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
|
|
||||||
/* Post a SDL_QUIT event */
|
/* Post a SDL_QUIT event */
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
event.type = SDL_QUIT;
|
event.type = SDL_QUIT;
|
||||||
|
|
@ -219,6 +221,15 @@ static NSString *getApplicationName(void)
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) sendSDLControlShiftKeystroke:(int)key
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = SDL_KEYDOWN;
|
||||||
|
event.key.keysym.sym = key;
|
||||||
|
event.key.keysym.mod = KMOD_CTRL | KMOD_SHIFT;
|
||||||
|
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
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,10 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
const char *SurfacePrint(SDL_Surface *surface, int showDialog);
|
const char *SurfacePrint(SDL_Surface *surface, int showDialog);
|
||||||
|
int DisplayPageSetup(const SDL_Surface *surface);
|
||||||
|
|
||||||
#ifdef OBJECTIVEC
|
#ifdef OBJECTIVEC
|
||||||
|
|
||||||
BOOL DisplayPageSetup();
|
|
||||||
|
|
||||||
@interface PrintSheetController : NSObject
|
@interface PrintSheetController : NSObject
|
||||||
{
|
{
|
||||||
bool displayPrintSetupSheet;
|
bool displayPrintSetupSheet;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
extern WrapperData macosx;
|
extern WrapperData macosx;
|
||||||
|
NSData* printData = nil;
|
||||||
|
|
||||||
// this object presents the image to the printing layer
|
// this object presents the image to the printing layer
|
||||||
@interface ImageView : NSView
|
@interface ImageView : NSView
|
||||||
|
|
@ -179,33 +180,8 @@ static NSImage* CreateImage( SDL_Surface *surface )
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DisplayPageSetup()
|
void DefaultPrintSettings( const SDL_Surface *surface, NSPrintInfo *printInfo )
|
||||||
{
|
{
|
||||||
NSPageLayout* pageLayout;
|
|
||||||
NSPrintInfo* printInfo;
|
|
||||||
ModalDelegate* delegate;
|
|
||||||
BOOL result;
|
|
||||||
|
|
||||||
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 )
|
if( surface->w > surface->h )
|
||||||
[ printInfo setOrientation:NSLandscapeOrientation ];
|
[ printInfo setOrientation:NSLandscapeOrientation ];
|
||||||
else
|
else
|
||||||
|
|
@ -217,6 +193,78 @@ void DefaultPrintSettings( SDL_Surface *surface )
|
||||||
[ printInfo setHorizontalPagination:NSFitPagination ];
|
[ printInfo setHorizontalPagination:NSFitPagination ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSPrintInfo* LoadPrintInfo( const SDL_Surface *surface )
|
||||||
|
{
|
||||||
|
NSUserDefaults* standardUserDefaults;
|
||||||
|
NSPrintInfo* printInfo;
|
||||||
|
NSData* printData = nil;
|
||||||
|
static BOOL firstTime = YES;
|
||||||
|
|
||||||
|
standardUserDefaults = [ NSUserDefaults standardUserDefaults ];
|
||||||
|
|
||||||
|
if( standardUserDefaults )
|
||||||
|
{
|
||||||
|
printData = [ standardUserDefaults dataForKey:@"PrintInfo" ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( printData )
|
||||||
|
{
|
||||||
|
printInfo = (NSPrintInfo*)[ NSUnarchiver unarchiveObjectWithData:printData ];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printInfo = [ NSPrintInfo sharedPrintInfo ];
|
||||||
|
if( firstTime == YES )
|
||||||
|
{
|
||||||
|
DefaultPrintSettings( surface, printInfo );
|
||||||
|
firstTime = NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return printInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SavePrintInfo( NSPrintInfo* printInfo )
|
||||||
|
{
|
||||||
|
NSUserDefaults* standardUserDefaults;
|
||||||
|
NSData* printData = nil;
|
||||||
|
|
||||||
|
printData = [ NSArchiver archivedDataWithRootObject:printInfo ];
|
||||||
|
standardUserDefaults = [ NSUserDefaults standardUserDefaults ];
|
||||||
|
|
||||||
|
if( standardUserDefaults )
|
||||||
|
{
|
||||||
|
[ standardUserDefaults setObject:printData forKey:@"PrintInfo" ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DisplayPageSetup( const SDL_Surface * surface )
|
||||||
|
{
|
||||||
|
NSPageLayout* pageLayout;
|
||||||
|
NSPrintInfo* printInfo;
|
||||||
|
ModalDelegate* delegate;
|
||||||
|
BOOL result;
|
||||||
|
|
||||||
|
macosx.cocoaKeystrokes = 1;
|
||||||
|
|
||||||
|
printInfo = LoadPrintInfo( surface );
|
||||||
|
|
||||||
|
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 ];
|
||||||
|
SavePrintInfo( printInfo );
|
||||||
|
|
||||||
|
macosx.cocoaKeystrokes = 0;
|
||||||
|
|
||||||
|
return (int)( result );
|
||||||
|
}
|
||||||
|
|
||||||
const char* SurfacePrint( SDL_Surface *surface, int showDialog )
|
const char* SurfacePrint( SDL_Surface *surface, int showDialog )
|
||||||
{
|
{
|
||||||
NSImage* image;
|
NSImage* image;
|
||||||
|
|
@ -225,7 +273,6 @@ 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;
|
||||||
|
|
||||||
|
|
@ -234,13 +281,8 @@ const char* SurfacePrint( SDL_Surface *surface, int showDialog )
|
||||||
if( image == nil )
|
if( image == nil )
|
||||||
return "Could not create image";
|
return "Could not create image";
|
||||||
|
|
||||||
if( firstTime == YES ) {
|
|
||||||
DefaultPrintSettings( surface );
|
|
||||||
firstTime = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create print control objects
|
// create print control objects
|
||||||
printInfo = [ NSPrintInfo sharedPrintInfo ];
|
printInfo = LoadPrintInfo( surface );
|
||||||
|
|
||||||
NSRect pageRect = [ printInfo imageablePageBounds ];
|
NSRect pageRect = [ printInfo imageablePageBounds ];
|
||||||
NSSize pageSize = pageRect.size;
|
NSSize pageSize = pageRect.size;
|
||||||
|
|
@ -285,6 +327,8 @@ const char* SurfacePrint( SDL_Surface *surface, int showDialog )
|
||||||
error = "Canceled or error when printing";
|
error = "Canceled or error when printing";
|
||||||
|
|
||||||
macosx.cocoaKeystrokes = 0;
|
macosx.cocoaKeystrokes = 0;
|
||||||
|
|
||||||
|
SavePrintInfo( printInfo );
|
||||||
[ image release ];
|
[ image release ];
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
|
||||||
|
|
@ -2051,6 +2051,12 @@ static void mainloop(void)
|
||||||
draw_toolbar();
|
draw_toolbar();
|
||||||
update_screen_rect(&r_tools);
|
update_screen_rect(&r_tools);
|
||||||
}
|
}
|
||||||
|
#ifdef __APPLE__
|
||||||
|
else if (key == SDLK_p && (mod & KMOD_CTRL) && (mod & KMOD_SHIFT) && !noshortcuts) {
|
||||||
|
/* Ctrl-Shft-P - Page Setup */
|
||||||
|
DisplayPageSetup(canvas);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else if (key == SDLK_p && (mod & KMOD_CTRL) && !noshortcuts)
|
else if (key == SDLK_p && (mod & KMOD_CTRL) && !noshortcuts)
|
||||||
{
|
{
|
||||||
/* Ctrl-P - Print */
|
/* Ctrl-P - Print */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue