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
40 class wxPrintData : public wxObject {
51 const wxString& GetPrinterName();
53 wxDuplexMode GetDuplex();
54 wxPaperSize GetPaperId();
55 const wxSize& GetPaperSize();
59 void SetNoCopies(int v);
60 void SetCollate(bool flag);
61 void SetOrientation(int orient);
63 void SetPrinterName(const wxString& name);
64 void SetColour(bool colour);
65 void SetDuplex(wxDuplexMode duplex);
66 void SetPaperId(wxPaperSize sizeId);
67 void SetPaperSize(const wxSize& sz);
68 void SetQuality(int quality);
70 // PostScript-specific data
71 const wxString& GetPrinterCommand();
72 const wxString& GetPrinterOptions();
73 const wxString& GetPreviewCommand();
74 const wxString& GetFilename();
75 const wxString& GetFontMetricPath();
76 double GetPrinterScaleX();
77 double GetPrinterScaleY();
78 long GetPrinterTranslateX();
79 long GetPrinterTranslateY();
80 wxPrintMode GetPrintMode();
82 void SetPrinterCommand(const wxString& command);
83 void SetPrinterOptions(const wxString& options);
84 void SetPreviewCommand(const wxString& command);
85 void SetFilename(const wxString& filename);
86 void SetFontMetricPath(const wxString& path);
87 void SetPrinterScaleX(double x);
88 void SetPrinterScaleY(double y);
89 void SetPrinterScaling(double x, double y);
90 void SetPrinterTranslateX(long x);
91 void SetPrinterTranslateY(long y);
92 void SetPrinterTranslation(long x, long y);
93 void SetPrintMode(wxPrintMode printMode);
95 %pythoncode { def __nonzero__(self): return self.Ok() }
98 //---------------------------------------------------------------------------
100 class wxPageSetupDialogData : public wxObject {
102 wxPageSetupDialogData();
103 ~wxPageSetupDialogData();
105 void EnableHelp(bool flag);
106 void EnableMargins(bool flag);
107 void EnableOrientation(bool flag);
108 void EnablePaper(bool flag);
109 void EnablePrinter(bool flag);
110 bool GetDefaultMinMargins();
111 bool GetEnableMargins();
112 bool GetEnableOrientation();
113 bool GetEnablePaper();
114 bool GetEnablePrinter();
115 bool GetEnableHelp();
116 bool GetDefaultInfo();
117 wxPoint GetMarginTopLeft();
118 wxPoint GetMarginBottomRight();
119 wxPoint GetMinMarginTopLeft();
120 wxPoint GetMinMarginBottomRight();
121 wxPaperSize GetPaperId();
122 wxSize GetPaperSize();
124 wxPrintData& GetPrintData();
126 // %new wxPrintData* GetPrintData() {
127 // return new wxPrintData(self->GetPrintData()); // force a copy
133 void SetDefaultInfo(bool flag);
134 void SetDefaultMinMargins(bool flag);
135 void SetMarginTopLeft(const wxPoint& pt);
136 void SetMarginBottomRight(const wxPoint& pt);
137 void SetMinMarginTopLeft(const wxPoint& pt);
138 void SetMinMarginBottomRight(const wxPoint& pt);
139 void SetPaperId(wxPaperSize id);
140 void SetPaperSize(const wxSize& size);
141 void SetPrintData(const wxPrintData& printData);
143 %pythoncode { def __nonzero__(self): return self.Ok() }
148 class wxPageSetupDialog : public wxDialog {
150 %pythonAppend wxPageSetupDialog "self._setOORInfo(self)"
152 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
154 wxPageSetupDialogData& GetPageSetupData();
158 //---------------------------------------------------------------------------
161 class wxPrintDialogData : public wxObject {
164 ~wxPrintDialogData();
166 int GetFromPage() const;
167 int GetToPage() const;
168 int GetMinPage() const;
169 int GetMaxPage() const;
170 int GetNoCopies() const;
171 bool GetAllPages() const;
172 bool GetSelection() const;
173 bool GetCollate() const;
174 bool GetPrintToFile() const;
175 bool GetSetupDialog() const;
177 void SetFromPage(int v);
178 void SetToPage(int v);
179 void SetMinPage(int v);
180 void SetMaxPage(int v);
181 void SetNoCopies(int v);
182 void SetAllPages(bool flag);
183 void SetSelection(bool flag);
184 void SetCollate(bool flag);
185 void SetPrintToFile(bool flag);
186 void SetSetupDialog(bool flag);
188 void EnablePrintToFile(bool flag);
189 void EnableSelection(bool flag);
190 void EnablePageNumbers(bool flag);
191 void EnableHelp(bool flag);
193 bool GetEnablePrintToFile() const;
194 bool GetEnableSelection() const;
195 bool GetEnablePageNumbers() const;
196 bool GetEnableHelp() const;
198 // Is this data OK for showing the print dialog?
202 wxPrintData& GetPrintData();
204 // %new wxPrintData* GetPrintData() {
205 // return new wxPrintData(self->GetPrintData()); // force a copy
208 void SetPrintData(const wxPrintData& printData);
210 %pythoncode { def __nonzero__(self): return self.Ok() }
214 class wxPrintDialog : public wxDialog {
216 %pythonAppend wxPrintDialog "self._setOORInfo(self)"
218 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
220 wxPrintDialogData& GetPrintDialogData();
222 %newobject GetPrintDC;
228 //---------------------------------------------------------------------------
229 //---------------------------------------------------------------------------
234 wxPRINTER_NO_ERROR = 0,
240 class wxPrinter : public wxObject {
242 wxPrinter(wxPrintDialogData* data = NULL);
245 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
246 wxPrintDialogData& GetPrintDialogData();
247 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=True);
248 wxDC* PrintDialog(wxWindow *parent);
249 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
250 bool Setup(wxWindow *parent);
253 static wxPrinterError GetLastError();
257 //---------------------------------------------------------------------------
258 // Custom wxPrintout class that knows how to call python
262 // Since this one would be tough and ugly to do with the Macros...
263 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
267 wxPyBeginBlockThreads();
268 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
269 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
270 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
273 val = PyTuple_GetItem(result, 0);
274 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
277 val = PyTuple_GetItem(result, 1);
278 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
281 val = PyTuple_GetItem(result, 2);
282 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
285 val = PyTuple_GetItem(result, 3);
286 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
293 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
298 wxPyEndBlockThreads();
300 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
303 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
304 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
308 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
309 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
310 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
311 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
312 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
313 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
314 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
320 // Now define the custom class for SWIGging
321 %name(Printout) class wxPyPrintout : public wxObject {
323 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
325 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
326 //~wxPyPrintout(); wxPrintPreview object takes ownership...
328 void _setCallbackInfo(PyObject* self, PyObject* _class);
331 wxString GetTitle() const;
333 void SetDC(wxDC *dc);
335 void SetPageSizePixels(int w, int h);
337 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
338 "GetPageSizePixels() -> (w, h)");
340 void SetPageSizeMM(int w, int h);
342 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
343 "GetPageSizeMM() -> (w, h)");
345 void SetPPIScreen(int x, int y);
347 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
348 "GetPPIScreen() -> (x,y)");
350 void SetPPIPrinter(int x, int y);
352 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
353 "GetPPIPrinter() -> (x,y)");
356 void SetIsPreview(bool p);
359 bool base_OnBeginDocument(int startPage, int endPage);
360 void base_OnEndDocument();
361 void base_OnBeginPrinting();
362 void base_OnEndPrinting();
363 void base_OnPreparePrinting();
364 bool base_HasPage(int page);
366 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
367 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
370 //---------------------------------------------------------------------------
374 class wxPreviewCanvas: public wxScrolledWindow
377 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
379 wxPreviewCanvas(wxPrintPreview *preview,
381 const wxPoint& pos = wxDefaultPosition,
382 const wxSize& size = wxDefaultSize,
384 const wxString& name = wxPyPreviewCanvasNameStr);
388 class wxPreviewFrame : public wxFrame {
390 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
392 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
393 const wxPoint& pos = wxDefaultPosition,
394 const wxSize& size = wxDefaultSize,
395 long style = wxDEFAULT_FRAME_STYLE,
396 const wxString& name = wxPyFrameNameStr);
399 void CreateControlBar();
402 wxPreviewControlBar* GetControlBar() const;
419 wxID_PREVIEW_PREVIOUS,
427 class wxPreviewControlBar: public wxPanel
430 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
432 wxPreviewControlBar(wxPrintPreview *preview,
435 const wxPoint& pos = wxDefaultPosition,
436 const wxSize& size = wxDefaultSize,
437 long style = wxTAB_TRAVERSAL,
438 const wxString& name = wxPyPanelNameStr);
440 int GetZoomControl();
441 void SetZoomControl(int zoom);
442 wxPrintPreview* GetPrintPreview();
453 //---------------------------------------------------------------------------
455 class wxPrintPreview : public wxObject {
457 wxPrintPreview(wxPyPrintout* printout,
458 wxPyPrintout* printoutForPrinting,
459 wxPrintData* data=NULL);
461 virtual bool SetCurrentPage(int pageNum);
462 int GetCurrentPage();
464 void SetPrintout(wxPyPrintout *printout);
465 wxPyPrintout *GetPrintout();
466 wxPyPrintout *GetPrintoutForPrinting();
468 void SetFrame(wxFrame *frame);
469 void SetCanvas(wxPreviewCanvas *canvas);
471 virtual wxFrame *GetFrame();
472 virtual wxPreviewCanvas *GetCanvas();
474 // The preview canvas should call this from OnPaint
475 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
477 // This draws a blank page onto the preview canvas
478 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
480 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
481 virtual bool RenderPage(int pageNum);
483 // Adjusts the scrollbars for the current scale
484 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
486 wxPrintDialogData& GetPrintDialogData();
488 virtual void SetZoom(int percent);
497 virtual bool Print(bool interactive);
498 virtual void DetermineScaling();
500 %pythoncode { def __nonzero__(self): return self.Ok() }
505 //---------------------------------------------------------------------------
507 // Python-derivable versions of the above preview classes
511 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
512 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
513 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
516 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
517 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
520 wxPyBeginBlockThreads(); \
521 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
522 PyObject* win = wxPyMake_wxObject(a); \
523 PyObject* dc = wxPyMake_wxObject(&b); \
524 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
528 wxPyEndBlockThreads(); \
530 rval = PCLASS::CBNAME(a, b); \
533 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
534 return PCLASS::CBNAME(a, b); \
540 class wxPyPrintPreview : public wxPrintPreview
542 DECLARE_CLASS(wxPyPrintPreview)
544 wxPyPrintPreview(wxPyPrintout* printout,
545 wxPyPrintout* printoutForPrinting,
546 wxPrintData* data=NULL)
547 : wxPrintPreview(printout, printoutForPrinting, data)
550 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
551 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
552 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
553 DEC_PYCALLBACK_BOOL_INT(RenderPage);
554 DEC_PYCALLBACK_VOID_INT(SetZoom);
555 DEC_PYCALLBACK_BOOL_BOOL(Print);
556 DEC_PYCALLBACK_VOID_(DetermineScaling);
561 // Stupid renamed classes... Fix this in 2.5...
562 #if defined(__WXMSW__)
563 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
564 #elif defined(__WXMAC__)
565 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
567 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
570 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
571 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
572 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
573 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
574 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
575 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
576 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
580 class wxPyPrintPreview : public wxPrintPreview
583 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
585 wxPyPrintPreview(wxPyPrintout* printout,
586 wxPyPrintout* printoutForPrinting,
587 wxPrintData* data=NULL);
589 void _setCallbackInfo(PyObject* self, PyObject* _class);
591 bool base_SetCurrentPage(int pageNum);
592 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
593 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
594 bool base_RenderPage(int pageNum);
595 void base_SetZoom(int percent);
596 bool base_Print(bool interactive);
597 void base_DetermineScaling();
604 class wxPyPreviewFrame : public wxPreviewFrame
606 DECLARE_CLASS(wxPyPreviewFrame);
608 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
609 const wxString& title,
610 const wxPoint& pos = wxDefaultPosition,
611 const wxSize& size = wxDefaultSize,
612 long style = wxDEFAULT_FRAME_STYLE,
613 const wxString& name = wxPyFrameNameStr)
614 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
617 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
618 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
620 DEC_PYCALLBACK_VOID_(Initialize);
621 DEC_PYCALLBACK_VOID_(CreateCanvas);
622 DEC_PYCALLBACK_VOID_(CreateControlBar);
627 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
629 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
630 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
631 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
635 class wxPyPreviewFrame : public wxPreviewFrame
638 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
640 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
641 const wxString& title,
642 const wxPoint& pos = wxDefaultPosition,
643 const wxSize& size = wxDefaultSize,
644 long style = wxDEFAULT_FRAME_STYLE,
645 const wxString& name = wxPyFrameNameStr);
647 void _setCallbackInfo(PyObject* self, PyObject* _class);
649 void SetPreviewCanvas(wxPreviewCanvas* canvas);
650 void SetControlBar(wxPreviewControlBar* bar);
652 void base_Initialize();
653 void base_CreateCanvas();
654 void base_CreateControlBar();
661 class wxPyPreviewControlBar : public wxPreviewControlBar
663 DECLARE_CLASS(wxPyPreviewControlBar);
665 wxPyPreviewControlBar(wxPrintPreview *preview,
668 const wxPoint& pos = wxDefaultPosition,
669 const wxSize& size = wxDefaultSize,
671 const wxString& name = wxPyPanelNameStr)
672 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
675 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
677 DEC_PYCALLBACK_VOID_(CreateButtons);
678 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
683 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
684 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
685 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
689 class wxPyPreviewControlBar : public wxPreviewControlBar
692 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
694 wxPyPreviewControlBar(wxPrintPreview *preview,
697 const wxPoint& pos = wxDefaultPosition,
698 const wxSize& size = wxDefaultSize,
700 const wxString& name = wxPyPanelNameStr);
702 void _setCallbackInfo(PyObject* self, PyObject* _class);
704 void SetPrintPreview(wxPrintPreview* preview);
706 void base_CreateButtons();
707 void base_SetZoomControl(int zoom);
711 //---------------------------------------------------------------------------
712 //---------------------------------------------------------------------------
714 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
716 //---------------------------------------------------------------------------