]> git.saurik.com Git - cydia.git/blob - CyteKit/ViewController.mm
WebDataSource needs to also be in iPhonePrivate.h.
[cydia.git] / CyteKit / ViewController.mm
1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include "CyteKit/UCPlatform.h"
23
24 #include <Foundation/Foundation.h>
25 #include <UIKit/UIKit.h>
26
27 #include "CyteKit/ViewController.h"
28
29 #include "iPhonePrivate.h"
30 #include <Menes/ObjectHandle.h>
31
32 @implementation UIViewController (Cydia)
33
34 - (BOOL) hasLoaded {
35 return YES;
36 }
37
38 - (void) reloadData {
39 [self view];
40 }
41
42 - (void) unloadData {
43 if (UIViewController *modal = [self modalViewController])
44 [modal unloadData];
45 }
46
47 - (UIViewController *) parentOrPresentingViewController {
48 if (UIViewController *parent = [self parentViewController])
49 return parent;
50 if ([self respondsToSelector:@selector(presentingViewController)])
51 return [self presentingViewController];
52 return nil;
53 }
54
55 - (UIViewController *) rootViewController {
56 UIViewController *base(self);
57 while ([base parentOrPresentingViewController] != nil)
58 base = [base parentOrPresentingViewController];
59 return base;
60 }
61
62 - (NSURL *) navigationURL {
63 return nil;
64 }
65
66 @end
67
68 @implementation CyteViewController {
69 _transient id delegate_;
70 BOOL loaded_;
71 _H<UIColor> color_;
72 }
73
74 - (void) setDelegate:(id)delegate {
75 delegate_ = delegate;
76 }
77
78 - (id) delegate {
79 return delegate_;
80 }
81
82 - (void) viewWillAppear:(BOOL)animated {
83 [super viewWillAppear:animated];
84
85 // Load on first appearance. We don't need to set the loaded flag here
86 // because it is set for us the first time -reloadData is called.
87 if (![self hasLoaded])
88 [self reloadData];
89 }
90
91 - (BOOL) hasLoaded {
92 return loaded_;
93 }
94
95 - (void) releaseSubviews {
96 loaded_ = NO;
97 }
98
99 - (void) setView:(UIView *)view {
100 // Nasty hack for 2.x-compatibility. In 3.0+, we can and
101 // should just override -viewDidUnload instead.
102 if (view == nil)
103 [self releaseSubviews];
104
105 [super setView:view];
106 }
107
108 - (void) reloadData {
109 [super reloadData];
110
111 // This is called automatically on the first appearance of a controller,
112 // or any other time it needs to reload the information shown. However (!),
113 // this is not called by any tab bar or navigation controller's -reloadData
114 // method unless this controller returns YES from -hadLoaded.
115 loaded_ = YES;
116 }
117
118 - (void) unloadData {
119 loaded_ = NO;
120 [super unloadData];
121 }
122
123 - (void) setPageColor:(UIColor *)color {
124 if (color == nil)
125 color = [UIColor groupTableViewBackgroundColor];
126 color_ = color;
127 }
128
129 - (UIColor *) pageColor {
130 return color_;
131 }
132
133 #include "InterfaceOrientation.h"
134
135 @end