]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_printfw.i
Disown the preview object when calling wxPyPreviewFrame ctor
[wxWidgets.git] / wxPython / src / _printfw.i
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 IsOk();
74 %pythoncode { Ok = IsOk }
75
76 const wxString& GetPrinterName();
77 bool GetColour();
78 wxDuplexMode GetDuplex();
79 wxPaperSize GetPaperId();
80 const wxSize& GetPaperSize();
81
82 int GetQuality();
83 wxPrintBin GetBin();
84 wxPrintMode GetPrintMode() const;
85 int GetMedia() const;
86
87 void SetNoCopies(int v);
88 void SetCollate(bool flag);
89 void SetOrientation(int orient);
90
91 void SetPrinterName(const wxString& name);
92 void SetColour(bool colour);
93 void SetDuplex(wxDuplexMode duplex);
94 void SetPaperId(wxPaperSize sizeId);
95 void SetPaperSize(const wxSize& sz);
96 void SetQuality(int quality);
97 void SetBin(wxPrintBin bin);
98 void SetPrintMode(wxPrintMode printMode);
99 void SetMedia(int media);
100
101 wxString GetFilename() const;
102 void SetFilename( const wxString &filename );
103
104 %pythoncode { def __nonzero__(self): return self.IsOk() }
105
106 //char* GetPrivData() const;
107 //int GetPrivDataLen() const;
108 //void SetPrivData( char *privData, int len );
109
110 %extend {
111 PyObject* GetPrivData() {
112 PyObject* data;
113 wxPyBlock_t blocked = wxPyBeginBlockThreads();
114 data = PyString_FromStringAndSize(self->GetPrivData(),
115 self->GetPrivDataLen());
116 wxPyEndBlockThreads(blocked);
117 return data;
118 }
119
120 void SetPrivData(PyObject* data) {
121 if (! PyString_Check(data)) {
122 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
123 "Expected string object"));
124 return /* NULL */ ;
125 }
126
127 wxPyBlock_t blocked = wxPyBeginBlockThreads();
128 self->SetPrivData(PyString_AS_STRING(data), PyString_GET_SIZE(data));
129 wxPyEndBlockThreads(blocked);
130 }
131 }
132
133
134 // NOTE: These are now inside of #if WXWIN_COMPATIBILITY_2_4, so be
135 // prepared to remove them...
136
137 // PostScript-specific data
138 // WXWIN_COMPATIBILITY_2_4
139 #if 0
140 const wxString& GetPrinterCommand();
141 const wxString& GetPrinterOptions();
142 const wxString& GetPreviewCommand();
143 const wxString& GetFontMetricPath();
144 double GetPrinterScaleX();
145 double GetPrinterScaleY();
146 long GetPrinterTranslateX();
147 long GetPrinterTranslateY();
148 void SetPrinterCommand(const wxString& command);
149 void SetPrinterOptions(const wxString& options);
150 void SetPreviewCommand(const wxString& command);
151 void SetFontMetricPath(const wxString& path);
152 void SetPrinterScaleX(double x);
153 void SetPrinterScaleY(double y);
154 void SetPrinterScaling(double x, double y);
155 void SetPrinterTranslateX(long x);
156 void SetPrinterTranslateY(long y);
157 void SetPrinterTranslation(long x, long y);
158 #endif
159
160 %property(Bin, GetBin, SetBin, doc="See `GetBin` and `SetBin`");
161 %property(Collate, GetCollate, SetCollate, doc="See `GetCollate` and `SetCollate`");
162 %property(Colour, GetColour, SetColour, doc="See `GetColour` and `SetColour`");
163 %property(Duplex, GetDuplex, SetDuplex, doc="See `GetDuplex` and `SetDuplex`");
164 %property(Filename, GetFilename, SetFilename, doc="See `GetFilename` and `SetFilename`");
165 %property(NoCopies, GetNoCopies, SetNoCopies, doc="See `GetNoCopies` and `SetNoCopies`");
166 %property(Orientation, GetOrientation, SetOrientation, doc="See `GetOrientation` and `SetOrientation`");
167 %property(PaperId, GetPaperId, SetPaperId, doc="See `GetPaperId` and `SetPaperId`");
168 %property(PaperSize, GetPaperSize, SetPaperSize, doc="See `GetPaperSize` and `SetPaperSize`");
169 %property(PrintMode, GetPrintMode, SetPrintMode, doc="See `GetPrintMode` and `SetPrintMode`");
170 %property(PrinterName, GetPrinterName, SetPrinterName, doc="See `GetPrinterName` and `SetPrinterName`");
171 %property(PrivData, GetPrivData, SetPrivData, doc="See `GetPrivData` and `SetPrivData`");
172 %property(Quality, GetQuality, SetQuality, doc="See `GetQuality` and `SetQuality`");
173 };
174
175 //---------------------------------------------------------------------------
176
177 class wxPageSetupDialogData : public wxObject {
178 public:
179 %nokwargs wxPageSetupDialogData;
180 wxPageSetupDialogData();
181 wxPageSetupDialogData(const wxPageSetupDialogData& data); // for making copies
182 wxPageSetupDialogData(const wxPrintData& data);
183 ~wxPageSetupDialogData();
184
185 void EnableHelp(bool flag);
186 void EnableMargins(bool flag);
187 void EnableOrientation(bool flag);
188 void EnablePaper(bool flag);
189 void EnablePrinter(bool flag);
190
191 bool GetDefaultMinMargins();
192 bool GetEnableMargins();
193 bool GetEnableOrientation();
194 bool GetEnablePaper();
195 bool GetEnablePrinter();
196 bool GetEnableHelp();
197 bool GetDefaultInfo();
198 wxPoint GetMarginTopLeft();
199 wxPoint GetMarginBottomRight();
200 wxPoint GetMinMarginTopLeft();
201 wxPoint GetMinMarginBottomRight();
202 wxPaperSize GetPaperId();
203 wxSize GetPaperSize();
204
205 wxPrintData& GetPrintData();
206
207 bool IsOk();
208 %pythoncode { Ok = IsOk }
209
210 void SetDefaultInfo(bool flag);
211 void SetDefaultMinMargins(bool flag);
212 void SetMarginTopLeft(const wxPoint& pt);
213 void SetMarginBottomRight(const wxPoint& pt);
214 void SetMinMarginTopLeft(const wxPoint& pt);
215 void SetMinMarginBottomRight(const wxPoint& pt);
216 void SetPaperId(wxPaperSize id);
217 void SetPaperSize(const wxSize& size);
218
219 void SetPrintData(const wxPrintData& printData);
220
221 // Use paper size defined in this object to set the wxPrintData
222 // paper id
223 void CalculateIdFromPaperSize();
224
225 // Use paper id in wxPrintData to set this object's paper size
226 void CalculatePaperSizeFromId();
227
228 %pythoncode { def __nonzero__(self): return self.IsOk() }
229
230 %property(DefaultInfo, GetDefaultInfo, SetDefaultInfo, doc="See `GetDefaultInfo` and `SetDefaultInfo`");
231 %property(DefaultMinMargins, GetDefaultMinMargins, SetDefaultMinMargins, doc="See `GetDefaultMinMargins` and `SetDefaultMinMargins`");
232
233 // %property(EnableHelp, GetEnableHelp, doc="See `GetEnableHelp`");
234 // %property(EnableMargins, GetEnableMargins, doc="See `GetEnableMargins`");
235 // %property(EnableOrientation, GetEnableOrientation, doc="See `GetEnableOrientation`");
236 // %property(EnablePaper, GetEnablePaper, doc="See `GetEnablePaper`");
237 // %property(EnablePrinter, GetEnablePrinter, doc="See `GetEnablePrinter`");
238
239 %property(MarginBottomRight, GetMarginBottomRight, SetMarginBottomRight, doc="See `GetMarginBottomRight` and `SetMarginBottomRight`");
240 %property(MarginTopLeft, GetMarginTopLeft, SetMarginTopLeft, doc="See `GetMarginTopLeft` and `SetMarginTopLeft`");
241 %property(MinMarginBottomRight, GetMinMarginBottomRight, SetMinMarginBottomRight, doc="See `GetMinMarginBottomRight` and `SetMinMarginBottomRight`");
242 %property(MinMarginTopLeft, GetMinMarginTopLeft, SetMinMarginTopLeft, doc="See `GetMinMarginTopLeft` and `SetMinMarginTopLeft`");
243 %property(PaperId, GetPaperId, SetPaperId, doc="See `GetPaperId` and `SetPaperId`");
244 %property(PaperSize, GetPaperSize, SetPaperSize, doc="See `GetPaperSize` and `SetPaperSize`");
245 %property(PrintData, GetPrintData, SetPrintData, doc="See `GetPrintData` and `SetPrintData`");
246
247 };
248
249
250
251 // NOTE: Contrary to it's name, this class doesn't derive from wxDialog. It
252 // is a facade in front of a platform-specific (native dialog) provided by the
253 // wxPrintFactory.
254
255 MustHaveApp(wxPageSetupDialog);
256
257 class wxPageSetupDialog : public wxObject
258 {
259 public:
260 wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
261 ~wxPageSetupDialog();
262
263 wxPageSetupDialogData& GetPageSetupData();
264 wxPageSetupDialogData& GetPageSetupDialogData();
265 int ShowModal();
266
267 %pythoncode { def Destroy(self): pass }
268
269 %property(PageSetupData, GetPageSetupData, doc="See `GetPageSetupData`");
270 %property(PageSetupDialogData, GetPageSetupDialogData, doc="See `GetPageSetupDialogData`");
271
272 };
273
274 //---------------------------------------------------------------------------
275
276
277 class wxPrintDialogData : public wxObject {
278 public:
279 %nokwargs wxPrintDialogData;
280 wxPrintDialogData();
281 wxPrintDialogData(const wxPrintData& printData);
282 wxPrintDialogData(const wxPrintDialogData& printData); // for making copies
283 ~wxPrintDialogData();
284
285 int GetFromPage() const;
286 int GetToPage() const;
287 int GetMinPage() const;
288 int GetMaxPage() const;
289 int GetNoCopies() const;
290 bool GetAllPages() const;
291 bool GetSelection() const;
292 bool GetCollate() const;
293 bool GetPrintToFile() const;
294
295 // WXWIN_COMPATIBILITY_2_4
296 #if 0
297 bool GetSetupDialog() const;
298 void SetSetupDialog(bool flag);
299 #endif
300 void SetFromPage(int v);
301 void SetToPage(int v);
302 void SetMinPage(int v);
303 void SetMaxPage(int v);
304 void SetNoCopies(int v);
305 void SetAllPages(bool flag);
306 void SetSelection(bool flag);
307 void SetCollate(bool flag);
308 void SetPrintToFile(bool flag);
309
310 void EnablePrintToFile(bool flag);
311 void EnableSelection(bool flag);
312 void EnablePageNumbers(bool flag);
313 void EnableHelp(bool flag);
314
315 bool GetEnablePrintToFile() const;
316 bool GetEnableSelection() const;
317 bool GetEnablePageNumbers() const;
318 bool GetEnableHelp() const;
319
320 // Is this data OK for showing the print dialog?
321 bool IsOk() const;
322 %pythoncode { Ok = IsOk }
323
324
325 wxPrintData& GetPrintData();
326 void SetPrintData(const wxPrintData& printData);
327
328 %pythoncode { def __nonzero__(self): return self.IsOk() }
329
330 %property(AllPages, GetAllPages, SetAllPages, doc="See `GetAllPages` and `SetAllPages`");
331 %property(Collate, GetCollate, SetCollate, doc="See `GetCollate` and `SetCollate`");
332 // %property(EnableHelp, GetEnableHelp, doc="See `GetEnableHelp`");
333 // %property(EnablePageNumbers, GetEnablePageNumbers, doc="See `GetEnablePageNumbers`");
334 // %property(EnablePrintToFile, GetEnablePrintToFile, doc="See `GetEnablePrintToFile`");
335 // %property(EnableSelection, GetEnableSelection, doc="See `GetEnableSelection`");
336 %property(FromPage, GetFromPage, SetFromPage, doc="See `GetFromPage` and `SetFromPage`");
337 %property(MaxPage, GetMaxPage, SetMaxPage, doc="See `GetMaxPage` and `SetMaxPage`");
338 %property(MinPage, GetMinPage, SetMinPage, doc="See `GetMinPage` and `SetMinPage`");
339 %property(NoCopies, GetNoCopies, SetNoCopies, doc="See `GetNoCopies` and `SetNoCopies`");
340 %property(PrintData, GetPrintData, SetPrintData, doc="See `GetPrintData` and `SetPrintData`");
341 %property(PrintToFile, GetPrintToFile, SetPrintToFile, doc="See `GetPrintToFile` and `SetPrintToFile`");
342 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
343 %property(ToPage, GetToPage, SetToPage, doc="See `GetToPage` and `SetToPage`");
344 };
345
346
347
348 MustHaveApp(wxPrintDialog);
349
350
351 // NOTE: Contrary to it's name, this class doesn't derive from wxDialog. It
352 // is a facade in front of a platform-specific (native dialog) provided by the
353 // wxPrintFactory.
354
355 class wxPrintDialog : public wxObject {
356 public:
357 wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
358
359 // TODO?: wxPrintDialog(wxWindow *parent, wxPrintData* data);
360
361 ~wxPrintDialog();
362
363 virtual int ShowModal();
364
365 virtual wxPrintDialogData& GetPrintDialogData();
366 virtual wxPrintData& GetPrintData();
367
368 %newobject GetPrintDC;
369 virtual wxDC *GetPrintDC();
370
371 %pythoncode { def Destroy(self): pass }
372
373 %property(PrintDC, GetPrintDC, doc="See `GetPrintDC`");
374 %property(PrintData, GetPrintData, doc="See `GetPrintData`");
375 %property(PrintDialogData, GetPrintDialogData, doc="See `GetPrintDialogData`");
376 };
377
378
379 //---------------------------------------------------------------------------
380 //---------------------------------------------------------------------------
381
382
383 enum wxPrinterError
384 {
385 wxPRINTER_NO_ERROR = 0,
386 wxPRINTER_CANCELLED,
387 wxPRINTER_ERROR
388 };
389
390
391 MustHaveApp(wxPrinter);
392
393 class wxPrinter : public wxObject {
394 public:
395 wxPrinter(wxPrintDialogData* data = NULL);
396 ~wxPrinter();
397
398 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPyPrintout *printout);
399 virtual void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
400
401 virtual bool Setup(wxWindow *parent);
402 virtual bool Print(wxWindow *parent, wxPyPrintout *printout, bool prompt = true);
403 virtual wxDC* PrintDialog(wxWindow *parent);
404
405 virtual wxPrintDialogData& GetPrintDialogData() const;
406
407 bool GetAbort();
408 static wxPrinterError GetLastError();
409
410 %property(Abort, GetAbort, doc="See `GetAbort`");
411 %property(PrintDialogData, GetPrintDialogData, doc="See `GetPrintDialogData`");
412 };
413
414
415 //---------------------------------------------------------------------------
416 // Custom wxPrintout class that knows how to call python, See implementation in
417 // include/sx/wxPython/printfw.h
418
419 %{
420
421 IMPLEMENT_ABSTRACT_CLASS(wxPyPrintout, wxPrintout);
422
423 // Since this one would be tough and ugly to do with the Macros...
424 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
425 bool hadErr = false;
426 bool found;
427
428 wxPyBlock_t blocked = wxPyBeginBlockThreads();
429 if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
430 PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
431 if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
432 PyObject* val;
433
434 val = PyTuple_GetItem(result, 0);
435 if (PyInt_Check(val)) *minPage = PyInt_AsLong(val);
436 else hadErr = true;
437
438 val = PyTuple_GetItem(result, 1);
439 if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val);
440 else hadErr = true;
441
442 val = PyTuple_GetItem(result, 2);
443 if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val);
444 else hadErr = true;
445
446 val = PyTuple_GetItem(result, 3);
447 if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val);
448 else hadErr = true;
449 }
450 else
451 hadErr = true;
452
453 if (hadErr) {
454 PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
455 PyErr_Print();
456 }
457 Py_DECREF(result);
458 }
459 wxPyEndBlockThreads(blocked);
460 if (! found)
461 wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
462 }
463
464
465
466 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
467 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
468 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
469 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
470 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
471 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
472 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
473
474
475 %}
476
477
478 MustHaveApp(wxPyPrintout);
479
480 // Now define the custom class for SWIGging
481 %rename(Printout) wxPyPrintout;
482 class wxPyPrintout : public wxObject {
483 public:
484 %pythonAppend wxPyPrintout "self._setCallbackInfo(self, Printout)"
485 %typemap(out) wxPyPrintout*; // turn off this typemap
486
487 wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
488 ~wxPyPrintout();
489
490 // Turn it back on again
491 %typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1, $owner); }
492
493 void _setCallbackInfo(PyObject* self, PyObject* _class);
494
495
496 wxString GetTitle() const;
497 wxDC* GetDC();
498 void SetDC(wxDC *dc);
499
500
501 void FitThisSizeToPaper(const wxSize& imageSize);
502 void FitThisSizeToPage(const wxSize& imageSize);
503 void FitThisSizeToPageMargins(const wxSize& imageSize, const wxPageSetupDialogData& pageSetupData);
504 void MapScreenSizeToPaper();
505 void MapScreenSizeToPage();
506 void MapScreenSizeToPageMargins(const wxPageSetupDialogData& pageSetupData);
507 void MapScreenSizeToDevice();
508
509 wxRect GetLogicalPaperRect() const;
510 wxRect GetLogicalPageRect() const;
511 wxRect GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSetupData) const;
512
513 void SetLogicalOrigin(wxCoord x, wxCoord y);
514 void OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff);
515
516
517 void SetPageSizePixels(int w, int h);
518 DocDeclA(
519 void, GetPageSizePixels(int *OUTPUT, int *OUTPUT),
520 "GetPageSizePixels() -> (w, h)");
521
522 void SetPageSizeMM(int w, int h);
523 DocDeclA(
524 void, GetPageSizeMM(int *OUTPUT, int *OUTPUT),
525 "GetPageSizeMM() -> (w, h)");
526
527 void SetPPIScreen(int x, int y);
528 DocDeclA(
529 void, GetPPIScreen(int *OUTPUT, int *OUTPUT),
530 "GetPPIScreen() -> (x,y)");
531
532 void SetPPIPrinter(int x, int y);
533 DocDeclA(
534 void, GetPPIPrinter(int *OUTPUT, int *OUTPUT),
535 "GetPPIPrinter() -> (x,y)");
536
537 void SetPaperRectPixels(const wxRect& paperRectPixels);
538 wxRect GetPaperRectPixels() const;
539
540 bool IsPreview();
541 void SetIsPreview(bool p);
542
543
544 bool OnBeginDocument(int startPage, int endPage);
545 void OnEndDocument();
546 void OnBeginPrinting();
547 void OnEndPrinting();
548 void OnPreparePrinting();
549 bool HasPage(int page);
550 DocDeclA(
551 void, GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT),
552 "GetPageInfo() -> (minPage, maxPage, pageFrom, pageTo)");
553
554 %MAKE_BASE_FUNC(Printout, OnBeginDocument);
555 %MAKE_BASE_FUNC(Printout, OnEndDocument);
556 %MAKE_BASE_FUNC(Printout, OnBeginPrinting);
557 %MAKE_BASE_FUNC(Printout, OnEndPrinting);
558 %MAKE_BASE_FUNC(Printout, OnPreparePrinting);
559 %MAKE_BASE_FUNC(Printout, GetPageInfo);
560
561
562 %property(DC, GetDC, SetDC, doc="See `GetDC` and `SetDC`");
563 %property(PPIPrinter, GetPPIPrinter, SetPPIPrinter, doc="See `GetPPIPrinter` and `SetPPIPrinter`");
564 %property(PPIScreen, GetPPIScreen, SetPPIScreen, doc="See `GetPPIScreen` and `SetPPIScreen`");
565 %property(PageSizeMM, GetPageSizeMM, SetPageSizeMM, doc="See `GetPageSizeMM` and `SetPageSizeMM`");
566 %property(PageSizePixels, GetPageSizePixels, SetPageSizePixels, doc="See `GetPageSizePixels` and `SetPageSizePixels`");
567 %property(Title, GetTitle, doc="See `GetTitle`");
568 };
569
570 //---------------------------------------------------------------------------
571
572
573
574 MustHaveApp(wxPreviewCanvas);
575
576 class wxPreviewCanvas: public wxScrolledWindow
577 {
578 public:
579 %pythonAppend wxPreviewCanvas "self._setOORInfo(self)"
580
581 wxPreviewCanvas(wxPrintPreview *preview,
582 wxWindow *parent,
583 const wxPoint& pos = wxDefaultPosition,
584 const wxSize& size = wxDefaultSize,
585 long style = 0,
586 const wxString& name = wxPyPreviewCanvasNameStr);
587 };
588
589
590 MustHaveApp(wxPreviewFrame);
591
592 class wxPreviewFrame : public wxFrame {
593 public:
594 %disownarg(wxPrintPreview*);
595
596 %pythonAppend wxPreviewFrame "self._setOORInfo(self)"
597 wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
598 const wxPoint& pos = wxDefaultPosition,
599 const wxSize& size = wxDefaultSize,
600 long style = wxDEFAULT_FRAME_STYLE,
601 const wxString& name = wxPyFrameNameStr);
602
603 %cleardisown(wxPrintPreview*);
604
605 void Initialize();
606 void CreateControlBar();
607 void CreateCanvas();
608
609 wxPreviewControlBar* GetControlBar() const;
610
611 %property(ControlBar, GetControlBar, doc="See `GetControlBar`");
612 };
613
614
615
616 enum {
617 wxPREVIEW_PRINT,
618 wxPREVIEW_PREVIOUS,
619 wxPREVIEW_NEXT,
620 wxPREVIEW_ZOOM,
621 wxPREVIEW_FIRST,
622 wxPREVIEW_LAST,
623 wxPREVIEW_GOTO,
624 wxPREVIEW_DEFAULT,
625
626 wxID_PREVIEW_CLOSE,
627 wxID_PREVIEW_NEXT,
628 wxID_PREVIEW_PREVIOUS,
629 wxID_PREVIEW_PRINT,
630 wxID_PREVIEW_ZOOM,
631 wxID_PREVIEW_FIRST,
632 wxID_PREVIEW_LAST,
633 wxID_PREVIEW_GOTO
634 };
635
636 MustHaveApp(wxPreviewControlBar);
637
638 class wxPreviewControlBar: public wxPanel
639 {
640 public:
641 %pythonAppend wxPreviewControlBar "self._setOORInfo(self)"
642
643 wxPreviewControlBar(wxPrintPreview *preview,
644 long buttons,
645 wxWindow *parent,
646 const wxPoint& pos = wxDefaultPosition,
647 const wxSize& size = wxDefaultSize,
648 long style = wxTAB_TRAVERSAL,
649 const wxString& name = wxPyPanelNameStr);
650
651 int GetZoomControl();
652 void SetZoomControl(int zoom);
653 wxPrintPreview* GetPrintPreview();
654
655 void OnNext();
656 void OnPrevious();
657 void OnFirst();
658 void OnLast();
659 void OnGoto();
660
661 %property(PrintPreview, GetPrintPreview, doc="See `GetPrintPreview`");
662 %property(ZoomControl, GetZoomControl, SetZoomControl, doc="See `GetZoomControl` and `SetZoomControl`");
663 };
664
665
666
667 //---------------------------------------------------------------------------
668
669 MustHaveApp(wxPrintPreview);
670
671 class wxPrintPreview : public wxObject {
672 public:
673 %disownarg(wxPyPrintout*);
674
675 %nokwargs wxPrintPreview;
676 wxPrintPreview(wxPyPrintout* printout,
677 wxPyPrintout* printoutForPrinting,
678 wxPrintDialogData *data=NULL);
679 wxPrintPreview(wxPyPrintout* printout,
680 wxPyPrintout* printoutForPrinting,
681 wxPrintData* data);
682
683 ~wxPrintPreview();
684
685 virtual bool SetCurrentPage(int pageNum);
686 int GetCurrentPage();
687
688 void SetPrintout(wxPyPrintout *printout);
689 wxPyPrintout *GetPrintout();
690 wxPyPrintout *GetPrintoutForPrinting();
691
692 %cleardisown(wxPyPrintout*);
693
694 void SetFrame(wxFrame *frame);
695 void SetCanvas(wxPreviewCanvas *canvas);
696
697 virtual wxFrame *GetFrame();
698 virtual wxPreviewCanvas *GetCanvas();
699
700 // The preview canvas should call this from OnPaint
701 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
702
703 // This draws a blank page onto the preview canvas
704 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
705
706 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
707 virtual bool RenderPage(int pageNum);
708
709 // Adjusts the scrollbars for the current scale
710 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
711
712 wxPrintDialogData& GetPrintDialogData();
713
714 virtual void SetZoom(int percent);
715 int GetZoom();
716
717 int GetMaxPage();
718 int GetMinPage();
719
720 bool IsOk();
721 %pythoncode { Ok = IsOk }
722 void SetOk(bool ok);
723
724 virtual bool Print(bool interactive);
725 virtual void DetermineScaling();
726
727 %pythoncode { def __nonzero__(self): return self.IsOk() }
728
729 %property(Canvas, GetCanvas, SetCanvas, doc="See `GetCanvas` and `SetCanvas`");
730 %property(CurrentPage, GetCurrentPage, SetCurrentPage, doc="See `GetCurrentPage` and `SetCurrentPage`");
731 %property(Frame, GetFrame, SetFrame, doc="See `GetFrame` and `SetFrame`");
732 %property(MaxPage, GetMaxPage, doc="See `GetMaxPage`");
733 %property(MinPage, GetMinPage, doc="See `GetMinPage`");
734 %property(PrintDialogData, GetPrintDialogData, doc="See `GetPrintDialogData`");
735 %property(Printout, GetPrintout, SetPrintout, doc="See `GetPrintout` and `SetPrintout`");
736 %property(PrintoutForPrinting, GetPrintoutForPrinting, doc="See `GetPrintoutForPrinting`");
737 %property(Zoom, GetZoom, SetZoom, doc="See `GetZoom` and `SetZoom`");
738 };
739
740
741
742 //---------------------------------------------------------------------------
743
744 // Python-derivable versions of the above preview classes
745
746 %{
747
748 #define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME) \
749 bool CBNAME(wxPreviewCanvas* a, wxDC& b)
750
751
752 #define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME) \
753 bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) { \
754 bool rval=false; \
755 bool found; \
756 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
757 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
758 PyObject* win = wxPyMake_wxObject(a,false); \
759 PyObject* dc = wxPyMake_wxObject(&b,false); \
760 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc)); \
761 Py_DECREF(win); \
762 Py_DECREF(dc); \
763 } \
764 wxPyEndBlockThreads(blocked); \
765 if (! found) \
766 rval = PCLASS::CBNAME(a, b); \
767 return rval; \
768 }
769
770
771
772
773 class wxPyPrintPreview : public wxPrintPreview
774 {
775 DECLARE_CLASS(wxPyPrintPreview)
776 public:
777 wxPyPrintPreview(wxPyPrintout* printout,
778 wxPyPrintout* printoutForPrinting,
779 wxPrintDialogData* data=NULL)
780 : wxPrintPreview(printout, printoutForPrinting, data)
781 {}
782 wxPyPrintPreview(wxPyPrintout* printout,
783 wxPyPrintout* printoutForPrinting,
784 wxPrintData* data)
785 : wxPrintPreview(printout, printoutForPrinting, data)
786 {}
787
788 DEC_PYCALLBACK_BOOL_INT(SetCurrentPage);
789 DEC_PYCALLBACK_BOOL_PREWINDC(PaintPage);
790 DEC_PYCALLBACK_BOOL_PREWINDC(DrawBlankPage);
791 DEC_PYCALLBACK_BOOL_INT(RenderPage);
792 DEC_PYCALLBACK_VOID_INT(SetZoom);
793 DEC_PYCALLBACK_BOOL_BOOL(Print);
794 DEC_PYCALLBACK_VOID_(DetermineScaling);
795
796 PYPRIVATE;
797 };
798
799 // Stupid renamed classes... Fix this in 2.5...
800 #if defined(__WXMSW__)
801 IMPLEMENT_CLASS( wxPyPrintPreview, wxWindowsPrintPreview );
802 #elif defined(__WXMAC__)
803 IMPLEMENT_CLASS( wxPyPrintPreview, wxMacPrintPreview );
804 #else
805 IMPLEMENT_CLASS( wxPyPrintPreview, wxPostScriptPrintPreview );
806 #endif
807
808 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, SetCurrentPage);
809 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, PaintPage);
810 IMP_PYCALLBACK_BOOL_PREWINDC(wxPyPrintPreview, wxPrintPreview, DrawBlankPage);
811 IMP_PYCALLBACK_BOOL_INT (wxPyPrintPreview, wxPrintPreview, RenderPage);
812 IMP_PYCALLBACK_VOID_INT (wxPyPrintPreview, wxPrintPreview, SetZoom);
813 IMP_PYCALLBACK_BOOL_BOOL (wxPyPrintPreview, wxPrintPreview, Print);
814 IMP_PYCALLBACK_VOID_ (wxPyPrintPreview, wxPrintPreview, DetermineScaling);
815 %}
816
817
818 MustHaveApp(wxPyPrintPreview);
819
820 class wxPyPrintPreview : public wxPrintPreview
821 {
822 public:
823 %disownarg(wxPyPrintout*);
824
825 %pythonAppend wxPyPrintPreview "self._setCallbackInfo(self, PyPrintPreview)"
826 %nokwargs wxPyPrintPreview;
827 wxPyPrintPreview(wxPyPrintout* printout,
828 wxPyPrintout* printoutForPrinting,
829 wxPrintDialogData* data=NULL);
830 wxPyPrintPreview(wxPyPrintout* printout,
831 wxPyPrintout* printoutForPrinting,
832 wxPrintData* data);
833
834 %cleardisown(wxPyPrintout*);
835
836 void _setCallbackInfo(PyObject* self, PyObject* _class);
837
838 bool SetCurrentPage(int pageNum);
839 bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
840 bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
841 bool RenderPage(int pageNum);
842 void SetZoom(int percent);
843 bool Print(bool interactive);
844 void DetermineScaling();
845
846 %MAKE_BASE_FUNC(PyPrintPreview, SetCurrentPage);
847 %MAKE_BASE_FUNC(PyPrintPreview, PaintPage);
848 %MAKE_BASE_FUNC(PyPrintPreview, DrawBlankPage);
849 %MAKE_BASE_FUNC(PyPrintPreview, RenderPage);
850 %MAKE_BASE_FUNC(PyPrintPreview, SetZoom);
851 %MAKE_BASE_FUNC(PyPrintPreview, Print);
852 %MAKE_BASE_FUNC(PyPrintPreview, DetermineScaling);
853 };
854
855
856
857
858 %{
859 class wxPyPreviewFrame : public wxPreviewFrame
860 {
861 DECLARE_CLASS(wxPyPreviewFrame)
862 public:
863 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
864 const wxString& title,
865 const wxPoint& pos = wxDefaultPosition,
866 const wxSize& size = wxDefaultSize,
867 long style = wxDEFAULT_FRAME_STYLE,
868 const wxString& name = wxPyFrameNameStr)
869 : wxPreviewFrame(preview, parent, title, pos, size, style, name)
870 {}
871
872 void SetPreviewCanvas(wxPreviewCanvas* canvas) { m_previewCanvas = canvas; }
873 void SetControlBar(wxPreviewControlBar* bar) { m_controlBar = bar; }
874
875 DEC_PYCALLBACK_VOID_(Initialize);
876 DEC_PYCALLBACK_VOID_(CreateCanvas);
877 DEC_PYCALLBACK_VOID_(CreateControlBar);
878
879 PYPRIVATE;
880 };
881
882 IMPLEMENT_CLASS(wxPyPreviewFrame, wxPreviewFrame);
883
884 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, Initialize);
885 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateCanvas);
886 IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
887 %}
888
889
890 MustHaveApp(wxPyPreviewFrame);
891
892 class wxPyPreviewFrame : public wxPreviewFrame
893 {
894 public:
895 %disownarg(wxPrintPreview*);
896 %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
897
898 wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
899 const wxString& title,
900 const wxPoint& pos = wxDefaultPosition,
901 const wxSize& size = wxDefaultSize,
902 long style = wxDEFAULT_FRAME_STYLE,
903 const wxString& name = wxPyFrameNameStr);
904
905 void _setCallbackInfo(PyObject* self, PyObject* _class);
906
907 void SetPreviewCanvas(wxPreviewCanvas* canvas);
908 void SetControlBar(wxPreviewControlBar* bar);
909
910 void Initialize();
911 void CreateCanvas();
912 void CreateControlBar();
913
914 %MAKE_BASE_FUNC(PyPreviewFrame, Initialize);
915 %MAKE_BASE_FUNC(PyPreviewFrame, CreateCanvas);
916 %MAKE_BASE_FUNC(PyPreviewFrame, CreateControlBar);
917 };
918
919
920
921
922 %{
923 class wxPyPreviewControlBar : public wxPreviewControlBar
924 {
925 DECLARE_CLASS(wxPyPreviewControlBar)
926 public:
927 wxPyPreviewControlBar(wxPrintPreview *preview,
928 long buttons,
929 wxWindow *parent,
930 const wxPoint& pos = wxDefaultPosition,
931 const wxSize& size = wxDefaultSize,
932 long style = 0,
933 const wxString& name = wxPyPanelNameStr)
934 : wxPreviewControlBar(preview, buttons, parent, pos, size, style, name)
935 {}
936
937 void SetPrintPreview(wxPrintPreview* preview) { m_printPreview = preview; }
938
939 DEC_PYCALLBACK_VOID_(CreateButtons);
940 DEC_PYCALLBACK_VOID_INT(SetZoomControl);
941
942 PYPRIVATE;
943 };
944
945 IMPLEMENT_CLASS(wxPyPreviewControlBar, wxPreviewControlBar);
946 IMP_PYCALLBACK_VOID_(wxPyPreviewControlBar, wxPreviewControlBar, CreateButtons);
947 IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomControl);
948 %}
949
950
951 MustHaveApp(wxPyPreviewControlBar);
952
953 class wxPyPreviewControlBar : public wxPreviewControlBar
954 {
955 public:
956 %pythonAppend wxPyPreviewControlBar "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
957
958 wxPyPreviewControlBar(wxPrintPreview *preview,
959 long buttons,
960 wxWindow *parent,
961 const wxPoint& pos = wxDefaultPosition,
962 const wxSize& size = wxDefaultSize,
963 long style = 0,
964 const wxString& name = wxPyPanelNameStr);
965
966 void _setCallbackInfo(PyObject* self, PyObject* _class);
967
968 void SetPrintPreview(wxPrintPreview* preview);
969
970 void CreateButtons();
971 void SetZoomControl(int zoom);
972
973 %MAKE_BASE_FUNC(PreviewControlBar, CreateButtons);
974 %MAKE_BASE_FUNC(PreviewControlBar, SetZoomControl);
975 };
976
977 //---------------------------------------------------------------------------
978 //---------------------------------------------------------------------------
979 %init %{
980 wxPyPtrTypeMap_Add("wxPrintout", "wxPyPrintout");
981 %}
982 //---------------------------------------------------------------------------