LMMS
Loading...
Searching...
No Matches
juce::ComboBox Class Reference

#include <juce_ComboBox.h>

Inheritance diagram for juce::ComboBox:
juce::Component juce::SettableTooltipClient juce::Value::Listener juce::AsyncUpdater juce::MouseListener juce::TooltipClient

Classes

class  Listener
struct  LookAndFeelMethods

Public Types

enum  ColourIds {
  backgroundColourId = 0x1000b00 , textColourId = 0x1000a00 , outlineColourId = 0x1000c00 , buttonColourId = 0x1000d00 ,
  arrowColourId = 0x1000e00 , focusedOutlineColourId = 0x1000f00
}
Public Types inherited from juce::Component
enum class  FocusContainerType { none , focusContainer , keyboardFocusContainer }
enum  FocusChangeType { focusChangedByMouseClick , focusChangedByTabKey , focusChangedDirectly }

Public Member Functions

 ComboBox (const String &componentName={})
 ~ComboBox () override
void setEditableText (bool isEditable)
bool isTextEditable () const noexcept
void setJustificationType (Justification justification)
Justification getJustificationType () const noexcept
void addItem (const String &newItemText, int newItemId)
void addItemList (const StringArray &items, int firstItemIdOffset)
void addSeparator ()
void addSectionHeading (const String &headingName)
void setItemEnabled (int itemId, bool shouldBeEnabled)
bool isItemEnabled (int itemId) const noexcept
void changeItemText (int itemId, const String &newText)
void clear (NotificationType notification=sendNotificationAsync)
int getNumItems () const noexcept
String getItemText (int index) const
int getItemId (int index) const noexcept
int indexOfItemId (int itemId) const noexcept
int getSelectedId () const noexcept
ValuegetSelectedIdAsValue ()
void setSelectedId (int newItemId, NotificationType notification=sendNotificationAsync)
int getSelectedItemIndex () const
void setSelectedItemIndex (int newItemIndex, NotificationType notification=sendNotificationAsync)
String getText () const
void setText (const String &newText, NotificationType notification=sendNotificationAsync)
void showEditor ()
virtual void showPopup ()
void hidePopup ()
bool isPopupActive () const noexcept
PopupMenugetRootMenu () noexcept
const PopupMenugetRootMenu () const noexcept
void addListener (Listener *listener)
void removeListener (Listener *listener)
void setTextWhenNothingSelected (const String &newMessage)
String getTextWhenNothingSelected () const
void setTextWhenNoChoicesAvailable (const String &newMessage)
String getTextWhenNoChoicesAvailable () const
void setTooltip (const String &newTooltip) override
void setScrollWheelEnabled (bool enabled) noexcept
void enablementChanged () override
void colourChanged () override
void focusGained (Component::FocusChangeType) override
void focusLost (Component::FocusChangeType) override
void handleAsyncUpdate () override
String getTooltip () override
void mouseDown (const MouseEvent &) override
void mouseDrag (const MouseEvent &) override
void mouseUp (const MouseEvent &) override
void mouseWheelMove (const MouseEvent &, const MouseWheelDetails &) override
void lookAndFeelChanged () override
void paint (Graphics &) override
void resized () override
bool keyStateChanged (bool) override
bool keyPressed (const KeyPress &) override
void valueChanged (Value &) override
void parentHierarchyChanged () override
void clear (bool)
void setSelectedId (int, bool)
void setSelectedItemIndex (int, bool)
void setText (const String &, bool)
Public Member Functions inherited from juce::Component
 Component () noexcept
 ~Component () override
 Component (const String &componentName) noexcept
