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