1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
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.
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.
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/>.
22 #include "CyteKit/UCPlatform.h"
24 #include "CyteKit/TabBarController.h"
26 #include "iPhonePrivate.h"
27 #include <Menes/ObjectHandle.h>
29 @implementation CyteTabBarController {
30 _transient UIViewController *transient_;
31 _H<UIViewController> remembered_;
34 - (NSArray *) navigationURLCollection {
35 NSMutableArray *items([NSMutableArray array]);
37 // XXX: Should this deal with transient view controllers?
38 for (id navigation in [self viewControllers]) {
39 NSArray *stack = [navigation performSelector:@selector(navigationURLCollection)];
41 [items addObject:stack];
47 - (void) addViewControllers:(id)no, ... {
51 NSMutableArray *controllers([NSMutableArray array]);
54 auto title(va_arg(args, NSString *));
58 UINavigationController *controller([[[UINavigationController alloc] init] autorelease]);
59 [controllers addObject:controller];
61 auto legacy(va_arg(args, NSString *));
62 auto normal(va_arg(args, NSString *));
63 auto select(va_arg(args, NSString *));
65 if (kCFCoreFoundationVersionNumber < 800)
66 [controller setTabBarItem:[[[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:legacy] tag:0] autorelease]];
68 [controller setTabBarItem:[[[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:normal] selectedImage:[UIImage imageNamed:select]] autorelease]];
73 [self setViewControllers:controllers];
76 - (void) didReceiveMemoryWarning {
77 [super didReceiveMemoryWarning];
79 // presenting a UINavigationController on 2.x does not update its transitionView
80 // it thereby will not allow its topViewController to be unloaded by memory pressure
81 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
82 UIViewController *selected([self selectedViewController]);
83 for (UINavigationController *controller in [self viewControllers])
84 if (controller != selected)
85 if (UIViewController *top = [controller topViewController])
90 - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
91 if ([self unselectedViewController])
92 [self setUnselectedViewController:nil];
94 // presenting a UINavigationController on 2.x does not update its transitionView
95 // if this view was unloaded, the tranitionView may currently be presenting nothing
96 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
97 UINavigationController *navigation((UINavigationController *) viewController);
98 [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
99 [navigation popViewControllerAnimated:NO];
103 - (void) dismissModalViewControllerAnimated:(BOOL)animated {
104 if ([self modalViewController] == nil && [self unselectedViewController] != nil)
105 [self setUnselectedViewController:nil];
107 [super dismissModalViewControllerAnimated:YES];
110 - (void) setUnselectedViewController:(UIViewController *)transient {
111 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
112 if (transient != nil) {
113 [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
114 [self setSelectedIndex:0];
118 NSMutableArray *controllers = [[[self viewControllers] mutableCopy] autorelease];
119 if (transient != nil) {
120 UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
121 [navigation setViewControllers:[NSArray arrayWithObject:transient]];
122 transient = navigation;
124 if (transient_ == nil)
125 remembered_ = [controllers objectAtIndex:0];
126 transient_ = transient;
127 [transient_ setTabBarItem:[remembered_ tabBarItem]];
128 [controllers replaceObjectAtIndex:0 withObject:transient_];
129 [self setSelectedIndex:0];
130 [self setViewControllers:controllers];
131 [self concealTabBarSelection];
132 } else if (remembered_ != nil) {
133 [remembered_ setTabBarItem:[transient_ tabBarItem]];
134 transient_ = transient;
135 [controllers replaceObjectAtIndex:0 withObject:remembered_];
137 [self setViewControllers:controllers];
138 [self revealTabBarSelection];
142 - (UIViewController *) unselectedViewController {
146 - (void) unloadData {
149 for (UINavigationController *controller in [self viewControllers])
150 [controller unloadData];
152 if (UIViewController *selected = [self selectedViewController])
153 [selected reloadData];
155 if (UIViewController *unselected = [self unselectedViewController]) {
156 [unselected unloadData];
157 [unselected reloadData];
161 #include "InterfaceOrientation.h"