The Window menu


I’m seeing several ways to make a standard “Window” menu. All have their limitations, though. I’d like to be put on the right track.
• I may make a plain Xojo menu. I think all items in the Window menu can be handled in Xojo code (with the MBS plugin). But Xojo menus are limited (can’t group similar items as a single menu, for instance) and if a MacOS update makes changes to the menu structure, my code wouldn’t include them automatically.
• The MBS plugin has this method in NSMenuMBS: NSMenuMBS.WindowMenu. The documentation says this: “Returns the window menu if one is registered.”. I’ve spent 30 minutes searching an MBS method to register one, but didn’t find any.
• MacOS Lib… I’ve long ago aborted to use it, as it was always out of date and hard to find. I always found versions from the past and couldn’t complete my suggestions with it. I’m not interested in this solution anymore, should it still be “available”.
• And Declares, finally. Will take longer than the other methods to implement.

Strangely, I haven’t found this question on this forum either. I’m missing something obvious or this is just never done in Xojo apps?

It’s not that difficult to make a window menu with the Xojo menu item class.
And I bet you find some sample code doing it.

You’ll need a MenuItem subclass and you call a add/remove from window open/close events.
We did it a few times over the years.

In the Ohanaware App Kit, there is code which gets Apple’s App Kit to automagically manage the window menu for you.

1 Like

As with anything made from scratch, this solution will break with updates to the OS, if there are hidden settings the user may have changed or if the implementer didn’t thought of something specific.
I know I’ll have to make my own menu for Windows anyway, but what are the native Mac OS classes made for if not used? (still a pain to make the work twice, but, otherwise, you end up with unfamiliar looks on one or another platform).

As a quick example, the native Window menu has menu items that change when you hold the option key:
1: the menu items in Xojo, as far as I recall, cannot be made as groups. There are declares and your plugin for methods about this, but the Xojo implementation… [I don’t remember; aren’t native or something like this].
2: I’m not sure any combinations supported natively are documented. Making my own menu will certainly result in a lack of shortcuts support or available functions.

Thanks for letting me know it’s still an “acceptable” solution, though.

I’m sure it’s a great tool (looks like, anyway), but I can’t afford it now (I don’t currently work).
Well, if a native solution has never been done in Xojo, I’ll dig into declares.
Thank you.

You don’t need to reinvent it as others have done it.
You may not need grouping features for the menu. Just dynamic MenuItems to build as many as needed.

Check the WindowMenu example coming with Xojo itself!

Yes, “Dynamic menu items” was I meant by “grouped items”; I just forgot the exact name. These dynamic menu items are what I think aren’t doable in Xojo (up to the EnableMenuItems event, one can hide or show items, but it’s not doable while the menus are open).
I’ll check the example you mentioned; thank you.

You’re welcome. It’s basically a collection of declares that I’ve gathered over the last decade or so. It’s what we use in our Xojo made Mac applications.

I guess the main reason as to why Xojo doesn’t automatically use the macOS Window menu, is perhaps there isn’t an automatic menu on Windows?

1 Like

Certainly. The lowest common denominator is ofter the reference.
I actually didn’t bothered guessing the reason; on the other hand, an AppleMenuItem is only for Mac and it exists in Xojo… Go figure…

1 Like