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_
14 #if defined(__GNUG__) && !defined(__APPLE__)
15 #pragma interface "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:
42 // Asign DC to this render
43 void SetDC(wxDC
*dc
, double pixel_scale
= 1.0);
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
);
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
);
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
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
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
);
67 // returns total height of the html document
68 // (compare Render's return value with this)
73 wxHtmlWinParser
*m_Parser
;
75 wxHtmlContainerCell
*m_Cells
;
76 int m_MaxWidth
, m_Width
, m_Height
;
78 DECLARE_NO_COPY_CLASS(wxHtmlDCRenderer
)
93 //--------------------------------------------------------------------------------
95 // This class is derived from standard wxWindows printout class
96 // and is used to print HTML documents.
97 //--------------------------------------------------------------------------------
100 class WXDLLEXPORT wxHtmlPrintout
: public wxPrintout
103 wxHtmlPrintout(const wxString
& title
= wxT("Printout"));
106 void SetHtmlText(const wxString
& html
, const wxString
&basepath
= wxEmptyString
, bool isdir
= TRUE
);
107 // prepares the class for printing this html document.
108 // Must be called before using the class, in fact just after constructor
110 // basepath is base directory (html string would be stored there if it was in
111 // file). It is used to determine path for loading images, for example.
112 // isdir is FALSE if basepath is filename, TRUE if it is directory name
113 // (see wxFileSystem for detailed explanation)
115 void SetHtmlFile(const wxString
&htmlfile
);
116 // same as SetHtmlText except that it takes regular file as the parameter
118 void SetHeader(const wxString
& header
, int pg
= wxPAGE_ALL
);
119 void SetFooter(const wxString
& footer
, int pg
= wxPAGE_ALL
);
120 // sets header/footer for the document. The argument is interpreted as HTML document.
121 // You can use macros in it:
122 // @PAGENUM@ is replaced by page number
123 // @PAGESCNT@ is replaced by total number of pages
125 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
126 // You can set different header/footer for odd and even pages
128 void SetMargins(float top
= 25.2, float bottom
= 25.2, float left
= 25.2, float right
= 25.2,
130 // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
131 // between text and header and/or footer
134 bool OnPrintPage(int page
);
135 bool HasPage(int page
);
136 void GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
);
137 bool OnBeginDocument(int startPage
, int endPage
);
141 void RenderPage(wxDC
*dc
, int page
);
142 // renders one page into dc
143 wxString
TranslateHeader(const wxString
& instr
, int page
);
144 // substitute @PAGENUM@ and @PAGESCNT@ by real values
146 // counts pages and fills m_NumPages and m_PageBreaks
151 int m_PageBreaks
[wxHTML_PRINT_MAX_PAGES
];
153 wxString m_Document
, m_BasePath
;
154 bool m_BasePathIsDir
;
155 wxString m_Headers
[2], m_Footers
[2];
157 int m_HeaderHeight
, m_FooterHeight
;
158 wxHtmlDCRenderer
*m_Renderer
, *m_RendererHdr
;
159 float m_MarginTop
, m_MarginBottom
, m_MarginLeft
, m_MarginRight
, m_MarginSpace
;
161 DECLARE_NO_COPY_CLASS(wxHtmlPrintout
)
168 //--------------------------------------------------------------------------------
169 // wxHtmlEasyPrinting
170 // This class provides very simple interface to printing
171 // architecture. It allows you to print HTML documents only
172 // with very few commands.
174 // Note : do not create this class on stack only.
175 // You should create an instance on app startup and
176 // use this instance for all printing. Why? The class
177 // stores page&printer settings in it.
178 //--------------------------------------------------------------------------------
180 class WXDLLEXPORT wxHtmlEasyPrinting
: public wxObject
183 wxHtmlEasyPrinting(const wxString
& name
= wxT("Printing"), wxFrame
*parent_frame
= NULL
);
184 ~wxHtmlEasyPrinting();
186 bool PreviewFile(const wxString
&htmlfile
);
187 bool PreviewText(const wxString
&htmltext
, const wxString
& basepath
= wxEmptyString
);
188 // Preview file / html-text for printing
189 // (and offers printing)
190 // basepath is base directory for opening subsequent files (e.g. from <img> tag)
192 bool PrintFile(const wxString
&htmlfile
);
193 bool PrintText(const wxString
&htmltext
, const wxString
& basepath
= wxEmptyString
);
194 // Print file / html-text w/o preview
198 // pop up printer or page setup dialog
200 void SetHeader(const wxString
& header
, int pg
= wxPAGE_ALL
);
201 void SetFooter(const wxString
& footer
, int pg
= wxPAGE_ALL
);
202 // sets header/footer for the document. The argument is interpreted as HTML document.
203 // You can use macros in it:
204 // @PAGENUM@ is replaced by page number
205 // @PAGESCNT@ is replaced by total number of pages
207 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
208 // You can set different header/footer for odd and even pages
210 wxPrintData
*GetPrintData() {return m_PrintData
;}
211 wxPageSetupDialogData
*GetPageSetupData() {return m_PageSetupData
;}
212 // return page setting data objects.
213 // (You can set their parameters.)
216 virtual wxHtmlPrintout
*CreatePrintout();
217 virtual bool DoPreview(wxHtmlPrintout
*printout1
, wxHtmlPrintout
*printout2
);
218 virtual bool DoPrint(wxHtmlPrintout
*printout
);
221 wxPrintData
*m_PrintData
;
222 wxPageSetupDialogData
*m_PageSetupData
;
224 wxString m_Headers
[2], m_Footers
[2];
227 DECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting
)
233 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
235 #endif // _WX_HTMPRINT_H_