]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmprint.h
c35df126ecc3f82ebb7b8ae5fcc282e6479c26b8
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_PRINTING_ARCHITECTURE
22 #include "wx/html/htmlcell.h"
23 #include "wx/html/winpars.h"
26 #include "wx/printdlg.h"
29 //--------------------------------------------------------------------------------
31 // This class is capable of rendering HTML into specified
33 //--------------------------------------------------------------------------------
36 class wxHtmlDCRenderer
: public wxObject
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)
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
54 void SetHtmlText(const wxString
& html
, const wxString
& basepath
= wxEmptyString
, bool isdir
= TRUE
);
55 // sets the text to be displayed
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)
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
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
71 // CAUTION! Render() changes DC's user scale and does NOT restore it!
74 // returns total height of the html document
75 // (compare Render's return value with this)
80 wxHtmlWinParser
*m_Parser
;
82 wxHtmlContainerCell
*m_Cells
;
83 int m_MaxWidth
, m_Width
, m_Height
;
99 //--------------------------------------------------------------------------------
101 // This class is derived from standard wxWindows printout class
102 // and is used to print HTML documents.
103 //--------------------------------------------------------------------------------
106 class wxHtmlPrintout
: public wxPrintout
109 wxHtmlPrintout(const wxString
& title
= "Printout");
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
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)
121 void SetHtmlFile(const wxString
&htmlfile
);
122 // same as SetHtmlText except that it takes regular file as the parameter
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
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
134 void SetMargins(float top
= 25.2, float bottom
= 25.2, float left
= 25.2, float right
= 25.2,
136 // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
137 // between text and header and/or footer
140 bool OnPrintPage(int page
);
141 bool HasPage(int page
);
142 void GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
);
143 bool OnBeginDocument(int start
, int end
);
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
152 // counts pages and fills m_NumPages and m_PageBreaks
157 int m_PageBreaks
[HTML_PRINT_MAX_PAGES
];
159 wxString m_Document
, m_BasePath
;
160 bool m_BasePathIsDir
;
161 wxString m_Headers
[2], m_Footers
[2];
163 int m_HeaderHeight
, m_FooterHeight
;
164 wxHtmlDCRenderer
*m_Renderer
, *m_RendererHdr
;
165 float m_MarginTop
, m_MarginBottom
, m_MarginLeft
, m_MarginRight
, m_MarginSpace
;
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.
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 //--------------------------------------------------------------------------------
184 class wxHtmlEasyPrinting
: public wxObject
188 wxHtmlEasyPrinting(const wxString
& name
= "Printing", wxFrame
*parent_frame
= NULL
);
189 ~wxHtmlEasyPrinting();
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)
197 void PrintFile(const wxString
&htmlfile
);
198 void PrintText(const wxString
&htmltext
, const wxString
& basepath
= wxEmptyString
);
199 // Print file / html-text w/o preview
203 // pop up printer or page setup dialog
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
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
215 wxPrintData
*GetPrintData() {return m_PrintData
;}
216 wxPageSetupDialogData
*GetPageSetupData() {return m_PageSetupData
;}
217 // return page setting data objects.
218 // (You can set their parameters.)
222 wxHtmlPrintout
*CreatePrintout();
223 void DoPreview(wxHtmlPrintout
*printout1
, wxHtmlPrintout
*printout2
);
224 void DoPrint(wxHtmlPrintout
*printout
);
226 wxPrintData
*m_PrintData
;
227 wxPageSetupDialogData
*m_PageSetupData
;
229 wxString m_Headers
[2], m_Footers
[2];
236 #endif // wxUSE_PRINTING_ARCHITECTURE
238 #endif // _WX_HTMPRINT_H_