1 // ===========================================================================
2 // Purpose:     printing related classes
3 // Author:      J Winwood, John Labenski
4 // Created:     14/11/2001
5 // Copyright:   (c) 2001-2002 Lomtick Software. All rights reserved.
6 // Licence:     wxWidgets licence
7 // wxWidgets:   Updated to 2.8.4
8 // ===========================================================================
9 
10 #if wxLUA_USE_wxPrint && wxUSE_PRINTING_ARCHITECTURE
11 
12 typedef wxScrolledWindow wxPreviewWindow
13 
14 #include "wx/print.h"
15 
16 // ---------------------------------------------------------------------------
17 // wxPrintout
18 
19 class wxPrintout : public wxObject
20 {
21     // virtual class, use wxLuaPrintout
22 
23     wxDC * GetDC();
24 
25     // %override [int minPage, int maxPage, int pageFrom, int pageTo] wxPrintout::GetPageInfo();
26     // C++ Func: void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo);
27     void GetPageInfo();
28 
29     // %override [int w, int h] wxPrintout::GetPageSizeMM();
30     // C++ Func: void GetPageSizeMM(int *w, int *h);
31     void GetPageSizeMM();
32 
33     // %override [int w, int h] wxPrintout::GetPageSizePixels();
34     // C++ Func: void GetPageSizePixels(int *w, int *h);
35     void GetPageSizePixels();
36 
37     // %override [int w, int h] wxPrintout::GetPPIPrinter();
38     // C++ Func: void GetPPIPrinter(int *w, int *h);
39     void GetPPIPrinter();
40 
41     // %override [int w, int h] wxPrintout::GetPPIScreen();
42     // C++ Func: void GetPPIScreen(int *w, int *h);
43     void GetPPIScreen();
44 
45     wxString  GetTitle();
46     bool HasPage(int pageNum);
47     bool IsPreview();
48     bool OnBeginDocument(int startPage, int endPage);
49     void OnEndDocument();
50     void OnBeginPrinting();
51     void OnEndPrinting();
52     void OnPreparePrinting();
53     bool OnPrintPage(int pageNum);
54 };
55 
56 // ---------------------------------------------------------------------------
57 // wxLuaPrintout
58 
59 #if wxLUA_USE_wxLuaPrintout
60 
61 #include "wxlua/wxlua_bind.h" // for wxLuaObject tag
62 #include "wxbind/include/wxcore_wxlcore.h"
63 
64 class %delete wxLuaPrintout : public wxPrintout
65 {
66     // %override - the C++ function takes the wxLuaState as the first param
67     wxLuaPrintout(const wxString& title = "Printout", wxLuaObject *pObject = NULL);
68 
69     wxLuaObject *GetID();
70 
71     // This is an added function to wxPrintout so you don't have to override GetPageInfo
72     void SetPageInfo(int minPage, int maxPage, int pageFrom = 0, int pageTo = 0);
73 
74     // The functions below are all virtual functions that you can override in Lua.
75     // See the printing sample and wxPrintout for proper parameters and usage.
76     //void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo);
77     //bool HasPage(int pageNum);
78     //bool OnBeginDocument(int startPage, int endPage);
79     //void OnEndDocument();
80     //void OnBeginPrinting();
81     //void OnEndPrinting();
82     //void OnPreparePrinting();
83     //bool OnPrintPage(int pageNum);
84 
85     // Dummy test function to directly verify that the binding virtual functions really work.
86     // This base class function appends "-Base" to the val string and returns it.
87     virtual wxString TestVirtualFunctionBinding(const wxString& val); // { return val + wxT("-Base"); }
88 
89     static int ms_test_int;
90 };
91 
92 
93 // ---------------------------------------------------------------------------
94 // wxPrinter
95 
96 enum wxPrinterError
97 {
98     wxPRINTER_NO_ERROR,
99     wxPRINTER_CANCELLED,
100     wxPRINTER_ERROR
101 };
102 
103 class %delete wxPrinter : public wxObject
104 {
105     wxPrinter(wxPrintDialogData* data = NULL);
106 
107     //bool Abort();
108     virtual void CreateAbortWindow(wxWindow* parent, wxPrintout* printout);
109     bool GetAbort() const;
110     static wxPrinterError GetLastError();
111     wxPrintDialogData& GetPrintDialogData();
112     bool Print(wxWindow *parent, wxPrintout *printout, bool prompt=true);
113     wxDC* PrintDialog(wxWindow *parent);
114     void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message);
115     bool Setup(wxWindow *parent);
116 };
117 
118 #endif //wxLUA_USE_wxLuaPrintout
119 
120 // ---------------------------------------------------------------------------
121 // wxPrintData
122 
123 #define wxPORTRAIT
124 #define wxLANDSCAPE
125 
126 enum wxDuplexMode
127 {
128     wxDUPLEX_HORIZONTAL,
129     wxDUPLEX_SIMPLEX,
130     wxDUPLEX_VERTICAL
131 };
132 
133 enum wxPaperSize
134 {
135     wxPAPER_NONE,
136     wxPAPER_LETTER,
137     wxPAPER_LEGAL,
138     wxPAPER_A4,
139     wxPAPER_CSHEET,
140     wxPAPER_DSHEET,
141     wxPAPER_ESHEET,
142     wxPAPER_LETTERSMALL,
143     wxPAPER_TABLOID,
144     wxPAPER_LEDGER,
145     wxPAPER_STATEMENT,
146     wxPAPER_EXECUTIVE,
147     wxPAPER_A3,
148     wxPAPER_A4SMALL,
149     wxPAPER_A5,
150     wxPAPER_B4,
151     wxPAPER_B5,
152     wxPAPER_FOLIO,
153     wxPAPER_QUARTO,
154     wxPAPER_10X14,
155     wxPAPER_11X17,
156     wxPAPER_NOTE,
157     wxPAPER_ENV_9,
158     wxPAPER_ENV_10,
159     wxPAPER_ENV_11,
160     wxPAPER_ENV_12,
161     wxPAPER_ENV_14,
162     wxPAPER_ENV_DL,
163     wxPAPER_ENV_C5,
164     wxPAPER_ENV_C3,
165     wxPAPER_ENV_C4,
166     wxPAPER_ENV_C6,
167     wxPAPER_ENV_C65,
168     wxPAPER_ENV_B4,
169     wxPAPER_ENV_B5,
170     wxPAPER_ENV_B6,
171     wxPAPER_ENV_ITALY,
172     wxPAPER_ENV_MONARCH,
173     wxPAPER_ENV_PERSONAL,
174     wxPAPER_FANFOLD_US,
175     wxPAPER_FANFOLD_STD_GERMAN,
176     wxPAPER_FANFOLD_LGL_GERMAN,
177 
178     wxPAPER_ISO_B4,
179     wxPAPER_JAPANESE_POSTCARD,
180     wxPAPER_9X11,
181     wxPAPER_10X11,
182     wxPAPER_15X11,
183     wxPAPER_ENV_INVITE,
184     wxPAPER_LETTER_EXTRA,
185     wxPAPER_LEGAL_EXTRA,
186     wxPAPER_TABLOID_EXTRA,
187     wxPAPER_A4_EXTRA,
188     wxPAPER_LETTER_TRANSVERSE,
189     wxPAPER_A4_TRANSVERSE,
190     wxPAPER_LETTER_EXTRA_TRANSVERSE,
191     wxPAPER_A_PLUS,
192     wxPAPER_B_PLUS,
193     wxPAPER_LETTER_PLUS,
194     wxPAPER_A4_PLUS,
195     wxPAPER_A5_TRANSVERSE,
196     wxPAPER_B5_TRANSVERSE,
197     wxPAPER_A3_EXTRA,
198     wxPAPER_A5_EXTRA,
199     wxPAPER_B5_EXTRA,
200     wxPAPER_A2,
201     wxPAPER_A3_TRANSVERSE,
202     wxPAPER_A3_EXTRA_TRANSVERSE,
203 
204     wxPAPER_DBL_JAPANESE_POSTCARD,
205     wxPAPER_A6,
206     wxPAPER_JENV_KAKU2,
207     wxPAPER_JENV_KAKU3,
208     wxPAPER_JENV_CHOU3,
209     wxPAPER_JENV_CHOU4,
210     wxPAPER_LETTER_ROTATED,
211     wxPAPER_A3_ROTATED,
212     wxPAPER_A4_ROTATED,
213     wxPAPER_A5_ROTATED,
214     wxPAPER_B4_JIS_ROTATED,
215     wxPAPER_B5_JIS_ROTATED,
216     wxPAPER_JAPANESE_POSTCARD_ROTATED,
217     wxPAPER_DBL_JAPANESE_POSTCARD_ROTATED,
218     wxPAPER_A6_ROTATED,
219     wxPAPER_JENV_KAKU2_ROTATED,
220     wxPAPER_JENV_KAKU3_ROTATED,
221     wxPAPER_JENV_CHOU3_ROTATED,
222     wxPAPER_JENV_CHOU4_ROTATED,
223     wxPAPER_B6_JIS,
224     wxPAPER_B6_JIS_ROTATED,
225     wxPAPER_12X11,
226     wxPAPER_JENV_YOU4,
227     wxPAPER_JENV_YOU4_ROTATED,
228     wxPAPER_P16K,
229     wxPAPER_P32K,
230     wxPAPER_P32KBIG,
231     wxPAPER_PENV_1,
232     wxPAPER_PENV_2,
233     wxPAPER_PENV_3,
234     wxPAPER_PENV_4,
235     wxPAPER_PENV_5,
236     wxPAPER_PENV_6,
237     wxPAPER_PENV_7,
238     wxPAPER_PENV_8,
239     wxPAPER_PENV_9,
240     wxPAPER_PENV_10,
241     wxPAPER_P16K_ROTATED,
242     wxPAPER_P32K_ROTATED,
243     wxPAPER_P32KBIG_ROTATED,
244     wxPAPER_PENV_1_ROTATED,
245     wxPAPER_PENV_2_ROTATED,
246     wxPAPER_PENV_3_ROTATED,
247     wxPAPER_PENV_4_ROTATED,
248     wxPAPER_PENV_5_ROTATED,
249     wxPAPER_PENV_6_ROTATED,
250     wxPAPER_PENV_7_ROTATED,
251     wxPAPER_PENV_8_ROTATED,
252     wxPAPER_PENV_9_ROTATED,
253     wxPAPER_PENV_10_ROTATED
254 };
255 
256 enum wxPrintQuality // actually not an enum, but a typedef int
257 {
258     wxPRINT_QUALITY_DRAFT,
259     wxPRINT_QUALITY_HIGH,
260     wxPRINT_QUALITY_LOW,
261     wxPRINT_QUALITY_MEDIUM
262 };
263 
264 enum wxPrintMode
265 {
266     wxPRINT_MODE_FILE,
267     wxPRINT_MODE_NONE,
268     wxPRINT_MODE_PREVIEW,
269     wxPRINT_MODE_PRINTER
270 };
271 
272 #if %wxchkver_2_6
273 enum wxPrintBin
274 {
275     wxPRINTBIN_DEFAULT,
276 
277     wxPRINTBIN_ONLYONE,
278     wxPRINTBIN_LOWER,
279     wxPRINTBIN_MIDDLE,
280     wxPRINTBIN_MANUAL,
281     wxPRINTBIN_ENVELOPE,
282     wxPRINTBIN_ENVMANUAL,
283     wxPRINTBIN_AUTO,
284     wxPRINTBIN_TRACTOR,
285     wxPRINTBIN_SMALLFMT,
286     wxPRINTBIN_LARGEFMT,
287     wxPRINTBIN_LARGECAPACITY,
288     wxPRINTBIN_CASSETTE,
289     wxPRINTBIN_FORMSOURCE,
290 
291     wxPRINTBIN_USER
292 };
293 #endif
294 
295 #if %wxchkver_3_0
296 enum wxPrintOrientation
297 {
298    wxPORTRAIT = 1,
299    wxLANDSCAPE
300 };
301 #endif
302 
303 class %delete wxPrintData : public wxObject
304 {
305     wxPrintData();
306     wxPrintData(const wxPrintData& data);
307 
308     wxPrintData *Copy();
309 
310     // copied straight from cmndata.h not docs
311     int  GetNoCopies() const;
312     bool GetCollate() const;
313     int  GetOrientation() const;
314     bool Ok() const;
315     wxString GetPrinterName() const;
316     bool GetColour() const;
317     wxDuplexMode GetDuplex() const;
318     %wxchkver_2_8 int GetMedia() const;
319     wxPaperSize GetPaperId() const;
320     wxSize GetPaperSize() const;
321     wxPrintQuality GetQuality() const;
322     wxPrintBin GetBin() const;
323     wxPrintMode GetPrintMode() const;
324     %wxchkver_2_8 bool IsOrientationReversed() const;
325     void SetNoCopies(int v);
326     void SetCollate(bool flag);
327     !%wxchkver_3_0 void SetOrientation(int orient);
328     %wxchkver_3_0 void SetOrientation(wxPrintOrientation orient);
329     void SetPrinterName(const wxString& name);
330     void SetColour(bool colour);
331     void SetDuplex(wxDuplexMode duplex);
332     %wxchkver_2_8 void SetOrientationReversed(bool reversed);
333     %wxchkver_2_8 void SetMedia(int media);
334     void SetPaperId(wxPaperSize sizeId);
335     void SetPaperSize(const wxSize& sz);
336     void SetQuality(wxPrintQuality quality);
337     void SetBin(wxPrintBin bin);
338     void SetPrintMode(wxPrintMode printMode);
339     wxString GetFilename() const;
340     void SetFilename(const wxString &filename);
341 
342     void operator=(const wxPrintData& data);
343 };
344 
345 // ---------------------------------------------------------------------------
346 // wxPageSetupDialogData
347 
348 class %delete wxPageSetupDialogData : public wxObject
349 {
350     wxPageSetupDialogData();
351     wxPageSetupDialogData(const wxPageSetupDialogData& data);
352 
353     wxPageSetupDialogData *Copy();
354 
355     // copied straight from cmndata.h not docs
356     wxSize GetPaperSize() const;
357     wxPaperSize GetPaperId() const;
358     wxPoint GetMinMarginTopLeft() const;
359     wxPoint GetMinMarginBottomRight() const;
360     wxPoint GetMarginTopLeft() const;
361     wxPoint GetMarginBottomRight() const;
362     bool GetDefaultMinMargins() const;
363     bool GetEnableMargins() const;
364     bool GetEnableOrientation() const;
365     bool GetEnablePaper() const;
366     bool GetEnablePrinter() const;
367     bool GetDefaultInfo() const;
368     bool GetEnableHelp() const;
369     bool Ok() const;
370     void SetPaperSize(const wxSize& sz);
371     void SetPaperSize(wxPaperSize id);
372     void SetPaperId(wxPaperSize id);
373     void SetMinMarginTopLeft(const wxPoint& pt);
374     void SetMinMarginBottomRight(const wxPoint& pt);
375     void SetMarginTopLeft(const wxPoint& pt);
376     void SetMarginBottomRight(const wxPoint& pt);
377     void SetDefaultMinMargins(bool flag);
378     void SetDefaultInfo(bool flag);
379     void EnableMargins(bool flag);
380     void EnableOrientation(bool flag);
381     void EnablePaper(bool flag);
382     void EnablePrinter(bool flag);
383     void EnableHelp(bool flag);
384     void CalculateIdFromPaperSize();
385     void CalculatePaperSizeFromId();
386     wxPrintData& GetPrintData();
387     void SetPrintData(const wxPrintData& printData);
388 
389     //wxPageSetupDialogData& operator=(const wxPageSetupData& data);
390     //wxPageSetupDialogData& operator=(const wxPrintData& data);
391 };
392 
393 // ---------------------------------------------------------------------------
394 // wxPageSetupDialog
395 
396 #include "wx/printdlg.h"
397 
398 //typedef wxPageSetupDialogBase wxPageSetupDialog
399 
400 class %delete wxPageSetupDialog : public wxObject // NOT a wxDialog in 2.8
401 {
402     wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
403 
404     wxPageSetupDialogData& GetPageSetupDialogData();
405     int ShowModal();
406 };
407 
408 // ---------------------------------------------------------------------------
409 // wxPrintDialog
410 
411 class %delete wxPrintDialog : public wxObject // NOT a wxDialog in 2.8
412 {
413     wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
414 
415     wxPrintDialogData& GetPrintDialogData();
416     wxPrintData& GetPrintData();
417     wxDC* GetPrintDC();
418     int ShowModal();
419 };
420 
421 // ---------------------------------------------------------------------------
422 // wxPrintDialogData
423 
424 class %delete wxPrintDialogData : public wxObject
425 {
426     wxPrintDialogData();
427     wxPrintDialogData(const wxPrintDialogData& dialogData);
428     wxPrintDialogData(const wxPrintData& data);
429 
430     // copied straight from cmndata.h not docs
431     int GetFromPage() const;
432     int GetToPage() const;
433     int GetMinPage() const;
434     int GetMaxPage() const;
435     int GetNoCopies() const;
436     bool GetAllPages() const;
437     bool GetSelection() const;
438     bool GetCollate() const;
439     bool GetPrintToFile() const;
440     // WXWIN_COMPATIBILITY_2_4 //bool GetSetupDialog() const;
441     void SetFromPage(int v);
442     void SetToPage(int v);
443     void SetMinPage(int v);
444     void SetMaxPage(int v);
445     void SetNoCopies(int v);
446     void SetAllPages(bool flag);
447     void SetSelection(bool flag);
448     void SetCollate(bool flag);
449     void SetPrintToFile(bool flag);
450     // WXWIN_COMPATIBILITY_2_4 //void SetSetupDialog(bool flag) { m_printSetupDialog = flag; };
451     void EnablePrintToFile(bool flag);
452     void EnableSelection(bool flag);
453     void EnablePageNumbers(bool flag);
454     void EnableHelp(bool flag);
455     bool GetEnablePrintToFile() const;
456     bool GetEnableSelection() const;
457     bool GetEnablePageNumbers() const;
458     bool GetEnableHelp() const;
459     bool Ok() const;
460     wxPrintData& GetPrintData();
461     void SetPrintData(const wxPrintData& printData);
462 
463     void operator=(const wxPrintDialogData& data);
464 };
465 
466 // ---------------------------------------------------------------------------
467 // wxPreviewCanvas
468 
469 class wxPreviewCanvas : public wxWindow
470 {
471     wxPreviewCanvas(wxPrintPreview *preview, wxWindow *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "wxPreviewCanvas");
472 };
473 
474 // ---------------------------------------------------------------------------
475 // wxPreviewControlBar
476 
477 #define wxPREVIEW_PRINT
478 #define wxPREVIEW_PREVIOUS
479 #define wxPREVIEW_NEXT
480 #define wxPREVIEW_ZOOM
481 #define wxPREVIEW_FIRST
482 #define wxPREVIEW_LAST
483 #define wxPREVIEW_GOTO
484 
485 #define wxID_PREVIEW_CLOSE
486 #define wxID_PREVIEW_NEXT
487 #define wxID_PREVIEW_PREVIOUS
488 #define wxID_PREVIEW_PRINT
489 #define wxID_PREVIEW_ZOOM
490 #define wxID_PREVIEW_FIRST
491 #define wxID_PREVIEW_LAST
492 #define wxID_PREVIEW_GOTO
493 
494 class wxPreviewControlBar : public wxWindow
495 {
496     wxPreviewControlBar(wxPrintPreview* preview, long buttons, wxWindow* parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "wxPreviewControlBar");
497 
498     //void CreateButtons();
499     virtual void SetZoomControl(int zoom);
500     virtual int GetZoomControl();
501     //virtual wxPrintPreviewBase *GetPrintPreview() const;
502 };
503 
504 // ---------------------------------------------------------------------------
505 // wxPrintPreview
506 #if wxLUA_USE_wxLuaPrintout
507 
508 class wxPrintPreview : public wxObject
509 {
510     wxPrintPreview(wxPrintout* printout, wxPrintout* printoutForPrinting, wxPrintData* data=NULL);
511 
512     bool DrawBlankPage(wxPreviewCanvas* window, wxDC& dc);
513     wxPreviewCanvas* GetCanvas();
514     int GetCurrentPage();
515     wxFrame * GetFrame();
516     int GetMaxPage();
517     int GetMinPage();
518     wxPrintout* GetPrintout();
519     wxPrintout* GetPrintoutForPrinting();
520     bool Ok();
521     bool PaintPage(wxPreviewCanvas* window, wxDC &dc);
522     bool Print(bool prompt);
523     bool RenderPage(int pageNum);
524     void SetCanvas(wxPreviewCanvas* window);
525     void SetCurrentPage(int pageNum);
526     void SetFrame(wxFrame *frame);
527     void SetPrintout(wxPrintout *printout);
528     void SetZoom(int percent);
529 };
530 
531 // ---------------------------------------------------------------------------
532 // wxPreviewFrame
533 
534 class wxPreviewFrame : public wxFrame
535 {
536     wxPreviewFrame(wxPrintPreview *preview, wxFrame *parent, const wxString &title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString &name = "wxPreviewFrame");
537 
538     void CreateControlBar();
539     void CreateCanvas();
540     void Initialize();
541     wxPreviewControlBar* GetControlBar() const;
542 };
543 
544 #endif //wxLUA_USE_wxLuaPrintout
545 
546 // ---------------------------------------------------------------------------
547 // wxPostScriptDC
548 
549 #if wxUSE_POSTSCRIPT
550 
551 #include "wx/dcps.h"
552 
553 class %delete wxPostScriptDC : public wxDC
554 {
555     wxPostScriptDC(const wxPrintData& printData);
556 
557     !%wxchkver_2_9_2 static void SetResolution(int ppi);
558     !%wxchkver_2_9_2 static int GetResolution();
559     %wxchkver_2_9_2 int GetResolution();
560 };
561 
562 #endif //wxUSE_POSTSCRIPT
563 
564 // ---------------------------------------------------------------------------
565 // wxPrinterDC
566 
567 #if %msw|%mac
568 #include "wx/dcprint.h"
569 
570 class %delete wxPrinterDC : public wxDC
571 {
572     wxPrinterDC(const wxPrintData& printData);
573 };
574 #endif // %msw|%mac
575 
576 #endif //wxLUA_USE_wxPrint && wxUSE_PRINTING_ARCHITECTURE
577 
578