Loading...
Searching...
No Matches
juce::ListBoxModel Class Referenceabstract

## Detailed Description

A subclass of this is used to drive a ListBox.

See also
  ListBox

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

- juce_gui_basics/widgets/juce_ListBox.h

Inheritance diagram for juce::ListBoxModel:

## Public Member Functions

virtual | ~ListBoxModel ()=default
| Destructor.
virtual int | getNumRows ()=0
| This has to return the number of items in the list.
virtual void | paintListBoxItem (int rowNumber, Graphics &g, int width, int height, bool rowIsSelected)=0
| This method must be implemented to draw a row of the list.
virtual Component * | refreshComponentForRow (int rowNumber, bool isRowSelected, Component *existingComponentToUpdate)
| This is used to create or update a custom component to go in a row of the list.
virtual String | getNameForRow (int rowNumber)
| This can be overridden to return a name for the specified row.
virtual void | listBoxItemClicked (int row, const MouseEvent &)
| This can be overridden to react to the user clicking on a row.
virtual void | listBoxItemDoubleClicked (int row, const MouseEvent &)
| This can be overridden to react to the user double-clicking on a row.
virtual void | backgroundClicked (const MouseEvent &)
| This can be overridden to react to the user clicking on a part of the list where there are no rows.
virtual void | selectedRowsChanged (int lastRowSelected)
| Override this to be informed when rows are selected or deselected.
virtual void | deleteKeyPressed (int lastRowSelected)
| Override this to be informed when the delete key is pressed.
virtual void | returnKeyPressed (int lastRowSelected)
| Override this to be informed when the return key is pressed.
virtual void | listWasScrolled ()
| Override this to be informed when the list is scrolled.
virtual var | getDragSourceDescription (const SparseSet< int > &rowsToDescribe)
| To allow rows from your list to be dragged-and-dropped, implement this method.
virtual bool | mayDragToExternalWindows () const
| Called when starting a drag operation on a list row to determine whether the item may be dragged to other windows.
virtual String | getTooltipForRow (int row)
| You can override this to provide tool tips for specific rows.
virtual MouseCursor | getMouseCursorForRow (int row)
| You can override this to return a custom mouse cursor for each row.

## Constructors and Destructors

## ~ListBoxModel()

virtual juce::ListBoxModel::~ListBoxModel | ( |  | ) |

virtual default

Destructor.

## Member Functions

## getNumRows()

virtual int juce::ListBoxModel::getNumRows | ( |  | ) |

pure virtual

This has to return the number of items in the list.

See also
  ListBox::getNumRows()

Implemented in juce::FileSearchPathListComponent, and juce::TableListBox.

## paintListBoxItem()

virtual void juce::ListBoxModel::paintListBoxItem | ( | int | rowNumber,
|  | Graphics & | g,
|  | int | width,
|  | int | height,
|  | bool | rowIsSelected )

pure virtual

This method must be implemented to draw a row of the list.

Note that the rowNumber value may be greater than the number of rows in your list, so be careful that you don't assume it's less than getNumRows().

Implemented in juce::FileSearchPathListComponent, and juce::TableListBox.

## refreshComponentForRow()

virtual Component * juce::ListBoxModel::refreshComponentForRow | ( | int | rowNumber,
|  | bool | isRowSelected,
|  | Component * | existingComponentToUpdate )

virtual

This is used to create or update a custom component to go in a row of the list.

Any row may contain a custom component, or can just be drawn with the paintListBoxItem() method and handle mouse clicks with listBoxItemClicked().

This method will be called whenever a custom component might need to be updated - e.g. when the list is changed, or ListBox::updateContent() is called.

If you don't need a custom component for the specified row, then return nullptr. (Bear in mind that even if you're not creating a new component, you may still need to delete existingComponentToUpdate if it's non-null).

If you do want a custom component, and the existingComponentToUpdate is null, then this method must create a suitable new component and return it.

If the existingComponentToUpdate is non-null, it will be a pointer to a component previously created by this method. In this case, the method must either update it to make sure it's correctly representing the given row (which may be different from the one that the component was created for), or it can delete this component and return a new one.

The component that your method returns will be deleted by the ListBox when it is no longer needed.

