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);
44 static AtkAttributeSet* gail_entry_get_attributes (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 const gchar* gail_entry_action_get_description (AtkAction *action,
156 static const gchar* gail_entry_get_keybinding (AtkAction *action,
158 static const gchar* gail_entry_action_get_name (AtkAction *action,
160 static gboolean gail_entry_action_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;
191 class->get_attributes = gail_entry_get_attributes;
193 widget_class->notify_gtk = gail_entry_real_notify_gtk;
197 gail_entry_init (GailEntry *entry)
199 entry->textutil = NULL;
200 entry->signal_name_insert = NULL;
201 entry->signal_name_delete = NULL;
202 entry->cursor_position = 0;
203 entry->selection_bound = 0;
204 entry->activate_description = NULL;
205 entry->activate_keybinding = NULL;
209 gail_entry_real_initialize (AtkObject *obj,
213 GailEntry *gail_entry;
214 gint start_pos, end_pos;
216 ATK_OBJECT_CLASS (gail_entry_parent_class)->initialize (obj, data);
218 gail_entry = GAIL_ENTRY (obj);
219 gail_entry->textutil = gail_text_util_new ();
221 g_assert (GTK_IS_ENTRY (data));
223 entry = GTK_ENTRY (data);
224 text_setup (gail_entry, entry);
225 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
226 &start_pos, &end_pos);
227 gail_entry->cursor_position = end_pos;
228 gail_entry->selection_bound = start_pos;
230 /* Set up signal callbacks */
231 g_signal_connect (data, "insert-text",
232 G_CALLBACK (_gail_entry_insert_text_cb), NULL);
233 g_signal_connect (data, "delete-text",
234 G_CALLBACK (_gail_entry_delete_text_cb), NULL);
235 g_signal_connect (data, "changed",
236 G_CALLBACK (_gail_entry_changed_cb), NULL);
238 if (gtk_entry_get_visibility (entry))
239 obj->role = ATK_ROLE_TEXT;
241 obj->role = ATK_ROLE_PASSWORD_TEXT;
245 gail_entry_real_notify_gtk (GObject *obj,
253 widget = GTK_WIDGET (obj);
254 atk_obj = gtk_widget_get_accessible (widget);
255 gtk_entry = GTK_ENTRY (widget);
256 entry = GAIL_ENTRY (atk_obj);
258 if (strcmp (pspec->name, "cursor-position") == 0)
260 if (entry->insert_idle_handler == 0)
261 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
263 if (check_for_selection_change (entry, gtk_entry))
264 g_signal_emit_by_name (atk_obj, "text_selection_changed");
266 * The entry cursor position has moved so generate the signal.
268 g_signal_emit_by_name (atk_obj, "text_caret_moved",
269 entry->cursor_position);
271 else if (strcmp (pspec->name, "selection-bound") == 0)
273 if (entry->insert_idle_handler == 0)
274 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
276 if (check_for_selection_change (entry, gtk_entry))
277 g_signal_emit_by_name (atk_obj, "text_selection_changed");
279 else if (strcmp (pspec->name, "editable") == 0)
283 g_object_get (obj, "editable", &value, NULL);
284 atk_object_notify_state_change (atk_obj, ATK_STATE_EDITABLE,
287 else if (strcmp (pspec->name, "visibility") == 0)
292 text_setup (entry, gtk_entry);
293 visibility = gtk_entry_get_visibility (gtk_entry);
294 new_role = visibility ? ATK_ROLE_TEXT : ATK_ROLE_PASSWORD_TEXT;
295 atk_object_set_role (atk_obj, new_role);
297 else if (strcmp (pspec->name, "invisible-char") == 0)
299 text_setup (entry, gtk_entry);
301 else if (strcmp (pspec->name, "editing-canceled") == 0)
303 if (entry->insert_idle_handler)
305 g_source_remove (entry->insert_idle_handler);
306 entry->insert_idle_handler = 0;
310 GAIL_WIDGET_CLASS (gail_entry_parent_class)->notify_gtk (obj, pspec);
314 text_setup (GailEntry *entry,
317 if (gtk_entry_get_visibility (gtk_entry))
319 gail_text_util_text_setup (entry->textutil, gtk_entry_get_text (gtk_entry));
323 gunichar invisible_char;
324 GString *tmp_string = g_string_new (NULL);
330 invisible_char = gtk_entry_get_invisible_char (gtk_entry);
331 if (invisible_char == 0)
332 invisible_char = ' ';
334 ch_len = g_unichar_to_utf8 (invisible_char, buf);
335 length = gtk_entry_get_text_length (gtk_entry);
336 for (i = 0; i < length; i++)
338 g_string_append_len (tmp_string, buf, ch_len);
341 gail_text_util_text_setup (entry->textutil, tmp_string->str);
342 g_string_free (tmp_string, TRUE);
348 gail_entry_finalize (GObject *object)
350 GailEntry *entry = GAIL_ENTRY (object);
352 g_object_unref (entry->textutil);
353 g_free (entry->activate_description);
354 g_free (entry->activate_keybinding);
355 if (entry->action_idle_handler)
357 g_source_remove (entry->action_idle_handler);
358 entry->action_idle_handler = 0;
360 if (entry->insert_idle_handler)
362 g_source_remove (entry->insert_idle_handler);
363 entry->insert_idle_handler = 0;
365 G_OBJECT_CLASS (gail_entry_parent_class)->finalize (object);
369 gail_entry_get_index_in_parent (AtkObject *accessible)
372 * If the parent widget is a combo box then the index is 1
373 * otherwise do the normal thing.
375 if (accessible->accessible_parent)
376 if (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_get_widget (GTK_ACCESSIBLE (accessible));
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);
408 static AtkAttributeSet *
409 gail_entry_get_attributes (AtkObject *accessible)
412 AtkAttributeSet *attributes;
413 AtkAttribute *placeholder_text;
416 attributes = ATK_OBJECT_CLASS (gail_entry_parent_class)->get_attributes (accessible);
418 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
422 text = gtk_entry_get_placeholder_text (GTK_ENTRY (widget));
426 placeholder_text = g_malloc (sizeof (AtkAttribute));
427 placeholder_text->name = g_strdup ("placeholder-text");
428 placeholder_text->value = g_strdup (text);
430 attributes = g_slist_append (attributes, placeholder_text);
438 atk_text_interface_init (AtkTextIface *iface)
440 iface->get_text = gail_entry_get_text;
441 iface->get_character_at_offset = gail_entry_get_character_at_offset;
442 iface->get_text_before_offset = gail_entry_get_text_before_offset;
443 iface->get_text_at_offset = gail_entry_get_text_at_offset;
444 iface->get_text_after_offset = gail_entry_get_text_after_offset;
445 iface->get_caret_offset = gail_entry_get_caret_offset;
446 iface->set_caret_offset = gail_entry_set_caret_offset;
447 iface->get_character_count = gail_entry_get_character_count;
448 iface->get_n_selections = gail_entry_get_n_selections;
449 iface->get_selection = gail_entry_get_selection;
450 iface->add_selection = gail_entry_add_selection;
451 iface->remove_selection = gail_entry_remove_selection;
452 iface->set_selection = gail_entry_set_selection;
453 iface->get_run_attributes = gail_entry_get_run_attributes;
454 iface->get_default_attributes = gail_entry_get_default_attributes;
455 iface->get_character_extents = gail_entry_get_character_extents;
456 iface->get_offset_at_point = gail_entry_get_offset_at_point;
460 gail_entry_get_text (AtkText *text,
466 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
468 /* State is defunct */
471 return gail_text_util_get_substring (GAIL_ENTRY (text)->textutil, start_pos, end_pos);
475 gail_entry_get_text_before_offset (AtkText *text,
477 AtkTextBoundary boundary_type,
484 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
486 /* State is defunct */
490 entry = GTK_ENTRY (widget);
492 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
493 gtk_entry_get_layout (entry), GAIL_BEFORE_OFFSET,
494 boundary_type, offset, start_offset, end_offset);
498 gail_entry_get_text_at_offset (AtkText *text,
500 AtkTextBoundary boundary_type,
507 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
509 /* State is defunct */
513 entry = GTK_ENTRY (widget);
515 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
516 gtk_entry_get_layout (entry), GAIL_AT_OFFSET,
517 boundary_type, offset, start_offset, end_offset);
521 gail_entry_get_text_after_offset (AtkText *text,
523 AtkTextBoundary boundary_type,
530 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
532 /* State is defunct */
536 entry = GTK_ENTRY (widget);
538 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
539 gtk_entry_get_layout (entry), GAIL_AFTER_OFFSET,
540 boundary_type, offset, start_offset, end_offset);
544 gail_entry_get_character_count (AtkText *text)
549 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
551 /* State is defunct */
554 entry = GTK_ENTRY (widget);
555 return g_utf8_strlen (gtk_entry_get_text (entry), -1);
559 gail_entry_get_caret_offset (AtkText *text)
564 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
566 /* State is defunct */
569 entry = GTK_ENTRY (widget);
571 return gtk_editable_get_position (GTK_EDITABLE (entry));
575 gail_entry_set_caret_offset (AtkText *text, gint offset)
580 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
582 /* State is defunct */
585 entry = GTK_ENTRY (widget);
587 gtk_editable_set_position (GTK_EDITABLE (entry), offset);
591 static AtkAttributeSet*
592 gail_entry_get_run_attributes (AtkText *text,
599 AtkAttributeSet *at_set = NULL;
600 GtkTextDirection dir;
602 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
604 /* State is defunct */
607 entry = GTK_ENTRY (widget);
609 dir = gtk_widget_get_direction (widget);
610 if (dir == GTK_TEXT_DIR_RTL)
612 at_set = gail_misc_add_attribute (at_set,
613 ATK_TEXT_ATTR_DIRECTION,
614 g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, dir)));
617 at_set = gail_misc_layout_get_run_attributes (at_set,
618 gtk_entry_get_layout (entry),
619 (gchar*)gtk_entry_get_text (entry),
626 static AtkAttributeSet*
627 gail_entry_get_default_attributes (AtkText *text)
631 AtkAttributeSet *at_set = NULL;
633 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
635 /* State is defunct */
638 entry = GTK_ENTRY (widget);
640 at_set = gail_misc_get_default_attributes (at_set,
641 gtk_entry_get_layout (entry),
647 gail_entry_get_character_extents (AtkText *text,
657 PangoRectangle char_rect;
658 gint index, x_layout, y_layout;
659 const gchar *entry_text;
660 gint start_pos, end_pos;
662 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
664 /* State is defunct */
667 entry = GTK_ENTRY (widget);
669 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
670 &start_pos, &end_pos);
671 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
672 entry_text = gtk_entry_get_text (entry);
674 index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text;
676 /* FIXME: entry->preedit cannot be accessed directly
677 cursor_index = g_utf8_offset_to_pointer (entry_text, end_pos) - entry_text;
678 if (index > cursor_index)
679 index += entry->preedit_length;
681 pango_layout_index_to_pos (gtk_entry_get_layout(entry), index, &char_rect);
683 gail_misc_get_extents_from_pango_rectangle (widget, &char_rect,
684 x_layout, y_layout, x, y, width, height, coords);
688 gail_entry_get_offset_at_point (AtkText *text,
695 gint index, x_layout, y_layout;
696 const gchar *entry_text;
698 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
700 /* State is defunct */
703 entry = GTK_ENTRY (widget);
705 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
706 entry_text = gtk_entry_get_text (entry);
708 index = gail_misc_get_index_at_point_in_layout (widget,
709 gtk_entry_get_layout(entry), x_layout, y_layout, x, y, coords);
712 if (coords == ATK_XY_SCREEN || coords == ATK_XY_WINDOW)
713 return g_utf8_strlen (entry_text, -1);
719 gint start_pos, end_pos;
721 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
722 &start_pos, &end_pos);
723 /* FIXME: entry->preedit_length cannot be accessed directly
724 cursor_index = g_utf8_offset_to_pointer (entry_text, end_pos) - entry_text;
725 if (index >= cursor_index && entry->preedit_length)
727 if (index >= cursor_index + entry->preedit_length)
728 index -= entry->preedit_length;
730 index = cursor_index;
733 return g_utf8_pointer_to_offset (entry_text, entry_text + index);
738 gail_entry_get_n_selections (AtkText *text)
742 gint select_start, select_end;
744 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
746 /* State is defunct */
749 entry = GTK_ENTRY (widget);
751 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
754 if (select_start != select_end)
761 gail_entry_get_selection (AtkText *text,
769 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
771 /* State is defunct */
774 /* Only let the user get the selection if one is set, and if the
775 * selection_num is 0.
777 if (selection_num != 0)
780 entry = GTK_ENTRY (widget);
781 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), start_pos, end_pos);
783 if (*start_pos != *end_pos)
784 return gtk_editable_get_chars (GTK_EDITABLE (entry), *start_pos, *end_pos);
790 gail_entry_add_selection (AtkText *text,
796 gint select_start, select_end;
798 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
800 /* State is defunct */
803 entry = GTK_ENTRY (widget);
805 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
808 /* If there is already a selection, then don't allow another to be added,
809 * since GtkEntry only supports one selected region.
811 if (select_start == select_end)
813 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
821 gail_entry_remove_selection (AtkText *text,
826 gint select_start, select_end, caret_pos;
828 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
830 /* State is defunct */
833 if (selection_num != 0)
836 entry = GTK_ENTRY (widget);
837 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
840 if (select_start != select_end)
842 /* Setting the start & end of the selected region to the caret position
843 * turns off the selection.
845 caret_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
846 gtk_editable_select_region (GTK_EDITABLE (entry), caret_pos, caret_pos);
854 gail_entry_set_selection (AtkText *text,
861 gint select_start, select_end;
863 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
865 /* State is defunct */
868 /* Only let the user move the selection if one is set, and if the
871 if (selection_num != 0)
874 entry = GTK_ENTRY (widget);
876 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
879 if (select_start != select_end)
881 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
889 atk_editable_text_interface_init (AtkEditableTextIface *iface)
891 iface->set_text_contents = gail_entry_set_text_contents;
892 iface->insert_text = gail_entry_insert_text;
893 iface->copy_text = gail_entry_copy_text;
894 iface->cut_text = gail_entry_cut_text;
895 iface->delete_text = gail_entry_delete_text;
896 iface->paste_text = gail_entry_paste_text;
897 iface->set_run_attributes = NULL;
901 gail_entry_set_text_contents (AtkEditableText *text,
906 GtkEditable *editable;
908 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
910 /* State is defunct */
913 entry = GTK_ENTRY (widget);
914 editable = GTK_EDITABLE (entry);
915 if (!gtk_editable_get_editable (editable))
918 gtk_entry_set_text (entry, string);
922 gail_entry_insert_text (AtkEditableText *text,
929 GtkEditable *editable;
931 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
933 /* State is defunct */
936 entry = GTK_ENTRY (widget);
937 editable = GTK_EDITABLE (entry);
938 if (!gtk_editable_get_editable (editable))
941 gtk_editable_insert_text (editable, string, length, position);
942 gtk_editable_set_position (editable, *position);
946 gail_entry_copy_text (AtkEditableText *text,
952 GtkEditable *editable;
954 GtkClipboard *clipboard;
956 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
958 /* State is defunct */
961 entry = GTK_ENTRY (widget);
962 editable = GTK_EDITABLE (entry);
963 str = gtk_editable_get_chars (editable, start_pos, end_pos);
964 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
965 GDK_SELECTION_CLIPBOARD);
966 gtk_clipboard_set_text (clipboard, str, -1);
970 gail_entry_cut_text (AtkEditableText *text,
976 GtkEditable *editable;
978 GtkClipboard *clipboard;
980 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
982 /* State is defunct */
985 entry = GTK_ENTRY (widget);
986 editable = GTK_EDITABLE (entry);
987 if (!gtk_editable_get_editable (editable))
989 str = gtk_editable_get_chars (editable, start_pos, end_pos);
990 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
991 GDK_SELECTION_CLIPBOARD);
992 gtk_clipboard_set_text (clipboard, str, -1);
993 gtk_editable_delete_text (editable, start_pos, end_pos);
997 gail_entry_delete_text (AtkEditableText *text,
1003 GtkEditable *editable;
1005 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
1007 /* State is defunct */
1010 entry = GTK_ENTRY (widget);
1011 editable = GTK_EDITABLE (entry);
1012 if (!gtk_editable_get_editable (editable))
1015 gtk_editable_delete_text (editable, start_pos, end_pos);
1019 gail_entry_paste_text (AtkEditableText *text,
1023 GtkEditable *editable;
1024 GailEntryPaste paste_struct;
1025 GtkClipboard *clipboard;
1027 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
1029 /* State is defunct */
1032 editable = GTK_EDITABLE (widget);
1033 if (!gtk_editable_get_editable (editable))
1035 paste_struct.entry = GTK_ENTRY (widget);
1036 paste_struct.position = position;
1038 g_object_ref (paste_struct.entry);
1039 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
1040 GDK_SELECTION_CLIPBOARD);
1041 gtk_clipboard_request_text (clipboard,
1042 gail_entry_paste_received, &paste_struct);
1046 gail_entry_paste_received (GtkClipboard *clipboard,
1050 GailEntryPaste* paste_struct = (GailEntryPaste *)data;
1053 gtk_editable_insert_text (GTK_EDITABLE (paste_struct->entry), text, -1,
1054 &(paste_struct->position));
1056 g_object_unref (paste_struct->entry);
1062 gail_entry_idle_notify_insert (gpointer data)
1066 entry = GAIL_ENTRY (data);
1067 entry->insert_idle_handler = 0;
1068 gail_entry_notify_insert (entry);
1074 gail_entry_notify_insert (GailEntry *entry)
1078 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1079 if (gtk_entry_get_text_length (GTK_ENTRY (widget)) == 0)
1082 if (entry->signal_name_insert)
1084 g_signal_emit_by_name (entry,
1085 entry->signal_name_insert,
1086 entry->position_insert,
1087 entry->length_insert);
1088 entry->signal_name_insert = NULL;
1092 /* Note arg1 returns the character at the start of the insert.
1093 * arg2 returns the number of characters inserted.
1096 _gail_entry_insert_text_cb (GtkEntry *entry,
1101 AtkObject *accessible;
1102 GailEntry *gail_entry;
1103 gint *position = (gint *) arg3;
1108 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1109 gail_entry = GAIL_ENTRY (accessible);
1110 if (!gail_entry->signal_name_insert)
1112 gail_entry->signal_name_insert = "text_changed::insert";
1113 gail_entry->position_insert = *position;
1114 gail_entry->length_insert = g_utf8_strlen(arg1, arg2);
1117 * The signal will be emitted when the cursor position is updated.
1118 * or in an idle handler if it not updated.
1120 if (gail_entry->insert_idle_handler == 0)
1121 gail_entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, gail_entry);
1125 gail_entry_get_character_at_offset (AtkText *text,
1134 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
1136 /* State is defunct */
1139 entry = GAIL_ENTRY (text);
1140 string = gail_text_util_get_substring (entry->textutil, 0, -1);
1141 if (offset >= g_utf8_strlen (string, -1))
1147 index = g_utf8_offset_to_pointer (string, offset);
1149 unichar = g_utf8_get_char(index);
1157 gail_entry_notify_delete (GailEntry *entry)
1159 if (entry->signal_name_delete)
1161 g_signal_emit_by_name (entry,
1162 entry->signal_name_delete,
1163 entry->position_delete,
1164 entry->length_delete);
1165 entry->signal_name_delete = NULL;
1169 /* Note arg1 returns the start of the delete range, arg2 returns the
1170 * end of the delete range if multiple characters are deleted.
1173 _gail_entry_delete_text_cb (GtkEntry *entry,
1177 AtkObject *accessible;
1178 GailEntry *gail_entry;
1181 * Zero length text deleted so ignore
1183 if (arg2 - arg1 == 0)
1186 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1187 gail_entry = GAIL_ENTRY (accessible);
1188 if (!gail_entry->signal_name_delete)
1190 gail_entry->signal_name_delete = "text_changed::delete";
1191 gail_entry->position_delete = arg1;
1192 gail_entry->length_delete = arg2 - arg1;
1194 gail_entry_notify_delete (gail_entry);
1198 _gail_entry_changed_cb (GtkEntry *entry)
1200 AtkObject *accessible;
1201 GailEntry *gail_entry;
1203 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1205 gail_entry = GAIL_ENTRY (accessible);
1207 text_setup (gail_entry, entry);
1211 check_for_selection_change (GailEntry *entry,
1212 GtkEntry *gtk_entry)
1214 gboolean selected, ret_val = FALSE;
1215 gint start_pos, end_pos;
1217 selected = gtk_editable_get_selection_bounds (GTK_EDITABLE (gtk_entry),
1218 &start_pos, &end_pos);
1221 if (end_pos != entry->cursor_position ||
1222 start_pos != entry->selection_bound)
1224 * This check is here as this function can be called
1225 * for notification of selection_bound and current_pos.
1226 * The values of current_pos and selection_bound may be the same
1227 * for both notifications and we only want to generate one
1228 * text_selection_changed signal.
1234 /* We had a selection */
1235 ret_val = (entry->cursor_position != entry->selection_bound);
1237 entry->cursor_position = end_pos;
1238 entry->selection_bound = start_pos;
1244 atk_action_interface_init (AtkActionIface *iface)
1246 iface->do_action = gail_entry_do_action;
1247 iface->get_n_actions = gail_entry_get_n_actions;
1248 iface->get_description = gail_entry_action_get_description;
1249 iface->get_keybinding = gail_entry_get_keybinding;
1250 iface->get_name = gail_entry_action_get_name;
1251 iface->set_description = gail_entry_action_set_description;
1255 gail_entry_do_action (AtkAction *action,
1260 gboolean return_value = TRUE;
1262 entry = GAIL_ENTRY (action);
1263 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
1270 if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1276 if (entry->action_idle_handler)
1277 return_value = FALSE;
1279 entry->action_idle_handler = gdk_threads_add_idle (idle_do_action, entry);
1282 return_value = FALSE;
1285 return return_value;
1289 idle_do_action (gpointer data)
1294 entry = GAIL_ENTRY (data);
1295 entry->action_idle_handler = 0;
1296 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1297 if (widget == NULL /* State is defunct */ ||
1298 !gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1301 gtk_widget_activate (widget);
1307 gail_entry_get_n_actions (AtkAction *action)
1313 gail_entry_action_get_description (AtkAction *action,
1317 const gchar *return_value;
1319 entry = GAIL_ENTRY (action);
1323 return_value = entry->activate_description;
1326 return_value = NULL;
1329 return return_value;
1333 gail_entry_get_keybinding (AtkAction *action,
1337 gchar *return_value = NULL;
1339 entry = GAIL_ENTRY (action);
1345 * We look for a mnemonic on the label
1349 AtkRelationSet *set;
1350 AtkRelation *relation;
1352 gpointer target_object;
1355 entry = GAIL_ENTRY (action);
1356 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1363 /* Find labelled-by relation */
1365 set = atk_object_ref_relation_set (ATK_OBJECT (action));
1369 relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
1372 target = atk_relation_get_target (relation);
1374 target_object = g_ptr_array_index (target, 0);
1375 label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
1378 g_object_unref (set);
1380 if (GTK_IS_LABEL (label))
1382 key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
1383 if (key_val != GDK_KEY_VoidSymbol)
1384 return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
1386 g_free (entry->activate_keybinding);
1387 entry->activate_keybinding = return_value;
1393 return return_value;
1397 gail_entry_action_get_name (AtkAction *action,
1400 const gchar *return_value;
1405 return_value = "activate";
1408 return_value = NULL;
1411 return return_value;
1415 gail_entry_action_set_description (AtkAction *action,
1422 entry = GAIL_ENTRY (action);
1426 value = &entry->activate_description;
1436 *value = g_strdup (desc);