From 2ee80846587eab5ef061cd39d3534088f3f2adb0 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 28 Dec 2014 11:06:57 +0000 Subject: [PATCH] Added a method ComboBox::hidePopup(). --- .../juce_gui_basics/widgets/juce_ComboBox.cpp | 38 +++++++++++-------- .../juce_gui_basics/widgets/juce_ComboBox.h | 6 ++- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_ComboBox.cpp b/modules/juce_gui_basics/widgets/juce_ComboBox.cpp index eed4111556..cc9339855b 100644 --- a/modules/juce_gui_basics/widgets/juce_ComboBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_ComboBox.cpp @@ -56,10 +56,7 @@ ComboBox::ComboBox (const String& name) ComboBox::~ComboBox() { currentId.removeListener (this); - - if (menuActive) - PopupMenu::dismissAllActiveMenus(); - + hidePopup(); label = nullptr; } @@ -501,17 +498,6 @@ void ComboBox::labelTextChanged (Label*) //============================================================================== -void ComboBox::popupMenuFinishedCallback (int result, ComboBox* box) -{ - if (box != nullptr) - { - box->menuActive = false; - - if (result != 0) - box->setSelectedId (result); - } -} - void ComboBox::showPopupIfNotActive() { if (! menuActive) @@ -521,6 +507,26 @@ void ComboBox::showPopupIfNotActive() } } +void ComboBox::hidePopup() +{ + if (menuActive) + { + menuActive = false; + PopupMenu::dismissAllActiveMenus(); + } +} + +static void comboBoxPopupMenuFinishedCallback (int result, ComboBox* combo) +{ + if (combo != nullptr) + { + combo->hidePopup(); + + if (result != 0) + combo->setSelectedId (result); + } +} + void ComboBox::showPopup() { PopupMenu menu; @@ -532,7 +538,7 @@ void ComboBox::showPopup() .withMinimumWidth (getWidth()) .withMaximumNumColumns (1) .withStandardItemHeight (label->getHeight()), - ModalCallbackFunction::forComponent (popupMenuFinishedCallback, this)); + ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this)); } void ComboBox::addItemsToMenu (PopupMenu& menu) const diff --git a/modules/juce_gui_basics/widgets/juce_ComboBox.h b/modules/juce_gui_basics/widgets/juce_ComboBox.h index 11f4dd47af..6fd4be7141 100644 --- a/modules/juce_gui_basics/widgets/juce_ComboBox.h +++ b/modules/juce_gui_basics/widgets/juce_ComboBox.h @@ -263,6 +263,9 @@ public: */ virtual void showPopup(); + /** Hides the combo box's popup list, if it's currently visible. */ + void hidePopup(); + /** Adds the items in this ComboBox to the given menu. */ virtual void addItemsToMenu (PopupMenu&) const; @@ -426,7 +429,7 @@ private: int lastCurrentId; bool isButtonDown, separatorPending, menuActive, scrollWheelEnabled; float mouseWheelAccumulator; - ListenerList listeners; + ListenerList listeners; ScopedPointer