From faed874968a1d3a0b92fb2d3cc1cea58c7e16893 Mon Sep 17 00:00:00 2001 From: "Gregor B. Rosenauer" Date: Wed, 28 Aug 2024 17:21:44 +0200 Subject: [PATCH] 116 bugfix pagenum (#120) * fixes #116 and jumps to page if provided via argument. * harden and fix page number handling. * fixup for pagenum patch to reuse existing method invoked from TextView and correctly update pagelist selection and position. --- bepdf/beos/BepdfApplication.cpp | 6 ++--- bepdf/beos/PDFWindow.cpp | 39 ++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/bepdf/beos/BepdfApplication.cpp b/bepdf/beos/BepdfApplication.cpp index 15a8f1b..ad184fa 100644 --- a/bepdf/beos/BepdfApplication.cpp +++ b/bepdf/beos/BepdfApplication.cpp @@ -604,9 +604,9 @@ void BepdfApplication::RefsReceived(BMessage *msg) } // jump to page if provided if (pageNum != 0) { - mWindow->LockLooper(); - mWindow->SetPage(pageNum); - mWindow->UnlockLooper(); + BMessage goToPageMsg(PDFWindow::GOTO_PAGE_CMD); + goToPageMsg.AddInt32("page", pageNum); + mWindow->MessageReceived(&goToPageMsg); } // stop after first document mGotSomething = true; diff --git a/bepdf/beos/PDFWindow.cpp b/bepdf/beos/PDFWindow.cpp index 4abbddd..2e84ee4 100644 --- a/bepdf/beos/PDFWindow.cpp +++ b/bepdf/beos/PDFWindow.cpp @@ -1069,22 +1069,31 @@ PDFWindow::MessageReceived(BMessage* message) mMainView->MoveToPage (mMainView->GetNumPages()); break; case GOTO_PAGE_CMD: { - status_t err; - BTextControl * control; - BControl * ptr; - - err = message->FindPointer ("source", (void **)&ptr); - control = dynamic_cast (ptr); - if (err == B_OK && control != NULL) { - const char *txt = control->Text (); - page = atoi (txt); - mMainView->MoveToPage (page); - mMainView->MakeFocus(); - } else { - /* ERROR */ - } - } + status_t result; + BTextControl * control; + BControl * ptr; + + result = message->FindPointer ("source", (void **)&ptr); + if (result == B_OK) { + control = dynamic_cast (ptr); + if (result == B_OK && control != NULL) { + const char *txt = control->Text (); + page = atoi (txt); + } + } else { // may come from external source over page parameter + result = message->FindInt32("page", &page); + if (result == B_OK) + mMainView->WaitForPage(); + } + + if (result == B_OK) { + LockLooper(); + mMainView->MoveToPage (page); + UnlockLooper(); + mMainView->MakeFocus(); + } break; + } case PAGE_SELECTED_CMD: page = mPagesView->CurrentSelection(0) + 1; mMainView->MoveToPage(page);