From 029df7575fd88e2ba7df2720198d0286fd0419e5 Mon Sep 17 00:00:00 2001 From: Fred Kiefer Date: Sun, 5 Jun 2011 21:55:34 +0000 Subject: [PATCH] Add newer MacOSX methods to NSPrintPanel git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33252 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 ++ Headers/AppKit/NSPrintPanel.h | 67 +++++++++++++- Source/NSPrintOperation.m | 7 +- Source/NSPrintPanel.m | 167 +++++++++++++++++++++++++++------- Source/externs.m | 5 + 5 files changed, 210 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 696f6ee22..8a4168b07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-05 Fred Kiefer + + * Headers/AppKit/NSPrintPanel.h, + * Source/NSPrintPanel.m: Add newer methods and ivars for these. + * Source/NSPrintOperation.m: User newer NSPrintPanel interfaces. + * Source/externs.m: Define a few strings for NSPrintPanel. + 2011-06-04 Wolfgang Lux * Source/NSApplication.m (-_init, -finishLaunching): Create the diff --git a/Headers/AppKit/NSPrintPanel.h b/Headers/AppKit/NSPrintPanel.h index e695ffe17..b884beb0a 100644 --- a/Headers/AppKit/NSPrintPanel.h +++ b/Headers/AppKit/NSPrintPanel.h @@ -35,7 +35,12 @@ #import +@class NSArray; +@class NSMutableArray; +@class NSSet; +@class NSString; @class NSView; +@class NSViewController; @class NSPrintInfo; enum { @@ -65,12 +70,41 @@ enum { NSPPOptionOKButton = 40 }; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST) +@protocol NSPrintPanelAccessorizing +- (NSSet *) keyPathsForValuesAffectingPreview; +- (NSArray *) localizedSummaryItems; +@end + +enum { + NSPrintPanelShowsCopies = 0x01, + NSPrintPanelShowsPageRange = 0x02, + NSPrintPanelShowsPaperSize = 0x04, + NSPrintPanelShowsOrientation = 0x08, + NSPrintPanelShowsScaling = 0x10, + NSPrintPanelShowsPageSetupAccessory = 0x100, + NSPrintPanelShowsPreview = 0x20000 +}; +typedef NSInteger NSPrintPanelOptions; + +NSString *NSPrintPanelAccessorySummaryItemNameKey; +NSString *NSPrintPanelAccessorySummaryItemDescriptionKey; +#endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST) +NSString *NSPrintPhotoJobStyleHint; +#endif + @interface NSPrintPanel : NSPanel { id _panel; id _optionPanel; - id _accessoryView; - id _savePath; + NSView *_accessoryView; + NSString *_savePath; + NSPrintInfo *_printInfo; + NSMutableArray *_accessoryControllers; + NSString *_jobStyleHint; + NSString *_helpAnchor; + NSPrintPanelOptions _options; int _picked; NSRange _pages; //this may also be removed } @@ -83,13 +117,32 @@ enum { // // Customizing the Panel // +#if OS_API_VERSION(GS_API_NONE, MAC_OS_X_VERSION_10_5) - (void)setAccessoryView:(NSView *)aView; - (NSView *)accessoryView; +#endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST) +- (NSArray *) accessoryControllers; +- (void) addAccessoryController: (NSViewController < NSPrintPanelAccessorizing >*)accessoryController; +- (void) removeAccessoryController: (NSViewController < NSPrintPanelAccessorizing >*)accessoryController; + +- (NSString *) defaultButtonTitle; +- (void) setDefaultButtonTitle: (NSString *)defaultButtonTitle; + +- (NSPrintPanelOptions) options; +- (void) setOptions: (NSPrintPanelOptions)options; + +- (NSString *) helpAnchor; +- (void) setHelpAnchor: (NSString *)helpAnchor; + +- (NSPrintInfo *) printInfo; +- (NSInteger) runModalWithPrintInfo: (NSPrintInfo *)printInfo; +#endif // // Running the Panel // -- (int) runModal; +- (NSInteger) runModal; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) - (void) beginSheetWithPrintInfo: (NSPrintInfo *)printInfo modalForWindow: (NSWindow *)docWindow @@ -98,6 +151,12 @@ enum { contextInfo: (void *)contextInfo; #endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST) +- (NSString *) jobStyleHint; +- (void) setJobStyleHint: (NSString *)hint; +#endif + +#if OS_API_VERSION(GS_API_NONE, MAC_OS_X_VERSION_10_5) // // Updating the Panel's Display // @@ -110,7 +169,7 @@ enum { // - (void)updateFromPrintInfo; - (void)finalWritePrintInfo; - +#endif @end // diff --git a/Source/NSPrintOperation.m b/Source/NSPrintOperation.m index 892cafd05..584250913 100644 --- a/Source/NSPrintOperation.m +++ b/Source/NSPrintOperation.m @@ -502,8 +502,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; [panel setAccessoryView: _accessory_view]; [self _setupPrintInfo]; - [panel updateFromPrintInfo]; - button = [panel runModal]; + button = [panel runModalWithPrintInfo: _print_info]; [panel setAccessoryView: nil]; if (button != NSOKButton) @@ -511,7 +510,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; [self cleanUpOperation]; return NO; } - [panel finalWritePrintInfo]; } result = NO; @@ -549,7 +547,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; */ [panel setAccessoryView: _accessory_view]; [self _setupPrintInfo]; - [panel updateFromPrintInfo]; [panel beginSheetWithPrintInfo: _print_info modalForWindow: docWindow delegate: self @@ -714,8 +711,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; if (returnCode == NSOKButton) { - NSPrintPanel *panel = [self printPanel]; - [panel finalWritePrintInfo]; if ([self _runOperation]) success = [self deliverResult]; } diff --git a/Source/NSPrintPanel.m b/Source/NSPrintPanel.m index 4cb87043c..776855329 100644 --- a/Source/NSPrintPanel.m +++ b/Source/NSPrintPanel.m @@ -49,12 +49,17 @@ #import "GSGuiPrivate.h" #import "GNUstepGUI/GSPrinting.h" -static NSPrintPanel *shared_instance; +static NSPrintPanel *shared_instance = nil; #define GSPANELNAME @"GSPrintPanel" #define CONTROL(panel, name) [[panel contentView] viewWithTag: name] +@interface NSPrintPanel (GSPrivate) +- (void)_updateFromPrintInfo: (NSPrintInfo*)info; +- (void)_finalWritePrintInfo: (NSPrintInfo*)info; +@end + /** Class Description @@ -110,10 +115,8 @@ static NSPrintPanel *shared_instance; // - (id) init { - int style = NSTitledWindowMask; - NSRect frame = NSMakeRect(300, 300, 420, 350); - return [self initWithContentRect: frame - styleMask: style + return [self initWithContentRect: NSMakeRect(300, 300, 420, 350) + styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: YES]; } @@ -137,6 +140,11 @@ static NSPrintPanel *shared_instance; if (self == nil) return nil; + /* Set the title */ + [self setTitle: _(@"Print Panel")]; + + _accessoryControllers = [[NSMutableArray alloc] init]; + // self will come from a bundle, to get the panel from the GUI library // we have to select that bundle explicitly panel = [GSGuiBundle() pathForNibResource: GSPANELNAME]; @@ -156,9 +164,6 @@ static NSPrintPanel *shared_instance; return nil; } - /* Set the title */ - [self setTitle: _(@"Print Panel")]; - /* Transfer the objects to us. FIXME: There must be a way to instantiate the panel directly */ subviews = [[_panel contentView] subviews]; @@ -187,7 +192,11 @@ static NSPrintPanel *shared_instance; RELEASE(_accessoryView); RELEASE(_savePath); RELEASE(_optionPanel); - + RELEASE(_printInfo); + RELEASE(_accessoryControllers); + RELEASE(_jobStyleHint); + RELEASE(_helpAnchor); + [super dealloc]; } @@ -197,7 +206,7 @@ static NSPrintPanel *shared_instance; /**

