1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-24 01:54:22 +00:00

Added a method ComboBox::hidePopup().

This commit is contained in:
jules 2014-12-28 11:06:57 +00:00
parent e02d7fc544
commit 2ee8084658
2 changed files with 26 additions and 18 deletions

View file

@ -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

View file

@ -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 <Listener> listeners;
ListenerList<Listener> listeners;
ScopedPointer<Label> label;
String textWhenNothingSelected, noChoicesMessage;
@ -436,7 +439,6 @@ private:
bool nudgeSelectedItem (int delta);
void sendChange (NotificationType);
void showPopupIfNotActive();
static void popupMenuFinishedCallback (int, ComboBox*);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBox)
};