Re: how to update the view of NSPrintOperation ?
Re: how to update the view of NSPrintOperation ?
- Subject: Re: how to update the view of NSPrintOperation ?
- From: "debin lei" <email@hidden>
- Date: Thu, 15 May 2008 09:37:35 +0800
You are kind to give me more detail about it.
I know the panel will update the preview when some printInfo changed.
What 's the attribute will affecte the preview can set with the
function keyPathsForValuesAffectingPreview . It is ok.
But in my app, the preview changes without any printInfo changed. For
example , i offer an button option to print the doc without tables. So when
user press the button, i will remove the tables in the print view and no
printInfo changed. And the preview did not change.
What should i do? it must offer a fake attribute,ex Margin,update it
without useful? Then let the preview update?
2008/5/15 douglas a. welton <email@hidden>:
>
> On May 14, 2008, at 9:13 AM, debin lei wrote:
>
> Thank you for your infomation, i know the function
> keyPathsForValuesAffectingPreview, however, i did not know how to use it.
>
> <<<<snip>>>>
>
> Can you give me more detail about it? I want the preview NSView call its
> drawrect function when i press the button in the accessory view . How to do
> this?
>
>
> Below you'll find a copy the implementation file from my Print Panel's
> accessory view controller.
>
> The gist is this:
>
> 1) My accessory panel has one button, a check box (bound to the sizeToFit
> property). When that button changes value my setter method is called. This
> method will manual trigger KVO for the localizedSummaryItems, then update
> the designated NSPrintInfo object.
>
> 2) the keyPathsForValuesAffectingPreview returns a set of NSPrintInfo
> properties that need to be observed KVO-style (by the Preview View?) so that
> when changes occur, the preview view can be updated.
>
> Hope this helps.
>
> regards,
>
> douglas
>
> ---
> //
> // PrintAccessory_ViewController.m
> // LightTable
> //
> // Created by Douglas Welton on 4/28/08.
> // Copyright 2008 __MyCompanyName__. All rights reserved.
> //
>
> #import "PrintAccessory_ViewController.h"
>
> @implementation PrintAccessory_ViewController
>
> @synthesize sizeToFit;
> @synthesize windowController;
> @synthesize printOperation;
>
> //+
> // Method: setSizeToFit: (BOOL) New_Value
> //
> // Function: Change the appropriate print info settings
> //-
>
> - (void) setSizeToFit: (BOOL) New_Value
> {
> NSPrintInfo *Current_PrintInfo;
>
>
> //+
> // Update the value of the sizeToFit flag and manually trigger the KVO for
> the summary items key
> //-
>
>
> [self willChangeValueForKey: @"localizedSummaryItems"];
> sizeToFit = New_Value;
> [self didChangeValueForKey: @"localizedSummaryItems"];
>
>
> //+
> // Update the PrintInfo from the attributes that affect this change, then
> update the print operation
> //-
>
>
> Current_PrintInfo = [self.printOperation printInfo];
>
>
> if ( sizeToFit )
> {
> [Current_PrintInfo setHorizontalPagination: NSFitPagination];
> [Current_PrintInfo setVerticalPagination: NSFitPagination];
> }
> else
> {
> [Current_PrintInfo setHorizontalPagination: NSAutoPagination];
> [Current_PrintInfo setVerticalPagination: NSAutoPagination];
> }
>
>
> [self.printOperation setPrintInfo: Current_PrintInfo];
> }
>
> #pragma mark -
> #pragma mark NSPrintPanelAcessorizing Protocol Support
>
>
> //+
> // Method: keyPathsForValuesAffectingPreview
> //
> // Function: Tells "whoever" is observing for the print preview which
> keys to observe for changes
> //-
>
> - (NSSet *) keyPathsForValuesAffectingPreview
> {
> return [NSSet setWithObjects: @"representedObject.horizontalPagination",
> @"representedObject.verticalPagination", nil];
> }
>
> //+
> // Method: localizedSummaryItems
> //
> // Function:
> //-
>
> - (NSArray *) localizedSummaryItems
> {
> NSString *Description;
>
>
> //+
> // Based on the value of sizeToFit, set the description string
> appropriately
> //-
>
>
> if ( self.sizeToFit )
> Description = @"Scale canvas to fit paper size";
> else
> Description = @"Natural pagination";
>
>
> return [NSArray arrayWithObject: [NSDictionary
> dictionaryWithObjectsAndKeys: @"Canvas Scaling",
> NSPrintPanelAccessorySummaryItemNameKey,
> Description, NSPrintPanelAccessorySummaryItemDescriptionKey,
> nil]];
> }
>
>
> @end
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden