Native menus on mac?


#1

Is it possible to implement native OS X menus using JUCE?


#2

I’ve not done this yet, but it’s on my to-do list!


#3

Now it is done ! thanks a lot :slight_smile:

When using the OSX menuBar, the juce demo makes an assertion at shutdown when trying to remove the listener of the MenuBarModel :

void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
{
    // Trying to remove a listener that isn't on the list!
    // If this assertion happens because this object is a dangling pointer, make sure you've not
    // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
    jassert (listeners.contains (listenerToRemove));

    listeners.removeValue (listenerToRemove);

What’s the better way to avoid this assertion ?

When adding setMacMainMenu(0) in the destructor of ContentComp (inheriting from MenuBarModel) everything seems alright…


#4

Yes - like it says, just make sure the model isn’t deleted before being removed. Calling setMacMainMenu(0) is the way to do it.


#5

I just found this too. I had to add the setmenu(0) to my destructor.

Bruce


#6

Hi Jules,

Could I please make a request that if a Menu item is called “About…” or “Preferences” (or maybe this is indicated with some soft of menu item “hint flag” identifying it has a special meaning to the user/OS), and if the native Mac menu is being used, then those items are put under the left-hand Mac native menu bar item? On Mac apps, the About and Preferences items are always found there, with a separator too.

That would allow mac-native Juce app menus to behave just like normal Mac app menus… which would be cool!

Anyways, hoping that makes sense. :slight_smile:

Pete


#7

Would love to do that, but couldn’t find any way of accessing that menu programatically. (I think there’s a thread about it somewhere…)


#8

Just for reference… keeping it all in one place, as it were…:slight_smile: !

http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/index.html

http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/index.html

http://developer.apple.com/documentation/Carbon/Conceptual/HIViewDoc/HIView_tasks/chapter_3_section_12.html

http://developer.apple.com/documentation/Carbon/Conceptual/HIViewDoc/HIView_tasks/chapter_3_section_15.html#//apple_ref/doc/uid/TP30000923-CH205-BAJHJCBC

Anyways, HTH! The key thing might be that from MacOS 10.3, all menus are now implemented as HIViews; presumably this implies that it must be possible now to do what you want programmatically… :slight_smile:

Pete


#9

My app repaints everytime a timer fires. However, if I open a native menu, the app stops repainting.


#10

…yes, I think most mac apps will do the same - when you open the menus with MenuSelect, it goes into a modal loop that doesn’t let all the messages through. That function seems to be left-over from the old days of OS9, not sure if they’ve got a better way of doing it now.


#11