From 095b7731f4a9e1d7c9ebb8757a55c98273a6d3f9 Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Wed, 9 Jul 2003 03:21:20 +0000 Subject: [PATCH] added support for multiple images in a single stream, such as in multi-page TIFF files git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3914 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tools/translation/inspector/Constants.h | 5 +- src/tools/translation/inspector/ImageView.cpp | 80 ++++++++++++++++--- src/tools/translation/inspector/ImageView.h | 14 +++- .../translation/inspector/ImageWindow.cpp | 33 ++++++++ 4 files changed, 120 insertions(+), 12 deletions(-) diff --git a/src/tools/translation/inspector/Constants.h b/src/tools/translation/inspector/Constants.h index 19dec94c08..a8243f13b9 100644 --- a/src/tools/translation/inspector/Constants.h +++ b/src/tools/translation/inspector/Constants.h @@ -40,7 +40,10 @@ #define M_INFO_WINDOW 'infw' #define M_INFO_WINDOW_QUIT 'infq' #define M_INFO_WINDOW_TEXT 'inft' - +#define M_VIEW_FIRST_PAGE 'vwfp' +#define M_VIEW_LAST_PAGE 'vwlp' +#define M_VIEW_NEXT_PAGE 'vwnp' +#define M_VIEW_PREV_PAGE 'vwpp' // String constants #define APP_SIG "application/x-vnd.OBOS-Inspector" diff --git a/src/tools/translation/inspector/ImageView.cpp b/src/tools/translation/inspector/ImageView.cpp index 96a31c9378..c55b77699b 100644 --- a/src/tools/translation/inspector/ImageView.cpp +++ b/src/tools/translation/inspector/ImageView.cpp @@ -63,6 +63,8 @@ ImageView::ImageView(BRect rect, const char *name) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS) { fpbitmap = NULL; + fdocumentIndex = 1; + fdocumentCount = 1; SetViewColor(192, 192, 192); SetHighColor(0, 0, 0); @@ -166,12 +168,12 @@ ImageView::SaveImageAtDropLocation(BMessage *pmsg) { // Find the location and name of the drop and // write the image file there - BBitmapStream stream(fpbitmap); StatusCheck chk; // throw an exception if this is assigned // anything other than B_OK + try { entry_ref dirref; chk = pmsg->FindRef("directory", &dirref); @@ -320,8 +322,9 @@ char_format(uint32 num) // Send information about the currently open image to the // BApplication object so it can send it to the InfoWindow void -ImageView::UpdateInfoWindow(const BPath &path, const translator_info &tinfo, - const char *tranname, const char *traninfo, int32 tranversion) +ImageView::UpdateInfoWindow(const BPath &path, BMessage &ioExtension, + const translator_info &tinfo, const char *tranname, const char *traninfo, + int32 tranversion) { BMessage msg(M_INFO_WINDOW_TEXT); BString bstr; @@ -348,6 +351,15 @@ ImageView::UpdateInfoWindow(const BPath &path, const translator_info &tinfo, bstr << "Quality: " << tinfo.quality << "\n"; bstr << "Capability: " << tinfo.capability << "\n"; + // Extension Info + bstr << "\nExtension Info:\n"; + int32 document_count = 0, document_index = 0; + if (ioExtension.FindInt32("/documentCount", &document_count) == B_OK) + bstr << "Number of Documents: " << document_count << "\n"; + if (ioExtension.FindInt32("/documentIndex", &document_index) == B_OK) + bstr << "Selected Document: " << document_index << "\n"; + + // Translator Info bstr << "\nTranslator Used:\n"; bstr << "Name: " << tranname << "\n"; @@ -391,12 +403,16 @@ ImageView::SetImage(BMessage *pmsg) // Replace current image with the image // specified in the given BMessage + entry_ref ref; + if (!pmsg) + ref = fcurrentRef; + else if (pmsg->FindRef("refs", &ref) != B_OK) + // If refs not found, just ignore the message + return; + StatusCheck chk; try { - entry_ref ref; - chk = pmsg->FindRef("refs", &ref); - BFile file(&ref, B_READ_ONLY); chk = file.InitCheck(); @@ -408,7 +424,9 @@ ImageView::SetImage(BMessage *pmsg) // determine what type the image is translator_info tinfo; - chk = proster->Identify(&file, NULL, &tinfo, 0, NULL, + BMessage ioExtension; + chk = ioExtension.AddInt32("/documentIndex", fdocumentIndex); + chk = proster->Identify(&file, &ioExtension, &tinfo, 0, NULL, B_TRANSLATOR_BITMAP); // get the name and info about the translator @@ -419,12 +437,20 @@ ImageView::SetImage(BMessage *pmsg) // perform the actual translation BBitmapStream outstream; - chk = proster->Translate(&file, &tinfo, NULL, &outstream, + chk = proster->Translate(&file, &tinfo, &ioExtension, &outstream, B_TRANSLATOR_BITMAP); BBitmap *pbitmap = NULL; chk = outstream.DetachBitmap(&pbitmap); fpbitmap = pbitmap; pbitmap = NULL; + fcurrentRef = ref; + // need to keep the ref around if user was to switch pages + int32 documentCount = 0; + if (ioExtension.FindInt32("/documentCount", &documentCount) == + B_OK && documentCount > 0) + fdocumentCount = documentCount; + else + fdocumentCount = 1; // Set the name of the Window to reflect the file name BWindow *pwin = Window(); @@ -438,7 +464,7 @@ ImageView::SetImage(BMessage *pmsg) } else pwin->SetTitle(IMAGEWINDOW_TITLE); - UpdateInfoWindow(path, tinfo, tranname, traninfo, tranversion); + UpdateInfoWindow(path, ioExtension, tinfo, tranname, traninfo, tranversion); // Resize parent window and set size limits to // reflect the size of the new bitmap @@ -479,3 +505,39 @@ ImageView::SetImage(BMessage *pmsg) } } +void +ImageView::FirstPage() +{ + if (fdocumentIndex != 1) { + fdocumentIndex = 1; + SetImage(NULL); + } +} + +void +ImageView::LastPage() +{ + if (fdocumentIndex != fdocumentCount) { + fdocumentIndex = fdocumentCount; + SetImage(NULL); + } +} + +void +ImageView::NextPage() +{ + if (fdocumentIndex < fdocumentCount) { + fdocumentIndex++; + SetImage(NULL); + } +} + +void +ImageView::PrevPage() +{ + if (fdocumentIndex > 1) { + fdocumentIndex--; + SetImage(NULL); + } +} + diff --git a/src/tools/translation/inspector/ImageView.h b/src/tools/translation/inspector/ImageView.h index 5d25875c67..09b23c8a5a 100644 --- a/src/tools/translation/inspector/ImageView.h +++ b/src/tools/translation/inspector/ImageView.h @@ -36,6 +36,7 @@ #include #include #include +#include #include class ImageView : public BView { @@ -54,15 +55,24 @@ public: void SetImage(BMessage *pmsg); bool HasImage() { return fpbitmap ? true : false; }; + void FirstPage(); + void LastPage(); + void NextPage(); + void PrevPage(); + private: - void UpdateInfoWindow(const BPath &path, const translator_info &info, - const char *tranname, const char *traninfo, int32 tranversion); + void UpdateInfoWindow(const BPath &path, BMessage &ioExtension, + const translator_info &info, const char *tranname, const char *traninfo, + int32 tranversion); void ReDraw(); void AdjustScrollBars(); void SaveImageAtDropLocation(BMessage *pmsg); BTranslatorRoster *SelectTranslatorRoster(BTranslatorRoster &roster); + entry_ref fcurrentRef; + int32 fdocumentIndex; + int32 fdocumentCount; BBitmap *fpbitmap; }; diff --git a/src/tools/translation/inspector/ImageWindow.cpp b/src/tools/translation/inspector/ImageWindow.cpp index 841456c0f1..4d0c0f4640 100644 --- a/src/tools/translation/inspector/ImageWindow.cpp +++ b/src/tools/translation/inspector/ImageWindow.cpp @@ -61,6 +61,26 @@ ImageWindow::ImageWindow(BRect rect, const char *name) pmnufile->AddItem(pitmquit); pbar->AddItem(pmnufile); + BMenu *pmnuview = new BMenu("View"); + BMenuItem *pitmfirst = new BMenuItem("First Page", + new BMessage(M_VIEW_FIRST_PAGE), 'F', 0); + + BMenuItem *pitmlast = new BMenuItem("Last Page", + new BMessage(M_VIEW_LAST_PAGE), 'L', 0); + + BMenuItem *pitmnext = new BMenuItem("Next Page", + new BMessage(M_VIEW_NEXT_PAGE), 'N', 0); + + BMenuItem *pitmprev = new BMenuItem("Previous Page", + new BMessage(M_VIEW_PREV_PAGE), 'P', 0); + + pmnuview->AddItem(pitmfirst); + pmnuview->AddItem(pitmlast); + pmnuview->AddItem(pitmnext); + pmnuview->AddItem(pitmprev); + pbar->AddItem(pmnuview); + + BMenu *pmnuwindow = new BMenu("Window"); BMenuItem *pitmactives = new BMenuItem("Active Translators", new BMessage(M_ACTIVE_TRANSLATORS_WINDOW), 'T', 0); @@ -126,6 +146,19 @@ ImageWindow::MessageReceived(BMessage *pmsg) fpimageView->SetImage(pmsg); break; + case M_VIEW_FIRST_PAGE: + fpimageView->FirstPage(); + break; + case M_VIEW_LAST_PAGE: + fpimageView->LastPage(); + break; + case M_VIEW_NEXT_PAGE: + fpimageView->NextPage(); + break; + case M_VIEW_PREV_PAGE: + fpimageView->PrevPage(); + break; + case B_CANCEL: break;