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