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