]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextformatdlg.h
Work around the fact that wxWebViewIE doesn't send page changing and page changed...
[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 #include "wx/withimages.h"
26
27 #if wxUSE_HTML
28 #include "wx/htmllbox.h"
29 #endif
30
31 #include "wx/richtext/richtextbuffer.h"
32 #include "wx/richtext/richtextstyles.h"
33 #include "wx/richtext/richtextuicustomization.h"
34
35 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFormattingDialog;
36 class WXDLLIMPEXP_FWD_CORE wxComboBox;
37 class WXDLLIMPEXP_FWD_CORE wxCheckBox;
38
39 /*!
40 * Flags determining the pages and buttons to be created in the dialog
41 */
42
43 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
44 #define wxRICHTEXT_FORMAT_FONT 0x0002
45 #define wxRICHTEXT_FORMAT_TABS 0x0004
46 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
47 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
48 #define wxRICHTEXT_FORMAT_LIST_STYLE 0x0020
49 #define wxRICHTEXT_FORMAT_MARGINS 0x0040
50 #define wxRICHTEXT_FORMAT_SIZE 0x0080
51 #define wxRICHTEXT_FORMAT_BORDERS 0x0100
52 #define wxRICHTEXT_FORMAT_BACKGROUND 0x0200
53
54 #define wxRICHTEXT_FORMAT_HELP_BUTTON 0x1000
55
56 /*!
57 * Indices for bullet styles in list control
58 */
59
60 enum {
61 wxRICHTEXT_BULLETINDEX_NONE = 0,
62 wxRICHTEXT_BULLETINDEX_ARABIC,
63 wxRICHTEXT_BULLETINDEX_UPPER_CASE,
64 wxRICHTEXT_BULLETINDEX_LOWER_CASE,
65 wxRICHTEXT_BULLETINDEX_UPPER_CASE_ROMAN,
66 wxRICHTEXT_BULLETINDEX_LOWER_CASE_ROMAN,
67 wxRICHTEXT_BULLETINDEX_OUTLINE,
68 wxRICHTEXT_BULLETINDEX_SYMBOL,
69 wxRICHTEXT_BULLETINDEX_BITMAP,
70 wxRICHTEXT_BULLETINDEX_STANDARD
71 };
72
73 /*!
74 * Shorthand for common combinations of pages
75 */
76
77 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
78 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
79 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
80
81 /*!
82 * Factory for formatting dialog
83 */
84
85 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory: public wxObject
86 {
87 public:
88 wxRichTextFormattingDialogFactory() {}
89 virtual ~wxRichTextFormattingDialogFactory() {}
90
91 // Overridables
92
93 /// Create all pages, under the dialog's book control, also calling AddPage
94 virtual bool CreatePages(long pages, wxRichTextFormattingDialog* dialog);
95
96 /// Create a page, given a page identifier
97 virtual wxPanel* CreatePage(int page, wxString& title, wxRichTextFormattingDialog* dialog);
98
99 /// Enumerate all available page identifiers
100 virtual int GetPageId(int i) const;
101
102 /// Get the number of available page identifiers
103 virtual int GetPageIdCount() const;
104
105 /// Get the image index for the given page identifier
106 virtual int GetPageImage(int WXUNUSED(id)) const { return -1; }
107
108 /// Invoke help for the dialog
109 virtual bool ShowHelp(int page, wxRichTextFormattingDialog* dialog);
110
111 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
112 virtual bool SetSheetStyle(wxRichTextFormattingDialog* dialog);
113
114 /// Create the main dialog buttons
115 virtual bool CreateButtons(wxRichTextFormattingDialog* dialog);
116 };
117
118 /*!
119 * Formatting dialog for a wxRichTextCtrl
120 */
121
122 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog: public wxPropertySheetDialog,
123 public wxWithImages
124 {
125 DECLARE_CLASS(wxRichTextFormattingDialog)
126 DECLARE_HELP_PROVISION()
127
128 public:
129 wxRichTextFormattingDialog() { Init(); }
130
131 wxRichTextFormattingDialog(long flags, wxWindow* parent, const wxString& title = wxGetTranslation(wxT("Formatting")), wxWindowID id = wxID_ANY,
132 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
133 long style = wxDEFAULT_DIALOG_STYLE)
134 {
135 Init();
136 Create(flags, parent, title, id, pos, sz, style);
137 }
138
139 ~wxRichTextFormattingDialog();
140
141 void Init();
142
143 bool Create(long flags, wxWindow* parent, const wxString& title = wxGetTranslation(wxT("Formatting")), wxWindowID id = wxID_ANY,
144 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
145 long style = wxDEFAULT_DIALOG_STYLE);
146
147 /// Get attributes from the given range
148 virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range);
149
150 /// Set the attributes and optionally update the display
151 virtual bool SetStyle(const wxRichTextAttr& style, bool update = true);
152
153 /// Set the style definition and optionally update the display
154 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef, wxRichTextStyleSheet* sheet, bool update = true);
155
156 /// Get the style definition, if any
157 virtual wxRichTextStyleDefinition* GetStyleDefinition() const { return m_styleDefinition; }
158
159 /// Get the style sheet, if any
160 virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
161
162 /// Update the display
163 virtual bool UpdateDisplay();
164
165 /// Apply attributes to the given range
166 virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE);
167
168 /// Apply attributes to the object being edited, if any
169 virtual bool ApplyStyle(wxRichTextCtrl* ctrl, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
170
171 /// Gets and sets the attributes
172 const wxRichTextAttr& GetAttributes() const { return m_attributes; }
173 wxRichTextAttr& GetAttributes() { return m_attributes; }
174 void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; }
175 #if 0
176 /// Gets and sets the attributes that the user wants to reset
177 const wxRichTextAttr& GetResetAttributes() const { return m_resetAttributes; }
178 wxRichTextAttr& GetResetAttributes() { return m_resetAttributes; }
179 void SetResetAttributes(const wxRichTextAttr& attr) { m_resetAttributes = attr; }
180 #endif
181 /// If editing the attributes for a particular object, such as an image,
182 /// set the object so the code can initialize attributes such as size correctly.
183 wxRichTextObject* GetObject() const { return m_object; }
184 void SetObject(wxRichTextObject* obj) { m_object = obj; }
185
186 /// Transfers the data and from to the window
187 virtual bool TransferDataToWindow();
188 virtual bool TransferDataFromWindow();
189
190 /// Apply the styles when a different tab is selected, so the previews are
191 /// up to date
192 void OnTabChanged(wxBookCtrlEvent& event);
193
194 /// Respond to help command
195 void OnHelp(wxCommandEvent& event);
196 void OnUpdateHelp(wxUpdateUIEvent& event);
197
198 /// Get/set formatting factory object
199 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory);
200 static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory() { return ms_FormattingDialogFactory; }
201
202 /// Helper for pages to get the top-level dialog
203 static wxRichTextFormattingDialog* GetDialog(wxWindow* win);
204
205 /// Helper for pages to get the attributes
206 static wxRichTextAttr* GetDialogAttributes(wxWindow* win);
207
208 /// Helper for pages to get the reset attributes
209 static wxRichTextAttr* GetDialogResetAttributes(wxWindow* win);
210
211 /// Helper for pages to get the style
212 static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win);
213
214 /// Should we show tooltips?
215 static bool ShowToolTips() { return sm_showToolTips; }
216
217 /// Determines whether tooltips will be shown
218 static void SetShowToolTips(bool show) { sm_showToolTips = show; }
219
220 /// Set the dimension into the value and units controls
221 static void SetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox);
222
223 /// Get the dimension from the value and units controls
224 static void GetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox);
225
226 /// Convert CM to MM
227 static bool ConvertFromString(const wxString& string, int& ret, int scale);
228
229 /// Map book control page index to our page id
230 void AddPageId(int id) { m_pageIds.Add(id); }
231
232 /// Find a page by class
233 wxWindow* FindPage(wxClassInfo* info) const;
234
235 protected:
236
237 wxRichTextAttr m_attributes;
238 //wxRichTextAttr m_resetAttributes;
239 wxRichTextStyleDefinition* m_styleDefinition;
240 wxRichTextStyleSheet* m_styleSheet;
241 wxRichTextObject* m_object;
242 wxArrayInt m_pageIds; // mapping of book control indexes to page ids
243
244 static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory;
245 static bool sm_showToolTips;
246
247 DECLARE_EVENT_TABLE()
248 };
249
250 //-----------------------------------------------------------------------------
251 // helper class - wxRichTextFontPreviewCtrl
252 //-----------------------------------------------------------------------------
253
254 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl : public wxWindow
255 {
256 public:
257 wxRichTextFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0);
258
259 void SetTextEffects(int effects) { m_textEffects = effects; }
260 int GetTextEffects() const { return m_textEffects; }
261
262 private:
263 int m_textEffects;
264
265 void OnPaint(wxPaintEvent& event);
266 DECLARE_EVENT_TABLE()
267 };
268
269 /*
270 * A control for displaying a small preview of a colour or bitmap
271 */
272
273 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl: public wxControl
274 {
275 DECLARE_CLASS(wxRichTextColourSwatchCtrl)
276 public:
277 wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
278 ~wxRichTextColourSwatchCtrl();
279
280 void OnMouseEvent(wxMouseEvent& event);
281
282 void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
283
284 wxColour& GetColour() { return m_colour; }
285
286 virtual wxSize DoGetBestSize() const { return GetSize(); }
287
288 protected:
289 wxColour m_colour;
290
291 DECLARE_EVENT_TABLE()
292 };
293
294 /*!
295 * wxRichTextFontListBox class declaration
296 * A listbox to display fonts.
297 */
298
299 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox: public wxHtmlListBox
300 {
301 DECLARE_CLASS(wxRichTextFontListBox)
302 DECLARE_EVENT_TABLE()
303
304 public:
305 wxRichTextFontListBox()
306 {
307 Init();
308 }
309 wxRichTextFontListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
310 const wxSize& size = wxDefaultSize, long style = 0);
311 virtual ~wxRichTextFontListBox();
312
313 void Init()
314 {
315 }
316
317 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
318 const wxSize& size = wxDefaultSize, long style = 0);
319
320 /// Creates a suitable HTML fragment for a font
321 wxString CreateHTML(const wxString& facename) const;
322
323 /// Get font name for index
324 wxString GetFaceName(size_t i) const ;
325
326 /// Set selection for string, returning the index.
327 int SetFaceNameSelection(const wxString& name);
328
329 /// Updates the font list
330 void UpdateFonts();
331
332 /// Does this face name exist?
333 bool HasFaceName(const wxString& faceName) const { return m_faceNames.Index(faceName) != wxNOT_FOUND; }
334
335 /// Returns the array of face names
336 const wxArrayString& GetFaceNames() const { return m_faceNames; }
337
338 protected:
339 /// Returns the HTML for this item
340 virtual wxString OnGetItem(size_t n) const;
341
342 private:
343
344 wxArrayString m_faceNames;
345 };
346
347 #endif
348 // wxUSE_RICHTEXT
349
350 #endif
351 // _WX_RICHTEXTFORMATDLG_H_