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;
212 gint start_pos, end_pos;
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 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
224 &start_pos, &end_pos);
225 gail_entry->cursor_position = end_pos;
226 gail_entry->selection_bound = start_pos;
228 /* Set up signal callbacks */
229 g_signal_connect (data, "insert-text",
230 G_CALLBACK (_gail_entry_insert_text_cb), NULL);
231 g_signal_connect (data, "delete-text",
232 G_CALLBACK (_gail_entry_delete_text_cb), NULL);
233 g_signal_connect (data, "changed",
234 G_CALLBACK (_gail_entry_changed_cb), NULL);
236 if (gtk_entry_get_visibility (entry))
237 obj->role = ATK_ROLE_TEXT;
239 obj->role = ATK_ROLE_PASSWORD_TEXT;
243 gail_entry_real_notify_gtk (GObject *obj,
251 widget = GTK_WIDGET (obj);
252 atk_obj = gtk_widget_get_accessible (widget);
253 gtk_entry = GTK_ENTRY (widget);
254 entry = GAIL_ENTRY (atk_obj);
256 if (strcmp (pspec->name, "cursor-position") == 0)
258 if (entry->insert_idle_handler == 0)
259 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
261 if (check_for_selection_change (entry, gtk_entry))
262 g_signal_emit_by_name (atk_obj, "text_selection_changed");
264 * The entry cursor position has moved so generate the signal.
266 g_signal_emit_by_name (atk_obj, "text_caret_moved",
267 entry->cursor_position);
269 else if (strcmp (pspec->name, "selection-bound") == 0)
271 if (entry->insert_idle_handler == 0)
272 entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, entry);
274 if (check_for_selection_change (entry, gtk_entry))
275 g_signal_emit_by_name (atk_obj, "text_selection_changed");
277 else if (strcmp (pspec->name, "editable") == 0)
281 g_object_get (obj, "editable", &value, NULL);
282 atk_object_notify_state_change (atk_obj, ATK_STATE_EDITABLE,
285 else if (strcmp (pspec->name, "visibility") == 0)
290 text_setup (entry, gtk_entry);
291 visibility = gtk_entry_get_visibility (gtk_entry);
292 new_role = visibility ? ATK_ROLE_TEXT : ATK_ROLE_PASSWORD_TEXT;
293 atk_object_set_role (atk_obj, new_role);
295 else if (strcmp (pspec->name, "invisible-char") == 0)
297 text_setup (entry, gtk_entry);
300 GAIL_WIDGET_CLASS (gail_entry_parent_class)->notify_gtk (obj, pspec);
304 text_setup (GailEntry *entry,
307 if (gtk_entry_get_visibility (gtk_entry))
309 gail_text_util_text_setup (entry->textutil, gtk_entry_get_text (gtk_entry));
313 gunichar invisible_char;
314 GString *tmp_string = g_string_new (NULL);
320 invisible_char = gtk_entry_get_invisible_char (gtk_entry);
321 if (invisible_char == 0)
322 invisible_char = ' ';
324 ch_len = g_unichar_to_utf8 (invisible_char, buf);
325 length = gtk_entry_get_text_length (gtk_entry);
326 for (i = 0; i < length; i++)
328 g_string_append_len (tmp_string, buf, ch_len);
331 gail_text_util_text_setup (entry->textutil, tmp_string->str);
332 g_string_free (tmp_string, TRUE);
338 gail_entry_finalize (GObject *object)
340 GailEntry *entry = GAIL_ENTRY (object);
342 g_object_unref (entry->textutil);
343 g_free (entry->activate_description);
344 g_free (entry->activate_keybinding);
345 if (entry->action_idle_handler)
347 g_source_remove (entry->action_idle_handler);
348 entry->action_idle_handler = 0;
350 if (entry->insert_idle_handler)
352 g_source_remove (entry->insert_idle_handler);
353 entry->insert_idle_handler = 0;
355 G_OBJECT_CLASS (gail_entry_parent_class)->finalize (object);
359 gail_entry_get_index_in_parent (AtkObject *accessible)
362 * If the parent widget is a combo box then the index is 1
363 * otherwise do the normal thing.
365 if (accessible->accessible_parent)
366 if (GAIL_IS_COMBO_BOX (accessible->accessible_parent))
369 return ATK_OBJECT_CLASS (gail_entry_parent_class)->get_index_in_parent (accessible);
375 gail_entry_ref_state_set (AtkObject *accessible)
377 AtkStateSet *state_set;
382 state_set = ATK_OBJECT_CLASS (gail_entry_parent_class)->ref_state_set (accessible);
383 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
388 entry = GTK_ENTRY (widget);
390 g_object_get (G_OBJECT (entry), "editable", &value, NULL);
392 atk_state_set_add_state (state_set, ATK_STATE_EDITABLE);
393 atk_state_set_add_state (state_set, ATK_STATE_SINGLE_LINE);
401 atk_text_interface_init (AtkTextIface *iface)
403 iface->get_text = gail_entry_get_text;
404 iface->get_character_at_offset = gail_entry_get_character_at_offset;
405 iface->get_text_before_offset = gail_entry_get_text_before_offset;
406 iface->get_text_at_offset = gail_entry_get_text_at_offset;
407 iface->get_text_after_offset = gail_entry_get_text_after_offset;
408 iface->get_caret_offset = gail_entry_get_caret_offset;
409 iface->set_caret_offset = gail_entry_set_caret_offset;
410 iface->get_character_count = gail_entry_get_character_count;
411 iface->get_n_selections = gail_entry_get_n_selections;
412 iface->get_selection = gail_entry_get_selection;
413 iface->add_selection = gail_entry_add_selection;
414 iface->remove_selection = gail_entry_remove_selection;
415 iface->set_selection = gail_entry_set_selection;
416 iface->get_run_attributes = gail_entry_get_run_attributes;
417 iface->get_default_attributes = gail_entry_get_default_attributes;
418 iface->get_character_extents = gail_entry_get_character_extents;
419 iface->get_offset_at_point = gail_entry_get_offset_at_point;
423 gail_entry_get_text (AtkText *text,
429 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
431 /* State is defunct */
434 return gail_text_util_get_substring (GAIL_ENTRY (text)->textutil, start_pos, end_pos);
438 gail_entry_get_text_before_offset (AtkText *text,
440 AtkTextBoundary boundary_type,
447 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
449 /* State is defunct */
453 entry = GTK_ENTRY (widget);
455 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
456 gtk_entry_get_layout (entry), GAIL_BEFORE_OFFSET,
457 boundary_type, offset, start_offset, end_offset);
461 gail_entry_get_text_at_offset (AtkText *text,
463 AtkTextBoundary boundary_type,
470 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
472 /* State is defunct */
476 entry = GTK_ENTRY (widget);
478 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
479 gtk_entry_get_layout (entry), GAIL_AT_OFFSET,
480 boundary_type, offset, start_offset, end_offset);
484 gail_entry_get_text_after_offset (AtkText *text,
486 AtkTextBoundary boundary_type,
493 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
495 /* State is defunct */
499 entry = GTK_ENTRY (widget);
501 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
502 gtk_entry_get_layout (entry), GAIL_AFTER_OFFSET,
503 boundary_type, offset, start_offset, end_offset);
507 gail_entry_get_character_count (AtkText *text)
512 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
514 /* State is defunct */
517 entry = GTK_ENTRY (widget);
518 return g_utf8_strlen (gtk_entry_get_text (entry), -1);
522 gail_entry_get_caret_offset (AtkText *text)
527 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
529 /* State is defunct */
532 entry = GTK_ENTRY (widget);
534 return gtk_editable_get_position (GTK_EDITABLE (entry));
538 gail_entry_set_caret_offset (AtkText *text, gint offset)
543 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
545 /* State is defunct */
548 entry = GTK_ENTRY (widget);
550 gtk_editable_set_position (GTK_EDITABLE (entry), offset);
554 static AtkAttributeSet*
555 gail_entry_get_run_attributes (AtkText *text,
562 AtkAttributeSet *at_set = NULL;
563 GtkTextDirection dir;
565 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
567 /* State is defunct */
570 entry = GTK_ENTRY (widget);
572 dir = gtk_widget_get_direction (widget);
573 if (dir == GTK_TEXT_DIR_RTL)
575 at_set = gail_misc_add_attribute (at_set,
576 ATK_TEXT_ATTR_DIRECTION,
577 g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, dir)));
580 at_set = gail_misc_layout_get_run_attributes (at_set,
581 gtk_entry_get_layout (entry),
582 (gchar*)gtk_entry_get_text (entry),
589 static AtkAttributeSet*
590 gail_entry_get_default_attributes (AtkText *text)
594 AtkAttributeSet *at_set = NULL;
596 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
598 /* State is defunct */
601 entry = GTK_ENTRY (widget);
603 at_set = gail_misc_get_default_attributes (at_set,
604 gtk_entry_get_layout (entry),
610 gail_entry_get_character_extents (AtkText *text,
620 PangoRectangle char_rect;
621 gint index, x_layout, y_layout;
622 const gchar *entry_text;
623 gint start_pos, end_pos;
625 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
627 /* State is defunct */
630 entry = GTK_ENTRY (widget);
632 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
633 &start_pos, &end_pos);
634 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
635 entry_text = gtk_entry_get_text (entry);
637 index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text;
639 /* FIXME: entry->preedit cannot be accessed directly
640 cursor_index = g_utf8_offset_to_pointer (entry_text, end_pos) - entry_text;
641 if (index > cursor_index)
642 index += entry->preedit_length;
644 pango_layout_index_to_pos (gtk_entry_get_layout(entry), index, &char_rect);
646 gail_misc_get_extents_from_pango_rectangle (widget, &char_rect,
647 x_layout, y_layout, x, y, width, height, coords);
651 gail_entry_get_offset_at_point (AtkText *text,
658 gint index, x_layout, y_layout;
659 const gchar *entry_text;
661 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
663 /* State is defunct */
666 entry = GTK_ENTRY (widget);
668 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
669 entry_text = gtk_entry_get_text (entry);
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 gint start_pos, end_pos;
684 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
685 &start_pos, &end_pos);
686 /* FIXME: entry->preedit_length cannot be accessed directly
687 cursor_index = g_utf8_offset_to_pointer (entry_text, end_pos) - entry_text;
688 if (index >= cursor_index && entry->preedit_length)
690 if (index >= cursor_index + entry->preedit_length)
691 index -= entry->preedit_length;
693 index = cursor_index;
696 return g_utf8_pointer_to_offset (entry_text, entry_text + index);
701 gail_entry_get_n_selections (AtkText *text)
705 gint select_start, select_end;
707 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
709 /* State is defunct */
712 entry = GTK_ENTRY (widget);
714 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
717 if (select_start != select_end)
724 gail_entry_get_selection (AtkText *text,
732 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
734 /* State is defunct */
737 /* Only let the user get the selection if one is set, and if the
738 * selection_num is 0.
740 if (selection_num != 0)
743 entry = GTK_ENTRY (widget);
744 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), start_pos, end_pos);
746 if (*start_pos != *end_pos)
747 return gtk_editable_get_chars (GTK_EDITABLE (entry), *start_pos, *end_pos);
753 gail_entry_add_selection (AtkText *text,
759 gint select_start, select_end;
761 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
763 /* State is defunct */
766 entry = GTK_ENTRY (widget);
768 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
771 /* If there is already a selection, then don't allow another to be added,
772 * since GtkEntry only supports one selected region.
774 if (select_start == select_end)
776 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
784 gail_entry_remove_selection (AtkText *text,
789 gint select_start, select_end, caret_pos;
791 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
793 /* State is defunct */
796 if (selection_num != 0)
799 entry = GTK_ENTRY (widget);
800 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
803 if (select_start != select_end)
805 /* Setting the start & end of the selected region to the caret position
806 * turns off the selection.
808 caret_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
809 gtk_editable_select_region (GTK_EDITABLE (entry), caret_pos, caret_pos);
817 gail_entry_set_selection (AtkText *text,
824 gint select_start, select_end;
826 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
828 /* State is defunct */
831 /* Only let the user move the selection if one is set, and if the
834 if (selection_num != 0)
837 entry = GTK_ENTRY (widget);
839 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
842 if (select_start != select_end)
844 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
852 atk_editable_text_interface_init (AtkEditableTextIface *iface)
854 iface->set_text_contents = gail_entry_set_text_contents;
855 iface->insert_text = gail_entry_insert_text;
856 iface->copy_text = gail_entry_copy_text;
857 iface->cut_text = gail_entry_cut_text;
858 iface->delete_text = gail_entry_delete_text;
859 iface->paste_text = gail_entry_paste_text;
860 iface->set_run_attributes = NULL;
864 gail_entry_set_text_contents (AtkEditableText *text,
869 GtkEditable *editable;
871 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
873 /* State is defunct */
876 entry = GTK_ENTRY (widget);
877 editable = GTK_EDITABLE (entry);
878 if (!gtk_editable_get_editable (editable))
881 gtk_entry_set_text (entry, string);
885 gail_entry_insert_text (AtkEditableText *text,
892 GtkEditable *editable;
894 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
896 /* State is defunct */
899 entry = GTK_ENTRY (widget);
900 editable = GTK_EDITABLE (entry);
901 if (!gtk_editable_get_editable (editable))
904 gtk_editable_insert_text (editable, string, length, position);
905 gtk_editable_set_position (editable, *position);
909 gail_entry_copy_text (AtkEditableText *text,
915 GtkEditable *editable;
917 GtkClipboard *clipboard;
919 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
921 /* State is defunct */
924 entry = GTK_ENTRY (widget);
925 editable = GTK_EDITABLE (entry);
926 str = gtk_editable_get_chars (editable, start_pos, end_pos);
927 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
928 GDK_SELECTION_CLIPBOARD);
929 gtk_clipboard_set_text (clipboard, str, -1);
933 gail_entry_cut_text (AtkEditableText *text,
939 GtkEditable *editable;
941 GtkClipboard *clipboard;
943 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
945 /* State is defunct */
948 entry = GTK_ENTRY (widget);
949 editable = GTK_EDITABLE (entry);
950 if (!gtk_editable_get_editable (editable))
952 str = gtk_editable_get_chars (editable, start_pos, end_pos);
953 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
954 GDK_SELECTION_CLIPBOARD);
955 gtk_clipboard_set_text (clipboard, str, -1);
956 gtk_editable_delete_text (editable, start_pos, end_pos);
960 gail_entry_delete_text (AtkEditableText *text,
966 GtkEditable *editable;
968 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
970 /* State is defunct */
973 entry = GTK_ENTRY (widget);
974 editable = GTK_EDITABLE (entry);
975 if (!gtk_editable_get_editable (editable))
978 gtk_editable_delete_text (editable, start_pos, end_pos);
982 gail_entry_paste_text (AtkEditableText *text,
986 GtkEditable *editable;
987 GailEntryPaste paste_struct;
988 GtkClipboard *clipboard;
990 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
992 /* State is defunct */
995 editable = GTK_EDITABLE (widget);
996 if (!gtk_editable_get_editable (editable))
998 paste_struct.entry = GTK_ENTRY (widget);
999 paste_struct.position = position;
1001 g_object_ref (paste_struct.entry);
1002 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
1003 GDK_SELECTION_CLIPBOARD);
1004 gtk_clipboard_request_text (clipboard,
1005 gail_entry_paste_received, &paste_struct);
1009 gail_entry_paste_received (GtkClipboard *clipboard,
1013 GailEntryPaste* paste_struct = (GailEntryPaste *)data;
1016 gtk_editable_insert_text (GTK_EDITABLE (paste_struct->entry), text, -1,
1017 &(paste_struct->position));
1019 g_object_unref (paste_struct->entry);
1025 gail_entry_idle_notify_insert (gpointer data)
1029 entry = GAIL_ENTRY (data);
1030 entry->insert_idle_handler = 0;
1031 gail_entry_notify_insert (entry);
1037 gail_entry_notify_insert (GailEntry *entry)
1041 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1042 if (gtk_entry_get_text_length (GTK_ENTRY (widget)) == 0)
1045 if (entry->signal_name_insert)
1047 g_signal_emit_by_name (entry,
1048 entry->signal_name_insert,
1049 entry->position_insert,
1050 entry->length_insert);
1051 entry->signal_name_insert = NULL;
1055 /* Note arg1 returns the character at the start of the insert.
1056 * arg2 returns the number of characters inserted.
1059 _gail_entry_insert_text_cb (GtkEntry *entry,
1064 AtkObject *accessible;
1065 GailEntry *gail_entry;
1066 gint *position = (gint *) arg3;
1071 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1072 gail_entry = GAIL_ENTRY (accessible);
1073 if (!gail_entry->signal_name_insert)
1075 gail_entry->signal_name_insert = "text_changed::insert";
1076 gail_entry->position_insert = *position;
1077 gail_entry->length_insert = g_utf8_strlen(arg1, arg2);
1080 * The signal will be emitted when the cursor position is updated.
1081 * or in an idle handler if it not updated.
1083 if (gail_entry->insert_idle_handler == 0)
1084 gail_entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, gail_entry);
1088 gail_entry_get_character_at_offset (AtkText *text,
1097 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
1099 /* State is defunct */
1102 entry = GAIL_ENTRY (text);
1103 string = gail_text_util_get_substring (entry->textutil, 0, -1);
1104 if (offset >= g_utf8_strlen (string, -1))
1110 index = g_utf8_offset_to_pointer (string, offset);
1112 unichar = g_utf8_get_char(index);
1120 gail_entry_notify_delete (GailEntry *entry)
1122 if (entry->signal_name_delete)
1124 g_signal_emit_by_name (entry,
1125 entry->signal_name_delete,
1126 entry->position_delete,
1127 entry->length_delete);
1128 entry->signal_name_delete = NULL;
1132 /* Note arg1 returns the start of the delete range, arg2 returns the
1133 * end of the delete range if multiple characters are deleted.
1136 _gail_entry_delete_text_cb (GtkEntry *entry,
1140 AtkObject *accessible;
1141 GailEntry *gail_entry;
1144 * Zero length text deleted so ignore
1146 if (arg2 - arg1 == 0)
1149 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1150 gail_entry = GAIL_ENTRY (accessible);
1151 if (!gail_entry->signal_name_delete)
1153 gail_entry->signal_name_delete = "text_changed::delete";
1154 gail_entry->position_delete = arg1;
1155 gail_entry->length_delete = arg2 - arg1;
1157 gail_entry_notify_delete (gail_entry);
1161 _gail_entry_changed_cb (GtkEntry *entry)
1163 AtkObject *accessible;
1164 GailEntry *gail_entry;
1166 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1168 gail_entry = GAIL_ENTRY (accessible);
1170 text_setup (gail_entry, entry);
1174 check_for_selection_change (GailEntry *entry,
1175 GtkEntry *gtk_entry)
1177 gboolean selected, ret_val = FALSE;
1178 gint start_pos, end_pos;
1180 selected = gtk_editable_get_selection_bounds (GTK_EDITABLE (gtk_entry),
1181 &start_pos, &end_pos);
1184 if (end_pos != entry->cursor_position ||
1185 start_pos != entry->selection_bound)
1187 * This check is here as this function can be called
1188 * for notification of selection_bound and current_pos.
1189 * The values of current_pos and selection_bound may be the same
1190 * for both notifications and we only want to generate one
1191 * text_selection_changed signal.
1197 /* We had a selection */
1198 ret_val = (entry->cursor_position != entry->selection_bound);
1200 entry->cursor_position = end_pos;
1201 entry->selection_bound = start_pos;
1207 atk_action_interface_init (AtkActionIface *iface)
1209 iface->do_action = gail_entry_do_action;
1210 iface->get_n_actions = gail_entry_get_n_actions;
1211 iface->get_description = gail_entry_get_description;
1212 iface->get_keybinding = gail_entry_get_keybinding;
1213 iface->get_name = gail_entry_action_get_name;
1214 iface->set_description = gail_entry_set_description;
1218 gail_entry_do_action (AtkAction *action,
1223 gboolean return_value = TRUE;
1225 entry = GAIL_ENTRY (action);
1226 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
1233 if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1239 if (entry->action_idle_handler)
1240 return_value = FALSE;
1242 entry->action_idle_handler = gdk_threads_add_idle (idle_do_action, entry);
1245 return_value = FALSE;
1248 return return_value;
1252 idle_do_action (gpointer data)
1257 entry = GAIL_ENTRY (data);
1258 entry->action_idle_handler = 0;
1259 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1260 if (widget == NULL /* State is defunct */ ||
1261 !gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1264 gtk_widget_activate (widget);
1270 gail_entry_get_n_actions (AtkAction *action)
1275 static G_CONST_RETURN gchar*
1276 gail_entry_get_description (AtkAction *action,
1280 G_CONST_RETURN gchar *return_value;
1282 entry = GAIL_ENTRY (action);
1286 return_value = entry->activate_description;
1289 return_value = NULL;
1292 return return_value;
1295 static G_CONST_RETURN gchar*
1296 gail_entry_get_keybinding (AtkAction *action,
1300 gchar *return_value = NULL;
1302 entry = GAIL_ENTRY (action);
1308 * We look for a mnemonic on the label
1312 AtkRelationSet *set;
1313 AtkRelation *relation;
1315 gpointer target_object;
1318 entry = GAIL_ENTRY (action);
1319 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1326 /* Find labelled-by relation */
1328 set = atk_object_ref_relation_set (ATK_OBJECT (action));
1332 relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
1335 target = atk_relation_get_target (relation);
1337 target_object = g_ptr_array_index (target, 0);
1338 label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
1341 g_object_unref (set);
1343 if (GTK_IS_LABEL (label))
1345 key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
1346 if (key_val != GDK_KEY_VoidSymbol)
1347 return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
1349 g_free (entry->activate_keybinding);
1350 entry->activate_keybinding = return_value;
1356 return return_value;
1359 static G_CONST_RETURN gchar*
1360 gail_entry_action_get_name (AtkAction *action,
1363 G_CONST_RETURN gchar *return_value;
1368 return_value = "activate";
1371 return_value = NULL;
1374 return return_value;
1378 gail_entry_set_description (AtkAction *action,
1385 entry = GAIL_ENTRY (action);
1389 value = &entry->activate_description;
1399 *value = g_strdup (desc);