]>
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 | ||
3b2cb431 JS |
39 | class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl; |
40 | class WXDLLIMPEXP_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 | ||
38f833b1 | 96 | /// Sets the style |
5d7836c4 JS |
97 | void SetStyle(const wxRichTextAttr& style) { m_style = style; } |
98 | const wxRichTextAttr& GetStyle() const { return m_style; } | |
99 | wxRichTextAttr& GetStyle() { return m_style; } | |
100 | ||
101 | protected: | |
102 | wxString m_name; | |
103 | wxString m_baseStyle; | |
42688aea | 104 | wxString m_description; |
5d7836c4 JS |
105 | wxRichTextAttr m_style; |
106 | }; | |
107 | ||
108 | /*! | |
109 | * wxRichTextCharacterStyleDefinition class declaration | |
110 | */ | |
111 | ||
3b2cb431 | 112 | class WXDLLIMPEXP_RICHTEXT wxRichTextCharacterStyleDefinition: public wxRichTextStyleDefinition |
5d7836c4 JS |
113 | { |
114 | DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition) | |
115 | public: | |
116 | ||
38f833b1 | 117 | /// Copy constructor |
fe5aa22c | 118 | wxRichTextCharacterStyleDefinition(const wxRichTextCharacterStyleDefinition& def): wxRichTextStyleDefinition(def) {} |
38f833b1 JS |
119 | |
120 | /// Default constructor | |
5d7836c4 JS |
121 | wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString): |
122 | wxRichTextStyleDefinition(name) {} | |
38f833b1 JS |
123 | |
124 | /// Destructor | |
d3c7fc99 | 125 | virtual ~wxRichTextCharacterStyleDefinition() {} |
5d7836c4 | 126 | |
38f833b1 | 127 | /// Clones the object |
86015e55 JS |
128 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextCharacterStyleDefinition(*this); } |
129 | ||
5d7836c4 JS |
130 | protected: |
131 | }; | |
132 | ||
133 | /*! | |
134 | * wxRichTextParagraphStyleDefinition class declaration | |
135 | */ | |
136 | ||
3b2cb431 | 137 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphStyleDefinition: public wxRichTextStyleDefinition |
5d7836c4 JS |
138 | { |
139 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition) | |
140 | public: | |
141 | ||
38f833b1 | 142 | /// Copy constructor |
fe5aa22c | 143 | wxRichTextParagraphStyleDefinition(const wxRichTextParagraphStyleDefinition& def): wxRichTextStyleDefinition(def) { m_nextStyle = def.m_nextStyle; } |
38f833b1 JS |
144 | |
145 | /// Default constructor | |
5d7836c4 JS |
146 | wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString): |
147 | wxRichTextStyleDefinition(name) {} | |
38f833b1 JS |
148 | |
149 | // Destructor | |
d3c7fc99 | 150 | virtual ~wxRichTextParagraphStyleDefinition() {} |
5d7836c4 | 151 | |
38f833b1 | 152 | /// Sets and gets the next style |
5d7836c4 JS |
153 | void SetNextStyle(const wxString& name) { m_nextStyle = name; } |
154 | const wxString& GetNextStyle() const { return m_nextStyle; } | |
155 | ||
38f833b1 | 156 | /// Copies from def |
fe5aa22c | 157 | void Copy(const wxRichTextParagraphStyleDefinition& def); |
38f833b1 JS |
158 | |
159 | /// Assignment operator | |
fe5aa22c | 160 | void operator =(const wxRichTextParagraphStyleDefinition& def) { Copy(def); } |
38f833b1 JS |
161 | |
162 | /// Equality operator | |
fe5aa22c JS |
163 | bool operator ==(const wxRichTextParagraphStyleDefinition& def) const; |
164 | ||
38f833b1 | 165 | /// Clones the object |
86015e55 JS |
166 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextParagraphStyleDefinition(*this); } |
167 | ||
5d7836c4 JS |
168 | protected: |
169 | ||
170 | /// The next style to use when adding a paragraph after this style. | |
171 | wxString m_nextStyle; | |
172 | }; | |
173 | ||
38f833b1 JS |
174 | /*! |
175 | * wxRichTextListStyleDefinition class declaration | |
176 | */ | |
177 | ||
178 | class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition: public wxRichTextParagraphStyleDefinition | |
179 | { | |
180 | DECLARE_DYNAMIC_CLASS(wxRichTextListStyleDefinition) | |
181 | public: | |
182 | ||
183 | /// Copy constructor | |
184 | wxRichTextListStyleDefinition(const wxRichTextListStyleDefinition& def): wxRichTextParagraphStyleDefinition(def) { Init(); Copy(def); } | |
185 | ||
186 | /// Default constructor | |
187 | wxRichTextListStyleDefinition(const wxString& name = wxEmptyString): | |
188 | wxRichTextParagraphStyleDefinition(name) { Init(); } | |
189 | ||
190 | /// Destructor | |
191 | virtual ~wxRichTextListStyleDefinition() {} | |
192 | ||
193 | /// Copies from def | |
194 | void Copy(const wxRichTextListStyleDefinition& def); | |
195 | ||
196 | /// Assignment operator | |
197 | void operator =(const wxRichTextListStyleDefinition& def) { Copy(def); } | |
198 | ||
199 | /// Equality operator | |
200 | bool operator ==(const wxRichTextListStyleDefinition& def) const; | |
201 | ||
202 | /// Clones the object | |
203 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextListStyleDefinition(*this); } | |
204 | ||
205 | /// Sets/gets the attributes for the given level | |
d2d0adc7 JS |
206 | void SetLevelAttributes(int i, const wxRichTextAttr& attr); |
207 | wxRichTextAttr* GetLevelAttributes(int i); | |
208 | const wxRichTextAttr* GetLevelAttributes(int i) const; | |
38f833b1 JS |
209 | |
210 | /// Convenience function for setting the major attributes for a list level specification | |
211 | void SetAttributes(int i, int leftIndent, int leftSubIndent, int bulletStyle, const wxString& bulletSymbol = wxEmptyString); | |
212 | ||
213 | /// Finds the level corresponding to the given indentation | |
214 | int FindLevelForIndent(int indent) const; | |
215 | ||
216 | /// Combine the base and list style with a paragraph style, using the given indent (from which | |
217 | /// an appropriate level is found) | |
d2d0adc7 | 218 | wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle); |
38f833b1 JS |
219 | |
220 | /// Combine the base and list style, using the given indent (from which | |
221 | /// an appropriate level is found) | |
d2d0adc7 | 222 | wxRichTextAttr GetCombinedStyle(int indent); |
38f833b1 JS |
223 | |
224 | /// Combine the base and list style, using the given level from which | |
225 | /// an appropriate level is found) | |
d2d0adc7 | 226 | wxRichTextAttr GetCombinedStyleForLevel(int level); |
38f833b1 JS |
227 | |
228 | /// Gets the number of available levels | |
229 | int GetLevelCount() const { return 10; } | |
230 | ||
231 | /// Is this a numbered list? | |
232 | bool IsNumbered(int i) const; | |
233 | ||
234 | protected: | |
235 | ||
236 | /// The styles for each level (up to 10) | |
d2d0adc7 | 237 | wxRichTextAttr m_levelStyles[10]; |
38f833b1 JS |
238 | }; |
239 | ||
5d7836c4 JS |
240 | /*! |
241 | * The style sheet | |
242 | */ | |
243 | ||
3b2cb431 | 244 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet: public wxObject |
5d7836c4 JS |
245 | { |
246 | DECLARE_CLASS( wxRichTextStyleSheet ) | |
247 | ||
248 | public: | |
249 | /// Constructors | |
b3298d1d WS |
250 | wxRichTextStyleSheet(const wxRichTextStyleSheet& sheet) |
251 | : wxObject() | |
252 | { | |
253 | Copy(sheet); | |
254 | } | |
5d7836c4 | 255 | wxRichTextStyleSheet() { Init(); } |
38f833b1 | 256 | virtual ~wxRichTextStyleSheet(); |
5d7836c4 JS |
257 | |
258 | /// Initialisation | |
259 | void Init(); | |
260 | ||
fe5aa22c JS |
261 | /// Copy |
262 | void Copy(const wxRichTextStyleSheet& sheet); | |
263 | ||
264 | /// Assignment | |
265 | void operator=(const wxRichTextStyleSheet& sheet) { Copy(sheet); } | |
266 | ||
267 | /// Equality | |
268 | bool operator==(const wxRichTextStyleSheet& sheet) const; | |
269 | ||
5d7836c4 | 270 | /// Add a definition to the character style list |
fe5aa22c | 271 | bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def); |
5d7836c4 JS |
272 | |
273 | /// Add a definition to the paragraph style list | |
fe5aa22c | 274 | bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def); |
5d7836c4 | 275 | |
38f833b1 JS |
276 | /// Add a definition to the list style list |
277 | bool AddListStyle(wxRichTextListStyleDefinition* def); | |
278 | ||
5d7836c4 JS |
279 | /// Remove a character style |
280 | bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); } | |
281 | ||
282 | /// Remove a paragraph style | |
fe5aa22c | 283 | bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_paragraphStyleDefinitions, def, deleteStyle); } |
5d7836c4 | 284 | |
38f833b1 JS |
285 | /// Remove a list style |
286 | bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); } | |
287 | ||
5d7836c4 | 288 | /// Find a character definition by name |
38f833b1 | 289 | wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); } |
5d7836c4 JS |
290 | |
291 | /// Find a paragraph definition by name | |
38f833b1 | 292 | wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, bool recurse = true) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name, recurse); } |
5d7836c4 | 293 | |
38f833b1 JS |
294 | /// Find a list definition by name |
295 | wxRichTextListStyleDefinition* FindListStyle(const wxString& name, bool recurse = true) const { return (wxRichTextListStyleDefinition*) FindStyle(m_listStyleDefinitions, name, recurse); } | |
296 | ||
297 | /// Return the number of character styles | |
5d7836c4 JS |
298 | size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); } |
299 | ||
38f833b1 | 300 | /// Return the number of paragraph styles |
5d7836c4 JS |
301 | size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); } |
302 | ||
38f833b1 JS |
303 | /// Return the number of list styles |
304 | size_t GetListStyleCount() const { return m_listStyleDefinitions.GetCount(); } | |
305 | ||
5d7836c4 JS |
306 | /// Return the nth character style |
307 | wxRichTextCharacterStyleDefinition* GetCharacterStyle(size_t n) const { return (wxRichTextCharacterStyleDefinition*) m_characterStyleDefinitions.Item(n)->GetData(); } | |
308 | ||
309 | /// Return the nth paragraph style | |
310 | wxRichTextParagraphStyleDefinition* GetParagraphStyle(size_t n) const { return (wxRichTextParagraphStyleDefinition*) m_paragraphStyleDefinitions.Item(n)->GetData(); } | |
311 | ||
38f833b1 JS |
312 | /// Return the nth list style |
313 | wxRichTextListStyleDefinition* GetListStyle(size_t n) const { return (wxRichTextListStyleDefinition*) m_listStyleDefinitions.Item(n)->GetData(); } | |
314 | ||
5d7836c4 JS |
315 | /// Delete all styles |
316 | void DeleteStyles(); | |
317 | ||
38f833b1 JS |
318 | /// Insert into list of style sheets |
319 | bool InsertSheet(wxRichTextStyleSheet* before); | |
320 | ||
321 | /// Append to list of style sheets | |
322 | bool AppendSheet(wxRichTextStyleSheet* after); | |
323 | ||
324 | /// Unlink from the list of style sheets | |
325 | void Unlink(); | |
326 | ||
327 | /// Get/set next sheet | |
328 | wxRichTextStyleSheet* GetNextSheet() const { return m_nextSheet; } | |
329 | void SetNextSheet(wxRichTextStyleSheet* sheet) { m_nextSheet = sheet; } | |
330 | ||
331 | /// Get/set previous sheet | |
332 | wxRichTextStyleSheet* GetPreviousSheet() const { return m_previousSheet; } | |
333 | void SetPreviousSheet(wxRichTextStyleSheet* sheet) { m_previousSheet = sheet; } | |
334 | ||
42688aea JS |
335 | /// Sets and gets the name of the style sheet |
336 | void SetName(const wxString& name) { m_name = name; } | |
337 | const wxString& GetName() const { return m_name; } | |
338 | ||
339 | /// Sets and gets the style description | |
340 | void SetDescription(const wxString& descr) { m_description = descr; } | |
341 | const wxString& GetDescription() const { return m_description; } | |
342 | ||
5d7836c4 JS |
343 | /// Implementation |
344 | ||
345 | /// Add a definition to one of the style lists | |
346 | bool AddStyle(wxList& list, wxRichTextStyleDefinition* def); | |
347 | ||
348 | /// Remove a style | |
349 | bool RemoveStyle(wxList& list, wxRichTextStyleDefinition* def, bool deleteStyle); | |
350 | ||
351 | /// Find a definition by name | |
38f833b1 | 352 | wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const; |
5d7836c4 JS |
353 | |
354 | protected: | |
355 | ||
42688aea JS |
356 | wxString m_description; |
357 | wxString m_name; | |
358 | ||
359 | wxList m_characterStyleDefinitions; | |
360 | wxList m_paragraphStyleDefinitions; | |
361 | wxList m_listStyleDefinitions; | |
38f833b1 | 362 | |
42688aea JS |
363 | wxRichTextStyleSheet* m_previousSheet; |
364 | wxRichTextStyleSheet* m_nextSheet; | |
5d7836c4 JS |
365 | }; |
366 | ||
367 | #if wxUSE_HTML | |
368 | /*! | |
369 | * wxRichTextStyleListBox class declaration | |
370 | * A listbox to display styles. | |
371 | */ | |
372 | ||
3b2cb431 | 373 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox |
5d7836c4 JS |
374 | { |
375 | DECLARE_CLASS(wxRichTextStyleListBox) | |
376 | DECLARE_EVENT_TABLE() | |
377 | ||
378 | public: | |
38f833b1 JS |
379 | /// Which type of style definition is currently showing? |
380 | enum wxRichTextStyleType | |
381 | { | |
382 | wxRICHTEXT_STYLE_ALL, | |
383 | wxRICHTEXT_STYLE_PARAGRAPH, | |
384 | wxRICHTEXT_STYLE_CHARACTER, | |
385 | wxRICHTEXT_STYLE_LIST | |
386 | }; | |
387 | ||
e637208a JS |
388 | wxRichTextStyleListBox() |
389 | { | |
390 | Init(); | |
391 | } | |
5d7836c4 JS |
392 | wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
393 | const wxSize& size = wxDefaultSize, long style = 0); | |
d3c7fc99 | 394 | virtual ~wxRichTextStyleListBox(); |
5d7836c4 | 395 | |
e637208a JS |
396 | void Init() |
397 | { | |
398 | m_styleSheet = NULL; | |
399 | m_richTextCtrl = NULL; | |
38f833b1 JS |
400 | m_applyOnSelection = false; |
401 | m_styleType = wxRICHTEXT_STYLE_PARAGRAPH; | |
dadd4f55 | 402 | m_autoSetSelection = true; |
e637208a JS |
403 | } |
404 | ||
405 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
406 | const wxSize& size = wxDefaultSize, long style = 0); | |
407 | ||
5d7836c4 JS |
408 | /// Creates a suitable HTML fragment for a definition |
409 | wxString CreateHTML(wxRichTextStyleDefinition* def) const; | |
410 | ||
1f65137f | 411 | /// Associates the control with a style sheet |
5d7836c4 JS |
412 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; } |
413 | wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; } | |
414 | ||
415 | /// Associates the control with a wxRichTextCtrl | |
416 | void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_richTextCtrl = ctrl; } | |
417 | wxRichTextCtrl* GetRichTextCtrl() const { return m_richTextCtrl; } | |
418 | ||
e637208a | 419 | /// Get style for index |
5d7836c4 JS |
420 | wxRichTextStyleDefinition* GetStyle(size_t i) const ; |
421 | ||
e637208a JS |
422 | /// Get index for style name |
423 | int GetIndexForStyle(const wxString& name) const ; | |
424 | ||
425 | /// Set selection for string, returning the index. | |
426 | int SetStyleSelection(const wxString& name); | |
427 | ||
5d7836c4 JS |
428 | /// Updates the list |
429 | void UpdateStyles(); | |
430 | ||
86015e55 JS |
431 | /// Apply the style |
432 | void ApplyStyle(int i); | |
e637208a | 433 | |
5d7836c4 JS |
434 | /// Left click |
435 | void OnLeftDown(wxMouseEvent& event); | |
436 | ||
38f833b1 JS |
437 | /// Left double-click |
438 | void OnLeftDoubleClick(wxMouseEvent& event); | |
439 | ||
e637208a JS |
440 | /// Auto-select from style under caret in idle time |
441 | void OnIdle(wxIdleEvent& event); | |
442 | ||
e637208a | 443 | /// Convert units in tends of a millimetre to device units |
5d7836c4 JS |
444 | int ConvertTenthsMMToPixels(wxDC& dc, int units) const; |
445 | ||
e637208a JS |
446 | /// Can we set the selection based on the editor caret position? |
447 | /// Need to override this if being used in a combobox popup | |
dadd4f55 JS |
448 | virtual bool CanAutoSetSelection() { return m_autoSetSelection; } |
449 | virtual void SetAutoSetSelection(bool autoSet) { m_autoSetSelection = autoSet; } | |
e637208a | 450 | |
86015e55 JS |
451 | /// Set whether the style should be applied as soon as the item is selected (the default) |
452 | void SetApplyOnSelection(bool applyOnSel) { m_applyOnSelection = applyOnSel; } | |
453 | bool GetApplyOnSelection() const { return m_applyOnSelection; } | |
454 | ||
38f833b1 JS |
455 | /// Set the style type to display |
456 | void SetStyleType(wxRichTextStyleType styleType) { m_styleType = styleType; UpdateStyles(); } | |
457 | wxRichTextStyleType GetStyleType() const { return m_styleType; } | |
458 | ||
459 | /// Helper for listbox and combo control | |
460 | static wxString GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType); | |
461 | ||
6f02a879 VZ |
462 | protected: |
463 | /// Returns the HTML for this item | |
464 | virtual wxString OnGetItem(size_t n) const; | |
465 | ||
5d7836c4 JS |
466 | private: |
467 | ||
468 | wxRichTextStyleSheet* m_styleSheet; | |
469 | wxRichTextCtrl* m_richTextCtrl; | |
86015e55 | 470 | bool m_applyOnSelection; // if true, applies style on selection |
38f833b1 | 471 | wxRichTextStyleType m_styleType; // style type to display |
dadd4f55 | 472 | bool m_autoSetSelection; |
38f833b1 JS |
473 | }; |
474 | ||
475 | /*! | |
476 | * wxRichTextStyleListCtrl class declaration | |
477 | * This is a container for the list control plus a combobox to switch between | |
478 | * style types. | |
479 | */ | |
480 | ||
dadd4f55 JS |
481 | #define wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR 0x1000 |
482 | ||
38f833b1 JS |
483 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListCtrl: public wxControl |
484 | { | |
485 | DECLARE_CLASS(wxRichTextStyleListCtrl) | |
486 | DECLARE_EVENT_TABLE() | |
487 | ||
488 | public: | |
489 | ||
490 | /// Constructors | |
491 | wxRichTextStyleListCtrl() | |
492 | { | |
493 | Init(); | |
494 | } | |
495 | ||
496 | wxRichTextStyleListCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
497 | const wxSize& size = wxDefaultSize, long style = 0); | |
498 | ||
499 | /// Constructors | |
500 | virtual ~wxRichTextStyleListCtrl(); | |
501 | ||
502 | /// Member initialisation | |
503 | void Init() | |
504 | { | |
505 | m_styleListBox = NULL; | |
506 | m_styleChoice = NULL; | |
507 | m_dontUpdate = false; | |
508 | } | |
509 | ||
510 | /// Creates the windows | |
511 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
512 | const wxSize& size = wxDefaultSize, long style = 0); | |
513 | ||
dadd4f55 JS |
514 | /// Updates the style list box |
515 | void UpdateStyles(); | |
516 | ||
1f65137f | 517 | /// Associates the control with a style sheet |
38f833b1 JS |
518 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet); |
519 | wxRichTextStyleSheet* GetStyleSheet() const; | |
520 | ||
521 | /// Associates the control with a wxRichTextCtrl | |
522 | void SetRichTextCtrl(wxRichTextCtrl* ctrl); | |
523 | wxRichTextCtrl* GetRichTextCtrl() const; | |
524 | ||
38f833b1 JS |
525 | /// Set/get the style type to display |
526 | void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType); | |
527 | wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const; | |
528 | ||
529 | /// Get the choice index for style type | |
530 | int StyleTypeToIndex(wxRichTextStyleListBox::wxRichTextStyleType styleType); | |
531 | ||
532 | /// Get the style type for choice index | |
533 | wxRichTextStyleListBox::wxRichTextStyleType StyleIndexToType(int i); | |
534 | ||
535 | /// Get the listbox | |
536 | wxRichTextStyleListBox* GetStyleListBox() const { return m_styleListBox; } | |
537 | ||
538 | /// Get the choice | |
539 | wxChoice* GetStyleChoice() const { return m_styleChoice; } | |
540 | ||
541 | /// React to style type choice | |
542 | void OnChooseType(wxCommandEvent& event); | |
543 | ||
544 | /// Lay out the controls | |
545 | void OnSize(wxSizeEvent& event); | |
546 | ||
547 | private: | |
548 | ||
549 | wxRichTextStyleListBox* m_styleListBox; | |
550 | wxChoice* m_styleChoice; | |
551 | bool m_dontUpdate; | |
5d7836c4 | 552 | }; |
e637208a JS |
553 | |
554 | #if wxUSE_COMBOCTRL | |
555 | ||
556 | /*! | |
557 | * Style drop-down for a wxComboCtrl | |
558 | */ | |
559 | ||
560 | class wxRichTextStyleComboPopup : public wxRichTextStyleListBox, public wxComboPopup | |
561 | { | |
562 | public: | |
563 | virtual void Init() | |
564 | { | |
565 | m_itemHere = -1; // hot item in list | |
566 | m_value = -1; | |
567 | } | |
568 | ||
569 | virtual bool Create( wxWindow* parent ) | |
570 | { | |
571 | return wxRichTextStyleListBox::Create(parent, wxID_ANY, | |
572 | wxPoint(0,0), wxDefaultSize, | |
573 | wxSIMPLE_BORDER); | |
574 | } | |
575 | ||
576 | virtual wxWindow *GetControl() { return this; } | |
577 | ||
578 | virtual void SetStringValue( const wxString& s ); | |
579 | ||
580 | virtual wxString GetStringValue() const; | |
581 | ||
582 | /// Can we set the selection based on the editor caret position? | |
583 | // virtual bool CanAutoSetSelection() { return ((m_combo == NULL) || !m_combo->IsPopupShown()); } | |
584 | virtual bool CanAutoSetSelection() { return false; } | |
585 | ||
586 | // | |
587 | // Popup event handlers | |
588 | // | |
589 | ||
590 | // Mouse hot-tracking | |
591 | void OnMouseMove(wxMouseEvent& event); | |
592 | ||
593 | // On mouse left, set the value and close the popup | |
594 | void OnMouseClick(wxMouseEvent& WXUNUSED(event)); | |
595 | ||
596 | protected: | |
597 | ||
598 | int m_itemHere; // hot item in popup | |
599 | int m_value; | |
600 | ||
601 | private: | |
602 | DECLARE_EVENT_TABLE() | |
603 | }; | |
604 | ||
605 | /*! | |
606 | * wxRichTextStyleComboCtrl | |
607 | * A combo for applying styles. | |
608 | */ | |
609 | ||
610 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleComboCtrl: public wxComboCtrl | |
611 | { | |
612 | DECLARE_CLASS(wxRichTextStyleComboCtrl) | |
613 | DECLARE_EVENT_TABLE() | |
614 | ||
615 | public: | |
616 | wxRichTextStyleComboCtrl() | |
617 | { | |
618 | Init(); | |
619 | } | |
620 | ||
621 | wxRichTextStyleComboCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
622 | const wxSize& size = wxDefaultSize, long style = wxCB_READONLY) | |
623 | { | |
624 | Init(); | |
625 | Create(parent, id, pos, size, style); | |
626 | } | |
627 | ||
628 | virtual ~wxRichTextStyleComboCtrl() {} | |
629 | ||
630 | void Init() | |
631 | { | |
632 | m_stylePopup = NULL; | |
633 | } | |
634 | ||
635 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
636 | const wxSize& size = wxDefaultSize, long style = 0); | |
637 | ||
638 | /// Updates the list | |
639 | void UpdateStyles() { m_stylePopup->UpdateStyles(); } | |
640 | ||
1f65137f | 641 | /// Associates the control with a style sheet |
e637208a JS |
642 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_stylePopup->SetStyleSheet(styleSheet); } |
643 | wxRichTextStyleSheet* GetStyleSheet() const { return m_stylePopup->GetStyleSheet(); } | |
644 | ||
645 | /// Associates the control with a wxRichTextCtrl | |
646 | void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_stylePopup->SetRichTextCtrl(ctrl); } | |
647 | wxRichTextCtrl* GetRichTextCtrl() const { return m_stylePopup->GetRichTextCtrl(); } | |
648 | ||
649 | /// Gets the style popup | |
650 | wxRichTextStyleComboPopup* GetStylePopup() const { return m_stylePopup; } | |
651 | ||
652 | /// Auto-select from style under caret in idle time | |
653 | void OnIdle(wxIdleEvent& event); | |
654 | ||
655 | protected: | |
656 | wxRichTextStyleComboPopup* m_stylePopup; | |
657 | }; | |
658 | ||
659 | #endif | |
660 | // wxUSE_COMBOCTRL | |
661 | ||
5d7836c4 | 662 | #endif |
e637208a | 663 | // wxUSE_HTML |
5d7836c4 JS |
664 | |
665 | #endif | |
666 | // wxUSE_RICHTEXT | |
667 | ||
668 | #endif | |
669 | // _WX_RICHTEXTSTYLES_H_ |