58 dragOverlayComp.reset();
77 for (
auto* c : columns)
84 return columns.
size();
90 return ci->getTitle();
99 if (
ci->getTitle() != newName)
101 ci->setTitle (newName);
102 sendColumnsChanged();
119 auto ci =
new ColumnInfo();
123 ci->lastDeliberateWidth = width;
124 ci->minimumWidth = minimumWidth;
127 ci->propertyFlags = propertyFlags;
134 sendColumnsChanged();
145 sendColumnsChanged();
151 if (columns.
size() > 0)
154 sendColumnsChanged();
166 sendColumnsChanged();
198 if (lastDeliberateWidth == 0)
201 resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
207 columnsResized =
true;
218 for (
auto* c : columns)
235 index = visibleIndexToTotalIndex (index);
237 if (
auto*
ci = columns [index])
245 int x = 0, width = 0, n = 0;
247 for (
auto* c : columns)
273 for (
auto*
ci : columns)
292 for (
auto* c : columns)
314 && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
331 sor.addItem (
ci->lastDeliberateWidth,
ci->minimumWidth,
ci->maximumWidth);
351 columnsResized =
true;
365 sendColumnsChanged();
374 return ci->isVisible();
384 for (
auto* c : columns)
396 for (
auto* c : columns)
405 for (
auto* c : columns)
430 for (
auto*
ci : columns)
432 auto* e =
doc.createNewChildElement (
"COLUMN");
433 e->setAttribute (
"id",
ci->id);
434 e->setAttribute (
"visible",
ci->isVisible());
435 e->setAttribute (
"width",
ci->width);
449 auto tabId =
col->getIntAttribute (
"id");
451 if (
auto*
ci = getInfoForId (
tabId))
454 ci->width =
col->getIntAttribute (
"width");
461 columnsResized =
true;
462 sendColumnsChanged();
465 storedXML->getBoolAttribute (
"sortForwards",
true));
490 for (
auto*
ci : columns)
492 menu.addItem (
ci->id,
ci->getTitle(),
506 if (!
ci.isVisible())
510 if (
ci.id == columnIdBeingDragged && dragOverlayComp !=
nullptr && dragOverlayComp->isVisible())
525 ci.id == columnIdUnderMouse,
534 lf.drawTableHeaderBackground (g, *
this);
536 for (
auto*
ci : columns)
537 drawColumnHeader (g,
lf, *
ci);
544 for (
auto*
ci : columns)
560 columnIdBeingResized = 0;
561 columnIdBeingDragged = 0;
563 if (columnIdUnderMouse != 0)
577 if (columnIdBeingResized == 0
578 && columnIdBeingDragged == 0
582 dragOverlayComp.reset();
584 columnIdBeingResized = getResizeDraggerAt (e.
getMouseDownX());
586 if (columnIdBeingResized != 0)
588 if (
auto*
ci = getInfoForId (columnIdBeingResized))
589 initialColumnWidth =
ci->width;
599 if (columnIdBeingResized != 0)
601 if (
auto*
ci = getInfoForId (columnIdBeingResized))
603 auto w =
jlimit (
ci->minimumWidth,
ci->maximumWidth,
622 else if (columnIdBeingDragged != 0)
626 if (dragOverlayComp !=
nullptr)
628 dragOverlayComp->setVisible (
true);
629 dragOverlayComp->setBounds (
jlimit (0,
631 e.
x - draggingColumnOffset),
633 dragOverlayComp->getWidth(),
636 for (
int i = columns.
size(); --i >= 0;)
672 > std::abs (dragOverlayComp->getRight() -
rightOfNext))
688 endDrag (draggingColumnOriginalIndex);
693void TableHeaderComponent::beginDrag (
const MouseEvent& e)
695 if (columnIdBeingDragged == 0)
699 auto*
ci = getInfoForId (columnIdBeingDragged);
703 columnIdBeingDragged = 0;
710 auto temp = columnIdBeingDragged;
711 columnIdBeingDragged = 0;
715 columnIdBeingDragged = temp;
719 for (
int i = listeners.size(); --i >= 0;)
721 listeners.getUnchecked (i)->tableColumnDraggingChanged (
this, columnIdBeingDragged);
722 i =
jmin (i, listeners.size() - 1);
728void TableHeaderComponent::endDrag (
const int finalIndex)
730 if (columnIdBeingDragged != 0)
734 columnIdBeingDragged = 0;
738 for (
int i = listeners.size(); --i >= 0;)
740 listeners.getUnchecked (i)->tableColumnDraggingChanged (
this, 0);
741 i =
jmin (i, listeners.size() - 1);
750 for (
auto* c : columns)
752 c->lastDeliberateWidth = c->width;
754 columnIdBeingResized = 0;
760 updateColumnUnderMouse (e);
765 dragOverlayComp.reset();
778TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (
int id)
const
780 for (
auto* c : columns)
787int TableHeaderComponent::visibleIndexToTotalIndex (
const int visibleIndex)
const
791 for (
int i = 0; i < columns.
size(); ++i)
805void TableHeaderComponent::sendColumnsChanged()
807 if (stretchToFit && lastDeliberateWidth > 0)
812 columnsChanged =
true;
816void TableHeaderComponent::handleAsyncUpdate()
818 const bool changed = columnsChanged || sortChanged;
819 const bool sized = columnsResized || changed;
820 const bool sorted = sortChanged;
821 columnsChanged =
false;
822 columnsResized =
false;
827 for (
int i = listeners.size(); --i >= 0;)
829 listeners.getUnchecked (i)->tableSortOrderChanged (
this);
830 i =
jmin (i, listeners.size() - 1);
836 for (
int i = listeners.size(); --i >= 0;)
838 listeners.getUnchecked (i)->tableColumnsChanged (
this);
839 i =
jmin (i, listeners.size() - 1);
845 for (
int i = listeners.size(); --i >= 0;)
847 listeners.getUnchecked (i)->tableColumnsResized (
this);
848 i =
jmin (i, listeners.size() - 1);
853int TableHeaderComponent::getResizeDraggerAt (
const int mouseX)
const
860 for (
auto*
ci : columns)
876void TableHeaderComponent::setColumnUnderMouse (
const int newCol)
878 if (
newCol != columnIdUnderMouse)
880 columnIdUnderMouse =
newCol;
885void TableHeaderComponent::updateColumnUnderMouse (
const MouseEvent& e)
887 setColumnUnderMouse (
reallyContains (e.getPosition(),
true) && getResizeDraggerAt (e.x) == 0
891static void tableHeaderMenuCallback (
int result, TableHeaderComponent* tableHeader,
int columnIdClicked)
893 if (tableHeader !=
nullptr && result != 0)
918 return std::make_unique<AccessibilityHandler> (*
this, AccessibilityRole::tableHeader);
923 return std::make_unique<AccessibilityHandler> (*
this, AccessibilityRole::tableHeader);
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
The base class for all JUCE user-interface objects.
bool isMouseButtonDown(bool includeChildren=false) const
Returns true if the mouse button is currently held down in this component.
virtual MouseCursor getMouseCursor()
Returns the mouse cursor shape to use when the mouse is over this component.
Image createComponentSnapshot(Rectangle< int > areaToGrab, bool clipImageToComponentBounds=true, float scaleFactor=1.0f)
Generates a snapshot of part of this component.
bool reallyContains(Point< int > localPoint, bool returnTrueIfWithinAChild)
Returns true if a given point lies in this component, taking any overlapping siblings into account.
void setFocusContainerType(FocusContainerType containerType) noexcept
Sets whether this component is a container for components that can have their focus traversed,...
int getHeight() const noexcept
Returns the component's height in pixels.
int getX() const noexcept
Returns the x coordinate of the component's left edge.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
void repaint()
Marks the whole component as needing to be redrawn.
@ focusContainer
The component will act as a top-level component within which focus is passed around.
Point< int > getMouseXYRelative() const
Returns the mouse's current position, relative to this component.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
Uses RAII to save and restore the state of a graphics context.
A graphics context, used for drawing a component or image.
void drawImage(const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, int sourceX, int sourceY, int sourceWidth, int sourceHeight, bool fillAlphaChannelWithCurrentBrush=false) const
Draws part of an image, rescaling it to fit in a given target region.
bool reduceClipRegion(int x, int y, int width, int height)
Intersects the current clipping region with another region.
Rectangle< int > getClipBounds() const
Returns the position of the bounding box for the current clipping region.
void setOrigin(Point< int > newOrigin)
Moves the position of the context's origin.
Holds a fixed-size bitmap.
void multiplyAllAlphas(float amountToMultiplyBy)
Changes the overall opacity of the image.
void duplicateIfShared()
Makes sure that no other Image objects share the same underlying data as this one.
LookAndFeel objects define the appearance of all the JUCE widgets, and subclasses can be used to appl...
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *), ComponentType *component)
This is a utility function to create a ModalComponentManager::Callback that will call a static functi...
Represents the state of the mouse buttons and modifier keys.
bool isPopupMenu() const noexcept
Checks whether the user is trying to launch a pop-up menu.
Represents a mouse cursor image.
@ LeftRightResizeCursor
An arrow pointing left and right.
Contains position and status information about a mouse event.
const ModifierKeys mods
The key modifiers associated with the event.
int getMouseDownX() const noexcept
Returns the x coordinate of the last place that a mouse was pressed.
const int x
The x-position of the mouse when the event occurred.
bool mouseWasDraggedSinceMouseDown() const noexcept
Returns true if the user seems to be performing a drag gesture.
const int y
The y-position of the mouse when the event occurred.
int getDistanceFromDragStartX() const noexcept
Returns the difference between the mouse's current x position and where it was when the button was la...
int size() const noexcept
Returns the number of items currently in the array.
ObjectClass * getUnchecked(int index) const noexcept
Returns a pointer to the object at this index in the array, without checking whether the index is in-...
void remove(int indexToRemove, bool deleteObject=true)
Removes an object from the array.
void clear(bool deleteObjects=true)
Clears the array, optionally deleting the objects inside it first.
int indexOf(const ObjectClass *objectToLookFor) const noexcept
Finds the index of an object which might be in the array.
void move(int currentIndex, int newIndex) noexcept
Moves one of the objects to a different position.
ObjectClass * insert(int indexToInsertAt, ObjectClass *newObject)
Inserts a new object into the array at the given index.
A general-purpose range object, that simply represents any linear range with a start and end point.
constexpr bool intersects(Range other) const noexcept
Returns true if the given range intersects this one.
Manages a rectangle and allows geometric operations to be performed on it.
ValueType getRight() const noexcept
Returns the x coordinate of the rectangle's right-hand-side.
Range< ValueType > getHorizontalRange() const noexcept
Returns the rectangle's left and right positions as a Range.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
A utility class for fitting a set of objects whose sizes can vary between a minimum and maximum size,...
Used to build a tree of elements representing an XML document.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
std::unique_ptr< XmlElement > parseXMLIfTagMatches(const String &textToParse, StringRef requiredTag)
Does an inexpensive check to see whether the top-level element has the given tag name,...
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
A struct containing options for formatting the text when representing an XML element as a string.
TextFormat withoutHeader() const
returns a copy of this format with the addDefaultHeader flag set to false.
TextFormat singleLine() const
returns a copy of this format with newLineChars set to nullptr.