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 {
64 const wxString& GetPrinterName();
66 wxDuplexMode GetDuplex();
67 wxPaperSize GetPaperId();
68 const wxSize& GetPaperSize();
70 wxPrintQuality GetQuality();
72 void SetNoCopies(int v);
73 void SetCollate(bool flag);
74 void SetOrientation(int orient);
76 void SetPrinterName(const wxString& name);
77 void SetColour(bool colour);
78 void SetDuplex(wxDuplexMode duplex);
79 void SetPaperId(wxPaperSize sizeId);
80 void SetPaperSize(const wxSize& sz);
81 void SetQuality(wxPrintQuality quality);
83 // PostScript-specific data
84 const wxString& GetPrinterCommand();
85 const wxString& GetPrinterOptions();
86 const wxString& GetPreviewCommand();
87 const wxString& GetFilename();
88 const wxString& GetFontMetricPath();
89 double GetPrinterScaleX();
90 double GetPrinterScaleY();
91 long GetPrinterTranslateX();
92 long GetPrinterTranslateY();
93 wxPrintMode GetPrintMode();
95 void SetPrinterCommand(const wxString& command);
96 void SetPrinterOptions(const wxString& options);
97 void SetPreviewCommand(const wxString& command);
98 void SetFilename(const wxString& filename);
99 void SetFontMetricPath(const wxString& path);
100 void SetPrinterScaleX(double x);
101 void SetPrinterScaleY(double y);
102 void SetPrinterScaling(double x, double y);
103 void SetPrinterTranslateX(long x);
104 void SetPrinterTranslateY(long y);
105 void SetPrinterTranslation(long x, long y);
106 void SetPrintMode(wxPrintMode printMode);
110 //----------------------------------------------------------------------
113 class wxPrinterDC : public wxDC {
115 wxPrinterDC(const wxPrintData& printData);
116 %name(wxPrinterDC2) wxPrinterDC(const wxString& driver,
117 const wxString& device,
118 const wxString& output,
119 bool interactive = TRUE,
120 int orientation = wxPORTRAIT);
124 //---------------------------------------------------------------------------
126 class wxPostScriptDC : public wxDC {
128 wxPostScriptDC(const wxPrintData& printData);
129 %name(wxPostScriptDC2)wxPostScriptDC(const wxString& output,
130 bool interactive = TRUE,
131 wxWindow* parent = NULL);
133 wxPrintData& GetPrintData();
134 void SetPrintData(const wxPrintData& data);
136 static void SetResolution(int ppi);
137 static int GetResolution();
140 //---------------------------------------------------------------------------
142 class wxPageSetupDialogData : public wxObject {
144 wxPageSetupDialogData();
145 ~wxPageSetupDialogData();
147 void EnableHelp(bool flag);
148 void EnableMargins(bool flag);
149 void EnableOrientation(bool flag);
150 void EnablePaper(bool flag);
151 void EnablePrinter(bool flag);
152 bool GetDefaultMinMargins();
153 bool GetEnableMargins();
154 bool GetEnableOrientation();
155 bool GetEnablePaper();
156 bool GetEnablePrinter();
157 bool GetEnableHelp();
158 bool GetDefaultInfo();
159 wxPoint GetMarginTopLeft();
160 wxPoint GetMarginBottomRight();
161 wxPoint GetMinMarginTopLeft();
162 wxPoint GetMinMarginBottomRight();
163 wxPaperSize GetPaperId();
164 wxSize GetPaperSize();
166 %new wxPrintData* GetPrintData() {
167 return new wxPrintData(self->GetPrintData()); // force a copy
170 void SetDefaultInfo(bool flag);
171 void SetDefaultMinMargins(bool flag);
172 void SetMarginTopLeft(const wxPoint& pt);
173 void SetMarginBottomRight(const wxPoint& pt);
174 void SetMinMarginTopLeft(const wxPoint& pt);
175 void SetMinMarginBottomRight(const wxPoint& pt);
176 void SetPaperId(wxPaperSize id);
177 void SetPaperSize(const wxSize& size);
178 void SetPrintData(const wxPrintData& printData);
182 class wxPageSetupDialog : public wxDialog {
184 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
186 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
188 wxPageSetupDialogData& GetPageSetupData();
192 //----------------------------------------------------------------------
195 class wxPrintDialogData : public wxObject {
198 ~wxPrintDialogData();
200 void EnableHelp(bool flag);
201 void EnablePageNumbers(bool flag);
202 void EnablePrintToFile(bool flag);
203 void EnableSelection(bool flag);
211 %new wxPrintData* GetPrintData() {
212 return new wxPrintData(self->GetPrintData()); // force a copy
215 bool GetPrintToFile();
217 void SetCollate(bool flag);
218 void SetFromPage(int page);
219 void SetMaxPage(int page);
220 void SetMinPage(int page);
221 void SetNoCopies(int n);
222 void SetPrintData(const wxPrintData& printData);
223 void SetPrintToFile(bool flag);
224 void SetSetupDialog(bool flag);
225 void SetToPage(int page);
229 class wxPrintDialog : public wxDialog {
231 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
233 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
235 wxPrintDialogData& GetPrintDialogData();
236 %new wxDC* GetPrintDC();
240 //----------------------------------------------------------------------
241 //----------------------------------------------------------------------
242 // Custom wxPrintout class that knows how to call python
246 // Since this one would be tough and ugly to do with the Macros...
247 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
251 wxPyBeginBlockThreads();
252 if ((found = m_myInst.findCallback("GetPageInfo"))) {
253 PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
254 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
257 val = PyTuple_GetItem(result, 0);
258 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
261 val = PyTuple_GetItem(result, 1);
262 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
265 val = PyTuple_GetItem(result, 2);
266 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
269 val = PyTuple_GetItem(result, 3);
270 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
277 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
282 wxPyEndBlockThreads();
284 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
287 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
288 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
292 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
293 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
294 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
295 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
296 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
297 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
298 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
304 // Now define the custom class for SWIGging
305 %name(wxPrintout) class wxPyPrintout : public wxObject {
307 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
309 void _setCallbackInfo(PyObject* self, PyObject* _class);
310 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPrintout)"
313 void Destroy() { delete self; }
317 void GetPageSizeMM(int *OUTPUT, int *OUTPUT);
318 void GetPageSizePixels(int *OUTPUT, int *OUTPUT);
319 void GetPPIPrinter(int *OUTPUT, int *OUTPUT);
320 void GetPPIScreen(int *OUTPUT, int *OUTPUT);
323 bool base_OnBeginDocument(int startPage, int endPage);
324 void base_OnEndDocument();
325 void base_OnBeginPrinting();
326 void base_OnEndPrinting();
327 void base_OnPreparePrinting();
328 void base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
329 bool base_HasPage(int page);
332 //----------------------------------------------------------------------
334 class wxPrinter : public wxObject {
336 wxPrinter(wxPrintDialogData* data = NULL);
340 void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
341 wxPrintDialogData& GetPrintDialogData();
342 bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=TRUE);
343 wxDC* PrintDialog(wxWindow *parent);
344 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
345 bool Setup(wxWindow *parent);
348 //----------------------------------------------------------------------
350 class wxPrintPreview : public wxObject {
352 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
353 // ~wxPrintPreview(); **** ????
355 wxWindow* GetCanvas();
356 int GetCurrentPage();
357 wxFrame * GetFrame();
360 wxPrintDialogData& GetPrintDialogData();
361 wxPyPrintout * GetPrintout();
362 wxPyPrintout * GetPrintoutForPrinting();
365 bool Print(bool prompt);
366 void SetCanvas(wxWindow* window);
367 void SetCurrentPage(int pageNum);
368 void SetFrame(wxFrame *frame);
369 void SetPrintout(wxPyPrintout *printout);
370 void SetZoom(int percent);
373 //----------------------------------------------------------------------
375 class wxPreviewFrame : public wxFrame {
377 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
378 const wxPoint& pos = wxDefaultPosition,
379 const wxSize& size = wxDefaultSize,
380 long style = wxDEFAULT_FRAME_STYLE,
381 const wxString& name = wxPyFrameNameStr);
383 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
387 // **** need to use derived class so these can be properly overridden:
388 //void CreateControlBar()
389 //void CreateCanvas()
393 //----------------------------------------------------------------------
396 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
399 //----------------------------------------------------------------------
400 //----------------------------------------------------------------------