X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/423f8cb9332c025bce60a40dc6efaf49abc59de9..a55054a22e40e78286803276227838d44a45530a:/UICaboodle/RVBook.mm diff --git a/UICaboodle/RVBook.mm b/UICaboodle/RVBook.mm index 5ac8b2ed..b639958b 100644 --- a/UICaboodle/RVBook.mm +++ b/UICaboodle/RVBook.mm @@ -8,19 +8,75 @@ #import #import +#import +#import + +#include +#include + +#include + #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]; [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]; @@ -44,17 +100,15 @@ pages_ = [[NSMutableArray arrayWithCapacity:4] retain]; struct CGRect bounds = [self bounds]; - CGSize navsize = [UINavigationBar defaultSizeWithPrompt]; + CGSize navsize = [UINavigationBar defaultSize]; CGRect navrect = {{0, 0}, navsize}; - navbar_ = [[UINavigationBar alloc] initWithFrame:navrect]; + navbar_ = [[RVNavigationBar alloc] initWithFrame:navrect]; [self addSubview:navbar_]; - [navbar_ setBarStyle:1]; + [navbar_ setBarStyle:0]; [navbar_ setDelegate:self]; - [navbar_ setPrompt:@""]; - transition_ = [[UITransitionView alloc] initWithFrame:CGRectMake( bounds.origin.x, bounds.origin.y + navsize.height, bounds.size.width, bounds.size.height - navsize.height )]; @@ -96,13 +150,18 @@ [navbar_ pushNavigationItem:navitem]; BOOL animated = [pages_ count] == 0 ? NO : YES; + [page setFrame:[transition_ bounds]]; [transition_ transition:(animated ? 1 : 0) toView:page]; [page setPageActive:YES]; [pages_ addObject:page]; [self reloadButtonsForPage:page]; - [navbar_ setAccessoryView:[page accessoryView] animate:animated goingBack:NO]; + [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO]; +} + +- (void) pushBook:(RVBook *)book { + [delegate_ popUpBook:book]; } - (void) popPages:(unsigned)pages { @@ -119,10 +178,6 @@ [self resetViewAnimated:YES toPage:[pages_ lastObject]]; } -- (void) setPrompt:(NSString *)prompt { - [navbar_ setPrompt:prompt]; -} - - (void) resetViewAnimated:(BOOL)animated { resetting_ = true; @@ -142,31 +197,51 @@ - (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]; - [navbar_ setAccessoryView:[page accessoryView] animate:animated goingBack:YES]; + + [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO]; } -- (void) setTitle:(NSString *)title forPage:(RVPage *)page { +- (void) setBackButtonTitle:(NSString *)title forPage:(RVPage *)page { if ([pages_ count] == 0 || page != [pages_ lastObject]) return; UINavigationItem *navitem = [navbar_ topItem]; - [navitem setTitle:title]; + [navitem setBackButtonTitle:title]; } -- (void) setBackButtonTitle:(NSString *)title forPage:(RVPage *)page { +- (void) reloadTitleForPage:(RVPage *)page { if ([pages_ count] == 0 || page != [pages_ lastObject]) return; UINavigationItem *navitem = [navbar_ topItem]; - [navitem setBackButtonTitle:title]; + NSString *title = [self getTitleForPage:page]; + [navitem setTitle:title]; +} + +- (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([pages_ count] == 1 ? [page leftButtonTitle] : nil); - [navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle]]; + + 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 { @@ -184,4 +259,30 @@ return [transition_ bounds]; } +- (void) close { +} + +@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 = @"Cancel"; + 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]; +} + @end