printing.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: samples/printing.h
  3. // Purpose: Printing demo for wxWidgets
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 1995
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // Define a new application
  11. class MyApp: public wxApp
  12. {
  13. public:
  14. MyApp() {}
  15. virtual bool OnInit();
  16. virtual int OnExit();
  17. void Draw(wxDC& dc);
  18. void IncrementAngle()
  19. { m_angle += 5; }
  20. void DecrementAngle()
  21. { m_angle -= 5; }
  22. wxFont& GetTestFont()
  23. { return m_testFont; }
  24. private:
  25. int m_angle;
  26. wxBitmap m_bitmap;
  27. wxFont m_testFont;
  28. };
  29. DECLARE_APP(MyApp)
  30. class MyCanvas;
  31. // Define a new canvas and frame
  32. class MyFrame: public wxFrame
  33. {
  34. public:
  35. MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
  36. void OnAngleUp(wxCommandEvent& event);
  37. void OnAngleDown(wxCommandEvent& event);
  38. void OnPrint(wxCommandEvent& event);
  39. void OnPrintPreview(wxCommandEvent& event);
  40. void OnPageSetup(wxCommandEvent& event);
  41. #if wxUSE_POSTSCRIPT
  42. void OnPrintPS(wxCommandEvent& event);
  43. void OnPrintPreviewPS(wxCommandEvent& event);
  44. void OnPageSetupPS(wxCommandEvent& event);
  45. #endif
  46. #ifdef __WXMAC__
  47. void OnPageMargins(wxCommandEvent& event);
  48. #endif
  49. void OnPreviewFrameModalityKind(wxCommandEvent& event);
  50. void OnExit(wxCommandEvent& event);
  51. void OnPrintAbout(wxCommandEvent& event);
  52. private:
  53. MyCanvas* m_canvas;
  54. wxPreviewFrameModalityKind m_previewModality;
  55. wxDECLARE_EVENT_TABLE();
  56. };
  57. // Define a new white canvas
  58. class MyCanvas: public wxScrolledWindow
  59. {
  60. public:
  61. MyCanvas(wxFrame *frame, const wxPoint& pos, const wxSize& size, long style = wxRETAINED);
  62. //void OnPaint(wxPaintEvent& evt);
  63. virtual void OnDraw(wxDC& dc);
  64. private:
  65. wxDECLARE_EVENT_TABLE();
  66. };
  67. // Defines a new printout class to print our document
  68. class MyPrintout: public wxPrintout
  69. {
  70. public:
  71. MyPrintout(MyFrame* frame, const wxString &title = wxT("My printout"))
  72. : wxPrintout(title) { m_frame=frame; }
  73. virtual bool OnPrintPage(int page);
  74. virtual bool HasPage(int page);
  75. virtual bool OnBeginDocument(int startPage, int endPage);
  76. virtual void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
  77. void DrawPageOne();
  78. void DrawPageTwo();
  79. // Writes a header on a page. Margin units are in millimetres.
  80. bool WritePageHeader(wxPrintout *printout, wxDC *dc, const wxString& text, float mmToLogical);
  81. private:
  82. MyFrame *m_frame;
  83. };
  84. // constants:
  85. enum
  86. {
  87. WXPRINT_PAGE_SETUP = 103,
  88. WXPRINT_PRINT_PS,
  89. WXPRINT_PAGE_SETUP_PS,
  90. WXPRINT_PREVIEW_PS,
  91. WXPRINT_ANGLEUP,
  92. WXPRINT_ANGLEDOWN,
  93. #ifdef __WXMAC__
  94. WXPRINT_PAGE_MARGINS,
  95. #endif
  96. WXPRINT_FRAME_MODAL_APP,
  97. WXPRINT_FRAME_MODAL_WIN,
  98. WXPRINT_FRAME_MODAL_NON
  99. };