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.