]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextprint.h
4c4104321017d278ead47c78b8a3f1cee40e0ff5
[wxWidgets.git] / include / wx / richtext / richtextprint.h
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$
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_RICHTEXTPRINT_H_
12 #define _WX_RICHTEXTPRINT_H_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
17
18 #include "wx/richtext/richtextbuffer.h"
19
20 #include "wx/print.h"
21 #include "wx/printdlg.h"
22
23 #define wxRICHTEXT_PRINT_MAX_PAGES 99999
24
25 // Header/footer page identifiers
26 enum wxRichTextOddEvenPage {
27 wxRICHTEXT_PAGE_ODD,
28 wxRICHTEXT_PAGE_EVEN,
29 wxRICHTEXT_PAGE_ALL
30 };
31
32 // Header/footer text locations
33 enum wxRichTextPageLocation {
34 wxRICHTEXT_PAGE_LEFT,
35 wxRICHTEXT_PAGE_CENTRE,
36 wxRICHTEXT_PAGE_RIGHT
37 };
38
39 /*!
40 * Header/footer data
41 */
42
43 class WXDLLIMPEXP_RICHTEXT wxRichTextHeaderFooterData: public wxObject
44 {
45 public:
46 wxRichTextHeaderFooterData() { Init(); }
47 wxRichTextHeaderFooterData(const wxRichTextHeaderFooterData& data): wxObject() { Copy(data); }
48
49 /// Initialise
50 void Init() { m_headerMargin = 20; m_footerMargin = 20; m_showOnFirstPage = true; }
51
52 /// Copy
53 void Copy(const wxRichTextHeaderFooterData& data);
54
55 /// Assignment
56 void operator= (const wxRichTextHeaderFooterData& data) { Copy(data); }
57
58 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
59 void SetHeaderText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
60 wxString GetHeaderText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
61
62 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
63 void SetFooterText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
64 wxString GetFooterText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
65
66 /// Set/get text
67 void SetText(const wxString& text, int headerFooter, wxRichTextOddEvenPage page, wxRichTextPageLocation location);
68 wxString GetText(int headerFooter, wxRichTextOddEvenPage page, wxRichTextPageLocation location) const;
69
70 /// Set/get margins between text and header or footer, in tenths of a millimeter
71 void SetMargins(int headerMargin, int footerMargin) { m_headerMargin = headerMargin; m_footerMargin = footerMargin; }
72 int GetHeaderMargin() const { return m_headerMargin; }
73 int GetFooterMargin() const { return m_footerMargin; }
74
75 /// Set/get whether to show header or footer on first page
76 void SetShowOnFirstPage(bool showOnFirstPage) { m_showOnFirstPage = showOnFirstPage; }
77 bool GetShowOnFirstPage() const { return m_showOnFirstPage; }
78
79 /// Clear all text
80 void Clear();
81
82 /// Set/get font
83 void SetFont(const wxFont& font) { m_font = font; }
84 const wxFont& GetFont() const { return m_font; }
85
86 /// Set/get colour
87 void SetTextColour(const wxColour& col) { m_colour = col; }
88 const wxColour& GetTextColour() const { return m_colour; }
89
90 DECLARE_CLASS(wxRichTextHeaderFooterData)
91
92 private:
93
94 // Strings for left, centre, right, top, bottom, odd, even
95 wxString m_text[12];
96 wxFont m_font;
97 wxColour m_colour;
98 int m_headerMargin;
99 int m_footerMargin;
100 bool m_showOnFirstPage;
101 };
102
103 /*!
104 * wxRichTextPrintout
105 */
106
107 class WXDLLIMPEXP_RICHTEXT wxRichTextPrintout : public wxPrintout
108 {
109 public:
110 wxRichTextPrintout(const wxString& title = _("Printout"));
111 virtual ~wxRichTextPrintout();
112
113 /// The buffer to print
114 void SetRichTextBuffer(wxRichTextBuffer* buffer) { m_richTextBuffer = buffer; }
115 wxRichTextBuffer* GetRichTextBuffer() const { return m_richTextBuffer; }
116
117 /// Set/get header/footer data
118 void SetHeaderFooterData(const wxRichTextHeaderFooterData& data) { m_headerFooterData = data; }
119 const wxRichTextHeaderFooterData& GetHeaderFooterData() const { return m_headerFooterData; }
120
121 /// Sets margins in 10ths of millimetre. Defaults to 1 inch for margins.
122 void SetMargins(int top = 254, int bottom = 254, int left = 254, int right = 254);
123
124 /// Calculate scaling and rectangles, setting the device context scaling
125 void CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& headerRect, wxRect& footerRect);
126
127 // wxPrintout virtual functions
128 virtual bool OnPrintPage(int page);
129 virtual bool HasPage(int page);
130 virtual void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
131 virtual bool OnBeginDocument(int startPage, int endPage);
132 virtual void OnPreparePrinting();
133
134 private:
135
136 /// Renders one page into dc
137 void RenderPage(wxDC *dc, int page);
138
139 /// Substitute keywords
140 static bool SubstituteKeywords(wxString& str, const wxString& title, int pageNum, int pageCount);
141
142 private:
143
144 wxRichTextBuffer* m_richTextBuffer;
145 int m_numPages;
146 wxArrayInt m_pageBreaksStart;
147 wxArrayInt m_pageBreaksEnd;
148 wxArrayInt m_pageYOffsets;
149 int m_marginLeft, m_marginTop, m_marginRight, m_marginBottom;
150
151 wxRichTextHeaderFooterData m_headerFooterData;
152
153 wxDECLARE_NO_COPY_CLASS(wxRichTextPrintout);
154 };
155
156 /*
157 *! wxRichTextPrinting
158 * A simple interface to perform wxRichTextBuffer printing.
159 */
160
161 class WXDLLIMPEXP_RICHTEXT wxRichTextPrinting : public wxObject
162 {
163 public:
164 wxRichTextPrinting(const wxString& name = _("Printing"), wxWindow *parentWindow = NULL);
165 virtual ~wxRichTextPrinting();
166
167 /// Preview the file or buffer
168 #if wxUSE_FFILE && wxUSE_STREAMS
169 bool PreviewFile(const wxString& richTextFile);
170 #endif
171 bool PreviewBuffer(const wxRichTextBuffer& buffer);
172
173 /// Print the file or buffer
174 #if wxUSE_FFILE && wxUSE_STREAMS
175 bool PrintFile(const wxString& richTextFile, bool showPrintDialog = true);
176 #endif
177 bool PrintBuffer(const wxRichTextBuffer& buffer, bool showPrintDialog = true);
178
179 /// Shows page setup dialog
180 void PageSetup();
181
182 /// Set/get header/footer data
183 void SetHeaderFooterData(const wxRichTextHeaderFooterData& data) { m_headerFooterData = data; }
184 const wxRichTextHeaderFooterData& GetHeaderFooterData() const { return m_headerFooterData; }
185
186 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
187 void SetHeaderText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
188 wxString GetHeaderText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
189
190 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
191 void SetFooterText(const wxString& text, wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
192 wxString GetFooterText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
193
194 /// Show header/footer on first page, or not
195 void SetShowOnFirstPage(bool show) { m_headerFooterData.SetShowOnFirstPage(show); }
196
197 /// Set the font
198 void SetHeaderFooterFont(const wxFont& font) { m_headerFooterData.SetFont(font); }
199
200 /// Set the colour
201 void SetHeaderFooterTextColour(const wxColour& font) { m_headerFooterData.SetTextColour(font); }
202
203 /// Get print and page setup data
204 wxPrintData *GetPrintData();
205 wxPageSetupDialogData *GetPageSetupData() { return m_pageSetupData; }
206
207 /// Set print and page setup data
208 void SetPrintData(const wxPrintData& printData);
209 void SetPageSetupData(const wxPageSetupDialogData& pageSetupData);
210
211 /// Set the rich text buffer pointer, deleting the existing object if present
212 void SetRichTextBufferPreview(wxRichTextBuffer* buf);
213 wxRichTextBuffer* GetRichTextBufferPreview() const { return m_richTextBufferPreview; }
214
215 void SetRichTextBufferPrinting(wxRichTextBuffer* buf);
216 wxRichTextBuffer* GetRichTextBufferPrinting() const { return m_richTextBufferPrinting; }
217
218 /// Set/get the parent window
219 void SetParentWindow(wxWindow* parent) { m_parentWindow = parent; }
220 wxWindow* GetParentWindow() const { return m_parentWindow; }
221
222 /// Set/get the title
223 void SetTitle(const wxString& title) { m_title = title; }
224 const wxString& GetTitle() const { return m_title; }
225
226 /// Set/get the preview rect
227 void SetPreviewRect(const wxRect& rect) { m_previewRect = rect; }
228 const wxRect& GetPreviewRect() const { return m_previewRect; }
229
230 protected:
231 virtual wxRichTextPrintout *CreatePrintout();
232 virtual bool DoPreview(wxRichTextPrintout *printout1, wxRichTextPrintout *printout2);
233 virtual bool DoPrint(wxRichTextPrintout *printout, bool showPrintDialog);
234
235 private:
236 wxPrintData* m_printData;
237 wxPageSetupDialogData* m_pageSetupData;
238
239 wxRichTextHeaderFooterData m_headerFooterData;
240 wxString m_title;
241 wxWindow* m_parentWindow;
242 wxRichTextBuffer* m_richTextBufferPreview;
243 wxRichTextBuffer* m_richTextBufferPrinting;
244 wxRect m_previewRect;
245
246 wxDECLARE_NO_COPY_CLASS(wxRichTextPrinting);
247 };
248
249 #endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
250
251 #endif // _WX_RICHTEXTPRINT_H_
252