]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmprint.h
HTML_xxxx constants changed to wxHTML_xxxx (with backward compatibility through WXWIN...
[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 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include <wx/defs.h>
19
20 #if 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 //--------------------------------------------------------------------------------
30 // wxHtmlDCRenderer
31 // This class is capable of rendering HTML into specified
32 // portion of DC
33 //--------------------------------------------------------------------------------
34
35
36 class wxHtmlDCRenderer : public wxObject
37 {
38 public:
39 wxHtmlDCRenderer();
40 ~wxHtmlDCRenderer();
41
42 // Following 3 methods *must* be called before any call to Render:
43 void SetDC(wxDC *dc, int maxwidth);
44 // asign DC to this render
45 // maxwidth is width of area (on this DC) that is equivalent to screen's width, in pixels
46 // (you should set it to page width minus margins)
47 // Also see SetSize
48 void SetSize(int width, int height);
49 // sets size of output rectangle, in pixels. Note that you *can't* change
50 // width of the rectangle between calls to Render! (You can freely change height.)
51 // If you set width = maxwidth then HTML is rendered as if it were displayed in fullscreen.
52 // If you set width = 1/2 maxwidth the it is rendered as if it covered half the screen
53 // and so on..
54 void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = TRUE);
55 // sets the text to be displayed
56 //
57 // basepath is base directory (html string would be stored there if it was in
58 // file). It is used to determine path for loading images, for example.
59 // isdir is FALSE if basepath is filename, TRUE if it is directory name
60 // (see wxFileSystem for detailed explanation)
61
62 int Render(int x, int y, int from = 0, int dont_render = FALSE);
63 // [x,y] is position of upper-left corner of printing rectangle (see SetSize)
64 // from is y-coordinate of the very first visible cell
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 // CAUTION! Render() changes DC's user scale and does NOT restore it!
72
73 int GetTotalHeight();
74 // returns total height of the html document
75 // (compare Render's return value with this)
76
77 private:
78
79 wxDC *m_DC;
80 wxHtmlWinParser *m_Parser;
81 wxFileSystem *m_FS;
82 wxHtmlContainerCell *m_Cells;
83 int m_MaxWidth, m_Width, m_Height;
84 double m_Scale;
85 };
86
87
88
89
90
91 enum {
92 wxPAGE_ODD,
93 wxPAGE_EVEN,
94 wxPAGE_ALL
95 };
96
97
98
99 //--------------------------------------------------------------------------------
100 // wxHtmlPrintout
101 // This class is derived from standard wxWindows printout class
102 // and is used to print HTML documents.
103 //--------------------------------------------------------------------------------
104
105
106 class wxHtmlPrintout : public wxPrintout
107 {
108 public:
109 wxHtmlPrintout(const wxString& title = "Printout");
110 ~wxHtmlPrintout();
111
112 void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = TRUE);
113 // prepares the class for printing this html document.
114 // Must be called before using the class, in fact just after constructor
115 //
116 // basepath is base directory (html string would be stored there if it was in
117 // file). It is used to determine path for loading images, for example.
118 // isdir is FALSE if basepath is filename, TRUE if it is directory name
119 // (see wxFileSystem for detailed explanation)
120
121 void SetHtmlFile(const wxString &htmlfile);
122 // same as SetHtmlText except that it takes regular file as the parameter
123
124 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
125 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
126 // sets header/footer for the document. The argument is interpreted as HTML document.
127 // You can use macros in it:
128 // @PAGENUM@ is replaced by page number
129 // @PAGESCNT@ is replaced by total number of pages
130 //
131 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
132 // You can set different header/footer for odd and even pages
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 void OnBeginPrinting();
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
168
169
170
171
172 //--------------------------------------------------------------------------------
173 // wxHtmlEasyPrinting
174 // This class provides very simple interface to printing
175 // architecture. It allows you to print HTML documents only
176 // with very few commands.
177 //
178 // Note : do not create this class on stack only.
179 // You should create an instance on app startup and
180 // use this instance for all printing. Why? The class
181 // stores page&printer settings in it.
182 //--------------------------------------------------------------------------------
183
184 class wxHtmlEasyPrinting : public wxObject
185 {
186 public:
187
188 wxHtmlEasyPrinting(const wxString& name = "Printing", wxFrame *parent_frame = NULL);
189 ~wxHtmlEasyPrinting();
190
191 void PreviewFile(const wxString &htmlfile);
192 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
193 // Preview file / html-text for printing
194 // (and offers printing)
195 // basepath is base directory for opening subsequent files (e.g. from <img> tag)
196
197 void PrintFile(const wxString &htmlfile);
198 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
199 // Print file / html-text w/o preview
200
201 void PrinterSetup();
202 void PageSetup();
203 // pop up printer or page setup dialog
204
205 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
206 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
207 // sets header/footer for the document. The argument is interpreted as HTML document.
208 // You can use macros in it:
209 // @PAGENUM@ is replaced by page number
210 // @PAGESCNT@ is replaced by total number of pages
211 //
212 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
213 // You can set different header/footer for odd and even pages
214
215 wxPrintData *GetPrintData() {return m_PrintData;}
216 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
217 // return page setting data objects.
218 // (You can set their parameters.)
219
220 private:
221
222 wxHtmlPrintout *CreatePrintout();
223 void DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2);
224 void DoPrint(wxHtmlPrintout *printout);
225
226 wxPrintData *m_PrintData;
227 wxPageSetupDialogData *m_PageSetupData;
228 wxString m_Name;
229 wxString m_Headers[2], m_Footers[2];
230 wxFrame *m_Frame;
231 };
232
233
234
235
236 #endif // wxUSE_PRINTING_ARCHITECTURE
237
238 #endif // _WX_HTMPRINT_H_
239