openshot-audio  0.1.7
juce_TableHeaderComponent.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_TABLEHEADERCOMPONENT_H_INCLUDED
26 #define JUCE_TABLEHEADERCOMPONENT_H_INCLUDED
27 
28 
29 //==============================================================================
44  private AsyncUpdater
45 {
46 public:
47  //==============================================================================
51 
54 
55  //==============================================================================
60  {
61  visible = 1,
62  resizable = 2,
63  draggable = 4,
64  appearsOnColumnMenu = 8,
65  sortable = 16,
66  sortedForwards = 32,
67  sortedBackwards = 64,
70  defaultFlags = (visible | resizable | draggable | appearsOnColumnMenu | sortable),
71 
73  notResizable = (visible | draggable | appearsOnColumnMenu | sortable),
74 
76  notResizableOrSortable = (visible | draggable | appearsOnColumnMenu),
77 
79  notSortable = (visible | resizable | draggable | appearsOnColumnMenu)
80  };
81 
102  void addColumn (const String& columnName,
103  int columnId,
104  int width,
105  int minimumWidth = 30,
106  int maximumWidth = -1,
107  int propertyFlags = defaultFlags,
108  int insertIndex = -1);
109 
115  void removeColumn (int columnIdToRemove);
116 
122  void removeAllColumns();
123 
131  int getNumColumns (bool onlyCountVisibleColumns) const;
132 
136  String getColumnName (int columnId) const;
137 
139  void setColumnName (int columnId, const String& newName);
140 
146  void moveColumn (int columnId, int newVisibleIndex);
147 
150  int getColumnWidth (int columnId) const;
151 
156  void setColumnWidth (int columnId, int newWidth);
157 
163  void setColumnVisible (int columnId, bool shouldBeVisible);
164 
168  bool isColumnVisible (int columnId) const;
169 
179  void setSortColumnId (int columnId, bool sortForwards);
180 
185  int getSortColumnId() const;
186 
190  bool isSortedForwards() const;
191 
200  void reSortTable();
201 
202  //==============================================================================
205  int getTotalWidth() const;
206 
214  int getIndexOfColumnId (int columnId, bool onlyCountVisibleColumns) const;
215 
223  int getColumnIdOfIndex (int index, bool onlyCountVisibleColumns) const;
224 
231  Rectangle<int> getColumnPosition (int index) const;
232 
236  int getColumnIdAtX (int xToFind) const;
237 
244  void setStretchToFitActive (bool shouldStretchToFit);
245 
249  bool isStretchToFitActive() const;
250 
257  void resizeAllColumnsToFit (int targetTotalWidth);
258 
259  //==============================================================================
269  void setPopupMenuActive (bool hasMenu);
270 
274  bool isPopupMenuActive() const;
275 
276  //==============================================================================
284  String toString() const;
285 
291  void restoreFromString (const String& storedVersion);
292 
293  //==============================================================================
303  {
304  public:
305  //==============================================================================
306  Listener() {}
307 
309  virtual ~Listener() {}
310 
311  //==============================================================================
315  virtual void tableColumnsChanged (TableHeaderComponent* tableHeader) = 0;
316 
318  virtual void tableColumnsResized (TableHeaderComponent* tableHeader) = 0;
319 
321  virtual void tableSortOrderChanged (TableHeaderComponent* tableHeader) = 0;
322 
328  virtual void tableColumnDraggingChanged (TableHeaderComponent* tableHeader,
329  int columnIdNowBeingDragged);
330  };
331 
333  void addListener (Listener* newListener);
334 
336  void removeListener (Listener* listenerToRemove);
337 
338  //==============================================================================
344  virtual void columnClicked (int columnId, const ModifierKeys& mods);
345 
355  virtual void addMenuItems (PopupMenu& menu, int columnIdClicked);
356 
366  virtual void reactToMenuItem (int menuReturnId, int columnIdClicked);
367 
368  //==============================================================================
371  {
372  virtual ~LookAndFeelMethods() {}
373 
374  virtual void drawTableHeaderBackground (Graphics&, TableHeaderComponent&) = 0;
375 
376  virtual void drawTableHeaderColumn (Graphics&, const String& columnName, int columnId,
377  int width, int height,
378  bool isMouseOver, bool isMouseDown, int columnFlags) = 0;
379  };
380 
381  //==============================================================================
383  void paint (Graphics&) override;
385  void resized() override;
387  void mouseMove (const MouseEvent&) override;
389  void mouseEnter (const MouseEvent&) override;
391  void mouseExit (const MouseEvent&) override;
393  void mouseDown (const MouseEvent&) override;
395  void mouseDrag (const MouseEvent&) override;
397  void mouseUp (const MouseEvent&) override;
399  MouseCursor getMouseCursor() override;
400 
402  virtual void showColumnChooserMenu (int columnIdClicked);
403 
404 private:
405  struct ColumnInfo
406  {
407  String name;
408  int id, propertyFlags, width, minimumWidth, maximumWidth;
409  double lastDeliberateWidth;
410 
411  bool isVisible() const;
412  };
413 
414  OwnedArray<ColumnInfo> columns;
415  Array<Listener*> listeners;
416  ScopedPointer<Component> dragOverlayComp;
417  class DragOverlayComp;
418 
419  bool columnsChanged, columnsResized, sortChanged, menuActive, stretchToFit;
420  int columnIdBeingResized, columnIdBeingDragged, initialColumnWidth;
421  int columnIdUnderMouse, draggingColumnOffset, draggingColumnOriginalIndex, lastDeliberateWidth;
422 
423  ColumnInfo* getInfoForId (int columnId) const;
424  int visibleIndexToTotalIndex (int visibleIndex) const;
425  void sendColumnsChanged();
426  void handleAsyncUpdate() override;
427  void beginDrag (const MouseEvent&);
428  void endDrag (int finalIndex);
429  int getResizeDraggerAt (int mouseX) const;
430  void updateColumnUnderMouse (const MouseEvent&);
431  void setColumnUnderMouse (int columnId);
432  void resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth);
433 
435 };
436 
439 
440 
441 #endif // JUCE_TABLEHEADERCOMPONENT_H_INCLUDED
Definition: juce_TableHeaderComponent.h:370
Definition: juce_MouseCursor.h:36
Definition: juce_PopupMenu.h:77
Definition: juce_ModifierKeys.h:38
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_AsyncUpdater.h:39
virtual ~Listener()
Definition: juce_TableHeaderComponent.h:309
Definition: juce_Rectangle.h:36
Definition: juce_TableHeaderComponent.h:43
Definition: juce_Component.h:33
png_const_structrp png_const_inforp int png_fixed_point * width
Definition: juce_PNGLoader.cpp:2339
Definition: juce_Array.h:60
Definition: juce_OwnedArray.h:55
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_GraphicsContext.h:42
Listener()
Definition: juce_TableHeaderComponent.h:306
Definition: juce_TableHeaderComponent.h:302
virtual ~LookAndFeelMethods()
Definition: juce_TableHeaderComponent.h:372
ColumnPropertyFlags
Definition: juce_TableHeaderComponent.h:59
Definition: juce_MouseEvent.h:36
TableHeaderComponent::Listener TableHeaderListener
Definition: juce_TableHeaderComponent.h:438