]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/htmprint.h
Implemented Mac-style button toggling within wxButtonToolBar, and line
[wxWidgets.git] / include / wx / html / htmprint.h
CommitLineData
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$
99d80019 7// Copyright: (c) Vaclav Slavik
65571936 8// Licence: wxWindows licence
3ce369e6
VS
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_HTMPRINT_H_
12#define _WX_HTMPRINT_H_
13
a2e9bc18 14#include "wx/defs.h"
3ce369e6 15
72cdf4c9 16#if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
3ce369e6
VS
17
18#include "wx/html/htmlcell.h"
19#include "wx/html/winpars.h"
fa10c70c 20#include "wx/html/htmlfilt.h"
3ce369e6
VS
21
22#include "wx/print.h"
23#include "wx/printdlg.h"
24
f2034f1b
VS
25#include <limits.h> // INT_MAX
26
3ce369e6
VS
27//--------------------------------------------------------------------------------
28// wxHtmlDCRenderer
6953da00 29// This class is capable of rendering HTML into specified
3ce369e6
VS
30// portion of DC
31//--------------------------------------------------------------------------------
32
6acba9a7 33class WXDLLIMPEXP_HTML wxHtmlDCRenderer : public wxObject
3ce369e6 34{
97494971
VS
35public:
36 wxHtmlDCRenderer();
37 ~wxHtmlDCRenderer();
38
39 // Following 3 methods *must* be called before any call to Render:
40
f2034f1b 41 // Assign DC to this render
97494971
VS
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.
6953da00 51 // isdir is false if basepath is filename, true if it is directory name
97494971 52 // (see wxFileSystem for detailed explanation)
6953da00 53 void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = true);
97494971 54
4eecf115 55 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
fbfb8bcc 56 void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
4eecf115 57
10e5c7ea
VS
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);
7acd3625 63
97494971 64 // [x,y] is position of upper-left corner of printing rectangle (see SetSize)
f2034f1b
VS
65 // from is y-coordinate of the very first visible cell
66 // to is y-coordinate of the next following page break, if any
97494971
VS
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 //
f2034f1b
VS
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!
4ac725a3
VS
80 int Render(int x, int y, int from = 0, int dont_render = FALSE,
81 int maxHeight = INT_MAX,
f2034f1b 82 int *known_pagebreaks = NULL, int number_of_pages = 0);
97494971
VS
83
84 // returns total height of the html document
85 // (compare Render's return value with this)
86 int GetTotalHeight();
87
88private:
89 wxDC *m_DC;
90 wxHtmlWinParser *m_Parser;
91 wxFileSystem *m_FS;
92 wxHtmlContainerCell *m_Cells;
93 int m_MaxWidth, m_Width, m_Height;
22f3361e
VZ
94
95 DECLARE_NO_COPY_CLASS(wxHtmlDCRenderer)
3ce369e6
VS
96};
97
98
99
100
101
102enum {
103 wxPAGE_ODD,
104 wxPAGE_EVEN,
105 wxPAGE_ALL
106};
107
108
109
110//--------------------------------------------------------------------------------
111// wxHtmlPrintout
77ffb593 112// This class is derived from standard wxWidgets printout class
3ce369e6
VS
113// and is used to print HTML documents.
114//--------------------------------------------------------------------------------
115
116
6acba9a7 117class WXDLLIMPEXP_HTML wxHtmlPrintout : public wxPrintout
3ce369e6 118{
29786211 119public:
2b5f62a0 120 wxHtmlPrintout(const wxString& title = wxT("Printout"));
29786211
VS
121 ~wxHtmlPrintout();
122
6953da00 123 void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = true);
29786211
VS
124 // prepares the class for printing this html document.
125 // Must be called before using the class, in fact just after constructor
126 //
127 // basepath is base directory (html string would be stored there if it was in
128 // file). It is used to determine path for loading images, for example.
6953da00 129 // isdir is false if basepath is filename, true if it is directory name
29786211
VS
130 // (see wxFileSystem for detailed explanation)
131
132 void SetHtmlFile(const wxString &htmlfile);
133 // same as SetHtmlText except that it takes regular file as the parameter
134
135 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
136 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
137 // sets header/footer for the document. The argument is interpreted as HTML document.
138 // You can use macros in it:
139 // @PAGENUM@ is replaced by page number
140 // @PAGESCNT@ is replaced by total number of pages
141 //
142 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
143 // You can set different header/footer for odd and even pages
144
4eecf115 145 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
fbfb8bcc 146 void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
4eecf115 147
10e5c7ea
VS
148 // Sets font sizes to be relative to the given size or the system
149 // default size; use either specified or default font
150 void SetStandardFonts(int size = -1,
151 const wxString& normal_face = wxEmptyString,
152 const wxString& fixed_face = wxEmptyString);
7acd3625 153
6953da00 154 void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2,
29786211
VS
155 float spaces = 5);
156 // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
157 // between text and header and/or footer
158
6953da00 159 // wxPrintout stuff:
29786211
VS
160 bool OnPrintPage(int page);
161 bool HasPage(int page);
162 void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
163 bool OnBeginDocument(int startPage, int endPage);
d2b354f9 164 void OnPreparePrinting();
29786211 165
fa10c70c
JS
166 // Adds input filter
167 static void AddFilter(wxHtmlFilter *filter);
168
169 // Cleanup
170 static void CleanUpStatics();
171
29786211
VS
172private:
173
174 void RenderPage(wxDC *dc, int page);
175 // renders one page into dc
176 wxString TranslateHeader(const wxString& instr, int page);
177 // substitute @PAGENUM@ and @PAGESCNT@ by real values
178 void CountPages();
179 // counts pages and fills m_NumPages and m_PageBreaks
180
181
182private:
183 int m_NumPages;
184 int m_PageBreaks[wxHTML_PRINT_MAX_PAGES];
185
186 wxString m_Document, m_BasePath;
187 bool m_BasePathIsDir;
188 wxString m_Headers[2], m_Footers[2];
189
190 int m_HeaderHeight, m_FooterHeight;
191 wxHtmlDCRenderer *m_Renderer, *m_RendererHdr;
192 float m_MarginTop, m_MarginBottom, m_MarginLeft, m_MarginRight, m_MarginSpace;
22f3361e 193
fa10c70c
JS
194 // list of HTML filters
195 static wxList m_Filters;
196
22f3361e 197 DECLARE_NO_COPY_CLASS(wxHtmlPrintout)
3ce369e6
VS
198};
199
200
201
202
203
204//--------------------------------------------------------------------------------
205// wxHtmlEasyPrinting
6953da00 206// This class provides very simple interface to printing
3ce369e6 207// architecture. It allows you to print HTML documents only
6953da00 208// with very few commands.
3ce369e6
VS
209//
210// Note : do not create this class on stack only.
6953da00 211// You should create an instance on app startup and
3ce369e6
VS
212// use this instance for all printing. Why? The class
213// stores page&printer settings in it.
214//--------------------------------------------------------------------------------
215
6acba9a7 216class WXDLLIMPEXP_HTML wxHtmlEasyPrinting : public wxObject
3ce369e6 217{
29786211 218public:
a5ae8241 219 wxHtmlEasyPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL);
29786211
VS
220 ~wxHtmlEasyPrinting();
221
222 bool PreviewFile(const wxString &htmlfile);
223 bool PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
224 // Preview file / html-text for printing
225 // (and offers printing)
226 // basepath is base directory for opening subsequent files (e.g. from <img> tag)
227
228 bool PrintFile(const wxString &htmlfile);
229 bool PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
230 // Print file / html-text w/o preview
231
29786211
VS
232 void PageSetup();
233 // pop up printer or page setup dialog
234
235 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
236 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
237 // sets header/footer for the document. The argument is interpreted as HTML document.
238 // You can use macros in it:
239 // @PAGENUM@ is replaced by page number
240 // @PAGESCNT@ is replaced by total number of pages
241 //
242 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
243 // You can set different header/footer for odd and even pages
244
fbfb8bcc 245 void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = 0);
4eecf115
VS
246 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used)
247
10e5c7ea
VS
248 // Sets font sizes to be relative to the given size or the system
249 // default size; use either specified or default font
250 void SetStandardFonts(int size = -1,
251 const wxString& normal_face = wxEmptyString,
252 const wxString& fixed_face = wxEmptyString);
6953da00 253
632783de 254 wxPrintData *GetPrintData();
29786211 255 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
6953da00 256 // return page setting data objects.
29786211
VS
257 // (You can set their parameters.)
258
f2034f1b 259protected:
29786211
VS
260 virtual wxHtmlPrintout *CreatePrintout();
261 virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2);
262 virtual bool DoPrint(wxHtmlPrintout *printout);
263
264private:
265 wxPrintData *m_PrintData;
266 wxPageSetupDialogData *m_PageSetupData;
267 wxString m_Name;
4eecf115
VS
268 int m_FontsSizesArr[7];
269 int *m_FontsSizes;
270 wxString m_FontFaceFixed, m_FontFaceNormal;
10e5c7ea
VS
271
272 enum FontMode
273 {
274 FontMode_Explicit,
275 FontMode_Standard
276 };
277 FontMode m_fontMode;
6953da00 278
29786211 279 wxString m_Headers[2], m_Footers[2];
a5ae8241 280 wxWindow *m_ParentWindow;
22f3361e
VZ
281
282 DECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting)
3ce369e6
VS
283};
284
285
286
287
72cdf4c9 288#endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
3ce369e6
VS
289
290#endif // _WX_HTMPRINT_H_
291