* code and style cleanup, no functional change...

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24661 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich 2008-03-29 16:26:18 +00:00
parent d8d5b63a94
commit 77b6a3f51b
2 changed files with 557 additions and 421 deletions

View File

@ -5,9 +5,8 @@
* Authors:
* Michael Pfeiffer
* Hartmut Reh
* julun <host.haiku@gmx.de>
*/
// TODO Remove. Use shared/libprint/Preview.cpp instead.
#include <stdlib.h>
@ -19,61 +18,80 @@
#include "Preview.h"
// Implementation of PreviewPage
// #pragma mark - PreviewPage
PreviewPage::PreviewPage(int32 page, PrintJobPage* pjp)
: fPage(page)
, fPictures(NULL)
, fPoints(NULL)
, fStatus(B_ERROR)
, fNumberOfPictures(0)
, fRects(NULL)
, fPoints(NULL)
, fPictures(NULL)
{
fNumberOfPictures = pjp->NumberOfPictures();
fPictures = new BPicture[fNumberOfPictures];
fPoints = new BPoint[fNumberOfPictures];
fRects = new BRect[fNumberOfPictures];
status_t rc = B_ERROR;
for (int32 i = 0; i < fNumberOfPictures &&
(rc = pjp->NextPicture(fPictures[i], fPoints[i], fRects[i])) == B_OK; i ++);
fStatus = rc;
}
fPoints = new BPoint[fNumberOfPictures];
fPictures = new BPicture[fNumberOfPictures];
PreviewPage::~PreviewPage() {
delete []fPictures;
delete []fPoints;
delete []fRects;
}
status_t PreviewPage::InitCheck() const {
return fStatus;
}
void PreviewPage::Draw(BView* view)
{
ASSERT(fStatus == B_OK);
for (int32 i = 0; i < fNumberOfPictures; i ++)
{
view->DrawPicture(&fPictures[i], fPoints[i]);
for (int32 i = 0; i < fNumberOfPictures; ++i) {
fStatus = pjp->NextPicture(fPictures[i], fPoints[i], fRects[i]);
if (fStatus != B_OK)
break;
}
}
// Implementation of PreviewView
PreviewPage::~PreviewPage()
{
delete [] fRects;
delete [] fPoints;
delete [] fPictures;
}
status_t
PreviewPage::InitCheck() const
{
return fStatus;
}
void
PreviewPage::Draw(BView* view)
{
ASSERT(fStatus == B_OK);
for (int32 i = 0; i < fNumberOfPictures; i++)
view->DrawPicture(&fPictures[i], fPoints[i]);
}
// #pragma mark - PreviewView
const float kPreviewTopMargin = 10;
const float kPreviewBottomMargin = 30;
const float kPreviewLeftMargin = 10;
const float kPreviewRightMargin = 30;
const uint8 ZOOM_IN[] = { 16, 1, 6, 6, 0, 0, 15, 128, 48, 96, 32, 32, 66, 16, 66, 16,
79, 144, 66, 16, 66, 16, 32, 32, 48, 112, 15, 184, 0, 28, 0, 14, 0, 6, 0, 0, 15,
128, 63, 224, 127, 240, 127, 240, 255, 248, 255, 248, 255, 248, 255, 248, 255, 248,
127, 248, 127, 248, 63, 252, 15, 254, 0, 31, 0, 15, 0, 7 };
const uint8 ZOOM_OUT[] = { 16, 1, 6, 6, 0, 0, 15, 128, 48, 96, 32, 32, 64, 16, 64, 16,
79, 144, 64, 16, 64, 16, 32, 32, 48, 112, 15, 184, 0, 28, 0, 14, 0, 6, 0, 0, 15,
128, 63, 224, 127, 240, 127, 240, 255, 248, 255, 248, 255, 248, 255, 248, 255, 248,
127, 248, 127, 248, 63, 252, 15, 254, 0, 31, 0, 15, 0, 7 };
const uint8 ZOOM_IN[] = { 16, 1, 6, 6, 0, 0, 15, 128, 48, 96, 32, 32, 66, 16,
66, 16, 79, 144, 66, 16, 66, 16, 32, 32, 48, 112, 15, 184, 0, 28, 0, 14, 0,
6, 0, 0, 15, 128, 63, 224, 127, 240, 127, 240, 255, 248, 255, 248, 255, 248,
255, 248, 255, 248, 127, 248, 127, 248, 63, 252, 15, 254, 0, 31, 0, 15, 0, 7 };
const uint8 ZOOM_OUT[] = { 16, 1, 6, 6, 0, 0, 15, 128, 48, 96, 32, 32, 64, 16,
64, 16, 79, 144, 64, 16, 64, 16, 32, 32, 48, 112, 15, 184, 0, 28, 0, 14, 0,
6, 0, 0, 15, 128, 63, 224, 127, 240, 127, 240, 255, 248, 255, 248, 255, 248,
255, 248, 255, 248, 127, 248, 127, 248, 63, 252, 15, 254, 0, 31, 0, 15, 0, 7 };
PreviewView::PreviewView(BFile* jobFile, BRect rect)
: BView(rect, "PreviewView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE)
: BView(rect, "PreviewView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS |
B_NAVIGABLE)
, fPage(0)
, fZoom(0)
, fTracking(false)
@ -96,6 +114,28 @@ PreviewView::Show()
}
void
PreviewView::Draw(BRect rect)
{
if (fReader.InitCheck() == B_OK) {
if (!_IsPageLoaded(fPage))
_LoadPage(fPage);
if (_IsPageValid()) {
_DrawPageFrame(rect);
_DrawPage(rect);
}
}
}
void
PreviewView::FrameResized(float width, float height)
{
FixScrollbars();
}
void
PreviewView::MouseDown(BPoint point)
{
@ -184,7 +224,7 @@ PreviewView::MouseUp(BPoint point)
void
PreviewView::KeyDown(const char* bytes, int32 numBytes)
{
MakeFocus(true);
MakeFocus(true);
switch (bytes[0]) {
case '-': {
if (modifiers() & B_CONTROL_KEY)
@ -203,8 +243,178 @@ PreviewView::KeyDown(const char* bytes, int32 numBytes)
}
void
PreviewView::ShowFirstPage()
{
if (!ShowsFirstPage()) {
fPage = 0;
Invalidate();
}
}
void
PreviewView::ShowPrevPage()
{
if (!ShowsFirstPage()) {
fPage --;
Invalidate();
}
}
void
PreviewView::ShowNextPage()
{
if (!ShowsLastPage()) {
fPage ++;
Invalidate();
}
}
void
PreviewView::ShowLastPage()
{
if (!ShowsLastPage()) {
fPage = NumberOfPages()-1;
Invalidate();
}
}
bool
PreviewView::ShowsFirstPage() const
{
return fPage == 0;
}
bool
PreviewView::ShowsLastPage() const
{
return fPage == NumberOfPages() - 1;
}
void
PreviewView::ShowFindPage(int32 page)
{
page--;
if (page < 0) {
page = 0;
} else if (page > (NumberOfPages()-1)) {
page = NumberOfPages()-1;
}
fPage = (int32)page;
Invalidate();
}
void
PreviewView::ZoomIn()
{
if (CanZoomIn()) {
fZoom ++; FixScrollbars();
Invalidate();
}
}
bool
PreviewView::CanZoomIn() const
{
return fZoom < 4;
}
void
PreviewView::ZoomOut()
{
if (CanZoomOut()) {
fZoom --; FixScrollbars();
Invalidate();
}
}
bool
PreviewView::CanZoomOut() const
{
return fZoom > -2;
}
void
PreviewView::FixScrollbars()
{
float width = _PageRect().Width() + kPreviewLeftMargin + kPreviewRightMargin;
float height = _PageRect().Height() + kPreviewTopMargin + kPreviewBottomMargin;
BRect frame(Bounds());
float x = width - frame.Width();
if (x < 0.0)
x = 0.0;
float y = height - frame.Height();
if (y < 0.0)
y = 0.0;
BScrollBar * scroll = ScrollBar(B_HORIZONTAL);
scroll->SetRange (0.0, x);
scroll->SetProportion ((width - x) / width);
float bigStep = frame.Width() - 2;
float smallStep = bigStep / 10.;
scroll->SetSteps (smallStep, bigStep);
scroll = ScrollBar (B_VERTICAL);
scroll->SetRange (0.0, y);
scroll->SetProportion ((height - y) / height);
bigStep = frame.Height() - 2;
smallStep = bigStep / 10.;
scroll->SetSteps (smallStep, bigStep);
}
BRect
PreviewView::ViewRect() const
{
BRect r(_PageRect());
r.right += kPreviewLeftMargin + kPreviewRightMargin;
r.bottom += kPreviewTopMargin + kPreviewBottomMargin;
return r;
}
status_t
PreviewView::InitCheck() const
{
return fReader.InitCheck();
}
int32
PreviewView::NumberOfPages() const
{
return fReader.NumberOfPages();
}
BRect
PreviewView::_PageRect() const
{
float f = _ZoomFactor();
BRect r = fReader.PaperRect();
return ScaleRect(r, f);
}
// returns 2 ^ fZoom
float PreviewView::ZoomFactor() const {
float
PreviewView::_ZoomFactor() const
{
const int32 b = 4;
int32 zoom;
if (fZoom > 0) {
@ -216,288 +426,169 @@ float PreviewView::ZoomFactor() const {
return factor * fReader.GetScale() / 100.0;
}
BRect PreviewView::PageRect() const {
float f = ZoomFactor();
BRect r = fReader.PaperRect();
return ScaleRect(r, f);
}
BRect PreviewView::PrintableRect() const {
float f = ZoomFactor();
BRect
PreviewView::_PrintableRect() const
{
float f = _ZoomFactor();
BRect r = fReader.PrintableRect();
return ScaleRect(r, f);
}
BRect PreviewView::ViewRect() const {
BRect r(PageRect());
r.right += kPreviewLeftMargin + kPreviewRightMargin;
r.bottom += kPreviewTopMargin + kPreviewBottomMargin;
return r;
}
status_t PreviewView::InitCheck() const {
return fReader.InitCheck();
}
bool PreviewView::IsPageLoaded(int32 page) const {
return fCachedPage != NULL && fCachedPage->Page() == page;
}
bool PreviewView::IsPageValid() const {
bool
PreviewView::_IsPageValid() const
{
return fCachedPage && fCachedPage->InitCheck() == B_OK;
}
void PreviewView::LoadPage(int32 page) {
delete fCachedPage; fCachedPage = NULL;
void
PreviewView::_LoadPage(int32 page)
{
delete fCachedPage;
fCachedPage = NULL;
PrintJobPage pjp;
if (fReader.GetPage(page, pjp) == B_OK) {
if (fReader.GetPage(page, pjp) == B_OK)
fCachedPage = new PreviewPage(page, &pjp);
}
}
void PreviewView::DrawPageFrame(BRect rect) {
bool
PreviewView::_IsPageLoaded(int32 page) const
{
return fCachedPage != NULL && fCachedPage->Page() == page;
}
void
PreviewView::_DrawPageFrame(BRect rect)
{
const float kShadowIndent = 3;
const float kShadowWidth = 3;
float x, y;
float right, bottom;
rgb_color frameColor = {0, 0, 0, 0};
rgb_color shadowColor = {90, 90, 90, 0};
BRect r(PageRect());
rgb_color frameColor = { 0, 0, 0, 0 };
rgb_color shadowColor = { 90, 90, 90, 0 };
PushState();
// draw page border around page
r.InsetBy(-1, -1);
BRect r(_PageRect().InsetByCopy(-1, -1));
r.OffsetTo(kPreviewLeftMargin-1, kPreviewTopMargin-1);
SetHighColor(frameColor);
StrokeRect(r);
// draw page shadow
SetHighColor(shadowColor);
x = r.right + 1;
right = x + kShadowWidth;
bottom = r.bottom + 1 + kShadowWidth;
y = r.top + kShadowIndent;
float x = r.right + 1;
float right = x + kShadowWidth;
float bottom = r.bottom + 1 + kShadowWidth;
float y = r.top + kShadowIndent;
FillRect(BRect(x, y, right, bottom));
x = r.left + kShadowIndent;
y = r.bottom + 1;
FillRect(BRect(x, y, r.right, bottom));
PopState();
}
void PreviewView::DrawPage(BRect rect)
{
void
PreviewView::_DrawPage(BRect rect)
{
// constrain clipping region to printable rectangle
BRect r(PrintableRect());
BRect r(_PrintableRect());
r.OffsetBy(kPreviewLeftMargin, kPreviewTopMargin);
BRegion clip(r);
// Text drawing does not work if clipping region
// is constraint.
// TODO enable after app_server bug has been fixed
// ConstrainClippingRegion(&clip);
ConstrainClippingRegion(&clip);
// draw page contents
PushState();
// print job coordinates are relative to the printable rect
BRect printRect = fReader.PrintableRect();
SetOrigin(kPreviewLeftMargin + printRect.left * ZoomFactor(),
kPreviewTopMargin + printRect.top * ZoomFactor());
SetScale(ZoomFactor());
PushState();
fCachedPage->Draw(this);
PopState();
SetOrigin(kPreviewLeftMargin + printRect.left * _ZoomFactor(),
kPreviewTopMargin + printRect.top * _ZoomFactor());
SetScale(_ZoomFactor());
PushState();
fCachedPage->Draw(this);
PopState();
PopState();
}
void PreviewView::Draw(BRect rect) {
if (fReader.InitCheck() == B_OK) {
if (!IsPageLoaded(fPage)) {
LoadPage(fPage);
}
if (IsPageValid()) {
DrawPageFrame(rect);
DrawPage(rect);
}
}
}
void PreviewView::FrameResized(float width, float height) {
FixScrollbars();
}
// #pragma mark - PreviewWindow
bool PreviewView::ShowsFirstPage() const {
return fPage == 0;
}
bool PreviewView::ShowsLastPage() const {
return fPage == NumberOfPages() - 1;
}
int PreviewView::NumberOfPages() const {
return fReader.NumberOfPages();
}
void PreviewView::ShowNextPage() {
if (!ShowsLastPage()) {
fPage ++;
Invalidate();
}
}
void PreviewView::ShowPrevPage() {
if (!ShowsFirstPage()) {
fPage --;
Invalidate();
}
}
void PreviewView::ShowFirstPage() {
if (!ShowsFirstPage()) {
fPage = 0;
Invalidate();
}
}
void PreviewView::ShowLastPage() {
if (!ShowsLastPage()) {
fPage = NumberOfPages()-1;
Invalidate();
}
}
void PreviewView::ShowFindPage(int page) {
page --;
if (page < 0) {
page = 0;
} else if (page > (NumberOfPages()-1)) {
page = NumberOfPages()-1;
}
fPage = (int32)page;
Invalidate();
}
bool PreviewView::CanZoomIn() const {
return fZoom < 4;
}
bool PreviewView::CanZoomOut() const {
return fZoom > -2;
}
void PreviewView::ZoomIn() {
if (CanZoomIn()) {
fZoom ++; FixScrollbars();
Invalidate();
}
}
void PreviewView::ZoomOut() {
if (CanZoomOut()) {
fZoom --; FixScrollbars();
Invalidate();
}
}
void PreviewView::FixScrollbars() {
BRect frame = Bounds();
BScrollBar * scroll;
float x, y;
float bigStep, smallStep;
float width = PageRect().Width() + kPreviewLeftMargin + kPreviewRightMargin;
float height = PageRect().Height() + kPreviewTopMargin + kPreviewBottomMargin;
x = width - frame.Width();
if (x < 0.0) {
x = 0.0;
}
y = height - frame.Height();
if (y < 0.0) {
y = 0.0;
}
scroll = ScrollBar (B_HORIZONTAL);
scroll->SetRange (0.0, x);
scroll->SetProportion ((width - x) / width);
bigStep = frame.Width() - 2;
smallStep = bigStep / 10.;
scroll->SetSteps (smallStep, bigStep);
scroll = ScrollBar (B_VERTICAL);
scroll->SetRange (0.0, y);
scroll->SetProportion ((height - y) / height);
bigStep = frame.Height() - 2;
smallStep = bigStep / 10.;
scroll->SetSteps (smallStep, bigStep);
}
// Implementation of PreviewWindow
PreviewWindow::PreviewWindow(BFile* jobFile)
PreviewWindow::PreviewWindow(BFile* jobFile)
: BlockingWindow(BRect(20, 24, 400, 600), "Preview", B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS)
, fButtonBarHeight(0.0)
{
const float kButtonDistance = 15;
const float kPageTextDistance = 10;
float top = 7;
float left = 20;
float width, height;
BRect r = Frame();
r.right = r.IntegerWidth() - B_V_SCROLL_BAR_WIDTH; r.left = 0;
r.bottom = r.IntegerHeight() - B_H_SCROLL_BAR_HEIGHT; r.top = 0;
// add navigation and zoom buttons
BRect r = Frame();
r.OffsetTo(B_ORIGIN);
r.right = r.IntegerWidth() - B_V_SCROLL_BAR_WIDTH;
r.bottom = r.IntegerHeight() - B_H_SCROLL_BAR_HEIGHT;
// add navigation and zoom buttons
// largest button first to get its size
fPrev = new BButton(BRect(left, top, left+10, top+10), "Prev", "Previous Page", new BMessage(MSG_PREV_PAGE));
fPrev = new BButton(BRect(left, top, left+10, top+10), "Prev", "Previous Page",
new BMessage(MSG_PREV_PAGE));
AddChild(fPrev);
fPrev->ResizeToPreferred();
width = fPrev->Bounds().Width()+1;
height = fPrev->Bounds().Height()+1;
fFirst = new BButton(BRect(left, top, left+10, top+10), "First", "First Page", new BMessage(MSG_FIRST_PAGE));
fFirst = new BButton(BRect(left, top, left+10, top+10), "First", "First Page",
new BMessage(MSG_FIRST_PAGE));
AddChild(fFirst);
fFirst->ResizeTo(width, height);
left = fFirst->Frame().right + kButtonDistance;
// move Previous Page button after First Page button
fPrev->MoveTo(left, top);
fPrev->MoveTo(left, top);
left = fPrev->Frame().right + kButtonDistance;
fNext = new BButton(BRect(left, top, left+10, top+10), "Next", "Next Page", new BMessage(MSG_NEXT_PAGE));
fNext = new BButton(BRect(left, top, left+10, top+10), "Next", "Next Page",
new BMessage(MSG_NEXT_PAGE));
AddChild(fNext);
fNext->ResizeTo(width, height);
left = fNext->Frame().right + kButtonDistance;
fLast = new BButton(BRect(left, top, left+10, top+10), "Last", "Last Page", new BMessage(MSG_LAST_PAGE));
fLast = new BButton(BRect(left, top, left+10, top+10), "Last", "Last Page",
new BMessage(MSG_LAST_PAGE));
AddChild(fLast);
fLast->ResizeTo(width, height);
left = fLast->Frame().right + kPageTextDistance;
// page number text
fPageNumber = new BTextControl(BRect(left, top+3, left+10, top+10), "FindPage", "", "", new BMessage(MSG_FIND_PAGE));
fPageNumber = new BTextControl(BRect(left, top+3, left+10, top+10), "FindPage",
"", "", new BMessage(MSG_FIND_PAGE));
fPageNumber->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_RIGHT);
int num;
uint32 num;
for (num = 0; num <= 255; num++) {
fPageNumber->TextView()->DisallowChar(num);
}
for (num = 0; num <= 9; num++) {
fPageNumber->TextView()->AllowChar('0' + num);
}
fPageNumber->TextView()-> SetMaxBytes(5);
fPageNumber->TextView()-> SetMaxBytes(5);
AddChild(fPageNumber);
fPageNumber->ResizeTo(be_plain_font->StringWidth("999999") + 10, height);
left = fPageNumber->Frame().right + 5;
// number of pages text
fPageText = new BStringView(BRect(left, top, left + 100, top + 15), "pageText", "");
AddChild(fPageText);
@ -511,128 +602,145 @@ PreviewWindow::PreviewWindow(BFile* jobFile)
fPageText->ResizeTo(pageTextWidth, pageTextHeight);
left += pageTextWidth + kPageTextDistance;
fPageText->MoveBy(0, (height - font.Size()) / 2);
fZoomIn = new BButton(BRect(left, top, left+10, top+10), "ZoomIn", "Zoom In", new BMessage(MSG_ZOOM_IN));
fZoomIn = new BButton(BRect(left, top, left+10, top+10), "ZoomIn", "Zoom In",
new BMessage(MSG_ZOOM_IN));
AddChild(fZoomIn);
fZoomIn->ResizeTo(width, height);
left = fZoomIn->Frame().right + kButtonDistance;
fZoomOut = new BButton(BRect(left, top, left+10, top+10), "ZoomOut", "Zoom Out", new BMessage(MSG_ZOOM_OUT));
fZoomOut = new BButton(BRect(left, top, left+10, top+10), "ZoomOut", "Zoom Out",
new BMessage(MSG_ZOOM_OUT));
AddChild(fZoomOut);
fZoomOut->ResizeTo(width, height);
fButtonBarHeight = fZoomOut->Frame().bottom + 7;
// add preview view
// add preview view
r.top = fButtonBarHeight;
fPreview = new PreviewView(jobFile, r);
fPreviewScroller = new BScrollView("PreviewScroller", fPreview, B_FOLLOW_ALL, 0, true, true, B_FANCY_BORDER);
fPreviewScroller = new BScrollView("PreviewScroller", fPreview, B_FOLLOW_ALL,
0, true, true, B_FANCY_BORDER);
fPreviewScroller->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fPreviewScroller);
if (fPreview->InitCheck() == B_OK) {
ResizeToPage();
_ResizeToPage();
fPreview->FixScrollbars();
UpdateControls();
_UpdateControls();
fPreview->MakeFocus(true);
}
}
void PreviewWindow::ResizeToPage() {
void
PreviewWindow::MessageReceived(BMessage* m)
{
switch (m->what) {
case MSG_FIRST_PAGE:
fPreview->ShowFirstPage();
break;
case MSG_NEXT_PAGE:
fPreview->ShowNextPage();
break;
case MSG_PREV_PAGE:
fPreview->ShowPrevPage();
break;
case MSG_LAST_PAGE:
fPreview->ShowLastPage();
break;
case MSG_FIND_PAGE:
fPreview->ShowFindPage(atoi(fPageNumber->Text())) ;
break;
case MSG_ZOOM_IN:
fPreview->ZoomIn();
_ResizeToPage();
break;
case MSG_ZOOM_OUT:
fPreview->ZoomOut();
_ResizeToPage();
break;
case B_MODIFIERS_CHANGED:
fPreview->MouseMoved(BPoint(), B_INSIDE_VIEW, m);
break;
default:
BlockingWindow::MessageReceived(m);
return;
}
_UpdateControls();
}
status_t
PreviewWindow::Go()
{
status_t st = InitCheck();
if (st == B_OK)
return BlockingWindow::Go();
Quit();
return st;
}
void
PreviewWindow::_ResizeToPage()
{
BScreen screen;
BRect r(fPreview->ViewRect());
float width, height;
float maxWidth, maxHeight, minWidth;
if (screen.Frame().right == 0.0)
return;
const float windowBorderWidth = 5;
const float windowBorderHeight = 5;
if (screen.Frame().right == 0.0) {
return; // invalid screen object
}
width = r.Width() + 1 + B_V_SCROLL_BAR_WIDTH;
height = r.Height() + 1 + fButtonBarHeight + B_H_SCROLL_BAR_HEIGHT;
// dimensions so that window does not reach outside of screen
maxWidth = screen.Frame().Width() + 1 - windowBorderWidth - Frame().left;
maxHeight = screen.Frame().Height() + 1 - windowBorderHeight - Frame().top;
BRect rect(fPreview->ViewRect());
float width = rect.Width() + 1 + B_V_SCROLL_BAR_WIDTH;
float height = rect.Height() + 1 + fButtonBarHeight + B_H_SCROLL_BAR_HEIGHT;
rect = screen.Frame();
// dimensions so that window does not reach outside of screen
float maxWidth = rect.Width() + 1 - windowBorderWidth - Frame().left;
float maxHeight = rect.Height() + 1 - windowBorderHeight - Frame().top;
// width so that all buttons are visible
minWidth = fZoomOut->Frame().right + 10;
if (width < minWidth) width = minWidth;
float minWidth = fZoomOut->Frame().right + 10;
if (width < minWidth) width = minWidth;
if (width > maxWidth) width = maxWidth;
if (height > maxHeight) height = maxHeight;
ResizeTo(width, height);
}
void PreviewWindow::UpdateControls() {
void
PreviewWindow::_UpdateControls()
{
fFirst->SetEnabled(!fPreview->ShowsFirstPage());
fPrev->SetEnabled(!fPreview->ShowsFirstPage());
fNext->SetEnabled(!fPreview->ShowsLastPage());
fLast->SetEnabled(!fPreview->ShowsLastPage());
fZoomIn->SetEnabled(fPreview->CanZoomIn());
fZoomOut->SetEnabled(fPreview->CanZoomOut());
BString page;
page << fPreview->CurrentPage();
fPageNumber->SetText(page.String());
BString text;
text << "of "
<< fPreview->NumberOfPages();
if (fPreview->NumberOfPages() == 1) {
text << " Page";
} else {
text << " Pages";
}
fPageText->SetText(text.String());}
BString text;
text << fPreview->CurrentPage();
fPageNumber->SetText(text.String());
void PreviewWindow::MessageReceived(BMessage* m) {
switch (m->what) {
case MSG_FIRST_PAGE:
fPreview->ShowFirstPage();
break;
case MSG_NEXT_PAGE:
fPreview->ShowNextPage();
break;
case MSG_PREV_PAGE:
fPreview->ShowPrevPage();
break;
case MSG_LAST_PAGE:
fPreview->ShowLastPage();
break;
case MSG_FIND_PAGE:
fPreview->ShowFindPage(atoi(fPageNumber->Text())) ;
break;
case MSG_ZOOM_IN:
fPreview->ZoomIn();
ResizeToPage();
break;
case MSG_ZOOM_OUT:
fPreview->ZoomOut();
ResizeToPage();
break;
case B_MODIFIERS_CHANGED:
fPreview->MouseMoved(BPoint(), B_INSIDE_VIEW, m);
break;
default:
inherited::MessageReceived(m); return;
}
UpdateControls();
}
status_t PreviewWindow::Go() {
status_t st = InitCheck();
if (st == B_OK) {
return inherited::Go();
} else {
Quit();
}
return st;
text.SetTo("of ");
text << fPreview->NumberOfPages() << " Page";
if (fPreview->NumberOfPages() > 1)
text.Append("s");
fPageText->SetText(text.String());
}

View File

@ -5,115 +5,143 @@
* Authors:
* Michael Pfeiffer
* Hartmut Reh
* julun <host.haiku@gmx.de>
*/
#include <InterfaceKit.h>
#include "PrintJobReader.h"
#include "InterfaceUtils.h"
#include "PrintJobReader.h"
#include <View.h>
class BButton;
class BFile;
class BMessage;
class BPicture;
class BScrollView;
class BStringView;
class BTextControl;
// #pragma mark - PreviewPage
class PreviewPage {
int32 fPage;
int32 fNumberOfPictures;
BPicture* fPictures;
BPoint* fPoints;
BRect* fRects;
status_t fStatus;
public:
PreviewPage(int32 page, PrintJobPage* pjp);
~PreviewPage();
status_t InitCheck() const;
int32 Page() const { return fPage; }
void Draw(BView* view);
PreviewPage(int32 page, PrintJobPage* pjp);
~PreviewPage();
void Draw(BView* view);
status_t InitCheck() const;
int32 Page() const { return fPage; }
private:
int32 fPage;
status_t fStatus;
int32 fNumberOfPictures;
BRect* fRects;
BPoint* fPoints;
BPicture* fPictures;
};
// #pragma mark - PreviewView
class PreviewView : public BView {
int32 fPage;
int32 fZoom;
bool fTracking;
bool fInsideView;
BPoint fScrollStart;
PrintJobReader fReader;
PreviewPage* fCachedPage;
float ZoomFactor() const;
BRect PageRect() const;
BRect PrintableRect() const;
public:
PreviewView(BFile* jobFile, BRect rect);
~PreviewView();
virtual void Show();
virtual void MouseDown(BPoint point);
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage* message);
virtual void MouseUp(BPoint point);
PreviewView(BFile* jobFile, BRect rect);
~PreviewView();
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void Show();
virtual void Draw(BRect r);
virtual void FrameResized(float width, float height);
virtual void MouseDown(BPoint point);
virtual void MouseMoved(BPoint point, uint32 transit,
const BMessage* message);
virtual void MouseUp(BPoint point);
virtual void KeyDown(const char* bytes, int32 numBytes);
status_t InitCheck() const;
BRect ViewRect() const;
void ShowFirstPage();
void ShowPrevPage();
void ShowNextPage();
void ShowLastPage();
bool ShowsFirstPage() const;
bool ShowsLastPage() const;
void ShowFindPage(int32 page);
bool IsPageLoaded(int32 page) const;
bool IsPageValid() const;
void LoadPage(int32 page);
void DrawPageFrame(BRect r);
void DrawPage(BRect r);
void Draw(BRect r);
void FrameResized(float width, float height);
void FixScrollbars();
bool ShowsFirstPage() const;
bool ShowsLastPage() const;
int CurrentPage() const { return fPage + 1; }
int NumberOfPages() const;
void ShowNextPage();
void ShowPrevPage();
void ShowFirstPage();
void ShowLastPage();
void ShowFindPage(int page);
bool CanZoomIn() const;
bool CanZoomOut() const;
void ZoomIn();
void ZoomOut();
void ZoomIn();
bool CanZoomIn() const;
void ZoomOut();
bool CanZoomOut() const;
void FixScrollbars();
BRect ViewRect() const;
status_t InitCheck() const;
int32 NumberOfPages() const;
int32 CurrentPage() const { return fPage + 1; }
private:
BRect _PageRect() const;
float _ZoomFactor() const;
BRect _PrintableRect() const;
void _LoadPage(int32 page);
bool _IsPageValid() const;
bool _IsPageLoaded(int32 page) const;
void _DrawPageFrame(BRect rect);
void _DrawPage(BRect updateRect);
private:
int32 fPage;
int32 fZoom;
bool fTracking;
bool fInsideView;
BPoint fScrollStart;
PrintJobReader fReader;
PreviewPage* fCachedPage;
};
// #pragma mark - PreviewWindow
class PreviewWindow : public BlockingWindow {
BButton *fFirst;
BButton *fNext;
BButton *fPrev;
BButton *fLast;
BButton *fZoomIn;
BButton *fZoomOut;
BTextControl *fPageNumber;
BStringView *fPageText;
PreviewView *fPreview;
BScrollView *fPreviewScroller;
float fButtonBarHeight;
enum {
MSG_FIRST_PAGE = 'pwfp',
MSG_NEXT_PAGE = 'pwnp',
MSG_PREV_PAGE = 'pwpp',
MSG_LAST_PAGE = 'pwlp',
MSG_FIND_PAGE = 'pwsp',
MSG_ZOOM_IN = 'pwzi',
MSG_ZOOM_OUT = 'pwzo',
};
void ResizeToPage();
void UpdateControls();
typedef BlockingWindow inherited;
public:
PreviewWindow(BFile* jobFile);
status_t InitCheck() const { return fPreview->InitCheck(); }
void MessageReceived(BMessage* m);
status_t Go();
};
PreviewWindow(BFile* jobFile);
virtual void MessageReceived(BMessage* m);
status_t Go();
status_t InitCheck() const { return fPreview->InitCheck(); }
private:
void _ResizeToPage();
void _UpdateControls();
private:
BButton* fFirst;
BButton* fNext;
BButton* fPrev;
BButton* fLast;
BButton* fZoomIn;
BButton* fZoomOut;
BTextControl* fPageNumber;
BStringView* fPageText;
PreviewView* fPreview;
BScrollView* fPreviewScroller;
float fButtonBarHeight;
enum {
MSG_FIRST_PAGE = 'pwfp',
MSG_NEXT_PAGE = 'pwnp',
MSG_PREV_PAGE = 'pwpp',
MSG_LAST_PAGE = 'pwlp',
MSG_FIND_PAGE = 'pwsp',
MSG_ZOOM_IN = 'pwzi',
MSG_ZOOM_OUT = 'pwzo',
};
};