Commit | Line | Data |
---|---|---|
bb0054cd RD |
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> | |
eedf876b | 19 | #include <wx/dcps.h> |
2abc0a0f RD |
20 | |
21 | #include "printfw.h" | |
bb0054cd RD |
22 | %} |
23 | ||
24 | //---------------------------------------------------------------------- | |
25 | ||
26 | %include typemaps.i | |
27 | %include my_typemaps.i | |
28 | ||
29 | // Import some definitions of other classes, etc. | |
30 | %import _defs.i | |
31 | %import misc.i | |
32 | %import windows.i | |
33 | %import gdi.i | |
34 | %import cmndlgs.i | |
35 | %import frames.i | |
36 | ||
37 | ||
38 | %pragma(python) code = "import wx" | |
39 | ||
40 | ||
41 | //---------------------------------------------------------------------- | |
42 | ||
43 | ||
44 | ||
9416aa89 | 45 | class wxPrintData : public wxObject { |
bb0054cd RD |
46 | public: |
47 | wxPrintData(); | |
48 | ~wxPrintData(); | |
49 | ||
50 | int GetNoCopies(); | |
51 | bool GetCollate(); | |
52 | int GetOrientation(); | |
53 | ||
54 | const wxString& GetPrinterName(); | |
55 | bool GetColour(); | |
56 | wxDuplexMode GetDuplex(); | |
57 | wxPaperSize GetPaperId(); | |
58 | const wxSize& GetPaperSize(); | |
59 | ||
60 | wxPrintQuality GetQuality(); | |
61 | ||
62 | void SetNoCopies(int v); | |
63 | void SetCollate(bool flag); | |
64 | void SetOrientation(int orient); | |
65 | ||
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); | |
72 | ||
926bb76c RD |
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(); | |
84 | ||
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); | |
bb0054cd RD |
97 | |
98 | }; | |
99 | ||
100 | //---------------------------------------------------------------------- | |
101 | ||
1b62f00d RD |
102 | #ifdef __WXMSW__ |
103 | class wxPrinterDC : public wxDC { | |
104 | public: | |
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); | |
111 | }; | |
112 | #endif | |
113 | ||
114 | //--------------------------------------------------------------------------- | |
115 | ||
eedf876b RD |
116 | class wxPostScriptDC : public wxDC { |
117 | public: | |
118 | wxPostScriptDC(const wxPrintData& printData); | |
119 | %name(wxPostScriptDC2)wxPostScriptDC(const wxString& output, | |
120 | bool interactive = TRUE, | |
121 | wxWindow* parent = NULL); | |
122 | ||
123 | wxPrintData& GetPrintData(); | |
124 | void SetPrintData(const wxPrintData& data); | |
125 | ||
126 | static void SetResolution(int ppi); | |
127 | static int GetResolution(); | |
128 | }; | |
129 | ||
130 | //--------------------------------------------------------------------------- | |
131 | ||
9416aa89 | 132 | class wxPageSetupDialogData : public wxObject { |
bb0054cd RD |
133 | public: |
134 | wxPageSetupDialogData(); | |
135 | ~wxPageSetupDialogData(); | |
136 | ||
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(); | |
155 | %addmethods { | |
156 | %new wxPrintData* GetPrintData() { | |
157 | return new wxPrintData(self->GetPrintData()); // force a copy | |
158 | } | |
159 | } | |
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); | |
3ca6a5f0 | 166 | void SetPaperId(wxPaperSize id); |
bb0054cd RD |
167 | void SetPaperSize(const wxSize& size); |
168 | void SetPrintData(const wxPrintData& printData); | |
169 | }; | |
170 | ||
171 | ||
172 | class wxPageSetupDialog : public wxDialog { | |
173 | public: | |
174 | wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL); | |
175 | ||
f6bcfd97 | 176 | %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)" |
bb0054cd RD |
177 | |
178 | wxPageSetupDialogData& GetPageSetupData(); | |
179 | int ShowModal(); | |
180 | }; | |
181 | ||
182 | //---------------------------------------------------------------------- | |
183 | ||
184 | ||
9416aa89 | 185 | class wxPrintDialogData : public wxObject { |
bb0054cd RD |
186 | public: |
187 | wxPrintDialogData(); | |
188 | ~wxPrintDialogData(); | |
189 | ||
190 | void EnableHelp(bool flag); | |
191 | void EnablePageNumbers(bool flag); | |
192 | void EnablePrintToFile(bool flag); | |
193 | void EnableSelection(bool flag); | |
194 | bool GetAllPages(); | |
195 | bool GetCollate(); | |
196 | int GetFromPage(); | |
197 | int GetMaxPage(); | |
198 | int GetMinPage(); | |
199 | int GetNoCopies(); | |
200 | %addmethods { | |
201 | %new wxPrintData* GetPrintData() { | |
202 | return new wxPrintData(self->GetPrintData()); // force a copy | |
203 | } | |
204 | } | |
205 | bool GetPrintToFile(); | |
206 | int GetToPage(); | |
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); | |
216 | }; | |
217 | ||
218 | ||
219 | class wxPrintDialog : public wxDialog { | |
220 | public: | |
221 | wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL); | |
222 | ||
f6bcfd97 | 223 | %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)" |
bb0054cd RD |
224 | |
225 | wxPrintDialogData& GetPrintDialogData(); | |
226 | %new wxDC* GetPrintDC(); | |
227 | int ShowModal(); | |
228 | }; | |
229 | ||
230 | //---------------------------------------------------------------------- | |
231 | //---------------------------------------------------------------------- | |
232 | // Custom wxPrintout class that knows how to call python | |
233 | %{ | |
2abc0a0f RD |
234 | |
235 | ||
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) { | |
194fa2ac | 238 | bool hadErr = FALSE; |
19a97bd6 | 239 | bool found; |
2abc0a0f | 240 | |
19a97bd6 RD |
241 | wxPyTState* state = wxPyBeginBlockThreads(); |
242 | if ((found = m_myInst.findCallback("GetPageInfo"))) { | |
2abc0a0f RD |
243 | PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()")); |
244 | if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) { | |
245 | PyObject* val; | |
246 | ||
247 | val = PyTuple_GetItem(result, 0); | |
248 | if (PyInt_Check(val)) *minPage = PyInt_AsLong(val); | |
194fa2ac | 249 | else hadErr = TRUE; |
2abc0a0f RD |
250 | |
251 | val = PyTuple_GetItem(result, 1); | |
252 | if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val); | |
194fa2ac | 253 | else hadErr = TRUE; |
2abc0a0f RD |
254 | |
255 | val = PyTuple_GetItem(result, 2); | |
256 | if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val); | |
194fa2ac | 257 | else hadErr = TRUE; |
2abc0a0f RD |
258 | |
259 | val = PyTuple_GetItem(result, 3); | |
260 | if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val); | |
194fa2ac | 261 | else hadErr = TRUE; |
bb0054cd RD |
262 | } |
263 | else | |
194fa2ac | 264 | hadErr = TRUE; |
1afc06c2 | 265 | |
2abc0a0f RD |
266 | if (hadErr) { |
267 | PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers."); | |
268 | PyErr_Print(); | |
269 | } | |
270 | Py_DECREF(result); | |
bb0054cd | 271 | } |
19a97bd6 RD |
272 | wxPyEndBlockThreads(state); |
273 | if (! found) | |
bb0054cd | 274 | wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); |
2abc0a0f RD |
275 | } |
276 | ||
277 | void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { | |
278 | wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); | |
279 | } | |
280 | ||
1afc06c2 RD |
281 | |
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); | |
289 | ||
290 | ||
bb0054cd RD |
291 | %} |
292 | ||
293 | ||
294 | // Now define the custom class for SWIGging | |
9416aa89 | 295 | %name(wxPrintout) class wxPyPrintout : public wxObject { |
bb0054cd RD |
296 | public: |
297 | wxPyPrintout(const char* title = "Printout"); | |
298 | ||
0122b7e3 RD |
299 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
300 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPrintout)" | |
bb0054cd RD |
301 | |
302 | %addmethods { | |
efc5f224 | 303 | void Destroy() { delete self; } |
bb0054cd RD |
304 | } |
305 | ||
306 | wxDC* GetDC(); | |
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); | |
311 | bool IsPreview(); | |
312 | ||
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); | |
320 | }; | |
321 | ||
322 | //---------------------------------------------------------------------- | |
323 | ||
9416aa89 | 324 | class wxPrinter : public wxObject { |
bb0054cd RD |
325 | public: |
326 | wxPrinter(wxPrintDialogData* data = NULL); | |
327 | ~wxPrinter(); | |
328 | ||
329 | // bool Abort(); | |
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); | |
336 | }; | |
337 | ||
338 | //---------------------------------------------------------------------- | |
339 | ||
9416aa89 | 340 | class wxPrintPreview : public wxObject { |
bb0054cd RD |
341 | public: |
342 | wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL); | |
343 | // ~wxPrintPreview(); **** ???? | |
344 | ||
345 | wxWindow* GetCanvas(); | |
346 | int GetCurrentPage(); | |
347 | wxFrame * GetFrame(); | |
348 | int GetMaxPage(); | |
349 | int GetMinPage(); | |
350 | wxPrintDialogData& GetPrintDialogData(); | |
351 | wxPyPrintout * GetPrintout(); | |
352 | wxPyPrintout * GetPrintoutForPrinting(); | |
353 | int GetZoom(); | |
354 | bool Ok(); | |
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); | |
361 | }; | |
362 | ||
363 | //---------------------------------------------------------------------- | |
364 | ||
365 | class wxPreviewFrame : public wxFrame { | |
366 | public: | |
367 | wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title, | |
b68dc582 RD |
368 | const wxPoint& pos = wxDefaultPosition, |
369 | const wxSize& size = wxDefaultSize, | |
bb0054cd RD |
370 | long style = wxDEFAULT_FRAME_STYLE, |
371 | char* name = "frame"); | |
372 | ||
0122b7e3 | 373 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" |
bb0054cd RD |
374 | |
375 | void Initialize(); | |
376 | ||
377 | // **** need to use derived class so these can be properly overridden: | |
378 | //void CreateControlBar() | |
379 | //void CreateCanvas() | |
380 | ||
381 | }; | |
382 | ||
383 | //---------------------------------------------------------------------- | |
9416aa89 RD |
384 | |
385 | %init %{ | |
386 | wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout"); | |
387 | %} | |
388 | ||
bb0054cd RD |
389 | //---------------------------------------------------------------------- |
390 | //---------------------------------------------------------------------- | |
391 | ||
392 | ||
393 | ||
394 |