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
53 wxPRINTBIN_LARGECAPACITY,
55 wxPRINTBIN_FORMSOURCE,
61 class wxPrintData : public wxObject {
63 %nokwargs wxPrintData;
65 wxPrintData(const wxPrintData& data); // for making copies
75 const wxString& GetPrinterName();
77 wxDuplexMode GetDuplex();
78 wxPaperSize GetPaperId();
79 const wxSize& GetPaperSize();
84 void SetNoCopies(int v);
85 void SetCollate(bool flag);
86 void SetOrientation(int orient);
88 void SetPrinterName(const wxString& name);
89 void SetColour(bool colour);
90 void SetDuplex(wxDuplexMode duplex);
91 void SetPaperId(wxPaperSize sizeId);
92 void SetPaperSize(const wxSize& sz);
93 void SetQuality(int quality);
94 void SetBin(wxPrintBin bin);
95 // PostScript-specific data
96 const wxString& GetPrinterCommand();
97 const wxString& GetPrinterOptions();
98 const wxString& GetPreviewCommand();
99 const wxString& GetFilename();
100 const wxString& GetFontMetricPath();
101 double GetPrinterScaleX();
102 double GetPrinterScaleY();
103 long GetPrinterTranslateX();
104 long GetPrinterTranslateY();
105 wxPrintMode GetPrintMode();
107 void SetPrinterCommand(const wxString& command);
108 void SetPrinterOptions(const wxString& options);
109 void SetPreviewCommand(const wxString& command);
110 void SetFilename(const wxString& filename);
111 void SetFontMetricPath(const wxString& path);
112 void SetPrinterScaleX(double x);
113 void SetPrinterScaleY(double y);
114 void SetPrinterScaling(double x, double y);
115 void SetPrinterTranslateX(long x);
116 void SetPrinterTranslateY(long y);
117 void SetPrinterTranslation(long x, long y);
118 void SetPrintMode(wxPrintMode printMode);
120 wxOutputStream* GetOutputStream();
121 void SetOutputStream(wxOutputStream* outputstream);
123 %pythoncode { def __nonzero__(self): return self.Ok() }
126 //---------------------------------------------------------------------------
128 class wxPageSetupDialogData : public wxObject {
130 %nokwargs wxPageSetupDialogData;
131 wxPageSetupDialogData();
132 wxPageSetupDialogData(const wxPageSetupDialogData& data); // for making copies
133 ~wxPageSetupDialogData();
135 void EnableHelp(bool flag);
136 void EnableMargins(bool flag);
137 void EnableOrientation(bool flag);
138 void EnablePaper(bool flag);
139 void EnablePrinter(bool flag);
140 bool GetDefaultMinMargins();
141 bool GetEnableMargins();
142 bool GetEnableOrientation();
143 bool GetEnablePaper();
144 bool GetEnablePrinter();
145 bool GetEnableHelp();
146 bool GetDefaultInfo();
147 wxPoint GetMarginTopLeft();
148 wxPoint GetMarginBottomRight();
149 wxPoint GetMinMarginTopLeft();
150 wxPoint GetMinMarginBottomRight();
151 wxPaperSize GetPaperId();
152 wxSize GetPaperSize();
154 wxPrintData& GetPrintData();
156 // %new wxPrintData* GetPrintData() {
157 // return new wxPrintData(self->GetPrintData()); // force a copy
163 void SetDefaultInfo(bool flag);
164 void SetDefaultMinMargins(bool flag);
165 void SetMarginTopLeft(const wxPoint& pt);
166 void SetMarginBottomRight(const wxPoint& pt);
167 void SetMinMarginTopLeft(const wxPoint& pt);
168 void SetMinMarginBottomRight(const wxPoint& pt);
169 void SetPaperId(wxPaperSize id);
170 void SetPaperSize(const wxSize& size);
171 void SetPrintData(const wxPrintData& printData);
173 %pythoncode { def __nonzero__(self): return self.Ok() }
178 MustHaveApp(wxPageSetupDialog);
180 class wxPageSetupDialog : public wxDialog {
182 %pythonAppend wxPageSetupDialog "self._setOORInfo(self)"
184 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
186 wxPageSetupDialogData& GetPageSetupData();
190 //---------------------------------------------------------------------------
193 class wxPrintDialogData : public wxObject {
195 %nokwargs wxPrintDialogData;
197 wxPrintDialogData(const wxPrintData& printData); // for making copies
198 ~wxPrintDialogData();
200 int GetFromPage() const;
201 int GetToPage() const;
202 int GetMinPage() const;
203 int GetMaxPage() const;
204 int GetNoCopies() const;
205 bool GetAllPages() const;
206 bool GetSelection() const;
207 bool GetCollate() const;
208 bool GetPrintToFile() const;
209 bool GetSetupDialog() const;
211 void SetFromPage(int v);
212 void SetToPage(int v);
213 void SetMinPage(int v);
214 void SetMaxPage(int v);
215 void SetNoCopies(int v);
216 void SetAllPages(bool flag);
217 void SetSelection(bool flag);
218 void SetCollate(bool flag);
219 void SetPrintToFile(bool flag);
220 void SetSetupDialog(bool flag);
222 void EnablePrintToFile(bool flag);
223 void EnableSelection(bool flag);
224 void EnablePageNumbers(bool flag);
225 void EnableHelp(bool flag);
227 bool GetEnablePrintToFile() const;
228 bool GetEnableSelection() const;
229 bool GetEnablePageNumbers() const;
230 bool GetEnableHelp() const;
232 // Is this data OK for showing the print dialog?
236 wxPrintData& GetPrintData();
238 // %new wxPrintData* GetPrintData() {
239 // return new wxPrintData(self->GetPrintData()); // force a copy
242 void SetPrintData(const wxPrintData& printData);
244 %pythoncode { def __nonzero__(self): return self.Ok() }
248 MustHaveApp(wxPrintDialog);
250 class wxPrintDialog : public wxDialog {
252 %pythonAppend wxPrintDialog "self._setOORInfo(self)"
254 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
256 wxPrintDialogData& GetPrintDialogData();
258 %newobject GetPrintDC;
264 //---------------------------------------------------------------------------
265 //---------------------------------------------------------------------------
270 wxPRINTER_NO_ERROR = 0,
276 MustHaveApp(wxPrinter);
278 class wxPrinter : public wxObject {
280 wxPrinter(wxPrintDialogData* data = NULL);
283 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
284 wxPrintDialogData& GetPrintDialogData();
285 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=true);
286 wxDC* PrintDialog(wxWindow *parent);
287 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
288 bool Setup(wxWindow *parent);
291 static wxPrinterError GetLastError();
295 //---------------------------------------------------------------------------
296 // Custom wxPrintout class that knows how to call python
300 // Since this one would be tough and ugly to do with the Macros...
301 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
305 bool blocked = wxPyBeginBlockThreads();
306 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
307 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
308 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
311 val = PyTuple_GetItem(result, 0);
312 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
315 val = PyTuple_GetItem(result, 1);
316 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
319 val = PyTuple_GetItem(result, 2);
320 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
323 val = PyTuple_GetItem(result, 3);
324 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
331 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
336 wxPyEndBlockThreads(blocked);
338 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
341 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
342 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
346 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
347 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
348 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
349 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
350 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
351 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
352 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
358 MustHaveApp(wxPyPrintout);
360 // Now define the custom class for SWIGging
361 %name(Printout) class wxPyPrintout : public wxObject {
363 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
365 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
366 //~wxPyPrintout(); wxPrintPreview object takes ownership...
368 void _setCallbackInfo(PyObject* self, PyObject* _class);
371 wxString GetTitle() const;
373 void SetDC(wxDC *dc);
375 void SetPageSizePixels(int w, int h);
377 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
378 "GetPageSizePixels() -> (w, h)");
380 void SetPageSizeMM(int w, int h);
382 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
383 "GetPageSizeMM() -> (w, h)");
385 void SetPPIScreen(int x, int y);
387 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
388 "GetPPIScreen() -> (x,y)");
390 void SetPPIPrinter(int x, int y);
392 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
393 "GetPPIPrinter() -> (x,y)");
396 void SetIsPreview(bool p);
399 bool base_OnBeginDocument(int startPage, int endPage);
400 void base_OnEndDocument();
401 void base_OnBeginPrinting();
402 void base_OnEndPrinting();
403 void base_OnPreparePrinting();
404 bool base_HasPage(int page);
406 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
407 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
410 //---------------------------------------------------------------------------
414 MustHaveApp(wxPreviewCanvas);
416 class wxPreviewCanvas: public wxScrolledWindow
419 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
421 wxPreviewCanvas(wxPrintPreview *preview,
423 const wxPoint& pos = wxDefaultPosition,
424 const wxSize& size = wxDefaultSize,
426 const wxString& name = wxPyPreviewCanvasNameStr);
430 MustHaveApp(wxPreviewFrame);
432 class wxPreviewFrame : public wxFrame {
434 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
436 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
437 const wxPoint& pos = wxDefaultPosition,
438 const wxSize& size = wxDefaultSize,
439 long style = wxDEFAULT_FRAME_STYLE,
440 const wxString& name = wxPyFrameNameStr);
443 void CreateControlBar();
446 wxPreviewControlBar* GetControlBar() const;
463 wxID_PREVIEW_PREVIOUS,
471 MustHaveApp(wxPreviewControlBar);
473 class wxPreviewControlBar: public wxPanel
476 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
478 wxPreviewControlBar(wxPrintPreview *preview,
481 const wxPoint& pos = wxDefaultPosition,
482 const wxSize& size = wxDefaultSize,
483 long style = wxTAB_TRAVERSAL,
484 const wxString& name = wxPyPanelNameStr);
486 int GetZoomControl();
487 void SetZoomControl(int zoom);
488 wxPrintPreview* GetPrintPreview();
499 //---------------------------------------------------------------------------
501 MustHaveApp(wxPrintPreview);
503 class wxPrintPreview : public wxObject {
505 %nokwargs wxPrintPreview;
506 wxPrintPreview(wxPyPrintout* printout,
507 wxPyPrintout* printoutForPrinting,
508 wxPrintDialogData *data=NULL);
509 wxPrintPreview(wxPyPrintout* printout,
510 wxPyPrintout* printoutForPrinting,
513 virtual bool SetCurrentPage(int pageNum);
514 int GetCurrentPage();
516 void SetPrintout(wxPyPrintout *printout);
517 wxPyPrintout *GetPrintout();
518 wxPyPrintout *GetPrintoutForPrinting();
520 void SetFrame(wxFrame *frame);
521 void SetCanvas(wxPreviewCanvas *canvas);
523 virtual wxFrame *GetFrame();
524 virtual wxPreviewCanvas *GetCanvas();
526 // The preview canvas should call this from OnPaint
527 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
529 // This draws a blank page onto the preview canvas
530 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
532 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
533 virtual bool RenderPage(int pageNum);
535 // Adjusts the scrollbars for the current scale
536 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
538 wxPrintDialogData& GetPrintDialogData();
540 virtual void SetZoom(int percent);
549 virtual bool Print(bool interactive);
550 virtual void DetermineScaling();
552 %pythoncode { def __nonzero__(self): return self.Ok() }
557 //---------------------------------------------------------------------------
559 // Python-derivable versions of the above preview classes
563 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
564 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
565 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
568 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
569 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
572 bool blocked = wxPyBeginBlockThreads(); \
573 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
574 PyObject* win = wxPyMake_wxObject(a,false); \
575 PyObject* dc = wxPyMake_wxObject(&b,false); \
576 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc)); \
580 wxPyEndBlockThreads(blocked); \
582 rval = PCLASS::CBNAME(a, b); \
585 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
586 return PCLASS::CBNAME(a, b); \
592 class wxPyPrintPreview : public wxPrintPreview
594 DECLARE_CLASS(wxPyPrintPreview)
596 wxPyPrintPreview(wxPyPrintout* printout,
597 wxPyPrintout* printoutForPrinting,
598 wxPrintDialogData* data=NULL)
599 : wxPrintPreview(printout, printoutForPrinting, data)
601 wxPyPrintPreview(wxPyPrintout* printout,
602 wxPyPrintout* printoutForPrinting,
603 wxPrintData* data=NULL)
604 : wxPrintPreview(printout, printoutForPrinting, data)
607 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
608 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
609 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
610 DEC_PYCALLBACK_BOOL_INT(RenderPage);
611 DEC_PYCALLBACK_VOID_INT(SetZoom);
612 DEC_PYCALLBACK_BOOL_BOOL(Print);
613 DEC_PYCALLBACK_VOID_(DetermineScaling);
618 // Stupid renamed classes... Fix this in 2.5...
619 #if defined(__WXMSW__)
620 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
621 #elif defined(__WXMAC__)
622 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
624 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
627 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
628 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
629 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
630 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
631 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
632 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
633 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
637 MustHaveApp(wxPyPrintPreview);
639 class wxPyPrintPreview : public wxPrintPreview
642 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
643 %nokwargs wxPyPrintPreview;
644 wxPyPrintPreview(wxPyPrintout* printout,
645 wxPyPrintout* printoutForPrinting,
646 wxPrintDialogData* data=NULL);
647 wxPyPrintPreview(wxPyPrintout* printout,
648 wxPyPrintout* printoutForPrinting,
651 void _setCallbackInfo(PyObject* self, PyObject* _class);
653 bool base_SetCurrentPage(int pageNum);
654 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
655 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
656 bool base_RenderPage(int pageNum);
657 void base_SetZoom(int percent);
658 bool base_Print(bool interactive);
659 void base_DetermineScaling();
666 class wxPyPreviewFrame : public wxPreviewFrame
668 DECLARE_CLASS(wxPyPreviewFrame);
670 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
671 const wxString& title,
672 const wxPoint& pos = wxDefaultPosition,
673 const wxSize& size = wxDefaultSize,
674 long style = wxDEFAULT_FRAME_STYLE,
675 const wxString& name = wxPyFrameNameStr)
676 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
679 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
680 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
682 DEC_PYCALLBACK_VOID_(Initialize);
683 DEC_PYCALLBACK_VOID_(CreateCanvas);
684 DEC_PYCALLBACK_VOID_(CreateControlBar);
689 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
691 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
692 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
693 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
697 MustHaveApp(wxPyPreviewFrame);
699 class wxPyPreviewFrame : public wxPreviewFrame
702 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
704 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
705 const wxString& title,
706 const wxPoint& pos = wxDefaultPosition,
707 const wxSize& size = wxDefaultSize,
708 long style = wxDEFAULT_FRAME_STYLE,
709 const wxString& name = wxPyFrameNameStr);
711 void _setCallbackInfo(PyObject* self, PyObject* _class);
713 void SetPreviewCanvas(wxPreviewCanvas* canvas);
714 void SetControlBar(wxPreviewControlBar* bar);
716 void base_Initialize();
717 void base_CreateCanvas();
718 void base_CreateControlBar();
725 class wxPyPreviewControlBar : public wxPreviewControlBar
727 DECLARE_CLASS(wxPyPreviewControlBar);
729 wxPyPreviewControlBar(wxPrintPreview *preview,
732 const wxPoint& pos = wxDefaultPosition,
733 const wxSize& size = wxDefaultSize,
735 const wxString& name = wxPyPanelNameStr)
736 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
739 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
741 DEC_PYCALLBACK_VOID_(CreateButtons);
742 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
747 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
748 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
749 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
753 MustHaveApp(wxPyPreviewControlBar);
755 class wxPyPreviewControlBar : public wxPreviewControlBar
758 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
760 wxPyPreviewControlBar(wxPrintPreview *preview,
763 const wxPoint& pos = wxDefaultPosition,
764 const wxSize& size = wxDefaultSize,
766 const wxString& name = wxPyPanelNameStr);
768 void _setCallbackInfo(PyObject* self, PyObject* _class);
770 void SetPrintPreview(wxPrintPreview* preview);
772 void base_CreateButtons();
773 void base_SetZoomControl(int zoom);
777 //---------------------------------------------------------------------------
778 //---------------------------------------------------------------------------
780 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
782 //---------------------------------------------------------------------------