From fcccd8b7592fb8c4a853129e9e986ecc03cbdb01 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Sat, 20 Jan 2007 15:52:37 +0000 Subject: [PATCH] Some printing related improvements: * libprint based drivers can now show a preview window and show progress window while printing contributed in part by Hartmut Reh. * Libprint and PCL6 driver bug fixes. * Code clean-up (removed code duplications, coding style, copyright text) Builds under Linux. Not tested under BeOS. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19882 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/print/BeUtils.h | 6 +- headers/private/print/PrintJobReader.h | 5 + headers/private/print/PrintTransport.h | 4 +- headers/private/print/PrintTransportAddOn.h | 7 +- headers/private/print/Template.h | 2 +- .../private/print/libprint/GraphicsDriver.h | 10 +- headers/private/print/libprint/JobData.h | 9 +- headers/private/print/libprint/JobSetupDlg.h | 2 +- headers/private/print/libprint/Preview.h | 152 +++- headers/private/print/libprint/StatusWindow.h | 47 ++ .../private/print/utils}/InterfaceUtils.h | 9 +- .../print/{libprint => utils}/MarginView.h | 6 +- .../private/print/utils}/Utils.h | 31 - .../print/drivers/canon_lips/lips3/Jamfile | 7 +- .../print/drivers/canon_lips/lips4/Jamfile | 7 +- src/add-ons/print/drivers/pcl5/Jamfile | 7 +- src/add-ons/print/drivers/pcl6/Jamfile | 9 +- src/add-ons/print/drivers/pcl6/PCL6.cpp | 33 +- src/add-ons/print/drivers/pcl6/PCL6.h | 2 + src/add-ons/print/drivers/pcl6/PCL6Cap.cpp | 4 +- src/add-ons/print/drivers/pcl6/PCL6Config.h | 2 + src/add-ons/print/drivers/pcl6/PCL6Entry.cpp | 1 + .../print/drivers/pdf/source/AboutText.cpp | 46 ++ .../drivers/pdf/source/InterfaceUtils.cpp | 291 ------- .../print/drivers/pdf/source/InterfaceUtils.h | 117 --- src/add-ons/print/drivers/pdf/source/Jamfile | 8 +- .../drivers/pdf/source/JobSetupWindow.cpp | 4 +- src/add-ons/print/drivers/pdf/source/Link.cpp | 1 + src/add-ons/print/drivers/pdf/source/Link.h | 2 + .../pdf/source/{Utils.h => PDFSystem.h} | 98 +-- .../print/drivers/pdf/source/PDFWriter.h | 1 + .../drivers/pdf/source/PrinterDriver.cpp | 10 +- .../print/drivers/pdf/source/PrinterDriver.h | 10 +- .../drivers/pdf/source/PrinterSettings.cpp | 7 +- .../print/drivers/pdf/source/StatusWindow.cpp | 55 +- .../print/drivers/pdf/source/StatusWindow.h | 7 +- .../print/drivers/pdf/source/Utils.cpp | 110 --- src/add-ons/print/drivers/postscript/Jamfile | 7 +- src/add-ons/print/drivers/preview/Driver.cpp | 37 +- src/add-ons/print/drivers/preview/Driver.h | 37 +- src/add-ons/print/drivers/preview/Jamfile | 15 +- .../print/drivers/preview/JobSetupWindow.cpp | 37 +- .../print/drivers/preview/JobSetupWindow.h | 37 +- .../print/drivers/preview/MarginView.cpp | 709 ------------------ .../print/drivers/preview/MarginView.h | 226 ------ .../print/drivers/preview/PageSetupWindow.cpp | 53 +- .../print/drivers/preview/PageSetupWindow.h | 40 +- src/add-ons/print/drivers/preview/Preview.cpp | 39 +- src/add-ons/print/drivers/preview/Preview.h | 36 +- .../print/drivers/preview/PreviewDriver.cpp | 37 +- .../print/drivers/preview/PreviewDriver.h | 33 +- .../print/drivers/preview/PrinterDriver.cpp | 46 +- .../print/drivers/preview/PrinterDriver.h | 43 +- .../drivers/preview/PrinterSetupWindow.cpp | 37 +- .../drivers/preview/PrinterSetupWindow.h | 37 +- src/add-ons/print/drivers/shared/Jamfile | 1 + .../shared/libprint/GraphicsDriver.cpp | 170 ++--- .../print/drivers/shared/libprint/Jamfile | 4 +- .../print/drivers/shared/libprint/JobData.cpp | 172 ++--- .../drivers/shared/libprint/JobSetupDlg.cpp | 35 +- .../drivers/shared/libprint/PageSetupDlg.cpp | 27 +- .../print/drivers/shared/libprint/Preview.cpp | 642 +++++++++++++++- .../drivers/shared/libprint/PrinterData.cpp | 9 +- .../drivers/shared/libprint/PrinterDriver.cpp | 8 + .../drivers/shared/libprint/StatusWindow.cpp | 182 +++++ .../utils}/InterfaceUtils.cpp | 15 +- .../print/drivers/shared/utils/Jamfile | 12 + .../shared/{libprint => utils}/MarginView.cpp | 8 +- .../{preview => shared/utils}/Utils.cpp | 53 -- src/add-ons/print/shared/Jamfile | 2 +- .../print/transports/lpr/LprSetupDlg.cpp | 408 +++++----- src/servers/print/Jamfile | 2 +- src/servers/print/shared/BeUtils.cpp | 20 +- src/servers/print/shared/Jamfile | 2 +- 74 files changed, 1755 insertions(+), 2652 deletions(-) create mode 100644 headers/private/print/libprint/StatusWindow.h rename {src/add-ons/print/drivers/preview => headers/private/print/utils}/InterfaceUtils.h (95%) rename headers/private/print/{libprint => utils}/MarginView.h (98%) rename {src/add-ons/print/drivers/preview => headers/private/print/utils}/Utils.h (74%) create mode 100644 src/add-ons/print/drivers/pdf/source/AboutText.cpp delete mode 100644 src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp delete mode 100644 src/add-ons/print/drivers/pdf/source/InterfaceUtils.h rename src/add-ons/print/drivers/pdf/source/{Utils.h => PDFSystem.h} (52%) delete mode 100644 src/add-ons/print/drivers/pdf/source/Utils.cpp delete mode 100644 src/add-ons/print/drivers/preview/MarginView.cpp delete mode 100644 src/add-ons/print/drivers/preview/MarginView.h create mode 100644 src/add-ons/print/drivers/shared/libprint/StatusWindow.cpp rename src/add-ons/print/drivers/{preview => shared/utils}/InterfaceUtils.cpp (96%) create mode 100644 src/add-ons/print/drivers/shared/utils/Jamfile rename src/add-ons/print/drivers/shared/{libprint => utils}/MarginView.cpp (99%) rename src/add-ons/print/drivers/{preview => shared/utils}/Utils.cpp (62%) diff --git a/headers/private/print/BeUtils.h b/headers/private/print/BeUtils.h index f48a67f9d3..3580848356 100644 --- a/headers/private/print/BeUtils.h +++ b/headers/private/print/BeUtils.h @@ -36,8 +36,8 @@ // DEALINGS IN THE SOFTWARE. /*****************************************************************************/ -#ifndef BEUTILS_H -#define BEUTILS_H +#ifndef _BE_UTILS_H +#define _BE_UTILS_H #include #include @@ -91,7 +91,7 @@ public: // mimetype from sender bool MimeTypeForSender(BMessage* sender, BString& mime); // adds fields to message or replaces existing fields -void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL, const char* includeList[] = NULL); +void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL, const char* includeList[] = NULL, bool overwrite = true); // load bitmap from application resources BBitmap* LoadBitmap(const char* name, uint32 type_code = B_TRANSLATOR_BITMAP); // convert bitmap to picture; view must be attached to a window! diff --git a/headers/private/print/PrintJobReader.h b/headers/private/print/PrintJobReader.h index 0998fd001f..59a580f005 100644 --- a/headers/private/print/PrintJobReader.h +++ b/headers/private/print/PrintJobReader.h @@ -27,6 +27,9 @@ THE SOFTWARE. */ +#ifndef _PRINT_JOB_READER_H +#define _PRINT_JOB_READER_H + #include #include @@ -80,3 +83,5 @@ public: status_t GetPage(int no, PrintJobPage& pjp); }; +#endif + diff --git a/headers/private/print/PrintTransport.h b/headers/private/print/PrintTransport.h index 0dc5cbf7f2..e81c36d684 100644 --- a/headers/private/print/PrintTransport.h +++ b/headers/private/print/PrintTransport.h @@ -28,8 +28,8 @@ THE SOFTWARE. */ -#ifndef PRINT_TRANSPORT_H -#define PRINT_TRANSPORT_H +#ifndef _PRINT_TRANSPORT_H +#define _PRINT_TRANSPORT_H #include #include diff --git a/headers/private/print/PrintTransportAddOn.h b/headers/private/print/PrintTransportAddOn.h index fb93a50f8b..57c66185d2 100644 --- a/headers/private/print/PrintTransportAddOn.h +++ b/headers/private/print/PrintTransportAddOn.h @@ -27,8 +27,8 @@ THE SOFTWARE. */ -#ifndef PRINT_TRANSPORT_ADD_ON_H -#define PRINT_TRANSPORT_ADD_ON_H +#ifndef _PRINT_TRANSPORT_ADD_ON_H +#define _PRINT_TRANSPORT_ADD_ON_H #include #include @@ -38,4 +38,5 @@ THE SOFTWARE. // to be implemented by the transport add-on extern "C" BDataIO* instantiate_transport(BDirectory* printer, BMessage* msg); -#endif PRINT_TRANSPORT_ADD_ON_H +#endif + diff --git a/headers/private/print/Template.h b/headers/private/print/Template.h index d135d1e782..364c066270 100644 --- a/headers/private/print/Template.h +++ b/headers/private/print/Template.h @@ -82,4 +82,4 @@ public: virtual void SetFontFace(int32 flags); }; -#endif _TEMPLATE_H +#endif // _TEMPLATE_H diff --git a/headers/private/print/libprint/GraphicsDriver.h b/headers/private/print/libprint/GraphicsDriver.h index 5600cae774..100fca36f0 100644 --- a/headers/private/print/libprint/GraphicsDriver.h +++ b/headers/private/print/libprint/GraphicsDriver.h @@ -11,6 +11,7 @@ #include "PrintProcess.h" #include "SpoolMetaData.h" #include "Transport.h" +#include "StatusWindow.h" class BView; class BBitmap; @@ -26,7 +27,11 @@ class GraphicsDriver { public: GraphicsDriver(BMessage *, PrinterData *, const PrinterCap *); virtual ~GraphicsDriver(); + const JobData *getJobData(BFile *spoolFile); BMessage *takeJob(BFile *spool, uint32 flags = 0); + static BPoint getScale(int32 nup, BRect physicalRect, float scaling); + static BPoint getOffset(int32 nup, int index, JobData::Orientation orientation, const BPoint *scale, + BRect scaledPhysicalRect, BRect scaledPrintableRect, BRect physicalRect); protected: virtual bool startDoc(); @@ -58,7 +63,7 @@ protected: GraphicsDriver &operator = (const GraphicsDriver &); private: - void setupData(BFile *file, long page_count); + bool setupData(BFile *file); void setupBitmap(); void cleanupData(); void cleanupBitmap(); @@ -91,6 +96,9 @@ private: int fPixelDepth; int fBandCount; int fInternalCopies; + + uint32 fPageCount; + StatusWindow *fStatusWindow; }; inline const JobData *GraphicsDriver::getJobData() const diff --git a/headers/private/print/libprint/JobData.h b/headers/private/print/libprint/JobData.h index 236a7b212e..cbf19e522c 100644 --- a/headers/private/print/libprint/JobData.h +++ b/headers/private/print/libprint/JobData.h @@ -206,7 +206,10 @@ public: */ enum Color { kMonochrome = 1, - kColor + kColor, + // Some PCL6 printers do not support compressed data + // in color mode. + kColorCompressionDisabled }; enum Settings { @@ -221,6 +224,7 @@ public: }; private: + bool fShowPreview; Paper fPaper; int32 fXRes; int32 fYRes; @@ -261,6 +265,9 @@ public: void load(BMessage *msg, const PrinterCap *cap, Settings settings); void save(BMessage *msg = NULL); + bool getShowPreview() const { return fShowPreview; } + void setShowPreview(bool showPreview) { fShowPreview = showPreview; } + Paper getPaper() const { return fPaper; } void setPaper(Paper paper) { fPaper = paper; } diff --git a/headers/private/print/libprint/JobSetupDlg.h b/headers/private/print/libprint/JobSetupDlg.h index cdf38b9a94..f164bfbd00 100644 --- a/headers/private/print/libprint/JobSetupDlg.h +++ b/headers/private/print/libprint/JobSetupDlg.h @@ -29,7 +29,7 @@ public: JobSetupView(BRect frame, JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap); virtual void AttachedToWindow(); virtual void MessageReceived(BMessage *msg); - bool UpdateJobData(); + bool UpdateJobData(bool showPreview); private: void UpdateButtonEnabledState(); diff --git a/headers/private/print/libprint/Preview.h b/headers/private/print/libprint/Preview.h index 054b2fb9d4..1e83d0f09b 100644 --- a/headers/private/print/libprint/Preview.h +++ b/headers/private/print/libprint/Preview.h @@ -1,29 +1,139 @@ /* - * Preview.h - * Copyright 1999-2000 Y.Takagi. All Rights Reserved. - */ -//#define USE_PREVIEW_FOR_DEBUG +Preview -#ifdef USE_PREVIEW_FOR_DEBUG -#ifndef __PREVIEW_H -#define __PREVIEW_H +Copyright (c) 2002, 2003 OpenBeOS. +Copyright (c) 2005 Haiku. -#include +Author: + Michael Pfeiffer + Hartmut Reh + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: -class PreviewWindow : public BWindow { +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#include +#include "PrintJobReader.h" +#include "InterfaceUtils.h" + +class PreviewPage { + int32 fPage; + int32 fNumberOfPictures; + BPicture* fPictures; + BPoint* fPoints; + BRect* fRects; + status_t fStatus; + public: - PreviewWindow(BRect, const char *, BBitmap *); - virtual bool QuitRequested(); - int Go(); - -protected: - PreviewWindow(const PreviewWindow &); - PreviewWindow &operator = (const PreviewWindow &); - -private: - long fSemaphore; + PreviewPage(int32 page, PrintJobPage* pjp); + ~PreviewPage(); + status_t InitCheck() const; + + int32 Page() const { return fPage; } + void Draw(BView* view); +}; + +class PreviewView : public BView { + int32 fPage; + int32 fZoom; + PrintJobReader fReader; + int32 fNumberOfPagesPerPage; + int32 fNumberOfPages; // physical pages + bool fReverse; + BRect fPageRect; + JobData::Orientation fOrientation; + JobData::PageSelection fPageSelection; + PreviewPage* fCachedPage; + + float ZoomFactor() const; + BRect PageRect() const; + BRect PrintableRect() const; + int32 GetPageNumber(int32 index) const; + +public: + PreviewView(BFile* jobFile, BRect rect); + ~PreviewView(); + status_t InitCheck() const; + + BRect ViewRect() const; + + 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(); +}; + +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', + MSG_PRINT_JOB = 'pwpj', + MSG_CANCEL_JOB = 'pwcj', + }; + + void ResizeToPage(bool allowShrinking = false); + void UpdateControls(); + + typedef BlockingWindow inherited; + +public: + PreviewWindow(BFile* jobFile, bool showOkAndCancelButtons = false); + status_t InitCheck() const { return fPreview->InitCheck(); } + void MessageReceived(BMessage* m); + status_t Go(); }; -#endif /* __PREVIEW_H */ -#endif /* USE_PREVIEW_FOR_DEBUG */ diff --git a/headers/private/print/libprint/StatusWindow.h b/headers/private/print/libprint/StatusWindow.h new file mode 100644 index 0000000000..5b69f537f3 --- /dev/null +++ b/headers/private/print/libprint/StatusWindow.h @@ -0,0 +1,47 @@ +/* + StatusWindow.h + Copyright 2005 Dr.H.Reh. All Rights Reserved. +*/ + + +#ifndef STATUS_WINDOW_H +#define STATUS_WINDOW_H + +#ifndef _WINDOW_H +#include +#endif + +#include + + +class StatusWindow : public BWindow +{ + public: + StatusWindow(bool oddPages, bool evenPages, + uint32 firstPage, uint32 numPages, + uint32 docCopies, uint32 nup); + ~StatusWindow(void); + + virtual void MessageReceived(BMessage *message); + + void ResetStatusBar(void); + bool UpdateStatusBar(uint32 page, uint32 copy); + void SetPageCopies(uint32 copies); + + private: + BView *fStatusView; + BStatusBar *fStatusBar; + BButton *fCancelButton; + BButton *fHideButton; + bool fCancelBar; + bool fDocumentCopy; + uint32 fNops; + uint32 fFirstPage; + uint32 fCopies; + uint32 fDocCopies; + float fStatusDelta; + float fDelta; +}; + +#endif + diff --git a/src/add-ons/print/drivers/preview/InterfaceUtils.h b/headers/private/print/utils/InterfaceUtils.h similarity index 95% rename from src/add-ons/print/drivers/preview/InterfaceUtils.h rename to headers/private/print/utils/InterfaceUtils.h index e532cce37f..84373da8e4 100644 --- a/src/add-ons/print/drivers/preview/InterfaceUtils.h +++ b/headers/private/print/utils/InterfaceUtils.h @@ -32,10 +32,6 @@ THE SOFTWARE. #include -// Text to be displayed in About window, declared in the application -// that uses HWindow class!!! -extern const char* kAbout; - // -------------------------------------------------- class HWindow : public BWindow { @@ -50,6 +46,7 @@ public: virtual void MessageReceived(BMessage* m); virtual void AboutRequested(); + virtual const char* AboutText() const { return NULL; } }; // -------------------------------------------------- @@ -67,12 +64,16 @@ public: virtual status_t Go(); // Or quit window e.g. something went wrong in constructor void Quit(); + // Sets the result that is returned when the user closes the window. + // Default is B_OK. + void SetUserQuitResult(status_t result); typedef HWindow inherited; private: void Init(const char* title); + status_t fUserQuitResult; bool fReadyToQuit; sem_id fExitSem; status_t* fResult; diff --git a/headers/private/print/libprint/MarginView.h b/headers/private/print/utils/MarginView.h similarity index 98% rename from headers/private/print/libprint/MarginView.h rename to headers/private/print/utils/MarginView.h index 97d1b80008..0e51d71f06 100644 --- a/headers/private/print/libprint/MarginView.h +++ b/headers/private/print/utils/MarginView.h @@ -118,8 +118,8 @@ THE SOFTWARE. kUnitPoint, 1 point/point */ -#ifndef MARGIN_VIEW_H -#define MARGIN_VIEW_H +#ifndef _MARGIN_VIEW_H +#define _MARGIN_VIEW_H #include #include @@ -222,4 +222,4 @@ public: void MessageReceived(BMessage *msg); }; -#endif //MARGIN_VIEW_H +#endif // _MARGIN_VIEW_H diff --git a/src/add-ons/print/drivers/preview/Utils.h b/headers/private/print/utils/Utils.h similarity index 74% rename from src/add-ons/print/drivers/preview/Utils.h rename to headers/private/print/utils/Utils.h index b8e84d8a73..4b36878b8a 100644 --- a/src/add-ons/print/drivers/preview/Utils.h +++ b/headers/private/print/utils/Utils.h @@ -38,8 +38,6 @@ THE SOFTWARE. #include -// adds fields to message or replaces existing fields (copy BeUtils.h) -void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL, const char* includeList[] = NULL); void AddString(BMessage* m, const char* name, const char* value); // set or replace a value in a BMessage @@ -47,9 +45,6 @@ void SetRect(BMessage* msg, const char* name, BRect rect); void SetFloat(BMessage* msg, const char* name, float value); void SetInt32(BMessage* msg, const char* name, int32 value); -// scalar multiplication -BRect ScaleRect(BRect rect, float scale); - class EscapeMessageFilter : public BMessageFilter { private: @@ -134,30 +129,4 @@ void TList::SortItems(int (*comp)(const T**, const T**)) { fList.SortItems(sort); } -// PDF coordinate system -class PDFSystem { -private: - float fHeight; - float fX; - float fY; - float fScale; - -public: - PDFSystem() - : fHeight(0), fX(0), fY(0), fScale(1) { } - PDFSystem(float h, float x, float y, float s) - : fHeight(h), fX(x), fY(y), fScale(s) { } - - void SetHeight(float h) { fHeight = h; } - void SetOrigin(float x, float y) { fX = x; fY = y; } - void SetScale(float scale) { fScale = scale; } - float Height() const { return fHeight; } - BPoint Origin() const { return BPoint(fX, fY); } - float Scale() const { return fScale; } - - inline float tx(float x) { return fX + fScale*x; } - inline float ty(float y) { return fHeight - (fY + fScale * y); } - inline float scale(float f) { return fScale * f; } -}; - #endif diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Jamfile b/src/add-ons/print/drivers/canon_lips/lips3/Jamfile index cb6cc3e1e0..d8ee25b627 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Jamfile +++ b/src/add-ons/print/drivers/canon_lips/lips3/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons print drivers canon_lips lips3 ; SetSubDirSupportedPlatformsBeOSCompatible ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print libprint ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; AddResources Canon\ LIPS3\ Compatible : Lips3.rdef ; @@ -13,7 +14,11 @@ Addon Canon\ LIPS3\ Compatible : Print : Compress3.cpp ; -LinkAgainst Canon\ LIPS3\ Compatible : be libprint.a $(TARGET_LIBSTDC++) ; +LinkAgainst Canon\ LIPS3\ Compatible : + be + libprint.a + libprintutils.a + $(TARGET_LIBSTDC++) ; Package haiku-printingkit-cvs : Canon\ LIPS3\ Compatible : diff --git a/src/add-ons/print/drivers/canon_lips/lips4/Jamfile b/src/add-ons/print/drivers/canon_lips/lips4/Jamfile index 511c9199dc..80036ff0de 100644 --- a/src/add-ons/print/drivers/canon_lips/lips4/Jamfile +++ b/src/add-ons/print/drivers/canon_lips/lips4/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons print drivers canon_lips lips4 ; SetSubDirSupportedPlatformsBeOSCompatible ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print libprint ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; AddResources Canon\ LIPS4\ Compatible : Lips4.rdef ; @@ -12,7 +13,11 @@ Addon Canon\ LIPS4\ Compatible : Print : Lips4Cap.cpp ; -LinkAgainst Canon\ LIPS4\ Compatible : be libprint.a $(TARGET_LIBSTDC++) ; +LinkAgainst Canon\ LIPS4\ Compatible : + be + libprint.a + libprintutils.a + $(TARGET_LIBSTDC++) ; Package haiku-printingkit-cvs : Canon\ LIPS4\ Compatible : diff --git a/src/add-ons/print/drivers/pcl5/Jamfile b/src/add-ons/print/drivers/pcl5/Jamfile index 39cc03aa91..acfd7a84b9 100644 --- a/src/add-ons/print/drivers/pcl5/Jamfile +++ b/src/add-ons/print/drivers/pcl5/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons print drivers pcl5 ; SetSubDirSupportedPlatformsBeOSCompatible ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print libprint ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; AddResources PCL5\ Compatible : PCL5.rsrc ; @@ -12,7 +13,11 @@ Addon PCL5\ Compatible : Print : PCL5Cap.cpp ; -LinkAgainst PCL5\ Compatible : be libprint.a $(TARGET_LIBSTDC++) ; +LinkAgainst PCL5\ Compatible : + be + libprint.a + libprintutils.a + $(TARGET_LIBSTDC++) ; Package haiku-printingkit-cvs : PCL5\ Compatible : diff --git a/src/add-ons/print/drivers/pcl6/Jamfile b/src/add-ons/print/drivers/pcl6/Jamfile index 8b2bbe0885..a978f0b3f1 100644 --- a/src/add-ons/print/drivers/pcl6/Jamfile +++ b/src/add-ons/print/drivers/pcl6/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons print drivers pcl6 ; SetSubDirSupportedPlatformsBeOSCompatible ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print libprint ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; AddResources PCL6\ Compatible : PCL6.rsrc ; @@ -16,9 +17,11 @@ Addon PCL6\ Compatible : Print : Rasterizer.cpp ; -ObjectC++Flags [ FGristFiles jetlib.o ] : -w ; - -LinkAgainst PCL6\ Compatible : be libprint.a $(TARGET_LIBSTDC++) ; +LinkAgainst PCL6\ Compatible : + be + libprint.a + libprintutils.a + $(TARGET_LIBSTDC++) ; Package haiku-printingkit-cvs : PCL6\ Compatible : diff --git a/src/add-ons/print/drivers/pcl6/PCL6.cpp b/src/add-ons/print/drivers/pcl6/PCL6.cpp index 03f753e91a..99ac6e5121 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6.cpp @@ -97,7 +97,7 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset) int y = (int)offset->y; PCL6Rasterizer *rasterizer; - if (getJobData()->getColor() == JobData::kColor) { + if (useColorMode()) { #if COLOR_DEPTH == 8 rasterizer = new ColorRGBRasterizer(fHalftone); #elif COLOR_DEPTH == 1 @@ -179,10 +179,12 @@ void PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int #endif #if ENABLE_RLE_COMPRESSION - int rleSize = pack_bits_size(buffer, outSize); - if (rleSize < dataSize) { - compressionMethod = PCL6Writer::kRLECompression; - dataSize = rleSize; + if (supportsRLECompression()) { + int rleSize = pack_bits_size(buffer, outSize); + if (rleSize < dataSize) { + compressionMethod = PCL6Writer::kRLECompression; + dataSize = rleSize; + } } #endif @@ -246,9 +248,8 @@ bool PCL6Driver::startPage(int) // PageOrigin from Windows NT printer driver int x = 142 * getJobData()->getXres() / 600; int y = 100 * getJobData()->getYres() / 600; - bool color = getJobData()->getColor() == JobData::kColor; fWriter->SetPageOrigin(x, y); - fWriter->SetColorSpace(color ? PCL6Writer::kRGB : PCL6Writer::kGray); + fWriter->SetColorSpace(useColorMode() ? PCL6Writer::kRGB : PCL6Writer::kGray); fWriter->SetPaintTxMode(PCL6Writer::kOpaque); fWriter->SetSourceTxMode(PCL6Writer::kOpaque); fWriter->SetROP(204); @@ -257,9 +258,8 @@ bool PCL6Driver::startPage(int) void PCL6Driver::startRasterGraphics(int x, int y, int width, int height, PCL6Writer::Compression compressionMethod) { - bool color = getJobData()->getColor() == JobData::kColor; PCL6Writer::ColorDepth colorDepth; - if (color) { + if (useColorMode()) { #if COLOR_DEPTH == 8 colorDepth = PCL6Writer::k8Bit; #elif COLOR_DEPTH == 1 @@ -351,10 +351,23 @@ void PCL6Driver::move(int x, int y) fWriter->SetCursor(x, y); } +bool +PCL6Driver::supportsRLECompression() +{ + return getJobData()->getColor() != JobData::kColorCompressionDisabled; +} + bool PCL6Driver::supportsDeltaRowCompression() { - return getProtocolClass() >= PCL6Writer::kProtocolClass2_1; + return getProtocolClass() >= PCL6Writer::kProtocolClass2_1 && + getJobData()->getColor() != JobData::kColorCompressionDisabled; +} + +bool +PCL6Driver::useColorMode() +{ + return getJobData()->getColor() != JobData::kMonochrome; } PCL6Writer::MediaSize PCL6Driver::mediaSize(JobData::Paper paper) diff --git a/src/add-ons/print/drivers/pcl6/PCL6.h b/src/add-ons/print/drivers/pcl6/PCL6.h index 8230ac286f..7e5f04b8cf 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6.h +++ b/src/add-ons/print/drivers/pcl6/PCL6.h @@ -29,7 +29,9 @@ protected: virtual bool endDoc(bool success); private: + bool supportsRLECompression(); bool supportsDeltaRowCompression(); + bool useColorMode(); PCL6Writer::MediaSize mediaSize(JobData::Paper paper); PCL6Writer::MediaSource mediaSource(JobData::PaperSource source); void move(int x, int y); diff --git a/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp b/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp index d5b1909922..01fc3a5164 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp @@ -1,7 +1,7 @@ /* * PCL6Cap.cpp * Copyright 1999-2000 Y.Takagi. All Rights Reserved. - * COpyright 2003-2005 Michael Pfeiffer. + * Copyright 2003-2007 Michael Pfeiffer. */ #include "PCL6Cap.h" @@ -247,10 +247,12 @@ const ProtocolClassCap *protocolClasses[] = { }; const ColorCap color("Color", false, JobData::kColor); +const ColorCap colorCompressionDisabled("Color (No Compression)", false, JobData::kColorCompressionDisabled); const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome); const ColorCap *colors[] = { &color, + &colorCompressionDisabled, &monochrome }; diff --git a/src/add-ons/print/drivers/pcl6/PCL6Config.h b/src/add-ons/print/drivers/pcl6/PCL6Config.h index 4629a22933..24595311ac 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Config.h +++ b/src/add-ons/print/drivers/pcl6/PCL6Config.h @@ -12,6 +12,7 @@ // Run-Length-Encoding Compression #define ENABLE_RLE_COMPRESSION 1 +//#define ENABLE_RLE_COMPRESSION 0 // Delta Row Compression #define ENABLE_DELTA_ROW_COMPRESSION 1 @@ -21,6 +22,7 @@ // If 1 bit depth is used, the class Halftone is used for dithering // otherwise dithering is not performed. #define COLOR_DEPTH 1 +//#define COLOR_DEPTH 8 #define DISPLAY_COMPRESSION_STATISTICS 0 diff --git a/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp b/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp index cf4bc29cd8..265690ec17 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp @@ -48,3 +48,4 @@ PrinterDriver* instantiate_printer_driver(BNode* printerFolder) { return new PCL6PrinterDriver(printerFolder); } + diff --git a/src/add-ons/print/drivers/pdf/source/AboutText.cpp b/src/add-ons/print/drivers/pdf/source/AboutText.cpp new file mode 100644 index 0000000000..f9287e5e64 --- /dev/null +++ b/src/add-ons/print/drivers/pdf/source/AboutText.cpp @@ -0,0 +1,46 @@ +/* + +AboutText.cpp + +Copyright (c) 2001-2006 Haiku. + +Author: + Michael Pfeiffer + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#include + +static const char* +kAbout = +"PDF Writer for BeOS\n" +B_UTF8_COPYRIGHT " 2001-2004 Haiku\n" +"\n" +"Philippe Houdoin\n" +"\tProject Leader\n\n" +"Simon Gauvin\n" +"\tGUI Design\n\n" +"Michael Pfeiffer\n" +"\tPDF Generation\n" +"\tConfiguration\n" +"\tInteractive Features\n" +"\t" B_UTF8_ELLIPSIS +; diff --git a/src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp b/src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp deleted file mode 100644 index d75af934c7..0000000000 --- a/src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/* - -InterfaceUtils.cpp - -Copyright (c) 2002 OpenBeOS. - -Author: - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - -#include -#include "InterfaceUtils.h" -#include "Utils.h" - -// Implementation of HWindow - -// -------------------------------------------------- -HWindow::HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace, uint32 escape_msg) - : BWindow(frame, title, type, flags, workspace) -{ - Init(escape_msg); -} - - -// -------------------------------------------------- -HWindow::HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace, uint32 escape_msg) - : BWindow(frame, title, look, feel, flags, workspace) -{ - Init(escape_msg); -} - - -// -------------------------------------------------- -void -HWindow::Init(uint32 escape_msg) -{ - AddShortcut('i', 0, new BMessage(B_ABOUT_REQUESTED)); - AddCommonFilter(new EscapeMessageFilter(this, escape_msg)); -} - - -// -------------------------------------------------- -void -HWindow::MessageReceived(BMessage* msg) -{ - if (msg->what == B_ABOUT_REQUESTED) { - AboutRequested(); - } else { - inherited::MessageReceived(msg); - } -} - -// -------------------------------------------------- -static const char* -kAbout = -"PDF Writer for BeOS\n" -B_UTF8_COPYRIGHT " 2001-2004 Haiku\n" -"\n" -"Philippe Houdoin\n" -"\tProject Leader\n\n" -"Simon Gauvin\n" -"\tGUI Design\n\n" -"Michael Pfeiffer\n" -"\tPDF Generation\n" -"\tConfiguration\n" -"\tInteractive Features\n" -"\t" B_UTF8_ELLIPSIS -; - -void -HWindow::AboutRequested() -{ - BAlert *about = new BAlert("About PDF Writer", kAbout, "Cool"); - BTextView *v = about->TextView(); - if (v) { - // Colors grab with Magnify on BeOS R5 deskbar logo - rgb_color red = {203, 0, 51, 255}; - rgb_color blue = {0, 51, 152, 255}; - - v->SetStylable(true); - char *text = (char*) v->Text(); - char *s = text; - - // set first line 16pt bold - s = strchr(text, '\n'); - BFont font(be_bold_font); - font.SetSize(16); // font.SetFace(B_OUTLINED_FACE); - v->SetFontAndColor(0, s-text, &font); - - // set all Be in blue and red - s = text; - while ((s = strstr(s, "BeOS")) != NULL) { - int32 i = s - text; - v->SetFontAndColor(i, i+2, NULL, 0, &blue); - v->SetFontAndColor(i+2, i+4, NULL, 0, &red); - s += 2; - } - }; - about->Go(); -} - - -// Impelementation of TextView - -// -------------------------------------------------- -TextView::TextView(BRect frame, - const char *name, - BRect textRect, - uint32 rmask, - uint32 flags) - : BTextView(frame, name, textRect, rmask, flags) -{ -} - - -// -------------------------------------------------- -TextView::TextView(BRect frame, - const char *name, - BRect textRect, - const BFont *font, const rgb_color *color, - uint32 rmask, - uint32 flags) - : BTextView(frame, name, textRect, font, color, rmask, flags) -{ -} - - -// -------------------------------------------------- -void -TextView::KeyDown(const char *bytes, int32 numBytes) -{ - if (numBytes == 1 && *bytes == B_TAB) { - BView::KeyDown(bytes, numBytes); - return; - } - inherited::KeyDown(bytes, numBytes); -} - - -// -------------------------------------------------- -void -TextView::Draw(BRect update) -{ - inherited::Draw(update); - if (IsFocus()) { - // stroke focus rectangle - SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); - StrokeRect(Bounds()); - } -} - - -// -------------------------------------------------- -void -TextView::MakeFocus(bool focus) -{ - Invalidate(); - inherited::MakeFocus(focus); - // notify TextControl - BView* parent = Parent(); // BBox - if (focus && parent) { - parent = parent->Parent(); // TextControl - TextControl* control = dynamic_cast(parent); - if (control) control->FocusSetTo(this); - } -} - - -// Impelementation of TextControl - -// -------------------------------------------------- -TextControl::TextControl(BRect frame, - const char *name, - const char *label, - const char *initial_text, - BMessage *message, - uint32 rmask, - uint32 flags) - : BView(frame, name, rmask, flags) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - BRect r(0, 0, frame.Width() / 2 -1, frame.Height()); - fLabel = new BStringView(r, "", label); - BRect f(r); - f.OffsetTo(frame.Width() / 2 + 1, 0); - // box around TextView - BBox *box = new BBox(f, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); - f.OffsetTo(0, 0); - f.InsetBy(1,1); - r.InsetBy(2,2); - fText = new TextView(f, "", r, rmask, flags | B_NAVIGABLE); - fText->SetWordWrap(false); - fText->DisallowChar('\n'); - fText->Insert(initial_text); - AddChild(fLabel); - AddChild(box); - box->AddChild(fText); -} - - -// -------------------------------------------------- -void -TextControl::ConvertToParent(BView* parent, BView* child, BRect &rect) -{ - do { - child->ConvertToParent(&rect); - child = child->Parent(); - } while (child != NULL && child != parent); -} - - -// -------------------------------------------------- -void -TextControl::FocusSetTo(BView *child) -{ - BRect r; - BView* parent = Parent(); // Table - if (parent) { - ConvertToParent(parent, child, r); - parent->ScrollTo(0, r.top); - } -} - - -// Impelementation of Implementation of Table - -// -------------------------------------------------- -Table::Table(BRect frame, const char *name, uint32 rmode, uint32 flags) - : BView(frame, name, rmode, flags) -{ -} - - -// -------------------------------------------------- -void -Table::ScrollTo(BPoint p) -{ - float h = Frame().Height()+1; - if (Parent()) { - BScrollView* scrollView = dynamic_cast(Parent()); - if (scrollView) { - BScrollBar *sb = scrollView->ScrollBar(B_VERTICAL); - float min, max; - sb->GetRange(&min, &max); - if (p.y < (h/2)) p.y = 0; - else if (p.y > max) p.y = max; - } - } - inherited::ScrollTo(p); -} - - -// Impelementation of DragListView - -// -------------------------------------------------- -DragListView::DragListView(BRect frame, const char *name, - list_view_type type, - uint32 resizingMode, uint32 flags) - : BListView(frame, name, type, resizingMode, flags) -{ -} - -// -------------------------------------------------- -bool DragListView::InitiateDrag(BPoint point, int32 index, bool wasSelected) -{ - BMessage m; - DragMessage(&m, ItemFrame(index), this); - return true; -} - - - diff --git a/src/add-ons/print/drivers/pdf/source/InterfaceUtils.h b/src/add-ons/print/drivers/pdf/source/InterfaceUtils.h deleted file mode 100644 index 2b0e3ff4e8..0000000000 --- a/src/add-ons/print/drivers/pdf/source/InterfaceUtils.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - -InterfaceUtils.cpp - -Copyright (c) 2002 OpenBeOS. - -Author: - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - -#ifndef _INTERFACE_UTILS_H -#define _INTERFACE_UTILS_H - -#include - -// -------------------------------------------------- -class HWindow : public BWindow -{ -protected: - void Init(uint32 escape_msg); - -public: - typedef BWindow inherited; - - HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED); - HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED); - - virtual void MessageReceived(BMessage* m); - virtual void AboutRequested(); -}; - -// -------------------------------------------------- -class TextView : public BTextView -{ -public: - typedef BTextView inherited; - - TextView(BRect frame, - const char *name, - BRect textRect, - uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); - - TextView(BRect frame, - const char *name, - BRect textRect, - const BFont *font, const rgb_color *color, - uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); - - void KeyDown(const char *bytes, int32 numBytes); - void MakeFocus(bool focus = true); - void Draw(BRect r); -}; - - -// -------------------------------------------------- -class TextControl : public BView -{ - BStringView *fLabel; - TextView *fText; -public: - TextControl(BRect frame, - const char *name, - const char *label, - const char *initial_text, - BMessage *message, - uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); - const char *Label() { return fLabel->Text(); } - const char *Text() { return fText->Text(); } - void MakeFocus(bool focus = true) { fText->MakeFocus(focus); } - void ConvertToParent(BView* parent, BView* child, BRect &rect); - void FocusSetTo(BView* child); -}; - - -// -------------------------------------------------- -class Table : public BView -{ -public: - typedef BView inherited; - - Table(BRect frame, const char *name, uint32 rmode, uint32 flags); - void ScrollTo(BPoint p); -}; - -class DragListView : public BListView -{ -public: - DragListView(BRect frame, const char *name, - list_view_type type = B_SINGLE_SELECTION_LIST, - uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS); - bool InitiateDrag(BPoint point, int32 index, bool wasSelected); -}; - -#endif diff --git a/src/add-ons/print/drivers/pdf/source/Jamfile b/src/add-ons/print/drivers/pdf/source/Jamfile index 4d1cf5964c..3084e5054e 100644 --- a/src/add-ons/print/drivers/pdf/source/Jamfile +++ b/src/add-ons/print/drivers/pdf/source/Jamfile @@ -2,8 +2,7 @@ SubDir HAIKU_TOP src add-ons print drivers pdf source ; SetSubDirSupportedPlatformsBeOSCompatible ; -UsePrivateHeaders interface print ; - +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; SubDirHdrs [ FDirName $(HAIKU_TOP) src libs pdflib libs pdflib ] ; AddResources PDF\ Writer : @@ -11,6 +10,7 @@ AddResources PDF\ Writer : ; Addon PDF\ Writer : Print : + AboutText.cpp AdvancedSettingsWindow.cpp Bezier.cpp Bookmark.cpp @@ -22,7 +22,6 @@ Addon PDF\ Writer : Print : FontsWindow.cpp Image.cpp ImageCache.cpp - InterfaceUtils.cpp JobSetupWindow.cpp LinePathBuilder.cpp Link.cpp @@ -42,7 +41,6 @@ Addon PDF\ Writer : Print : Scanner.cpp StatusWindow.cpp SubPath.cpp - Utils.cpp XReferences.cpp ; @@ -51,7 +49,7 @@ LinkAgainst PDF\ Writer : textencoding translation libpdf.a - libprint.a + libprintutils.a ; Package haiku-pdf_writer-cvs : diff --git a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp index 633fb4867f..e37e7f8b7f 100644 --- a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp @@ -33,6 +33,8 @@ THE SOFTWARE. #include #include +#include "BeUtils.h" + #include "PrinterDriver.h" #include "JobSetupWindow.h" #include "DocInfoWindow.h" @@ -89,7 +91,7 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) doc_info.AddString("Keywords", ""); fSetupMsg->AddMessage("doc_info", &doc_info); } - AddFields(&fDocInfo, fSetupMsg, true, NULL, includeKeys); + AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys); allPages = firstPage == 1 && lastPage == MAX_INT32; diff --git a/src/add-ons/print/drivers/pdf/source/Link.cpp b/src/add-ons/print/drivers/pdf/source/Link.cpp index e32d35cdf9..076e16f0eb 100644 --- a/src/add-ons/print/drivers/pdf/source/Link.cpp +++ b/src/add-ons/print/drivers/pdf/source/Link.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include "Link.h" #include "XReferences.h" #include "Bookmark.h" +#include "PDFSystem.h" #include "PDFWriter.h" #include "Log.h" #include "Report.h" diff --git a/src/add-ons/print/drivers/pdf/source/Link.h b/src/add-ons/print/drivers/pdf/source/Link.h index 5f35aaebed..5b3be612cd 100644 --- a/src/add-ons/print/drivers/pdf/source/Link.h +++ b/src/add-ons/print/drivers/pdf/source/Link.h @@ -34,7 +34,9 @@ THE SOFTWARE. #include #include #include "Utils.h" +#include "PDFSystem.h" +class PDFSystem; class PDFWriter; class TextLine; diff --git a/src/add-ons/print/drivers/pdf/source/Utils.h b/src/add-ons/print/drivers/pdf/source/PDFSystem.h similarity index 52% rename from src/add-ons/print/drivers/pdf/source/Utils.h rename to src/add-ons/print/drivers/pdf/source/PDFSystem.h index 122841559c..f36bf15a92 100644 --- a/src/add-ons/print/drivers/pdf/source/Utils.h +++ b/src/add-ons/print/drivers/pdf/source/PDFSystem.h @@ -3,6 +3,7 @@ PDF Writer printer driver. Copyright (c) 2001-2003 OpenBeOS. +Copyright (c) 2006 Haiku. Authors: Philippe Houdoin @@ -29,101 +30,8 @@ THE SOFTWARE. */ -#ifndef _UTILS_H -#define _UTILS_H - -#include -#include -#include - - -// adds fields to message or replaces existing fields (copy BeUtils.h) -void AddFields(BMessage* to, const BMessage* from, bool overwrite = true, const char* excludeList[] = NULL, const char* includeList[] = NULL); -void AddString(BMessage* m, const char* name, const char* value); - -class EscapeMessageFilter : public BMessageFilter -{ -private: - BWindow *fWindow; - int32 fWhat; - -public: - EscapeMessageFilter(BWindow *window, int32 what); - filter_result Filter(BMessage *msg, BHandler **target); -}; - - -#define BEGINS_CHAR(byte) ((byte & 0xc0) != 0x80) - - -template -class TList { -private: - BList fList; - typedef int (*sort_func)(const void*, const void*); - -public: - virtual ~TList(); - void MakeEmpty(); - int32 CountItems() const; - T* ItemAt(int32 index) const; - void AddItem(T* p); - T* RemoveItem(int i); - T* Items(); - void SortItems(int (*comp)(const T**, const T**)); -}; - -// TList -template -TList::~TList() { - MakeEmpty(); -} - - -template -void TList::MakeEmpty() { - const int32 n = CountItems(); - for (int i = 0; i < n; i++) { - delete ItemAt(i); - } - fList.MakeEmpty(); -} - - -template -int32 TList::CountItems() const { - return fList.CountItems(); -} - - -template -T* TList::ItemAt(int32 index) const { - return (T*)fList.ItemAt(index); -} - - -template -void TList::AddItem(T* p) { - fList.AddItem(p); -} - -template -T* TList::RemoveItem(int i) { - return (T*)fList.RemoveItem(i); -} - - -template -T* TList::Items() { - return (T*)fList.Items(); -} - - -template -void TList::SortItems(int (*comp)(const T**, const T**)) { - sort_func sort = (sort_func)comp; - fList.SortItems(sort); -} +#ifndef _PDF_SYSTEM_H +#define _PDF_SYSTEM_H // PDF coordinate system class PDFSystem { diff --git a/src/add-ons/print/drivers/pdf/source/PDFWriter.h b/src/add-ons/print/drivers/pdf/source/PDFWriter.h index 722bd9e84a..3b59605e77 100644 --- a/src/add-ons/print/drivers/pdf/source/PDFWriter.h +++ b/src/add-ons/print/drivers/pdf/source/PDFWriter.h @@ -46,6 +46,7 @@ THE SOFTWARE. #include "Utils.h" #include "Link.h" #include "ImageCache.h" +#include "PDFSystem.h" #include "pdflib.h" diff --git a/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp b/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp index 43017a6f72..c7b5d3cb8c 100644 --- a/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp +++ b/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp @@ -137,7 +137,7 @@ PrinterDriver::PrintJob Report::Instance(); // show status window - fStatusWindow = new StatusWindow(passes, pfh.page_count, this); + StatusWindow* statusWindow = new StatusWindow(passes, pfh.page_count, this); status = BeginJob(); @@ -146,7 +146,7 @@ PrinterDriver::PrintJob for (copy = 0; copy < copies && status == B_OK && fPrinting; copy++) { for (page = 1; page <= pfh.page_count && status == B_OK && fPrinting; page++) { - fStatusWindow->PostMessage(new BMessage('page')); + statusWindow->NextPage(); status = PrintPage(page, pfh.page_count); } @@ -163,10 +163,10 @@ PrinterDriver::PrintJob // close status window if (Report::Instance()->CountItems() != 0) { - fStatusWindow->WaitForClose(); + statusWindow->WaitForClose(); } - if (fStatusWindow->Lock()) { - fStatusWindow->Quit(); + if (statusWindow->Lock()) { + statusWindow->Quit(); } // delete Report object diff --git a/src/add-ons/print/drivers/pdf/source/PrinterDriver.h b/src/add-ons/print/drivers/pdf/source/PrinterDriver.h index 3226f63036..27c1bd8737 100644 --- a/src/add-ons/print/drivers/pdf/source/PrinterDriver.h +++ b/src/add-ons/print/drivers/pdf/source/PrinterDriver.h @@ -29,8 +29,8 @@ THE SOFTWARE. */ -#ifndef PRINTERDRIVER_H -#define PRINTERDRIVER_H +#ifndef _PRINTER_DRIVER_H +#define _PRINTER_DRIVER_H #include #include @@ -50,8 +50,6 @@ extern "C" { }; -class StatusWindow; - // close StatusWindow after pdf generation enum CloseOption { kAlways, @@ -90,7 +88,6 @@ public: inline BNode *PrinterNode() { return fPrinterNode; } inline BMessage *JobMsg() { return fJobMsg; } inline BDataIO *Transport() { return fPrintTransport.GetDataIO(); } - inline StatusWindow *Status() { return fStatusWindow; } inline int32 Pass() const { return fPass; } // publics status code @@ -104,7 +101,6 @@ private: BFile *fJobFile; BNode *fPrinterNode; BMessage *fJobMsg; - StatusWindow *fStatusWindow; volatile Orientation fOrientation; @@ -115,4 +111,4 @@ private: PrintTransport fPrintTransport; }; -#endif // #ifndef PRINTERDRIVER_H +#endif // _PRINTER_DRIVER_H diff --git a/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp b/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp index 1bddab9b00..3478c8ce71 100644 --- a/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp +++ b/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp @@ -29,14 +29,13 @@ THE SOFTWARE. */ -#ifndef PRINTER_SETTINGS_H #include "PrinterSettings.h" -#endif #include +#include "BeUtils.h" + #include "PrinterPrefs.h" -#include "Utils.h" /** * Constructor @@ -283,7 +282,7 @@ PrinterSettings::Read(BNode* node, BMessage* msg, Kind kind) // if there were none, then create a default set... ps.GetDefaults(&settings); } - AddFields(msg, &settings, false); + AddFields(msg, &settings, NULL, NULL, false); } void diff --git a/src/add-ons/print/drivers/pdf/source/StatusWindow.cpp b/src/add-ons/print/drivers/pdf/source/StatusWindow.cpp index 61acf6974d..f763a39720 100644 --- a/src/add-ons/print/drivers/pdf/source/StatusWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/StatusWindow.cpp @@ -34,19 +34,20 @@ THE SOFTWARE. #include #include +static const uint32 kCancelMsg = 'cncl'; +static const uint32 kProgressMsg = 'prgs'; // -------------------------------------------------- StatusWindow::StatusWindow(int32 passes, int32 pages, PrinterDriver *pd) - : HWindow(BRect(100, 100, 700, 600/*400, 185*/), "PDF Writer", + : HWindow(BRect(100, 100, 700, 600), "PDF Writer", B_TITLED_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE|B_NOT_CLOSABLE|B_FRAME_EVENTS, - B_CURRENT_WORKSPACE, 'cncl') + B_CURRENT_WORKSPACE, kCancelMsg) { fPass = 0; fPages = pages; fPrinterDriver = pd; fPageCount = 0; -// fPopyCount = 0; fReportIndex = 0; fCloseSem = -1; int32 closeOption; @@ -61,21 +62,7 @@ StatusWindow::StatusWindow(int32 passes, int32 pages, PrinterDriver *pd) B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(fPanel); -/* - if (fCopies > 1) { - pages *= fCopies; - } - - r.Set(10, 0, Frame().Width(), 50); - copyLabel = new BStringView(r, "copy_text", "Copy"); - panel->AddChild(copyLabel); - - r.Set(10, 55, Frame().Width()-20, 65); - copyStatus = new BStatusBar(r, "copyStatus"); - copyStatus->SetMaxValue(copies); - copyStatus->SetBarHeight(12); - panel->AddChild(copyStatus); -*/ + r.Set(10, 12, Frame().Width()-5, 22); fPageLabel = new BStringView(r, "page_text", "Page", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); fPanel->AddChild(fPageLabel); @@ -86,17 +73,11 @@ StatusWindow::StatusWindow(int32 passes, int32 pages, PrinterDriver *pd) fPageStatus->SetBarHeight(12); fPanel->AddChild(fPageStatus); - // Cancel button - // add a separator line... -// BBox *line = new BBox(BRect(r.left, 50, r.right, 51), NULL, -// B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); -// panel->AddChild(line); - // add a "Cancel" button int32 x = 110; int32 y = 55; fCancel = new BButton(BRect(x, y, x + 100, y + 20), NULL, "Cancel", - new BMessage('cncl'), B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS); + new BMessage(kCancelMsg), B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS); fCancel->ResizeToPreferred(); fPanel->AddChild(fCancel); @@ -107,7 +88,6 @@ StatusWindow::StatusWindow(int32 passes, int32 pages, PrinterDriver *pd) fReport->SetStylable(true); fReport->MakeEditable(false); fPanel->AddChild(new BScrollView("", fReport, B_FOLLOW_ALL, 0, false, true)); -// fPanel->AddChild(fReport); ResizeTo(300, 85); @@ -119,15 +99,7 @@ void StatusWindow::MessageReceived(BMessage *msg) { switch (msg->what) { -/* - case 'copy': - copy = ""; - copy << "Copy: " << ++copyCount; - copyLabel->SetText(copy.String()); - copyStatus->Update(1); - break; -*/ - case 'cncl': + case kCancelMsg: if (fCloseSem == -1) { fPrinterDriver->StopPrinting(); fCancel->SetEnabled(false); @@ -136,7 +108,8 @@ StatusWindow::MessageReceived(BMessage *msg) release_sem(fCloseSem); } break; - case 'page': + + case kProgressMsg: fPage = ""; if (fPass == 0) fPage << "Collecting Patterns Page: " << fPageCount; @@ -200,7 +173,13 @@ void StatusWindow::UpdateReport() { } } -void StatusWindow::WaitForClose() { +void +StatusWindow::NextPage() { + PostMessage(kProgressMsg); +} + +void +StatusWindow::WaitForClose() { fCloseSem = create_sem(0, "close_sem"); Lock(); @@ -220,7 +199,7 @@ void StatusWindow::WaitForClose() { fCloseOption == kNoErrors && !hasErrors || fCloseOption == kNoErrorsOrWarnings && !hasErrorsOrWarnings || fCloseOption == kNoErrorsWarningsOrInfo && !hasErrorsWarningsOrInfo) { - PostMessage('cncl'); + PostMessage(kCancelMsg); } Unlock(); diff --git a/src/add-ons/print/drivers/pdf/source/StatusWindow.h b/src/add-ons/print/drivers/pdf/source/StatusWindow.h index 76bacfafff..59cf5c31a9 100644 --- a/src/add-ons/print/drivers/pdf/source/StatusWindow.h +++ b/src/add-ons/print/drivers/pdf/source/StatusWindow.h @@ -44,14 +44,11 @@ class StatusWindow : public HWindow private: int32 fPass; int32 fPages; -// BString fCopy; + BString fPage; int32 fPageCount; -// int fCopyCount; -// BStringView *fCopyLabel; BStringView *fPageLabel; BStatusBar *fPageStatus; -// BStatusBar *fCopyStatus; BButton *fCancel; PrinterDriver *fPrinterDriver; int32 fReportIndex; @@ -60,12 +57,14 @@ private: CloseOption fCloseOption; void UpdateReport(); + public: typedef HWindow inherited; StatusWindow(int32 passes, int32 pages, PrinterDriver *pd); void MessageReceived(BMessage *msg); + void NextPage(); void WaitForClose(); }; #endif diff --git a/src/add-ons/print/drivers/pdf/source/Utils.cpp b/src/add-ons/print/drivers/pdf/source/Utils.cpp deleted file mode 100644 index 7d078b082e..0000000000 --- a/src/add-ons/print/drivers/pdf/source/Utils.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - -PDF Writer printer driver. - -Copyright (c) 2001-2003 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - -#include -#include "Utils.h" - -// -------------------------------------------------- -EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what) - : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD') - , fWindow(window), - fWhat(what) -{ -} - - -// -------------------------------------------------- -filter_result -EscapeMessageFilter::Filter(BMessage *msg, BHandler **target) -{ - int32 key; - // notify window with message fWhat if Escape key is hit - if (B_OK == msg->FindInt32("key", &key) && key == 1) { - fWindow->PostMessage(fWhat); - return B_SKIP_MESSAGE; - } - return B_DISPATCH_MESSAGE; -} - -// -------------------------------------------------- -// copied from BeUtils.cpp -static bool InList(const char* list[], const char* name) { - for (int i = 0; list[i] != NULL; i ++) { - if (strcmp(list[i], name) == 0) return true; - } - return false; -} - -// -------------------------------------------------- -// copied from BeUtils.cpp -void AddFields(BMessage* to, const BMessage* from, bool overwrite, const char* excludeList[], const char* includeList[]) { - if (to == from) return; - char* name; - type_code type; - int32 count; - for (int32 i = 0; from->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i ++) { - const void* data; - ssize_t size; - if (excludeList && InList(excludeList, name)) continue; - if (includeList && !InList(includeList, name)) continue; - - if (!overwrite && to->FindData(name, type, 0, &data, &size) == B_OK) { - continue; - } - // replace existing data - to->RemoveName(name); - - for (int32 j = 0; j < count; j ++) { - if (from->FindData(name, type, j, &data, &size) == B_OK) { - // WTF why works AddData not for B_STRING_TYPE in R5.0.3? - if (type == B_STRING_TYPE) { - to->AddString(name, (const char*)data); - } else if (type == B_MESSAGE_TYPE) { - BMessage m; - from->FindMessage(name, j, &m); - to->AddMessage(name, &m); - } else { - to->AddData(name, type, data, size); - } - } - } - } -} - -void AddString(BMessage* m, const char* name, const char* value) { - if (m->HasString(name, 0)) { - m->ReplaceString(name, value); - } else { - m->AddString(name, value); - } -} - - diff --git a/src/add-ons/print/drivers/postscript/Jamfile b/src/add-ons/print/drivers/postscript/Jamfile index 0c4e8feb6c..7db90e52e5 100644 --- a/src/add-ons/print/drivers/postscript/Jamfile +++ b/src/add-ons/print/drivers/postscript/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons print drivers postscript ; SetSubDirSupportedPlatformsBeOSCompatible ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print libprint ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; AddResources PS\ Compatible : PS.rsrc ; @@ -12,7 +13,11 @@ Addon PS\ Compatible : Print : PSCap.cpp ; -LinkAgainst PS\ Compatible : be libprint.a $(TARGET_LIBSTDC++) ; +LinkAgainst PS\ Compatible : + be + libprint.a + libprintutils.a + $(TARGET_LIBSTDC++) ; Package haiku-printingkit-cvs : PS\ Compatible : diff --git a/src/add-ons/print/drivers/preview/Driver.cpp b/src/add-ons/print/drivers/preview/Driver.cpp index 1812045760..a2994de29f 100644 --- a/src/add-ons/print/drivers/preview/Driver.cpp +++ b/src/add-ons/print/drivers/preview/Driver.cpp @@ -1,33 +1,12 @@ /* - -Preview printer driver. - -Copyright (c) 2001 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2001-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + */ #include diff --git a/src/add-ons/print/drivers/preview/Driver.h b/src/add-ons/print/drivers/preview/Driver.h index fc90b34b44..455ef9a5d8 100644 --- a/src/add-ons/print/drivers/preview/Driver.h +++ b/src/add-ons/print/drivers/preview/Driver.h @@ -1,33 +1,12 @@ /* - -Preview printer driver. - -Copyright (c) 2002 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2002-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + */ #include diff --git a/src/add-ons/print/drivers/preview/Jamfile b/src/add-ons/print/drivers/preview/Jamfile index 53a6be0f2c..15d7dd73c0 100644 --- a/src/add-ons/print/drivers/preview/Jamfile +++ b/src/add-ons/print/drivers/preview/Jamfile @@ -2,24 +2,27 @@ SubDir HAIKU_TOP src add-ons print drivers preview ; SetSubDirSupportedPlatformsBeOSCompatible ; -UsePrivateHeaders interface print ; +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; + +UsePrivateHeaders interface ; AddResources Preview : Preview.rsrc ; Addon Preview : Print : - Utils.cpp - InterfaceUtils.cpp - MarginView.cpp PrinterSetupWindow.cpp PageSetupWindow.cpp JobSetupWindow.cpp Driver.cpp - PrinterDriver.cpp Preview.cpp + PrinterDriver.cpp PreviewDriver.cpp ; -LinkAgainst Preview : be root libprint.a ; +LinkAgainst Preview : + be + root + libprintutils.a ; Package haiku-printingkit-cvs : Preview : diff --git a/src/add-ons/print/drivers/preview/JobSetupWindow.cpp b/src/add-ons/print/drivers/preview/JobSetupWindow.cpp index 7b27a4b829..2023befe88 100644 --- a/src/add-ons/print/drivers/preview/JobSetupWindow.cpp +++ b/src/add-ons/print/drivers/preview/JobSetupWindow.cpp @@ -1,33 +1,12 @@ /* - -Preview printer driver. - -Copyright (c) 2003 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + */ #include #include diff --git a/src/add-ons/print/drivers/preview/JobSetupWindow.h b/src/add-ons/print/drivers/preview/JobSetupWindow.h index 57d76ab9d3..ddbc9a6481 100644 --- a/src/add-ons/print/drivers/preview/JobSetupWindow.h +++ b/src/add-ons/print/drivers/preview/JobSetupWindow.h @@ -1,33 +1,12 @@ /* - -Preview printer driver. - -Copyright (c) 2003 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + */ #ifndef JOBSETUPWINDOW_H #define JOBSETUPWINDOW_H diff --git a/src/add-ons/print/drivers/preview/MarginView.cpp b/src/add-ons/print/drivers/preview/MarginView.cpp deleted file mode 100644 index eae9e438eb..0000000000 --- a/src/add-ons/print/drivers/preview/MarginView.cpp +++ /dev/null @@ -1,709 +0,0 @@ -/* - -MarginView.cpp - -Copyright (c) 2002 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - Todo: - - 2 Make Strings constants or UI resources - -*/ - -#ifndef MARGIN_VIEW_H -#include "MarginView.h" -#endif - -#include -#include - -#include -#include - -/*----------------- MarginView Private Constants --------------------*/ - -const int Y_OFFSET = 20; -const int X_OFFSET = 10; -const int STRING_SIZE = 50; -const int _WIDTH = 50; -const int NUM_COUNT = 10; - -const static float _pointUnits = 1; // 1 point = 1 point -const static float _inchUnits = 72; // 1" = 72 points -const static float _cmUnits = 28.346; // 72/2.54 1cm = 28.346 points - -const static float _minFieldWidth = 100; // pixels -const static float _minUnitHeight = 30; // pixels -const static float _drawInset = 10; // pixels - -const static float unitFormat[] = { _inchUnits, _cmUnits, _pointUnits }; -const static char *unitNames[] = { "Inch", "cm", "Points", NULL }; -const static uint32 unitMsg[] = { MarginView::UNIT_INCH, - MarginView::UNIT_CM, - MarginView::UNIT_POINT }; - -const pattern dots = {{ 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }}; - -const rgb_color black = { 0,0,0,0 }; -const rgb_color red = { 255,0,0,0 }; -const rgb_color white = { 255,255,255,0 }; -const rgb_color gray = { 220,220,220,0 }; - -/*----------------- MarginView Public Methods --------------------*/ - -/** - * Constructor - * - * @param frame, BRect that is the size of the view passed to the superclase - * @param pageWidth, float that is the points value of the page width - * @param pageHeight, float that is the points value of the page height - * @param margins, BRect values of margins - * @param units, unit32 enum for units used in view - * @return void - */ -MarginView::MarginView(BRect frame, - int32 pageWidth, - int32 pageHeight, - BRect margins, - uint32 units) - - :BBox(frame, NULL, B_FOLLOW_ALL) -{ - fUnits = units; - fUnitValue = unitFormat[units]; - - SetLabel("Margins"); - - fMaxPageHeight = frame.Height() - _minUnitHeight - Y_OFFSET; - fMaxPageWidth = frame.Width() - _minFieldWidth - X_OFFSET; - - fMargins = margins; - - fPageWidth = pageWidth; - fPageHeight = pageHeight; -} - -/** - * Destructor - * - * @param none - * @return void - */ -MarginView::~MarginView() { -} - -/*----------------- MarginView Public BeOS Hook Methods --------------------*/ - -/** - * Draw - * - * @param BRect, the draw bounds - * @return void - */ -void MarginView::Draw(BRect rect) -{ - BBox::Draw(rect); - - float y_offset = (float)Y_OFFSET; - float x_offset = (float)X_OFFSET; - BRect r; - - // Calculate offsets depending on orientation - if (fPageWidth < fPageHeight) { // Portrait - x_offset = (fMaxPageWidth/2 + X_OFFSET) - fViewWidth/2; - } else { // landscape - y_offset = (fMaxPageHeight/2 + Y_OFFSET) - fViewHeight/2; - } - - // draw the page - SetHighColor(white); - r = BRect(0, 0, fViewWidth, fViewHeight); - r.OffsetBy(x_offset, y_offset); - FillRect(r); - SetHighColor(black); - StrokeRect(r); - - // draw margin - SetHighColor(red); - SetLowColor(white); - r.top += fMargins.top; - r.right -= fMargins.right; - r.bottom -= fMargins.bottom; - r.left += fMargins.left; - StrokeRect(r, dots); - - // draw the page size label - SetHighColor(black); - SetLowColor(gray); - char str[STRING_SIZE]; - sprintf(str, "%2.1f x %2.1f", fPageWidth/fUnitValue, fPageHeight/fUnitValue); - SetFontSize(10); - DrawString((const char *)str, BPoint(x_offset, fMaxPageHeight + 40)); -} - - -/** - * BeOS Hook Function, change the size of the margin display - * - * @param width of the page - * @param height the page - * @return void - */ -void MarginView::FrameResized(float width, float height) -{ - fMaxPageHeight = height - _minUnitHeight - X_OFFSET; - fMaxPageWidth = width - _minFieldWidth - Y_OFFSET; - - CalculateViewSize(MARGIN_CHANGED); - Invalidate(); -} - -/** - * AttachToWindow - * - * @param none - * @return void - */ -void MarginView::AttachedToWindow() -{ - if (Parent()) { - SetViewColor(Parent()->ViewColor()); - } - ConstructGUI(); -} - -/*----------------- MarginView Public Methods --------------------*/ - -/** - * GetUnits - * - * @param none - * @return uint32 enum, units in inches, cm, points - */ -uint32 MarginView::GetUnits(void) { - return fUnits; -} - -/** - * UpdateView, recalculate and redraw the view - * - * @param msg is a message to the calculate size to tell which field caused - * the update to occur, or it is a general update. - * @return void - */ -void MarginView::UpdateView(uint32 msg) -{ - Window()->Lock(); - CalculateViewSize(msg); // nur Preview in Margins BBox! - Invalidate(); - Window()->Unlock(); -} - -/** - * SetPageSize - * - * @param pageWidth, float that is the unit value of the page width - * @param pageHeight, float that is the unit value of the page height - * @return void - */ -void MarginView::SetPageSize(float pageWidth, float pageHeight) -{ - fPageWidth = pageWidth; - fPageHeight = pageHeight; -} - -/** - * GetPageSize - * - * @param none - * @return BPoint, contains actual point values of page in x, y of point - */ -BPoint MarginView::GetPageSize(void) { - return BPoint(fPageWidth, fPageHeight); -} - -/** - * GetMargin - * - * @param none - * @return rect, return margin values always in points - */ -BRect MarginView::GetMargin(void) -{ - BRect margin; - - // convert the field text to values - float ftop = atof(fTop->Text()); - float fright = atof(fRight->Text()); - float fleft = atof(fLeft->Text()); - float fbottom = atof(fBottom->Text()); - - // convert to units to points - switch (fUnits) - { - case UNIT_INCH: - // convert to points - ftop *= _inchUnits; - fright *= _inchUnits; - fleft *= _inchUnits; - fbottom *= _inchUnits; - break; - case UNIT_CM: - // convert to points - ftop *= _cmUnits; - fright *= _cmUnits; - fleft *= _cmUnits; - fbottom *= _cmUnits; - break; - } - - margin.Set(fleft, ftop, fright, fbottom); - - return margin; -} - -/** - * MesssageReceived() - * - * Receive messages for the view - * - * @param BMessage* , the message being received - * @return void - */ -void MarginView::MessageReceived(BMessage *msg) -{ - switch (msg->what) - { - case CHANGE_PAGE_SIZE: { - float w; - float h; - msg->FindFloat("width", &w); - msg->FindFloat("height", &h); - SetPageSize(w, h); - UpdateView(MARGIN_CHANGED); - } - break; - - case FLIP_PAGE: { - BPoint p; - p = GetPageSize(); - SetPageSize(p.y, p.x); - UpdateView(MARGIN_CHANGED); - } - break; - - case MARGIN_CHANGED: - UpdateView(MARGIN_CHANGED); - break; - - case TOP_MARGIN_CHANGED: - UpdateView(TOP_MARGIN_CHANGED); - break; - - case LEFT_MARGIN_CHANGED: - UpdateView(LEFT_MARGIN_CHANGED); - break; - - case RIGHT_MARGIN_CHANGED: - UpdateView(RIGHT_MARGIN_CHANGED); - break; - - case BOTTOM_MARGIN_CHANGED: - UpdateView(BOTTOM_MARGIN_CHANGED); - break; - - case UNIT_INCH: - case UNIT_CM: - case UNIT_POINT: - SetUnits(msg->what); - break; - - default: - BView::MessageReceived(msg); - break; - } -} -/*----------------- MarginView Private Methods --------------------*/ - -/** - * ConstructGUI() - * - * Creates the GUI for the View. MUST be called AFTER the View is attached to - * the Window, or will crash and/or create strange behaviour - * - * @param none - * @return void - */ -void MarginView::ConstructGUI() -{ - BMessage *msg; - BString str; - BMenuItem *item; - BMenuField *mf; - BPopUpMenu *menu; - -// Create text fields - msg = new BMessage(MARGIN_CHANGED); - BRect r(Frame().Width() - be_plain_font->StringWidth("Top#") - _WIDTH, - Y_OFFSET, Frame().Width() - X_OFFSET, _WIDTH); - - // top - str << fMargins.top/fUnitValue; - fTop = new BTextControl( r, "top", "Top", str.String(), NULL, - B_FOLLOW_RIGHT); - - fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED)); - fTop->SetDivider(be_plain_font->StringWidth("Top#")); - fTop->SetTarget(this); - AllowOnlyNumbers(fTop, NUM_COUNT); - AddChild(fTop); - - - - - //left - r.OffsetBy(0, Y_OFFSET); - r.left = Frame().Width() - be_plain_font->StringWidth("Left#") - _WIDTH; - str = ""; - str << fMargins.left/fUnitValue; - fLeft = new BTextControl( r, "left", "Left", str.String(), NULL, - B_FOLLOW_RIGHT); - - fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED)); - fLeft->SetDivider(be_plain_font->StringWidth("Left#")); - fLeft->SetTarget(this); - AllowOnlyNumbers(fLeft, NUM_COUNT); - AddChild(fLeft); - - - - - //bottom - r.OffsetBy(0, Y_OFFSET); - r.left = Frame().Width() - be_plain_font->StringWidth("Bottom#") - _WIDTH; - str = ""; - str << fMargins.bottom/fUnitValue; - fBottom = new BTextControl( r, "bottom", "Bottom", str.String(), NULL, - B_FOLLOW_RIGHT); - - fBottom->SetModificationMessage(new BMessage(BOTTOM_MARGIN_CHANGED)); - fBottom->SetDivider(be_plain_font->StringWidth("Bottom#")); - fBottom->SetTarget(this); - - AllowOnlyNumbers(fBottom, NUM_COUNT); - AddChild(fBottom); - - - - - //right - r.OffsetBy(0, Y_OFFSET); - r.left = Frame().Width() - be_plain_font->StringWidth("Right#") - _WIDTH; - str = ""; - str << fMargins.right/fUnitValue; - fRight = new BTextControl( r, "right", "Right", str.String(), NULL, - B_FOLLOW_RIGHT); - - fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED)); - fRight->SetDivider(be_plain_font->StringWidth("Right#")); - fRight->SetTarget(this); - AllowOnlyNumbers(fRight, NUM_COUNT); - AddChild(fRight); - - - -// Create Units popup - r.OffsetBy(-X_OFFSET,Y_OFFSET); - r.right += Y_OFFSET; - - menu = new BPopUpMenu("units"); - mf = new BMenuField(r, "units", "Units", menu, - B_FOLLOW_BOTTOM|B_FOLLOW_RIGHT|B_WILL_DRAW); - mf->ResizeToPreferred(); - mf->SetDivider(be_plain_font->StringWidth("Units#")); - - // Construct menu items - for (int i=0; unitNames[i] != NULL; i++ ) - { - msg = new BMessage(unitMsg[i]); - menu->AddItem(item = new BMenuItem(unitNames[i], msg)); - item->SetTarget(this); - if (fUnits == unitMsg[i]) { - item->SetMarked(true); - } - } - AddChild(mf); - - // calculate the sizes for drawing page view - CalculateViewSize(MARGIN_CHANGED); -} - - -/** - * AllowOnlyNumbers() - * - * @param BTextControl, the control we want to only allow numbers - * @param maxNum, the maximun number of characters allowed - * @return void - */ -void MarginView::AllowOnlyNumbers(BTextControl *textControl, int maxNum) -{ - BTextView *tv = textControl->TextView(); - - for (long i = 0; i < 256; i++) { - tv->DisallowChar(i); - } - for (long i = '0'; i <= '9'; i++) { - tv->AllowChar(i); - } - tv->AllowChar(B_BACKSPACE); - tv->AllowChar('.'); - tv->SetMaxBytes(maxNum); -} - -/** - * SetMargin - * - * @param brect, margin values in rect - * @return void - */ -void MarginView::SetMargin(BRect margin) { - fMargins = margin; -} - -/** - * SetUnits, called by the MarginMgr when the units popup is selected - * - * @param uint32, the enum that identifies the units requested to change to. - * @return void - */ -void MarginView::SetUnits(uint32 unit) -{ - // do nothing if the current units are the same as requested - if (unit == fUnits) { - return; - } - - // set the units Format - fUnitValue = unitFormat[unit]; - - // convert the field text to values - float ftop = atof(fTop->Text()); - float fright = atof(fRight->Text()); - float fleft = atof(fLeft->Text()); - float fbottom = atof(fBottom->Text()); - - // convert to target units - switch (fUnits) - { - case UNIT_INCH: - // convert to points - ftop *= _inchUnits; - fright *= _inchUnits; - fleft *= _inchUnits; - fbottom *= _inchUnits; - // check for target unit is cm - if (unit == UNIT_CM) { - ftop /= _cmUnits; - fright /= _cmUnits; - fleft /= _cmUnits; - fbottom /= _cmUnits; - } - break; - case UNIT_CM: - // convert to points - ftop *= _cmUnits; - fright *= _cmUnits; - fleft *= _cmUnits; - fbottom *= _cmUnits; - // check for target unit is inches - if (unit == UNIT_INCH) { - ftop /= _inchUnits; - fright /= _inchUnits; - fleft /= _inchUnits; - fbottom /= _inchUnits; - } - break; - case UNIT_POINT: - // check for target unit is cm - if (unit == UNIT_CM) { - ftop /= _cmUnits; - fright /= _cmUnits; - fleft /= _cmUnits; - fbottom /= _cmUnits; - } - // check for target unit is inches - if (unit == UNIT_INCH) { - ftop /= _inchUnits; - fright /= _inchUnits; - fleft /= _inchUnits; - fbottom /= _inchUnits; - } - break; - } - fUnits = unit; - - // lock Window since these changes are from another thread - Window()->Lock(); - - // set the fields to new units - BString str; - str << ftop; - fTop->SetText(str.String()); - - str = ""; - str << fleft; - fLeft->SetText(str.String()); - - str = ""; - str << fright; - fRight->SetText(str.String()); - - str = ""; - str << fbottom; - fBottom->SetText(str.String()); - - // update UI - CalculateViewSize(MARGIN_CHANGED); - Invalidate(); - - Window()->Unlock(); -} - -/** - * CalculateViewSize - * - * calculate the size of the view that is used - * to show the page inside the margin box. This is dependent - * on the size of the box and the room we have to show it and - * the units that we are using and the orientation of the page. - * - * @param msg, the message for which field changed to check value bounds - * @return void - */ -void MarginView::CalculateViewSize(uint32 msg) -{ - // determine page orientation - if (fPageHeight < fPageWidth) { // LANDSCAPE - fViewWidth = fMaxPageWidth; - fViewHeight = fPageHeight * (fViewWidth/fPageWidth); - float hdiff = fViewHeight - fMaxPageHeight; - if (hdiff > 0) { - fViewHeight -= hdiff; - fViewWidth -= hdiff; - } - } else { // PORTRAIT - fViewHeight = fMaxPageHeight; - fViewWidth = fPageWidth * (fViewHeight/fPageHeight); - float wdiff = fViewWidth - fMaxPageWidth; - if (wdiff > 0) { - fViewHeight -= wdiff; - fViewWidth -= wdiff; - } - } - - // calculate margins based on view size - - // find the length of 1 pixel in points - // ex: 80px/800pt = 0.1px/pt - float pixelLength = fViewHeight/fPageHeight; - - // convert the margins to points - // The text field will have a number that us in the current unit - // ex 0.2" * 72pt = 14.4pts - float ftop = atof(fTop->Text()) * fUnitValue; - float fright = atof(fRight->Text()) * fUnitValue; - float fbottom = atof(fBottom->Text()) * fUnitValue; - float fleft = atof(fLeft->Text()) * fUnitValue; - - // Check that the margins don't overlap each other... - float ph = fPageHeight; - float pw = fPageWidth; - BString str; - - // Bounds calculation rules: - if (msg == TOP_MARGIN_CHANGED) - { - // top must be <= bottom - if (ftop > (ph - fbottom)) { - ftop = ph - fbottom; - str = ""; - str << ftop / fUnitValue; - Window()->Lock(); - fTop->SetText(str.String()); - Window()->Unlock(); - } - - } - - if (msg == BOTTOM_MARGIN_CHANGED) - { - // bottom must be <= pageHeight - if (fbottom > (ph - ftop)) { - fbottom = ph - ftop; - str = ""; - str << fbottom / fUnitValue; - Window()->Lock(); - fBottom->SetText(str.String()); - Window()->Unlock(); - } - } - - if (msg == LEFT_MARGIN_CHANGED) - { - // left must be <= right - if (fleft > (pw - fright)) { - fleft = pw - fright; - str = ""; - str << fleft / fUnitValue; - Window()->Lock(); - fLeft->SetText(str.String()); - Window()->Unlock(); - } - } - - if (msg == RIGHT_MARGIN_CHANGED) - { - // right must be <= fPageWidth - if (fright > (pw - fleft)) { - fright = pw - fleft; - str = ""; - str << fright / fUnitValue; - Window()->Lock(); - fRight->SetText(str.String()); - Window()->Unlock(); - } - } - - // convert the unit value to pixels - // ex: 14.4pt * 0.1px/pt = 1.44px - fMargins.top = ftop * pixelLength; - fMargins.right = fright * pixelLength; - fMargins.bottom = fbottom * pixelLength; - fMargins.left = fleft * pixelLength; -} - - diff --git a/src/add-ons/print/drivers/preview/MarginView.h b/src/add-ons/print/drivers/preview/MarginView.h deleted file mode 100644 index cd8a826e7c..0000000000 --- a/src/add-ons/print/drivers/preview/MarginView.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - -MarginView.h - -Copyright (c) 2002 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - Documentation: - - The MarginView is designed to be a self contained component that manages - the display of a BBox control that shows a graphic of a page and its' - margings. The component also includes text fields that are used to mofify - the margin values and a popup to change the units used for the margins. - - There are two interfaces for the MarginView component: - - 1) Set methods: - - page size - - orientation - - Get methods to retrieve: - - margins - - page size - - The method interface is available for the parent Component to call on - the MarginView in response to the Window receiveing messages from - other BControls that it contains, such as a Page Size popup. The - Get methods are used to extract the page size and margins so that - the printer driver may put these values into a BMessage for printing. - - 2) 'Optional' Message interface: - - Set Page Size - - Flip Orientation - - The message interface is available for GUI Controls, BPopupMenu to send - messages to the MarginView if the parent Window is not used to handle - the messages. - - General Use of MarginView component: - - 1) Simply construct a new MarginView object with the margins - you want as defaults and add this view to the parent view - of the dialog. - - MarginView *mv; - mv = new MarginView(viewSizeRect, pageWidth, pageHeight); - parentView->AddChild(mv); - - * you can also set the margins in the constructor, and the units: - - mv = new MarginView(viewSizeRect, pageWidth, pageHeight - marginRect, UNIT_POINTS); - - ! but remeber to have the marginRect values match the UNITS :-) - - 2) Set Page Size with methods: - - mv-SetPageSize( pageWidth, pageHeight ); - mv->UpdateView(); - - 3) Set Page Size with BMessage: - - BMessage* msg = new BMessage(CHANGE_PAGE_SIZE); - msg->AddFloat("width", pageWidth); - msg->AddFloat("height", pageHeight); - mv->PostMessage(msg); - - 4) Flip Page with methods: - - mv-SetPageSize( pageHeight, pageWidth ); - mv->UpdateView(); - - 5) Flip Page with BMessage: - - BMessage* msg = new BMessage(FLIP_PAGE); - mv->Looper()->PostMessage(msg); - - Note: the MarginView DOES NOT keep track of the orientation. This - should be done by the code for the Page setup dialog. - - 6) Get Page Size - - BPoint pageSize = mv->GetPageSize(); - - 7) Get Margins - - BRect margins = mv->GetMargins(); - - 8) Get Units - - uint32 units = mv->GetUnits(); - - where units is one of: - UNIT_INCH, 72 points/in - UNIT_CM, 28.346 points/cm - UNIT_POINT, 1 point/point -*/ - -#ifndef MARGIN_VIEW_H -#define MARGIN_VIEW_H - -#include -#include - -class MarginManager; - -// Messages that the MarginManager accepts -const uint32 TOP_MARGIN_CHANGED = 'tchg'; -const uint32 RIGHT_MARGIN_CHANGED = 'rchg'; -const uint32 LEFT_MARGIN_CHANGED = 'lchg'; -const uint32 BOTTOM_MARGIN_CHANGED = 'bchg'; -const uint32 MARGIN_CHANGED = 'mchg'; -const uint32 CHANGE_PAGE_SIZE = 'chps'; -const uint32 FLIP_PAGE = 'flip'; - -/** - * Class MarginView - */ -class MarginView : public BBox -{ -friend class MarginManager; - -public: - // used to index unitFormat array - typedef enum { - UNIT_INCH = 0, - UNIT_CM, - UNIT_POINT - }; - -private: - - // GUI components - BTextControl *fTop, *fBottom, *fLeft, *fRight; - - // rect that holds the margins for the page as a set of point offsets - BRect fMargins; - - // the maximum size of the page view calculated from the view size - float fMaxPageWidth; - float fMaxPageHeight; - - // the actual size of the page in points - float fPageHeight; - float fPageWidth; - - // the units used to calculate the page size - uint32 fUnits; - float fUnitValue; - - // the size of the drawing area we have to draw the view in pixels - float fViewHeight; - float fViewWidth; - - // Calculate the view size for the margins - void CalculateViewSize(uint32 msg); - - // performed internally using the supplied popup - void SetUnits(uint32 unit); - - // performed internally using text fields - void SetMargin(BRect margin); - - // utility method - void AllowOnlyNumbers(BTextControl *textControl, int maxNum); - -public: - MarginView(BRect rect, - int32 pageWidth = 0, - int32 pageHeight = 0, - BRect margins = BRect(1, 1, 1, 1), // default to 1 inch - uint32 units = UNIT_INCH); - - ~MarginView(); - - /// all the GUI construction code - void ConstructGUI(); - - // page size - void SetPageSize(float pageWidth, float pageHeight); - // point.x = width, point.y = height - BPoint GetPageSize(void); - - // margin - BRect GetMargin(void); - - // orientation - // None, this state should be saved elsewhere in the page setup code - // and not here. See the FLIP_PAGE message to perform this function. - - // units - uint32 GetUnits(void); - - // will cause a recalc and redraw - void UpdateView(uint32 msg); - - // BeOS Hook methods - virtual void AttachedToWindow(void); - void Draw(BRect rect); - void FrameResized(float width, float height); - void MessageReceived(BMessage *msg); -}; - -#endif //MARGIN_VIEW_H diff --git a/src/add-ons/print/drivers/preview/PageSetupWindow.cpp b/src/add-ons/print/drivers/preview/PageSetupWindow.cpp index ca4e4d2235..d08998cd17 100644 --- a/src/add-ons/print/drivers/preview/PageSetupWindow.cpp +++ b/src/add-ons/print/drivers/preview/PageSetupWindow.cpp @@ -1,35 +1,13 @@ /* - -Preview printer driver. - -Copyright (c) 2003 OpenBeOS. -Copyright (c) 2005 Haiku. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - Hartmut Reh - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + * Hartmut Reh + */ #include @@ -38,9 +16,9 @@ THE SOFTWARE. #include "PrinterDriver.h" #include "PageSetupWindow.h" +#include "BeUtils.h" #include "MarginView.h" - // static global variables static struct { @@ -113,7 +91,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) int32 orient; BRect page; BRect margin(0, 0, 0, 0); - int32 units = MarginView::UNIT_INCH; + MarginUnit units = kUnitInch; BString setting_value; // load orientation @@ -131,7 +109,10 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) } // Load units - fSetupMsg->FindInt32("units", &units); + int32 unitsValue; + if (fSetupMsg->FindInt32("units", &unitsValue) == B_OK) { + units = (MarginUnit)unitsValue; + } // add a *dialog* background r = Bounds(); @@ -149,7 +130,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) margin.right = page.right - margin.right; margin.bottom = page.bottom - margin.bottom; } else { - margin.Set(0, 0, 0, 0); + margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm } fMarginView = new MarginView(BRect(20,20,200,160), (int32)width, (int32)height, @@ -340,7 +321,7 @@ PageSetupWindow::UpdateSetupMessage() SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR)); // save the units used - int32 units = fMarginView->GetUnits(); + int32 units = fMarginView->GetMarginUnit(); SetInt32(fSetupMsg, "units", units); } } diff --git a/src/add-ons/print/drivers/preview/PageSetupWindow.h b/src/add-ons/print/drivers/preview/PageSetupWindow.h index 7b0132c814..5343504267 100644 --- a/src/add-ons/print/drivers/preview/PageSetupWindow.h +++ b/src/add-ons/print/drivers/preview/PageSetupWindow.h @@ -1,35 +1,13 @@ /* - -Preview printer driver. - -Copyright (c) 2003 OpenBeOS. -Copyright (c) 2005 Haiku. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - Hartmut Reh - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + * Hartmut Reh + */ #ifndef PAGESETUPWINDOW_H #define PAGESETUPWINDOW_H diff --git a/src/add-ons/print/drivers/preview/Preview.cpp b/src/add-ons/print/drivers/preview/Preview.cpp index c43ecd5fc3..5c63533785 100644 --- a/src/add-ons/print/drivers/preview/Preview.cpp +++ b/src/add-ons/print/drivers/preview/Preview.cpp @@ -1,38 +1,19 @@ /* - -Preview - -Copyright (c) 2002, 2003 OpenBeOS. -Copyright (c) 2005 Haiku. - -Author: - Michael Pfeiffer - Hartmut Reh - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2002-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Michael Pfeiffer + * Hartmut Reh + */ + +// TODO Remove. Use shared/libprint/Preview.cpp instead. #include #include #include +#include "BeUtils.h" #include "Utils.h" #include "Preview.h" diff --git a/src/add-ons/print/drivers/preview/Preview.h b/src/add-ons/print/drivers/preview/Preview.h index c426bfa64e..55c37c97c4 100644 --- a/src/add-ons/print/drivers/preview/Preview.h +++ b/src/add-ons/print/drivers/preview/Preview.h @@ -1,33 +1,11 @@ /* - -Preview - -Copyright (c) 2002, 2003 OpenBeOS. -Copyright (c) 2005 Haiku. - -Author: - Michael Pfeiffer - Hartmut Reh - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2002-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Michael Pfeiffer + * Hartmut Reh + */ #include #include "PrintJobReader.h" diff --git a/src/add-ons/print/drivers/preview/PreviewDriver.cpp b/src/add-ons/print/drivers/preview/PreviewDriver.cpp index 7aa5fe32c6..53bad05125 100644 --- a/src/add-ons/print/drivers/preview/PreviewDriver.cpp +++ b/src/add-ons/print/drivers/preview/PreviewDriver.cpp @@ -1,31 +1,10 @@ /* - -PreviewDriver - -Copyright (c) 2003 OpenBeOS. - -Author: - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Michael Pfeiffer + */ #include "PreviewDriver.h" @@ -43,8 +22,8 @@ PrinterDriver* instanciate_driver(BNode *spoolDir) // About dialog text: const char* kAbout = -"Preview for BeOS\n" -"© 2003 OpenBeOS\n" +"Preview for Haiku\n" +"© 2003-2007 Haiku\n" "by Michael Pfeiffer\n" "\n" "Based on PDF Writer by\nPhilippe Houdoin, Simon Gauvin, Michael Pfeiffer\n" diff --git a/src/add-ons/print/drivers/preview/PreviewDriver.h b/src/add-ons/print/drivers/preview/PreviewDriver.h index 08b6eddc77..548c468771 100644 --- a/src/add-ons/print/drivers/preview/PreviewDriver.h +++ b/src/add-ons/print/drivers/preview/PreviewDriver.h @@ -1,31 +1,10 @@ /* - -Preview - -Copyright (c) 2002, 2003 OpenBeOS. - -Author: - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2002-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Michael Pfeiffer + */ #include "Preview.h" #include "PrinterDriver.h" diff --git a/src/add-ons/print/drivers/preview/PrinterDriver.cpp b/src/add-ons/print/drivers/preview/PrinterDriver.cpp index 9126ad9138..90611bd491 100644 --- a/src/add-ons/print/drivers/preview/PrinterDriver.cpp +++ b/src/add-ons/print/drivers/preview/PrinterDriver.cpp @@ -1,34 +1,13 @@ /* - -Preview printer driver. - -Copyright (c) 2003 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + * Dr. Hartmut Reh + */ #include #include // for memset() @@ -105,13 +84,6 @@ PrinterDriver::PrintJob if (!fJobFile || !fPrinterNode) return B_ERROR; - if (fPrintTransport.Open(fPrinterNode) != B_OK) { - return B_ERROR; - } - if (fPrintTransport.IsPrintToFileCanceled()) { - return B_OK; - } - // read print file header fJobFile->Seek(0, SEEK_SET); fJobFile->Read(&pfh, sizeof(pfh)); diff --git a/src/add-ons/print/drivers/preview/PrinterDriver.h b/src/add-ons/print/drivers/preview/PrinterDriver.h index f315409e23..81ff1d01fd 100644 --- a/src/add-ons/print/drivers/preview/PrinterDriver.h +++ b/src/add-ons/print/drivers/preview/PrinterDriver.h @@ -1,40 +1,19 @@ /* - -Preview printer driver. - -Copyright (c) 2001 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2001-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + * Dr. Hartmut Reh + */ #ifndef PRINTERDRIVER_H #define PRINTERDRIVER_H #include #include -#include "PrintTransport.h" #include "InterfaceUtils.h" #ifndef ROUND_UP @@ -102,7 +81,6 @@ public: inline BFile *JobFile() { return fJobFile; } inline BNode *PrinterNode() { return fPrinterNode; } inline BMessage *JobMsg() { return fJobMsg; } - inline BDataIO *Transport() { return fPrintTransport.GetDataIO(); } inline int32 Pass() const { return fPass; } // publics status code @@ -123,9 +101,6 @@ private: bool fPrinting; int32 fPass; - - // transport-related - PrintTransport fPrintTransport; }; #endif // #ifndef PRINTERDRIVER_H diff --git a/src/add-ons/print/drivers/preview/PrinterSetupWindow.cpp b/src/add-ons/print/drivers/preview/PrinterSetupWindow.cpp index 1c7f9421b7..9be9b8bf06 100644 --- a/src/add-ons/print/drivers/preview/PrinterSetupWindow.cpp +++ b/src/add-ons/print/drivers/preview/PrinterSetupWindow.cpp @@ -1,33 +1,12 @@ /* - -Preview printer driver. - -Copyright (c) 2003 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + */ #include #include diff --git a/src/add-ons/print/drivers/preview/PrinterSetupWindow.h b/src/add-ons/print/drivers/preview/PrinterSetupWindow.h index be370be183..d10395b1cb 100644 --- a/src/add-ons/print/drivers/preview/PrinterSetupWindow.h +++ b/src/add-ons/print/drivers/preview/PrinterSetupWindow.h @@ -1,33 +1,12 @@ /* - -Preview printer driver. - -Copyright (c) 2003 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ + * Copyright 2003-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Philippe Houdoin + * Simon Gauvin + * Michael Pfeiffer + */ #ifndef PRINTERSETUPWINDOW_H #define PRINTERSETUPWINDOW_H diff --git a/src/add-ons/print/drivers/shared/Jamfile b/src/add-ons/print/drivers/shared/Jamfile index b3d0bcea31..363e44c42d 100644 --- a/src/add-ons/print/drivers/shared/Jamfile +++ b/src/add-ons/print/drivers/shared/Jamfile @@ -1,3 +1,4 @@ SubDir HAIKU_TOP src add-ons print drivers shared ; +SubInclude HAIKU_TOP src add-ons print drivers shared utils ; SubInclude HAIKU_TOP src add-ons print drivers shared libprint ; diff --git a/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp b/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp index aa3a3ae130..e0ef649f17 100644 --- a/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp +++ b/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -34,12 +35,17 @@ using namespace std; #define std #endif +// Measure printJob() time. Either true or false. +#define MEASURE_PRINT_JOB_TIME false + enum { kMaxMemorySize = (4 *1024 *1024) }; GraphicsDriver::GraphicsDriver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap) - : fMsg(msg), fPrinterData(printer_data), fPrinterCap(printer_cap) + : fMsg(msg) + , fPrinterData(printer_data) + , fPrinterCap(printer_cap) { fView = NULL; fBitmap = NULL; @@ -60,9 +66,29 @@ static BRect RotateRect(BRect rect) return rotated; } -void -GraphicsDriver::setupData(BFile *spool_file, long page_count) +bool +GraphicsDriver::setupData(BFile *spool_file) { + if (fOrgJobData != NULL) { + // already initialized + return true; + } + + print_file_header pfh; + + spool_file->Seek(0, SEEK_SET); + spool_file->Read(&pfh, sizeof(pfh)); + + DBGMSG(("print_file_header::version = 0x%x\n", pfh.version)); + DBGMSG(("print_file_header::page_count = %d\n", pfh.page_count)); + DBGMSG(("print_file_header::first_page = 0x%x\n", (int)pfh.first_page)); + + if (pfh.page_count <= 0) { + // nothing to print + return false; + } + + fPageCount = (uint32) pfh.page_count; BMessage *msg = new BMessage(); msg->Unflatten(spool_file); fOrgJobData = new JobData(msg, fPrinterCap, JobData::kJobSettings); @@ -87,7 +113,7 @@ GraphicsDriver::setupData(BFile *spool_file, long page_count) break; } - if (fOrgJobData->getCollate() && page_count > 1) { + if (fOrgJobData->getCollate() && fPageCount > 1) { fRealJobData->setCopies(1); fInternalCopies = fOrgJobData->getCopies(); } else { @@ -95,6 +121,7 @@ GraphicsDriver::setupData(BFile *spool_file, long page_count) } fSpoolMetaData = new SpoolMetaData(spool_file); + return true; } void @@ -159,8 +186,8 @@ GraphicsDriver::cleanupBitmap() fView = NULL; } -static -BPoint get_scale(JobData *org_job_data) +BPoint +GraphicsDriver::getScale(int32 nup, BRect physicalRect, float scaling) { float width; float height; @@ -168,13 +195,13 @@ BPoint get_scale(JobData *org_job_data) scale.x = scale.y = 1.0f; - switch (org_job_data->getNup()) { + switch (nup) { case 1: scale.x = scale.y = 1.0f; break; case 2: /* 1x2 or 2x1 */ - width = org_job_data->getPhysicalRect().Width(); - height = org_job_data->getPhysicalRect().Height(); + width = physicalRect.Width(); + height = physicalRect.Height(); if (width < height) { // portrait scale.x = height / 2.0f / width; scale.y = width / height; @@ -184,8 +211,8 @@ BPoint get_scale(JobData *org_job_data) } break; case 8: /* 2x4 or 4x2 */ - width = org_job_data->getPhysicalRect().Width(); - height = org_job_data->getPhysicalRect().Height(); + width = physicalRect.Width(); + height = physicalRect.Height(); if (width < height) { scale.x = height / 4.0f / width; scale.y = width / height / 2.0f; @@ -195,8 +222,8 @@ BPoint get_scale(JobData *org_job_data) } break; case 32: /* 4x8 or 8x4 */ - width = org_job_data->getPhysicalRect().Width(); - height = org_job_data->getPhysicalRect().Height(); + width = physicalRect.Width(); + height = physicalRect.Height(); if (width < height) { scale.x = height / 8.0f / width; scale.y = width / height / 4.0f; @@ -237,32 +264,30 @@ BPoint get_scale(JobData *org_job_data) break; } - scale.x = scale.x * org_job_data->getScaling() / 100.0; - scale.y = scale.y * org_job_data->getScaling() / 100.0; + scale.x = scale.x * scaling / 100.0; + scale.y = scale.y * scaling / 100.0; - DBGMSG(("real scale = %f, %f\n", scale.x, scale.y)); return scale; } -static BPoint -get_offset( - int index, - const BPoint *scale, - JobData *org_job_data) +BPoint +GraphicsDriver::getOffset(int32 nup, int index, JobData::Orientation orientation, + const BPoint *scale, BRect scaledPhysicalRect, BRect scaledPrintableRect, + BRect physicalRect) { BPoint offset; offset.x = 0; offset.y = 0; - float width = org_job_data->getScaledPhysicalRect().Width(); - float height = org_job_data->getScaledPhysicalRect().Height(); + float width = scaledPhysicalRect.Width(); + float height = scaledPhysicalRect.Height(); - switch (org_job_data->getNup()) { + switch (nup) { case 1: break; case 2: if (index == 1) { - if (JobData::kPortrait == org_job_data->getOrientation()) { + if (JobData::kPortrait == orientation) { offset.x = width; } else { offset.y = height; @@ -270,7 +295,7 @@ get_offset( } break; case 8: - if (JobData::kPortrait == org_job_data->getOrientation()) { + if (JobData::kPortrait == orientation) { offset.x = width * (index / 2); offset.y = height * (index % 2); } else { @@ -279,7 +304,7 @@ get_offset( } break; case 32: - if (JobData::kPortrait == org_job_data->getOrientation()) { + if (JobData::kPortrait == orientation) { offset.x = width * (index / 4); offset.y = height * (index % 4); } else { @@ -330,10 +355,8 @@ get_offset( } // adjust margin - offset.x += org_job_data->getScaledPrintableRect().left - - org_job_data->getPhysicalRect().left; - offset.y += org_job_data->getScaledPrintableRect().top - - org_job_data->getPhysicalRect().top; + offset.x += scaledPrintableRect.left - physicalRect.left; + offset.y += scaledPrintableRect.top - physicalRect.top; float real_scale = min(scale->x, scale->y); if (real_scale != scale->x) @@ -348,7 +371,6 @@ get_offset( bool GraphicsDriver::printPage(PageDataList *pages) { -#ifndef USE_PREVIEW_FOR_DEBUG BPoint offset; offset.x = 0.0f; offset.y = 0.0f; @@ -364,8 +386,7 @@ GraphicsDriver::printPage(PageDataList *pages) fView->ConstrainClippingRegion(NULL); fView->FillRect(fView->Bounds()); - - BPoint scale = get_scale(fOrgJobData); + BPoint scale = getScale(fOrgJobData->getNup(), fOrgJobData->getPhysicalRect(), fOrgJobData->getScaling()); float real_scale = min(scale.x, scale.y) * fOrgJobData->getXres() / 72.0f; fView->SetScale(real_scale); float x = offset.x / real_scale; @@ -373,7 +394,7 @@ GraphicsDriver::printPage(PageDataList *pages) int page_index = 0; for (PageDataList::iterator it = pages->begin(); it != pages->end(); it++) { - BPoint left_top(get_offset(page_index++, &scale, fOrgJobData)); + BPoint left_top(getOffset(fOrgJobData->getNup(), page_index++, fOrgJobData->getOrientation(), &scale, fOrgJobData->getScaledPhysicalRect(), fOrgJobData->getScaledPrintableRect(), fOrgJobData->getPhysicalRect())); left_top.x -= x; left_top.y -= y; BRect clip(fOrgJobData->getScaledPrintableRect()); @@ -398,46 +419,7 @@ GraphicsDriver::printPage(PageDataList *pages) return false; } } while (offset.x >= 0.0f && offset.y >= 0.0f); -#else // !USE_PREVIEW_FOR_DEBUG - fView->SetScale(1.0); - fView->SetHighColor(255, 255, 255); - fView->ConstrainClippingRegion(NULL); - fView->FillRect(fView->Bounds()); - - BPoint scale = get_scale(fOrgJobData); - fView->SetScale(min(scale.x, scale.y)); - - int page_index = 0; - PageDataList::iterator it; - - for (it = pages->begin() ; it != pages->end() ; it++) { - BPoint left_top(get_offset(page_index, &scale, fOrgJobData)); - BRect clip(fOrgJobData->getScaledPrintableRect()); - clip.OffsetTo(left_top); - BRegion *region = new BRegion(); - region->Set(clip); - fView->ConstrainClippingRegion(region); - delete region; - if ((*it)->startEnum()) { - bool more; - do { - PictureData *picture_data; - more = (*it)->enumObject(&picture_data); - BPoint real_offset = left_top + picture_data->point; - fView->DrawPicture(picture_data->picture, real_offset); - fView->Sync(); - delete picture_data; - } while (more); - } - page_index++; - } - - BRect rc(fRealJobData->getPhysicalRect()); - rc.OffsetTo(30.0, 30.0); - PreviewWindow *preview = new PreviewWindow(rc, "Preview", fBitmap); - preview->Go(); -#endif // USE_PREVIEW_FOR_DEBUG - + return true; } @@ -484,6 +466,7 @@ GraphicsDriver::printDocument(SpoolData *spool_data) // send the page multiple times to the printer copies = fRealJobData->getCopies(); } + fStatusWindow -> SetPageCopies(copies); // inform fStatusWindow about number of copies // printing of even/odd numbered pages only is valid in simplex mode bool simplex = fRealJobData->getPrintStyle() == JobData::kSimplex; @@ -514,6 +497,11 @@ GraphicsDriver::printDocument(SpoolData *spool_data) // print each physical page "copies" of times for (copy = 0; success && copy < copies; copy ++) { + + // Update the status / cancel job + if (fStatusWindow->UpdateStatusBar(page_index, copy)) + return false; + success = startPage(page_index); if (!success) break; @@ -549,20 +537,19 @@ GraphicsDriver::printDocument(SpoolData *spool_data) return success; } +const JobData* +GraphicsDriver::getJobData(BFile *spoolFile) +{ + setupData(spoolFile); + return fOrgJobData; +} + bool GraphicsDriver::printJob(BFile *spool_file) { bool success = true; - print_file_header pfh; - - spool_file->Seek(0, SEEK_SET); - spool_file->Read(&pfh, sizeof(pfh)); - - DBGMSG(("print_file_header::version = 0x%x\n", pfh.version)); - DBGMSG(("print_file_header::page_count = %d\n", pfh.page_count)); - DBGMSG(("print_file_header::first_page = 0x%x\n", (int)pfh.first_page)); - - if (pfh.page_count <= 0) { + if (!setupData(spool_file)) { + // silently exit if there is nothing to print return true; } @@ -571,11 +558,18 @@ GraphicsDriver::printJob(BFile *spool_file) if (fTransport->check_abort()) { success = false; } else if (!fTransport->is_print_to_file_canceled()) { - setupData(spool_file, pfh.page_count); + BStopWatch stopWatch("printJob", !MEASURE_PRINT_JOB_TIME); setupBitmap(); - SpoolData spool_data(spool_file, pfh.page_count, fOrgJobData->getNup(), fOrgJobData->getReverse()); + SpoolData spool_data(spool_file, fPageCount, fOrgJobData->getNup(), fOrgJobData->getReverse()); success = startDoc(); if (success) { + fStatusWindow = new StatusWindow( + fRealJobData->getPageSelection() == JobData::kOddNumberedPages, + fRealJobData->getPageSelection() == JobData::kEvenNumberedPages, + fRealJobData->getFirstPage(), + fPageCount, + fInternalCopies,fRealJobData->getNup()); + while (fInternalCopies--) { success = printDocument(&spool_data); if (success == false) { @@ -583,6 +577,8 @@ GraphicsDriver::printJob(BFile *spool_file) } } endDoc(success); + + fStatusWindow -> Quit(); } cleanupBitmap(); cleanupData(); diff --git a/src/add-ons/print/drivers/shared/libprint/Jamfile b/src/add-ons/print/drivers/shared/libprint/Jamfile index 2912145e47..d193fc17df 100644 --- a/src/add-ons/print/drivers/shared/libprint/Jamfile +++ b/src/add-ons/print/drivers/shared/libprint/Jamfile @@ -6,6 +6,8 @@ SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print libprint ] ; # for BeUtils.h SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print ] ; +# for Utils.h, InterfaceUtils.h +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; StaticLibrary libprint.a : AboutBox.cpp @@ -18,7 +20,6 @@ StaticLibrary libprint.a : JSDSlider.cpp JobData.cpp JobSetupDlg.cpp - MarginView.cpp PackBits.cpp PageSetupDlg.cpp PagesView.cpp @@ -28,6 +29,7 @@ StaticLibrary libprint.a : PrinterCap.cpp PrintProcess.cpp SpoolMetaData.cpp + StatusWindow.cpp Transport.cpp UIDriver.cpp ValidRect.cpp diff --git a/src/add-ons/print/drivers/shared/libprint/JobData.cpp b/src/add-ons/print/drivers/shared/libprint/JobData.cpp index d968e53c07..62c5159e92 100644 --- a/src/add-ons/print/drivers/shared/libprint/JobData.cpp +++ b/src/add-ons/print/drivers/shared/libprint/JobData.cpp @@ -19,6 +19,7 @@ static const char *kJDScaledPrintableRect = "printable_rect"; static const char *kJDFirstPage = "first_page"; static const char *kJDLastPage = "last_page"; +static const char *kJDShowPreview = "JJJJ_showPreview"; static const char *kJDPaper = "JJJJ_paper"; static const char *kJDNup = "JJJJ_nup"; static const char *kJDGamma = "JJJJ_gamma"; @@ -49,6 +50,7 @@ JobData::~JobData() JobData::JobData(const JobData &job_data) { + fShowPreview = job_data.fShowPreview; fPaper = job_data.fPaper; fXRes = job_data.fXRes; fYRes = job_data.fYRes; @@ -82,6 +84,7 @@ JobData::JobData(const JobData &job_data) JobData &JobData::operator = (const JobData &job_data) { + fShowPreview = job_data.fShowPreview; fPaper = job_data.fPaper; fXRes = job_data.fXRes; fYRes = job_data.fYRes; @@ -121,6 +124,11 @@ void JobData::load(BMessage *msg, const PrinterCap *cap, Settings settings) const PaperCap *paperCap = NULL; + if (msg->HasBool(kJDShowPreview)) + fShowPreview = msg->FindBool(kJDShowPreview); + else + fShowPreview = false; + if (msg->HasInt32(kJDPaper)) fPaper = (Paper)msg->FindInt32(kJDPaper); else if (cap->isSupport(PrinterCap::kPaper)) { @@ -263,8 +271,10 @@ void JobData::load(BMessage *msg, const PrinterCap *cap, Settings settings) else fPageOrder = kAcrossFromLeft; - if (msg->HasBool(kJDColor)) - fColor = msg->FindBool(kJDColor) ? kColor : kMonochrome; + if (msg->HasInt32(kJDColor)) + fColor = (Color)msg->FindInt32(kJDColor); + else if (cap->isSupport(PrinterCap::kColor)) + fColor = ((const ColorCap *)cap->getDefaultCap(PrinterCap::kColor))->color; else fColor = kMonochrome; @@ -291,142 +301,108 @@ void JobData::save(BMessage *msg) } // page settings - if (msg->HasInt32(kJDPaper)) - msg->ReplaceInt32(kJDPaper, fPaper); - else - msg->AddInt32(kJDPaper, fPaper); + msg->RemoveName(kJDPaper); + msg->AddInt32(kJDPaper, fPaper); - if (msg->HasInt64(kJDXRes)) - msg->ReplaceInt64(kJDXRes, fXRes); - else - msg->AddInt64(kJDXRes, fXRes); + msg->RemoveName(kJDXRes); + msg->AddInt64(kJDXRes, fXRes); - if (msg->HasInt64(kJDYRes)) - msg->ReplaceInt64(kJDYRes, fYRes); - else - msg->AddInt64(kJDYRes, fYRes); + msg->RemoveName(kJDYRes); + msg->AddInt64(kJDYRes, fYRes); - if (msg->HasInt32(kJDOrientation)) - msg->ReplaceInt32(kJDOrientation, fOrientation); - else - msg->AddInt32(kJDOrientation, fOrientation); + msg->RemoveName(kJDOrientation); + msg->AddInt32(kJDOrientation, fOrientation); - if (msg->HasFloat(kJDScaling)) - msg->ReplaceFloat(kJDScaling, fScaling); - else - msg->AddFloat(kJDScaling, fScaling); + msg->RemoveName(kJDScaling); + msg->AddFloat(kJDScaling, fScaling); - if (msg->HasRect(kJDPaperRect)) - msg->ReplaceRect(kJDPaperRect, fPaperRect); - else - msg->AddRect(kJDPaperRect, fPaperRect); + msg->RemoveName(kJDPaperRect); + msg->AddRect(kJDPaperRect, fPaperRect); - if (msg->HasRect(kJDScaledPaperRect)) - msg->ReplaceRect(kJDScaledPaperRect, fScaledPaperRect); - else - msg->AddRect(kJDScaledPaperRect, fScaledPaperRect); + msg->RemoveName(kJDScaledPaperRect); + msg->AddRect(kJDScaledPaperRect, fScaledPaperRect); - if (msg->HasRect(kJDPrintableRect)) - msg->ReplaceRect(kJDPrintableRect, fPrintableRect); - else - msg->AddRect(kJDPrintableRect, fPrintableRect); + msg->RemoveName(kJDPrintableRect); + msg->AddRect(kJDPrintableRect, fPrintableRect); - if (msg->HasRect(kJDScaledPrintableRect)) - msg->ReplaceRect(kJDScaledPrintableRect, fScaledPrintableRect); - else - msg->AddRect(kJDScaledPrintableRect, fScaledPrintableRect); + msg->RemoveName(kJDScaledPrintableRect); + msg->AddRect(kJDScaledPrintableRect, fScaledPrintableRect); - if (msg->HasRect(kJDPhysicalRect)) - msg->ReplaceRect(kJDPhysicalRect, fPhysicalRect); - else - msg->AddRect(kJDPhysicalRect, fPhysicalRect); + msg->RemoveName(kJDPhysicalRect); + msg->AddRect(kJDPhysicalRect, fPhysicalRect); - if (msg->HasRect(kJDScaledPhysicalRect)) - msg->ReplaceRect(kJDScaledPhysicalRect, fScaledPhysicalRect); - else - msg->AddRect(kJDScaledPhysicalRect, fScaledPhysicalRect); + msg->RemoveName(kJDScaledPhysicalRect); + msg->AddRect(kJDScaledPhysicalRect, fScaledPhysicalRect); - if (msg->HasInt32(kJDMarginUnit)) - msg->ReplaceInt32(kJDMarginUnit, fMarginUnit); - else - msg->AddInt32(kJDMarginUnit, fMarginUnit); + msg->RemoveName(kJDMarginUnit); + msg->AddInt32(kJDMarginUnit, fMarginUnit); - // page settings end here; don't store job settings in message - if (fSettings == kPageSettings) return; + // page settings end here // job settings - if (msg->HasInt32(kJDNup)) - msg->ReplaceInt32(kJDNup, fNup); - else + + // make sure job settings are not present in page settings + msg->RemoveName(kJDShowPreview); + if (fSettings == kJobSettings) + msg->AddBool(kJDShowPreview, fShowPreview); + + msg->RemoveName(kJDNup); + if (fSettings == kJobSettings) msg->AddInt32(kJDNup, fNup); - if (msg->HasInt32(kJDFirstPage)) - msg->ReplaceInt32(kJDFirstPage, fFirstPage); - else + msg->RemoveName(kJDFirstPage); + if (fSettings == kJobSettings) msg->AddInt32(kJDFirstPage, fFirstPage); - if (msg->HasInt32(kJDLastPage)) - msg->ReplaceInt32(kJDLastPage, fLastPage); - else + msg->RemoveName(kJDLastPage); + if (fSettings == kJobSettings) msg->AddInt32(kJDLastPage, fLastPage); - if (msg->HasFloat(kJDGamma)) - msg->ReplaceFloat(kJDGamma, fGamma); - else + msg->RemoveName(kJDGamma); + if (fSettings == kJobSettings) msg->AddFloat(kJDGamma, fGamma); - if (msg->HasFloat(kJDInkDensity)) - msg->ReplaceFloat(kJDInkDensity, fInkDensity); - else + msg->RemoveName(kJDInkDensity); + if (fSettings == kJobSettings) msg->AddFloat(kJDInkDensity, fInkDensity); - if (msg->HasInt32(kJDPaperSource)) - msg->ReplaceInt32(kJDPaperSource, fPaperSource); - else + msg->RemoveName(kJDPaperSource); + if (fSettings == kJobSettings) msg->AddInt32(kJDPaperSource, fPaperSource); - if (msg->HasInt32(kJDCopies)) - msg->ReplaceInt32(kJDCopies, fCopies); - else + msg->RemoveName(kJDCopies); + if (fSettings == kJobSettings) msg->AddInt32(kJDCopies, fCopies); - if (msg->HasBool(kJDCollate)) - msg->ReplaceBool(kJDCollate, fCollate); - else + msg->RemoveName(kJDCollate); + if (fSettings == kJobSettings) msg->AddBool(kJDCollate, fCollate); - if (msg->HasBool(kJDReverse)) - msg->ReplaceBool(kJDReverse, fReverse); - else + msg->RemoveName(kJDReverse); + if (fSettings == kJobSettings) msg->AddBool(kJDReverse, fReverse); - if (msg->HasInt32(kJDPrintStyle)) - msg->ReplaceInt32(kJDPrintStyle, fPrintStyle); - else + msg->RemoveName(kJDPrintStyle); + if (fSettings == kJobSettings) msg->AddInt32(kJDPrintStyle, fPrintStyle); - if (msg->HasInt32(kJDBindingLocation)) - msg->ReplaceInt32(kJDBindingLocation, fBindingLocation); - else + msg->RemoveName(kJDBindingLocation); + if (fSettings == kJobSettings) msg->AddInt32(kJDBindingLocation, fBindingLocation); - if (msg->HasInt32(kJDPageOrder)) - msg->ReplaceInt32(kJDPageOrder, fPageOrder); - else + msg->RemoveName(kJDPageOrder); + if (fSettings == kJobSettings) msg->AddInt32(kJDPageOrder, fPageOrder); - if (msg->HasBool(kJDColor)) - msg->ReplaceBool(kJDColor, fColor == kColor); - else - msg->AddBool(kJDColor, fColor == kColor); + msg->RemoveName(kJDColor); + if (fSettings == kJobSettings) + msg->AddInt32(kJDColor, fColor); - if (msg->HasInt32(kJDDitherType)) - msg->ReplaceInt32(kJDDitherType, fDitherType); - else + msg->RemoveName(kJDDitherType); + if (fSettings == kJobSettings) msg->AddInt32(kJDDitherType, fDitherType); - if (msg->HasInt32(kJDPageSelection)) - msg->ReplaceInt32(kJDPageSelection, fPageSelection); - else + msg->RemoveName(kJDPageSelection); + if (fSettings == kJobSettings) msg->AddInt32(kJDPageSelection, fPageSelection); } diff --git a/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp b/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp index c45ca99689..75eae82b25 100644 --- a/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp +++ b/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp @@ -107,7 +107,7 @@ using namespace std; #define TO_HEIGHT FROM_HEIGHT #define PRINT_WIDTH 365 -#define PRINT_HEIGHT QUALITY_HEIGHT + PAGERABGE_HEIGHT + 20 // 210 +#define PRINT_HEIGHT QUALITY_HEIGHT + PAGERABGE_HEIGHT + 60 #define PAPERFEED_H QUALITY_H + QUALITY_WIDTH + 10 #define PAPERFEED_V QUALITY_V + 5 @@ -173,7 +173,10 @@ using namespace std; #define PRINT_OK_BUTTON_H (PRINT_WIDTH - PRINT_BUTTON_WIDTH - 10) #define PRINT_OK_BUTTON_V (PRINT_HEIGHT - PRINT_BUTTON_HEIGHT - 11) -#define PRINT_CANCEL_BUTTON_H (PRINT_OK_BUTTON_H - PRINT_BUTTON_WIDTH - 12) +#define PREVIEW_H (PRINT_OK_BUTTON_H - PRINT_BUTTON_WIDTH - 12) +#define PREVIEW_V (PRINT_OK_BUTTON_V) + +#define PRINT_CANCEL_BUTTON_H (PREVIEW_H - PRINT_BUTTON_WIDTH - 12) #define PRINT_CANCEL_BUTTON_V PRINT_OK_BUTTON_V const BRect quality_rect( @@ -320,6 +323,14 @@ const BRect cancel_rect( PRINT_CANCEL_BUTTON_H + PRINT_BUTTON_WIDTH, PRINT_CANCEL_BUTTON_V + PRINT_BUTTON_HEIGHT); +const BRect preview_rect( + PREVIEW_H, + PREVIEW_V, + PREVIEW_H + PRINT_BUTTON_WIDTH, + PREVIEW_V + PRINT_BUTTON_HEIGHT); + + + struct SurfaceCap : public BaseCap { color_space surface_type; SurfaceCap(const string &s, bool d, color_space cs) : BaseCap(s, d), surface_type(cs) {} @@ -384,6 +395,7 @@ const DitherCap *gDitherTypes[] = { enum { kMsgRangeAll = 'JSdl', kMsgRangeSelection, + kMsgPreview, kMsgCancel, kMsgOK, kMsgQuality, @@ -525,7 +537,7 @@ JobSetupView::AttachedToWindow() fHalftone = new HalftoneView(rect.OffsetToCopy(1, 1), "halftone", B_FOLLOW_ALL, B_WILL_DRAW); halftoneBorder->AddChild(fHalftone); - fHalftone->preview(fJobData->getGamma(), fJobData->getInkDensity(), fJobData->getDitherType(), fJobData->getColor() == JobData::kColor); + fHalftone->preview(fJobData->getGamma(), fJobData->getInkDensity(), fJobData->getDitherType(), fJobData->getColor() != JobData::kMonochrome); /* gamma */ fGamma = new JSDSlider(gamma_rect, "gamma", "Gamma", new BMessage(kMsgQuality), -300, 300, B_BLOCK_THUMB); @@ -702,6 +714,14 @@ JobSetupView::AttachedToWindow() fOddNumberedPages = AddPageSelectionItem(pageSelectionBox, page_selection_odd_pages_rect, "oddPages", "Odd-Numbered Pages", JobData::kOddNumberedPages); fEvenNumberedPages = AddPageSelectionItem(pageSelectionBox, page_selection_even_pages_rect, "evenPages", "Even-Numbered Pages", JobData::kEvenNumberedPages); + + + /* preview */ + + button = new BButton(preview_rect, "preview", "Preview ...", new BMessage(kMsgPreview)); + AddChild(button); + + /* cancel */ button = new BButton(cancel_rect, "cancel", "Cancel", new BMessage(kMsgCancel)); @@ -709,6 +729,7 @@ JobSetupView::AttachedToWindow() /* ok */ + // TODO OK or "Print"? button = new BButton(ok_rect, "ok", "OK", new BMessage(kMsgOK)); AddChild(button); button->MakeDefault(true); @@ -741,7 +762,7 @@ JobSetupView::MessageReceived(BMessage *msg) break; case kMsgQuality: - fHalftone->preview(getGamma(), getInkDensity(), getDitherType(), getColor() == JobData::kColor); + fHalftone->preview(getGamma(), getInkDensity(), getDitherType(), getColor() != JobData::kMonochrome); break; case kMsgCollateChanged: @@ -799,7 +820,7 @@ JobSetupView::getInkDensity() } bool -JobSetupView::UpdateJobData() +JobSetupView::UpdateJobData(bool showPreview) { int count; @@ -815,6 +836,7 @@ JobSetupView::UpdateJobData() surface_cap++; } */ + fJobData->setShowPreview(showPreview); fJobData->setColor(getColor()); fJobData->setGamma(getGamma()); fJobData->setInkDensity(getInkDensity()); @@ -895,7 +917,8 @@ JobSetupDlg::MessageReceived(BMessage *msg) { switch (msg->what) { case kMsgOK: - fJobSetup->UpdateJobData(); + case kMsgPreview: + fJobSetup->UpdateJobData(msg->what == kMsgPreview); SetResult(B_NO_ERROR); PostMessage(B_QUIT_REQUESTED); break; diff --git a/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp b/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp index 5055f35d7d..214e1988b5 100644 --- a/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp +++ b/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp @@ -354,10 +354,20 @@ PageSetupView::UpdateJobData() resolution_cap++; } + // rotate paper and physical rectangle if landscape orientation + if (JobData::kLandscape == fJobData->getOrientation()) { + swap(&paper_rect.left, &paper_rect.top); + swap(&paper_rect.right, &paper_rect.bottom); + swap(&physical_rect.left, &physical_rect.top); + swap(&physical_rect.right, &physical_rect.bottom); + } + // adjust printable rect by margin fJobData->setMarginUnit(fMarginView->GetMarginUnit()); BRect margin = fMarginView->GetMargin(); - BRect printable_rect = margin; + BRect printable_rect; + printable_rect.left = paper_rect.left + margin.left; + printable_rect.top = paper_rect.top + margin.top; printable_rect.right = paper_rect.right - margin.right; printable_rect.bottom = paper_rect.bottom - margin.bottom; @@ -366,16 +376,6 @@ PageSetupView::UpdateJobData() printable_rect.right = min_c(printable_rect.right, physical_rect.right); printable_rect.bottom = min_c(printable_rect.bottom, physical_rect.bottom); - - if (JobData::kLandscape == fJobData->getOrientation()) { - swap(&paper_rect.left, &paper_rect.top); - swap(&paper_rect.right, &paper_rect.bottom); - swap(&printable_rect.left, &printable_rect.top); - swap(&printable_rect.right, &printable_rect.bottom); - swap(&physical_rect.left, &physical_rect.top); - swap(&physical_rect.right, &physical_rect.bottom); - } - float scaling = atoi(fScaling->Text()); if (scaling <= 0.0) { // sanity check scaling = 100.0; @@ -427,11 +427,6 @@ PageSetupDlg::PageSetupDlg(JobData *job_data, PrinterData *printer_data, const P "Page Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE) { -/* - ostringstream oss; - oss << printer_data->get_printer_name() << " Setup"; - SetTitle(title.str().c_str()); -*/ AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); PageSetupView *view = new PageSetupView(Bounds(), job_data, printer_data, printer_cap); diff --git a/src/add-ons/print/drivers/shared/libprint/Preview.cpp b/src/add-ons/print/drivers/shared/libprint/Preview.cpp index 59c9746f47..0e5596d173 100644 --- a/src/add-ons/print/drivers/shared/libprint/Preview.cpp +++ b/src/add-ons/print/drivers/shared/libprint/Preview.cpp @@ -1,53 +1,619 @@ /* - * Preview.cpp - * Copyright 1999-2000 Y.Takagi. All Rights Reserved. + * Copyright 2002-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Michael Pfeiffer + * Hartmut Reh */ -#include +#include + +#include +#include +#include "BeUtils.h" +#include "Utils.h" + +#include "GraphicsDriver.h" #include "Preview.h" -#ifdef USE_PREVIEW_FOR_DEBUG - -class PreviewView : public BView { -public: - PreviewView(BRect, BBitmap *); - void Draw(BRect); -private: - BBitmap *fBitmap; -}; - -PreviewView::PreviewView(BRect frame, BBitmap *bitmap) - : BView(frame, "preview", B_FOLLOW_ALL, B_WILL_DRAW) +// Implementation of PreviewPage +PreviewPage::PreviewPage(int32 page, PrintJobPage* pjp) + : fPage(page) + , fPictures(NULL) + , fPoints(NULL) + , fRects(NULL) { - fBitmap = bitmap; + 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; } -void PreviewView::Draw(BRect) -{ - DrawBitmap(fBitmap); -} - -PreviewWindow::PreviewWindow(BRect frame, const char *title, BBitmap *bitmap) - : BWindow(frame, title, B_TITLED_WINDOW, 0) -{ - AddChild(new PreviewView(Bounds(), bitmap)); - fSemaphore = create_sem(0, "PreviewSem"); +PreviewPage::~PreviewPage() { + delete []fPictures; + delete []fPoints; + delete []fRects; } -bool PreviewWindow::QuitRequested() -{ - release_sem(fSemaphore); - return true; +status_t PreviewPage::InitCheck() const { + return fStatus; } -int PreviewWindow::Go() +void PreviewPage::Draw(BView* view) { - Show(); - acquire_sem(fSemaphore); - delete_sem(fSemaphore); - Lock(); - Quit(); - return 0; + ASSERT(fStatus == B_OK); + for (int32 i = 0; i < fNumberOfPictures; i ++) + { + view->DrawPicture(&fPictures[i], fPoints[i]); + } } -#endif /* USE_PREVIEW_FOR_DEBUG */ +// Implementation of PreviewView + +const float kPreviewTopMargin = 10; +const float kPreviewBottomMargin = 30; +const float kPreviewLeftMargin = 10; +const float kPreviewRightMargin = 30; + +// TODO share constant with JobData +static const char *kJDOrientation = "orientation"; +static const char *kJDNup = "JJJJ_nup"; +static const char *kJDReverse = "JJJJ_reverse"; +static const char* kJDPageSelection = "JJJJ_page_selection"; + +static BRect RotateRect(BRect rect) +{ + BRect rotated(rect.top, rect.left, rect.bottom, rect.right); + return rotated; +} + +PreviewView::PreviewView(BFile* jobFile, BRect rect) + : BView(rect, "PreviewView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS) + , fPage(0) + , fZoom(0) + , fReader(jobFile) + , fNumberOfPagesPerPage(1) + , fReverse(false) + , fOrientation(JobData::kPortrait) + , fPageSelection(JobData::kAllPages) + , fCachedPage(NULL) +{ + int32 value32; + if (fReader.JobSettings()->FindInt32(kJDOrientation, &value32) == B_OK) { + fOrientation = (JobData::Orientation)value32; + } + if (fReader.JobSettings()->FindInt32(kJDPageSelection, &value32) == B_OK) { + fPageSelection = (JobData::PageSelection)value32; + } + fReader.JobSettings()->FindInt32(kJDNup, &fNumberOfPagesPerPage); + fReader.JobSettings()->FindBool(kJDReverse, &fReverse); + fNumberOfPages = (fReader.NumberOfPages() + fNumberOfPagesPerPage - 1) / fNumberOfPagesPerPage; + if (fPageSelection == JobData::kOddNumberedPages) { + fNumberOfPages = (fNumberOfPages + 1) / 2; + } + else if (fPageSelection == JobData::kEvenNumberedPages) { + fNumberOfPages /= 2; + } + fPageRect = fReader.PaperRect(); + switch (fNumberOfPagesPerPage) { + case 2: + case 8: + case 32: + case 128: + fPageRect = RotateRect(fPageRect); + break; + } +} + +PreviewView::~PreviewView() { + delete fCachedPage; +} + +// returns 2 ^ fZoom +float PreviewView::ZoomFactor() const { + const int32 b = 4; + int32 zoom; + if (fZoom > 0) { + zoom = (1 << b) << fZoom; + } else { + zoom = (1 << b) >> -fZoom; + } + float factor = zoom / (float)(1 << b); + return factor * fReader.GetScale() / 100.0; +} + +BRect PreviewView::PageRect() const { + float f = ZoomFactor(); + BRect r(fPageRect); + return ScaleRect(r, f); +} + +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 { + return fCachedPage && fCachedPage->InitCheck() == B_OK; +} + +void PreviewView::LoadPage(int32 page) { + delete fCachedPage; + fCachedPage = NULL; + PrintJobPage pjp; + if (fReader.GetPage(page, pjp) == B_OK) { + fCachedPage = new PreviewPage(page, &pjp); + } +} + +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()); + + PushState(); + // draw page border around page + r.InsetBy(-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; + FillRect(BRect(x, y, right, bottom)); + + x = r.left + kShadowIndent; + y = r.bottom + 1; + FillRect(BRect(x, y, r.right, bottom)); + PopState(); +} + + +int32 PreviewView::GetPageNumber(int32 index) const +{ + int page = fPage; + if (fReverse) { + page = fNumberOfPages - fPage - 1; + } + + if (fPageSelection == JobData::kOddNumberedPages) { + page *= 2; // 0, 2, 4, ... + } + else if (fPageSelection == JobData::kEvenNumberedPages) { + page = 2 * page + 1; // 1, 3, 5, ... + } + + return page * fNumberOfPagesPerPage + index; +} + +void PreviewView::DrawPage(BRect rect) +{ + + BRect physicalRect = fReader.PaperRect(); + BRect scaledPhysicalRect = physicalRect; + BRect scaledPrintableRect = fReader.PrintableRect(); + + for (int32 index = 0; index < fNumberOfPagesPerPage; index ++) { + int32 pageNumber = GetPageNumber(index); + if (pageNumber < 0) { + // no page at index + continue; + } + if (!IsPageLoaded(pageNumber)) { + LoadPage(pageNumber); + } + if (!IsPageValid()) { + // TODO show feedback + continue; + } + + BPoint scalingXY = GraphicsDriver::getScale(fNumberOfPagesPerPage, physicalRect, 100.0); + float scaling = min_c(scalingXY.x, scalingXY.y); + BPoint offset = GraphicsDriver::getOffset(fNumberOfPagesPerPage, index, fOrientation, &scalingXY, + scaledPhysicalRect, scaledPrintableRect, physicalRect); + + // draw page contents + PushState(); + + // print job coordinates are relative to the printable rect + SetScale(ZoomFactor() * scaling); + + BPoint leftTopMargin(BPoint(kPreviewLeftMargin, kPreviewTopMargin)); + leftTopMargin.x /= ZoomFactor() * scaling; + leftTopMargin.y /= ZoomFactor() * scaling; + offset += leftTopMargin; + SetOrigin(offset); + + // constrain clipping region to printable rectangle + BRect clipRect(fReader.PrintableRect()); + clipRect.OffsetTo(0, 0); + BRegion clip(clipRect); + ConstrainClippingRegion(&clip); + + fCachedPage->Draw(this); + + PopState(); + } +} + +void PreviewView::Draw(BRect rect) { + if (fReader.InitCheck() == B_OK) { + DrawPageFrame(rect); + DrawPage(rect); + } +} + +void PreviewView::FrameResized(float width, float height) { + FixScrollbars(); +} + +bool PreviewView::ShowsFirstPage() const { + return fPage == 0; +} + +bool PreviewView::ShowsLastPage() const { + return fPage == NumberOfPages() - 1; +} + +int PreviewView::NumberOfPages() const { + return fNumberOfPages; +} + +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, bool showOkAndCancelButtons) + : BlockingWindow(BRect(20, 24, 400, 600), "Preview", B_DOCUMENT_WINDOW, 0) +{ + const float kButtonDistance = 15; + const float kPageTextDistance = 10; + const float kVerticalIndent = 7; + const float kHorizontalIndent = 20; + + float top = kVerticalIndent; + float left = kHorizontalIndent; + 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 + fFirst = new BButton(BRect(left, top, left+10, top+10), "First", "First Page", new BMessage(MSG_FIRST_PAGE)); + AddChild(fFirst); + + fPrev = new BButton(BRect(left, top, left+10, top+10), "Prev", "Previous Page", new BMessage(MSG_PREV_PAGE)); + AddChild(fPrev); + fPrev->ResizeToPreferred(); + // remember size of largest button + width = fPrev->Bounds().Width()+1; + height = fPrev->Bounds().Height()+1; + + fFirst->ResizeTo(width, height); + left = fFirst->Frame().right + kButtonDistance; + + // move Previous Page button after First Page button + 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)); + 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)); + 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->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_RIGHT); + int 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); + 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); + // estimate max. width + float pageTextWidth = fPageText->StringWidth("of 99999 Pages"); + // estimate height + BFont font; + fPageText->GetFont(&font); + float pageTextHeight = font.Size() + 2; + // resize to estimated size + 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)); + 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)); + AddChild(fZoomOut); + fZoomOut->ResizeTo(width, height); + + fButtonBarHeight = fZoomOut->Frame().bottom + 7; + float bottomOfTopButtonBar = fButtonBarHeight; + + if (showOkAndCancelButtons) { + // cancel printing if user closes the preview window + SetUserQuitResult(B_ERROR); + + // add another button bar at bottom of window + r.bottom -= fButtonBarHeight; + // update the total height of both bars + fButtonBarHeight *= 2; + + // right align buttons + left = r.Width() - width - kHorizontalIndent; + top = r.Height() + kVerticalIndent + B_H_SCROLL_BAR_HEIGHT; + + left -= width + kButtonDistance; + BButton *printJob = new BButton(BRect(left, top+2, left+10, top+12), "PrintJob", "Print", new BMessage(MSG_PRINT_JOB), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + printJob->MakeDefault(true); + AddChild(printJob); + printJob->ResizeTo(width+4, height+4); + + left += width + kButtonDistance; + BButton *cancelJob = new BButton(BRect(left, top, left+10, top+10), "CancelJob", "Cancel", new BMessage(MSG_CANCEL_JOB), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + AddChild(cancelJob); + cancelJob->ResizeTo(width, height); + } + + + // add preview view + r.top = bottomOfTopButtonBar; + fPreview = new PreviewView(jobFile, r); + + + 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(true); + fPreview->FixScrollbars(); + UpdateControls(); + } +} + +void PreviewWindow::ResizeToPage(bool allowShrinking) { + BScreen screen; + BRect r(fPreview->ViewRect()); + float width, height; + float maxWidth, maxHeight, minWidth; + 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; + + // width so that all buttons are visible + minWidth = fZoomOut->Frame().right + 10; + + if (width < minWidth) width = minWidth; + + if (width > maxWidth) width = maxWidth; + if (height > maxHeight) height = maxHeight; + + if (!allowShrinking) { + if (Bounds().Width() > width) width = Bounds().Width(); + if (Bounds().Height() > height) height = Bounds().Height(); + } + ResizeTo(width, height); +} + +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());} + +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 MSG_CANCEL_JOB: + Quit(B_ERROR); + break; + case MSG_PRINT_JOB: + Quit(B_OK); + 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; +} diff --git a/src/add-ons/print/drivers/shared/libprint/PrinterData.cpp b/src/add-ons/print/drivers/shared/libprint/PrinterData.cpp index fef8f6e0fb..af81d17db1 100644 --- a/src/add-ons/print/drivers/shared/libprint/PrinterData.cpp +++ b/src/add-ons/print/drivers/shared/libprint/PrinterData.cpp @@ -34,6 +34,7 @@ void PrinterData::load() char buffer[512]; fNode->ReadAttr(PD_DRIVER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer)); + // TODO fix possible buffer overrun (not terminated string). fDriverName = buffer; fNode->ReadAttr(PD_PRINTER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer)); fPrinterName = buffer; @@ -41,14 +42,18 @@ void PrinterData::load() fComments = buffer; fNode->ReadAttr(PD_TRANSPORT, B_STRING_TYPE, 0, buffer, sizeof(buffer)); fTransport = buffer; - fNode->ReadAttr(PD_PROTOCOL_CLASS, B_BOOL_TYPE, 0, &fProtocolClass, sizeof(fProtocolClass)); + + int32 valueI32; + fNode->ReadAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, sizeof(valueI32)); + fProtocolClass = (int)valueI32; } void PrinterData::save() { if (fNode == NULL) return; - fNode->WriteAttr(PD_PROTOCOL_CLASS, B_BOOL_TYPE, 0, &fProtocolClass, sizeof(fProtocolClass)); + int32 valueI32 = (int32)fProtocolClass; + fNode->WriteAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, sizeof(valueI32)); } bool PrinterData::getPath(string &path) const diff --git a/src/add-ons/print/drivers/shared/libprint/PrinterDriver.cpp b/src/add-ons/print/drivers/shared/libprint/PrinterDriver.cpp index d36ba4b5de..abcb27c042 100644 --- a/src/add-ons/print/drivers/shared/libprint/PrinterDriver.cpp +++ b/src/add-ons/print/drivers/shared/libprint/PrinterDriver.cpp @@ -22,6 +22,7 @@ #include "PrinterCap.h" #include "PrinterData.h" #include "UIDriver.h" +#include "Preview.h" // Implementation of PrinterDriver @@ -138,6 +139,13 @@ PrinterDriver::TakeJob(BFile* printJob, BMessage* settings) DUMP_BNODE(fSpoolFolder); fGraphicsDriver = InstantiateGraphicsDriver(settings, fPrinterData, fPrinterCap); + const JobData* jobData = fGraphicsDriver->getJobData(printJob); + if (jobData != NULL && jobData->getShowPreview()) { + PreviewWindow *preview = new PreviewWindow(printJob, true); + if (preview->Go() != B_OK) { + return new BMessage('okok'); + } + } BMessage *result = fGraphicsDriver->takeJob(printJob); DUMP_BMESSAGE(result); diff --git a/src/add-ons/print/drivers/shared/libprint/StatusWindow.cpp b/src/add-ons/print/drivers/shared/libprint/StatusWindow.cpp new file mode 100644 index 0000000000..8cb328a707 --- /dev/null +++ b/src/add-ons/print/drivers/shared/libprint/StatusWindow.cpp @@ -0,0 +1,182 @@ +/* + * Copyright 2005-2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Dr.H.Reh + */ + +#include "StatusWindow.h" +#include +#include +#include +#include +#include +#include + + +#define CANCEL_MSG 'canM' +#define HIDE_MSG 'hidM' + + +StatusWindow::StatusWindow(bool oddPages, bool evenPages, uint32 firstPage, uint32 numPages, uint32 numCopies, uint32 nup) + : BWindow (BRect(200, 200, 650, 270), "Print Status", B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE) +{ + // oddPages - if true, only print odd umbered pages + // evenPages - if true, only print even umbered pages + // firstPage - number of first page + // numPages - total number of pages (must be recalculate if odd/even is used) + // numCopies - total number of document copies + + BRect frame = Frame(); + // the status view + frame.OffsetTo(B_ORIGIN); + fStatusView = new BView(frame,"Status View",B_FOLLOW_ALL, B_WILL_DRAW); + fStatusView->SetViewColor(216,216,216); + AddChild(fStatusView); + + // the status bar + fStatusBar = new BStatusBar(BRect(10, 15, 245, 50),"Status Bar","Page: "); + fStatusView->AddChild(fStatusBar); + + // the cancel button + fHideButton = new BButton(BRect(260, 25, 330,50),"Hide Button","Hide Status", new BMessage(HIDE_MSG)); + fHideButton->ResizeToPreferred(); + fStatusView->AddChild(fHideButton); + + fCancelButton = new BButton(BRect(260, 25, 330,50),"Cancel Button","Cancel", new BMessage(CANCEL_MSG)); + fCancelButton->ResizeToPreferred(); + fCancelButton->MoveBy(90,0); + + fStatusView->AddChild(fCancelButton); + + fCancelBar = false; + + // calculate the real number of pages + fNops = numPages; + + bool evenFirstPage = (firstPage % 2) == 0; + bool evenNumPages = (numPages % 2) == 0; + + // recalculate page numbers if even or odd is used + if (oddPages || evenPages) { + if (evenNumPages) { + fNops = numPages / 2; + } else if (evenFirstPage) { + if (oddPages) + fNops = (numPages - 1) / 2; + if (evenPages) + fNops = (numPages + 1) / 2; + } else { + if (oddPages) + fNops = (numPages + 1) / 2; + if (evenPages) + fNops = (numPages - 1) / 2; + } + } + + uint32 addPage = 0; + if (fNops % nup > 0) + addPage = 1; + fNops = (uint32) ( fNops/(float)nup ) + addPage; + // recalculate page numbers nup-pages-up + + fStatusBar->SetMaxValue ((float)fNops); + // max value of status bar = real number of pages + fDelta = 1.0/numCopies; + // reduce step width of status bar + fStatusDelta = fDelta; + fDocCopies = numCopies; + + fDocumentCopy = fDocCopies > 1; + + fDocCopies++; + + ResetStatusBar(); + Show(); +} + + +StatusWindow::~StatusWindow(void) +{ +} + +void +StatusWindow::ResetStatusBar(void) +{ + Lock(); + fStatusBar->Reset("Page: "); + Unlock(); +} + +bool +StatusWindow::UpdateStatusBar(uint32 page, uint32 copy) +{ + Lock(); + Activate(true); + // Frontmost Window + char buffer[20]; + + sprintf(buffer,"%d", (int)(page + 1)); + BString string1(buffer); + + sprintf(buffer,"%d",(int)fNops ); + BString string2(buffer); + string1.Append(BString(" / ")); + string1.Append(string2); + + BString string3 = BString("Remaining Document Copies: "); + if (fDocumentCopy == true) { + sprintf(buffer, "%d", (int)(fDocCopies)); + BString string4(buffer); + string3.Append(string4); + } else { + string3 = BString("Remaining Page Copies: "); + char buffer[20]; + sprintf(buffer,"%d",(int)(fCopies - copy) ); + BString string4(buffer); + string3.Append(string4); + } + + fStatusBar->Update(fStatusDelta*100.0/fNops, string1.String(), string3.String()); + if ( (fStatusBar->MaxValue()) == (fStatusBar->CurrentValue()) ) + fCancelButton->SetEnabled(false); + Unlock(); + return fCancelBar; +} + +void +StatusWindow::SetPageCopies(uint32 copies) +{ + fCopies = copies; + fStatusDelta = fDelta/(float)fCopies; + fDocCopies--; +} + + +// Handling of user interface and other events +void +StatusWindow::MessageReceived(BMessage *message) +{ + + switch(message->what) { + case CANCEL_MSG: // 'CancelButton' is pressed... + { + fCancelBar = true; + fCancelButton->SetEnabled(false); + fCancelButton->SetLabel("Job cancelled"); + } + break; + + case HIDE_MSG: // 'HideButton' is pressed... + { + Hide(); + } + break; + + default: + inherited::MessageReceived(message); + break; + } + +} diff --git a/src/add-ons/print/drivers/preview/InterfaceUtils.cpp b/src/add-ons/print/drivers/shared/utils/InterfaceUtils.cpp similarity index 96% rename from src/add-ons/print/drivers/preview/InterfaceUtils.cpp rename to src/add-ons/print/drivers/shared/utils/InterfaceUtils.cpp index 1aadbe4ca4..99c6faecd8 100644 --- a/src/add-ons/print/drivers/preview/InterfaceUtils.cpp +++ b/src/add-ons/print/drivers/shared/utils/InterfaceUtils.cpp @@ -74,7 +74,12 @@ HWindow::MessageReceived(BMessage* msg) void HWindow::AboutRequested() { - BAlert *about = new BAlert("About Preview", kAbout, "Cool"); + const char* aboutText = AboutText(); + if (aboutText == NULL) { + return; + } + + BAlert *about = new BAlert("About", aboutText, "Cool"); BTextView *v = about->TextView(); if (v) { rgb_color red = {255, 0, 51, 255}; @@ -123,6 +128,7 @@ BlockingWindow::~BlockingWindow() void BlockingWindow::Init(const char* title) { + fUserQuitResult = B_OK; fResult = NULL; fExitSem = create_sem(0, title); fReadyToQuit = false; @@ -134,7 +140,7 @@ BlockingWindow::QuitRequested() { return true; } else { // user requested to quit the window - *fResult = B_OK; + *fResult = fUserQuitResult; release_sem(fExitSem); return false; } @@ -154,6 +160,11 @@ BlockingWindow::Quit(status_t result) { release_sem(fExitSem); } +void +BlockingWindow::SetUserQuitResult(status_t result) { + fUserQuitResult = result; +} + status_t BlockingWindow::Go() { status_t result = B_ERROR; diff --git a/src/add-ons/print/drivers/shared/utils/Jamfile b/src/add-ons/print/drivers/shared/utils/Jamfile new file mode 100644 index 0000000000..5800091808 --- /dev/null +++ b/src/add-ons/print/drivers/shared/utils/Jamfile @@ -0,0 +1,12 @@ +SubDir HAIKU_TOP src add-ons print drivers shared utils ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ; + +StaticLibrary libprintutils.a : + InterfaceUtils.cpp + MarginView.cpp + Utils.cpp +; + diff --git a/src/add-ons/print/drivers/shared/libprint/MarginView.cpp b/src/add-ons/print/drivers/shared/utils/MarginView.cpp similarity index 99% rename from src/add-ons/print/drivers/shared/libprint/MarginView.cpp rename to src/add-ons/print/drivers/shared/utils/MarginView.cpp index e15940d3f8..fb91f99f45 100644 --- a/src/add-ons/print/drivers/shared/libprint/MarginView.cpp +++ b/src/add-ons/print/drivers/shared/utils/MarginView.cpp @@ -33,9 +33,7 @@ THE SOFTWARE. */ -#ifndef MARGIN_VIEW_H #include "MarginView.h" -#endif #include #include @@ -659,8 +657,10 @@ MarginView::CalculateViewSize(uint32 msg) float fleft = atof(fLeft->Text()) * fUnitValue; // Check that the margins don't overlap each other... - float ph = fPageHeight; - float pw = fPageWidth; + float delta = 72.0; + // minimum printable rect = 1 inch * 1 inch + float ph = fPageHeight-delta; + float pw = fPageWidth-delta; BString str; // Bounds calculation rules: diff --git a/src/add-ons/print/drivers/preview/Utils.cpp b/src/add-ons/print/drivers/shared/utils/Utils.cpp similarity index 62% rename from src/add-ons/print/drivers/preview/Utils.cpp rename to src/add-ons/print/drivers/shared/utils/Utils.cpp index 9117dea48b..6403ae92c5 100644 --- a/src/add-ons/print/drivers/preview/Utils.cpp +++ b/src/add-ons/print/drivers/shared/utils/Utils.cpp @@ -30,9 +30,7 @@ THE SOFTWARE. */ -#include #include "Utils.h" -#include // -------------------------------------------------- EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what) @@ -56,49 +54,6 @@ EscapeMessageFilter::Filter(BMessage *msg, BHandler **target) return B_DISPATCH_MESSAGE; } -// -------------------------------------------------- -// copied from BeUtils.cpp -static bool InList(const char* list[], const char* name) { - for (int i = 0; list[i] != NULL; i ++) { - if (strcmp(list[i], name) == 0) return true; - } - return false; -} - -#include - -// -------------------------------------------------- -// copied from BeUtils.cpp -void AddFields(BMessage* to, const BMessage* from, const char* excludeList[], const char* includeList[]) { - if (to == from) return; - char* name; - type_code type; - int32 count; - for (int32 i = 0; from->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i ++) { - if (excludeList && InList(excludeList, name)) continue; - if (includeList && !InList(includeList, name)) continue; - // replace existing data - to->RemoveName(name); - - const void* data; - ssize_t size; - for (int32 j = 0; j < count; j ++) { - if (from->FindData(name, type, j, &data, &size) == B_OK) { - // WTF why works AddData not for B_STRING_TYPE in R5.0.3? - if (type == B_STRING_TYPE) { - to->AddString(name, (const char*)data); - } else if (type == B_MESSAGE_TYPE) { - BMessage m; - from->FindMessage(name, j, &m); - to->AddMessage(name, &m); - } else { - to->AddData(name, type, data, size); - } - } - } - } -} - void AddString(BMessage* m, const char* name, const char* value) { if (m->HasString(name, 0)) { m->ReplaceString(name, value); @@ -130,11 +85,3 @@ void SetInt32(BMessage* msg, const char* name, int32 value) { msg->AddInt32(name, value); } } - -BRect ScaleRect(BRect rect, float scale) { - rect.left *= scale; - rect.right *= scale; - rect.top *= scale; - rect.bottom *= scale; - return rect; -} diff --git a/src/add-ons/print/shared/Jamfile b/src/add-ons/print/shared/Jamfile index 5928d55c0e..ca0705b545 100644 --- a/src/add-ons/print/shared/Jamfile +++ b/src/add-ons/print/shared/Jamfile @@ -5,7 +5,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ; UsePrivateHeaders interface print ; StaticLibrary - libprint.a + libprintutils.a : PicturePrinter.cpp PrintJobReader.cpp diff --git a/src/add-ons/print/transports/lpr/LprSetupDlg.cpp b/src/add-ons/print/transports/lpr/LprSetupDlg.cpp index 1de893524b..29ba3d4fdd 100644 --- a/src/add-ons/print/transports/lpr/LprSetupDlg.cpp +++ b/src/add-ons/print/transports/lpr/LprSetupDlg.cpp @@ -1,203 +1,205 @@ -// Sun, 18 Jun 2000 -// Y.Takagi - -#include -#include -#include -#include -#include -#include - -#include - -#include "LpsClient.h" -#include "LprSetupDlg.h" -#include "LprDefs.h" -#include "DbgMsg.h" - -#define DLG_WIDTH 370 -#define DLG_HEIGHT 100 - -#define BUTTON_WIDTH 70 -#define BUTTON_HEIGHT 20 - -#define SERVER_H 10 -#define SERVER_V 10 -#define SERVER_WIDTH (DLG_WIDTH - SERVER_H - SERVER_H) -#define SERVER_HEIGHT 20 -#define SERVER_TEXT "Server name" - -#define QUEUE_H 10 -#define QUEUE_V SERVER_V + SERVER_HEIGHT + 2 -#define QUEUE_WIDTH (DLG_WIDTH - QUEUE_H - QUEUE_H) -#define QUEUE_HEIGHT 20 -#define QUEUE_TEXT "Queue name" - -#define OK_H (DLG_WIDTH - BUTTON_WIDTH - 11) -#define OK_V (DLG_HEIGHT - BUTTON_HEIGHT - 11) -#define OK_TEXT "OK" - -#define CANCEL_H (OK_H - BUTTON_WIDTH - 12) -#define CANCEL_V OK_V -#define CANCEL_TEXT "Cancel" - -const BRect SERVER_RECT( - SERVER_H, - SERVER_V, - SERVER_H + SERVER_WIDTH, - SERVER_V + SERVER_HEIGHT); - -const BRect QUEUE_RECT( - QUEUE_H, - QUEUE_V, - QUEUE_H + QUEUE_WIDTH, - QUEUE_V + QUEUE_HEIGHT); - -const BRect OK_RECT( - OK_H, - OK_V, - OK_H + BUTTON_WIDTH, - OK_V + BUTTON_HEIGHT); - -const BRect CANCEL_RECT( - CANCEL_H, - CANCEL_V, - CANCEL_H + BUTTON_WIDTH, - CANCEL_V + BUTTON_HEIGHT); - -enum MSGS { - M_CANCEL = 1, - M_OK -}; - - -class LprSetupView : public BView { -public: - LprSetupView(BRect, BDirectory *); - ~LprSetupView() {} - virtual void AttachedToWindow(); - bool UpdateViewData(); - -private: - BTextControl *server; - BTextControl *queue; - BDirectory *dir; -}; - -LprSetupView::LprSetupView(BRect frame, BDirectory *d) - : BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW), dir(d) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); -} - -void LprSetupView::AttachedToWindow() -{ - float width = max(StringWidth(SERVER_TEXT), StringWidth(QUEUE_TEXT)) + 10; - - /* server name box */ - - server = new BTextControl(SERVER_RECT, "", SERVER_TEXT, "", NULL); - AddChild(server); - server->SetDivider(width); - - /* queue name box */ - - queue = new BTextControl(QUEUE_RECT, "", QUEUE_TEXT, "", NULL); - AddChild(queue); - queue->SetDivider(width); - - /* cancel */ - - BButton *button = new BButton(CANCEL_RECT, "", CANCEL_TEXT, new BMessage(M_CANCEL)); - AddChild(button); - - /* ok */ - - button = new BButton(OK_RECT, "", OK_TEXT, new BMessage(M_OK)); - AddChild(button); - button->MakeDefault(true); -} - -bool LprSetupView::UpdateViewData() -{ - if (*server->Text() && *queue->Text()) { - - try { - LpsClient lpr(server->Text()); - lpr.connect(); - } - - catch (LPSException &err) { - BAlert *alert = new BAlert("", err.what(), "OK"); - alert->Go(); - return false; - } - - dir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, server->Text(), strlen(server->Text()) + 1); - dir->WriteAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, queue->Text(), strlen(queue->Text()) + 1); - return true; - } - - BAlert *alert = new BAlert("", "please input parameters.", "OK"); - alert->Go(); - return false; -} - -LprSetupDlg::LprSetupDlg(BDirectory *dir) - : BWindow(BRect(100, 100, 100 + DLG_WIDTH, 100 + DLG_HEIGHT), - "LPR Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, - B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE) -{ - result = 0; - - Lock(); - LprSetupView *view = new LprSetupView(Bounds(), dir); - AddChild(view); - Unlock(); - - semaphore = create_sem(0, "lprSetupSem"); -} - -bool LprSetupDlg::QuitRequested() -{ - result = B_ERROR; - release_sem(semaphore); - return true; -} - -void LprSetupDlg::MessageReceived(BMessage *msg) -{ - bool success; - - switch (msg->what) { - case M_OK: - Lock(); - success = ((LprSetupView *)ChildAt(0))->UpdateViewData(); - Unlock(); - if (success) { - result = B_NO_ERROR; - release_sem(semaphore); - } - break; - - case M_CANCEL: - result = B_ERROR; - release_sem(semaphore); - break; - - default: - BWindow::MessageReceived(msg); - break; - } -} - -int LprSetupDlg::Go() -{ - Show(); - acquire_sem(semaphore); - delete_sem(semaphore); - int value = result; - Lock(); - Quit(); - return value; -} +// Sun, 18 Jun 2000 +// Y.Takagi + +#include +#include +#include +#include +#include +#include + +#include + +#include "LpsClient.h" +#include "LprSetupDlg.h" +#include "LprDefs.h" +#include "DbgMsg.h" + +#define DLG_WIDTH 370 +#define DLG_HEIGHT 100 + +#define BUTTON_WIDTH 70 +#define BUTTON_HEIGHT 20 + +#define SERVER_H 10 +#define SERVER_V 10 +#define SERVER_WIDTH (DLG_WIDTH - SERVER_H - SERVER_H) +#define SERVER_HEIGHT 20 +#define SERVER_TEXT "Server name" + +#define QUEUE_H 10 +#define QUEUE_V SERVER_V + SERVER_HEIGHT + 2 +#define QUEUE_WIDTH (DLG_WIDTH - QUEUE_H - QUEUE_H) +#define QUEUE_HEIGHT 20 +#define QUEUE_TEXT "Queue name" + +#define OK_H (DLG_WIDTH - BUTTON_WIDTH - 11) +#define OK_V (DLG_HEIGHT - BUTTON_HEIGHT - 11) +#define OK_TEXT "OK" + +#define CANCEL_H (OK_H - BUTTON_WIDTH - 12) +#define CANCEL_V OK_V +#define CANCEL_TEXT "Cancel" + +const BRect SERVER_RECT( + SERVER_H, + SERVER_V, + SERVER_H + SERVER_WIDTH, + SERVER_V + SERVER_HEIGHT); + +const BRect QUEUE_RECT( + QUEUE_H, + QUEUE_V, + QUEUE_H + QUEUE_WIDTH, + QUEUE_V + QUEUE_HEIGHT); + +const BRect OK_RECT( + OK_H, + OK_V, + OK_H + BUTTON_WIDTH, + OK_V + BUTTON_HEIGHT); + +const BRect CANCEL_RECT( + CANCEL_H, + CANCEL_V, + CANCEL_H + BUTTON_WIDTH, + CANCEL_V + BUTTON_HEIGHT); + +enum MSGS { + M_CANCEL = 1, + M_OK +}; + + +class LprSetupView : public BView { +public: + LprSetupView(BRect, BDirectory *); + ~LprSetupView() {} + virtual void AttachedToWindow(); + bool UpdateViewData(); + +private: + BTextControl *server; + BTextControl *queue; + BDirectory *dir; +}; + +LprSetupView::LprSetupView(BRect frame, BDirectory *d) + : BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW), dir(d) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + +void LprSetupView::AttachedToWindow() +{ + float width = max(StringWidth(SERVER_TEXT), StringWidth(QUEUE_TEXT)) + 10; + + /* server name box */ + + // TODO remember previous value + server = new BTextControl(SERVER_RECT, "", SERVER_TEXT, "192.168.0.0", NULL); + AddChild(server); + server->SetDivider(width); + + /* queue name box */ + + // TODO remember previous value + queue = new BTextControl(QUEUE_RECT, "", QUEUE_TEXT, "LPT1_PASSTHRU", NULL); + AddChild(queue); + queue->SetDivider(width); + + /* cancel */ + + BButton *button = new BButton(CANCEL_RECT, "", CANCEL_TEXT, new BMessage(M_CANCEL)); + AddChild(button); + + /* ok */ + + button = new BButton(OK_RECT, "", OK_TEXT, new BMessage(M_OK)); + AddChild(button); + button->MakeDefault(true); +} + +bool LprSetupView::UpdateViewData() +{ + if (*server->Text() && *queue->Text()) { + + try { + LpsClient lpr(server->Text()); + lpr.connect(); + } + + catch (LPSException &err) { + BAlert *alert = new BAlert("", err.what(), "OK"); + alert->Go(); + return false; + } + + dir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, server->Text(), strlen(server->Text()) + 1); + dir->WriteAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, queue->Text(), strlen(queue->Text()) + 1); + return true; + } + + BAlert *alert = new BAlert("", "please input parameters.", "OK"); + alert->Go(); + return false; +} + +LprSetupDlg::LprSetupDlg(BDirectory *dir) + : BWindow(BRect(100, 100, 100 + DLG_WIDTH, 100 + DLG_HEIGHT), + "LPR Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, + B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE) +{ + result = 0; + + Lock(); + LprSetupView *view = new LprSetupView(Bounds(), dir); + AddChild(view); + Unlock(); + + semaphore = create_sem(0, "lprSetupSem"); +} + +bool LprSetupDlg::QuitRequested() +{ + result = B_ERROR; + release_sem(semaphore); + return true; +} + +void LprSetupDlg::MessageReceived(BMessage *msg) +{ + bool success; + + switch (msg->what) { + case M_OK: + Lock(); + success = ((LprSetupView *)ChildAt(0))->UpdateViewData(); + Unlock(); + if (success) { + result = B_NO_ERROR; + release_sem(semaphore); + } + break; + + case M_CANCEL: + result = B_ERROR; + release_sem(semaphore); + break; + + default: + BWindow::MessageReceived(msg); + break; + } +} + +int LprSetupDlg::Go() +{ + Show(); + acquire_sem(semaphore); + delete_sem(semaphore); + int value = result; + Lock(); + Quit(); + return value; +} diff --git a/src/servers/print/Jamfile b/src/servers/print/Jamfile index 57455b506d..f460a0bf44 100644 --- a/src/servers/print/Jamfile +++ b/src/servers/print/Jamfile @@ -33,7 +33,7 @@ LinkAgainst be root translation - libprint.a + libprintutils.a ; Package haiku-printingkit-cvs : diff --git a/src/servers/print/shared/BeUtils.cpp b/src/servers/print/shared/BeUtils.cpp index 08e46694e3..40f0f729d6 100644 --- a/src/servers/print/shared/BeUtils.cpp +++ b/src/servers/print/shared/BeUtils.cpp @@ -101,27 +101,35 @@ static bool InList(const char* list[], const char* name) { return false; } -void AddFields(BMessage* to, const BMessage* from, const char* excludeList[], const char* includeList[]) { +void AddFields(BMessage* to, const BMessage* from, const char* excludeList[], const char* includeList[], bool overwrite) { if (to == from) return; char* name; type_code type; int32 count; for (int32 i = 0; from->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i ++) { + const void* data; + ssize_t size; + if (excludeList && InList(excludeList, name)) continue; if (includeList && !InList(includeList, name)) continue; + + if (!overwrite && to->FindData(name, type, 0, &data, &size) == B_OK) { + continue; + } // replace existing data to->RemoveName(name); - const void* data; - ssize_t size; for (int32 j = 0; j < count; j ++) { if (from->FindData(name, type, j, &data, &size) == B_OK) { - if (type == B_STRING_TYPE) to->AddString(name, (const char*)data); - else if (type == B_MESSAGE_TYPE) { + if (type == B_STRING_TYPE) { + to->AddString(name, (const char*)data); + } else if (type == B_MESSAGE_TYPE) { BMessage m; from->FindMessage(name, j, &m); to->AddMessage(name, &m); - } else to->AddData(name, type, data, size); + } else { + to->AddData(name, type, data, size); + } } } } diff --git a/src/servers/print/shared/Jamfile b/src/servers/print/shared/Jamfile index 879acfe9ed..571949ee91 100644 --- a/src/servers/print/shared/Jamfile +++ b/src/servers/print/shared/Jamfile @@ -5,7 +5,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ; UsePrivateHeaders shared interface print ; StaticLibrary - libprint.a + libprintutils.a : BeUtils.cpp BeUtilsTranslation.cpp