ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Public Member Functions | Data Fields
ViewController Struct Reference

A ViewController manages a View and its descendants. More...

#include <ViewController.h>

Inheritance diagram for ViewController:
DebugViewController NavigationViewController TabViewController

Public Member Functions

Class * _ViewController (void)
 The ViewController archetype. More...
 
void addChildViewController (ViewController *self, ViewController *childViewController)
 Adds the specified child ViewController to this ViewController. More...
 
void handleNotification (ViewController *self, const Notification *notification)
 Handles a broadcast notification. More...
 
ViewControllerinit (ViewController *self)
 Initializes this ViewController. More...
 
void loadView (ViewController *self)
 Loads this ViewController's View. More...
 
void loadViewIfNeeded (ViewController *self)
 Loads this ViewController's View if it is not already loaded. More...
 
void moveToParentViewController (ViewController *self, ViewController *parentViewController)
 Moves this ViewController to the specified parent. More...
 
void removeChildViewController (ViewController *self, ViewController *childViewController)
 Removes the specified child ViewController from this ViewController. More...
 
void removeFromParentViewController (ViewController *self)
 Removes this ViewController from its parent. More...
 
void respondToEvent (ViewController *self, const SDL_Event *event)
 Responds to the given event. More...
 
void setView (ViewController *self, View *view)
 Sets this ViewController's View. More...
 
void viewDidAppear (ViewController *self)
 This method is invoked after this ViewController's View is added to the View hierarchy. More...
 
void viewDidDisappear (ViewController *self)
 This method is invoked after this ViewController's View is removed to the View hierarchy. More...
 
void viewWillAppear (ViewController *self)
 This method is invoked before this ViewController's View is added to the View hierarchy. More...
 
void viewWillDisappear (ViewController *self)
 This method is invoked before this ViewController's View is removed from the View hierarchy. More...
 

Data Fields

MutableArray * childViewControllers
 The child view controllers. More...
 
ViewControllerInterface * interface
 The interface. More...
 
Object object
 The superclass. More...
 
ViewControllerparentViewController
 The parent view controller. More...
 
Viewview
 The main view. More...
 

Detailed Description

A ViewController manages a View and its descendants.

Definition at line 53 of file ViewController.h.

Member Function Documentation

◆ _ViewController()

Class * _ViewController ( void  )

The ViewController archetype.

Returns
The ViewController Class.

Definition at line 305 of file ViewController.c.

305 {
306 static Class *clazz;
307 static Once once;
308
309 do_once(&once, {
310 clazz = _initialize(&(const ClassDef) {
311 .name = "ViewController",
312 .superclass = _Object(),
313 .instanceSize = sizeof(ViewController),
314 .interfaceOffset = offsetof(ViewController, interface),
315 .interfaceSize = sizeof(ViewControllerInterface),
317 });
318 });
319
320 return clazz;
321}
static void initialize(Class *clazz)
A ViewController manages a View and its descendants.
ViewControllerInterface * interface
The interface.

◆ addChildViewController()

void addChildViewController ( ViewController self,
ViewController childViewController 
)

Adds the specified child ViewController to this ViewController.

Parameters
selfThe ViewController.
childViewControllerThe child ViewController.

Definition at line 68 of file TabViewController.c.

68 {
69
70 super(ViewController, self, addChildViewController, childViewController);
71
72 TabViewController *this = (TabViewController *) self;
73
74 TabViewItem *tab = $(alloc(TabViewItem), initWithView, childViewController->view);
75
76 $(this->tabView, addTab, tab);
77
78 release(tab);
79}
static void addTab(TabView *self, TabViewItem *tab)
Definition: TabView.c:131
static TabViewItem * initWithView(TabViewItem *self, View *view)
Definition: TabViewItem.c:77
TabViewControllers arrange and manage their child ViewControllers in a tab view interface.
TabViewItems embed Views in a TabView.
Definition: TabViewItem.h:51
View * view
The main view.
void addChildViewController(ViewController *self, ViewController *childViewController)
Adds the specified child ViewController to this ViewController.

◆ handleNotification()

void handleNotification ( ViewController self,
const Notification notification 
)

Handles a broadcast notification.

Parameters
selfThe ViewController.
notificationThe Notification.
See also
MVC_PostNotification

Definition at line 90 of file ViewController.c.

90 {
91 $((Array *) self->childViewControllers, enumerateObjects, handleNotification_recurse, (ident) notification);
92}
static void handleNotification_recurse(const Array *array, ident obj, ident data)
ArrayEnumerator for handleNotification recursion.
MutableArray * childViewControllers
The child view controllers.

◆ init()

ViewController * init ( ViewController self)

Initializes this ViewController.

