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 {
43 %nokwargs wxPrintData;
45 wxPrintData(const wxPrintData& data); // for making copies
55 const wxString& GetPrinterName();
57 wxDuplexMode GetDuplex();
58 wxPaperSize GetPaperId();
59 const wxSize& GetPaperSize();
63 void SetNoCopies(int v);
64 void SetCollate(bool flag);
65 void SetOrientation(int orient);
67 void SetPrinterName(const wxString& name);
68 void SetColour(bool colour);
69 void SetDuplex(wxDuplexMode duplex);
70 void SetPaperId(wxPaperSize sizeId);
71 void SetPaperSize(const wxSize& sz);
72 void SetQuality(int quality);
74 // PostScript-specific data
75 const wxString& GetPrinterCommand();
76 const wxString& GetPrinterOptions();
77 const wxString& GetPreviewCommand();
78 const wxString& GetFilename();
79 const wxString& GetFontMetricPath();
80 double GetPrinterScaleX();
81 double GetPrinterScaleY();
82 long GetPrinterTranslateX();
83 long GetPrinterTranslateY();
84 wxPrintMode GetPrintMode();
86 void SetPrinterCommand(const wxString& command);
87 void SetPrinterOptions(const wxString& options);
88 void SetPreviewCommand(const wxString& command);
89 void SetFilename(const wxString& filename);
90 void SetFontMetricPath(const wxString& path);
91 void SetPrinterScaleX(double x);
92 void SetPrinterScaleY(double y);
93 void SetPrinterScaling(double x, double y);
94 void SetPrinterTranslateX(long x);
95 void SetPrinterTranslateY(long y);
96 void SetPrinterTranslation(long x, long y);
97 void SetPrintMode(wxPrintMode printMode);
99 wxOutputStream* GetOutputStream();
100 void SetOutputStream(wxOutputStream* outputstream);
102 %pythoncode { def __nonzero__(self): return self.Ok() }
105 //---------------------------------------------------------------------------
107 class wxPageSetupDialogData : public wxObject {
109 %nokwargs wxPageSetupDialogData;
110 wxPageSetupDialogData();
111 wxPageSetupDialogData(const wxPageSetupDialogData& data); // for making copies
112 ~wxPageSetupDialogData();
114 void EnableHelp(bool flag);
115 void EnableMargins(bool flag);
116 void EnableOrientation(bool flag);
117 void EnablePaper(bool flag);
118 void EnablePrinter(bool flag);
119 bool GetDefaultMinMargins();
120 bool GetEnableMargins();
121 bool GetEnableOrientation();
122 bool GetEnablePaper();
123 bool GetEnablePrinter();
124 bool GetEnableHelp();
125 bool GetDefaultInfo();
126 wxPoint GetMarginTopLeft();
127 wxPoint GetMarginBottomRight();
128 wxPoint GetMinMarginTopLeft();
129 wxPoint GetMinMarginBottomRight();
130 wxPaperSize GetPaperId();
131 wxSize GetPaperSize();
133 wxPrintData& GetPrintData();
135 // %new wxPrintData* GetPrintData() {
136 // return new wxPrintData(self->GetPrintData()); // force a copy
142 void SetDefaultInfo(bool flag);
143 void SetDefaultMinMargins(bool flag);
144 void SetMarginTopLeft(const wxPoint& pt);
145 void SetMarginBottomRight(const wxPoint& pt);
146 void SetMinMarginTopLeft(const wxPoint& pt);
147 void SetMinMarginBottomRight(const wxPoint& pt);
148 void SetPaperId(wxPaperSize id);
149 void SetPaperSize(const wxSize& size);
150 void SetPrintData(const wxPrintData& printData);
152 %pythoncode { def __nonzero__(self): return self.Ok() }
157 MustHaveApp(wxPageSetupDialog);
159 class wxPageSetupDialog : public wxDialog {
161 %pythonAppend wxPageSetupDialog "self._setOORInfo(self)"
163 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
165 wxPageSetupDialogData& GetPageSetupData();
169 //---------------------------------------------------------------------------
172 class wxPrintDialogData : public wxObject {
174 %nokwargs wxPrintDialogData;
176 wxPrintDialogData(const wxPrintData& printData); // for making copies
177 ~wxPrintDialogData();
179 int GetFromPage() const;
180 int GetToPage() const;
181 int GetMinPage() const;
182 int GetMaxPage() const;
183 int GetNoCopies() const;
184 bool GetAllPages() const;
185 bool GetSelection() const;
186 bool GetCollate() const;
187 bool GetPrintToFile() const;
188 bool GetSetupDialog() const;
190 void SetFromPage(int v);
191 void SetToPage(int v);
192 void SetMinPage(int v);
193 void SetMaxPage(int v);
194 void SetNoCopies(int v);
195 void SetAllPages(bool flag);
196 void SetSelection(bool flag);
197 void SetCollate(bool flag);
198 void SetPrintToFile(bool flag);
199 void SetSetupDialog(bool flag);
201 void EnablePrintToFile(bool flag);
202 void EnableSelection(bool flag);
203 void EnablePageNumbers(bool flag);
204 void EnableHelp(bool flag);
206 bool GetEnablePrintToFile() const;
207 bool GetEnableSelection() const;
208 bool GetEnablePageNumbers() const;
209 bool GetEnableHelp() const;
211 // Is this data OK for showing the print dialog?
215 wxPrintData& GetPrintData();
217 // %new wxPrintData* GetPrintData() {
218 // return new wxPrintData(self->GetPrintData()); // force a copy
221 void SetPrintData(const wxPrintData& printData);
223 %pythoncode { def __nonzero__(self): return self.Ok() }
227 MustHaveApp(wxPrintDialog);
229 class wxPrintDialog : public wxDialog {
231 %pythonAppend wxPrintDialog "self._setOORInfo(self)"
233 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
235 wxPrintDialogData& GetPrintDialogData();
237 %newobject GetPrintDC;
243 //---------------------------------------------------------------------------
244 //---------------------------------------------------------------------------
249 wxPRINTER_NO_ERROR = 0,
255 MustHaveApp(wxPrinter);
257 class wxPrinter : public wxObject {
259 wxPrinter(wxPrintDialogData* data = NULL);
262 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
263 wxPrintDialogData& GetPrintDialogData();
264 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=True);
265 wxDC* PrintDialog(wxWindow *parent);
266 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
267 bool Setup(wxWindow *parent);
270 static wxPrinterError GetLastError();
274 //---------------------------------------------------------------------------
275 // Custom wxPrintout class that knows how to call python
279 // Since this one would be tough and ugly to do with the Macros...
280 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
284 bool blocked = wxPyBeginBlockThreads();
285 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
286 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
287 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
290 val = PyTuple_GetItem(result, 0);
291 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
294 val = PyTuple_GetItem(result, 1);
295 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
298 val = PyTuple_GetItem(result, 2);
299 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
302 val = PyTuple_GetItem(result, 3);
303 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
310 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
315 wxPyEndBlockThreads(blocked);
317 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
320 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
321 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
325 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
326 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
327 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
328 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
329 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
330 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
331 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
337 MustHaveApp(wxPyPrintout);
339 // Now define the custom class for SWIGging
340 %name(Printout) class wxPyPrintout : public wxObject {
342 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
344 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
345 //~wxPyPrintout(); wxPrintPreview object takes ownership...
347 void _setCallbackInfo(PyObject* self, PyObject* _class);
350 wxString GetTitle() const;
352 void SetDC(wxDC *dc);
354 void SetPageSizePixels(int w, int h);
356 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
357 "GetPageSizePixels() -> (w, h)");
359 void SetPageSizeMM(int w, int h);
361 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
362 "GetPageSizeMM() -> (w, h)");
364 void SetPPIScreen(int x, int y);
366 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
367 "GetPPIScreen() -> (x,y)");
369 void SetPPIPrinter(int x, int y);
371 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
372 "GetPPIPrinter() -> (x,y)");
375 void SetIsPreview(bool p);
378 bool base_OnBeginDocument(int startPage, int endPage);
379 void base_OnEndDocument();
380 void base_OnBeginPrinting();
381 void base_OnEndPrinting();
382 void base_OnPreparePrinting();
383 bool base_HasPage(int page);
385 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
386 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
389 //---------------------------------------------------------------------------
393 MustHaveApp(wxPreviewCanvas);
395 class wxPreviewCanvas: public wxScrolledWindow
398 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
400 wxPreviewCanvas(wxPrintPreview *preview,
402 const wxPoint& pos = wxDefaultPosition,
403 const wxSize& size = wxDefaultSize,
405 const wxString& name = wxPyPreviewCanvasNameStr);
409 MustHaveApp(wxPreviewFrame);
411 class wxPreviewFrame : public wxFrame {
413 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
415 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
416 const wxPoint& pos = wxDefaultPosition,
417 const wxSize& size = wxDefaultSize,
418 long style = wxDEFAULT_FRAME_STYLE,
419 const wxString& name = wxPyFrameNameStr);
422 void CreateControlBar();
425 wxPreviewControlBar* GetControlBar() const;
442 wxID_PREVIEW_PREVIOUS,
450 MustHaveApp(wxPreviewControlBar);
452 class wxPreviewControlBar: public wxPanel
455 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
457 wxPreviewControlBar(wxPrintPreview *preview,
460 const wxPoint& pos = wxDefaultPosition,
461 const wxSize& size = wxDefaultSize,
462 long style = wxTAB_TRAVERSAL,
463 const wxString& name = wxPyPanelNameStr);
465 int GetZoomControl();
466 void SetZoomControl(int zoom);
467 wxPrintPreview* GetPrintPreview();
478 //---------------------------------------------------------------------------
480 MustHaveApp(wxPrintPreview);
482 class wxPrintPreview : public wxObject {
484 %nokwargs wxPrintPreview;
485 wxPrintPreview(wxPyPrintout* printout,
486 wxPyPrintout* printoutForPrinting,
487 wxPrintDialogData *data=NULL);
488 wxPrintPreview(wxPyPrintout* printout,
489 wxPyPrintout* printoutForPrinting,
492 virtual bool SetCurrentPage(int pageNum);
493 int GetCurrentPage();
495 void SetPrintout(wxPyPrintout *printout);
496 wxPyPrintout *GetPrintout();
497 wxPyPrintout *GetPrintoutForPrinting();
499 void SetFrame(wxFrame *frame);
500 void SetCanvas(wxPreviewCanvas *canvas);
502 virtual wxFrame *GetFrame();
503 virtual wxPreviewCanvas *GetCanvas();
505 // The preview canvas should call this from OnPaint
506 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
508 // This draws a blank page onto the preview canvas
509 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
511 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
512 virtual bool RenderPage(int pageNum);
514 // Adjusts the scrollbars for the current scale
515 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
517 wxPrintDialogData& GetPrintDialogData();
519 virtual void SetZoom(int percent);
528 virtual bool Print(bool interactive);
529 virtual void DetermineScaling();
531 %pythoncode { def __nonzero__(self): return self.Ok() }
536 //---------------------------------------------------------------------------
538 // Python-derivable versions of the above preview classes
542 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
543 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
544 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
547 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
548 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
551 bool blocked = wxPyBeginBlockThreads(); \
552 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
553 PyObject* win = wxPyMake_wxObject(a); \
554 PyObject* dc = wxPyMake_wxObject(&b); \
555 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
559 wxPyEndBlockThreads(blocked); \
561 rval = PCLASS::CBNAME(a, b); \
564 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
565 return PCLASS::CBNAME(a, b); \
571 class wxPyPrintPreview : public wxPrintPreview
573 DECLARE_CLASS(wxPyPrintPreview)
575 wxPyPrintPreview(wxPyPrintout* printout,
576 wxPyPrintout* printoutForPrinting,
577 wxPrintDialogData* data=NULL)
578 : wxPrintPreview(printout, printoutForPrinting, data)
580 wxPyPrintPreview(wxPyPrintout* printout,
581 wxPyPrintout* printoutForPrinting,
582 wxPrintData* data=NULL)
583 : wxPrintPreview(printout, printoutForPrinting, data)
586 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
587 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
588 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
589 DEC_PYCALLBACK_BOOL_INT(RenderPage);
590 DEC_PYCALLBACK_VOID_INT(SetZoom);
591 DEC_PYCALLBACK_BOOL_BOOL(Print);
592 DEC_PYCALLBACK_VOID_(DetermineScaling);
597 // Stupid renamed classes... Fix this in 2.5...
598 #if defined(__WXMSW__)
599 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
600 #elif defined(__WXMAC__)
601 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
603 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
606 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
607 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
608 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
609 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
610 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
611 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
612 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
616 MustHaveApp(wxPyPrintPreview);
618 class wxPyPrintPreview : public wxPrintPreview
621 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
622 %nokwargs wxPyPrintPreview;
623 wxPyPrintPreview(wxPyPrintout* printout,
624 wxPyPrintout* printoutForPrinting,
625 wxPrintDialogData* data=NULL);
626 wxPyPrintPreview(wxPyPrintout* printout,
627 wxPyPrintout* printoutForPrinting,
630 void _setCallbackInfo(PyObject* self, PyObject* _class);
632 bool base_SetCurrentPage(int pageNum);
633 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
634 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
635 bool base_RenderPage(int pageNum);
636 void base_SetZoom(int percent);
637 bool base_Print(bool interactive);
638 void base_DetermineScaling();
645 class wxPyPreviewFrame : public wxPreviewFrame
647 DECLARE_CLASS(wxPyPreviewFrame);
649 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
650 const wxString& title,
651 const wxPoint& pos = wxDefaultPosition,
652 const wxSize& size = wxDefaultSize,
653 long style = wxDEFAULT_FRAME_STYLE,
654 const wxString& name = wxPyFrameNameStr)
655 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
658 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
659 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
661 DEC_PYCALLBACK_VOID_(Initialize);
662 DEC_PYCALLBACK_VOID_(CreateCanvas);
663 DEC_PYCALLBACK_VOID_(CreateControlBar);
668 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
670 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
671 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
672 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
676 MustHaveApp(wxPyPreviewFrame);
678 class wxPyPreviewFrame : public wxPreviewFrame
681 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
683 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
684 const wxString& title,
685 const wxPoint& pos = wxDefaultPosition,
686 const wxSize& size = wxDefaultSize,
687 long style = wxDEFAULT_FRAME_STYLE,
688 const wxString& name = wxPyFrameNameStr);
690 void _setCallbackInfo(PyObject* self, PyObject* _class);
692 void SetPreviewCanvas(wxPreviewCanvas* canvas);
693 void SetControlBar(wxPreviewControlBar* bar);
695 void base_Initialize();
696 void base_CreateCanvas();
697 void base_CreateControlBar();
704 class wxPyPreviewControlBar : public wxPreviewControlBar
706 DECLARE_CLASS(wxPyPreviewControlBar);
708 wxPyPreviewControlBar(wxPrintPreview *preview,
711 const wxPoint& pos = wxDefaultPosition,
712 const wxSize& size = wxDefaultSize,
714 const wxString& name = wxPyPanelNameStr)
715 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
718 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
720 DEC_PYCALLBACK_VOID_(CreateButtons);
721 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
726 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
727 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
728 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
732 MustHaveApp(wxPyPreviewControlBar);
734 class wxPyPreviewControlBar : public wxPreviewControlBar
737 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
739 wxPyPreviewControlBar(wxPrintPreview *preview,
742 const wxPoint& pos = wxDefaultPosition,
743 const wxSize& size = wxDefaultSize,
745 const wxString& name = wxPyPanelNameStr);
747 void _setCallbackInfo(PyObject* self, PyObject* _class);
749 void SetPrintPreview(wxPrintPreview* preview);
751 void base_CreateButtons();
752 void base_SetZoomControl(int zoom);
756 //---------------------------------------------------------------------------
757 //---------------------------------------------------------------------------
759 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
761 //---------------------------------------------------------------------------