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 "gailcombobox.h"
27 #include <libgail-util/gailmisc.h>
29 static void gail_entry_class_init (GailEntryClass *klass);
30 static void gail_entry_init (GailEntry *entry);
31 static void gail_entry_real_initialize (AtkObject *obj,
33 static void text_setup (GailEntry *entry,
35 static void gail_entry_real_notify_gtk (GObject *obj,
37 static void gail_entry_finalize (GObject *object);
39 static gint gail_entry_get_index_in_parent (AtkObject *accessible);
43 static AtkStateSet* gail_entry_ref_state_set (AtkObject *accessible);
47 static void atk_text_interface_init (AtkTextIface *iface);
49 static gchar* gail_entry_get_text (AtkText *text,
52 static gunichar gail_entry_get_character_at_offset
55 static gchar* gail_entry_get_text_before_offset(AtkText *text,
57 AtkTextBoundary boundary_type,
60 static gchar* gail_entry_get_text_at_offset (AtkText *text,
62 AtkTextBoundary boundary_type,
65 static gchar* gail_entry_get_text_after_offset (AtkText *text,
67 AtkTextBoundary boundary_type,
70 static gint gail_entry_get_caret_offset (AtkText *text);
71 static gboolean gail_entry_set_caret_offset (AtkText *text,
73 static gint gail_entry_get_n_selections (AtkText *text);
74 static gchar* gail_entry_get_selection (AtkText *text,
78 static gboolean gail_entry_add_selection (AtkText *text,
81 static gboolean gail_entry_remove_selection (AtkText *text,
83 static gboolean gail_entry_set_selection (AtkText *text,
87 static gint gail_entry_get_character_count (AtkText *text);
88 static AtkAttributeSet * gail_entry_get_run_attributes
93 static AtkAttributeSet * gail_entry_get_default_attributes
95 static void gail_entry_get_character_extents (AtkText *text,
101 AtkCoordType coords);
102 static gint gail_entry_get_offset_at_point (AtkText *text,
105 AtkCoordType coords);
106 /* atkeditabletext.h */
108 static void atk_editable_text_interface_init (AtkEditableTextIface *iface);
109 static void gail_entry_set_text_contents (AtkEditableText *text,
110 const gchar *string);
111 static void gail_entry_insert_text (AtkEditableText *text,
115 static void gail_entry_copy_text (AtkEditableText *text,
118 static void gail_entry_cut_text (AtkEditableText *text,
121 static void gail_entry_delete_text (AtkEditableText *text,
124 static void gail_entry_paste_text (AtkEditableText *text,
126 static void gail_entry_paste_received (GtkClipboard *clipboard,
133 static gboolean gail_entry_idle_notify_insert (gpointer data);
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);
233 if (gtk_entry_get_visibility (entry))
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 if (entry->insert_idle_handler == 0)
256 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
258 if (check_for_selection_change (entry, gtk_entry))
259 g_signal_emit_by_name (atk_obj, "text_selection_changed");
261 * The entry cursor position has moved so generate the signal.
263 g_signal_emit_by_name (atk_obj, "text_caret_moved",
264 entry->cursor_position);
266 else if (strcmp (pspec->name, "selection-bound") == 0)
268 if (entry->insert_idle_handler == 0)
269 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
271 if (check_for_selection_change (entry, gtk_entry))
272 g_signal_emit_by_name (atk_obj, "text_selection_changed");
274 else if (strcmp (pspec->name, "editable") == 0)
278 g_object_get (obj, "editable", &value, NULL);
279 atk_object_notify_state_change (atk_obj, ATK_STATE_EDITABLE,
282 else if (strcmp (pspec->name, "visibility") == 0)
287 text_setup (entry, gtk_entry);
288 visibility = gtk_entry_get_visibility (gtk_entry);
289 new_role = visibility ? ATK_ROLE_TEXT : ATK_ROLE_PASSWORD_TEXT;
290 atk_object_set_role (atk_obj, new_role);
292 else if (strcmp (pspec->name, "invisible-char") == 0)
294 text_setup (entry, gtk_entry);
297 GAIL_WIDGET_CLASS (gail_entry_parent_class)->notify_gtk (obj, pspec);
301 text_setup (GailEntry *entry,
304 if (gtk_entry_get_visibility (gtk_entry))
306 gail_text_util_text_setup (entry->textutil, gtk_entry_get_text (gtk_entry));
310 gunichar invisible_char;
311 GString *tmp_string = g_string_new (NULL);
317 invisible_char = gtk_entry_get_invisible_char (gtk_entry);
318 if (invisible_char == 0)
319 invisible_char = ' ';
321 ch_len = g_unichar_to_utf8 (invisible_char, buf);
322 length = gtk_entry_get_text_length (gtk_entry);
323 for (i = 0; i < length; i++)
325 g_string_append_len (tmp_string, buf, ch_len);
328 gail_text_util_text_setup (entry->textutil, tmp_string->str);
329 g_string_free (tmp_string, TRUE);
335 gail_entry_finalize (GObject *object)
337 GailEntry *entry = GAIL_ENTRY (object);
339 g_object_unref (entry->textutil);
340 g_free (entry->activate_description);
341 g_free (entry->activate_keybinding);
342 if (entry->action_idle_handler)
344 g_source_remove (entry->action_idle_handler);
345 entry->action_idle_handler = 0;
347 if (entry->insert_idle_handler)
349 g_source_remove (entry->insert_idle_handler);
350 entry->insert_idle_handler = 0;
352 G_OBJECT_CLASS (gail_entry_parent_class)->finalize (object);
356 gail_entry_get_index_in_parent (AtkObject *accessible)
359 * If the parent widget is a combo box then the index is 1
360 * otherwise do the normal thing.
362 if (accessible->accessible_parent)
363 if (GAIL_IS_COMBO (accessible->accessible_parent) ||
364 GAIL_IS_COMBO_BOX (accessible->accessible_parent))
367 return ATK_OBJECT_CLASS (gail_entry_parent_class)->get_index_in_parent (accessible);
373 gail_entry_ref_state_set (AtkObject *accessible)
375 AtkStateSet *state_set;
380 state_set = ATK_OBJECT_CLASS (gail_entry_parent_class)->ref_state_set (accessible);
381 widget = GTK_ACCESSIBLE (accessible)->widget;
386 entry = GTK_ENTRY (widget);
388 g_object_get (G_OBJECT (entry), "editable", &value, NULL);
390 atk_state_set_add_state (state_set, ATK_STATE_EDITABLE);
391 atk_state_set_add_state (state_set, ATK_STATE_SINGLE_LINE);
399 atk_text_interface_init (AtkTextIface *iface)
401 iface->get_text = gail_entry_get_text;
402 iface->get_character_at_offset = gail_entry_get_character_at_offset;
403 iface->get_text_before_offset = gail_entry_get_text_before_offset;
404 iface->get_text_at_offset = gail_entry_get_text_at_offset;
405 iface->get_text_after_offset = gail_entry_get_text_after_offset;
406 iface->get_caret_offset = gail_entry_get_caret_offset;
407 iface->set_caret_offset = gail_entry_set_caret_offset;
408 iface->get_character_count = gail_entry_get_character_count;
409 iface->get_n_selections = gail_entry_get_n_selections;
410 iface->get_selection = gail_entry_get_selection;
411 iface->add_selection = gail_entry_add_selection;
412 iface->remove_selection = gail_entry_remove_selection;
413 iface->set_selection = gail_entry_set_selection;
414 iface->get_run_attributes = gail_entry_get_run_attributes;
415 iface->get_default_attributes = gail_entry_get_default_attributes;
416 iface->get_character_extents = gail_entry_get_character_extents;
417 iface->get_offset_at_point = gail_entry_get_offset_at_point;
421 gail_entry_get_text (AtkText *text,
427 widget = GTK_ACCESSIBLE (text)->widget;
429 /* State is defunct */
432 return gail_text_util_get_substring (GAIL_ENTRY (text)->textutil, start_pos, end_pos);
436 gail_entry_get_text_before_offset (AtkText *text,
438 AtkTextBoundary boundary_type,
445 widget = GTK_ACCESSIBLE (text)->widget;
447 /* State is defunct */
451 entry = GTK_ENTRY (widget);
453 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
454 gtk_entry_get_layout (entry), GAIL_BEFORE_OFFSET,
455 boundary_type, offset, start_offset, end_offset);
459 gail_entry_get_text_at_offset (AtkText *text,
461 AtkTextBoundary boundary_type,
468 widget = GTK_ACCESSIBLE (text)->widget;
470 /* State is defunct */
474 entry = GTK_ENTRY (widget);
476 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
477 gtk_entry_get_layout (entry), GAIL_AT_OFFSET,
478 boundary_type, offset, start_offset, end_offset);
482 gail_entry_get_text_after_offset (AtkText *text,
484 AtkTextBoundary boundary_type,
491 widget = GTK_ACCESSIBLE (text)->widget;
493 /* State is defunct */
497 entry = GTK_ENTRY (widget);
499 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
500 gtk_entry_get_layout (entry), GAIL_AFTER_OFFSET,
501 boundary_type, offset, start_offset, end_offset);
505 gail_entry_get_character_count (AtkText *text)
510 widget = GTK_ACCESSIBLE (text)->widget;
512 /* State is defunct */
515 entry = GTK_ENTRY (widget);
516 return g_utf8_strlen (gtk_entry_get_text (entry), -1);
520 gail_entry_get_caret_offset (AtkText *text)
525 widget = GTK_ACCESSIBLE (text)->widget;
527 /* State is defunct */
530 entry = GTK_ENTRY (widget);
532 return gtk_editable_get_position (GTK_EDITABLE (entry));
536 gail_entry_set_caret_offset (AtkText *text, gint offset)
541 widget = GTK_ACCESSIBLE (text)->widget;
543 /* State is defunct */
546 entry = GTK_ENTRY (widget);
548 gtk_editable_set_position (GTK_EDITABLE (entry), offset);
552 static AtkAttributeSet*
553 gail_entry_get_run_attributes (AtkText *text,
560 AtkAttributeSet *at_set = NULL;
561 GtkTextDirection dir;
563 widget = GTK_ACCESSIBLE (text)->widget;
565 /* State is defunct */
568 entry = GTK_ENTRY (widget);
570 dir = gtk_widget_get_direction (widget);
571 if (dir == GTK_TEXT_DIR_RTL)
573 at_set = gail_misc_add_attribute (at_set,
574 ATK_TEXT_ATTR_DIRECTION,
575 g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, dir)));
578 at_set = gail_misc_layout_get_run_attributes (at_set,
579 gtk_entry_get_layout (entry),
580 (gchar*)gtk_entry_get_text (entry),
587 static AtkAttributeSet*
588 gail_entry_get_default_attributes (AtkText *text)
592 AtkAttributeSet *at_set = NULL;
594 widget = GTK_ACCESSIBLE (text)->widget;
596 /* State is defunct */
599 entry = GTK_ENTRY (widget);
601 at_set = gail_misc_get_default_attributes (at_set,
602 gtk_entry_get_layout (entry),
608 gail_entry_get_character_extents (AtkText *text,
618 PangoRectangle char_rect;
619 gint index, cursor_index, x_layout, y_layout;
620 const gchar *entry_text;
622 widget = GTK_ACCESSIBLE (text)->widget;
624 /* State is defunct */
627 entry = GTK_ENTRY (widget);
629 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
630 entry_text = gtk_entry_get_text (entry);
631 index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text;
632 cursor_index = g_utf8_offset_to_pointer (entry_text, entry->current_pos) - entry_text;
633 if (index > cursor_index)
634 index += entry->preedit_length;
635 pango_layout_index_to_pos (gtk_entry_get_layout(entry), index, &char_rect);
637 gail_misc_get_extents_from_pango_rectangle (widget, &char_rect,
638 x_layout, y_layout, x, y, width, height, coords);
642 gail_entry_get_offset_at_point (AtkText *text,
649 gint index, cursor_index, x_layout, y_layout;
650 const gchar *entry_text;
652 widget = GTK_ACCESSIBLE (text)->widget;
654 /* State is defunct */
657 entry = GTK_ENTRY (widget);
659 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
660 entry_text = gtk_entry_get_text (entry);
662 index = gail_misc_get_index_at_point_in_layout (widget,
663 gtk_entry_get_layout(entry), x_layout, y_layout, x, y, coords);
666 if (coords == ATK_XY_SCREEN || coords == ATK_XY_WINDOW)
667 return g_utf8_strlen (entry_text, -1);
673 cursor_index = g_utf8_offset_to_pointer (entry_text, entry->current_pos) - entry_text;
674 if (index >= cursor_index && entry->preedit_length)
676 if (index >= cursor_index + entry->preedit_length)
677 index -= entry->preedit_length;
679 index = cursor_index;
681 return g_utf8_pointer_to_offset (entry_text, entry_text + index);
686 gail_entry_get_n_selections (AtkText *text)
690 gint select_start, select_end;
692 widget = GTK_ACCESSIBLE (text)->widget;
694 /* State is defunct */
697 entry = GTK_ENTRY (widget);
699 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
702 if (select_start != select_end)
709 gail_entry_get_selection (AtkText *text,
717 widget = GTK_ACCESSIBLE (text)->widget;
719 /* State is defunct */
722 /* Only let the user get the selection if one is set, and if the
723 * selection_num is 0.
725 if (selection_num != 0)
728 entry = GTK_ENTRY (widget);
729 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), start_pos, end_pos);
731 if (*start_pos != *end_pos)
732 return gtk_editable_get_chars (GTK_EDITABLE (entry), *start_pos, *end_pos);
738 gail_entry_add_selection (AtkText *text,
744 gint select_start, select_end;
746 widget = GTK_ACCESSIBLE (text)->widget;
748 /* State is defunct */
751 entry = GTK_ENTRY (widget);
753 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
756 /* If there is already a selection, then don't allow another to be added,
757 * since GtkEntry only supports one selected region.
759 if (select_start == select_end)
761 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
769 gail_entry_remove_selection (AtkText *text,
774 gint select_start, select_end, caret_pos;
776 widget = GTK_ACCESSIBLE (text)->widget;
778 /* State is defunct */
781 if (selection_num != 0)
784 entry = GTK_ENTRY (widget);
785 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
788 if (select_start != select_end)
790 /* Setting the start & end of the selected region to the caret position
791 * turns off the selection.
793 caret_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
794 gtk_editable_select_region (GTK_EDITABLE (entry), caret_pos, caret_pos);
802 gail_entry_set_selection (AtkText *text,
809 gint select_start, select_end;
811 widget = GTK_ACCESSIBLE (text)->widget;
813 /* State is defunct */
816 /* Only let the user move the selection if one is set, and if the
819 if (selection_num != 0)
822 entry = GTK_ENTRY (widget);
824 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
827 if (select_start != select_end)
829 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
837 atk_editable_text_interface_init (AtkEditableTextIface *iface)
839 iface->set_text_contents = gail_entry_set_text_contents;
840 iface->insert_text = gail_entry_insert_text;
841 iface->copy_text = gail_entry_copy_text;
842 iface->cut_text = gail_entry_cut_text;
843 iface->delete_text = gail_entry_delete_text;
844 iface->paste_text = gail_entry_paste_text;
845 iface->set_run_attributes = NULL;
849 gail_entry_set_text_contents (AtkEditableText *text,
854 GtkEditable *editable;
856 widget = GTK_ACCESSIBLE (text)->widget;
858 /* State is defunct */
861 entry = GTK_ENTRY (widget);
862 editable = GTK_EDITABLE (entry);
863 if (!gtk_editable_get_editable (editable))
866 gtk_entry_set_text (entry, string);
870 gail_entry_insert_text (AtkEditableText *text,
877 GtkEditable *editable;
879 widget = GTK_ACCESSIBLE (text)->widget;
881 /* State is defunct */
884 entry = GTK_ENTRY (widget);
885 editable = GTK_EDITABLE (entry);
886 if (!gtk_editable_get_editable (editable))
889 gtk_editable_insert_text (editable, string, length, position);
890 gtk_editable_set_position (editable, *position);
894 gail_entry_copy_text (AtkEditableText *text,
900 GtkEditable *editable;
902 GtkClipboard *clipboard;
904 widget = GTK_ACCESSIBLE (text)->widget;
906 /* State is defunct */
909 entry = GTK_ENTRY (widget);
910 editable = GTK_EDITABLE (entry);
911 str = gtk_editable_get_chars (editable, start_pos, end_pos);
912 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
913 GDK_SELECTION_CLIPBOARD);
914 gtk_clipboard_set_text (clipboard, str, -1);
918 gail_entry_cut_text (AtkEditableText *text,
924 GtkEditable *editable;
926 GtkClipboard *clipboard;
928 widget = GTK_ACCESSIBLE (text)->widget;
930 /* State is defunct */
933 entry = GTK_ENTRY (widget);
934 editable = GTK_EDITABLE (entry);
935 if (!gtk_editable_get_editable (editable))
937 str = gtk_editable_get_chars (editable, start_pos, end_pos);
938 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
939 GDK_SELECTION_CLIPBOARD);
940 gtk_clipboard_set_text (clipboard, str, -1);
941 gtk_editable_delete_text (editable, start_pos, end_pos);
945 gail_entry_delete_text (AtkEditableText *text,
951 GtkEditable *editable;
953 widget = GTK_ACCESSIBLE (text)->widget;
955 /* State is defunct */
958 entry = GTK_ENTRY (widget);
959 editable = GTK_EDITABLE (entry);
960 if (!gtk_editable_get_editable (editable))
963 gtk_editable_delete_text (editable, start_pos, end_pos);
967 gail_entry_paste_text (AtkEditableText *text,
971 GtkEditable *editable;
972 GailEntryPaste paste_struct;
973 GtkClipboard *clipboard;
975 widget = GTK_ACCESSIBLE (text)->widget;
977 /* State is defunct */
980 editable = GTK_EDITABLE (widget);
981 if (!gtk_editable_get_editable (editable))
983 paste_struct.entry = GTK_ENTRY (widget);
984 paste_struct.position = position;
986 g_object_ref (paste_struct.entry);
987 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
988 GDK_SELECTION_CLIPBOARD);
989 gtk_clipboard_request_text (clipboard,
990 gail_entry_paste_received, &paste_struct);
994 gail_entry_paste_received (GtkClipboard *clipboard,
998 GailEntryPaste* paste_struct = (GailEntryPaste *)data;
1001 gtk_editable_insert_text (GTK_EDITABLE (paste_struct->entry), text, -1,
1002 &(paste_struct->position));
1004 g_object_unref (paste_struct->entry);
1010 gail_entry_idle_notify_insert (gpointer data)
1014 entry = GAIL_ENTRY (data);
1015 entry->insert_idle_handler = 0;
1016 gail_entry_notify_insert (entry);
1022 gail_entry_notify_insert (GailEntry *entry)
1024 if (entry->signal_name_insert)
1026 g_signal_emit_by_name (entry,
1027 entry->signal_name_insert,
1028 entry->position_insert,
1029 entry->length_insert);
1030 entry->signal_name_insert = NULL;
1034 /* Note arg1 returns the character at the start of the insert.
1035 * arg2 returns the number of characters inserted.
1038 _gail_entry_insert_text_cb (GtkEntry *entry,
1043 AtkObject *accessible;
1044 GailEntry *gail_entry;
1045 gint *position = (gint *) arg3;
1047 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1048 gail_entry = GAIL_ENTRY (accessible);
1049 if (!gail_entry->signal_name_insert)
1051 gail_entry->signal_name_insert = "text_changed::insert";
1052 gail_entry->position_insert = *position;
1053 gail_entry->length_insert = g_utf8_strlen(arg1, arg2);
1056 * The signal will be emitted when the cursor position is updated.
1057 * or in an idle handler if it not updated.
1059 if (gail_entry->insert_idle_handler == 0)
1060 gail_entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, gail_entry);
1064 gail_entry_get_character_at_offset (AtkText *text,
1073 widget = GTK_ACCESSIBLE (text)->widget;
1075 /* State is defunct */
1078 entry = GAIL_ENTRY (text);
1079 string = gail_text_util_get_substring (entry->textutil, 0, -1);
1080 if (offset >= g_utf8_strlen (string, -1))
1086 index = g_utf8_offset_to_pointer (string, offset);
1088 unichar = g_utf8_get_char(index);
1096 gail_entry_notify_delete (GailEntry *entry)
1098 if (entry->signal_name_delete)
1100 g_signal_emit_by_name (entry,
1101 entry->signal_name_delete,
1102 entry->position_delete,
1103 entry->length_delete);
1104 entry->signal_name_delete = NULL;
1108 /* Note arg1 returns the start of the delete range, arg2 returns the
1109 * end of the delete range if multiple characters are deleted.
1112 _gail_entry_delete_text_cb (GtkEntry *entry,
1116 AtkObject *accessible;
1117 GailEntry *gail_entry;
1120 * Zero length text deleted so ignore
1122 if (arg2 - arg1 == 0)
1125 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1126 gail_entry = GAIL_ENTRY (accessible);
1127 if (!gail_entry->signal_name_delete)
1129 gail_entry->signal_name_delete = "text_changed::delete";
1130 gail_entry->position_delete = arg1;
1131 gail_entry->length_delete = arg2 - arg1;
1133 gail_entry_notify_delete (gail_entry);
1137 _gail_entry_changed_cb (GtkEntry *entry)
1139 AtkObject *accessible;
1140 GailEntry *gail_entry;
1142 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1144 gail_entry = GAIL_ENTRY (accessible);
1146 text_setup (gail_entry, entry);
1150 check_for_selection_change (GailEntry *entry,
1151 GtkEntry *gtk_entry)
1153 gboolean ret_val = FALSE;
1155 if (gtk_entry->current_pos != gtk_entry->selection_bound)
1157 if (gtk_entry->current_pos != entry->cursor_position ||
1158 gtk_entry->selection_bound != entry->selection_bound)
1160 * This check is here as this function can be called
1161 * for notification of selection_bound and current_pos.
1162 * The values of current_pos and selection_bound may be the same
1163 * for both notifications and we only want to generate one
1164 * text_selection_changed signal.
1170 /* We had a selection */
1171 ret_val = (entry->cursor_position != entry->selection_bound);
1173 entry->cursor_position = gtk_entry->current_pos;
1174 entry->selection_bound = gtk_entry->selection_bound;
1180 atk_action_interface_init (AtkActionIface *iface)
1182 iface->do_action = gail_entry_do_action;
1183 iface->get_n_actions = gail_entry_get_n_actions;
1184 iface->get_description = gail_entry_get_description;
1185 iface->get_keybinding = gail_entry_get_keybinding;
1186 iface->get_name = gail_entry_action_get_name;
1187 iface->set_description = gail_entry_set_description;
1191 gail_entry_do_action (AtkAction *action,
1196 gboolean return_value = TRUE;
1198 entry = GAIL_ENTRY (action);
1199 widget = GTK_ACCESSIBLE (action)->widget;
1206 if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1212 if (entry->action_idle_handler)
1213 return_value = FALSE;
1215 entry->action_idle_handler = gdk_threads_add_idle (idle_do_action, entry);
1218 return_value = FALSE;
1221 return return_value;
1225 idle_do_action (gpointer data)
1230 entry = GAIL_ENTRY (data);
1231 entry->action_idle_handler = 0;
1232 widget = GTK_ACCESSIBLE (entry)->widget;
1233 if (widget == NULL /* State is defunct */ ||
1234 !gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1237 gtk_widget_activate (widget);
1243 gail_entry_get_n_actions (AtkAction *action)
1248 static G_CONST_RETURN gchar*
1249 gail_entry_get_description (AtkAction *action,
1253 G_CONST_RETURN gchar *return_value;
1255 entry = GAIL_ENTRY (action);
1259 return_value = entry->activate_description;
1262 return_value = NULL;
1265 return return_value;
1268 static G_CONST_RETURN gchar*
1269 gail_entry_get_keybinding (AtkAction *action,
1273 gchar *return_value = NULL;
1275 entry = GAIL_ENTRY (action);
1281 * We look for a mnemonic on the label
1285 AtkRelationSet *set;
1286 AtkRelation *relation;
1288 gpointer target_object;
1291 entry = GAIL_ENTRY (action);
1292 widget = GTK_ACCESSIBLE (entry)->widget;
1299 /* Find labelled-by relation */
1301 set = atk_object_ref_relation_set (ATK_OBJECT (action));
1305 relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
1308 target = atk_relation_get_target (relation);
1310 target_object = g_ptr_array_index (target, 0);
1311 if (GTK_IS_ACCESSIBLE (target_object))
1313 label = GTK_ACCESSIBLE (target_object)->widget;
1317 g_object_unref (set);
1319 if (GTK_IS_LABEL (label))
1321 key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
1322 if (key_val != GDK_VoidSymbol)
1323 return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
1325 g_free (entry->activate_keybinding);
1326 entry->activate_keybinding = return_value;
1332 return return_value;
1335 static G_CONST_RETURN gchar*
1336 gail_entry_action_get_name (AtkAction *action,
1339 G_CONST_RETURN gchar *return_value;
1344 return_value = "activate";
1347 return_value = NULL;
1350 return return_value;
1354 gail_entry_set_description (AtkAction *action,
1361 entry = GAIL_ENTRY (action);
1365 value = &entry->activate_description;
1375 *value = g_strdup (desc);