]>
Commit | Line | Data |
---|---|---|
5d7836c4 | 1 | ///////////////////////////////////////////////////////////////////////////// |
b3298d1d | 2 | // Name: wx/richtext/richtextstyles.h |
5d7836c4 JS |
3 | // Purpose: Style management for wxRichTextCtrl |
4 | // Author: Julian Smart | |
e637208a | 5 | // Modified by: |
5d7836c4 | 6 | // Created: 2005-09-30 |
41a85215 | 7 | // RCS-ID: $Id$ |
5d7836c4 JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_RICHTEXTSTYLES_H_ | |
13 | #define _WX_RICHTEXTSTYLES_H_ | |
14 | ||
15 | /*! | |
16 | * Includes | |
17 | */ | |
18 | ||
b3298d1d | 19 | #include "wx/defs.h" |
5d7836c4 JS |
20 | |
21 | #if wxUSE_RICHTEXT | |
22 | ||
b3298d1d WS |
23 | #include "wx/richtext/richtextbuffer.h" |
24 | ||
5d7836c4 JS |
25 | #if wxUSE_HTML |
26 | #include "wx/htmllbox.h" | |
27 | #endif | |
28 | ||
e637208a JS |
29 | #if wxUSE_COMBOCTRL |
30 | #include "wx/combo.h" | |
31 | #endif | |
32 | ||
38f833b1 JS |
33 | #include "wx/choice.h" |
34 | ||
5d7836c4 JS |
35 | /*! |
36 | * Forward declarations | |
37 | */ | |
38 | ||
b5dbe15d VS |
39 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl; |
40 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; | |
5d7836c4 JS |
41 | |
42 | /*! | |
43 | * wxRichTextStyleDefinition class declaration | |
44 | * A base class for paragraph and character styles. | |
45 | */ | |
46 | ||
3b2cb431 | 47 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition: public wxObject |
5d7836c4 JS |
48 | { |
49 | DECLARE_CLASS(wxRichTextStyleDefinition) | |
50 | public: | |
51 | ||
38f833b1 | 52 | /// Copy constructors |
b3298d1d WS |
53 | wxRichTextStyleDefinition(const wxRichTextStyleDefinition& def) |
54 | : wxObject() | |
55 | { | |
38f833b1 | 56 | Init(); |
b3298d1d WS |
57 | Copy(def); |
58 | } | |
38f833b1 JS |
59 | |
60 | /// Default constructor | |
5d7836c4 | 61 | wxRichTextStyleDefinition(const wxString& name = wxEmptyString) { Init(); m_name = name; } |
38f833b1 JS |
62 | |
63 | /// Destructor | |
d3c7fc99 | 64 | virtual ~wxRichTextStyleDefinition() {} |
5d7836c4 | 65 | |
38f833b1 | 66 | /// Initialises members |
5d7836c4 | 67 | void Init() {} |
38f833b1 JS |
68 | |
69 | /// Copies from def | |
fe5aa22c | 70 | void Copy(const wxRichTextStyleDefinition& def); |
38f833b1 JS |
71 | |
72 | /// Equality test | |
fe5aa22c | 73 | bool Eq(const wxRichTextStyleDefinition& def) const; |
38f833b1 JS |
74 | |
75 | /// Assignment operator | |
fe5aa22c | 76 | void operator =(const wxRichTextStyleDefinition& def) { Copy(def); } |
38f833b1 JS |
77 | |
78 | /// Equality operator | |
fe5aa22c | 79 | bool operator ==(const wxRichTextStyleDefinition& def) const { return Eq(def); } |
38f833b1 JS |
80 | |
81 | /// Override to clone the object | |
86015e55 | 82 | virtual wxRichTextStyleDefinition* Clone() const = 0; |
5d7836c4 | 83 | |
38f833b1 | 84 | /// Sets and gets the name of the style |
5d7836c4 JS |
85 | void SetName(const wxString& name) { m_name = name; } |
86 | const wxString& GetName() const { return m_name; } | |
87 | ||
42688aea JS |
88 | /// Sets and gets the style description |
89 | void SetDescription(const wxString& descr) { m_description = descr; } | |
90 | const wxString& GetDescription() const { return m_description; } | |
91 | ||
38f833b1 | 92 | /// Sets and gets the name of the style that this style is based on |
5d7836c4 JS |
93 | void SetBaseStyle(const wxString& name) { m_baseStyle = name; } |
94 | const wxString& GetBaseStyle() const { return m_baseStyle; } | |
95 | ||
336d8ae9 | 96 | /// Sets and gets the style |
24777478 JS |
97 | void SetStyle(const wxRichTextAttr& style) { m_style = style; } |
98 | const wxRichTextAttr& GetStyle() const { return m_style; } | |
99 | wxRichTextAttr& GetStyle() { return m_style; } | |
5d7836c4 | 100 | |
336d8ae9 | 101 | /// Gets the style combined with the base style |
24777478 | 102 | virtual wxRichTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const; |
336d8ae9 | 103 | |
c6182d48 | 104 | /** |
32423dd8 | 105 | Returns the definition's properties. |
c6182d48 JS |
106 | */ |
107 | wxRichTextProperties& GetProperties() { return m_properties; } | |
108 | ||
109 | /** | |
110 | Returns the definition's properties. | |
111 | */ | |
112 | const wxRichTextProperties& GetProperties() const { return m_properties; } | |
113 | ||
114 | /** | |
32423dd8 | 115 | Sets the definition's properties. |
c6182d48 JS |
116 | */ |
117 | void SetProperties(const wxRichTextProperties& props) { m_properties = props; } | |
118 | ||
5d7836c4 | 119 | protected: |
c6182d48 JS |
120 | wxString m_name; |
121 | wxString m_baseStyle; | |
122 | wxString m_description; | |
123 | wxRichTextAttr m_style; | |
124 | wxRichTextProperties m_properties; | |
5d7836c4 JS |
125 | }; |
126 | ||
127 | /*! | |
128 | * wxRichTextCharacterStyleDefinition class declaration | |
129 | */ | |
130 | ||
3b2cb431 | 131 | class WXDLLIMPEXP_RICHTEXT wxRichTextCharacterStyleDefinition: public wxRichTextStyleDefinition |
5d7836c4 JS |
132 | { |
133 | DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition) | |
134 | public: | |
135 | ||
38f833b1 | 136 | /// Copy constructor |
fe5aa22c | 137 | wxRichTextCharacterStyleDefinition(const wxRichTextCharacterStyleDefinition& def): wxRichTextStyleDefinition(def) {} |
38f833b1 JS |
138 | |
139 | /// Default constructor | |
5d7836c4 JS |
140 | wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString): |
141 | wxRichTextStyleDefinition(name) {} | |
38f833b1 JS |
142 | |
143 | /// Destructor | |
d3c7fc99 | 144 | virtual ~wxRichTextCharacterStyleDefinition() {} |
5d7836c4 | 145 | |
38f833b1 | 146 | /// Clones the object |
86015e55 JS |
147 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextCharacterStyleDefinition(*this); } |
148 | ||
5d7836c4 JS |
149 | protected: |
150 | }; | |
151 | ||
152 | /*! | |
153 | * wxRichTextParagraphStyleDefinition class declaration | |
154 | */ | |
155 | ||
3b2cb431 | 156 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphStyleDefinition: public wxRichTextStyleDefinition |
5d7836c4 JS |
157 | { |
158 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition) | |
159 | public: | |
160 | ||
38f833b1 | 161 | /// Copy constructor |
fe5aa22c | 162 | wxRichTextParagraphStyleDefinition(const wxRichTextParagraphStyleDefinition& def): wxRichTextStyleDefinition(def) { m_nextStyle = def.m_nextStyle; } |
38f833b1 JS |
163 | |
164 | /// Default constructor | |
5d7836c4 JS |
165 | wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString): |
166 | wxRichTextStyleDefinition(name) {} | |
38f833b1 JS |
167 | |
168 | // Destructor | |
d3c7fc99 | 169 | virtual ~wxRichTextParagraphStyleDefinition() {} |
5d7836c4 | 170 | |
38f833b1 | 171 | /// Sets and gets the next style |
5d7836c4 JS |
172 | void SetNextStyle(const wxString& name) { m_nextStyle = name; } |
173 | const wxString& GetNextStyle() const { return m_nextStyle; } | |
174 | ||
38f833b1 | 175 | /// Copies from def |
fe5aa22c | 176 | void Copy(const wxRichTextParagraphStyleDefinition& def); |
38f833b1 JS |
177 | |
178 | /// Assignment operator | |
fe5aa22c | 179 | void operator =(const wxRichTextParagraphStyleDefinition& def) { Copy(def); } |
38f833b1 JS |
180 | |
181 | /// Equality operator | |
fe5aa22c JS |
182 | bool operator ==(const wxRichTextParagraphStyleDefinition& def) const; |
183 | ||
38f833b1 | 184 | /// Clones the object |
86015e55 JS |
185 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextParagraphStyleDefinition(*this); } |
186 | ||
5d7836c4 JS |
187 | protected: |
188 | ||
189 | /// The next style to use when adding a paragraph after this style. | |
190 | wxString m_nextStyle; | |
191 | }; | |
192 | ||
38f833b1 JS |
193 | /*! |
194 | * wxRichTextListStyleDefinition class declaration | |
195 | */ | |
196 | ||
197 | class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition: public wxRichTextParagraphStyleDefinition | |
198 | { | |
199 | DECLARE_DYNAMIC_CLASS(wxRichTextListStyleDefinition) | |
200 | public: | |
201 | ||
202 | /// Copy constructor | |
203 | wxRichTextListStyleDefinition(const wxRichTextListStyleDefinition& def): wxRichTextParagraphStyleDefinition(def) { Init(); Copy(def); } | |
204 | ||
205 | /// Default constructor | |
206 | wxRichTextListStyleDefinition(const wxString& name = wxEmptyString): | |
207 | wxRichTextParagraphStyleDefinition(name) { Init(); } | |
208 | ||
209 | /// Destructor | |
210 | virtual ~wxRichTextListStyleDefinition() {} | |
211 | ||
212 | /// Copies from def | |
213 | void Copy(const wxRichTextListStyleDefinition& def); | |
214 | ||
215 | /// Assignment operator | |
216 | void operator =(const wxRichTextListStyleDefinition& def) { Copy(def); } | |
217 | ||
218 | /// Equality operator | |
219 | bool operator ==(const wxRichTextListStyleDefinition& def) const; | |
220 | ||
221 | /// Clones the object | |
222 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextListStyleDefinition(*this); } | |
223 | ||
224 | /// Sets/gets the attributes for the given level | |
24777478 JS |
225 | void SetLevelAttributes(int i, const wxRichTextAttr& attr); |
226 | wxRichTextAttr* GetLevelAttributes(int i); | |
227 | const wxRichTextAttr* GetLevelAttributes(int i) const; | |
38f833b1 JS |
228 | |
229 | /// Convenience function for setting the major attributes for a list level specification | |
230 | void SetAttributes(int i, int leftIndent, int leftSubIndent, int bulletStyle, const wxString& bulletSymbol = wxEmptyString); | |
231 | ||
232 | /// Finds the level corresponding to the given indentation | |
233 | int FindLevelForIndent(int indent) const; | |
234 | ||
235 | /// Combine the base and list style with a paragraph style, using the given indent (from which | |
236 | /// an appropriate level is found) | |
24777478 | 237 | wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle, wxRichTextStyleSheet* styleSheet = NULL); |
38f833b1 JS |
238 | |
239 | /// Combine the base and list style, using the given indent (from which | |
240 | /// an appropriate level is found) | |
24777478 | 241 | wxRichTextAttr GetCombinedStyle(int indent, wxRichTextStyleSheet* styleSheet = NULL); |
38f833b1 JS |
242 | |
243 | /// Combine the base and list style, using the given level from which | |
244 | /// an appropriate level is found) | |
24777478 | 245 | wxRichTextAttr GetCombinedStyleForLevel(int level, wxRichTextStyleSheet* styleSheet = NULL); |
38f833b1 JS |
246 | |
247 | /// Gets the number of available levels | |
248 | int GetLevelCount() const { return 10; } | |
249 | ||
250 | /// Is this a numbered list? | |
251 | bool IsNumbered(int i) const; | |
252 | ||
253 | protected: | |
254 | ||
255 | /// The styles for each level (up to 10) | |
24777478 | 256 | wxRichTextAttr m_levelStyles[10]; |
38f833b1 JS |
257 | }; |
258 | ||
603f702b JS |
259 | /*! |
260 | * wxRichTextBoxStyleDefinition class declaration, for box attributes in objects such as wxRichTextBox. | |
261 | */ | |
262 | ||
263 | class WXDLLIMPEXP_RICHTEXT wxRichTextBoxStyleDefinition: public wxRichTextStyleDefinition | |
264 | { | |
265 | DECLARE_DYNAMIC_CLASS(wxRichTextBoxStyleDefinition) | |
266 | public: | |
267 | ||
268 | /// Copy constructor | |
bcc37238 | 269 | wxRichTextBoxStyleDefinition(const wxRichTextBoxStyleDefinition& def): wxRichTextStyleDefinition(def) { Copy(def); } |
603f702b JS |
270 | |
271 | /// Default constructor | |
272 | wxRichTextBoxStyleDefinition(const wxString& name = wxEmptyString): | |
273 | wxRichTextStyleDefinition(name) {} | |
274 | ||
275 | // Destructor | |
276 | virtual ~wxRichTextBoxStyleDefinition() {} | |
277 | ||
278 | /// Copies from def | |
279 | void Copy(const wxRichTextBoxStyleDefinition& def); | |
280 | ||
281 | /// Assignment operator | |
282 | void operator =(const wxRichTextBoxStyleDefinition& def) { Copy(def); } | |
283 | ||
284 | /// Equality operator | |
285 | bool operator ==(const wxRichTextBoxStyleDefinition& def) const; | |
286 | ||
287 | /// Clones the object | |
288 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextBoxStyleDefinition(*this); } | |
289 | ||
290 | protected: | |
291 | }; | |
292 | ||
5d7836c4 JS |
293 | /*! |
294 | * The style sheet | |
295 | */ | |
296 | ||
3b2cb431 | 297 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet: public wxObject |
5d7836c4 JS |
298 | { |
299 | DECLARE_CLASS( wxRichTextStyleSheet ) | |
300 | ||
301 | public: | |
302 | /// Constructors | |
b3298d1d WS |
303 | wxRichTextStyleSheet(const wxRichTextStyleSheet& sheet) |
304 | : wxObject() | |
305 | { | |
44cc96a8 | 306 | Init(); |
b3298d1d WS |
307 | Copy(sheet); |
308 | } | |
5d7836c4 | 309 | wxRichTextStyleSheet() { Init(); } |
38f833b1 | 310 | virtual ~wxRichTextStyleSheet(); |
5d7836c4 JS |
311 | |
312 | /// Initialisation | |
313 | void Init(); | |
314 | ||
fe5aa22c JS |
315 | /// Copy |
316 | void Copy(const wxRichTextStyleSheet& sheet); | |
317 | ||
318 | /// Assignment | |
319 | void operator=(const wxRichTextStyleSheet& sheet) { Copy(sheet); } | |
320 | ||
321 | /// Equality | |
322 | bool operator==(const wxRichTextStyleSheet& sheet) const; | |
323 | ||
5d7836c4 | 324 | /// Add a definition to the character style list |
fe5aa22c | 325 | bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def); |
5d7836c4 JS |
326 | |
327 | /// Add a definition to the paragraph style list | |
fe5aa22c | 328 | bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def); |
5d7836c4 | 329 | |
38f833b1 JS |
330 | /// Add a definition to the list style list |
331 | bool AddListStyle(wxRichTextListStyleDefinition* def); | |
332 | ||
603f702b JS |
333 | /// Add a definition to the box style list |
334 | bool AddBoxStyle(wxRichTextBoxStyleDefinition* def); | |
335 | ||
336d8ae9 VZ |
336 | /// Add a definition to the appropriate style list |
337 | bool AddStyle(wxRichTextStyleDefinition* def); | |
338 | ||
5d7836c4 JS |
339 | /// Remove a character style |
340 | bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); } | |
341 | ||
342 | /// Remove a paragraph style | |
fe5aa22c | 343 | bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_paragraphStyleDefinitions, def, deleteStyle); } |
5d7836c4 | 344 | |
38f833b1 JS |
345 | /// Remove a list style |
346 | bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); } | |
347 | ||
603f702b JS |
348 | /// Remove a box style |
349 | bool RemoveBoxStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_boxStyleDefinitions, def, deleteStyle); } | |
350 | ||
336d8ae9 VZ |
351 | /// Remove a style |
352 | bool RemoveStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false); | |
353 | ||
5d7836c4 | 354 | /// Find a character definition by name |
38f833b1 | 355 | wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); } |
5d7836c4 JS |
356 | |
357 | /// Find a paragraph definition by name | |
38f833b1 | 358 | wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, bool recurse = true) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name, recurse); } |
5d7836c4 | 359 | |
38f833b1 JS |
360 | /// Find a list definition by name |
361 | wxRichTextListStyleDefinition* FindListStyle(const wxString& name, bool recurse = true) const { return (wxRichTextListStyleDefinition*) FindStyle(m_listStyleDefinitions, name, recurse); } | |
362 | ||
603f702b JS |
363 | /// Find a box definition by name |
364 | wxRichTextBoxStyleDefinition* FindBoxStyle(const wxString& name, bool recurse = true) const { return (wxRichTextBoxStyleDefinition*) FindStyle(m_boxStyleDefinitions, name, recurse); } | |
365 | ||
336d8ae9 VZ |
366 | /// Find any definition by name |
367 | wxRichTextStyleDefinition* FindStyle(const wxString& name, bool recurse = true) const; | |
368 | ||
38f833b1 | 369 | /// Return the number of character styles |
5d7836c4 JS |
370 | size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); } |
371 | ||
38f833b1 | 372 | /// Return the number of paragraph styles |
5d7836c4 JS |
373 | size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); } |
374 | ||
38f833b1 JS |
375 | /// Return the number of list styles |
376 | size_t GetListStyleCount() const { return m_listStyleDefinitions.GetCount(); } | |
377 | ||
603f702b JS |
378 | /// Return the number of box styles |
379 | size_t GetBoxStyleCount() const { return m_boxStyleDefinitions.GetCount(); } | |
380 | ||
5d7836c4 JS |
381 | /// Return the nth character style |
382 | wxRichTextCharacterStyleDefinition* GetCharacterStyle(size_t n) const { return (wxRichTextCharacterStyleDefinition*) m_characterStyleDefinitions.Item(n)->GetData(); } | |
383 | ||
384 | /// Return the nth paragraph style | |
385 | wxRichTextParagraphStyleDefinition* GetParagraphStyle(size_t n) const { return (wxRichTextParagraphStyleDefinition*) m_paragraphStyleDefinitions.Item(n)->GetData(); } | |
386 | ||
38f833b1 JS |
387 | /// Return the nth list style |
388 | wxRichTextListStyleDefinition* GetListStyle(size_t n) const { return (wxRichTextListStyleDefinition*) m_listStyleDefinitions.Item(n)->GetData(); } | |
389 | ||
603f702b JS |
390 | /// Return the nth box style |
391 | wxRichTextBoxStyleDefinition* GetBoxStyle(size_t n) const { return (wxRichTextBoxStyleDefinition*) m_boxStyleDefinitions.Item(n)->GetData(); } | |
392 | ||
5d7836c4 JS |
393 | /// Delete all styles |
394 | void DeleteStyles(); | |
395 | ||
38f833b1 JS |
396 | /// Insert into list of style sheets |
397 | bool InsertSheet(wxRichTextStyleSheet* before); | |
398 | ||
399 | /// Append to list of style sheets | |
400 | bool AppendSheet(wxRichTextStyleSheet* after); | |
401 | ||
402 | /// Unlink from the list of style sheets | |
403 | void Unlink(); | |
404 | ||
405 | /// Get/set next sheet | |
406 | wxRichTextStyleSheet* GetNextSheet() const { return m_nextSheet; } | |
407 | void SetNextSheet(wxRichTextStyleSheet* sheet) { m_nextSheet = sheet; } | |
408 | ||
409 | /// Get/set previous sheet | |
410 | wxRichTextStyleSheet* GetPreviousSheet() const { return m_previousSheet; } | |
411 | void SetPreviousSheet(wxRichTextStyleSheet* sheet) { m_previousSheet = sheet; } | |
412 | ||
42688aea JS |
413 | /// Sets and gets the name of the style sheet |
414 | void SetName(const wxString& name) { m_name = name; } | |
415 | const wxString& GetName() const { return m_name; } | |
416 | ||
417 | /// Sets and gets the style description | |
418 | void SetDescription(const wxString& descr) { m_description = descr; } | |
419 | const wxString& GetDescription() const { return m_description; } | |
420 | ||
c6182d48 | 421 | /** |
32423dd8 | 422 | Returns the sheet's properties. |
c6182d48 JS |
423 | */ |
424 | wxRichTextProperties& GetProperties() { return m_properties; } | |
425 | ||
426 | /** | |
32423dd8 | 427 | Returns the sheet's properties. |
c6182d48 JS |
428 | */ |
429 | const wxRichTextProperties& GetProperties() const { return m_properties; } | |
430 | ||
431 | /** | |
32423dd8 | 432 | Sets the sheet's properties. |
c6182d48 JS |
433 | */ |
434 | void SetProperties(const wxRichTextProperties& props) { m_properties = props; } | |
435 | ||
5d7836c4 JS |
436 | /// Implementation |
437 | ||
438 | /// Add a definition to one of the style lists | |
439 | bool AddStyle(wxList& list, wxRichTextStyleDefinition* def); | |
440 | ||
441 | /// Remove a style | |
442 | bool RemoveStyle(wxList& list, wxRichTextStyleDefinition* def, bool deleteStyle); | |
443 | ||
444 | /// Find a definition by name | |
38f833b1 | 445 | wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const; |
5d7836c4 JS |
446 | |
447 | protected: | |
448 | ||
42688aea JS |
449 | wxString m_description; |
450 | wxString m_name; | |
451 | ||
452 | wxList m_characterStyleDefinitions; | |
453 | wxList m_paragraphStyleDefinitions; | |
454 | wxList m_listStyleDefinitions; | |
603f702b | 455 | wxList m_boxStyleDefinitions; |
38f833b1 | 456 | |
42688aea JS |
457 | wxRichTextStyleSheet* m_previousSheet; |
458 | wxRichTextStyleSheet* m_nextSheet; | |
c6182d48 | 459 | wxRichTextProperties m_properties; |
5d7836c4 JS |
460 | }; |
461 | ||
462 | #if wxUSE_HTML | |
463 | /*! | |
464 | * wxRichTextStyleListBox class declaration | |
465 | * A listbox to display styles. | |
466 | */ | |
467 | ||
3b2cb431 | 468 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox |
5d7836c4 JS |
469 | { |
470 | DECLARE_CLASS(wxRichTextStyleListBox) | |
471 | DECLARE_EVENT_TABLE() | |
472 | ||
473 | public: | |
38f833b1 JS |
474 | /// Which type of style definition is currently showing? |
475 | enum wxRichTextStyleType | |
476 | { | |
477 | wxRICHTEXT_STYLE_ALL, | |
478 | wxRICHTEXT_STYLE_PARAGRAPH, | |
479 | wxRICHTEXT_STYLE_CHARACTER, | |
603f702b JS |
480 | wxRICHTEXT_STYLE_LIST, |
481 | wxRICHTEXT_STYLE_BOX | |
38f833b1 JS |
482 | }; |
483 | ||
e637208a JS |
484 | wxRichTextStyleListBox() |
485 | { | |
486 | Init(); | |
487 | } | |
5d7836c4 JS |
488 | wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
489 | const wxSize& size = wxDefaultSize, long style = 0); | |
d3c7fc99 | 490 | virtual ~wxRichTextStyleListBox(); |
5d7836c4 | 491 | |
e637208a JS |
492 | void Init() |
493 | { | |
494 | m_styleSheet = NULL; | |
495 | m_richTextCtrl = NULL; | |
38f833b1 JS |
496 | m_applyOnSelection = false; |
497 | m_styleType = wxRICHTEXT_STYLE_PARAGRAPH; | |
dadd4f55 | 498 | m_autoSetSelection = true; |
e637208a JS |
499 | } |
500 | ||
501 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
502 | const wxSize& size = wxDefaultSize, long style = 0); | |
503 | ||
5d7836c4 JS |
504 | /// Creates a suitable HTML fragment for a definition |
505 | wxString CreateHTML(wxRichTextStyleDefinition* def) const; | |
506 | ||
1f65137f | 507 | /// Associates the control with a style sheet |
5d7836c4 JS |
508 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; } |
509 | wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; } | |
510 | ||
511 | /// Associates the control with a wxRichTextCtrl | |
512 | void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_richTextCtrl = ctrl; } | |
513 | wxRichTextCtrl* GetRichTextCtrl() const { return m_richTextCtrl; } | |
514 | ||
e637208a | 515 | /// Get style for index |
5d7836c4 JS |
516 | wxRichTextStyleDefinition* GetStyle(size_t i) const ; |
517 | ||
e637208a JS |
518 | /// Get index for style name |
519 | int GetIndexForStyle(const wxString& name) const ; | |
520 | ||
521 | /// Set selection for string, returning the index. | |
522 | int SetStyleSelection(const wxString& name); | |
523 | ||
5d7836c4 JS |
524 | /// Updates the list |
525 | void UpdateStyles(); | |
526 | ||
86015e55 JS |
527 | /// Apply the style |
528 | void ApplyStyle(int i); | |
e637208a | 529 | |
5d7836c4 JS |
530 | /// Left click |
531 | void OnLeftDown(wxMouseEvent& event); | |
532 | ||
38f833b1 JS |
533 | /// Left double-click |
534 | void OnLeftDoubleClick(wxMouseEvent& event); | |
535 | ||
e637208a JS |
536 | /// Auto-select from style under caret in idle time |
537 | void OnIdle(wxIdleEvent& event); | |
538 | ||
e637208a | 539 | /// Convert units in tends of a millimetre to device units |
5d7836c4 JS |
540 | int ConvertTenthsMMToPixels(wxDC& dc, int units) const; |
541 | ||
e637208a JS |
542 | /// Can we set the selection based on the editor caret position? |
543 | /// Need to override this if being used in a combobox popup | |
dadd4f55 JS |
544 | virtual bool CanAutoSetSelection() { return m_autoSetSelection; } |
545 | virtual void SetAutoSetSelection(bool autoSet) { m_autoSetSelection = autoSet; } | |
e637208a | 546 | |
86015e55 JS |
547 | /// Set whether the style should be applied as soon as the item is selected (the default) |
548 | void SetApplyOnSelection(bool applyOnSel) { m_applyOnSelection = applyOnSel; } | |
549 | bool GetApplyOnSelection() const { return m_applyOnSelection; } | |
550 | ||
38f833b1 JS |
551 | /// Set the style type to display |
552 | void SetStyleType(wxRichTextStyleType styleType) { m_styleType = styleType; UpdateStyles(); } | |
553 | wxRichTextStyleType GetStyleType() const { return m_styleType; } | |
554 | ||
555 | /// Helper for listbox and combo control | |
556 | static wxString GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType); | |
557 | ||
6f02a879 VZ |
558 | protected: |
559 | /// Returns the HTML for this item | |
560 | virtual wxString OnGetItem(size_t n) const; | |
561 | ||
5d7836c4 JS |
562 | private: |
563 | ||
564 | wxRichTextStyleSheet* m_styleSheet; | |
565 | wxRichTextCtrl* m_richTextCtrl; | |
86015e55 | 566 | bool m_applyOnSelection; // if true, applies style on selection |
38f833b1 | 567 | wxRichTextStyleType m_styleType; // style type to display |
dadd4f55 | 568 | bool m_autoSetSelection; |
486dd03a | 569 | wxArrayString m_styleNames; |
38f833b1 JS |
570 | }; |
571 | ||
572 | /*! | |
573 | * wxRichTextStyleListCtrl class declaration | |
574 | * This is a container for the list control plus a combobox to switch between | |
575 | * style types. | |
576 | */ | |
577 | ||
dadd4f55 JS |
578 | #define wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR 0x1000 |
579 | ||
38f833b1 JS |
580 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListCtrl: public wxControl |
581 | { | |
582 | DECLARE_CLASS(wxRichTextStyleListCtrl) | |
583 | DECLARE_EVENT_TABLE() | |
584 | ||
585 | public: | |
586 | ||
587 | /// Constructors | |
588 | wxRichTextStyleListCtrl() | |
589 | { | |
590 | Init(); | |
591 | } | |
592 | ||
593 | wxRichTextStyleListCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
594 | const wxSize& size = wxDefaultSize, long style = 0); | |
595 | ||
596 | /// Constructors | |
597 | virtual ~wxRichTextStyleListCtrl(); | |
598 | ||
599 | /// Member initialisation | |
600 | void Init() | |
601 | { | |
602 | m_styleListBox = NULL; | |
603 | m_styleChoice = NULL; | |
604 | m_dontUpdate = false; | |
605 | } | |
606 | ||
607 | /// Creates the windows | |
608 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
609 | const wxSize& size = wxDefaultSize, long style = 0); | |
610 | ||
dadd4f55 JS |
611 | /// Updates the style list box |
612 | void UpdateStyles(); | |
613 | ||
1f65137f | 614 | /// Associates the control with a style sheet |
38f833b1 JS |
615 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet); |
616 | wxRichTextStyleSheet* GetStyleSheet() const; | |
617 | ||
618 | /// Associates the control with a wxRichTextCtrl | |
619 | void SetRichTextCtrl(wxRichTextCtrl* ctrl); | |
620 | wxRichTextCtrl* GetRichTextCtrl() const; | |
621 | ||
38f833b1 JS |
622 | /// Set/get the style type to display |
623 | void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType); | |
624 | wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const; | |
625 | ||
626 | /// Get the choice index for style type | |
627 | int StyleTypeToIndex(wxRichTextStyleListBox::wxRichTextStyleType styleType); | |
628 | ||
629 | /// Get the style type for choice index | |
630 | wxRichTextStyleListBox::wxRichTextStyleType StyleIndexToType(int i); | |
631 | ||
632 | /// Get the listbox | |
633 | wxRichTextStyleListBox* GetStyleListBox() const { return m_styleListBox; } | |
634 | ||
635 | /// Get the choice | |
636 | wxChoice* GetStyleChoice() const { return m_styleChoice; } | |
637 | ||
638 | /// React to style type choice | |
639 | void OnChooseType(wxCommandEvent& event); | |
640 | ||
641 | /// Lay out the controls | |
642 | void OnSize(wxSizeEvent& event); | |
643 | ||
644 | private: | |
645 | ||
646 | wxRichTextStyleListBox* m_styleListBox; | |
647 | wxChoice* m_styleChoice; | |
648 | bool m_dontUpdate; | |
5d7836c4 | 649 | }; |
e637208a JS |
650 | |
651 | #if wxUSE_COMBOCTRL | |
652 | ||
653 | /*! | |
654 | * Style drop-down for a wxComboCtrl | |
655 | */ | |
656 | ||
657 | class wxRichTextStyleComboPopup : public wxRichTextStyleListBox, public wxComboPopup | |
658 | { | |
659 | public: | |
660 | virtual void Init() | |
661 | { | |
662 | m_itemHere = -1; // hot item in list | |
663 | m_value = -1; | |
664 | } | |
665 | ||
a047aff2 | 666 | virtual bool Create( wxWindow* parent ); |
e637208a JS |
667 | |
668 | virtual wxWindow *GetControl() { return this; } | |
669 | ||
670 | virtual void SetStringValue( const wxString& s ); | |
671 | ||
672 | virtual wxString GetStringValue() const; | |
673 | ||
674 | /// Can we set the selection based on the editor caret position? | |
675 | // virtual bool CanAutoSetSelection() { return ((m_combo == NULL) || !m_combo->IsPopupShown()); } | |
676 | virtual bool CanAutoSetSelection() { return false; } | |
677 | ||
678 | // | |
679 | // Popup event handlers | |
680 | // | |
681 | ||
682 | // Mouse hot-tracking | |
683 | void OnMouseMove(wxMouseEvent& event); | |
684 | ||
685 | // On mouse left, set the value and close the popup | |
686 | void OnMouseClick(wxMouseEvent& WXUNUSED(event)); | |
687 | ||
688 | protected: | |
689 | ||
690 | int m_itemHere; // hot item in popup | |
691 | int m_value; | |
692 | ||
693 | private: | |
694 | DECLARE_EVENT_TABLE() | |
695 | }; | |
696 | ||
697 | /*! | |
698 | * wxRichTextStyleComboCtrl | |
699 | * A combo for applying styles. | |
700 | */ | |
701 | ||
702 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleComboCtrl: public wxComboCtrl | |
703 | { | |
704 | DECLARE_CLASS(wxRichTextStyleComboCtrl) | |
705 | DECLARE_EVENT_TABLE() | |
706 | ||
707 | public: | |
708 | wxRichTextStyleComboCtrl() | |
709 | { | |
710 | Init(); | |
711 | } | |
712 | ||
713 | wxRichTextStyleComboCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
714 | const wxSize& size = wxDefaultSize, long style = wxCB_READONLY) | |
715 | { | |
716 | Init(); | |
717 | Create(parent, id, pos, size, style); | |
718 | } | |
719 | ||
720 | virtual ~wxRichTextStyleComboCtrl() {} | |
721 | ||
722 | void Init() | |
723 | { | |
724 | m_stylePopup = NULL; | |
725 | } | |
726 | ||
727 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
728 | const wxSize& size = wxDefaultSize, long style = 0); | |
729 | ||
730 | /// Updates the list | |
731 | void UpdateStyles() { m_stylePopup->UpdateStyles(); } | |
732 | ||
1f65137f | 733 | /// Associates the control with a style sheet |
e637208a JS |
734 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_stylePopup->SetStyleSheet(styleSheet); } |
735 | wxRichTextStyleSheet* GetStyleSheet() const { return m_stylePopup->GetStyleSheet(); } | |
736 | ||
737 | /// Associates the control with a wxRichTextCtrl | |
738 | void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_stylePopup->SetRichTextCtrl(ctrl); } | |
739 | wxRichTextCtrl* GetRichTextCtrl() const { return m_stylePopup->GetRichTextCtrl(); } | |
740 | ||
741 | /// Gets the style popup | |
742 | wxRichTextStyleComboPopup* GetStylePopup() const { return m_stylePopup; } | |
743 | ||
744 | /// Auto-select from style under caret in idle time | |
745 | void OnIdle(wxIdleEvent& event); | |
746 | ||
747 | protected: | |
748 | wxRichTextStyleComboPopup* m_stylePopup; | |
749 | }; | |
750 | ||
751 | #endif | |
752 | // wxUSE_COMBOCTRL | |
753 | ||
5d7836c4 | 754 | #endif |
e637208a | 755 | // wxUSE_HTML |
5d7836c4 JS |
756 | |
757 | #endif | |
758 | // wxUSE_RICHTEXT | |
759 | ||
760 | #endif | |
761 | // _WX_RICHTEXTSTYLES_H_ |