]>
Commit | Line | Data |
---|---|---|
3ce369e6 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmprint.h | |
3 | // Purpose: html printing classes | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 25/09/99 | |
6 | // RCS-ID: $Id$ | |
99d80019 | 7 | // Copyright: (c) Vaclav Slavik |
65571936 | 8 | // Licence: wxWindows licence |
3ce369e6 VS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_HTMPRINT_H_ | |
12 | #define _WX_HTMPRINT_H_ | |
13 | ||
a2e9bc18 | 14 | #include "wx/defs.h" |
3ce369e6 | 15 | |
72cdf4c9 | 16 | #if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE |
3ce369e6 VS |
17 | |
18 | #include "wx/html/htmlcell.h" | |
19 | #include "wx/html/winpars.h" | |
fa10c70c | 20 | #include "wx/html/htmlfilt.h" |
3ce369e6 VS |
21 | |
22 | #include "wx/print.h" | |
23 | #include "wx/printdlg.h" | |
24 | ||
f2034f1b VS |
25 | #include <limits.h> // INT_MAX |
26 | ||
3ce369e6 VS |
27 | //-------------------------------------------------------------------------------- |
28 | // wxHtmlDCRenderer | |
6953da00 | 29 | // This class is capable of rendering HTML into specified |
3ce369e6 VS |
30 | // portion of DC |
31 | //-------------------------------------------------------------------------------- | |
32 | ||
6acba9a7 | 33 | class WXDLLIMPEXP_HTML wxHtmlDCRenderer : public wxObject |
3ce369e6 | 34 | { |
97494971 VS |
35 | public: |
36 | wxHtmlDCRenderer(); | |
d3c7fc99 | 37 | virtual ~wxHtmlDCRenderer(); |
97494971 VS |
38 | |
39 | // Following 3 methods *must* be called before any call to Render: | |
40 | ||
f2034f1b | 41 | // Assign DC to this render |
c44a49b8 VS |
42 | void SetDC(wxDC *dc, double pixel_scale = 1.0) |
43 | { SetDC(dc, pixel_scale, pixel_scale); } | |
44 | void SetDC(wxDC *dc, double pixel_scale, double font_scale); | |
97494971 VS |
45 | |
46 | // Sets size of output rectangle, in pixels. Note that you *can't* change | |
47 | // width of the rectangle between calls to Render! (You can freely change height.) | |
48 | void SetSize(int width, int height); | |
49 | ||
50 | // Sets the text to be displayed. | |
51 | // Basepath is base directory (html string would be stored there if it was in | |
52 | // file). It is used to determine path for loading images, for example. | |
6953da00 | 53 | // isdir is false if basepath is filename, true if it is directory name |
97494971 | 54 | // (see wxFileSystem for detailed explanation) |
6953da00 | 55 | void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = true); |
97494971 | 56 | |
4eecf115 | 57 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
fbfb8bcc | 58 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL); |
4eecf115 | 59 | |
10e5c7ea VS |
60 | // Sets font sizes to be relative to the given size or the system |
61 | // default size; use either specified or default font | |
62 | void SetStandardFonts(int size = -1, | |
63 | const wxString& normal_face = wxEmptyString, | |
64 | const wxString& fixed_face = wxEmptyString); | |
7acd3625 | 65 | |
97494971 | 66 | // [x,y] is position of upper-left corner of printing rectangle (see SetSize) |
f2034f1b VS |
67 | // from is y-coordinate of the very first visible cell |
68 | // to is y-coordinate of the next following page break, if any | |
97494971 VS |
69 | // Returned value is y coordinate of first cell than didn't fit onto page. |
70 | // Use this value as 'from' in next call to Render in order to print multiple pages | |
71 | // document | |
72 | // If dont_render is TRUE then nothing is rendered into DC and it only counts | |
73 | // pixels and return y coord of the next page | |
74 | // | |
f2034f1b VS |
75 | // known_pagebreaks and number_of_pages are used only when counting pages; |
76 | // otherwise, their default values should be used. Their purpose is to | |
77 | // support pagebreaks using a subset of CSS2's <DIV>. The <DIV> handler | |
78 | // needs to know what pagebreaks have already been set so that it doesn't | |
79 | // set the same pagebreak twice. | |
80 | // | |
81 | // CAUTION! Render() changes DC's user scale and does NOT restore it! | |
fd0bab43 | 82 | int Render(int x, int y, wxArrayInt& known_pagebreaks, int from = 0, |
18e9c453 | 83 | int dont_render = false, int to = INT_MAX); |
97494971 | 84 | |
4209475c VZ |
85 | // returns total width of the html document |
86 | int GetTotalWidth() const; | |
87 | ||
97494971 VS |
88 | // returns total height of the html document |
89 | // (compare Render's return value with this) | |
4209475c | 90 | int GetTotalHeight() const; |
97494971 VS |
91 | |
92 | private: | |
93 | wxDC *m_DC; | |
94 | wxHtmlWinParser *m_Parser; | |
95 | wxFileSystem *m_FS; | |
96 | wxHtmlContainerCell *m_Cells; | |
97 | int m_MaxWidth, m_Width, m_Height; | |
22f3361e | 98 | |
c0c133e1 | 99 | wxDECLARE_NO_COPY_CLASS(wxHtmlDCRenderer); |
3ce369e6 VS |
100 | }; |
101 | ||
102 | ||
103 | ||
104 | ||
105 | ||
106 | enum { | |
107 | wxPAGE_ODD, | |
108 | wxPAGE_EVEN, | |
109 | wxPAGE_ALL | |
110 | }; | |
111 | ||
112 | ||
113 | ||
114 | //-------------------------------------------------------------------------------- | |
115 | // wxHtmlPrintout | |
77ffb593 | 116 | // This class is derived from standard wxWidgets printout class |
3ce369e6 VS |
117 | // and is used to print HTML documents. |
118 | //-------------------------------------------------------------------------------- | |
119 | ||
120 | ||
6acba9a7 | 121 | class WXDLLIMPEXP_HTML wxHtmlPrintout : public wxPrintout |
3ce369e6 | 122 | { |
29786211 | 123 | public: |
2b5f62a0 | 124 | wxHtmlPrintout(const wxString& title = wxT("Printout")); |
d3c7fc99 | 125 | virtual ~wxHtmlPrintout(); |
29786211 | 126 | |
6953da00 | 127 | void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = true); |
29786211 VS |
128 | // prepares the class for printing this html document. |
129 | // Must be called before using the class, in fact just after constructor | |
130 | // | |
131 | // basepath is base directory (html string would be stored there if it was in | |
132 | // file). It is used to determine path for loading images, for example. | |
6953da00 | 133 | // isdir is false if basepath is filename, true if it is directory name |
29786211 VS |
134 | // (see wxFileSystem for detailed explanation) |
135 | ||
136 | void SetHtmlFile(const wxString &htmlfile); | |
137 | // same as SetHtmlText except that it takes regular file as the parameter | |
138 | ||
139 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
140 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
141 | // sets header/footer for the document. The argument is interpreted as HTML document. | |
142 | // You can use macros in it: | |
143 | // @PAGENUM@ is replaced by page number | |
144 | // @PAGESCNT@ is replaced by total number of pages | |
145 | // | |
146 | // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants. | |
147 | // You can set different header/footer for odd and even pages | |
148 | ||
4eecf115 | 149 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
fbfb8bcc | 150 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL); |
4eecf115 | 151 | |
10e5c7ea VS |
152 | // Sets font sizes to be relative to the given size or the system |
153 | // default size; use either specified or default font | |
154 | void SetStandardFonts(int size = -1, | |
155 | const wxString& normal_face = wxEmptyString, | |
156 | const wxString& fixed_face = wxEmptyString); | |
7acd3625 | 157 | |
6953da00 | 158 | void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2, |
29786211 VS |
159 | float spaces = 5); |
160 | // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space | |
161 | // between text and header and/or footer | |
162 | ||
6953da00 | 163 | // wxPrintout stuff: |
29786211 VS |
164 | bool OnPrintPage(int page); |
165 | bool HasPage(int page); | |
166 | void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo); | |
167 | bool OnBeginDocument(int startPage, int endPage); | |
d2b354f9 | 168 | void OnPreparePrinting(); |
29786211 | 169 | |
fa10c70c JS |
170 | // Adds input filter |
171 | static void AddFilter(wxHtmlFilter *filter); | |
172 | ||
173 | // Cleanup | |
174 | static void CleanUpStatics(); | |
175 | ||
29786211 | 176 | private: |
4209475c VZ |
177 | // this function is called by the base class OnPreparePrinting() |
178 | // implementation and by default checks whether the document fits into | |
fc48f78f VZ |
179 | // pageArea horizontally and warns the user if it does not and, if we're |
180 | // going to print and not just to preview the document, giving him the | |
181 | // possibility to cancel printing | |
4209475c VZ |
182 | // |
183 | // you may override it to either suppress this check if truncation of the | |
184 | // HTML being printed is acceptable or, on the contrary, add more checks to | |
185 | // it, e.g. for the fit in the vertical direction if the document should | |
186 | // always appear on a single page | |
187 | // | |
fc48f78f VZ |
188 | // return true if printing should go ahead or false to cancel it (the |
189 | // return value is ignored when previewing) | |
4209475c | 190 | virtual bool CheckFit(const wxSize& pageArea, const wxSize& docArea) const; |
29786211 VS |
191 | |
192 | void RenderPage(wxDC *dc, int page); | |
193 | // renders one page into dc | |
194 | wxString TranslateHeader(const wxString& instr, int page); | |
195 | // substitute @PAGENUM@ and @PAGESCNT@ by real values | |
196 | void CountPages(); | |
197 | // counts pages and fills m_NumPages and m_PageBreaks | |
198 | ||
199 | ||
200 | private: | |
201 | int m_NumPages; | |
fd0bab43 VZ |
202 | //int m_PageBreaks[wxHTML_PRINT_MAX_PAGES]; |
203 | wxArrayInt m_PageBreaks; | |
29786211 VS |
204 | |
205 | wxString m_Document, m_BasePath; | |
206 | bool m_BasePathIsDir; | |
207 | wxString m_Headers[2], m_Footers[2]; | |
208 | ||
209 | int m_HeaderHeight, m_FooterHeight; | |
210 | wxHtmlDCRenderer *m_Renderer, *m_RendererHdr; | |
211 | float m_MarginTop, m_MarginBottom, m_MarginLeft, m_MarginRight, m_MarginSpace; | |
22f3361e | 212 | |
fa10c70c JS |
213 | // list of HTML filters |
214 | static wxList m_Filters; | |
215 | ||
c0c133e1 | 216 | wxDECLARE_NO_COPY_CLASS(wxHtmlPrintout); |
3ce369e6 VS |
217 | }; |
218 | ||
219 | ||
220 | ||
221 | ||
222 | ||
223 | //-------------------------------------------------------------------------------- | |
224 | // wxHtmlEasyPrinting | |
6953da00 | 225 | // This class provides very simple interface to printing |
3ce369e6 | 226 | // architecture. It allows you to print HTML documents only |
6953da00 | 227 | // with very few commands. |
3ce369e6 VS |
228 | // |
229 | // Note : do not create this class on stack only. | |
6953da00 | 230 | // You should create an instance on app startup and |
3ce369e6 VS |
231 | // use this instance for all printing. Why? The class |
232 | // stores page&printer settings in it. | |
233 | //-------------------------------------------------------------------------------- | |
234 | ||
6acba9a7 | 235 | class WXDLLIMPEXP_HTML wxHtmlEasyPrinting : public wxObject |
3ce369e6 | 236 | { |
29786211 | 237 | public: |
a5ae8241 | 238 | wxHtmlEasyPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL); |
d3c7fc99 | 239 | virtual ~wxHtmlEasyPrinting(); |
29786211 VS |
240 | |
241 | bool PreviewFile(const wxString &htmlfile); | |
242 | bool PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString); | |
243 | // Preview file / html-text for printing | |
244 | // (and offers printing) | |
245 | // basepath is base directory for opening subsequent files (e.g. from <img> tag) | |
246 | ||
247 | bool PrintFile(const wxString &htmlfile); | |
248 | bool PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString); | |
249 | // Print file / html-text w/o preview | |
250 | ||
29786211 VS |
251 | void PageSetup(); |
252 | // pop up printer or page setup dialog | |
253 | ||
254 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
255 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
256 | // sets header/footer for the document. The argument is interpreted as HTML document. | |
257 | // You can use macros in it: | |
258 | // @PAGENUM@ is replaced by page number | |
259 | // @PAGESCNT@ is replaced by total number of pages | |
260 | // | |
261 | // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants. | |
262 | // You can set different header/footer for odd and even pages | |
263 | ||
fbfb8bcc | 264 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = 0); |
4eecf115 VS |
265 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used) |
266 | ||
10e5c7ea VS |
267 | // Sets font sizes to be relative to the given size or the system |
268 | // default size; use either specified or default font | |
269 | void SetStandardFonts(int size = -1, | |
270 | const wxString& normal_face = wxEmptyString, | |
271 | const wxString& fixed_face = wxEmptyString); | |
6953da00 | 272 | |
632783de | 273 | wxPrintData *GetPrintData(); |
29786211 | 274 | wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;} |
6953da00 | 275 | // return page setting data objects. |
29786211 VS |
276 | // (You can set their parameters.) |
277 | ||
2a225ba6 JS |
278 | wxWindow* GetParentWindow() const { return m_ParentWindow; } |
279 | // get the parent window | |
280 | void SetParentWindow(wxWindow* window) { m_ParentWindow = window; } | |
281 | // set the parent window | |
282 | ||
0678e935 BP |
283 | const wxString& GetName() const { return m_Name; } |
284 | // get the printout name | |
285 | void SetName(const wxString& name) { m_Name = name; } | |
286 | // set the printout name | |
287 | ||
f2034f1b | 288 | protected: |
29786211 VS |
289 | virtual wxHtmlPrintout *CreatePrintout(); |
290 | virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2); | |
291 | virtual bool DoPrint(wxHtmlPrintout *printout); | |
292 | ||
293 | private: | |
294 | wxPrintData *m_PrintData; | |
295 | wxPageSetupDialogData *m_PageSetupData; | |
296 | wxString m_Name; | |
4eecf115 VS |
297 | int m_FontsSizesArr[7]; |
298 | int *m_FontsSizes; | |
299 | wxString m_FontFaceFixed, m_FontFaceNormal; | |
10e5c7ea VS |
300 | |
301 | enum FontMode | |
302 | { | |
303 | FontMode_Explicit, | |
304 | FontMode_Standard | |
305 | }; | |
306 | FontMode m_fontMode; | |
6953da00 | 307 | |
29786211 | 308 | wxString m_Headers[2], m_Footers[2]; |
a5ae8241 | 309 | wxWindow *m_ParentWindow; |
22f3361e | 310 | |
c0c133e1 | 311 | wxDECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting); |
3ce369e6 VS |
312 | }; |
313 | ||
314 | ||
315 | ||
316 | ||
72cdf4c9 | 317 | #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE |
3ce369e6 VS |
318 | |
319 | #endif // _WX_HTMPRINT_H_ | |
320 |