]>
Commit | Line | Data |
---|---|---|
3ce369e6 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmprint.cpp | |
3 | // Purpose: html printing classes | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 25/09/99 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) Vaclav Slavik, 1999 | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | ||
12 | #ifdef __GNUG__ | |
1aedb1dd | 13 | #pragma implementation "htmprint.h" |
3ce369e6 VS |
14 | #endif |
15 | ||
16 | // For compilers that support precompilation, includes "wx/wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
314260fb VS |
19 | #include "wx/defs.h" |
20 | ||
3ce369e6 VS |
21 | #ifdef __BORLANDC__ |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | #ifndef WX_PRECOMP | |
04dbb646 VZ |
26 | #include "wx/log.h" |
27 | #include "wx/intl.h" | |
5438a566 | 28 | #include "wx/dc.h" |
3ce369e6 VS |
29 | #endif |
30 | ||
f6bcfd97 | 31 | #if wxUSE_HTML && wxUSE_PRINTING_ARCHITECTURE && wxUSE_STREAMS |
3ce369e6 | 32 | |
f11bdd03 | 33 | #include "wx/dc.h" |
3ce369e6 VS |
34 | #include "wx/print.h" |
35 | #include "wx/printdlg.h" | |
36 | #include "wx/html/htmprint.h" | |
37 | #include "wx/wxhtml.h" | |
38 | #include "wx/wfstream.h" | |
39 | ||
40 | ||
41 | //-------------------------------------------------------------------------------- | |
42 | // wxHtmlDCRenderer | |
43 | //-------------------------------------------------------------------------------- | |
44 | ||
45 | ||
46 | wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject() | |
47 | { | |
48 | m_DC = NULL; | |
49 | m_Width = m_Height = 0; | |
50 | m_Cells = NULL; | |
51 | m_Parser = new wxHtmlWinParser(NULL); | |
52 | m_FS = new wxFileSystem(); | |
4f9297b0 | 53 | m_Parser->SetFS(m_FS); |
3ce369e6 VS |
54 | } |
55 | ||
56 | ||
57 | ||
58 | wxHtmlDCRenderer::~wxHtmlDCRenderer() | |
59 | { | |
60 | if (m_Cells) delete m_Cells; | |
61 | if (m_Parser) delete m_Parser; | |
62 | if (m_FS) delete m_FS; | |
63 | } | |
64 | ||
65 | ||
66 | ||
edbd0635 | 67 | void wxHtmlDCRenderer::SetDC(wxDC *dc, double pixel_scale) |
3ce369e6 | 68 | { |
3ce369e6 | 69 | m_DC = dc; |
4f9297b0 | 70 | m_Parser->SetDC(m_DC, pixel_scale); |
3ce369e6 VS |
71 | } |
72 | ||
73 | ||
74 | ||
75 | void wxHtmlDCRenderer::SetSize(int width, int height) | |
76 | { | |
edbd0635 VS |
77 | m_Width = width; |
78 | m_Height = height; | |
3ce369e6 VS |
79 | } |
80 | ||
81 | ||
3ce369e6 VS |
82 | void wxHtmlDCRenderer::SetHtmlText(const wxString& html, const wxString& basepath, bool isdir) |
83 | { | |
84 | if (m_DC == NULL) return; | |
85 | ||
86 | if (m_Cells != NULL) delete m_Cells; | |
04dbb646 | 87 | |
4f9297b0 VS |
88 | m_FS->ChangePathTo(basepath, isdir); |
89 | m_Cells = (wxHtmlContainerCell*) m_Parser->Parse(html); | |
90 | m_Cells->SetIndent(0, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS); | |
91 | m_Cells->Layout(m_Width); | |
3ce369e6 VS |
92 | } |
93 | ||
94 | ||
4eecf115 VS |
95 | void wxHtmlDCRenderer::SetFonts(wxString normal_face, wxString fixed_face, |
96 | const int *sizes) | |
97 | { | |
98 | m_Parser->SetFonts(normal_face, fixed_face, sizes); | |
99 | if (m_DC == NULL && m_Cells != NULL) m_Cells->Layout(m_Width); | |
100 | } | |
101 | ||
3ce369e6 | 102 | |
f2034f1b | 103 | int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render, int to, int *known_pagebreaks, int number_of_pages) |
3ce369e6 | 104 | { |
ec939b68 | 105 | int pbreak, hght; |
04dbb646 | 106 | |
3ce369e6 | 107 | if (m_Cells == NULL || m_DC == NULL) return 0; |
04dbb646 | 108 | |
edbd0635 | 109 | pbreak = (int)(from + m_Height); |
f2034f1b | 110 | while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks, number_of_pages)) {} |
edbd0635 | 111 | hght = pbreak - from; |
f2034f1b VS |
112 | if(to < hght) |
113 | hght = to; | |
04dbb646 VZ |
114 | |
115 | if (!dont_render) | |
4f9297b0 VS |
116 | { |
117 | m_DC->SetBrush(*wxWHITE_BRUSH); | |
04dbb646 | 118 | |
4f9297b0 | 119 | m_DC->SetClippingRegion(x, y, m_Width, hght); |
04dbb646 | 120 | m_Cells->Draw(*m_DC, |
edbd0635 VS |
121 | x, (y - from), |
122 | y, pbreak + (y /*- from*/)); | |
4f9297b0 | 123 | m_DC->DestroyClippingRegion(); |
3ce369e6 | 124 | } |
04dbb646 | 125 | |
4f9297b0 | 126 | if (pbreak < m_Cells->GetHeight()) return pbreak; |
3ce369e6 VS |
127 | else return GetTotalHeight(); |
128 | } | |
129 | ||
130 | ||
131 | ||
132 | int wxHtmlDCRenderer::GetTotalHeight() | |
133 | { | |
4f9297b0 | 134 | if (m_Cells) return m_Cells->GetHeight(); |
3ce369e6 VS |
135 | else return 0; |
136 | } | |
137 | ||
138 | ||
139 | ||
140 | ||
141 | ||
142 | ||
143 | ||
144 | ||
145 | ||
146 | ||
147 | ||
148 | ||
149 | ||
150 | ||
151 | ||
152 | ||
153 | //-------------------------------------------------------------------------------- | |
154 | // wxHtmlPrintout | |
155 | //-------------------------------------------------------------------------------- | |
156 | ||
157 | ||
158 | ||
159 | wxHtmlPrintout::wxHtmlPrintout(const wxString& title) : wxPrintout(title) | |
160 | { | |
161 | m_Renderer = new wxHtmlDCRenderer; | |
162 | m_RendererHdr = new wxHtmlDCRenderer; | |
efba2b89 | 163 | m_NumPages = wxHTML_PRINT_MAX_PAGES; |
3ce369e6 VS |
164 | m_Document = m_BasePath = wxEmptyString; m_BasePathIsDir = TRUE; |
165 | m_Headers[0] = m_Headers[1] = wxEmptyString; | |
166 | m_Footers[0] = m_Footers[1] = wxEmptyString; | |
167 | m_HeaderHeight = m_FooterHeight = 0; | |
168 | SetMargins(); // to default values | |
169 | } | |
170 | ||
171 | ||
172 | ||
173 | wxHtmlPrintout::~wxHtmlPrintout() | |
174 | { | |
175 | delete m_Renderer; | |
176 | delete m_RendererHdr; | |
177 | } | |
178 | ||
179 | ||
180 | ||
2a0eb922 | 181 | bool wxHtmlPrintout::OnBeginDocument(int startPage, int endPage) |
3ce369e6 | 182 | { |
edbd0635 | 183 | int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h; |
3ce369e6 | 184 | float ppmm_h, ppmm_v; |
04dbb646 | 185 | |
2a0eb922 | 186 | if (!wxPrintout::OnBeginDocument(startPage, endPage)) return FALSE; |
3ce369e6 VS |
187 | |
188 | GetPageSizePixels(&pageWidth, &pageHeight); | |
189 | GetPageSizeMM(&mm_w, &mm_h); | |
190 | ppmm_h = (float)pageWidth / mm_w; | |
191 | ppmm_v = (float)pageHeight / mm_h; | |
192 | ||
edbd0635 VS |
193 | int ppiPrinterX, ppiPrinterY; |
194 | GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); | |
195 | int ppiScreenX, ppiScreenY; | |
196 | GetPPIScreen(&ppiScreenX, &ppiScreenY); | |
197 | ||
198 | wxDisplaySize(&scr_w, &scr_h); | |
4f9297b0 | 199 | GetDC()->GetSize(&dc_w, &dc_h); |
edbd0635 | 200 | |
4f9297b0 | 201 | GetDC()->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_w / (double)pageWidth); |
edbd0635 | 202 | |
3ce369e6 | 203 | /* prepare headers/footers renderer: */ |
04dbb646 | 204 | |
4f9297b0 | 205 | m_RendererHdr->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY); |
04dbb646 | 206 | m_RendererHdr->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)), |
68be9f09 | 207 | (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom))); |
04dbb646 | 208 | if (m_Headers[0] != wxEmptyString) |
4f9297b0 VS |
209 | { |
210 | m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[0], 1)); | |
211 | m_HeaderHeight = m_RendererHdr->GetTotalHeight(); | |
3ce369e6 | 212 | } |
04dbb646 | 213 | else if (m_Headers[1] != wxEmptyString) |
4f9297b0 VS |
214 | { |
215 | m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[1], 1)); | |
216 | m_HeaderHeight = m_RendererHdr->GetTotalHeight(); | |
3ce369e6 | 217 | } |
04dbb646 | 218 | if (m_Footers[0] != wxEmptyString) |
4f9297b0 VS |
219 | { |
220 | m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[0], 1)); | |
221 | m_FooterHeight = m_RendererHdr->GetTotalHeight(); | |
3ce369e6 | 222 | } |
04dbb646 | 223 | else if (m_Footers[1] != wxEmptyString) |
4f9297b0 VS |
224 | { |
225 | m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[1], 1)); | |
226 | m_FooterHeight = m_RendererHdr->GetTotalHeight(); | |
3ce369e6 | 227 | } |
04dbb646 | 228 | |
3ce369e6 | 229 | /* prepare main renderer: */ |
4f9297b0 | 230 | m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY); |
6c5b628e | 231 | m_Renderer->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)), |
04dbb646 | 232 | (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom) - |
3ce369e6 VS |
233 | m_FooterHeight - m_HeaderHeight - |
234 | ((m_HeaderHeight == 0) ? 0 : m_MarginSpace * ppmm_v) - | |
235 | ((m_FooterHeight == 0) ? 0 : m_MarginSpace * ppmm_v) | |
68be9f09 | 236 | )); |
4f9297b0 | 237 | m_Renderer->SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir); |
3ce369e6 | 238 | CountPages(); |
2a0eb922 | 239 | return TRUE; |
3ce369e6 VS |
240 | } |
241 | ||
242 | ||
243 | bool wxHtmlPrintout::OnPrintPage(int page) | |
244 | { | |
245 | wxDC *dc = GetDC(); | |
04dbb646 | 246 | if (dc) |
4f9297b0 | 247 | { |
3ce369e6 VS |
248 | if (HasPage(page)) |
249 | RenderPage(dc, page); | |
250 | return TRUE; | |
04dbb646 | 251 | } |
4f9297b0 | 252 | else return FALSE; |
3ce369e6 VS |
253 | } |
254 | ||
255 | ||
256 | void wxHtmlPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) | |
257 | { | |
258 | *minPage = 1; | |
efba2b89 | 259 | *maxPage = wxHTML_PRINT_MAX_PAGES; |
3ce369e6 | 260 | *selPageFrom = 1; |
efba2b89 | 261 | *selPageTo = wxHTML_PRINT_MAX_PAGES; |
3ce369e6 VS |
262 | } |
263 | ||
264 | ||
265 | ||
266 | bool wxHtmlPrintout::HasPage(int pageNum) | |
267 | { | |
268 | return (pageNum >= 1 && pageNum <= m_NumPages); | |
269 | } | |
270 | ||
271 | ||
272 | ||
273 | void wxHtmlPrintout::SetHtmlText(const wxString& html, const wxString &basepath, bool isdir) | |
274 | { | |
275 | m_Document = html; | |
276 | m_BasePath = basepath; | |
277 | m_BasePathIsDir = isdir; | |
278 | } | |
279 | ||
3ce369e6 VS |
280 | void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile) |
281 | { | |
282 | wxFileSystem fs; | |
283 | wxFSFile *ff = fs.OpenFile(htmlfile); | |
04dbb646 | 284 | |
f5ba273e | 285 | if (ff == NULL) |
04dbb646 | 286 | { |
f5ba273e VS |
287 | wxLogError(htmlfile + _(": file does not exist!")); |
288 | return; | |
289 | } | |
04dbb646 | 290 | |
2b5f62a0 VZ |
291 | wxHtmlFilterHTML filter; |
292 | wxString doc = filter.ReadFile(*ff); | |
293 | ||
3ce369e6 | 294 | SetHtmlText(doc, htmlfile, FALSE); |
2b5f62a0 | 295 | delete ff; |
3ce369e6 VS |
296 | } |
297 | ||
298 | ||
299 | ||
300 | void wxHtmlPrintout::SetHeader(const wxString& header, int pg) | |
301 | { | |
04dbb646 | 302 | if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN) |
3ce369e6 | 303 | m_Headers[0] = header; |
04dbb646 | 304 | if (pg == wxPAGE_ALL || pg == wxPAGE_ODD) |
3ce369e6 VS |
305 | m_Headers[1] = header; |
306 | } | |
307 | ||
308 | ||
309 | ||
310 | void wxHtmlPrintout::SetFooter(const wxString& footer, int pg) | |
311 | { | |
04dbb646 | 312 | if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN) |
3ce369e6 | 313 | m_Footers[0] = footer; |
04dbb646 | 314 | if (pg == wxPAGE_ALL || pg == wxPAGE_ODD) |
3ce369e6 VS |
315 | m_Footers[1] = footer; |
316 | } | |
317 | ||
318 | ||
319 | ||
320 | void wxHtmlPrintout::CountPages() | |
321 | { | |
322 | wxBusyCursor wait; | |
323 | int pageWidth, pageHeight, mm_w, mm_h; | |
324 | float ppmm_h, ppmm_v; | |
325 | ||
326 | GetPageSizePixels(&pageWidth, &pageHeight); | |
327 | GetPageSizeMM(&mm_w, &mm_h); | |
328 | ppmm_h = (float)pageWidth / mm_w; | |
329 | ppmm_v = (float)pageHeight / mm_h; | |
330 | ||
331 | int pos = 0; | |
332 | ||
333 | m_NumPages = 0; | |
04dbb646 | 334 | |
3ce369e6 | 335 | m_PageBreaks[0] = 0; |
04dbb646 | 336 | do |
4f9297b0 | 337 | { |
04dbb646 | 338 | pos = m_Renderer->Render((int)( ppmm_h * m_MarginLeft), |
68be9f09 | 339 | (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), |
f2034f1b | 340 | pos, TRUE, INT_MAX, m_PageBreaks, m_NumPages); |
3ce369e6 | 341 | m_PageBreaks[++m_NumPages] = pos; |
4f9297b0 | 342 | } while (pos < m_Renderer->GetTotalHeight()); |
3ce369e6 VS |
343 | } |
344 | ||
345 | ||
346 | ||
347 | void wxHtmlPrintout::RenderPage(wxDC *dc, int page) | |
348 | { | |
349 | wxBusyCursor wait; | |
350 | ||
edbd0635 | 351 | int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h; |
3ce369e6 VS |
352 | float ppmm_h, ppmm_v; |
353 | ||
354 | GetPageSizePixels(&pageWidth, &pageHeight); | |
355 | GetPageSizeMM(&mm_w, &mm_h); | |
356 | ppmm_h = (float)pageWidth / mm_w; | |
357 | ppmm_v = (float)pageHeight / mm_h; | |
edbd0635 | 358 | wxDisplaySize(&scr_w, &scr_h); |
4f9297b0 | 359 | dc->GetSize(&dc_w, &dc_h); |
3ce369e6 | 360 | |
edbd0635 VS |
361 | int ppiPrinterX, ppiPrinterY; |
362 | GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); | |
363 | int ppiScreenX, ppiScreenY; | |
364 | GetPPIScreen(&ppiScreenX, &ppiScreenY); | |
365 | ||
4f9297b0 | 366 | dc->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_w / (double)pageWidth); |
04dbb646 | 367 | |
4f9297b0 | 368 | m_Renderer->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY); |
04dbb646 | 369 | |
4f9297b0 | 370 | dc->SetBackgroundMode(wxTRANSPARENT); |
3ce369e6 | 371 | |
04dbb646 | 372 | m_Renderer->Render((int) (ppmm_h * m_MarginLeft), |
68be9f09 | 373 | (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), |
f2034f1b | 374 | m_PageBreaks[page-1], FALSE, m_PageBreaks[page]-m_PageBreaks[page-1]); |
04dbb646 | 375 | |
4f9297b0 | 376 | m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY); |
04dbb646 | 377 | if (m_Headers[page % 2] != wxEmptyString) |
4f9297b0 VS |
378 | { |
379 | m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page)); | |
380 | m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop)); | |
3ce369e6 | 381 | } |
04dbb646 | 382 | if (m_Footers[page % 2] != wxEmptyString) |
4f9297b0 VS |
383 | { |
384 | m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page)); | |
385 | m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight)); | |
3ce369e6 VS |
386 | } |
387 | } | |
388 | ||
389 | ||
390 | ||
391 | wxString wxHtmlPrintout::TranslateHeader(const wxString& instr, int page) | |
392 | { | |
393 | wxString r = instr; | |
394 | wxString num; | |
04dbb646 | 395 | |
66a77a74 OK |
396 | num.Printf(wxT("%i"), page); |
397 | r.Replace(wxT("@PAGENUM@"), num); | |
3ce369e6 | 398 | |
66a77a74 OK |
399 | num.Printf(wxT("%i"), m_NumPages); |
400 | r.Replace(wxT("@PAGESCNT@"), num); | |
3ce369e6 VS |
401 | |
402 | return r; | |
403 | } | |
404 | ||
405 | ||
406 | ||
407 | void wxHtmlPrintout::SetMargins(float top, float bottom, float left, float right, float spaces) | |
408 | { | |
409 | m_MarginTop = top; | |
410 | m_MarginBottom = bottom; | |
411 | m_MarginLeft = left; | |
412 | m_MarginRight = right; | |
413 | m_MarginSpace = spaces; | |
414 | } | |
415 | ||
416 | ||
417 | ||
418 | ||
4eecf115 VS |
419 | void wxHtmlPrintout::SetFonts(wxString normal_face, wxString fixed_face, |
420 | const int *sizes) | |
421 | { | |
422 | m_Renderer->SetFonts(normal_face, fixed_face, sizes); | |
423 | m_RendererHdr->SetFonts(normal_face, fixed_face, sizes); | |
424 | } | |
3ce369e6 VS |
425 | |
426 | ||
4eecf115 VS |
427 | |
428 | //---------------------------------------------------------------------------- | |
3ce369e6 | 429 | // wxHtmlEasyPrinting |
4eecf115 | 430 | //---------------------------------------------------------------------------- |
3ce369e6 VS |
431 | |
432 | ||
433 | wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxFrame *parent_frame) | |
434 | { | |
435 | m_Frame = parent_frame; | |
436 | m_Name = name; | |
437 | m_PrintData = new wxPrintData; | |
438 | m_PageSetupData = new wxPageSetupDialogData; | |
439 | m_Headers[0] = m_Headers[1] = m_Footers[0] = m_Footers[1] = wxEmptyString; | |
04dbb646 | 440 | |
4f9297b0 | 441 | m_PageSetupData->EnableMargins(TRUE); |
04dbb646 | 442 | m_PageSetupData->SetMarginTopLeft(wxPoint(25, 25)); |
4f9297b0 | 443 | m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25)); |
4eecf115 VS |
444 | |
445 | SetFonts(wxEmptyString, wxEmptyString, NULL); | |
3ce369e6 VS |
446 | } |
447 | ||
448 | ||
449 | ||
450 | wxHtmlEasyPrinting::~wxHtmlEasyPrinting() | |
451 | { | |
452 | delete m_PrintData; | |
453 | delete m_PageSetupData; | |
454 | } | |
455 | ||
456 | ||
457 | ||
f6bcfd97 | 458 | bool wxHtmlEasyPrinting::PreviewFile(const wxString &htmlfile) |
3ce369e6 VS |
459 | { |
460 | wxHtmlPrintout *p1 = CreatePrintout(); | |
4f9297b0 | 461 | p1->SetHtmlFile(htmlfile); |
3ce369e6 | 462 | wxHtmlPrintout *p2 = CreatePrintout(); |
4f9297b0 | 463 | p2->SetHtmlFile(htmlfile); |
f6bcfd97 | 464 | return DoPreview(p1, p2); |
3ce369e6 VS |
465 | } |
466 | ||
467 | ||
468 | ||
f6bcfd97 | 469 | bool wxHtmlEasyPrinting::PreviewText(const wxString &htmltext, const wxString &basepath) |
3ce369e6 VS |
470 | { |
471 | wxHtmlPrintout *p1 = CreatePrintout(); | |
4f9297b0 | 472 | p1->SetHtmlText(htmltext, basepath, TRUE); |
3ce369e6 | 473 | wxHtmlPrintout *p2 = CreatePrintout(); |
4f9297b0 | 474 | p2->SetHtmlText(htmltext, basepath, TRUE); |
f6bcfd97 | 475 | return DoPreview(p1, p2); |
3ce369e6 VS |
476 | } |
477 | ||
478 | ||
479 | ||
f6bcfd97 | 480 | bool wxHtmlEasyPrinting::PrintFile(const wxString &htmlfile) |
3ce369e6 VS |
481 | { |
482 | wxHtmlPrintout *p = CreatePrintout(); | |
4f9297b0 | 483 | p->SetHtmlFile(htmlfile); |
453507f2 VS |
484 | bool ret = DoPrint(p); |
485 | delete p; | |
486 | return ret; | |
3ce369e6 VS |
487 | } |
488 | ||
489 | ||
490 | ||
f6bcfd97 | 491 | bool wxHtmlEasyPrinting::PrintText(const wxString &htmltext, const wxString &basepath) |
3ce369e6 VS |
492 | { |
493 | wxHtmlPrintout *p = CreatePrintout(); | |
4f9297b0 | 494 | p->SetHtmlText(htmltext, basepath, TRUE); |
453507f2 VS |
495 | bool ret = DoPrint(p); |
496 | delete p; | |
497 | return ret; | |
3ce369e6 VS |
498 | } |
499 | ||
500 | ||
501 | ||
f6bcfd97 | 502 | bool wxHtmlEasyPrinting::DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2) |
3ce369e6 VS |
503 | { |
504 | // Pass two printout objects: for preview, and possible printing. | |
505 | wxPrintDialogData printDialogData(*m_PrintData); | |
506 | wxPrintPreview *preview = new wxPrintPreview(printout1, printout2, &printDialogData); | |
04dbb646 | 507 | if (!preview->Ok()) |
4f9297b0 | 508 | { |
3ce369e6 | 509 | delete preview; |
f6bcfd97 | 510 | return FALSE; |
3ce369e6 | 511 | } |
3ca6a5f0 | 512 | |
04dbb646 VZ |
513 | wxPreviewFrame *frame = new wxPreviewFrame(preview, m_Frame, |
514 | m_Name + _(" Preview"), | |
3ca6a5f0 | 515 | wxPoint(100, 100), wxSize(650, 500)); |
4f9297b0 VS |
516 | frame->Centre(wxBOTH); |
517 | frame->Initialize(); | |
518 | frame->Show(TRUE); | |
3ca6a5f0 | 519 | return TRUE; |
3ce369e6 VS |
520 | } |
521 | ||
522 | ||
523 | ||
f6bcfd97 | 524 | bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout *printout) |
3ce369e6 VS |
525 | { |
526 | wxPrintDialogData printDialogData(*m_PrintData); | |
527 | wxPrinter printer(&printDialogData); | |
528 | ||
529 | if (!printer.Print(m_Frame, printout, TRUE)) | |
f6bcfd97 BP |
530 | { |
531 | return FALSE; | |
532 | } | |
3ca6a5f0 BP |
533 | |
534 | (*m_PrintData) = printer.GetPrintDialogData().GetPrintData(); | |
535 | return TRUE; | |
3ce369e6 VS |
536 | } |
537 | ||
538 | ||
539 | ||
540 | void wxHtmlEasyPrinting::PrinterSetup() | |
541 | { | |
542 | wxPrintDialogData printDialogData(*m_PrintData); | |
543 | wxPrintDialog printerDialog(m_Frame, &printDialogData); | |
04dbb646 | 544 | |
3ce369e6 VS |
545 | printerDialog.GetPrintDialogData().SetSetupDialog(TRUE); |
546 | ||
547 | if (printerDialog.ShowModal() == wxID_OK) | |
548 | (*m_PrintData) = printerDialog.GetPrintDialogData().GetPrintData(); | |
549 | } | |
550 | ||
551 | ||
552 | ||
553 | void wxHtmlEasyPrinting::PageSetup() | |
554 | { | |
58cf0491 JS |
555 | if (!m_PrintData->Ok()) |
556 | { | |
936b18ac | 557 | wxLogError(_("There was a problem during page setup: you may need to set a default printer.")); |
58cf0491 JS |
558 | return; |
559 | } | |
560 | ||
4f9297b0 | 561 | m_PageSetupData->SetPrintData(*m_PrintData); |
3ce369e6 VS |
562 | wxPageSetupDialog pageSetupDialog(m_Frame, m_PageSetupData); |
563 | ||
04dbb646 | 564 | if (pageSetupDialog.ShowModal() == wxID_OK) |
4f9297b0 | 565 | { |
3ce369e6 VS |
566 | (*m_PrintData) = pageSetupDialog.GetPageSetupData().GetPrintData(); |
567 | (*m_PageSetupData) = pageSetupDialog.GetPageSetupData(); | |
568 | } | |
569 | } | |
570 | ||
571 | ||
572 | ||
573 | void wxHtmlEasyPrinting::SetHeader(const wxString& header, int pg) | |
574 | { | |
04dbb646 | 575 | if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN) |
3ce369e6 | 576 | m_Headers[0] = header; |
04dbb646 | 577 | if (pg == wxPAGE_ALL || pg == wxPAGE_ODD) |
3ce369e6 VS |
578 | m_Headers[1] = header; |
579 | } | |
580 | ||
581 | ||
582 | ||
583 | void wxHtmlEasyPrinting::SetFooter(const wxString& footer, int pg) | |
584 | { | |
04dbb646 | 585 | if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN) |
3ce369e6 | 586 | m_Footers[0] = footer; |
04dbb646 | 587 | if (pg == wxPAGE_ALL || pg == wxPAGE_ODD) |
3ce369e6 VS |
588 | m_Footers[1] = footer; |
589 | } | |
590 | ||
591 | ||
4eecf115 VS |
592 | void wxHtmlEasyPrinting::SetFonts(wxString normal_face, wxString fixed_face, |
593 | const int *sizes) | |
594 | { | |
595 | m_FontFaceNormal = normal_face; | |
596 | m_FontFaceFixed = fixed_face; | |
597 | ||
598 | if (sizes) | |
599 | { | |
600 | m_FontsSizes = m_FontsSizesArr; | |
601 | for (int i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i]; | |
602 | } | |
603 | else | |
604 | m_FontsSizes = NULL; | |
605 | } | |
606 | ||
3ce369e6 VS |
607 | |
608 | wxHtmlPrintout *wxHtmlEasyPrinting::CreatePrintout() | |
609 | { | |
610 | wxHtmlPrintout *p = new wxHtmlPrintout(m_Name); | |
04dbb646 | 611 | |
4eecf115 VS |
612 | p->SetFonts(m_FontFaceNormal, m_FontFaceFixed, m_FontsSizes); |
613 | ||
4f9297b0 VS |
614 | p->SetHeader(m_Headers[0], wxPAGE_EVEN); |
615 | p->SetHeader(m_Headers[1], wxPAGE_ODD); | |
616 | p->SetFooter(m_Footers[0], wxPAGE_EVEN); | |
617 | p->SetFooter(m_Footers[1], wxPAGE_ODD); | |
618 | ||
619 | p->SetMargins(m_PageSetupData->GetMarginTopLeft().y, | |
620 | m_PageSetupData->GetMarginBottomRight().y, | |
621 | m_PageSetupData->GetMarginTopLeft().x, | |
622 | m_PageSetupData->GetMarginBottomRight().x); | |
04dbb646 | 623 | |
3ce369e6 VS |
624 | return p; |
625 | } | |
626 | ||
627 | ||
0cecad31 VS |
628 | // This hack forces the linker to always link in m_* files |
629 | // (wxHTML doesn't work without handlers from these files) | |
630 | #include "wx/html/forcelnk.h" | |
631 | FORCE_WXHTML_MODULES() | |
3ce369e6 | 632 | |
72cdf4c9 | 633 | #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE |