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