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 void gail_entry_notify_insert (GailEntry *entry);
135 static void gail_entry_notify_delete (GailEntry *entry);
136 static void _gail_entry_insert_text_cb (GtkEntry *entry,
140 static void _gail_entry_delete_text_cb (GtkEntry *entry,
143 static void _gail_entry_changed_cb (GtkEntry *entry);
144 static gboolean check_for_selection_change (GailEntry *entry,
145 GtkEntry *gtk_entry);
147 static void atk_action_interface_init (AtkActionIface *iface);
149 static gboolean gail_entry_do_action (AtkAction *action,
151 static gboolean idle_do_action (gpointer data);
152 static gint gail_entry_get_n_actions (AtkAction *action);
153 static G_CONST_RETURN gchar* gail_entry_get_description (AtkAction *action,
155 static G_CONST_RETURN gchar* gail_entry_get_keybinding (AtkAction *action,
157 static G_CONST_RETURN gchar* gail_entry_action_get_name (AtkAction *action,
159 static gboolean gail_entry_set_description (AtkAction *action,
163 typedef struct _GailEntryPaste GailEntryPaste;
165 struct _GailEntryPaste
171 G_DEFINE_TYPE_WITH_CODE (GailEntry, gail_entry, GAIL_TYPE_WIDGET,
172 G_IMPLEMENT_INTERFACE (ATK_TYPE_EDITABLE_TEXT, atk_editable_text_interface_init)
173 G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init)
174 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
177 gail_entry_class_init (GailEntryClass *klass)
179 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
180 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
181 GailWidgetClass *widget_class;
183 widget_class = (GailWidgetClass*)klass;
185 gobject_class->finalize = gail_entry_finalize;
187 class->ref_state_set = gail_entry_ref_state_set;
188 class->get_index_in_parent = gail_entry_get_index_in_parent;
189 class->initialize = gail_entry_real_initialize;
191 widget_class->notify_gtk = gail_entry_real_notify_gtk;
195 gail_entry_init (GailEntry *entry)
197 entry->textutil = NULL;
198 entry->signal_name_insert = NULL;
199 entry->signal_name_delete = NULL;
200 entry->cursor_position = 0;
201 entry->selection_bound = 0;
202 entry->activate_description = NULL;
203 entry->activate_keybinding = NULL;
207 gail_entry_real_initialize (AtkObject *obj,
211 GailEntry *gail_entry;
213 ATK_OBJECT_CLASS (gail_entry_parent_class)->initialize (obj, data);
215 gail_entry = GAIL_ENTRY (obj);
216 gail_entry->textutil = gail_text_util_new ();
218 g_assert (GTK_IS_ENTRY (data));
220 entry = GTK_ENTRY (data);
221 text_setup (gail_entry, entry);
222 gail_entry->cursor_position = entry->current_pos;
223 gail_entry->selection_bound = entry->selection_bound;
225 /* Set up signal callbacks */
226 g_signal_connect (data, "insert-text",
227 G_CALLBACK (_gail_entry_insert_text_cb), NULL);
228 g_signal_connect (data, "delete-text",
229 G_CALLBACK (_gail_entry_delete_text_cb), NULL);
230 g_signal_connect (data, "changed",
231 G_CALLBACK (_gail_entry_changed_cb), NULL);
234 obj->role = ATK_ROLE_TEXT;
236 obj->role = ATK_ROLE_PASSWORD_TEXT;
240 gail_entry_real_notify_gtk (GObject *obj,
248 widget = GTK_WIDGET (obj);
249 atk_obj = gtk_widget_get_accessible (widget);
250 gtk_entry = GTK_ENTRY (widget);
251 entry = GAIL_ENTRY (atk_obj);
253 if (strcmp (pspec->name, "cursor-position") == 0)
255 gail_entry_notify_insert (entry);
257 if (check_for_selection_change (entry, gtk_entry))
258 g_signal_emit_by_name (atk_obj, "text_selection_changed");
260 * The entry cursor position has moved so generate the signal.
262 g_signal_emit_by_name (atk_obj, "text_caret_moved",
263 entry->cursor_position);
265 else if (strcmp (pspec->name, "selection-bound") == 0)
267 gail_entry_notify_insert (entry);
269 if (check_for_selection_change (entry, gtk_entry))
270 g_signal_emit_by_name (atk_obj, "text_selection_changed");
272 else if (strcmp (pspec->name, "editable") == 0)
276 g_object_get (obj, "editable", &value, NULL);
277 atk_object_notify_state_change (atk_obj, ATK_STATE_EDITABLE,
280 else if (strcmp (pspec->name, "visibility") == 0)
285 text_setup (entry, gtk_entry);
286 visibility = gtk_entry_get_visibility (gtk_entry);
287 new_role = visibility ? ATK_ROLE_TEXT : ATK_ROLE_PASSWORD_TEXT;
288 atk_object_set_role (atk_obj, new_role);
290 else if (strcmp (pspec->name, "invisible-char") == 0)
292 text_setup (entry, gtk_entry);
295 GAIL_WIDGET_CLASS (gail_entry_parent_class)->notify_gtk (obj, pspec);
299 text_setup (GailEntry *entry,
302 if (gtk_entry_get_visibility (gtk_entry))
304 gail_text_util_text_setup (entry->textutil, gtk_entry_get_text (gtk_entry));
308 gunichar invisible_char;
309 GString *tmp_string = g_string_new (NULL);
314 invisible_char = gtk_entry_get_invisible_char (gtk_entry);
315 if (invisible_char == 0)
316 invisible_char = ' ';
318 ch_len = g_unichar_to_utf8 (invisible_char, buf);
319 for (i = 0; i < gtk_entry->text_length; i++)
321 g_string_append_len (tmp_string, buf, ch_len);
324 gail_text_util_text_setup (entry->textutil, tmp_string->str);
325 g_string_free (tmp_string, TRUE);
331 gail_entry_finalize (GObject *object)
333 GailEntry *entry = GAIL_ENTRY (object);
335 g_object_unref (entry->textutil);
336 g_free (entry->activate_description);
337 g_free (entry->activate_keybinding);
338 if (entry->action_idle_handler)
340 g_source_remove (entry->action_idle_handler);
341 entry->action_idle_handler = 0;
343 if (entry->insert_idle_handler)
345 g_source_remove (entry->insert_idle_handler);
346 entry->insert_idle_handler = 0;
348 G_OBJECT_CLASS (gail_entry_parent_class)->finalize (object);
352 gail_entry_new (GtkWidget *widget)
355 AtkObject *accessible;
357 g_return_val_if_fail (GTK_IS_ENTRY (widget), NULL);
359 object = g_object_new (GAIL_TYPE_ENTRY, NULL);
361 accessible = ATK_OBJECT (object);
362 atk_object_initialize (accessible, widget);
368 gail_entry_get_index_in_parent (AtkObject *accessible)
371 * If the parent widget is a combo box then the index is 1
372 * otherwise do the normal thing.
374 if (accessible->accessible_parent)
375 if (GAIL_IS_COMBO (accessible->accessible_parent) ||
376 GAIL_IS_COMBO_BOX (accessible->accessible_parent))
379 return ATK_OBJECT_CLASS (gail_entry_parent_class)->get_index_in_parent (accessible);
385 gail_entry_ref_state_set (AtkObject *accessible)
387 AtkStateSet *state_set;
392 state_set = ATK_OBJECT_CLASS (gail_entry_parent_class)->ref_state_set (accessible);
393 widget = GTK_ACCESSIBLE (accessible)->widget;
398 entry = GTK_ENTRY (widget);
400 g_object_get (G_OBJECT (entry), "editable", &value, NULL);
402 atk_state_set_add_state (state_set, ATK_STATE_EDITABLE);
403 atk_state_set_add_state (state_set, ATK_STATE_SINGLE_LINE);
411 atk_text_interface_init (AtkTextIface *iface)
413 iface->get_text = gail_entry_get_text;
414 iface->get_character_at_offset = gail_entry_get_character_at_offset;
415 iface->get_text_before_offset = gail_entry_get_text_before_offset;
416 iface->get_text_at_offset = gail_entry_get_text_at_offset;
417 iface->get_text_after_offset = gail_entry_get_text_after_offset;
418 iface->get_caret_offset = gail_entry_get_caret_offset;
419 iface->set_caret_offset = gail_entry_set_caret_offset;
420 iface->get_character_count = gail_entry_get_character_count;
421 iface->get_n_selections = gail_entry_get_n_selections;
422 iface->get_selection = gail_entry_get_selection;
423 iface->add_selection = gail_entry_add_selection;
424 iface->remove_selection = gail_entry_remove_selection;
425 iface->set_selection = gail_entry_set_selection;
426 iface->get_run_attributes = gail_entry_get_run_attributes;
427 iface->get_default_attributes = gail_entry_get_default_attributes;
428 iface->get_character_extents = gail_entry_get_character_extents;
429 iface->get_offset_at_point = gail_entry_get_offset_at_point;
433 gail_entry_get_text (AtkText *text,
439 widget = GTK_ACCESSIBLE (text)->widget;
441 /* State is defunct */
444 return gail_text_util_get_substring (GAIL_ENTRY (text)->textutil, start_pos, end_pos);
448 gail_entry_get_text_before_offset (AtkText *text,
450 AtkTextBoundary boundary_type,
457 widget = GTK_ACCESSIBLE (text)->widget;
459 /* State is defunct */
463 entry = GTK_ENTRY (widget);
465 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
466 gtk_entry_get_layout (entry), GAIL_BEFORE_OFFSET,
467 boundary_type, offset, start_offset, end_offset);
471 gail_entry_get_text_at_offset (AtkText *text,
473 AtkTextBoundary boundary_type,
480 widget = GTK_ACCESSIBLE (text)->widget;
482 /* State is defunct */
486 entry = GTK_ENTRY (widget);
488 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
489 gtk_entry_get_layout (entry), GAIL_AT_OFFSET,
490 boundary_type, offset, start_offset, end_offset);
494 gail_entry_get_text_after_offset (AtkText *text,
496 AtkTextBoundary boundary_type,
503 widget = GTK_ACCESSIBLE (text)->widget;
505 /* State is defunct */
509 entry = GTK_ENTRY (widget);
511 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
512 gtk_entry_get_layout (entry), GAIL_AFTER_OFFSET,
513 boundary_type, offset, start_offset, end_offset);
517 gail_entry_get_character_count (AtkText *text)
522 widget = GTK_ACCESSIBLE (text)->widget;
524 /* State is defunct */
527 entry = GTK_ENTRY (widget);
528 return g_utf8_strlen (gtk_entry_get_text (entry), -1);
532 gail_entry_get_caret_offset (AtkText *text)
537 widget = GTK_ACCESSIBLE (text)->widget;
539 /* State is defunct */
542 entry = GTK_ENTRY (widget);
544 return gtk_editable_get_position (GTK_EDITABLE (entry));
548 gail_entry_set_caret_offset (AtkText *text, gint offset)
553 widget = GTK_ACCESSIBLE (text)->widget;
555 /* State is defunct */
558 entry = GTK_ENTRY (widget);
560 gtk_editable_set_position (GTK_EDITABLE (entry), offset);
564 static AtkAttributeSet*
565 gail_entry_get_run_attributes (AtkText *text,
572 AtkAttributeSet *at_set = NULL;
573 GtkTextDirection dir;
575 widget = GTK_ACCESSIBLE (text)->widget;
577 /* State is defunct */
580 entry = GTK_ENTRY (widget);
582 dir = gtk_widget_get_direction (widget);
583 if (dir == GTK_TEXT_DIR_RTL)
585 at_set = gail_misc_add_attribute (at_set,
586 ATK_TEXT_ATTR_DIRECTION,
587 g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, dir)));
590 at_set = gail_misc_layout_get_run_attributes (at_set,
591 gtk_entry_get_layout (entry),
599 static AtkAttributeSet*
600 gail_entry_get_default_attributes (AtkText *text)
604 AtkAttributeSet *at_set = NULL;
606 widget = GTK_ACCESSIBLE (text)->widget;
608 /* State is defunct */
611 entry = GTK_ENTRY (widget);
613 at_set = gail_misc_get_default_attributes (at_set,
614 gtk_entry_get_layout (entry),
620 gail_entry_get_character_extents (AtkText *text,
630 PangoRectangle char_rect;
631 gint index, cursor_index, x_layout, y_layout;
633 widget = GTK_ACCESSIBLE (text)->widget;
635 /* State is defunct */
638 entry = GTK_ENTRY (widget);
640 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
641 index = g_utf8_offset_to_pointer (entry->text, offset) - entry->text;
642 cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) -
644 if (index > cursor_index)
645 index += entry->preedit_length;
646 pango_layout_index_to_pos (gtk_entry_get_layout(entry), index, &char_rect);
648 gail_misc_get_extents_from_pango_rectangle (widget, &char_rect,
649 x_layout, y_layout, x, y, width, height, coords);
653 gail_entry_get_offset_at_point (AtkText *text,
660 gint index, cursor_index, x_layout, y_layout;
662 widget = GTK_ACCESSIBLE (text)->widget;
664 /* State is defunct */
667 entry = GTK_ENTRY (widget);
669 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
671 index = gail_misc_get_index_at_point_in_layout (widget,
672 gtk_entry_get_layout(entry), x_layout, y_layout, x, y, coords);
675 if (coords == ATK_XY_SCREEN || coords == ATK_XY_WINDOW)
676 return g_utf8_strlen (entry->text, -1);
682 cursor_index = g_utf8_offset_to_pointer (entry->text,
683 entry->current_pos) -
685 if (index >= cursor_index && entry->preedit_length)
687 if (index >= cursor_index + entry->preedit_length)
688 index -= entry->preedit_length;
690 index = cursor_index;
692 return g_utf8_pointer_to_offset (entry->text, entry->text + index);
697 gail_entry_get_n_selections (AtkText *text)
701 gint select_start, select_end;
703 widget = GTK_ACCESSIBLE (text)->widget;
705 /* State is defunct */
708 entry = GTK_ENTRY (widget);
710 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
713 if (select_start != select_end)
720 gail_entry_get_selection (AtkText *text,
728 widget = GTK_ACCESSIBLE (text)->widget;
730 /* State is defunct */
733 /* Only let the user get the selection if one is set, and if the
734 * selection_num is 0.
736 if (selection_num != 0)
739 entry = GTK_ENTRY (widget);
740 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), start_pos, end_pos);
742 if (*start_pos != *end_pos)
743 return gtk_editable_get_chars (GTK_EDITABLE (entry), *start_pos, *end_pos);
749 gail_entry_add_selection (AtkText *text,
755 gint select_start, select_end;
757 widget = GTK_ACCESSIBLE (text)->widget;
759 /* State is defunct */
762 entry = GTK_ENTRY (widget);
764 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
767 /* If there is already a selection, then don't allow another to be added,
768 * since GtkEntry only supports one selected region.
770 if (select_start == select_end)
772 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
780 gail_entry_remove_selection (AtkText *text,
785 gint select_start, select_end, caret_pos;
787 widget = GTK_ACCESSIBLE (text)->widget;
789 /* State is defunct */
792 if (selection_num != 0)
795 entry = GTK_ENTRY (widget);
796 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
799 if (select_start != select_end)
801 /* Setting the start & end of the selected region to the caret position
802 * turns off the selection.
804 caret_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
805 gtk_editable_select_region (GTK_EDITABLE (entry), caret_pos, caret_pos);
813 gail_entry_set_selection (AtkText *text,
820 gint select_start, select_end;
822 widget = GTK_ACCESSIBLE (text)->widget;
824 /* State is defunct */
827 /* Only let the user move the selection if one is set, and if the
830 if (selection_num != 0)
833 entry = GTK_ENTRY (widget);
835 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
838 if (select_start != select_end)
840 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
848 atk_editable_text_interface_init (AtkEditableTextIface *iface)
850 iface->set_text_contents = gail_entry_set_text_contents;
851 iface->insert_text = gail_entry_insert_text;
852 iface->copy_text = gail_entry_copy_text;
853 iface->cut_text = gail_entry_cut_text;
854 iface->delete_text = gail_entry_delete_text;
855 iface->paste_text = gail_entry_paste_text;
856 iface->set_run_attributes = NULL;
860 gail_entry_set_text_contents (AtkEditableText *text,
865 GtkEditable *editable;
867 widget = GTK_ACCESSIBLE (text)->widget;
869 /* State is defunct */
872 entry = GTK_ENTRY (widget);
873 editable = GTK_EDITABLE (entry);
874 if (!gtk_editable_get_editable (editable))
877 gtk_entry_set_text (entry, string);
881 gail_entry_insert_text (AtkEditableText *text,
888 GtkEditable *editable;
890 widget = GTK_ACCESSIBLE (text)->widget;
892 /* State is defunct */
895 entry = GTK_ENTRY (widget);
896 editable = GTK_EDITABLE (entry);
897 if (!gtk_editable_get_editable (editable))
900 gtk_editable_insert_text (editable, string, length, position);
904 gail_entry_copy_text (AtkEditableText *text,
910 GtkEditable *editable;
913 widget = GTK_ACCESSIBLE (text)->widget;
915 /* State is defunct */
918 entry = GTK_ENTRY (widget);
919 editable = GTK_EDITABLE (entry);
920 str = gtk_editable_get_chars (editable, start_pos, end_pos);
921 gtk_clipboard_set_text (gtk_clipboard_get (GDK_NONE), str, -1);
925 gail_entry_cut_text (AtkEditableText *text,
931 GtkEditable *editable;
934 widget = GTK_ACCESSIBLE (text)->widget;
936 /* State is defunct */
939 entry = GTK_ENTRY (widget);
940 editable = GTK_EDITABLE (entry);
941 if (!gtk_editable_get_editable (editable))
943 str = gtk_editable_get_chars (editable, start_pos, end_pos);
944 gtk_clipboard_set_text (gtk_clipboard_get (GDK_NONE), str, -1);
945 gtk_editable_delete_text (editable, start_pos, end_pos);
949 gail_entry_delete_text (AtkEditableText *text,
955 GtkEditable *editable;
957 widget = GTK_ACCESSIBLE (text)->widget;
959 /* State is defunct */
962 entry = GTK_ENTRY (widget);
963 editable = GTK_EDITABLE (entry);
964 if (!gtk_editable_get_editable (editable))
967 gtk_editable_delete_text (editable, start_pos, end_pos);
971 gail_entry_paste_text (AtkEditableText *text,
975 GtkEditable *editable;
976 GailEntryPaste paste_struct;
978 widget = GTK_ACCESSIBLE (text)->widget;
980 /* State is defunct */
983 editable = GTK_EDITABLE (widget);
984 if (!gtk_editable_get_editable (editable))
986 paste_struct.entry = GTK_ENTRY (widget);
987 paste_struct.position = position;
989 g_object_ref (paste_struct.entry);
990 gtk_clipboard_request_text (gtk_clipboard_get(GDK_NONE),
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 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 (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_SENSITIVE (widget) || !GTK_WIDGET_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_SENSITIVE (widget) || !GTK_WIDGET_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);