29static const Identifier tableColumnProperty {
"_tableColumnId" };
30static const Identifier tableAccessiblePlaceholderProperty {
"_accessiblePlaceholder" };
46 tableModel->paintRowBackground (g, getRow(),
getWidth(),
getHeight(), isSelected());
49 const auto numColumns =
jmin ((
int) columnComponents.size(),
headerComp.getNumColumns (
true));
52 for (
int i = 0; i < numColumns; ++i)
68 tableModel->paintCell (g, getRow(),
headerComp.getColumnIdOfIndex (i,
true),
85 if (tableModel !=
nullptr && getRow() < owner.
getNumRows())
87 const ComponentDeleter deleter { columnForComponent };
90 while (numColumns < (
int) columnComponents.size())
91 columnComponents.pop_back();
93 while ((
int) columnComponents.size() < numColumns)
94 columnComponents.emplace_back (
nullptr, deleter);
96 for (
int i = 0; i < numColumns; ++i)
99 auto originalComp = std::move (columnComponents[(
size_t) i]);
102 :
std::unique_ptr<
Component, ComponentDeleter> {
nullptr, deleter };
126 comp->setInterceptsMouseClicks (
false,
false);
127 comp->getProperties().set (tableAccessiblePlaceholderProperty,
true);
131 columnForComponent.emplace (
columnComp.get(), i);
141 resizeCustomComp (i);
146 columnComponents.clear();
152 for (
auto i = (
int) columnComponents.size(); --i >= 0;)
153 resizeCustomComp (i);
156 void resizeCustomComp (
int index)
158 if (
auto& c = columnComponents[(
size_t) index])
160 c->setBounds (owner.getHeader()
161 .getColumnPosition (index)
167 void performSelection (
const MouseEvent& e,
bool isMouseUp)
169 owner.selectRowsBasedOnModifierKeys (getRow(), e.mods,
isMouseUp);
171 auto columnId = owner.getHeader().getColumnIdAtX (e.x);
174 if (
auto* m = owner.getTableListBoxModel())
175 m->cellClicked (getRow(),
columnId, e);
183 const auto columnId = owner.getHeader().getColumnIdAtX (e.
x);
186 if (
auto* m = owner.getTableListBoxModel())
187 m->cellDoubleClicked (getRow(),
columnId, e);
195 if (
auto* m = owner.getTableListBoxModel())
196 return m->getCellTooltip (getRow(),
columnId);
203 const auto index = (
size_t) owner.getHeader().getIndexOfColumnId (
columnId,
true);
206 return columnComponents[index].get();
211 int getColumnNumberOfComponent (
const Component* comp)
const
213 const auto iter = columnForComponent.find (comp);
214 return iter != columnForComponent.cend() ? iter->second : -1;
219 return std::make_unique<RowAccessibilityHandler> (*
this);
229 RowAccessibilityHandler (RowComp& rowComp)
232 getListRowAccessibilityActions (rowComp),
233 { std::make_unique<RowComponentCellInterface> (*
this) }),
234 rowComponent (rowComp)
238 String getTitle()
const override
240 if (
auto* m = rowComponent.owner.ListBox::model)
241 return m->getNameForRow (rowComponent.getRow());
246 String getHelp()
const override {
return rowComponent.getTooltip(); }
248 AccessibleState getCurrentState()
const override
250 if (
auto* m = rowComponent.owner.getTableListBoxModel())
251 if (rowComponent.getRow() >= m->getNumRows())
252 return AccessibleState().withIgnored();
254 auto state = AccessibilityHandler::getCurrentState();
256 if (rowComponent.owner.multipleSelection)
257 state = state.withMultiSelectable();
259 state = state.withSelectable();
261 if (rowComponent.isSelected())
262 return state.withSelected();
268 class RowComponentCellInterface final :
public AccessibilityCellInterface
271 RowComponentCellInterface (RowAccessibilityHandler& handler)
276 int getDisclosureLevel()
const override {
return 0; }
278 const AccessibilityHandler* getTableHandler()
const override {
return owner.rowComponent.owner.getAccessibilityHandler(); }
281 RowAccessibilityHandler& owner;
285 RowComp& rowComponent;
289 class ComponentDeleter
293 : columnForComponent (&locations) {}
295 void operator() (Component* comp)
const
297 columnForComponent->erase (comp);
346 enum { autoSizeColumnId = 0xf836743, autoSizeAllId = 0xf836744 };
355 ListBox::assignModelPtr (
this);
357 setHeader (std::make_unique<Header> (*
this));
383 if (header !=
nullptr)
421 autoSizeOptionsShown = shouldBeShown;
449 auto x =
scrollbar.getCurrentRangeStart();
450 auto w =
scrollbar.getCurrentRangeSize();
454 else if (pos.getRight() > x + w)
455 x +=
jmax (0.0, pos.getRight() - (x + w));
462 return model !=
nullptr ? model->
getNumRows() : 0;
481 if (model !=
nullptr)
487 if (model !=
nullptr)
493 if (model !=
nullptr)
499 if (model !=
nullptr)
505 if (model !=
nullptr)
513 updateColumnComponents();
520 updateColumnComponents();
525 if (model !=
nullptr)
544void TableListBox::updateColumnComponents()
const
553template <
typename FindIndex>
563 return AccessibilityTableInterface::Span { result, 1 };
574 explicit TableInterface (
TableListBox& tableListBoxToWrap)
575 : tableListBox (tableListBoxToWrap)
579 int getNumRows()
const override
581 if (
auto* tableModel = tableListBox.getTableListBoxModel())
582 return tableModel->getNumRows();
587 int getNumColumns()
const override
589 return tableListBox.getHeader().getNumColumns (
true);
595 if (
auto* rowComp = tableListBox.getComponentForRowNumber (row))
596 return rowComp->getAccessibilityHandler();
604 if (
auto* cellComponent = tableListBox.getCellComponent (tableListBox.getHeader().getColumnIdOfIndex (column,
true), row))
605 return cellComponent->getAccessibilityHandler();
612 if (tableListBox.hasAccessibleHeaderComponent())
613 return tableListBox.headerComponent->getAccessibilityHandler();
621 return findRecursively (handler, &tableListBox, [&] (
auto* c) {
return tableListBox.getRowNumberOfComponent (c); });
628 if (
const auto rowSpan = getRowSpan (handler))
629 if (
auto* rowComponent =
dynamic_cast<RowComp*
> (tableListBox.getComponentForRowNumber (rowSpan->begin)))
630 return findRecursively (handler, &tableListBox, [&] (
auto* c) {
return rowComponent->getColumnNumberOfComponent (c); });
637 const auto row = getRowSpan (handler);
638 const auto col = getColumnSpan (handler);
640 if (row.hasValue() && col.hasValue())
642 tableListBox.scrollToEnsureRowIsOnscreen (row->begin);
643 tableListBox.scrollToEnsureColumnIsOnscreen (col->begin);
653 return std::make_unique<AccessibilityHandler> (*
this,
654 AccessibilityRole::table,
A simple wrapper for building a collection of supported accessibility actions and corresponding callb...
Base class for accessible Components.
const Component & getComponent() const noexcept
Returns the Component that this handler represents.
An abstract interface which represents a UI element that supports a table interface.
The base class for all JUCE user-interface objects.
bool contains(Point< int > localPoint)
Returns true if a given point lies within this component or one of its children.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
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.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void repaint()
Marks the whole component as needing to be redrawn.
Component() noexcept
Creates a component.
@ 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.
NamedValueSet & getProperties() noexcept
Returns the set of properties that belong to this component.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
int getWidth() const noexcept
Returns the component's width in pixels.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
Uses RAII to save and restore the state of a graphics context.
A graphics context, used for drawing a component or image.
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.
A list of items that can be scrolled vertically.
int getRowContainingPosition(int x, int y) const noexcept
Finds the row index that contains a given x,y position.
void setMinimumContentWidth(int newMinimumWidth)
Changes the width of the rows in the list.
Component * getComponentForRowNumber(int rowNumber) const noexcept
Finds the row component for a given row in the list.
int getVisibleContentWidth() const noexcept
Returns the space currently available for the row items, taking into account borders,...
ScrollBar & getHorizontalScrollBar() const noexcept
Returns a reference to the horizontal scrollbar.
Rectangle< int > getRowPosition(int rowNumber, bool relativeToComponentTopLeft) const noexcept
Returns the position of one of the rows, relative to the top-left of the listbox.
int getNumRowsOnScreen() const noexcept
Returns the number of rows actually visible.
void updateContent()
Causes the list to refresh its content.
void setHeaderComponent(std::unique_ptr< Component > newHeaderComponent)
Sets a component that the list should use as a header.
void resized() override
Called when this component's size has been changed.
Contains position and status information about a mouse event.
const int x
The x-position of the mouse when the event occurred.
Manages a rectangle and allows geometric operations to be performed on it.
Rectangle withX(ValueType newX) const noexcept
Returns a rectangle which has the same size and y-position as this one, but with a different x-positi...
Rectangle withHeight(ValueType newHeight) const noexcept
Returns a rectangle which has the same position and width as this one, but with a different height.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
void translate(ValueType deltaX, ValueType deltaY) noexcept
Moves the rectangle's position by adding amount to its x and y coordinates.
Rectangle withWidth(ValueType newWidth) const noexcept
Returns a rectangle which has the same position and height as this one, but with a different width.
Holds a set of primitive values, storing them as a set of ranges.
One of these is used by a TableListBox as the data model for the table's contents.
virtual String getCellTooltip(int rowNumber, int columnId)
Returns a tooltip for a particular cell in the table.
virtual int getColumnAutoSizeWidth(int columnId)
Returns the best width for one of the columns.
virtual var getDragSourceDescription(const SparseSet< int > ¤tlySelectedRows)
To allow rows from your table to be dragged-and-dropped, implement this method.
virtual void cellClicked(int rowNumber, int columnId, const MouseEvent &)
This callback is made when the user clicks on one of the cells in the table.
virtual void sortOrderChanged(int newSortColumnId, bool isForwards)
This callback is made when the table's sort order is changed.
virtual void cellDoubleClicked(int rowNumber, int columnId, const MouseEvent &)
This callback is made when the user clicks on one of the cells in the table.
virtual void selectedRowsChanged(int lastRowSelected)
Override this to be informed when rows are selected or deselected.
virtual void returnKeyPressed(int lastRowSelected)
Override this to be informed when the return key is pressed.
virtual void backgroundClicked(const MouseEvent &)
This can be overridden to react to the user double-clicking on a part of the list where there are no ...
virtual void listWasScrolled()
Override this to be informed when the list is scrolled.
virtual Component * refreshComponentForCell(int rowNumber, int columnId, bool isRowSelected, Component *existingComponentToUpdate)
This is used to create or update a custom component to go in a cell.
virtual int getNumRows()=0
This must return the number of rows currently in the table.
virtual void deleteKeyPressed(int lastRowSelected)
Override this to be informed when the delete key is pressed.
void resized() override
Called when this component's size has been changed.
String getTooltip() override
Returns the string that this object wants to show as its tooltip.
void mouseDoubleClick(const MouseEvent &e) override
Called when a mouse button has been double-clicked on a component.
void paint(Graphics &g) override
Components can override this method to draw their content.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
A table of cells, using a TableHeaderComponent as its header.
void tableColumnsChanged(TableHeaderComponent *) override
This is called when some of the table's columns are added, removed, hidden, or rearranged.
void autoSizeAllColumns()
Calls autoSizeColumn() for all columns in the table.
void setModel(TableListBoxModel *newModel)
Changes the TableListBoxModel that is being used for this table.
int getHeaderHeight() const noexcept
Returns the height of the table header.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
TableListBoxModel * getTableListBoxModel() const noexcept
Returns the model currently in use.
void scrollToEnsureColumnIsOnscreen(int columnId)
Scrolls horizontally if necessary to make sure that a particular column is visible.
void paintListBoxItem(int, Graphics &, int, int, bool) override
This method must be implemented to draw a row of the list.
bool isAutoSizeMenuOptionShown() const noexcept
True if the auto-size options should be shown on the menu.
void setHeaderHeight(int newHeight)
Changes the height of the table header component.
TableListBox(const String &componentName=String(), TableListBoxModel *model=nullptr)
Creates a TableListBox.
void autoSizeColumn(int columnId)
Resizes a column to fit its contents.
Component * getCellComponent(int columnId, int rowNumber) const
Returns the component that currently represents a given cell.
void deleteKeyPressed(int currentSelectedRow) override
Override this to be informed when the delete key is pressed.
void setHeader(std::unique_ptr< TableHeaderComponent > newHeader)
Sets the header component to use for the table.
void tableColumnsResized(TableHeaderComponent *) override
This is called when one or more of the table's columns are resized.
void setAutoSizeMenuOptionShown(bool shouldBeShown) noexcept
Enables or disables the auto size options on the popup menu.
Component * refreshComponentForRow(int rowNumber, bool isRowSelected, Component *existingComponentToUpdate) override
This is used to create or update a custom component to go in a row of the list.
void listWasScrolled() override
Override this to be informed when the list is scrolled.
void resized() override
Called when this component's size has been changed.
int getNumRows() override
This has to return the number of items in the list.
void selectedRowsChanged(int row) override
Override this to be informed when rows are selected or deselected.
~TableListBox() override
Destructor.
TableHeaderComponent & getHeader() const noexcept
Returns the header component being used in this table.
Rectangle< int > getCellPosition(int columnId, int rowNumber, bool relativeToComponentTopLeft) const
Returns the position of one of the cells in the table.
void returnKeyPressed(int currentSelectedRow) override
Override this to be informed when the return key is pressed.
void tableSortOrderChanged(TableHeaderComponent *) override
This is called when the column by which the table should be sorted is changed.
void tableColumnDraggingChanged(TableHeaderComponent *, int) override
This is called when the user begins or ends dragging one of the columns around.
void backgroundClicked(const MouseEvent &) override
This can be overridden to react to the user clicking on a part of the list where there are no rows.
A variant class, that can be used to hold a range of primitive values.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
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.
AccessibilityRole
The list of available roles for an AccessibilityHandler object.
Utility struct which holds one or more accessibility interfaces.