LookAndFeel::getIdealPopupMenuItemSize override isn't called


I have a custom look and feel that overrides some of the popup methods. All of them work as expected, except my implementation of getIdealPopupMenuItemSize never gets called – the base class LookAndFeel::getIdealPopupMenuItemSize is used instead.

I was sure this must be some kind of declaration problem on my part, either a typo in the name or one of the variable types being wrong or something, but that’s not it.

When the ItemComponents are created, they figure out their size in the c’tor. They don’t know about the cusom LookAndFeel, so a default is used.

I hacked in some code to deal with this in PopupMenu::Window’s c’tor:

[code] PopupMenu::ItemComponent* const itemComp = new PopupMenu::ItemComponent (*menu.items.getUnchecked(i), standardItemHeight);

		// hack
		int itemW = 80;
		int itemH = 16;
		itemComp->getIdealSize (itemW, itemH, standardItemHeight);
		itemComp->setSize (itemW, jlimit (2, 600, itemH));
		// end of hack

        items.add (itemComp);
        addAndMakeVisible (itemComp);
        itemComp->addMouseListener (this, false);


Might be a cleaner way to do that though.


Thanks. Yep, the cleaner way is just to add to the ItemComponent to its parent before calling getIdealSize(), e.g.

[code] ItemComponent (const PopupMenu::Item& itemInfo_, int standardItemHeight, Component& parent)
: itemInfo (itemInfo_),
isHighlighted (false)
if (itemInfo.customComp != 0)
addAndMakeVisible (itemInfo.customComp);

    parent.addAndMakeVisible (this);
    int itemW = 80;
    int itemH = 16;
    getIdealSize (itemW, itemH, standardItemHeight);
    setSize (itemW, jlimit (2, 600, itemH));