* 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:
@@ -5,9 +5,8 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Michael Pfeiffer
|
* Michael Pfeiffer
|
||||||
* Hartmut Reh
|
* Hartmut Reh
|
||||||
|
* julun <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO Remove. Use shared/libprint/Preview.cpp instead.
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -19,61 +18,80 @@
|
|||||||
|
|
||||||
#include "Preview.h"
|
#include "Preview.h"
|
||||||
|
|
||||||
// Implementation of PreviewPage
|
|
||||||
|
// #pragma mark - PreviewPage
|
||||||
|
|
||||||
|
|
||||||
PreviewPage::PreviewPage(int32 page, PrintJobPage* pjp)
|
PreviewPage::PreviewPage(int32 page, PrintJobPage* pjp)
|
||||||
: fPage(page)
|
: fPage(page)
|
||||||
, fPictures(NULL)
|
, fStatus(B_ERROR)
|
||||||
, fPoints(NULL)
|
, fNumberOfPictures(0)
|
||||||
, fRects(NULL)
|
, fRects(NULL)
|
||||||
|
, fPoints(NULL)
|
||||||
|
, fPictures(NULL)
|
||||||
{
|
{
|
||||||
fNumberOfPictures = pjp->NumberOfPictures();
|
fNumberOfPictures = pjp->NumberOfPictures();
|
||||||
fPictures = new BPicture[fNumberOfPictures];
|
|
||||||
fPoints = new BPoint[fNumberOfPictures];
|
|
||||||
fRects = new BRect[fNumberOfPictures];
|
fRects = new BRect[fNumberOfPictures];
|
||||||
status_t rc = B_ERROR;
|
fPoints = new BPoint[fNumberOfPictures];
|
||||||
for (int32 i = 0; i < fNumberOfPictures &&
|
fPictures = new BPicture[fNumberOfPictures];
|
||||||
(rc = pjp->NextPicture(fPictures[i], fPoints[i], fRects[i])) == B_OK; i ++);
|
|
||||||
fStatus = rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
PreviewPage::~PreviewPage() {
|
for (int32 i = 0; i < fNumberOfPictures; ++i) {
|
||||||
delete []fPictures;
|
fStatus = pjp->NextPicture(fPictures[i], fPoints[i], fRects[i]);
|
||||||
delete []fPoints;
|
if (fStatus != B_OK)
|
||||||
delete []fRects;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 kPreviewTopMargin = 10;
|
||||||
const float kPreviewBottomMargin = 30;
|
const float kPreviewBottomMargin = 30;
|
||||||
const float kPreviewLeftMargin = 10;
|
const float kPreviewLeftMargin = 10;
|
||||||
const float kPreviewRightMargin = 30;
|
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,
|
const uint8 ZOOM_IN[] = { 16, 1, 6, 6, 0, 0, 15, 128, 48, 96, 32, 32, 66, 16,
|
||||||
79, 144, 64, 16, 64, 16, 32, 32, 48, 112, 15, 184, 0, 28, 0, 14, 0, 6, 0, 0, 15,
|
66, 16, 79, 144, 66, 16, 66, 16, 32, 32, 48, 112, 15, 184, 0, 28, 0, 14, 0,
|
||||||
128, 63, 224, 127, 240, 127, 240, 255, 248, 255, 248, 255, 248, 255, 248, 255, 248,
|
6, 0, 0, 15, 128, 63, 224, 127, 240, 127, 240, 255, 248, 255, 248, 255, 248,
|
||||||
127, 248, 127, 248, 63, 252, 15, 254, 0, 31, 0, 15, 0, 7 };
|
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)
|
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)
|
, fPage(0)
|
||||||
, fZoom(0)
|
, fZoom(0)
|
||||||
, fTracking(false)
|
, 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
|
void
|
||||||
PreviewView::MouseDown(BPoint point)
|
PreviewView::MouseDown(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -184,7 +224,7 @@ PreviewView::MouseUp(BPoint point)
|
|||||||
void
|
void
|
||||||
PreviewView::KeyDown(const char* bytes, int32 numBytes)
|
PreviewView::KeyDown(const char* bytes, int32 numBytes)
|
||||||
{
|
{
|
||||||
MakeFocus(true);
|
MakeFocus(true);
|
||||||
switch (bytes[0]) {
|
switch (bytes[0]) {
|
||||||
case '-': {
|
case '-': {
|
||||||
if (modifiers() & B_CONTROL_KEY)
|
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
|
// returns 2 ^ fZoom
|
||||||
float PreviewView::ZoomFactor() const {
|
float
|
||||||
|
PreviewView::_ZoomFactor() const
|
||||||
|
{
|
||||||
const int32 b = 4;
|
const int32 b = 4;
|
||||||
int32 zoom;
|
int32 zoom;
|
||||||
if (fZoom > 0) {
|
if (fZoom > 0) {
|
||||||
@@ -216,288 +426,169 @@ float PreviewView::ZoomFactor() const {
|
|||||||
return factor * fReader.GetScale() / 100.0;
|
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 {
|
BRect
|
||||||
float f = ZoomFactor();
|
PreviewView::_PrintableRect() const
|
||||||
|
{
|
||||||
|
float f = _ZoomFactor();
|
||||||
BRect r = fReader.PrintableRect();
|
BRect r = fReader.PrintableRect();
|
||||||
return ScaleRect(r, f);
|
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 {
|
bool
|
||||||
return fReader.InitCheck();
|
PreviewView::_IsPageValid() const
|
||||||
}
|
{
|
||||||
|
|
||||||
bool PreviewView::IsPageLoaded(int32 page) const {
|
|
||||||
return fCachedPage != NULL && fCachedPage->Page() == page;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PreviewView::IsPageValid() const {
|
|
||||||
return fCachedPage && fCachedPage->InitCheck() == B_OK;
|
return fCachedPage && fCachedPage->InitCheck() == B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewView::LoadPage(int32 page) {
|
void
|
||||||
delete fCachedPage; fCachedPage = NULL;
|
PreviewView::_LoadPage(int32 page)
|
||||||
|
{
|
||||||
|
delete fCachedPage;
|
||||||
|
fCachedPage = NULL;
|
||||||
|
|
||||||
PrintJobPage pjp;
|
PrintJobPage pjp;
|
||||||
if (fReader.GetPage(page, pjp) == B_OK) {
|
if (fReader.GetPage(page, pjp) == B_OK)
|
||||||
fCachedPage = new PreviewPage(page, &pjp);
|
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 kShadowIndent = 3;
|
||||||
const float kShadowWidth = 3;
|
const float kShadowWidth = 3;
|
||||||
float x, y;
|
|
||||||
float right, bottom;
|
rgb_color frameColor = { 0, 0, 0, 0 };
|
||||||
rgb_color frameColor = {0, 0, 0, 0};
|
rgb_color shadowColor = { 90, 90, 90, 0 };
|
||||||
rgb_color shadowColor = {90, 90, 90, 0};
|
|
||||||
BRect r(PageRect());
|
|
||||||
|
|
||||||
PushState();
|
PushState();
|
||||||
|
|
||||||
// draw page border around page
|
// draw page border around page
|
||||||
r.InsetBy(-1, -1);
|
BRect r(_PageRect().InsetByCopy(-1, -1));
|
||||||
r.OffsetTo(kPreviewLeftMargin-1, kPreviewTopMargin-1);
|
r.OffsetTo(kPreviewLeftMargin-1, kPreviewTopMargin-1);
|
||||||
SetHighColor(frameColor);
|
SetHighColor(frameColor);
|
||||||
StrokeRect(r);
|
StrokeRect(r);
|
||||||
|
|
||||||
// draw page shadow
|
// draw page shadow
|
||||||
SetHighColor(shadowColor);
|
SetHighColor(shadowColor);
|
||||||
|
|
||||||
x = r.right + 1;
|
float x = r.right + 1;
|
||||||
right = x + kShadowWidth;
|
float right = x + kShadowWidth;
|
||||||
bottom = r.bottom + 1 + kShadowWidth;
|
float bottom = r.bottom + 1 + kShadowWidth;
|
||||||
y = r.top + kShadowIndent;
|
float y = r.top + kShadowIndent;
|
||||||
FillRect(BRect(x, y, right, bottom));
|
FillRect(BRect(x, y, right, bottom));
|
||||||
|
|
||||||
x = r.left + kShadowIndent;
|
x = r.left + kShadowIndent;
|
||||||
y = r.bottom + 1;
|
y = r.bottom + 1;
|
||||||
FillRect(BRect(x, y, r.right, bottom));
|
FillRect(BRect(x, y, r.right, bottom));
|
||||||
|
|
||||||
PopState();
|
PopState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
void PreviewView::DrawPage(BRect rect)
|
PreviewView::_DrawPage(BRect rect)
|
||||||
{
|
{
|
||||||
// constrain clipping region to printable rectangle
|
// constrain clipping region to printable rectangle
|
||||||
BRect r(PrintableRect());
|
BRect r(_PrintableRect());
|
||||||
r.OffsetBy(kPreviewLeftMargin, kPreviewTopMargin);
|
r.OffsetBy(kPreviewLeftMargin, kPreviewTopMargin);
|
||||||
BRegion clip(r);
|
BRegion clip(r);
|
||||||
// Text drawing does not work if clipping region
|
ConstrainClippingRegion(&clip);
|
||||||
// is constraint.
|
|
||||||
// TODO enable after app_server bug has been fixed
|
|
||||||
// ConstrainClippingRegion(&clip);
|
|
||||||
|
|
||||||
// draw page contents
|
// draw page contents
|
||||||
PushState();
|
PushState();
|
||||||
|
|
||||||
// print job coordinates are relative to the printable rect
|
// print job coordinates are relative to the printable rect
|
||||||
BRect printRect = fReader.PrintableRect();
|
BRect printRect = fReader.PrintableRect();
|
||||||
SetOrigin(kPreviewLeftMargin + printRect.left * ZoomFactor(),
|
SetOrigin(kPreviewLeftMargin + printRect.left * _ZoomFactor(),
|
||||||
kPreviewTopMargin + printRect.top * ZoomFactor());
|
kPreviewTopMargin + printRect.top * _ZoomFactor());
|
||||||
|
|
||||||
SetScale(ZoomFactor());
|
SetScale(_ZoomFactor());
|
||||||
|
|
||||||
PushState();
|
PushState();
|
||||||
fCachedPage->Draw(this);
|
fCachedPage->Draw(this);
|
||||||
PopState();
|
PopState();
|
||||||
|
|
||||||
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) {
|
// #pragma mark - PreviewWindow
|
||||||
FixScrollbars();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PreviewView::ShowsFirstPage() const {
|
|
||||||
return fPage == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PreviewView::ShowsLastPage() const {
|
PreviewWindow::PreviewWindow(BFile* jobFile)
|
||||||
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)
|
|
||||||
: BlockingWindow(BRect(20, 24, 400, 600), "Preview", B_DOCUMENT_WINDOW,
|
: BlockingWindow(BRect(20, 24, 400, 600), "Preview", B_DOCUMENT_WINDOW,
|
||||||
B_ASYNCHRONOUS_CONTROLS)
|
B_ASYNCHRONOUS_CONTROLS)
|
||||||
|
, fButtonBarHeight(0.0)
|
||||||
{
|
{
|
||||||
const float kButtonDistance = 15;
|
const float kButtonDistance = 15;
|
||||||
const float kPageTextDistance = 10;
|
const float kPageTextDistance = 10;
|
||||||
|
|
||||||
float top = 7;
|
float top = 7;
|
||||||
float left = 20;
|
float left = 20;
|
||||||
float width, height;
|
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
|
// 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);
|
AddChild(fPrev);
|
||||||
fPrev->ResizeToPreferred();
|
fPrev->ResizeToPreferred();
|
||||||
width = fPrev->Bounds().Width()+1;
|
width = fPrev->Bounds().Width()+1;
|
||||||
height = fPrev->Bounds().Height()+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);
|
AddChild(fFirst);
|
||||||
fFirst->ResizeTo(width, height);
|
fFirst->ResizeTo(width, height);
|
||||||
left = fFirst->Frame().right + kButtonDistance;
|
left = fFirst->Frame().right + kButtonDistance;
|
||||||
|
|
||||||
// move Previous Page button after First Page button
|
// move Previous Page button after First Page button
|
||||||
fPrev->MoveTo(left, top);
|
fPrev->MoveTo(left, top);
|
||||||
left = fPrev->Frame().right + kButtonDistance;
|
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);
|
AddChild(fNext);
|
||||||
fNext->ResizeTo(width, height);
|
fNext->ResizeTo(width, height);
|
||||||
left = fNext->Frame().right + kButtonDistance;
|
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);
|
AddChild(fLast);
|
||||||
fLast->ResizeTo(width, height);
|
fLast->ResizeTo(width, height);
|
||||||
left = fLast->Frame().right + kPageTextDistance;
|
left = fLast->Frame().right + kPageTextDistance;
|
||||||
|
|
||||||
// page number text
|
// 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);
|
fPageNumber->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_RIGHT);
|
||||||
int num;
|
uint32 num;
|
||||||
for (num = 0; num <= 255; num++) {
|
for (num = 0; num <= 255; num++) {
|
||||||
fPageNumber->TextView()->DisallowChar(num);
|
fPageNumber->TextView()->DisallowChar(num);
|
||||||
}
|
}
|
||||||
for (num = 0; num <= 9; num++) {
|
for (num = 0; num <= 9; num++) {
|
||||||
fPageNumber->TextView()->AllowChar('0' + num);
|
fPageNumber->TextView()->AllowChar('0' + num);
|
||||||
}
|
}
|
||||||
fPageNumber->TextView()-> SetMaxBytes(5);
|
fPageNumber->TextView()-> SetMaxBytes(5);
|
||||||
AddChild(fPageNumber);
|
AddChild(fPageNumber);
|
||||||
fPageNumber->ResizeTo(be_plain_font->StringWidth("999999") + 10, height);
|
fPageNumber->ResizeTo(be_plain_font->StringWidth("999999") + 10, height);
|
||||||
left = fPageNumber->Frame().right + 5;
|
left = fPageNumber->Frame().right + 5;
|
||||||
|
|
||||||
// number of pages text
|
// number of pages text
|
||||||
fPageText = new BStringView(BRect(left, top, left + 100, top + 15), "pageText", "");
|
fPageText = new BStringView(BRect(left, top, left + 100, top + 15), "pageText", "");
|
||||||
AddChild(fPageText);
|
AddChild(fPageText);
|
||||||
@@ -511,128 +602,145 @@ PreviewWindow::PreviewWindow(BFile* jobFile)
|
|||||||
fPageText->ResizeTo(pageTextWidth, pageTextHeight);
|
fPageText->ResizeTo(pageTextWidth, pageTextHeight);
|
||||||
left += pageTextWidth + kPageTextDistance;
|
left += pageTextWidth + kPageTextDistance;
|
||||||
fPageText->MoveBy(0, (height - font.Size()) / 2);
|
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);
|
AddChild(fZoomIn);
|
||||||
fZoomIn->ResizeTo(width, height);
|
fZoomIn->ResizeTo(width, height);
|
||||||
left = fZoomIn->Frame().right + kButtonDistance;
|
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);
|
AddChild(fZoomOut);
|
||||||
fZoomOut->ResizeTo(width, height);
|
fZoomOut->ResizeTo(width, height);
|
||||||
|
|
||||||
fButtonBarHeight = fZoomOut->Frame().bottom + 7;
|
fButtonBarHeight = fZoomOut->Frame().bottom + 7;
|
||||||
|
|
||||||
// add preview view
|
// add preview view
|
||||||
r.top = fButtonBarHeight;
|
r.top = fButtonBarHeight;
|
||||||
fPreview = new PreviewView(jobFile, r);
|
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));
|
fPreviewScroller->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
AddChild(fPreviewScroller);
|
AddChild(fPreviewScroller);
|
||||||
|
|
||||||
if (fPreview->InitCheck() == B_OK) {
|
if (fPreview->InitCheck() == B_OK) {
|
||||||
ResizeToPage();
|
_ResizeToPage();
|
||||||
fPreview->FixScrollbars();
|
fPreview->FixScrollbars();
|
||||||
UpdateControls();
|
_UpdateControls();
|
||||||
fPreview->MakeFocus(true);
|
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;
|
BScreen screen;
|
||||||
BRect r(fPreview->ViewRect());
|
if (screen.Frame().right == 0.0)
|
||||||
float width, height;
|
return;
|
||||||
float maxWidth, maxHeight, minWidth;
|
|
||||||
const float windowBorderWidth = 5;
|
const float windowBorderWidth = 5;
|
||||||
const float windowBorderHeight = 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
|
BRect rect(fPreview->ViewRect());
|
||||||
maxWidth = screen.Frame().Width() + 1 - windowBorderWidth - Frame().left;
|
float width = rect.Width() + 1 + B_V_SCROLL_BAR_WIDTH;
|
||||||
maxHeight = screen.Frame().Height() + 1 - windowBorderHeight - Frame().top;
|
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
|
// width so that all buttons are visible
|
||||||
minWidth = fZoomOut->Frame().right + 10;
|
float minWidth = fZoomOut->Frame().right + 10;
|
||||||
|
|
||||||
if (width < minWidth) width = minWidth;
|
|
||||||
|
|
||||||
|
if (width < minWidth) width = minWidth;
|
||||||
if (width > maxWidth) width = maxWidth;
|
if (width > maxWidth) width = maxWidth;
|
||||||
if (height > maxHeight) height = maxHeight;
|
if (height > maxHeight) height = maxHeight;
|
||||||
|
|
||||||
ResizeTo(width, height);
|
ResizeTo(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewWindow::UpdateControls() {
|
|
||||||
|
void
|
||||||
|
PreviewWindow::_UpdateControls()
|
||||||
|
{
|
||||||
fFirst->SetEnabled(!fPreview->ShowsFirstPage());
|
fFirst->SetEnabled(!fPreview->ShowsFirstPage());
|
||||||
fPrev->SetEnabled(!fPreview->ShowsFirstPage());
|
fPrev->SetEnabled(!fPreview->ShowsFirstPage());
|
||||||
fNext->SetEnabled(!fPreview->ShowsLastPage());
|
fNext->SetEnabled(!fPreview->ShowsLastPage());
|
||||||
fLast->SetEnabled(!fPreview->ShowsLastPage());
|
fLast->SetEnabled(!fPreview->ShowsLastPage());
|
||||||
fZoomIn->SetEnabled(fPreview->CanZoomIn());
|
fZoomIn->SetEnabled(fPreview->CanZoomIn());
|
||||||
fZoomOut->SetEnabled(fPreview->CanZoomOut());
|
fZoomOut->SetEnabled(fPreview->CanZoomOut());
|
||||||
|
|
||||||
BString page;
|
|
||||||
page << fPreview->CurrentPage();
|
|
||||||
fPageNumber->SetText(page.String());
|
|
||||||
|
|
||||||
BString text;
|
BString text;
|
||||||
text << "of "
|
text << fPreview->CurrentPage();
|
||||||
<< fPreview->NumberOfPages();
|
fPageNumber->SetText(text.String());
|
||||||
if (fPreview->NumberOfPages() == 1) {
|
|
||||||
text << " Page";
|
|
||||||
} else {
|
|
||||||
text << " Pages";
|
|
||||||
}
|
|
||||||
fPageText->SetText(text.String());}
|
|
||||||
|
|
||||||
void PreviewWindow::MessageReceived(BMessage* m) {
|
text.SetTo("of ");
|
||||||
switch (m->what) {
|
text << fPreview->NumberOfPages() << " Page";
|
||||||
case MSG_FIRST_PAGE:
|
if (fPreview->NumberOfPages() > 1)
|
||||||
fPreview->ShowFirstPage();
|
text.Append("s");
|
||||||
break;
|
fPageText->SetText(text.String());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,115 +5,143 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Michael Pfeiffer
|
* Michael Pfeiffer
|
||||||
* Hartmut Reh
|
* Hartmut Reh
|
||||||
|
* julun <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <InterfaceKit.h>
|
|
||||||
#include "PrintJobReader.h"
|
|
||||||
#include "InterfaceUtils.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 {
|
class PreviewPage {
|
||||||
int32 fPage;
|
|
||||||
int32 fNumberOfPictures;
|
|
||||||
BPicture* fPictures;
|
|
||||||
BPoint* fPoints;
|
|
||||||
BRect* fRects;
|
|
||||||
status_t fStatus;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PreviewPage(int32 page, PrintJobPage* pjp);
|
PreviewPage(int32 page, PrintJobPage* pjp);
|
||||||
~PreviewPage();
|
~PreviewPage();
|
||||||
status_t InitCheck() const;
|
|
||||||
|
void Draw(BView* view);
|
||||||
int32 Page() const { return fPage; }
|
status_t InitCheck() const;
|
||||||
void Draw(BView* view);
|
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 {
|
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:
|
public:
|
||||||
PreviewView(BFile* jobFile, BRect rect);
|
PreviewView(BFile* jobFile, BRect rect);
|
||||||
~PreviewView();
|
~PreviewView();
|
||||||
|
|
||||||
virtual void Show();
|
|
||||||
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);
|
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;
|
void ShowFirstPage();
|
||||||
|
void ShowPrevPage();
|
||||||
BRect ViewRect() const;
|
void ShowNextPage();
|
||||||
|
void ShowLastPage();
|
||||||
|
bool ShowsFirstPage() const;
|
||||||
|
bool ShowsLastPage() const;
|
||||||
|
void ShowFindPage(int32 page);
|
||||||
|
|
||||||
bool IsPageLoaded(int32 page) const;
|
void ZoomIn();
|
||||||
bool IsPageValid() const;
|
bool CanZoomIn() const;
|
||||||
void LoadPage(int32 page);
|
void ZoomOut();
|
||||||
void DrawPageFrame(BRect r);
|
bool CanZoomOut() const;
|
||||||
void DrawPage(BRect r);
|
|
||||||
void Draw(BRect r);
|
void FixScrollbars();
|
||||||
void FrameResized(float width, float height);
|
BRect ViewRect() const;
|
||||||
|
status_t InitCheck() const;
|
||||||
void FixScrollbars();
|
int32 NumberOfPages() const;
|
||||||
|
int32 CurrentPage() const { return fPage + 1; }
|
||||||
bool ShowsFirstPage() const;
|
|
||||||
bool ShowsLastPage() const;
|
private:
|
||||||
int CurrentPage() const { return fPage + 1; }
|
BRect _PageRect() const;
|
||||||
int NumberOfPages() const;
|
float _ZoomFactor() const;
|
||||||
void ShowNextPage();
|
BRect _PrintableRect() const;
|
||||||
void ShowPrevPage();
|
|
||||||
void ShowFirstPage();
|
void _LoadPage(int32 page);
|
||||||
void ShowLastPage();
|
bool _IsPageValid() const;
|
||||||
void ShowFindPage(int page);
|
bool _IsPageLoaded(int32 page) const;
|
||||||
|
|
||||||
bool CanZoomIn() const;
|
void _DrawPageFrame(BRect rect);
|
||||||
bool CanZoomOut() const;
|
void _DrawPage(BRect updateRect);
|
||||||
void ZoomIn();
|
|
||||||
void ZoomOut();
|
private:
|
||||||
|
int32 fPage;
|
||||||
|
int32 fZoom;
|
||||||
|
bool fTracking;
|
||||||
|
bool fInsideView;
|
||||||
|
BPoint fScrollStart;
|
||||||
|
PrintJobReader fReader;
|
||||||
|
PreviewPage* fCachedPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - PreviewWindow
|
||||||
|
|
||||||
|
|
||||||
class PreviewWindow : public BlockingWindow {
|
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:
|
public:
|
||||||
PreviewWindow(BFile* jobFile);
|
PreviewWindow(BFile* jobFile);
|
||||||
status_t InitCheck() const { return fPreview->InitCheck(); }
|
|
||||||
void MessageReceived(BMessage* m);
|
|
||||||
status_t Go();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
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',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user