Bear in mind that if you put a custom component inside the row but still want the listbox to automatically handle clicking, selection, etc, then you'll need to make sure your custom component doesn't intercept all the mouse events that land on it, e.g by using Component::setInterceptsMouseClicks().

Reimplemented in juce::TableListBox.

## getNameForRow()

virtual String juce::ListBoxModel::getNameForRow | ( | int | rowNumber | ) |

virtual

This can be overridden to return a name for the specified row.

By default this will just return a string containing the row number.

## listBoxItemClicked()

virtual void juce::ListBoxModel::listBoxItemClicked | ( | int | row,
|  | const MouseEvent & | )

virtual

This can be overridden to react to the user clicking on a row.

See also
  listBoxItemDoubleClicked

## listBoxItemDoubleClicked()

virtual void juce::ListBoxModel::listBoxItemDoubleClicked | ( | int | row,
|  | const MouseEvent & | )

virtual

This can be overridden to react to the user double-clicking on a row.

See also
  listBoxItemClicked

Reimplemented in juce::FileSearchPathListComponent.

## backgroundClicked()

virtual void juce::ListBoxModel::backgroundClicked | ( | const MouseEvent & |  | ) |

virtual

This can be overridden to react to the user clicking on a part of the list where there are no rows.

See also
  listBoxItemClicked

Reimplemented in juce::TableListBox.

## selectedRowsChanged()

virtual void juce::ListBoxModel::selectedRowsChanged | ( | int | lastRowSelected | ) |

virtual

Override this to be informed when rows are selected or deselected.

This will be called whenever a row is selected or deselected. If a range of rows is selected all at once, this will just be called once for that event.

Parameters

  lastRowSelected | the last row that the user selected. If no rows are currently selected, this may be -1.

Reimplemented in juce::FileSearchPathListComponent, and juce::TableListBox.

## deleteKeyPressed()

virtual void juce::ListBoxModel::deleteKeyPressed | ( | int | lastRowSelected | ) |

virtual

Override this to be informed when the delete key is pressed.

If no rows are selected when they press the key, this won't be called.

Parameters

  lastRowSelected | the last row that had been selected when they pressed the key - if there are multiple selections, this might not be very useful

Reimplemented in juce::FileSearchPathListComponent, and juce::TableListBox.

## returnKeyPressed()

virtual void juce::ListBoxModel::returnKeyPressed | ( | int | lastRowSelected | ) |

virtual

Override this to be informed when the return key is pressed.

If no rows are selected when they press the key, this won't be called.

Parameters

  lastRowSelected | the last row that had been selected when they pressed the key - if there are multiple selections, this might not be very useful

Reimplemented in juce::FileSearchPathListComponent, and juce::TableListBox.

## listWasScrolled()

virtual void juce::ListBoxModel::listWasScrolled | ( |  | ) |

virtual

Override this to be informed when the list is scrolled.

This might be caused by the user moving the scrollbar, or by programmatic changes to the list position.

Reimplemented in juce::TableListBox.

## getDragSourceDescription()

virtual var juce::ListBoxModel::getDragSourceDescription | ( | const SparseSet< int > & | rowsToDescribe | ) |

virtual

To allow rows from your list to be dragged-and-dropped, implement this method.

If this returns a non-null variant then when the user drags a row, the listbox will try to find a DragAndDropContainer in its parent hierarchy, and will use it to trigger a drag-and-drop operation, using this string as the source description, with the listbox itself as the source component.

See also
  DragAndDropContainer::startDragging

## mayDragToExternalWindows()

virtual bool juce::ListBoxModel::mayDragToExternalWindows | ( |  | ) | const

inline virtual

Called when starting a drag operation on a list row to determine whether the item may be dragged to other windows.

Returns true by default.

## getTooltipForRow()

virtual String juce::ListBoxModel::getTooltipForRow | ( | int | row | ) |

virtual

You can override this to provide tool tips for specific rows.

See also
  TooltipClient

## getMouseCursorForRow()

virtual MouseCursor juce::ListBoxModel::getMouseCursorForRow | ( | int | row | ) |

virtual

You can override this to return a custom mouse cursor for each row.

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited