1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Printing Framework classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/printdlg.h>
24 //----------------------------------------------------------------------
27 %include my_typemaps.i
29 // Import some definitions of other classes, etc.
38 %pragma(python) code = "import wx"
41 //----------------------------------------------------------------------
45 class wxPrintData : public wxObject {
54 const wxString& GetPrinterName();
56 wxDuplexMode GetDuplex();
57 wxPaperSize GetPaperId();
58 const wxSize& GetPaperSize();
60 wxPrintQuality GetQuality();
62 void SetNoCopies(int v);
63 void SetCollate(bool flag);
64 void SetOrientation(int orient);
66 void SetPrinterName(const wxString& name);
67 void SetColour(bool colour);
68 void SetDuplex(wxDuplexMode duplex);
69 void SetPaperId(wxPaperSize sizeId);
70 void SetPaperSize(const wxSize& sz);
71 void SetQuality(wxPrintQuality quality);
73 // PostScript-specific data
74 const wxString& GetPrinterCommand();
75 const wxString& GetPrinterOptions();
76 const wxString& GetPreviewCommand();
77 const wxString& GetFilename();
78 const wxString& GetFontMetricPath();
79 double GetPrinterScaleX();
80 double GetPrinterScaleY();
81 long GetPrinterTranslateX();
82 long GetPrinterTranslateY();
83 wxPrintMode GetPrintMode();
85 void SetPrinterCommand(const wxString& command);
86 void SetPrinterOptions(const wxString& options);
87 void SetPreviewCommand(const wxString& command);
88 void SetFilename(const wxString& filename);
89 void SetFontMetricPath(const wxString& path);
90 void SetPrinterScaleX(double x);
91 void SetPrinterScaleY(double y);
92 void SetPrinterScaling(double x, double y);
93 void SetPrinterTranslateX(long x);
94 void SetPrinterTranslateY(long y);
95 void SetPrinterTranslation(long x, long y);
96 void SetPrintMode(wxPrintMode printMode);
100 //----------------------------------------------------------------------
103 class wxPrinterDC : public wxDC {
105 wxPrinterDC(const wxPrintData& printData);
106 %name(wxPrinterDC2) wxPrinterDC(const wxString& driver,
107 const wxString& device,
108 const wxString& output,
109 bool interactive = TRUE,
110 int orientation = wxPORTRAIT);
114 //---------------------------------------------------------------------------
116 class wxPostScriptDC : public wxDC {
118 wxPostScriptDC(const wxPrintData& printData);
119 %name(wxPostScriptDC2)wxPostScriptDC(const wxString& output,
120 bool interactive = TRUE,
121 wxWindow* parent = NULL);
123 wxPrintData& GetPrintData();
124 void SetPrintData(const wxPrintData& data);
126 static void SetResolution(int ppi);
127 static int GetResolution();
130 //---------------------------------------------------------------------------
132 class wxPageSetupDialogData : public wxObject {
134 wxPageSetupDialogData();
135 ~wxPageSetupDialogData();
137 void EnableHelp(bool flag);
138 void EnableMargins(bool flag);
139 void EnableOrientation(bool flag);
140 void EnablePaper(bool flag);
141 void EnablePrinter(bool flag);
142 bool GetDefaultMinMargins();
143 bool GetEnableMargins();
144 bool GetEnableOrientation();
145 bool GetEnablePaper();
146 bool GetEnablePrinter();
147 bool GetEnableHelp();
148 bool GetDefaultInfo();
149 wxPoint GetMarginTopLeft();
150 wxPoint GetMarginBottomRight();
151 wxPoint GetMinMarginTopLeft();
152 wxPoint GetMinMarginBottomRight();
153 wxPaperSize GetPaperId();
154 wxSize GetPaperSize();
156 %new wxPrintData* GetPrintData() {
157 return new wxPrintData(self->GetPrintData()); // force a copy
160 void SetDefaultInfo(bool flag);
161 void SetDefaultMinMargins(bool flag);
162 void SetMarginTopLeft(const wxPoint& pt);
163 void SetMarginBottomRight(const wxPoint& pt);
164 void SetMinMarginTopLeft(const wxPoint& pt);
165 void SetMinMarginBottomRight(const wxPoint& pt);
166 void SetPaperId(wxPaperSize id);
167 void SetPaperSize(const wxSize& size);
168 void SetPrintData(const wxPrintData& printData);
172 class wxPageSetupDialog : public wxDialog {
174 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
176 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
178 wxPageSetupDialogData& GetPageSetupData();
182 //----------------------------------------------------------------------
185 class wxPrintDialogData : public wxObject {
188 ~wxPrintDialogData();
190 void EnableHelp(bool flag);
191 void EnablePageNumbers(bool flag);
192 void EnablePrintToFile(bool flag);
193 void EnableSelection(bool flag);
201 %new wxPrintData* GetPrintData() {
202 return new wxPrintData(self->GetPrintData()); // force a copy
205 bool GetPrintToFile();
207 void SetCollate(bool flag);
208 void SetFromPage(int page);
209 void SetMaxPage(int page);
210 void SetMinPage(int page);
211 void SetNoCopies(int n);
212 void SetPrintData(const wxPrintData& printData);
213 void SetPrintToFile(bool flag);
214 void SetSetupDialog(bool flag);
215 void SetToPage(int page);
219 class wxPrintDialog : public wxDialog {
221 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
223 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
225 wxPrintDialogData& GetPrintDialogData();
226 %new wxDC* GetPrintDC();
230 //----------------------------------------------------------------------
231 //----------------------------------------------------------------------
232 // Custom wxPrintout class that knows how to call python
236 // Since this one would be tough and ugly to do with the Macros...
237 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
241 wxPyBeginBlockThreads();
242 if ((found = m_myInst.findCallback("GetPageInfo"))) {
243 PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
244 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
247 val = PyTuple_GetItem(result, 0);
248 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
251 val = PyTuple_GetItem(result, 1);
252 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
255 val = PyTuple_GetItem(result, 2);
256 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
259 val = PyTuple_GetItem(result, 3);
260 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
267 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
272 wxPyEndBlockThreads();
274 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
277 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
278 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
282 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
283 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
284 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
285 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
286 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
287 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
288 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
294 // Now define the custom class for SWIGging
295 %name(wxPrintout) class wxPyPrintout : public wxObject {
297 wxPyPrintout(const char* title = "Printout");
299 void _setCallbackInfo(PyObject* self, PyObject* _class);
300 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPrintout)"
303 void Destroy() { delete self; }
307 void GetPageSizeMM(int *OUTPUT, int *OUTPUT);
308 void GetPageSizePixels(int *OUTPUT, int *OUTPUT);
309 void GetPPIPrinter(int *OUTPUT, int *OUTPUT);
310 void GetPPIScreen(int *OUTPUT, int *OUTPUT);
313 bool base_OnBeginDocument(int startPage, int endPage);
314 void base_OnEndDocument();
315 void base_OnBeginPrinting();
316 void base_OnEndPrinting();
317 void base_OnPreparePrinting();
318 void base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
319 bool base_HasPage(int page);
322 //----------------------------------------------------------------------
324 class wxPrinter : public wxObject {
326 wxPrinter(wxPrintDialogData* data = NULL);
330 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
331 wxPrintDialogData& GetPrintDialogData();
332 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=TRUE);
333 wxDC* PrintDialog(wxWindow *parent);
334 void ReportError(wxWindow *parent, wxPyPrintout *printout, char* message);
335 bool Setup(wxWindow *parent);
338 //----------------------------------------------------------------------
340 class wxPrintPreview : public wxObject {
342 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
343 // ~wxPrintPreview(); **** ????
345 wxWindow* GetCanvas();
346 int GetCurrentPage();
347 wxFrame * GetFrame();
350 wxPrintDialogData& GetPrintDialogData();
351 wxPyPrintout * GetPrintout();
352 wxPyPrintout * GetPrintoutForPrinting();
355 bool Print(bool prompt);
356 void SetCanvas(wxWindow* window);
357 void SetCurrentPage(int pageNum);
358 void SetFrame(wxFrame *frame);
359 void SetPrintout(wxPyPrintout *printout);
360 void SetZoom(int percent);
363 //----------------------------------------------------------------------
365 class wxPreviewFrame : public wxFrame {
367 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
368 const wxPoint& pos = wxDefaultPosition,
369 const wxSize& size = wxDefaultSize,
370 long style = wxDEFAULT_FRAME_STYLE,
371 char* name = "frame");
373 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
377 // **** need to use derived class so these can be properly overridden:
378 //void CreateControlBar()
379 //void CreateCanvas()
383 //----------------------------------------------------------------------
386 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
389 //----------------------------------------------------------------------
390 //----------------------------------------------------------------------