1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Printing Framework classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/printdlg.h>
21 //----------------------------------------------------------------------
24 %include my_typemaps.i
26 // Import some definitions of other classes, etc.
35 %pragma(python) code = "import wx"
38 //----------------------------------------------------------------------
51 const wxString& GetPrinterName();
53 wxDuplexMode GetDuplex();
54 wxPaperSize GetPaperId();
55 const wxSize& GetPaperSize();
57 wxPrintQuality GetQuality();
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(wxPrintQuality 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);
97 //----------------------------------------------------------------------
99 class wxPageSetupDialogData {
101 wxPageSetupDialogData();
102 ~wxPageSetupDialogData();
104 void EnableHelp(bool flag);
105 void EnableMargins(bool flag);
106 void EnableOrientation(bool flag);
107 void EnablePaper(bool flag);
108 void EnablePrinter(bool flag);
109 bool GetDefaultMinMargins();
110 bool GetEnableMargins();
111 bool GetEnableOrientation();
112 bool GetEnablePaper();
113 bool GetEnablePrinter();
114 bool GetEnableHelp();
115 bool GetDefaultInfo();
116 wxPoint GetMarginTopLeft();
117 wxPoint GetMarginBottomRight();
118 wxPoint GetMinMarginTopLeft();
119 wxPoint GetMinMarginBottomRight();
120 wxPaperSize GetPaperId();
121 wxSize GetPaperSize();
123 %new wxPrintData* GetPrintData() {
124 return new wxPrintData(self->GetPrintData()); // force a copy
127 void SetDefaultInfo(bool flag);
128 void SetDefaultMinMargins(bool flag);
129 void SetMarginTopLeft(const wxPoint& pt);
130 void SetMarginBottomRight(const wxPoint& pt);
131 void SetMinMarginTopLeft(const wxPoint& pt);
132 void SetMinMarginBottomRight(const wxPoint& pt);
133 void SetPaperId(wxPaperSize& id);
134 void SetPaperSize(const wxSize& size);
135 void SetPrintData(const wxPrintData& printData);
139 class wxPageSetupDialog : public wxDialog {
141 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
143 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
145 wxPageSetupDialogData& GetPageSetupData();
149 //----------------------------------------------------------------------
152 class wxPrintDialogData {
155 ~wxPrintDialogData();
157 void EnableHelp(bool flag);
158 void EnablePageNumbers(bool flag);
159 void EnablePrintToFile(bool flag);
160 void EnableSelection(bool flag);
168 %new wxPrintData* GetPrintData() {
169 return new wxPrintData(self->GetPrintData()); // force a copy
172 bool GetPrintToFile();
174 void SetCollate(bool flag);
175 void SetFromPage(int page);
176 void SetMaxPage(int page);
177 void SetMinPage(int page);
178 void SetNoCopies(int n);
179 void SetPrintData(const wxPrintData& printData);
180 void SetPrintToFile(bool flag);
181 void SetSetupDialog(bool flag);
182 void SetToPage(int page);
186 class wxPrintDialog : public wxDialog {
188 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
190 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
192 wxPrintDialogData& GetPrintDialogData();
193 %new wxDC* GetPrintDC();
197 //----------------------------------------------------------------------
198 //----------------------------------------------------------------------
199 // Custom wxPrintout class that knows how to call python
201 class wxPyPrintout : public wxPrintout {
203 wxPyPrintout(const wxString& title) : wxPrintout(title) {}
205 DEC_PYCALLBACK_BOOL_INTINT(OnBeginDocument);
206 DEC_PYCALLBACK__(OnEndDocument);
207 DEC_PYCALLBACK__(OnBeginPrinting);
208 DEC_PYCALLBACK__(OnEndPrinting);
209 DEC_PYCALLBACK__(OnPreparePrinting);
210 DEC_PYCALLBACK_BOOL_INT_pure(OnPrintPage);
211 DEC_PYCALLBACK_BOOL_INT(HasPage);
214 // Since this one would be tough and ugly to do with the Macros...
215 void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
218 bool doSave = wxPyRestoreThread();
219 if (m_myInst.findCallback("GetPageInfo")) {
220 PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
221 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
224 val = PyTuple_GetItem(result, 0);
225 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
228 val = PyTuple_GetItem(result, 1);
229 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
232 val = PyTuple_GetItem(result, 2);
233 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
236 val = PyTuple_GetItem(result, 3);
237 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
244 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
250 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
252 wxPySaveThread(doSave);
255 void base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
256 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
262 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
263 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
264 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
265 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
266 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
267 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
268 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
274 // Now define the custom class for SWIGging
275 %name(wxPrintout) class wxPyPrintout {
277 wxPyPrintout(const char* title = "Printout");
279 void _setSelf(PyObject* self);
280 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
283 void Destroy() { delete self; }
287 void GetPageSizeMM(int *OUTPUT, int *OUTPUT);
288 void GetPageSizePixels(int *OUTPUT, int *OUTPUT);
289 void GetPPIPrinter(int *OUTPUT, int *OUTPUT);
290 void GetPPIScreen(int *OUTPUT, int *OUTPUT);
293 bool base_OnBeginDocument(int startPage, int endPage);
294 void base_OnEndDocument();
295 void base_OnBeginPrinting();
296 void base_OnEndPrinting();
297 void base_OnPreparePrinting();
298 void base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
299 bool base_HasPage(int page);
302 //----------------------------------------------------------------------
306 wxPrinter(wxPrintDialogData* data = NULL);
310 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
311 wxPrintDialogData& GetPrintDialogData();
312 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=TRUE);
313 wxDC* PrintDialog(wxWindow *parent);
314 void ReportError(wxWindow *parent, wxPyPrintout *printout, char* message);
315 bool Setup(wxWindow *parent);
318 //----------------------------------------------------------------------
320 class wxPrintPreview {
322 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
323 // ~wxPrintPreview(); **** ????
325 wxWindow* GetCanvas();
326 int GetCurrentPage();
327 wxFrame * GetFrame();
330 wxPrintDialogData& GetPrintDialogData();
331 wxPyPrintout * GetPrintout();
332 wxPyPrintout * GetPrintoutForPrinting();
335 bool Print(bool prompt);
336 void SetCanvas(wxWindow* window);
337 void SetCurrentPage(int pageNum);
338 void SetFrame(wxFrame *frame);
339 void SetPrintout(wxPyPrintout *printout);
340 void SetZoom(int percent);
343 //----------------------------------------------------------------------
345 class wxPreviewFrame : public wxFrame {
347 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
348 const wxPoint& pos = wxPyDefaultPosition,
349 const wxSize& size = wxPyDefaultSize,
350 long style = wxDEFAULT_FRAME_STYLE,
351 char* name = "frame");
353 %pragma(python) addtomethod = "__init__:wx._StdFrameCallbacks(self)"
357 // **** need to use derived class so these can be properly overridden:
358 //void CreateControlBar()
359 //void CreateCanvas()
363 //----------------------------------------------------------------------
364 //----------------------------------------------------------------------
365 //----------------------------------------------------------------------