]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/richtext/richtextprint.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / richtext / richtextprint.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/richtext/richtextprint.h
3// Purpose: Rich text printing classes
4// Author: Julian Smart
5// Created: 2006-10-23
6// Copyright: (c) Julian Smart
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_RICHTEXTPRINT_H_
11#define _WX_RICHTEXTPRINT_H_
12
13#include "wx/defs.h"
14
15#if wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
16
17#include "wx/richtext/richtextbuffer.h"
18
19#include "wx/print.h"
20#include "wx/printdlg.h"
21
22#define wxRICHTEXT_PRINT_MAX_PAGES 99999
23
24// Header/footer page identifiers
25enum wxRichTextOddEvenPage {
26 wxRICHTEXT_PAGE_ODD,
27 wxRICHTEXT_PAGE_EVEN,
28 wxRICHTEXT_PAGE_ALL
29};
30
31// Header/footer text locations
32enum wxRichTextPageLocation {
33 wxRICHTEXT_PAGE_LEFT,
34 wxRICHTEXT_PAGE_CENTRE,
35 wxRICHTEXT_PAGE_RIGHT
36};
37
38/*!
39 * Header/footer data
40 */
41
42class WXDLLIMPEXP_RICHTEXT wxRichTextHeaderFooterData: public wxObject
43{
44public:
45 wxRichTextHeaderFooterData() { Init(); }
46 wxRichTextHeaderFooterData(const wxRichTextHeaderFooterData& data): wxObject() { Copy(data); }
47
48 /// Initialise
49 void Init() { m_headerMargin = 20; m_footerMargin = 20; m_showOnFirstPage = true; }
50
51 /// Copy
52 void Copy(const wxRichTextHeaderFooterData& data);
53
54 /// Assignment
55 void operator= (const wxRichTextHeaderFooterData& data) { Copy(data); }
56
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;
60
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;
64
65 /// Set/get text
66 void SetText(const wxString& text, int headerFooter, wxRichTextOddEvenPage page, wxRichTextPageLocation location);
67 wxString GetText(int headerFooter, wxRichTextOddEvenPage page, wxRichTextPageLocation location) const;
68
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; }
73
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; }
77
78 /// Clear all text
79 void Clear();
80
81 /// Set/get font
82 void SetFont(const wxFont& font) { m_font = font; }
83 const wxFont& GetFont() const { return m_font; }
84
85 /// Set/get colour
86 void SetTextColour(const wxColour& col) { m_colour = col; }
87 const wxColour& GetTextColour() const { return m_colour; }
88
89 DECLARE_CLASS(wxRichTextHeaderFooterData)
90
91private:
92
93 // Strings for left, centre, right, top, bottom, odd, even
94 wxString m_text[12];
95 wxFont m_font;
96 wxColour m_colour;
97 int m_headerMargin;
98 int m_footerMargin;
99 bool m_showOnFirstPage;
100};
101
102/*!
103 * wxRichTextPrintout
104 */
105
106class WXDLLIMPEXP_RICHTEXT wxRichTextPrintout : public wxPrintout
107{
108public:
109 wxRichTextPrintout(const wxString& title = _("Printout"));
110 virtual ~wxRichTextPrintout();
111
112 /// The buffer to print
113 void SetRichTextBuffer(wxRichTextBuffer* buffer) { m_richTextBuffer = buffer; }
114 wxRichTextBuffer* GetRichTextBuffer() const { return m_richTextBuffer; }
115
116 /// Set/get header/footer data
117 void SetHeaderFooterData(const wxRichTextHeaderFooterData& data) { m_headerFooterData = data; }
118 const wxRichTextHeaderFooterData& GetHeaderFooterData() const { return m_headerFooterData; }
119
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);
122
123 /// Calculate scaling and rectangles, setting the device context scaling
124 void CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& headerRect, wxRect& footerRect);
125
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();
132
133private:
134
135 /// Renders one page into dc
136 void RenderPage(wxDC *dc, int page);
137
138 /// Substitute keywords
139 static bool SubstituteKeywords(wxString& str, const wxString& title, int pageNum, int pageCount);
140
141private:
142
143 wxRichTextBuffer* m_richTextBuffer;
144 int m_numPages;
145 wxArrayInt m_pageBreaksStart;
146 wxArrayInt m_pageBreaksEnd;
147 wxArrayInt m_pageYOffsets;
148 int m_marginLeft, m_marginTop, m_marginRight, m_marginBottom;
149
150 wxRichTextHeaderFooterData m_headerFooterData;
151
152 wxDECLARE_NO_COPY_CLASS(wxRichTextPrintout);
153};
154
155/*
156 *! wxRichTextPrinting
157 * A simple interface to perform wxRichTextBuffer printing.
158 */
159
160class WXDLLIMPEXP_RICHTEXT wxRichTextPrinting : public wxObject
161{
162public:
163 wxRichTextPrinting(const wxString& name = _("Printing"), wxWindow *parentWindow = NULL);
164 virtual ~wxRichTextPrinting();
165
166 /// Preview the file or buffer
167#if wxUSE_FFILE && wxUSE_STREAMS
168 bool PreviewFile(const wxString& richTextFile);
169#endif
170 bool PreviewBuffer(const wxRichTextBuffer& buffer);
171
172 /// Print the file or buffer
173#if wxUSE_FFILE && wxUSE_STREAMS
174 bool PrintFile(const wxString& richTextFile, bool showPrintDialog = true);
175#endif
176 bool PrintBuffer(const wxRichTextBuffer& buffer, bool showPrintDialog = true);
177
178 /// Shows page setup dialog
179 void PageSetup();
180
181 /// Set/get header/footer data
182 void SetHeaderFooterData(const wxRichTextHeaderFooterData& data) { m_headerFooterData = data; }
183 const wxRichTextHeaderFooterData& GetHeaderFooterData() const { return m_headerFooterData; }
184
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;
188
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;
192
193 /// Show header/footer on first page, or not
194 void SetShowOnFirstPage(bool show) { m_headerFooterData.SetShowOnFirstPage(show); }
195
196 /// Set the font
197 void SetHeaderFooterFont(const wxFont& font) { m_headerFooterData.SetFont(font); }
198
199 /// Set the colour
200 void SetHeaderFooterTextColour(const wxColour& font) { m_headerFooterData.SetTextColour(font); }
201
202 /// Get print and page setup data
203 wxPrintData *GetPrintData();
204 wxPageSetupDialogData *GetPageSetupData() { return m_pageSetupData; }
205
206 /// Set print and page setup data
207 void SetPrintData(const wxPrintData& printData);
208 void SetPageSetupData(const wxPageSetupDialogData& pageSetupData);
209
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; }
213
214 void SetRichTextBufferPrinting(wxRichTextBuffer* buf);
215 wxRichTextBuffer* GetRichTextBufferPrinting() const { return m_richTextBufferPrinting; }
216
217 /// Set/get the parent window
218 void SetParentWindow(wxWindow* parent) { m_parentWindow = parent; }
219 wxWindow* GetParentWindow() const { return m_parentWindow; }
220
221 /// Set/get the title
222 void SetTitle(const wxString& title) { m_title = title; }
223 const wxString& GetTitle() const { return m_title; }
224
225 /// Set/get the preview rect
226 void SetPreviewRect(const wxRect& rect) { m_previewRect = rect; }
227 const wxRect& GetPreviewRect() const { return m_previewRect; }
228
229protected:
230 virtual wxRichTextPrintout *CreatePrintout();
231 virtual bool DoPreview(wxRichTextPrintout *printout1, wxRichTextPrintout *printout2);
232 virtual bool DoPrint(wxRichTextPrintout *printout, bool showPrintDialog);
233
234private:
235 wxPrintData* m_printData;
236 wxPageSetupDialogData* m_pageSetupData;
237
238 wxRichTextHeaderFooterData m_headerFooterData;
239 wxString m_title;
240 wxWindow* m_parentWindow;
241 wxRichTextBuffer* m_richTextBufferPreview;
242 wxRichTextBuffer* m_richTextBufferPrinting;
243 wxRect m_previewRect;
244
245 wxDECLARE_NO_COPY_CLASS(wxRichTextPrinting);
246};
247
248#endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE
249
250#endif // _WX_RICHTEXTPRINT_H_
251