1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Printing Framework classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/printdlg.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
37 %pragma(python) code = "import wx"
40 //----------------------------------------------------------------------
44 class wxPrintData : public wxObject {
53 const wxString& GetPrinterName();
55 wxDuplexMode GetDuplex();
56 wxPaperSize GetPaperId();
57 const wxSize& GetPaperSize();
59 wxPrintQuality GetQuality();
61 void SetNoCopies(int v);
62 void SetCollate(bool flag);
63 void SetOrientation(int orient);
65 void SetPrinterName(const wxString& name);
66 void SetColour(bool colour);
67 void SetDuplex(wxDuplexMode duplex);
68 void SetPaperId(wxPaperSize sizeId);
69 void SetPaperSize(const wxSize& sz);
70 void SetQuality(wxPrintQuality quality);
72 // PostScript-specific data
73 const wxString& GetPrinterCommand();
74 const wxString& GetPrinterOptions();
75 const wxString& GetPreviewCommand();
76 const wxString& GetFilename();
77 const wxString& GetFontMetricPath();
78 double GetPrinterScaleX();
79 double GetPrinterScaleY();
80 long GetPrinterTranslateX();
81 long GetPrinterTranslateY();
82 wxPrintMode GetPrintMode();
84 void SetPrinterCommand(const wxString& command);
85 void SetPrinterOptions(const wxString& options);
86 void SetPreviewCommand(const wxString& command);
87 void SetFilename(const wxString& filename);
88 void SetFontMetricPath(const wxString& path);
89 void SetPrinterScaleX(double x);
90 void SetPrinterScaleY(double y);
91 void SetPrinterScaling(double x, double y);
92 void SetPrinterTranslateX(long x);
93 void SetPrinterTranslateY(long y);
94 void SetPrinterTranslation(long x, long y);
95 void SetPrintMode(wxPrintMode printMode);
99 //----------------------------------------------------------------------
102 class wxPrinterDC : public wxDC {
104 wxPrinterDC(const wxPrintData& printData);
105 %name(wxPrinterDC2) wxPrinterDC(const wxString& driver,
106 const wxString& device,
107 const wxString& output,
108 bool interactive = TRUE,
109 int orientation = wxPORTRAIT);
113 //---------------------------------------------------------------------------
115 class wxPageSetupDialogData : public wxObject {
117 wxPageSetupDialogData();
118 ~wxPageSetupDialogData();
120 void EnableHelp(bool flag);
121 void EnableMargins(bool flag);
122 void EnableOrientation(bool flag);
123 void EnablePaper(bool flag);
124 void EnablePrinter(bool flag);
125 bool GetDefaultMinMargins();
126 bool GetEnableMargins();
127 bool GetEnableOrientation();
128 bool GetEnablePaper();
129 bool GetEnablePrinter();
130 bool GetEnableHelp();
131 bool GetDefaultInfo();
132 wxPoint GetMarginTopLeft();
133 wxPoint GetMarginBottomRight();
134 wxPoint GetMinMarginTopLeft();
135 wxPoint GetMinMarginBottomRight();
136 wxPaperSize GetPaperId();
137 wxSize GetPaperSize();
139 %new wxPrintData* GetPrintData() {
140 return new wxPrintData(self->GetPrintData()); // force a copy
143 void SetDefaultInfo(bool flag);
144 void SetDefaultMinMargins(bool flag);
145 void SetMarginTopLeft(const wxPoint& pt);
146 void SetMarginBottomRight(const wxPoint& pt);
147 void SetMinMarginTopLeft(const wxPoint& pt);
148 void SetMinMarginBottomRight(const wxPoint& pt);
149 void SetPaperId(wxPaperSize id);
150 void SetPaperSize(const wxSize& size);
151 void SetPrintData(const wxPrintData& printData);
155 class wxPageSetupDialog : public wxDialog {
157 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
159 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
161 wxPageSetupDialogData& GetPageSetupData();
165 //----------------------------------------------------------------------
168 class wxPrintDialogData : public wxObject {
171 ~wxPrintDialogData();
173 void EnableHelp(bool flag);
174 void EnablePageNumbers(bool flag);
175 void EnablePrintToFile(bool flag);
176 void EnableSelection(bool flag);
184 %new wxPrintData* GetPrintData() {
185 return new wxPrintData(self->GetPrintData()); // force a copy
188 bool GetPrintToFile();
190 void SetCollate(bool flag);
191 void SetFromPage(int page);
192 void SetMaxPage(int page);
193 void SetMinPage(int page);
194 void SetNoCopies(int n);
195 void SetPrintData(const wxPrintData& printData);
196 void SetPrintToFile(bool flag);
197 void SetSetupDialog(bool flag);
198 void SetToPage(int page);
202 class wxPrintDialog : public wxDialog {
204 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
206 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
208 wxPrintDialogData& GetPrintDialogData();
209 %new wxDC* GetPrintDC();
213 //----------------------------------------------------------------------
214 //----------------------------------------------------------------------
215 // Custom wxPrintout class that knows how to call python
219 // Since this one would be tough and ugly to do with the Macros...
220 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
223 bool doSave = wxPyRestoreThread();
224 if (m_myInst.findCallback("GetPageInfo")) {
225 PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
226 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
229 val = PyTuple_GetItem(result, 0);
230 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
233 val = PyTuple_GetItem(result, 1);
234 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
237 val = PyTuple_GetItem(result, 2);
238 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
241 val = PyTuple_GetItem(result, 3);
242 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
249 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
255 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
257 wxPySaveThread(doSave);
260 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
261 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
265 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
266 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
267 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
268 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
269 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
270 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
271 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
277 // Now define the custom class for SWIGging
278 %name(wxPrintout) class wxPyPrintout : public wxObject {
280 wxPyPrintout(const char* title = "Printout");
282 void _setSelf(PyObject* self, PyObject* _class);
283 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPrintout)"
286 void Destroy() { delete self; }
290 void GetPageSizeMM(int *OUTPUT, int *OUTPUT);
291 void GetPageSizePixels(int *OUTPUT, int *OUTPUT);
292 void GetPPIPrinter(int *OUTPUT, int *OUTPUT);
293 void GetPPIScreen(int *OUTPUT, int *OUTPUT);
296 bool base_OnBeginDocument(int startPage, int endPage);
297 void base_OnEndDocument();
298 void base_OnBeginPrinting();
299 void base_OnEndPrinting();
300 void base_OnPreparePrinting();
301 void base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
302 bool base_HasPage(int page);
305 //----------------------------------------------------------------------
307 class wxPrinter : public wxObject {
309 wxPrinter(wxPrintDialogData* data = NULL);
313 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
314 wxPrintDialogData& GetPrintDialogData();
315 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=TRUE);
316 wxDC* PrintDialog(wxWindow *parent);
317 void ReportError(wxWindow *parent, wxPyPrintout *printout, char* message);
318 bool Setup(wxWindow *parent);
321 //----------------------------------------------------------------------
323 class wxPrintPreview : public wxObject {
325 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
326 // ~wxPrintPreview(); **** ????
328 wxWindow* GetCanvas();
329 int GetCurrentPage();
330 wxFrame * GetFrame();
333 wxPrintDialogData& GetPrintDialogData();
334 wxPyPrintout * GetPrintout();
335 wxPyPrintout * GetPrintoutForPrinting();
338 bool Print(bool prompt);
339 void SetCanvas(wxWindow* window);
340 void SetCurrentPage(int pageNum);
341 void SetFrame(wxFrame *frame);
342 void SetPrintout(wxPyPrintout *printout);
343 void SetZoom(int percent);
346 //----------------------------------------------------------------------
348 class wxPreviewFrame : public wxFrame {
350 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
351 const wxPoint& pos = wxDefaultPosition,
352 const wxSize& size = wxDefaultSize,
353 long style = wxDEFAULT_FRAME_STYLE,
354 char* name = "frame");
356 %pragma(python) addtomethod = "__init__:#wx._StdFrameCallbacks(self)"
360 // **** need to use derived class so these can be properly overridden:
361 //void CreateControlBar()
362 //void CreateCanvas()
366 //----------------------------------------------------------------------
369 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
372 //----------------------------------------------------------------------
373 //----------------------------------------------------------------------