1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "gailhtmlboxtext.h"
22 static void gail_html_box_text_class_init (GailHtmlBoxTextClass *klass);
23 static void gail_html_box_text_text_interface_init (AtkTextIface *iface);
24 static gchar* gail_html_box_text_get_text (AtkText *text,
27 static gchar* gail_html_box_text_get_text_after_offset
30 AtkTextBoundary boundary_type,
33 static gchar* gail_html_box_text_get_text_at_offset (AtkText *text,
35 AtkTextBoundary boundary_type,
38 static gchar* gail_html_box_text_get_text_before_offset
41 AtkTextBoundary boundary_type,
44 static gunichar gail_html_box_text_get_character_at_offset
47 static gint gail_html_box_text_get_character_count (AtkText *text);
48 static gint gail_html_box_text_get_caret_offset (AtkText *text);
49 static gboolean gail_html_box_text_set_caret_offset (AtkText *text,
51 static gint gail_html_box_text_get_offset_at_point (AtkText *text,
55 static void gail_html_box_text_get_character_extents (AtkText *text,
62 static AtkAttributeSet*
63 gail_html_box_text_get_run_attributes (AtkText *text,
67 static AtkAttributeSet*
68 gail_html_box_text_get_default_attributes (AtkText *text);
69 static gint gail_html_box_text_get_n_selections (AtkText *text);
70 static gchar* gail_html_box_text_get_selection (AtkText *text,
74 static gboolean gail_html_box_text_add_selection (AtkText *text,
77 static gboolean gail_html_box_text_remove_selection (AtkText *text,
79 static gboolean gail_html_box_text_set_selection (AtkText *text,
83 static AtkAttributeSet*
84 add_to_attr_set (AtkAttributeSet *attrib_set,
85 GtkTextAttributes *attrs,
86 AtkTextAttribute attr);
87 static gchar* get_text_near_offset (AtkText *text,
88 GailOffsetType function,
89 AtkTextBoundary boundary_type,
94 G_DEFINE_TYPE_WITH_CODE (GailHtmlBoxText, gail_html_box_text, GAIL_TYPE_HTML_BOX,
95 G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, gail_html_box_text_text_interface_init))
98 gail_html_box_text_new (GObject *obj)
101 AtkObject *atk_object;
102 GailHtmlBoxText *gail_text;
104 g_return_val_if_fail (HTML_IS_BOX_TEXT (obj), NULL);
105 object = g_object_new (GAIL_TYPE_HTML_BOX_TEXT, NULL);
106 atk_object = ATK_OBJECT (object);
107 gail_text = GAIL_HTML_BOX_TEXT (object);
109 atk_object_initialize (atk_object, obj);
110 gail_text->texthelper = gail_text_helper_new ();
112 gail_text_helper_text_setup (gail_text->texthelper,
113 HTML_BOX_TEXT (obj)->master->text);
116 atk_object->role = ATK_ROLE_TEXT;
121 gail_html_box_text_class_init (GailHtmlBoxTextClass *klass)
126 gail_html_box_text_text_interface_init (AtkTextIface *iface)
128 iface->get_text = gail_html_box_text_get_text;
129 iface->get_text_after_offset = gail_html_box_text_get_text_after_offset;
130 iface->get_text_at_offset = gail_html_box_text_get_text_at_offset;
131 iface->get_text_before_offset = gail_html_box_text_get_text_before_offset;
132 iface->get_character_at_offset = gail_html_box_text_get_character_at_offset;
133 iface->get_character_count = gail_html_box_text_get_character_count;
134 iface->get_caret_offset = gail_html_box_text_get_caret_offset;
135 iface->set_caret_offset = gail_html_box_text_set_caret_offset;
136 iface->get_offset_at_point = gail_html_box_text_get_offset_at_point;
137 iface->get_character_extents = gail_html_box_text_get_character_extents;
138 iface->get_n_selections = gail_html_box_text_get_n_selections;
139 iface->get_selection = gail_html_box_text_get_selection;
140 iface->add_selection = gail_html_box_text_add_selection;
141 iface->remove_selection = gail_html_box_text_remove_selection;
142 iface->set_selection = gail_html_box_text_set_selection;
143 iface->get_run_attributes = gail_html_box_text_get_run_attributes;
144 iface->get_default_attributes = gail_html_box_text_get_default_attributes;
148 gail_html_box_text_get_text (AtkText *text,
152 GailHtmlBoxText *gail_text;
153 GtkTextBuffer *buffer;
154 GtkTextIter start, end;
156 g_return_val_if_fail (GAIL_IS_HTML_BOX_TEXT (text), NULL);
157 gail_text = GAIL_HTML_BOX_TEXT (text);
158 g_return_val_if_fail (gail_text->texthelper, NULL);
160 buffer = gail_text->texthelper->buffer;
161 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_offset);
162 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_offset);
164 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
168 gail_html_box_text_get_text_after_offset (AtkText *text,
170 AtkTextBoundary boundary_type,
174 return get_text_near_offset (text, GAIL_AFTER_OFFSET,
175 boundary_type, offset,
176 start_offset, end_offset);
180 gail_html_box_text_get_text_at_offset (AtkText *text,
182 AtkTextBoundary boundary_type,
186 return get_text_near_offset (text, GAIL_AT_OFFSET,
187 boundary_type, offset,
188 start_offset, end_offset);
192 gail_html_box_text_get_text_before_offset (AtkText *text,
194 AtkTextBoundary boundary_type,
198 return get_text_near_offset (text, GAIL_BEFORE_OFFSET,
199 boundary_type, offset,
200 start_offset, end_offset);
204 gail_html_box_text_get_character_at_offset (AtkText *text,
207 GailHtmlBoxText *gail_item;
208 GtkTextIter start, end;
209 GtkTextBuffer *buffer;
213 g_return_val_if_fail (GAIL_IS_HTML_BOX_TEXT (text), 0);
214 gail_item = GAIL_HTML_BOX_TEXT (text);
215 buffer = gail_item->texthelper->buffer;
216 gtk_text_buffer_get_start_iter (buffer, &start);
217 gtk_text_buffer_get_end_iter (buffer, &end);
218 string = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
219 index = g_utf8_offset_to_pointer (string, offset);
222 return g_utf8_get_char (index);
226 gail_html_box_text_get_character_count (AtkText *text)
228 GtkTextBuffer *buffer;
229 GailHtmlBoxText *gail_text;
231 g_return_val_if_fail (GAIL_IS_HTML_BOX_TEXT (text), 0);
232 gail_text = GAIL_HTML_BOX_TEXT (text);
233 g_return_val_if_fail (gail_text->texthelper, 0);
234 buffer = gail_text->texthelper->buffer;
235 return gtk_text_buffer_get_char_count (buffer);
239 gail_html_box_text_get_caret_offset (AtkText *text)
241 GailHtmlBoxText *gail_text;
242 GtkTextBuffer *buffer;
243 GtkTextMark *cursor_mark;
244 GtkTextIter cursor_itr;
246 g_return_val_if_fail (GAIL_IS_HTML_BOX_TEXT (text), 0);
247 gail_text = GAIL_HTML_BOX_TEXT (text);
248 g_return_val_if_fail (gail_text->texthelper, 0);
249 buffer = gail_text->texthelper->buffer;
250 cursor_mark = gtk_text_buffer_get_insert (buffer);
251 gtk_text_buffer_get_iter_at_mark (buffer, &cursor_itr, cursor_mark);
252 return gtk_text_iter_get_offset (&cursor_itr);
256 gail_html_box_text_set_caret_offset (AtkText *text,
259 GailHtmlBoxText *gail_text;
260 GtkTextBuffer *buffer;
263 g_return_val_if_fail (GAIL_IS_HTML_BOX_TEXT (text), FALSE);
264 gail_text = GAIL_HTML_BOX_TEXT (text);
265 g_return_val_if_fail (gail_text->texthelper, FALSE);
266 buffer = gail_text->texthelper->buffer;
267 gtk_text_buffer_get_iter_at_offset (buffer, &pos_itr, offset);
268 gtk_text_buffer_move_mark_by_name (buffer, "insert", &pos_itr);
273 gail_html_box_text_get_offset_at_point (AtkText *text,
282 gail_html_box_text_get_character_extents (AtkText *text,
293 static AtkAttributeSet*
294 gail_html_box_text_get_run_attributes (AtkText *text,
302 static AtkAttributeSet*
303 gail_html_box_text_get_default_attributes (AtkText *text)
309 gail_html_box_text_get_n_selections (AtkText *text)
315 gail_html_box_text_get_selection (AtkText *text,
324 gail_html_box_text_add_selection (AtkText *text,
332 gail_html_box_text_remove_selection (AtkText *text,
339 gail_html_box_text_set_selection (AtkText *text,
347 static AtkAttributeSet*
348 add_to_attr_set (AtkAttributeSet *attrib_set,
349 GtkTextAttributes *attrs,
350 AtkTextAttribute attr)
356 case ATK_TEXT_ATTR_LEFT_MARGIN:
357 value = g_strdup_printf ("%i", attrs->left_margin);
359 case ATK_TEXT_ATTR_RIGHT_MARGIN:
360 value = g_strdup_printf ("%i", attrs->right_margin);
362 case ATK_TEXT_ATTR_INDENT:
363 value = g_strdup_printf ("%i", attrs->indent);
365 case ATK_TEXT_ATTR_INVISIBLE:
366 value = g_strdup (atk_text_attribute_get_value (attr, attrs->invisible));
368 case ATK_TEXT_ATTR_EDITABLE:
369 value = g_strdup (atk_text_attribute_get_value (attr, attrs->editable));
371 case ATK_TEXT_ATTR_PIXELS_ABOVE_LINES:
372 value = g_strdup_printf ("%i", attrs->pixels_above_lines);
374 case ATK_TEXT_ATTR_PIXELS_BELOW_LINES:
375 value = g_strdup_printf ("%i", attrs->pixels_below_lines);
377 case ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP:
378 value = g_strdup_printf ("%i", attrs->pixels_inside_wrap);
380 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
381 value = g_strdup (atk_text_attribute_get_value (attr, attrs->bg_full_height));
383 case ATK_TEXT_ATTR_RISE:
384 value = g_strdup_printf ("%i", attrs->appearance.rise);
386 case ATK_TEXT_ATTR_UNDERLINE:
387 value = g_strdup (atk_text_attribute_get_value (attr, attrs->appearance.underline));
389 case ATK_TEXT_ATTR_STRIKETHROUGH:
390 value = g_strdup (atk_text_attribute_get_value (attr, attrs->appearance.strikethrough));
392 case ATK_TEXT_ATTR_SIZE:
393 value = g_strdup_printf ("%i",
394 pango_font_description_get_size (attrs->font));
396 case ATK_TEXT_ATTR_SCALE:
397 value = g_strdup_printf ("%g", attrs->font_scale);
399 case ATK_TEXT_ATTR_WEIGHT:
400 value = g_strdup_printf ("%d",
401 pango_font_description_get_weight (attrs->font));
403 case ATK_TEXT_ATTR_LANGUAGE:
404 value = g_strdup ((gchar *)(attrs->language));
406 case ATK_TEXT_ATTR_FAMILY_NAME:
407 value = g_strdup (pango_font_description_get_family (attrs->font));
409 case ATK_TEXT_ATTR_BG_COLOR:
410 value = g_strdup_printf ("%u,%u,%u",
411 attrs->appearance.bg_color.red,
412 attrs->appearance.bg_color.green,
413 attrs->appearance.bg_color.blue);
415 case ATK_TEXT_ATTR_FG_COLOR:
416 value = g_strdup_printf ("%u,%u,%u",
417 attrs->appearance.fg_color.red,
418 attrs->appearance.fg_color.green,
419 attrs->appearance.fg_color.blue);
421 case ATK_TEXT_ATTR_BG_STIPPLE:
422 value = g_strdup (atk_text_attribute_get_value (attr, attrs->appearance.bg_stipple ? 1 : 0));
424 case ATK_TEXT_ATTR_FG_STIPPLE:
425 value = g_strdup (atk_text_attribute_get_value (attr, attrs->appearance.fg_stipple ? 1 : 0));
427 case ATK_TEXT_ATTR_WRAP_MODE:
428 value = g_strdup (atk_text_attribute_get_value (attr, attrs->wrap_mode));
430 case ATK_TEXT_ATTR_DIRECTION:
431 value = g_strdup (atk_text_attribute_get_value (attr, attrs->direction));
433 case ATK_TEXT_ATTR_JUSTIFICATION:
434 value = g_strdup (atk_text_attribute_get_value (attr, attrs->justification));
436 case ATK_TEXT_ATTR_STRETCH:
437 value = g_strdup (atk_text_attribute_get_value (attr,
438 pango_font_description_get_stretch (attrs->font)));
440 case ATK_TEXT_ATTR_VARIANT:
441 value = g_strdup (atk_text_attribute_get_value (attr,
442 pango_font_description_get_variant (attrs->font)));
444 case ATK_TEXT_ATTR_STYLE:
445 value = g_strdup (atk_text_attribute_get_value (attr,
446 pango_font_description_get_style (attrs->font)));
452 return gail_text_helper_add_attribute (attrib_set,
458 get_text_near_offset (AtkText *text,
459 GailOffsetType function,
460 AtkTextBoundary boundary_type,
465 return gail_text_helper_get_text (GAIL_HTML_BOX_TEXT (text)->texthelper, NULL,
466 function, boundary_type, offset,
467 start_offset, end_offset);