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