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
|
||||
ShowImageApp::Open(const entry_ref *pref)
|
||||
{
|
||||
if (ShowImageWindow::NewWindow(pref) != B_OK) {
|
||||
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();
|
||||
}
|
||||
new ShowImageWindow(pref);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ const uint32 MSG_SAVE_PANEL = 'mFSP';
|
||||
const uint32 MSG_CLEAR_SELECT = 'mCSL';
|
||||
const uint32 MSG_SELECT_ALL = 'mSAL';
|
||||
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;
|
||||
|
||||
|
||||
@@ -27,13 +27,16 @@
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Message.h>
|
||||
#include <ScrollBar.h>
|
||||
#include <StopWatch.h>
|
||||
#include <Alert.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <File.h>
|
||||
#include <Bitmap.h>
|
||||
#include <TranslatorRoster.h>
|
||||
#include <BitmapStream.h>
|
||||
|
||||
#include "ShowImageConstants.h"
|
||||
#include "ShowImageView.h"
|
||||
@@ -43,6 +46,9 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
||||
: BView(rect, name, resizingMode, flags)
|
||||
{
|
||||
fpbitmap = NULL;
|
||||
fdocumentIndex = 1;
|
||||
fdocumentCount = 1;
|
||||
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
}
|
||||
|
||||
@@ -53,9 +59,60 @@ ShowImageView::~ShowImageView()
|
||||
}
|
||||
|
||||
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 *
|
||||
@@ -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
|
||||
|
||||
#include <View.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Entry.h>
|
||||
#include <String.h>
|
||||
|
||||
class ShowImageView : public BView {
|
||||
public:
|
||||
@@ -37,7 +40,7 @@ public:
|
||||
uint32 flags);
|
||||
~ShowImageView();
|
||||
|
||||
void SetBitmap(BBitmap *pbitmap);
|
||||
void SetImage(const entry_ref *pref);
|
||||
BBitmap *GetBitmap();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
@@ -47,7 +50,18 @@ public:
|
||||
|
||||
void FixupScrollBars();
|
||||
|
||||
int32 CurrentPage();
|
||||
int32 PageCount();
|
||||
|
||||
void FirstPage();
|
||||
void LastPage();
|
||||
void NextPage();
|
||||
void PrevPage();
|
||||
|
||||
private:
|
||||
entry_ref fcurrentRef;
|
||||
int32 fdocumentIndex;
|
||||
int32 fdocumentCount;
|
||||
BBitmap *fpbitmap;
|
||||
};
|
||||
|
||||
|
||||
@@ -48,32 +48,7 @@
|
||||
#include "ShowImageView.h"
|
||||
#include "ShowImageStatusView.h"
|
||||
|
||||
status_t
|
||||
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)
|
||||
ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
||||
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
||||
{
|
||||
fpsavePanel = NULL;
|
||||
@@ -91,9 +66,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap,
|
||||
|
||||
// create the image view
|
||||
fpimageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
||||
fpimageView->SetBitmap(pbitmap);
|
||||
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
||||
// wrap a scroll view around the view
|
||||
BScrollView *pscrollView = new BScrollView("image_scroller", fpimageView,
|
||||
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.right = kstatusWidth - 1;
|
||||
ShowImageStatusView *pstatusView;
|
||||
pstatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
|
||||
fpstatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
|
||||
B_WILL_DRAW);
|
||||
pstatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
||||
pstatusView->SetText(strId);
|
||||
AddChild(pstatusView);
|
||||
fpstatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
||||
AddChild(fpstatusView);
|
||||
|
||||
rect = Bounds();
|
||||
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);
|
||||
AddChild(pvscroll);
|
||||
|
||||
WindowRedimension(pbitmap);
|
||||
SetSizeLimits(250, 100000, 100, 100000);
|
||||
|
||||
// finish creating window
|
||||
SetRef(pref);
|
||||
UpdateTitle();
|
||||
|
||||
fpimageView->SetImage(pref);
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -200,6 +173,13 @@ ShowImageWindow::LoadMenus(BMenuBar *pbar)
|
||||
AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', false);
|
||||
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");
|
||||
AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
||||
pbar->AddItem(pmenu);
|
||||
@@ -282,6 +262,14 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
|
||||
delete fpsavePanel;
|
||||
fpsavePanel = NULL;
|
||||
break;
|
||||
|
||||
case MSG_UPDATE_STATUS:
|
||||
{
|
||||
BString str;
|
||||
if (pmsg->FindString("status", &str) == B_OK)
|
||||
fpstatusView->SetText(str);
|
||||
break;
|
||||
}
|
||||
|
||||
case B_UNDO:
|
||||
break;
|
||||
@@ -295,6 +283,22 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
|
||||
break;
|
||||
case MSG_SELECT_ALL:
|
||||
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:
|
||||
BMenuItem *pmenuDither;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <String.h>
|
||||
|
||||
class ShowImageView;
|
||||
class ShowImageStatusView;
|
||||
|
||||
// BMessage field names used in Save messages
|
||||
#define TRANSLATOR_FLD "be:translator"
|
||||
@@ -42,9 +43,7 @@ class ShowImageView;
|
||||
|
||||
class ShowImageWindow : public BWindow {
|
||||
public:
|
||||
static status_t NewWindow(const entry_ref *pref);
|
||||
|
||||
ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap, BString &strId);
|
||||
ShowImageWindow(const entry_ref *pref);
|
||||
virtual ~ShowImageWindow();
|
||||
|
||||
virtual void FrameResized(float width, float height);
|
||||
@@ -76,6 +75,7 @@ private:
|
||||
BMenuBar *fpbar;
|
||||
entry_ref *fpref;
|
||||
ShowImageView *fpimageView;
|
||||
ShowImageStatusView *fpstatusView;
|
||||
};
|
||||
|
||||
#endif /* _ShowImageWindow_h */
|
||||
|
||||
Reference in New Issue
Block a user