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

#include <juce_ListBox.h>

Inheritance diagram for juce::ListBox:
juce::Component juce::SettableTooltipClient juce::MouseListener juce::TooltipClient juce::FileListComponent juce::TableListBox

Classes

class  RowComponent
class  ListViewport

Public Types

enum  ColourIds { backgroundColourId = 0x1002800 , outlineColourId = 0x1002810 , textColourId = 0x1002820 }
Public Types inherited from juce::Component
enum class  FocusContainerType { none , focusContainer , keyboardFocusContainer }
enum  FocusChangeType { focusChangedByMouseClick , focusChangedByTabKey , focusChangedDirectly }

Public Member Functions

 ListBox (const String &componentName=String(), ListBoxModel *model=nullptr)
 ~ListBox () override
void setModel (ListBoxModel *newModel)
ListBoxModelgetModel () const noexcept
void updateContent ()
void setMultipleSelectionEnabled (bool shouldBeEnabled) noexcept
void setClickingTogglesRowSelection (bool flipRowSelection) noexcept
void setRowSelectedOnMouseDown (bool isSelectedOnMouseDown) noexcept
void setMouseMoveSelectsRows (bool shouldSelect)
void selectRow (int rowNumber, bool dontScrollToShowThisRow=false, bool deselectOthersFirst=true)
void selectRangeOfRows (int firstRow, int lastRow, bool dontScrollToShowThisRange=false)
void deselectRow (int rowNumber)
void deselectAllRows ()
void flipRowSelection (int rowNumber)
SparseSet< intgetSelectedRows () const
void setSelectedRows (const SparseSet< int > &setOfRowsToBeSelected, NotificationType sendNotificationEventToModel=sendNotification)
bool isRowSelected (int rowNumber) const
int getNumSelectedRows () const
int getSelectedRow (int index=0) const
int getLastRowSelected () const
void selectRowsBasedOnModifierKeys (int rowThatWasClickedOn, ModifierKeys modifiers, bool isMouseUpEvent)
void setVerticalPosition (double newProportion)
double getVerticalPosition () const
void scrollToEnsureRowIsOnscreen (int row)
ScrollBargetVerticalScrollBar () const noexcept
ScrollBargetHorizontalScrollBar () const noexcept
int getRowContainingPosition (int x, int y) const noexcept
int getInsertionIndexForPosition (int x, int y) const noexcept
Rectangle< intgetRowPosition (int rowNumber, bool relativeToComponentTopLeft) const noexcept
ComponentgetComponentForRowNumber (int rowNumber) const noexcept
int getRowNumberOfComponent (Component *rowComponent) const noexcept
int getVisibleRowWidth () const noexcept
void setRowHeight (int newHeight)
int getRowHeight () const noexcept
int getNumRowsOnScreen () const noexcept
void setOutlineThickness (int outlineThickness)
int getOutlineThickness () const noexcept
void setHeaderComponent (std::unique_ptr< Component > newHeaderComponent)
ComponentgetHeaderComponent () const noexcept
void setMinimumContentWidth (int newMinimumWidth)
int getVisibleContentWidth () const noexcept
void repaintRow (int rowNumber) noexcept
virtual ScaledImage createSnapshotOfRows (const SparseSet< int > &rows, int &x, int &y)
ViewportgetViewport () const noexcept
bool keyPressed (const KeyPress &) override
bool keyStateChanged (bool isKeyDown) override
void paint (Graphics &) override
void paintOverChildren (Graphics &) override
void resized () override
void visibilityChanged () override
void mouseWheelMove (const MouseEvent &, const MouseWheelDetails &) override
void mouseUp (const MouseEvent &) override
void colourChanged () override
void parentHierarchyChanged () override
void startDragAndDrop (const MouseEvent &, const SparseSet< int > &rowsToDrag, const var &dragDescription, bool allowDraggingToOtherWindows)
void setSelectedRows (const SparseSet< int > &, 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
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)
virtual void lookAndFeelChanged ()
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)
virtual void enablementChanged ()
float getAlpha () const noexcept
void setAlpha (float newAlpha)
virtual void alphaChanged ()
void setMouseCursor (const MouseCursor &cursorType)
virtual MouseCursor getMouseCursor ()
void updateMouseCursor () const
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 mouseDoubleClick (const MouseEvent &event) 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 focusGained (FocusChangeType cause)
virtual void focusLost (FocusChangeType cause)
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
virtual void setTooltip (const String &newTooltip)
String getTooltip () override
Public Member Functions inherited from juce::TooltipClient
virtual ~TooltipClient ()=default

