diff --git a/bepdf/beos/BepdfApplication.cpp b/bepdf/beos/BepdfApplication.cpp index 15a8f1b..cb511d1 100644 --- a/bepdf/beos/BepdfApplication.cpp +++ b/bepdf/beos/BepdfApplication.cpp @@ -577,6 +577,7 @@ void BepdfApplication::RefsReceived(BMessage *msg) BRect rect(mSettings->GetWindowRect()); bool ok; bool encrypted = false; + if (mWindow == NULL) { win = new PDFWindow(&ref, rect, owner, user, &encrypted); ok = win->IsOk(); @@ -591,22 +592,24 @@ void BepdfApplication::RefsReceived(BMessage *msg) if (!encrypted) { BAlert *error = new BAlert(B_TRANSLATE("Error"), B_TRANSLATE("BePDF: Error opening file!"), B_TRANSLATE("Close"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); error->Go(); - } + if (mWindow == NULL) { // fixme: always true even if a PDF window is already open! + OpenFilePanel(); + } + } else { + new PasswordWindow(&ref, rect, this); + } if (mWindow == NULL) delete win; - if (encrypted) { - new PasswordWindow(&ref, rect, this); - } } else if (mWindow == NULL) { mWindow = win; win->Show(); } // 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/PDFView.cpp b/bepdf/beos/PDFView.cpp index f969d98..da295b6 100644 --- a/bepdf/beos/PDFView.cpp +++ b/bepdf/beos/PDFView.cpp @@ -232,6 +232,9 @@ PDFView::MakeTitleString(BPath* path) { bool PDFView::OpenFile(entry_ref *ref, const char *ownerPassword, const char *userPassword, bool *encrypted) { BEntry entry (ref, true); + if (!entry.Exists()) { + return false; + } BPath path; entry.GetPath (&path); @@ -245,11 +248,8 @@ PDFView::OpenFile(entry_ref *ref, const char *ownerPassword, const char *userPas UpdatePanelDirectory(&path); bool ok = newDoc->isOk(); - // xpdf 3.01 returns false even PDF file is password protected?!? - *encrypted = true; // newDoc->isEncrypted(); -// fprintf(stderr, "ok %s encrypted %s\n", -// ok ? "yes" : "no", -// (*encrypted) ? "yes" : "no"); + *encrypted = newDoc->isEncrypted(); + if (ok) { delete mDoc; mDoc = newDoc; 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);