ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
TableRowView.c
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for OpenGL, SDL2 and GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#include <assert.h>
25
26#include "TableRowView.h"
27#include "TableView.h"
28
29#define _Class _TableRowView
30
31#pragma mark - Object
32
36static void dealloc(Object *self) {
37
38 TableRowView *this = (TableRowView *) self;
39
40 release(this->cells);
41
42 super(Object, self, dealloc);
43}
44
45#pragma mark - View
46
50static _Bool matchesSelector(const View *self, const SimpleSelector *simpleSelector) {
51
52 TableRowView *this = (TableRowView *) self;
53
54 if (simpleSelector->type == SimpleSelectorTypePseudo) {
55 if (strcmp("selected", simpleSelector->pattern) == 0) {
56 return this->isSelected;
57 }
58 }
59
60 return super(View, self, matchesSelector, simpleSelector);
61}
62
63#pragma mark - TableRowView
64
69static void addCell(TableRowView *self, TableCellView *cell) {
70
71 assert(cell);
72
73 $(self->cells, addObject, cell);
74
75 $((View *) self, addSubview, (View *) cell);
76}
77
83
84 self = (TableRowView *) super(StackView, self, initWithFrame, NULL);
85 if (self) {
86
87 const Array *columns = (Array *) tableView->columns;
88
89 self->cells = $$(MutableArray, arrayWithCapacity, columns->count);
90 assert(self->cells);
91
92 self->tableView = tableView;
93 assert(self->tableView);
94 }
95
96 return self;
97}
98
102static void removeAllCells_enumerate(const Array *array, ident obj, ident data) {
103 $((View *) obj, removeFromSuperview);
104}
105
111static void removeAllCells(TableRowView *self) {
112 $(self->cells, removeAllObjectsWithEnumerator, removeAllCells_enumerate, NULL);
113}
114
119static void removeCell(TableRowView *self, TableCellView *cell) {
120
121 assert(cell);
122
123 $(self->cells, removeObject, cell);
124
125 $((View *) self, removeSubview, (View *) cell);
126}
127
132static void setSelected(TableRowView *self, _Bool isSelected) {
133
134 if (isSelected != self->isSelected) {
135 self->isSelected = isSelected;
136 $((View *) self, invalidateStyle);
137 }
138}
139
140#pragma mark - Class lifecycle
141
145static void initialize(Class *clazz) {
146
147 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
148
149 ((ViewInterface *) clazz->interface)->matchesSelector = matchesSelector;
150
151 ((TableRowViewInterface *) clazz->interface)->addCell = addCell;
152 ((TableRowViewInterface *) clazz->interface)->initWithTableView = initWithTableView;
153 ((TableRowViewInterface *) clazz->interface)->removeAllCells = removeAllCells;
154 ((TableRowViewInterface *) clazz->interface)->removeCell = removeCell;
155 ((TableRowViewInterface *) clazz->interface)->setSelected = setSelected;
156}
157
162Class *_TableRowView(void) {
163 static Class *clazz;
164 static Once once;
165
166 do_once(&once, {
167 clazz = _initialize(&(const ClassDef) {
168 .name = "TableRowView",
169 .superclass = _StackView(),
170 .instanceSize = sizeof(TableRowView),
171 .interfaceOffset = offsetof(TableRowView, interface),
172 .interfaceSize = sizeof(TableRowViewInterface),
174 });
175 });
176
177 return clazz;
178}
179#undef _Class
180
@ SimpleSelectorTypePseudo
static void dealloc(Object *self)
Definition: TableRowView.c:36
static void removeAllCells_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator to remove TableCellViews from the row.
Definition: TableRowView.c:102
static void initialize(Class *clazz)
Definition: TableRowView.c:145
Rows for TableViews.
TableViews provide sortable, tabular presentations of data.
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92
void setSelected(CollectionItemView *self, _Bool isSelected)
Sets the selected state of this item.
_Bool isSelected(const Control *self)
Definition: Control.c:325
The SimpleSelector type.
SimpleSelectorType type
The SimpleSelectorType.
char * pattern
The pattern, as provided by the user.
StackViews are containers that manage the arrangement of their subviews.
Definition: StackView.h:68
Class * _StackView(void)
The StackView archetype.
Definition: StackView.c:262
Each row in a TableView is comprised of TableCellViews.
Definition: TableCellView.h:41
TableHeaderView * initWithTableView(TableHeaderView *self, TableView *tableView)
Initializes this TableHeaderView with the give table.
Rows for TableViews.
Definition: TableRowView.h:44
Class * _TableRowView(void)
The TableRowView archetype.
Definition: TableRowView.c:162
_Bool isSelected
True when this row is selected, false otherwise.
Definition: TableRowView.h:65
void removeAllCells(TableRowView *self)
Removes all cells from this row.
Definition: TableRowView.c:111
MutableArray * cells
The cells.
Definition: TableRowView.h:60
TableView * tableView
The table.
Definition: TableRowView.h:70
void removeCell(TableRowView *self, TableCellView *cell)
Removes the specified cell from this row.
Definition: TableRowView.c:119
void addCell(TableRowView *self, TableCellView *cell)
Adds the specified cell to this row.
Definition: TableRowView.c:69
TableViews provide sortable, tabular presentations of data.
Definition: TableView.h:122
MutableArray * columns
The column definitions.
Definition: TableView.h:138
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
void invalidateStyle(View *self)
Invalidates the computed Style for this View and its descendants.
Definition: View.c:822
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35
void removeFromSuperview(View *self)
Removes this View from its superview.
Definition: View.c:1175
_Bool matchesSelector(const View *self, const SimpleSelector *simpleSelector)
void removeSubview(View *self, View *subview)
Removes the given subview from this View.
Definition: PageView.c:58