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);
299 else if (strcmp (pspec->name, "editing-canceled") == 0)
303 g_object_get (obj, "editing-canceled", &canceled, NULL);
305 if (entry->insert_idle_handler && canceled)
307 g_source_remove (entry->insert_idle_handler);
308 entry->insert_idle_handler = 0;
312 GAIL_WIDGET_CLASS (gail_entry_parent_class)->notify_gtk (obj, pspec);
316 text_setup (GailEntry *entry,
319 if (gtk_entry_get_visibility (gtk_entry))
321 gail_text_util_text_setup (entry->textutil, gtk_entry_get_text (gtk_entry));
325 gunichar invisible_char;
326 GString *tmp_string = g_string_new (NULL);
332 invisible_char = gtk_entry_get_invisible_char (gtk_entry);
333 if (invisible_char == 0)
334 invisible_char = ' ';
336 ch_len = g_unichar_to_utf8 (invisible_char, buf);
337 length = gtk_entry_get_text_length (gtk_entry);
338 for (i = 0; i < length; i++)
340 g_string_append_len (tmp_string, buf, ch_len);
343 gail_text_util_text_setup (entry->textutil, tmp_string->str);
344 g_string_free (tmp_string, TRUE);
350 gail_entry_finalize (GObject *object)
352 GailEntry *entry = GAIL_ENTRY (object);
354 g_object_unref (entry->textutil);
355 g_free (entry->activate_description);
356 g_free (entry->activate_keybinding);
357 if (entry->action_idle_handler)
359 g_source_remove (entry->action_idle_handler);
360 entry->action_idle_handler = 0;
362 if (entry->insert_idle_handler)
364 g_source_remove (entry->insert_idle_handler);
365 entry->insert_idle_handler = 0;
367 G_OBJECT_CLASS (gail_entry_parent_class)->finalize (object);
371 gail_entry_get_index_in_parent (AtkObject *accessible)
374 * If the parent widget is a combo box then the index is 1
375 * otherwise do the normal thing.
377 if (accessible->accessible_parent)
378 if (GAIL_IS_COMBO_BOX (accessible->accessible_parent))
381 return ATK_OBJECT_CLASS (gail_entry_parent_class)->get_index_in_parent (accessible);
387 gail_entry_ref_state_set (AtkObject *accessible)
389 AtkStateSet *state_set;
394 state_set = ATK_OBJECT_CLASS (gail_entry_parent_class)->ref_state_set (accessible);
395 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
400 entry = GTK_ENTRY (widget);
402 g_object_get (G_OBJECT (entry), "editable", &value, NULL);
404 atk_state_set_add_state (state_set, ATK_STATE_EDITABLE);
405 atk_state_set_add_state (state_set, ATK_STATE_SINGLE_LINE);
413 atk_text_interface_init (AtkTextIface *iface)
415 iface->get_text = gail_entry_get_text;
416 iface->get_character_at_offset = gail_entry_get_character_at_offset;
417 iface->get_text_before_offset = gail_entry_get_text_before_offset;
418 iface->get_text_at_offset = gail_entry_get_text_at_offset;
419 iface->get_text_after_offset = gail_entry_get_text_after_offset;
420 iface->get_caret_offset = gail_entry_get_caret_offset;
421 iface->set_caret_offset = gail_entry_set_caret_offset;
422 iface->get_character_count = gail_entry_get_character_count;
423 iface->get_n_selections = gail_entry_get_n_selections;
424 iface->get_selection = gail_entry_get_selection;
425 iface->add_selection = gail_entry_add_selection;
426 iface->remove_selection = gail_entry_remove_selection;
427 iface->set_selection = gail_entry_set_selection;
428 iface->get_run_attributes = gail_entry_get_run_attributes;
429 iface->get_default_attributes = gail_entry_get_default_attributes;
430 iface->get_character_extents = gail_entry_get_character_extents;
431 iface->get_offset_at_point = gail_entry_get_offset_at_point;
435 gail_entry_get_text (AtkText *text,
441 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
443 /* State is defunct */
446 return gail_text_util_get_substring (GAIL_ENTRY (text)->textutil, start_pos, end_pos);
450 gail_entry_get_text_before_offset (AtkText *text,
452 AtkTextBoundary boundary_type,
459 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
461 /* State is defunct */
465 entry = GTK_ENTRY (widget);
467 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
468 gtk_entry_get_layout (entry), GAIL_BEFORE_OFFSET,
469 boundary_type, offset, start_offset, end_offset);
473 gail_entry_get_text_at_offset (AtkText *text,
475 AtkTextBoundary boundary_type,
482 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
484 /* State is defunct */
488 entry = GTK_ENTRY (widget);
490 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
491 gtk_entry_get_layout (entry), GAIL_AT_OFFSET,
492 boundary_type, offset, start_offset, end_offset);
496 gail_entry_get_text_after_offset (AtkText *text,
498 AtkTextBoundary boundary_type,
505 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
507 /* State is defunct */
511 entry = GTK_ENTRY (widget);
513 return gail_text_util_get_text (GAIL_ENTRY (text)->textutil,
514 gtk_entry_get_layout (entry), GAIL_AFTER_OFFSET,
515 boundary_type, offset, start_offset, end_offset);
519 gail_entry_get_character_count (AtkText *text)
524 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
526 /* State is defunct */
529 entry = GTK_ENTRY (widget);
530 return g_utf8_strlen (gtk_entry_get_text (entry), -1);
534 gail_entry_get_caret_offset (AtkText *text)
539 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
541 /* State is defunct */
544 entry = GTK_ENTRY (widget);
546 return gtk_editable_get_position (GTK_EDITABLE (entry));
550 gail_entry_set_caret_offset (AtkText *text, gint offset)
555 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
557 /* State is defunct */
560 entry = GTK_ENTRY (widget);
562 gtk_editable_set_position (GTK_EDITABLE (entry), offset);
566 static AtkAttributeSet*
567 gail_entry_get_run_attributes (AtkText *text,
574 AtkAttributeSet *at_set = NULL;
575 GtkTextDirection dir;
577 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
579 /* State is defunct */
582 entry = GTK_ENTRY (widget);
584 dir = gtk_widget_get_direction (widget);
585 if (dir == GTK_TEXT_DIR_RTL)
587 at_set = gail_misc_add_attribute (at_set,
588 ATK_TEXT_ATTR_DIRECTION,
589 g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, dir)));
592 at_set = gail_misc_layout_get_run_attributes (at_set,
593 gtk_entry_get_layout (entry),
594 (gchar*)gtk_entry_get_text (entry),
601 static AtkAttributeSet*
602 gail_entry_get_default_attributes (AtkText *text)
606 AtkAttributeSet *at_set = NULL;
608 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
610 /* State is defunct */
613 entry = GTK_ENTRY (widget);
615 at_set = gail_misc_get_default_attributes (at_set,
616 gtk_entry_get_layout (entry),
622 gail_entry_get_character_extents (AtkText *text,
632 PangoRectangle char_rect;
633 gint index, x_layout, y_layout;
634 const gchar *entry_text;
635 gint start_pos, end_pos;
637 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
639 /* State is defunct */
642 entry = GTK_ENTRY (widget);
644 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
645 &start_pos, &end_pos);
646 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
647 entry_text = gtk_entry_get_text (entry);
649 index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text;
651 /* FIXME: entry->preedit cannot be accessed directly
652 cursor_index = g_utf8_offset_to_pointer (entry_text, end_pos) - entry_text;
653 if (index > cursor_index)
654 index += entry->preedit_length;
656 pango_layout_index_to_pos (gtk_entry_get_layout(entry), index, &char_rect);
658 gail_misc_get_extents_from_pango_rectangle (widget, &char_rect,
659 x_layout, y_layout, x, y, width, height, coords);
663 gail_entry_get_offset_at_point (AtkText *text,
670 gint index, x_layout, y_layout;
671 const gchar *entry_text;
673 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
675 /* State is defunct */
678 entry = GTK_ENTRY (widget);
680 gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout);
681 entry_text = gtk_entry_get_text (entry);
683 index = gail_misc_get_index_at_point_in_layout (widget,
684 gtk_entry_get_layout(entry), x_layout, y_layout, x, y, coords);
687 if (coords == ATK_XY_SCREEN || coords == ATK_XY_WINDOW)
688 return g_utf8_strlen (entry_text, -1);
694 gint start_pos, end_pos;
696 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
697 &start_pos, &end_pos);
698 /* FIXME: entry->preedit_length cannot be accessed directly
699 cursor_index = g_utf8_offset_to_pointer (entry_text, end_pos) - entry_text;
700 if (index >= cursor_index && entry->preedit_length)
702 if (index >= cursor_index + entry->preedit_length)
703 index -= entry->preedit_length;
705 index = cursor_index;
708 return g_utf8_pointer_to_offset (entry_text, entry_text + index);
713 gail_entry_get_n_selections (AtkText *text)
717 gint select_start, select_end;
719 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
721 /* State is defunct */
724 entry = GTK_ENTRY (widget);
726 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
729 if (select_start != select_end)
736 gail_entry_get_selection (AtkText *text,
744 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
746 /* State is defunct */
749 /* Only let the user get the selection if one is set, and if the
750 * selection_num is 0.
752 if (selection_num != 0)
755 entry = GTK_ENTRY (widget);
756 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), start_pos, end_pos);
758 if (*start_pos != *end_pos)
759 return gtk_editable_get_chars (GTK_EDITABLE (entry), *start_pos, *end_pos);
765 gail_entry_add_selection (AtkText *text,
771 gint select_start, select_end;
773 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
775 /* State is defunct */
778 entry = GTK_ENTRY (widget);
780 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
783 /* If there is already a selection, then don't allow another to be added,
784 * since GtkEntry only supports one selected region.
786 if (select_start == select_end)
788 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
796 gail_entry_remove_selection (AtkText *text,
801 gint select_start, select_end, caret_pos;
803 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
805 /* State is defunct */
808 if (selection_num != 0)
811 entry = GTK_ENTRY (widget);
812 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
815 if (select_start != select_end)
817 /* Setting the start & end of the selected region to the caret position
818 * turns off the selection.
820 caret_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
821 gtk_editable_select_region (GTK_EDITABLE (entry), caret_pos, caret_pos);
829 gail_entry_set_selection (AtkText *text,
836 gint select_start, select_end;
838 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
840 /* State is defunct */
843 /* Only let the user move the selection if one is set, and if the
846 if (selection_num != 0)
849 entry = GTK_ENTRY (widget);
851 gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &select_start,
854 if (select_start != select_end)
856 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
864 atk_editable_text_interface_init (AtkEditableTextIface *iface)
866 iface->set_text_contents = gail_entry_set_text_contents;
867 iface->insert_text = gail_entry_insert_text;
868 iface->copy_text = gail_entry_copy_text;
869 iface->cut_text = gail_entry_cut_text;
870 iface->delete_text = gail_entry_delete_text;
871 iface->paste_text = gail_entry_paste_text;
872 iface->set_run_attributes = NULL;
876 gail_entry_set_text_contents (AtkEditableText *text,
881 GtkEditable *editable;
883 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
885 /* State is defunct */
888 entry = GTK_ENTRY (widget);
889 editable = GTK_EDITABLE (entry);
890 if (!gtk_editable_get_editable (editable))
893 gtk_entry_set_text (entry, string);
897 gail_entry_insert_text (AtkEditableText *text,
904 GtkEditable *editable;
906 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
908 /* State is defunct */
911 entry = GTK_ENTRY (widget);
912 editable = GTK_EDITABLE (entry);
913 if (!gtk_editable_get_editable (editable))
916 gtk_editable_insert_text (editable, string, length, position);
917 gtk_editable_set_position (editable, *position);
921 gail_entry_copy_text (AtkEditableText *text,
927 GtkEditable *editable;
929 GtkClipboard *clipboard;
931 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
933 /* State is defunct */
936 entry = GTK_ENTRY (widget);
937 editable = GTK_EDITABLE (entry);
938 str = gtk_editable_get_chars (editable, start_pos, end_pos);
939 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
940 GDK_SELECTION_CLIPBOARD);
941 gtk_clipboard_set_text (clipboard, str, -1);
945 gail_entry_cut_text (AtkEditableText *text,
951 GtkEditable *editable;
953 GtkClipboard *clipboard;
955 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
957 /* State is defunct */
960 entry = GTK_ENTRY (widget);
961 editable = GTK_EDITABLE (entry);
962 if (!gtk_editable_get_editable (editable))
964 str = gtk_editable_get_chars (editable, start_pos, end_pos);
965 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
966 GDK_SELECTION_CLIPBOARD);
967 gtk_clipboard_set_text (clipboard, str, -1);
968 gtk_editable_delete_text (editable, start_pos, end_pos);
972 gail_entry_delete_text (AtkEditableText *text,
978 GtkEditable *editable;
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))
990 gtk_editable_delete_text (editable, start_pos, end_pos);
994 gail_entry_paste_text (AtkEditableText *text,
998 GtkEditable *editable;
999 GailEntryPaste paste_struct;
1000 GtkClipboard *clipboard;
1002 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
1004 /* State is defunct */
1007 editable = GTK_EDITABLE (widget);
1008 if (!gtk_editable_get_editable (editable))
1010 paste_struct.entry = GTK_ENTRY (widget);
1011 paste_struct.position = position;
1013 g_object_ref (paste_struct.entry);
1014 clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
1015 GDK_SELECTION_CLIPBOARD);
1016 gtk_clipboard_request_text (clipboard,
1017 gail_entry_paste_received, &paste_struct);
1021 gail_entry_paste_received (GtkClipboard *clipboard,
1025 GailEntryPaste* paste_struct = (GailEntryPaste *)data;
1028 gtk_editable_insert_text (GTK_EDITABLE (paste_struct->entry), text, -1,
1029 &(paste_struct->position));
1031 g_object_unref (paste_struct->entry);
1037 gail_entry_idle_notify_insert (gpointer data)
1041 entry = GAIL_ENTRY (data);
1042 entry->insert_idle_handler = 0;
1043 gail_entry_notify_insert (entry);
1049 gail_entry_notify_insert (GailEntry *entry)
1053 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1054 if (gtk_entry_get_text_length (GTK_ENTRY (widget)) == 0)
1057 if (entry->signal_name_insert)
1059 g_signal_emit_by_name (entry,
1060 entry->signal_name_insert,
1061 entry->position_insert,
1062 entry->length_insert);
1063 entry->signal_name_insert = NULL;
1067 /* Note arg1 returns the character at the start of the insert.
1068 * arg2 returns the number of characters inserted.
1071 _gail_entry_insert_text_cb (GtkEntry *entry,
1076 AtkObject *accessible;
1077 GailEntry *gail_entry;
1078 gint *position = (gint *) arg3;
1083 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1084 gail_entry = GAIL_ENTRY (accessible);
1085 if (!gail_entry->signal_name_insert)
1087 gail_entry->signal_name_insert = "text_changed::insert";
1088 gail_entry->position_insert = *position;
1089 gail_entry->length_insert = g_utf8_strlen(arg1, arg2);
1092 * The signal will be emitted when the cursor position is updated.
1093 * or in an idle handler if it not updated.
1095 if (gail_entry->insert_idle_handler == 0)
1096 gail_entry->insert_idle_handler = gdk_threads_add_idle (gail_entry_idle_notify_insert, gail_entry);
1100 gail_entry_get_character_at_offset (AtkText *text,
1109 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
1111 /* State is defunct */
1114 entry = GAIL_ENTRY (text);
1115 string = gail_text_util_get_substring (entry->textutil, 0, -1);
1116 if (offset >= g_utf8_strlen (string, -1))
1122 index = g_utf8_offset_to_pointer (string, offset);
1124 unichar = g_utf8_get_char(index);
1132 gail_entry_notify_delete (GailEntry *entry)
1134 if (entry->signal_name_delete)
1136 g_signal_emit_by_name (entry,
1137 entry->signal_name_delete,
1138 entry->position_delete,
1139 entry->length_delete);
1140 entry->signal_name_delete = NULL;
1144 /* Note arg1 returns the start of the delete range, arg2 returns the
1145 * end of the delete range if multiple characters are deleted.
1148 _gail_entry_delete_text_cb (GtkEntry *entry,
1152 AtkObject *accessible;
1153 GailEntry *gail_entry;
1156 * Zero length text deleted so ignore
1158 if (arg2 - arg1 == 0)
1161 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1162 gail_entry = GAIL_ENTRY (accessible);
1163 if (!gail_entry->signal_name_delete)
1165 gail_entry->signal_name_delete = "text_changed::delete";
1166 gail_entry->position_delete = arg1;
1167 gail_entry->length_delete = arg2 - arg1;
1169 gail_entry_notify_delete (gail_entry);
1173 _gail_entry_changed_cb (GtkEntry *entry)
1175 AtkObject *accessible;
1176 GailEntry *gail_entry;
1178 accessible = gtk_widget_get_accessible (GTK_WIDGET (entry));
1180 gail_entry = GAIL_ENTRY (accessible);
1182 text_setup (gail_entry, entry);
1186 check_for_selection_change (GailEntry *entry,
1187 GtkEntry *gtk_entry)
1189 gboolean selected, ret_val = FALSE;
1190 gint start_pos, end_pos;
1192 selected = gtk_editable_get_selection_bounds (GTK_EDITABLE (gtk_entry),
1193 &start_pos, &end_pos);
1196 if (end_pos != entry->cursor_position ||
1197 start_pos != entry->selection_bound)
1199 * This check is here as this function can be called
1200 * for notification of selection_bound and current_pos.
1201 * The values of current_pos and selection_bound may be the same
1202 * for both notifications and we only want to generate one
1203 * text_selection_changed signal.
1209 /* We had a selection */
1210 ret_val = (entry->cursor_position != entry->selection_bound);
1212 entry->cursor_position = end_pos;
1213 entry->selection_bound = start_pos;
1219 atk_action_interface_init (AtkActionIface *iface)
1221 iface->do_action = gail_entry_do_action;
1222 iface->get_n_actions = gail_entry_get_n_actions;
1223 iface->get_description = gail_entry_get_description;
1224 iface->get_keybinding = gail_entry_get_keybinding;
1225 iface->get_name = gail_entry_action_get_name;
1226 iface->set_description = gail_entry_set_description;
1230 gail_entry_do_action (AtkAction *action,
1235 gboolean return_value = TRUE;
1237 entry = GAIL_ENTRY (action);
1238 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
1245 if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1251 if (entry->action_idle_handler)
1252 return_value = FALSE;
1254 entry->action_idle_handler = gdk_threads_add_idle (idle_do_action, entry);
1257 return_value = FALSE;
1260 return return_value;
1264 idle_do_action (gpointer data)
1269 entry = GAIL_ENTRY (data);
1270 entry->action_idle_handler = 0;
1271 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1272 if (widget == NULL /* State is defunct */ ||
1273 !gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
1276 gtk_widget_activate (widget);
1282 gail_entry_get_n_actions (AtkAction *action)
1287 static G_CONST_RETURN gchar*
1288 gail_entry_get_description (AtkAction *action,
1292 G_CONST_RETURN gchar *return_value;
1294 entry = GAIL_ENTRY (action);
1298 return_value = entry->activate_description;
1301 return_value = NULL;
1304 return return_value;
1307 static G_CONST_RETURN gchar*
1308 gail_entry_get_keybinding (AtkAction *action,
1312 gchar *return_value = NULL;
1314 entry = GAIL_ENTRY (action);
1320 * We look for a mnemonic on the label
1324 AtkRelationSet *set;
1325 AtkRelation *relation;
1327 gpointer target_object;
1330 entry = GAIL_ENTRY (action);
1331 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (entry));
1338 /* Find labelled-by relation */
1340 set = atk_object_ref_relation_set (ATK_OBJECT (action));
1344 relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
1347 target = atk_relation_get_target (relation);
1349 target_object = g_ptr_array_index (target, 0);
1350 label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
1353 g_object_unref (set);
1355 if (GTK_IS_LABEL (label))
1357 key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
1358 if (key_val != GDK_KEY_VoidSymbol)
1359 return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
1361 g_free (entry->activate_keybinding);
1362 entry->activate_keybinding = return_value;
1368 return return_value;
1371 static G_CONST_RETURN gchar*
1372 gail_entry_action_get_name (AtkAction *action,
1375 G_CONST_RETURN gchar *return_value;
1380 return_value = "activate";
1383 return_value = NULL;
1386 return return_value;
1390 gail_entry_set_description (AtkAction *action,
1397 entry = GAIL_ENTRY (action);
1401 value = &entry->activate_description;
1411 *value = g_strdup (desc);