> 1) how do i get that nifty application/preferences/services menu? i create my 
> menus dynamically (not nibs)

I did this by starting out with a menu created from a NIB (and which contained 
the Application menu, File menu, Edit menu and so forth) and then modifying 
this to add the additional elements I wanted.  The NIB I started with was 
created by Xcode, using the generic 'Cocoa Application' template.

> 3) are there window styles for palettes / document windows? there seems to be 
> only one style...

Have a look at the style masks for NSPanel.  In particular, NSUtilityWindowMask 
will give you a floating pallette (with the smaller title bar).

> 4) ... when i delete a menu... do i have to delete the individual items?

Apart from the answer already given, no.  NSMenu retains its submenus and menu 
items so when the parent is deleted (or, rather, released for the last time) 
then all the children will go away too, unless they have been retained 
somewhere else.  This is generally true of collection objects.

To look for leaks, I too use the 'Leaks' tool in Instruments and it did 
discover few things.  It's not foolproof though - there is a chance of a false 
negative - so another simple trick is to watch the memory usage of your app in 
Activity Monitor.  If this keeps on creeping up over time, you still have a 
leak.  I found one or two things this way as well, including a situation where 
an autorelease pool was not being drained for long periods of time resulting in 
excessive peak memory usage.

> 5) is my screen flipping code below going to work on multiple monitors?

Yes, that is essentially what I do to map from and to 'top down' coordinates.  
In fact, I just do:

    // Map a screen Y coordinate between Windows (top-down) and Mac (bottom-up) 
coordinate systems (works either way round)
    float WCLMapScreenY (float y)
    {
        NSRect r = [[NSScreen mainScreen] frame];
        y = r.size.height + r.origin.y - y;
        return y;
    }

I tested my multiple-monitor support by plugging an external monitor into the 
back of my 2009 MacBook.  Note that the menu isn't necessary located on the 
primary screen; ditto the dock.

> NSMenu *newmenu(unsigned char *menuname)
> {
>     NSMenu *themenu;
>     NSString *mystring;
>     char tempstring[256];
> 
>     pstr2cstr(menuname, tempstring);
>     mystring = [NSString stringWithUTF8String:tempstring];
>     themenu = [[NSMenu alloc] initWithTitle:mystring];
>     [themenu setAutoenablesItems:NO];
>     [mystring release];
>     return(themenu);
> }

You should not be releasing mystring. [NSString stringWithUTF8String:] will 
autorelease it, as the memory management guidelines make clear.  You are doing 
the right thing with themenu (i.e. not autoreleasing it) because your method 
has 'new' in the name.  The caller of this method is therefore responsible for 
the object's ultimate disposal.  setmenuitemtext contains a similar error.  To 
catch problems like this early, enable 'zombies' (but not when checking for 
leaks!!):

http://www.cocoadev.com/index.pl?NSZombieEnabled

Paul Sanders.
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to