Private Member Functions

void assignModelPtr (ListBoxModel *)
void checkModelPtrIsValid () const
std::unique_ptr< AccessibilityHandlercreateAccessibilityHandler () override
bool hasAccessibleHeaderComponent () const
void selectRowInternal (int rowNumber, bool dontScrollToShowThisRow, bool deselectOthersFirst, bool isMouseClick)

Private Attributes

ListBoxModelmodel = nullptr
std::unique_ptr< ListViewportviewport
std::unique_ptr< ComponentheaderComponent
std::unique_ptr< MouseListenermouseMoveSelector
SparseSet< intselected
int totalItems = 0
int rowHeight = 22
int minimumRowWidth = 0
int outlineThickness = 0
int lastRowSelected = -1
bool multipleSelection = false
bool alwaysFlipSelection = false
bool hasDoneInitialUpdate = false
bool selectOnMouseDown = true
std::weak_ptr< ListBoxModel::EmptyweakModelPtr

Friends

class ListViewport
class TableListBox

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 list of items that can be scrolled vertically.

To create a list, you'll need to create a subclass of ListBoxModel. This can either paint each row of the list and respond to events via callbacks, or for more specialised tasks, it can supply a custom component to fill each row.

See also
ComboBox, TableListBox

@tags{GUI}

Member Enumeration Documentation

◆ ColourIds

enum juce::ListBox::ColourIds

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

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

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

The background colour to fill the list with. Make this transparent if you don't want the background to be filled.

outlineColourId 

An optional colour to use to draw a border around the list. Make this transparent to not have an outline.

textColourId 

The preferred colour to use for drawing text in the listbox.

Constructor & Destructor Documentation

◆ ListBox()

juce::ListBox::ListBox ( const String & componentName = String(),
ListBoxModel * model = nullptr )

Creates a ListBox.

The model pointer passed-in can be null, in which case you can set it later with setModel().

The ListBoxModel instance must stay alive for as long as the ListBox holds a pointer to it. Be careful to destroy the ListBox before the ListBoxModel, or to call ListBox::setModel (nullptr) before destroying the ListBoxModel.

◆ ~ListBox()

juce::ListBox::~ListBox ( )
override

Destructor.

Member Function Documentation

◆ assignModelPtr()

void juce::ListBox::assignModelPtr ( ListBoxModel * newModel)
private

◆ checkModelPtrIsValid()

void juce::ListBox::checkModelPtrIsValid ( ) const
private

◆ colourChanged()

void juce::ListBox::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::ListBox::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.

Reimplemented in juce::TableListBox.

◆ createSnapshotOfRows()

ScaledImage juce::ListBox::createSnapshotOfRows ( const SparseSet< int > & rows,
int & x,
int & y )
virtual

This fairly obscure method creates an image that shows the row components specified in rows (for example, these could be the currently selected row components).

It's a handy method for doing drag-and-drop, as it can be passed to the DragAndDropContainer for use as the drag image.

Note that it will make the row components temporarily invisible, so if you're using custom components this could affect them if they're sensitive to that sort of thing.

See also
Component::createComponentSnapshot

◆ deselectAllRows()

void juce::ListBox::deselectAllRows ( )

Deselects any currently selected rows.

See also
deselectRow

◆ deselectRow()

void juce::ListBox::deselectRow ( int rowNumber)

Deselects a row. If it's not currently selected, this will do nothing.

See also
selectRow, deselectAllRows

◆ flipRowSelection()

void juce::ListBox::flipRowSelection ( int rowNumber)

Selects or deselects a row. If the row's currently selected, this deselects it, and vice-versa.

◆ getComponentForRowNumber()

Component * juce::ListBox::getComponentForRowNumber ( int rowNumber) const
noexcept

Finds the row component for a given row in the list.

The component returned will have been created using ListBoxModel::refreshComponentForRow().

If the component for this row is off-screen or if the row is out-of-range, this will return nullptr.

See also
getRowContainingPosition

◆ getHeaderComponent()

Component * juce::ListBox::getHeaderComponent ( ) const
inlinenoexcept

Returns whatever header component was set with setHeaderComponent().

◆ getHorizontalScrollBar()

ScrollBar & juce::ListBox::getHorizontalScrollBar ( ) const
noexcept

Returns a reference to the horizontal scrollbar.

◆ getInsertionIndexForPosition()

int juce::ListBox::getInsertionIndexForPosition ( int x,
int y ) const
noexcept

Finds a row index that would be the most suitable place to insert a new item for a given position.

