27#include <Objectively/String.h>
31#define _Class _TableView
42 memset(&this->delegate, 0,
sizeof(this->delegate));
44 release(this->columns);
45 release(this->contentView);
46 release(this->headerView);
48 release(this->scrollView);
60 const String *identifier = $((Dictionary *) obj, objectForKeyPath,
"identifier");
78 const Array *columns = $(dictionary, objectForKeyPath,
"columns");
100 View *scrollView = (
View *) this->scrollView;
101 View *headerView = (
View *) this->headerView;
103 SDL_Rect frame = $(self,
bounds);
113 scrollView->
frame = frame;
125 return $(self,
size);
133#pragma mark - Control
143 if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
147 const SDL_Point point = {
148 .x =
event->button.x,
163 const SDL_Point point = {
164 .x =
event->button.x,
168 const ssize_t index = $(
this,
rowAtPoint, &point);
170 const Array *rows = (Array *) this->rows;
171 if (index > -1 && index < (ssize_t) rows->count) {
175 switch (this->control.selection) {
185 if (SDL_GetModState() & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) {
198 if (this->delegate.didSelectRowsAtIndexes) {
216#pragma mark - TableView
226 $(self->
columns, addObject, column);
252 if (SDL_PointInRect(point, &frame)) {
255 const Array *columns = (Array *) self->
columns;
257 assert(cells->count == columns->count);
259 for (
size_t i = 0; i < cells->count; i++) {
261 const View *cell = $(cells, objectAtIndex, i);
265 return $(columns, objectAtIndex, i);
281 const Array *columns = (Array *) self->
columns;
282 for (
size_t i = 0; i < columns->count; i++) {
284 TableColumn *column = $(columns, objectAtIndex, i);
285 if (strcmp(identifier, column->
identifier) == 0) {
314 const Array *rows = (Array *) self->
rows;
315 if (index < rows->count) {
329 for (
size_t i = 0; i < indexes->count; i++) {
343 self->
columns = $$(Array, array);
346 self->
rows = $$(Array, array);
355 assert(self->contentView);
360 assert(self->scrollView);
383 size.w += this->padding.left + this->padding.right;
384 size.h += this->padding.top + this->padding.bottom;
410 const Array *columns = (Array *) self->
columns;
411 for (
size_t i = 0; i < columns->count; i++) {
413 const TableColumn *column = $(columns, objectAtIndex, i);
418 for (
size_t i = 0; i < numberOfRows; i++) {
423 for (
size_t j = 0; j < columns->count; j++) {
424 const TableColumn *column = $(columns, objectAtIndex, j);
435 $(self->
rows, addObject, row);
457 $(self->
columns, removeObject, column);
469 if (SDL_PointInRect(point, &scrollFrame)) {
471 const Array *rows = (Array *) self->
rows;
472 for (
size_t i = 0; i < rows->count; i++) {
474 const View *row = $(rows, objectAtIndex, i);
505 size_t indexes[self->
rows->count];
508 const Array *rows = (Array *) self->
rows;
509 for (
size_t i = 0; i < rows->count; i++) {
513 indexes[count++] = i;
517 return $(alloc(IndexSet), initWithIndexes, indexes, count);
526 const Array *rows = (Array *) self->
rows;
527 if (index < rows->count) {
543 for (
size_t i = 0; i < indexes->count; i++) {
563 assert($((Array *) self->
columns, containsObject, column));
579#pragma mark - Class lifecycle
586 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
589 ((ViewInterface *) clazz->interface)->init =
init;
591 ((ViewInterface *) clazz->interface)->sizeThatFits =
sizeThatFits;
593 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
595 ((TableViewInterface *) clazz->interface)->addColumn =
addColumn;
597 ((TableViewInterface *) clazz->interface)->columnAtPoint =
columnAtPoint;
599 ((TableViewInterface *) clazz->interface)->deselectAll =
deselectAll;
602 ((TableViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
604 ((TableViewInterface *) clazz->interface)->reloadData =
reloadData;
605 ((TableViewInterface *) clazz->interface)->removeColumn =
removeColumn;
606 ((TableViewInterface *) clazz->interface)->rowAtPoint =
rowAtPoint;
608 ((TableViewInterface *) clazz->interface)->selectAll =
selectAll;
609 ((TableViewInterface *) clazz->interface)->selectRowAtIndex =
selectRowAtIndex;
611 ((TableViewInterface *) clazz->interface)->setSortColumn =
setSortColumn;
623 clazz = _initialize(&(
const ClassDef) {
627 .interfaceSize =
sizeof(TableViewInterface),
static void setSelected(CollectionItemView *self, bool isSelected)
static bool isHighlighted(const Control *self)
@ ControlSelectionMultiple
static SDL_Size size(const Image *self)
static void removeSubview(View *self, View *subview)
static void addSubview(View *self, View *subview)
static SDL_Size contentSize(const Panel *self)
static TableColumn * initWithIdentifier(TableColumn *self, const char *identifier)
static void removeCell(TableRowView *self, TableCellView *cell)
static void addCell(TableRowView *self, TableCellView *cell)
static void removeAllCells(TableRowView *self)
static void setSortColumn(TableView *self, TableColumn *column)
static void deselectAll(TableView *self)
static void selectRowAtIndex(TableView *self, size_t index)
static TableView * initWithFrame(TableView *self, const SDL_Rect *frame)
static View * init(View *self)
static void reloadData_removeRows(const Array *array, ident obj, ident data)
ArrayEnumerator to remove TableRowViews from the table's contentView.
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
static void deselectRowsAtIndexes(TableView *self, const IndexSet *indexes)
static void selectRowsAtIndexes(TableView *self, const IndexSet *indexes)
static IndexSet * selectedRowIndexes(const TableView *self)
static SDL_Size sizeThatFits(const View *self)
static bool captureEvent(Control *self, const SDL_Event *event)
static TableColumn * columnWithIdentifier(const TableView *self, const char *identifier)
static SDL_Size naturalSize(const TableView *self)
static void selectAll(TableView *self)
static void deselectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all Row deselection.
static void addColumnWithIdentifier(TableView *self, const char *identifier)
static void dealloc(Object *self)
static void addColumn(TableView *self, TableColumn *column)
static ssize_t rowAtPoint(const TableView *self, const SDL_Point *point)
static void awakeWithDictionary_columns(const Array *array, ident obj, ident data)
ArrayEnumerator for awaking TableColumns.
static void removeColumn(TableView *self, TableColumn *column)
static void selectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all row selection.
static void deselectRowAtIndex(TableView *self, size_t index)
static void initialize(Class *clazz)
static void reloadData(TableView *self)
static void layoutSubviews(View *self)
static TableColumn * columnAtPoint(const TableView *self, const SDL_Point *point)
TableViews provide sortable, tabular presentations of data.
static void addClassName(View *self, const char *className)
static bool isContainer(const View *self)
static void layoutIfNeeded(View *self)
static bool didReceiveEvent(const View *self, const SDL_Event *event)
static void setNeedsLayout(View *self)
static SDL_Rect renderFrame(const View *self)
static void enumerate(View *self, ViewEnumerator enumerator, ident data)
static bool containsPoint(const View *self, const SDL_Point *point)
static SDL_Rect bounds(const View *self)
Controls are Views which capture and respond to events.
StackViews are containers that manage the arrangement of their subviews.
Each row in a TableView is comprised of TableCellViews.
Columns provide alignment, spacing and sorting hints for TableView instances.
char * identifier
The identifier.
TableHeaderCellView * headerCell
The header cell.
Order order
The sort order.
bool isSelected
True when this row is selected, false otherwise.
size_t(* numberOfRows)(const TableView *tableView)
void(* didSetSortColumn)(TableView *tableView)
Called by the TableView when the sort column or order changes.
TableCellView *(* cellForColumnAndRow)(const TableView *tableView, const TableColumn *column, size_t row)
Called by the TableView to instantiate cells.
TableViews provide sortable, tabular presentations of data.
ScrollView * scrollView
The scroll view.
TableViewDelegate delegate
The delegate.
TableColumn * sortColumn
The column to sort by.
TableViewDataSource dataSource
The data source.
SDL_Size naturalSize(const TableView *self)
Array * columns
The column definitions.
StackView * contentView
The content View.
TableHeaderView * headerView
The header.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
char * identifier
An optional identifier.
layoutSubviews(View *self)
Arranges this View's immediate subviews within its (already final) frame.
ViewVisibility visibility
Whether this View is drawn, and contributes to its superview's size.
SDL_Rect frame
The frame, relative to the superview.