LMMS
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//==============================================================================
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 String getTooltipForRow (int row);
163
165 virtual MouseCursor getMouseCursorForRow (int row);
166
167private:
168 #if ! JUCE_DISABLE_ASSERTIONS
169 friend class ListBox;
170 struct Empty {};
171 std::shared_ptr<Empty> sharedState = std::make_shared<Empty>();
172 #endif
173};
174
175//==============================================================================
189{
190public:
191 //==============================================================================
203 ListBoxModel* model = nullptr);
204
206 ~ListBox() override;
207
208 //==============================================================================
216 void setModel (ListBoxModel* newModel);
217
220 {
221 #if ! JUCE_DISABLE_ASSERTIONS
223 #endif
224
225 return model;
226 }
227
228 //==============================================================================
236 void updateContent();
237
238 //==============================================================================
248 void setMultipleSelectionEnabled (bool shouldBeEnabled) noexcept;
249
257 void setClickingTogglesRowSelection (bool flipRowSelection) noexcept;
258
262 void setRowSelectedOnMouseDown (bool isSelectedOnMouseDown) noexcept;
263
269 void setMouseMoveSelectsRows (bool shouldSelect);
270
271 //==============================================================================
285 void selectRow (int rowNumber,
286 bool dontScrollToShowThisRow = false,
287 bool deselectOthersFirst = true);
288
300 void selectRangeOfRows (int firstRow,
301 int lastRow,
302 bool dontScrollToShowThisRange = false);
303
308 void deselectRow (int rowNumber);
309
313 void deselectAllRows();
314
318 void flipRowSelection (int rowNumber);
319
323 SparseSet<int> getSelectedRows() const;
324
332 void setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
333 NotificationType sendNotificationEventToModel = sendNotification);
334
337 bool isRowSelected (int rowNumber) const;
338
342 int getNumSelectedRows() const;
343
354 int getSelectedRow (int index = 0) const;
355
363 int getLastRowSelected() const;
364
378 void selectRowsBasedOnModifierKeys (int rowThatWasClickedOn,
379 ModifierKeys modifiers,
380 bool isMouseUpEvent);
381
382 //==============================================================================
393 void setVerticalPosition (double newProportion);
394
402 double getVerticalPosition() const;
403
405 void scrollToEnsureRowIsOnscreen (int row);
406
408 ScrollBar& getVerticalScrollBar() const noexcept;
409
411 ScrollBar& getHorizontalScrollBar() const noexcept;
412
418 int getRowContainingPosition (int x, int y) const noexcept;
419
433 int getInsertionIndexForPosition (int x, int y) const noexcept;
434
441 Rectangle<int> getRowPosition (int rowNumber,
442 bool relativeToComponentTopLeft) const noexcept;
443
453 Component* getComponentForRowNumber (int rowNumber) const noexcept;
454
458 int getRowNumberOfComponent (Component* rowComponent) const noexcept;
459
463 int getVisibleRowWidth() const noexcept;
464
465 //==============================================================================
470 void setRowHeight (int newHeight);
471
476
482 int getNumRowsOnScreen() const noexcept;
483
484 //==============================================================================
493 {
494 backgroundColourId = 0x1002800,
496 outlineColourId = 0x1002810,
498 textColourId = 0x1002820
499 };
500
506 void setOutlineThickness (int outlineThickness);
507
512
522 void setHeaderComponent (std::unique_ptr<Component> newHeaderComponent);
523
526
537 void setMinimumContentWidth (int newMinimumWidth);
538
542 int getVisibleContentWidth() const noexcept;
543
549 void repaintRow (int rowNumber) noexcept;
550
563 virtual ScaledImage createSnapshotOfRows (const SparseSet<int>& rows, int& x, int& y);
564
570 Viewport* getViewport() const noexcept;
571
572 //==============================================================================
574 bool keyPressed (const KeyPress&) override;
576 bool keyStateChanged (bool isKeyDown) override;
578 void paint (Graphics&) override;
580 void paintOverChildren (Graphics&) override;
582 void resized() override;
584 void visibilityChanged() override;
586 void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
588 void mouseUp (const MouseEvent&) override;
590 void colourChanged() override;
592 void parentHierarchyChanged() override;
594 void startDragAndDrop (const MouseEvent&, const SparseSet<int>& rowsToDrag,
595 const var& dragDescription, bool allowDraggingToOtherWindows);
596
597 //==============================================================================
598 #ifndef DOXYGEN
599 [[deprecated ("This method's bool parameter has changed: see the new method signature.")]]
600 void setSelectedRows (const SparseSet<int>&, bool);
601 #endif
602
603private:
604 //==============================================================================
607 friend class ListViewport;
608 friend class TableListBox;
609 ListBoxModel* model = nullptr;
618
619 #if ! JUCE_DISABLE_ASSERTIONS
620 std::weak_ptr<ListBoxModel::Empty> weakModelPtr;
621 #endif
622
624 void checkModelPtrIsValid() const;
625 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
626 bool hasAccessibleHeaderComponent() const;
627 void selectRowInternal (int rowNumber, bool dontScrollToShowThisRow,
628 bool deselectOthersFirst, bool isMouseClick);
629
631};
632
633} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
#define override
Definition DistrhoDefines.h:73
Definition juce_Component.h:36
String componentName
Definition juce_Component.h:2534
Component() noexcept
Definition juce_Component.cpp:517
Definition juce_GraphicsContext.h:45
Definition juce_KeyPress.h:40
Definition juce_ListBox.cpp:291
Definition juce_ListBox.cpp:69
bool multipleSelection
Definition juce_ListBox.h:617
ListBox(const String &componentName=String(), ListBoxModel *model=nullptr)
Definition juce_ListBox.cpp:528
int rowHeight
Definition juce_ListBox.h:614
std::unique_ptr< Component > headerComponent
Definition juce_ListBox.h:611
SparseSet< int > selected
Definition juce_ListBox.h:613
friend class TableListBox
Definition juce_ListBox.h:608
bool alwaysFlipSelection
Definition juce_ListBox.h:617
std::unique_ptr< MouseListener > mouseMoveSelector
Definition juce_ListBox.h:612
ListBoxModel * getModel() const noexcept
Definition juce_ListBox.h:219
void selectRowInternal(int rowNumber, bool dontScrollToShowThisRow, bool deselectOthersFirst, bool isMouseClick)
Definition juce_ListBox.cpp:656
bool hasDoneInitialUpdate
Definition juce_ListBox.h:617
ListBoxModel * model
Definition juce_ListBox.h:609
void checkModelPtrIsValid() const
Definition juce_ListBox.cpp:54
void setModel(ListBoxModel *newModel)
Definition juce_ListBox.cpp:556
bool selectOnMouseDown
Definition juce_ListBox.h:617
ColourIds
Definition juce_ListBox.h:493
@ textColourId
Definition juce_ListBox.h:498
@ backgroundColourId
Definition juce_ListBox.h:494
@ outlineColourId
Definition juce_ListBox.h:496
int lastRowSelected
Definition juce_ListBox.h:616
int minimumRowWidth
Definition juce_ListBox.h:614
bool hasAccessibleHeaderComponent() const
Definition juce_ListBox.cpp:1061
int getOutlineThickness() const noexcept
Definition juce_ListBox.h:511
int outlineThickness
Definition juce_ListBox.h:615
std::unique_ptr< ListViewport > viewport
Definition juce_ListBox.h:610
void setSelectedRows(const SparseSet< int > &, bool)
Component * getHeaderComponent() const noexcept
Definition juce_ListBox.h:525
int getRowHeight() const noexcept
Definition juce_ListBox.h:475
int totalItems
Definition juce_ListBox.h:614
void assignModelPtr(ListBoxModel *)
Definition juce_ListBox.cpp:547
std::weak_ptr< ListBoxModel::Empty > weakModelPtr
Definition juce_ListBox.h:620
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_ListBox.cpp:1144
Definition juce_ListBox.h:38
virtual void deleteKeyPressed(int lastRowSelected)
Definition juce_ListBox.cpp:1223
virtual void returnKeyPressed(int lastRowSelected)
Definition juce_ListBox.cpp:1224
virtual Component * refreshComponentForRow(int rowNumber, bool isRowSelected, Component *existingComponentToUpdate)
Definition juce_ListBox.cpp:1211
virtual void paintListBoxItem(int rowNumber, Graphics &g, int width, int height, bool rowIsSelected)=0
friend class ListBox
Definition juce_ListBox.h:169
virtual void listBoxItemDoubleClicked(int row, const MouseEvent &)
Definition juce_ListBox.cpp:1220
virtual String getTooltipForRow(int row)
Definition juce_ListBox.cpp:1227
virtual var getDragSourceDescription(const SparseSet< int > &rowsToDescribe)
Definition juce_ListBox.cpp:1226
virtual int getNumRows()=0
virtual void listBoxItemClicked(int row, const MouseEvent &)
Definition juce_ListBox.cpp:1219
std::shared_ptr< Empty > sharedState
Definition juce_ListBox.h:171
virtual void listWasScrolled()
Definition juce_ListBox.cpp:1225
virtual ~ListBoxModel()=default
virtual String getNameForRow(int rowNumber)
Definition juce_ListBox.cpp:1218
virtual void backgroundClicked(const MouseEvent &)
Definition juce_ListBox.cpp:1221
virtual MouseCursor getMouseCursorForRow(int row)
Definition juce_ListBox.cpp:1228
virtual void selectedRowsChanged(int lastRowSelected)
Definition juce_ListBox.cpp:1222
Definition juce_ModifierKeys.h:41
Definition juce_MouseCursor.h:39
Definition juce_MouseEvent.h:39
Definition juce_MouseListener.h:39
Definition juce_Rectangle.h:67
Definition juce_ScaledImage.h:45
Definition juce_ScrollBar.h:54
Definition juce_SparseSet.h:41
Definition juce_String.h:53
Definition juce_Viewport.h:47
Definition juce_Variant.h:42
int y
Definition inflate.c:1588
int g
Definition inflate.c:1573
unsigned x[BMAX+1]
Definition inflate.c:1586
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
#define JUCE_PUBLIC_IN_DLL_BUILD(declaration)
Definition juce_StandardHeader.h:158
Definition carla_juce.cpp:31
NotificationType
Definition juce_NotificationType.h:32
@ sendNotification
Definition juce_NotificationType.h:34
Definition juce_Uuid.h:141
#define true
Definition ordinals.h:82
#define false
Definition ordinals.h:83
Definition juce_ListBox.h:170
Definition juce_MouseEvent.h:392
#define const
Definition zconf.h:137