Native Mac menubar

Seems to be broken in the trunk?

Also, SystemStats::getClockCycleCounter contains a jassertfalse (crashing it in gdb)

Yes, sorry about the assertion, I’ve fixed that now.

The menu bar seems ok to me though… What exactly is wrong?

My mistake, seems to work fine in the demo.

What was your original problem? I have it working but can easily break it!

Using the “command manager” technique it seems fine (demo, Jucer, plugin host etc all use this?)

Try to set a menu that is not built using the command manager doesn’t seem to work. E.g., like this:

[code]const PopupMenu MainAppWindow::getMenuForIndex (int topLevelMenuIndex, const String& menuName)
PopupMenu menu;

if(topLevelMenuIndex == 0)
	// File
	menu.addItem(1, T("Open..."));
	menu.addItem(2, T("Save"));
	menu.addItem(3, T("Save As..."));
else if(topLevelMenuIndex == 1)
	// Controls
	menu.addItem(4, T("Minimum"));
	menu.addItem(5, T("Maximum"));

return menu;


This is with Juce tip r651, seems OK on r597 (using either technique).

Perhaps you’re changing the menus without calling menuItemsChanged? I think you could often get away without doing this in the carbon version, because it would rebuild the menus every time you clicked on the title bar, but in cocoa it works slightly differently, and you need to make sure you always let it know when something has changed.

That got it - thanks!

So I have to do :

setMacMainMenu (this); menuItemsChanged();

…in my MenuBarModel subclass constructor.

hmm, I wouldn’t have thought that you’d need to call menuItemsChanged() straight after setting the menu, but only later if you subsequently change some items. Doesn’t it work without that?

That’s right, I’m not changing menus just setting up a one-and-only menu from the main window constructor. Unless using the command manager stuff (which presumably calls an equivalent of menuItemsChanged() at some point?) the menus don’t appear without a call to menuItemsChanged().

It’s not a major issue, obviously the command manager way is more flexible - I’m just developing some as-simple-as-possible examples and wanted one which didn’t need all the command manager bits-n-pieces but could use the native menu.

Ok, I’ll add a call to make sure you don’t need to call it immediately after the setMacMainMenu call.

Perhaps obvious, but I’ve missed how to add items under the main application menu item. Hints?

setMacMainMenu() now has an extra parameter that lets you pass in stuff for the apple menu.

Some coalesced questions from the crew :slight_smile:

Seems the Mac menu has troubles being updated. With Cocoa, it seems it is needed to call menuItemsChanged() for each update of menu items, yes ?

Another Q Jules, have you looked at validateUserInterfaceItem (think its an NSMenu method)? Might be used to automize the update process, no ?

And last: The items added to the main app menu item (via setMacMainMenu) don’t seem to support commandItems, just regular ones, which inhibits using/displaying shortcuts there. A bug ?

All for now.

Yes, in the old carbon code it used to get a chance to refresh the menu items when the mouse was clicked on the menu bar. In cocoa, I couldn’t find any way of doing that - I’m pretty sure I looked at validateUserInterfaceItem and it wasn’t quite right… but I’m not 100% sure, I’ll maybe take another look.

And last: The items added to the main app menu item (via setMacMainMenu) don’t seem to support commandItems, just regular ones, which inhibits using/displaying shortcuts there. A bug ? [/quote]

Odd - it uses exactly the same code to add those items as it does the normal ones, so I don’t see why it’d lose the command info… I’ll have to investigate.

I thought the same shortly after my earlier message in this thread … but I’d forgotten to add the commands to getAllCommands() and/or getCommandInfo() in the app.

I have keyboard shortcut (Apple)Command-, working for a “Preferences” menu item in this menu using commands, see here:

(This app doesn’t really do anything, it’s a very basic demo app I’m setting up which has a single window you can save/load the state of and a preferences box - which let’s you change the background colour of the window.)