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
53 wxPRINTBIN_LARGECAPACITY,
55 wxPRINTBIN_FORMSOURCE,
61 class wxPrintData : public wxObject {
63 %nokwargs wxPrintData;
65 wxPrintData(const wxPrintData& data); // for making copies
75 const wxString& GetPrinterName();
77 wxDuplexMode GetDuplex();
78 wxPaperSize GetPaperId();
79 const wxSize& GetPaperSize();
83 wxPrintMode GetPrintMode() const;
85 void SetNoCopies(int v);
86 void SetCollate(bool flag);
87 void SetOrientation(int orient);
89 void SetPrinterName(const wxString& name);
90 void SetColour(bool colour);
91 void SetDuplex(wxDuplexMode duplex);
92 void SetPaperId(wxPaperSize sizeId);
93 void SetPaperSize(const wxSize& sz);
94 void SetQuality(int quality);
95 void SetBin(wxPrintBin bin);
96 void SetPrintMode(wxPrintMode printMode);
98 wxString GetFilename() const;
99 void SetFilename( const wxString &filename );
101 %pythoncode { def __nonzero__(self): return self.Ok() }
104 // NOTE: These are now inside of #if WXWIN_COMPATIBILITY_2_4, so be
105 // prepared to remove them...
107 // PostScript-specific data
108 const wxString& GetPrinterCommand();
109 const wxString& GetPrinterOptions();
110 const wxString& GetPreviewCommand();
111 const wxString& GetFontMetricPath();
112 double GetPrinterScaleX();
113 double GetPrinterScaleY();
114 long GetPrinterTranslateX();
115 long GetPrinterTranslateY();
116 void SetPrinterCommand(const wxString& command);
117 void SetPrinterOptions(const wxString& options);
118 void SetPreviewCommand(const wxString& command);
119 void SetFontMetricPath(const wxString& path);
120 void SetPrinterScaleX(double x);
121 void SetPrinterScaleY(double y);
122 void SetPrinterScaling(double x, double y);
123 void SetPrinterTranslateX(long x);
124 void SetPrinterTranslateY(long y);
125 void SetPrinterTranslation(long x, long y);
129 //---------------------------------------------------------------------------
131 class wxPageSetupDialogData : public wxObject {
133 %nokwargs wxPageSetupDialogData;
134 wxPageSetupDialogData();
135 wxPageSetupDialogData(const wxPageSetupDialogData& data); // for making copies
136 ~wxPageSetupDialogData();
138 void EnableHelp(bool flag);
139 void EnableMargins(bool flag);
140 void EnableOrientation(bool flag);
141 void EnablePaper(bool flag);
142 void EnablePrinter(bool flag);
143 bool GetDefaultMinMargins();
144 bool GetEnableMargins();
145 bool GetEnableOrientation();
146 bool GetEnablePaper();
147 bool GetEnablePrinter();
148 bool GetEnableHelp();
149 bool GetDefaultInfo();
150 wxPoint GetMarginTopLeft();
151 wxPoint GetMarginBottomRight();
152 wxPoint GetMinMarginTopLeft();
153 wxPoint GetMinMarginBottomRight();
154 wxPaperSize GetPaperId();
155 wxSize GetPaperSize();
157 wxPrintData& GetPrintData();
159 // %new wxPrintData* GetPrintData() {
160 // return new wxPrintData(self->GetPrintData()); // force a copy
166 void SetDefaultInfo(bool flag);
167 void SetDefaultMinMargins(bool flag);
168 void SetMarginTopLeft(const wxPoint& pt);
169 void SetMarginBottomRight(const wxPoint& pt);
170 void SetMinMarginTopLeft(const wxPoint& pt);
171 void SetMinMarginBottomRight(const wxPoint& pt);
172 void SetPaperId(wxPaperSize id);
173 void SetPaperSize(const wxSize& size);
174 void SetPrintData(const wxPrintData& printData);
176 %pythoncode { def __nonzero__(self): return self.Ok() }
181 // NOTE: Contrary to it's name, this class doesn't derive from wxDialog. It
182 // is a facade in front of a platform-specific (native dialog) provided by the
185 MustHaveApp(wxPageSetupDialog);
187 class wxPageSetupDialog : public wxObject
190 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
192 wxPageSetupDialogData& GetPageSetupData();
193 wxPageSetupDialogData& GetPageSetupDialogData();
197 //---------------------------------------------------------------------------
200 class wxPrintDialogData : public wxObject {
202 %nokwargs wxPrintDialogData;
204 wxPrintDialogData(const wxPrintData& printData); // for making copies
205 ~wxPrintDialogData();
207 int GetFromPage() const;
208 int GetToPage() const;
209 int GetMinPage() const;
210 int GetMaxPage() const;
211 int GetNoCopies() const;
212 bool GetAllPages() const;
213 bool GetSelection() const;
214 bool GetCollate() const;
215 bool GetPrintToFile() const;
217 // WXWIN_COMPATIBILITY_2_4
218 bool GetSetupDialog() const;
219 void SetSetupDialog(bool flag);
221 void SetFromPage(int v);
222 void SetToPage(int v);
223 void SetMinPage(int v);
224 void SetMaxPage(int v);
225 void SetNoCopies(int v);
226 void SetAllPages(bool flag);
227 void SetSelection(bool flag);
228 void SetCollate(bool flag);
229 void SetPrintToFile(bool flag);
231 void EnablePrintToFile(bool flag);
232 void EnableSelection(bool flag);
233 void EnablePageNumbers(bool flag);
234 void EnableHelp(bool flag);
236 bool GetEnablePrintToFile() const;
237 bool GetEnableSelection() const;
238 bool GetEnablePageNumbers() const;
239 bool GetEnableHelp() const;
241 // Is this data OK for showing the print dialog?
245 wxPrintData& GetPrintData();
246 void SetPrintData(const wxPrintData& printData);
248 %pythoncode { def __nonzero__(self): return self.Ok() }
253 MustHaveApp(wxPrintDialog);
256 // NOTE: Contrary to it's name, this class doesn't derive from wxDialog. It
257 // is a facade in front of a platform-specific (native dialog) provided by the
260 class wxPrintDialog : public wxObject {
262 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
264 // TODO?: wxPrintDialog(wxWindow *parent, wxPrintData* data);
266 virtual int ShowModal();
268 virtual wxPrintDialogData& GetPrintDialogData();
269 virtual wxPrintData& GetPrintData();
271 %newobject GetPrintDC;
272 virtual wxDC *GetPrintDC();
277 //---------------------------------------------------------------------------
278 //---------------------------------------------------------------------------
283 wxPRINTER_NO_ERROR = 0,
289 MustHaveApp(wxPrinter);
291 class wxPrinter : public wxObject {
293 wxPrinter(wxPrintDialogData* data = NULL);
296 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPyPrintout *printout);
297 virtual void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
299 virtual bool Setup(wxWindow *parent);
300 virtual bool Print(wxWindow *parent, wxPyPrintout *printout, bool prompt = true);
301 virtual wxDC* PrintDialog(wxWindow *parent);
303 virtual wxPrintDialogData& GetPrintDialogData() const;
306 static wxPrinterError GetLastError();
310 //---------------------------------------------------------------------------
311 // Custom wxPrintout class that knows how to call python, See implementation in
312 // include/sx/wxPython/printfw.h
316 IMPLEMENT_ABSTRACT_CLASS(wxPyPrintout, wxPrintout);
318 // Since this one would be tough and ugly to do with the Macros...
319 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
323 bool blocked = wxPyBeginBlockThreads();
324 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
325 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
326 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
329 val = PyTuple_GetItem(result, 0);
330 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
333 val = PyTuple_GetItem(result, 1);
334 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
337 val = PyTuple_GetItem(result, 2);
338 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
341 val = PyTuple_GetItem(result, 3);
342 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
349 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
354 wxPyEndBlockThreads(blocked);
356 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
359 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
360 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
364 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
365 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
366 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
367 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
368 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
369 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
370 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
376 MustHaveApp(wxPyPrintout);
378 // Now define the custom class for SWIGging
379 %rename(Printout) wxPyPrintout;
380 class wxPyPrintout : public wxObject {
382 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
384 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
385 //~wxPyPrintout(); wxPrintPreview object takes ownership...
387 void _setCallbackInfo(PyObject* self, PyObject* _class);
390 wxString GetTitle() const;
392 void SetDC(wxDC *dc);
394 void SetPageSizePixels(int w, int h);
396 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
397 "GetPageSizePixels() -> (w, h)");
399 void SetPageSizeMM(int w, int h);
401 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
402 "GetPageSizeMM() -> (w, h)");
404 void SetPPIScreen(int x, int y);
406 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
407 "GetPPIScreen() -> (x,y)");
409 void SetPPIPrinter(int x, int y);
411 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
412 "GetPPIPrinter() -> (x,y)");
415 void SetIsPreview(bool p);
418 bool base_OnBeginDocument(int startPage, int endPage);
419 void base_OnEndDocument();
420 void base_OnBeginPrinting();
421 void base_OnEndPrinting();
422 void base_OnPreparePrinting();
423 bool base_HasPage(int page);
425 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
426 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
429 //---------------------------------------------------------------------------
433 MustHaveApp(wxPreviewCanvas);
435 class wxPreviewCanvas: public wxScrolledWindow
438 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
440 wxPreviewCanvas(wxPrintPreview *preview,
442 const wxPoint& pos = wxDefaultPosition,
443 const wxSize& size = wxDefaultSize,
445 const wxString& name = wxPyPreviewCanvasNameStr);
449 MustHaveApp(wxPreviewFrame);
451 class wxPreviewFrame : public wxFrame {
453 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
455 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
456 const wxPoint& pos = wxDefaultPosition,
457 const wxSize& size = wxDefaultSize,
458 long style = wxDEFAULT_FRAME_STYLE,
459 const wxString& name = wxPyFrameNameStr);
462 void CreateControlBar();
465 wxPreviewControlBar* GetControlBar() const;
482 wxID_PREVIEW_PREVIOUS,
490 MustHaveApp(wxPreviewControlBar);
492 class wxPreviewControlBar: public wxPanel
495 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
497 wxPreviewControlBar(wxPrintPreview *preview,
500 const wxPoint& pos = wxDefaultPosition,
501 const wxSize& size = wxDefaultSize,
502 long style = wxTAB_TRAVERSAL,
503 const wxString& name = wxPyPanelNameStr);
505 int GetZoomControl();
506 void SetZoomControl(int zoom);
507 wxPrintPreview* GetPrintPreview();
518 //---------------------------------------------------------------------------
520 MustHaveApp(wxPrintPreview);
522 class wxPrintPreview : public wxObject {
524 %nokwargs wxPrintPreview;
525 wxPrintPreview(wxPyPrintout* printout,
526 wxPyPrintout* printoutForPrinting,
527 wxPrintDialogData *data=NULL);
528 wxPrintPreview(wxPyPrintout* printout,
529 wxPyPrintout* printoutForPrinting,
532 virtual bool SetCurrentPage(int pageNum);
533 int GetCurrentPage();
535 void SetPrintout(wxPyPrintout *printout);
536 wxPyPrintout *GetPrintout();
537 wxPyPrintout *GetPrintoutForPrinting();
539 void SetFrame(wxFrame *frame);
540 void SetCanvas(wxPreviewCanvas *canvas);
542 virtual wxFrame *GetFrame();
543 virtual wxPreviewCanvas *GetCanvas();
545 // The preview canvas should call this from OnPaint
546 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
548 // This draws a blank page onto the preview canvas
549 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
551 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
552 virtual bool RenderPage(int pageNum);
554 // Adjusts the scrollbars for the current scale
555 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
557 wxPrintDialogData& GetPrintDialogData();
559 virtual void SetZoom(int percent);
568 virtual bool Print(bool interactive);
569 virtual void DetermineScaling();
571 %pythoncode { def __nonzero__(self): return self.Ok() }
576 //---------------------------------------------------------------------------
578 // Python-derivable versions of the above preview classes
582 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
583 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
584 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
587 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
588 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
591 bool blocked = wxPyBeginBlockThreads(); \
592 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
593 PyObject* win = wxPyMake_wxObject(a,false); \
594 PyObject* dc = wxPyMake_wxObject(&b,false); \
595 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc)); \
599 wxPyEndBlockThreads(blocked); \
601 rval = PCLASS::CBNAME(a, b); \
604 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
605 return PCLASS::CBNAME(a, b); \
611 class wxPyPrintPreview : public wxPrintPreview
613 DECLARE_CLASS(wxPyPrintPreview)
615 wxPyPrintPreview(wxPyPrintout* printout,
616 wxPyPrintout* printoutForPrinting,
617 wxPrintDialogData* data=NULL)
618 : wxPrintPreview(printout, printoutForPrinting, data)
620 wxPyPrintPreview(wxPyPrintout* printout,
621 wxPyPrintout* printoutForPrinting,
622 wxPrintData* data=NULL)
623 : wxPrintPreview(printout, printoutForPrinting, data)
626 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
627 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
628 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
629 DEC_PYCALLBACK_BOOL_INT(RenderPage);
630 DEC_PYCALLBACK_VOID_INT(SetZoom);
631 DEC_PYCALLBACK_BOOL_BOOL(Print);
632 DEC_PYCALLBACK_VOID_(DetermineScaling);
637 // Stupid renamed classes... Fix this in 2.5...
638 #if defined(__WXMSW__)
639 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
640 #elif defined(__WXMAC__)
641 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
643 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
646 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
647 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
648 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
649 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
650 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
651 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
652 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
656 MustHaveApp(wxPyPrintPreview);
658 class wxPyPrintPreview : public wxPrintPreview
661 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
662 %nokwargs wxPyPrintPreview;
663 wxPyPrintPreview(wxPyPrintout* printout,
664 wxPyPrintout* printoutForPrinting,
665 wxPrintDialogData* data=NULL);
666 wxPyPrintPreview(wxPyPrintout* printout,
667 wxPyPrintout* printoutForPrinting,
670 void _setCallbackInfo(PyObject* self, PyObject* _class);
672 bool base_SetCurrentPage(int pageNum);
673 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
674 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
675 bool base_RenderPage(int pageNum);
676 void base_SetZoom(int percent);
677 bool base_Print(bool interactive);
678 void base_DetermineScaling();
685 class wxPyPreviewFrame : public wxPreviewFrame
687 DECLARE_CLASS(wxPyPreviewFrame);
689 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
690 const wxString& title,
691 const wxPoint& pos = wxDefaultPosition,
692 const wxSize& size = wxDefaultSize,
693 long style = wxDEFAULT_FRAME_STYLE,
694 const wxString& name = wxPyFrameNameStr)
695 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
698 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
699 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
701 DEC_PYCALLBACK_VOID_(Initialize);
702 DEC_PYCALLBACK_VOID_(CreateCanvas);
703 DEC_PYCALLBACK_VOID_(CreateControlBar);
708 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
710 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
711 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
712 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
716 MustHaveApp(wxPyPreviewFrame);
718 class wxPyPreviewFrame : public wxPreviewFrame
721 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
723 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
724 const wxString& title,
725 const wxPoint& pos = wxDefaultPosition,
726 const wxSize& size = wxDefaultSize,
727 long style = wxDEFAULT_FRAME_STYLE,
728 const wxString& name = wxPyFrameNameStr);
730 void _setCallbackInfo(PyObject* self, PyObject* _class);
732 void SetPreviewCanvas(wxPreviewCanvas* canvas);
733 void SetControlBar(wxPreviewControlBar* bar);
735 void base_Initialize();
736 void base_CreateCanvas();
737 void base_CreateControlBar();
744 class wxPyPreviewControlBar : public wxPreviewControlBar
746 DECLARE_CLASS(wxPyPreviewControlBar);
748 wxPyPreviewControlBar(wxPrintPreview *preview,
751 const wxPoint& pos = wxDefaultPosition,
752 const wxSize& size = wxDefaultSize,
754 const wxString& name = wxPyPanelNameStr)
755 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
758 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
760 DEC_PYCALLBACK_VOID_(CreateButtons);
761 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
766 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
767 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
768 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
772 MustHaveApp(wxPyPreviewControlBar);
774 class wxPyPreviewControlBar : public wxPreviewControlBar
777 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
779 wxPyPreviewControlBar(wxPrintPreview *preview,
782 const wxPoint& pos = wxDefaultPosition,
783 const wxSize& size = wxDefaultSize,
785 const wxString& name = wxPyPanelNameStr);
787 void _setCallbackInfo(PyObject* self, PyObject* _class);
789 void SetPrintPreview(wxPrintPreview* preview);
791 void base_CreateButtons();
792 void base_SetZoomControl(int zoom);
795 //---------------------------------------------------------------------------
796 //---------------------------------------------------------------------------
798 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
800 //---------------------------------------------------------------------------