1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: html printing classes
4 // Author: Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HTMPRINT_H_
12 #define _WX_HTMPRINT_H_
20 #if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
22 #include "wx/html/htmlcell.h"
23 #include "wx/html/winpars.h"
26 #include "wx/printdlg.h"
28 //--------------------------------------------------------------------------------
30 // This class is capable of rendering HTML into specified
32 //--------------------------------------------------------------------------------
34 class WXDLLEXPORT wxHtmlDCRenderer
: public wxObject
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)
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
52 void SetHtmlText(const wxString
& html
, const wxString
& basepath
= wxEmptyString
, bool isdir
= TRUE
);
53 // sets the text to be displayed
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)
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
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
69 // CAUTION! Render() changes DC's user scale and does NOT restore it!
72 // returns total height of the html document
73 // (compare Render's return value with this)
78 wxHtmlWinParser
*m_Parser
;
80 wxHtmlContainerCell
*m_Cells
;
81 int m_MaxWidth
, m_Width
, m_Height
;
97 //--------------------------------------------------------------------------------
99 // This class is derived from standard wxWindows printout class
100 // and is used to print HTML documents.
101 //--------------------------------------------------------------------------------
104 class WXDLLEXPORT wxHtmlPrintout
: public wxPrintout
107 wxHtmlPrintout(const wxString
& title
= "Printout");
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
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)
119 void SetHtmlFile(const wxString
&htmlfile
);
120 // same as SetHtmlText except that it takes regular file as the parameter
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
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
132 void SetMargins(float top
= 25.2, float bottom
= 25.2, float left
= 25.2, float right
= 25.2,
134 // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
135 // between text and header and/or footer
138 bool OnPrintPage(int page
);
139 bool HasPage(int page
);
140 void GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
);
141 void OnBeginPrinting();
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
150 // counts pages and fills m_NumPages and m_PageBreaks
155 int m_PageBreaks
[wxHTML_PRINT_MAX_PAGES
];
157 wxString m_Document
, m_BasePath
;
158 bool m_BasePathIsDir
;
159 wxString m_Headers
[2], m_Footers
[2];
161 int m_HeaderHeight
, m_FooterHeight
;
162 wxHtmlDCRenderer
*m_Renderer
, *m_RendererHdr
;
163 float m_MarginTop
, m_MarginBottom
, m_MarginLeft
, m_MarginRight
, m_MarginSpace
;
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.
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 //--------------------------------------------------------------------------------
182 class WXDLLEXPORT wxHtmlEasyPrinting
: public wxObject
186 wxHtmlEasyPrinting(const wxString
& name
= "Printing", wxFrame
*parent_frame
= NULL
);
187 ~wxHtmlEasyPrinting();
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)
195 void PrintFile(const wxString
&htmlfile
);
196 void PrintText(const wxString
&htmltext
, const wxString
& basepath
= wxEmptyString
);
197 // Print file / html-text w/o preview
201 // pop up printer or page setup dialog
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
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
213 wxPrintData
*GetPrintData() {return m_PrintData
;}
214 wxPageSetupDialogData
*GetPageSetupData() {return m_PageSetupData
;}
215 // return page setting data objects.
216 // (You can set their parameters.)
220 wxHtmlPrintout
*CreatePrintout();
221 void DoPreview(wxHtmlPrintout
*printout1
, wxHtmlPrintout
*printout2
);
222 void DoPrint(wxHtmlPrintout
*printout
);
224 wxPrintData
*m_PrintData
;
225 wxPageSetupDialogData
*m_PageSetupData
;
227 wxString m_Headers
[2], m_Footers
[2];
234 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
236 #endif // _WX_HTMPRINT_H_