]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/printfw.i
minor fixes
[wxWidgets.git] / utils / wxPython / src / printfw.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: printfw.i
3 // Purpose: Printing Framework classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7-May-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module printfw
14
15 %{
16 #include "helpers.h"
17 #include <wx/print.h>
18 #include <wx/printdlg.h>
19 %}
20
21 //----------------------------------------------------------------------
22
23 %include typemaps.i
24 %include my_typemaps.i
25
26 // Import some definitions of other classes, etc.
27 %import _defs.i
28 %import misc.i
29 %import windows.i
30 %import gdi.i
31 %import cmndlgs.i
32 %import frames.i
33
34
35 %pragma(python) code = "import wx"
36
37
38 //----------------------------------------------------------------------
39
40
41
42 class wxPrintData {
43 public:
44 wxPrintData();
45 ~wxPrintData();
46
47 int GetNoCopies();
48 bool GetCollate();
49 int GetOrientation();
50
51 const wxString& GetPrinterName();
52 bool GetColour();
53 wxDuplexMode GetDuplex();
54 wxPaperSize GetPaperId();
55 const wxSize& GetPaperSize();
56
57 wxPrintQuality GetQuality();
58
59 void SetNoCopies(int v);
60 void SetCollate(bool flag);
61 void SetOrientation(int orient);
62
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);
69
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();
81
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);
94
95 };
96
97 //----------------------------------------------------------------------
98
99 class wxPageSetupDialogData {
100 public:
101 wxPageSetupDialogData();
102 ~wxPageSetupDialogData();
103
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();
122 %addmethods {
123 %new wxPrintData* GetPrintData() {
124 return new wxPrintData(self->GetPrintData()); // force a copy
125 }
126 }
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);
136 };
137
138
139 class wxPageSetupDialog : public wxDialog {
140 public:
141 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
142
143 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
144
145 wxPageSetupDialogData& GetPageSetupData();
146 int ShowModal();
147 };
148
149 //----------------------------------------------------------------------
150
151
152 class wxPrintDialogData {
153 public:
154 wxPrintDialogData();
155 ~wxPrintDialogData();
156
157 void EnableHelp(bool flag);
158 void EnablePageNumbers(bool flag);
159 void EnablePrintToFile(bool flag);
160 void EnableSelection(bool flag);
161 bool GetAllPages();
162 bool GetCollate();
163 int GetFromPage();
164 int GetMaxPage();
165 int GetMinPage();
166 int GetNoCopies();
167 %addmethods {
168 %new wxPrintData* GetPrintData() {
169 return new wxPrintData(self->GetPrintData()); // force a copy
170 }
171 }
172 bool GetPrintToFile();
173 int GetToPage();
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);
183 };
184
185
186 class wxPrintDialog : public wxDialog {
187 public:
188 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
189
190 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
191
192 wxPrintDialogData& GetPrintDialogData();
193 %new wxDC* GetPrintDC();
194 int ShowModal();
195 };
196
197 //----------------------------------------------------------------------
198 //----------------------------------------------------------------------
199 // Custom wxPrintout class that knows how to call python
200 %{
201 class wxPyPrintout : public wxPrintout {
202 public:
203 wxPyPrintout(const wxString& title) : wxPrintout(title) {}
204
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);
212
213
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) {
216 bool hadErr = false;
217
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) {
222 PyObject* val;
223
224 val = PyTuple_GetItem(result, 0);
225 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
226 else hadErr = true;
227
228 val = PyTuple_GetItem(result, 1);
229 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
230 else hadErr = true;
231
232 val = PyTuple_GetItem(result, 2);
233 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
234 else hadErr = true;
235
236 val = PyTuple_GetItem(result, 3);
237 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
238 else hadErr = true;
239 }
240 else
241 hadErr = true;
242
243 if (hadErr) {
244 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
245 PyErr_Print();
246 }
247 Py_DECREF(result);
248 }
249 else
250 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
251
252 wxPySaveThread(doSave);
253 }
254
255 void base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
256 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
257 }
258
259 PYPRIVATE;
260 };
261
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);
269
270
271 %}
272
273
274 // Now define the custom class for SWIGging
275 %name(wxPrintout) class wxPyPrintout {
276 public:
277 wxPyPrintout(const char* title = "Printout");
278
279 void _setSelf(PyObject* self);
280 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
281
282 %addmethods {
283 void Destroy() { delete self; }
284 }
285
286 wxDC* GetDC();
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);
291 bool IsPreview();
292
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);
300 };
301
302 //----------------------------------------------------------------------
303
304 class wxPrinter {
305 public:
306 wxPrinter(wxPrintDialogData* data = NULL);
307 ~wxPrinter();
308
309 // bool Abort();
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);
316 };
317
318 //----------------------------------------------------------------------
319
320 class wxPrintPreview {
321 public:
322 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
323 // ~wxPrintPreview(); **** ????
324
325 wxWindow* GetCanvas();
326 int GetCurrentPage();
327 wxFrame * GetFrame();
328 int GetMaxPage();
329 int GetMinPage();
330 wxPrintDialogData& GetPrintDialogData();
331 wxPyPrintout * GetPrintout();
332 wxPyPrintout * GetPrintoutForPrinting();
333 int GetZoom();
334 bool Ok();
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);
341 };
342
343 //----------------------------------------------------------------------
344
345 class wxPreviewFrame : public wxFrame {
346 public:
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");
352
353 %pragma(python) addtomethod = "__init__:wx._StdFrameCallbacks(self)"
354
355 void Initialize();
356
357 // **** need to use derived class so these can be properly overridden:
358 //void CreateControlBar()
359 //void CreateCanvas()
360
361 };
362
363 //----------------------------------------------------------------------
364 //----------------------------------------------------------------------
365 //----------------------------------------------------------------------
366
367
368
369