]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/richtext/richtextstyles.h | |
3 | // Purpose: Style management for wxRichTextCtrl | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 2005-09-30 | |
7 | // RCS-ID: $Id$ | |
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 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_RICHTEXT | |
22 | ||
23 | #include "wx/richtext/richtextbuffer.h" | |
24 | ||
25 | #if wxUSE_HTML | |
26 | #include "wx/htmllbox.h" | |
27 | #endif | |
28 | ||
29 | #if wxUSE_COMBOCTRL | |
30 | #include "wx/combo.h" | |
31 | #endif | |
32 | ||
33 | #include "wx/choice.h" | |
34 | ||
35 | /*! | |
36 | * Forward declarations | |
37 | */ | |
38 | ||
39 | class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl; | |
40 | class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer; | |
41 | ||
42 | /*! | |
43 | * wxRichTextStyleDefinition class declaration | |
44 | * A base class for paragraph and character styles. | |
45 | */ | |
46 | ||
47 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition: public wxObject | |
48 | { | |
49 | DECLARE_CLASS(wxRichTextStyleDefinition) | |
50 | public: | |
51 | ||
52 | /// Copy constructors | |
53 | wxRichTextStyleDefinition(const wxRichTextStyleDefinition& def) | |
54 | : wxObject() | |
55 | { | |
56 | Init(); | |
57 | Copy(def); | |
58 | } | |
59 | ||
60 | /// Default constructor | |
61 | wxRichTextStyleDefinition(const wxString& name = wxEmptyString) { Init(); m_name = name; } | |
62 | ||
63 | /// Destructor | |
64 | virtual ~wxRichTextStyleDefinition() {} | |
65 | ||
66 | /// Initialises members | |
67 | void Init() {} | |
68 | ||
69 | /// Copies from def | |
70 | void Copy(const wxRichTextStyleDefinition& def); | |
71 | ||
72 | /// Equality test | |
73 | bool Eq(const wxRichTextStyleDefinition& def) const; | |
74 | ||
75 | /// Assignment operator | |
76 | void operator =(const wxRichTextStyleDefinition& def) { Copy(def); } | |
77 | ||
78 | /// Equality operator | |
79 | bool operator ==(const wxRichTextStyleDefinition& def) const { return Eq(def); } | |
80 | ||
81 | /// Override to clone the object | |
82 | virtual wxRichTextStyleDefinition* Clone() const = 0; | |
83 | ||
84 | /// Sets and gets the name of the style | |
85 | void SetName(const wxString& name) { m_name = name; } | |
86 | const wxString& GetName() const { return m_name; } | |
87 | ||
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 | ||
92 | /// Sets and gets the name of the style that this style is based on | |
93 | void SetBaseStyle(const wxString& name) { m_baseStyle = name; } | |
94 | const wxString& GetBaseStyle() const { return m_baseStyle; } | |
95 | ||
96 | /// Sets the style | |
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; | |
104 | wxString m_description; | |
105 | wxRichTextAttr m_style; | |
106 | }; | |
107 | ||
108 | /*! | |
109 | * wxRichTextCharacterStyleDefinition class declaration | |
110 | */ | |
111 | ||
112 | class WXDLLIMPEXP_RICHTEXT wxRichTextCharacterStyleDefinition: public wxRichTextStyleDefinition | |
113 | { | |
114 | DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition) | |
115 | public: | |
116 | ||
117 | /// Copy constructor | |
118 | wxRichTextCharacterStyleDefinition(const wxRichTextCharacterStyleDefinition& def): wxRichTextStyleDefinition(def) {} | |
119 | ||
120 | /// Default constructor | |
121 | wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString): | |
122 | wxRichTextStyleDefinition(name) {} | |
123 | ||
124 | /// Destructor | |
125 | virtual ~wxRichTextCharacterStyleDefinition() {} | |
126 | ||
127 | /// Clones the object | |
128 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextCharacterStyleDefinition(*this); } | |
129 | ||
130 | protected: | |
131 | }; | |
132 | ||
133 | /*! | |
134 | * wxRichTextParagraphStyleDefinition class declaration | |
135 | */ | |
136 | ||
137 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphStyleDefinition: public wxRichTextStyleDefinition | |
138 | { | |
139 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition) | |
140 | public: | |
141 | ||
142 | /// Copy constructor | |
143 | wxRichTextParagraphStyleDefinition(const wxRichTextParagraphStyleDefinition& def): wxRichTextStyleDefinition(def) { m_nextStyle = def.m_nextStyle; } | |
144 | ||
145 | /// Default constructor | |
146 | wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString): | |
147 | wxRichTextStyleDefinition(name) {} | |
148 | ||
149 | // Destructor | |
150 | virtual ~wxRichTextParagraphStyleDefinition() {} | |
151 | ||
152 | /// Sets and gets the next style | |
153 | void SetNextStyle(const wxString& name) { m_nextStyle = name; } | |
154 | const wxString& GetNextStyle() const { return m_nextStyle; } | |
155 | ||
156 | /// Copies from def | |
157 | void Copy(const wxRichTextParagraphStyleDefinition& def); | |
158 | ||
159 | /// Assignment operator | |
160 | void operator =(const wxRichTextParagraphStyleDefinition& def) { Copy(def); } | |
161 | ||
162 | /// Equality operator | |
163 | bool operator ==(const wxRichTextParagraphStyleDefinition& def) const; | |
164 | ||
165 | /// Clones the object | |
166 | virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextParagraphStyleDefinition(*this); } | |
167 | ||
168 | protected: | |
169 | ||
170 | /// The next style to use when adding a paragraph after this style. | |
171 | wxString m_nextStyle; | |
172 | }; | |
173 | ||
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 | |
206 | void SetLevelAttributes(int i, const wxRichTextAttr& attr); | |
207 | wxRichTextAttr* GetLevelAttributes(int i); | |
208 | const wxRichTextAttr* GetLevelAttributes(int i) const; | |
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) | |
218 | wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle); | |
219 | ||
220 | /// Combine the base and list style, using the given indent (from which | |
221 | /// an appropriate level is found) | |
222 | wxRichTextAttr GetCombinedStyle(int indent); | |
223 | ||
224 | /// Combine the base and list style, using the given level from which | |
225 | /// an appropriate level is found) | |
226 | wxRichTextAttr GetCombinedStyleForLevel(int level); | |
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) | |
237 | wxRichTextAttr m_levelStyles[10]; | |
238 | }; | |
239 | ||
240 | /*! | |
241 | * The style sheet | |
242 | */ | |
243 | ||
244 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet: public wxObject | |
245 | { | |
246 | DECLARE_CLASS( wxRichTextStyleSheet ) | |
247 | ||
248 | public: | |
249 | /// Constructors | |
250 | wxRichTextStyleSheet(const wxRichTextStyleSheet& sheet) | |
251 | : wxObject() | |
252 | { | |
253 | Copy(sheet); | |
254 | } | |
255 | wxRichTextStyleSheet() { Init(); } | |
256 | virtual ~wxRichTextStyleSheet(); | |
257 | ||
258 | /// Initialisation | |
259 | void Init(); | |
260 | ||
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 | ||
270 | /// Add a definition to the character style list | |
271 | bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def); | |
272 | ||
273 | /// Add a definition to the paragraph style list | |
274 | bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def); | |
275 | ||
276 | /// Add a definition to the list style list | |
277 | bool AddListStyle(wxRichTextListStyleDefinition* def); | |
278 | ||
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 | |
283 | bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_paragraphStyleDefinitions, def, deleteStyle); } | |
284 | ||
285 | /// Remove a list style | |
286 | bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); } | |
287 | ||
288 | /// Find a character definition by name | |
289 | wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); } | |
290 | ||
291 | /// Find a paragraph definition by name | |
292 | wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, bool recurse = true) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name, recurse); } | |
293 | ||
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 | |
298 | size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); } | |
299 | ||
300 | /// Return the number of paragraph styles | |
301 | size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); } | |
302 | ||
303 | /// Return the number of list styles | |
304 | size_t GetListStyleCount() const { return m_listStyleDefinitions.GetCount(); } | |
305 | ||
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 | ||
312 | /// Return the nth list style | |
313 | wxRichTextListStyleDefinition* GetListStyle(size_t n) const { return (wxRichTextListStyleDefinition*) m_listStyleDefinitions.Item(n)->GetData(); } | |
314 | ||
315 | /// Delete all styles | |
316 | void DeleteStyles(); | |
317 | ||
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 | ||
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 | ||
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 | |
352 | wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const; | |
353 | ||
354 | protected: | |
355 | ||
356 | wxString m_description; | |
357 | wxString m_name; | |
358 | ||
359 | wxList m_characterStyleDefinitions; | |
360 | wxList m_paragraphStyleDefinitions; | |
361 | wxList m_listStyleDefinitions; | |
362 | ||
363 | wxRichTextStyleSheet* m_previousSheet; | |
364 | wxRichTextStyleSheet* m_nextSheet; | |
365 | }; | |
366 | ||
367 | #if wxUSE_HTML | |
368 | /*! | |
369 | * wxRichTextStyleListBox class declaration | |
370 | * A listbox to display styles. | |
371 | */ | |
372 | ||
373 | class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox | |
374 | { | |
375 | DECLARE_CLASS(wxRichTextStyleListBox) | |
376 | DECLARE_EVENT_TABLE() | |
377 | ||
378 | public: | |
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 | ||
388 | wxRichTextStyleListBox() | |
389 | { | |
390 | Init(); | |
391 | } | |
392 | wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
393 | const wxSize& size = wxDefaultSize, long style = 0); | |
394 | virtual ~wxRichTextStyleListBox(); | |
395 | ||
396 | void Init() | |
397 | { | |
398 | m_styleSheet = NULL; | |
399 | m_richTextCtrl = NULL; | |
400 | m_applyOnSelection = false; | |
401 | m_styleType = wxRICHTEXT_STYLE_PARAGRAPH; | |
402 | m_autoSetSelection = true; | |
403 | } | |
404 | ||
405 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
406 | const wxSize& size = wxDefaultSize, long style = 0); | |
407 | ||
408 | /// Creates a suitable HTML fragment for a definition | |
409 | wxString CreateHTML(wxRichTextStyleDefinition* def) const; | |
410 | ||
411 | /// Associates the control with a style sheet | |
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 | ||
419 | /// Get style for index | |
420 | wxRichTextStyleDefinition* GetStyle(size_t i) const ; | |
421 | ||
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 | ||
428 | /// Updates the list | |
429 | void UpdateStyles(); | |
430 | ||
431 | /// Apply the style | |
432 | void ApplyStyle(int i); | |
433 | ||
434 | /// Left click | |
435 | void OnLeftDown(wxMouseEvent& event); | |
436 | ||
437 | /// Left double-click | |
438 | void OnLeftDoubleClick(wxMouseEvent& event); | |
439 | ||
440 | /// Auto-select from style under caret in idle time | |
441 | void OnIdle(wxIdleEvent& event); | |
442 | ||
443 | /// Convert units in tends of a millimetre to device units | |
444 | int ConvertTenthsMMToPixels(wxDC& dc, int units) const; | |
445 | ||
446 | /// Can we set the selection based on the editor caret position? | |
447 | /// Need to override this if being used in a combobox popup | |
448 | virtual bool CanAutoSetSelection() { return m_autoSetSelection; } | |
449 | virtual void SetAutoSetSelection(bool autoSet) { m_autoSetSelection = autoSet; } | |
450 | ||
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 | ||
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 | ||
462 | protected: | |
463 | /// Returns the HTML for this item | |
464 | virtual wxString OnGetItem(size_t n) const; | |
465 | ||
466 | private: | |
467 | ||
468 | wxRichTextStyleSheet* m_styleSheet; | |
469 | wxRichTextCtrl* m_richTextCtrl; | |
470 | bool m_applyOnSelection; // if true, applies style on selection | |
471 | wxRichTextStyleType m_styleType; // style type to display | |
472 | bool m_autoSetSelection; | |
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 | ||
481 | #define wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR 0x1000 | |
482 | ||
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 | ||
514 | /// Updates the style list box | |
515 | void UpdateStyles(); | |
516 | ||
517 | /// Associates the control with a style sheet | |
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 | ||
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; | |
552 | }; | |
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 | ||
641 | /// Associates the control with a style sheet | |
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 | ||
662 | #endif | |
663 | // wxUSE_HTML | |
664 | ||
665 | #endif | |
666 | // wxUSE_RICHTEXT | |
667 | ||
668 | #endif | |
669 | // _WX_RICHTEXTSTYLES_H_ |