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