This is useful when the user is e.g. dragging and dropping onto the listbox, because it lets you easily choose the best position to insert the item that they drop, based on where they drop it.

If the position is out of range, this will return -1. If the position is beyond the end of the list, it will return getNumRows() to indicate the end of the list.

See also
getComponentForRowNumber

◆ getLastRowSelected()

int juce::ListBox::getLastRowSelected ( ) const

Returns the last row that the user selected.

This isn't the same as the highest row number that is currently selected - if the user had multiply-selected rows 10, 5 and then 6 in that order, this would return 6.

If nothing is selected, it will return -1.

◆ getModel()

ListBoxModel * juce::ListBox::getModel ( ) const
inlinenoexcept

Returns the current list model.

◆ getNumRowsOnScreen()

int juce::ListBox::getNumRowsOnScreen ( ) const
noexcept

Returns the number of rows actually visible.

This is the number of whole rows which will fit on-screen, so the value might be more than the actual number of rows in the list.

◆ getNumSelectedRows()

int juce::ListBox::getNumSelectedRows ( ) const

Returns the number of rows that are currently selected.

See also
getSelectedRow, isRowSelected, getLastRowSelected

◆ getOutlineThickness()

int juce::ListBox::getOutlineThickness ( ) const
inlinenoexcept

Returns the thickness of outline that will be drawn around the listbox.

See also
setOutlineColour

◆ getRowContainingPosition()

int juce::ListBox::getRowContainingPosition ( int x,
int y ) const
noexcept

Finds the row index that contains a given x,y position. The position is relative to the ListBox's top-left. If no row exists at this position, the method will return -1.

See also
getComponentForRowNumber

◆ getRowHeight()

int juce::ListBox::getRowHeight ( ) const
inlinenoexcept

Returns the height of a row in the list.

See also
setRowHeight

◆ getRowNumberOfComponent()

int juce::ListBox::getRowNumberOfComponent ( Component * rowComponent) const
noexcept

Returns the row number that the given component represents. If the component isn't one of the list's rows, this will return -1.

◆ getRowPosition()

Rectangle< int > juce::ListBox::getRowPosition ( int rowNumber,
bool relativeToComponentTopLeft ) const
noexcept

Returns the position of one of the rows, relative to the top-left of the listbox.

This may be off-screen, and the range of the row number that is passed-in is not checked to see if it's a valid row.

◆ getSelectedRow()

int juce::ListBox::getSelectedRow ( int index = 0) const

Returns the row number of a selected row.

This will return the row number of the Nth selected row. The row numbers returned will be sorted in order from low to high.

Parameters
indexthe index of the selected row to return, (from 0 to getNumSelectedRows() - 1)
Returns
the row number, or -1 if the index was out of range or if there aren't any rows selected
See also
getNumSelectedRows, isRowSelected, getLastRowSelected

◆ getSelectedRows()

SparseSet< int > juce::ListBox::getSelectedRows ( ) const

Returns a sparse set indicating the rows that are currently selected.

See also
setSelectedRows

◆ getVerticalPosition()

double juce::ListBox::getVerticalPosition ( ) const

Returns the current vertical position as a proportion of the total.

This can be used in conjunction with setVerticalPosition() to save and restore the list's position. It returns a value in the range 0 to 1.

See also
setVerticalPosition

◆ getVerticalScrollBar()

ScrollBar & juce::ListBox::getVerticalScrollBar ( ) const
noexcept

Returns a reference to the vertical scrollbar.

◆ getViewport()

Viewport * juce::ListBox::getViewport ( ) const
noexcept

Returns the viewport that this ListBox uses.

You may need to use this to change parameters such as whether scrollbars are shown, etc.

◆ getVisibleContentWidth()

int juce::ListBox::getVisibleContentWidth ( ) const
noexcept

Returns the space currently available for the row items, taking into account borders, scrollbars, etc.

◆ getVisibleRowWidth()

int juce::ListBox::getVisibleRowWidth ( ) const
noexcept

