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