From 3bb8dbe3ac1c8ee481f9ef9b5334aead6737b10f Mon Sep 17 00:00:00 2001 From: hogliux Date: Thu, 23 Feb 2017 10:01:21 +0000 Subject: [PATCH] Fixed a bug where ComboBoxes with no itmes wouldn't show the "no choices" entry --- .../juce_gui_basics/widgets/juce_ComboBox.cpp | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_ComboBox.cpp b/modules/juce_gui_basics/widgets/juce_ComboBox.cpp index e227e7142c..57f1254958 100644 --- a/modules/juce_gui_basics/widgets/juce_ComboBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_ComboBox.cpp @@ -530,24 +530,35 @@ static void comboBoxPopupMenuFinishedCallback (int result, ComboBox* combo) void ComboBox::showPopup() { - PopupMenu::MenuItemIterator iterator (currentMenu, true); - const int selectedId = getSelectedId(); + PopupMenu noChoicesMenu; + const bool hasItems = (currentMenu.getNumItems() > 0); - while (iterator.next()) + if (hasItems) { - PopupMenu::Item &item = iterator.getItem(); + PopupMenu::MenuItemIterator iterator (currentMenu, true); + const int selectedId = getSelectedId(); - if (item.itemID != 0) - item.isTicked = (item.itemID == selectedId); + while (iterator.next()) + { + PopupMenu::Item &item = iterator.getItem(); + + if (item.itemID != 0) + item.isTicked = (item.itemID == selectedId); + } + } + else + { + noChoicesMenu.addItem (1, noChoicesMessage, false, false); } - currentMenu.setLookAndFeel(&getLookAndFeel()); - currentMenu.showMenuAsync (PopupMenu::Options().withTargetComponent (this) - .withItemThatMustBeVisible (getSelectedId()) - .withMinimumWidth (getWidth()) - .withMaximumNumColumns (1) - .withStandardItemHeight (label->getHeight()), - ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this)); + PopupMenu& menuToShow = (hasItems ? currentMenu : noChoicesMenu); + menuToShow.setLookAndFeel (&getLookAndFeel()); + menuToShow.showMenuAsync (PopupMenu::Options().withTargetComponent (this) + .withItemThatMustBeVisible (getSelectedId()) + .withMinimumWidth (getWidth()) + .withMaximumNumColumns (1) + .withStandardItemHeight (label->getHeight()), + ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this)); } //==============================================================================