1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Printing Framework classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/printdlg.h>
24 //----------------------------------------------------------------------
27 // Put some wx default wxChar* values into wxStrings.
28 static const wxChar* wxPrintoutTitleStr = wxT("Printout");
29 DECLARE_DEF_STRING(PrintoutTitleStr);
30 static const wxChar* wxPreviewCanvasNameStr = wxT("previewcanvas");
31 DECLARE_DEF_STRING(PreviewCanvasNameStr);
33 DECLARE_DEF_STRING(FrameNameStr);
34 DECLARE_DEF_STRING(PanelNameStr);
35 DECLARE_DEF_STRING(DialogNameStr);
39 //----------------------------------------------------------------------
42 %include my_typemaps.i
44 // Import some definitions of other classes, etc.
53 %pragma(python) code = "import wx"
56 //----------------------------------------------------------------------
60 wxPRINT_MODE_NONE = 0,
61 wxPRINT_MODE_PREVIEW = 1, // Preview in external application
62 wxPRINT_MODE_FILE = 2, // Print to file
63 wxPRINT_MODE_PRINTER = 3 // Send to printer
68 class wxPrintData : public wxObject {
79 const wxString& GetPrinterName();
81 wxDuplexMode GetDuplex();
82 wxPaperSize GetPaperId();
83 const wxSize& GetPaperSize();
85 wxPrintQuality GetQuality();
87 void SetNoCopies(int v);
88 void SetCollate(bool flag);
89 void SetOrientation(int orient);
91 void SetPrinterName(const wxString& name);
92 void SetColour(bool colour);
93 void SetDuplex(wxDuplexMode duplex);
94 void SetPaperId(wxPaperSize sizeId);
95 void SetPaperSize(const wxSize& sz);
96 void SetQuality(wxPrintQuality quality);
98 // PostScript-specific data
99 const wxString& GetPrinterCommand();
100 const wxString& GetPrinterOptions();
101 const wxString& GetPreviewCommand();
102 const wxString& GetFilename();
103 const wxString& GetFontMetricPath();
104 double GetPrinterScaleX();
105 double GetPrinterScaleY();
106 long GetPrinterTranslateX();
107 long GetPrinterTranslateY();
108 wxPrintMode GetPrintMode();
110 void SetPrinterCommand(const wxString& command);
111 void SetPrinterOptions(const wxString& options);
112 void SetPreviewCommand(const wxString& command);
113 void SetFilename(const wxString& filename);
114 void SetFontMetricPath(const wxString& path);
115 void SetPrinterScaleX(double x);
116 void SetPrinterScaleY(double y);
117 void SetPrinterScaling(double x, double y);
118 void SetPrinterTranslateX(long x);
119 void SetPrinterTranslateY(long y);
120 void SetPrinterTranslation(long x, long y);
121 void SetPrintMode(wxPrintMode printMode);
123 %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()"
126 //----------------------------------------------------------------------
129 class wxPrinterDC : public wxDC {
131 wxPrinterDC(const wxPrintData& printData);
132 %name(wxPrinterDC2) wxPrinterDC(const wxString& driver,
133 const wxString& device,
134 const wxString& output,
135 bool interactive = TRUE,
136 int orientation = wxPORTRAIT);
140 //---------------------------------------------------------------------------
142 class wxPostScriptDC : public wxDC {
144 wxPostScriptDC(const wxPrintData& printData);
145 // %name(wxPostScriptDC2)wxPostScriptDC(const wxString& output,
146 // bool interactive = TRUE,
147 // wxWindow* parent = NULL);
149 wxPrintData& GetPrintData();
150 void SetPrintData(const wxPrintData& data);
152 static void SetResolution(int ppi);
153 static int GetResolution();
156 //---------------------------------------------------------------------------
158 class wxPageSetupDialogData : public wxObject {
160 wxPageSetupDialogData();
161 ~wxPageSetupDialogData();
163 void EnableHelp(bool flag);
164 void EnableMargins(bool flag);
165 void EnableOrientation(bool flag);
166 void EnablePaper(bool flag);
167 void EnablePrinter(bool flag);
168 bool GetDefaultMinMargins();
169 bool GetEnableMargins();
170 bool GetEnableOrientation();
171 bool GetEnablePaper();
172 bool GetEnablePrinter();
173 bool GetEnableHelp();
174 bool GetDefaultInfo();
175 wxPoint GetMarginTopLeft();
176 wxPoint GetMarginBottomRight();
177 wxPoint GetMinMarginTopLeft();
178 wxPoint GetMinMarginBottomRight();
179 wxPaperSize GetPaperId();
180 wxSize GetPaperSize();
182 %new wxPrintData* GetPrintData() {
183 return new wxPrintData(self->GetPrintData()); // force a copy
189 void SetDefaultInfo(bool flag);
190 void SetDefaultMinMargins(bool flag);
191 void SetMarginTopLeft(const wxPoint& pt);
192 void SetMarginBottomRight(const wxPoint& pt);
193 void SetMinMarginTopLeft(const wxPoint& pt);
194 void SetMinMarginBottomRight(const wxPoint& pt);
195 void SetPaperId(wxPaperSize id);
196 void SetPaperSize(const wxSize& size);
197 void SetPrintData(const wxPrintData& printData);
199 %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()"
203 class wxPageSetupDialog : public wxDialog {
205 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
207 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
209 wxPageSetupDialogData& GetPageSetupData();
213 //----------------------------------------------------------------------
216 class wxPrintDialogData : public wxObject {
219 ~wxPrintDialogData();
221 int GetFromPage() const;
222 int GetToPage() const;
223 int GetMinPage() const;
224 int GetMaxPage() const;
225 int GetNoCopies() const;
226 bool GetAllPages() const;
227 bool GetSelection() const;
228 bool GetCollate() const;
229 bool GetPrintToFile() const;
230 bool GetSetupDialog() const;
232 void SetFromPage(int v);
233 void SetToPage(int v);
234 void SetMinPage(int v);
235 void SetMaxPage(int v);
236 void SetNoCopies(int v);
237 void SetAllPages(bool flag);
238 void SetSelection(bool flag);
239 void SetCollate(bool flag);
240 void SetPrintToFile(bool flag);
241 void SetSetupDialog(bool flag);
243 void EnablePrintToFile(bool flag);
244 void EnableSelection(bool flag);
245 void EnablePageNumbers(bool flag);
246 void EnableHelp(bool flag);
248 bool GetEnablePrintToFile() const;
249 bool GetEnableSelection() const;
250 bool GetEnablePageNumbers() const;
251 bool GetEnableHelp() const;
253 // Is this data OK for showing the print dialog?
257 %new wxPrintData* GetPrintData() {
258 return new wxPrintData(self->GetPrintData()); // force a copy
261 void SetPrintData(const wxPrintData& printData);
263 %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()"
267 class wxPrintDialog : public wxDialog {
269 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
271 wxPrintDialogData& GetPrintDialogData();
272 %new wxDC* GetPrintDC();
276 //----------------------------------------------------------------------
277 //----------------------------------------------------------------------
278 // Custom wxPrintout class that knows how to call python
282 // Since this one would be tough and ugly to do with the Macros...
283 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
287 wxPyBeginBlockThreads();
288 if ((found = m_myInst.findCallback("GetPageInfo"))) {
289 PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
290 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
293 val = PyTuple_GetItem(result, 0);
294 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
297 val = PyTuple_GetItem(result, 1);
298 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
301 val = PyTuple_GetItem(result, 2);
302 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
305 val = PyTuple_GetItem(result, 3);
306 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
313 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
318 wxPyEndBlockThreads();
320 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
323 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
324 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
328 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
329 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
330 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
331 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
332 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
333 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
334 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
340 // Now define the custom class for SWIGging
341 %name(wxPrintout) class wxPyPrintout : public wxObject {
343 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
345 void _setCallbackInfo(PyObject* self, PyObject* _class);
346 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPrintout)"
349 void Destroy() { delete self; }
353 void GetPageSizeMM(int *OUTPUT, int *OUTPUT);
354 void GetPageSizePixels(int *OUTPUT, int *OUTPUT);
355 void GetPPIPrinter(int *OUTPUT, int *OUTPUT);
356 void GetPPIScreen(int *OUTPUT, int *OUTPUT);
359 bool base_OnBeginDocument(int startPage, int endPage);
360 void base_OnEndDocument();
361 void base_OnBeginPrinting();
362 void base_OnEndPrinting();
363 void base_OnPreparePrinting();
364 void base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
365 bool base_HasPage(int page);
368 //----------------------------------------------------------------------
372 wxPRINTER_NO_ERROR = 0,
378 class wxPrinter : public wxObject {
380 wxPrinter(wxPrintDialogData* data = NULL);
383 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
384 wxPrintDialogData& GetPrintDialogData();
385 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=TRUE);
386 wxDC* PrintDialog(wxWindow *parent);
387 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
388 bool Setup(wxWindow *parent);
391 static wxPrinterError GetLastError();
394 //----------------------------------------------------------------------
396 class wxPrintAbortDialog: public wxDialog
399 wxPrintAbortDialog(wxWindow *parent,
400 const wxString& title,
401 const wxPoint& pos = wxDefaultPosition,
402 const wxSize& size = wxDefaultSize,
404 const wxString& name = wxPyDialogNameStr);
408 //----------------------------------------------------------------------
410 class wxPrintPreview : public wxObject {
412 wxPrintPreview(wxPyPrintout* printout,
413 wxPyPrintout* printoutForPrinting,
414 wxPrintData* data=NULL);
416 virtual bool SetCurrentPage(int pageNum);
417 int GetCurrentPage();
419 void SetPrintout(wxPyPrintout *printout);
420 wxPyPrintout *GetPrintout();
421 wxPyPrintout *GetPrintoutForPrinting();
423 void SetFrame(wxFrame *frame);
424 void SetCanvas(wxPreviewCanvas *canvas);
426 virtual wxFrame *GetFrame();
427 virtual wxPreviewCanvas *GetCanvas();
429 // The preview canvas should call this from OnPaint
430 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
432 // This draws a blank page onto the preview canvas
433 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
435 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
436 virtual bool RenderPage(int pageNum);
438 // Adjusts the scrollbars for the current scale
439 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
441 wxPrintDialogData& GetPrintDialogData();
443 virtual void SetZoom(int percent);
452 virtual bool Print(bool interactive);
453 virtual void DetermineScaling();
455 %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()"
459 class wxPreviewFrame : public wxFrame {
461 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
462 const wxPoint& pos = wxDefaultPosition,
463 const wxSize& size = wxDefaultSize,
464 long style = wxDEFAULT_FRAME_STYLE,
465 const wxString& name = wxPyFrameNameStr);
467 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
470 void CreateControlBar();
473 wxPreviewControlBar* GetControlBar() const;
477 class wxPreviewCanvas: public wxScrolledWindow
480 wxPreviewCanvas(wxPrintPreview *preview,
482 const wxPoint& pos = wxDefaultPosition,
483 const wxSize& size = wxDefaultSize,
485 const wxString& name = wxPyPreviewCanvasNameStr);
486 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
503 wxID_PREVIEW_PREVIOUS,
511 class wxPreviewControlBar: public wxPanel
514 wxPreviewControlBar(wxPrintPreview *preview,
517 const wxPoint& pos = wxDefaultPosition,
518 const wxSize& size = wxDefaultSize,
519 long style = wxTAB_TRAVERSAL,
520 const wxString& name = wxPyPanelNameStr);
521 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
523 int GetZoomControl();
524 void SetZoomControl(int zoom);
525 wxPrintPreview* GetPrintPreview();
535 //----------------------------------------------------------------------
536 // Python-derivable versions of the above preview classes
540 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
541 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
542 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
545 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
546 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
549 wxPyBeginBlockThreads(); \
550 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
551 PyObject* win = wxPyMake_wxObject(a); \
552 PyObject* dc = wxPyMake_wxObject(&b); \
553 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
557 wxPyEndBlockThreads(); \
559 rval = PCLASS::CBNAME(a, b); \
562 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
563 return PCLASS::CBNAME(a, b); \
569 class wxPyPrintPreview : public wxPrintPreview
571 DECLARE_CLASS(wxPyPrintPreview)
573 wxPyPrintPreview(wxPyPrintout* printout,
574 wxPyPrintout* printoutForPrinting,
575 wxPrintData* data=NULL)
576 : wxPrintPreview(printout, printoutForPrinting, data)
579 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
580 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
581 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
582 DEC_PYCALLBACK_BOOL_INT(RenderPage);
583 DEC_PYCALLBACK_VOID_INT(SetZoom);
584 DEC_PYCALLBACK_BOOL_BOOL(Print);
585 DEC_PYCALLBACK_VOID_(DetermineScaling);
590 // Stupid renamed classes... Fix this in 2.5...
591 #if defined(__WXMSW__)
592 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
593 #elif defined(__WXMAC__)
594 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
596 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
599 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
600 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
601 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
602 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
603 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
604 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
605 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
609 class wxPyPrintPreview : public wxPrintPreview
612 wxPyPrintPreview(wxPyPrintout* printout,
613 wxPyPrintout* printoutForPrinting,
614 wxPrintData* data=NULL);
616 void _setCallbackInfo(PyObject* self, PyObject* _class);
617 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyPrintPreview)"
619 bool base_SetCurrentPage(int pageNum);
620 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
621 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
622 bool base_RenderPage(int pageNum);
623 void base_SetZoom(int percent);
624 bool base_Print(bool interactive);
625 void base_DetermineScaling();
632 class wxPyPreviewFrame : public wxPreviewFrame
634 DECLARE_CLASS(wxPyPreviewFrame);
636 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
637 const wxString& title,
638 const wxPoint& pos = wxDefaultPosition,
639 const wxSize& size = wxDefaultSize,
640 long style = wxDEFAULT_FRAME_STYLE,
641 const wxString& name = wxPyFrameNameStr)
642 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
645 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
646 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
648 DEC_PYCALLBACK_VOID_(Initialize);
649 DEC_PYCALLBACK_VOID_(CreateCanvas);
650 DEC_PYCALLBACK_VOID_(CreateControlBar);
655 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
657 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
658 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
659 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
662 class wxPyPreviewFrame : public wxPreviewFrame
665 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
666 const wxString& title,
667 const wxPoint& pos = wxDefaultPosition,
668 const wxSize& size = wxDefaultSize,
669 long style = wxDEFAULT_FRAME_STYLE,
670 const wxString& name = wxPyFrameNameStr);
672 void _setCallbackInfo(PyObject* self, PyObject* _class);
673 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyPreviewFrame)"
674 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
676 void SetPreviewCanvas(wxPreviewCanvas* canvas);
677 void SetControlBar(wxPreviewControlBar* bar);
679 void base_Initialize();
680 void base_CreateCanvas();
681 void base_CreateControlBar();
688 class wxPyPreviewControlBar : public wxPreviewControlBar
690 DECLARE_CLASS(wxPyPreviewControlBar);
692 wxPyPreviewControlBar(wxPrintPreview *preview,
695 const wxPoint& pos = wxDefaultPosition,
696 const wxSize& size = wxDefaultSize,
698 const wxString& name = wxPyPanelNameStr)
699 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
702 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
704 DEC_PYCALLBACK_VOID_(CreateButtons);
705 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
710 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
711 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
712 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
715 class wxPyPreviewControlBar : public wxPreviewControlBar
718 wxPyPreviewControlBar(wxPrintPreview *preview,
721 const wxPoint& pos = wxDefaultPosition,
722 const wxSize& size = wxDefaultSize,
724 const wxString& name = wxPyPanelNameStr);
726 void _setCallbackInfo(PyObject* self, PyObject* _class);
727 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyPreviewControlBar)"
728 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
730 void SetPrintPreview(wxPrintPreview* preview);
732 void base_CreateButtons();
733 void base_SetZoomControl(int zoom);
737 //----------------------------------------------------------------------
740 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
743 //----------------------------------------------------------------------
744 //----------------------------------------------------------------------