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