Browse Source

Added a method ComboBox::hidePopup().

tags/2021-05-28
jules 10 years ago
parent
commit
2ee8084658
2 changed files with 24 additions and 16 deletions
  1. +20
    -14
      modules/juce_gui_basics/widgets/juce_ComboBox.cpp
  2. +4
    -2
      modules/juce_gui_basics/widgets/juce_ComboBox.h

+ 20
- 14
modules/juce_gui_basics/widgets/juce_ComboBox.cpp View File

@@ -56,10 +56,7 @@ ComboBox::ComboBox (const String& name)
ComboBox::~ComboBox()
{
currentId.removeListener (this);
if (menuActive)
PopupMenu::dismissAllActiveMenus();
hidePopup();
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())
.withMaximumNumColumns (1)
.withStandardItemHeight (label->getHeight()),
ModalCallbackFunction::forComponent (popupMenuFinishedCallback, this));
ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this));
}
void ComboBox::addItemsToMenu (PopupMenu& menu) const


+ 4
- 2
modules/juce_gui_basics/widgets/juce_ComboBox.h 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)
};


Loading…
Cancel
Save