diff --git a/src/apps/showimage/ImageFileNavigator.cpp b/src/apps/showimage/ImageFileNavigator.cpp index b4eff7ec25..be45ea8b76 100644 --- a/src/apps/showimage/ImageFileNavigator.cpp +++ b/src/apps/showimage/ImageFileNavigator.cpp @@ -503,6 +503,20 @@ ImageFileNavigator::PreviousPage() } +bool +ImageFileNavigator::HasNextPage() +{ + return fDocumentIndex < fDocumentCount; +} + + +bool +ImageFileNavigator::HasPreviousPage() +{ + return fDocumentIndex > 1; +} + + bool ImageFileNavigator::GoToPage(int32 page) { diff --git a/src/apps/showimage/ImageFileNavigator.h b/src/apps/showimage/ImageFileNavigator.h index 96febd67a1..7a7b6db458 100644 --- a/src/apps/showimage/ImageFileNavigator.h +++ b/src/apps/showimage/ImageFileNavigator.h @@ -43,6 +43,8 @@ public: bool LastPage(); bool NextPage(); bool PreviousPage(); + bool HasNextPage(); + bool HasPreviousPage(); bool GoToPage(int32 page); bool FirstFile(); diff --git a/src/apps/showimage/ShowImageStatusView.cpp b/src/apps/showimage/ShowImageStatusView.cpp index a00eacf090..8ed52cbdfd 100644 --- a/src/apps/showimage/ShowImageStatusView.cpp +++ b/src/apps/showimage/ShowImageStatusView.cpp @@ -150,12 +150,13 @@ ShowImageStatusView::MouseDown(BPoint where) void ShowImageStatusView::Update(const entry_ref& ref, const BString& text, - const BString& imageType, float zoom) + const BString& pages, const BString& imageType, float zoom) { fRef = ref; _SetFrameText(text); _SetZoomText(zoom); + _SetPagesText(pages); _SetImageTypeText(imageType); _ValidatePreferredSize(); @@ -175,21 +176,28 @@ ShowImageStatusView::SetZoom(float zoom) void ShowImageStatusView::_SetFrameText(const BString& text) { - fCellText[0] = text; + fCellText[kFrameSizeCell] = text; } void ShowImageStatusView::_SetZoomText(float zoom) { - fCellText[1].SetToFormat("%.0f%%", zoom * 100); + fCellText[kZoomCell].SetToFormat("%.0f%%", zoom * 100); +} + + +void +ShowImageStatusView::_SetPagesText(const BString& pages) +{ + fCellText[kPagesCell] = pages; } void ShowImageStatusView::_SetImageTypeText(const BString& imageType) { - fCellText[2] = imageType; + fCellText[kImageTypeCell] = imageType; } diff --git a/src/apps/showimage/ShowImageStatusView.h b/src/apps/showimage/ShowImageStatusView.h index ef70af320f..9c419c1312 100644 --- a/src/apps/showimage/ShowImageStatusView.h +++ b/src/apps/showimage/ShowImageStatusView.h @@ -18,6 +18,7 @@ enum { kFrameSizeCell, kZoomCell, + kPagesCell, kImageTypeCell, kStatusCellCount }; @@ -34,12 +35,13 @@ public: virtual void MouseDown(BPoint where); void Update(const entry_ref& ref, - const BString& text, const BString& imageType, - float zoom); + const BString& text, const BString& pages, + const BString& imageType, float zoom); void SetZoom(float zoom); private: void _SetFrameText(const BString& text); void _SetZoomText(float zoom); + void _SetPagesText(const BString& pages); void _SetImageTypeText(const BString& imageType); void _ValidatePreferredSize(); BScrollView* fScrollView; diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index 0eefc9a177..982c1a37cc 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -615,6 +615,15 @@ ShowImageWindow::MessageReceived(BMessage* message) break; } + int32 page = message->FindInt32("page"); + int32 pageCount = message->FindInt32("pageCount"); + if (!first && page != fNavigator.CurrentPage()) { + // ignore older pages + if (bitmapOwner != NULL) + bitmapOwner->ReleaseReference(); + break; + } + status_t status = fImageView->SetImage(message); if (status != B_OK) { if (bitmapOwner != NULL) @@ -629,8 +638,7 @@ ShowImageWindow::MessageReceived(BMessage* message) } fImageType = message->FindString("type"); - fNavigator.SetTo(ref, message->FindInt32("page"), - message->FindInt32("pageCount")); + fNavigator.SetTo(ref, page, pageCount); fImageView->FitToBounds(); if (first) { @@ -680,12 +688,12 @@ ShowImageWindow::MessageReceived(BMessage* message) int32 pages = fNavigator.PageCount(); int32 currentPage = fNavigator.CurrentPage(); - bool enable = pages > 1 ? true : false; - _EnableMenuItem(fBar, MSG_PAGE_FIRST, enable); - _EnableMenuItem(fBar, MSG_PAGE_LAST, enable); - _EnableMenuItem(fBar, MSG_PAGE_NEXT, enable); - _EnableMenuItem(fBar, MSG_PAGE_PREV, enable); - fGoToPageMenu->SetEnabled(enable); + _EnableMenuItem(fBar, MSG_PAGE_FIRST, + fNavigator.HasPreviousPage()); + _EnableMenuItem(fBar, MSG_PAGE_LAST, fNavigator.HasNextPage()); + _EnableMenuItem(fBar, MSG_PAGE_NEXT, fNavigator.HasNextPage()); + _EnableMenuItem(fBar, MSG_PAGE_PREV, fNavigator.HasPreviousPage()); + fGoToPageMenu->SetEnabled(pages > 1); _EnableMenuItem(fBar, MSG_FILE_NEXT, fNavigator.HasNextFile()); _EnableMenuItem(fBar, MSG_FILE_PREV, fNavigator.HasPreviousFile()); @@ -1054,14 +1062,16 @@ ShowImageWindow::MessageReceived(BMessage* message) void ShowImageWindow::_UpdateStatusText(const BMessage* message) { - BString status; + BString frameText; if (fImageView->Bitmap() != NULL) { BRect bounds = fImageView->Bitmap()->Bounds(); - status << bounds.IntegerWidth() + 1 + frameText << bounds.IntegerWidth() + 1 << "x" << bounds.IntegerHeight() + 1; } - - fStatusView->Update(fNavigator.CurrentRef(), status, fImageType, + BString pages; + if (fNavigator.PageCount() > 1) + pages << fNavigator.CurrentPage() << "/" << fNavigator.PageCount(); + fStatusView->Update(fNavigator.CurrentRef(), frameText, pages, fImageType, fImageView->Zoom()); }