1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 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.
24 #include <gdk/gdkkeysyms.h>
25 #include "gailentry.h"
26 #include "gailcombo.h"
27 #include "gailcombobox.h"
28 #include <libgail-util/gailmisc.h>
30 static void gail_entry_class_init (GailEntryClass *klass);
31 static void gail_entry_init (GailEntry *entry);
32 static void gail_entry_real_initialize (AtkObject *obj,
34 static void text_setup (GailEntry *entry,
36 static void gail_entry_real_notify_gtk (GObject *obj,
38 static void gail_entry_finalize (GObject *object);
40 static gint gail_entry_get_index_in_parent (AtkObject *accessible);
44 static AtkStateSet* gail_entry_ref_state_set (AtkObject *accessible);
48 static void atk_text_interface_init (AtkTextIface *iface);
50 static gchar* gail_entry_get_text (AtkText *text,
53 static gunichar gail_entry_get_character_at_offset
56 static gchar* gail_entry_get_text_before_offset(AtkText *text,
58 AtkTextBoundary boundary_type,
61 static gchar* gail_entry_get_text_at_offset (AtkText *text,
63 AtkTextBoundary boundary_type,
66 static gchar* gail_entry_get_text_after_offset (AtkText *text,
68 AtkTextBoundary boundary_type,
71 static gint gail_entry_get_caret_offset (AtkText *text);
72 static gboolean gail_entry_set_caret_offset (AtkText *text,
74 static gint gail_entry_get_n_selections (AtkText *text);
75 static gchar* gail_entry_get_selection (AtkText *text,
79 static gboolean gail_entry_add_selection (AtkText *text,
82 static gboolean gail_entry_remove_selection (AtkText *text,
84 static gboolean gail_entry_set_selection (AtkText *text,
88 static gint gail_entry_get_character_count (AtkText *text);
89 static AtkAttributeSet * gail_entry_get_run_attributes
94 static AtkAttributeSet * gail_entry_get_default_attributes
96 static void gail_entry_get_character_extents (AtkText *text,
102 AtkCoordType coords);
103 static gint gail_entry_get_offset_at_point (AtkText *text,
106 AtkCoordType coords);
107 /* atkeditabletext.h */
109 static void atk_editable_text_interface_init (AtkEditableTextIface *iface);
110 static void gail_entry_set_text_contents (AtkEditableText *text,
111 const gchar *string);
112 static void gail_entry_insert_text (AtkEditableText *text,
116 static void gail_entry_copy_text (AtkEditableText *text,
119 static void gail_entry_cut_text (AtkEditableText *text,
122 static void gail_entry_delete_text (AtkEditableText *text,
125 static void gail_entry_paste_text (AtkEditableText *text,
127 static void gail_entry_paste_received (GtkClipboard *clipboard,
134 static gboolean gail_entry_idle_notify_insert (gpointer data);
135 static void gail_entry_notify_insert (GailEntry *entry);
136 static void gail_entry_notify_delete (GailEntry *entry);
137 static void _gail_entry_insert_text_cb (GtkEntry *entry,
141 static void _gail_entry_delete_text_cb (GtkEntry *entry,
144 static void _gail_entry_changed_cb (GtkEntry *entry);
145 static gboolean check_for_selection_change (GailEntry *entry,
146 GtkEntry *gtk_entry);
148 static void atk_action_interface_init (AtkActionIface *iface);
150 static gboolean gail_entry_do_action (AtkAction *action,
152 static gboolean idle_do_action (gpointer data);
153 static gint gail_entry_get_n_actions (AtkAction *action);
154 static G_CONST_RETURN gchar* gail_entry_get_description (AtkAction *action,
156 static G_CONST_RETURN gchar* gail_entry_get_keybinding (AtkAction *action,
158 static G_CONST_RETURN gchar* gail_entry_action_get_name (AtkAction *action,
160 static gboolean gail_entry_set_description (AtkAction *action,
164 typedef struct _GailEntryPaste GailEntryPaste;
166 struct _GailEntryPaste
172 G_DEFINE_TYPE_WITH_CODE (GailEntry, gail_entry, GAIL_TYPE_WIDGET,
173 G_IMPLEMENT_INTERFACE (ATK_TYPE_EDITABLE_TEXT, atk_editable_text_interface_init)
174 G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init)
175 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
178 gail_entry_class_init (GailEntryClass *klass)
180 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
181 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
182 GailWidgetClass *widget_class;
184 widget_class = (GailWidgetClass*)klass;
186 gobject_class->finalize = gail_entry_finalize;
188 class->ref_state_set = gail_entry_ref_state_set;
189 class->get_index_in_parent = gail_entry_get_index_in_parent;
190 class->initialize = gail_entry_real_initialize;
192 widget_class->notify_gtk = gail_entry_real_notify_gtk;
196 gail_entry_init (GailEntry *entry)
198 entry->textutil = NULL;
199 entry->signal_name_insert = NULL;
200 entry->signal_name_delete = NULL;
201 entry->cursor_position = 0;
202 entry->selection_bound = 0;
203 entry->activate_description = NULL;
204 entry->activate_keybinding = NULL;
208 gail_entry_real_initialize (AtkObject *obj,
212 GailEntry *gail_entry;
214 ATK_OBJECT_CLASS (gail_entry_parent_class)->initialize (obj, data);
216 gail_entry = GAIL_ENTRY (obj);
217 gail_entry->textutil = gail_text_util_new ();
219 g_assert (GTK_IS_ENTRY (data));
221 entry = GTK_ENTRY (data);
222 text_setup (gail_entry, entry);
223 gail_entry->cursor_position = entry->current_pos;
224 gail_entry->selection_bound = entry->selection_bound;
226 /* Set up signal callbacks */
227 g_signal_connect (data, "insert-text",
228 G_CALLBACK (_gail_entry_insert_text_cb), NULL);
229 g_signal_connect (data, "delete-text",
230 G_CALLBACK (_gail_entry_delete_text_cb), NULL);
231 g_signal_connect (data, "changed",
232 G_CALLBACK (_gail_entry_changed_cb), NULL);
234 if (gtk_entry_get_visibility (entry))
235 obj->role = ATK_ROLE_TEXT;
237 obj->role = ATK_ROLE_PASSWORD_TEXT;
241 gail_entry_real_notify_gtk (GObject *obj,
249 widget = GTK_WIDGET (obj);
250 atk_obj = gtk_widget_get_accessible (widget);
251 gtk_entry = GTK_ENTRY (widget);
252 entry = GAIL_ENTRY (atk_obj);
254 if (strcmp (pspec->name, "cursor-position") == 0)
256 if (entry->insert_idle_handler == 0)
257 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
259 if (check_for_selection_change (entry, gtk_entry))
260 g_signal_emit_by_name (atk_obj, "text_selection_changed");
262 * The entry cursor position has moved so generate the signal.
264 g_signal_emit_by_name (atk_obj, "text_caret_moved",
265 entry->cursor_position);
267 else if (strcmp (pspec->name, "selection-bound") == 0)
269 if (entry->insert_idle_handler == 0)
270 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
272 if (check_for_selection_change (entry, gtk_entry))
273 g_signal_emit_by_name (atk_obj, "text_selection_changed");
275 else if (strcmp (pspec->name, "editable") == 0)
279 g_object_get (obj, "editable", &value, NULL);
280 atk_object_notify_state_change (atk_obj, ATK_STATE_EDITABLE,
283 else if (strcmp (pspec->name, "visibility") == 0)
288 text_setup (entry, gtk_entry);
289 visibility = gtk_entry_get_visibility (gtk_entry);
290 new_role = visibility ? ATK_ROLE_TEXT : ATK_ROLE_PASSWORD_TEXT;
291 atk_object_set_role (atk_obj, new_role);
293 else if (strcmp (pspec->name, "invisible-char") == 0)
295 text_setup (entry, gtk_entry);
298 GAIL_WIDGET_CLASS (gail_entry_parent_class)->notify_gtk (obj, pspec);
302 text_setup (GailEntry *entry,
305 if (gtk_entry_get_visibility (gtk_entry))
307 gail_text_util_text_setup (entry->textutil, gtk_entry_get_text (gtk_entry));
311 gunichar invisible_char;
312 GString *tmp_string = g_string_new (NULL);
318 invisible_char = gtk_entry_get_invisible_char (gtk_entry);
319 if (invisible_char == 0)
320 invisible_char = ' ';
322 ch_len = g_unichar_to_utf8 (invisible_char, buf);
323 length = gtk_entry_get_text_length (gtk_entry);
324 for (i = 0; i < length; i++)
326 g_string_append_len (tmp_string, buf, ch_len);
329 gail_text_util_text_setup (entry->textutil, tmp_string->str);
330 g_string_free (tmp_string, TRUE);
336 gail_entry_finalize (GObject *object)
338 GailEntry *entry = GAIL_ENTRY (object);
340 g_object_unref (entry->textutil);
341 g_free (entry->activate_description);
342 g_free (entry->activate_keybinding);
343 if (entry->action_idle_handler)
345 g_source_remove (entry->action_idle_handler);
346 entry->action_idle_handler = 0;
348 if (entry->insert_idle_handler)
350 g_source_remove (entry->insert_idle_handler);
351 entry->insert_idle_handler = 0;
353 G_OBJECT_CLASS (gail_entry_parent_class)->finalize (object);
357 gail_entry_get_index_in_parent (AtkObject *accessible)
360 * If the parent widget is a combo box then the index is 1
361 * otherwise do the normal thing.
363 if (accessible->accessible_parent)
364 if (GAIL_IS_COMBO (accessible->accessible_parent) ||
365 GAIL_IS_COMBO_BOX (accessible->accessible_parent))
368 return ATK_OBJECT_CLASS (gail_entry_parent_class)->get_index_in_parent (accessible);
374 gail_entry_ref_state_set (AtkObject *accessible)
376 AtkStateSet *state_set;
381 state_set = ATK_OBJECT_CLASS (gail_entry_parent_class)->ref_state_set (accessible);
382 widget = GTK_ACCESSIBLE (accessible)->widget;
387 entry = GTK_ENTRY (widget);
389 g_object_get (G_OBJECT (entry), "editable", &value, NULL);
391 atk_state_set_add_state (state_set, ATK_STATE_EDITABLE);
392 atk_state_set_add_state (state_set, ATK_STATE_SINGLE_LINE);
400 atk_text_interface_init (AtkTextIface *iface)
402 iface->get_text = gail_entry_get_text;
403 iface->get_character_at_offset = gail_entry_get_character_at_offset;
404 iface->get_text_before_offset = gail_entry_get_text_before_offset;
405 iface->get_text_at_offset = gail_entry_get_text_at_offset;
406 iface->get_text_after_offset = gail_entry_get_text_after_offset;
407 iface->get_caret_offset = gail_entry_get_caret_offset;
408 iface->set_caret_offset = gail_entry_set_caret_offset;
409 iface->get_character_count = gail_entry_get_character_count;
410 iface->get_n_selections = gail_entry_get_n_selections;
411 iface->get_selection = gail_entry_get_selection;
412 iface->add_selection = gail_entry_add_selection;
413 iface->remove_selection = gail_entry_remove_selection;
414 iface->set_selection = gail_entry_set_selection;
415 iface->get_run_attributes = gail_entry_get_run_attributes;
416 iface->get_default_attributes = gail_entry_get_default_attributes;
417 iface->get_character_extents = gail_entry_get_character_extents;
418 iface->get_offset_at_point = gail_entry_get_offset_at_point;
422 gail_entry_get_text (AtkText *text,
428 widget = GTK_ACCESSIBLE (text)->widget;
430 /* State is defunct */
433 return gail_text_util_get_substring (GAIL_ENTRY (text)->textutil, start_pos, end_pos);
437 gail_entry_get_text_before_offset (AtkText *text,
439 AtkTextBoundary boundary_type,
446 widget = GTK_ACCESSIBLE (text)->widget;
448 /* State is defunct */
452 entry = GTK_ENTRY (widget);
454 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
455 gtk_entry_get_layout (entry), GAIL_BEFORE_OFFSET,
456 boundary_type, offset, start_offset, end_offset);
460 gail_entry_get_text_at_offset (AtkText *text,
462 AtkTextBoundary boundary_type,
469 widget = GTK_ACCESSIBLE (text)->widget;
471 /* State is defunct */
475 entry = GTK_ENTRY (widget);
477 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
478 gtk_entry_get_layout (entry), GAIL_AT_OFFSET,
479 boundary_type, offset, start_offset, end_offset);
483 gail_entry_get_text_after_offset (AtkText *text,
485 AtkTextBoundary boundary_type,
492 widget = GTK_ACCESSIBLE (text)->widget;
494 /* State is defunct */
498 entry = GTK_ENTRY (widget);
500 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
501 gtk_entry_get_layout (entry), GAIL_AFTER_OFFSET,
502 boundary_type, offset, start_offset, end_offset);
506 gail_entry_get_character_count (AtkText *text)
511 widget = GTK_ACCESSIBLE (text)->widget;
513 /* State is defunct */
516 entry = GTK_ENTRY (widget);
517 return g_utf8_strlen (gtk_entry_get_text (entry), -1);
521 gail_entry_get_caret_offset (AtkText *text)
526 widget = GTK_ACCESSIBLE (text)->widget;
528 /* State is defunct */
531 entry = GTK_ENTRY (widget);
533 return gtk_editable_get_position (GTK_EDITABLE (entry));
537 gail_entry_set_caret_offset (AtkText *text, gint offset)
542 widget = GTK_ACCESSIBLE (text)->widget;
544 /* State is defunct */
547 entry = GTK_ENTRY (widget);
549 gtk_editable_set_position (GTK_EDITABLE (entry), offset);
553 static AtkAttributeSet*
554 gail_entry_get_run_attributes (AtkText *text,
561 AtkAttributeSet *at_set = NULL;
562 GtkTextDirection dir;
564 widget = GTK_ACCESSIBLE (text)->widget;
566 /* State is defunct */
569 entry = GTK_ENTRY (widget);
571 dir = gtk_widget_get_direction (widget);
572 if (dir == GTK_TEXT_DIR_RTL)
574 at_set = gail_misc_add_attribute (at_set,
575 ATK_TEXT_ATTR_DIRECTION,
576 g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, dir)));
579 at_set = gail_misc_layout_get_run_attributes (at_set,
580 gtk_entry_get_layout (entry),
581 (gchar*)gtk_entry_get_text (entry),
588 static AtkAttributeSet*
589 gail_entry_get_default_attributes (AtkText *text)
593 AtkAttributeSet *at_set = NULL;
595 widget = GTK_ACCESSIBLE (text)->widget;
597 /* State is defunct */
600 entry = GTK_ENTRY (widget);
602 at_set = gail_misc_get_default_attributes (at_set,
603 gtk_entry_get_layout (entry),
609 gail_entry_get_character_extents (AtkText *text,
619 PangoRectangle char_rect;
620 gint index, cursor_index, x_layout, y_layout;
621 const gchar *entry_text;
623 widget = GTK_ACCESSIBLE (text)->widget;
625 /* State is defunct */
628 entry = GTK_ENTRY (widget);
630 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
631 entry_text = gtk_entry_get_text (entry);
632 index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text;
633 cursor_index = g_utf8_offset_to_pointer (entry_text, entry->current_pos) - entry_text;
634 if (index > cursor_index)
635 index += entry->preedit_length;
636 pango_layout_index_to_pos (gtk_entry_get_layout(entry), index, &char_rect);
638 gail_misc_get_extents_from_pango_rectangle (widget, &char_rect,
639 x_layout, y_layout, x, y, width, height, coords);
643 gail_entry_get_offset_at_point (AtkText *text,
650 gint index, cursor_index, x_layout, y_layout;
651 const gchar *entry_text;
653 widget = GTK_ACCESSIBLE (text)->widget;
655 /* State is defunct */
658 entry = GTK_ENTRY (widget);
660 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
661 entry_text = gtk_entry_get_text (entry);
663 index = gail_misc_get_index_at_point_in_layout (widget,
664 gtk_entry_get_layout(entry), x_layout, y_layout, x, y, coords);
667 if (coords == ATK_XY_SCREEN || coords == ATK_XY_WINDOW)
668 return g_utf8_strlen (entry_text, -1);
674 cursor_index = g_utf8_offset_to_pointer (entry_text, entry->current_pos) - entry_text;
675 if (index >= cursor_index && entry->preedit_length)
677 if (index >= cursor_index + entry->preedit_length)
678 index -= entry->preedit_length;
680 index = cursor_index;
682 return g_utf8_pointer_to_offset (entry_text, entry_text + index);
687 gail_entry_get_n_selections (AtkText *text)
691 gint select_start, select_end;
693 widget = GTK_ACCESSIBLE (text)->widget;
695 /* State is defunct */
698 entry = GTK_ENTRY (widget);
700 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
703 if (select_start != select_end)
710 gail_entry_get_selection (AtkText *text,
718 widget = GTK_ACCESSIBLE (text)->widget;
720 /* State is defunct */
723 /* Only let the user get the selection if one is set, and if the
724 * selection_num is 0.
726 if (selection_num != 0)
729 entry = GTK_ENTRY (widget);
730 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), start_pos, end_pos);
732 if (*start_pos != *end_pos)
733 return gtk_editable_get_chars (GTK_EDITABLE (entry), *start_pos, *end_pos);
739 gail_entry_add_selection (AtkText *text,
745 gint select_start, select_end;
747 widget = GTK_ACCESSIBLE (text)->widget;
749 /* State is defunct */
752 entry = GTK_ENTRY (widget);
754 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
757 /* If there is already a selection, then don't allow another to be added,
758 * since GtkEntry only supports one selected region.
760 if (select_start == select_end)
762 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
770 gail_entry_remove_selection (AtkText *text,
775 gint select_start, select_end, caret_pos;
777 widget = GTK_ACCESSIBLE (text)->widget;
779 /* State is defunct */
782 if (selection_num != 0)
785 entry = GTK_ENTRY (widget);
786 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
789 if (select_start != select_end)
791 /* Setting the start & end of the selected region to the caret position
792 * turns off the selection.
794 caret_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
795 gtk_editable_select_region (GTK_EDITABLE (entry), caret_pos, caret_pos);
803 gail_entry_set_selection (AtkText *text,
810 gint select_start, select_end;
812 widget = GTK_ACCESSIBLE (text)->widget;
814 /* State is defunct */
817 /* Only let the user move the selection if one is set, and if the
820 if (selection_num != 0)
823 entry = GTK_ENTRY (widget);
825 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
828 if (select_start != select_end)
830 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
838 atk_editable_text_interface_init (AtkEditableTextIface *iface)
840 iface->set_text_contents = gail_entry_set_text_contents;
841 iface->insert_text = gail_entry_insert_text;
842 iface->copy_text = gail_entry_copy_text;
843 iface->cut_text = gail_entry_cut_text;
844 iface->delete_text = gail_entry_delete_text;
845 iface->paste_text = gail_entry_paste_text;
846 iface->set_run_attributes = NULL;
850 gail_entry_set_text_contents (AtkEditableText *text,
855 GtkEditable *editable;
857 widget = GTK_ACCESSIBLE (text)->widget;
859 /* State is defunct */
862 entry = GTK_ENTRY (widget);
863 editable = GTK_EDITABLE (entry);
864 if (!gtk_editable_get_editable (editable))
867 gtk_entry_set_text (entry, string);
871 gail_entry_insert_text (AtkEditableText *text,
878 GtkEditable *editable;
880 widget = GTK_ACCESSIBLE (text)->widget;
882 /* State is defunct */
885 entry = GTK_ENTRY (widget);
886 editable = GTK_EDITABLE (entry);
887 if (!gtk_editable_get_editable (editable))
890 gtk_editable_insert_text (editable, string, length, position);
891 gtk_editable_set_position (editable, *position);
895 gail_entry_copy_text (AtkEditableText *text,
901 GtkEditable *editable;
903 GtkClipboard *clipboard;
905 widget = GTK_ACCESSIBLE (text)->widget;
907 /* State is defunct */
910 entry = GTK_ENTRY (widget);
911 editable = GTK_EDITABLE (entry);
912 str = gtk_editable_get_chars (editable, start_pos, end_pos);
913 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
914 GDK_SELECTION_CLIPBOARD);
915 gtk_clipboard_set_text (clipboard, str, -1);
919 gail_entry_cut_text (AtkEditableText *text,
925 GtkEditable *editable;
927 GtkClipboard *clipboard;
929 widget = GTK_ACCESSIBLE (text)->widget;
931 /* State is defunct */
934 entry = GTK_ENTRY (widget);
935 editable = GTK_EDITABLE (entry);
936 if (!gtk_editable_get_editable (editable))
938 str = gtk_editable_get_chars (editable, start_pos, end_pos);
939 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
940 GDK_SELECTION_CLIPBOARD);
941 gtk_clipboard_set_text (clipboard, str, -1);
942 gtk_editable_delete_text (editable, start_pos, end_pos);
946 gail_entry_delete_text (AtkEditableText *text,
952 GtkEditable *editable;
954 widget = GTK_ACCESSIBLE (text)->widget;
956 /* State is defunct */
959 entry = GTK_ENTRY (widget);
960 editable = GTK_EDITABLE (entry);
961 if (!gtk_editable_get_editable (editable))
964 gtk_editable_delete_text (editable, start_pos, end_pos);
968 gail_entry_paste_text (AtkEditableText *text,
972 GtkEditable *editable;
973 GailEntryPaste paste_struct;
974 GtkClipboard *clipboard;
976 widget = GTK_ACCESSIBLE (text)->widget;
978 /* State is defunct */
981 editable = GTK_EDITABLE (widget);
982 if (!gtk_editable_get_editable (editable))
984 paste_struct.entry = GTK_ENTRY (widget);
985 paste_struct.position = position;
987 g_object_ref (paste_struct.entry);
988 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
989 GDK_SELECTION_CLIPBOARD);
990 gtk_clipboard_request_text (clipboard,
991 gail_entry_paste_received, &paste_struct);
995 gail_entry_paste_received (GtkClipboard *clipboard,
999 GailEntryPaste* paste_struct = (GailEntryPaste *)data;
1002 gtk_editable_insert_text (GTK_EDITABLE (paste_struct->entry), text, -1,
1003 &(paste_struct->position));
1005 g_object_unref (paste_struct->entry);
1011 gail_entry_idle_notify_insert (gpointer data)
1015 entry = GAIL_ENTRY (data);
1016 entry->insert_idle_handler = 0;
1017 gail_entry_notify_insert (entry);
1023 gail_entry_notify_insert (GailEntry *entry)
1025 if (entry->signal_name_insert)
1027 g_signal_emit_by_name (entry,
1028 entry->signal_name_insert,
1029 entry->position_insert,
1030 entry->length_insert);
1031 entry->signal_name_insert = NULL;
1035 /* Note arg1 returns the character at the start of the insert.
1036 * arg2 returns the number of characters inserted.
1039 _gail_entry_insert_text_cb (GtkEntry *entry,
1044 AtkObject *accessible;
1045 GailEntry *gail_entry;
1046 gint *position = (gint *) arg3;
1048 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1049 gail_entry = GAIL_ENTRY (accessible);
1050 if (!gail_entry->signal_name_insert)
1052 gail_entry->signal_name_insert = "text_changed::insert";
1053 gail_entry->position_insert = *position;
1054 gail_entry->length_insert = g_utf8_strlen(arg1, arg2);
1057 * The signal will be emitted when the cursor position is updated.
1058 * or in an idle handler if it not updated.
1060 if (gail_entry->insert_idle_handler == 0)
1061 gail_entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, gail_entry);
1065 gail_entry_get_character_at_offset (AtkText *text,
1074 widget = GTK_ACCESSIBLE (text)->widget;
1076 /* State is defunct */
1079 entry = GAIL_ENTRY (text);
1080 string = gail_text_util_get_substring (entry->textutil, 0, -1);
1081 if (offset >= g_utf8_strlen (string, -1))
1087 index = g_utf8_offset_to_pointer (string, offset);
1089 unichar = g_utf8_get_char(index);
1097 gail_entry_notify_delete (GailEntry *entry)
1099 if (entry->signal_name_delete)
1101 g_signal_emit_by_name (entry,
1102 entry->signal_name_delete,
1103 entry->position_delete,
1104 entry->length_delete);
1105 entry->signal_name_delete = NULL;
1109 /* Note arg1 returns the start of the delete range, arg2 returns the
1110 * end of the delete range if multiple characters are deleted.
1113 _gail_entry_delete_text_cb (GtkEntry *entry,
1117 AtkObject *accessible;
1118 GailEntry *gail_entry;
1121 * Zero length text deleted so ignore
1123 if (arg2 - arg1 == 0)
1126 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1127 gail_entry = GAIL_ENTRY (accessible);
1128 if (!gail_entry->signal_name_delete)
1130 gail_entry->signal_name_delete = "text_changed::delete";
1131 gail_entry->position_delete = arg1;
1132 gail_entry->length_delete = arg2 - arg1;
1134 gail_entry_notify_delete (gail_entry);
1138 _gail_entry_changed_cb (GtkEntry *entry)
1140 AtkObject *accessible;
1141 GailEntry *gail_entry;
1143 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1145 gail_entry = GAIL_ENTRY (accessible);
1147 text_setup (gail_entry, entry);
1151 check_for_selection_change (GailEntry *entry,
1152 GtkEntry *gtk_entry)
1154 gboolean ret_val = FALSE;
1156 if (gtk_entry->current_pos != gtk_entry->selection_bound)
1158 if (gtk_entry->current_pos != entry->cursor_position ||
1159 gtk_entry->selection_bound != entry->selection_bound)
1161 * This check is here as this function can be called
1162 * for notification of selection_bound and current_pos.
1163 * The values of current_pos and selection_bound may be the same
1164 * for both notifications and we only want to generate one
1165 * text_selection_changed signal.
1171 /* We had a selection */
1172 ret_val = (entry->cursor_position != entry->selection_bound);
1174 entry->cursor_position = gtk_entry->current_pos;
1175 entry->selection_bound = gtk_entry->selection_bound;
1181 atk_action_interface_init (AtkActionIface *iface)
1183 iface->do_action = gail_entry_do_action;
1184 iface->get_n_actions = gail_entry_get_n_actions;
1185 iface->get_description = gail_entry_get_description;
1186 iface->get_keybinding = gail_entry_get_keybinding;
1187 iface->get_name = gail_entry_action_get_name;
1188 iface->set_description = gail_entry_set_description;
1192 gail_entry_do_action (AtkAction *action,
1197 gboolean return_value = TRUE;
1199 entry = GAIL_ENTRY (action);
1200 widget = GTK_ACCESSIBLE (action)->widget;
1207 if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1213 if (entry->action_idle_handler)
1214 return_value = FALSE;
1216 entry->action_idle_handler = gdk_threads_add_idle (idle_do_action, entry);
1219 return_value = FALSE;
1222 return return_value;
1226 idle_do_action (gpointer data)
1231 entry = GAIL_ENTRY (data);
1232 entry->action_idle_handler = 0;
1233 widget = GTK_ACCESSIBLE (entry)->widget;
1234 if (widget == NULL /* State is defunct */ ||
1235 !gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1238 gtk_widget_activate (widget);
1244 gail_entry_get_n_actions (AtkAction *action)
1249 static G_CONST_RETURN gchar*
1250 gail_entry_get_description (AtkAction *action,
1254 G_CONST_RETURN gchar *return_value;
1256 entry = GAIL_ENTRY (action);
1260 return_value = entry->activate_description;
1263 return_value = NULL;
1266 return return_value;
1269 static G_CONST_RETURN gchar*
1270 gail_entry_get_keybinding (AtkAction *action,
1274 gchar *return_value = NULL;
1276 entry = GAIL_ENTRY (action);
1282 * We look for a mnemonic on the label
1286 AtkRelationSet *set;
1287 AtkRelation *relation;
1289 gpointer target_object;
1292 entry = GAIL_ENTRY (action);
1293 widget = GTK_ACCESSIBLE (entry)->widget;
1300 /* Find labelled-by relation */
1302 set = atk_object_ref_relation_set (ATK_OBJECT (action));
1306 relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
1309 target = atk_relation_get_target (relation);
1311 target_object = g_ptr_array_index (target, 0);
1312 if (GTK_IS_ACCESSIBLE (target_object))
1314 label = GTK_ACCESSIBLE (target_object)->widget;
1318 g_object_unref (set);
1320 if (GTK_IS_LABEL (label))
1322 key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
1323 if (key_val != GDK_VoidSymbol)
1324 return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
1326 g_free (entry->activate_keybinding);
1327 entry->activate_keybinding = return_value;
1333 return return_value;
1336 static G_CONST_RETURN gchar*
1337 gail_entry_action_get_name (AtkAction *action,
1340 G_CONST_RETURN gchar *return_value;
1345 return_value = "activate";
1348 return_value = NULL;
1351 return return_value;
1355 gail_entry_set_description (AtkAction *action,
1362 entry = GAIL_ENTRY (action);
1366 value = &entry->activate_description;
1376 *value = g_strdup (desc);