mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fixed some typos and did a bit of code cleanup
This commit is contained in:
parent
c9a36c9f1d
commit
62955e7737
3 changed files with 39 additions and 53 deletions
|
|
@ -29,13 +29,7 @@ namespace juce
|
|||
|
||||
ComboBox::ComboBox (const String& name)
|
||||
: Component (name),
|
||||
lastCurrentId (0),
|
||||
isButtonDown (false),
|
||||
menuActive (false),
|
||||
scrollWheelEnabled (false),
|
||||
mouseWheelAccumulator (0),
|
||||
noChoicesMessage (TRANS("(no choices)")),
|
||||
labelEditableState (editableUnknown)
|
||||
noChoicesMessage (TRANS("(no choices)"))
|
||||
{
|
||||
setRepaintsOnMouseActivity (true);
|
||||
lookAndFeelChanged();
|
||||
|
|
@ -84,7 +78,7 @@ void ComboBox::setTooltip (const String& newTooltip)
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void ComboBox::addItem (const String& newItemText, const int newItemId)
|
||||
void ComboBox::addItem (const String& newItemText, int newItemId)
|
||||
{
|
||||
// you can't add empty strings to the list..
|
||||
jassert (newItemText.isNotEmpty());
|
||||
|
|
@ -96,12 +90,10 @@ void ComboBox::addItem (const String& newItemText, const int newItemId)
|
|||
jassert (getItemForId (newItemId) == nullptr);
|
||||
|
||||
if (newItemText.isNotEmpty() && newItemId != 0)
|
||||
{
|
||||
currentMenu.addItem (newItemId, newItemText, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ComboBox::addItemList (const StringArray& itemsToAdd, const int firstItemIdOffset)
|
||||
void ComboBox::addItemList (const StringArray& itemsToAdd, int firstItemIdOffset)
|
||||
{
|
||||
for (int i = 0; i < itemsToAdd.size(); ++i)
|
||||
currentMenu.addItem (i + firstItemIdOffset, itemsToAdd[i]);
|
||||
|
|
@ -118,26 +110,26 @@ void ComboBox::addSectionHeading (const String& headingName)
|
|||
jassert (headingName.isNotEmpty());
|
||||
|
||||
if (headingName.isNotEmpty())
|
||||
{
|
||||
currentMenu.addSectionHeader (headingName);
|
||||
}
|
||||
}
|
||||
|
||||
void ComboBox::setItemEnabled (const int itemId, const bool shouldBeEnabled)
|
||||
void ComboBox::setItemEnabled (int itemId, bool shouldBeEnabled)
|
||||
{
|
||||
if (PopupMenu::Item* item = getItemForId (itemId))
|
||||
if (auto* item = getItemForId (itemId))
|
||||
item->isEnabled = shouldBeEnabled;
|
||||
}
|
||||
|
||||
bool ComboBox::isItemEnabled (int itemId) const noexcept
|
||||
{
|
||||
const PopupMenu::Item* item = getItemForId (itemId);
|
||||
return item != nullptr && item->isEnabled;
|
||||
if (auto* item = getItemForId (itemId))
|
||||
return item->isEnabled;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ComboBox::changeItemText (const int itemId, const String& newText)
|
||||
void ComboBox::changeItemText (int itemId, const String& newText)
|
||||
{
|
||||
if (PopupMenu::Item* item = getItemForId (itemId))
|
||||
if (auto* item = getItemForId (itemId))
|
||||
item->text = newText;
|
||||
else
|
||||
jassertfalse;
|
||||
|
|
@ -152,15 +144,13 @@ void ComboBox::clear (const NotificationType notification)
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
PopupMenu::Item* ComboBox::getItemForId (const int itemId) const noexcept
|
||||
PopupMenu::Item* ComboBox::getItemForId (int itemId) const noexcept
|
||||
{
|
||||
if (itemId != 0)
|
||||
{
|
||||
PopupMenu::MenuItemIterator iterator (currentMenu, true);
|
||||
|
||||
while (iterator.next())
|
||||
for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
|
||||
{
|
||||
PopupMenu::Item &item = iterator.getItem();
|
||||
auto& item = iterator.getItem();
|
||||
|
||||
if (item.itemID == itemId)
|
||||
return &item;
|
||||
|
|
@ -173,11 +163,10 @@ PopupMenu::Item* ComboBox::getItemForId (const int itemId) const noexcept
|
|||
PopupMenu::Item* ComboBox::getItemForIndex (const int index) const noexcept
|
||||
{
|
||||
int n = 0;
|
||||
PopupMenu::MenuItemIterator iterator (currentMenu, true);
|
||||
|
||||
while (iterator.next())
|
||||
for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
|
||||
{
|
||||
PopupMenu::Item &item = iterator.getItem();
|
||||
auto& item = iterator.getItem();
|
||||
|
||||
if (item.itemID != 0)
|
||||
if (n++ == index)
|
||||
|
|
@ -190,11 +179,10 @@ PopupMenu::Item* ComboBox::getItemForIndex (const int index) const noexcept
|
|||
int ComboBox::getNumItems() const noexcept
|
||||
{
|
||||
int n = 0;
|
||||
PopupMenu::MenuItemIterator iterator (currentMenu, true);
|
||||
|
||||
while (iterator.next())
|
||||
for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
|
||||
{
|
||||
PopupMenu::Item &item = iterator.getItem();
|
||||
auto& item = iterator.getItem();
|
||||
|
||||
if (item.itemID != 0)
|
||||
n++;
|
||||
|
|
@ -224,9 +212,8 @@ int ComboBox::indexOfItemId (const int itemId) const noexcept
|
|||
if (itemId != 0)
|
||||
{
|
||||
int n = 0;
|
||||
PopupMenu::MenuItemIterator iterator (currentMenu, true);
|
||||
|
||||
while (iterator.next())
|
||||
for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
|
||||
{
|
||||
auto& item = iterator.getItem();
|
||||
|
||||
|
|
@ -244,7 +231,7 @@ int ComboBox::indexOfItemId (const int itemId) const noexcept
|
|||
//==============================================================================
|
||||
int ComboBox::getSelectedItemIndex() const
|
||||
{
|
||||
int index = indexOfItemId (currentId.getValue());
|
||||
auto index = indexOfItemId (currentId.getValue());
|
||||
|
||||
if (getText() != getItemText (index))
|
||||
index = -1;
|
||||
|
|
@ -259,15 +246,17 @@ void ComboBox::setSelectedItemIndex (const int index, const NotificationType not
|
|||
|
||||
int ComboBox::getSelectedId() const noexcept
|
||||
{
|
||||
const PopupMenu::Item* const item = getItemForId (currentId.getValue());
|
||||
if (auto* item = getItemForId (currentId.getValue()))
|
||||
if (getText() == item->text)
|
||||
return item->itemID;
|
||||
|
||||
return (item != nullptr && getText() == item->text) ? item->itemID : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ComboBox::setSelectedId (const int newItemId, const NotificationType notification)
|
||||
{
|
||||
const PopupMenu::Item* const item = getItemForId (newItemId);
|
||||
const String newItemText (item != nullptr ? item->text : String());
|
||||
auto* item = getItemForId (newItemId);
|
||||
auto newItemText = item != nullptr ? item->text : String();
|
||||
|
||||
if (lastCurrentId != newItemId || label->getText() != newItemText)
|
||||
{
|
||||
|
|
@ -283,7 +272,7 @@ void ComboBox::setSelectedId (const int newItemId, const NotificationType notifi
|
|||
|
||||
bool ComboBox::selectIfEnabled (const int index)
|
||||
{
|
||||
if (const PopupMenu::Item* const item = getItemForIndex (index))
|
||||
if (auto* item = getItemForIndex (index))
|
||||
{
|
||||
if (item->isEnabled)
|
||||
{
|
||||
|
|
@ -318,11 +307,9 @@ String ComboBox::getText() const
|
|||
|
||||
void ComboBox::setText (const String& newText, const NotificationType notification)
|
||||
{
|
||||
PopupMenu::MenuItemIterator iterator (currentMenu, true);
|
||||
|
||||
while (iterator.next())
|
||||
for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
|
||||
{
|
||||
PopupMenu::Item &item = iterator.getItem();
|
||||
auto& item = iterator.getItem();
|
||||
|
||||
if (item.itemID != 0
|
||||
&& item.text == newText)
|
||||
|
|
@ -547,12 +534,11 @@ void ComboBox::showPopup()
|
|||
|
||||
if (hasItems)
|
||||
{
|
||||
PopupMenu::MenuItemIterator iterator (currentMenu, true);
|
||||
const int selectedId = getSelectedId();
|
||||
auto selectedId = getSelectedId();
|
||||
|
||||
while (iterator.next())
|
||||
for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
|
||||
{
|
||||
PopupMenu::Item &item = iterator.getItem();
|
||||
auto& item = iterator.getItem();
|
||||
|
||||
if (item.itemID != 0)
|
||||
item.isTicked = (item.itemID == selectedId);
|
||||
|
|
@ -563,7 +549,7 @@ void ComboBox::showPopup()
|
|||
noChoicesMenu.addItem (1, noChoicesMessage, false, false);
|
||||
}
|
||||
|
||||
PopupMenu& menuToShow = (hasItems ? currentMenu : noChoicesMenu);
|
||||
auto& menuToShow = (hasItems ? currentMenu : noChoicesMenu);
|
||||
menuToShow.setLookAndFeel (&getLookAndFeel());
|
||||
menuToShow.showMenuAsync (PopupMenu::Options().withTargetComponent (this)
|
||||
.withItemThatMustBeVisible (getSelectedId())
|
||||
|
|
@ -599,7 +585,7 @@ void ComboBox::mouseUp (const MouseEvent& e2)
|
|||
isButtonDown = false;
|
||||
repaint();
|
||||
|
||||
const MouseEvent e (e2.getEventRelativeTo (this));
|
||||
auto e = e2.getEventRelativeTo (this);
|
||||
|
||||
if (reallyContains (e.getPosition(), true)
|
||||
&& (e2.eventComponent == this || ! label->isEditable()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue