@@ -56,10 +56,7 @@ ComboBox::ComboBox (const String& name) | |||||
ComboBox::~ComboBox() | ComboBox::~ComboBox() | ||||
{ | { | ||||
currentId.removeListener (this); | currentId.removeListener (this); | ||||
if (menuActive) | |||||
PopupMenu::dismissAllActiveMenus(); | |||||
hidePopup(); | |||||
label = nullptr; | label = nullptr; | ||||
} | } | ||||
@@ -501,23 +498,32 @@ void ComboBox::labelTextChanged (Label*) | |||||
//============================================================================== | //============================================================================== | ||||
void ComboBox::popupMenuFinishedCallback (int result, ComboBox* box) | |||||
void ComboBox::showPopupIfNotActive() | |||||
{ | { | ||||
if (box != nullptr) | |||||
if (! menuActive) | |||||
{ | { | ||||
box->menuActive = false; | |||||
menuActive = true; | |||||
showPopup(); | |||||
} | |||||
} | |||||
if (result != 0) | |||||
box->setSelectedId (result); | |||||
void ComboBox::hidePopup() | |||||
{ | |||||
if (menuActive) | |||||
{ | |||||
menuActive = false; | |||||
PopupMenu::dismissAllActiveMenus(); | |||||
} | } | ||||
} | } | ||||
void ComboBox::showPopupIfNotActive() | |||||
static void comboBoxPopupMenuFinishedCallback (int result, ComboBox* combo) | |||||
{ | { | ||||
if (! menuActive) | |||||
if (combo != nullptr) | |||||
{ | { | ||||
menuActive = true; | |||||
showPopup(); | |||||
combo->hidePopup(); | |||||
if (result != 0) | |||||
combo->setSelectedId (result); | |||||
} | } | ||||
} | } | ||||
@@ -532,7 +538,7 @@ void ComboBox::showPopup() | |||||
.withMinimumWidth (getWidth()) | .withMinimumWidth (getWidth()) | ||||
.withMaximumNumColumns (1) | .withMaximumNumColumns (1) | ||||
.withStandardItemHeight (label->getHeight()), | .withStandardItemHeight (label->getHeight()), | ||||
ModalCallbackFunction::forComponent (popupMenuFinishedCallback, this)); | |||||
ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this)); | |||||
} | } | ||||
void ComboBox::addItemsToMenu (PopupMenu& menu) const | void ComboBox::addItemsToMenu (PopupMenu& menu) const | ||||
@@ -263,6 +263,9 @@ public: | |||||
*/ | */ | ||||
virtual void showPopup(); | 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. */ | /** Adds the items in this ComboBox to the given menu. */ | ||||
virtual void addItemsToMenu (PopupMenu&) const; | virtual void addItemsToMenu (PopupMenu&) const; | ||||
@@ -426,7 +429,7 @@ private: | |||||
int lastCurrentId; | int lastCurrentId; | ||||
bool isButtonDown, separatorPending, menuActive, scrollWheelEnabled; | bool isButtonDown, separatorPending, menuActive, scrollWheelEnabled; | ||||
float mouseWheelAccumulator; | float mouseWheelAccumulator; | ||||
ListenerList <Listener> listeners; | |||||
ListenerList<Listener> listeners; | |||||
ScopedPointer<Label> label; | ScopedPointer<Label> label; | ||||
String textWhenNothingSelected, noChoicesMessage; | String textWhenNothingSelected, noChoicesMessage; | ||||
@@ -436,7 +439,6 @@ private: | |||||
bool nudgeSelectedItem (int delta); | bool nudgeSelectedItem (int delta); | ||||
void sendChange (NotificationType); | void sendChange (NotificationType); | ||||
void showPopupIfNotActive(); | void showPopupIfNotActive(); | ||||
static void popupMenuFinishedCallback (int, ComboBox*); | |||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBox) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBox) | ||||
}; | }; | ||||