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