You need to subclass MenuBarModel and override its pure virtual methods to set up your menu. Take a look at the MenusDemo class in the WidgetsDemo.cpp file of the JUCE Demo to see an example of how to do this.
Well, you’d need to just make your MenuBarModel remove or disable items when you don’t want them displayed.
If you use the ApplicationCommand stuff, it’ll disable things automatically based on the currently focused component, but if not then you can just roll your own menu disabling logic.
Hi!
I have the same question as in the beginning of the topic. How can I make a menu?
How do you do that? I didn’t found anything like “addItem” or something in MenuBarModel class :((
There’s no such class in WidgetsDemo.cpp (JUCE 7.0.3). There is, however, a class in a file ‘MenusDemo.h’ though I guess it requires building all Demos to see how it’s all connected and how to use it. Also the file is kinda… big and funky. Essentialy I need a simple menu with like two items (e.g. “Close”, “Format C:”).
The MenuBarModel class discussed in this thread is, iirc, for the application’s minimize/maximize/close buttons. Do you want to add the option to format your C drive to that list? What are the requirements, here?
The MenuBarModel relates to the whole issue of putting up a menubar in Mac or Windows, with drop down menus, submenus and commands, for which you use the ApplicationCommandManager, ApplicationCommandTarget, etc.
See the MenusDemo:
//==============================================================================
class MenusDemo : public Component,
public ApplicationCommandTarget,
public MenuBarModel
{
public:
//==============================================================================
/** A list of the commands that this demo responds to. */
enum CommandIDs
{
menuPositionInsideWindow = 1,
menuPositionGlobalMenuBar,
menuPositionBurgerMenu,
outerColourRed,
outerColourGreen,
outerColourBlue,
innerColourRed,
innerColourGreen,
innerColourBlue
[snip...]
EDIT: I found it quite complicated to get a fully-featured menubar up and running. There are a lot of interconnected pieces and classes.
It’s also highly recommended to examine the source code for The Projucer, which utilizes just about every menubar feature in a fully-fledged app.
I know )) I looked at the code and I couldn’t belive that for some simple menu bar, like “Help”, “About” and “Close” you have to write half thousand lines.
I decided that making my own menu-like component would be easier. In the end all I need is a bar with some text lines, and popup-menus connected to those lines.
P.S. I miss Delphi sometimes ))