]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextformatdlg.h
Fix wrong tab order in wxAuiNotebook after dragging.
[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 enum { Option_AllowPixelFontSize = 0x0001 };
130
131 wxRichTextFormattingDialog() { Init(); }
132
133 wxRichTextFormattingDialog(long flags, wxWindow* parent, const wxString& title = wxGetTranslation(wxT("Formatting")), wxWindowID id = wxID_ANY,
134 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
135 long style = wxDEFAULT_DIALOG_STYLE)
136 {
137 Init();
138 Create(flags, parent, title, id, pos, sz, style);
139 }
140
141 ~wxRichTextFormattingDialog();
142
143 void Init();
144
145 bool Create(long flags, wxWindow* parent, const wxString& title = wxGetTranslation(wxT("Formatting")), wxWindowID id = wxID_ANY,
146 const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
147 long style = wxDEFAULT_DIALOG_STYLE);
148
149 /// Get attributes from the given range
150 virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range);
151
152 /// Set the attributes and optionally update the display
153 virtual bool SetStyle(const wxRichTextAttr& style, bool update = true);
154
155 /// Set the style definition and optionally update the display
156 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef, wxRichTextStyleSheet* sheet, bool update = true);
157
158 /// Get the style definition, if any
159 virtual wxRichTextStyleDefinition* GetStyleDefinition() const { return m_styleDefinition; }
160
161 /// Get the style sheet, if any
162 virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
163
164 /// Update the display
165 virtual bool UpdateDisplay();
166
167 /// Apply attributes to the given range
168 virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE);
169
170 /// Apply attributes to the object being edited, if any
171 virtual bool ApplyStyle(wxRichTextCtrl* ctrl, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
172
173 /// Gets and sets the attributes
174 const wxRichTextAttr& GetAttributes() const { return m_attributes; }
175 wxRichTextAttr& GetAttributes() { return m_attributes; }
176 void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; }
177
178 /// Sets the dialog options, determining what the interface presents to the user.
179 /// Currently the only option is Option_AllowPixelFontSize.
180 void SetOptions(int options) { m_options = options; }
181
182 /// Gets the dialog options, determining what the interface presents to the user.
183 /// Currently the only option is Option_AllowPixelFontSize.
184 int GetOptions() const { return m_options; }
185
186 /// Returns @true if the given option is present.
187 bool HasOption(int option) const { return (m_options & option) != 0; }
188
189 /// If editing the attributes for a particular object, such as an image,
190 /// set the object so the code can initialize attributes such as size correctly.
191 wxRichTextObject* GetObject() const { return m_object; }
192 void SetObject(wxRichTextObject* obj) { m_object = obj; }
193
194 /// Transfers the data and from to the window
195 virtual bool TransferDataToWindow();
196 virtual bool TransferDataFromWindow();
197
198 /// Apply the styles when a different tab is selected, so the previews are
199 /// up to date
200 void OnTabChanged(wxBookCtrlEvent& event);
201
202 /// Respond to help command
203 void OnHelp(wxCommandEvent& event);
204 void OnUpdateHelp(wxUpdateUIEvent& event);
205
206 /// Get/set formatting factory object
207 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory);
208 static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory() { return ms_FormattingDialogFactory; }
209
210 /// Helper for pages to get the top-level dialog
211 static wxRichTextFormattingDialog* GetDialog(wxWindow* win);
212
213 /// Helper for pages to get the attributes
214 static wxRichTextAttr* GetDialogAttributes(wxWindow* win);
215
216 /// Helper for pages to get the reset attributes
217 static wxRichTextAttr* GetDialogResetAttributes(wxWindow* win);
218
219 /// Helper for pages to get the style
220 static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win);
221
222 /// Should we show tooltips?
223 static bool ShowToolTips() { return sm_showToolTips; }
224
225 /// Determines whether tooltips will be shown
226 static void SetShowToolTips(bool show) { sm_showToolTips = show; }
227
228 /// Set the dimension into the value and units controls
229 static void SetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox);
230
231 /// Get the dimension from the value and units controls
232 static void GetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox);
233
234 /// Convert CM to MM
235 static bool ConvertFromString(const wxString& string, int& ret, int scale);
236
237 /// Map book control page index to our page id
238 void AddPageId(int id) { m_pageIds.Add(id); }
239
240 /// Find a page by class
241 wxWindow* FindPage(wxClassInfo* info) const;
242
243 protected:
244
245 wxRichTextAttr m_attributes;
246 wxRichTextStyleDefinition* m_styleDefinition;
247 wxRichTextStyleSheet* m_styleSheet;
248 wxRichTextObject* m_object;
249 wxArrayInt m_pageIds; // mapping of book control indexes to page ids
250 int m_options; // UI options
251
252 static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory;
253 static bool sm_showToolTips;
254
255 DECLARE_EVENT_TABLE()
256 };
257
258 //-----------------------------------------------------------------------------
259 // helper class - wxRichTextFontPreviewCtrl
260 //-----------------------------------------------------------------------------
261
262 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl : public wxWindow
263 {
264 public:
265 wxRichTextFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0);
266
267 void SetTextEffects(int effects) { m_textEffects = effects; }
268 int GetTextEffects() const { return m_textEffects; }
269
270 private:
271 int m_textEffects;
272
273 void OnPaint(wxPaintEvent& event);
274 DECLARE_EVENT_TABLE()
275 };
276
277 /*
278 * A control for displaying a small preview of a colour or bitmap
279 */
280
281 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl: public wxControl
282 {
283 DECLARE_CLASS(wxRichTextColourSwatchCtrl)
284 public:
285 wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
286 ~wxRichTextColourSwatchCtrl();
287
288 void OnMouseEvent(wxMouseEvent& event);
289
290 void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
291
292 wxColour& GetColour() { return m_colour; }
293
294 virtual wxSize DoGetBestSize() const { return GetSize(); }
295
296 protected:
297 wxColour m_colour;
298
299 DECLARE_EVENT_TABLE()
300 };
301
302 /*!
303 * wxRichTextFontListBox class declaration
304 * A listbox to display fonts.
305 */
306
307 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox: public wxHtmlListBox
308 {
309 DECLARE_CLASS(wxRichTextFontListBox)
310 DECLARE_EVENT_TABLE()
311
312 public:
313 wxRichTextFontListBox()
314 {
315 Init();
316 }
317 wxRichTextFontListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
318 const wxSize& size = wxDefaultSize, long style = 0);
319 virtual ~wxRichTextFontListBox();
320
321 void Init()
322 {
323 }
324
325 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
326 const wxSize& size = wxDefaultSize, long style = 0);
327
328 /// Creates a suitable HTML fragment for a font
329 wxString CreateHTML(const wxString& facename) const;
330
331 /// Get font name for index
332 wxString GetFaceName(size_t i) const ;
333
334 /// Set selection for string, returning the index.
335 int SetFaceNameSelection(const wxString& name);
336
337 /// Updates the font list
338 void UpdateFonts();
339
340 /// Does this face name exist?
341 bool HasFaceName(const wxString& faceName) const { return m_faceNames.Index(faceName) != wxNOT_FOUND; }
342
343 /// Returns the array of face names
344 const wxArrayString& GetFaceNames() const { return m_faceNames; }
345
346 protected:
347 /// Returns the HTML for this item
348 virtual wxString OnGetItem(size_t n) const;
349
350 private:
351
352 wxArrayString m_faceNames;
353 };
354
355 #endif
356 // wxUSE_RICHTEXT
357
358 #endif
359 // _WX_RICHTEXTFORMATDLG_H_