PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Extras/wxWidgets-2.9.0/include/wx/richtext/richtextprint.h

http://dynamica.googlecode.com/
C Header | 247 lines | 129 code | 63 blank | 55 comment | 0 complexity | b289fb6efec06e26cf48be26e0a18723 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-3.0
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/richtext/richtextprint.h
  3. // Purpose: Rich text printing classes
  4. // Author: Julian Smart
  5. // Created: 2006-10-23
  6. // RCS-ID: $Id: richtextprint.h 58757 2009-02-08 11:45:59Z VZ $
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RICHTEXTPRINT_H_
  11. #define _WX_RICHTEXTPRINT_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
  14. #include "wx/richtext/richtextbuffer.h"
  15. #include "wx/print.h"
  16. #include "wx/printdlg.h"
  17. #define wxRICHTEXT_PRINT_MAX_PAGES 99999
  18. // Header/footer page identifiers
  19. enum wxRichTextOddEvenPage {
  20. wxRICHTEXT_PAGE_ODD,
  21. wxRICHTEXT_PAGE_EVEN,
  22. wxRICHTEXT_PAGE_ALL
  23. };
  24. // Header/footer text locations
  25. enum wxRichTextPageLocation {
  26. wxRICHTEXT_PAGE_LEFT,
  27. wxRICHTEXT_PAGE_CENTRE,
  28. wxRICHTEXT_PAGE_RIGHT
  29. };
  30. /*!
  31. * Header/footer data
  32. */
  33. class WXDLLIMPEXP_RICHTEXT wxRichTextHeaderFooterData: public wxObject
  34. {
  35. public:
  36. wxRichTextHeaderFooterData() { Init(); }
  37. wxRichTextHeaderFooterData(const wxRichTextHeaderFooterData& data): wxObject() { Copy(data); }
  38. /// Initialise
  39. void Init() { m_headerMargin = 20; m_footerMargin = 20; m_showOnFirstPage = true; }
  40. /// Copy
  41. void Copy(const wxRichTextHeaderFooterData& data);
  42. /// Assignment
  43. void operator= (const wxRichTextHeaderFooterData& data) { Copy(data); }
  44. /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
  45. void SetHeaderText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
  46. wxString GetHeaderText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
  47. /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
  48. void SetFooterText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
  49. wxString GetFooterText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
  50. /// Set/get text
  51. void SetText(const wxString& text, int headerFooter, wxRichTextOddEvenPage page, wxRichTextPageLocation location);
  52. wxString GetText(int headerFooter, wxRichTextOddEvenPage page, wxRichTextPageLocation location) const;
  53. /// Set/get margins between text and header or footer, in tenths of a millimeter
  54. void SetMargins(int headerMargin, int footerMargin) { m_headerMargin = headerMargin; m_footerMargin = footerMargin; }
  55. int GetHeaderMargin() const { return m_headerMargin; }
  56. int GetFooterMargin() const { return m_footerMargin; }
  57. /// Set/get whether to show header or footer on first page
  58. void SetShowOnFirstPage(bool showOnFirstPage) { m_showOnFirstPage = showOnFirstPage; }
  59. bool GetShowOnFirstPage() const { return m_showOnFirstPage; }
  60. /// Clear all text
  61. void Clear();
  62. /// Set/get font
  63. void SetFont(const wxFont& font) { m_font = font; }
  64. const wxFont& GetFont() const { return m_font; }
  65. /// Set/get colour
  66. void SetTextColour(const wxColour& col) { m_colour = col; }
  67. const wxColour& GetTextColour() const { return m_colour; }
  68. DECLARE_CLASS(wxRichTextHeaderFooterData)
  69. private:
  70. // Strings for left, centre, right, top, bottom, odd, even
  71. wxString m_text[12];
  72. wxFont m_font;
  73. wxColour m_colour;
  74. int m_headerMargin;
  75. int m_footerMargin;
  76. bool m_showOnFirstPage;
  77. };
  78. /*!
  79. * wxRichTextPrintout
  80. */
  81. class WXDLLIMPEXP_RICHTEXT wxRichTextPrintout : public wxPrintout
  82. {
  83. public:
  84. wxRichTextPrintout(const wxString& title = wxT("Printout"));
  85. virtual ~wxRichTextPrintout();
  86. /// The buffer to print
  87. void SetRichTextBuffer(wxRichTextBuffer* buffer) { m_richTextBuffer = buffer; }
  88. wxRichTextBuffer* GetRichTextBuffer() const { return m_richTextBuffer; }
  89. /// Set/get header/footer data
  90. void SetHeaderFooterData(const wxRichTextHeaderFooterData& data) { m_headerFooterData = data; }
  91. const wxRichTextHeaderFooterData& GetHeaderFooterData() const { return m_headerFooterData; }
  92. /// Sets margins in 10ths of millimetre. Defaults to 1 inch for margins.
  93. void SetMargins(int top = 254, int bottom = 254, int left = 254, int right = 254);
  94. /// Calculate scaling and rectangles, setting the device context scaling
  95. void CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& headerRect, wxRect& footerRect);
  96. // wxPrintout virtual functions
  97. virtual bool OnPrintPage(int page);
  98. virtual bool HasPage(int page);
  99. virtual void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
  100. virtual bool OnBeginDocument(int startPage, int endPage);
  101. virtual void OnPreparePrinting();
  102. private:
  103. /// Renders one page into dc
  104. void RenderPage(wxDC *dc, int page);
  105. /// Substitute keywords
  106. static bool SubstituteKeywords(wxString& str, const wxString& title, int pageNum, int pageCount);
  107. private:
  108. wxRichTextBuffer* m_richTextBuffer;
  109. int m_numPages;
  110. wxArrayInt m_pageBreaksStart;
  111. wxArrayInt m_pageBreaksEnd;
  112. int m_marginLeft, m_marginTop, m_marginRight, m_marginBottom;
  113. wxRichTextHeaderFooterData m_headerFooterData;
  114. wxDECLARE_NO_COPY_CLASS(wxRichTextPrintout);
  115. };
  116. /*
  117. *! wxRichTextPrinting
  118. * A simple interface to perform wxRichTextBuffer printing.
  119. */
  120. class WXDLLIMPEXP_RICHTEXT wxRichTextPrinting : public wxObject
  121. {
  122. public:
  123. wxRichTextPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL);
  124. virtual ~wxRichTextPrinting();
  125. /// Preview the file or buffer
  126. bool PreviewFile(const wxString& richTextFile);
  127. bool PreviewBuffer(const wxRichTextBuffer& buffer);
  128. /// Print the file or buffer
  129. bool PrintFile(const wxString& richTextFile);
  130. bool PrintBuffer(const wxRichTextBuffer& buffer);
  131. /// Shows page setup dialog
  132. void PageSetup();
  133. /// Set/get header/footer data
  134. void SetHeaderFooterData(const wxRichTextHeaderFooterData& data) { m_headerFooterData = data; }
  135. const wxRichTextHeaderFooterData& GetHeaderFooterData() const { return m_headerFooterData; }
  136. /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
  137. void SetHeaderText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
  138. wxString GetHeaderText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
  139. /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
  140. void SetFooterText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
  141. wxString GetFooterText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
  142. /// Show header/footer on first page, or not
  143. void SetShowOnFirstPage(bool show) { m_headerFooterData.SetShowOnFirstPage(show); }
  144. /// Set the font
  145. void SetHeaderFooterFont(const wxFont& font) { m_headerFooterData.SetFont(font); }
  146. /// Set the colour
  147. void SetHeaderFooterTextColour(const wxColour& font) { m_headerFooterData.SetTextColour(font); }
  148. /// Get print and page setup data
  149. wxPrintData *GetPrintData();
  150. wxPageSetupDialogData *GetPageSetupData() { return m_pageSetupData; }
  151. /// Set print and page setup data
  152. void SetPrintData(const wxPrintData& printData);
  153. void SetPageSetupData(const wxPageSetupData& pageSetupData);
  154. /// Set the rich text buffer pointer, deleting the existing object if present
  155. void SetRichTextBufferPreview(wxRichTextBuffer* buf);
  156. wxRichTextBuffer* GetRichTextBufferPreview() const { return m_richTextBufferPreview; }
  157. void SetRichTextBufferPrinting(wxRichTextBuffer* buf);
  158. wxRichTextBuffer* GetRichTextBufferPrinting() const { return m_richTextBufferPrinting; }
  159. /// Set/get the parent window
  160. void SetParentWindow(wxWindow* parent) { m_parentWindow = parent; }
  161. wxWindow* GetParentWindow() const { return m_parentWindow; }
  162. /// Set/get the title
  163. void SetTitle(const wxString& title) { m_title = title; }
  164. const wxString& GetTitle() const { return m_title; }
  165. /// Set/get the preview rect
  166. void SetPreviewRect(const wxRect& rect) { m_previewRect = rect; }
  167. const wxRect& GetPreviewRect() const { return m_previewRect; }
  168. protected:
  169. virtual wxRichTextPrintout *CreatePrintout();
  170. virtual bool DoPreview(wxRichTextPrintout *printout1, wxRichTextPrintout *printout2);
  171. virtual bool DoPrint(wxRichTextPrintout *printout);
  172. private:
  173. wxPrintData* m_printData;
  174. wxPageSetupDialogData* m_pageSetupData;
  175. wxRichTextHeaderFooterData m_headerFooterData;
  176. wxString m_title;
  177. wxWindow* m_parentWindow;
  178. wxRichTextBuffer* m_richTextBufferPreview;
  179. wxRichTextBuffer* m_richTextBufferPrinting;
  180. wxRect m_previewRect;
  181. wxDECLARE_NO_COPY_CLASS(wxRichTextPrinting);
  182. };
  183. #endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
  184. #endif // _WX_RICHTEXTPRINT_H_