RE: How to know user clicks [print] button in cocoa PDE
RE: How to know user clicks [print] button in cocoa PDE
- Subject: RE: How to know user clicks [print] button in cocoa PDE
- From: "Jeff Chen" <email@hidden>
- Date: Wed, 13 Sep 2006 14:28:51 +0800
Thank you so much! Now it works. But there's another problem:
[Print] button can only responde to my custom method when my PDE is shown. If OS PDE(Layout, Paper Handeling, Paper Feed...) is currently opened, then [Print] button won't respond to custom method. I think it's because [Print] button is created again when my PDE is closed and OS PDE is opened. So it is different from the [Print] button created in my PDE. Do you have any idea about getting [Print] button correctly?
Following is my code to get [Print] button:
NSButtonCell * PrintButtonCell;
NSButton * PrintButton;
PrintButtonCell = [[MyCustomView window] defaultButtonCell];//MyCustomView is the view for PDE window
PrintButton = (NSButton*)[PrintButtonCell controlview];
-----Original Message-----
From: Dustin Voss [mailto:email@hidden]
Sent: Tuesday, September 12, 2006 9:50 AM
To: Jeff Chen
Cc: cocoa-dev List; Yu, Min; Zhang, Annie
Subject: Re: How to know user clicks [print] button in cocoa PDE
You are making this too hard for yourself. You do not need to make a
new subclass of NSButton. When an NSButton is clicked, it simply
calls a method on an object. The object is the "target," the method
is the "action." Read http://developer.apple.com/documentation/Cocoa/
Conceptual/CocoaFundamentals/CommunicatingWithObjects/
chapter_6_section_5.html.
The reason DoPrint: did not print anything is because you were not
calling the target's action method, you were just checking to see if
the target has that action. The code you wanted was:
[OriginalTarget performSelector:OriginalAction]
On 11 Sep 2006, at 1:59 AM, Jeff Chen wrote:
> Thank you for your solution. I tried it, and successfully
> implemented step 1 and 2, but failed at step 3. Print button can't
> print correctly. The folliowing is my sample code:
>
> NSButton * PrintButton;
> ...............//Get PrintButton
> PrintAction = [PrintButton action];
> PrintTarget = [PrintButton target];
>
> NSPrintButton * MyPrintButton;
> [PrintButton setTarget:MyPrintButton];
> [PrintButton setAction:@selector(DoPrint:)];
> [MyPrintButton SetOriginTarget:(NSWindowController*)PrintTarget
> andAction:PrintAction ];
>
> For the class NSPrintButton, my definition is following:
>
> NSPrintButton.h:
> @interface NSPrintButton : NSButton
> {
> @private
> NSWindowController * OriginalTarget;
> SEL OrignialAction;
> }
>
> - (void)SetOriginTarget:(NSWindowController*)idTarget andAction:
> (SEL)action;
>
> - (IBAction)DoPrint:(id)sender;
>
> @end
>
> NSPrintButton.m:
> #import "NSPrintButton.h"
>
> @implementation NSPrintButton
>
> - (void)SetOriginTarget:(NSWindowController*)idTarget andAction:
> (SEL)action;
> {
> OriginalTarget = idTarget;
> OrignialAction = action;
> }
>
>
> - (IBAction)DoPrint:(id)sender
> {
> [OriginalTarget respondsToSelector:OrignialAction];
> }
>
> @end
>
> Now when I press [print] button, DoPrint() is called, but my print
> job can't be printed. "OriginalTarget" and "OriginalAction" are
> obtained successfully. So it seems that system will do more action
> than just let "OriginalTarget" execute "OriginalAction". Do you
> have any idea about getting "OriginalAction" and "OriginalTarget"
> completely?
>
> -----Original Message-----
> From: Dustin Voss [mailto:email@hidden]
> Sent: Sunday, September 10, 2006 2:06 AM
> To: Jeff Chen
> Cc: cocoa-dev List; Yu, Min; Zhang, Annie
> Subject: Re: How to know user clicks [print] button in cocoa PDE
>
>
> On 7 Sep 2006, at 2:33 AM, Jeff Chen wrote:
>
>> I can't catch the event that user presses [Print] button, in carbon
>> PDE, I can get the ControlRef of [Print] button and install event
>> handler to it. However, in cocoa, I can only get the NSButton *
>> pointer of [Print] button, but I can't install event handler to
>> NSControl in cocoa. I can only use the event in NSResponder. But
>> NSResponder doesn't provide the event that handles the clicking of
>> [Print] Button.
>>
>> Who knows how I can catch the event that user clicks [print] Button
>> in cocoa? Or who knows how to install event handler to a special
>> NSControl in cocoa?
>
> You are writing a printer-specific item for the Print panel? And you
> want to do something when the user clicks Print? I assume the PDE
> close and terminate callbacks aren't sufficient, because you only
> want to do this if he clicks Print. I also assume that you can't do
> what you need in the printer module callbacks listed here:
>
> http://developer.apple.com/documentation/Printing/Reference/
> PrintingPlugin_Ref/Reference/reference.html#//apple_ref/doc/uid/
> TP30000241-CH2g-TPXREF104
>
> If you have the NSButton *, I think you can intercept its action as
> follows:
>
> 1. Call -action and -target to find out what it does now.
> 2. Redefine what it does by calling -setTarget: with your class and -
> setAction: with the method you want it to call.
> 3. In that method, make sure you call the original action on the
> original target.
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden