]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextstyles.h
Alphabetize wxWindow members list
[wxWidgets.git] / include / wx / richtext / richtextstyles.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtextstyles.h
3 // Purpose: Style management for wxRichTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-09-30
7 // RCS-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 /*!
30 * Forward declarations
31 */
32
33 class WXDLLIMPEXP_ADV wxRichTextCtrl;
34 class WXDLLIMPEXP_ADV wxRichTextBuffer;
35
36 /*!
37 * wxRichTextStyleDefinition class declaration
38 * A base class for paragraph and character styles.
39 */
40
41 class WXDLLIMPEXP_ADV wxRichTextStyleDefinition: public wxObject
42 {
43 DECLARE_CLASS(wxRichTextStyleDefinition)
44 public:
45
46 // Constructors
47
48 wxRichTextStyleDefinition(const wxString& name = wxEmptyString) { Init(); m_name = name; }
49 ~wxRichTextStyleDefinition() {}
50
51 void Init() {}
52
53 /// The name of the style.
54 void SetName(const wxString& name) { m_name = name; }
55 const wxString& GetName() const { return m_name; }
56
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; }
60
61 /// The style.
62 void SetStyle(const wxRichTextAttr& style) { m_style = style; }
63 const wxRichTextAttr& GetStyle() const { return m_style; }
64 wxRichTextAttr& GetStyle() { return m_style; }
65
66 protected:
67 wxString m_name;
68 wxString m_baseStyle;
69 wxRichTextAttr m_style;
70 };
71
72 /*!
73 * wxRichTextCharacterStyleDefinition class declaration
74 */
75
76 class WXDLLIMPEXP_ADV wxRichTextCharacterStyleDefinition: public wxRichTextStyleDefinition
77 {
78 DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition)
79 public:
80
81 // Constructors
82
83 wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString):
84 wxRichTextStyleDefinition(name) {}
85 ~wxRichTextCharacterStyleDefinition() {}
86
87 protected:
88 };
89
90 /*!
91 * wxRichTextParagraphStyleDefinition class declaration
92 */
93
94 class WXDLLIMPEXP_ADV wxRichTextParagraphStyleDefinition: public wxRichTextStyleDefinition
95 {
96 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition)
97 public:
98
99 // Constructors
100
101 wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString):
102 wxRichTextStyleDefinition(name) {}
103 ~wxRichTextParagraphStyleDefinition() {}
104
105 /// The next style.
106 void SetNextStyle(const wxString& name) { m_nextStyle = name; }
107 const wxString& GetNextStyle() const { return m_nextStyle; }
108
109 protected:
110
111 /// The next style to use when adding a paragraph after this style.
112 wxString m_nextStyle;
113 };
114
115 /*!
116 * The style sheet
117 */
118
119 class WXDLLIMPEXP_ADV wxRichTextStyleSheet: public wxObject
120 {
121 DECLARE_CLASS( wxRichTextStyleSheet )
122
123 public:
124 /// Constructors
125 wxRichTextStyleSheet() { Init(); }
126 ~wxRichTextStyleSheet() { DeleteStyles(); }
127
128 /// Initialisation
129 void Init();
130
131 /// Add a definition to the character style list
132 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def) { return AddStyle(m_characterStyleDefinitions, def); }
133
134 /// Add a definition to the paragraph style list
135 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def) { return AddStyle(m_paragraphStyleDefinitions, def); }
136
137 /// Remove a character style
138 bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); }
139
140 /// Remove a paragraph style
141 bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); }
142
143 /// Find a character definition by name
144 wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name); }
145
146 /// Find a paragraph definition by name
147 wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_characterStyleDefinitions, name); }
148
149 /// Return the number of character styes.
150 size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); }
151
152 /// Return the number of paragraph styes.
153 size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); }
154
155 /// Return the nth character style
156 wxRichTextCharacterStyleDefinition* GetCharacterStyle(size_t n) const { return (wxRichTextCharacterStyleDefinition*) m_characterStyleDefinitions.Item(n)->GetData(); }
157
158 /// Return the nth paragraph style
159 wxRichTextParagraphStyleDefinition* GetParagraphStyle(size_t n) const { return (wxRichTextParagraphStyleDefinition*) m_paragraphStyleDefinitions.Item(n)->GetData(); }
160
161 /// Delete all styles
162 void DeleteStyles();
163
164 /// Implementation
165
166 /// Add a definition to one of the style lists
167 bool AddStyle(wxList& list, wxRichTextStyleDefinition* def);
168
169 /// Remove a style
170 bool RemoveStyle(wxList& list, wxRichTextStyleDefinition* def, bool deleteStyle);
171
172 /// Find a definition by name
173 wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name) const;
174
175 protected:
176
177 wxList m_characterStyleDefinitions;
178 wxList m_paragraphStyleDefinitions;
179 };
180
181 #if wxUSE_HTML
182 /*!
183 * wxRichTextStyleListBox class declaration
184 * A listbox to display styles.
185 */
186
187 class WXDLLIMPEXP_ADV wxRichTextStyleListBox: public wxHtmlListBox
188 {
189 DECLARE_CLASS(wxRichTextStyleListBox)
190 DECLARE_EVENT_TABLE()
191
192 public:
193 wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
194 const wxSize& size = wxDefaultSize, long style = 0);
195 ~wxRichTextStyleListBox();
196
197 /// Returns the HTML for this item
198 virtual wxString OnGetItem(size_t n) const;
199
200 /// Creates a suitable HTML fragment for a definition
201 wxString CreateHTML(wxRichTextStyleDefinition* def) const;
202
203 /// Associates the control with a style manager
204 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
205 wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
206
207 /// Associates the control with a wxRichTextCtrl
208 void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_richTextCtrl = ctrl; }
209 wxRichTextCtrl* GetRichTextCtrl() const { return m_richTextCtrl; }
210
211 // Get style for index
212 wxRichTextStyleDefinition* GetStyle(size_t i) const ;
213
214 /// Updates the list
215 void UpdateStyles();
216
217 /// React to selection
218 void OnSelect(wxCommandEvent& event);
219
220 /// Left click
221 void OnLeftDown(wxMouseEvent& event);
222
223 #if 0
224 virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
225 virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
226 #endif
227
228 // Convert units in tends of a millimetre to device units
229 int ConvertTenthsMMToPixels(wxDC& dc, int units) const;
230
231 private:
232
233 wxRichTextStyleSheet* m_styleSheet;
234 wxRichTextCtrl* m_richTextCtrl;
235 };
236 #endif
237
238 #endif
239 // wxUSE_RICHTEXT
240
241 #endif
242 // _WX_RICHTEXTSTYLES_H_