]> git.saurik.com Git - wxWidgets.git/blame - include/wx/richtext/richtextformatdlg.h
Added some missing newlines to ends of files (necessary for linear RTF)
[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"
2b741a39
WS
24#include "wx/bookctrl.h"
25
97ff49b3
JS
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
97ff49b3 33class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog;
38b13085 34class WXDLLIMPEXP_CORE wxImageList;
97ff49b3
JS
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
58class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory: public wxObject
59{
60public:
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
95class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog: public wxPropertySheetDialog
96{
97DECLARE_CLASS(wxRichTextFormattingDialog)
98public:
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
2b741a39 149 void OnTabChanged(wxBookCtrlEvent& event);
97ff49b3
JS
150
151 /// Set/get image list
152 void SetImageList(wxImageList* imageList) { m_imageList = imageList; }
153 wxImageList* GetImageList() const { return m_imageList; }
154
155 /// Get/set formatting factory object
156 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory);
157 static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory() { return ms_FormattingDialogFactory; }
158
159 /// Helper for pages to get the top-level dialog
160 static wxRichTextFormattingDialog* GetDialog(wxWindow* win);
161
162 /// Helper for pages to get the attributes
163 static wxTextAttrEx* GetDialogAttributes(wxWindow* win);
164
165 /// Helper for pages to get the style
166 static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win);
167
168protected:
169
170 wxImageList* m_imageList;
171 wxTextAttrEx m_attributes;
172 wxRichTextStyleDefinition* m_styleDefinition;
173 wxRichTextStyleSheet* m_styleSheet;
174
175 static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory;
176
177DECLARE_EVENT_TABLE()
178};
179
180//-----------------------------------------------------------------------------
181// helper class - wxRichTextFontPreviewCtrl
182//-----------------------------------------------------------------------------
183
184class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl : public wxWindow
185{
186public:
187 wxRichTextFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0) :
188 wxWindow(parent, id, pos, sz, style)
189 {
190 SetBackgroundColour(*wxWHITE);
191 }
192
193private:
194 void OnPaint(wxPaintEvent& event);
195 DECLARE_EVENT_TABLE()
196};
197
198/*
199 * A control for displaying a small preview of a colour or bitmap
200 */
201
202class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl: public wxControl
203{
204 DECLARE_CLASS(wxRichTextColourSwatchCtrl)
205public:
206 wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
207 ~wxRichTextColourSwatchCtrl();
208
97ff49b3
JS
209 void OnMouseEvent(wxMouseEvent& event);
210
211 void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
212
213 wxColour& GetColour() { return m_colour; }
214
215 virtual wxSize DoGetBestSize() const { return GetSize(); }
216
217protected:
218 wxColour m_colour;
219
220DECLARE_EVENT_TABLE()
221};
222
223/*!
224 * wxRichTextFontListBox class declaration
225 * A listbox to display fonts.
226 */
227
228class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox: public wxHtmlListBox
229{
230 DECLARE_CLASS(wxRichTextFontListBox)
231 DECLARE_EVENT_TABLE()
232
233public:
234 wxRichTextFontListBox()
235 {
236 Init();
237 }
238 wxRichTextFontListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
239 const wxSize& size = wxDefaultSize, long style = 0);
240 virtual ~wxRichTextFontListBox();
241
242 void Init()
243 {
244 }
245
246 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
247 const wxSize& size = wxDefaultSize, long style = 0);
248
249 /// Creates a suitable HTML fragment for a font
250 wxString CreateHTML(const wxString& facename) const;
251
252 /// Get font name for index
253 wxString GetFaceName(size_t i) const ;
254
255 /// Set selection for string, returning the index.
256 int SetFaceNameSelection(const wxString& name);
257
258 /// Updates the font list
259 void UpdateFonts();
260
261 /// Does this face name exist?
262 bool HasFaceName(const wxString& faceName) const { return m_faceNames.Index(faceName) != wxNOT_FOUND; }
263
264 /// Returns the array of face names
265 const wxArrayString& GetFaceNames() const { return m_faceNames; }
266
267protected:
268 /// Returns the HTML for this item
269 virtual wxString OnGetItem(size_t n) const;
270
271private:
272
273 wxArrayString m_faceNames;
274};
275
276#endif
277 // wxUSE_RICHTEXT
278
279#endif
280 // _WX_RICHTEXTFORMATDLG_H_