removed (page x of y) from status text, (page info should come from the identify string of translators that support multiple pages) added a border around the image (like Be's ShowImage has), added disabling of Page menu for single page images

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4218 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2003-08-03 15:29:07 +00:00
parent ab361b2efb
commit 1d5920700f
3 changed files with 43 additions and 18 deletions
+34 -16
View File
@@ -37,10 +37,15 @@
#include <Bitmap.h> #include <Bitmap.h>
#include <TranslatorRoster.h> #include <TranslatorRoster.h>
#include <BitmapStream.h> #include <BitmapStream.h>
#include <Rect.h>
#include "ShowImageConstants.h" #include "ShowImageConstants.h"
#include "ShowImageView.h" #include "ShowImageView.h"
#define BORDER_WIDTH 16
#define BORDER_HEIGHT 16
#define PEN_SIZE 1.0f
ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode, ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
uint32 flags) uint32 flags)
: BView(rect, name, resizingMode, flags) : BView(rect, name, resizingMode, flags)
@@ -50,6 +55,8 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
fdocumentCount = 1; fdocumentCount = 1;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(0, 0, 0);
SetPenSize(PEN_SIZE);
} }
ShowImageView::~ShowImageView() ShowImageView::~ShowImageView()
@@ -61,6 +68,7 @@ ShowImageView::~ShowImageView()
void void
ShowImageView::SetImage(const entry_ref *pref) ShowImageView::SetImage(const entry_ref *pref)
{ {
ClearViewBitmap();
delete fpbitmap; delete fpbitmap;
fpbitmap = NULL; fpbitmap = NULL;
@@ -104,13 +112,18 @@ ShowImageView::SetImage(const entry_ref *pref)
fdocumentCount = 1; fdocumentCount = 1;
// send message to parent about new image // send message to parent about new image
BString str = info.name;
str << " (page " << fdocumentIndex << " of " << fdocumentCount << ")";
BMessage msg(MSG_UPDATE_STATUS); BMessage msg(MSG_UPDATE_STATUS);
msg.AddString("status", str); msg.AddString("status", info.name);
BMessenger msgr(Window()); BMessenger msgr(Window());
msgr.SendMessage(&msg); msgr.SendMessage(&msg);
SetViewBitmap(fpbitmap, fpbitmap->Bounds(),
BRect(BORDER_WIDTH - PEN_SIZE, BORDER_HEIGHT - PEN_SIZE,
fpbitmap->Bounds().Width() + BORDER_WIDTH + PEN_SIZE,
fpbitmap->Bounds().Height() + BORDER_HEIGHT + PEN_SIZE),
B_FOLLOW_TOP | B_FOLLOW_LEFT, 0
);
FixupScrollBars(); FixupScrollBars();
Invalidate(); Invalidate();
} }
@@ -130,8 +143,14 @@ ShowImageView::AttachedToWindow()
void void
ShowImageView::Draw(BRect updateRect) ShowImageView::Draw(BRect updateRect)
{ {
if (fpbitmap) if (fpbitmap) {
DrawBitmap(fpbitmap, updateRect, updateRect); // Draw black rectangle around image
StrokeRect(
BRect(BORDER_WIDTH - PEN_SIZE,
BORDER_HEIGHT - PEN_SIZE,
fpbitmap->Bounds().Width() + BORDER_WIDTH + PEN_SIZE,
fpbitmap->Bounds().Height() + BORDER_HEIGHT + PEN_SIZE));
}
} }
void void
@@ -153,28 +172,27 @@ ShowImageView::MessageReceived(BMessage *pmsg)
void void
ShowImageView::FixupScrollBars() ShowImageView::FixupScrollBars()
{ {
if (!fpbitmap) BRect rctview = Bounds(), rctbitmap(0, 0, 0, 0);
return; if (fpbitmap)
rctbitmap = fpbitmap->Bounds();
BRect vBds = Bounds(), bBds = fpbitmap->Bounds();
float prop;
float range;
float prop, range;
BScrollBar *psb = ScrollBar(B_HORIZONTAL); BScrollBar *psb = ScrollBar(B_HORIZONTAL);
if (psb) { if (psb) {
range = bBds.Width() - vBds.Width(); range = rctbitmap.Width() + (BORDER_WIDTH * 2) - rctview.Width();
if (range < 0) range = 0; if (range < 0) range = 0;
prop = vBds.Width() / bBds.Width(); prop = rctview.Width() / (rctbitmap.Width() + (BORDER_WIDTH * 2));
if (prop > 1.0f) prop = 1.0f; if (prop > 1.0f) prop = 1.0f;
psb->SetRange(0, range); psb->SetRange(0, range);
psb->SetProportion(prop); psb->SetProportion(prop);
psb->SetSteps(10, 100); psb->SetSteps(10, 100);
} }
psb = ScrollBar(B_VERTICAL); psb = ScrollBar(B_VERTICAL);
if (psb) { if (psb) {
range = bBds.Height() - vBds.Height(); range = rctbitmap.Height() + (BORDER_HEIGHT * 2) - rctview.Height();
if (range < 0) range = 0; if (range < 0) range = 0;
prop = vBds.Height() / bBds.Height(); prop = rctview.Height() / (rctbitmap.Height() + (BORDER_HEIGHT * 2));
if (prop > 1.0f) prop = 1.0f; if (prop > 1.0f) prop = 1.0f;
psb->SetRange(0, range); psb->SetRange(0, range);
psb->SetProportion(prop); psb->SetProportion(prop);
+8 -2
View File
@@ -66,7 +66,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref)
// 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);
// 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);
@@ -173,7 +173,7 @@ 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"); pmenu = fppageMenu = new BMenu("Page");
AddItemMenu(pmenu, "First", MSG_PAGE_FIRST, 'F', 0, 'W', true); AddItemMenu(pmenu, "First", MSG_PAGE_FIRST, 'F', 0, 'W', true);
AddItemMenu(pmenu, "Last", MSG_PAGE_LAST, 'L', 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, "Next", MSG_PAGE_NEXT, 'N', 0, 'W', true);
@@ -265,6 +265,12 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
case MSG_UPDATE_STATUS: case MSG_UPDATE_STATUS:
{ {
bool benable = (fpimageView->PageCount() > 1) ? true : false;
if (fppageMenu->IsEnabled() != benable)
// Only call this function if the state is changing
// to avoid flickering
fppageMenu->SetEnabled(benable);
BString str; BString str;
if (pmsg->FindString("status", &str) == B_OK) if (pmsg->FindString("status", &str) == B_OK)
fpstatusView->SetText(str); fpstatusView->SetText(str);
+1
View File
@@ -73,6 +73,7 @@ private:
BFilePanel *fpsavePanel; BFilePanel *fpsavePanel;
BMenuBar *fpbar; BMenuBar *fpbar;
BMenu *fppageMenu;
entry_ref *fpref; entry_ref *fpref;
ShowImageView *fpimageView; ShowImageView *fpimageView;
ShowImageStatusView *fpstatusView; ShowImageStatusView *fpstatusView;