- [pages_ addObject:page];
- [self reloadButtonsForPage:page];
-
- [navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
-}
-
-- (void) pushBook:(RVBook *)book {
- [delegate_ popUpBook:book];
-}
-
-- (void) popPages:(unsigned)pages {
- if (pages == 0)
- return;
-
- [[pages_ lastObject] setPageActive:NO];
-
- resetting_ = true;
- for (unsigned i(0); i != pages; ++i)
- [navbar_ popNavigationItem];
- resetting_ = false;
-
- [self resetViewAnimated:YES toPage:[pages_ lastObject]];
-}
-
-- (void) resetViewAnimated:(BOOL)animated {
- resetting_ = true;
-
- if ([pages_ count] > 1) {
- [navbar_ disableAnimation];
- while ([pages_ count] != (animated ? 2 : 1))
- [navbar_ popNavigationItem];
- [navbar_ enableAnimation];
- if (animated)
- [navbar_ popNavigationItem];
- }
-
- resetting_ = false;
-
- [self resetViewAnimated:animated toPage:[pages_ lastObject]];
-}
-
-- (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 removeOnPop:NO];
-}
-
-- (void) setBackButtonTitle:(NSString *)title forPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- UINavigationItem *navitem = [navbar_ topItem];
- [navitem setBackButtonTitle:title];
-}
-
-- (void) reloadTitleForPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- UINavigationItem *navitem = [navbar_ topItem];
- NSString *title = [self getTitleForPage:page];
- [navitem setTitle:title];
-}
-
-- (NSString *) _leftButtonTitleForPage:(RVPage *)page {
- return [page leftButtonTitle];
-}
-
-- (void) reloadButtonsForPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- NSString *leftButtonTitle([self _leftButtonTitleForPage:page]);
- UINavigationButtonStyle leftButtonStyle = [page leftButtonStyle];
- 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 {
- return [page title];
-}
-
-- (void) reloadData {
- for (int i(0), e([pages_ count]); i != e; ++i) {
- RVPage *page([pages_ objectAtIndex:(e - i - 1)]);
- [page reloadData];
- }
-}
-
-- (CGRect) pageBounds {
- return [transition_ bounds];
-}
-
-- (void) close {
-}
-
-@end
-
-@implementation RVPopUpBook
-
-- (NSString *) _leftButtonTitleForPage:(RVPage *)page {
- NSString *title([super _leftButtonTitleForPage:page]);
- return (cancel_ = title == nil && [pages_ count] == 1) ? @"Cancel" : title;
-}
-
-- (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