]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/printfw.i
Use the OOR typemap for wxTreeCtrls too.
[wxWidgets.git] / wxPython / src / printfw.i
CommitLineData
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
137b5242
RD
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
bb0054cd
RD
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
9416aa89 55class wxPrintData : public wxObject {
bb0054cd
RD
56public:
57 wxPrintData();
58 ~wxPrintData();
59
60 int GetNoCopies();
61 bool GetCollate();
62 int GetOrientation();
63
64 const wxString& GetPrinterName();
65 bool GetColour();
66 wxDuplexMode GetDuplex();
67 wxPaperSize GetPaperId();
68 const wxSize& GetPaperSize();
69
70 wxPrintQuality GetQuality();
71
72 void SetNoCopies(int v);
73 void SetCollate(bool flag);
74 void SetOrientation(int orient);
75
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);
82
926bb76c
RD
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();
94
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);
bb0054cd
RD
107
108};
109
110//----------------------------------------------------------------------
111
1b62f00d
RD
112#ifdef __WXMSW__
113class wxPrinterDC : public wxDC {
114public:
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);
121};
122#endif
123
124//---------------------------------------------------------------------------
125
eedf876b
RD
126class wxPostScriptDC : public wxDC {
127public:
128 wxPostScriptDC(const wxPrintData& printData);
129 %name(wxPostScriptDC2)wxPostScriptDC(const wxString& output,
130 bool interactive = TRUE,
131 wxWindow* parent = NULL);
132
133 wxPrintData& GetPrintData();
134 void SetPrintData(const wxPrintData& data);
135
136 static void SetResolution(int ppi);
137 static int GetResolution();
138};
139
140//---------------------------------------------------------------------------
141
9416aa89 142class wxPageSetupDialogData : public wxObject {
bb0054cd
RD
143public:
144 wxPageSetupDialogData();
145 ~wxPageSetupDialogData();
146
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();
165 %addmethods {
166 %new wxPrintData* GetPrintData() {
167 return new wxPrintData(self->GetPrintData()); // force a copy
168 }
169 }
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);
3ca6a5f0 176 void SetPaperId(wxPaperSize id);
bb0054cd
RD
177 void SetPaperSize(const wxSize& size);
178 void SetPrintData(const wxPrintData& printData);
179};
180
181
182class wxPageSetupDialog : public wxDialog {
183public:
184 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
185
f6bcfd97 186 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
bb0054cd
RD
187
188 wxPageSetupDialogData& GetPageSetupData();
189 int ShowModal();
190};
191
192//----------------------------------------------------------------------
193
194
9416aa89 195class wxPrintDialogData : public wxObject {
bb0054cd
RD
196public:
197 wxPrintDialogData();
198 ~wxPrintDialogData();
199
200 void EnableHelp(bool flag);
201 void EnablePageNumbers(bool flag);
202 void EnablePrintToFile(bool flag);
203 void EnableSelection(bool flag);
204 bool GetAllPages();
205 bool GetCollate();
206 int GetFromPage();
207 int GetMaxPage();
208 int GetMinPage();
209 int GetNoCopies();
210 %addmethods {
211 %new wxPrintData* GetPrintData() {
212 return new wxPrintData(self->GetPrintData()); // force a copy
213 }
214 }
215 bool GetPrintToFile();
216 int GetToPage();
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);
226};
227
228
229class wxPrintDialog : public wxDialog {
230public:
231 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
232
f6bcfd97 233 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
bb0054cd
RD
234
235 wxPrintDialogData& GetPrintDialogData();
236 %new wxDC* GetPrintDC();
237 int ShowModal();
238};
239
240//----------------------------------------------------------------------
241//----------------------------------------------------------------------
242// Custom wxPrintout class that knows how to call python
243%{
2abc0a0f
RD
244
245
246// Since this one would be tough and ugly to do with the Macros...
247void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
194fa2ac 248 bool hadErr = FALSE;
19a97bd6 249 bool found;
2abc0a0f 250
4268f798 251 wxPyBeginBlockThreads();
19a97bd6 252 if ((found = m_myInst.findCallback("GetPageInfo"))) {
2abc0a0f
RD
253 PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
254 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
255 PyObject* val;
256
257 val = PyTuple_GetItem(result, 0);
258 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
194fa2ac 259 else hadErr = TRUE;
2abc0a0f
RD
260
261 val = PyTuple_GetItem(result, 1);
262 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
194fa2ac 263 else hadErr = TRUE;
2abc0a0f
RD
264
265 val = PyTuple_GetItem(result, 2);
266 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
194fa2ac 267 else hadErr = TRUE;
2abc0a0f
RD
268
269 val = PyTuple_GetItem(result, 3);
270 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
194fa2ac 271 else hadErr = TRUE;
bb0054cd
RD
272 }
273 else
194fa2ac 274 hadErr = TRUE;
1afc06c2 275
2abc0a0f
RD
276 if (hadErr) {
277 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
278 PyErr_Print();
279 }
280 Py_DECREF(result);
bb0054cd 281 }
4268f798 282 wxPyEndBlockThreads();
19a97bd6 283 if (! found)
bb0054cd 284 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
2abc0a0f
RD
285}
286
287void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
288 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
289}
290
1afc06c2
RD
291
292IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
293IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
294IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
295IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
296IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
297IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
298IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
299
300
bb0054cd
RD
301%}
302
303
304// Now define the custom class for SWIGging
9416aa89 305%name(wxPrintout) class wxPyPrintout : public wxObject {
bb0054cd 306public:
137b5242 307 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
bb0054cd 308
0122b7e3
RD
309 void _setCallbackInfo(PyObject* self, PyObject* _class);
310 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPrintout)"
bb0054cd
RD
311
312 %addmethods {
efc5f224 313 void Destroy() { delete self; }
bb0054cd
RD
314 }
315
316 wxDC* GetDC();
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);
321 bool IsPreview();
322
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);
330};
331
332//----------------------------------------------------------------------
333
9416aa89 334class wxPrinter : public wxObject {
bb0054cd
RD
335public:
336 wxPrinter(wxPrintDialogData* data = NULL);
337 ~wxPrinter();
338
339// bool Abort();
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);
137b5242 344 void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
bb0054cd
RD
345 bool Setup(wxWindow *parent);
346};
347
348//----------------------------------------------------------------------
349
9416aa89 350class wxPrintPreview : public wxObject {
bb0054cd
RD
351public:
352 wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
353// ~wxPrintPreview(); **** ????
354
355 wxWindow* GetCanvas();
356 int GetCurrentPage();
357 wxFrame * GetFrame();
358 int GetMaxPage();
359 int GetMinPage();
360 wxPrintDialogData& GetPrintDialogData();
361 wxPyPrintout * GetPrintout();
362 wxPyPrintout * GetPrintoutForPrinting();
363 int GetZoom();
364 bool Ok();
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);
371};
372
373//----------------------------------------------------------------------
374
375class wxPreviewFrame : public wxFrame {
376public:
377 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
b68dc582
RD
378 const wxPoint& pos = wxDefaultPosition,
379 const wxSize& size = wxDefaultSize,
bb0054cd 380 long style = wxDEFAULT_FRAME_STYLE,
137b5242 381 const wxString& name = wxPyFrameNameStr);
bb0054cd 382
0122b7e3 383 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
bb0054cd
RD
384
385 void Initialize();
386
387 // **** need to use derived class so these can be properly overridden:
388 //void CreateControlBar()
389 //void CreateCanvas()
390
391};
392
393//----------------------------------------------------------------------
9416aa89
RD
394
395%init %{
396 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
397%}
398
bb0054cd
RD
399//----------------------------------------------------------------------
400//----------------------------------------------------------------------
401
402
403
404