]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmprint.h
don't leave two conscutive separators after "moving" a standard menu item to the...
[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 // Sets font sizes to be relative to the given size or the system
63 // default size; use either specified or default font
64 void SetStandardFonts(int size = -1,
65 const wxString& normal_face = wxEmptyString,
66 const wxString& fixed_face = wxEmptyString);
67
68 // [x,y] is position of upper-left corner of printing rectangle (see SetSize)
69 // from is y-coordinate of the very first visible cell
70 // to is y-coordinate of the next following page break, if any
71 // Returned value is y coordinate of first cell than didn't fit onto page.
72 // Use this value as 'from' in next call to Render in order to print multiple pages
73 // document
74 // If dont_render is TRUE then nothing is rendered into DC and it only counts
75 // pixels and return y coord of the next page
76 //
77 // known_pagebreaks and number_of_pages are used only when counting pages;
78 // otherwise, their default values should be used. Their purpose is to
79 // support pagebreaks using a subset of CSS2's <DIV>. The <DIV> handler
80 // needs to know what pagebreaks have already been set so that it doesn't
81 // set the same pagebreak twice.
82 //
83 // CAUTION! Render() changes DC's user scale and does NOT restore it!
84 int Render(int x, int y, int from = 0, int dont_render = FALSE, int to = INT_MAX,
85 int *known_pagebreaks = NULL, int number_of_pages = 0);
86
87 // returns total height of the html document
88 // (compare Render's return value with this)
89 int GetTotalHeight();
90
91 private:
92 wxDC *m_DC;
93 wxHtmlWinParser *m_Parser;
94 wxFileSystem *m_FS;
95 wxHtmlContainerCell *m_Cells;
96 int m_MaxWidth, m_Width, m_Height;
97
98 DECLARE_NO_COPY_CLASS(wxHtmlDCRenderer)
99 };
100
101
102
103
104
105 enum {
106 wxPAGE_ODD,
107 wxPAGE_EVEN,
108 wxPAGE_ALL
109 };
110
111
112
113 //--------------------------------------------------------------------------------
114 // wxHtmlPrintout
115 // This class is derived from standard wxWidgets printout class
116 // and is used to print HTML documents.
117 //--------------------------------------------------------------------------------
118
119
120 class WXDLLIMPEXP_HTML wxHtmlPrintout : public wxPrintout
121 {
122 public:
123 wxHtmlPrintout(const wxString& title = wxT("Printout"));
124 ~wxHtmlPrintout();
125
126 void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = true);
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.
132 // isdir is false if basepath is filename, true if it is directory name
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
148 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
149 void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL);
150
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);
156
157 void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2,
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
162 // wxPrintout stuff:
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);
167 void OnPreparePrinting();
168
169 // Adds input filter
170 static void AddFilter(wxHtmlFilter *filter);
171
172 // Cleanup
173 static void CleanUpStatics();
174
175 private:
176
177 void RenderPage(wxDC *dc, int page);
178 // renders one page into dc
179 wxString TranslateHeader(const wxString& instr, int page);
180 // substitute @PAGENUM@ and @PAGESCNT@ by real values
181 void CountPages();
182 // counts pages and fills m_NumPages and m_PageBreaks
183
184
185 private:
186 int m_NumPages;
187 int m_PageBreaks[wxHTML_PRINT_MAX_PAGES];
188
189 wxString m_Document, m_BasePath;
190 bool m_BasePathIsDir;
191 wxString m_Headers[2], m_Footers[2];
192
193 int m_HeaderHeight, m_FooterHeight;
194 wxHtmlDCRenderer *m_Renderer, *m_RendererHdr;
195 float m_MarginTop, m_MarginBottom, m_MarginLeft, m_MarginRight, m_MarginSpace;
196
197 // list of HTML filters
198 static wxList m_Filters;
199
200 DECLARE_NO_COPY_CLASS(wxHtmlPrintout)
201 };
202
203
204
205
206
207 //--------------------------------------------------------------------------------
208 // wxHtmlEasyPrinting
209 // This class provides very simple interface to printing
210 // architecture. It allows you to print HTML documents only
211 // with very few commands.
212 //
213 // Note : do not create this class on stack only.
214 // You should create an instance on app startup and
215 // use this instance for all printing. Why? The class
216 // stores page&printer settings in it.
217 //--------------------------------------------------------------------------------
218
219 class WXDLLIMPEXP_HTML wxHtmlEasyPrinting : public wxObject
220 {
221 public:
222 wxHtmlEasyPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL);
223 ~wxHtmlEasyPrinting();
224
225 bool PreviewFile(const wxString &htmlfile);
226 bool PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
227 // Preview file / html-text for printing
228 // (and offers printing)
229 // basepath is base directory for opening subsequent files (e.g. from <img> tag)
230
231 bool PrintFile(const wxString &htmlfile);
232 bool PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
233 // Print file / html-text w/o preview
234
235 void PrinterSetup();
236 void PageSetup();
237 // pop up printer or page setup dialog
238
239 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
240 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
241 // sets header/footer for the document. The argument is interpreted as HTML document.
242 // You can use macros in it:
243 // @PAGENUM@ is replaced by page number
244 // @PAGESCNT@ is replaced by total number of pages
245 //
246 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
247 // You can set different header/footer for odd and even pages
248
249 void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = 0);
250 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used)
251
252 // Sets font sizes to be relative to the given size or the system
253 // default size; use either specified or default font
254 void SetStandardFonts(int size = -1,
255 const wxString& normal_face = wxEmptyString,
256 const wxString& fixed_face = wxEmptyString);
257
258 wxPrintData *GetPrintData();
259 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
260 // return page setting data objects.
261 // (You can set their parameters.)
262
263 protected:
264 virtual wxHtmlPrintout *CreatePrintout();
265 virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2);
266 virtual bool DoPrint(wxHtmlPrintout *printout);
267
268 private:
269 wxPrintData *m_PrintData;
270 wxPageSetupDialogData *m_PageSetupData;
271 wxString m_Name;
272 int m_FontsSizesArr[7];
273 int *m_FontsSizes;
274 wxString m_FontFaceFixed, m_FontFaceNormal;
275
276 enum FontMode
277 {
278 FontMode_Explicit,
279 FontMode_Standard
280 };
281 FontMode m_fontMode;
282
283 wxString m_Headers[2], m_Footers[2];
284 wxWindow *m_ParentWindow;
285
286 DECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting)
287 };
288
289
290
291
292 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
293
294 #endif // _WX_HTMPRINT_H_
295