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 class wxPageSetupDialog : public wxDialog {
154 %pythonAppend wxPageSetupDialog "self._setOORInfo(self)"
156 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
158 wxPageSetupDialogData& GetPageSetupData();
162 //---------------------------------------------------------------------------
165 class wxPrintDialogData : public wxObject {
167 %nokwargs wxPrintDialogData;
169 wxPrintDialogData(const wxPrintData& printData);
170 ~wxPrintDialogData();
172 int GetFromPage() const;
173 int GetToPage() const;
174 int GetMinPage() const;
175 int GetMaxPage() const;
176 int GetNoCopies() const;
177 bool GetAllPages() const;
178 bool GetSelection() const;
179 bool GetCollate() const;
180 bool GetPrintToFile() const;
181 bool GetSetupDialog() const;
183 void SetFromPage(int v);
184 void SetToPage(int v);
185 void SetMinPage(int v);
186 void SetMaxPage(int v);
187 void SetNoCopies(int v);
188 void SetAllPages(bool flag);
189 void SetSelection(bool flag);
190 void SetCollate(bool flag);
191 void SetPrintToFile(bool flag);
192 void SetSetupDialog(bool flag);
194 void EnablePrintToFile(bool flag);
195 void EnableSelection(bool flag);
196 void EnablePageNumbers(bool flag);
197 void EnableHelp(bool flag);
199 bool GetEnablePrintToFile() const;
200 bool GetEnableSelection() const;
201 bool GetEnablePageNumbers() const;
202 bool GetEnableHelp() const;
204 // Is this data OK for showing the print dialog?
208 wxPrintData& GetPrintData();
210 // %new wxPrintData* GetPrintData() {
211 // return new wxPrintData(self->GetPrintData()); // force a copy
214 void SetPrintData(const wxPrintData& printData);
216 %pythoncode { def __nonzero__(self): return self.Ok() }
220 class wxPrintDialog : public wxDialog {
222 %pythonAppend wxPrintDialog "self._setOORInfo(self)"
224 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
226 wxPrintDialogData& GetPrintDialogData();
228 %newobject GetPrintDC;
234 //---------------------------------------------------------------------------
235 //---------------------------------------------------------------------------
240 wxPRINTER_NO_ERROR = 0,
246 class wxPrinter : public wxObject {
248 wxPrinter(wxPrintDialogData* data = NULL);
251 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
252 wxPrintDialogData& GetPrintDialogData();
253 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=True);
254 wxDC* PrintDialog(wxWindow *parent);
255 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
256 bool Setup(wxWindow *parent);
259 static wxPrinterError GetLastError();
263 //---------------------------------------------------------------------------
264 // Custom wxPrintout class that knows how to call python
268 // Since this one would be tough and ugly to do with the Macros...
269 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
273 bool blocked = wxPyBeginBlockThreads();
274 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
275 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
276 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
279 val = PyTuple_GetItem(result, 0);
280 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
283 val = PyTuple_GetItem(result, 1);
284 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
287 val = PyTuple_GetItem(result, 2);
288 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
291 val = PyTuple_GetItem(result, 3);
292 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
299 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
304 wxPyEndBlockThreads(blocked);
306 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
309 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
310 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
314 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
315 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
316 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
317 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
318 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
319 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
320 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
326 // Now define the custom class for SWIGging
327 %name(Printout) class wxPyPrintout : public wxObject {
329 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
331 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
332 //~wxPyPrintout(); wxPrintPreview object takes ownership...
334 void _setCallbackInfo(PyObject* self, PyObject* _class);
337 wxString GetTitle() const;
339 void SetDC(wxDC *dc);
341 void SetPageSizePixels(int w, int h);
343 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
344 "GetPageSizePixels() -> (w, h)");
346 void SetPageSizeMM(int w, int h);
348 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
349 "GetPageSizeMM() -> (w, h)");
351 void SetPPIScreen(int x, int y);
353 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
354 "GetPPIScreen() -> (x,y)");
356 void SetPPIPrinter(int x, int y);
358 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
359 "GetPPIPrinter() -> (x,y)");
362 void SetIsPreview(bool p);
365 bool base_OnBeginDocument(int startPage, int endPage);
366 void base_OnEndDocument();
367 void base_OnBeginPrinting();
368 void base_OnEndPrinting();
369 void base_OnPreparePrinting();
370 bool base_HasPage(int page);
372 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
373 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
376 //---------------------------------------------------------------------------
380 class wxPreviewCanvas: public wxScrolledWindow
383 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
385 wxPreviewCanvas(wxPrintPreview *preview,
387 const wxPoint& pos = wxDefaultPosition,
388 const wxSize& size = wxDefaultSize,
390 const wxString& name = wxPyPreviewCanvasNameStr);
394 class wxPreviewFrame : public wxFrame {
396 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
398 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
399 const wxPoint& pos = wxDefaultPosition,
400 const wxSize& size = wxDefaultSize,
401 long style = wxDEFAULT_FRAME_STYLE,
402 const wxString& name = wxPyFrameNameStr);
405 void CreateControlBar();
408 wxPreviewControlBar* GetControlBar() const;
425 wxID_PREVIEW_PREVIOUS,
433 class wxPreviewControlBar: public wxPanel
436 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
438 wxPreviewControlBar(wxPrintPreview *preview,
441 const wxPoint& pos = wxDefaultPosition,
442 const wxSize& size = wxDefaultSize,
443 long style = wxTAB_TRAVERSAL,
444 const wxString& name = wxPyPanelNameStr);
446 int GetZoomControl();
447 void SetZoomControl(int zoom);
448 wxPrintPreview* GetPrintPreview();
459 //---------------------------------------------------------------------------
461 class wxPrintPreview : public wxObject {
463 %nokwargs wxPrintPreview;
464 wxPrintPreview(wxPyPrintout* printout,
465 wxPyPrintout* printoutForPrinting,
466 wxPrintDialogData *data=NULL);
467 wxPrintPreview(wxPyPrintout* printout,
468 wxPyPrintout* printoutForPrinting,
471 virtual bool SetCurrentPage(int pageNum);
472 int GetCurrentPage();
474 void SetPrintout(wxPyPrintout *printout);
475 wxPyPrintout *GetPrintout();
476 wxPyPrintout *GetPrintoutForPrinting();
478 void SetFrame(wxFrame *frame);
479 void SetCanvas(wxPreviewCanvas *canvas);
481 virtual wxFrame *GetFrame();
482 virtual wxPreviewCanvas *GetCanvas();
484 // The preview canvas should call this from OnPaint
485 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
487 // This draws a blank page onto the preview canvas
488 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
490 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
491 virtual bool RenderPage(int pageNum);
493 // Adjusts the scrollbars for the current scale
494 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
496 wxPrintDialogData& GetPrintDialogData();
498 virtual void SetZoom(int percent);
507 virtual bool Print(bool interactive);
508 virtual void DetermineScaling();
510 %pythoncode { def __nonzero__(self): return self.Ok() }
515 //---------------------------------------------------------------------------
517 // Python-derivable versions of the above preview classes
521 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
522 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
523 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
526 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
527 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
530 bool blocked = wxPyBeginBlockThreads(); \
531 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
532 PyObject* win = wxPyMake_wxObject(a); \
533 PyObject* dc = wxPyMake_wxObject(&b); \
534 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
538 wxPyEndBlockThreads(blocked); \
540 rval = PCLASS::CBNAME(a, b); \
543 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
544 return PCLASS::CBNAME(a, b); \
550 class wxPyPrintPreview : public wxPrintPreview
552 DECLARE_CLASS(wxPyPrintPreview)
554 wxPyPrintPreview(wxPyPrintout* printout,
555 wxPyPrintout* printoutForPrinting,
556 wxPrintDialogData* data=NULL)
557 : wxPrintPreview(printout, printoutForPrinting, data)
559 wxPyPrintPreview(wxPyPrintout* printout,
560 wxPyPrintout* printoutForPrinting,
561 wxPrintData* data=NULL)
562 : wxPrintPreview(printout, printoutForPrinting, data)
565 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
566 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
567 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
568 DEC_PYCALLBACK_BOOL_INT(RenderPage);
569 DEC_PYCALLBACK_VOID_INT(SetZoom);
570 DEC_PYCALLBACK_BOOL_BOOL(Print);
571 DEC_PYCALLBACK_VOID_(DetermineScaling);
576 // Stupid renamed classes... Fix this in 2.5...
577 #if defined(__WXMSW__)
578 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
579 #elif defined(__WXMAC__)
580 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
582 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
585 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
586 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
587 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
588 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
589 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
590 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
591 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
595 class wxPyPrintPreview : public wxPrintPreview
598 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
599 %nokwargs wxPyPrintPreview;
600 wxPyPrintPreview(wxPyPrintout* printout,
601 wxPyPrintout* printoutForPrinting,
602 wxPrintDialogData* data=NULL);
603 wxPyPrintPreview(wxPyPrintout* printout,
604 wxPyPrintout* printoutForPrinting,
607 void _setCallbackInfo(PyObject* self, PyObject* _class);
609 bool base_SetCurrentPage(int pageNum);
610 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
611 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
612 bool base_RenderPage(int pageNum);
613 void base_SetZoom(int percent);
614 bool base_Print(bool interactive);
615 void base_DetermineScaling();
622 class wxPyPreviewFrame : public wxPreviewFrame
624 DECLARE_CLASS(wxPyPreviewFrame);
626 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
627 const wxString& title,
628 const wxPoint& pos = wxDefaultPosition,
629 const wxSize& size = wxDefaultSize,
630 long style = wxDEFAULT_FRAME_STYLE,
631 const wxString& name = wxPyFrameNameStr)
632 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
635 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
636 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
638 DEC_PYCALLBACK_VOID_(Initialize);
639 DEC_PYCALLBACK_VOID_(CreateCanvas);
640 DEC_PYCALLBACK_VOID_(CreateControlBar);
645 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
647 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
648 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
649 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
653 class wxPyPreviewFrame : public wxPreviewFrame
656 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
658 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
659 const wxString& title,
660 const wxPoint& pos = wxDefaultPosition,
661 const wxSize& size = wxDefaultSize,
662 long style = wxDEFAULT_FRAME_STYLE,
663 const wxString& name = wxPyFrameNameStr);
665 void _setCallbackInfo(PyObject* self, PyObject* _class);
667 void SetPreviewCanvas(wxPreviewCanvas* canvas);
668 void SetControlBar(wxPreviewControlBar* bar);
670 void base_Initialize();
671 void base_CreateCanvas();
672 void base_CreateControlBar();
679 class wxPyPreviewControlBar : public wxPreviewControlBar
681 DECLARE_CLASS(wxPyPreviewControlBar);
683 wxPyPreviewControlBar(wxPrintPreview *preview,
686 const wxPoint& pos = wxDefaultPosition,
687 const wxSize& size = wxDefaultSize,
689 const wxString& name = wxPyPanelNameStr)
690 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
693 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
695 DEC_PYCALLBACK_VOID_(CreateButtons);
696 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
701 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
702 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
703 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
707 class wxPyPreviewControlBar : public wxPreviewControlBar
710 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
712 wxPyPreviewControlBar(wxPrintPreview *preview,
715 const wxPoint& pos = wxDefaultPosition,
716 const wxSize& size = wxDefaultSize,
718 const wxString& name = wxPyPanelNameStr);
720 void _setCallbackInfo(PyObject* self, PyObject* _class);
722 void SetPrintPreview(wxPrintPreview* preview);
724 void base_CreateButtons();
725 void base_SetZoomControl(int zoom);
729 //---------------------------------------------------------------------------
730 //---------------------------------------------------------------------------
732 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
734 //---------------------------------------------------------------------------