From 86d4ce73ad545b4e1c375be0c598b6d2cd09fe40 Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 28 Oct 2009 19:02:39 +0000 Subject: [PATCH] Report: ChoosePrinter, ChooseDefaultPrinter - selects printer before rendering report, renders to chosen paper size git-svn-id: svn://ultimatepp.org/upp/trunk@1668 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/CtrlUtil.h | 1 + uppsrc/DocTypes/ShowReport.cpp | 6 +++--- uppsrc/Report/Report.cpp | 23 +++++++++++++++++++++++ uppsrc/Report/Report.h | 19 ++++++++++++------- uppsrc/Report/ReportDlg.cpp | 10 +++++++--- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/uppsrc/CtrlLib/CtrlUtil.h b/uppsrc/CtrlLib/CtrlUtil.h index d6ea30ede..f75971eea 100644 --- a/uppsrc/CtrlLib/CtrlUtil.h +++ b/uppsrc/CtrlLib/CtrlUtil.h @@ -71,6 +71,7 @@ public: PrinterJob& MinMaxPage(int minpage, int maxpage); PrinterJob& PageCount(int n) { return MinMaxPage(0, n - 1); } PrinterJob& CurrentPage(int currentpage); + PrinterJob& Name(const char *_name) { name = _name; return *this; } PrinterJob(const char *name = NULL); ~PrinterJob(); diff --git a/uppsrc/DocTypes/ShowReport.cpp b/uppsrc/DocTypes/ShowReport.cpp index da33b49bb..65c0f5a56 100644 --- a/uppsrc/DocTypes/ShowReport.cpp +++ b/uppsrc/DocTypes/ShowReport.cpp @@ -301,9 +301,9 @@ bool DocReport::Print0(int i, const char *_name) { dlg.nFromPage = dlg.nMinPage; dlg.nToPage = dlg.nMaxPage; } - Size sz = w.GetPageMMs(); - int x = (6000 * sz.cx / 254 - pgsz.cx) / 2; - int y = (6000 * sz.cy / 254 - pgsz.cy) / 2; + Size sz = w.GetPageSize(); + int x = (sz.cx - pgsz.cx) / 2; + int y = (sz.cy - pgsz.cy) / 2; for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1); c++) for(i = dlg.nFromPage - 1; i <= dlg.nToPage - 1; i++) for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies); c++) { diff --git a/uppsrc/Report/Report.cpp b/uppsrc/Report/Report.cpp index 64ae7e377..054db37ce 100644 --- a/uppsrc/Report/Report.cpp +++ b/uppsrc/Report/Report.cpp @@ -163,4 +163,27 @@ void Report::Put(const char *qtf) Put(ParseQTF(qtf)); } +bool Report::ChoosePrinter(const char *jobname) +{ + printerjob.Create(); + printerjob->Name(jobname); + if(!printerjob->Execute()) { + printerjob.Clear(); + return false; + } + SetPageSize(printerjob->GetDraw().GetPageSize()); + return true; +} + +bool Report::ChooseDefaultPrinter(const char *jobname) +{ + printerjob.Create(); + printerjob->Name(jobname); + Size sz = printerjob->GetDraw().GetPageSize(); + if(sz.cx == 0 || sz.cy == 0) + return false; + SetPageSize(sz); + return true; +} + END_UPP_NAMESPACE diff --git a/uppsrc/Report/Report.h b/uppsrc/Report/Report.h index 17af7af6c..3e215f43e 100644 --- a/uppsrc/Report/Report.h +++ b/uppsrc/Report/Report.h @@ -14,12 +14,13 @@ public: virtual Draw& Page(int i); private: - Array page; - int pagei; - int y; - String header, footer; - int headercy, headerspc, footercy, footerspc; - Point mg; + Array page; + int pagei; + int y; + String header, footer; + int headercy, headerspc, footercy, footerspc; + Point mg; + One printerjob; void Flush(); String FormatHF(const char *s, int pageno); @@ -27,7 +28,7 @@ private: void PaintHF(Draw& w, int y, const char *qtf, int i); void StartPage(int i); void RestartPage(); - + public: int GetCount() { Flush(); return page.GetCount(); } Drawing GetPage(int i) { Flush(); return page[i]; } @@ -52,6 +53,10 @@ public: Point GetMargins() const { return mg; } + bool ChoosePrinter(const char *jobname = t_("Report")); + bool ChooseDefaultPrinter(const char *jobname = t_("Report")); + PrinterJob *GetPrinterJob() { return ~printerjob; } + Report& SetPageSize(Size sz); Report& SetPageSize(int cx, int cy) { return SetPageSize(Size(cx, cy)); } Report& Landscape(); diff --git a/uppsrc/Report/ReportDlg.cpp b/uppsrc/Report/ReportDlg.cpp index 28b0c597a..5714c1255 100644 --- a/uppsrc/Report/ReportDlg.cpp +++ b/uppsrc/Report/ReportDlg.cpp @@ -7,14 +7,14 @@ NAMESPACE_UPP void Print(Report& r, PrinterJob& pd, bool center) { Draw& w = pd; - Size sz = w.GetPageMMs(); + Size sz = w.GetPageSize(); Point mg = r.GetMargins(); Size pgsz = r.GetPage(0).GetSize(); int x = 0; int y = 0; if(center) { - x = Nvl(mg.x, (6000 * sz.cx / 254 - pgsz.cx) / 2); - y = Nvl(mg.y, (6000 * sz.cy / 254 - pgsz.cy) / 2); + x = Nvl(mg.x, (sz.cx - pgsz.cx) / 2); + y = Nvl(mg.y, (sz.cy - pgsz.cy) / 2); } for(int i = 0; i < pd.GetPageCount(); i++) { Drawing iw = r.GetPage(pd[i]); @@ -26,6 +26,10 @@ void Print(Report& r, PrinterJob& pd, bool center) } bool Print0(Report& r, int i, const char *_name, bool dodlg) { + if(r.GetPrinterJob()) { + Print(r, *r.GetPrinterJob()); + return true; + } PrinterJob pd(_name); pd.CurrentPage(i); pd.MinMaxPage(0, r.GetCount() - 1);