1999-10-17 09:03:40 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: htmprint.h
|
|
|
|
// Purpose: html printing classes
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 25/09/99
|
|
|
|
// RCS-ID: $Id$
|
2005-05-04 14:57:50 -04:00
|
|
|
// Copyright: (c) Vaclav Slavik
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1999-10-17 09:03:40 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_HTMPRINT_H_
|
|
|
|
#define _WX_HTMPRINT_H_
|
|
|
|
|
2002-01-06 10:40:15 -05:00
|
|
|
#include "wx/defs.h"
|
1999-10-17 09:03:40 -04:00
|
|
|
|
1999-10-18 11:14:52 -04:00
|
|
|
#if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
|
1999-10-17 09:03:40 -04:00
|
|
|
|
|
|
|
#include "wx/html/htmlcell.h"
|
|
|
|
#include "wx/html/winpars.h"
|
2003-07-06 13:52:42 -04:00
|
|
|
#include "wx/html/htmlfilt.h"
|
1999-10-17 09:03:40 -04:00
|
|
|
|
|
|
|
#include "wx/print.h"
|
|
|
|
#include "wx/printdlg.h"
|
|
|
|
|
2003-05-12 18:33:51 -04:00
|
|
|
#include <limits.h> // INT_MAX
|
|
|
|
|
1999-10-17 09:03:40 -04:00
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
// wxHtmlDCRenderer
|
2004-09-27 15:06:39 -04:00
|
|
|
// This class is capable of rendering HTML into specified
|
1999-10-17 09:03:40 -04:00
|
|
|
// portion of DC
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
2003-07-04 09:04:05 -04:00
|
|
|
class WXDLLIMPEXP_HTML wxHtmlDCRenderer : public wxObject
|
1999-10-17 09:03:40 -04:00
|
|
|
{
|
2001-04-29 13:57:59 -04:00
|
|
|
public:
|
|
|
|
wxHtmlDCRenderer();
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxHtmlDCRenderer();
|
2001-04-29 13:57:59 -04:00
|
|
|
|
|
|
|
// Following 3 methods *must* be called before any call to Render:
|
|
|
|
|
2003-05-12 18:33:51 -04:00
|
|
|
// Assign DC to this render
|
2001-04-29 13:57:59 -04:00
|
|
|
void SetDC(wxDC *dc, double pixel_scale = 1.0);
|
|
|
|
|
|
|
|
// Sets size of output rectangle, in pixels. Note that you *can't* change
|
|
|
|
// width of the rectangle between calls to Render! (You can freely change height.)
|
|
|
|
void SetSize(int width, int height);
|
|
|
|
|
|
|
|
// Sets the text to be displayed.
|
|
|
|
// Basepath is base directory (html string would be stored there if it was in
|
|
|
|
// file). It is used to determine path for loading images, for example.
|
2004-09-27 15:06:39 -04:00
|
|
|
// isdir is false if basepath is filename, true if it is directory name
|
2001-04-29 13:57:59 -04:00
|
|
|
// (see wxFileSystem for detailed explanation)
|
2004-09-27 15:06:39 -04:00
|
|
|
void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = true);
|
2001-04-29 13:57:59 -04:00
|
|
|
|
2003-03-16 15:30:26 -05:00
|
|
|
// Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
|
2005-09-24 17:43:15 -04:00
|
|
|
void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
|
2003-03-16 15:30:26 -05:00
|
|
|
|
2004-09-24 05:55:10 -04:00
|
|
|
// Sets font sizes to be relative to the given size or the system
|
|
|
|
// default size; use either specified or default font
|
|
|
|
void SetStandardFonts(int size = -1,
|
|
|
|
const wxString& normal_face = wxEmptyString,
|
|
|
|
const wxString& fixed_face = wxEmptyString);
|
2004-08-05 19:59:44 -04:00
|
|
|
|
2001-04-29 13:57:59 -04:00
|
|
|
// [x,y] is position of upper-left corner of printing rectangle (see SetSize)
|
2003-05-12 18:33:51 -04:00
|
|
|
// from is y-coordinate of the very first visible cell
|
|
|
|
// to is y-coordinate of the next following page break, if any
|
2001-04-29 13:57:59 -04:00
|
|
|
// Returned value is y coordinate of first cell than didn't fit onto page.
|
|
|
|
// Use this value as 'from' in next call to Render in order to print multiple pages
|
|
|
|
// document
|
|
|
|
// If dont_render is TRUE then nothing is rendered into DC and it only counts
|
|
|
|
// pixels and return y coord of the next page
|
|
|
|
//
|
2003-05-12 18:33:51 -04:00
|
|
|
// known_pagebreaks and number_of_pages are used only when counting pages;
|
|
|
|
// otherwise, their default values should be used. Their purpose is to
|
|
|
|
// support pagebreaks using a subset of CSS2's <DIV>. The <DIV> handler
|
|
|
|
// needs to know what pagebreaks have already been set so that it doesn't
|
|
|
|
// set the same pagebreak twice.
|
|
|
|
//
|
|
|
|
// CAUTION! Render() changes DC's user scale and does NOT restore it!
|
2006-05-28 18:56:28 -04:00
|
|
|
int Render(int x, int y, wxArrayInt& known_pagebreaks, int from = 0,
|
2008-10-29 14:58:21 -04:00
|
|
|
int dont_render = false, int to = INT_MAX);
|
2001-04-29 13:57:59 -04:00
|
|
|
|
2009-03-26 09:37:37 -04:00
|
|
|
// returns total width of the html document
|
|
|
|
int GetTotalWidth() const;
|
|
|
|
|
2001-04-29 13:57:59 -04:00
|
|
|
// returns total height of the html document
|
|
|
|
// (compare Render's return value with this)
|
2009-03-26 09:37:37 -04:00
|
|
|
int GetTotalHeight() const;
|
2001-04-29 13:57:59 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxDC *m_DC;
|
|
|
|
wxHtmlWinParser *m_Parser;
|
|
|
|
wxFileSystem *m_FS;
|
|
|
|
wxHtmlContainerCell *m_Cells;
|
|
|
|
int m_MaxWidth, m_Width, m_Height;
|
2003-01-02 18:38:11 -05:00
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxHtmlDCRenderer);
|
1999-10-17 09:03:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
wxPAGE_ODD,
|
|
|
|
wxPAGE_EVEN,
|
|
|
|
wxPAGE_ALL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
// wxHtmlPrintout
|
2004-05-23 10:56:36 -04:00
|
|
|
// This class is derived from standard wxWidgets printout class
|
1999-10-17 09:03:40 -04:00
|
|
|
// and is used to print HTML documents.
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2003-07-04 09:04:05 -04:00
|
|
|
class WXDLLIMPEXP_HTML wxHtmlPrintout : public wxPrintout
|
1999-10-17 09:03:40 -04:00
|
|
|
{
|
2001-08-23 14:56:41 -04:00
|
|
|
public:
|
2002-12-04 09:11:26 -05:00
|
|
|
wxHtmlPrintout(const wxString& title = wxT("Printout"));
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxHtmlPrintout();
|
2001-08-23 14:56:41 -04:00
|
|
|
|
2004-09-27 15:06:39 -04:00
|
|
|
void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = true);
|
2001-08-23 14:56:41 -04:00
|
|
|
// prepares the class for printing this html document.
|
|
|
|
// Must be called before using the class, in fact just after constructor
|
|
|
|
//
|
|
|
|
// basepath is base directory (html string would be stored there if it was in
|
|
|
|
// file). It is used to determine path for loading images, for example.
|
2004-09-27 15:06:39 -04:00
|
|
|
// isdir is false if basepath is filename, true if it is directory name
|
2001-08-23 14:56:41 -04:00
|
|
|
// (see wxFileSystem for detailed explanation)
|
|
|
|
|
|
|
|
void SetHtmlFile(const wxString &htmlfile);
|
|
|
|
// same as SetHtmlText except that it takes regular file as the parameter
|
|
|
|
|
|
|
|
void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
|
|
|
|
void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
|
|
|
|
// sets header/footer for the document. The argument is interpreted as HTML document.
|
|
|
|
// You can use macros in it:
|
|
|
|
// @PAGENUM@ is replaced by page number
|
|
|
|
// @PAGESCNT@ is replaced by total number of pages
|
|
|
|
//
|
|
|
|
// pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
|
|
|
|
// You can set different header/footer for odd and even pages
|
|
|
|
|
2003-03-16 15:30:26 -05:00
|
|
|
// Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
|
2005-09-24 17:43:15 -04:00
|
|
|
void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
|
2003-03-16 15:30:26 -05:00
|
|
|
|
2004-09-24 05:55:10 -04:00
|
|
|
// Sets font sizes to be relative to the given size or the system
|
|
|
|
// default size; use either specified or default font
|
|
|
|
void SetStandardFonts(int size = -1,
|
|
|
|
const wxString& normal_face = wxEmptyString,
|
|
|
|
const wxString& fixed_face = wxEmptyString);
|
2004-08-05 19:59:44 -04:00
|
|
|
|
2004-09-27 15:06:39 -04:00
|
|
|
void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2,
|
2001-08-23 14:56:41 -04:00
|
|
|
float spaces = 5);
|
|
|
|
// sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
|
|
|
|
// between text and header and/or footer
|
|
|
|
|
2004-09-27 15:06:39 -04:00
|
|
|
// wxPrintout stuff:
|
2001-08-23 14:56:41 -04:00
|
|
|
bool OnPrintPage(int page);
|
|
|
|
bool HasPage(int page);
|
|
|
|
void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
|
|
|
|
bool OnBeginDocument(int startPage, int endPage);
|
2003-07-23 16:30:19 -04:00
|
|
|
void OnPreparePrinting();
|
2001-08-23 14:56:41 -04:00
|
|
|
|
2003-07-06 13:52:42 -04:00
|
|
|
// Adds input filter
|
|
|
|
static void AddFilter(wxHtmlFilter *filter);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
static void CleanUpStatics();
|
|
|
|
|
2001-08-23 14:56:41 -04:00
|
|
|
private:
|
2009-03-26 09:37:37 -04:00
|
|
|
// this function is called by the base class OnPreparePrinting()
|
|
|
|
// implementation and by default checks whether the document fits into
|
|
|
|
// pageArea horizontally and warns the user if it does not, giving him
|
|
|
|
// the possibility to cancel printing in this case
|
|
|
|
//
|
|
|
|
// you may override it to either suppress this check if truncation of the
|
|
|
|
// HTML being printed is acceptable or, on the contrary, add more checks to
|
|
|
|
// it, e.g. for the fit in the vertical direction if the document should
|
|
|
|
// always appear on a single page
|
|
|
|
//
|
|
|
|
// return true if printing should go ahead or false to cancel it
|
|
|
|
virtual bool CheckFit(const wxSize& pageArea, const wxSize& docArea) const;
|
2001-08-23 14:56:41 -04:00
|
|
|
|
|
|
|
void RenderPage(wxDC *dc, int page);
|
|
|
|
// renders one page into dc
|
|
|
|
wxString TranslateHeader(const wxString& instr, int page);
|
|
|
|
// substitute @PAGENUM@ and @PAGESCNT@ by real values
|
|
|
|
void CountPages();
|
|
|
|
// counts pages and fills m_NumPages and m_PageBreaks
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_NumPages;
|
2006-05-28 18:56:28 -04:00
|
|
|
//int m_PageBreaks[wxHTML_PRINT_MAX_PAGES];
|
|
|
|
wxArrayInt m_PageBreaks;
|
2001-08-23 14:56:41 -04:00
|
|
|
|
|
|
|
wxString m_Document, m_BasePath;
|
|
|
|
bool m_BasePathIsDir;
|
|
|
|
wxString m_Headers[2], m_Footers[2];
|
|
|
|
|
|
|
|
int m_HeaderHeight, m_FooterHeight;
|
|
|
|
wxHtmlDCRenderer *m_Renderer, *m_RendererHdr;
|
|
|
|
float m_MarginTop, m_MarginBottom, m_MarginLeft, m_MarginRight, m_MarginSpace;
|
2003-01-02 18:38:11 -05:00
|
|
|
|
2003-07-06 13:52:42 -04:00
|
|
|
// list of HTML filters
|
|
|
|
static wxList m_Filters;
|
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxHtmlPrintout);
|
1999-10-17 09:03:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
// wxHtmlEasyPrinting
|
2004-09-27 15:06:39 -04:00
|
|
|
// This class provides very simple interface to printing
|
1999-10-17 09:03:40 -04:00
|
|
|
// architecture. It allows you to print HTML documents only
|
2004-09-27 15:06:39 -04:00
|
|
|
// with very few commands.
|
1999-10-17 09:03:40 -04:00
|
|
|
//
|
|
|
|
// Note : do not create this class on stack only.
|
2004-09-27 15:06:39 -04:00
|
|
|
// You should create an instance on app startup and
|
1999-10-17 09:03:40 -04:00
|
|
|
// use this instance for all printing. Why? The class
|
|
|
|
// stores page&printer settings in it.
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
2003-07-04 09:04:05 -04:00
|
|
|
class WXDLLIMPEXP_HTML wxHtmlEasyPrinting : public wxObject
|
1999-10-17 09:03:40 -04:00
|
|
|
{
|
2001-08-23 14:56:41 -04:00
|
|
|
public:
|
2003-05-26 05:55:28 -04:00
|
|
|
wxHtmlEasyPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL);
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxHtmlEasyPrinting();
|
2001-08-23 14:56:41 -04:00
|
|
|
|
|
|
|
bool PreviewFile(const wxString &htmlfile);
|
|
|
|
bool PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
|
|
|
|
// Preview file / html-text for printing
|
|
|
|
// (and offers printing)
|
|
|
|
// basepath is base directory for opening subsequent files (e.g. from <img> tag)
|
|
|
|
|
|
|
|
bool PrintFile(const wxString &htmlfile);
|
|
|
|
bool PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
|
|
|
|
// Print file / html-text w/o preview
|
|
|
|
|
|
|
|
void PageSetup();
|
|
|
|
// pop up printer or page setup dialog
|
|
|
|
|
|
|
|
void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
|
|
|
|
void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
|
|
|
|
// sets header/footer for the document. The argument is interpreted as HTML document.
|
|
|
|
// You can use macros in it:
|
|
|
|
// @PAGENUM@ is replaced by page number
|
|
|
|
// @PAGESCNT@ is replaced by total number of pages
|
|
|
|
//
|
|
|
|
// pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
|
|
|
|
// You can set different header/footer for odd and even pages
|
|
|
|
|
2005-09-24 17:43:15 -04:00
|
|
|
void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = 0);
|
2003-03-16 15:30:26 -05:00
|
|
|
// Sets fonts to be used when displaying HTML page. (if size null then default sizes used)
|
|
|
|
|
2004-09-24 05:55:10 -04:00
|
|
|
// Sets font sizes to be relative to the given size or the system
|
|
|
|
// default size; use either specified or default font
|
|
|
|
void SetStandardFonts(int size = -1,
|
|
|
|
const wxString& normal_face = wxEmptyString,
|
|
|
|
const wxString& fixed_face = wxEmptyString);
|
2004-09-27 15:06:39 -04:00
|
|
|
|
2004-02-23 17:38:30 -05:00
|
|
|
wxPrintData *GetPrintData();
|
2001-08-23 14:56:41 -04:00
|
|
|
wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
|
2004-09-27 15:06:39 -04:00
|
|
|
// return page setting data objects.
|
2001-08-23 14:56:41 -04:00
|
|
|
// (You can set their parameters.)
|
|
|
|
|
2007-08-03 04:50:18 -04:00
|
|
|
wxWindow* GetParentWindow() const { return m_ParentWindow; }
|
|
|
|
// get the parent window
|
|
|
|
void SetParentWindow(wxWindow* window) { m_ParentWindow = window; }
|
|
|
|
// set the parent window
|
|
|
|
|
2003-05-12 18:33:51 -04:00
|
|
|
protected:
|
2001-08-23 14:56:41 -04:00
|
|
|
virtual wxHtmlPrintout *CreatePrintout();
|
|
|
|
virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2);
|
|
|
|
virtual bool DoPrint(wxHtmlPrintout *printout);
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxPrintData *m_PrintData;
|
|
|
|
wxPageSetupDialogData *m_PageSetupData;
|
|
|
|
wxString m_Name;
|
2003-03-16 15:30:26 -05:00
|
|
|
int m_FontsSizesArr[7];
|
|
|
|
int *m_FontsSizes;
|
|
|
|
wxString m_FontFaceFixed, m_FontFaceNormal;
|
2004-09-24 05:55:10 -04:00
|
|
|
|
|
|
|
enum FontMode
|
|
|
|
{
|
|
|
|
FontMode_Explicit,
|
|
|
|
FontMode_Standard
|
|
|
|
};
|
|
|
|
FontMode m_fontMode;
|
2004-09-27 15:06:39 -04:00
|
|
|
|
2001-08-23 14:56:41 -04:00
|
|
|
wxString m_Headers[2], m_Footers[2];
|
2003-05-26 05:55:28 -04:00
|
|
|
wxWindow *m_ParentWindow;
|
2003-01-02 18:38:11 -05:00
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting);
|
1999-10-17 09:03:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-10-18 11:14:52 -04:00
|
|
|
#endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
|
1999-10-17 09:03:40 -04:00
|
|
|
|
|
|
|
#endif // _WX_HTMPRINT_H_
|
|
|
|
|