String getName () const noexcept
virtual void setName (const String &newName)
String getComponentID () const noexcept
void setComponentID (const String &newID)
virtual void setVisible (bool shouldBeVisible)
bool isVisible () const noexcept
virtual void visibilityChanged ()
bool isShowing () const
virtual void addToDesktop (int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
void removeFromDesktop ()
bool isOnDesktop () const noexcept
ComponentPeergetPeer () const
virtual void userTriedToCloseWindow ()
virtual void minimisationStateChanged (bool isNowMinimised)
virtual float getDesktopScaleFactor () const
void toFront (bool shouldAlsoGainKeyboardFocus)
void toBack ()
void toBehind (Component *other)
void setAlwaysOnTop (bool shouldStayOnTop)
bool isAlwaysOnTop () const noexcept
int getX () const noexcept
int getY () const noexcept
int getWidth () const noexcept
int getHeight () const noexcept
int getRight () const noexcept
Point< intgetPosition () const noexcept
int getBottom () const noexcept
Rectangle< intgetBounds () const noexcept
Rectangle< intgetLocalBounds () const noexcept
Rectangle< intgetBoundsInParent () const noexcept
int getScreenX () const
int getScreenY () const
Point< intgetScreenPosition () const
Rectangle< intgetScreenBounds () const
Point< intgetLocalPoint (const Component *sourceComponent, Point< int > pointRelativeToSourceComponent) const
Point< float > getLocalPoint (const Component *sourceComponent, Point< float > pointRelativeToSourceComponent) const
Rectangle< intgetLocalArea (const Component *sourceComponent, Rectangle< int > areaRelativeToSourceComponent) const
Rectangle< float > getLocalArea (const Component *sourceComponent, Rectangle< float > areaRelativeToSourceComponent) const
Point< intlocalPointToGlobal (Point< int > localPoint) const
Point< float > localPointToGlobal (Point< float > localPoint) const
Rectangle< intlocalAreaToGlobal (Rectangle< int > localArea) const
Rectangle< float > localAreaToGlobal (Rectangle< float > localArea) const
void setTopLeftPosition (int x, int y)
void setTopLeftPosition (Point< int > newTopLeftPosition)
void setTopRightPosition (int x, int y)
void setSize (int newWidth, int newHeight)
void setBounds (int x, int y, int width, int height)
void setBounds (Rectangle< int > newBounds)
void setBoundsRelative (float proportionalX, float proportionalY, float proportionalWidth, float proportionalHeight)
void setBoundsRelative (Rectangle< float > proportionalArea)
void setBoundsInset (BorderSize< int > borders)
void setBoundsToFit (Rectangle< int > targetArea, Justification justification, bool onlyReduceInSize)
void setCentrePosition (int x, int y)
void setCentrePosition (Point< int > newCentrePosition)
void setCentreRelative (float x, float y)
void centreWithSize (int width, int height)
void setTransform (const AffineTransform &transform)
AffineTransform getTransform () const
bool isTransformed () const noexcept
int proportionOfWidth (float proportion) const noexcept
int proportionOfHeight (float proportion) const noexcept
int getParentWidth () const noexcept
int getParentHeight () const noexcept
Rectangle< intgetParentMonitorArea () const
int getNumChildComponents () const noexcept
ComponentgetChildComponent (int index) const noexcept
int getIndexOfChildComponent (const Component *child) const noexcept
const Array< Component * > & getChildren () const noexcept
ComponentfindChildWithID (StringRef componentID) const noexcept
void addChildComponent (Component *child, int zOrder=-1)
void addChildComponent (Component &child, int zOrder=-1)
void addAndMakeVisible (Component *child, int zOrder=-1)
void addAndMakeVisible (Component &child, int zOrder=-1)
void addChildAndSetID (Component *child, const String &componentID)
void removeChildComponent (Component *childToRemove)
ComponentremoveChildComponent (int childIndexToRemove)
void removeAllChildren ()
void deleteAllChildren ()
ComponentgetParentComponent () const noexcept
template<class TargetClass>
TargetClass * findParentComponentOfClass () const
ComponentgetTopLevelComponent () const noexcept
bool isParentOf (const Component *possibleChild) const noexcept
virtual void childrenChanged ()
virtual bool hitTest (int x, int y)
void setInterceptsMouseClicks (bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
void getInterceptsMouseClicks (bool &allowsClicksOnThisComponent, bool &allowsClicksOnChildComponents) const noexcept
bool contains (Point< int > localPoint)
bool contains (Point< float > localPoint)
bool reallyContains (Point< int > localPoint, bool returnTrueIfWithinAChild)
bool reallyContains (Point< float > localPoint, bool returnTrueIfWithinAChild)
ComponentgetComponentAt (int x, int y)
ComponentgetComponentAt (Point< int > position)
ComponentgetComponentAt (Point< float > position)
void repaint ()
void repaint (int x, int y, int width, int height)
void repaint (Rectangle< int > area)
void setBufferedToImage (bool shouldBeBuffered)
Image createComponentSnapshot (Rectangle< int > areaToGrab, bool clipImageToComponentBounds=true, float scaleFactor=1.0f)
void paintEntireComponent (Graphics &context, bool ignoreAlphaLevel)
void setPaintingIsUnclipped (bool shouldPaintWithoutClipping) noexcept
bool isPaintingUnclipped () const noexcept
void setComponentEffect (ImageEffectFilter *newEffect)
ImageEffectFiltergetComponentEffect () const noexcept
LookAndFeelgetLookAndFeel () const noexcept
void setLookAndFeel (LookAndFeel *newLookAndFeel)
void sendLookAndFeelChange ()
void setOpaque (bool shouldBeOpaque)
bool isOpaque () const noexcept
void setBroughtToFrontOnMouseClick (bool shouldBeBroughtToFront) noexcept
bool isBroughtToFrontOnMouseClick () const noexcept
void setExplicitFocusOrder (int newFocusOrderIndex)
int getExplicitFocusOrder () const
void setFocusContainerType (FocusContainerType containerType) noexcept
bool isFocusContainer () const noexcept
bool isKeyboardFocusContainer () const noexcept
ComponentfindFocusContainer () const
ComponentfindKeyboardFocusContainer () const
void setWantsKeyboardFocus (bool wantsFocus) noexcept
bool getWantsKeyboardFocus () const noexcept
void setMouseClickGrabsKeyboardFocus (bool shouldGrabFocus)
bool getMouseClickGrabsKeyboardFocus () const noexcept
void grabKeyboardFocus ()
void giveAwayKeyboardFocus ()
bool hasKeyboardFocus (bool trueIfChildIsFocused) const
void moveKeyboardFocusToSibling (bool moveToNext)
virtual std::unique_ptr< ComponentTraversercreateFocusTraverser ()
virtual std::unique_ptr< ComponentTraversercreateKeyboardFocusTraverser ()
void setHasFocusOutline (bool hasFocusOutline) noexcept
bool hasFocusOutline () const noexcept
bool isEnabled () const noexcept
void setEnabled (bool shouldBeEnabled)
float getAlpha () const noexcept
void setAlpha (float newAlpha)
virtual void alphaChanged ()
void setMouseCursor (const MouseCursor &cursorType)
virtual MouseCursor getMouseCursor ()
void updateMouseCursor () const
virtual void paintOverChildren (Graphics &g)
void mouseMove (const MouseEvent &event) override
void mouseEnter (const MouseEvent &event) override
void mouseExit (const MouseEvent &event) override
void mouseDown (const MouseEvent &event) override
void mouseDrag (const MouseEvent &event) override
void mouseUp (const MouseEvent &event) override
void mouseDoubleClick (const MouseEvent &event) override
void mouseWheelMove (const MouseEvent &event, const MouseWheelDetails &wheel) override
void mouseMagnify (const MouseEvent &event, float scaleFactor) override
void setRepaintsOnMouseActivity (bool shouldRepaint) noexcept
void addMouseListener (MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
void removeMouseListener (MouseListener *listenerToRemove)
void addKeyListener (KeyListener *newListener)
void removeKeyListener (KeyListener *listenerToRemove)
virtual void modifierKeysChanged (const ModifierKeys &modifiers)
virtual void focusOfChildComponentChanged (FocusChangeType cause)
bool isMouseOver (bool includeChildren=false) const
bool isMouseButtonDown (bool includeChildren=false) const
bool isMouseOverOrDragging (bool includeChildren=false) const
Point< intgetMouseXYRelative () const
virtual void moved ()
virtual void childBoundsChanged (Component *child)
virtual void parentSizeChanged ()
virtual void broughtToFront ()
void addComponentListener (ComponentListener *newListener)
void removeComponentListener (ComponentListener *listenerToRemove)
void postCommandMessage (int commandId)
virtual void handleCommandMessage (int commandId)
void enterModalState (bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=nullptr, bool deleteWhenDismissed=false)
void exitModalState (int returnValue)
bool isCurrentlyModal (bool onlyConsiderForemostModalComponent=true) const noexcept
bool isCurrentlyBlockedByAnotherModalComponent () const
virtual bool canModalEventBeSentToComponent (const Component *targetComponent)
virtual void inputAttemptWhenModal ()
NamedValueSetgetProperties () noexcept
const NamedValueSetgetProperties () const noexcept
Colour findColour (int colourID, bool inheritFromParent=false) const
void setColour (int colourID, Colour newColour)
void removeColour (int colourID)
bool isColourSpecified (int colourID) const
void copyAllExplicitColoursTo (Component &target) const
voidgetWindowHandle () const
PositionergetPositioner () const noexcept
void setPositioner (Positioner *newPositioner)
void setCachedComponentImage (CachedComponentImage *newCachedImage)
CachedComponentImagegetCachedComponentImage () const noexcept
void setViewportIgnoreDragFlag (bool ignoreDrag) noexcept
bool getViewportIgnoreDragFlag () const noexcept
String getTitle () const noexcept
void setTitle (const String &newTitle)
String getDescription () const noexcept
void setDescription (const String &newDescription)
String getHelpText () const noexcept
void setHelpText (const String &newHelpText)
void setAccessible (bool shouldBeAccessible)
bool isAccessible () const noexcept
AccessibilityHandlergetAccessibilityHandler ()
void invalidateAccessibilityHandler ()
void setFocusContainer (bool shouldBeFocusContainer) noexcept
void contains (int, int)=delete
Public Member Functions inherited from juce::MouseListener
virtual ~MouseListener ()=default
Public Member Functions inherited from juce::SettableTooltipClient
 ~SettableTooltipClient () override=default
String getTooltip () override
Public Member Functions inherited from juce::TooltipClient
virtual ~TooltipClient ()=default
Public Member Functions inherited from juce::Value::Listener
 Listener ()=default
virtual ~Listener ()=default

Public Attributes

std::function< void()> onChange

Private Types

enum  EditableState { editableUnknown , labelIsNotEditable , labelIsEditable }

Private Member Functions

std::unique_ptr< AccessibilityHandlercreateAccessibilityHandler () override
PopupMenu::ItemgetItemForId (int) const noexcept
PopupMenu::ItemgetItemForIndex (int) const noexcept
bool selectIfEnabled (int index)
bool nudgeSelectedItem (int delta)
void sendChange (NotificationType)
void showPopupIfNotActive ()
Private Member Functions inherited from juce::AsyncUpdater
 AsyncUpdater ()
virtual ~AsyncUpdater ()
void triggerAsyncUpdate ()
void cancelPendingUpdate () noexcept
void handleUpdateNowIfNeeded ()
bool isUpdatePending () const noexcept

Private Attributes

PopupMenu currentMenu
Value currentId
int lastCurrentId = 0
bool isButtonDown = false
bool menuActive = false
bool scrollWheelEnabled = false
float mouseWheelAccumulator = 0
ListenerList< Listenerlisteners
std::unique_ptr< Labellabel
String textWhenNothingSelected
String noChoicesMessage
EditableState labelEditableState = editableUnknown

Additional Inherited Members

Static Public Member Functions inherited from juce::Component
static float JUCE_CALLTYPE getApproximateScaleFactorForComponent (const Component *targetComponent)
static Component *JUCE_CALLTYPE getCurrentlyFocusedComponent () noexcept
static void JUCE_CALLTYPE unfocusAllComponents ()
static void JUCE_CALLTYPE beginDragAutoRepeat (int millisecondsBetweenCallbacks)
static bool JUCE_CALLTYPE isMouseButtonDownAnywhere () noexcept
static int JUCE_CALLTYPE getNumCurrentlyModalComponents () noexcept
static Component *JUCE_CALLTYPE getCurrentlyModalComponent (int index=0) noexcept
Protected Member Functions inherited from juce::Component
virtual ComponentPeercreateNewPeer (int styleFlags, void *nativeWindowToAttachTo)
Protected Member Functions inherited from juce::SettableTooltipClient
 SettableTooltipClient ()=default
Static Protected Member Functions inherited from juce::Component
static std::unique_ptr< AccessibilityHandlercreateIgnoredAccessibilityHandler (Component &)

Detailed Description

A component that lets the user choose from a drop-down list of choices.

The combo-box has a list of text strings, each with an associated id number, that will be shown in the drop-down list when the user clicks on the component.

The currently selected choice is displayed in the combo-box, and this can either be read-only text, or editable.

To find out when the user selects a different item or edits the text, you can assign a lambda to the onChange member, or register a ComboBox::Listener to receive callbacks.

@tags{GUI}

Member Enumeration Documentation

◆ ColourIds

enum juce::ComboBox::ColourIds

A set of colour IDs to use to change the colour of various aspects of the combo box.

These constants can be used either via the Component::setColour(), or LookAndFeel::setColour() methods.

To change the colours of the menu that pops up, you can set the colour IDs in PopupMenu::ColourIDs.

See also
Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
Enumerator
backgroundColourId 

The background colour to fill the box with.

textColourId 

The colour for the text in the box.

outlineColourId 

The colour for an outline around the box.

buttonColourId 

The base colour for the button (a LookAndFeel class will probably use variations on this).

arrowColourId 

The colour for the arrow shape that pops up the menu

focusedOutlineColourId 

The colour that will be used to draw a box around the edge of the component when it has focus.

◆ EditableState

enum juce::ComboBox::EditableState
private
Enumerator
editableUnknown 
labelIsNotEditable 
labelIsEditable 

Constructor & Destructor Documentation

◆ ComboBox()

juce::ComboBox::ComboBox ( const String & componentName = {})
explicit

Creates a combo-box.

On construction, the text field will be empty, so you should call the setSelectedId() or setText() method to choose the initial value before displaying it.

Parameters
componentNamethe name to set for the component (see Component::setName())

◆ ~ComboBox()

juce::ComboBox::~ComboBox ( )
override

Destructor.

Member Function Documentation

◆ addItem()

void juce::ComboBox::addItem ( const String & newItemText,
int newItemId )

Adds an item to be shown in the drop-down list.

Parameters
newItemTextthe text of the item to show in the list
newItemIdan associated ID number that can be set or retrieved - see getSelectedId() and setSelectedId(). Note that this value can not be 0!
See also
setItemEnabled, addSeparator, addSectionHeading, getNumItems, getItemText, getItemId

◆ addItemList()

void juce::ComboBox::addItemList ( const StringArray & items,
int firstItemIdOffset )

Adds an array of items to the drop-down list. The item ID of each item will be its index in the StringArray + firstItemIdOffset.

◆ addListener()

void juce::ComboBox::addListener ( ComboBox::Listener * l)

Registers a listener that will be called when the box's content changes.

◆ addSectionHeading()

void juce::ComboBox::addSectionHeading ( const String & headingName)

Adds a heading to the drop-down list, so that you can group the items into different sections.

The headings are indented slightly differently to set them apart from the items on the list, and obviously can't be selected. You might want to add separators between your sections too.

See also
addItem, addSeparator

◆ addSeparator()

void juce::ComboBox::addSeparator ( )

Adds a separator line to the drop-down list.

This is like adding a separator to a popup menu. See PopupMenu::addSeparator().

◆ changeItemText()

void juce::ComboBox::changeItemText ( int itemId,
const String & newText )

Changes the text for an existing item.

◆ clear() [1/2]

void juce::ComboBox::clear ( bool dontSendChange)

◆ clear() [2/2]

void juce::ComboBox::clear ( NotificationType notification = sendNotificationAsync)

Removes all the items from the drop-down list.

If this call causes the content to be cleared, and a change-message will be broadcast according to the notification parameter.

See also
addItem, getNumItems

◆ colourChanged()

void juce::ComboBox::colourChanged ( )
overridevirtual

This method is called when a colour is changed by the setColour() method.

See also
setColour, findColour

Reimplemented from juce::Component.

◆ createAccessibilityHandler()

std::unique_ptr< AccessibilityHandler > juce::ComboBox::createAccessibilityHandler ( )
overrideprivatevirtual

Override this method to return a custom AccessibilityHandler for this component.

The default implementation creates and returns a AccessibilityHandler object with an unspecified role, meaning that it will be visible to accessibility clients but without a specific role, action callbacks or interfaces. To control how accessibility clients see and interact with your component subclass AccessibilityHandler, implement the desired behaviours, and return an instance of it from this method in your component subclass.

The accessibility handler you return here is guaranteed to be destroyed before its Component, so it's safe to store and use a reference back to the Component inside the AccessibilityHandler if necessary.

See also
getAccessibilityHandler

Reimplemented from juce::Component.

◆ enablementChanged()

void juce::ComboBox::enablementChanged ( )
overridevirtual

Callback to indicate that this component has been enabled or disabled.

This can be triggered by one of the component's parent components being enabled or disabled, as well as changes to the component itself.

The default implementation of this method does nothing; your class may wish to repaint itself or something when this happens.

See also
setEnabled, isEnabled

Reimplemented from juce::Component.

◆ focusGained()

void juce::ComboBox::focusGained ( Component::FocusChangeType cause)
overridevirtual

Called to indicate that this component has just acquired the keyboard focus.

See also
focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented from juce::Component.

◆ focusLost()

void juce::ComboBox::focusLost ( Component::FocusChangeType cause)
overridevirtual

Called to indicate that this component has just lost the keyboard focus.

See also
focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented from juce::Component.

◆ getItemForId()

PopupMenu::Item * juce::ComboBox::getItemForId ( int itemId) const
privatenoexcept

◆ getItemForIndex()

PopupMenu::Item * juce::ComboBox::getItemForIndex ( int index) const
privatenoexcept

◆ getItemId()

int juce::ComboBox::getItemId ( int index) const
noexcept

Returns the ID for one of the items in the list. Note that this doesn't include headers or separators.

Parameters
indexthe item's index from 0 to (getNumItems() - 1)

◆ getItemText()

String juce::ComboBox::getItemText ( int index) const

Returns the text for one of the items in the list. Note that this doesn't include headers or separators.

Parameters
indexthe item's index from 0 to (getNumItems() - 1)

◆ getJustificationType()

Justification juce::ComboBox::getJustificationType ( ) const
noexcept

Returns the current justification for the text box.

See also
setJustificationType

◆ getNumItems()

int juce::ComboBox::getNumItems ( ) const
noexcept

Returns the number of items that have been added to the list.

Note that this doesn't include headers or separators.

◆ getRootMenu() [1/2]

const PopupMenu * juce::ComboBox::getRootMenu ( ) const
inlinenoexcept

Returns the PopupMenu object associated with the ComboBox.

◆ getRootMenu() [2/2]

PopupMenu * juce::ComboBox::getRootMenu ( )
inlinenoexcept

Returns the PopupMenu object associated with the ComboBox. Can be useful for adding sub-menus to the ComboBox standard PopupMenu

◆ getSelectedId()

int juce::ComboBox::getSelectedId ( ) const
noexcept

Returns the ID of the item that's currently shown in the box.

If no item is selected, or if the text is editable and the user has entered something which isn't one of the items in the list, then this will return 0.

See also
setSelectedId, getSelectedItemIndex, getText

◆ getSelectedIdAsValue()

Value & juce::ComboBox::getSelectedIdAsValue ( )
inline

Returns a Value object that can be used to get or set the selected item's ID.

You can call Value::referTo() on this object to make the combo box control another Value object.

◆ getSelectedItemIndex()

int juce::ComboBox::getSelectedItemIndex ( ) const

Returns the index of the item that's currently shown in the box.

If no item is selected, or if the text is editable and the user has entered something which isn't one of the items in the list, then this will return -1.

See also
setSelectedItemIndex, getSelectedId, getText

◆ getText()

String juce::ComboBox::getText ( ) const

Returns the text that is currently shown in the combo-box's text field.

If the ComboBox has editable text, then this text may have been edited by the user; otherwise it will be one of the items from the list, or possibly an empty string if nothing was selected.

See also
setText, getSelectedId, getSelectedItemIndex

◆ getTextWhenNoChoicesAvailable()

String juce::ComboBox::getTextWhenNoChoicesAvailable ( ) const

Returns the text shown when no items have been added to the list.

See also
setTextWhenNoChoicesAvailable

◆ getTextWhenNothingSelected()

String juce::ComboBox::getTextWhenNothingSelected ( ) const

Returns the text that is shown when no item is selected.

See also
setTextWhenNothingSelected

◆ getTooltip()

String juce::ComboBox::getTooltip ( )
inlineoverridevirtual

Returns the string that this object wants to show as its tooltip.

Implements juce::TooltipClient.

◆ handleAsyncUpdate()

void juce::ComboBox::handleAsyncUpdate ( )
overridevirtual

Called back to do whatever your class needs to do.

This method is called by the message thread at the next convenient time after the triggerAsyncUpdate() method has been called.

Implements juce::AsyncUpdater.

◆ hidePopup()

void juce::ComboBox::hidePopup ( )

Hides the combo box's popup list, if it's currently visible.

◆ indexOfItemId()

int juce::ComboBox::indexOfItemId ( int itemId) const
noexcept

Returns the index in the list of a particular item ID. If no such ID is found, this will return -1.

◆ isItemEnabled()

bool juce::ComboBox::isItemEnabled ( int itemId) const
noexcept

Returns true if the given item is enabled.

◆ isPopupActive()

bool juce::ComboBox::isPopupActive ( ) const
inlinenoexcept

Returns true if the popup menu is currently being shown.

◆ isTextEditable()

bool juce::ComboBox::isTextEditable ( ) const
noexcept

Returns true if the text is directly editable.

See also
setEditableText

◆ keyPressed()

bool juce::ComboBox::keyPressed ( const KeyPress & key)
overridevirtual

Called when a key is pressed.

When a key is pressed, the component that has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, the key will be passed to any KeyListeners that have been registered with this component. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.

The default implementation of this method does nothing and returns false.

See also
keyStateChanged, getCurrentlyFocusedComponent, addKeyListener

Reimplemented from juce::Component.

◆ keyStateChanged()

bool juce::ComboBox::keyStateChanged ( bool isKeyDown)
overridevirtual

Called when a key is pressed or released.

Whenever a key on the keyboard is pressed or released (including modifier keys like shift and ctrl), this method will be called on the component that currently has the keyboard focus. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, then any KeyListeners that have been registered with this component will have their keyStateChanged methods called. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.

The default implementation of this method does nothing and returns false.

To find out which keys are up or down at any time, see the KeyPress::isKeyCurrentlyDown() method.

Parameters
isKeyDowntrue if a key has been pressed; false if it has been released
See also
keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener

Reimplemented from juce::Component.

◆ lookAndFeelChanged()

void juce::ComboBox::lookAndFeelChanged ( )
overridevirtual

Called to let the component react to a change in the look-and-feel setting.

When the look-and-feel is changed for a component, this will be called in all its child components, recursively.

It can also be triggered manually by the sendLookAndFeelChange() method, in case an application uses a LookAndFeel class that might have changed internally.

See also
sendLookAndFeelChange, getLookAndFeel

Reimplemented from juce::Component.

◆ mouseDown()

void juce::ComboBox::mouseDown ( const MouseEvent & event)
overridevirtual

Called when a mouse button is pressed.

The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.

Once a button is held down, the mouseDrag method will be called when the mouse moves, until the button is released.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseUp, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

◆ mouseDrag()

void juce::ComboBox::mouseDrag ( const MouseEvent & event)
overridevirtual

Called when the mouse is moved while a button is held down.

When a mouse button is pressed inside a component, that component receives mouseDrag callbacks each time the mouse moves, even if the mouse strays outside the component's bounds.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseUp, mouseMove, contains, setDragRepeatInterval

Reimplemented from juce::MouseListener.

◆ mouseUp()

void juce::ComboBox::mouseUp ( const MouseEvent & event)
overridevirtual

Called when a mouse button is released.

A mouseUp callback is sent to the component in which a button was pressed even if the mouse is actually over a different component when the button is released.

The MouseEvent object passed in contains lots of methods for finding out which buttons were down just before they were released.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

◆ mouseWheelMove()

void juce::ComboBox::mouseWheelMove ( const MouseEvent & event,
const MouseWheelDetails & wheel )
overridevirtual

Called when the mouse-wheel is moved.

This callback is sent to the component that the mouse is over when the wheel is moved.

If not overridden, a component will forward this message to its parent, so that parent components can collect mouse-wheel messages that happen to child components which aren't interested in them.

Parameters
Eventdetails about the mouse event
wheeldetails about the wheel movement

Reimplemented from juce::MouseListener.

◆ nudgeSelectedItem()

bool juce::ComboBox::nudgeSelectedItem ( int delta)
private

◆ paint()

void juce::ComboBox::paint ( Graphics & g)
overridevirtual

Components can override this method to draw their content.

The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.

Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.

If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In JUCE (and almost all modern UI frameworks), you never redraw something synchronously.

You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().

Parameters
gthe graphics context that must be used to do the drawing operations.
See also
repaint, paintOverChildren, Graphics

Reimplemented from juce::Component.

◆ parentHierarchyChanged()

void juce::ComboBox::parentHierarchyChanged ( )
overridevirtual

Called to indicate that the component's parents have changed.

When a component is added or removed from its parent, this method will be called on all of its children (recursively - so all children of its children will also be called as well).

Subclasses can override this if they need to react to this in some way.

See also
getParentComponent, isShowing, ComponentListener::componentParentHierarchyChanged

Reimplemented from juce::Component.

◆ removeListener()

void juce::ComboBox::removeListener ( ComboBox::Listener * l)

Deregisters a previously-registered listener.

◆ resized()

void juce::ComboBox::resized ( )
overridevirtual

Called when this component's size has been changed.

A component can implement this method to do things such as laying out its child components when its width or height changes.

The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).

If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.

See also
moved, setSize

Reimplemented from juce::Component.

◆ selectIfEnabled()

bool juce::ComboBox::selectIfEnabled ( int index)
private

◆ sendChange()

void juce::ComboBox::sendChange ( NotificationType notification)
private

◆ setEditableText()

void juce::ComboBox::setEditableText ( bool isEditable)

Sets whether the text in the combo-box is editable.

The default state for a new ComboBox is non-editable, and can only be changed by choosing from the drop-down list.

◆ setItemEnabled()

void juce::ComboBox::setItemEnabled ( int itemId,
bool shouldBeEnabled )

This allows items in the drop-down list to be selectively disabled.

When you add an item, it's enabled by default, but you can call this method to change its status.

If you disable an item which is already selected, this won't change the current selection - it just stops the user choosing that item from the list.

◆ setJustificationType()

void juce::ComboBox::setJustificationType ( Justification justification)

Sets the style of justification to be used for positioning the text.

The default is Justification::centredLeft. The text is displayed using a Label component inside the ComboBox.

◆ setScrollWheelEnabled()

void juce::ComboBox::setScrollWheelEnabled ( bool enabled)
noexcept

This can be used to allow the scroll-wheel to nudge the chosen item. By default it's disabled, and I'd recommend leaving it disabled if there's any chance that the control might be inside a scrollable list or viewport.

◆ setSelectedId() [1/2]

void juce::ComboBox::setSelectedId ( int newItemId,
NotificationType notification = sendNotificationAsync )

Sets one of the items to be the current selection.

This will set the ComboBox's text to that of the item that matches this ID.

Parameters
newItemIdthe new item to select
notificationdetermines the type of change notification that will be sent to listeners if the value changes
See also
getSelectedId, setSelectedItemIndex, setText

◆ setSelectedId() [2/2]

void juce::ComboBox::setSelectedId ( int newItemId,
bool dontSendChange )

◆ setSelectedItemIndex() [1/2]

void juce::ComboBox::setSelectedItemIndex ( int newItemIndex,
NotificationType notification = sendNotificationAsync )

Sets one of the items to be the current selection.

This will set the ComboBox's text to that of the item at the given index in the list.

Parameters
newItemIndexthe new item to select
notificationdetermines the type of change notification that will be sent to listeners if the value changes
See also
getSelectedItemIndex, setSelectedId, setText

◆ setSelectedItemIndex() [2/2]

void juce::ComboBox::setSelectedItemIndex ( int index,
bool dontSendChange )

◆ setText() [1/2]

void juce::ComboBox::setText ( const String & newText,
bool dontSendChange )

◆ setText() [2/2]

void juce::ComboBox::setText ( const String & newText,
NotificationType notification = sendNotificationAsync )

Sets the contents of the combo-box's text field.

The text passed-in will be set as the current text regardless of whether it is one of the items in the list. If the current text isn't one of the items, then getSelectedId() will return 0, otherwise it will return the appropriate ID.

Parameters
newTextthe text to select
notificationdetermines the type of change notification that will be sent to listeners if the text changes
See also
getText

◆ setTextWhenNoChoicesAvailable()

void juce::ComboBox::setTextWhenNoChoicesAvailable ( const String & newMessage)

Sets the message to show when there are no items in the list, and the user clicks on the drop-down box.

By default it just says "no choices", but this lets you change it to something more meaningful.

◆ setTextWhenNothingSelected()

void juce::ComboBox::setTextWhenNothingSelected ( const String & newMessage)

Sets a message to display when there is no item currently selected.

See also
getTextWhenNothingSelected

◆ setTooltip()

void juce::ComboBox::setTooltip ( const String & newTooltip)
overridevirtual

Gives the ComboBox a tooltip.

Reimplemented from juce::SettableTooltipClient.

◆ showEditor()

void juce::ComboBox::showEditor ( )

Programmatically opens the text editor to allow the user to edit the current item.

This is the same effect as when the box is clicked-on.

See also
Label::showEditor();

◆ showPopup()

void juce::ComboBox::showPopup ( )
virtual

Pops up the combo box's list. This is virtual so that you can override it with your own custom popup mechanism if you need some really unusual behaviour.

◆ showPopupIfNotActive()

void juce::ComboBox::showPopupIfNotActive ( )
private

◆ valueChanged()

void juce::ComboBox::valueChanged ( Value & value)
overridevirtual

Called when a Value object is changed.

Note that the Value object passed as a parameter may not be exactly the same object that you registered the listener with - it might be a copy that refers to the same underlying ValueSource. To find out, you can call Value::refersToSameSourceAs().

Implements juce::Value::Listener.

Member Data Documentation

◆ currentId

Value juce::ComboBox::currentId
private

◆ currentMenu

PopupMenu juce::ComboBox::currentMenu
private

◆ isButtonDown

bool juce::ComboBox::isButtonDown = false
private

◆ label

std::unique_ptr<Label> juce::ComboBox::label
private

◆ labelEditableState

EditableState juce::ComboBox::labelEditableState = editableUnknown
private

◆ lastCurrentId

int juce::ComboBox::lastCurrentId = 0
private

◆ listeners

ListenerList<Listener> juce::ComboBox::listeners
private

◆ menuActive

bool juce::ComboBox::menuActive = false
private

◆ mouseWheelAccumulator

float juce::ComboBox::mouseWheelAccumulator = 0
private

◆ noChoicesMessage

String juce::ComboBox::noChoicesMessage
private

◆ onChange

std::function<void()> juce::ComboBox::onChange

You can assign a lambda to this callback object to have it called when the selected ID is changed.

◆ scrollWheelEnabled

bool juce::ComboBox::scrollWheelEnabled = false
private

◆ textWhenNothingSelected

String juce::ComboBox::textWhenNothingSelected
private

The documentation for this class was generated from the following files: