summaryrefslogtreecommitdiff
path: root/UICaboodle
diff options
context:
space:
mode:
authorGrant Paul <chpwn@chpwn.com>2010-09-21 10:53:41 +0000
committerJay Freeman (saurik) <saurik@saurik.com>2010-09-30 10:42:31 +0000
commitb5e7eebb25026afcb8052552a5fedb7984c08a38 (patch)
tree904c8b45935bae94a1d40a3ffe91b8e4e0549573 /UICaboodle
parentdf86a2c8189742f00ba09e75b77b6f0cc7eb1824 (diff)
Commit (chpwn): uiviewcontroller-final.patch
Diffstat (limited to 'UICaboodle')
-rw-r--r--UICaboodle/BrowserView.h14
-rw-r--r--UICaboodle/BrowserView.mm175
-rw-r--r--UICaboodle/RVBook.h74
-rw-r--r--UICaboodle/RVBook.mm316
-rw-r--r--UICaboodle/RVPage.h40
-rw-r--r--UICaboodle/RVPage.mm80
6 files changed, 121 insertions, 578 deletions
diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h
index 4d30ef7..69d0bfc 100644
--- a/UICaboodle/BrowserView.h
+++ b/UICaboodle/BrowserView.h
@@ -40,12 +40,10 @@
@end
@protocol BrowserViewDelegate
-- (RVPage *) pageForURL:(NSURL *)url hasTag:(int *)tag;
+- (UCViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag;
@end
-@interface BrowserView : RVPage <
- RVBookHook
-> {
+@interface BrowserView : UCViewController {
UIScroller *scroller_;
UIWebDocumentView *document_;
UIProgressIndicator *indicator_;
@@ -96,9 +94,9 @@
- (WebView *) webView;
- (UIWebDocumentView *) documentView;
-- (id) initWithBook:(RVBook *)book;
-- (id) initWithBook:(RVBook *)book forWidth:(float)width;
-- (id) initWithBook:(RVBook *)book forWidth:(float)width ofClass:(Class)_class;
+- (id) init;
+- (id) initWithWidth:(float)width;
+- (id) initWithWidth:(float)width ofClass:(Class)_class;
- (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *)script;
- (void) callFunction:(WebScriptObject *)function;
@@ -121,4 +119,4 @@
- (bool) promptForSensitive:(NSString *)name;
- (bool) allowSensitiveRequests;
-@end
+@end \ No newline at end of file
diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm
index caa2ba2..9bfeb79 100644
--- a/UICaboodle/BrowserView.mm
+++ b/UICaboodle/BrowserView.mm
@@ -149,7 +149,7 @@ static Class $UIWebBrowserView;
@end
#define ShowInternals 0
-#define LogBrowser 0
+#define LogBrowser 1
#define lprintf(args...) fprintf(stderr, args)
@@ -160,7 +160,7 @@ static Class $UIWebBrowserView;
#endif
+ (void) _initialize {
- [WebView enableWebThread];
+ //[WebView enableWebThread];
WebPreferences *preferences([WebPreferences standardPreferences]);
[preferences setCacheModel:WebCacheModelDocumentBrowser];
@@ -311,7 +311,7 @@ static Class $UIWebBrowserView;
/* XXX: WebThreadLock? */
- (void) _fixScroller:(CGRect)bounds {
- float extra;
+ float extra;
if (!editing_ || $UIFormAssistant == nil)
extra = 0;
@@ -360,10 +360,10 @@ static Class $UIWebBrowserView;
[self view:sender didSetFrame:frame];
}
-- (void) pushPage:(RVPage *)page {
+- (void) pushPage:(UCViewController *)page {
[page setDelegate:delegate_];
- [self setBackButtonTitle:title_];
- [book_ pushPage:page];
+ [[self navigationItem] setTitle:title_];
+ [[self navigationController] pushViewController:page animated:YES];
}
- (void) _pushPage {
@@ -371,15 +371,14 @@ static Class $UIWebBrowserView;
return;
// WTR: [self autorelease];
pushed_ = true;
- [book_ pushPage:self];
+ [[self navigationController] pushViewController:self animated:YES];
}
-- (void) swapPage:(RVPage *)page {
+- (void) swapPage:(UCViewController *)page {
[page setDelegate:delegate_];
- if (pushed_)
- [book_ swapPage:page];
- else
- [book_ pushPage:page];
+ if (pushed_) [[self navigationController] popViewControllerAnimated:NO];
+
+ [[self navigationController] pushViewController:page animated:NO];
}
- (BOOL) getSpecial:(NSURL *)url swap:(BOOL)swap {
@@ -387,7 +386,7 @@ static Class $UIWebBrowserView;
NSLog(@"getSpecial:%@", url);
#endif
- if (RVPage *page = [delegate_ pageForURL:url hasTag:NULL]) {
+ if (UCViewController *page = [delegate_ pageForURL:url hasTag:NULL]) {
if (swap)
[self swapPage:page];
else
@@ -532,7 +531,7 @@ static Class $UIWebBrowserView;
[function_ autorelease];
function_ = function == nil ? nil : [function retain];
- [self reloadButtons];
+ [self reloadButtons];
}
- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
@@ -548,7 +547,7 @@ static Class $UIWebBrowserView;
[function_ autorelease];
function_ = function == nil ? nil : [function retain];
- [self reloadButtons];
+ [self reloadButtons];
}
- (void) setFinishHook:(id)function {
@@ -581,11 +580,11 @@ static Class $UIWebBrowserView;
}
- (void) webViewClose:(WebView *)sender {
- [book_ close];
+ [self close];
}
- (void) close {
- [book_ close];
+ [[self navigationController] dismissModalViewControllerAnimated:YES];
}
- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
@@ -615,25 +614,32 @@ static Class $UIWebBrowserView;
if ([scheme isEqualToString:@"mailto"])
[self _openMailToURL:url];
else {
- RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
- [book setHook:indirect_];
+ UCNavigationController *navigation([[[UCNavigationController alloc] init] autorelease]);
+ [navigation setHook:indirect_];
- RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
+ UCViewController *page([delegate_ pageForURL:url hasTag:NULL]);
if (page == nil) {
/* XXX: call createWebViewWithRequest instead? */
- [self setBackButtonTitle:title_];
-
- BrowserView *browser([[[class_ alloc] initWithBook:book] autorelease]);
+ BrowserView *browser([[[class_ alloc] init] autorelease]);
[browser loadURL:url];
page = browser;
}
- [book setDelegate:delegate_];
+ [navigation setDelegate:delegate_];
[page setDelegate:delegate_];
- [book setPage:page];
- [book_ pushBook:book];
+ [navigation setViewControllers:[NSArray arrayWithObject:page]];
+ UIBarButtonItem *closeItem = [[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("CLOSE")
+ style:UIBarButtonItemStylePlain
+ target:page
+ action:@selector(close)
+ ];
+ [[page navigationItem] setLeftBarButtonItem:closeItem];
+ [closeItem release];
+
+ [[self navigationController] presentModalViewController:navigation animated:YES];
}
} else goto unknown;
@@ -881,25 +887,34 @@ static Class $UIWebBrowserView;
NSNumber *value([features objectForKey:@"width"]);
float width(value == nil ? 0 : [value floatValue]);
- RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
+ UCNavigationController *navigation(!popup_ ? [self navigationController] : [[[UCNavigationController alloc] init] autorelease]);
/* XXX: deal with cydia:// pages */
- BrowserView *browser([[[class_ alloc] initWithBook:book forWidth:width] autorelease]);
+ BrowserView *browser([[[class_ alloc] initWithWidth:width] autorelease]);
if (features != nil && popup_) {
- [book setDelegate:delegate_];
- [book setHook:indirect_];
+ [navigation setDelegate:delegate_];
+ [navigation setHook:indirect_];
[browser setDelegate:delegate_];
[browser loadRequest:request];
- [book setPage:browser];
- [book_ pushBook:book];
- } else if (request == nil) {
- [self setBackButtonTitle:title_];
+ [navigation setViewControllers:[NSArray arrayWithObject:browser]];
+ UIBarButtonItem *closeItem = [[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("CLOSE")
+ style:UIBarButtonItemStylePlain
+ target:browser
+ action:@selector(close)
+ ];
+ [[browser navigationItem] setLeftBarButtonItem:closeItem];
+ [closeItem release];
+
+ [[self navigationController] presentModalViewController:navigation animated:YES];
+ } /*else if (request == nil) {
+ [[self navigationItem] setTitle:title_];
[browser setDelegate:delegate_];
[browser retain];
- } else {
+ }*/ else {
[self pushPage:browser];
[browser loadRequest:request];
}
@@ -917,7 +932,7 @@ static Class $UIWebBrowserView;
return;
title_ = [title retain];
- [book_ reloadTitleForPage:self];
+ [[self navigationItem] setTitle:title_];
}
- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
@@ -965,7 +980,7 @@ static Class $UIWebBrowserView;
special_ = nil;
}
- [book_ reloadTitleForPage:self];
+ [[self navigationItem] setTitle:title_];
if (Wildcat_) {
CGRect webrect = [scroller_ bounds];
@@ -992,9 +1007,11 @@ static Class $UIWebBrowserView;
}
}
- [self reloadButtons];
+ [self reloadButtons];
}
+- (void) didFinishLoading { }
+
- (void) _finishLoading {
size_t count([loading_ count]);
/*if (count == 0)
@@ -1003,21 +1020,14 @@ static Class $UIWebBrowserView;
return;
if (finish_ != nil)
[self callFunction:finish_];
- [self reloadButtons];
+
+ [self reloadButtons];
}
- (bool) isLoading {
return [loading_ count] != 0;
}
-- (void) reloadButtons {
- if ([self isLoading])
- [indicator_ startAnimation];
- else
- [indicator_ stopAnimation];
- [super reloadButtons];
-}
-
- (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
return [document_ webView:sender shouldScrollToPoint:point forFrame:frame];
}
@@ -1242,16 +1252,16 @@ static Class $UIWebBrowserView;
[self _setTileDrawingEnabled:YES];
}
-- (id) initWithBook:(RVBook *)book forWidth:(float)width ofClass:(Class)_class {
- if ((self = [super initWithBook:book]) != nil) {
+- (id) initWithWidth:(float)width ofClass:(Class)_class {
+ if ((self = [super init]) != nil) {
class_ = _class;
loading_ = [[NSMutableSet alloc] initWithCapacity:3];
popup_ = false;
- struct CGRect bounds = [self bounds];
+ struct CGRect bounds = [[self view] bounds];
scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds];
- [self addSubview:scroller_];
+ [[self view] addSubview:scroller_];
[scroller_ setFixedBackgroundPattern:YES];
[scroller_ setBackgroundColor:[UIColor pinStripeColor]];
@@ -1395,26 +1405,26 @@ static Class $UIWebBrowserView;
WebThreadUnlock();
CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
- indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(bounds.size.width - 39, 12, indsize.width, indsize.height)];
+ indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)];
[indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
+ [indicator_ startAnimation];
- [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[document_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
- /*UIWebView *test([[[UIWebView alloc] initWithFrame:[self bounds]] autorelease]);
+ /*UIWebView *test([[[UIWebView alloc] initWithFrame:[[self view] bounds]] autorelease]);
[test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];
- [self addSubview:test];*/
+ [[self view] addSubview:test];*/
} return self;
}
-- (id) initWithBook:(RVBook *)book forWidth:(float)width {
- return [self initWithBook:book forWidth:width ofClass:[self class]];
+- (id) initWithWidth:(float)width {
+ return [self initWithWidth:width ofClass:[self class]];
}
-- (id) initWithBook:(RVBook *)book {
- return [self initWithBook:book forWidth:0];
+- (id) init {
+ return [self initWithWidth:0];
}
- (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *)script {
@@ -1443,7 +1453,7 @@ static Class $UIWebBrowserView;
settings->setJavaScriptCanOpenWindowsAutomatically(true);
}
- if (UIWindow *window = [self window])
+ if (UIWindow *window = [[self view] window])
if (UIResponder *responder = [window firstResponder])
[responder resignFirstResponder];
@@ -1457,7 +1467,7 @@ static Class $UIWebBrowserView;
WebThreadUnlock();
}
-- (void) didCloseBook:(RVBook *)book {
+- (void) didDismissModalViewController {
if (closer_ != nil)
[self callFunction:closer_];
}
@@ -1476,14 +1486,6 @@ static Class $UIWebBrowserView;
[self __rightButtonClicked];
}
-- (id) _rightButtonTitle {
- return UCLocalize("RELOAD");
-}
-
-- (id) rightButtonTitle {
- return [self isLoading] ? @"" : button_ != nil ? button_ : [self _rightButtonTitle];
-}
-
- (UINavigationButtonStyle) rightButtonStyle {
if (style_ == nil) normal:
return UINavigationButtonStyleNormal;
@@ -1498,19 +1500,38 @@ static Class $UIWebBrowserView;
else goto normal;
}
-- (NSString *) title {
- return title_ == nil ? UCLocalize("LOADING") : title_;
-}
-
-- (NSString *) backButtonTitle {
- return UCLocalize("BROWSER");
+- (void) reloadButtons {
+ if ([self isLoading]) {
+ UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc]
+ initWithTitle:@" "
+ style:UIBarButtonItemStylePlain
+ target:self
+ action:@selector(_rightButtonClicked)
+ ];
+ [[self navigationItem] setRightBarButtonItem:reloadItem];
+ [[reloadItem view] addSubview:indicator_];
+ [[self navigationItem] setTitle:UCLocalize("LOADING")];
+ [reloadItem release];
+ } else {
+ UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc]
+ initWithTitle:button_ ?: UCLocalize("RELOAD")
+ style:[self rightButtonStyle]
+ target:self
+ action:@selector(_rightButtonClicked)
+ ];
+ [[self navigationItem] setRightBarButtonItem:reloadItem animated:YES];
+ [[self navigationItem] setTitle:title_];
+ [reloadItem release];
+
+ if (function_ == nil) [self didFinishLoading];
+ }
}
- (void) setPageActive:(BOOL)active {
if (!active)
[indicator_ removeFromSuperview];
else
- [[book_ navigationBar] addSubview:indicator_];
+ [[[[self navigationItem] rightBarButtonItem] view] addSubview:indicator_];
}
- (void) resetViewAnimated:(BOOL)animated {
@@ -1524,4 +1545,4 @@ static Class $UIWebBrowserView;
return 980;
}
-@end
+@end \ No newline at end of file
diff --git a/UICaboodle/RVBook.h b/UICaboodle/RVBook.h
index 376a153..b605cc6 100644
--- a/UICaboodle/RVBook.h
+++ b/UICaboodle/RVBook.h
@@ -2,80 +2,10 @@
#import <UIKit/UIKit.h>
-@class NSMutableArray;
-@class RVBook;
-@class RVPage;
-@class UINavigationBar;
-@class UITransitionView;
-
-@interface UIView (PopUpView)
-- (void) popFromSuperviewAnimated:(BOOL)animated;
-- (void) popSubview:(UIView *)view;
-@end
-
-@protocol RVNavigationBarDelegate
-@end
-
-@protocol RVDelegate
-- (void) setPageActive:(BOOL)active with:(id)object;
-- (void) resetViewAnimated:(BOOL)animated with:(id)object;
-- (void) reloadDataWith:(id)object;
-- (void) popUpBook:(RVBook *)book;
-- (CGRect) popUpBounds;
-@end
-
-@protocol RVBookHook
-- (void) didCloseBook:(RVBook *)book;
-@end
-
-@interface RVBook : UIView <
- RVNavigationBarDelegate
-> {
- NSMutableArray *pages_;
- UINavigationBar *navbar_;
- UITransitionView *transition_;
- BOOL resetting_;
- _transient id delegate_;
- _transient id hook_;
- UIToolbar *toolbar_;
+@interface UCNavigationController : UINavigationController {
+ id hook_;
}
-
-- (UINavigationBar *) navigationBar;
-
-- (id) initWithFrame:(CGRect)frame;
-- (void) setDelegate:(id)delegate;
- (void) setHook:(id)hook;
-
-- (void) setPage:(RVPage *)page;
-
-- (void) swapPage:(RVPage *)page;
-
-- (void) pushPage:(RVPage *)page animated:(BOOL)animated;
-- (void) pushPage:(RVPage *)page;
-
-- (void) popPages:(unsigned)pages;
-
-- (void) pushBook:(RVBook *)book;
-
-- (void) resetViewAnimated:(BOOL)animated;
-- (void) resetViewAnimated:(BOOL)animated toPage:(RVPage *)page;
-
-- (void) setBackButtonTitle:(NSString *)title forPage:(RVPage *)page;
-- (void) reloadTitleForPage:(RVPage *)page;
-- (void) reloadButtonsForPage:(RVPage *)page;
-- (NSString *) getTitleForPage:(RVPage *)page;
-
-- (void) reloadButtons;
-- (void) reloadData;
-
-- (CGRect) pageBounds;
-- (void) close;
-
@end
-@interface RVPopUpBook : RVBook {
- _transient RVBook *parent_;
- bool cancel_;
-}
-@end
diff --git a/UICaboodle/RVBook.mm b/UICaboodle/RVBook.mm
index 3fd525e..2271cee 100644
--- a/UICaboodle/RVBook.mm
+++ b/UICaboodle/RVBook.mm
@@ -18,321 +18,17 @@
#import "RVPage.h"
-@interface NSObject (UICaboodleRVBook)
-- (float) widthForButtonContents:(float)width;
-@end
-
-@implementation NSObject (UICaboodleRVBook)
-
-- (float) widthForButtonContents:(float)width {
- return width;
-}
-
-@end
-
-@interface UIImage (UICaboodleRVBook)
-- (float) widthForButtonContents:(float)width;
-@end
-
-@implementation UIImage (UICaboodleRVBook)
-
-- (float) widthForButtonContents:(float)width {
- return [self size].width + 8;
-}
-
-@end
-
-@interface RVNavigationBar : UINavigationBar {
-}
-
-- (id) createButtonWithContents:(id)contents width:(float)width barStyle:(int)barStyle buttonStyle:(int)style isRight:(BOOL)right;
-@end
-
-@implementation RVNavigationBar
-
-- (id) createButtonWithContents:(id)contents width:(float)width barStyle:(int)barStyle buttonStyle:(int)style isRight:(BOOL)right {
- float adjust = [contents widthForButtonContents:width];
- width = adjust;
- return [super createButtonWithContents:contents width:width barStyle:barStyle buttonStyle:style isRight:right];
-}
-
-@end
-
-@implementation RVBook
-
-- (void) dealloc {
- [navbar_ setDelegate:nil];
- if (toolbar_ != nil)
- [toolbar_ setDelegate:nil];
-
- for (RVPage *page in pages_)
- [page setBook:nil];
-
- [pages_ release];
- [navbar_ release];
- [transition_ release];
- if (toolbar_ != nil)
- [toolbar_ release];
- [super dealloc];
-}
-
-- (UINavigationBar *) navigationBar {
- return navbar_;
-}
-
-- (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button {
- _assert([pages_ count] != 0);
- RVPage *page = [pages_ lastObject];
- switch (button) {
- case 0: [page _rightButtonClicked]; break;
- case 1: [page _leftButtonClicked]; break;
- }
-}
-
-- (void) navigationBar:(UINavigationBar *)navbar poppedItem:(UINavigationItem *)item {
- _assert([pages_ count] != 0);
- if (!resetting_)
- [[pages_ lastObject] setPageActive:NO];
- [pages_ removeLastObject];
- if (!resetting_)
- [self resetViewAnimated:YES toPage:[pages_ lastObject]];
-}
-
-- (id) initWithFrame:(CGRect)frame {
- if ((self = [super initWithFrame:frame]) != nil) {
- pages_ = [[NSMutableArray arrayWithCapacity:4] retain];
-
- struct CGRect bounds = [self bounds];
- CGSize navsize = [UINavigationBar defaultSize];
- CGRect navrect = {{0, 0}, {bounds.size.width, navsize.height}};
-
- navbar_ = [[RVNavigationBar alloc] initWithFrame:navrect];
- [navbar_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
- [self addSubview:navbar_];
-
- [navbar_ setBarStyle:0];
- [navbar_ setDelegate:self];
-
- transition_ = [[UITransitionView alloc] initWithFrame:CGRectMake(
- bounds.origin.x, bounds.origin.y + navsize.height, bounds.size.width, bounds.size.height - navsize.height
- )];
-
- [transition_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
- [self addSubview:transition_];
- } return self;
-}
-
-- (void) setDelegate:(id)delegate {
- delegate_ = delegate;
-}
+@implementation UCNavigationController
- (void) setHook:(id)hook {
- hook_ = hook;
-}
-
-- (void) setPage:(RVPage *)page {
- if ([pages_ count] != 0)
- [[pages_ lastObject] setPageActive:NO];
-
- [navbar_ disableAnimation];
- resetting_ = true;
- for (unsigned i(0), pages([pages_ count]); i != pages; ++i)
- [navbar_ popNavigationItem];
- resetting_ = false;
-
- [self pushPage:page];
- [navbar_ enableAnimation];
-}
-
-- (void) swapPage:(RVPage *)page {
- if ([pages_ count] == 0)
- return [self pushPage:page];
-
- [[pages_ lastObject] setPageActive:NO];
-
- [navbar_ disableAnimation];
- resetting_ = true;
- [navbar_ popNavigationItem];
- resetting_ = false;
-
- [self pushPage:page animated:NO];
- [navbar_ enableAnimation];
+ hook_ = hook;
}
+- (void) dismissModalViewControllerAnimated:(BOOL)animated {
+ [super dismissModalViewControllerAnimated:YES];
-- (void) pushPage:(RVPage *)page animated:(BOOL)animated {
- NSString *title = [self getTitleForPage:page];
-
- NSString *backButtonTitle = [page backButtonTitle];
- if (backButtonTitle == nil)
- backButtonTitle = title;
-
- UINavigationItem *navitem = [[[UINavigationItem alloc] initWithTitle:title] autorelease];
- [navitem setBackButtonTitle:backButtonTitle];
- [navbar_ pushNavigationItem:navitem];
-
- [page setFrame:[transition_ bounds]];
- [transition_ transition:(animated ? 1 : 0) toView:page];
- [page setPageActive:YES];
-
- [pages_ addObject:page];
- [self reloadButtonsForPage:page];
-
- if ([navbar_ respondsToSelector:@selector(setAccessoryView:animate:removeOnPop:)])
- [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
- else
- [navbar_ setAccessoryView:[page accessoryView] animate:animated];
-}
-
-- (void) pushPage:(RVPage *)page {
- if ([pages_ count] != 0)
- [[pages_ lastObject] setPageActive:NO];
- [self pushPage:page animated:([pages_ count] == 0 ? NO : YES)];
-}
-
-- (void) pushBook:(RVBook *)book {
- [delegate_ popUpBook:book];
-}
-
-- (void) popPages:(unsigned)pages {
- if (pages == 0)
- return;
-
- [[pages_ lastObject] setPageActive:NO];
-
- resetting_ = true;
- for (unsigned i(0); i != pages; ++i)
- [navbar_ popNavigationItem];
- resetting_ = false;
-
- [self resetViewAnimated:YES toPage:[pages_ lastObject]];
-}
-
-- (void) resetViewAnimated:(BOOL)animated {
- resetting_ = true;
-
- if ([pages_ count] > 1) {
- [navbar_ disableAnimation];
- while ([pages_ count] != (animated ? 2 : 1))
- [navbar_ popNavigationItem];
- [navbar_ enableAnimation];
- if (animated)
- [navbar_ popNavigationItem];
- }
-
- resetting_ = false;
-
- [self resetViewAnimated:animated toPage:[pages_ lastObject]];
-}
-
-- (void) resetViewAnimated:(BOOL)animated toPage:(RVPage *)page {
- [page resetViewAnimated:animated];
- [page setFrame:[transition_ bounds]];
- [transition_ transition:(animated ? 2 : 0) toView:page];
- [page setPageActive:YES];
- [self reloadButtonsForPage:page];
-
- if ([navbar_ respondsToSelector:@selector(setAccessoryView:animate:removeOnPop:)])
- [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
- else
- [navbar_ setAccessoryView:[page accessoryView] animate:animated];
-}
-
-- (void) setBackButtonTitle:(NSString *)title forPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- UINavigationItem *navitem = [navbar_ topItem];
- [navitem setBackButtonTitle:title];
-}
-
-- (void) reloadTitleForPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- UINavigationItem *navitem = [navbar_ topItem];
- NSString *title = [self getTitleForPage:page];
- [navitem setTitle:title];
+ if (hook_ != nil)
+ [hook_ didDismissModalViewController];
}
-
-- (void) _leftButtonTitle:(NSString *&)leftButtonTitle style:(UINavigationButtonStyle &)leftButtonStyle forPage:(RVPage *)page {
- leftButtonTitle = [page leftButtonTitle];
- leftButtonStyle = [page leftButtonStyle];
-}
-
-- (void) reloadButtonsForPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
-
- NSString *leftButtonTitle;
- UINavigationButtonStyle leftButtonStyle;
- [self _leftButtonTitle:leftButtonTitle style:leftButtonStyle forPage:page];
-
- UINavigationButtonStyle rightButtonStyle = [page rightButtonStyle];
- //[navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle] leftBack:(leftButtonTitle == nil)];
-
- [navbar_
- showLeftButton:leftButtonTitle
- withStyle:leftButtonStyle
- rightButton:[page rightButtonTitle]
- withStyle:rightButtonStyle
- ];
-}
-
-- (NSString *) getTitleForPage:(RVPage *)page {
- return [page title];
-}
-
-- (void) reloadData {
- size_t count([pages_ count]);
- for (size_t i(0); i != count; ++i) {
- RVPage *page([pages_ objectAtIndex:(count - i - 1)]);
- [page reloadData];
- }
-
- if (count != 0) {
- RVPage *page([pages_ lastObject]);
- [self reloadButtonsForPage:page];
- }
-}
-
-- (void) reloadButtons {
- size_t count([pages_ count]);
- if (count != 0) {
- RVPage *page([pages_ lastObject]);
- [self reloadButtonsForPage:page];
- }
-}
-
-- (CGRect) pageBounds {
- return [transition_ bounds];
-}
-
-- (void) close {
- if (hook_ != nil)
- [hook_ didCloseBook:self];
-}
-
@end
-@implementation RVPopUpBook
-- (void) _leftButtonTitle:(NSString *&)leftButtonTitle style:(UINavigationButtonStyle &)leftButtonStyle forPage:(RVPage *)page {
- [super _leftButtonTitle:leftButtonTitle style:leftButtonStyle forPage:page];
- if ((cancel_ = leftButtonTitle == nil && [pages_ count] == 1)) {
- leftButtonTitle = [[NSBundle mainBundle] localizedStringForKey:@"CANCEL" value:nil table:nil];
- leftButtonStyle = UINavigationButtonStyleNormal;
- }
-}
-
-- (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button {
- if (button == 1 && cancel_)
- [self close];
- else
- [super navigationBar:navbar buttonClicked:button];
-}
-
-- (void) close {
- [self popFromSuperviewAnimated:YES];
- [super close];
-}
-
-@end
diff --git a/UICaboodle/RVPage.h b/UICaboodle/RVPage.h
index 284ebca..270c248 100644
--- a/UICaboodle/RVPage.h
+++ b/UICaboodle/RVPage.h
@@ -2,41 +2,9 @@
#import <UIKit/UIKit.h>
-@class NSString;
-@class RVBook;
-
-@interface RVPage : UIView {
- _transient RVBook *book_;
- _transient id delegate_;
+@interface UCViewController : UIViewController {
+ id delegate_;
}
-
-- (bool) splitView;
-
-- (NSString *) title;
-- (NSString *) backButtonTitle;
-- (id) rightButtonTitle;
-- (NSString *) leftButtonTitle;
-- (UIView *) accessoryView;
-
-- (UIImage *) rightButtonImage;
-
-- (UINavigationButtonStyle) leftButtonStyle;
-- (UINavigationButtonStyle) rightButtonStyle;
-
-- (void) _rightButtonClicked;
-- (void) _leftButtonClicked;
-
-- (void) setPageActive:(BOOL)active;
-- (void) resetViewAnimated:(BOOL)animated;
-
-- (void) setBackButtonTitle:(NSString *)title;
-
-- (void) reloadButtons;
-- (void) reloadData;
-
-- (id) initWithBook:(RVBook *)book;
-
-- (void) setDelegate:(id)delegate;
-- (void) setBook:(RVBook *)book;
-
+- (void)setDelegate:(id)delegate;
@end
+
diff --git a/UICaboodle/RVPage.mm b/UICaboodle/RVPage.mm
index 7154bab..932b45e 100644
--- a/UICaboodle/RVPage.mm
+++ b/UICaboodle/RVPage.mm
@@ -5,83 +5,13 @@
#import "RVBook.h"
-@implementation RVPage
-
-- (bool) splitView {
- return false;
-}
-
-- (NSString *) title {
- [self doesNotRecognizeSelector:_cmd];
- return nil;
-}
-
-- (NSString *) backButtonTitle {
- return nil;
-}
-
-- (NSString *) leftButtonTitle {
- return nil;
-}
-
-- (id) rightButtonTitle {
- return nil;
-}
-
-- (UINavigationButtonStyle) leftButtonStyle {
- return [self leftButtonTitle] == nil ? UINavigationButtonStyleBack : UINavigationButtonStyleNormal;
-}
-
-- (UINavigationButtonStyle) rightButtonStyle {
- return UINavigationButtonStyleNormal;
-}
-
-- (void) _rightButtonClicked {
- [self doesNotRecognizeSelector:_cmd];
-}
-
-- (void) _leftButtonClicked {
- [self doesNotRecognizeSelector:_cmd];
-}
-
-- (UIView *) accessoryView {
- return nil;
-}
-
-- (UIImage *) rightButtonImage {
- return nil;
-}
-
-- (void) setPageActive:(BOOL)active {
-}
-
-- (void) resetViewAnimated:(BOOL)animated {
- [self doesNotRecognizeSelector:_cmd];
-}
-
-- (void) setBackButtonTitle:(NSString *)title {
- [book_ setBackButtonTitle:title forPage:self];
+@implementation UCViewController
+- (void)setDelegate:(id)delegate {
+ delegate_ = delegate;
}
-
-- (void) reloadButtons {
- [book_ reloadButtonsForPage:self];
+- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
+ return NO; /* XXX: return YES; */
}
-
- (void) reloadData {
}
-
-- (id) initWithBook:(RVBook *)book {
- if ((self = [super initWithFrame:[book pageBounds]]) != nil) {
- book_ = book;
- } return self;
-}
-
-- (void) setDelegate:(id)delegate {
- delegate_ = delegate;
-}
-
-- (void) setBook:(RVBook *)book {
- book_ = book;
-}
-
@end