From 6c3054116ed26f244b826d3bd4e06f5c651a44ca Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Sun, 9 Nov 2003 14:10:26 +0000 Subject: [PATCH] Added Go To Page submenu so the user can directly go to the page that they want. Also fixed a typo. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5290 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/ShowImageConstants.h | 1 + src/apps/showimage/ShowImageView.cpp | 9 ++++ src/apps/showimage/ShowImageView.h | 1 + src/apps/showimage/ShowImageWindow.cpp | 66 ++++++++++++++++++++++++- src/apps/showimage/ShowImageWindow.h | 1 + 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/apps/showimage/ShowImageConstants.h b/src/apps/showimage/ShowImageConstants.h index 10a194c0cb..c189a20605 100644 --- a/src/apps/showimage/ShowImageConstants.h +++ b/src/apps/showimage/ShowImageConstants.h @@ -46,6 +46,7 @@ const uint32 MSG_PAGE_FIRST = 'mPGF'; const uint32 MSG_PAGE_LAST = 'mPGL'; const uint32 MSG_PAGE_NEXT = 'mPGN'; const uint32 MSG_PAGE_PREV = 'mPGP'; +const uint32 MSG_GOTO_PAGE = 'mGTP'; const uint32 MSG_FILE_NEXT = 'mFLN'; const uint32 MSG_FILE_PREV = 'mFLP'; const uint32 MSG_FIT_TO_WINDOW_SIZE = 'mFWS'; diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index f185a6139b..55bebdce46 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -914,6 +914,15 @@ ShowImageView::PrevPage() } } +void +ShowImageView::GoToPage(int32 page) +{ + if (page > 0 && page <= fDocumentCount && page != fDocumentIndex) { + fDocumentIndex = page; + SetImage(NULL); + } +} + void ShowImageView::FreeEntries(BList* entries) { diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index 8ae61f5e4b..a501561848 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -72,6 +72,7 @@ public: void LastPage(); void NextPage(); void PrevPage(); + void GoToPage(int32 page); bool NextFile(); bool PrevFile(); void SetSlideShowDelay(float seconds); diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index aafb65d9b5..9a98d0611e 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -210,6 +210,8 @@ ShowImageWindow::LoadMenus(BMenuBar *pbar) AddItemMenu(pmenu, "Last Page", MSG_PAGE_LAST, 'L', 0, 'W', true); AddItemMenu(pmenu, "Next Page", MSG_PAGE_NEXT, 'N', 0, 'W', true); AddItemMenu(pmenu, "Previous Page", MSG_PAGE_PREV, 'P', 0, 'W', true); + fpGoToPageMenu = new BMenu("Go To Page"); + pmenu->AddItem(fpGoToPageMenu); pmenu->AddSeparatorItem(); AddItemMenu(pmenu, "Next File", MSG_FILE_NEXT, B_DOWN_ARROW, 0, 'W', true); AddItemMenu(pmenu, "Previous File", MSG_FILE_PREV, B_UP_ARROW, 0, 'W', true); @@ -245,7 +247,7 @@ ShowImageWindow::LoadMenus(BMenuBar *pbar) AddDelayItem(pDelay, "Eight Seconds", 8, false); AddDelayItem(pDelay, "Nine Seconds", 9, false); AddDelayItem(pDelay, "Ten Seconds", 10, false); - AddDelayItem(pDelay, "Tweenty Seconds", 20, false); + AddDelayItem(pDelay, "Twenty Seconds", 20, false); pmenu->AddItem(pDelay); pmenu->AddSeparatorItem(); AddItemMenu(pmenu, "Fit To Window Size", MSG_FIT_TO_WINDOW_SIZE, 0, 0, 'W', true); @@ -386,11 +388,50 @@ ShowImageWindow::MessageReceived(BMessage *pmsg) case MSG_UPDATE_STATUS: { - bool benable = (fpImageView->PageCount() > 1) ? true : false; + int32 pages, curPage; + pages = fpImageView->PageCount(); + curPage = fpImageView->CurrentPage(); + + bool benable = (pages > 1) ? true : false; EnableMenuItem(MSG_PAGE_FIRST, benable); EnableMenuItem(MSG_PAGE_LAST, benable); EnableMenuItem(MSG_PAGE_NEXT, benable); EnableMenuItem(MSG_PAGE_PREV, benable); + + if (fpGoToPageMenu->CountItems() != pages) { + // Only rebuild the submenu if the number of + // pages is different + + while (fpGoToPageMenu->CountItems() > 0) + // Remove all page numbers + delete fpGoToPageMenu->RemoveItem(0L); + + for (int32 i = 1; i > 0 && i <= pages; i++) { + // Fill Go To page submenu with an entry for each page + BMessage *pgomsg; + pgomsg = new BMessage(MSG_GOTO_PAGE); + pgomsg->AddInt32("page", i); + BString strCaption; + strCaption << i; + BMenuItem *pitem; + pitem = new BMenuItem(strCaption.String(), pgomsg, 0); + if (curPage == i) + pitem->SetMarked(true); + fpGoToPageMenu->AddItem(pitem); + } + } else { + // Make sure the correct page is marked + BMenuItem *pcurItem; + pcurItem = fpGoToPageMenu->ItemAt(curPage - 1); + if (!pcurItem->IsMarked()) { + // If the current page isn't marked, unmark everything + // then mark the current page + int32 items = fpGoToPageMenu->CountItems(); + for (int32 i = 0; i < items; i++) + fpGoToPageMenu->ItemAt(i)->SetMarked(false); + pcurItem->SetMarked(true); + } + } BString str; if (pmsg->FindString("status", &str) == B_OK) @@ -431,6 +472,27 @@ ShowImageWindow::MessageReceived(BMessage *pmsg) case MSG_PAGE_PREV: fpImageView->PrevPage(); break; + + case MSG_GOTO_PAGE: + { + int32 curPage, newPage, pages; + if (pmsg->FindInt32("page", &newPage) == B_OK) { + curPage = fpImageView->CurrentPage(); + pages = fpImageView->PageCount(); + + if (newPage > 0 && newPage <= pages) { + BMenuItem *pcurItem, *pnewItem; + pcurItem = fpGoToPageMenu->ItemAt(curPage - 1); + pnewItem = fpGoToPageMenu->ItemAt(newPage - 1); + if (!pcurItem || !pnewItem) + break; + pcurItem->SetMarked(false); + pnewItem->SetMarked(true); + fpImageView->GoToPage(newPage); + } + } + } + break; case MSG_DITHER_IMAGE: ToggleMenuItem(pmsg->what); diff --git a/src/apps/showimage/ShowImageWindow.h b/src/apps/showimage/ShowImageWindow.h index ac514a4d39..f9153acfb1 100644 --- a/src/apps/showimage/ShowImageWindow.h +++ b/src/apps/showimage/ShowImageWindow.h @@ -82,6 +82,7 @@ private: BMenuBar *fpBar; BMenu *fpOpenMenu; BMenu *fpBrowseMenu; + BMenu *fpGoToPageMenu; ShowImageView *fpImageView; ShowImageStatusView *fpStatusView; bool fFullScreen;