Parameters
selfThe ViewController.
Returns
The intialized ViewController, or NULL on error.

Definition at line 98 of file ViewController.c.

98 {
99
100 self = (ViewController *) super(Object, self, init);
101 if (self) {
102 self->childViewControllers = $$(MutableArray, arrayWithCapacity, 0);
103 assert(self->childViewControllers);
104 }
105
106 return self;
107}
ViewController * init(ViewController *self)
Initializes this ViewController.

◆ loadView()

void loadView ( ViewController self)

Loads this ViewController's View.

Parameters
selfThe ViewController.
Remarks
Override this method to populate this ViewController's view.

Definition at line 182 of file DebugViewController.c.

182 {
183
184 super(ViewController, self, loadView);
185
187
188 Outlet outlets[] = MakeOutlets(
189 MakeOutlet("statistics", &this->statistics),
190 MakeOutlet("description", &this->description),
191 MakeOutlet("path", &this->path),
192 MakeOutlet("selectors", &this->selectors),
193 MakeOutlet("computedStyle", &this->computedStyle),
194 MakeOutlet("warnings", &this->warnings)
195 );
196
197 View *view = $$(View, viewWithCharacters, (char *) debug_json, outlets);
198 view->stylesheet = $$(Stylesheet, stylesheetWithCharacters, (char *) debug_css);
199
200 $(self, setView, view);
201 release(view);
202
203 this->selectors->dataSource.self = self;
204 this->selectors->dataSource.numberOfRows = selectors_numberOfRows;
205 this->selectors->dataSource.valueForColumnAndRow = selectors_valueForColumnAndRow;
206 this->selectors->delegate.self = self;
207 this->selectors->delegate.cellForColumnAndRow = selectors_cellForColumnAndRow;
208
209 this->computedStyle->dataSource.self = self;
210 this->computedStyle->dataSource.numberOfRows = computedStyle_numberOfRows;
211 this->computedStyle->dataSource.valueForColumnAndRow = computedStyle_valueForColumnAndRow;
212 this->computedStyle->delegate.self = self;
213 this->computedStyle->delegate.cellForColumnAndRow = computedStyle_cellForColumnAndRow;
214
215 this->warnings->dataSource.self = self;
216 this->warnings->dataSource.numberOfRows = warnings_numberOfRows;
217 this->warnings->dataSource.valueForColumnAndRow = warnings_valueForColumnAndRow;
218 this->warnings->delegate.self = self;
219 this->warnings->delegate.cellForColumnAndRow = warnings_cellForColumnAndRow;
220}
static TableCellView * selectors_cellForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static ident warnings_valueForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static ident computedStyle_valueForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static TableCellView * warnings_cellForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static size_t computedStyle_numberOfRows(const TableView *tableView)
static TableCellView * computedStyle_cellForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static size_t selectors_numberOfRows(const TableView *tableView)
static ident selectors_valueForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static size_t warnings_numberOfRows(const TableView *tableView)
static String * description(const Object *self)
Definition: Label.c:47
static Stylesheet * stylesheetWithCharacters(const char *chars)
Definition: Stylesheet.c:206
#define MakeOutlet(identifier, view)
Creates an Outlet with the specified parameters.
Definition: View+JSON.h:230
#define MakeOutlets(...)
Creates a NULL-termianted array of Outlets.
Definition: View+JSON.h:235
static String * path(const View *self)
Definition: View.c:1091
static View * viewWithCharacters(const char *chars, Outlet *outlets)
Definition: View.c:1558
The DebugViewController type.
Outlets enable outbound data binding of Views through JSON.
Definition: View+JSON.h:200
Stylesheets are comprised of Selectors and Styles.
Definition: Stylesheet.h:44
void loadView(ViewController *self)
Loads this ViewController's View.
void setView(ViewController *self, View *view)
Sets this ViewController's View.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
Stylesheet * stylesheet
An optional Stylesheet.
Definition: View.h:247

◆ loadViewIfNeeded()

void loadViewIfNeeded ( ViewController self)

Loads this ViewController's View if it is not already loaded.

Parameters
selfThe ViewController.

Definition at line 128 of file ViewController.c.

128 {
129
130 if (self->view == NULL) {
131 $(self, loadView);
132 }
133
134 assert(self->view);
135}

◆ moveToParentViewController()

void moveToParentViewController ( ViewController self,
ViewController parentViewController 
)

Moves this ViewController to the specified parent.

Parameters
selfThe ViewController.
parentViewControllerThe parent ViewController, or NULL.

Definition at line 141 of file ViewController.c.

141 {
142
143 ViewController *this = retain(self);
144
146
149 }
150
151 release(this);
152}
void removeFromParentViewController(ViewController *self)
Removes this ViewController from its parent.
ViewController * parentViewController
The parent view controller.

