]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/richtext/richtextformatdlg.h
Use CreateButtonSizer in wxAboutBox() to make OK button look native.
[wxWidgets.git] / include / wx / richtext / richtextformatdlg.h
... / ...
CommitLineData
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;
33class WXDLLIMPEXP_CORE wxImageList;
34
35/*!
36 * Flags determining the pages to be created in the dialog
37 */
38
39#define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
40#define wxRICHTEXT_FORMAT_FONT 0x0002
41#define wxRICHTEXT_FORMAT_TABS 0x0004
42#define wxRICHTEXT_FORMAT_BULLETS 0x0008
43#define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
44
45/*!
46 * Shorthand for common combinations of pages
47 */
48
49#define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
50#define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
51#define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
52
53/*!
54 * Factory for formatting dialog
55 */
56
57class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory: public wxObject
58{
59public:
60 wxRichTextFormattingDialogFactory() {}
61 virtual ~wxRichTextFormattingDialogFactory() {}
62
63// Overrideables
64
65 /// Create all pages, under the dialog's book control, also calling AddPage
66 virtual bool CreatePages(long pages, wxRichTextFormattingDialog* dialog);
67
68 /// Create a page, given a page identifier
69 virtual wxPanel* CreatePage(int page, wxString& title, wxRichTextFormattingDialog* dialog);
70
71 /// Enumerate all available page identifiers
72 virtual int GetPageId(int i) const;
73
74 /// Get the number of available page identifiers
75 virtual int GetPageIdCount() const;
76
77 /// Get the image index for the given page identifier
78 virtual int GetPageImage(int WXUNUSED(id)) const { return -1; }
79
80 /// Invoke help for the dialog
81 virtual bool ShowHelp(int WXUNUSED(page), wxRichTextFormattingDialog* WXUNUSED(dialog)) { return false; }
82
83 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
84 virtual bool SetSheetStyle(wxRichTextFormattingDialog* dialog);
85
86 /// Create the main dialog buttons
87 virtual bool CreateButtons(wxRichTextFormattingDialog* dialog);
88};
89
90/*!
91 * Formatting dialog for a wxRichTextCtrl
92 */
93
94class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog: public wxPropertySheetDialog
95{
96DECLARE_CLASS(wxRichTextFormattingDialog)
97public:
98 wxRichTextFormattingDialog() { Init(); }
99
100 wxRichTextFormattingDialog(long flags, wxWindow* parent, const wxString& title = _("Formatting"), wxWindowID id = wxID_ANY,
101 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
102 long style = wxDEFAULT_DIALOG_STYLE)
103 {
104 Init();
105 Create(flags, parent, title, id, pos, sz, style);
106 }
107
108 ~wxRichTextFormattingDialog();
109
110 void Init();
111
112 bool Create(long flags, wxWindow* parent, const wxString& title, wxWindowID id,
113 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
114 long style = wxDEFAULT_DIALOG_STYLE);
115
116 /// Get attributes from the given range
117 virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range);
118
119 /// Set the attributes and optionally update the display
120 virtual bool SetStyle(const wxTextAttrEx& style, bool update = true);
121
122 /// Set the style definition and optionally update the display
123 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef, wxRichTextStyleSheet* sheet, bool update = true);
124
125 /// Get the style definition, if any
126 virtual wxRichTextStyleDefinition* GetStyleDefinition() const { return m_styleDefinition; }
127
128 /// Get the style sheet, if any
129 virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
130
131 /// Update the display
132 virtual bool UpdateDisplay();
133
134 /// Apply attributes to the given range
135 virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE);
136
137 /// Gets and sets the attributes
138 const wxTextAttrEx& GetAttributes() const { return m_attributes; }
139 wxTextAttrEx& GetAttributes() { return m_attributes; }
140 void SetAttributes(const wxTextAttrEx& attr) { m_attributes = attr; }
141
142 /// Transfers the data and from to the window
143 virtual bool TransferDataToWindow();
144 virtual bool TransferDataFromWindow();
145
146 /// Apply the styles when a different tab is selected, so the previews are
147 /// up to date
148 void OnTabChanged(wxNotebookEvent& event);
149
150 /// Set/get image list
151 void SetImageList(wxImageList* imageList) { m_imageList = imageList; }
152 wxImageList* GetImageList() const { return m_imageList; }
153
154 /// Get/set formatting factory object
155 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory);
156 static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory() { return ms_FormattingDialogFactory; }
157
158 /// Helper for pages to get the top-level dialog
159 static wxRichTextFormattingDialog* GetDialog(wxWindow* win);
160
161 /// Helper for pages to get the attributes
162 static wxTextAttrEx* GetDialogAttributes(wxWindow* win);
163
164 /// Helper for pages to get the style
165 static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win);
166
167protected:
168
169 wxImageList* m_imageList;
170 wxTextAttrEx m_attributes;
171 wxRichTextStyleDefinition* m_styleDefinition;
172 wxRichTextStyleSheet* m_styleSheet;
173
174 static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory;
175
176DECLARE_EVENT_TABLE()
177};
178
179//-----------------------------------------------------------------------------
180// helper class - wxRichTextFontPreviewCtrl
181//-----------------------------------------------------------------------------
182
183class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl : public wxWindow
184{
185public:
186 wxRichTextFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0) :
187 wxWindow(parent, id, pos, sz, style)
188 {
189 SetBackgroundColour(*wxWHITE);
190 }
191
192private:
193 void OnPaint(wxPaintEvent& event);
194 DECLARE_EVENT_TABLE()
195};
196
197/*
198 * A control for displaying a small preview of a colour or bitmap
199 */
200
201class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl: public wxControl
202{
203 DECLARE_CLASS(wxRichTextColourSwatchCtrl)
204public:
205 wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
206 ~wxRichTextColourSwatchCtrl();
207
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_