1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtextstyles.h
3 // Purpose: Style management for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTSTYLES_H_
13 #define _WX_RICHTEXTSTYLES_H_
23 #include "wx/richtext/richtextbuffer.h"
26 #include "wx/htmllbox.h"
30 * Forward declarations
33 class WXDLLIMPEXP_ADV wxRichTextCtrl
;
34 class WXDLLIMPEXP_ADV wxRichTextBuffer
;
37 * wxRichTextStyleDefinition class declaration
38 * A base class for paragraph and character styles.
41 class WXDLLIMPEXP_ADV wxRichTextStyleDefinition
: public wxObject
43 DECLARE_CLASS(wxRichTextStyleDefinition
)
48 wxRichTextStyleDefinition(const wxString
& name
= wxEmptyString
) { Init(); m_name
= name
; }
49 ~wxRichTextStyleDefinition() {}
53 /// The name of the style.
54 void SetName(const wxString
& name
) { m_name
= name
; }
55 const wxString
& GetName() const { return m_name
; }
57 /// The name of the style that this style is based on.
58 void SetBaseStyle(const wxString
& name
) { m_baseStyle
= name
; }
59 const wxString
& GetBaseStyle() const { return m_baseStyle
; }
62 void SetStyle(const wxRichTextAttr
& style
) { m_style
= style
; }
63 const wxRichTextAttr
& GetStyle() const { return m_style
; }
64 wxRichTextAttr
& GetStyle() { return m_style
; }
69 wxRichTextAttr m_style
;
73 * wxRichTextCharacterStyleDefinition class declaration
76 class WXDLLIMPEXP_ADV wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
78 DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition
)
83 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
):
84 wxRichTextStyleDefinition(name
) {}
85 ~wxRichTextCharacterStyleDefinition() {}
91 * wxRichTextParagraphStyleDefinition class declaration
94 class WXDLLIMPEXP_ADV wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
96 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition
)
101 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
):
102 wxRichTextStyleDefinition(name
) {}
103 ~wxRichTextParagraphStyleDefinition() {}
106 void SetNextStyle(const wxString
& name
) { m_nextStyle
= name
; }
107 const wxString
& GetNextStyle() const { return m_nextStyle
; }
111 /// The next style to use when adding a paragraph after this style.
112 wxString m_nextStyle
;
119 class WXDLLIMPEXP_ADV wxRichTextStyleSheet
: public wxObject
121 DECLARE_CLASS( wxRichTextStyleSheet
)
125 wxRichTextStyleSheet() { Init(); }
126 ~wxRichTextStyleSheet() { DeleteStyles(); }
131 /// Add a definition to the character style list
132 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
) { return AddStyle(m_characterStyleDefinitions
, def
); }
134 /// Add a definition to the paragraph style list
135 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
) { return AddStyle(m_paragraphStyleDefinitions
, def
); }
137 /// Remove a character style
138 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
, bool deleteStyle
= false) { return RemoveStyle(m_characterStyleDefinitions
, def
, deleteStyle
); }
140 /// Remove a paragraph style
141 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
, bool deleteStyle
= false) { return RemoveStyle(m_characterStyleDefinitions
, def
, deleteStyle
); }
143 /// Find a character definition by name
144 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
) const { return (wxRichTextCharacterStyleDefinition
*) FindStyle(m_characterStyleDefinitions
, name
); }
146 /// Find a paragraph definition by name
147 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
) const { return (wxRichTextParagraphStyleDefinition
*) FindStyle(m_characterStyleDefinitions
, name
); }
149 /// Return the number of character styes.
150 size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions
.GetCount(); }
152 /// Return the number of paragraph styes.
153 size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions
.GetCount(); }
155 /// Return the nth character style
156 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
) const { return (wxRichTextCharacterStyleDefinition
*) m_characterStyleDefinitions
.Item(n
)->GetData(); }
158 /// Return the nth paragraph style
159 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
) const { return (wxRichTextParagraphStyleDefinition
*) m_paragraphStyleDefinitions
.Item(n
)->GetData(); }
161 /// Delete all styles
166 /// Add a definition to one of the style lists
167 bool AddStyle(wxList
& list
, wxRichTextStyleDefinition
* def
);
170 bool RemoveStyle(wxList
& list
, wxRichTextStyleDefinition
* def
, bool deleteStyle
);
172 /// Find a definition by name
173 wxRichTextStyleDefinition
* FindStyle(const wxList
& list
, const wxString
& name
) const;
177 wxList m_characterStyleDefinitions
;
178 wxList m_paragraphStyleDefinitions
;
183 * wxRichTextStyleListBox class declaration
184 * A listbox to display styles.
187 class WXDLLIMPEXP_ADV wxRichTextStyleListBox
: public wxHtmlListBox
189 DECLARE_CLASS(wxRichTextStyleListBox
)
190 DECLARE_EVENT_TABLE()
193 wxRichTextStyleListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
194 const wxSize
& size
= wxDefaultSize
, long style
= 0);
195 ~wxRichTextStyleListBox();
197 /// Returns the HTML for this item
198 virtual wxString
OnGetItem(size_t n
) const;
200 /// Creates a suitable HTML fragment for a definition
201 wxString
CreateHTML(wxRichTextStyleDefinition
* def
) const;
203 /// Associates the control with a style manager
204 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
205 wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
207 /// Associates the control with a wxRichTextCtrl
208 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_richTextCtrl
= ctrl
; }
209 wxRichTextCtrl
* GetRichTextCtrl() const { return m_richTextCtrl
; }
211 // Get style for index
212 wxRichTextStyleDefinition
* GetStyle(size_t i
) const ;
217 /// React to selection
218 void OnSelect(wxCommandEvent
& event
);
221 void OnLeftDown(wxMouseEvent
& event
);
224 virtual wxColour
GetSelectedTextColour(const wxColour
& colFg
) const;
225 virtual wxColour
GetSelectedTextBgColour(const wxColour
& colBg
) const;
228 // Convert units in tends of a millimetre to device units
229 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
233 wxRichTextStyleSheet
* m_styleSheet
;
234 wxRichTextCtrl
* m_richTextCtrl
;
242 // _WX_RICHTEXTSTYLES_H_