Return type change
[wxWidgets.git] / include / wx / richtext / richtextformatdlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextformatdlg.h
3 // Purpose: Formatting dialog for wxRichTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2006-10-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_RICHTEXTFORMATDLG_H_
13 #define _WX_RICHTEXTFORMATDLG_H_
14
15 /*!
16 * Includes
17 */
18
19 #include "wx/defs.h"
20
21 #if wxUSE_RICHTEXT
22
23 #include "wx/propdlg.h"
24 #include "wx/bookctrl.h"
25
26 #if wxUSE_HTML
27 #include "wx/htmllbox.h"
28 #endif
29
30 #include "wx/richtext/richtextbuffer.h"
31 #include "wx/richtext/richtextstyles.h"
32
33 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog;
34 class WXDLLIMPEXP_CORE wxImageList;
35
36 /*!
37 * Flags determining the pages to be created in the dialog
38 */
39
40 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
41 #define wxRICHTEXT_FORMAT_FONT 0x0002
42 #define wxRICHTEXT_FORMAT_TABS 0x0004
43 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
44 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
45
46 /*!
47 * Shorthand for common combinations of pages
48 */
49
50 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
51 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
52 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
53
54 /*!
55 * Factory for formatting dialog
56 */
57
58 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory: public wxObject
59 {
60 public:
61 wxRichTextFormattingDialogFactory() {}
62 virtual ~wxRichTextFormattingDialogFactory() {}
63
64 // Overrideables
65
66 /// Create all pages, under the dialog's book control, also calling AddPage
67 virtual bool CreatePages(long pages, wxRichTextFormattingDialog* dialog);
68
69 /// Create a page, given a page identifier
70 virtual wxPanel* CreatePage(int page, wxString& title, wxRichTextFormattingDialog* dialog);
71
72 /// Enumerate all available page identifiers
73 virtual int GetPageId(int i) const;
74
75 /// Get the number of available page identifiers
76 virtual int GetPageIdCount() const;
77
78 /// Get the image index for the given page identifier
79 virtual int GetPageImage(int WXUNUSED(id)) const { return -1; }
80
81 /// Invoke help for the dialog
82 virtual bool ShowHelp(int WXUNUSED(page), wxRichTextFormattingDialog* WXUNUSED(dialog)) { return false; }
83
84 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
85 virtual bool SetSheetStyle(wxRichTextFormattingDialog* dialog);
86
87 /// Create the main dialog buttons
88 virtual bool CreateButtons(wxRichTextFormattingDialog* dialog);
89 };
90
91 /*!
92 * Formatting dialog for a wxRichTextCtrl
93 */
94
95 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog: public wxPropertySheetDialog
96 {
97 DECLARE_CLASS(wxRichTextFormattingDialog)
98 public:
99 wxRichTextFormattingDialog() { Init(); }
100
101 wxRichTextFormattingDialog(long flags, wxWindow* parent, const wxString& title = _("Formatting"), wxWindowID id = wxID_ANY,
102 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
103 long style = wxDEFAULT_DIALOG_STYLE)
104 {
105 Init();
106 Create(flags, parent, title, id, pos, sz, style);
107 }
108
109 ~wxRichTextFormattingDialog();
110
111 void Init();
112
113 bool Create(long flags, wxWindow* parent, const wxString& title, wxWindowID id,
114 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
115 long style = wxDEFAULT_DIALOG_STYLE);
116
117 /// Get attributes from the given range
118 virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range);
119
120 /// Set the attributes and optionally update the display
121 virtual bool SetStyle(const wxTextAttrEx& style, bool update = true);
122
123 /// Set the style definition and optionally update the display
124 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef, wxRichTextStyleSheet* sheet, bool update = true);
125
126 /// Get the style definition, if any
127 virtual wxRichTextStyleDefinition* GetStyleDefinition() const { return m_styleDefinition; }
128
129 /// Get the style sheet, if any
130 virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
131
132 /// Update the display
133 virtual bool UpdateDisplay();
134
135 /// Apply attributes to the given range
136 virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE);
137
138 /// Gets and sets the attributes
139 const wxTextAttrEx& GetAttributes() const { return m_attributes; }
140 wxTextAttrEx& GetAttributes() { return m_attributes; }
141 void SetAttributes(const wxTextAttrEx& attr) { m_attributes = attr; }
142
143 /// Transfers the data and from to the window
144 virtual bool TransferDataToWindow();
145 virtual bool TransferDataFromWindow();
146
147 /// Apply the styles when a different tab is selected, so the previews are
148 /// up to date
149 void OnTabChanged(wxBookCtrlEvent& event);
150
151 /// Respond to help command
152 void OnHelp(wxCommandEvent& event);
153
154 /// Set/get image list
155 void SetImageList(wxImageList* imageList) { m_imageList = imageList; }
156 wxImageList* GetImageList() const { return m_imageList; }
157
158 /// Get/set formatting factory object
159 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory);
160 static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory() { return ms_FormattingDialogFactory; }
161
162 /// Helper for pages to get the top-level dialog
163 static wxRichTextFormattingDialog* GetDialog(wxWindow* win);
164
165 /// Helper for pages to get the attributes
166 static wxTextAttrEx* GetDialogAttributes(wxWindow* win);
167
168 /// Helper for pages to get the style
169 static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win);
170
171 /// Map book control page index to our page id
172 void AddPageId(int id) { m_pageIds.Add(id); }
173
174 protected:
175
176 wxImageList* m_imageList;
177 wxTextAttrEx m_attributes;
178 wxRichTextStyleDefinition* m_styleDefinition;
179 wxRichTextStyleSheet* m_styleSheet;
180 wxArrayInt m_pageIds; // mapping of book control indexes to page ids
181
182 static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory;
183
184 DECLARE_EVENT_TABLE()
185 };
186
187 //-----------------------------------------------------------------------------
188 // helper class - wxRichTextFontPreviewCtrl
189 //-----------------------------------------------------------------------------
190
191 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl : public wxWindow
192 {
193 public:
194 wxRichTextFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0) :
195 wxWindow(parent, id, pos, sz, style)
196 {
197 SetBackgroundColour(*wxWHITE);
198 }
199
200 private:
201 void OnPaint(wxPaintEvent& event);
202 DECLARE_EVENT_TABLE()
203 };
204
205 /*
206 * A control for displaying a small preview of a colour or bitmap
207 */
208
209 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl: public wxControl
210 {
211 DECLARE_CLASS(wxRichTextColourSwatchCtrl)
212 public:
213 wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
214 ~wxRichTextColourSwatchCtrl();
215
216 void OnMouseEvent(wxMouseEvent& event);
217
218 void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
219
220 wxColour& GetColour() { return m_colour; }
221
222 virtual wxSize DoGetBestSize() const { return GetSize(); }
223
224 protected:
225 wxColour m_colour;
226
227 DECLARE_EVENT_TABLE()
228 };
229
230 /*!
231 * wxRichTextFontListBox class declaration
232 * A listbox to display fonts.
233 */
234
235 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox: public wxHtmlListBox
236 {
237 DECLARE_CLASS(wxRichTextFontListBox)
238 DECLARE_EVENT_TABLE()
239
240 public:
241 wxRichTextFontListBox()
242 {
243 Init();
244 }
245 wxRichTextFontListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
246 const wxSize& size = wxDefaultSize, long style = 0);
247 virtual ~wxRichTextFontListBox();
248
249 void Init()
250 {
251 }
252
253 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
254 const wxSize& size = wxDefaultSize, long style = 0);
255
256 /// Creates a suitable HTML fragment for a font
257 wxString CreateHTML(const wxString& facename) const;
258
259 /// Get font name for index
260 wxString GetFaceName(size_t i) const ;
261
262 /// Set selection for string, returning the index.
263 int SetFaceNameSelection(const wxString& name);
264
265 /// Updates the font list
266 void UpdateFonts();
267
268 /// Does this face name exist?
269 bool HasFaceName(const wxString& faceName) const { return m_faceNames.Index(faceName) != wxNOT_FOUND; }
270
271 /// Returns the array of face names
272 const wxArrayString& GetFaceNames() const { return m_faceNames; }
273
274 protected:
275 /// Returns the HTML for this item
276 virtual wxString OnGetItem(size_t n) const;
277
278 private:
279
280 wxArrayString m_faceNames;
281 };
282
283 #endif
284 // wxUSE_RICHTEXT
285
286 #endif
287 // _WX_RICHTEXTFORMATDLG_H_