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 MustHaveApp(wxPageSetupDialog);
183 class wxPageSetupDialog : public wxDialog {
185 %pythonAppend wxPageSetupDialog "self._setOORInfo(self)"
187 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
189 wxPageSetupDialogData& GetPageSetupData();
193 //---------------------------------------------------------------------------
196 class wxPrintDialogData : public wxObject {
198 %nokwargs wxPrintDialogData;
200 wxPrintDialogData(const wxPrintData& printData); // for making copies
201 ~wxPrintDialogData();
203 int GetFromPage() const;
204 int GetToPage() const;
205 int GetMinPage() const;
206 int GetMaxPage() const;
207 int GetNoCopies() const;
208 bool GetAllPages() const;
209 bool GetSelection() const;
210 bool GetCollate() const;
211 bool GetPrintToFile() const;
213 // WXWIN_COMPATIBILITY_2_4
214 bool GetSetupDialog() const;
215 void SetSetupDialog(bool flag);
217 void SetFromPage(int v);
218 void SetToPage(int v);
219 void SetMinPage(int v);
220 void SetMaxPage(int v);
221 void SetNoCopies(int v);
222 void SetAllPages(bool flag);
223 void SetSelection(bool flag);
224 void SetCollate(bool flag);
225 void SetPrintToFile(bool flag);
227 void EnablePrintToFile(bool flag);
228 void EnableSelection(bool flag);
229 void EnablePageNumbers(bool flag);
230 void EnableHelp(bool flag);
232 bool GetEnablePrintToFile() const;
233 bool GetEnableSelection() const;
234 bool GetEnablePageNumbers() const;
235 bool GetEnableHelp() const;
237 // Is this data OK for showing the print dialog?
241 wxPrintData& GetPrintData();
242 void SetPrintData(const wxPrintData& printData);
244 %pythoncode { def __nonzero__(self): return self.Ok() }
249 MustHaveApp(wxPrintDialog);
252 // NOTE: Contrary to it's name, this class doesn't derive from wxDialog. It
253 // is a facade in front of a platform-specific (native dialog) provided by the
256 class wxPrintDialog : public wxObject {
258 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
260 // TODO?: wxPrintDialog(wxWindow *parent, wxPrintData* data);
262 virtual int ShowModal();
264 virtual wxPrintDialogData& GetPrintDialogData();
265 virtual wxPrintData& GetPrintData();
267 %newobject GetPrintDC;
268 virtual wxDC *GetPrintDC();
273 //---------------------------------------------------------------------------
274 //---------------------------------------------------------------------------
279 wxPRINTER_NO_ERROR = 0,
285 MustHaveApp(wxPrinter);
287 class wxPrinter : public wxObject {
289 wxPrinter(wxPrintDialogData* data = NULL);
292 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPyPrintout *printout);
293 virtual void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
295 virtual bool Setup(wxWindow *parent);
296 virtual bool Print(wxWindow *parent, wxPyPrintout *printout, bool prompt = true);
297 virtual wxDC* PrintDialog(wxWindow *parent);
299 virtual wxPrintDialogData& GetPrintDialogData() const;
302 static wxPrinterError GetLastError();
306 //---------------------------------------------------------------------------
307 // Custom wxPrintout class that knows how to call python, See implementation in
308 // include/sx/wxPython/printfw.h
312 IMPLEMENT_ABSTRACT_CLASS(wxPyPrintout, wxPrintout);
314 // Since this one would be tough and ugly to do with the Macros...
315 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
319 bool blocked = wxPyBeginBlockThreads();
320 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
321 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
322 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
325 val = PyTuple_GetItem(result, 0);
326 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
329 val = PyTuple_GetItem(result, 1);
330 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
333 val = PyTuple_GetItem(result, 2);
334 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
337 val = PyTuple_GetItem(result, 3);
338 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
345 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
350 wxPyEndBlockThreads(blocked);
352 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
355 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
356 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
360 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
361 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
362 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
363 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
364 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
365 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
366 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
372 MustHaveApp(wxPyPrintout);
374 // Now define the custom class for SWIGging
375 %name(Printout) class wxPyPrintout : public wxObject {
377 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
379 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
380 //~wxPyPrintout(); wxPrintPreview object takes ownership...
382 void _setCallbackInfo(PyObject* self, PyObject* _class);
385 wxString GetTitle() const;
387 void SetDC(wxDC *dc);
389 void SetPageSizePixels(int w, int h);
391 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
392 "GetPageSizePixels() -> (w, h)");
394 void SetPageSizeMM(int w, int h);
396 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
397 "GetPageSizeMM() -> (w, h)");
399 void SetPPIScreen(int x, int y);
401 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
402 "GetPPIScreen() -> (x,y)");
404 void SetPPIPrinter(int x, int y);
406 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
407 "GetPPIPrinter() -> (x,y)");
410 void SetIsPreview(bool p);
413 bool base_OnBeginDocument(int startPage, int endPage);
414 void base_OnEndDocument();
415 void base_OnBeginPrinting();
416 void base_OnEndPrinting();
417 void base_OnPreparePrinting();
418 bool base_HasPage(int page);
420 void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
421 "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
424 //---------------------------------------------------------------------------
428 MustHaveApp(wxPreviewCanvas);
430 class wxPreviewCanvas: public wxScrolledWindow
433 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
435 wxPreviewCanvas(wxPrintPreview *preview,
437 const wxPoint& pos = wxDefaultPosition,
438 const wxSize& size = wxDefaultSize,
440 const wxString& name = wxPyPreviewCanvasNameStr);
444 MustHaveApp(wxPreviewFrame);
446 class wxPreviewFrame : public wxFrame {
448 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
450 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
451 const wxPoint& pos = wxDefaultPosition,
452 const wxSize& size = wxDefaultSize,
453 long style = wxDEFAULT_FRAME_STYLE,
454 const wxString& name = wxPyFrameNameStr);
457 void CreateControlBar();
460 wxPreviewControlBar* GetControlBar() const;
477 wxID_PREVIEW_PREVIOUS,
485 MustHaveApp(wxPreviewControlBar);
487 class wxPreviewControlBar: public wxPanel
490 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
492 wxPreviewControlBar(wxPrintPreview *preview,
495 const wxPoint& pos = wxDefaultPosition,
496 const wxSize& size = wxDefaultSize,
497 long style = wxTAB_TRAVERSAL,
498 const wxString& name = wxPyPanelNameStr);
500 int GetZoomControl();
501 void SetZoomControl(int zoom);
502 wxPrintPreview* GetPrintPreview();
513 //---------------------------------------------------------------------------
515 MustHaveApp(wxPrintPreview);
517 class wxPrintPreview : public wxObject {
519 %nokwargs wxPrintPreview;
520 wxPrintPreview(wxPyPrintout* printout,
521 wxPyPrintout* printoutForPrinting,
522 wxPrintDialogData *data=NULL);
523 wxPrintPreview(wxPyPrintout* printout,
524 wxPyPrintout* printoutForPrinting,
527 virtual bool SetCurrentPage(int pageNum);
528 int GetCurrentPage();
530 void SetPrintout(wxPyPrintout *printout);
531 wxPyPrintout *GetPrintout();
532 wxPyPrintout *GetPrintoutForPrinting();
534 void SetFrame(wxFrame *frame);
535 void SetCanvas(wxPreviewCanvas *canvas);
537 virtual wxFrame *GetFrame();
538 virtual wxPreviewCanvas *GetCanvas();
540 // The preview canvas should call this from OnPaint
541 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
543 // This draws a blank page onto the preview canvas
544 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
546 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
547 virtual bool RenderPage(int pageNum);
549 // Adjusts the scrollbars for the current scale
550 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
552 wxPrintDialogData& GetPrintDialogData();
554 virtual void SetZoom(int percent);
563 virtual bool Print(bool interactive);
564 virtual void DetermineScaling();
566 %pythoncode { def __nonzero__(self): return self.Ok() }
571 //---------------------------------------------------------------------------
573 // Python-derivable versions of the above preview classes
577 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
578 bool CBNAME(wxPreviewCanvas* a, wxDC& b); \
579 bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
582 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
583 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
586 bool blocked = wxPyBeginBlockThreads(); \
587 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
588 PyObject* win = wxPyMake_wxObject(a,false); \
589 PyObject* dc = wxPyMake_wxObject(&b,false); \
590 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc)); \
594 wxPyEndBlockThreads(blocked); \
596 rval = PCLASS::CBNAME(a, b); \
599 bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \
600 return PCLASS::CBNAME(a, b); \
606 class wxPyPrintPreview : public wxPrintPreview
608 DECLARE_CLASS(wxPyPrintPreview)
610 wxPyPrintPreview(wxPyPrintout* printout,
611 wxPyPrintout* printoutForPrinting,
612 wxPrintDialogData* data=NULL)
613 : wxPrintPreview(printout, printoutForPrinting, data)
615 wxPyPrintPreview(wxPyPrintout* printout,
616 wxPyPrintout* printoutForPrinting,
617 wxPrintData* data=NULL)
618 : wxPrintPreview(printout, printoutForPrinting, data)
621 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
622 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
623 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
624 DEC_PYCALLBACK_BOOL_INT(RenderPage);
625 DEC_PYCALLBACK_VOID_INT(SetZoom);
626 DEC_PYCALLBACK_BOOL_BOOL(Print);
627 DEC_PYCALLBACK_VOID_(DetermineScaling);
632 // Stupid renamed classes... Fix this in 2.5...
633 #if defined(__WXMSW__)
634 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
635 #elif defined(__WXMAC__)
636 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
638 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
641 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
642 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
643 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
644 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
645 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
646 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
647 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
651 MustHaveApp(wxPyPrintPreview);
653 class wxPyPrintPreview : public wxPrintPreview
656 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
657 %nokwargs wxPyPrintPreview;
658 wxPyPrintPreview(wxPyPrintout* printout,
659 wxPyPrintout* printoutForPrinting,
660 wxPrintDialogData* data=NULL);
661 wxPyPrintPreview(wxPyPrintout* printout,
662 wxPyPrintout* printoutForPrinting,
665 void _setCallbackInfo(PyObject* self, PyObject* _class);
667 bool base_SetCurrentPage(int pageNum);
668 bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
669 bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
670 bool base_RenderPage(int pageNum);
671 void base_SetZoom(int percent);
672 bool base_Print(bool interactive);
673 void base_DetermineScaling();
680 class wxPyPreviewFrame : public wxPreviewFrame
682 DECLARE_CLASS(wxPyPreviewFrame);
684 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
685 const wxString& title,
686 const wxPoint& pos = wxDefaultPosition,
687 const wxSize& size = wxDefaultSize,
688 long style = wxDEFAULT_FRAME_STYLE,
689 const wxString& name = wxPyFrameNameStr)
690 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
693 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
694 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
696 DEC_PYCALLBACK_VOID_(Initialize);
697 DEC_PYCALLBACK_VOID_(CreateCanvas);
698 DEC_PYCALLBACK_VOID_(CreateControlBar);
703 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
705 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
706 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
707 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
711 MustHaveApp(wxPyPreviewFrame);
713 class wxPyPreviewFrame : public wxPreviewFrame
716 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
718 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
719 const wxString& title,
720 const wxPoint& pos = wxDefaultPosition,
721 const wxSize& size = wxDefaultSize,
722 long style = wxDEFAULT_FRAME_STYLE,
723 const wxString& name = wxPyFrameNameStr);
725 void _setCallbackInfo(PyObject* self, PyObject* _class);
727 void SetPreviewCanvas(wxPreviewCanvas* canvas);
728 void SetControlBar(wxPreviewControlBar* bar);
730 void base_Initialize();
731 void base_CreateCanvas();
732 void base_CreateControlBar();
739 class wxPyPreviewControlBar : public wxPreviewControlBar
741 DECLARE_CLASS(wxPyPreviewControlBar);
743 wxPyPreviewControlBar(wxPrintPreview *preview,
746 const wxPoint& pos = wxDefaultPosition,
747 const wxSize& size = wxDefaultSize,
749 const wxString& name = wxPyPanelNameStr)
750 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
753 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
755 DEC_PYCALLBACK_VOID_(CreateButtons);
756 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
761 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
762 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
763 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
767 MustHaveApp(wxPyPreviewControlBar);
769 class wxPyPreviewControlBar : public wxPreviewControlBar
772 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
774 wxPyPreviewControlBar(wxPrintPreview *preview,
777 const wxPoint& pos = wxDefaultPosition,
778 const wxSize& size = wxDefaultSize,
780 const wxString& name = wxPyPanelNameStr);
782 void _setCallbackInfo(PyObject* self, PyObject* _class);
784 void SetPrintPreview(wxPrintPreview* preview);
786 void base_CreateButtons();
787 void base_SetZoomControl(int zoom);
790 //---------------------------------------------------------------------------
791 //---------------------------------------------------------------------------
793 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
795 //---------------------------------------------------------------------------