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
This commit is contained in:
Fred Kiefer 2011-06-05 21:55:34 +00:00
parent 503ebee65b
commit 029df7575f
5 changed files with 210 additions and 43 deletions

View file

@ -1,3 +1,10 @@
2011-06-05 Fred Kiefer <FredKiefer@gmx.de>
* 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 <wolfgang.lux@gmail.com> 2011-06-04 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSApplication.m (-_init, -finishLaunching): Create the * Source/NSApplication.m (-_init, -finishLaunching): Create the

View file

@ -35,7 +35,12 @@
#import <AppKit/NSPanel.h> #import <AppKit/NSPanel.h>
@class NSArray;
@class NSMutableArray;
@class NSSet;
@class NSString;
@class NSView; @class NSView;
@class NSViewController;
@class NSPrintInfo; @class NSPrintInfo;
enum { enum {
@ -65,12 +70,41 @@ enum {
NSPPOptionOKButton = 40 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 @interface NSPrintPanel : NSPanel
{ {
id _panel; id _panel;
id _optionPanel; id _optionPanel;
id _accessoryView; NSView *_accessoryView;
id _savePath; NSString *_savePath;
NSPrintInfo *_printInfo;
NSMutableArray *_accessoryControllers;
NSString *_jobStyleHint;
NSString *_helpAnchor;
NSPrintPanelOptions _options;
int _picked; int _picked;
NSRange _pages; //this may also be removed NSRange _pages; //this may also be removed
} }
@ -83,13 +117,32 @@ enum {
// //
// Customizing the Panel // Customizing the Panel
// //
#if OS_API_VERSION(GS_API_NONE, MAC_OS_X_VERSION_10_5)
- (void)setAccessoryView:(NSView *)aView; - (void)setAccessoryView:(NSView *)aView;
- (NSView *)accessoryView; - (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 // Running the Panel
// //
- (int) runModal; - (NSInteger) runModal;
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
- (void) beginSheetWithPrintInfo: (NSPrintInfo *)printInfo - (void) beginSheetWithPrintInfo: (NSPrintInfo *)printInfo
modalForWindow: (NSWindow *)docWindow modalForWindow: (NSWindow *)docWindow
@ -98,6 +151,12 @@ enum {
contextInfo: (void *)contextInfo; contextInfo: (void *)contextInfo;
#endif #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 // Updating the Panel's Display
// //
@ -110,7 +169,7 @@ enum {
// //
- (void)updateFromPrintInfo; - (void)updateFromPrintInfo;
- (void)finalWritePrintInfo; - (void)finalWritePrintInfo;
#endif
@end @end
// //

View file

@ -502,8 +502,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
[panel setAccessoryView: _accessory_view]; [panel setAccessoryView: _accessory_view];
[self _setupPrintInfo]; [self _setupPrintInfo];
[panel updateFromPrintInfo]; button = [panel runModalWithPrintInfo: _print_info];
button = [panel runModal];
[panel setAccessoryView: nil]; [panel setAccessoryView: nil];
if (button != NSOKButton) if (button != NSOKButton)
@ -511,7 +510,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
[self cleanUpOperation]; [self cleanUpOperation];
return NO; return NO;
} }
[panel finalWritePrintInfo];
} }
result = NO; result = NO;
@ -549,7 +547,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
*/ */
[panel setAccessoryView: _accessory_view]; [panel setAccessoryView: _accessory_view];
[self _setupPrintInfo]; [self _setupPrintInfo];
[panel updateFromPrintInfo];
[panel beginSheetWithPrintInfo: _print_info [panel beginSheetWithPrintInfo: _print_info
modalForWindow: docWindow modalForWindow: docWindow
delegate: self delegate: self
@ -714,8 +711,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
if (returnCode == NSOKButton) if (returnCode == NSOKButton)
{ {
NSPrintPanel *panel = [self printPanel];
[panel finalWritePrintInfo];
if ([self _runOperation]) if ([self _runOperation])
success = [self deliverResult]; success = [self deliverResult];
} }

View file

@ -49,12 +49,17 @@
#import "GSGuiPrivate.h" #import "GSGuiPrivate.h"
#import "GNUstepGUI/GSPrinting.h" #import "GNUstepGUI/GSPrinting.h"
static NSPrintPanel *shared_instance; static NSPrintPanel *shared_instance = nil;
#define GSPANELNAME @"GSPrintPanel" #define GSPANELNAME @"GSPrintPanel"
#define CONTROL(panel, name) [[panel contentView] viewWithTag: name] #define CONTROL(panel, name) [[panel contentView] viewWithTag: name]
@interface NSPrintPanel (GSPrivate)
- (void)_updateFromPrintInfo: (NSPrintInfo*)info;
- (void)_finalWritePrintInfo: (NSPrintInfo*)info;
@end
/** /**
<unit> <unit>
<heading>Class Description</heading> <heading>Class Description</heading>
@ -110,10 +115,8 @@ static NSPrintPanel *shared_instance;
// //
- (id) init - (id) init
{ {
int style = NSTitledWindowMask; return [self initWithContentRect: NSMakeRect(300, 300, 420, 350)
NSRect frame = NSMakeRect(300, 300, 420, 350); styleMask: NSTitledWindowMask
return [self initWithContentRect: frame
styleMask: style
backing: NSBackingStoreBuffered backing: NSBackingStoreBuffered
defer: YES]; defer: YES];
} }
@ -137,6 +140,11 @@ static NSPrintPanel *shared_instance;
if (self == nil) if (self == nil)
return 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 // self will come from a bundle, to get the panel from the GUI library
// we have to select that bundle explicitly // we have to select that bundle explicitly
panel = [GSGuiBundle() pathForNibResource: GSPANELNAME]; panel = [GSGuiBundle() pathForNibResource: GSPANELNAME];
@ -156,9 +164,6 @@ static NSPrintPanel *shared_instance;
return nil; return nil;
} }
/* Set the title */
[self setTitle: _(@"Print Panel")];
/* Transfer the objects to us. FIXME: There must be a way to /* Transfer the objects to us. FIXME: There must be a way to
instantiate the panel directly */ instantiate the panel directly */
subviews = [[_panel contentView] subviews]; subviews = [[_panel contentView] subviews];
@ -187,7 +192,11 @@ static NSPrintPanel *shared_instance;
RELEASE(_accessoryView); RELEASE(_accessoryView);
RELEASE(_savePath); RELEASE(_savePath);
RELEASE(_optionPanel); RELEASE(_optionPanel);
RELEASE(_printInfo);
RELEASE(_accessoryControllers);
RELEASE(_jobStyleHint);
RELEASE(_helpAnchor);
[super dealloc]; [super dealloc];
} }
@ -197,7 +206,7 @@ static NSPrintPanel *shared_instance;
/** <p>Sets the accessory view for the print panel to aView</p> /** <p>Sets the accessory view for the print panel to aView</p>
<p>See Also: -accessoryView</p> <p>See Also: -accessoryView</p>
*/ */
- (void)setAccessoryView:(NSView *)aView - (void) setAccessoryView: (NSView *)aView
{ {
ASSIGN(_accessoryView, aView); ASSIGN(_accessoryView, aView);
} }
@ -205,11 +214,75 @@ static NSPrintPanel *shared_instance;
/** <p>Returns the accessory view for the print panel </p> /** <p>Returns the accessory view for the print panel </p>
<p>See Also: -setAccessoryView:</p> <p>See Also: -setAccessoryView:</p>
*/ */
- (NSView *)accessoryView - (NSView *) accessoryView
{ {
return _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 // Running the Panel
// //
@ -220,13 +293,23 @@ static NSPrintPanel *shared_instance;
itself out after the modal session is finished. You must do that itself out after the modal session is finished. You must do that
yourself. yourself.
*/ */
- (int)runModal - (NSInteger)runModal
{ {
int ret; NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo];
return [self runModalWithPrintInfo: info];
}
- (NSInteger) runModalWithPrintInfo: (NSPrintInfo *)printInfo
{
NSInteger ret;
_picked = NSOKButton; _picked = NSOKButton;
ASSIGN(_printInfo, printInfo);
// Set the values from printInfo
[self _updateFromPrintInfo: _printInfo];
ret = [NSApp runModalForWindow: self]; ret = [NSApp runModalForWindow: self];
[_optionPanel orderOut: self]; [_optionPanel orderOut: self];
DESTROY(_printInfo);
/* Don't order ourselves out, let the NSPrintOperation do that */ /* Don't order ourselves out, let the NSPrintOperation do that */
return ret; return ret;
} }
@ -238,16 +321,19 @@ static NSPrintPanel *shared_instance;
contextInfo: (void *)contextInfo contextInfo: (void *)contextInfo
{ {
_picked = NSOKButton; _picked = NSOKButton;
ASSIGN(_printInfo, printInfo);
// Set the values from printInfo
[self _updateFromPrintInfo: _printInfo];
[NSApp beginSheet: self [NSApp beginSheet: self
modalForWindow: docWindow modalForWindow: docWindow
modalDelegate: delegate modalDelegate: delegate
didEndSelector: didEndSelector didEndSelector: didEndSelector
contextInfo: contextInfo]; contextInfo: contextInfo];
[_optionPanel orderOut: self]; [_optionPanel orderOut: self];
DESTROY(_printInfo);
[self orderOut: self]; [self orderOut: self];
} }
- (BOOL) _getSavePath - (BOOL) _getSavePath
{ {
int result; int result;
@ -268,6 +354,9 @@ static NSPrintPanel *shared_instance;
{ {
int tag = [sender tag]; int tag = [sender tag];
// FIXME
[self _finalWritePrintInfo: _printInfo];
if (tag == NSPPSaveButton) if (tag == NSPPSaveButton)
{ {
_picked = NSPPSaveButton; _picked = NSPPSaveButton;
@ -282,7 +371,7 @@ static NSPrintPanel *shared_instance;
{ {
_picked = NSPPPreviewButton; _picked = NSPPPreviewButton;
} }
else if (tag ==NSFaxButton) else if (tag == NSFaxButton)
{ {
_picked = NSFaxButton; _picked = NSFaxButton;
NSRunAlertPanel(_(@"Sorry"), _(@"Faxing of print file not implemented"), NSRunAlertPanel(_(@"Sorry"), _(@"Faxing of print file not implemented"),
@ -318,12 +407,11 @@ static NSPrintPanel *shared_instance;
- (void) _pickedPrinter: (id)sender - (void) _pickedPrinter: (id)sender
{ {
NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo];
NSString *name = [sender titleOfSelectedItem]; NSString *name = [sender titleOfSelectedItem];
NSPrinter *printer = [NSPrinter printerWithName: name]; NSPrinter *printer = [NSPrinter printerWithName: name];
[info setPrinter: printer]; [_printInfo setPrinter: printer];
[self updateFromPrintInfo]; [self _updateFromPrintInfo: _printInfo];
} }
- (void) _pickedPage: (id)sender - (void) _pickedPage: (id)sender
@ -353,7 +441,7 @@ static NSPrintPanel *shared_instance;
- (void)pickedButton:(id)sender - (void)pickedButton:(id)sender
{ {
NSLog(@"[NSPrintPanel -pickedButton:] method depreciated"); NSLog(@"[NSPrintPanel -pickedButton:] method depreciated");
[self pickedButton: sender]; [self _pickedButton: sender];
} }
/** This method has been depreciated. It doesn't do anything useful. /** 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. in the NSPrintInfo object from the current NSPrintOperation.
*/ */
- (void)updateFromPrintInfo - (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; id control;
int layout; int layout;
@ -385,7 +498,6 @@ static NSPrintPanel *shared_instance;
NSString *str; NSString *str;
NSPrinter *printer; NSPrinter *printer;
NSDictionary *dict; NSDictionary *dict;
NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo];
printer = [info printer]; printer = [info printer];
dict = [info dictionary]; dict = [info dictionary];
@ -528,15 +640,11 @@ static NSPrintPanel *shared_instance;
} }
else else
[control addItemWithTitle: _(@"Unknown")]; [control addItemWithTitle: _(@"Unknown")];
} }
#define NSNUMBER(a) [NSNumber numberWithInt: (a)] #define NSNUMBER(a) [NSNumber numberWithInt: (a)]
/** Saves information set by the user in the receiver's panel - (void)_finalWritePrintInfo: (NSPrintInfo*)info
in the NSPrintInfo object from the current NSPrintOperation.
*/
- (void)finalWritePrintInfo
{ {
id control; id control;
double scale; double scale;
@ -546,7 +654,7 @@ static NSPrintPanel *shared_instance;
NSPrinter *printer; NSPrinter *printer;
NSMutableDictionary *dict; NSMutableDictionary *dict;
NSMutableDictionary *features; NSMutableDictionary *features;
NSPrintInfo* info = [[NSPrintOperation currentOperation] printInfo];
dict = [info dictionary]; dict = [info dictionary];
printer = [info printer]; printer = [info printer];
features = [dict objectForKey: NSPrintJobFeatures]; features = [dict objectForKey: NSPrintJobFeatures];
@ -683,12 +791,5 @@ static NSPrintPanel *shared_instance;
NSDebugLLog(@"NSPrinting", NSDebugLLog(@"NSPrinting",
@"Final info dictionary ----\n %@ \n --------------", dict); @"Final info dictionary ----\n %@ \n --------------", dict);
}
/* Private method for NSPrintOperation */
- (void) _setStatusStringValue: (NSString *)string
{
[CONTROL(self, NSPPStatusField) setStringValue: string ];
} }
@end @end

View file

@ -353,6 +353,11 @@ NSString *NSPrintPreviewJob = @"PrintPreviewJob";
NSString *NSPrintSaveJob = @"PrintSaveJob"; NSString *NSPrintSaveJob = @"PrintSaveJob";
NSString *NSPrintSpoolJob = @"PrintSpoolJob"; NSString *NSPrintSpoolJob = @"PrintSpoolJob";
// Print Panel
NSString *NSPrintPanelAccessorySummaryItemNameKey = @"AccessorySummaryItemName";
NSString *NSPrintPanelAccessorySummaryItemDescriptionKey = @"AccessorySummaryItemDescription";
NSString *NSPrintPhotoJobStyleHint = @"PhotoJobStyle";
// NSSplitView notifications // NSSplitView notifications
NSString *NSSplitViewDidResizeSubviewsNotification = NSString *NSSplitViewDidResizeSubviewsNotification =
@"NSSplitViewDidResizeSubviewsNotification"; @"NSSplitViewDidResizeSubviewsNotification";