Author: phoudoin Date: 2011-03-21 13:14:37 +0100 (Mon, 21 Mar 2011) New Revision: 41067 Changeset: https://dev.haiku-os.org/changeset/41067 Modified: haiku/trunk/src/preferences/printers/PrintersWindow.cpp haiku/trunk/src/preferences/printers/TestPageView.cpp Log: Moved the whole testpage into its own (offscreen) window, and print from this window's looper. There is two majors bugs raised by the test page feature, which sports both gradiants and vector drawing (leaf, gradiant colors): - radiants are not recorded/handled in BPicture color gradiants presents in the test page - scale is not correctly recorded or handled in BPicture, as seen when zooming on the leaf drawing in Preview window... I will investigate how to fix both. Anyway, an incomplete test page is better than none. Modified: haiku/trunk/src/preferences/printers/PrintersWindow.cpp =================================================================== --- haiku/trunk/src/preferences/printers/PrintersWindow.cpp 2011-03-21 11:39:54 UTC (rev 41066) +++ haiku/trunk/src/preferences/printers/PrintersWindow.cpp 2011-03-21 12:14:37 UTC (rev 41067) @@ -16,6 +16,7 @@ #include <Button.h> #include <Catalog.h> #include <FindDirectory.h> +#include <GroupLayout.h> #include <Layout.h> #include <ListView.h> #include <Locale.h> @@ -36,6 +37,60 @@ #define B_TRANSLATE_CONTEXT "PrintersWindow" +class TestPageWindow : public BWindow { +public: + TestPageWindow(BPrintJob* job, PrinterItem* printer); + virtual ~TestPageWindow(); + + void MessageReceived(BMessage* message); +private: + BPrintJob* fJob; + TestPageView* fTestPage; +}; + + +TestPageWindow::TestPageWindow(BPrintJob* job, PrinterItem* printer) + : BWindow(job->PaperRect().OffsetByCopy(-20000, -20000), B_TRANSLATE("Test Page"), + B_TITLED_WINDOW, 0), fJob(job) +{ + fTestPage = new TestPageView(job->PrintableRect(), printer); + + // SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(fTestPage); +} + + +TestPageWindow::~TestPageWindow() +{ + delete fJob; +} + + +void +TestPageWindow::MessageReceived(BMessage* message) +{ + if (message->what != kMsgPrintTestPage) { + BWindow::MessageReceived(message); + return; + } + + fJob->BeginJob(); + + fJob->DrawView(fTestPage, fTestPage->Bounds(), B_ORIGIN); + fJob->SpoolPage(); + + if (!fJob->CanContinue()) + return; + + fJob->CommitJob(); + + Quit(); +} + + +// #pragma mark PrintersWindow main class + + PrintersWindow::PrintersWindow(BRect frame) : BWindow(BRect(78, 71, 761, 509), B_TRANSLATE_APP_NAME("Printers"), @@ -166,12 +221,12 @@ void PrintersWindow::PrintTestPage(PrinterItem* printer) { - BPrintJob job(B_TRANSLATE("Test Page")); - job.ConfigPage(); + BPrintJob* job = new BPrintJob(B_TRANSLATE("Test Page")); + job->ConfigPage(); - // job.ConfigJob(); + // job->ConfigJob(); - BMessage* settings = job.Settings(); + BMessage* settings = job->Settings(); if (settings == NULL) return; @@ -180,30 +235,9 @@ settings->AddInt32("first_page", 1); settings->AddInt32("last_page", -1); - job.BeginJob(); - - BRect paperRect = job.PaperRect(); - BRect pageRect = job.PrintableRect(); - TestPageView* testPage = new TestPageView(pageRect, printer); - - BWindow* dummyWindow = new BWindow(paperRect.OffsetByCopy(40, 40), - B_TRANSLATE("Test Page"), B_TITLED_WINDOW, 0); - // B_NOT_RESIZABLE | B_NOT_ZOOMABLE); - // dummyWindow->Show(); - dummyWindow->AddChild(testPage); - - if (testPage->LockLooper()) { - job.DrawView(testPage, testPage->Bounds(), B_ORIGIN); - testPage->UnlockLooper(); - } - job.SpoolPage(); - - delete dummyWindow; - - if (!job.CanContinue()) - return; - - job.CommitJob(); + BWindow* win = new TestPageWindow(job, printer); + win->Show(); + win->PostMessage(kMsgPrintTestPage); } Modified: haiku/trunk/src/preferences/printers/TestPageView.cpp =================================================================== --- haiku/trunk/src/preferences/printers/TestPageView.cpp 2011-03-21 11:39:54 UTC (rev 41066) +++ haiku/trunk/src/preferences/printers/TestPageView.cpp 2011-03-21 12:14:37 UTC (rev 41067) @@ -235,8 +235,8 @@ TestPageView::TestPageView(BRect frame, PrinterItem* printer) - : BView(frame, "testpage", /* B_FOLLOW_NONE */ B_FOLLOW_ALL, - B_WILL_DRAW | B_DRAW_ON_CHILDREN | B_FULL_UPDATE_ON_RESIZE), + : BView(frame, "testpage", B_FOLLOW_ALL, + B_DRAW_ON_CHILDREN | B_FULL_UPDATE_ON_RESIZE), fPrinter(printer) { SetViewColor(255, 255, 255); @@ -319,6 +319,8 @@ float size = minDimension * 0.05; + SetPenSize(3.0); + BPoint pt = Bounds().LeftTop(); StrokeLine(pt, BPoint(pt.x + size, pt.y)); StrokeLine(pt, BPoint(pt.x, pt.y + size));