]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: _????.i | |
3 | // Purpose: SWIG interface for wx???? | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 9-Aug-2003 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %newgroup | |
18 | ||
19 | %{ | |
20 | #include "wx/wxPython/printfw.h" | |
21 | ||
22 | %} | |
23 | ||
24 | MAKE_CONST_WXSTRING2(PrintoutTitleStr, wxT("Printout")); | |
25 | MAKE_CONST_WXSTRING2(PreviewCanvasNameStr, wxT("previewcanvas")); | |
26 | ||
27 | ||
28 | //--------------------------------------------------------------------------- | |
29 | ||
30 | enum wxPrintMode | |
31 | { | |
32 | wxPRINT_MODE_NONE = 0, | |
33 | wxPRINT_MODE_PREVIEW = 1, // Preview in external application | |
34 | wxPRINT_MODE_FILE = 2, // Print to file | |
35 | wxPRINT_MODE_PRINTER = 3, // Send to printer | |
36 | wxPRINT_MODE_STREAM = 4 // Send postscript data into a stream | |
37 | }; | |
38 | ||
39 | enum wxPrintBin | |
40 | { | |
41 | wxPRINTBIN_DEFAULT, | |
42 | ||
43 | wxPRINTBIN_ONLYONE, | |
44 | wxPRINTBIN_LOWER, | |
45 | wxPRINTBIN_MIDDLE, | |
46 | wxPRINTBIN_MANUAL, | |
47 | wxPRINTBIN_ENVELOPE, | |
48 | wxPRINTBIN_ENVMANUAL, | |
49 | wxPRINTBIN_AUTO, | |
50 | wxPRINTBIN_TRACTOR, | |
51 | wxPRINTBIN_SMALLFMT, | |
52 | wxPRINTBIN_LARGEFMT, | |
53 | wxPRINTBIN_LARGECAPACITY, | |
54 | wxPRINTBIN_CASSETTE, | |
55 | wxPRINTBIN_FORMSOURCE, | |
56 | ||
57 | wxPRINTBIN_USER, | |
58 | }; | |
59 | ||
60 | ||
61 | class wxPrintData : public wxObject { | |
62 | public: | |
63 | %nokwargs wxPrintData; | |
64 | wxPrintData(); | |
65 | wxPrintData(const wxPrintData& data); // for making copies | |
66 | ||
67 | ~wxPrintData(); | |
68 | ||
69 | int GetNoCopies(); | |
70 | bool GetCollate(); | |
71 | int GetOrientation(); | |
72 | ||
73 | bool Ok(); | |
74 | ||
75 | const wxString& GetPrinterName(); | |
76 | bool GetColour(); | |
77 | wxDuplexMode GetDuplex(); | |
78 | wxPaperSize GetPaperId(); | |
79 | const wxSize& GetPaperSize(); | |
80 | ||
81 | int GetQuality(); | |
82 | wxPrintBin GetBin(); | |
83 | wxPrintMode GetPrintMode() const; | |
84 | ||
85 | void SetNoCopies(int v); | |
86 | void SetCollate(bool flag); | |
87 | void SetOrientation(int orient); | |
88 | ||
89 | void SetPrinterName(const wxString& name); | |
90 | void SetColour(bool colour); | |
91 | void SetDuplex(wxDuplexMode duplex); | |
92 | void SetPaperId(wxPaperSize sizeId); | |
93 | void SetPaperSize(const wxSize& sz); | |
94 | void SetQuality(int quality); | |
95 | void SetBin(wxPrintBin bin); | |
96 | void SetPrintMode(wxPrintMode printMode); | |
97 | ||
98 | wxString GetFilename() const; | |
99 | void SetFilename( const wxString &filename ); | |
100 | ||
101 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
102 | ||
103 | //char* GetPrivData() const; | |
104 | //int GetPrivDataLen() const; | |
105 | //void SetPrivData( char *privData, int len ); | |
106 | ||
107 | %extend { | |
108 | PyObject* GetPrivData() { | |
109 | PyObject* data; | |
110 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
111 | data = PyString_FromStringAndSize(self->GetPrivData(), | |
112 | self->GetPrivDataLen()); | |
113 | wxPyEndBlockThreads(blocked); | |
114 | return data; | |
115 | } | |
116 | ||
117 | void SetPrivData(PyObject* data) { | |
118 | if (! PyString_Check(data)) { | |
119 | wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError, | |
120 | "Expected string object")); | |
121 | return /* NULL */ ; | |
122 | } | |
123 | ||
124 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
125 | self->SetPrivData(PyString_AS_STRING(data), PyString_GET_SIZE(data)); | |
126 | wxPyEndBlockThreads(blocked); | |
127 | } | |
128 | } | |
129 | ||
130 | ||
131 | // NOTE: These are now inside of #if WXWIN_COMPATIBILITY_2_4, so be | |
132 | // prepared to remove them... | |
133 | ||
134 | // PostScript-specific data | |
135 | // WXWIN_COMPATIBILITY_2_4 | |
136 | #if 0 | |
137 | const wxString& GetPrinterCommand(); | |
138 | const wxString& GetPrinterOptions(); | |
139 | const wxString& GetPreviewCommand(); | |
140 | const wxString& GetFontMetricPath(); | |
141 | double GetPrinterScaleX(); | |
142 | double GetPrinterScaleY(); | |
143 | long GetPrinterTranslateX(); | |
144 | long GetPrinterTranslateY(); | |
145 | void SetPrinterCommand(const wxString& command); | |
146 | void SetPrinterOptions(const wxString& options); | |
147 | void SetPreviewCommand(const wxString& command); | |
148 | void SetFontMetricPath(const wxString& path); | |
149 | void SetPrinterScaleX(double x); | |
150 | void SetPrinterScaleY(double y); | |
151 | void SetPrinterScaling(double x, double y); | |
152 | void SetPrinterTranslateX(long x); | |
153 | void SetPrinterTranslateY(long y); | |
154 | void SetPrinterTranslation(long x, long y); | |
155 | #endif | |
156 | ||
157 | }; | |
158 | ||
159 | //--------------------------------------------------------------------------- | |
160 | ||
161 | class wxPageSetupDialogData : public wxObject { | |
162 | public: | |
163 | %nokwargs wxPageSetupDialogData; | |
164 | wxPageSetupDialogData(); | |
165 | wxPageSetupDialogData(const wxPageSetupDialogData& data); // for making copies | |
166 | wxPageSetupDialogData(const wxPrintData& data); | |
167 | ~wxPageSetupDialogData(); | |
168 | ||
169 | void EnableHelp(bool flag); | |
170 | void EnableMargins(bool flag); | |
171 | void EnableOrientation(bool flag); | |
172 | void EnablePaper(bool flag); | |
173 | void EnablePrinter(bool flag); | |
174 | ||
175 | bool GetDefaultMinMargins(); | |
176 | bool GetEnableMargins(); | |
177 | bool GetEnableOrientation(); | |
178 | bool GetEnablePaper(); | |
179 | bool GetEnablePrinter(); | |
180 | bool GetEnableHelp(); | |
181 | bool GetDefaultInfo(); | |
182 | wxPoint GetMarginTopLeft(); | |
183 | wxPoint GetMarginBottomRight(); | |
184 | wxPoint GetMinMarginTopLeft(); | |
185 | wxPoint GetMinMarginBottomRight(); | |
186 | wxPaperSize GetPaperId(); | |
187 | wxSize GetPaperSize(); | |
188 | ||
189 | wxPrintData& GetPrintData(); | |
190 | ||
191 | bool Ok(); | |
192 | ||
193 | void SetDefaultInfo(bool flag); | |
194 | void SetDefaultMinMargins(bool flag); | |
195 | void SetMarginTopLeft(const wxPoint& pt); | |
196 | void SetMarginBottomRight(const wxPoint& pt); | |
197 | void SetMinMarginTopLeft(const wxPoint& pt); | |
198 | void SetMinMarginBottomRight(const wxPoint& pt); | |
199 | void SetPaperId(wxPaperSize id); | |
200 | void SetPaperSize(const wxSize& size); | |
201 | ||
202 | void SetPrintData(const wxPrintData& printData); | |
203 | ||
204 | // Use paper size defined in this object to set the wxPrintData | |
205 | // paper id | |
206 | void CalculateIdFromPaperSize(); | |
207 | ||
208 | // Use paper id in wxPrintData to set this object's paper size | |
209 | void CalculatePaperSizeFromId(); | |
210 | ||
211 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
212 | }; | |
213 | ||
214 | ||
215 | ||
216 | // NOTE: Contrary to it's name, this class doesn't derive from wxDialog. It | |
217 | // is a facade in front of a platform-specific (native dialog) provided by the | |
218 | // wxPrintFactory. | |
219 | ||
220 | MustHaveApp(wxPageSetupDialog); | |
221 | ||
222 | class wxPageSetupDialog : public wxObject | |
223 | { | |
224 | public: | |
225 | wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL); | |
226 | ||
227 | wxPageSetupDialogData& GetPageSetupData(); | |
228 | wxPageSetupDialogData& GetPageSetupDialogData(); | |
229 | int ShowModal(); | |
230 | }; | |
231 | ||
232 | //--------------------------------------------------------------------------- | |
233 | ||
234 | ||
235 | class wxPrintDialogData : public wxObject { | |
236 | public: | |
237 | %nokwargs wxPrintDialogData; | |
238 | wxPrintDialogData(); | |
239 | wxPrintDialogData(const wxPrintData& printData); | |
240 | wxPrintDialogData(const wxPrintDialogData& printData); // for making copies | |
241 | ~wxPrintDialogData(); | |
242 | ||
243 | int GetFromPage() const; | |
244 | int GetToPage() const; | |
245 | int GetMinPage() const; | |
246 | int GetMaxPage() const; | |
247 | int GetNoCopies() const; | |
248 | bool GetAllPages() const; | |
249 | bool GetSelection() const; | |
250 | bool GetCollate() const; | |
251 | bool GetPrintToFile() const; | |
252 | ||
253 | // WXWIN_COMPATIBILITY_2_4 | |
254 | #if 0 | |
255 | bool GetSetupDialog() const; | |
256 | void SetSetupDialog(bool flag); | |
257 | #endif | |
258 | void SetFromPage(int v); | |
259 | void SetToPage(int v); | |
260 | void SetMinPage(int v); | |
261 | void SetMaxPage(int v); | |
262 | void SetNoCopies(int v); | |
263 | void SetAllPages(bool flag); | |
264 | void SetSelection(bool flag); | |
265 | void SetCollate(bool flag); | |
266 | void SetPrintToFile(bool flag); | |
267 | ||
268 | void EnablePrintToFile(bool flag); | |
269 | void EnableSelection(bool flag); | |
270 | void EnablePageNumbers(bool flag); | |
271 | void EnableHelp(bool flag); | |
272 | ||
273 | bool GetEnablePrintToFile() const; | |
274 | bool GetEnableSelection() const; | |
275 | bool GetEnablePageNumbers() const; | |
276 | bool GetEnableHelp() const; | |
277 | ||
278 | // Is this data OK for showing the print dialog? | |
279 | bool Ok() const; | |
280 | ||
281 | ||
282 | wxPrintData& GetPrintData(); | |
283 | void SetPrintData(const wxPrintData& printData); | |
284 | ||
285 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
286 | }; | |
287 | ||
288 | ||
289 | ||
290 | MustHaveApp(wxPrintDialog); | |
291 | ||
292 | ||
293 | // NOTE: Contrary to it's name, this class doesn't derive from wxDialog. It | |
294 | // is a facade in front of a platform-specific (native dialog) provided by the | |
295 | // wxPrintFactory. | |
296 | ||
297 | class wxPrintDialog : public wxObject { | |
298 | public: | |
299 | wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL); | |
300 | ||
301 | // TODO?: wxPrintDialog(wxWindow *parent, wxPrintData* data); | |
302 | ||
303 | virtual int ShowModal(); | |
304 | ||
305 | virtual wxPrintDialogData& GetPrintDialogData(); | |
306 | virtual wxPrintData& GetPrintData(); | |
307 | ||
308 | %newobject GetPrintDC; | |
309 | virtual wxDC *GetPrintDC(); | |
310 | ||
311 | }; | |
312 | ||
313 | ||
314 | //--------------------------------------------------------------------------- | |
315 | //--------------------------------------------------------------------------- | |
316 | ||
317 | ||
318 | enum wxPrinterError | |
319 | { | |
320 | wxPRINTER_NO_ERROR = 0, | |
321 | wxPRINTER_CANCELLED, | |
322 | wxPRINTER_ERROR | |
323 | }; | |
324 | ||
325 | ||
326 | MustHaveApp(wxPrinter); | |
327 | ||
328 | class wxPrinter : public wxObject { | |
329 | public: | |
330 | wxPrinter(wxPrintDialogData* data = NULL); | |
331 | ~wxPrinter(); | |
332 | ||
333 | virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPyPrintout *printout); | |
334 | virtual void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message); | |
335 | ||
336 | virtual bool Setup(wxWindow *parent); | |
337 | virtual bool Print(wxWindow *parent, wxPyPrintout *printout, bool prompt = true); | |
338 | virtual wxDC* PrintDialog(wxWindow *parent); | |
339 | ||
340 | virtual wxPrintDialogData& GetPrintDialogData() const; | |
341 | ||
342 | bool GetAbort(); | |
343 | static wxPrinterError GetLastError(); | |
344 | }; | |
345 | ||
346 | ||
347 | //--------------------------------------------------------------------------- | |
348 | // Custom wxPrintout class that knows how to call python, See implementation in | |
349 | // include/sx/wxPython/printfw.h | |
350 | ||
351 | %{ | |
352 | ||
353 | IMPLEMENT_ABSTRACT_CLASS(wxPyPrintout, wxPrintout); | |
354 | ||
355 | // Since this one would be tough and ugly to do with the Macros... | |
356 | void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { | |
357 | bool hadErr = false; | |
358 | bool found; | |
359 | ||
360 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
361 | if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) { | |
362 | PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); | |
363 | if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) { | |
364 | PyObject* val; | |
365 | ||
366 | val = PyTuple_GetItem(result, 0); | |
367 | if (PyInt_Check(val)) *minPage = PyInt_AsLong(val); | |
368 | else hadErr = true; | |
369 | ||
370 | val = PyTuple_GetItem(result, 1); | |
371 | if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val); | |
372 | else hadErr = true; | |
373 | ||
374 | val = PyTuple_GetItem(result, 2); | |
375 | if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val); | |
376 | else hadErr = true; | |
377 | ||
378 | val = PyTuple_GetItem(result, 3); | |
379 | if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val); | |
380 | else hadErr = true; | |
381 | } | |
382 | else | |
383 | hadErr = true; | |
384 | ||
385 | if (hadErr) { | |
386 | PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers."); | |
387 | PyErr_Print(); | |
388 | } | |
389 | Py_DECREF(result); | |
390 | } | |
391 | wxPyEndBlockThreads(blocked); | |
392 | if (! found) | |
393 | wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); | |
394 | } | |
395 | ||
396 | void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { | |
397 | wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); | |
398 | } | |
399 | ||
400 | ||
401 | IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument); | |
402 | IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument); | |
403 | IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting); | |
404 | IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting); | |
405 | IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting); | |
406 | IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage); | |
407 | IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage); | |
408 | ||
409 | ||
410 | %} | |
411 | ||
412 | ||
413 | MustHaveApp(wxPyPrintout); | |
414 | ||
415 | // Now define the custom class for SWIGging | |
416 | %rename(Printout) wxPyPrintout; | |
417 | class wxPyPrintout : public wxObject { | |
418 | public: | |
419 | %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)" | |
420 | ||
421 | wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr); | |
422 | //~wxPyPrintout(); wxPrintPreview object takes ownership... | |
423 | ||
424 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
425 | ||
426 | ||
427 | wxString GetTitle() const; | |
428 | wxDC* GetDC(); | |
429 | void SetDC(wxDC *dc); | |
430 | ||
431 | void SetPageSizePixels(int w, int h); | |
432 | DocDeclA( | |
433 | void, GetPageSizePixels(int *OUTPUT, int *OUTPUT), | |
434 | "GetPageSizePixels() -> (w, h)"); | |
435 | ||
436 | void SetPageSizeMM(int w, int h); | |
437 | DocDeclA( | |
438 | void, GetPageSizeMM(int *OUTPUT, int *OUTPUT), | |
439 | "GetPageSizeMM() -> (w, h)"); | |
440 | ||
441 | void SetPPIScreen(int x, int y); | |
442 | DocDeclA( | |
443 | void, GetPPIScreen(int *OUTPUT, int *OUTPUT), | |
444 | "GetPPIScreen() -> (x,y)"); | |
445 | ||
446 | void SetPPIPrinter(int x, int y); | |
447 | DocDeclA( | |
448 | void, GetPPIPrinter(int *OUTPUT, int *OUTPUT), | |
449 | "GetPPIPrinter() -> (x,y)"); | |
450 | ||
451 | bool IsPreview(); | |
452 | void SetIsPreview(bool p); | |
453 | ||
454 | ||
455 | bool base_OnBeginDocument(int startPage, int endPage); | |
456 | void base_OnEndDocument(); | |
457 | void base_OnBeginPrinting(); | |
458 | void base_OnEndPrinting(); | |
459 | void base_OnPreparePrinting(); | |
460 | bool base_HasPage(int page); | |
461 | DocDeclA( | |
462 | void, base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT), | |
463 | "base_GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)"); | |
464 | }; | |
465 | ||
466 | //--------------------------------------------------------------------------- | |
467 | ||
468 | ||
469 | ||
470 | MustHaveApp(wxPreviewCanvas); | |
471 | ||
472 | class wxPreviewCanvas: public wxScrolledWindow | |
473 | { | |
474 | public: | |
475 | %pythonAppend wxPreviewCanvas "self._setOORInfo(self)" | |
476 | ||
477 | wxPreviewCanvas(wxPrintPreview *preview, | |
478 | wxWindow *parent, | |
479 | const wxPoint& pos = wxDefaultPosition, | |
480 | const wxSize& size = wxDefaultSize, | |
481 | long style = 0, | |
482 | const wxString& name = wxPyPreviewCanvasNameStr); | |
483 | }; | |
484 | ||
485 | ||
486 | MustHaveApp(wxPreviewFrame); | |
487 | ||
488 | class wxPreviewFrame : public wxFrame { | |
489 | public: | |
490 | %pythonAppend wxPreviewFrame "self._setOORInfo(self)" | |
491 | ||
492 | wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title, | |
493 | const wxPoint& pos = wxDefaultPosition, | |
494 | const wxSize& size = wxDefaultSize, | |
495 | long style = wxDEFAULT_FRAME_STYLE, | |
496 | const wxString& name = wxPyFrameNameStr); | |
497 | ||
498 | void Initialize(); | |
499 | void CreateControlBar(); | |
500 | void CreateCanvas(); | |
501 | ||
502 | wxPreviewControlBar* GetControlBar() const; | |
503 | }; | |
504 | ||
505 | ||
506 | ||
507 | enum { | |
508 | wxPREVIEW_PRINT, | |
509 | wxPREVIEW_PREVIOUS, | |
510 | wxPREVIEW_NEXT, | |
511 | wxPREVIEW_ZOOM, | |
512 | wxPREVIEW_FIRST, | |
513 | wxPREVIEW_LAST, | |
514 | wxPREVIEW_GOTO, | |
515 | wxPREVIEW_DEFAULT, | |
516 | ||
517 | wxID_PREVIEW_CLOSE, | |
518 | wxID_PREVIEW_NEXT, | |
519 | wxID_PREVIEW_PREVIOUS, | |
520 | wxID_PREVIEW_PRINT, | |
521 | wxID_PREVIEW_ZOOM, | |
522 | wxID_PREVIEW_FIRST, | |
523 | wxID_PREVIEW_LAST, | |
524 | wxID_PREVIEW_GOTO | |
525 | }; | |
526 | ||
527 | MustHaveApp(wxPreviewControlBar); | |
528 | ||
529 | class wxPreviewControlBar: public wxPanel | |
530 | { | |
531 | public: | |
532 | %pythonAppend wxPreviewControlBar "self._setOORInfo(self)" | |
533 | ||
534 | wxPreviewControlBar(wxPrintPreview *preview, | |
535 | long buttons, | |
536 | wxWindow *parent, | |
537 | const wxPoint& pos = wxDefaultPosition, | |
538 | const wxSize& size = wxDefaultSize, | |
539 | long style = wxTAB_TRAVERSAL, | |
540 | const wxString& name = wxPyPanelNameStr); | |
541 | ||
542 | int GetZoomControl(); | |
543 | void SetZoomControl(int zoom); | |
544 | wxPrintPreview* GetPrintPreview(); | |
545 | ||
546 | void OnNext(); | |
547 | void OnPrevious(); | |
548 | void OnFirst(); | |
549 | void OnLast(); | |
550 | void OnGoto(); | |
551 | }; | |
552 | ||
553 | ||
554 | ||
555 | //--------------------------------------------------------------------------- | |
556 | ||
557 | MustHaveApp(wxPrintPreview); | |
558 | ||
559 | class wxPrintPreview : public wxObject { | |
560 | public: | |
561 | %nokwargs wxPrintPreview; | |
562 | wxPrintPreview(wxPyPrintout* printout, | |
563 | wxPyPrintout* printoutForPrinting, | |
564 | wxPrintDialogData *data=NULL); | |
565 | wxPrintPreview(wxPyPrintout* printout, | |
566 | wxPyPrintout* printoutForPrinting, | |
567 | wxPrintData* data); | |
568 | ||
569 | virtual bool SetCurrentPage(int pageNum); | |
570 | int GetCurrentPage(); | |
571 | ||
572 | void SetPrintout(wxPyPrintout *printout); | |
573 | wxPyPrintout *GetPrintout(); | |
574 | wxPyPrintout *GetPrintoutForPrinting(); | |
575 | ||
576 | void SetFrame(wxFrame *frame); | |
577 | void SetCanvas(wxPreviewCanvas *canvas); | |
578 | ||
579 | virtual wxFrame *GetFrame(); | |
580 | virtual wxPreviewCanvas *GetCanvas(); | |
581 | ||
582 | // The preview canvas should call this from OnPaint | |
583 | virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc); | |
584 | ||
585 | // This draws a blank page onto the preview canvas | |
586 | virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc); | |
587 | ||
588 | // This is called by wxPrintPreview to render a page into a wxMemoryDC. | |
589 | virtual bool RenderPage(int pageNum); | |
590 | ||
591 | // Adjusts the scrollbars for the current scale | |
592 | virtual void AdjustScrollbars(wxPreviewCanvas *canvas); | |
593 | ||
594 | wxPrintDialogData& GetPrintDialogData(); | |
595 | ||
596 | virtual void SetZoom(int percent); | |
597 | int GetZoom(); | |
598 | ||
599 | int GetMaxPage(); | |
600 | int GetMinPage(); | |
601 | ||
602 | bool Ok(); | |
603 | void SetOk(bool ok); | |
604 | ||
605 | virtual bool Print(bool interactive); | |
606 | virtual void DetermineScaling(); | |
607 | ||
608 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
609 | }; | |
610 | ||
611 | ||
612 | ||
613 | //--------------------------------------------------------------------------- | |
614 | ||
615 | // Python-derivable versions of the above preview classes | |
616 | ||
617 | %{ | |
618 | ||
619 | #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \ | |
620 | bool CBNAME(wxPreviewCanvas* a, wxDC& b); \ | |
621 | bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b) | |
622 | ||
623 | ||
624 | #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \ | |
625 | bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \ | |
626 | bool rval=false; \ | |
627 | bool found; \ | |
628 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); \ | |
629 | if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ | |
630 | PyObject* win = wxPyMake_wxObject(a,false); \ | |
631 | PyObject* dc = wxPyMake_wxObject(&b,false); \ | |
632 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc)); \ | |
633 | Py_DECREF(win); \ | |
634 | Py_DECREF(dc); \ | |
635 | } \ | |
636 | wxPyEndBlockThreads(blocked); \ | |
637 | if (! found) \ | |
638 | rval = PCLASS::CBNAME(a, b); \ | |
639 | return rval; \ | |
640 | } \ | |
641 | bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) { \ | |
642 | return PCLASS::CBNAME(a, b); \ | |
643 | } | |
644 | ||
645 | ||
646 | ||
647 | ||
648 | class wxPyPrintPreview : public wxPrintPreview | |
649 | { | |
650 | DECLARE_CLASS(wxPyPrintPreview) | |
651 | public: | |
652 | wxPyPrintPreview(wxPyPrintout* printout, | |
653 | wxPyPrintout* printoutForPrinting, | |
654 | wxPrintDialogData* data=NULL) | |
655 | : wxPrintPreview(printout, printoutForPrinting, data) | |
656 | {} | |
657 | wxPyPrintPreview(wxPyPrintout* printout, | |
658 | wxPyPrintout* printoutForPrinting, | |
659 | wxPrintData* data=NULL) | |
660 | : wxPrintPreview(printout, printoutForPrinting, data) | |
661 | {} | |
662 | ||
663 | DEC_PYCALLBACK_BOOL_INT(SetCurrentPage); | |
664 | DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage); | |
665 | DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage); | |
666 | DEC_PYCALLBACK_BOOL_INT(RenderPage); | |
667 | DEC_PYCALLBACK_VOID_INT(SetZoom); | |
668 | DEC_PYCALLBACK_BOOL_BOOL(Print); | |
669 | DEC_PYCALLBACK_VOID_(DetermineScaling); | |
670 | ||
671 | PYPRIVATE; | |
672 | }; | |
673 | ||
674 | // Stupid renamed classes... Fix this in 2.5... | |
675 | #if defined(__WXMSW__) | |
676 | IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview ); | |
677 | #elif defined(__WXMAC__) | |
678 | IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview ); | |
679 | #else | |
680 | IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview ); | |
681 | #endif | |
682 | ||
683 | IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage); | |
684 | IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage); | |
685 | IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage); | |
686 | IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage); | |
687 | IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom); | |
688 | IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print); | |
689 | IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling); | |
690 | %} | |
691 | ||
692 | ||
693 | MustHaveApp(wxPyPrintPreview); | |
694 | ||
695 | class wxPyPrintPreview : public wxPrintPreview | |
696 | { | |
697 | public: | |
698 | %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)" | |
699 | %nokwargs wxPyPrintPreview; | |
700 | wxPyPrintPreview(wxPyPrintout* printout, | |
701 | wxPyPrintout* printoutForPrinting, | |
702 | wxPrintDialogData* data=NULL); | |
703 | wxPyPrintPreview(wxPyPrintout* printout, | |
704 | wxPyPrintout* printoutForPrinting, | |
705 | wxPrintData* data); | |
706 | ||
707 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
708 | ||
709 | bool base_SetCurrentPage(int pageNum); | |
710 | bool base_PaintPage(wxPreviewCanvas *canvas, wxDC& dc); | |
711 | bool base_DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc); | |
712 | bool base_RenderPage(int pageNum); | |
713 | void base_SetZoom(int percent); | |
714 | bool base_Print(bool interactive); | |
715 | void base_DetermineScaling(); | |
716 | }; | |
717 | ||
718 | ||
719 | ||
720 | ||
721 | %{ | |
722 | class wxPyPreviewFrame : public wxPreviewFrame | |
723 | { | |
724 | DECLARE_CLASS(wxPyPreviewFrame); | |
725 | public: | |
726 | wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent, | |
727 | const wxString& title, | |
728 | const wxPoint& pos = wxDefaultPosition, | |
729 | const wxSize& size = wxDefaultSize, | |
730 | long style = wxDEFAULT_FRAME_STYLE, | |
731 | const wxString& name = wxPyFrameNameStr) | |
732 | : wxPreviewFrame(preview, parent, title, pos, size, style, name) | |
733 | {} | |
734 | ||
735 | void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; } | |
736 | void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; } | |
737 | ||
738 | DEC_PYCALLBACK_VOID_(Initialize); | |
739 | DEC_PYCALLBACK_VOID_(CreateCanvas); | |
740 | DEC_PYCALLBACK_VOID_(CreateControlBar); | |
741 | ||
742 | PYPRIVATE; | |
743 | }; | |
744 | ||
745 | IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame); | |
746 | ||
747 | IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize); | |
748 | IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas); | |
749 | IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar); | |
750 | %} | |
751 | ||
752 | ||
753 | MustHaveApp(wxPyPreviewFrame); | |
754 | ||
755 | class wxPyPreviewFrame : public wxPreviewFrame | |
756 | { | |
757 | public: | |
758 | %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)" | |
759 | ||
760 | wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent, | |
761 | const wxString& title, | |
762 | const wxPoint& pos = wxDefaultPosition, | |
763 | const wxSize& size = wxDefaultSize, | |
764 | long style = wxDEFAULT_FRAME_STYLE, | |
765 | const wxString& name = wxPyFrameNameStr); | |
766 | ||
767 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
768 | ||
769 | void SetPreviewCanvas(wxPreviewCanvas* canvas); | |
770 | void SetControlBar(wxPreviewControlBar* bar); | |
771 | ||
772 | void base_Initialize(); | |
773 | void base_CreateCanvas(); | |
774 | void base_CreateControlBar(); | |
775 | }; | |
776 | ||
777 | ||
778 | ||
779 | ||
780 | %{ | |
781 | class wxPyPreviewControlBar : public wxPreviewControlBar | |
782 | { | |
783 | DECLARE_CLASS(wxPyPreviewControlBar); | |
784 | public: | |
785 | wxPyPreviewControlBar(wxPrintPreview *preview, | |
786 | long buttons, | |
787 | wxWindow *parent, | |
788 | const wxPoint& pos = wxDefaultPosition, | |
789 | const wxSize& size = wxDefaultSize, | |
790 | long style = 0, | |
791 | const wxString& name = wxPyPanelNameStr) | |
792 | : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name) | |
793 | {} | |
794 | ||
795 | void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; } | |
796 | ||
797 | DEC_PYCALLBACK_VOID_(CreateButtons); | |
798 | DEC_PYCALLBACK_VOID_INT(SetZoomControl); | |
799 | ||
800 | PYPRIVATE; | |
801 | }; | |
802 | ||
803 | IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar); | |
804 | IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons); | |
805 | IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl); | |
806 | %} | |
807 | ||
808 | ||
809 | MustHaveApp(wxPyPreviewControlBar); | |
810 | ||
811 | class wxPyPreviewControlBar : public wxPreviewControlBar | |
812 | { | |
813 | public: | |
814 | %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)" | |
815 | ||
816 | wxPyPreviewControlBar(wxPrintPreview *preview, | |
817 | long buttons, | |
818 | wxWindow *parent, | |
819 | const wxPoint& pos = wxDefaultPosition, | |
820 | const wxSize& size = wxDefaultSize, | |
821 | long style = 0, | |
822 | const wxString& name = wxPyPanelNameStr); | |
823 | ||
824 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
825 | ||
826 | void SetPrintPreview(wxPrintPreview* preview); | |
827 | ||
828 | void base_CreateButtons(); | |
829 | void base_SetZoomControl(int zoom); | |
830 | }; | |
831 | ||
832 | //--------------------------------------------------------------------------- | |
833 | //--------------------------------------------------------------------------- | |
834 | %init %{ | |
835 | wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout"); | |
836 | %} | |
837 | //--------------------------------------------------------------------------- |