]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/RVBook.mm
Fixing more bugs in window opening.
[cydia.git] / UICaboodle / RVBook.mm
index cef1acee62e297fb58d8ac6e6f68792f4753030b..b639958bf452e41d1d93daf65cc729a89f95a101 100644 (file)
 
 #import "RVPage.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];
+    width = adjust;
+    return [super createButtonWithContents:contents width:width barStyle:barStyle buttonStyle:style isRight:right];
+}
+
+@end
+
 @implementation RVBook
 
 - (void) dealloc {
     [navbar_ setDelegate:nil];
 @implementation RVBook
 
 - (void) dealloc {
     [navbar_ setDelegate:nil];
+    if (toolbar_ != nil)
+        [toolbar_ setDelegate:nil];
 
     [pages_ release];
     [navbar_ release];
     [transition_ release];
 
     [pages_ release];
     [navbar_ release];
     [transition_ release];
+    if (toolbar_ != nil)
+        [toolbar_ release];
     [super dealloc];
 }
 
     [super dealloc];
 }
 
         CGSize navsize = [UINavigationBar defaultSize];
         CGRect navrect = {{0, 0}, navsize};
 
         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];
         [self addSubview:navbar_];
 
         [navbar_ setBarStyle:0];
     [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
 }
 
     [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
 }
 
+- (void) pushBook:(RVBook *)book {
+    [delegate_ popUpBook:book];
+}
+
 - (void) popPages:(unsigned)pages {
     if (pages == 0)
         return;
 - (void) popPages:(unsigned)pages {
     if (pages == 0)
         return;
     [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];
     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];
     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;
 }
 
 - (void) reloadButtonsForPage:(RVPage *)page {
     if ([pages_ count] == 0 || page != [pages_ lastObject])
         return;
-    NSString *leftButtonTitle([page leftButtonTitle]);
-    UINavigationButtonStyle leftButtonStyle = [page leftButtonStyle];
+
+    NSString *leftButtonTitle;
+    UINavigationButtonStyle leftButtonStyle;
+    [self _leftButtonTitle:leftButtonTitle style:leftButtonStyle forPage:page];
+
     UINavigationButtonStyle rightButtonStyle = [page rightButtonStyle];
     //[navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle] leftBack:(leftButtonTitle == nil)];
 
     UINavigationButtonStyle rightButtonStyle = [page rightButtonStyle];
     //[navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle] leftBack:(leftButtonTitle == nil)];
 
     return [transition_ bounds];
 }
 
     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
 @end