Re: poseAsClassing???
Re: poseAsClassing???
- Subject: Re: poseAsClassing???
- From: John Hörnkvist <email@hidden>
- Date: Sat, 24 Nov 2001 23:57:58 +0100
On Saturday, November 24, 2001, at 11:25 , Ondra Cada wrote:
What's strange: in some applications (like Grab) it works like a charm.
In
others (like TextEdit) it does not! The [NSApplication run] just keeps
calling the overridden [NSApplication sendEvent:]. The poseAsClass:
worked
though -- if I check in gdb the [NSApplication sharedApplication], I'll
truly
get "%NSapplication", just like if I try [NSApplication superclass]...
I can think of two things that will make this happen:
1) The application instance exists before poseAsClass: is called.
2) Someone cached the IMP before poseAsClass: was called.
If you need a work-around for the first case, you can always override
without posing; just store the IMP for the original method before you
install your own method.
Savage runtime hacking:
@implementation NSApplication(sendEvent)
static IMP NSApplication_sendEvent =nil;
+ (void)install_sendEvent
{
NSApplication_sendEvent =[self
instanceMethodForSelector:@selector(sendEvent:)];
struct objc_method *method;
if (method = class_getInstanceMethod(aClass, oldSelector))
{
method->method_imp = [self
instanceMethodForSelector;@selector(my_sendEvent:)];
_objc_flush_caches([self class]); // From memory; there may be a
documented way of doing this...
}
}
- (void)my_sendEvent:(NSEvent*)event
{
// ...
NSApplication_sendEvent(self,@selector(sendEvent:),event);
// ...
}
@end
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com