@end
+@interface BrowserView : UIView {
+@private
+ UIWebDocumentView *documentView;
+}
+@property (nonatomic, retain) UIWebDocumentView *documentView;
+@end
+
+@implementation BrowserView
+
+@synthesize documentView;
+
+- (void)dealloc {
+ [documentView release];
+ [super dealloc];
+}
+
+- (void)layoutSubviews {
+ [super layoutSubviews];
+ if ([documentView respondsToSelector:@selector(setMinimumSize:)])
+ [documentView setMinimumSize:documentView.bounds.size];
+}
+
+@end
+
#define ShowInternals 0
#define LogBrowser 1
#define lprintf(args...) fprintf(stderr, args)
-@implementation BrowserView
+@implementation BrowserController
#if ShowInternals
#include "UICaboodle/UCInternal.h"
- (void) dealloc {
#if LogBrowser
- NSLog(@"[BrowserView dealloc]");
+ NSLog(@"[BrowserController dealloc]");
#endif
if (challenge_ != nil)
[sensitive_ release];
if (title_ != nil)
[title_ release];
+ if (reloaditem_ != nil)
+ [reloaditem_ release];
+ if (loadingitem_ != nil)
+ [loadingitem_ release];
+
[super dealloc];
}
[function_ autorelease];
function_ = function == nil ? nil : [function retain];
- [self reloadButtons];
+ [self applyRightButton];
}
- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
[function_ autorelease];
function_ = function == nil ? nil : [function retain];
- [self reloadButtons];
+ [self applyRightButton];
}
- (void) setFinishHook:(id)function {
if (page == nil) {
/* XXX: call createWebViewWithRequest instead? */
- BrowserView *browser([[[class_ alloc] init] autorelease]);
+ BrowserController *browser([[[class_ alloc] init] autorelease]);
[browser loadURL:url];
page = browser;
}
UCNavigationController *navigation(!popup_ ? [self navigationController] : [[[UCNavigationController alloc] init] autorelease]);
/* XXX: deal with cydia:// pages */
- BrowserView *browser([[[class_ alloc] initWithWidth:width] autorelease]);
+ BrowserController *browser([[[class_ alloc] initWithWidth:width] autorelease]);
if (features != nil && popup_) {
[navigation setDelegate:delegate_];
}
}
- [self reloadButtons];
+ [self _startLoading];
+}
+
+- (UINavigationButtonStyle) rightButtonStyle {
+ if (style_ == nil) normal:
+ return UINavigationButtonStyleNormal;
+ else if ([style_ isEqualToString:@"Normal"])
+ return UINavigationButtonStyleNormal;
+ else if ([style_ isEqualToString:@"Back"])
+ return UINavigationButtonStyleBack;
+ else if ([style_ isEqualToString:@"Highlighted"])
+ return UINavigationButtonStyleHighlighted;
+ else if ([style_ isEqualToString:@"Destructive"])
+ return UINavigationButtonStyleDestructive;
+ else goto normal;
+}
+
+- (UIBarButtonItem *) customButton {
+ UIBarButtonItem *customItem = [[UIBarButtonItem alloc]
+ initWithTitle:button_
+ style:[self rightButtonStyle]
+ target:self
+ action:@selector(customButtonClicked)
+ ];
+
+ return [customItem autorelease];
+}
+
+- (void) applyLoadingTitle {
+ [[self navigationItem] setTitle:UCLocalize("LOADING")];
+}
+
+- (void) applyRightButton {
+ if ([self isLoading]) {
+ [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
+ [[loadingitem_ view] addSubview:indicator_];
+ [self applyLoadingTitle];
+ } else if (button_) {
+ [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES];
+ } else {
+ [[self navigationItem] setRightBarButtonItem:reloaditem_ animated:YES];
+ }
}
-- (void) didFinishLoading { }
+- (void) _startLoading {
+ [self applyRightButton];
+}
- (void) _finishLoading {
size_t count([loading_ count]);
if (finish_ != nil)
[self callFunction:finish_];
- [self reloadButtons];
+ [self applyRightButton];
+ if (![self isLoading]) [[self navigationItem] setTitle:title_];
}
- (bool) isLoading {
loading_ = [[NSMutableSet alloc] initWithCapacity:3];
popup_ = false;
+ BrowserView *actualView = [[BrowserView alloc] initWithFrame:CGRectZero];
+ [self setView:actualView];
+
struct CGRect bounds = [[self view] bounds];
scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds];
else
[preferences _setLayoutInterval:0];
}
+
+ actualView.documentView = document_;
+ [actualView release];
[self setViewportWidth:width];
indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)];
[indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
[indicator_ startAnimation];
+
+ reloaditem_ = [[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("RELOAD")
+ style:[self rightButtonStyle]
+ target:self
+ action:@selector(reloadButtonClicked)
+ ];
+
+ loadingitem_ = [[UIBarButtonItem alloc]
+ initWithTitle:@" "
+ style:UIBarButtonItemStylePlain
+ target:self
+ action:@selector(reloadButtonClicked)
+ ];
+ [[loadingitem_ view] addSubview:indicator_];
[scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
- [document_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+ [document_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
/*UIWebView *test([[[UIWebView alloc] initWithFrame:[[self view] bounds]] autorelease]);
[test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];
[self callFunction:closer_];
}
-- (void) __rightButtonClicked {
+- (void) reloadButtonClicked {
reloading_ = true;
[self reloadURL];
}
-- (void) _rightButtonClicked {
+- (void) customButtonClicked {
#if !AlwaysReload
if (function_ != nil)
[self callFunction:function_];
else
#endif
- [self __rightButtonClicked];
-}
-
-- (UINavigationButtonStyle) rightButtonStyle {
- if (style_ == nil) normal:
- return UINavigationButtonStyleNormal;
- else if ([style_ isEqualToString:@"Normal"])
- return UINavigationButtonStyleNormal;
- else if ([style_ isEqualToString:@"Back"])
- return UINavigationButtonStyleBack;
- else if ([style_ isEqualToString:@"Highlighted"])
- return UINavigationButtonStyleHighlighted;
- else if ([style_ isEqualToString:@"Destructive"])
- return UINavigationButtonStyleDestructive;
- else goto normal;
-}
-
-- (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];
- }
+ [self reloadButtonClicked];
}
- (void) setPageActive:(BOOL)active {