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