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