]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/RVBook.mm
Removed final pinstriping.
[cydia.git] / UICaboodle / RVBook.mm
index d83d7608051339e163aa3eb911f5ecfec43ee887..a6f53181c35ab8e8b026428c7b16317a1949d061 100644 (file)
@@ -8,8 +8,57 @@
 #import <UIKit/UIView-Geometry.h>
 #import <UIKit/UIView-Hierarchy.h>
 
+#import <Foundation/Foundation.h>
+#import <CoreGraphics/CGGeometry.h>
+
+#include <cstdio>
+#include <cstdlib>
+
+#include <errno.h>
+
 #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];
+    NSLog(@"cc:%@:%g:%g", contents, width, adjust);
+    width = adjust;
+    return [super createButtonWithContents:contents width:width barStyle:barStyle buttonStyle:style isRight:right];
+}
+
+@end
+
 @implementation RVBook
 
 - (void) dealloc {
     [super dealloc];
 }
 
+- (UINavigationBar *) navigationBar {
+    return navbar_;
+}
+
 - (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button {
     _assert([pages_ count] != 0);
     RVPage *page = [pages_ lastObject];
         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: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
         )];
     [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];
 
-    if ([navbar_ respondsToSelector:@selector(setAccessoryView:animate:goingBack:)])
-        [navbar_ setAccessoryView:[page accessoryView] animate:animated goingBack:NO];
-    else
-        [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
+    [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
 }
 
 - (void) popPages:(unsigned)pages {
     [self resetViewAnimated:YES toPage:[pages_ lastObject]];
 }
 
-- (void) setPrompt:(NSString *)prompt {
-    [navbar_ setPrompt:prompt];
-}
-
 - (void) resetViewAnimated:(BOOL)animated {
     resetting_ = true;
 
 
 - (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:goingBack:)])
-        [navbar_ setAccessoryView:[page accessoryView] animate:animated goingBack:YES];
-    else
-        [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
+    [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) reloadButtonsForPage:(RVPage *)page {
     if ([pages_ count] == 0 || page != [pages_ lastObject])
         return;
     NSString *leftButtonTitle([page leftButtonTitle]);
-    RVUINavBarButtonStyle leftButtonStyle = [page leftButtonStyle];
-    RVUINavBarButtonStyle rightButtonStyle = [page rightButtonStyle];
+    UINavigationButtonStyle leftButtonStyle = [page leftButtonStyle];
+    UINavigationButtonStyle rightButtonStyle = [page rightButtonStyle];
     //[navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle] leftBack:(leftButtonTitle == nil)];
 
     [navbar_