1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wx????
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
20 #include "wx/wxPython/printfw.h"
24 MAKE_CONST_WXSTRING2(PrintoutTitleStr, wxT("Printout"));
25 MAKE_CONST_WXSTRING2(PreviewCanvasNameStr, wxT("previewcanvas"));
28 //---------------------------------------------------------------------------
32 wxPRINT_MODE_NONE = 0,
33 wxPRINT_MODE_PREVIEW = 1, // Preview in external application
34 wxPRINT_MODE_FILE = 2, // Print to file
35 wxPRINT_MODE_PRINTER = 3, // Send to printer
36 wxPRINT_MODE_STREAM = 4 // Send postscript data into a stream
41 class wxPrintData : public wxObject {
52 const wxString& GetPrinterName();
54 wxDuplexMode GetDuplex();
55 wxPaperSize GetPaperId();
56 const wxSize& GetPaperSize();
60 void SetNoCopies(int v);
61 void SetCollate(bool flag);
62 void SetOrientation(int orient);
64 void SetPrinterName(const wxString& name);
65 void SetColour(bool colour);
66 void SetDuplex(wxDuplexMode duplex);
67 void SetPaperId(wxPaperSize sizeId);
68 void SetPaperSize(const wxSize& sz);
69 void SetQuality(int quality);
71 // PostScript-specific data
72 const wxString& GetPrinterCommand();
73 const wxString& GetPrinterOptions();
74 const wxString& GetPreviewCommand();
75 const wxString& GetFilename();
76 const wxString& GetFontMetricPath();
77 double GetPrinterScaleX();
78 double GetPrinterScaleY();
79 long GetPrinterTranslateX();
80 long GetPrinterTranslateY();
81 wxPrintMode GetPrintMode();
83 void SetPrinterCommand(const wxString& command);
84 void SetPrinterOptions(const wxString& options);
85 void SetPreviewCommand(const wxString& command);
86 void SetFilename(const wxString& filename);
87 void SetFontMetricPath(const wxString& path);
88 void SetPrinterScaleX(double x);
89 void SetPrinterScaleY(double y);
90 void SetPrinterScaling(double x, double y);
91 void SetPrinterTranslateX(long x);
92 void SetPrinterTranslateY(long y);
93 void SetPrinterTranslation(long x, long y);
94 void SetPrintMode(wxPrintMode printMode);
96 wxOutputStream* GetOutputStream();
97 void SetOutputStream(wxOutputStream* outputstream);
99 %pythoncode { def __nonzero__(self): return self.Ok() }
102 //---------------------------------------------------------------------------
104 class wxPageSetupDialogData : public wxObject {
106 wxPageSetupDialogData();
107 ~wxPageSetupDialogData();
109 void EnableHelp(bool flag);
110 void EnableMargins(bool flag);
111 void EnableOrientation(bool flag);
112 void EnablePaper(bool flag);
113 void EnablePrinter(bool flag);
114 bool GetDefaultMinMargins();
115 bool GetEnableMargins();
116 bool GetEnableOrientation();
117 bool GetEnablePaper();
118 bool GetEnablePrinter();
119 bool GetEnableHelp();
120 bool GetDefaultInfo();
121 wxPoint GetMarginTopLeft();
122 wxPoint GetMarginBottomRight();
123 wxPoint GetMinMarginTopLeft();
124 wxPoint GetMinMarginBottomRight();
125 wxPaperSize GetPaperId();
126 wxSize GetPaperSize();
128 wxPrintData& GetPrintData();
130 // %new wxPrintData* GetPrintData() {
131 // return new wxPrintData(self->GetPrintData()); // force a copy
137 void SetDefaultInfo(bool flag);
138 void SetDefaultMinMargins(bool flag);
139 void SetMarginTopLeft(const wxPoint& pt);
140 void SetMarginBottomRight(const wxPoint& pt);
141 void SetMinMarginTopLeft(const wxPoint& pt);
142 void SetMinMarginBottomRight(const wxPoint& pt);
143 void SetPaperId(wxPaperSize id);
144 void SetPaperSize(const wxSize& size);
145 void SetPrintData(const wxPrintData& printData);
147 %pythoncode { def __nonzero__(self): return self.Ok() }
152 MustHaveApp(wxPageSetupDialog);
154 class wxPageSetupDialog : public wxDialog {
156 %pythonAppend wxPageSetupDialog "self._setOORInfo(self)"
158 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
160 wxPageSetupDialogData& GetPageSetupData();
164 //---------------------------------------------------------------------------
167 class wxPrintDialogData : public wxObject {
169 %nokwargs wxPrintDialogData;
171 wxPrintDialogData(const wxPrintData& printData);
172 ~wxPrintDialogData();
174 int GetFromPage() const;
175 int GetToPage() const;
176 int GetMinPage() const;
177 int GetMaxPage() const;
178 int GetNoCopies() const;
179 bool GetAllPages() const;
180 bool GetSelection() const;
181 bool GetCollate() const;
182 bool GetPrintToFile() const;
183 bool GetSetupDialog() const;
185 void SetFromPage(int v);
186 void SetToPage(int v);
187 void SetMinPage(int v);
188 void SetMaxPage(int v);
189 void SetNoCopies(int v);
190 void SetAllPages(bool flag);
191 void SetSelection(bool flag);
192 void SetCollate(bool flag);
193 void SetPrintToFile(bool flag);
194 void SetSetupDialog(bool flag);
196 void EnablePrintToFile(bool flag);
197 void EnableSelection(bool flag);
198 void EnablePageNumbers(bool flag);
199 void EnableHelp(bool flag);
201 bool GetEnablePrintToFile() const;
202 bool GetEnableSelection() const;
203 bool GetEnablePageNumbers() const;
204 bool GetEnableHelp() const;
206 // Is this data OK for showing the print dialog?
210 wxPrintData& GetPrintData();
212 // %new wxPrintData* GetPrintData() {
213 // return new wxPrintData(self->GetPrintData()); // force a copy
216 void SetPrintData(const wxPrintData& printData);
218 %pythoncode { def __nonzero__(self): return self.Ok() }
222 MustHaveApp(wxPrintDialog);
224 class wxPrintDialog : public wxDialog {
226 %pythonAppend wxPrintDialog "self._setOORInfo(self)"
228 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
230 wxPrintDialogData& GetPrintDialogData();
232 %newobject GetPrintDC;
238 //---------------------------------------------------------------------------
239 //---------------------------------------------------------------------------
244 wxPRINTER_NO_ERROR = 0,
250 MustHaveApp(wxPrinter);
252 class wxPrinter : public wxObject {
254 wxPrinter(wxPrintDialogData* data = NULL);
257 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
258 wxPrintDialogData& GetPrintDialogData();
259 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=True);
260 wxDC* PrintDialog(wxWindow *parent);
261 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
262 bool Setup(wxWindow *parent);
265 static wxPrinterError GetLastError();
269 //---------------------------------------------------------------------------
270 // Custom wxPrintout class that knows how to call python
274 // Since this one would be tough and ugly to do with the Macros...
275 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
279 bool blocked = wxPyBeginBlockThreads();
280 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
281 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
282 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
285 val = PyTuple_GetItem(result, 0);
286 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
289 val = PyTuple_GetItem(result, 1);
290 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
293 val = PyTuple_GetItem(result, 2);
294 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
297 val = PyTuple_GetItem(result, 3);
298 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
305 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
310 wxPyEndBlockThreads(blocked);
312 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
315 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
316 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
320 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
321 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
322 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
323 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
324 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
325 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
326 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
332 MustHaveApp(wxPyPrintout);
334 // Now define the custom class for SWIGging
335 %name(Printout) class wxPyPrintout : public wxObject {
337 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
339 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
340 //~wxPyPrintout(); wxPrintPreview object takes ownership...
342 void _setCallbackInfo(PyObject* self, PyObject* _class);
345 wxString GetTitle() const;
347 void SetDC(wxDC *dc);
349 void SetPageSizePixels(int w, int h);
351 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
352 "GetPageSizePixels() -> (w, h)");
354 void SetPageSizeMM(int w, int h);
356 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
357 "GetPageSizeMM() -> (w, h)");
359 void SetPPIScreen(int x, int y);
361 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
362 "GetPPIScreen() -> (x,y)");
364 void SetPPIPrinter(int x, int y);
366 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
367 "GetPPIPrinter() -> (x,y)");
370 void SetIsPreview(bool p);
373 bool base_OnBeginDocument(int startPage, int endPage);
374 void base_OnEndDocument();
375 void base_OnBeginPrinting();
376 void base_OnEndPrinting();
377 void base_OnPreparePrinting();
378 bool base_HasPage(int page);
380 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
381 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
384 //---------------------------------------------------------------------------
388 MustHaveApp(wxPreviewCanvas);
390 class wxPreviewCanvas: public wxScrolledWindow
393 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
395 wxPreviewCanvas(wxPrintPreview *preview,
397 const wxPoint& pos = wxDefaultPosition,
398 const wxSize& size = wxDefaultSize,
400 const wxString& name = wxPyPreviewCanvasNameStr);
404 MustHaveApp(wxPreviewFrame);
406 class wxPreviewFrame : public wxFrame {
408 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
410 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
411 const wxPoint& pos = wxDefaultPosition,
412 const wxSize& size = wxDefaultSize,
413 long style = wxDEFAULT_FRAME_STYLE,
414 const wxString& name = wxPyFrameNameStr);
417 void CreateControlBar();
420 wxPreviewControlBar* GetControlBar() const;
437 wxID_PREVIEW_PREVIOUS,
445 MustHaveApp(wxPreviewControlBar);
447 class wxPreviewControlBar: public wxPanel
450 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
452 wxPreviewControlBar(wxPrintPreview *preview,
455 const wxPoint& pos = wxDefaultPosition,
456 const wxSize& size = wxDefaultSize,
457 long style = wxTAB_TRAVERSAL,
458 const wxString& name = wxPyPanelNameStr);
460 int GetZoomControl();
461 void SetZoomControl(int zoom);
462 wxPrintPreview* GetPrintPreview();
473 //---------------------------------------------------------------------------
475 MustHaveApp(wxPrintPreview);
477 class wxPrintPreview : public wxObject {
479 %nokwargs wxPrintPreview;
480 wxPrintPreview(wxPyPrintout* printout,
481 wxPyPrintout* printoutForPrinting,
482 wxPrintDialogData *data=NULL);
483 wxPrintPreview(wxPyPrintout* printout,
484 wxPyPrintout* printoutForPrinting,
487 virtual bool SetCurrentPage(int pageNum);
488 int GetCurrentPage();
490 void SetPrintout(wxPyPrintout *printout);
491 wxPyPrintout *GetPrintout();
492 wxPyPrintout *GetPrintoutForPrinting();
494 void SetFrame(wxFrame *frame);
495 void SetCanvas(wxPreviewCanvas *canvas);
497 virtual wxFrame *GetFrame();
498 virtual wxPreviewCanvas *GetCanvas();
500 // The preview canvas should call this from OnPaint
501 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
503 // This draws a blank page onto the preview canvas
504 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
506 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
507 virtual bool RenderPage(int pageNum);
509 // Adjusts the scrollbars for the current scale
510 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
512 wxPrintDialogData& GetPrintDialogData();
514 virtual void SetZoom(int percent);
523 virtual bool Print(bool interactive);
524 virtual void DetermineScaling();
526 %pythoncode { def __nonzero__(self): return self.Ok() }
531 //---------------------------------------------------------------------------
533 // Python-derivable versions of the above preview classes
537 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
538 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
539 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
542 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
543 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
546 bool blocked = wxPyBeginBlockThreads(); \
547 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
548 PyObject* win = wxPyMake_wxObject(a); \
549 PyObject* dc = wxPyMake_wxObject(&b); \
550 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
554 wxPyEndBlockThreads(blocked); \
556 rval = PCLASS::CBNAME(a, b); \
559 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
560 return PCLASS::CBNAME(a, b); \
566 class wxPyPrintPreview : public wxPrintPreview
568 DECLARE_CLASS(wxPyPrintPreview)
570 wxPyPrintPreview(wxPyPrintout* printout,
571 wxPyPrintout* printoutForPrinting,
572 wxPrintDialogData* data=NULL)
573 : wxPrintPreview(printout, printoutForPrinting, data)
575 wxPyPrintPreview(wxPyPrintout* printout,
576 wxPyPrintout* printoutForPrinting,
577 wxPrintData* data=NULL)
578 : wxPrintPreview(printout, printoutForPrinting, data)
581 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
582 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
583 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
584 DEC_PYCALLBACK_BOOL_INT(RenderPage);
585 DEC_PYCALLBACK_VOID_INT(SetZoom);
586 DEC_PYCALLBACK_BOOL_BOOL(Print);
587 DEC_PYCALLBACK_VOID_(DetermineScaling);
592 // Stupid renamed classes... Fix this in 2.5...
593 #if defined(__WXMSW__)
594 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
595 #elif defined(__WXMAC__)
596 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
598 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
601 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
602 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
603 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
604 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
605 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
606 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
607 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
611 MustHaveApp(wxPyPrintPreview);
613 class wxPyPrintPreview : public wxPrintPreview
616 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
617 %nokwargs wxPyPrintPreview;
618 wxPyPrintPreview(wxPyPrintout* printout,
619 wxPyPrintout* printoutForPrinting,
620 wxPrintDialogData* data=NULL);
621 wxPyPrintPreview(wxPyPrintout* printout,
622 wxPyPrintout* printoutForPrinting,
625 void _setCallbackInfo(PyObject* self, PyObject* _class);
627 bool base_SetCurrentPage(int pageNum);
628 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
629 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
630 bool base_RenderPage(int pageNum);
631 void base_SetZoom(int percent);
632 bool base_Print(bool interactive);
633 void base_DetermineScaling();
640 class wxPyPreviewFrame : public wxPreviewFrame
642 DECLARE_CLASS(wxPyPreviewFrame);
644 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
645 const wxString& title,
646 const wxPoint& pos = wxDefaultPosition,
647 const wxSize& size = wxDefaultSize,
648 long style = wxDEFAULT_FRAME_STYLE,
649 const wxString& name = wxPyFrameNameStr)
650 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
653 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
654 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
656 DEC_PYCALLBACK_VOID_(Initialize);
657 DEC_PYCALLBACK_VOID_(CreateCanvas);
658 DEC_PYCALLBACK_VOID_(CreateControlBar);
663 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
665 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
666 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
667 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
671 MustHaveApp(wxPyPreviewFrame);
673 class wxPyPreviewFrame : public wxPreviewFrame
676 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
678 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
679 const wxString& title,
680 const wxPoint& pos = wxDefaultPosition,
681 const wxSize& size = wxDefaultSize,
682 long style = wxDEFAULT_FRAME_STYLE,
683 const wxString& name = wxPyFrameNameStr);
685 void _setCallbackInfo(PyObject* self, PyObject* _class);
687 void SetPreviewCanvas(wxPreviewCanvas* canvas);
688 void SetControlBar(wxPreviewControlBar* bar);
690 void base_Initialize();
691 void base_CreateCanvas();
692 void base_CreateControlBar();
699 class wxPyPreviewControlBar : public wxPreviewControlBar
701 DECLARE_CLASS(wxPyPreviewControlBar);
703 wxPyPreviewControlBar(wxPrintPreview *preview,
706 const wxPoint& pos = wxDefaultPosition,
707 const wxSize& size = wxDefaultSize,
709 const wxString& name = wxPyPanelNameStr)
710 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
713 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
715 DEC_PYCALLBACK_VOID_(CreateButtons);
716 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
721 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
722 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
723 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
727 MustHaveApp(wxPyPreviewControlBar);
729 class wxPyPreviewControlBar : public wxPreviewControlBar
732 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
734 wxPyPreviewControlBar(wxPrintPreview *preview,
737 const wxPoint& pos = wxDefaultPosition,
738 const wxSize& size = wxDefaultSize,
740 const wxString& name = wxPyPanelNameStr);
742 void _setCallbackInfo(PyObject* self, PyObject* _class);
744 void SetPrintPreview(wxPrintPreview* preview);
746 void base_CreateButtons();
747 void base_SetZoomControl(int zoom);
751 //---------------------------------------------------------------------------
752 //---------------------------------------------------------------------------
754 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
756 //---------------------------------------------------------------------------