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