27#include <Objectively/String.h>
32#define _Class _TableView
43 release(this->columns);
44 release(this->contentView);
45 release(this->headerView);
47 release(this->scrollView);
59 const String *identifier = $((Dictionary *) obj, objectForKeyPath,
"identifier");
77 const Array *columns = $(dictionary, objectForKeyPath,
"columns");
99 View *scrollView = (
View *) this->scrollView;
100 View *headerView = (
View *) this->headerView;
102 SDL_Rect frame = $(self,
bounds);
104 if (headerView->
hidden ==
false) {
112 scrollView->
frame = frame;
125#pragma mark - Control
134 if (event->type == SDL_MOUSEBUTTONUP) {
138 const SDL_Point point = {
139 .x =
event->button.x,
154 const SDL_Point point = {
155 .x =
event->button.x,
159 const ssize_t index = $(
this,
rowAtPoint, &point);
161 const Array *rows = (Array *) this->rows;
162 if (index > -1 && index < (ssize_t) rows->count) {
166 switch (this->control.selection) {
177 if (SDL_GetModState() & (KMOD_CTRL | KMOD_GUI)) {
179 $(this, deselectRowAtIndex, index);
181 $(this, selectRowAtIndex, index);
190 if (this->delegate.didSelectRowsAtIndexes) {
208#pragma mark - TableView
218 $(self->
columns, addObject, column);
244 if (SDL_PointInRect(point, &frame)) {
247 const Array *columns = (Array *) self->
columns;
249 assert(cells->count == columns->count);
251 for (
size_t i = 0; i < cells->count; i++) {
253 const View *cell = $(cells, objectAtIndex, i);
257 return $(columns, objectAtIndex, i);
273 const Array *columns = (Array *) self->
columns;
274 for (
size_t i = 0; i < columns->count; i++) {
276 TableColumn *column = $(columns, objectAtIndex, i);
277 if (strcmp(identifier, column->
identifier) == 0) {
306 const Array *rows = (Array *) self->
rows;
307 if (index < rows->count) {
321 for (
size_t i = 0; i < indexes->count; i++) {
335 self->
columns = $$(MutableArray, array);
338 self->
rows = $$(MutableArray, array);
347 assert(self->contentView);
352 assert(self->scrollView);
375 size.
w += this->padding.left + this->padding.right;
376 size.
h += this->padding.top + this->padding.bottom;
402 const Array *columns = (Array *) self->
columns;
403 for (
size_t i = 0; i < columns->count; i++) {
405 const TableColumn *column = $(columns, objectAtIndex, i);
410 for (
size_t i = 0; i < numberOfRows; i++) {
415 for (
size_t j = 0; j < columns->count; j++) {
416 const TableColumn *column = $(columns, objectAtIndex, j);
427 $(self->
rows, addObject, row);
449 $(self->
columns, removeObject, column);
461 if (SDL_PointInRect(point, &scrollFrame)) {
463 const Array *rows = (Array *) self->
rows;
464 for (
size_t i = 0; i < rows->count; i++) {
466 const View *row = $(rows, objectAtIndex, i);
497 size_t indexes[self->
rows->array.count];
500 const Array *rows = (Array *) self->
rows;
501 for (
size_t i = 0; i < rows->count; i++) {
505 indexes[count++] = i;
509 return $(alloc(IndexSet), initWithIndexes, indexes, count);
518 const Array *rows = (Array *) self->
rows;
519 if (index < rows->count) {
533 for (
size_t i = 0; i < indexes->count; i++) {
553 assert($((Array *) self->
columns, containsObject, column));
569#pragma mark - Class lifecycle
576 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
579 ((ViewInterface *) clazz->interface)->init =
init;
581 ((ViewInterface *) clazz->interface)->sizeThatFits =
sizeThatFits;
583 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
585 ((TableViewInterface *) clazz->interface)->addColumn =
addColumn;
587 ((TableViewInterface *) clazz->interface)->columnAtPoint =
columnAtPoint;
589 ((TableViewInterface *) clazz->interface)->deselectAll =
deselectAll;
592 ((TableViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
593 ((TableViewInterface *) clazz->interface)->naturalSize =
naturalSize;
594 ((TableViewInterface *) clazz->interface)->reloadData =
reloadData;
595 ((TableViewInterface *) clazz->interface)->removeColumn =
removeColumn;
596 ((TableViewInterface *) clazz->interface)->rowAtPoint =
rowAtPoint;
598 ((TableViewInterface *) clazz->interface)->selectAll =
selectAll;
599 ((TableViewInterface *) clazz->interface)->selectRowAtIndex =
selectRowAtIndex;
601 ((TableViewInterface *) clazz->interface)->setSortColumn =
setSortColumn;
613 clazz = _initialize(&(
const ClassDef) {
617 .interfaceOffset = offsetof(
TableView, interface),
618 .interfaceSize =
sizeof(TableViewInterface),
@ ControlSelectionMultiple
OBJECTIVELYMVC_EXPORT void MVC_PlaySound(const Sound *sound)
Plays the specified Sound through the current SoundStage (if any).
static void reloadData_removeRows(const Array *array, ident obj, ident data)
ArrayEnumerator to remove TableRowViews from the table's contentView.
static void deselectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all Row deselection.
static void dealloc(Object *self)
static void awakeWithDictionary_columns(const Array *array, ident obj, ident data)
ArrayEnumerator for awaking TableColumns.
static void selectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all row selection.
static void initialize(Class *clazz)
TableViews provide sortable, tabular presentations of data.
#define MakeSize(w, h)
Creates an SDL_Size with the given dimensions.
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
void setSelected(CollectionItemView *self, _Bool isSelected)
Sets the selected state of this item.
void deselectAll(CollectionView *self)
Deselects all items in this CollectionView.
void reloadData(CollectionView *self)
Reloads this CollectionView's visible items.
SDL_Size naturalSize(const CollectionView *self)
void selectAll(CollectionView *self)
Selects all items in this CollectionView.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Controls are Views which capture events and dispatch Actions.
_Bool captureEvent(Control *self, const SDL_Event *event)
Captures a given event, potentially altering the state of this Control.
Class * _Control(void)
The Control archetype.
_Bool isHighlighted(const Control *self)
SDL_Size size(const Image *self)
SDL_Size contentSize(const Panel *self)
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.
TableColumn * initWithIdentifier(TableColumn *self, const char *identifier)
Initializes this TableColumn with the given identifier.
char * identifier
The identifier.
TableHeaderCellView * headerCell
The header cell.
Order order
The sort order.
_Bool isSelected
True when this row is selected, false otherwise.
void removeAllCells(TableRowView *self)
Removes all cells from this row.
MutableArray * cells
The cells.
void removeCell(TableRowView *self, TableCellView *cell)
Removes the specified cell from this row.
void addCell(TableRowView *self, TableCellView *cell)
Adds the specified cell to this row.
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.
void deselectRowAtIndex(TableView *self, size_t index)
Deselects the row at the given index.
void removeColumn(TableView *self, TableColumn *column)
Removes the specified column from this table.
void addColumn(TableView *self, TableColumn *column)
Adds the specified column to this table.
Control control
The superclass.
ScrollView * scrollView
The scroll view.
void addColumnWithIdentifier(TableView *self, const char *identifier)
Adds a new TableColumn with the given identifier to this table.
Class * _TableView(void)
The TableView archetype.
TableViewDelegate delegate
The delegate.
MutableArray * columns
The column definitions.
TableColumn * sortColumn
The column to sort by.
IndexSet * selectedRowIndexes(const TableView *self)
TableViewDataSource dataSource
The data source.
StackView * contentView
The content View.
TableColumn * columnAtPoint(const TableView *self, const SDL_Point *point)
void deselectRowsAtIndexes(TableView *self, const IndexSet *indexes)
TableHeaderView * headerView
The header.
MutableArray * rows
The rows.
ssize_t rowAtPoint(const TableView *self, const SDL_Point *point)
TableColumn * columnWithIdentifier(const TableView *self, const char *identifier)
void setSortColumn(TableView *self, TableColumn *column)
Sets the sort column for this table.
void selectRowAtIndex(TableView *self, size_t index)
Selects the row at the given index.
void selectRowsAtIndexes(TableView *self, const IndexSet *indexes)
Selects the rows at the given indexes.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
SDL_Rect bounds(const View *self)
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
_Bool hidden
If true, this View is not drawn.
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
void addClassName(View *self, const char *className)
Adds the given class name to this View.
_Bool didReceiveEvent(const View *self, const SDL_Event *event)
char * identifier
An optional identifier.
void sizeThatFits(const View *self)
_Bool containsPoint(const View *self, const SDL_Point *point)
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.
SDL_Rect renderFrame(const View *self)
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
SDL_Rect frame
The frame, relative to the superview.
void removeSubview(View *self, View *subview)
Removes the given subview from this View.