Re: Cocoa window in Carbon app and [NSApp postEvent]
Re: Cocoa window in Carbon app and [NSApp postEvent]
- Subject: Re: Cocoa window in Carbon app and [NSApp postEvent]
- From: Frederik Slijkerman <email@hidden>
- Date: Fri, 14 Aug 2009 17:41:09 +0200
Brilliant! Thank you very much!
Best regards,
Frederik Slijkerman
Ken Ferry wrote:
Hi,
It sounds to me like you are interested in
-[NSObject performSelectorOnMainThread:withObject:waitUntilDone:modes:].
-Ken
On Thu, Aug 13, 2009 at 12:38 PM, Frederik Slijkerman
<email@hidden <mailto:email@hidden>> wrote:
Hi,
I'm working on a Photoshop plugin that uses a Cocoa UI, while of
course Photoshop is still Carbon currently. The plugin runs as a
modal window pretty much all the time.
Now I've run into a problem: when I post a custom event to the main
event queue using [NSApp postEvent], it is never processed. As far
as I can tell, this is because [NSApp runModalForWindow] calls into
Carbon to actually run the modal window, and while Carbon does
handle mouse, keyboard and timer messages fine (by sending them
directly to the window involved), it apparently doesn't know
anything about any Cocoa events that are waiting in the main event
queue.
Does this sound familiar to anyone? Is there any way I can work
around this?
This is the code I use to post the event:
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:0
context:0 subtype:0 data1:reinterpret_cast<NSInteger>(h)
data2:reinterpret_cast<NSInteger>(data)];
[NSApp postEvent:event atStart:NO];
I've thought about replacing postEvent with a timer that would fire
immediately, but it looks like this wouldn't work from a different
thread, as timers work directly with NSRunLoop and NSRunLoop has a
stern warning regarding thread safety...
So basically what I'm looking for is a thread-safe way to add an
event to the main event queue, in such a way that it will be
processed even when a modal window is running, this all in a Carbon
application.
Thanks in advance!
Best regards,
Frederik Slijkerman
_______________________________________________
Cocoa-dev mailing list (email@hidden
<mailto:email@hidden>)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
<http://lists.apple.com>
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden <mailto:email@hidden>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden