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