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)) {
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);
282 for (
size_t i = 0; i <
columns->count; i++) {
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);
411 for (
size_t i = 0; i <
columns->count; i++) {
418 for (
size_t i = 0; i < numberOfRows; i++) {
423 for (
size_t j = 0; j <
columns->count; 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;
590 ((ViewInterface *) clazz->interface)->layoutSubviews =
layoutSubviews;
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;
603 ((TableViewInterface *) clazz->interface)->naturalSize =
naturalSize;
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 initialize(Class *clazz)
static View * init(View *self)
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
static void dealloc(Object *self)
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
static void layoutSubviews(View *self)
static void setSelected(CollectionItemView *self, bool isSelected)
static void selectAll(CollectionView *self)
static void deselectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all item deselection.
static SDL_Size naturalSize(const CollectionView *self)
static void selectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all item selection.
static void deselectAll(CollectionView *self)
static void reloadData(CollectionView *self)
static bool isHighlighted(const Control *self)
@ ControlSelectionMultiple
static SDL_Size size(const Image *self)
static void removeSubview(View *self, View *subview)
static SDL_Size contentSize(const Panel *self)
static SDL_Size sizeThatFits(const View *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 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 void enumerate(View *self, ViewEnumerator enumerator, ident data)
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.
void deselectRowAtIndex(TableView *self, size_t index)
Deselects the row at the given index.
void addColumn(TableView *self, TableColumn *column)
Adds the specified column to this table.
ScrollView * scrollView
The scroll view.
TableView * initWithFrame(TableView *self, const SDL_Rect *frame)
Initializes this TableView with the specified frame and style.
TableViewDelegate delegate
The delegate.
TableColumn * sortColumn
The column to sort by.
TableViewDataSource dataSource
The data source.
Array * columns
The column definitions.
StackView * contentView
The content View.
TableHeaderView * headerView
The header.
void selectRowAtIndex(TableView *self, size_t index)
Selects the row at the given index.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
void setNeedsLayout(View *self)
Marks this View as needing layout before it is next 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.
void sizeThatFits(const View *self)
char * identifier
An optional identifier.
SDL_Rect renderFrame(const View *self)
SDL_Size size(const View *self)
ViewPadding padding
The padding.
bool containsPoint(const View *self, const SDL_Point *point)
ViewVisibility visibility
Whether this View is drawn, and contributes to its superview's size.
void enumerate(const View *self, ViewEnumerator enumerator, ident data)
SDL_Rect frame
The frame, relative to the superview.