Sets the accessory view for the print panel to aView

See Also: -accessoryView

*/ -- (void)setAccessoryView:(NSView *)aView +- (void) setAccessoryView: (NSView *)aView { ASSIGN(_accessoryView, aView); } @@ -205,11 +214,75 @@ static NSPrintPanel *shared_instance; /**

Returns the accessory view for the print panel

See Also: -setAccessoryView:

*/ -- (NSView *)accessoryView +- (NSView *) accessoryView { return _accessoryView; } +- (NSArray *) accessoryControllers +{ + return _accessoryControllers; +} + +- (void) addAccessoryController: (NSViewController < NSPrintPanelAccessorizing >*)accessoryController +{ + [_accessoryControllers addObject: accessoryController]; +} + +- (void) removeAccessoryController: (NSViewController < NSPrintPanelAccessorizing >*)accessoryController +{ + [_accessoryControllers removeObjectIdenticalTo: accessoryController]; +} + +- (NSString *) defaultButtonTitle +{ + NSButton *defaultButton = CONTROL(self, NSOKButton); + + return [defaultButton title]; +} + +- (void) setDefaultButtonTitle: (NSString *)defaultButtonTitle +{ + NSButton *defaultButton = CONTROL(self, NSOKButton); + + [defaultButton setTitle: defaultButtonTitle]; +} + +- (NSPrintPanelOptions) options +{ + return _options; +} + +- (void) setOptions: (NSPrintPanelOptions)options +{ + _options = options; +} + +- (NSString *) jobStyleHint +{ + return _jobStyleHint; +} + +- (void) setJobStyleHint: (NSString *)hint +{ + ASSIGN(_jobStyleHint, hint); +} + +- (NSString *) helpAnchor +{ + return _helpAnchor; +} + +- (void) setHelpAnchor: (NSString *)helpAnchor +{ + ASSIGN(_helpAnchor, helpAnchor); +} + +- (NSPrintInfo *) printInfo +{ + return _printInfo; +} + // // Running the Panel // @@ -220,13 +293,23 @@ static NSPrintPanel *shared_instance; itself out after the modal session is finished. You must do that yourself. */ -- (int)runModal +- (NSInteger)runModal { - int ret; + NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo]; + return [self runModalWithPrintInfo: info]; +} + +- (NSInteger) runModalWithPrintInfo: (NSPrintInfo *)printInfo +{ + NSInteger ret; _picked = NSOKButton; + ASSIGN(_printInfo, printInfo); + // Set the values from printInfo + [self _updateFromPrintInfo: _printInfo]; ret = [NSApp runModalForWindow: self]; [_optionPanel orderOut: self]; + DESTROY(_printInfo); /* Don't order ourselves out, let the NSPrintOperation do that */ return ret; } @@ -238,16 +321,19 @@ static NSPrintPanel *shared_instance; contextInfo: (void *)contextInfo { _picked = NSOKButton; + ASSIGN(_printInfo, printInfo); + // Set the values from printInfo + [self _updateFromPrintInfo: _printInfo]; [NSApp beginSheet: self modalForWindow: docWindow modalDelegate: delegate didEndSelector: didEndSelector contextInfo: contextInfo]; [_optionPanel orderOut: self]; + DESTROY(_printInfo); [self orderOut: self]; } - - (BOOL) _getSavePath { int result; @@ -268,6 +354,9 @@ static NSPrintPanel *shared_instance; { int tag = [sender tag]; + // FIXME + [self _finalWritePrintInfo: _printInfo]; + if (tag == NSPPSaveButton) { _picked = NSPPSaveButton; @@ -282,7 +371,7 @@ static NSPrintPanel *shared_instance; { _picked = NSPPPreviewButton; } - else if (tag ==NSFaxButton) + else if (tag == NSFaxButton) { _picked = NSFaxButton; NSRunAlertPanel(_(@"Sorry"), _(@"Faxing of print file not implemented"), @@ -318,12 +407,11 @@ static NSPrintPanel *shared_instance; - (void) _pickedPrinter: (id)sender { - NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo]; NSString *name = [sender titleOfSelectedItem]; NSPrinter *printer = [NSPrinter printerWithName: name]; - [info setPrinter: printer]; - [self updateFromPrintInfo]; + [_printInfo setPrinter: printer]; + [self _updateFromPrintInfo: _printInfo]; } - (void) _pickedPage: (id)sender @@ -353,7 +441,7 @@ static NSPrintPanel *shared_instance; - (void)pickedButton:(id)sender { NSLog(@"[NSPrintPanel -pickedButton:] method depreciated"); - [self pickedButton: sender]; + [self _pickedButton: sender]; } /** This method has been depreciated. It doesn't do anything useful. @@ -378,6 +466,31 @@ static NSPrintPanel *shared_instance; in the NSPrintInfo object from the current NSPrintOperation. */ - (void)updateFromPrintInfo +{ + NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo]; + + [self _updateFromPrintInfo: info]; +} + +/** Saves information set by the user in the receiver's panel + in the NSPrintInfo object from the current NSPrintOperation. +*/ +- (void)finalWritePrintInfo +{ + NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo]; + + [self _finalWritePrintInfo: info]; +} + +/* Private method for NSPrintOperation */ +- (void) _setStatusStringValue: (NSString *)string +{ + [CONTROL(self, NSPPStatusField) setStringValue: string ]; +} +@end + +@implementation NSPrintPanel (GSPrivate) +- (void)_updateFromPrintInfo: (NSPrintInfo*)info { id control; int layout; @@ -385,7 +498,6 @@ static NSPrintPanel *shared_instance; NSString *str; NSPrinter *printer; NSDictionary *dict; - NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo]; printer = [info printer]; dict = [info dictionary]; @@ -528,15 +640,11 @@ static NSPrintPanel *shared_instance; } else [control addItemWithTitle: _(@"Unknown")]; - } #define NSNUMBER(a) [NSNumber numberWithInt: (a)] -/** Saves information set by the user in the receiver's panel - in the NSPrintInfo object from the current NSPrintOperation. -*/ -- (void)finalWritePrintInfo +- (void)_finalWritePrintInfo: (NSPrintInfo*)info { id control; double scale; @@ -546,7 +654,7 @@ static NSPrintPanel *shared_instance; NSPrinter *printer; NSMutableDictionary *dict; NSMutableDictionary *features; - NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo]; + dict = [info dictionary]; printer = [info printer]; features = [dict objectForKey: NSPrintJobFeatures]; @@ -683,12 +791,5 @@ static NSPrintPanel *shared_instance; NSDebugLLog(@"NSPrinting", @"Final info dictionary ----\n %@ \n --------------", dict); - -} - -/* Private method for NSPrintOperation */ -- (void) _setStatusStringValue: (NSString *)string -{ - [CONTROL(self, NSPPStatusField) setStringValue: string ]; } @end diff --git a/Source/externs.m b/Source/externs.m index 912bd429b..d1333298c 100644 --- a/Source/externs.m +++ b/Source/externs.m @@ -353,6 +353,11 @@ NSString *NSPrintPreviewJob = @"PrintPreviewJob"; NSString *NSPrintSaveJob = @"PrintSaveJob"; NSString *NSPrintSpoolJob = @"PrintSpoolJob"; +// Print Panel +NSString *NSPrintPanelAccessorySummaryItemNameKey = @"AccessorySummaryItemName"; +NSString *NSPrintPanelAccessorySummaryItemDescriptionKey = @"AccessorySummaryItemDescription"; +NSString *NSPrintPhotoJobStyleHint = @"PhotoJobStyle"; + // NSSplitView notifications NSString *NSSplitViewDidResizeSubviewsNotification = @"NSSplitViewDidResizeSubviewsNotification";