ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
TableColumn.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#include <stdlib.h>
26#include <string.h>
27
28#include <Objectively/String.h>
29
30#include "TableColumn.h"
31
32#define _Class _TableColumn
33
34#pragma mark - Object
35
39static void dealloc(Object *self) {
40
41 TableColumn *this = (TableColumn *) self;
42
43 release(this->headerCell);
44
45 free(this->identifier);
46
47 super(Object, self, dealloc);
48}
49
50#pragma mark - TableColumn
51
56static TableColumn *initWithIdentifier(TableColumn *self, const char *identifier) {
57
58 self = (TableColumn *) super(Object, self, init);
59 if (self) {
60
61 self->headerCell = $(alloc(TableHeaderCellView), initWithFrame, NULL);
62 assert(self->headerCell);
63
64 self->identifier = strdup(identifier);
65 assert(self->identifier);
66
67 self->headerCell->tableCellView.view.identifier = strdup(self->identifier);
68
69 $(((TableCellView *) self->headerCell)->text, setText, self->identifier);
70 }
71
72 return self;
73}
74
75#pragma mark - Class lifecycle
76
80static void initialize(Class *clazz) {
81
82 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
83
84 ((TableColumnInterface *) clazz->interface)->initWithIdentifier = initWithIdentifier;
85}
86
91Class *_TableColumn(void) {
92 static Class *clazz;
93 static Once once;
94
95 do_once(&once, {
96 clazz = _initialize(&(const ClassDef) {
97 .name = "TableColumn",
98 .superclass = _Object(),
99 .instanceSize = sizeof(TableColumn),
100 .interfaceOffset = offsetof(TableColumn, interface),
101 .interfaceSize = sizeof(TableColumnInterface),
103 });
104 });
105
106 return clazz;
107}
108
109#undef _Class
110
static void dealloc(Object *self)
Definition: TableColumn.c:39
static void initialize(Class *clazz)
Definition: TableColumn.c:80
Columns for TableViews.
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Each row in a TableView is comprised of TableCellViews.
Definition: TableCellView.h:41
View view
The superclass.
Definition: TableCellView.h:46
Columns provide alignment, spacing and sorting hints for TableView instances.
Definition: TableColumn.h:45
TableColumn * initWithIdentifier(TableColumn *self, const char *identifier)
Initializes this TableColumn with the given identifier.
Definition: TableColumn.c:56
char * identifier
The identifier.
Definition: TableColumn.h:66
TableHeaderCellView * headerCell
The header cell.
Definition: TableColumn.h:61
Class * _TableColumn(void)
The TableColumn archetype.
Definition: TableColumn.c:91
Header cells provide clickable sort handles for TableView instances.
TableCellView tableCellView
The superclass.
void setText(Text *self, const char *text)
Sets this Text's text.
Definition: Text.c:261
char * identifier
An optional identifier.
Definition: View.h:201