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 // Put some wx default wxChar* values into wxStrings.
28 static const wxChar* wxPrintoutTitleStr = wxT("Printout");
29 DECLARE_DEF_STRING(PrintoutTitleStr);
31 DECLARE_DEF_STRING(FrameNameStr);
34 //----------------------------------------------------------------------
37 %include my_typemaps.i
39 // Import some definitions of other classes, etc.
48 %pragma(python) code = "import wx"
51 //----------------------------------------------------------------------
55 class wxPrintData : public wxObject {
66 const wxString& GetPrinterName();
68 wxDuplexMode GetDuplex();
69 wxPaperSize GetPaperId();
70 const wxSize& GetPaperSize();
72 wxPrintQuality GetQuality();
74 void SetNoCopies(int v);
75 void SetCollate(bool flag);
76 void SetOrientation(int orient);
78 void SetPrinterName(const wxString& name);
79 void SetColour(bool colour);
80 void SetDuplex(wxDuplexMode duplex);
81 void SetPaperId(wxPaperSize sizeId);
82 void SetPaperSize(const wxSize& sz);
83 void SetQuality(wxPrintQuality quality);
85 // PostScript-specific data
86 const wxString& GetPrinterCommand();
87 const wxString& GetPrinterOptions();
88 const wxString& GetPreviewCommand();
89 const wxString& GetFilename();
90 const wxString& GetFontMetricPath();
91 double GetPrinterScaleX();
92 double GetPrinterScaleY();
93 long GetPrinterTranslateX();
94 long GetPrinterTranslateY();
95 wxPrintMode GetPrintMode();
97 void SetPrinterCommand(const wxString& command);
98 void SetPrinterOptions(const wxString& options);
99 void SetPreviewCommand(const wxString& command);
100 void SetFilename(const wxString& filename);
101 void SetFontMetricPath(const wxString& path);
102 void SetPrinterScaleX(double x);
103 void SetPrinterScaleY(double y);
104 void SetPrinterScaling(double x, double y);
105 void SetPrinterTranslateX(long x);
106 void SetPrinterTranslateY(long y);
107 void SetPrinterTranslation(long x, long y);
108 void SetPrintMode(wxPrintMode printMode);
112 //----------------------------------------------------------------------
115 class wxPrinterDC : public wxDC {
117 wxPrinterDC(const wxPrintData& printData);
118 %name(wxPrinterDC2) wxPrinterDC(const wxString& driver,
119 const wxString& device,
120 const wxString& output,
121 bool interactive = TRUE,
122 int orientation = wxPORTRAIT);
126 //---------------------------------------------------------------------------
128 class wxPostScriptDC : public wxDC {
130 wxPostScriptDC(const wxPrintData& printData);
131 %name(wxPostScriptDC2)wxPostScriptDC(const wxString& output,
132 bool interactive = TRUE,
133 wxWindow* parent = NULL);
135 wxPrintData& GetPrintData();
136 void SetPrintData(const wxPrintData& data);
138 static void SetResolution(int ppi);
139 static int GetResolution();
142 //---------------------------------------------------------------------------
144 class wxPageSetupDialogData : public wxObject {
146 wxPageSetupDialogData();
147 ~wxPageSetupDialogData();
149 void EnableHelp(bool flag);
150 void EnableMargins(bool flag);
151 void EnableOrientation(bool flag);
152 void EnablePaper(bool flag);
153 void EnablePrinter(bool flag);
154 bool GetDefaultMinMargins();
155 bool GetEnableMargins();
156 bool GetEnableOrientation();
157 bool GetEnablePaper();
158 bool GetEnablePrinter();
159 bool GetEnableHelp();
160 bool GetDefaultInfo();
161 wxPoint GetMarginTopLeft();
162 wxPoint GetMarginBottomRight();
163 wxPoint GetMinMarginTopLeft();
164 wxPoint GetMinMarginBottomRight();
165 wxPaperSize GetPaperId();
166 wxSize GetPaperSize();
168 %new wxPrintData* GetPrintData() {
169 return new wxPrintData(self->GetPrintData()); // force a copy
175 void SetDefaultInfo(bool flag);
176 void SetDefaultMinMargins(bool flag);
177 void SetMarginTopLeft(const wxPoint& pt);
178 void SetMarginBottomRight(const wxPoint& pt);
179 void SetMinMarginTopLeft(const wxPoint& pt);
180 void SetMinMarginBottomRight(const wxPoint& pt);
181 void SetPaperId(wxPaperSize id);
182 void SetPaperSize(const wxSize& size);
183 void SetPrintData(const wxPrintData& printData);
187 class wxPageSetupDialog : public wxDialog {
189 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
191 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
193 wxPageSetupDialogData& GetPageSetupData();
197 //----------------------------------------------------------------------
200 class wxPrintDialogData : public wxObject {
203 ~wxPrintDialogData();
205 void EnableHelp(bool flag);
206 void EnablePageNumbers(bool flag);
207 void EnablePrintToFile(bool flag);
208 void EnableSelection(bool flag);
216 %new wxPrintData* GetPrintData() {
217 return new wxPrintData(self->GetPrintData()); // force a copy
220 bool GetPrintToFile();
225 void SetCollate(bool flag);
226 void SetFromPage(int page);
227 void SetMaxPage(int page);
228 void SetMinPage(int page);
229 void SetNoCopies(int n);
230 void SetPrintData(const wxPrintData& printData);
231 void SetPrintToFile(bool flag);
232 void SetSetupDialog(bool flag);
233 void SetToPage(int page);
237 class wxPrintDialog : public wxDialog {
239 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
241 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
243 wxPrintDialogData& GetPrintDialogData();
244 %new wxDC* GetPrintDC();
248 //----------------------------------------------------------------------
249 //----------------------------------------------------------------------
250 // Custom wxPrintout class that knows how to call python
254 // Since this one would be tough and ugly to do with the Macros...
255 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
259 wxPyBeginBlockThreads();
260 if ((found = m_myInst.findCallback("GetPageInfo"))) {
261 PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
262 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
265 val = PyTuple_GetItem(result, 0);
266 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
269 val = PyTuple_GetItem(result, 1);
270 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
273 val = PyTuple_GetItem(result, 2);
274 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
277 val = PyTuple_GetItem(result, 3);
278 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
285 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
290 wxPyEndBlockThreads();
292 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
295 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
296 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
300 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
301 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
302 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
303 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
304 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
305 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
306 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
312 // Now define the custom class for SWIGging
313 %name(wxPrintout) class wxPyPrintout : public wxObject {
315 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
317 void _setCallbackInfo(PyObject* self, PyObject* _class);
318 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPrintout)"
321 void Destroy() { delete self; }
325 void GetPageSizeMM(int *OUTPUT, int *OUTPUT);
326 void GetPageSizePixels(int *OUTPUT, int *OUTPUT);
327 void GetPPIPrinter(int *OUTPUT, int *OUTPUT);
328 void GetPPIScreen(int *OUTPUT, int *OUTPUT);
331 bool base_OnBeginDocument(int startPage, int endPage);
332 void base_OnEndDocument();
333 void base_OnBeginPrinting();
334 void base_OnEndPrinting();
335 void base_OnPreparePrinting();
336 void base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
337 bool base_HasPage(int page);
340 //----------------------------------------------------------------------
342 class wxPrinter : public wxObject {
344 wxPrinter(wxPrintDialogData* data = NULL);
348 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
349 wxPrintDialogData& GetPrintDialogData();
350 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=TRUE);
351 wxDC* PrintDialog(wxWindow *parent);
352 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
353 bool Setup(wxWindow *parent);
356 //----------------------------------------------------------------------
358 class wxPrintPreview : public wxObject {
360 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
361 // ~wxPrintPreview(); **** ????
363 wxWindow* GetCanvas();
364 int GetCurrentPage();
365 wxFrame * GetFrame();
368 wxPrintDialogData& GetPrintDialogData();
369 wxPyPrintout * GetPrintout();
370 wxPyPrintout * GetPrintoutForPrinting();
373 bool Print(bool prompt);
374 void SetCanvas(wxWindow* window);
375 void SetCurrentPage(int pageNum);
376 void SetFrame(wxFrame *frame);
377 void SetPrintout(wxPyPrintout *printout);
378 void SetZoom(int percent);
381 //----------------------------------------------------------------------
383 class wxPreviewFrame : public wxFrame {
385 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
386 const wxPoint& pos = wxDefaultPosition,
387 const wxSize& size = wxDefaultSize,
388 long style = wxDEFAULT_FRAME_STYLE,
389 const wxString& name = wxPyFrameNameStr);
391 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
395 // **** need to use derived class so these can be properly overridden:
396 //void CreateControlBar()
397 //void CreateCanvas()
401 //----------------------------------------------------------------------
404 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
407 //----------------------------------------------------------------------
408 //----------------------------------------------------------------------