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_
19 #include "wx/richtext/richtextbuffer.h"
24 #include "wx/htmllbox.h"
28 * Forward declarations
31 class WXDLLIMPEXP_ADV wxRichTextCtrl
;
32 class WXDLLIMPEXP_ADV wxRichTextBuffer
;
35 * wxRichTextStyleDefinition class declaration
36 * A base class for paragraph and character styles.
39 class WXDLLIMPEXP_ADV wxRichTextStyleDefinition
: public wxObject
41 DECLARE_CLASS(wxRichTextStyleDefinition
)
46 wxRichTextStyleDefinition(const wxString
& name
= wxEmptyString
) { Init(); m_name
= name
; }
47 ~wxRichTextStyleDefinition() {}
51 /// The name of the style.
52 void SetName(const wxString
& name
) { m_name
= name
; }
53 const wxString
& GetName() const { return m_name
; }
55 /// The name of the style that this style is based on.
56 void SetBaseStyle(const wxString
& name
) { m_baseStyle
= name
; }
57 const wxString
& GetBaseStyle() const { return m_baseStyle
; }
60 void SetStyle(const wxRichTextAttr
& style
) { m_style
= style
; }
61 const wxRichTextAttr
& GetStyle() const { return m_style
; }
62 wxRichTextAttr
& GetStyle() { return m_style
; }
67 wxRichTextAttr m_style
;
71 * wxRichTextCharacterStyleDefinition class declaration
74 class WXDLLIMPEXP_ADV wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
76 DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition
)
81 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
):
82 wxRichTextStyleDefinition(name
) {}
83 ~wxRichTextCharacterStyleDefinition() {}
89 * wxRichTextParagraphStyleDefinition class declaration
92 class WXDLLIMPEXP_ADV wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
94 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition
)
99 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
):
100 wxRichTextStyleDefinition(name
) {}
101 ~wxRichTextParagraphStyleDefinition() {}
104 void SetNextStyle(const wxString
& name
) { m_nextStyle
= name
; }
105 const wxString
& GetNextStyle() const { return m_nextStyle
; }
109 /// The next style to use when adding a paragraph after this style.
110 wxString m_nextStyle
;
117 class WXDLLIMPEXP_ADV wxRichTextStyleSheet
: public wxObject
119 DECLARE_CLASS( wxRichTextStyleSheet
)
123 wxRichTextStyleSheet() { Init(); }
124 ~wxRichTextStyleSheet() { DeleteStyles(); }
129 /// Add a definition to the character style list
130 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
) { return AddStyle(m_characterStyleDefinitions
, def
); }
132 /// Add a definition to the paragraph style list
133 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
) { return AddStyle(m_paragraphStyleDefinitions
, def
); }
135 /// Remove a character style
136 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
, bool deleteStyle
= false) { return RemoveStyle(m_characterStyleDefinitions
, def
, deleteStyle
); }
138 /// Remove a paragraph style
139 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
, bool deleteStyle
= false) { return RemoveStyle(m_characterStyleDefinitions
, def
, deleteStyle
); }
141 /// Find a character definition by name
142 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
) const { return (wxRichTextCharacterStyleDefinition
*) FindStyle(m_characterStyleDefinitions
, name
); }
144 /// Find a paragraph definition by name
145 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
) const { return (wxRichTextParagraphStyleDefinition
*) FindStyle(m_characterStyleDefinitions
, name
); }
147 /// Return the number of character styes.
148 size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions
.GetCount(); }
150 /// Return the number of paragraph styes.
151 size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions
.GetCount(); }
153 /// Return the nth character style
154 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
) const { return (wxRichTextCharacterStyleDefinition
*) m_characterStyleDefinitions
.Item(n
)->GetData(); }
156 /// Return the nth paragraph style
157 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
) const { return (wxRichTextParagraphStyleDefinition
*) m_paragraphStyleDefinitions
.Item(n
)->GetData(); }
159 /// Delete all styles
164 /// Add a definition to one of the style lists
165 bool AddStyle(wxList
& list
, wxRichTextStyleDefinition
* def
);
168 bool RemoveStyle(wxList
& list
, wxRichTextStyleDefinition
* def
, bool deleteStyle
);
170 /// Find a definition by name
171 wxRichTextStyleDefinition
* FindStyle(const wxList
& list
, const wxString
& name
) const;
175 wxList m_characterStyleDefinitions
;
176 wxList m_paragraphStyleDefinitions
;
181 * wxRichTextStyleListBox class declaration
182 * A listbox to display styles.
185 class WXDLLIMPEXP_ADV wxRichTextStyleListBox
: public wxHtmlListBox
187 DECLARE_CLASS(wxRichTextStyleListBox
)
188 DECLARE_EVENT_TABLE()
191 wxRichTextStyleListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
192 const wxSize
& size
= wxDefaultSize
, long style
= 0);
193 ~wxRichTextStyleListBox();
195 /// Returns the HTML for this item
196 virtual wxString
OnGetItem(size_t n
) const;
198 /// Creates a suitable HTML fragment for a definition
199 wxString
CreateHTML(wxRichTextStyleDefinition
* def
) const;
201 /// Associates the control with a style manager
202 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
203 wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
205 /// Associates the control with a wxRichTextCtrl
206 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_richTextCtrl
= ctrl
; }
207 wxRichTextCtrl
* GetRichTextCtrl() const { return m_richTextCtrl
; }
209 // Get style for index
210 wxRichTextStyleDefinition
* GetStyle(size_t i
) const ;
215 /// React to selection
216 void OnSelect(wxCommandEvent
& event
);
219 void OnLeftDown(wxMouseEvent
& event
);
222 virtual wxColour
GetSelectedTextColour(const wxColour
& colFg
) const;
223 virtual wxColour
GetSelectedTextBgColour(const wxColour
& colBg
) const;
226 // Convert units in tends of a millimetre to device units
227 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
231 wxRichTextStyleSheet
* m_styleSheet
;
232 wxRichTextCtrl
* m_richTextCtrl
;
240 // _WX_RICHTEXTSTYLES_H_