June 15, 2007

Trippy (Cocoa Notifications in a Mostly Carbon App)

Filed under: ResearchAndDevelopment,VonTrapp — Ryan Wilcox @ 11:58 am

So I’m using a little bit of Cocoa in a client’s application. The fun thing is that this application is mostly Carbon/wxWidgets. This isn’t too terribly odd: people use Cocoa in Carbon applications all the time (anymore). The wxWidgets part is different than normal, but whatever.

The trippy thing comes when I needed to adapt when the system Appearance color changed (so Aqua to Graphite, for example). You can get that via [NSColor currentControlTint], but the old Appearance Manager Apple Event (kAppearanceEventClass/kAEAppearanceChanged) must fire too soon, because looking at the currentControlTint color then just gives me the old color.

Cocoa has a notification for this NSControlTintDidChangeNotification, and using this in a Cocoa app, then retrieving the control tint, got me the new tint.

So I had an idea: Register for the (Cocoa) notification (via NSNotificationCenter) in my Carbon/wxWidgets app (in a wrapper function). Whatdayaknow… my notification got to me! (Which I then turned into a wxWidgets event and sent along its way).

So now my (Carbon/wxWidgets) + Cocoa app has three ways of getting events: Carbon Events, wxWidgets Events, and the occasional Cocoa Notification. It’s the first time I’ve used that last one, and I think it’s pretty trippy (and really really cool).

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment