Re: Problems using Hotkeys and references to an NSSearchField
Re: Problems using Hotkeys and references to an NSSearchField
- Subject: Re: Problems using Hotkeys and references to an NSSearchField
- From: Matt Neuburg <email@hidden>
- Date: Wed, 25 Jan 2006 09:21:47 -0800
- Thread-topic: Problems using Hotkeys and references to an NSSearchField
On Wed, 25 Jan 2006 09:13:16 +0100, "Lars Pettersson"
<email@hidden> said:
>OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef
>theEvent, void *myObjectPointer);
>
>I can't refer any of the Object-C instances / methods defined in the Nib
>from MyHotKeyHandler, and retrieve a compile error if I try to use
>something like [phraseField setStringValue:@"xxx"]. As far as I
>understand, you can't directly use Object-C variables from here, like
>self etc.
>
>My guess is that you have to add an object references when calling
>InstallApplicationEventHandler, that later should be used in the
>HotKeyHandler function to refer to the actual NSSearchField. But I can't
>find out what object to use or how to implement a correct solution.
>Should I use Self? NSWindow? NSApplication?
This had me mystified at first too. You are guessing exactly right - it was
your job to supply the desired value for myObjectPointer when you set up the
carbon event registration in the first place. NSWindow and NSApplication are
the names of classes. How would those help? What you probably need is a
reference to an object - an instance. And so the answer to your question is:
pass a reference to whatever you need a reference to! If the code is in the
same instance as the thing you need a reference to, then sure, use self. It
all depends how your app works, where your code is, what it does, etc. It's
an object reference like any other object reference.
Here's an example (this is from my MothersHelper app). At startup, we
register for the carbon event, like this:
InstallApplicationEventHandler (handlerUPP, 1, &eventType, self, NULL);
When the event comes in, we respond (in part) like this:
[(id)userData performSelector:@selector(doYourStuff:) withObject:nil
afterDelay:0.1];
(My userData is your myObjectPointer. The reason for the delayed processing
here is that I want to return from the carbon event call immediately.)
Daniel Jalkut (who, I expect, will leap in here) provided code to work
around a problem where carbon event dispatching wasn't working in Cocoa. But
they work OMM without his code, so possibly Apple probably fixed a bug, in
Tiger, without telling anyone.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
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