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