]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextstyles.h
Fix wrong tab order in wxAuiNotebook after dragging.
[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 // 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_FWD_RICHTEXT wxRichTextCtrl;
40 class WXDLLIMPEXP_FWD_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 and gets 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 /// Gets the style combined with the base style
102 virtual wxRichTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const;
103
104 /**
105 Returns the definition's properties.
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 /**
115 Sets the definition's properties.
116 */
117 void SetProperties(const wxRichTextProperties& props) { m_properties = props; }
118
119 protected:
120 wxString m_name;
121 wxString m_baseStyle;
122 wxString m_description;
123 wxRichTextAttr m_style;
124 wxRichTextProperties m_properties;
125 };
126
127 /*!
128 * wxRichTextCharacterStyleDefinition class declaration
129 */
130
131 class WXDLLIMPEXP_RICHTEXT wxRichTextCharacterStyleDefinition: public wxRichTextStyleDefinition
132 {
133 DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition)
134 public:
135
136 /// Copy constructor
137 wxRichTextCharacterStyleDefinition(const wxRichTextCharacterStyleDefinition& def): wxRichTextStyleDefinition(def) {}
138
139 /// Default constructor
140 wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString):
141 wxRichTextStyleDefinition(name) {}
142
143 /// Destructor
144 virtual ~wxRichTextCharacterStyleDefinition() {}
145
146 /// Clones the object
147 virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextCharacterStyleDefinition(*this); }
148
149 protected:
150 };
151
152 /*!
153 * wxRichTextParagraphStyleDefinition class declaration
154 */
155
156 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphStyleDefinition: public wxRichTextStyleDefinition
157 {
158 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition)
159 public:
160
161 /// Copy constructor
162 wxRichTextParagraphStyleDefinition(const wxRichTextParagraphStyleDefinition& def): wxRichTextStyleDefinition(def) { m_nextStyle = def.m_nextStyle; }
163
164 /// Default constructor
165 wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString):
166 wxRichTextStyleDefinition(name) {}
167
168 // Destructor
169 virtual ~wxRichTextParagraphStyleDefinition() {}
170
171 /// Sets and gets the next style
172 void SetNextStyle(const wxString& name) { m_nextStyle = name; }
173 const wxString& GetNextStyle() const { return m_nextStyle; }
174
175 /// Copies from def
176 void Copy(const wxRichTextParagraphStyleDefinition& def);
177
178 /// Assignment operator
179 void operator =(const wxRichTextParagraphStyleDefinition& def) { Copy(def); }
180
181 /// Equality operator
182 bool operator ==(const wxRichTextParagraphStyleDefinition& def) const;
183
184 /// Clones the object
185 virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextParagraphStyleDefinition(*this); }
186
187 protected:
188
189 /// The next style to use when adding a paragraph after this style.
190 wxString m_nextStyle;
191 };
192
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
225 void SetLevelAttributes(int i, const wxRichTextAttr& attr);
226 wxRichTextAttr* GetLevelAttributes(int i);
227 const wxRichTextAttr* GetLevelAttributes(int i) const;
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)
237 wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle, wxRichTextStyleSheet* styleSheet = NULL);
238
239 /// Combine the base and list style, using the given indent (from which
240 /// an appropriate level is found)
241 wxRichTextAttr GetCombinedStyle(int indent, wxRichTextStyleSheet* styleSheet = NULL);
242
243 /// Combine the base and list style, using the given level from which
244 /// an appropriate level is found)
245 wxRichTextAttr GetCombinedStyleForLevel(int level, wxRichTextStyleSheet* styleSheet = NULL);
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)
256 wxRichTextAttr m_levelStyles[10];
257 };
258
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
269 wxRichTextBoxStyleDefinition(const wxRichTextBoxStyleDefinition& def): wxRichTextStyleDefinition(def) { Copy(def); }
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
293 /*!
294 * The style sheet
295 */
296
297 class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet: public wxObject
298 {
299 DECLARE_CLASS( wxRichTextStyleSheet )
300
301 public:
302 /// Constructors
303 wxRichTextStyleSheet(const wxRichTextStyleSheet& sheet)
304 : wxObject()
305 {
306 Init();
307 Copy(sheet);
308 }
309 wxRichTextStyleSheet() { Init(); }
310 virtual ~wxRichTextStyleSheet();
311
312 /// Initialisation
313 void Init();
314
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
324 /// Add a definition to the character style list
325 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def);
326
327 /// Add a definition to the paragraph style list
328 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def);
329
330 /// Add a definition to the list style list
331 bool AddListStyle(wxRichTextListStyleDefinition* def);
332
333 /// Add a definition to the box style list
334 bool AddBoxStyle(wxRichTextBoxStyleDefinition* def);
335
336 /// Add a definition to the appropriate style list
337 bool AddStyle(wxRichTextStyleDefinition* def);
338
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
343 bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_paragraphStyleDefinitions, def, deleteStyle); }
344
345 /// Remove a list style
346 bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); }
347
348 /// Remove a box style
349 bool RemoveBoxStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_boxStyleDefinitions, def, deleteStyle); }
350
351 /// Remove a style
352 bool RemoveStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false);
353
354 /// Find a character definition by name
355 wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); }
356
357 /// Find a paragraph definition by name
358 wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, bool recurse = true) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name, recurse); }
359
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
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
366 /// Find any definition by name
367 wxRichTextStyleDefinition* FindStyle(const wxString& name, bool recurse = true) const;
368
369 /// Return the number of character styles
370 size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); }
371
372 /// Return the number of paragraph styles
373 size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); }
374
375 /// Return the number of list styles
376 size_t GetListStyleCount() const { return m_listStyleDefinitions.GetCount(); }
377
378 /// Return the number of box styles
379 size_t GetBoxStyleCount() const { return m_boxStyleDefinitions.GetCount(); }
380
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
387 /// Return the nth list style
388 wxRichTextListStyleDefinition* GetListStyle(size_t n) const { return (wxRichTextListStyleDefinition*) m_listStyleDefinitions.Item(n)->GetData(); }
389
390 /// Return the nth box style
391 wxRichTextBoxStyleDefinition* GetBoxStyle(size_t n) const { return (wxRichTextBoxStyleDefinition*) m_boxStyleDefinitions.Item(n)->GetData(); }
392
393 /// Delete all styles
394 void DeleteStyles();
395
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
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
421 /**
422 Returns the sheet's properties.
423 */
424 wxRichTextProperties& GetProperties() { return m_properties; }
425
426 /**
427 Returns the sheet's properties.
428 */
429 const wxRichTextProperties& GetProperties() const { return m_properties; }
430
431 /**
432 Sets the sheet's properties.
433 */
434 void SetProperties(const wxRichTextProperties& props) { m_properties = props; }
435
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
445 wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const;
446
447 protected:
448
449 wxString m_description;
450 wxString m_name;
451
452 wxList m_characterStyleDefinitions;
453 wxList m_paragraphStyleDefinitions;
454 wxList m_listStyleDefinitions;
455 wxList m_boxStyleDefinitions;
456
457 wxRichTextStyleSheet* m_previousSheet;
458 wxRichTextStyleSheet* m_nextSheet;
459 wxRichTextProperties m_properties;
460 };
461
462 #if wxUSE_HTML
463 /*!
464 * wxRichTextStyleListBox class declaration
465 * A listbox to display styles.
466 */
467
468 class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox
469 {
470 DECLARE_CLASS(wxRichTextStyleListBox)
471 DECLARE_EVENT_TABLE()
472
473 public:
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,
480 wxRICHTEXT_STYLE_LIST,
481 wxRICHTEXT_STYLE_BOX
482 };
483
484 wxRichTextStyleListBox()
485 {
486 Init();
487 }
488 wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
489 const wxSize& size = wxDefaultSize, long style = 0);
490 virtual ~wxRichTextStyleListBox();
491
492 void Init()
493 {
494 m_styleSheet = NULL;
495 m_richTextCtrl = NULL;
496 m_applyOnSelection = false;
497 m_styleType = wxRICHTEXT_STYLE_PARAGRAPH;
498 m_autoSetSelection = true;
499 }
500
501 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
502 const wxSize& size = wxDefaultSize, long style = 0);
503
504 /// Creates a suitable HTML fragment for a definition
505 wxString CreateHTML(wxRichTextStyleDefinition* def) const;
506
507 /// Associates the control with a style sheet
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
515 /// Get style for index
516 wxRichTextStyleDefinition* GetStyle(size_t i) const ;
517
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
524 /// Updates the list
525 void UpdateStyles();
526
527 /// Apply the style
528 void ApplyStyle(int i);
529
530 /// Left click
531 void OnLeftDown(wxMouseEvent& event);
532
533 /// Left double-click
534 void OnLeftDoubleClick(wxMouseEvent& event);
535
536 /// Auto-select from style under caret in idle time
537 void OnIdle(wxIdleEvent& event);
538
539 /// Convert units in tends of a millimetre to device units
540 int ConvertTenthsMMToPixels(wxDC& dc, int units) const;
541
542 /// Can we set the selection based on the editor caret position?
543 /// Need to override this if being used in a combobox popup
544 virtual bool CanAutoSetSelection() { return m_autoSetSelection; }
545 virtual void SetAutoSetSelection(bool autoSet) { m_autoSetSelection = autoSet; }
546
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
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
558 protected:
559 /// Returns the HTML for this item
560 virtual wxString OnGetItem(size_t n) const;
561
562 private:
563
564 wxRichTextStyleSheet* m_styleSheet;
565 wxRichTextCtrl* m_richTextCtrl;
566 bool m_applyOnSelection; // if true, applies style on selection
567 wxRichTextStyleType m_styleType; // style type to display
568 bool m_autoSetSelection;
569 wxArrayString m_styleNames;
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
578 #define wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR 0x1000
579
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
611 /// Updates the style list box
612 void UpdateStyles();
613
614 /// Associates the control with a style sheet
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
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;
649 };
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
666 virtual bool Create( wxWindow* parent );
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
733 /// Associates the control with a style sheet
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
754 #endif
755 // wxUSE_HTML
756
757 #endif
758 // wxUSE_RICHTEXT
759
760 #endif
761 // _WX_RICHTEXTSTYLES_H_