> didn't mean to come across as 'argumentative' ! all the advice is
> greatly appreciated.. I'm just trying to understand the full picture
[quoted text clipped - 5 lines]
> beasts? I mean at some point, the Cocoa widget must be calling some
> lower level Mac api to insert itself into the menu no?
Neither view is correct. Cocoa and Carbon are on an equal footing, but
they aren't totally independent either.
The low level framework is CoreGraphics, also known as Quartz, which
includes a bunch of private stuff like the core window objects which both
Cocoa and Carbon windows are implemented on top of.
Many things are implemented independently. For example, the control
hierarchies are done completely separately, which often causes odd
inconsisitencies in the behavior of what should be identical Carbon and
Cocoa controls.
Many things are implemented in terms of the other framework. As an
example, Cocoa menus are implemented on top of Carbon menus. And Carbon
font and color panels use the Cocoa ones.
The end result is that both frameworks are capable of doing most things
but there are certain things which only one can do, and you can't say
which framework will be able to do it without actually researching it.
The good news is that the frameworks mix just fine in most cases,
especially if you do all of your GUI in only one of them. I believe, and I
think many other will agree, that the most productive environment is to
write your GUI in Cocoa and use Cocoa liberally otherwise, but to use
Carbon whenever it's necessary or convenient to get things done inside the
app.

Signature
Michael Ash
Rogue Amoeba Software
> didn't mean to come across as 'argumentative' ! all the advice is
> greatly appreciated.. I'm just trying to understand the full picture
[quoted text clipped - 3 lines]
> Carbon was like win32 and that Cocoa was a higher-level layer/
> framework on top of that - but this is not the case?
No.
> Totally separate beasts?
Not totally separate. What you read "somewhere" about portions of Cocoa
being implemented in Carbon is accurate. But I wouldn't say that it's a
lot and certainly not most, and there are some things that today simply
are not cost-effective (and sometimes not realistically possible) to do
in Carbon.
> I mean at some point, the Cocoa widget must be calling some
> lower level Mac api to insert itself into the menu no?
Not necessarily. The libraries themselves can certainly be exposing only
Objective-C interfaces with no public procedural API for a given task.
> would love to get all these pieces straight in my head - I might just
> make a decent Mac programmer one day - lol
[quoted text clipped - 4 lines]
> enjoying it even...
> :-)
Hmmm... Having been a Mac programmer since 1988 and a Windows programmer
since 1993 I suggest that what's probably changed most is you. If you're
looking at Carbon, there's really not much fundamentally different from
what you might have seen at any time in the 1990s. If anything, some
things have gotten more convoluted and opaque since then.
If you're a capable C programmer - and I expect you are - and don't let
yourself get defensive/hostile about the "weird" syntax, you can gain at
least a functional knowledge of Objective-C in literally an hour or two.
It'll probably take some practical use and a couple of missteps to
really "get" it - like really understanding the difference between
calling a function and sending a message, and the implications of that
difference - but putting together a status bar item is a piece of cake
once you let the tools work for you.
Depending on the complexity of your app, I think it's entirely likely
that you'll be creating a single subclass (of NSObject) that will act as
the delegate for your application and the target of the menu commands
you create. The trickiest thing you'll hit is a bug in either the
implementation or documentation of NSStatusBar, depending on your point
of view:
The way you create your status bar item is by sending
statusItemWithlength: to the NSStatusBar. This will create the item and
give you back a reference so you can actually set its properties. The
documentation notes, "The receiver does not retain a reference to the
status item, so you need to retain it."
The Cocoa memory contract says that if you retain something, you're
responsible for releasing it later. But if you try to release the status
item, your app will crash because apparently the status bar also sends a
release. So don't, and all will be fine.
mlabs - 20 Aug 2007 22:46 GMT
Gregory & Michael - thanks v much this is very helpful indeed. I bit
the bullet and went down the bookshop to browse objective-C .. yeah
you're totally right - it's trivial if you already know C/C++ and
OOP... so that will be the way I will proceed..My little app just
needs to do some HTTP calls and read/write to a local XML file ... I
found some usefull looking URL classes in the framework, but so far
nothing regarding XML .. any clues there?
again - thanks.
Tom Harrington - 21 Aug 2007 00:12 GMT
> Gregory & Michael - thanks v much this is very helpful indeed. I bit
> the bullet and went down the bookshop to browse objective-C .. yeah
[quoted text clipped - 3 lines]
> found some usefull looking URL classes in the framework, but so far
> nothing regarding XML .. any clues there?
For general purpose XML manipulation, Cocoa has NSXMLDocument and
associated classes (e.g. NSXMLElement). There's a CF equivalent
(CFXMLNode, etc) if you prefer a C-style interface.
At a lower level, Mac OS X includes libxml2.

Signature
Tom "Tom" Harrington
MondoMouse makes your mouse mightier
See http://www.atomicbird.com/mondomouse/
mlabs - 21 Aug 2007 06:45 GMT
thanks Tom - looks like the 'cocoa in a nutshell' book I got is out of
date - that class isn't in it...
mlabs - 22 Aug 2007 09:21 GMT
ok i have managed to confuse myself...
I've got my 'menulet' application running over on the right side of
the menu bar .. got my icon in there, got a menu hanging off it with 5
menu items ... got rid of the default menu and window ... the menulet,
containing the NSStatusItem reference, is derived from NSObject....
next I added 5 actions for the menu items.. hooked them up..
next I used IB to construct a panel... .. currently it's not hooked up
to anything..
what I want to do next is 2 things:
1. in one of the actions, bring up my panel, in a modal state...
Q: should I wrap this in it's own class??
2. in the 'about' action, bring up the standard about box..
no idea how to do #1.
as for #2, I read that NSApplication has a
'orderFrontStandardAboutPanel' message .. but I can't figure out how
to get to my NSApplication instance from the action handler.. is this
thing global?
Gregory Weston - 22 Aug 2007 12:51 GMT
> ok i have managed to confuse myself...
Excellent. A necessary early step. (And I'm only half kidding. I find
most people learn more when they don't initially just "get it.")
> I've got my 'menulet' application running over on the right side of
> the menu bar .. got my icon in there, got a menu hanging off it with 5
[quoted text clipped - 7 lines]
>
> 1. in one of the actions, bring up my panel, in a modal state...
How modal are we talking about? System-wide modality is pretty much
anathema for OS X and most other modern desktop operating systems. If
you just need to prevent access to other bits of your program while this
window is displayed, no problem.
> Q: should I wrap this in it's own class??
Probably not. You can probably get what you want with this method:
<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/
Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/occ/inst
m/NSApplication/beginModalSessionForWindow:>
> 2. in the 'about' action, bring up the standard about box..
>
[quoted text clipped - 4 lines]
> to get to my NSApplication instance from the action handler.. is this
> thing global?
There's a global instance of NSApplication called NSApp. Send it
messages and you should get what you want. If you're offended by the
notion of gratuitous globals you can use the NSApplication's class
method sharedApplication to get this object instead.
Many Cocoa classes that are at least treated as singletons have a
sharedFoo or standardFoo method to retrieve their "stock" instance, btw.
mlabs - 23 Aug 2007 02:59 GMT
thanks again Gregory - the tip regarding the globals and how to find
them was key. I feel like i'm getting the hang of this now .. i've got
my about box up and i've added a self-contianed prefs panel (in it's
own nib) and I have that hanging off one of the menu items as well.
It's all very spiffy. The action/outlet thing is just like DDX and
event handling in MFC .. once I had that epiphany I was good to go.
:-)