1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextprint.h
3 // Purpose: Rich text printing classes
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_RICHTEXTPRINT_H_
12 #define _WX_RICHTEXTPRINT_H_
16 #if wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
18 #include "wx/richtext/richtextbuffer.h"
21 #include "wx/printdlg.h"
23 #define wxRICHTEXT_PRINT_MAX_PAGES 99999
25 // Header/footer page identifiers
26 enum wxRichTextOddEvenPage
{
32 // Header/footer text locations
33 enum wxRichTextPageLocation
{
35 wxRICHTEXT_PAGE_CENTRE
,
43 class WXDLLIMPEXP_RICHTEXT wxRichTextHeaderFooterData
: public wxObject
46 wxRichTextHeaderFooterData() { Init(); }
47 wxRichTextHeaderFooterData(const wxRichTextHeaderFooterData
& data
) { Copy(data
); }
50 void Init() { m_headerMargin
= 20; m_footerMargin
= 20; m_showOnFirstPage
= true; }
53 void Copy(const wxRichTextHeaderFooterData
& data
);
56 void operator= (const wxRichTextHeaderFooterData
& data
) { Copy(data
); }
58 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
59 void SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
60 wxString
GetHeaderText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
62 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
63 void SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
64 wxString
GetFooterText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
67 void SetText(const wxString
& text
, int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
);
68 wxString
GetText(int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const;
70 /// Set/get margins between text and header or footer, in tenths of a millimeter
71 void SetMargins(int headerMargin
, int footerMargin
) { m_headerMargin
= headerMargin
; m_footerMargin
= footerMargin
; }
72 int GetHeaderMargin() const { return m_headerMargin
; }
73 int GetFooterMargin() const { return m_footerMargin
; }
75 /// Set/get whether to show header or footer on first page
76 void SetShowOnFirstPage(bool showOnFirstPage
) { m_showOnFirstPage
= showOnFirstPage
; }
77 bool GetShowOnFirstPage() const { return m_showOnFirstPage
; }
83 void SetFont(const wxFont
& font
) { m_font
= font
; }
84 const wxFont
& GetFont() const { return m_font
; }
87 void SetTextColour(const wxColour
& col
) { m_colour
= col
; }
88 const wxColour
& GetTextColour() const { return m_colour
; }
90 DECLARE_CLASS(wxRichTextHeaderFooterData
)
94 // Strings for left, centre, right, top, bottom, odd, even
100 bool m_showOnFirstPage
;
107 class WXDLLIMPEXP_RICHTEXT wxRichTextPrintout
: public wxPrintout
110 wxRichTextPrintout(const wxString
& title
= wxT("Printout"));
111 virtual ~wxRichTextPrintout();
113 /// The buffer to print
114 void SetRichTextBuffer(wxRichTextBuffer
* buffer
) { m_richTextBuffer
= buffer
; }
115 wxRichTextBuffer
* GetRichTextBuffer() const { return m_richTextBuffer
; }
117 /// Set/get header/footer data
118 void SetHeaderFooterData(const wxRichTextHeaderFooterData
& data
) { m_headerFooterData
= data
; }
119 const wxRichTextHeaderFooterData
& GetHeaderFooterData() const { return m_headerFooterData
; }
121 /// Sets margins in 10ths of millimetre. Defaults to 1 inch for margins.
122 void SetMargins(int top
= 252, int bottom
= 252, int left
= 252, int right
= 252);
124 /// Calculate scaling and rectangles, setting the device context scaling
125 void CalculateScaling(wxDC
* dc
, wxRect
& textRect
, wxRect
& headerRect
, wxRect
& footerRect
);
127 // wxPrintout virtual functions
128 virtual bool OnPrintPage(int page
);
129 virtual bool HasPage(int page
);
130 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
);
131 virtual bool OnBeginDocument(int startPage
, int endPage
);
132 virtual void OnPreparePrinting();
136 /// Renders one page into dc
137 void RenderPage(wxDC
*dc
, int page
);
139 /// Substitute keywords
140 static bool SubstituteKeywords(wxString
& str
, const wxString
& title
, int pageNum
, int pageCount
);
144 wxRichTextBuffer
* m_richTextBuffer
;
146 wxArrayInt m_pageBreaksStart
;
147 wxArrayInt m_pageBreaksEnd
;
148 int m_marginLeft
, m_marginTop
, m_marginRight
, m_marginBottom
;
150 wxRichTextHeaderFooterData m_headerFooterData
;
152 DECLARE_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
= wxT("Printing"), wxWindow
*parentWindow
= NULL
);
164 virtual ~wxRichTextPrinting();
166 /// Preview the file or buffer
167 bool PreviewFile(const wxString
& richTextFile
);
168 bool PreviewBuffer(const wxRichTextBuffer
& buffer
);
170 /// Print the file or buffer
171 bool PrintFile(const wxString
& richTextFile
);
172 bool PrintBuffer(const wxRichTextBuffer
& buffer
);
174 /// Shows page setup dialog
177 /// Set/get header/footer data
178 void SetHeaderFooterData(const wxRichTextHeaderFooterData
& data
) { m_headerFooterData
= data
; }
179 const wxRichTextHeaderFooterData
& GetHeaderFooterData() const { return m_headerFooterData
; }
181 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
182 void SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
183 wxString
GetHeaderText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
185 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
186 void SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_ALL
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
);
187 wxString
GetFooterText(wxRichTextOddEvenPage page
= wxRICHTEXT_PAGE_EVEN
, wxRichTextPageLocation location
= wxRICHTEXT_PAGE_CENTRE
) const;
189 /// Show header/footer on first page, or not
190 void SetShowOnFirstPage(bool show
) { m_headerFooterData
.SetShowOnFirstPage(show
); }
193 void SetHeaderFooterFont(const wxFont
& font
) { m_headerFooterData
.SetFont(font
); }
196 void SetHeaderFooterTextColour(const wxColour
& font
) { m_headerFooterData
.SetTextColour(font
); }
198 /// Get print and page setup data
199 wxPrintData
*GetPrintData();
200 wxPageSetupDialogData
*GetPageSetupData() { return m_pageSetupData
; }
202 /// Set the rich text buffer pointer, deleting the existing object if present
203 void SetRichTextBufferPreview(wxRichTextBuffer
* buf
);
204 wxRichTextBuffer
* GetRichTextBufferPreview() const { return m_richTextBufferPreview
; }
206 void SetRichTextBufferPrinting(wxRichTextBuffer
* buf
);
207 wxRichTextBuffer
* GetRichTextBufferPrinting() const { return m_richTextBufferPrinting
; }
209 /// Set/get the parent window
210 void SetParentWindow(wxWindow
* parent
) { m_parentWindow
= parent
; }
211 wxWindow
* GetParentWindow() const { return m_parentWindow
; }
213 /// Set/get the title
214 void SetTitle(const wxString
& title
) { m_title
= title
; }
215 const wxString
& GetTitle() const { return m_title
; }
217 /// Set/get the preview rect
218 void SetPreviewRect(const wxRect
& rect
) { m_previewRect
= rect
; }
219 const wxRect
& GetPreviewRect() const { return m_previewRect
; }
222 virtual wxRichTextPrintout
*CreatePrintout();
223 virtual bool DoPreview(wxRichTextPrintout
*printout1
, wxRichTextPrintout
*printout2
);
224 virtual bool DoPrint(wxRichTextPrintout
*printout
);
227 wxPrintData
* m_printData
;
228 wxPageSetupDialogData
* m_pageSetupData
;
230 wxRichTextHeaderFooterData m_headerFooterData
;
232 wxWindow
* m_parentWindow
;
233 wxRichTextBuffer
* m_richTextBufferPreview
;
234 wxRichTextBuffer
* m_richTextBufferPrinting
;
235 wxRect m_previewRect
;
237 DECLARE_NO_COPY_CLASS(wxRichTextPrinting
)
240 #endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
242 #endif // _WX_RICHTEXTPRINT_H_