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_TableHeaderComponent.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//==============================================================================
45class JUCE_API TableHeaderComponent : public Component,
46 private AsyncUpdater
47{
48public:
49 //==============================================================================
53
55 ~TableHeaderComponent() override;
56
57 //==============================================================================
62 {
63 visible = 1,
64 resizable = 2,
65 draggable = 4,
66 appearsOnColumnMenu = 8,
67 sortable = 16,
68 sortedForwards = 32,
69 sortedBackwards = 64,
72 defaultFlags = (visible | resizable | draggable | appearsOnColumnMenu | sortable),
73
75 notResizable = (visible | draggable | appearsOnColumnMenu | sortable),
76
78 notResizableOrSortable = (visible | draggable | appearsOnColumnMenu),
79
81 notSortable = (visible | resizable | draggable | appearsOnColumnMenu)
82 };
83
104 void addColumn (const String& columnName,
105 int columnId,
106 int width,
107 int minimumWidth = 30,
108 int maximumWidth = -1,
109 int propertyFlags = defaultFlags,
110 int insertIndex = -1);
111
117 void removeColumn (int columnIdToRemove);
118
124 void removeAllColumns();
125
133 int getNumColumns (bool onlyCountVisibleColumns) const;
134
138 String getColumnName (int columnId) const;
139
141 void setColumnName (int columnId, const String& newName);
142
148 void moveColumn (int columnId, int newVisibleIndex);
149
152 int getColumnWidth (int columnId) const;
153
158 void setColumnWidth (int columnId, int newWidth);
159
165 void setColumnVisible (int columnId, bool shouldBeVisible);
166
170 bool isColumnVisible (int columnId) const;
171
181 void setSortColumnId (int columnId, bool sortForwards);
182
187 int getSortColumnId() const;
188
192 bool isSortedForwards() const;
193
202 void reSortTable();
203
204 //==============================================================================
207 int getTotalWidth() const;
208
216 int getIndexOfColumnId (int columnId, bool onlyCountVisibleColumns) const;
217
225 int getColumnIdOfIndex (int index, bool onlyCountVisibleColumns) const;
226
233 Rectangle<int> getColumnPosition (int index) const;
234
238 int getColumnIdAtX (int xToFind) const;
239
246 void setStretchToFitActive (bool shouldStretchToFit);
247
251 bool isStretchToFitActive() const;
252
259 void resizeAllColumnsToFit (int targetTotalWidth);
260
261 //==============================================================================
271 void setPopupMenuActive (bool hasMenu);
272
276 bool isPopupMenuActive() const;
277
278 //==============================================================================
286 String toString() const;
287
293 void restoreFromString (const String& storedVersion);
294
295 //==============================================================================
304 class JUCE_API Listener
305 {
306 public:
307 //==============================================================================
308 Listener() = default;
309
311 virtual ~Listener() = default;
312
313 //==============================================================================
317 virtual void tableColumnsChanged (TableHeaderComponent* tableHeader) = 0;
318
320 virtual void tableColumnsResized (TableHeaderComponent* tableHeader) = 0;
321
323 virtual void tableSortOrderChanged (TableHeaderComponent* tableHeader) = 0;
324
330 virtual void tableColumnDraggingChanged (TableHeaderComponent* tableHeader,
331 int columnIdNowBeingDragged);
332 };
333
335 void addListener (Listener* newListener);
336
338 void removeListener (Listener* listenerToRemove);
339
340 //==============================================================================
346 virtual void columnClicked (int columnId, const ModifierKeys& mods);
347
357 virtual void addMenuItems (PopupMenu& menu, int columnIdClicked);
358
368 virtual void reactToMenuItem (int menuReturnId, int columnIdClicked);
369
370 //==============================================================================
376 {
377 textColourId = 0x1003800,
378 backgroundColourId = 0x1003810,
380 outlineColourId = 0x1003820,
381 highlightColourId = 0x1003830,
386 };
387
388 //==============================================================================
390 struct JUCE_API LookAndFeelMethods
391 {
392 virtual ~LookAndFeelMethods() = default;
393
394 virtual void drawTableHeaderBackground (Graphics&, TableHeaderComponent&) = 0;
395
396 virtual void drawTableHeaderColumn (Graphics&, TableHeaderComponent&,
397 const String& columnName, int columnId,
398 int width, int height,
399 bool isMouseOver, bool isMouseDown, int columnFlags) = 0;
400 };
401
402 //==============================================================================
404 void paint (Graphics&) override;
406 void resized() override;
408 void mouseMove (const MouseEvent&) override;
410 void mouseEnter (const MouseEvent&) override;
412 void mouseExit (const MouseEvent&) override;
414 void mouseDown (const MouseEvent&) override;
416 void mouseDrag (const MouseEvent&) override;
418 void mouseUp (const MouseEvent&) override;
420 MouseCursor getMouseCursor() override;
422 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
423
425 virtual void showColumnChooserMenu (int columnIdClicked);
426
427private:
428 struct ColumnInfo : public Component
429 {
430 ColumnInfo() { setInterceptsMouseClicks (false, false); }
431 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
432
433 int id, propertyFlags, width, minimumWidth, maximumWidth;
434 double lastDeliberateWidth;
435 };
436
437 OwnedArray<ColumnInfo> columns;
438 Array<Listener*> listeners;
439 std::unique_ptr<Component> dragOverlayComp;
440 class DragOverlayComp;
441
442 bool columnsChanged = false, columnsResized = false, sortChanged = false;
443 bool menuActive = true, stretchToFit = false;
444 int columnIdBeingResized = 0, columnIdBeingDragged = 0, initialColumnWidth = 0;
445 int columnIdUnderMouse = 0, draggingColumnOffset = 0, draggingColumnOriginalIndex = 0, lastDeliberateWidth = 0;
446
447 ColumnInfo* getInfoForId (int columnId) const;
448 int visibleIndexToTotalIndex (int visibleIndex) const;
449 void sendColumnsChanged();
450 void handleAsyncUpdate() override;
451 void beginDrag (const MouseEvent&);
452 void endDrag (int finalIndex);
453 int getResizeDraggerAt (int mouseX) const;
454 void updateColumnUnderMouse (const MouseEvent&);
455 void setColumnUnderMouse (int columnId);
456 void resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth);
457 void drawColumnHeader (Graphics&, LookAndFeel&, const ColumnInfo&);
458
460};
461
462
463} // namespace juce
Has a callback method that is triggered asynchronously.
The base class for all JUCE user-interface objects.
A graphics context, used for drawing a component or image.
Represents the state of the mouse buttons and modifier keys.
Represents a mouse cursor image.
Contains position and status information about a mouse event.
Creates and displays a popup-menu.
Manages a rectangle and allows geometric operations to be performed on it.
The JUCE String class!
Definition juce_String.h:53
Receives events from a TableHeaderComponent when columns are resized, moved, etc.
virtual void tableSortOrderChanged(TableHeaderComponent *tableHeader)=0
This is called when the column by which the table should be sorted is changed.
virtual void tableColumnsChanged(TableHeaderComponent *tableHeader)=0
This is called when some of the table's columns are added, removed, hidden, or rearranged.
virtual void tableColumnsResized(TableHeaderComponent *tableHeader)=0
This is called when one or more of the table's columns are resized.
virtual ~Listener()=default
Destructor.
A component that displays a strip of column headings for a table, and allows these to be resized,...
ColourIds
A set of colour IDs to use to change the colour of various aspects of the TableHeaderComponent.
ColumnPropertyFlags
A combination of these flags are passed into the addColumn() method to specify the properties of a co...
#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.
This abstract base class is implemented by LookAndFeel classes.