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

View File

@ -37,10 +37,15 @@
#include <Bitmap.h>
#include <TranslatorRoster.h>
#include <BitmapStream.h>
#include <Rect.h>
#include "ShowImageConstants.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,
uint32 flags)
: BView(rect, name, resizingMode, flags)
@ -50,6 +55,8 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
fdocumentCount = 1;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(0, 0, 0);
SetPenSize(PEN_SIZE);
}
ShowImageView::~ShowImageView()
@ -61,6 +68,7 @@ ShowImageView::~ShowImageView()
void
ShowImageView::SetImage(const entry_ref *pref)
{
ClearViewBitmap();
delete fpbitmap;
fpbitmap = NULL;
@ -104,13 +112,18 @@ ShowImageView::SetImage(const entry_ref *pref)
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);
msg.AddString("status", info.name);
BMessenger msgr(Window());
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();
Invalidate();
}
@ -130,8 +143,14 @@ ShowImageView::AttachedToWindow()
void
ShowImageView::Draw(BRect updateRect)
{
if (fpbitmap)
DrawBitmap(fpbitmap, updateRect, updateRect);
if (fpbitmap) {
// 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
@ -153,28 +172,27 @@ ShowImageView::MessageReceived(BMessage *pmsg)
void
ShowImageView::FixupScrollBars()
{
if (!fpbitmap)
return;
BRect vBds = Bounds(), bBds = fpbitmap->Bounds();
float prop;
float range;
BRect rctview = Bounds(), rctbitmap(0, 0, 0, 0);
if (fpbitmap)
rctbitmap = fpbitmap->Bounds();
float prop, range;
BScrollBar *psb = ScrollBar(B_HORIZONTAL);
if (psb) {
range = bBds.Width() - vBds.Width();
range = rctbitmap.Width() + (BORDER_WIDTH * 2) - rctview.Width();
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;
psb->SetRange(0, range);
psb->SetProportion(prop);
psb->SetSteps(10, 100);
}
psb = ScrollBar(B_VERTICAL);
if (psb) {
range = bBds.Height() - vBds.Height();
range = rctbitmap.Height() + (BORDER_HEIGHT * 2) - rctview.Height();
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;
psb->SetRange(0, range);
psb->SetProportion(prop);

View File

@ -66,7 +66,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref)
// create the image view
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
BScrollView *pscrollView = new BScrollView("image_scroller", fpimageView,
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);
pbar->AddItem(pmenu);
pmenu = new BMenu("Page");
pmenu = fppageMenu = 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);
@ -265,6 +265,12 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
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;
if (pmsg->FindString("status", &str) == B_OK)
fpstatusView->SetText(str);

View File

@ -73,6 +73,7 @@ private:
BFilePanel *fpsavePanel;
BMenuBar *fpbar;
BMenu *fppageMenu;
entry_ref *fpref;
ShowImageView *fpimageView;
ShowImageStatusView *fpstatusView;