◆ removeChildViewController()

void removeChildViewController ( ViewController self,
ViewController childViewController 
)

Removes the specified child ViewController from this ViewController.

Parameters
selfThe ViewController.
childViewControllerThe child ViewController.

Definition at line 84 of file TabViewController.c.

84 {
85
86 super(ViewController, self, removeChildViewController, childViewController);
87
88 TabViewController *this = (TabViewController *) self;
89
90 TabViewItem *tab = $(this, tabForViewController, childViewController);
91
92 $(this->tabView, removeTab, tab);
93}
static void removeTab(TabView *self, TabViewItem *tab)
Definition: TabView.c:181
static TabViewItem * tabForViewController(const TabViewController *self, const ViewController *viewController)
void removeChildViewController(ViewController *self, ViewController *childViewController)
Removes the specified child ViewController from this ViewController.

◆ removeFromParentViewController()

void removeFromParentViewController ( ViewController self)

Removes this ViewController from its parent.

Parameters
selfThe ViewController.

Definition at line 179 of file ViewController.c.

179 {
180
181 if (self->parentViewController) {
183 }
184}

◆ respondToEvent()

void respondToEvent ( ViewController self,
const SDL_Event *  event 
)

Responds to the given event.

Parameters
selfThe ViewController.
eventThe event.

Definition at line 190 of file ViewController.c.

190 {
191
192}

◆ setView()

void setView ( ViewController self,
View view 
)

Sets this ViewController's View.

Parameters
selfThe ViewController.
viewThe View.

Definition at line 198 of file ViewController.c.

198 {
199
200 if (view != self->view) {
201
202 if (self->view) {
203 self->view->viewController = NULL;
204 release(self->view);
205 }
206
207 if (view) {
208 self->view = retain(view);
209 self->view->viewController = self;
210 } else {
211 self->view = NULL;
212 }
213 }
214}
ViewController * viewController
The ViewController.
Definition: View.h:264

◆ viewDidAppear()

void viewDidAppear ( ViewController self)

This method is invoked after this ViewController's View is added to the View hierarchy.

Parameters
selfThe ViewController.
Remarks
The default implementation of this method does nothing.

Definition at line 227 of file ViewController.c.

227 {
228 $((Array *) self->childViewControllers, enumerateObjects, viewDidAppear_recurse, NULL);
229}
static void viewDidAppear_recurse(const Array *array, ident obj, ident data)
ArrayEnumerator for viewDidAppear recursion.

◆ viewDidDisappear()

void viewDidDisappear ( ViewController self)

This method is invoked after this ViewController's View is removed to the View hierarchy.

Parameters
selfThe ViewController.
Remarks
The default implementation of this method does nothing.

Definition at line 242 of file ViewController.c.

242 {
243 $((Array *) self->childViewControllers, enumerateObjects, viewDidDisappear_recurse, NULL);
244}
static void viewDidDisappear_recurse(const Array *array, ident obj, ident data)
ArrayEnumerator for viewDidDisappear recursion.

◆ viewWillAppear()

void viewWillAppear ( ViewController self)

This method is invoked before this ViewController's View is added to the View hierarchy.

Parameters
selfThe ViewController.
Remarks
The default implementation of this method does nothing.

Definition at line 257 of file ViewController.c.

257 {
258 $((Array *) self->childViewControllers, enumerateObjects, viewWillAppear_recurse, NULL);
259}
static void viewWillAppear_recurse(const Array *array, ident obj, ident data)
ArrayEnumerator for viewWillAppear recursion.

◆ viewWillDisappear()

void viewWillDisappear ( ViewController self)

This method is invoked before this ViewController's View is removed from the View hierarchy.

Parameters
selfThe ViewController.
Remarks
The default implementation of this method does nothing.

Definition at line 272 of file ViewController.c.

272 {
273 $((Array *) self->childViewControllers, enumerateObjects, viewWillDisappear_recurse, NULL);
274}
static void viewWillDisappear_recurse(const Array *array, ident obj, ident data)
ArrayEnumerator for viewWillDisappear recursion.

Field Documentation

◆ childViewControllers

MutableArray* ViewController::childViewControllers

The child view controllers.

Definition at line 68 of file ViewController.h.

◆ interface

ViewControllerInterface* ViewController::interface

The interface.

Definition at line 63 of file ViewController.h.

◆ object

Object ViewController::object

The superclass.

Definition at line 58 of file ViewController.h.

◆ parentViewController

ViewController* ViewController::parentViewController

The parent view controller.

Definition at line 78 of file ViewController.h.

◆ view

View* ViewController::view

The main view.

Definition at line 73 of file ViewController.h.


The documentation for this struct was generated from the following files: