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 {
168 ~wxPrintDialogData();
170 int GetFromPage() const;
171 int GetToPage() const;
172 int GetMinPage() const;
173 int GetMaxPage() const;
174 int GetNoCopies() const;
175 bool GetAllPages() const;
176 bool GetSelection() const;
177 bool GetCollate() const;
178 bool GetPrintToFile() const;
179 bool GetSetupDialog() const;
181 void SetFromPage(int v);
182 void SetToPage(int v);
183 void SetMinPage(int v);
184 void SetMaxPage(int v);
185 void SetNoCopies(int v);
186 void SetAllPages(bool flag);
187 void SetSelection(bool flag);
188 void SetCollate(bool flag);
189 void SetPrintToFile(bool flag);
190 void SetSetupDialog(bool flag);
192 void EnablePrintToFile(bool flag);
193 void EnableSelection(bool flag);
194 void EnablePageNumbers(bool flag);
195 void EnableHelp(bool flag);
197 bool GetEnablePrintToFile() const;
198 bool GetEnableSelection() const;
199 bool GetEnablePageNumbers() const;
200 bool GetEnableHelp() const;
202 // Is this data OK for showing the print dialog?
206 wxPrintData& GetPrintData();
208 // %new wxPrintData* GetPrintData() {
209 // return new wxPrintData(self->GetPrintData()); // force a copy
212 void SetPrintData(const wxPrintData& printData);
214 %pythoncode { def __nonzero__(self): return self.Ok() }
218 class wxPrintDialog : public wxDialog {
220 %pythonAppend wxPrintDialog "self._setOORInfo(self)"
222 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
224 wxPrintDialogData& GetPrintDialogData();
226 %newobject GetPrintDC;
232 //---------------------------------------------------------------------------
233 //---------------------------------------------------------------------------
238 wxPRINTER_NO_ERROR = 0,
244 class wxPrinter : public wxObject {
246 wxPrinter(wxPrintDialogData* data = NULL);
249 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
250 wxPrintDialogData& GetPrintDialogData();
251 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=True);
252 wxDC* PrintDialog(wxWindow *parent);
253 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
254 bool Setup(wxWindow *parent);
257 static wxPrinterError GetLastError();
261 //---------------------------------------------------------------------------
262 // Custom wxPrintout class that knows how to call python
266 // Since this one would be tough and ugly to do with the Macros...
267 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
271 wxPyBeginBlockThreads();
272 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
273 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
274 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
277 val = PyTuple_GetItem(result, 0);
278 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
281 val = PyTuple_GetItem(result, 1);
282 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
285 val = PyTuple_GetItem(result, 2);
286 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
289 val = PyTuple_GetItem(result, 3);
290 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
297 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
302 wxPyEndBlockThreads();
304 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
307 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
308 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
312 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
313 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
314 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
315 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
316 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
317 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
318 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
324 // Now define the custom class for SWIGging
325 %name(Printout) class wxPyPrintout : public wxObject {
327 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
329 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
330 //~wxPyPrintout(); wxPrintPreview object takes ownership...
332 void _setCallbackInfo(PyObject* self, PyObject* _class);
335 wxString GetTitle() const;
337 void SetDC(wxDC *dc);
339 void SetPageSizePixels(int w, int h);
341 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
342 "GetPageSizePixels() -> (w, h)");
344 void SetPageSizeMM(int w, int h);
346 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
347 "GetPageSizeMM() -> (w, h)");
349 void SetPPIScreen(int x, int y);
351 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
352 "GetPPIScreen() -> (x,y)");
354 void SetPPIPrinter(int x, int y);
356 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
357 "GetPPIPrinter() -> (x,y)");
360 void SetIsPreview(bool p);
363 bool base_OnBeginDocument(int startPage, int endPage);
364 void base_OnEndDocument();
365 void base_OnBeginPrinting();
366 void base_OnEndPrinting();
367 void base_OnPreparePrinting();
368 bool base_HasPage(int page);
370 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
371 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
374 //---------------------------------------------------------------------------
378 class wxPreviewCanvas: public wxScrolledWindow
381 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
383 wxPreviewCanvas(wxPrintPreview *preview,
385 const wxPoint& pos = wxDefaultPosition,
386 const wxSize& size = wxDefaultSize,
388 const wxString& name = wxPyPreviewCanvasNameStr);
392 class wxPreviewFrame : public wxFrame {
394 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
396 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
397 const wxPoint& pos = wxDefaultPosition,
398 const wxSize& size = wxDefaultSize,
399 long style = wxDEFAULT_FRAME_STYLE,
400 const wxString& name = wxPyFrameNameStr);
403 void CreateControlBar();
406 wxPreviewControlBar* GetControlBar() const;
423 wxID_PREVIEW_PREVIOUS,
431 class wxPreviewControlBar: public wxPanel
434 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
436 wxPreviewControlBar(wxPrintPreview *preview,
439 const wxPoint& pos = wxDefaultPosition,
440 const wxSize& size = wxDefaultSize,
441 long style = wxTAB_TRAVERSAL,
442 const wxString& name = wxPyPanelNameStr);
444 int GetZoomControl();
445 void SetZoomControl(int zoom);
446 wxPrintPreview* GetPrintPreview();
457 //---------------------------------------------------------------------------
459 class wxPrintPreview : public wxObject {
461 wxPrintPreview(wxPyPrintout* printout,
462 wxPyPrintout* printoutForPrinting,
463 wxPrintData* data=NULL);
465 virtual bool SetCurrentPage(int pageNum);
466 int GetCurrentPage();
468 void SetPrintout(wxPyPrintout *printout);
469 wxPyPrintout *GetPrintout();
470 wxPyPrintout *GetPrintoutForPrinting();
472 void SetFrame(wxFrame *frame);
473 void SetCanvas(wxPreviewCanvas *canvas);
475 virtual wxFrame *GetFrame();
476 virtual wxPreviewCanvas *GetCanvas();
478 // The preview canvas should call this from OnPaint
479 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
481 // This draws a blank page onto the preview canvas
482 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
484 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
485 virtual bool RenderPage(int pageNum);
487 // Adjusts the scrollbars for the current scale
488 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
490 wxPrintDialogData& GetPrintDialogData();
492 virtual void SetZoom(int percent);
501 virtual bool Print(bool interactive);
502 virtual void DetermineScaling();
504 %pythoncode { def __nonzero__(self): return self.Ok() }
509 //---------------------------------------------------------------------------
511 // Python-derivable versions of the above preview classes
515 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
516 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
517 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
520 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
521 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
524 wxPyBeginBlockThreads(); \
525 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
526 PyObject* win = wxPyMake_wxObject(a); \
527 PyObject* dc = wxPyMake_wxObject(&b); \
528 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
532 wxPyEndBlockThreads(); \
534 rval = PCLASS::CBNAME(a, b); \
537 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
538 return PCLASS::CBNAME(a, b); \
544 class wxPyPrintPreview : public wxPrintPreview
546 DECLARE_CLASS(wxPyPrintPreview)
548 wxPyPrintPreview(wxPyPrintout* printout,
549 wxPyPrintout* printoutForPrinting,
550 wxPrintData* data=NULL)
551 : wxPrintPreview(printout, printoutForPrinting, data)
554 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
555 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
556 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
557 DEC_PYCALLBACK_BOOL_INT(RenderPage);
558 DEC_PYCALLBACK_VOID_INT(SetZoom);
559 DEC_PYCALLBACK_BOOL_BOOL(Print);
560 DEC_PYCALLBACK_VOID_(DetermineScaling);
565 // Stupid renamed classes... Fix this in 2.5...
566 #if defined(__WXMSW__)
567 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
568 #elif defined(__WXMAC__)
569 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
571 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
574 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
575 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
576 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
577 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
578 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
579 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
580 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
584 class wxPyPrintPreview : public wxPrintPreview
587 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
589 wxPyPrintPreview(wxPyPrintout* printout,
590 wxPyPrintout* printoutForPrinting,
591 wxPrintData* data=NULL);
593 void _setCallbackInfo(PyObject* self, PyObject* _class);
595 bool base_SetCurrentPage(int pageNum);
596 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
597 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
598 bool base_RenderPage(int pageNum);
599 void base_SetZoom(int percent);
600 bool base_Print(bool interactive);
601 void base_DetermineScaling();
608 class wxPyPreviewFrame : public wxPreviewFrame
610 DECLARE_CLASS(wxPyPreviewFrame);
612 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
613 const wxString& title,
614 const wxPoint& pos = wxDefaultPosition,
615 const wxSize& size = wxDefaultSize,
616 long style = wxDEFAULT_FRAME_STYLE,
617 const wxString& name = wxPyFrameNameStr)
618 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
621 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
622 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
624 DEC_PYCALLBACK_VOID_(Initialize);
625 DEC_PYCALLBACK_VOID_(CreateCanvas);
626 DEC_PYCALLBACK_VOID_(CreateControlBar);
631 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
633 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
634 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
635 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
639 class wxPyPreviewFrame : public wxPreviewFrame
642 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
644 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
645 const wxString& title,
646 const wxPoint& pos = wxDefaultPosition,
647 const wxSize& size = wxDefaultSize,
648 long style = wxDEFAULT_FRAME_STYLE,
649 const wxString& name = wxPyFrameNameStr);
651 void _setCallbackInfo(PyObject* self, PyObject* _class);
653 void SetPreviewCanvas(wxPreviewCanvas* canvas);
654 void SetControlBar(wxPreviewControlBar* bar);
656 void base_Initialize();
657 void base_CreateCanvas();
658 void base_CreateControlBar();
665 class wxPyPreviewControlBar : public wxPreviewControlBar
667 DECLARE_CLASS(wxPyPreviewControlBar);
669 wxPyPreviewControlBar(wxPrintPreview *preview,
672 const wxPoint& pos = wxDefaultPosition,
673 const wxSize& size = wxDefaultSize,
675 const wxString& name = wxPyPanelNameStr)
676 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
679 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
681 DEC_PYCALLBACK_VOID_(CreateButtons);
682 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
687 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
688 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
689 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
693 class wxPyPreviewControlBar : public wxPreviewControlBar
696 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
698 wxPyPreviewControlBar(wxPrintPreview *preview,
701 const wxPoint& pos = wxDefaultPosition,
702 const wxSize& size = wxDefaultSize,
704 const wxString& name = wxPyPanelNameStr);
706 void _setCallbackInfo(PyObject* self, PyObject* _class);
708 void SetPrintPreview(wxPrintPreview* preview);
710 void base_CreateButtons();
711 void base_SetZoomControl(int zoom);
715 //---------------------------------------------------------------------------
716 //---------------------------------------------------------------------------
718 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
720 //---------------------------------------------------------------------------