MenuBarComponent::showMenu set LookAndFeel Missing?


#1

I noticed that the look and feel isn’t set on the PopupMenu in MenuBarComponent::showMenu method. Shouldn’t this be just like the ComboBox::showPopup() method?

[code]PopupMenu menu;

menu.setLookAndFeel (&getLookAndFeel());[/code]

or are we supposed to set this ourselves in our version of

MenuBarModel::getMenuForIndex when creating the menu?

Thanks


#2

I guess setting this in MainEditorComponent::getMenuForIndex is more flexible because you can have different looks for different top level indices. Don’t know why I would need that, but it might come in handy one day I suppose.


#3

I think you’re right - it should inherit from the menubar. But I guess you might want to override it too, so it could do this, in juce_MenuBarComponent.cpp, 223:

[code] PopupMenu m (model->getMenuForIndex (itemUnderMouse,
menuNames [itemUnderMouse]));

            if (m.lookAndFeel == 0)
                m.setLookAndFeel (&getLookAndFeel());

[/code]


#4

That works, but I’m not sure if the menu lookAndFeel would be 0. Isn’t it set somewhere to the default l&f to begin with?


#5

No, it gets left as 0 unless you explicitly set one.


#6

Hey Jules

I think I found another one that might need this in TableHeaderComponent::showColumnChooserMenu.

[code]void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
{
PopupMenu m;
addMenuItems (m, columnIdClicked);

if (m.getNumItems() > 0)
{
	if (m.lookAndFeel == 0)
		m.setLookAndFeel (&getLookAndFeel());

    const int result = m.show();

    if (result != 0)
        reactToMenuItem (result, columnIdClicked);
}

}[/code]


#7

Thanks, I’ll chuck that in there.


#8

One more…

[code]void TextEditor::mouseDown (const MouseEvent& e)
{
beginDragAutoRepeat (100);
newTransaction();

if (wasFocused || ! selectAllTextWhenFocused)
{
    if (! (popupMenuEnabled && e.mods.isPopupMenu()))
    {
        moveCursorTo (getTextIndexAt (e.x, e.y),
                      e.mods.isShiftDown());
    }
    else
    {
        PopupMenu m;
        addPopupMenuItems (m, &e);

		   if (m.lookAndFeel == 0)
			   m.setLookAndFeel (&getLookAndFeel());

        menuActive = true;
        const int result = m.show();
        menuActive = false;

        if (result != 0)
            performPopupMenuAction (result);
    }
}

}[/code]

I remember running into another one, but can’t think of it now. Slider pop-up menu? I think there was one more.


#9

Thanks. I’ll do the Slider one too.


#10

Also when you do get around to do the TextEditor pop-up menu, is there any chance you can add a

to the Label? It can get checked in Label::createEditorComponent()?


#11

Doesn’t really feel like something that belongs in the Label… I don’t want to fill the label class with copies of all of TextEditor’s methods. Not sure of a better suggestion for you though…


#12