]>
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$ | |
7 | // Copyright: (c) | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_HTMPRINT_H_ | |
12 | #define _WX_HTMPRINT_H_ | |
13 | ||
af49c4b8 | 14 | #if defined(__GNUG__) && !defined(__APPLE__) |
97494971 | 15 | #pragma interface "htmprint.h" |
3ce369e6 VS |
16 | #endif |
17 | ||
a2e9bc18 | 18 | #include "wx/defs.h" |
3ce369e6 | 19 | |
72cdf4c9 | 20 | #if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE |
3ce369e6 VS |
21 | |
22 | #include "wx/html/htmlcell.h" | |
23 | #include "wx/html/winpars.h" | |
24 | ||
25 | #include "wx/print.h" | |
26 | #include "wx/printdlg.h" | |
27 | ||
f2034f1b VS |
28 | #include <limits.h> // INT_MAX |
29 | ||
3ce369e6 VS |
30 | //-------------------------------------------------------------------------------- |
31 | // wxHtmlDCRenderer | |
32 | // This class is capable of rendering HTML into specified | |
33 | // portion of DC | |
34 | //-------------------------------------------------------------------------------- | |
35 | ||
72cdf4c9 | 36 | class WXDLLEXPORT wxHtmlDCRenderer : public wxObject |
3ce369e6 | 37 | { |
97494971 VS |
38 | public: |
39 | wxHtmlDCRenderer(); | |
40 | ~wxHtmlDCRenderer(); | |
41 | ||
42 | // Following 3 methods *must* be called before any call to Render: | |
43 | ||
f2034f1b | 44 | // Assign DC to this render |
97494971 VS |
45 | void SetDC(wxDC *dc, double pixel_scale = 1.0); |
46 | ||
47 | // Sets size of output rectangle, in pixels. Note that you *can't* change | |
48 | // width of the rectangle between calls to Render! (You can freely change height.) | |
49 | void SetSize(int width, int height); | |
50 | ||
51 | // Sets the text to be displayed. | |
52 | // Basepath is base directory (html string would be stored there if it was in | |
53 | // file). It is used to determine path for loading images, for example. | |
54 | // isdir is FALSE if basepath is filename, TRUE if it is directory name | |
55 | // (see wxFileSystem for detailed explanation) | |
56 | void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = TRUE); | |
57 | ||
4eecf115 VS |
58 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
59 | void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL); | |
60 | ||
97494971 | 61 | // [x,y] is position of upper-left corner of printing rectangle (see SetSize) |
f2034f1b VS |
62 | // from is y-coordinate of the very first visible cell |
63 | // to is y-coordinate of the next following page break, if any | |
97494971 VS |
64 | // Returned value is y coordinate of first cell than didn't fit onto page. |
65 | // Use this value as 'from' in next call to Render in order to print multiple pages | |
66 | // document | |
67 | // If dont_render is TRUE then nothing is rendered into DC and it only counts | |
68 | // pixels and return y coord of the next page | |
69 | // | |
f2034f1b VS |
70 | // known_pagebreaks and number_of_pages are used only when counting pages; |
71 | // otherwise, their default values should be used. Their purpose is to | |
72 | // support pagebreaks using a subset of CSS2's <DIV>. The <DIV> handler | |
73 | // needs to know what pagebreaks have already been set so that it doesn't | |
74 | // set the same pagebreak twice. | |
75 | // | |
76 | // CAUTION! Render() changes DC's user scale and does NOT restore it! | |
77 | int Render(int x, int y, int from = 0, int dont_render = FALSE, int to = INT_MAX, | |
78 | int *known_pagebreaks = NULL, int number_of_pages = 0); | |
97494971 VS |
79 | |
80 | // returns total height of the html document | |
81 | // (compare Render's return value with this) | |
82 | int GetTotalHeight(); | |
83 | ||
84 | private: | |
85 | wxDC *m_DC; | |
86 | wxHtmlWinParser *m_Parser; | |
87 | wxFileSystem *m_FS; | |
88 | wxHtmlContainerCell *m_Cells; | |
89 | int m_MaxWidth, m_Width, m_Height; | |
22f3361e VZ |
90 | |
91 | DECLARE_NO_COPY_CLASS(wxHtmlDCRenderer) | |
3ce369e6 VS |
92 | }; |
93 | ||
94 | ||
95 | ||
96 | ||
97 | ||
98 | enum { | |
99 | wxPAGE_ODD, | |
100 | wxPAGE_EVEN, | |
101 | wxPAGE_ALL | |
102 | }; | |
103 | ||
104 | ||
105 | ||
106 | //-------------------------------------------------------------------------------- | |
107 | // wxHtmlPrintout | |
108 | // This class is derived from standard wxWindows printout class | |
109 | // and is used to print HTML documents. | |
110 | //-------------------------------------------------------------------------------- | |
111 | ||
112 | ||
72cdf4c9 | 113 | class WXDLLEXPORT wxHtmlPrintout : public wxPrintout |
3ce369e6 | 114 | { |
29786211 | 115 | public: |
2b5f62a0 | 116 | wxHtmlPrintout(const wxString& title = wxT("Printout")); |
29786211 VS |
117 | ~wxHtmlPrintout(); |
118 | ||
119 | void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = TRUE); | |
120 | // prepares the class for printing this html document. | |
121 | // Must be called before using the class, in fact just after constructor | |
122 | // | |
123 | // basepath is base directory (html string would be stored there if it was in | |
124 | // file). It is used to determine path for loading images, for example. | |
125 | // isdir is FALSE if basepath is filename, TRUE if it is directory name | |
126 | // (see wxFileSystem for detailed explanation) | |
127 | ||
128 | void SetHtmlFile(const wxString &htmlfile); | |
129 | // same as SetHtmlText except that it takes regular file as the parameter | |
130 | ||
131 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
132 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
133 | // sets header/footer for the document. The argument is interpreted as HTML document. | |
134 | // You can use macros in it: | |
135 | // @PAGENUM@ is replaced by page number | |
136 | // @PAGESCNT@ is replaced by total number of pages | |
137 | // | |
138 | // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants. | |
139 | // You can set different header/footer for odd and even pages | |
140 | ||
4eecf115 VS |
141 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
142 | void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL); | |
143 | ||
29786211 VS |
144 | void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2, |
145 | float spaces = 5); | |
146 | // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space | |
147 | // between text and header and/or footer | |
148 | ||
149 | // wxPrintout stuff: | |
150 | bool OnPrintPage(int page); | |
151 | bool HasPage(int page); | |
152 | void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo); | |
153 | bool OnBeginDocument(int startPage, int endPage); | |
154 | ||
155 | private: | |
156 | ||
157 | void RenderPage(wxDC *dc, int page); | |
158 | // renders one page into dc | |
159 | wxString TranslateHeader(const wxString& instr, int page); | |
160 | // substitute @PAGENUM@ and @PAGESCNT@ by real values | |
161 | void CountPages(); | |
162 | // counts pages and fills m_NumPages and m_PageBreaks | |
163 | ||
164 | ||
165 | private: | |
166 | int m_NumPages; | |
167 | int m_PageBreaks[wxHTML_PRINT_MAX_PAGES]; | |
168 | ||
169 | wxString m_Document, m_BasePath; | |
170 | bool m_BasePathIsDir; | |
171 | wxString m_Headers[2], m_Footers[2]; | |
172 | ||
173 | int m_HeaderHeight, m_FooterHeight; | |
174 | wxHtmlDCRenderer *m_Renderer, *m_RendererHdr; | |
175 | float m_MarginTop, m_MarginBottom, m_MarginLeft, m_MarginRight, m_MarginSpace; | |
22f3361e VZ |
176 | |
177 | DECLARE_NO_COPY_CLASS(wxHtmlPrintout) | |
3ce369e6 VS |
178 | }; |
179 | ||
180 | ||
181 | ||
182 | ||
183 | ||
184 | //-------------------------------------------------------------------------------- | |
185 | // wxHtmlEasyPrinting | |
186 | // This class provides very simple interface to printing | |
187 | // architecture. It allows you to print HTML documents only | |
188 | // with very few commands. | |
189 | // | |
190 | // Note : do not create this class on stack only. | |
191 | // You should create an instance on app startup and | |
192 | // use this instance for all printing. Why? The class | |
193 | // stores page&printer settings in it. | |
194 | //-------------------------------------------------------------------------------- | |
195 | ||
72cdf4c9 | 196 | class WXDLLEXPORT wxHtmlEasyPrinting : public wxObject |
3ce369e6 | 197 | { |
29786211 | 198 | public: |
a5ae8241 | 199 | wxHtmlEasyPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL); |
29786211 VS |
200 | ~wxHtmlEasyPrinting(); |
201 | ||
202 | bool PreviewFile(const wxString &htmlfile); | |
203 | bool PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString); | |
204 | // Preview file / html-text for printing | |
205 | // (and offers printing) | |
206 | // basepath is base directory for opening subsequent files (e.g. from <img> tag) | |
207 | ||
208 | bool PrintFile(const wxString &htmlfile); | |
209 | bool PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString); | |
210 | // Print file / html-text w/o preview | |
211 | ||
212 | void PrinterSetup(); | |
213 | void PageSetup(); | |
214 | // pop up printer or page setup dialog | |
215 | ||
216 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
217 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
218 | // sets header/footer for the document. The argument is interpreted as HTML document. | |
219 | // You can use macros in it: | |
220 | // @PAGENUM@ is replaced by page number | |
221 | // @PAGESCNT@ is replaced by total number of pages | |
222 | // | |
223 | // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants. | |
224 | // You can set different header/footer for odd and even pages | |
225 | ||
4eecf115 VS |
226 | void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = 0); |
227 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used) | |
228 | ||
29786211 VS |
229 | wxPrintData *GetPrintData() {return m_PrintData;} |
230 | wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;} | |
231 | // return page setting data objects. | |
232 | // (You can set their parameters.) | |
233 | ||
f2034f1b | 234 | protected: |
29786211 VS |
235 | virtual wxHtmlPrintout *CreatePrintout(); |
236 | virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2); | |
237 | virtual bool DoPrint(wxHtmlPrintout *printout); | |
238 | ||
239 | private: | |
240 | wxPrintData *m_PrintData; | |
241 | wxPageSetupDialogData *m_PageSetupData; | |
242 | wxString m_Name; | |
4eecf115 VS |
243 | int m_FontsSizesArr[7]; |
244 | int *m_FontsSizes; | |
245 | wxString m_FontFaceFixed, m_FontFaceNormal; | |
29786211 | 246 | wxString m_Headers[2], m_Footers[2]; |
a5ae8241 | 247 | wxWindow *m_ParentWindow; |
22f3361e VZ |
248 | |
249 | DECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting) | |
3ce369e6 VS |
250 | }; |
251 | ||
252 | ||
253 | ||
254 | ||
72cdf4c9 | 255 | #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE |
3ce369e6 VS |
256 | |
257 | #endif // _WX_HTMPRINT_H_ | |
258 |