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