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