diff --git a/bepdf/beos/BepdfApplication.cpp b/bepdf/beos/BepdfApplication.cpp index 428aee5..15a8f1b 100644 --- a/bepdf/beos/BepdfApplication.cpp +++ b/bepdf/beos/BepdfApplication.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -60,7 +61,7 @@ static const char * GPLCopyright = "\n\n" "This program is free software under the GNU GPL v2, or any later version.\n"; -static const char *PAGE_NUM_MSG = "bepdf:page_num"; +static const char *PAGE_NUM_MSG_KEY = "bepdf:page_num"; static const char *settingsFilename = "BePDF"; @@ -528,33 +529,45 @@ bool BepdfApplication::QuitRequested() { /* Opens everything. */ -void BepdfApplication::RefsReceived ( BMessage * msg ) +void BepdfApplication::RefsReceived(BMessage *msg) { uint32 type; int32 count; - int32 i; - entry_ref ref; - mReadyToQuit = false; + status_t result; - msg->GetInfo ( "refs", &type, &count ); - if ( type != B_REF_TYPE ) { - return; - } + msg->GetInfo("refs", &type, &count); + + if (type != B_REF_TYPE) { + BAlert *error = new BAlert(B_TRANSLATE("Error"), B_TRANSLATE("Invalid file reference received!"), B_TRANSLATE("Close"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + error->Go(); + + return; + } BString ownerPassword, userPassword; const char *owner = NULL; const char *user = NULL; + int32 pageNum = 0; + entry_ref ref; + if (B_OK == msg->FindString("ownerPassword", &ownerPassword)) { owner = ownerPassword.String(); } if (B_OK == msg->FindString("userPassword", &userPassword)) { user = userPassword.String(); } + result = msg->FindInt32(PAGE_NUM_MSG_KEY, &pageNum); + if (result != B_OK) { + if (result != B_NAME_NOT_FOUND) { + BAlert *error = new BAlert(B_TRANSLATE("Error"), B_TRANSLATE("Error getting page number!"), B_TRANSLATE("Close"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + error->Go(); + } + } Initialize(); - for ( i = --count ; i >= 0; i-- ) { + for (int32 i = --count ; i >= 0; i-- ) { if ( msg->FindRef("refs", i, &ref ) == B_OK ) { /* Open the document... @@ -589,6 +602,12 @@ void BepdfApplication::RefsReceived ( BMessage * msg ) mWindow = win; win->Show(); } + // jump to page if provided + if (pageNum != 0) { + mWindow->LockLooper(); + mWindow->SetPage(pageNum); + mWindow->UnlockLooper(); + } // stop after first document mGotSomething = true; break; @@ -673,7 +692,7 @@ BepdfApplication::ArgvReceived (int32 argc, char **argv) // fprintf(errFile, "%s%s\n", pdfViewerCopyright, GPLCopyright); BMessage msg(B_REFS_RECEIVED); - msg.AddInt32 (PAGE_NUM_MSG, pg); + msg.AddInt32 (PAGE_NUM_MSG_KEY, pg); get_ref_for_path (argvCopy[1], &fileToOpen); msg.AddRef ("refs", &fileToOpen); PostMessage (&msg); diff --git a/bepdf/beos/PDFWindow.cpp b/bepdf/beos/PDFWindow.cpp index e12832b..4abbddd 100644 --- a/bepdf/beos/PDFWindow.cpp +++ b/bepdf/beos/PDFWindow.cpp @@ -973,8 +973,12 @@ PDFWindow::SetZoomSize(float w, float h) /////////////////////////////////////////////////////////// // update page list and page number item void -PDFWindow::SetPage(int16 page) { +PDFWindow::SetPage(int32 page) { char pageStr [64]; + if (page <= 0) page = 1; + if (page > mPagesView->CountItems()) { + page = mPagesView->CountItems(); + } snprintf (pageStr, sizeof (pageStr), "%d", page); mPageNumberItem->SetText (pageStr); mPagesView->Select(page-1); diff --git a/bepdf/beos/PDFWindow.h b/bepdf/beos/PDFWindow.h index e9d30d2..49e1737 100644 --- a/bepdf/beos/PDFWindow.h +++ b/bepdf/beos/PDFWindow.h @@ -283,7 +283,7 @@ class PDFWindow void SetZoomSize (float w, float h); void SetZoom(int16 zoom); void SetRotation(float rotation); - void SetPage(int16 page); + void SetPage(int32 page); static void OpenPDF(const char* file); static bool OpenPDFHelp(const char* name);