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