1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextprint.h
3 // Purpose: Rich text printing classes
4 // Author: Julian Smart
6 // Copyright: (c) Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_RICHTEXTPRINT_H_
11 #define _WX_RICHTEXTPRINT_H_
15 #if wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
17 #include "wx/richtext/richtextbuffer.h"
20 #include "wx/printdlg.h"
22 #define wxRICHTEXT_PRINT_MAX_PAGES 99999
24 // Header/footer page identifiers
25 enum wxRichTextOddEvenPage
{
31 // Header/footer text locations
32 enum wxRichTextPageLocation
{
34 wxRICHTEXT_PAGE_CENTRE
,
42 class WXDLLIMPEXP_RICHTEXT wxRichTextHeaderFooterData
: public wxObject
45 wxRichTextHeaderFooterData() { Init(); }
46 wxRichTextHeaderFooterData(const wxRichTextHeaderFooterData
& data
): wxObject() { Copy(data
); }
49 void Init() { m_headerMargin
= 20; m_footerMargin
= 20; m_showOnFirstPage
= true; }
52 void Copy(const wxRichTextHeaderFooterData
& data
);
55 void operator= (const wxRichTextHeaderFooterData
& data
) { Copy(data
); }
57 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
58 void SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
59 wxString
GetHeaderText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
61 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
62 void SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
63 wxString
GetFooterText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
66 void SetText(const wxString
& text
, int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
);
67 wxString
GetText(int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const;
69 /// Set/get margins between text and header or footer, in tenths of a millimeter
70 void SetMargins(int headerMargin
, int footerMargin
) { m_headerMargin
= headerMargin
; m_footerMargin
= footerMargin
; }
71 int GetHeaderMargin() const { return m_headerMargin
; }
72 int GetFooterMargin() const { return m_footerMargin
; }
74 /// Set/get whether to show header or footer on first page
75 void SetShowOnFirstPage(bool showOnFirstPage
) { m_showOnFirstPage
= showOnFirstPage
; }
76 bool GetShowOnFirstPage() const { return m_showOnFirstPage
; }
82 void SetFont(const wxFont
& font
) { m_font
= font
; }
83 const wxFont
& GetFont() const { return m_font
; }
86 void SetTextColour(const wxColour
& col
) { m_colour
= col
; }
87 const wxColour
& GetTextColour() const { return m_colour
; }
89 DECLARE_CLASS(wxRichTextHeaderFooterData
)
93 // Strings for left, centre, right, top, bottom, odd, even
99 bool m_showOnFirstPage
;
106 class WXDLLIMPEXP_RICHTEXT wxRichTextPrintout
: public wxPrintout
109 wxRichTextPrintout(const wxString
& title
= _("Printout"));
110 virtual ~wxRichTextPrintout();
112 /// The buffer to print
113 void SetRichTextBuffer(wxRichTextBuffer
* buffer
) { m_richTextBuffer
= buffer
; }
114 wxRichTextBuffer
* GetRichTextBuffer() const { return m_richTextBuffer
; }
116 /// Set/get header/footer data
117 void SetHeaderFooterData(const wxRichTextHeaderFooterData
& data
) { m_headerFooterData
= data
; }
118 const wxRichTextHeaderFooterData
& GetHeaderFooterData() const { return m_headerFooterData
; }
120 /// Sets margins in 10ths of millimetre. Defaults to 1 inch for margins.
121 void SetMargins(int top
= 254, int bottom
= 254, int left
= 254, int right
= 254);
123 /// Calculate scaling and rectangles, setting the device context scaling
124 void CalculateScaling(wxDC
* dc
, wxRect
& textRect
, wxRect
& headerRect
, wxRect
& footerRect
);
126 // wxPrintout virtual functions
127 virtual bool OnPrintPage(int page
);
128 virtual bool HasPage(int page
);
129 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
);
130 virtual bool OnBeginDocument(int startPage
, int endPage
);
131 virtual void OnPreparePrinting();
135 /// Renders one page into dc
136 void RenderPage(wxDC
*dc
, int page
);
138 /// Substitute keywords
139 static bool SubstituteKeywords(wxString
& str
, const wxString
& title
, int pageNum
, int pageCount
);
143 wxRichTextBuffer
* m_richTextBuffer
;
145 wxArrayInt m_pageBreaksStart
;
146 wxArrayInt m_pageBreaksEnd
;
147 wxArrayInt m_pageYOffsets
;
148 int m_marginLeft
, m_marginTop
, m_marginRight
, m_marginBottom
;
150 wxRichTextHeaderFooterData m_headerFooterData
;
152 wxDECLARE_NO_COPY_CLASS(wxRichTextPrintout
);
156 *! wxRichTextPrinting
157 * A simple interface to perform wxRichTextBuffer printing.
160 class WXDLLIMPEXP_RICHTEXT wxRichTextPrinting
: public wxObject
163 wxRichTextPrinting(const wxString
& name
= _("Printing"), wxWindow
*parentWindow
= NULL
);
164 virtual ~wxRichTextPrinting();
166 /// Preview the file or buffer
167 #if wxUSE_FFILE && wxUSE_STREAMS
168 bool PreviewFile(const wxString
& richTextFile
);
170 bool PreviewBuffer(const wxRichTextBuffer
& buffer
);
172 /// Print the file or buffer
173 #if wxUSE_FFILE && wxUSE_STREAMS
174 bool PrintFile(const wxString
& richTextFile
, bool showPrintDialog
= true);
176 bool PrintBuffer(const wxRichTextBuffer
& buffer
, bool showPrintDialog
= true);
178 /// Shows page setup dialog
181 /// Set/get header/footer data
182 void SetHeaderFooterData(const wxRichTextHeaderFooterData
& data
) { m_headerFooterData
= data
; }
183 const wxRichTextHeaderFooterData
& GetHeaderFooterData() const { return m_headerFooterData
; }
185 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
186 void SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
187 wxString
GetHeaderText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
189 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
190 void SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
191 wxString
GetFooterText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
193 /// Show header/footer on first page, or not
194 void SetShowOnFirstPage(bool show
) { m_headerFooterData
.SetShowOnFirstPage(show
); }
197 void SetHeaderFooterFont(const wxFont
& font
) { m_headerFooterData
.SetFont(font
); }
200 void SetHeaderFooterTextColour(const wxColour
& font
) { m_headerFooterData
.SetTextColour(font
); }
202 /// Get print and page setup data
203 wxPrintData
*GetPrintData();
204 wxPageSetupDialogData
*GetPageSetupData() { return m_pageSetupData
; }
206 /// Set print and page setup data
207 void SetPrintData(const wxPrintData
& printData
);
208 void SetPageSetupData(const wxPageSetupDialogData
& pageSetupData
);
210 /// Set the rich text buffer pointer, deleting the existing object if present
211 void SetRichTextBufferPreview(wxRichTextBuffer
* buf
);
212 wxRichTextBuffer
* GetRichTextBufferPreview() const { return m_richTextBufferPreview
; }
214 void SetRichTextBufferPrinting(wxRichTextBuffer
* buf
);
215 wxRichTextBuffer
* GetRichTextBufferPrinting() const { return m_richTextBufferPrinting
; }
217 /// Set/get the parent window
218 void SetParentWindow(wxWindow
* parent
) { m_parentWindow
= parent
; }
219 wxWindow
* GetParentWindow() const { return m_parentWindow
; }
221 /// Set/get the title
222 void SetTitle(const wxString
& title
) { m_title
= title
; }
223 const wxString
& GetTitle() const { return m_title
; }
225 /// Set/get the preview rect
226 void SetPreviewRect(const wxRect
& rect
) { m_previewRect
= rect
; }
227 const wxRect
& GetPreviewRect() const { return m_previewRect
; }
230 virtual wxRichTextPrintout
*CreatePrintout();
231 virtual bool DoPreview(wxRichTextPrintout
*printout1
, wxRichTextPrintout
*printout2
);
232 virtual bool DoPrint(wxRichTextPrintout
*printout
, bool showPrintDialog
);
235 wxPrintData
* m_printData
;
236 wxPageSetupDialogData
* m_pageSetupData
;
238 wxRichTextHeaderFooterData m_headerFooterData
;
240 wxWindow
* m_parentWindow
;
241 wxRichTextBuffer
* m_richTextBufferPreview
;
242 wxRichTextBuffer
* m_richTextBufferPrinting
;
243 wxRect m_previewRect
;
245 wxDECLARE_NO_COPY_CLASS(wxRichTextPrinting
);
248 #endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
250 #endif // _WX_RICHTEXTPRINT_H_