< Previous PageNext Page > Hide TOC

Using a Page Setup Panel

NSPageLayout creates a panel that queries the user for information such as paper size and orientation. This information is stored in an NSPrintInfo object, and is later used when printing. The NSPageLayout panel is created, displayed, and run when a runPageLayout: message is sent to the NSApplication or an NSDocument object. NSApplication runs it as a modal panel, whereas NSDocument runs it as a sheet. By default, this message is sent up the responder chain when the user chooses the Page Setup menu command.

If the NSApplication or NSDocument implementation is not sufficient you can handle the Page Setup panel yourself. Typically, you create an NSPageLayout object by invoking the pageLayout method. It can be run application modally using runModal or runModalWithPrintInfo:, or document modally as a sheet using beginSheetWithPrintInfo:modalForWindow:delegate:didEndSelector:contextInfo:.

You rarely need to subclass NSPageLayout 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 Settings pop-up menu in the Page Setup 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.

When running a non-NSDocument-based application, you need to override NSApplication’s runPageLayout: method (or implement the method earlier in the responder chain), if you need to add an accessory view. Your method might look like this:

- (void)runPageLayout:(id)sender {
    NSPageLayout *pageLayout = [NSPageLayout pageLayout];
    // Assume layoutAccessoryView exists and returns your custom view
    NSView *accView = [self layoutAccessoryView];
    [pageLayout setAccessoryView:accView];
    [pageLayout runModal];
}

When running an NSDocument-based application, NSDocument’s default implementation of runPageLayout: creates the page layout panel and then passes the object to its preparePageLayout: method. Override this second method to add an accessory view. NSDocument then runs the panel as a sheet attached to its window.



< Previous PageNext Page > Hide TOC


© 2002, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-06-28)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.