Returns the width of a row (which may be less than the width of this component if there's a scrollbar).

◆ hasAccessibleHeaderComponent()

bool juce::ListBox::hasAccessibleHeaderComponent ( ) const
private

◆ isRowSelected()

bool juce::ListBox::isRowSelected ( int rowNumber) const

Checks whether a row is selected.

◆ keyPressed()

bool juce::ListBox::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::ListBox::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.

◆ mouseUp()

void juce::ListBox::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::Component.

◆ mouseWheelMove()

void juce::ListBox::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. (Bear in mind that if you attach a component as a mouse-listener to other components, then those wheel moves will also end up calling this method and being passed up to the parents, which may not be what you intended to happen).

Parameters
Eventdetails about the mouse event
wheeldetails about the mouse wheel movement

Reimplemented from juce::Component.

◆ paint()

void juce::ListBox::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.

◆ paintOverChildren()

void juce::ListBox::paintOverChildren ( Graphics & g)
overridevirtual

Components can override this method to draw over the top of their children.

For most drawing operations, it's better to use the normal paint() method, but if you need to overlay something on top of the children, this can be used.

See also
paint, Graphics

Reimplemented from juce::Component.

◆ parentHierarchyChanged()

void juce::ListBox::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.

◆ repaintRow()

void juce::ListBox::repaintRow ( int rowNumber)
noexcept

Repaints one of the rows.

This does not invoke updateContent(), it just invokes a straightforward repaint for the area covered by this row.

◆ resized()

void juce::ListBox::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.

Reimplemented in juce::TableListBox.

◆ scrollToEnsureRowIsOnscreen()

void juce::ListBox::scrollToEnsureRowIsOnscreen ( int row)

Scrolls if necessary to make sure that a particular row is visible.

◆ selectRangeOfRows()

void juce::ListBox::selectRangeOfRows ( int firstRow,
int lastRow,
bool dontScrollToShowThisRange = false )

Selects a set of rows.

This will add these rows to the current selection, so you might need to clear the current selection first with deselectAllRows()

Parameters
firstRowthe first row to select (inclusive)
lastRowthe last row to select (inclusive)
dontScrollToShowThisRangeif true, the list's position won't change; if false and the selected range is off-screen, it'll scroll to make sure that the range of rows is on-screen

◆ selectRow()

void juce::ListBox::selectRow ( int rowNumber,
bool dontScrollToShowThisRow = false,
bool deselectOthersFirst = true )

Selects a row.

If the row is already selected, this won't do anything.

Parameters
rowNumberthe row to select
dontScrollToShowThisRowif true, the list's position won't change; if false and the selected row is off-screen, it'll scroll to make sure that row is on-screen
deselectOthersFirstif true and there are multiple selections, these will first be deselected before this item is selected
See also
isRowSelected, selectRowsBasedOnModifierKeys, flipRowSelection, deselectRow, deselectAllRows, selectRangeOfRows

◆ selectRowInternal()

void juce::ListBox::selectRowInternal ( int rowNumber,
bool dontScrollToShowThisRow,
bool deselectOthersFirst,
bool isMouseClick )
private

◆ selectRowsBasedOnModifierKeys()

void juce::ListBox::selectRowsBasedOnModifierKeys ( int rowThatWasClickedOn,
ModifierKeys modifiers,
bool isMouseUpEvent )

Multiply-selects rows based on the modifier keys.

If no modifier keys are down, this will select the given row and deselect any others.

If the ctrl (or command on the Mac) key is down, it'll flip the state of the selected row.

If the shift key is down, it'll select up to the given row from the last row selected.

See also
selectRow

◆ setClickingTogglesRowSelection()

void juce::ListBox::setClickingTogglesRowSelection ( bool flipRowSelection)
noexcept

If enabled, this makes the listbox flip the selection status of each row that the user clicks, without affecting other selected rows.

(This only has an effect if multiple selection is also enabled). If not enabled, you can still get the same row-flipping behaviour by holding down CMD or CTRL when clicking.

◆ setHeaderComponent()

void juce::ListBox::setHeaderComponent ( std::unique_ptr< Component > newHeaderComponent)

Sets a component that the list should use as a header.

This will position the given component at the top of the list, maintaining the height of the component passed-in, but rescaling it horizontally to match the width of the items in the listbox.

The component will be deleted when setHeaderComponent() is called with a different component, or when the listbox is deleted.

◆ setMinimumContentWidth()

void juce::ListBox::setMinimumContentWidth ( int newMinimumWidth)

Changes the width of the rows in the list.

This can be used to make the list's row components wider than the list itself - the width of the rows will be either the width of the list or this value, whichever is greater, and if the rows become wider than the list, a horizontal scrollbar will appear.

The default value for this is 0, which means that the rows will always be the same width as the list.

◆ setModel()

void juce::ListBox::setModel ( ListBoxModel * newModel)

Changes the current data model to display.

The ListBoxModel instance must stay alive for as long as the ListBox holds a pointer to it. Be careful to destroy the ListBox before the ListBoxModel, or to call ListBox::setModel (nullptr) before destroying the ListBoxModel.

◆ setMouseMoveSelectsRows()

void juce::ListBox::setMouseMoveSelectsRows ( bool shouldSelect)

Makes the list react to mouse moves by selecting the row that the mouse if over.

This function is here primarily for the ComboBox class to use, but might be useful for some other purpose too.

◆ setMultipleSelectionEnabled()

void juce::ListBox::setMultipleSelectionEnabled ( bool shouldBeEnabled)
noexcept

Turns on multiple-selection of rows.

By default this is disabled.

When your row component gets clicked you'll need to call the selectRowsBasedOnModifierKeys() method to tell the list that it's been clicked and to get it to do the appropriate selection based on whether the ctrl/shift keys are held down.

◆ setOutlineThickness()

void juce::ListBox::setOutlineThickness ( int outlineThickness)

Sets the thickness of a border that will be drawn around the box.

To set the colour of the outline, use

void setColour(int colourID, Colour newColour)
Definition juce_Component.cpp:2242
@ outlineColourId
Definition juce_ListBox.h:496
See also
outlineColourId

◆ setRowHeight()

void juce::ListBox::setRowHeight ( int newHeight)

Sets the height of each row in the list. The default height is 22 pixels.

See also
getRowHeight

◆ setRowSelectedOnMouseDown()

void juce::ListBox::setRowSelectedOnMouseDown ( bool isSelectedOnMouseDown)
noexcept

Sets whether a row should be selected when the mouse is pressed or released. By default this is true, but you may want to turn it off.

◆ setSelectedRows() [1/2]

void juce::ListBox::setSelectedRows ( const SparseSet< int > & ,
bool  )

◆ setSelectedRows() [2/2]

void juce::ListBox::setSelectedRows ( const SparseSet< int > & setOfRowsToBeSelected,
NotificationType sendNotificationEventToModel = sendNotification )

Sets the rows that should be selected, based on an explicit set of ranges.

If sendNotificationEventToModel is true, the ListBoxModel::selectedRowsChanged() method will be called. If it's false, no notification will be sent to the model.

See also
getSelectedRows

◆ setVerticalPosition()

void juce::ListBox::setVerticalPosition ( double newProportion)

Scrolls the list to a particular position.

The proportion is between 0 and 1.0, so 0 scrolls to the top of the list, 1.0 scrolls to the bottom.

If the total number of rows all fit onto the screen at once, then this method won't do anything.

See also
getVerticalPosition

◆ startDragAndDrop()

void juce::ListBox::startDragAndDrop ( const MouseEvent & e,
const SparseSet< int > & rowsToDrag,
const var & dragDescription,
bool allowDraggingToOtherWindows )

◆ updateContent()

void juce::ListBox::updateContent ( )

Causes the list to refresh its content.

Call this when the number of rows in the list changes, or if you want it to call refreshComponentForRow() on all the row components.

This must only be called from the main message thread.

◆ visibilityChanged()

void juce::ListBox::visibilityChanged ( )
overridevirtual

Called when this component's visibility changes.

See also
setVisible, isVisible

Reimplemented from juce::Component.

◆ ListViewport

friend class ListViewport
friend

◆ TableListBox

friend class TableListBox
friend

Member Data Documentation

◆ alwaysFlipSelection

bool juce::ListBox::alwaysFlipSelection = false
private

◆ hasDoneInitialUpdate

bool juce::ListBox::hasDoneInitialUpdate = false
private

◆ headerComponent

std::unique_ptr<Component> juce::ListBox::headerComponent
private

◆ lastRowSelected

int juce::ListBox::lastRowSelected = -1
private

◆ minimumRowWidth

int juce::ListBox::minimumRowWidth = 0
private

◆ model

ListBoxModel* juce::ListBox::model = nullptr
private

◆ mouseMoveSelector

std::unique_ptr<MouseListener> juce::ListBox::mouseMoveSelector
private

◆ multipleSelection

bool juce::ListBox::multipleSelection = false
private

◆ outlineThickness

int juce::ListBox::outlineThickness = 0
private

◆ rowHeight

int juce::ListBox::rowHeight = 22
private

◆ selected

SparseSet<int> juce::ListBox::selected
private

◆ selectOnMouseDown

bool juce::ListBox::selectOnMouseDown = true
private

◆ totalItems

int juce::ListBox::totalItems = 0
private

◆ viewport

std::unique_ptr<ListViewport> juce::ListBox::viewport
private

◆ weakModelPtr

std::weak_ptr<ListBoxModel::Empty> juce::ListBox::weakModelPtr
private

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