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