• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: poseAsClassing???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >poseAsClassing??? (From: Ondra Cada <email@hidden>)

  • Prev by Date: Working with HTML in NSAttributedString
  • Next by Date: Re: poseAsClassing???
  • Previous by thread: Re: poseAsClassing???
  • Next by thread: NSTextField delegate textDidChange:
  • Index(es):
    • Date
    • Thread