Added multi-page support (as in OBOS TIFFTranslator). Made many changes to the way the app, window and view objects interface with each other. Still could use some polish.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4216 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -153,12 +153,5 @@ ShowImageApp::RefsReceived(BMessage *pmsg)
|
|||||||
void
|
void
|
||||||
ShowImageApp::Open(const entry_ref *pref)
|
ShowImageApp::Open(const entry_ref *pref)
|
||||||
{
|
{
|
||||||
if (ShowImageWindow::NewWindow(pref) != B_OK) {
|
new ShowImageWindow(pref);
|
||||||
char errStr[B_FILE_NAME_LENGTH + 50];
|
|
||||||
sprintf(errStr, "Couldn't open file: %s",
|
|
||||||
(pref && pref->name) ? pref->name : "???");
|
|
||||||
|
|
||||||
BAlert* pAlert = new BAlert("file i/o error", errStr, "OK");
|
|
||||||
pAlert->Go();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ const uint32 MSG_SAVE_PANEL = 'mFSP';
|
|||||||
const uint32 MSG_CLEAR_SELECT = 'mCSL';
|
const uint32 MSG_CLEAR_SELECT = 'mCSL';
|
||||||
const uint32 MSG_SELECT_ALL = 'mSAL';
|
const uint32 MSG_SELECT_ALL = 'mSAL';
|
||||||
const uint32 MSG_DITHER_IMAGE = 'mDIM';
|
const uint32 MSG_DITHER_IMAGE = 'mDIM';
|
||||||
|
const uint32 MSG_UPDATE_STATUS = 'mUPS';
|
||||||
|
const uint32 MSG_PAGE_FIRST = 'mPGF';
|
||||||
|
const uint32 MSG_PAGE_LAST = 'mPGL';
|
||||||
|
const uint32 MSG_PAGE_NEXT = 'mPGN';
|
||||||
|
const uint32 MSG_PAGE_PREV = 'mPGP';
|
||||||
|
|
||||||
extern const char *APP_SIG;
|
extern const char *APP_SIG;
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,16 @@
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <Bitmap.h>
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#include <StopWatch.h>
|
#include <StopWatch.h>
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
|
#include <File.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <TranslatorRoster.h>
|
||||||
|
#include <BitmapStream.h>
|
||||||
|
|
||||||
#include "ShowImageConstants.h"
|
#include "ShowImageConstants.h"
|
||||||
#include "ShowImageView.h"
|
#include "ShowImageView.h"
|
||||||
@@ -43,6 +46,9 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
|||||||
: BView(rect, name, resizingMode, flags)
|
: BView(rect, name, resizingMode, flags)
|
||||||
{
|
{
|
||||||
fpbitmap = NULL;
|
fpbitmap = NULL;
|
||||||
|
fdocumentIndex = 1;
|
||||||
|
fdocumentCount = 1;
|
||||||
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,9 +59,60 @@ ShowImageView::~ShowImageView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetBitmap(BBitmap *pbitmap)
|
ShowImageView::SetImage(const entry_ref *pref)
|
||||||
{
|
{
|
||||||
fpbitmap = pbitmap;
|
delete fpbitmap;
|
||||||
|
fpbitmap = NULL;
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
if (!pref)
|
||||||
|
ref = fcurrentRef;
|
||||||
|
else
|
||||||
|
ref = *pref;
|
||||||
|
|
||||||
|
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
||||||
|
if (!proster)
|
||||||
|
return;
|
||||||
|
BFile file(&ref, B_READ_ONLY);
|
||||||
|
translator_info info;
|
||||||
|
memset(&info, 0, sizeof(translator_info));
|
||||||
|
BMessage ioExtension;
|
||||||
|
if (ref != fcurrentRef)
|
||||||
|
// if new image, reset to first document
|
||||||
|
fdocumentIndex = 1;
|
||||||
|
if (ioExtension.AddInt32("/documentIndex", fdocumentIndex) != B_OK)
|
||||||
|
return;
|
||||||
|
if (proster->Identify(&file, &ioExtension, &info, 0, NULL,
|
||||||
|
B_TRANSLATOR_BITMAP) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Translate image data and create a new ShowImage window
|
||||||
|
BBitmapStream outstream;
|
||||||
|
if (proster->Translate(&file, &info, &ioExtension, &outstream,
|
||||||
|
B_TRANSLATOR_BITMAP) != B_OK)
|
||||||
|
return;
|
||||||
|
if (outstream.DetachBitmap(&fpbitmap) != B_OK)
|
||||||
|
return;
|
||||||
|
fcurrentRef = ref;
|
||||||
|
|
||||||
|
// get the number of documents (pages) if it has been supplied
|
||||||
|
int32 documentCount = 0;
|
||||||
|
if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK &&
|
||||||
|
documentCount > 0)
|
||||||
|
fdocumentCount = documentCount;
|
||||||
|
else
|
||||||
|
fdocumentCount = 1;
|
||||||
|
|
||||||
|
// send message to parent about new image
|
||||||
|
BString str = info.name;
|
||||||
|
str << " (page " << fdocumentIndex << " of " << fdocumentCount << ")";
|
||||||
|
BMessage msg(MSG_UPDATE_STATUS);
|
||||||
|
msg.AddString("status", str);
|
||||||
|
BMessenger msgr(Window());
|
||||||
|
msgr.SendMessage(&msg);
|
||||||
|
|
||||||
|
FixupScrollBars();
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
BBitmap *
|
BBitmap *
|
||||||
@@ -125,3 +182,50 @@ ShowImageView::FixupScrollBars()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
ShowImageView::CurrentPage()
|
||||||
|
{
|
||||||
|
return fdocumentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
ShowImageView::PageCount()
|
||||||
|
{
|
||||||
|
return fdocumentCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::FirstPage()
|
||||||
|
{
|
||||||
|
if (fdocumentIndex != 1) {
|
||||||
|
fdocumentIndex = 1;
|
||||||
|
SetImage(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::LastPage()
|
||||||
|
{
|
||||||
|
if (fdocumentIndex != fdocumentCount) {
|
||||||
|
fdocumentIndex = fdocumentCount;
|
||||||
|
SetImage(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::NextPage()
|
||||||
|
{
|
||||||
|
if (fdocumentIndex < fdocumentCount) {
|
||||||
|
fdocumentIndex++;
|
||||||
|
SetImage(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::PrevPage()
|
||||||
|
{
|
||||||
|
if (fdocumentIndex > 1) {
|
||||||
|
fdocumentIndex--;
|
||||||
|
SetImage(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
#define _ShowImageView_h
|
#define _ShowImageView_h
|
||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
class ShowImageView : public BView {
|
class ShowImageView : public BView {
|
||||||
public:
|
public:
|
||||||
@@ -37,7 +40,7 @@ public:
|
|||||||
uint32 flags);
|
uint32 flags);
|
||||||
~ShowImageView();
|
~ShowImageView();
|
||||||
|
|
||||||
void SetBitmap(BBitmap *pbitmap);
|
void SetImage(const entry_ref *pref);
|
||||||
BBitmap *GetBitmap();
|
BBitmap *GetBitmap();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
@@ -47,7 +50,18 @@ public:
|
|||||||
|
|
||||||
void FixupScrollBars();
|
void FixupScrollBars();
|
||||||
|
|
||||||
|
int32 CurrentPage();
|
||||||
|
int32 PageCount();
|
||||||
|
|
||||||
|
void FirstPage();
|
||||||
|
void LastPage();
|
||||||
|
void NextPage();
|
||||||
|
void PrevPage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
entry_ref fcurrentRef;
|
||||||
|
int32 fdocumentIndex;
|
||||||
|
int32 fdocumentCount;
|
||||||
BBitmap *fpbitmap;
|
BBitmap *fpbitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -48,32 +48,7 @@
|
|||||||
#include "ShowImageView.h"
|
#include "ShowImageView.h"
|
||||||
#include "ShowImageStatusView.h"
|
#include "ShowImageStatusView.h"
|
||||||
|
|
||||||
status_t
|
ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
||||||
ShowImageWindow::NewWindow(const entry_ref *pref)
|
|
||||||
{
|
|
||||||
// Get identify string (image type)
|
|
||||||
BString strId = "Unknown image type";
|
|
||||||
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
|
||||||
if (!proster)
|
|
||||||
return B_ERROR;
|
|
||||||
BFile file(pref, B_READ_ONLY);
|
|
||||||
translator_info info;
|
|
||||||
if (proster->Identify(&file, NULL, &info) == B_OK)
|
|
||||||
strId = info.name;
|
|
||||||
|
|
||||||
// Translate image data and create a new ShowImage window
|
|
||||||
file.Seek(0, SEEK_SET);
|
|
||||||
BBitmap* pbitmap = BTranslationUtils::GetBitmap(&file);
|
|
||||||
if (pbitmap) {
|
|
||||||
ShowImageWindow* pwin = new ShowImageWindow(pref, pbitmap, strId);
|
|
||||||
return pwin->InitCheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
ShowImageWindow::ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap,
|
|
||||||
BString &strId)
|
|
||||||
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
||||||
{
|
{
|
||||||
fpsavePanel = NULL;
|
fpsavePanel = NULL;
|
||||||
@@ -92,8 +67,6 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap,
|
|||||||
// create the image view
|
// create the image view
|
||||||
fpimageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
fpimageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
||||||
fpimageView->SetBitmap(pbitmap);
|
|
||||||
|
|
||||||
// wrap a scroll view around the view
|
// wrap a scroll view around the view
|
||||||
BScrollView *pscrollView = new BScrollView("image_scroller", fpimageView,
|
BScrollView *pscrollView = new BScrollView("image_scroller", fpimageView,
|
||||||
B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
|
B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
|
||||||
@@ -112,12 +85,10 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap,
|
|||||||
|
|
||||||
rect.left = 0;
|
rect.left = 0;
|
||||||
rect.right = kstatusWidth - 1;
|
rect.right = kstatusWidth - 1;
|
||||||
ShowImageStatusView *pstatusView;
|
fpstatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
|
||||||
pstatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
|
|
||||||
B_WILL_DRAW);
|
B_WILL_DRAW);
|
||||||
pstatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
fpstatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
||||||
pstatusView->SetText(strId);
|
AddChild(fpstatusView);
|
||||||
AddChild(pstatusView);
|
|
||||||
|
|
||||||
rect = Bounds();
|
rect = Bounds();
|
||||||
rect.top = viewFrame.top;
|
rect.top = viewFrame.top;
|
||||||
@@ -127,12 +98,14 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap,
|
|||||||
pvscroll = new BScrollBar(rect, "vscroll", fpimageView, 0, 150, B_VERTICAL);
|
pvscroll = new BScrollBar(rect, "vscroll", fpimageView, 0, 150, B_VERTICAL);
|
||||||
AddChild(pvscroll);
|
AddChild(pvscroll);
|
||||||
|
|
||||||
WindowRedimension(pbitmap);
|
SetSizeLimits(250, 100000, 100, 100000);
|
||||||
|
|
||||||
// finish creating window
|
// finish creating window
|
||||||
SetRef(pref);
|
SetRef(pref);
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
|
|
||||||
|
fpimageView->SetImage(pref);
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +173,13 @@ ShowImageWindow::LoadMenus(BMenuBar *pbar)
|
|||||||
AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', false);
|
AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', false);
|
||||||
pbar->AddItem(pmenu);
|
pbar->AddItem(pmenu);
|
||||||
|
|
||||||
|
pmenu = new BMenu("Page");
|
||||||
|
AddItemMenu(pmenu, "First", MSG_PAGE_FIRST, 'F', 0, 'W', true);
|
||||||
|
AddItemMenu(pmenu, "Last", MSG_PAGE_LAST, 'L', 0, 'W', true);
|
||||||
|
AddItemMenu(pmenu, "Next", MSG_PAGE_NEXT, 'N', 0, 'W', true);
|
||||||
|
AddItemMenu(pmenu, "Previous", MSG_PAGE_PREV, 'P', 0, 'W', true);
|
||||||
|
pbar->AddItem(pmenu);
|
||||||
|
|
||||||
pmenu = new BMenu("Image");
|
pmenu = new BMenu("Image");
|
||||||
AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
||||||
pbar->AddItem(pmenu);
|
pbar->AddItem(pmenu);
|
||||||
@@ -283,6 +263,14 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
|
|||||||
fpsavePanel = NULL;
|
fpsavePanel = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MSG_UPDATE_STATUS:
|
||||||
|
{
|
||||||
|
BString str;
|
||||||
|
if (pmsg->FindString("status", &str) == B_OK)
|
||||||
|
fpstatusView->SetText(str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case B_UNDO:
|
case B_UNDO:
|
||||||
break;
|
break;
|
||||||
case B_CUT:
|
case B_CUT:
|
||||||
@@ -296,6 +284,22 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
|
|||||||
case MSG_SELECT_ALL:
|
case MSG_SELECT_ALL:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MSG_PAGE_FIRST:
|
||||||
|
fpimageView->FirstPage();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSG_PAGE_LAST:
|
||||||
|
fpimageView->LastPage();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSG_PAGE_NEXT:
|
||||||
|
fpimageView->NextPage();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSG_PAGE_PREV:
|
||||||
|
fpimageView->PrevPage();
|
||||||
|
break;
|
||||||
|
|
||||||
case MSG_DITHER_IMAGE:
|
case MSG_DITHER_IMAGE:
|
||||||
BMenuItem *pmenuDither;
|
BMenuItem *pmenuDither;
|
||||||
pmenuDither = fpbar->FindItem(pmsg->what);
|
pmenuDither = fpbar->FindItem(pmsg->what);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
class ShowImageView;
|
class ShowImageView;
|
||||||
|
class ShowImageStatusView;
|
||||||
|
|
||||||
// BMessage field names used in Save messages
|
// BMessage field names used in Save messages
|
||||||
#define TRANSLATOR_FLD "be:translator"
|
#define TRANSLATOR_FLD "be:translator"
|
||||||
@@ -42,9 +43,7 @@ class ShowImageView;
|
|||||||
|
|
||||||
class ShowImageWindow : public BWindow {
|
class ShowImageWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
static status_t NewWindow(const entry_ref *pref);
|
ShowImageWindow(const entry_ref *pref);
|
||||||
|
|
||||||
ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap, BString &strId);
|
|
||||||
virtual ~ShowImageWindow();
|
virtual ~ShowImageWindow();
|
||||||
|
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
@@ -76,6 +75,7 @@ private:
|
|||||||
BMenuBar *fpbar;
|
BMenuBar *fpbar;
|
||||||
entry_ref *fpref;
|
entry_ref *fpref;
|
||||||
ShowImageView *fpimageView;
|
ShowImageView *fpimageView;
|
||||||
|
ShowImageStatusView *fpstatusView;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _ShowImageWindow_h */
|
#endif /* _ShowImageWindow_h */
|
||||||
|
|||||||
Reference in New Issue
Block a user