]> git.saurik.com Git - wxWidgets.git/blob - src/html/htmprint.cpp
3b628934c5e02da836566115e10b75e38d42d6cb
[wxWidgets.git] / src / html / htmprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/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 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_HTML && wxUSE_PRINTING_ARCHITECTURE && wxUSE_STREAMS
19
20 #ifndef WX_PRECOMP
21 #include "wx/log.h"
22 #include "wx/intl.h"
23 #include "wx/dc.h"
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
26 #include "wx/module.h"
27 #endif
28
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"
34
35
36 // default font size of normal text (HTML font size 0) for printing, in points:
37 #define DEFAULT_PRINT_FONT_SIZE 12
38
39
40 //--------------------------------------------------------------------------------
41 // wxHtmlDCRenderer
42 //--------------------------------------------------------------------------------
43
44
45 wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject()
46 {
47 m_DC = NULL;
48 m_Width = m_Height = 0;
49 m_Cells = NULL;
50 m_Parser = new wxHtmlWinParser();
51 m_FS = new wxFileSystem();
52 m_Parser->SetFS(m_FS);
53 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE);
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
67 void wxHtmlDCRenderer::SetDC(wxDC *dc, double pixel_scale)
68 {
69 m_DC = dc;
70 m_Parser->SetDC(m_DC, pixel_scale);
71 }
72
73
74
75 void wxHtmlDCRenderer::SetSize(int width, int height)
76 {
77 wxCHECK_RET( width, "width must be non-zero" );
78 wxCHECK_RET( height, "height must be non-zero" );
79
80 m_Width = width;
81 m_Height = height;
82 }
83
84
85 void wxHtmlDCRenderer::SetHtmlText(const wxString& html, const wxString& basepath, bool isdir)
86 {
87 wxCHECK_RET( m_DC, "SetDC() must be called before SetHtmlText()" );
88 wxCHECK_RET( m_Width, "SetSize() must be called before SetHtmlText()" );
89
90 wxDELETE(m_Cells);
91
92 m_FS->ChangePathTo(basepath, isdir);
93 m_Cells = (wxHtmlContainerCell*) m_Parser->Parse(html);
94 m_Cells->SetIndent(0, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
95 m_Cells->Layout(m_Width);
96 }
97
98
99 void wxHtmlDCRenderer::SetFonts(const wxString& normal_face, const wxString& fixed_face,
100 const int *sizes)
101 {
102 m_Parser->SetFonts(normal_face, fixed_face, sizes);
103
104 if ( m_Cells )
105 m_Cells->Layout(m_Width);
106 // else: SetHtmlText() not yet called, no need for relayout
107 }
108
109 void wxHtmlDCRenderer::SetStandardFonts(int size,
110 const wxString& normal_face,
111 const wxString& fixed_face)
112 {
113 m_Parser->SetStandardFonts(size, normal_face, fixed_face);
114
115 if ( m_Cells )
116 m_Cells->Layout(m_Width);
117 // else: SetHtmlText() not yet called, no need for relayout
118 }
119
120 int wxHtmlDCRenderer::Render(int x, int y,
121 wxArrayInt& known_pagebreaks,
122 int from, int dont_render, int to)
123 {
124 wxCHECK_MSG( m_Cells, 0, "SetHtmlText() must be called before Render()" );
125 wxCHECK_MSG( m_DC, 0, "SetDC() must be called before Render()" );
126
127 int pbreak, hght;
128
129 pbreak = (int)(from + m_Height);
130 while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks)) {}
131 hght = pbreak - from;
132 if(to < hght)
133 hght = to;
134
135 if (!dont_render)
136 {
137 wxHtmlRenderingInfo rinfo;
138 wxDefaultHtmlRenderingStyle rstyle;
139 rinfo.SetStyle(&rstyle);
140 m_DC->SetBrush(*wxWHITE_BRUSH);
141 m_DC->SetClippingRegion(x, y, m_Width, hght);
142 m_Cells->Draw(*m_DC,
143 x, (y - from),
144 y, y + hght,
145 rinfo);
146 m_DC->DestroyClippingRegion();
147 }
148
149 if (pbreak < m_Cells->GetHeight()) return pbreak;
150 else return GetTotalHeight();
151 }
152
153 int wxHtmlDCRenderer::GetTotalWidth() const
154 {
155 return m_Cells ? m_Cells->GetWidth() : 0;
156 }
157
158 int wxHtmlDCRenderer::GetTotalHeight() const
159 {
160 return m_Cells ? m_Cells->GetHeight() : 0;
161 }
162
163
164 //--------------------------------------------------------------------------------
165 // wxHtmlPrintout
166 //--------------------------------------------------------------------------------
167
168
169 wxList wxHtmlPrintout::m_Filters;
170
171 wxHtmlPrintout::wxHtmlPrintout(const wxString& title) : wxPrintout(title)
172 {
173 m_Renderer = new wxHtmlDCRenderer;
174 m_RendererHdr = new wxHtmlDCRenderer;
175 m_NumPages = wxHTML_PRINT_MAX_PAGES;
176 m_Document = m_BasePath = wxEmptyString; m_BasePathIsDir = true;
177 m_Headers[0] = m_Headers[1] = wxEmptyString;
178 m_Footers[0] = m_Footers[1] = wxEmptyString;
179 m_HeaderHeight = m_FooterHeight = 0;
180 SetMargins(); // to default values
181 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE);
182 }
183
184
185
186 wxHtmlPrintout::~wxHtmlPrintout()
187 {
188 delete m_Renderer;
189 delete m_RendererHdr;
190 }
191
192 void wxHtmlPrintout::CleanUpStatics()
193 {
194 WX_CLEAR_LIST(wxList, m_Filters);
195 }
196
197 // Adds input filter
198 void wxHtmlPrintout::AddFilter(wxHtmlFilter *filter)
199 {
200 m_Filters.Append(filter);
201 }
202
203 bool
204 wxHtmlPrintout::CheckFit(const wxSize& pageArea, const wxSize& docArea) const
205 {
206 if ( docArea.x > pageArea.x )
207 {
208 wxMessageDialog
209 dlg
210 (
211 NULL,
212 wxString::Format
213 (
214 _("The document \"%s\" doesn't fit on the page "
215 "horizontally and will be truncated if printed.\n"
216 "\n"
217 "Would you like to proceed with printing it nevertheless?"),
218 GetTitle()
219 ),
220 _("Printing"),
221 wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxICON_QUESTION
222 );
223 dlg.SetExtendedMessage
224 (
225 _("If possible, try changing the layout parameters to "
226 "make the printout more narrow.")
227 );
228 dlg.SetOKLabel(wxID_PRINT);
229
230 if ( dlg.ShowModal() == wxID_CANCEL )
231 return false;
232 }
233
234 return true;
235 }
236
237 void wxHtmlPrintout::OnPreparePrinting()
238 {
239 int pageWidth, pageHeight, mm_w, mm_h, dc_w, dc_h;
240 float ppmm_h, ppmm_v;
241
242 GetPageSizePixels(&pageWidth, &pageHeight);
243 GetPageSizeMM(&mm_w, &mm_h);
244 ppmm_h = (float)pageWidth / mm_w;
245 ppmm_v = (float)pageHeight / mm_h;
246
247 int ppiPrinterX, ppiPrinterY;
248 GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
249 wxUnusedVar(ppiPrinterX);
250 int ppiScreenX, ppiScreenY;
251 GetPPIScreen(&ppiScreenX, &ppiScreenY);
252 wxUnusedVar(ppiScreenX);
253
254 GetDC()->GetSize(&dc_w, &dc_h);
255
256 GetDC()->SetUserScale((double)dc_w / (double)pageWidth,
257 (double)dc_h / (double)pageHeight);
258
259 /* prepare headers/footers renderer: */
260
261 m_RendererHdr->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
262 m_RendererHdr->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)),
263 (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom)));
264 if (m_Headers[0] != wxEmptyString)
265 {
266 m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[0], 1));
267 m_HeaderHeight = m_RendererHdr->GetTotalHeight();
268 }
269 else if (m_Headers[1] != wxEmptyString)
270 {
271 m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[1], 1));
272 m_HeaderHeight = m_RendererHdr->GetTotalHeight();
273 }
274 if (m_Footers[0] != wxEmptyString)
275 {
276 m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[0], 1));
277 m_FooterHeight = m_RendererHdr->GetTotalHeight();
278 }
279 else if (m_Footers[1] != wxEmptyString)
280 {
281 m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[1], 1));
282 m_FooterHeight = m_RendererHdr->GetTotalHeight();
283 }
284
285 /* prepare main renderer: */
286 m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
287
288 const int printAreaW = int(ppmm_h * (mm_w - m_MarginLeft - m_MarginRight));
289 int printAreaH = int(ppmm_v * (mm_h - m_MarginTop - m_MarginBottom));
290 if ( m_HeaderHeight )
291 printAreaH -= int(m_HeaderHeight + m_MarginSpace * ppmm_v);
292 if ( m_FooterHeight )
293 printAreaH -= int(m_FooterHeight + m_MarginSpace * ppmm_v);
294
295 m_Renderer->SetSize(printAreaW, printAreaH);
296 m_Renderer->SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir);
297
298 if ( CheckFit(wxSize(printAreaW, printAreaH),
299 wxSize(m_Renderer->GetTotalWidth(),
300 m_Renderer->GetTotalHeight())) )
301 {
302 // do paginate the document
303 CountPages();
304 }
305 //else: if we don't call CountPages() m_PageBreaks remains empty and our
306 // GetPageInfo() will return 0 as max page and so nothing will be
307 // printed
308 }
309
310 bool wxHtmlPrintout::OnBeginDocument(int startPage, int endPage)
311 {
312 if (!wxPrintout::OnBeginDocument(startPage, endPage)) return false;
313
314 return true;
315 }
316
317
318 bool wxHtmlPrintout::OnPrintPage(int page)
319 {
320 wxDC *dc = GetDC();
321 if (dc && dc->IsOk())
322 {
323 if (HasPage(page))
324 RenderPage(dc, page);
325 return true;
326 }
327 else return false;
328 }
329
330
331 void wxHtmlPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
332 {
333 *minPage = 1;
334 if ( m_NumPages >= (signed)m_PageBreaks.GetCount()-1)
335 *maxPage = m_NumPages;
336 else
337 *maxPage = (signed)m_PageBreaks.GetCount()-1;
338 *selPageFrom = 1;
339 *selPageTo = (signed)m_PageBreaks.GetCount()-1;
340 }
341
342
343
344 bool wxHtmlPrintout::HasPage(int pageNum)
345 {
346 return pageNum > 0 && (unsigned)pageNum < m_PageBreaks.GetCount();
347 }
348
349
350
351 void wxHtmlPrintout::SetHtmlText(const wxString& html, const wxString &basepath, bool isdir)
352 {
353 m_Document = html;
354 m_BasePath = basepath;
355 m_BasePathIsDir = isdir;
356 }
357
358 void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile)
359 {
360 wxFileSystem fs;
361 wxFSFile *ff;
362
363 if (wxFileExists(htmlfile))
364 ff = fs.OpenFile(wxFileSystem::FileNameToURL(htmlfile));
365 else
366 ff = fs.OpenFile(htmlfile);
367
368 if (ff == NULL)
369 {
370 wxLogError(htmlfile + _(": file does not exist!"));
371 return;
372 }
373
374 bool done = false;
375 wxHtmlFilterHTML defaultFilter;
376 wxString doc;
377
378 wxList::compatibility_iterator node = m_Filters.GetFirst();
379 while (node)
380 {
381 wxHtmlFilter *h = (wxHtmlFilter*) node->GetData();
382 if (h->CanRead(*ff))
383 {
384 doc = h->ReadFile(*ff);
385 done = true;
386 break;
387 }
388 node = node->GetNext();
389 }
390
391 if (!done)
392 doc = defaultFilter.ReadFile(*ff);
393
394 SetHtmlText(doc, htmlfile, false);
395 delete ff;
396 }
397
398
399
400 void wxHtmlPrintout::SetHeader(const wxString& header, int pg)
401 {
402 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
403 m_Headers[0] = header;
404 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
405 m_Headers[1] = header;
406 }
407
408
409
410 void wxHtmlPrintout::SetFooter(const wxString& footer, int pg)
411 {
412 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
413 m_Footers[0] = footer;
414 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
415 m_Footers[1] = footer;
416 }
417
418
419
420 void wxHtmlPrintout::CountPages()
421 {
422 wxBusyCursor wait;
423 int pageWidth, pageHeight, mm_w, mm_h;
424 float ppmm_h, ppmm_v;
425
426 GetPageSizePixels(&pageWidth, &pageHeight);
427 GetPageSizeMM(&mm_w, &mm_h);
428 ppmm_h = (float)pageWidth / mm_w;
429 ppmm_v = (float)pageHeight / mm_h;
430
431 int pos = 0;
432 m_NumPages = 0;
433 // m_PageBreaks[0] = 0;
434
435 m_PageBreaks.Clear();
436 m_PageBreaks.Add( 0);
437 do
438 {
439 pos = m_Renderer->Render((int)( ppmm_h * m_MarginLeft),
440 (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight),
441 m_PageBreaks,
442 pos, true, INT_MAX);
443 m_PageBreaks.Add( pos);
444 if( m_PageBreaks.GetCount() > wxHTML_PRINT_MAX_PAGES)
445 {
446 wxMessageBox( _("HTML pagination algorithm generated more than the allowed maximum number of pages and it can't continue any longer!"),
447 _("Warning"), wxCANCEL | wxICON_ERROR );
448 break;
449 }
450 } while (pos < m_Renderer->GetTotalHeight());
451 }
452
453
454
455 void wxHtmlPrintout::RenderPage(wxDC *dc, int page)
456 {
457 wxBusyCursor wait;
458
459 int pageWidth, pageHeight, mm_w, mm_h, dc_w, dc_h;
460 float ppmm_h, ppmm_v;
461
462 GetPageSizePixels(&pageWidth, &pageHeight);
463 GetPageSizeMM(&mm_w, &mm_h);
464 ppmm_h = (float)pageWidth / mm_w;
465 ppmm_v = (float)pageHeight / mm_h;
466 dc->GetSize(&dc_w, &dc_h);
467
468 int ppiPrinterX, ppiPrinterY;
469 GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
470 wxUnusedVar(ppiPrinterX);
471 int ppiScreenX, ppiScreenY;
472 GetPPIScreen(&ppiScreenX, &ppiScreenY);
473 wxUnusedVar(ppiScreenX);
474
475 dc->SetUserScale((double)dc_w / (double)pageWidth,
476 (double)dc_h / (double)pageHeight);
477
478 m_Renderer->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
479
480 dc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
481
482 m_Renderer->Render((int) (ppmm_h * m_MarginLeft),
483 (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), m_PageBreaks,
484 m_PageBreaks[page-1], false, m_PageBreaks[page]-m_PageBreaks[page-1]);
485
486
487 m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
488 if (m_Headers[page % 2] != wxEmptyString)
489 {
490 m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page));
491 m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop), m_PageBreaks);
492 }
493 if (m_Footers[page % 2] != wxEmptyString)
494 {
495 m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page));
496 m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight), m_PageBreaks);
497 }
498 }
499
500
501
502 wxString wxHtmlPrintout::TranslateHeader(const wxString& instr, int page)
503 {
504 wxString r = instr;
505 wxString num;
506
507 num.Printf(wxT("%i"), page);
508 r.Replace(wxT("@PAGENUM@"), num);
509
510 num.Printf(wxT("%lu"), (unsigned long)(m_PageBreaks.GetCount() - 1));
511 r.Replace(wxT("@PAGESCNT@"), num);
512
513 const wxDateTime now = wxDateTime::Now();
514 r.Replace(wxT("@DATE@"), now.FormatDate());
515 r.Replace(wxT("@TIME@"), now.FormatTime());
516
517 r.Replace(wxT("@TITLE@"), GetTitle());
518
519 return r;
520 }
521
522
523
524 void wxHtmlPrintout::SetMargins(float top, float bottom, float left, float right, float spaces)
525 {
526 m_MarginTop = top;
527 m_MarginBottom = bottom;
528 m_MarginLeft = left;
529 m_MarginRight = right;
530 m_MarginSpace = spaces;
531 }
532
533
534
535
536 void wxHtmlPrintout::SetFonts(const wxString& normal_face, const wxString& fixed_face,
537 const int *sizes)
538 {
539 m_Renderer->SetFonts(normal_face, fixed_face, sizes);
540 m_RendererHdr->SetFonts(normal_face, fixed_face, sizes);
541 }
542
543 void wxHtmlPrintout::SetStandardFonts(int size,
544 const wxString& normal_face,
545 const wxString& fixed_face)
546 {
547 m_Renderer->SetStandardFonts(size, normal_face, fixed_face);
548 m_RendererHdr->SetStandardFonts(size, normal_face, fixed_face);
549 }
550
551
552
553 //----------------------------------------------------------------------------
554 // wxHtmlEasyPrinting
555 //----------------------------------------------------------------------------
556
557
558 wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxWindow *parentWindow)
559 {
560 m_ParentWindow = parentWindow;
561 m_Name = name;
562 m_PrintData = NULL;
563 m_PageSetupData = new wxPageSetupDialogData;
564 m_Headers[0] = m_Headers[1] = m_Footers[0] = m_Footers[1] = wxEmptyString;
565
566 m_PageSetupData->EnableMargins(true);
567 m_PageSetupData->SetMarginTopLeft(wxPoint(25, 25));
568 m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25));
569
570 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE);
571 }
572
573
574
575 wxHtmlEasyPrinting::~wxHtmlEasyPrinting()
576 {
577 delete m_PrintData;
578 delete m_PageSetupData;
579 }
580
581
582 wxPrintData *wxHtmlEasyPrinting::GetPrintData()
583 {
584 if (m_PrintData == NULL)
585 m_PrintData = new wxPrintData();
586 return m_PrintData;
587 }
588
589
590 bool wxHtmlEasyPrinting::PreviewFile(const wxString &htmlfile)
591 {
592 wxHtmlPrintout *p1 = CreatePrintout();
593 p1->SetHtmlFile(htmlfile);
594 wxHtmlPrintout *p2 = CreatePrintout();
595 p2->SetHtmlFile(htmlfile);
596 return DoPreview(p1, p2);
597 }
598
599
600
601 bool wxHtmlEasyPrinting::PreviewText(const wxString &htmltext, const wxString &basepath)
602 {
603 wxHtmlPrintout *p1 = CreatePrintout();
604 p1->SetHtmlText(htmltext, basepath, true);
605 wxHtmlPrintout *p2 = CreatePrintout();
606 p2->SetHtmlText(htmltext, basepath, true);
607 return DoPreview(p1, p2);
608 }
609
610
611
612 bool wxHtmlEasyPrinting::PrintFile(const wxString &htmlfile)
613 {
614 wxHtmlPrintout *p = CreatePrintout();
615 p->SetHtmlFile(htmlfile);
616 bool ret = DoPrint(p);
617 delete p;
618 return ret;
619 }
620
621
622
623 bool wxHtmlEasyPrinting::PrintText(const wxString &htmltext, const wxString &basepath)
624 {
625 wxHtmlPrintout *p = CreatePrintout();
626 p->SetHtmlText(htmltext, basepath, true);
627 bool ret = DoPrint(p);
628 delete p;
629 return ret;
630 }
631
632
633
634 bool wxHtmlEasyPrinting::DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2)
635 {
636 // Pass two printout objects: for preview, and possible printing.
637 wxPrintDialogData printDialogData(*GetPrintData());
638 wxPrintPreview *preview = new wxPrintPreview(printout1, printout2, &printDialogData);
639 if (!preview->Ok())
640 {
641 delete preview;
642 return false;
643 }
644
645 wxPreviewFrame *frame = new wxPreviewFrame(preview, m_ParentWindow,
646 m_Name + _(" Preview"),
647 wxPoint(100, 100), wxSize(650, 500));
648 frame->Centre(wxBOTH);
649 frame->Initialize();
650 frame->Show(true);
651 return true;
652 }
653
654
655
656 bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout *printout)
657 {
658 wxPrintDialogData printDialogData(*GetPrintData());
659 wxPrinter printer(&printDialogData);
660
661 if (!printer.Print(m_ParentWindow, printout, true))
662 {
663 return false;
664 }
665
666 (*GetPrintData()) = printer.GetPrintDialogData().GetPrintData();
667 return true;
668 }
669
670
671
672
673 void wxHtmlEasyPrinting::PageSetup()
674 {
675 if (!GetPrintData()->Ok())
676 {
677 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
678 return;
679 }
680
681 m_PageSetupData->SetPrintData(*GetPrintData());
682 wxPageSetupDialog pageSetupDialog(m_ParentWindow, m_PageSetupData);
683
684 if (pageSetupDialog.ShowModal() == wxID_OK)
685 {
686 (*GetPrintData()) = pageSetupDialog.GetPageSetupData().GetPrintData();
687 (*m_PageSetupData) = pageSetupDialog.GetPageSetupData();
688 }
689 }
690
691
692
693 void wxHtmlEasyPrinting::SetHeader(const wxString& header, int pg)
694 {
695 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
696 m_Headers[0] = header;
697 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
698 m_Headers[1] = header;
699 }
700
701
702
703 void wxHtmlEasyPrinting::SetFooter(const wxString& footer, int pg)
704 {
705 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
706 m_Footers[0] = footer;
707 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
708 m_Footers[1] = footer;
709 }
710
711
712 void wxHtmlEasyPrinting::SetFonts(const wxString& normal_face, const wxString& fixed_face,
713 const int *sizes)
714 {
715 m_fontMode = FontMode_Explicit;
716 m_FontFaceNormal = normal_face;
717 m_FontFaceFixed = fixed_face;
718
719 if (sizes)
720 {
721 m_FontsSizes = m_FontsSizesArr;
722 for (int i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i];
723 }
724 else
725 m_FontsSizes = NULL;
726 }
727
728 void wxHtmlEasyPrinting::SetStandardFonts(int size,
729 const wxString& normal_face,
730 const wxString& fixed_face)
731 {
732 m_fontMode = FontMode_Standard;
733 m_FontFaceNormal = normal_face;
734 m_FontFaceFixed = fixed_face;
735 m_FontsSizesArr[0] = size;
736 }
737
738
739 wxHtmlPrintout *wxHtmlEasyPrinting::CreatePrintout()
740 {
741 wxHtmlPrintout *p = new wxHtmlPrintout(m_Name);
742
743 if (m_fontMode == FontMode_Explicit)
744 {
745 p->SetFonts(m_FontFaceNormal, m_FontFaceFixed, m_FontsSizes);
746 }
747 else // FontMode_Standard
748 {
749 p->SetStandardFonts(m_FontsSizesArr[0],
750 m_FontFaceNormal, m_FontFaceFixed);
751 }
752
753 p->SetHeader(m_Headers[0], wxPAGE_EVEN);
754 p->SetHeader(m_Headers[1], wxPAGE_ODD);
755 p->SetFooter(m_Footers[0], wxPAGE_EVEN);
756 p->SetFooter(m_Footers[1], wxPAGE_ODD);
757
758 p->SetMargins(m_PageSetupData->GetMarginTopLeft().y,
759 m_PageSetupData->GetMarginBottomRight().y,
760 m_PageSetupData->GetMarginTopLeft().x,
761 m_PageSetupData->GetMarginBottomRight().x);
762
763 return p;
764 }
765
766 // A module to allow initialization/cleanup
767 // without calling these functions from app.cpp or from
768 // the user's application.
769
770 class wxHtmlPrintingModule: public wxModule
771 {
772 DECLARE_DYNAMIC_CLASS(wxHtmlPrintingModule)
773 public:
774 wxHtmlPrintingModule() : wxModule() {}
775 bool OnInit() { return true; }
776 void OnExit() { wxHtmlPrintout::CleanUpStatics(); }
777 };
778
779 IMPLEMENT_DYNAMIC_CLASS(wxHtmlPrintingModule, wxModule)
780
781
782 // This hack forces the linker to always link in m_* files
783 // (wxHTML doesn't work without handlers from these files)
784 #include "wx/html/forcelnk.h"
785 FORCE_WXHTML_MODULES()
786
787 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE