1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the KDE libraries |
---|
3 | |
---|
4 | Copyright (C) 1997 Martin Jones (mjones@kde.org) |
---|
5 | Copyright (C) 1997 Torben Weis (weis@kde.org) |
---|
6 | Copyright (C) 1999, 2000, 2001 Helix Code, Inc. |
---|
7 | |
---|
8 | This library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU Library General Public |
---|
10 | License as published by the Free Software Foundation; either |
---|
11 | version 2 of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | This library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | Library General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU Library General Public License |
---|
19 | along with this library; see the file COPYING.LIB. If not, write to |
---|
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | #ifndef _HTMLTEXT_H_ |
---|
24 | #define _HTMLTEXT_H_ |
---|
25 | |
---|
26 | #include "htmlobject.h" |
---|
27 | |
---|
28 | #define HTML_TEXT(x) ((HTMLText *)(x)) |
---|
29 | #define HTML_TEXT_CLASS(x) ((HTMLTextClass *)(x)) |
---|
30 | #define HTML_IS_TEXT(x) (HTML_CHECK_TYPE ((x), HTML_TYPE_TEXT)) |
---|
31 | |
---|
32 | struct _SpellError { |
---|
33 | guint off; |
---|
34 | guint len; |
---|
35 | }; |
---|
36 | |
---|
37 | struct _Link { |
---|
38 | guint start_index; |
---|
39 | guint end_index; |
---|
40 | gint start_offset; |
---|
41 | gint end_offset; |
---|
42 | gchar *url; |
---|
43 | gchar *target; |
---|
44 | }; |
---|
45 | |
---|
46 | struct _HTMLTextPangoInfoEntry { |
---|
47 | PangoItem *item; |
---|
48 | PangoGlyphUnit *widths; |
---|
49 | }; |
---|
50 | |
---|
51 | struct _HTMLTextPangoInfo { |
---|
52 | HTMLTextPangoInfoEntry *entries; |
---|
53 | PangoLogAttr *attrs; |
---|
54 | gint n; |
---|
55 | }; |
---|
56 | |
---|
57 | struct _HTMLPangoAttrFontSize { |
---|
58 | PangoAttrInt attr_int; |
---|
59 | GtkHTMLFontStyle style; |
---|
60 | }; |
---|
61 | |
---|
62 | struct _HTMLText { |
---|
63 | HTMLObject object; |
---|
64 | |
---|
65 | gchar *text; |
---|
66 | guint text_len; |
---|
67 | guint text_bytes; |
---|
68 | |
---|
69 | PangoAttrList *attr_list; |
---|
70 | PangoAttrList *extra_attr_list; |
---|
71 | GtkHTMLFontStyle font_style; |
---|
72 | HTMLFontFace *face; |
---|
73 | HTMLColor *color; |
---|
74 | |
---|
75 | guint select_start; |
---|
76 | guint select_length; |
---|
77 | |
---|
78 | GList *spell_errors; |
---|
79 | |
---|
80 | HTMLTextPangoInfo *pi; |
---|
81 | |
---|
82 | GSList *links; |
---|
83 | gint focused_link_offset; |
---|
84 | }; |
---|
85 | |
---|
86 | struct _HTMLTextClass { |
---|
87 | HTMLObjectClass object_class; |
---|
88 | |
---|
89 | void (* queue_draw) (HTMLText *text, HTMLEngine *engine, |
---|
90 | guint offset, guint len); |
---|
91 | |
---|
92 | GtkHTMLFontStyle (* get_font_style) (const HTMLText *text); |
---|
93 | void (* set_font_style) (HTMLText *text, HTMLEngine *engine, GtkHTMLFontStyle style); |
---|
94 | }; |
---|
95 | |
---|
96 | extern HTMLTextClass html_text_class; |
---|
97 | |
---|
98 | void html_text_type_init (void); |
---|
99 | void html_text_class_init (HTMLTextClass *klass, |
---|
100 | HTMLType type, |
---|
101 | guint object_size); |
---|
102 | void html_text_init (HTMLText *text_object, |
---|
103 | HTMLTextClass *klass, |
---|
104 | const gchar *text, |
---|
105 | gint len, |
---|
106 | GtkHTMLFontStyle font_style, |
---|
107 | HTMLColor *color); |
---|
108 | HTMLObject *html_text_new (const gchar *text, |
---|
109 | GtkHTMLFontStyle font_style, |
---|
110 | HTMLColor *color); |
---|
111 | HTMLObject *html_text_new_with_len (const gchar *text, |
---|
112 | gint len, |
---|
113 | GtkHTMLFontStyle font_style, |
---|
114 | HTMLColor *color); |
---|
115 | void html_text_queue_draw (HTMLText *text, |
---|
116 | HTMLEngine *engine, |
---|
117 | guint offset, |
---|
118 | guint len); |
---|
119 | GtkHTMLFontStyle html_text_get_font_style (const HTMLText *text); |
---|
120 | void html_text_set_font_style (HTMLText *text, |
---|
121 | HTMLEngine *engine, |
---|
122 | GtkHTMLFontStyle style); |
---|
123 | void html_text_append (HTMLText *text, |
---|
124 | const gchar *str, |
---|
125 | gint len); |
---|
126 | void html_text_set_text (HTMLText *text, |
---|
127 | const gchar *new_text); |
---|
128 | void html_text_set_font_face (HTMLText *text, |
---|
129 | HTMLFontFace *face); |
---|
130 | gint html_text_get_nb_width (HTMLText *text, |
---|
131 | HTMLPainter *painter, |
---|
132 | gboolean begin); |
---|
133 | guint html_text_get_bytes (HTMLText *text); |
---|
134 | guint html_text_get_index (HTMLText *text, |
---|
135 | guint offset); |
---|
136 | gunichar html_text_get_char (HTMLText *text, |
---|
137 | guint offset); |
---|
138 | gchar *html_text_get_text (HTMLText *text, |
---|
139 | guint offset); |
---|
140 | GList *html_text_get_items (HTMLText *text, |
---|
141 | HTMLPainter *painter); |
---|
142 | void html_text_spell_errors_clear (HTMLText *text); |
---|
143 | void html_text_spell_errors_clear_interval (HTMLText *text, |
---|
144 | HTMLInterval *i); |
---|
145 | void html_text_spell_errors_add (HTMLText *text, |
---|
146 | guint off, |
---|
147 | guint len); |
---|
148 | gboolean html_text_magic_link (HTMLText *text, |
---|
149 | HTMLEngine *engine, |
---|
150 | guint offset); |
---|
151 | gint html_text_trail_space_width (HTMLText *text, |
---|
152 | HTMLPainter *painter); |
---|
153 | gboolean html_text_convert_nbsp (HTMLText *text, |
---|
154 | gboolean free_text); |
---|
155 | gint html_text_get_line_offset (HTMLText *text, |
---|
156 | HTMLPainter *painter, |
---|
157 | gint offset); |
---|
158 | gint html_text_text_line_length (const gchar *text, |
---|
159 | gint *line_offset, |
---|
160 | guint len, |
---|
161 | gint *tabs); |
---|
162 | gint html_text_calc_part_width (HTMLText *text, |
---|
163 | HTMLPainter *painter, |
---|
164 | char *start, |
---|
165 | gint offset, |
---|
166 | gint len, |
---|
167 | gint *asc, |
---|
168 | gint *dsc); |
---|
169 | gint html_text_get_item_index (HTMLText *text, |
---|
170 | HTMLPainter *painter, |
---|
171 | gint offset, |
---|
172 | gint *item_offset); |
---|
173 | gboolean html_text_pi_backward (HTMLTextPangoInfo *pi, |
---|
174 | gint *ii, |
---|
175 | gint *io); |
---|
176 | gboolean html_text_pi_forward (HTMLTextPangoInfo *pi, |
---|
177 | gint *ii, |
---|
178 | gint *io); |
---|
179 | void html_text_free_attrs (GSList *attrs); |
---|
180 | gint html_text_tail_white_space (HTMLText *text, |
---|
181 | HTMLPainter *painter, |
---|
182 | gint offset, |
---|
183 | gint ii, |
---|
184 | gint io, |
---|
185 | gint *white_len, |
---|
186 | gint line_offset, |
---|
187 | gchar *s); |
---|
188 | void html_text_append_link (HTMLText *text, |
---|
189 | gchar *url, |
---|
190 | gchar *target, |
---|
191 | gint start_offset, |
---|
192 | gint end_offset); |
---|
193 | void html_text_append_link_full (HTMLText *text, |
---|
194 | gchar *url, |
---|
195 | gchar *target, |
---|
196 | gint start_index, |
---|
197 | gint end_index, |
---|
198 | gint start_offset, |
---|
199 | gint end_offset); |
---|
200 | void html_text_add_link (HTMLText *text, |
---|
201 | HTMLEngine *e, |
---|
202 | gchar *url, |
---|
203 | gchar *target, |
---|
204 | gint start_offset, |
---|
205 | gint end_offset); |
---|
206 | void html_text_add_link_full (HTMLText *text, |
---|
207 | HTMLEngine *e, |
---|
208 | gchar *url, |
---|
209 | gchar *target, |
---|
210 | gint start_index, |
---|
211 | gint end_index, |
---|
212 | gint start_offset, |
---|
213 | gint end_offset); |
---|
214 | void html_text_remove_links (HTMLText *text); |
---|
215 | gboolean html_text_get_link_rectangle (HTMLText *text, |
---|
216 | HTMLPainter *painter, |
---|
217 | gint offset, |
---|
218 | gint *x1, |
---|
219 | gint *y1, |
---|
220 | gint *x2, |
---|
221 | gint *y2); |
---|
222 | Link *html_text_get_link_at_offset (HTMLText *text, |
---|
223 | gint offset); |
---|
224 | HTMLTextSlave *html_text_get_slave_at_offset (HTMLObject *o, |
---|
225 | gint offset); |
---|
226 | Link *html_text_get_link_slaves_at_offset (HTMLText *text, |
---|
227 | gint offset, |
---|
228 | HTMLTextSlave **start, |
---|
229 | HTMLTextSlave **end); |
---|
230 | gboolean html_text_next_link_offset (HTMLText *text, |
---|
231 | gint *offset); |
---|
232 | gboolean html_text_prev_link_offset (HTMLText *text, |
---|
233 | gint *offset); |
---|
234 | gboolean html_text_first_link_offset (HTMLText *text, |
---|
235 | gint *offset); |
---|
236 | gboolean html_text_last_link_offset (HTMLText *text, |
---|
237 | gint *offset); |
---|
238 | gchar *html_text_get_link_text (HTMLText *text, |
---|
239 | gint offset); |
---|
240 | void html_text_calc_font_size (HTMLText *text, |
---|
241 | HTMLEngine *e); |
---|
242 | GtkHTMLFontStyle html_text_get_fontstyle_at_index (HTMLText *text, |
---|
243 | gint index); |
---|
244 | GtkHTMLFontStyle html_text_get_style_conflicts (HTMLText *text, |
---|
245 | GtkHTMLFontStyle style, |
---|
246 | gint start_index, |
---|
247 | gint end_index); |
---|
248 | void html_text_set_style_in_range (HTMLText *text, |
---|
249 | GtkHTMLFontStyle style, |
---|
250 | HTMLEngine *e, |
---|
251 | gint start_index, |
---|
252 | gint end_index); |
---|
253 | void html_text_set_style (HTMLText *text, |
---|
254 | GtkHTMLFontStyle style, |
---|
255 | HTMLEngine *e); |
---|
256 | void html_text_unset_style (HTMLText *text, |
---|
257 | GtkHTMLFontStyle style); |
---|
258 | HTMLColor *html_text_get_color_at_index (HTMLText *text, |
---|
259 | HTMLEngine *e, |
---|
260 | gint index); |
---|
261 | HTMLColor *html_text_get_color (HTMLText *text, |
---|
262 | HTMLEngine *e, |
---|
263 | gint start_index); |
---|
264 | void html_text_set_color_in_range (HTMLText *text, |
---|
265 | HTMLColor *color, |
---|
266 | gint start_index, |
---|
267 | gint end_index); |
---|
268 | void html_text_set_color (HTMLText *text, |
---|
269 | HTMLColor *color); |
---|
270 | |
---|
271 | Link *html_link_new (gchar *url, |
---|
272 | gchar *target, |
---|
273 | guint start_index, |
---|
274 | guint end_index, |
---|
275 | gint start_offset, |
---|
276 | gint end_offset); |
---|
277 | Link *html_link_dup (Link *link); |
---|
278 | void html_link_free (Link *link); |
---|
279 | gboolean html_link_equal (Link *l1, |
---|
280 | Link *l2); |
---|
281 | void html_link_set_url_and_target (Link *link, |
---|
282 | gchar *url, |
---|
283 | gchar *target); |
---|
284 | |
---|
285 | /* |
---|
286 | * protected |
---|
287 | */ |
---|
288 | HTMLTextPangoInfo *html_text_pango_info_new (gint n); |
---|
289 | void html_text_pango_info_destroy (HTMLTextPangoInfo *pi); |
---|
290 | HTMLTextPangoInfo *html_text_get_pango_info (HTMLText *text, |
---|
291 | HTMLPainter *painter); |
---|
292 | gint html_text_pango_info_get_index (HTMLTextPangoInfo *pi, |
---|
293 | gint byte_offset, |
---|
294 | gint idx); |
---|
295 | PangoAttribute *html_pango_attr_font_size_new (GtkHTMLFontStyle style); |
---|
296 | void html_pango_attr_font_size_calc (HTMLPangoAttrFontSize *attr, |
---|
297 | HTMLEngine *e); |
---|
298 | PangoAttrList *html_text_get_attr_list (HTMLText *text, |
---|
299 | gint start_index, |
---|
300 | gint end_index); |
---|
301 | void html_text_calc_text_size (HTMLText *t, |
---|
302 | HTMLPainter *painter, |
---|
303 | gint start_byte_offset, |
---|
304 | guint len, |
---|
305 | HTMLTextPangoInfo *pi, |
---|
306 | GList *glyphs, |
---|
307 | gint *line_offset, |
---|
308 | GtkHTMLFontStyle font_style, |
---|
309 | HTMLFontFace *face, |
---|
310 | gint *width, |
---|
311 | gint *asc, |
---|
312 | gint *dsc); |
---|
313 | void html_text_change_attrs (PangoAttrList *attr_list, |
---|
314 | GtkHTMLFontStyle style, |
---|
315 | HTMLEngine *e, |
---|
316 | gint start_index, |
---|
317 | gint end_index, |
---|
318 | gboolean avoid_default_size); |
---|
319 | |
---|
320 | gboolean html_text_is_line_break (PangoLogAttr attr); |
---|
321 | void html_text_remove_unwanted_line_breaks (char *s, |
---|
322 | int len, |
---|
323 | PangoLogAttr *attrs); |
---|
324 | |
---|
325 | typedef HTMLObject * (* HTMLTextHelperFunc) (HTMLText *, gint begin, gint end); |
---|
326 | HTMLObject *html_text_op_copy_helper (HTMLText *text, |
---|
327 | GList *from, |
---|
328 | GList *to, |
---|
329 | guint *len); |
---|
330 | HTMLObject *html_text_op_cut_helper (HTMLText *text, |
---|
331 | HTMLEngine *e, |
---|
332 | GList *from, |
---|
333 | GList *to, |
---|
334 | GList *left, |
---|
335 | GList *right, |
---|
336 | guint *len); |
---|
337 | #endif /* _HTMLTEXT_H_ */ |
---|