openshot-audio  0.1.2
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_LISTBOX_H_INCLUDED
26 #define JUCE_LISTBOX_H_INCLUDED
27 
28 
29 //==============================================================================
36 {
37 public:
38  //==============================================================================
40  virtual ~ListBoxModel() {}
41 
42  //==============================================================================
46  virtual int getNumRows() = 0;
47 
52  virtual void paintListBoxItem (int rowNumber,
53  Graphics& g,
54  int width, int height,
55  bool rowIsSelected) = 0;
56 
84  virtual Component* refreshComponentForRow (int rowNumber, bool isRowSelected,
85  Component* existingComponentToUpdate);
86 
90  virtual void listBoxItemClicked (int row, const MouseEvent&);
91 
95  virtual void listBoxItemDoubleClicked (int row, const MouseEvent&);
96 
101  virtual void backgroundClicked (const MouseEvent&);
102 
111  virtual void selectedRowsChanged (int lastRowSelected);
112 
121  virtual void deleteKeyPressed (int lastRowSelected);
122 
131  virtual void returnKeyPressed (int lastRowSelected);
132 
138  virtual void listWasScrolled();
139 
149  virtual var getDragSourceDescription (const SparseSet<int>& rowsToDescribe);
150 
154  virtual String getTooltipForRow (int row);
155 
157  virtual MouseCursor getMouseCursorForRow (int row);
158 
159 private:
160  #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
161  // This method's signature has changed to take a MouseEvent parameter - please update your code!
162  JUCE_DEPRECATED_WITH_BODY (virtual int backgroundClicked(), { return 0; })
163  #endif
164 };
165 
166 
167 //==============================================================================
177 class JUCE_API ListBox : public Component,
178  public SettableTooltipClient
179 {
180 public:
181  //==============================================================================
187  ListBox (const String& componentName = String::empty,
188  ListBoxModel* model = nullptr);
189 
191  ~ListBox();
192 
193 
194  //==============================================================================
196  void setModel (ListBoxModel* newModel);
197 
199  ListBoxModel* getModel() const noexcept { return model; }
200 
201 
202  //==============================================================================
210  void updateContent();
211 
212  //==============================================================================
222  void setMultipleSelectionEnabled (bool shouldBeEnabled) noexcept;
223 
231  void setClickingTogglesRowSelection (bool flipRowSelection) noexcept;
232 
236  void setRowSelectedOnMouseDown (bool isSelectedOnMouseDown) noexcept;
237 
243  void setMouseMoveSelectsRows (bool shouldSelect);
244 
245  //==============================================================================
259  void selectRow (int rowNumber,
260  bool dontScrollToShowThisRow = false,
261  bool deselectOthersFirst = true);
262 
271  void selectRangeOfRows (int firstRow,
272  int lastRow);
273 
278  void deselectRow (int rowNumber);
279 
283  void deselectAllRows();
284 
288  void flipRowSelection (int rowNumber);
289 
293  SparseSet<int> getSelectedRows() const;
294 
302  void setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
303  NotificationType sendNotificationEventToModel = sendNotification);
304 
307  bool isRowSelected (int rowNumber) const;
308 
312  int getNumSelectedRows() const;
313 
324  int getSelectedRow (int index = 0) const;
325 
333  int getLastRowSelected() const;
334 
348  void selectRowsBasedOnModifierKeys (int rowThatWasClickedOn,
349  ModifierKeys modifiers,
350  bool isMouseUpEvent);
351 
352  //==============================================================================
363  void setVerticalPosition (double newProportion);
364 
372  double getVerticalPosition() const;
373 
375  void scrollToEnsureRowIsOnscreen (int row);
376 
378  ScrollBar* getVerticalScrollBar() const noexcept;
379 
381  ScrollBar* getHorizontalScrollBar() const noexcept;
382 
388  int getRowContainingPosition (int x, int y) const noexcept;
389 
403  int getInsertionIndexForPosition (int x, int y) const noexcept;
404 
411  Rectangle<int> getRowPosition (int rowNumber,
412  bool relativeToComponentTopLeft) const noexcept;
413 
423  Component* getComponentForRowNumber (int rowNumber) const noexcept;
424 
428  int getRowNumberOfComponent (Component* rowComponent) const noexcept;
429 
433  int getVisibleRowWidth() const noexcept;
434 
435  //==============================================================================
440  void setRowHeight (int newHeight);
441 
445  int getRowHeight() const noexcept { return rowHeight; }
446 
452  int getNumRowsOnScreen() const noexcept;
453 
454  //==============================================================================
463  {
464  backgroundColourId = 0x1002800,
466  outlineColourId = 0x1002810,
468  textColourId = 0x1002820
469  };
470 
476  void setOutlineThickness (int outlineThickness);
477 
481  int getOutlineThickness() const noexcept { return outlineThickness; }
482 
492  void setHeaderComponent (Component* newHeaderComponent);
493 
495  Component* getHeaderComponent() const noexcept { return headerComponent; }
496 
507  void setMinimumContentWidth (int newMinimumWidth);
508 
512  int getVisibleContentWidth() const noexcept;
513 
519  void repaintRow (int rowNumber) noexcept;
520 
533  virtual Image createSnapshotOfRows (const SparseSet<int>& rows, int& x, int& y);
534 
540  Viewport* getViewport() const noexcept;
541 
542  //==============================================================================
544  bool keyPressed (const KeyPress&) override;
546  bool keyStateChanged (bool isKeyDown) override;
548  void paint (Graphics&) override;
550  void paintOverChildren (Graphics&) override;
552  void resized() override;
554  void visibilityChanged() override;
556  void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
558  void mouseUp (const MouseEvent&) override;
560  void colourChanged() override;
562  void parentHierarchyChanged() override;
564  void startDragAndDrop (const MouseEvent&, const SparseSet<int>& rowsToDrag,
565  const var& dragDescription, bool allowDraggingToOtherWindows);
566 
567 private:
568  //==============================================================================
571  friend class ListViewport;
572  friend class TableListBox;
573  ListBoxModel* model;
574  ScopedPointer<ListViewport> viewport;
575  ScopedPointer<Component> headerComponent;
576  ScopedPointer<MouseListener> mouseMoveSelector;
577  int totalItems, rowHeight, minimumRowWidth;
578  int outlineThickness;
579  int lastRowSelected;
580  bool multipleSelection, alwaysFlipSelection, hasDoneInitialUpdate, selectOnMouseDown;
581  SparseSet<int> selected;
582 
583  void selectRowInternal (int rowNumber, bool dontScrollToShowThisRow,
584  bool deselectOthersFirst, bool isMouseClick);
585 
586  #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
587  // This method's bool parameter has changed: see the new method signature.
588  JUCE_DEPRECATED (void setSelectedRows (const SparseSet<int>&, bool));
589  // This method has been replaced by the more flexible method createSnapshotOfRows.
590  // Please call createSnapshotOfRows (getSelectedRows(), x, y) to get the same behaviour.
591  JUCE_DEPRECATED (virtual void createSnapshotOfSelectedRows (int&, int&)) {}
592  #endif
593 
595 };
596 
597 
598 #endif // JUCE_LISTBOX_H_INCLUDED
Definition: juce_Variant.h:46
Definition: juce_ListBox.cpp:25
int getOutlineThickness() const noexcept
Definition: juce_ListBox.h:481
Definition: juce_TableListBox.h:206
Definition: juce_KeyPress.h:37
Definition: juce_MouseCursor.h:36
virtual ~ListBoxModel()
Definition: juce_ListBox.h:40
static const String empty
Definition: juce_String.h:152
Definition: juce_ListBox.h:177
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_ScrollBar.h:49
Definition: juce_ModifierKeys.h:38
virtual void mouseWheelMove(const MouseEvent &event, const MouseWheelDetails &wheel) override
Definition: juce_Component.cpp:2257
Definition: juce_ListBox.cpp:156
Definition: juce_String.h:43
virtual void paintOverChildren(Graphics &g)
Definition: juce_Component.cpp:1936
#define JUCE_API
Definition: juce_StandardHeader.h:139
#define JUCE_PUBLIC_IN_DLL_BUILD(declaration)
Definition: juce_StandardHeader.h:145
Definition: juce_Rectangle.h:36
ListBoxModel * getModel() const noexcept
Definition: juce_ListBox.h:199
virtual void resized()
Definition: juce_Component.cpp:2272
NotificationType
Definition: juce_NotificationType.h:33
Definition: juce_TooltipClient.h:63
virtual bool keyStateChanged(bool isKeyDown)
Definition: juce_Component.cpp:3005
virtual void colourChanged()
Definition: juce_Component.cpp:2139
ColourIds
Definition: juce_ListBox.h:462
virtual void paint(Graphics &g)
Definition: juce_Component.cpp:1929
Definition: juce_Component.h:33
Definition: juce_ScopedPointer.h:70
Definition: juce_MouseEvent.h:329
Definition: juce_MouseListener.h:36
int getRowHeight() const noexcept
Definition: juce_ListBox.h:445
virtual void parentHierarchyChanged()
Definition: juce_Component.cpp:1646
virtual void mouseUp(const MouseEvent &event) override
Definition: juce_Component.cpp:2252
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_GraphicsContext.h:42
Definition: juce_Image.h:54
Definition: juce_Viewport.h:42
JUCE_DEPRECATED(Point< int > relativePositionToGlobal(Point< int >) const)
Definition: juce_NotificationType.h:36
virtual void visibilityChanged()
Definition: juce_Component.cpp:559
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body)
Definition: juce_PlatformDefs.h:320
Definition: juce_MouseEvent.h:36
Component * getHeaderComponent() const noexcept
Definition: juce_ListBox.h:495
Definition: juce_ListBox.h:35
virtual bool keyPressed(const KeyPress &key)
Definition: juce_Component.cpp:3004