JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ListBox.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
37class JUCE_API ListBoxModel
38{
39public:
40 //==============================================================================
42 virtual ~ListBoxModel() = default;
43
44 //==============================================================================
48 virtual int getNumRows() = 0;
49
54 virtual void paintListBoxItem (int rowNumber,
55 Graphics& g,
56 int width, int height,
57 bool rowIsSelected) = 0;
58
86 virtual Component* refreshComponentForRow (int rowNumber, bool isRowSelected,
87 Component* existingComponentToUpdate);
88
93 virtual String getNameForRow (int rowNumber);
94
98 virtual void listBoxItemClicked (int row, const MouseEvent&);
99
103 virtual void listBoxItemDoubleClicked (int row, const MouseEvent&);
104
109 virtual void backgroundClicked (const MouseEvent&);
110
119 virtual void selectedRowsChanged (int lastRowSelected);
120
129 virtual void deleteKeyPressed (int lastRowSelected);
130
139 virtual void returnKeyPressed (int lastRowSelected);
140
146 virtual void listWasScrolled();
147
157 virtual var getDragSourceDescription (const SparseSet<int>& rowsToDescribe);
158
162 virtual bool mayDragToExternalWindows() const { return true; }
163
167 virtual String getTooltipForRow (int row);
168
170 virtual MouseCursor getMouseCursorForRow (int row);
171
172private:
173 #if ! JUCE_DISABLE_ASSERTIONS
174 friend class ListBox;
175 struct Empty {};
176 std::shared_ptr<Empty> sharedState = std::make_shared<Empty>();
177 #endif
178};
179
180//==============================================================================
192class JUCE_API ListBox : public Component,
194{
195public:
196 //==============================================================================
207 ListBox (const String& componentName = String(),
208 ListBoxModel* model = nullptr);
209
211 ~ListBox() override;
212
213 //==============================================================================
221 void setModel (ListBoxModel* newModel);
222
225 {
226 #if ! JUCE_DISABLE_ASSERTIONS
227 checkModelPtrIsValid();
228 #endif
229
230 return model;
231 }
232
233 //==============================================================================
241 void updateContent();
242
243 //==============================================================================
253 void setMultipleSelectionEnabled (bool shouldBeEnabled) noexcept;
254
262 void setClickingTogglesRowSelection (bool flipRowSelection) noexcept;
263
267 void setRowSelectedOnMouseDown (bool isSelectedOnMouseDown) noexcept;
268
272 bool getRowSelectedOnMouseDown() const { return selectOnMouseDown; }
273
279 void setMouseMoveSelectsRows (bool shouldSelect);
280
281 //==============================================================================
295 void selectRow (int rowNumber,
296 bool dontScrollToShowThisRow = false,
297 bool deselectOthersFirst = true);
298
310 void selectRangeOfRows (int firstRow,
311 int lastRow,
312 bool dontScrollToShowThisRange = false);
313
318 void deselectRow (int rowNumber);
319
323 void deselectAllRows();
324
328 void flipRowSelection (int rowNumber);
329
333 SparseSet<int> getSelectedRows() const;
334
342 void setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
343 NotificationType sendNotificationEventToModel = sendNotification);
344
347 bool isRowSelected (int rowNumber) const;
348
352 int getNumSelectedRows() const;
353
364 int getSelectedRow (int index = 0) const;
365
373 int getLastRowSelected() const;
374
388 void selectRowsBasedOnModifierKeys (int rowThatWasClickedOn,
389 ModifierKeys modifiers,
390 bool isMouseUpEvent);
391
392 //==============================================================================
403 void setVerticalPosition (double newProportion);
404
412 double getVerticalPosition() const;
413
415 void scrollToEnsureRowIsOnscreen (int row);
416
418 ScrollBar& getVerticalScrollBar() const noexcept;
419
421 ScrollBar& getHorizontalScrollBar() const noexcept;
422
428 int getRowContainingPosition (int x, int y) const noexcept;
429
443 int getInsertionIndexForPosition (int x, int y) const noexcept;
444
451 Rectangle<int> getRowPosition (int rowNumber,
452 bool relativeToComponentTopLeft) const noexcept;
453
463 Component* getComponentForRowNumber (int rowNumber) const noexcept;
464
468 int getRowNumberOfComponent (const Component* rowComponent) const noexcept;
469
473 int getVisibleRowWidth() const noexcept;
474
475 //==============================================================================
480 void setRowHeight (int newHeight);
481
485 int getRowHeight() const noexcept { return rowHeight; }
486
492 int getNumRowsOnScreen() const noexcept;
493
494 //==============================================================================
503 {
504 backgroundColourId = 0x1002800,
506 outlineColourId = 0x1002810,
508 textColourId = 0x1002820
509 };
510
516 void setOutlineThickness (int outlineThickness);
517
521 int getOutlineThickness() const noexcept { return outlineThickness; }
522
532 void setHeaderComponent (std::unique_ptr<Component> newHeaderComponent);
533
535 Component* getHeaderComponent() const noexcept { return headerComponent.get(); }
536
547 void setMinimumContentWidth (int newMinimumWidth);
548
552 int getVisibleContentWidth() const noexcept;
553
559 void repaintRow (int rowNumber) noexcept;
560
573 virtual ScaledImage createSnapshotOfRows (const SparseSet<int>& rows, int& x, int& y);
574
580 Viewport* getViewport() const noexcept;
581
582 //==============================================================================
584 bool keyPressed (const KeyPress&) override;
586 bool keyStateChanged (bool isKeyDown) override;
588 void paint (Graphics&) override;
590 void paintOverChildren (Graphics&) override;
592 void resized() override;
594 void visibilityChanged() override;
596 void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
598 void mouseUp (const MouseEvent&) override;
600 void colourChanged() override;
602 void parentHierarchyChanged() override;
604 void startDragAndDrop (const MouseEvent&, const SparseSet<int>& rowsToDrag,
605 const var& dragDescription, bool allowDraggingToOtherWindows);
607 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
608
609 //==============================================================================
610 #ifndef DOXYGEN
611 [[deprecated ("This method's bool parameter has changed: see the new method signature.")]]
612 void setSelectedRows (const SparseSet<int>&, bool);
613 #endif
614
615 [[deprecated ("The name of this function is ambiguous if derived classes supply their own models, use getListBoxModel instead")]]
616 ListBoxModel* getModel() const noexcept { return getListBoxModel(); }
617
618private:
619 //==============================================================================
620 JUCE_PUBLIC_IN_DLL_BUILD (class ListViewport)
621 JUCE_PUBLIC_IN_DLL_BUILD (class RowComponent)
622 friend class ListViewport;
623 friend class TableListBox;
624 ListBoxModel* model = nullptr;
626 std::unique_ptr<Component> headerComponent;
627 std::unique_ptr<MouseListener> mouseMoveSelector;
628 SparseSet<int> selected;
629 int totalItems = 0, rowHeight = 22, minimumRowWidth = 0;
630 int outlineThickness = 0;
631 int lastRowSelected = -1;
632 bool multipleSelection = false, alwaysFlipSelection = false, hasDoneInitialUpdate = false, selectOnMouseDown = true;
633
634 #if ! JUCE_DISABLE_ASSERTIONS
636 #endif
637
638 void assignModelPtr (ListBoxModel*);
639 void checkModelPtrIsValid() const;
640 bool hasAccessibleHeaderComponent() const;
641 void selectRowInternal (int rowNumber, bool dontScrollToShowThisRow,
642 bool deselectOthersFirst, bool isMouseClick);
643
645};
646
647} // namespace juce
Base class for accessible Components.
The base class for all JUCE user-interface objects.
A graphics context, used for drawing a component or image.
Represents a key press, including any modifier keys that are needed.
A subclass of this is used to drive a ListBox.
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 int getNumRows()=0
This has to return the number of items in the list.
virtual bool mayDragToExternalWindows() const
Called when starting a drag operation on a list row to determine whether the item may be dragged to o...
virtual ~ListBoxModel()=default
Destructor.
A list of items that can be scrolled vertically.
ColourIds
A set of colour IDs to use to change the colour of various aspects of the label.
int getOutlineThickness() const noexcept
Returns the thickness of outline that will be drawn around the listbox.
bool getRowSelectedOnMouseDown() const
Gets whether a row should be selected when the mouse is pressed or released.
ListBoxModel * getListBoxModel() const noexcept
Returns the current list model.
Component * getHeaderComponent() const noexcept
Returns whatever header component was set with setHeaderComponent().
Represents the state of the mouse buttons and modifier keys.
Represents a mouse cursor image.
Contains position and status information about a mouse event.
Manages a rectangle and allows geometric operations to be performed on it.
An image that will be resampled before it is drawn.
A scrollbar component.
An implementation of TooltipClient that stores the tooltip string and a method for changing it.
Holds a set of primitive values, storing them as a set of ranges.
The JUCE String class!
Definition juce_String.h:53
A Viewport is used to contain a larger child component, and allows the child to be automatically scro...
A variant class, that can be used to hold a range of primitive values.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
Contains status information about a mouse wheel event.