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"
22 static const wxChar* wxPrintoutTitleStr = wxT("Printout");
23 DECLARE_DEF_STRING(PrintoutTitleStr);
24 static const wxChar* wxPreviewCanvasNameStr = wxT("previewcanvas");
25 DECLARE_DEF_STRING(PreviewCanvasNameStr);
30 //---------------------------------------------------------------------------
34 wxPRINT_MODE_NONE = 0,
35 wxPRINT_MODE_PREVIEW = 1, // Preview in external application
36 wxPRINT_MODE_FILE = 2, // Print to file
37 wxPRINT_MODE_PRINTER = 3 // Send to printer
42 class wxPrintData : public wxObject {
53 const wxString& GetPrinterName();
55 wxDuplexMode GetDuplex();
56 wxPaperSize GetPaperId();
57 const wxSize& GetPaperSize();
59 wxPrintQuality GetQuality();
61 void SetNoCopies(int v);
62 void SetCollate(bool flag);
63 void SetOrientation(int orient);
65 void SetPrinterName(const wxString& name);
66 void SetColour(bool colour);
67 void SetDuplex(wxDuplexMode duplex);
68 void SetPaperId(wxPaperSize sizeId);
69 void SetPaperSize(const wxSize& sz);
70 void SetQuality(wxPrintQuality quality);
72 // PostScript-specific data
73 const wxString& GetPrinterCommand();
74 const wxString& GetPrinterOptions();
75 const wxString& GetPreviewCommand();
76 const wxString& GetFilename();
77 const wxString& GetFontMetricPath();
78 double GetPrinterScaleX();
79 double GetPrinterScaleY();
80 long GetPrinterTranslateX();
81 long GetPrinterTranslateY();
82 wxPrintMode GetPrintMode();
84 void SetPrinterCommand(const wxString& command);
85 void SetPrinterOptions(const wxString& options);
86 void SetPreviewCommand(const wxString& command);
87 void SetFilename(const wxString& filename);
88 void SetFontMetricPath(const wxString& path);
89 void SetPrinterScaleX(double x);
90 void SetPrinterScaleY(double y);
91 void SetPrinterScaling(double x, double y);
92 void SetPrinterTranslateX(long x);
93 void SetPrinterTranslateY(long y);
94 void SetPrinterTranslation(long x, long y);
95 void SetPrintMode(wxPrintMode printMode);
97 %pythoncode { def __nonzero__(self): return self.Ok() }
100 //---------------------------------------------------------------------------
102 class wxPageSetupDialogData : public wxObject {
104 wxPageSetupDialogData();
105 ~wxPageSetupDialogData();
107 void EnableHelp(bool flag);
108 void EnableMargins(bool flag);
109 void EnableOrientation(bool flag);
110 void EnablePaper(bool flag);
111 void EnablePrinter(bool flag);
112 bool GetDefaultMinMargins();
113 bool GetEnableMargins();
114 bool GetEnableOrientation();
115 bool GetEnablePaper();
116 bool GetEnablePrinter();
117 bool GetEnableHelp();
118 bool GetDefaultInfo();
119 wxPoint GetMarginTopLeft();
120 wxPoint GetMarginBottomRight();
121 wxPoint GetMinMarginTopLeft();
122 wxPoint GetMinMarginBottomRight();
123 wxPaperSize GetPaperId();
124 wxSize GetPaperSize();
126 wxPrintData& GetPrintData();
128 // %new wxPrintData* GetPrintData() {
129 // return new wxPrintData(self->GetPrintData()); // force a copy
135 void SetDefaultInfo(bool flag);
136 void SetDefaultMinMargins(bool flag);
137 void SetMarginTopLeft(const wxPoint& pt);
138 void SetMarginBottomRight(const wxPoint& pt);
139 void SetMinMarginTopLeft(const wxPoint& pt);
140 void SetMinMarginBottomRight(const wxPoint& pt);
141 void SetPaperId(wxPaperSize id);
142 void SetPaperSize(const wxSize& size);
143 void SetPrintData(const wxPrintData& printData);
145 %pythoncode { def __nonzero__(self): return self.Ok() }
150 class wxPageSetupDialog : public wxDialog {
152 %addtofunc wxPageSetupDialog "self._setOORInfo(self)"
154 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
156 wxPageSetupDialogData& GetPageSetupData();
160 //---------------------------------------------------------------------------
163 class wxPrintDialogData : public wxObject {
166 ~wxPrintDialogData();
168 int GetFromPage() const;
169 int GetToPage() const;
170 int GetMinPage() const;
171 int GetMaxPage() const;
172 int GetNoCopies() const;
173 bool GetAllPages() const;
174 bool GetSelection() const;
175 bool GetCollate() const;
176 bool GetPrintToFile() const;
177 bool GetSetupDialog() const;
179 void SetFromPage(int v);
180 void SetToPage(int v);
181 void SetMinPage(int v);
182 void SetMaxPage(int v);
183 void SetNoCopies(int v);
184 void SetAllPages(bool flag);
185 void SetSelection(bool flag);
186 void SetCollate(bool flag);
187 void SetPrintToFile(bool flag);
188 void SetSetupDialog(bool flag);
190 void EnablePrintToFile(bool flag);
191 void EnableSelection(bool flag);
192 void EnablePageNumbers(bool flag);
193 void EnableHelp(bool flag);
195 bool GetEnablePrintToFile() const;
196 bool GetEnableSelection() const;
197 bool GetEnablePageNumbers() const;
198 bool GetEnableHelp() const;
200 // Is this data OK for showing the print dialog?
204 wxPrintData& GetPrintData();
206 // %new wxPrintData* GetPrintData() {
207 // return new wxPrintData(self->GetPrintData()); // force a copy
210 void SetPrintData(const wxPrintData& printData);
212 %pythoncode { def __nonzero__(self): return self.Ok() }
216 class wxPrintDialog : public wxDialog {
218 %addtofunc wxPrintDialog "self._setOORInfo(self)"
220 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
222 wxPrintDialogData& GetPrintDialogData();
224 %newobject GetPrintDC;
230 //---------------------------------------------------------------------------
231 //---------------------------------------------------------------------------
236 wxPRINTER_NO_ERROR = 0,
242 class wxPrinter : public wxObject {
244 wxPrinter(wxPrintDialogData* data = NULL);
247 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
248 wxPrintDialogData& GetPrintDialogData();
249 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=True);
250 wxDC* PrintDialog(wxWindow *parent);
251 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
252 bool Setup(wxWindow *parent);
255 static wxPrinterError GetLastError();
259 //---------------------------------------------------------------------------
260 // Custom wxPrintout class that knows how to call python
264 // Since this one would be tough and ugly to do with the Macros...
265 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
269 wxPyBeginBlockThreads();
270 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
271 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
272 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
275 val = PyTuple_GetItem(result, 0);
276 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
279 val = PyTuple_GetItem(result, 1);
280 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
283 val = PyTuple_GetItem(result, 2);
284 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
287 val = PyTuple_GetItem(result, 3);
288 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
295 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
300 wxPyEndBlockThreads();
302 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
305 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
306 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
310 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
311 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
312 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
313 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
314 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
315 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
316 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
322 // Now define the custom class for SWIGging
323 %name(Printout) class wxPyPrintout : public wxObject {
325 %addtofunc wxPyPrintout "self._setCallbackInfo(self, Printout)"
327 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
328 //~wxPyPrintout(); wxPrintPreview object takes ownership...
330 void _setCallbackInfo(PyObject* self, PyObject* _class);
333 wxString GetTitle() const;
335 void SetDC(wxDC *dc);
337 void SetPageSizePixels(int w, int h);
339 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
340 "GetPageSizePixels() -> (w, h)");
342 void SetPageSizeMM(int w, int h);
344 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
345 "GetPageSizeMM() -> (w, h)");
347 void SetPPIScreen(int x, int y);
349 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
350 "GetPPIScreen() -> (x,y)");
352 void SetPPIPrinter(int x, int y);
354 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
355 "GetPPIPrinter() -> (x,y)");
358 void SetIsPreview(bool p);
361 bool base_OnBeginDocument(int startPage, int endPage);
362 void base_OnEndDocument();
363 void base_OnBeginPrinting();
364 void base_OnEndPrinting();
365 void base_OnPreparePrinting();
366 bool base_HasPage(int page);
368 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
369 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
372 //---------------------------------------------------------------------------
376 class wxPreviewCanvas: public wxScrolledWindow
379 %addtofunc wxPreviewCanvas "self._setOORInfo(self)"
381 wxPreviewCanvas(wxPrintPreview *preview,
383 const wxPoint& pos = wxDefaultPosition,
384 const wxSize& size = wxDefaultSize,
386 const wxString& name = wxPyPreviewCanvasNameStr);
390 class wxPreviewFrame : public wxFrame {
392 %addtofunc wxPreviewFrame "self._setOORInfo(self)"
394 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
395 const wxPoint& pos = wxDefaultPosition,
396 const wxSize& size = wxDefaultSize,
397 long style = wxDEFAULT_FRAME_STYLE,
398 const wxString& name = wxPyFrameNameStr);
401 void CreateControlBar();
404 wxPreviewControlBar* GetControlBar() const;
421 wxID_PREVIEW_PREVIOUS,
429 class wxPreviewControlBar: public wxPanel
432 %addtofunc wxPreviewControlBar "self._setOORInfo(self)"
434 wxPreviewControlBar(wxPrintPreview *preview,
437 const wxPoint& pos = wxDefaultPosition,
438 const wxSize& size = wxDefaultSize,
439 long style = wxTAB_TRAVERSAL,
440 const wxString& name = wxPyPanelNameStr);
442 int GetZoomControl();
443 void SetZoomControl(int zoom);
444 wxPrintPreview* GetPrintPreview();
455 //---------------------------------------------------------------------------
457 class wxPrintPreview : public wxObject {
459 wxPrintPreview(wxPyPrintout* printout,
460 wxPyPrintout* printoutForPrinting,
461 wxPrintData* data=NULL);
463 virtual bool SetCurrentPage(int pageNum);
464 int GetCurrentPage();
466 void SetPrintout(wxPyPrintout *printout);
467 wxPyPrintout *GetPrintout();
468 wxPyPrintout *GetPrintoutForPrinting();
470 void SetFrame(wxFrame *frame);
471 void SetCanvas(wxPreviewCanvas *canvas);
473 virtual wxFrame *GetFrame();
474 virtual wxPreviewCanvas *GetCanvas();
476 // The preview canvas should call this from OnPaint
477 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
479 // This draws a blank page onto the preview canvas
480 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
482 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
483 virtual bool RenderPage(int pageNum);
485 // Adjusts the scrollbars for the current scale
486 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
488 wxPrintDialogData& GetPrintDialogData();
490 virtual void SetZoom(int percent);
499 virtual bool Print(bool interactive);
500 virtual void DetermineScaling();
502 %pythoncode { def __nonzero__(self): return self.Ok() }
507 //---------------------------------------------------------------------------
509 // Python-derivable versions of the above preview classes
513 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
514 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
515 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
518 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
519 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
522 wxPyBeginBlockThreads(); \
523 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
524 PyObject* win = wxPyMake_wxObject(a); \
525 PyObject* dc = wxPyMake_wxObject(&b); \
526 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
530 wxPyEndBlockThreads(); \
532 rval = PCLASS::CBNAME(a, b); \
535 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
536 return PCLASS::CBNAME(a, b); \
542 class wxPyPrintPreview : public wxPrintPreview
544 DECLARE_CLASS(wxPyPrintPreview)
546 wxPyPrintPreview(wxPyPrintout* printout,
547 wxPyPrintout* printoutForPrinting,
548 wxPrintData* data=NULL)
549 : wxPrintPreview(printout, printoutForPrinting, data)
552 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
553 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
554 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
555 DEC_PYCALLBACK_BOOL_INT(RenderPage);
556 DEC_PYCALLBACK_VOID_INT(SetZoom);
557 DEC_PYCALLBACK_BOOL_BOOL(Print);
558 DEC_PYCALLBACK_VOID_(DetermineScaling);
563 // Stupid renamed classes... Fix this in 2.5...
564 #if defined(__WXMSW__)
565 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
566 #elif defined(__WXMAC__)
567 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
569 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
572 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
573 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
574 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
575 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
576 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
577 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
578 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
582 class wxPyPrintPreview : public wxPrintPreview
585 %addtofunc wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
587 wxPyPrintPreview(wxPyPrintout* printout,
588 wxPyPrintout* printoutForPrinting,
589 wxPrintData* data=NULL);
591 void _setCallbackInfo(PyObject* self, PyObject* _class);
593 bool base_SetCurrentPage(int pageNum);
594 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
595 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
596 bool base_RenderPage(int pageNum);
597 void base_SetZoom(int percent);
598 bool base_Print(bool interactive);
599 void base_DetermineScaling();
606 class wxPyPreviewFrame : public wxPreviewFrame
608 DECLARE_CLASS(wxPyPreviewFrame);
610 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
611 const wxString& title,
612 const wxPoint& pos = wxDefaultPosition,
613 const wxSize& size = wxDefaultSize,
614 long style = wxDEFAULT_FRAME_STYLE,
615 const wxString& name = wxPyFrameNameStr)
616 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
619 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
620 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
622 DEC_PYCALLBACK_VOID_(Initialize);
623 DEC_PYCALLBACK_VOID_(CreateCanvas);
624 DEC_PYCALLBACK_VOID_(CreateControlBar);
629 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
631 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
632 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
633 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
637 class wxPyPreviewFrame : public wxPreviewFrame
640 %addtofunc wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
642 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
643 const wxString& title,
644 const wxPoint& pos = wxDefaultPosition,
645 const wxSize& size = wxDefaultSize,
646 long style = wxDEFAULT_FRAME_STYLE,
647 const wxString& name = wxPyFrameNameStr);
649 void _setCallbackInfo(PyObject* self, PyObject* _class);
651 void SetPreviewCanvas(wxPreviewCanvas* canvas);
652 void SetControlBar(wxPreviewControlBar* bar);
654 void base_Initialize();
655 void base_CreateCanvas();
656 void base_CreateControlBar();
663 class wxPyPreviewControlBar : public wxPreviewControlBar
665 DECLARE_CLASS(wxPyPreviewControlBar);
667 wxPyPreviewControlBar(wxPrintPreview *preview,
670 const wxPoint& pos = wxDefaultPosition,
671 const wxSize& size = wxDefaultSize,
673 const wxString& name = wxPyPanelNameStr)
674 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
677 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
679 DEC_PYCALLBACK_VOID_(CreateButtons);
680 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
685 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
686 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
687 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
691 class wxPyPreviewControlBar : public wxPreviewControlBar
694 %addtofunc wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
696 wxPyPreviewControlBar(wxPrintPreview *preview,
699 const wxPoint& pos = wxDefaultPosition,
700 const wxSize& size = wxDefaultSize,
702 const wxString& name = wxPyPanelNameStr);
704 void _setCallbackInfo(PyObject* self, PyObject* _class);
706 void SetPrintPreview(wxPrintPreview* preview);
708 void base_CreateButtons();
709 void base_SetZoomControl(int zoom);
713 //---------------------------------------------------------------------------
714 //---------------------------------------------------------------------------
716 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
718 //---------------------------------------------------------------------------