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