-@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];
- 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}, navsize};
-
- navbar_ = [[RVNavigationBar alloc] initWithFrame:navrect];
- [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
- )];
-
- [self addSubview:transition_];
- } return self;
-}
-
-- (void) setDelegate:(id)delegate {
- delegate_ = delegate;
-}