Mac OS X Reference Library Apple Developer
Search

Using a Print Panel

NSPrintPanel creates a Print panel, which is used to query the user for information about a print job, such as which pages to print and how many copies.

When a print: message is sent to an NSView or NSWindow, an NSPrintOperation object is created to control the print operation (see “Creating a Print Job” for details). An NSPrintOperation object uses an NSPrintPanel unless it is sent the setShowPanels: message, passing NO as the argument. If you want to use a custom subclass for a particular print operation, pass an instance of your subclass to the print operation using the setPrintPanel: message.

However, you rarely need to subclass NSPrintPanel because you can augment its display by adding your own accessory view using the setAccessoryView: method. Place controls for setting application-specific print settings on your accessory view. The accessory view is displayed when the user chooses the appropriate entry in the pane-selection pop-up menu in the Print panel. The application’s name is used for the accessory view’s entry in the menu. The panel automatically resizes to accommodate the view you add. If possible, you should make your accessory view the same size as the standard views in the panel.

Typically, you do not need to create an NSPrintPanel yourself. NSPrintOperation creates a standard panel for you if you do not set a different one with setPrintPanel:. Even if you need to add an accessory view, you can have NSPrintOperation add your view to its default panel using its setAccessoryView: method as shown here:

- (void)print:(id)sender {
    NSPrintOperation *op = [NSPrintOperation printOperationWithView:self];
    // Assume printAccessoryView exists and returns your custom view
    NSView *accView = [self printAccessoryView];
    [op setAccessoryView:accView];
    [op runOperation];
}

If you do need to create an NSPrintPanel, use the printPanel class method.




Last updated: 2006-06-28

Did this document help you? Yes It's good, but... Not helpful...