]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/printfw.i
2.4 -> 2.5; build in another directory than source one; mention --disable-shared
[wxWidgets.git] / 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 #include <wx/dcps.h>
20
21 #include "printfw.h"
22 %}
23
24 //----------------------------------------------------------------------
25
26 %{
27 // Put some wx default wxChar* values into wxStrings.
28 static const wxChar* wxPrintoutTitleStr = wxT("Printout");
29 DECLARE_DEF_STRING(PrintoutTitleStr);
30
31 DECLARE_DEF_STRING(FrameNameStr);
32 %}
33
34 //----------------------------------------------------------------------
35
36 %include typemaps.i
37 %include my_typemaps.i
38
39 // Import some definitions of other classes, etc.
40 %import _defs.i
41 %import misc.i
42 %import windows.i
43 %import gdi.i
44 %import cmndlgs.i
45 %import frames.i
46
47
48 %pragma(python) code = "import wx"
49
50
51 //----------------------------------------------------------------------
52
53
54
55 class wxPrintData : public wxObject {
56 public:
57 wxPrintData();
58 ~wxPrintData();
59
60 int GetNoCopies();
61 bool GetCollate();
62 int GetOrientation();
63
64 bool Ok();
65
66 const wxString& GetPrinterName();
67 bool GetColour();
68 wxDuplexMode GetDuplex();
69 wxPaperSize GetPaperId();
70 const wxSize& GetPaperSize();
71
72 wxPrintQuality GetQuality();
73
74 void SetNoCopies(int v);
75 void SetCollate(bool flag);
76 void SetOrientation(int orient);
77
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);
84
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();
96
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);
109
110 };
111
112 //----------------------------------------------------------------------
113
114 #ifdef __WXMSW__
115 class wxPrinterDC : public wxDC {
116 public:
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);
123 };
124 #endif
125
126 //---------------------------------------------------------------------------
127
128 class wxPostScriptDC : public wxDC {
129 public:
130 wxPostScriptDC(const wxPrintData& printData);
131 // %name(wxPostScriptDC2)wxPostScriptDC(const wxString& output,
132 // bool interactive = TRUE,
133 // wxWindow* parent = NULL);
134
135 wxPrintData& GetPrintData();
136 void SetPrintData(const wxPrintData& data);
137
138 static void SetResolution(int ppi);
139 static int GetResolution();
140 };
141
142 //---------------------------------------------------------------------------
143
144 class wxPageSetupDialogData : public wxObject {
145 public:
146 wxPageSetupDialogData();
147 ~wxPageSetupDialogData();
148
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();
167 %addmethods {
168 %new wxPrintData* GetPrintData() {
169 return new wxPrintData(self->GetPrintData()); // force a copy
170 }
171 }
172
173 bool Ok();
174
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);
184 };
185
186
187 class wxPageSetupDialog : public wxDialog {
188 public:
189 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
190
191 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
192
193 wxPageSetupDialogData& GetPageSetupData();
194 int ShowModal();
195 };
196
197 //----------------------------------------------------------------------
198
199
200 class wxPrintDialogData : public wxObject {
201 public:
202 wxPrintDialogData();
203 ~wxPrintDialogData();
204
205 void EnableHelp(bool flag);
206 void EnablePageNumbers(bool flag);
207 void EnablePrintToFile(bool flag);
208 void EnableSelection(bool flag);
209 bool GetAllPages();
210 bool GetCollate();
211 int GetFromPage();
212 int GetMaxPage();
213 int GetMinPage();
214 int GetNoCopies();
215 %addmethods {
216 %new wxPrintData* GetPrintData() {
217 return new wxPrintData(self->GetPrintData()); // force a copy
218 }
219 }
220 bool GetPrintToFile();
221 int GetToPage();
222
223 bool Ok();
224
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);
234 };
235
236
237 class wxPrintDialog : public wxDialog {
238 public:
239 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
240
241 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
242
243 wxPrintDialogData& GetPrintDialogData();
244 %new wxDC* GetPrintDC();
245 int ShowModal();
246 };
247
248 //----------------------------------------------------------------------
249 //----------------------------------------------------------------------
250 // Custom wxPrintout class that knows how to call python
251 %{
252
253
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) {
256 bool hadErr = FALSE;
257 bool found;
258
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) {
263 PyObject* val;
264
265 val = PyTuple_GetItem(result, 0);
266 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
267 else hadErr = TRUE;
268
269 val = PyTuple_GetItem(result, 1);
270 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
271 else hadErr = TRUE;
272
273 val = PyTuple_GetItem(result, 2);
274 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
275 else hadErr = TRUE;
276
277 val = PyTuple_GetItem(result, 3);
278 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
279 else hadErr = TRUE;
280 }
281 else
282 hadErr = TRUE;
283
284 if (hadErr) {
285 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
286 PyErr_Print();
287 }
288 Py_DECREF(result);
289 }
290 wxPyEndBlockThreads();
291 if (! found)
292 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
293 }
294
295 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
296 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
297 }
298
299
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);
307
308
309 %}
310
311
312 // Now define the custom class for SWIGging
313 %name(wxPrintout) class wxPyPrintout : public wxObject {
314 public:
315 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
316
317 void _setCallbackInfo(PyObject* self, PyObject* _class);
318 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPrintout)"
319
320 %addmethods {
321 void Destroy() { delete self; }
322 }
323
324 wxDC* GetDC();
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);
329 bool IsPreview();
330
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);
338 };
339
340 //----------------------------------------------------------------------
341
342 class wxPrinter : public wxObject {
343 public:
344 wxPrinter(wxPrintDialogData* data = NULL);
345 ~wxPrinter();
346
347 // bool Abort();
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);
354 };
355
356 //----------------------------------------------------------------------
357
358 class wxPrintPreview : public wxObject {
359 public:
360 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
361 // ~wxPrintPreview(); **** ????
362
363 wxWindow* GetCanvas();
364 int GetCurrentPage();
365 wxFrame * GetFrame();
366 int GetMaxPage();
367 int GetMinPage();
368 wxPrintDialogData& GetPrintDialogData();
369 wxPyPrintout * GetPrintout();
370 wxPyPrintout * GetPrintoutForPrinting();
371 int GetZoom();
372 bool Ok();
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);
379 };
380
381 //----------------------------------------------------------------------
382
383 class wxPreviewFrame : public wxFrame {
384 public:
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);
390
391 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
392
393 void Initialize();
394
395 // **** need to use derived class so these can be properly overridden:
396 //void CreateControlBar()
397 //void CreateCanvas()
398
399 };
400
401 //----------------------------------------------------------------------
402
403 %init %{
404 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
405 %}
406
407 //----------------------------------------------------------------------
408 //----------------------------------------------------------------------
409
410
411
412