]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextstyles.h
added assignment operators from int for disambiguation of expressions such as ll=0
[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 /// Creates a suitable HTML fragment for a definition
196 wxString CreateHTML(wxRichTextStyleDefinition* def) const;
197
198 /// Associates the control with a style manager
199 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
200 wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
201
202 /// Associates the control with a wxRichTextCtrl
203 void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_richTextCtrl = ctrl; }
204 wxRichTextCtrl* GetRichTextCtrl() const { return m_richTextCtrl; }
205
206 // Get style for index
207 wxRichTextStyleDefinition* GetStyle(size_t i) const ;
208
209 /// Updates the list
210 void UpdateStyles();
211
212 /// React to selection
213 void OnSelect(wxCommandEvent& event);
214
215 /// Left click
216 void OnLeftDown(wxMouseEvent& event);
217
218 #if 0
219 virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
220 virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
221 #endif
222
223 // Convert units in tends of a millimetre to device units
224 int ConvertTenthsMMToPixels(wxDC& dc, int units) const;
225
226 protected:
227 /// Returns the HTML for this item
228 virtual wxString OnGetItem(size_t n) const;
229
230 private:
231
232 wxRichTextStyleSheet* m_styleSheet;
233 wxRichTextCtrl* m_richTextCtrl;
234 };
235 #endif
236
237 #endif
238 // wxUSE_RICHTEXT
239
240 #endif
241 // _WX_RICHTEXTSTYLES_H_