1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gtkbindings.h"
37 #include "gtkcelleditable.h"
38 #include "gtkclipboard.h"
41 #include "gtkentrybuffer.h"
42 #include "gtkiconhelperprivate.h"
43 #include "gtkimagemenuitem.h"
44 #include "gtkimcontextsimple.h"
45 #include "gtkimmulticontext.h"
49 #include "gtkmarshalers.h"
51 #include "gtkmenuitem.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkselection.h"
54 #include "gtksettings.h"
55 #include "gtkspinbutton.h"
57 #include "gtktextutil.h"
58 #include "gtkwindow.h"
59 #include "gtktreeview.h"
60 #include "gtktreeselection.h"
61 #include "gtktypebuiltins.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
68 #include "gtkwidgetprivate.h"
69 #include "gtkstylecontextprivate.h"
71 #include "a11y/gtkentryaccessible.h"
75 * @Short_description: A single line text entry field
77 * @See_also: #GtkTextView, #GtkEntryCompletion
79 * The #GtkEntry widget is a single line text entry
80 * widget. A fairly large set of key bindings are supported
81 * by default. If the entered text is longer than the allocation
82 * of the widget, the widget will scroll so that the cursor
83 * position is visible.
85 * When using an entry for passwords and other sensitive information,
86 * it can be put into "password mode" using gtk_entry_set_visibility().
87 * In this mode, entered text is displayed using a 'invisible' character.
88 * By default, GTK+ picks the best invisible character that is available
89 * in the current font, but it can be changed with
90 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
91 * when Caps Lock or input methods might interfere with entering text in
92 * a password entry. The warning can be turned off with the
93 * #GtkEntry:caps-lock-warning property.
95 * Since 2.16, GtkEntry has the ability to display progress or activity
96 * information behind the text. To make an entry display such information,
97 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
99 * Additionally, GtkEntry can show icons at either side of the entry. These
100 * icons can be activatable by clicking, can be set up as drag source and
101 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
102 * one of the various other functions that set an icon from a stock id, an
103 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
104 * connect to the #GtkEntry::icon-press signal. To allow DND operations
105 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
106 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
109 * Note that functionality or information that is only available by clicking
110 * on an icon in an entry may not be accessible at all to users which are not
111 * able to use a mouse or other pointing device. It is therefore recommended
112 * that any such functionality should also be available by other means, e.g.
113 * via the context menu of the entry.
117 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
119 #define MIN_ENTRY_WIDTH 150
120 #define DRAW_TIMEOUT 20
121 #define COMPLETION_TIMEOUT 300
122 #define PASSWORD_HINT_MAX 8
127 #define IS_VALID_ICON_POSITION(pos) \
128 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
129 (pos) == GTK_ENTRY_ICON_SECONDARY)
131 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
132 static GQuark quark_inner_border = 0;
133 static GQuark quark_password_hint = 0;
134 static GQuark quark_cursor_hadjustment = 0;
135 static GQuark quark_capslock_feedback = 0;
137 typedef struct _EntryIconInfo EntryIconInfo;
138 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
139 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
141 struct _GtkEntryPrivate
143 EntryIconInfo *icons[MAX_ICONS];
145 GtkEntryBuffer *buffer;
146 GtkIMContext *im_context;
147 GtkShadowType shadow_type;
148 GtkWidget *popup_menu;
152 GdkDevice *completion_device;
153 GdkWindow *text_area;
155 PangoLayout *cached_layout;
159 gdouble progress_fraction;
160 gdouble progress_pulse_fraction;
161 gdouble progress_pulse_current;
163 gchar *placeholder_text;
167 gint ascent; /* font ascent in pango units */
169 gint descent; /* font descent in pango units */
170 gint dnd_position; /* In chars, -1 == no DND cursor */
175 gint selection_bound;
181 gunichar invisible_char;
184 guint blink_time; /* time in msec the cursor has blinked since last user event */
186 guint recompute_idle;
188 guint16 x_text_size; /* allocated size, in bytes */
189 guint16 x_n_bytes; /* length in use, in bytes */
191 guint16 preedit_length; /* length of preedit string, in bytes */
192 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
196 guint overwrite_mode : 1;
199 guint activates_default : 1;
200 guint cache_includes_preedit : 1;
201 guint caps_lock_warning : 1;
202 guint caps_lock_warning_shown : 1;
203 guint change_count : 8;
204 guint cursor_visible : 1;
205 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
207 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
208 guint is_cell_renderer : 1;
209 guint invisible_char_set : 1;
210 guint interior_focus : 1;
211 guint mouse_cursor_obscured : 1;
212 guint need_im_reset : 1;
213 guint progress_pulse_mode : 1;
214 guint progress_pulse_way_back : 1;
215 guint real_changed : 1;
216 guint resolved_dir : 4; /* PangoDirection */
217 guint select_words : 1;
218 guint select_lines : 1;
219 guint truncate_multiline : 1;
222 struct _EntryIconInfo
226 guint insensitive : 1;
227 guint nonactivatable : 1;
232 GtkIconHelper *icon_helper;
234 GtkTargetList *target_list;
235 GdkDragAction actions;
238 struct _GtkEntryPasswordHint
240 gint position; /* Position (in text) of the last password hint */
241 guint source_id; /* Timeout source id */
244 struct _GtkEntryCapslockFeedback
271 PROP_CURSOR_POSITION,
272 PROP_SELECTION_BOUND,
279 PROP_ACTIVATES_DEFAULT,
284 PROP_TRUNCATE_MULTILINE,
288 PROP_INVISIBLE_CHAR_SET,
289 PROP_CAPS_LOCK_WARNING,
290 PROP_PROGRESS_FRACTION,
291 PROP_PROGRESS_PULSE_STEP,
293 PROP_PIXBUF_SECONDARY,
295 PROP_STOCK_SECONDARY,
296 PROP_ICON_NAME_PRIMARY,
297 PROP_ICON_NAME_SECONDARY,
299 PROP_GICON_SECONDARY,
300 PROP_STORAGE_TYPE_PRIMARY,
301 PROP_STORAGE_TYPE_SECONDARY,
302 PROP_ACTIVATABLE_PRIMARY,
303 PROP_ACTIVATABLE_SECONDARY,
304 PROP_SENSITIVE_PRIMARY,
305 PROP_SENSITIVE_SECONDARY,
306 PROP_TOOLTIP_TEXT_PRIMARY,
307 PROP_TOOLTIP_TEXT_SECONDARY,
308 PROP_TOOLTIP_MARKUP_PRIMARY,
309 PROP_TOOLTIP_MARKUP_SECONDARY,
311 PROP_EDITING_CANCELED,
312 PROP_PLACEHOLDER_TEXT,
316 static guint signals[LAST_SIGNAL] = { 0 };
325 DISPLAY_NORMAL, /* The entry text is being shown */
326 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
327 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
332 static void gtk_entry_editable_init (GtkEditableInterface *iface);
333 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
334 static void gtk_entry_set_property (GObject *object,
338 static void gtk_entry_get_property (GObject *object,
342 static void gtk_entry_finalize (GObject *object);
343 static void gtk_entry_dispose (GObject *object);
347 static void gtk_entry_destroy (GtkWidget *widget);
348 static void gtk_entry_realize (GtkWidget *widget);
349 static void gtk_entry_unrealize (GtkWidget *widget);
350 static void gtk_entry_map (GtkWidget *widget);
351 static void gtk_entry_unmap (GtkWidget *widget);
352 static void gtk_entry_get_preferred_width (GtkWidget *widget,
355 static void gtk_entry_get_preferred_height (GtkWidget *widget,
358 static void gtk_entry_size_allocate (GtkWidget *widget,
359 GtkAllocation *allocation);
360 static void gtk_entry_draw_frame (GtkWidget *widget,
361 GtkStyleContext *context,
363 static void gtk_entry_draw_progress (GtkWidget *widget,
364 GtkStyleContext *context,
366 static gint gtk_entry_draw (GtkWidget *widget,
368 static gint gtk_entry_button_press (GtkWidget *widget,
369 GdkEventButton *event);
370 static gint gtk_entry_button_release (GtkWidget *widget,
371 GdkEventButton *event);
372 static gint gtk_entry_enter_notify (GtkWidget *widget,
373 GdkEventCrossing *event);
374 static gint gtk_entry_leave_notify (GtkWidget *widget,
375 GdkEventCrossing *event);
376 static gint gtk_entry_motion_notify (GtkWidget *widget,
377 GdkEventMotion *event);
378 static gint gtk_entry_key_press (GtkWidget *widget,
380 static gint gtk_entry_key_release (GtkWidget *widget,
382 static gint gtk_entry_focus_in (GtkWidget *widget,
383 GdkEventFocus *event);
384 static gint gtk_entry_focus_out (GtkWidget *widget,
385 GdkEventFocus *event);
386 static void gtk_entry_grab_focus (GtkWidget *widget);
387 static void gtk_entry_style_updated (GtkWidget *widget);
388 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
391 gboolean keyboard_tip,
392 GtkTooltip *tooltip);
393 static void gtk_entry_direction_changed (GtkWidget *widget,
394 GtkTextDirection previous_dir);
395 static void gtk_entry_state_flags_changed (GtkWidget *widget,
396 GtkStateFlags previous_state);
397 static void gtk_entry_screen_changed (GtkWidget *widget,
398 GdkScreen *old_screen);
400 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
401 GdkDragContext *context,
405 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
406 GdkDragContext *context,
410 static void gtk_entry_drag_leave (GtkWidget *widget,
411 GdkDragContext *context,
413 static void gtk_entry_drag_data_received (GtkWidget *widget,
414 GdkDragContext *context,
417 GtkSelectionData *selection_data,
420 static void gtk_entry_drag_data_get (GtkWidget *widget,
421 GdkDragContext *context,
422 GtkSelectionData *selection_data,
425 static void gtk_entry_drag_data_delete (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_entry_drag_begin (GtkWidget *widget,
428 GdkDragContext *context);
429 static void gtk_entry_drag_end (GtkWidget *widget,
430 GdkDragContext *context);
433 /* GtkEditable method implementations
435 static void gtk_entry_insert_text (GtkEditable *editable,
436 const gchar *new_text,
437 gint new_text_length,
439 static void gtk_entry_delete_text (GtkEditable *editable,
442 static gchar * gtk_entry_get_chars (GtkEditable *editable,
445 static void gtk_entry_real_set_position (GtkEditable *editable,
447 static gint gtk_entry_get_position (GtkEditable *editable);
448 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
451 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
455 /* GtkCellEditable method implementations
457 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
460 /* Default signal handlers
462 static void gtk_entry_real_insert_text (GtkEditable *editable,
463 const gchar *new_text,
464 gint new_text_length,
466 static void gtk_entry_real_delete_text (GtkEditable *editable,
469 static void gtk_entry_move_cursor (GtkEntry *entry,
470 GtkMovementStep step,
472 gboolean extend_selection);
473 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
475 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
478 static void gtk_entry_backspace (GtkEntry *entry);
479 static void gtk_entry_cut_clipboard (GtkEntry *entry);
480 static void gtk_entry_copy_clipboard (GtkEntry *entry);
481 static void gtk_entry_paste_clipboard (GtkEntry *entry);
482 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
483 static void gtk_entry_select_all (GtkEntry *entry);
484 static void gtk_entry_real_activate (GtkEntry *entry);
485 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
487 static void keymap_direction_changed (GdkKeymap *keymap,
489 static void keymap_state_changed (GdkKeymap *keymap,
491 static void remove_capslock_feedback (GtkEntry *entry);
493 /* IM Context Callbacks
495 static void gtk_entry_commit_cb (GtkIMContext *context,
498 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
500 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
502 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
509 static void gtk_entry_enter_text (GtkEntry *entry,
511 static void gtk_entry_set_positions (GtkEntry *entry,
513 gint selection_bound);
514 static void gtk_entry_draw_text (GtkEntry *entry,
516 static void gtk_entry_draw_cursor (GtkEntry *entry,
519 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
520 gboolean include_preedit);
521 static void gtk_entry_reset_layout (GtkEntry *entry);
522 static void gtk_entry_recompute (GtkEntry *entry);
523 static gint gtk_entry_find_position (GtkEntry *entry,
525 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
529 static void gtk_entry_adjust_scroll (GtkEntry *entry);
530 static gint gtk_entry_move_visually (GtkEntry *editable,
533 static gint gtk_entry_move_logically (GtkEntry *entry,
536 static gint gtk_entry_move_forward_word (GtkEntry *entry,
538 gboolean allow_whitespace);
539 static gint gtk_entry_move_backward_word (GtkEntry *entry,
541 gboolean allow_whitespace);
542 static void gtk_entry_delete_whitespace (GtkEntry *entry);
543 static void gtk_entry_select_word (GtkEntry *entry);
544 static void gtk_entry_select_line (GtkEntry *entry);
545 static void gtk_entry_paste (GtkEntry *entry,
547 static void gtk_entry_update_primary_selection (GtkEntry *entry);
548 static void gtk_entry_do_popup (GtkEntry *entry,
549 GdkEventButton *event);
550 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
551 gboolean group_cycling);
552 static void gtk_entry_grab_notify (GtkWidget *widget,
553 gboolean was_grabbed);
554 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
555 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
556 static void gtk_entry_reset_blink_time (GtkEntry *entry);
557 static void gtk_entry_get_text_area_size (GtkEntry *entry,
562 static void get_text_area_size (GtkEntry *entry,
567 static void get_frame_size (GtkEntry *entry,
568 gboolean relative_to_window,
573 static void gtk_entry_move_adjustments (GtkEntry *entry);
574 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
575 GtkEntryIconPosition icon_pos);
576 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
579 static gint gtk_entry_completion_timeout (gpointer data);
580 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
583 static void gtk_entry_completion_changed (GtkWidget *entry,
585 static gboolean check_completion_callback (GtkEntryCompletion *completion);
586 static void clear_completion_callback (GtkEntry *entry,
588 static gboolean accept_completion_callback (GtkEntry *entry);
589 static void completion_insert_text_callback (GtkEntry *entry,
593 GtkEntryCompletion *completion);
594 static void completion_changed (GtkEntryCompletion *completion,
597 static void disconnect_completion_signals (GtkEntry *entry,
598 GtkEntryCompletion *completion);
599 static void connect_completion_signals (GtkEntry *entry,
600 GtkEntryCompletion *completion);
602 static void begin_change (GtkEntry *entry);
603 static void end_change (GtkEntry *entry);
604 static void emit_changed (GtkEntry *entry);
606 static void buffer_inserted_text (GtkEntryBuffer *buffer,
611 static void buffer_deleted_text (GtkEntryBuffer *buffer,
615 static void buffer_notify_text (GtkEntryBuffer *buffer,
618 static void buffer_notify_length (GtkEntryBuffer *buffer,
621 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
624 static void buffer_connect_signals (GtkEntry *entry);
625 static void buffer_disconnect_signals (GtkEntry *entry);
626 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
628 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
629 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
630 gtk_entry_editable_init)
631 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
632 gtk_entry_cell_editable_init))
635 add_move_binding (GtkBindingSet *binding_set,
638 GtkMovementStep step,
641 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
643 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
647 G_TYPE_BOOLEAN, FALSE);
649 /* Selection-extending version */
650 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
654 G_TYPE_BOOLEAN, TRUE);
658 gtk_entry_class_init (GtkEntryClass *class)
660 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
661 GtkWidgetClass *widget_class;
662 GtkBindingSet *binding_set;
664 widget_class = (GtkWidgetClass*) class;
666 gobject_class->dispose = gtk_entry_dispose;
667 gobject_class->finalize = gtk_entry_finalize;
668 gobject_class->set_property = gtk_entry_set_property;
669 gobject_class->get_property = gtk_entry_get_property;
671 widget_class->destroy = gtk_entry_destroy;
672 widget_class->map = gtk_entry_map;
673 widget_class->unmap = gtk_entry_unmap;
674 widget_class->realize = gtk_entry_realize;
675 widget_class->unrealize = gtk_entry_unrealize;
676 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
677 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
678 widget_class->size_allocate = gtk_entry_size_allocate;
679 widget_class->draw = gtk_entry_draw;
680 widget_class->enter_notify_event = gtk_entry_enter_notify;
681 widget_class->leave_notify_event = gtk_entry_leave_notify;
682 widget_class->button_press_event = gtk_entry_button_press;
683 widget_class->button_release_event = gtk_entry_button_release;
684 widget_class->motion_notify_event = gtk_entry_motion_notify;
685 widget_class->key_press_event = gtk_entry_key_press;
686 widget_class->key_release_event = gtk_entry_key_release;
687 widget_class->focus_in_event = gtk_entry_focus_in;
688 widget_class->focus_out_event = gtk_entry_focus_out;
689 widget_class->grab_focus = gtk_entry_grab_focus;
690 widget_class->style_updated = gtk_entry_style_updated;
691 widget_class->query_tooltip = gtk_entry_query_tooltip;
692 widget_class->drag_begin = gtk_entry_drag_begin;
693 widget_class->drag_end = gtk_entry_drag_end;
694 widget_class->direction_changed = gtk_entry_direction_changed;
695 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
696 widget_class->screen_changed = gtk_entry_screen_changed;
697 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
698 widget_class->grab_notify = gtk_entry_grab_notify;
700 widget_class->drag_drop = gtk_entry_drag_drop;
701 widget_class->drag_motion = gtk_entry_drag_motion;
702 widget_class->drag_leave = gtk_entry_drag_leave;
703 widget_class->drag_data_received = gtk_entry_drag_data_received;
704 widget_class->drag_data_get = gtk_entry_drag_data_get;
705 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
707 widget_class->popup_menu = gtk_entry_popup_menu;
709 class->move_cursor = gtk_entry_move_cursor;
710 class->insert_at_cursor = gtk_entry_insert_at_cursor;
711 class->delete_from_cursor = gtk_entry_delete_from_cursor;
712 class->backspace = gtk_entry_backspace;
713 class->cut_clipboard = gtk_entry_cut_clipboard;
714 class->copy_clipboard = gtk_entry_copy_clipboard;
715 class->paste_clipboard = gtk_entry_paste_clipboard;
716 class->toggle_overwrite = gtk_entry_toggle_overwrite;
717 class->activate = gtk_entry_real_activate;
718 class->get_text_area_size = gtk_entry_get_text_area_size;
720 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
721 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
722 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
723 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
725 g_object_class_override_property (gobject_class,
726 PROP_EDITING_CANCELED,
729 g_object_class_install_property (gobject_class,
731 g_param_spec_object ("buffer",
733 P_("Text buffer object which actually stores entry text"),
734 GTK_TYPE_ENTRY_BUFFER,
735 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
737 g_object_class_install_property (gobject_class,
738 PROP_CURSOR_POSITION,
739 g_param_spec_int ("cursor-position",
740 P_("Cursor Position"),
741 P_("The current position of the insertion cursor in chars"),
743 GTK_ENTRY_BUFFER_MAX_SIZE,
745 GTK_PARAM_READABLE));
747 g_object_class_install_property (gobject_class,
748 PROP_SELECTION_BOUND,
749 g_param_spec_int ("selection-bound",
750 P_("Selection Bound"),
751 P_("The position of the opposite end of the selection from the cursor in chars"),
753 GTK_ENTRY_BUFFER_MAX_SIZE,
755 GTK_PARAM_READABLE));
757 g_object_class_install_property (gobject_class,
759 g_param_spec_boolean ("editable",
761 P_("Whether the entry contents can be edited"),
763 GTK_PARAM_READWRITE));
765 g_object_class_install_property (gobject_class,
767 g_param_spec_int ("max-length",
768 P_("Maximum length"),
769 P_("Maximum number of characters for this entry. Zero if no maximum"),
771 GTK_ENTRY_BUFFER_MAX_SIZE,
773 GTK_PARAM_READWRITE));
774 g_object_class_install_property (gobject_class,
776 g_param_spec_boolean ("visibility",
778 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
780 GTK_PARAM_READWRITE));
782 g_object_class_install_property (gobject_class,
784 g_param_spec_boolean ("has-frame",
786 P_("FALSE removes outside bevel from entry"),
788 GTK_PARAM_READWRITE));
791 * GtkEntry:inner-border:
793 * Sets the text area's border between the text and the frame.
795 * Deprecated: 3.4: Use the standard border and padding CSS properties;
796 * the value of this style property is ignored.
798 g_object_class_install_property (gobject_class,
800 g_param_spec_boxed ("inner-border",
802 P_("Border between text and frame. Overrides the inner-border style property"),
804 GTK_PARAM_READWRITE |
805 G_PARAM_DEPRECATED));
807 g_object_class_install_property (gobject_class,
809 g_param_spec_unichar ("invisible-char",
810 P_("Invisible character"),
811 P_("The character to use when masking entry contents (in \"password mode\")"),
813 GTK_PARAM_READWRITE));
815 g_object_class_install_property (gobject_class,
816 PROP_ACTIVATES_DEFAULT,
817 g_param_spec_boolean ("activates-default",
818 P_("Activates default"),
819 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
821 GTK_PARAM_READWRITE));
822 g_object_class_install_property (gobject_class,
824 g_param_spec_int ("width-chars",
825 P_("Width in chars"),
826 P_("Number of characters to leave space for in the entry"),
830 GTK_PARAM_READWRITE));
832 g_object_class_install_property (gobject_class,
834 g_param_spec_int ("scroll-offset",
836 P_("Number of pixels of the entry scrolled off the screen to the left"),
840 GTK_PARAM_READABLE));
842 g_object_class_install_property (gobject_class,
844 g_param_spec_string ("text",
846 P_("The contents of the entry"),
848 GTK_PARAM_READWRITE));
853 * The horizontal alignment, from 0 (left) to 1 (right).
854 * Reversed for RTL layouts.
858 g_object_class_install_property (gobject_class,
860 g_param_spec_float ("xalign",
862 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
866 GTK_PARAM_READWRITE));
869 * GtkEntry:truncate-multiline:
871 * When %TRUE, pasted multi-line text is truncated to the first line.
875 g_object_class_install_property (gobject_class,
876 PROP_TRUNCATE_MULTILINE,
877 g_param_spec_boolean ("truncate-multiline",
878 P_("Truncate multiline"),
879 P_("Whether to truncate multiline pastes to one line."),
881 GTK_PARAM_READWRITE));
884 * GtkEntry:shadow-type:
886 * Which kind of shadow to draw around the entry when
887 * #GtkEntry:has-frame is set to %TRUE.
891 g_object_class_install_property (gobject_class,
893 g_param_spec_enum ("shadow-type",
895 P_("Which kind of shadow to draw around the entry when has-frame is set"),
896 GTK_TYPE_SHADOW_TYPE,
898 GTK_PARAM_READWRITE));
901 * GtkEntry:overwrite-mode:
903 * If text is overwritten when typing in the #GtkEntry.
907 g_object_class_install_property (gobject_class,
909 g_param_spec_boolean ("overwrite-mode",
910 P_("Overwrite mode"),
911 P_("Whether new text overwrites existing text"),
913 GTK_PARAM_READWRITE));
916 * GtkEntry:text-length:
918 * The length of the text in the #GtkEntry.
922 g_object_class_install_property (gobject_class,
924 g_param_spec_uint ("text-length",
926 P_("Length of the text currently in the entry"),
930 GTK_PARAM_READABLE));
932 * GtkEntry:invisible-char-set:
934 * Whether the invisible char has been set for the #GtkEntry.
938 g_object_class_install_property (gobject_class,
939 PROP_INVISIBLE_CHAR_SET,
940 g_param_spec_boolean ("invisible-char-set",
941 P_("Invisible character set"),
942 P_("Whether the invisible character has been set"),
944 GTK_PARAM_READWRITE));
947 * GtkEntry:caps-lock-warning
949 * Whether password entries will show a warning when Caps Lock is on.
951 * Note that the warning is shown using a secondary icon, and thus
952 * does not work if you are using the secondary icon position for some
957 g_object_class_install_property (gobject_class,
958 PROP_CAPS_LOCK_WARNING,
959 g_param_spec_boolean ("caps-lock-warning",
960 P_("Caps Lock warning"),
961 P_("Whether password entries will show a warning when Caps Lock is on"),
963 GTK_PARAM_READWRITE));
966 * GtkEntry:progress-fraction:
968 * The current fraction of the task that's been completed.
972 g_object_class_install_property (gobject_class,
973 PROP_PROGRESS_FRACTION,
974 g_param_spec_double ("progress-fraction",
975 P_("Progress Fraction"),
976 P_("The current fraction of the task that's been completed"),
980 GTK_PARAM_READWRITE));
983 * GtkEntry:progress-pulse-step:
985 * The fraction of total entry width to move the progress
986 * bouncing block for each call to gtk_entry_progress_pulse().
990 g_object_class_install_property (gobject_class,
991 PROP_PROGRESS_PULSE_STEP,
992 g_param_spec_double ("progress-pulse-step",
993 P_("Progress Pulse Step"),
994 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
998 GTK_PARAM_READWRITE));
1001 * GtkEntry:placeholder-text:
1003 * The text that will be displayed in the #GtkEntry when it is empty
1008 g_object_class_install_property (gobject_class,
1009 PROP_PLACEHOLDER_TEXT,
1010 g_param_spec_string ("placeholder-text",
1011 P_("Placeholder text"),
1012 P_("Show text in the entry when it's empty and unfocused"),
1014 GTK_PARAM_READWRITE));
1017 * GtkEntry:primary-icon-pixbuf:
1019 * A pixbuf to use as the primary icon for the entry.
1023 g_object_class_install_property (gobject_class,
1024 PROP_PIXBUF_PRIMARY,
1025 g_param_spec_object ("primary-icon-pixbuf",
1026 P_("Primary pixbuf"),
1027 P_("Primary pixbuf for the entry"),
1029 GTK_PARAM_READWRITE));
1032 * GtkEntry:secondary-icon-pixbuf:
1034 * An pixbuf to use as the secondary icon for the entry.
1038 g_object_class_install_property (gobject_class,
1039 PROP_PIXBUF_SECONDARY,
1040 g_param_spec_object ("secondary-icon-pixbuf",
1041 P_("Secondary pixbuf"),
1042 P_("Secondary pixbuf for the entry"),
1044 GTK_PARAM_READWRITE));
1047 * GtkEntry:primary-icon-stock:
1049 * The stock id to use for the primary icon for the entry.
1053 g_object_class_install_property (gobject_class,
1055 g_param_spec_string ("primary-icon-stock",
1056 P_("Primary stock ID"),
1057 P_("Stock ID for primary icon"),
1059 GTK_PARAM_READWRITE));
1062 * GtkEntry:secondary-icon-stock:
1064 * The stock id to use for the secondary icon for the entry.
1068 g_object_class_install_property (gobject_class,
1069 PROP_STOCK_SECONDARY,
1070 g_param_spec_string ("secondary-icon-stock",
1071 P_("Secondary stock ID"),
1072 P_("Stock ID for secondary icon"),
1074 GTK_PARAM_READWRITE));
1077 * GtkEntry:primary-icon-name:
1079 * The icon name to use for the primary icon for the entry.
1083 g_object_class_install_property (gobject_class,
1084 PROP_ICON_NAME_PRIMARY,
1085 g_param_spec_string ("primary-icon-name",
1086 P_("Primary icon name"),
1087 P_("Icon name for primary icon"),
1089 GTK_PARAM_READWRITE));
1092 * GtkEntry:secondary-icon-name:
1094 * The icon name to use for the secondary icon for the entry.
1098 g_object_class_install_property (gobject_class,
1099 PROP_ICON_NAME_SECONDARY,
1100 g_param_spec_string ("secondary-icon-name",
1101 P_("Secondary icon name"),
1102 P_("Icon name for secondary icon"),
1104 GTK_PARAM_READWRITE));
1107 * GtkEntry:primary-icon-gicon:
1109 * The #GIcon to use for the primary icon for the entry.
1113 g_object_class_install_property (gobject_class,
1115 g_param_spec_object ("primary-icon-gicon",
1116 P_("Primary GIcon"),
1117 P_("GIcon for primary icon"),
1119 GTK_PARAM_READWRITE));
1122 * GtkEntry:secondary-icon-gicon:
1124 * The #GIcon to use for the secondary icon for the entry.
1128 g_object_class_install_property (gobject_class,
1129 PROP_GICON_SECONDARY,
1130 g_param_spec_object ("secondary-icon-gicon",
1131 P_("Secondary GIcon"),
1132 P_("GIcon for secondary icon"),
1134 GTK_PARAM_READWRITE));
1137 * GtkEntry:primary-icon-storage-type:
1139 * The representation which is used for the primary icon of the entry.
1143 g_object_class_install_property (gobject_class,
1144 PROP_STORAGE_TYPE_PRIMARY,
1145 g_param_spec_enum ("primary-icon-storage-type",
1146 P_("Primary storage type"),
1147 P_("The representation being used for primary icon"),
1148 GTK_TYPE_IMAGE_TYPE,
1150 GTK_PARAM_READABLE));
1153 * GtkEntry:secondary-icon-storage-type:
1155 * The representation which is used for the secondary icon of the entry.
1159 g_object_class_install_property (gobject_class,
1160 PROP_STORAGE_TYPE_SECONDARY,
1161 g_param_spec_enum ("secondary-icon-storage-type",
1162 P_("Secondary storage type"),
1163 P_("The representation being used for secondary icon"),
1164 GTK_TYPE_IMAGE_TYPE,
1166 GTK_PARAM_READABLE));
1169 * GtkEntry:primary-icon-activatable:
1171 * Whether the primary icon is activatable.
1173 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1174 * signals only on sensitive, activatable icons.
1176 * Sensitive, but non-activatable icons can be used for purely
1177 * informational purposes.
1181 g_object_class_install_property (gobject_class,
1182 PROP_ACTIVATABLE_PRIMARY,
1183 g_param_spec_boolean ("primary-icon-activatable",
1184 P_("Primary icon activatable"),
1185 P_("Whether the primary icon is activatable"),
1187 GTK_PARAM_READWRITE));
1190 * GtkEntry:secondary-icon-activatable:
1192 * Whether the secondary icon is activatable.
1194 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1195 * signals only on sensitive, activatable icons.
1197 * Sensitive, but non-activatable icons can be used for purely
1198 * informational purposes.
1202 g_object_class_install_property (gobject_class,
1203 PROP_ACTIVATABLE_SECONDARY,
1204 g_param_spec_boolean ("secondary-icon-activatable",
1205 P_("Secondary icon activatable"),
1206 P_("Whether the secondary icon is activatable"),
1208 GTK_PARAM_READWRITE));
1212 * GtkEntry:primary-icon-sensitive:
1214 * Whether the primary icon is sensitive.
1216 * An insensitive icon appears grayed out. GTK+ does not emit the
1217 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1218 * does not allow DND from insensitive icons.
1220 * An icon should be set insensitive if the action that would trigger
1221 * when clicked is currently not available.
1225 g_object_class_install_property (gobject_class,
1226 PROP_SENSITIVE_PRIMARY,
1227 g_param_spec_boolean ("primary-icon-sensitive",
1228 P_("Primary icon sensitive"),
1229 P_("Whether the primary icon is sensitive"),
1231 GTK_PARAM_READWRITE));
1234 * GtkEntry:secondary-icon-sensitive:
1236 * Whether the secondary icon is sensitive.
1238 * An insensitive icon appears grayed out. GTK+ does not emit the
1239 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1240 * does not allow DND from insensitive icons.
1242 * An icon should be set insensitive if the action that would trigger
1243 * when clicked is currently not available.
1247 g_object_class_install_property (gobject_class,
1248 PROP_SENSITIVE_SECONDARY,
1249 g_param_spec_boolean ("secondary-icon-sensitive",
1250 P_("Secondary icon sensitive"),
1251 P_("Whether the secondary icon is sensitive"),
1253 GTK_PARAM_READWRITE));
1256 * GtkEntry:primary-icon-tooltip-text:
1258 * The contents of the tooltip on the primary icon.
1260 * Also see gtk_entry_set_icon_tooltip_text().
1264 g_object_class_install_property (gobject_class,
1265 PROP_TOOLTIP_TEXT_PRIMARY,
1266 g_param_spec_string ("primary-icon-tooltip-text",
1267 P_("Primary icon tooltip text"),
1268 P_("The contents of the tooltip on the primary icon"),
1270 GTK_PARAM_READWRITE));
1273 * GtkEntry:secondary-icon-tooltip-text:
1275 * The contents of the tooltip on the secondary icon.
1277 * Also see gtk_entry_set_icon_tooltip_text().
1281 g_object_class_install_property (gobject_class,
1282 PROP_TOOLTIP_TEXT_SECONDARY,
1283 g_param_spec_string ("secondary-icon-tooltip-text",
1284 P_("Secondary icon tooltip text"),
1285 P_("The contents of the tooltip on the secondary icon"),
1287 GTK_PARAM_READWRITE));
1290 * GtkEntry:primary-icon-tooltip-markup:
1292 * The contents of the tooltip on the primary icon, which is marked up
1293 * with the <link linkend="PangoMarkupFormat">Pango text markup
1296 * Also see gtk_entry_set_icon_tooltip_markup().
1300 g_object_class_install_property (gobject_class,
1301 PROP_TOOLTIP_MARKUP_PRIMARY,
1302 g_param_spec_string ("primary-icon-tooltip-markup",
1303 P_("Primary icon tooltip markup"),
1304 P_("The contents of the tooltip on the primary icon"),
1306 GTK_PARAM_READWRITE));
1309 * GtkEntry:secondary-icon-tooltip-markup:
1311 * The contents of the tooltip on the secondary icon, which is marked up
1312 * with the <link linkend="PangoMarkupFormat">Pango text markup
1315 * Also see gtk_entry_set_icon_tooltip_markup().
1319 g_object_class_install_property (gobject_class,
1320 PROP_TOOLTIP_MARKUP_SECONDARY,
1321 g_param_spec_string ("secondary-icon-tooltip-markup",
1322 P_("Secondary icon tooltip markup"),
1323 P_("The contents of the tooltip on the secondary icon"),
1325 GTK_PARAM_READWRITE));
1328 * GtkEntry:im-module:
1330 * Which IM (input method) module should be used for this entry.
1331 * See #GtkIMContext.
1333 * Setting this to a non-%NULL value overrides the
1334 * system-wide IM module setting. See the GtkSettings
1335 * #GtkSettings:gtk-im-module property.
1339 g_object_class_install_property (gobject_class,
1341 g_param_spec_string ("im-module",
1343 P_("Which IM module should be used"),
1345 GTK_PARAM_READWRITE));
1348 * GtkEntry:completion:
1350 * The auxiliary completion object to use with the entry.
1354 g_object_class_install_property (gobject_class,
1356 g_param_spec_object ("completion",
1358 P_("The auxiliary completion object"),
1359 GTK_TYPE_ENTRY_COMPLETION,
1360 GTK_PARAM_READWRITE));
1363 * GtkEntry:icon-prelight:
1365 * The prelight style property determines whether activatable
1366 * icons prelight on mouseover.
1370 gtk_widget_class_install_style_property (widget_class,
1371 g_param_spec_boolean ("icon-prelight",
1372 P_("Icon Prelight"),
1373 P_("Whether activatable icons should prelight when hovered"),
1375 GTK_PARAM_READABLE));
1378 * GtkEntry:progress-border:
1380 * The border around the progress bar in the entry.
1384 * Deprecated: 3.4: Use the standard margin CSS property;
1385 * the value of this style property is ignored.
1387 gtk_widget_class_install_style_property (widget_class,
1388 g_param_spec_boxed ("progress-border",
1389 P_("Progress Border"),
1390 P_("Border around the progress bar"),
1392 GTK_PARAM_READABLE |
1393 G_PARAM_DEPRECATED));
1396 * GtkEntry:invisible-char:
1398 * The invisible character is used when masking entry contents (in
1399 * \"password mode\")"). When it is not explicitly set with the
1400 * #GtkEntry:invisible-char property, GTK+ determines the character
1401 * to use from a list of possible candidates, depending on availability
1402 * in the current font.
1404 * This style property allows the theme to prepend a character
1405 * to the list of candidates.
1409 gtk_widget_class_install_style_property (widget_class,
1410 g_param_spec_unichar ("invisible-char",
1411 P_("Invisible character"),
1412 P_("The character to use when masking entry contents (in \"password mode\")"),
1414 GTK_PARAM_READABLE));
1417 * GtkEntry::populate-popup:
1418 * @entry: The entry on which the signal is emitted
1419 * @menu: the menu that is being populated
1421 * The ::populate-popup signal gets emitted before showing the
1422 * context menu of the entry.
1424 * If you need to add items to the context menu, connect
1425 * to this signal and append your menuitems to the @menu.
1427 signals[POPULATE_POPUP] =
1428 g_signal_new (I_("populate-popup"),
1429 G_OBJECT_CLASS_TYPE (gobject_class),
1431 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1433 _gtk_marshal_VOID__OBJECT,
1437 /* Action signals */
1440 * GtkEntry::activate:
1441 * @entry: The entry on which the signal is emitted
1443 * A <link linkend="keybinding-signals">keybinding signal</link>
1444 * which gets emitted when the user activates the entry.
1446 * Applications should not connect to it, but may emit it with
1447 * g_signal_emit_by_name() if they need to control activation
1450 * The default bindings for this signal are all forms of the Enter key.
1453 g_signal_new (I_("activate"),
1454 G_OBJECT_CLASS_TYPE (gobject_class),
1455 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1456 G_STRUCT_OFFSET (GtkEntryClass, activate),
1458 _gtk_marshal_VOID__VOID,
1460 widget_class->activate_signal = signals[ACTIVATE];
1463 * GtkEntry::move-cursor:
1464 * @entry: the object which received the signal
1465 * @step: the granularity of the move, as a #GtkMovementStep
1466 * @count: the number of @step units to move
1467 * @extend_selection: %TRUE if the move should extend the selection
1469 * The ::move-cursor signal is a
1470 * <link linkend="keybinding-signals">keybinding signal</link>
1471 * which gets emitted when the user initiates a cursor movement.
1472 * If the cursor is not visible in @entry, this signal causes
1473 * the viewport to be moved instead.
1475 * Applications should not connect to it, but may emit it with
1476 * g_signal_emit_by_name() if they need to control the cursor
1479 * The default bindings for this signal come in two variants,
1480 * the variant with the Shift modifier extends the selection,
1481 * the variant without the Shift modifer does not.
1482 * There are too many key combinations to list them all here.
1484 * <listitem>Arrow keys move by individual characters/lines</listitem>
1485 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1486 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1489 signals[MOVE_CURSOR] =
1490 g_signal_new (I_("move-cursor"),
1491 G_OBJECT_CLASS_TYPE (gobject_class),
1492 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1493 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1495 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1497 GTK_TYPE_MOVEMENT_STEP,
1502 * GtkEntry::insert-at-cursor:
1503 * @entry: the object which received the signal
1504 * @string: the string to insert
1506 * The ::insert-at-cursor signal is a
1507 * <link linkend="keybinding-signals">keybinding signal</link>
1508 * which gets emitted when the user initiates the insertion of a
1509 * fixed string at the cursor.
1511 * This signal has no default bindings.
1513 signals[INSERT_AT_CURSOR] =
1514 g_signal_new (I_("insert-at-cursor"),
1515 G_OBJECT_CLASS_TYPE (gobject_class),
1516 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1517 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1519 _gtk_marshal_VOID__STRING,
1524 * GtkEntry::delete-from-cursor:
1525 * @entry: the object which received the signal
1526 * @type: the granularity of the deletion, as a #GtkDeleteType
1527 * @count: the number of @type units to delete
1529 * The ::delete-from-cursor signal is a
1530 * <link linkend="keybinding-signals">keybinding signal</link>
1531 * which gets emitted when the user initiates a text deletion.
1533 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1534 * if there is one, otherwise it deletes the requested number
1537 * The default bindings for this signal are
1538 * Delete for deleting a character and Ctrl-Delete for
1541 signals[DELETE_FROM_CURSOR] =
1542 g_signal_new (I_("delete-from-cursor"),
1543 G_OBJECT_CLASS_TYPE (gobject_class),
1544 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1545 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1547 _gtk_marshal_VOID__ENUM_INT,
1549 GTK_TYPE_DELETE_TYPE,
1553 * GtkEntry::backspace:
1554 * @entry: the object which received the signal
1556 * The ::backspace signal is a
1557 * <link linkend="keybinding-signals">keybinding signal</link>
1558 * which gets emitted when the user asks for it.
1560 * The default bindings for this signal are
1561 * Backspace and Shift-Backspace.
1563 signals[BACKSPACE] =
1564 g_signal_new (I_("backspace"),
1565 G_OBJECT_CLASS_TYPE (gobject_class),
1566 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1567 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1569 _gtk_marshal_VOID__VOID,
1573 * GtkEntry::cut-clipboard:
1574 * @entry: the object which received the signal
1576 * The ::cut-clipboard signal is a
1577 * <link linkend="keybinding-signals">keybinding signal</link>
1578 * which gets emitted to cut the selection to the clipboard.
1580 * The default bindings for this signal are
1581 * Ctrl-x and Shift-Delete.
1583 signals[CUT_CLIPBOARD] =
1584 g_signal_new (I_("cut-clipboard"),
1585 G_OBJECT_CLASS_TYPE (gobject_class),
1586 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1587 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1589 _gtk_marshal_VOID__VOID,
1593 * GtkEntry::copy-clipboard:
1594 * @entry: the object which received the signal
1596 * The ::copy-clipboard signal is a
1597 * <link linkend="keybinding-signals">keybinding signal</link>
1598 * which gets emitted to copy the selection to the clipboard.
1600 * The default bindings for this signal are
1601 * Ctrl-c and Ctrl-Insert.
1603 signals[COPY_CLIPBOARD] =
1604 g_signal_new (I_("copy-clipboard"),
1605 G_OBJECT_CLASS_TYPE (gobject_class),
1606 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1607 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1609 _gtk_marshal_VOID__VOID,
1613 * GtkEntry::paste-clipboard:
1614 * @entry: the object which received the signal
1616 * The ::paste-clipboard signal is a
1617 * <link linkend="keybinding-signals">keybinding signal</link>
1618 * which gets emitted to paste the contents of the clipboard
1619 * into the text view.
1621 * The default bindings for this signal are
1622 * Ctrl-v and Shift-Insert.
1624 signals[PASTE_CLIPBOARD] =
1625 g_signal_new (I_("paste-clipboard"),
1626 G_OBJECT_CLASS_TYPE (gobject_class),
1627 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1628 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1630 _gtk_marshal_VOID__VOID,
1634 * GtkEntry::toggle-overwrite:
1635 * @entry: the object which received the signal
1637 * The ::toggle-overwrite signal is a
1638 * <link linkend="keybinding-signals">keybinding signal</link>
1639 * which gets emitted to toggle the overwrite mode of the entry.
1641 * The default bindings for this signal is Insert.
1643 signals[TOGGLE_OVERWRITE] =
1644 g_signal_new (I_("toggle-overwrite"),
1645 G_OBJECT_CLASS_TYPE (gobject_class),
1646 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1647 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1649 _gtk_marshal_VOID__VOID,
1653 * GtkEntry::icon-press:
1654 * @entry: The entry on which the signal is emitted
1655 * @icon_pos: The position of the clicked icon
1656 * @event: (type Gdk.EventButton): the button press event
1658 * The ::icon-press signal is emitted when an activatable icon
1663 signals[ICON_PRESS] =
1664 g_signal_new (I_("icon-press"),
1665 G_TYPE_FROM_CLASS (gobject_class),
1669 _gtk_marshal_VOID__ENUM_BOXED,
1671 GTK_TYPE_ENTRY_ICON_POSITION,
1672 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1675 * GtkEntry::icon-release:
1676 * @entry: The entry on which the signal is emitted
1677 * @icon_pos: The position of the clicked icon
1678 * @event: (type Gdk.EventButton): the button release event
1680 * The ::icon-release signal is emitted on the button release from a
1681 * mouse click over an activatable icon.
1685 signals[ICON_RELEASE] =
1686 g_signal_new (I_("icon-release"),
1687 G_TYPE_FROM_CLASS (gobject_class),
1691 _gtk_marshal_VOID__ENUM_BOXED,
1693 GTK_TYPE_ENTRY_ICON_POSITION,
1694 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1697 * GtkEntry::preedit-changed:
1698 * @entry: the object which received the signal
1699 * @preedit: the current preedit string
1701 * If an input method is used, the typed text will not immediately
1702 * be committed to the buffer. So if you are interested in the text,
1703 * connect to this signal.
1707 signals[PREEDIT_CHANGED] =
1708 g_signal_new_class_handler (I_("preedit-changed"),
1709 G_OBJECT_CLASS_TYPE (gobject_class),
1710 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1713 _gtk_marshal_VOID__STRING,
1722 binding_set = gtk_binding_set_by_class (class);
1724 /* Moving the insertion point */
1725 add_move_binding (binding_set, GDK_KEY_Right, 0,
1726 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1728 add_move_binding (binding_set, GDK_KEY_Left, 0,
1729 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1731 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1732 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1734 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1735 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1737 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1738 GTK_MOVEMENT_WORDS, 1);
1740 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1741 GTK_MOVEMENT_WORDS, -1);
1743 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1744 GTK_MOVEMENT_WORDS, 1);
1746 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1747 GTK_MOVEMENT_WORDS, -1);
1749 add_move_binding (binding_set, GDK_KEY_Home, 0,
1750 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1752 add_move_binding (binding_set, GDK_KEY_End, 0,
1753 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1755 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1756 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1758 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1759 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1761 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1762 GTK_MOVEMENT_BUFFER_ENDS, -1);
1764 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1765 GTK_MOVEMENT_BUFFER_ENDS, 1);
1767 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1768 GTK_MOVEMENT_BUFFER_ENDS, -1);
1770 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1771 GTK_MOVEMENT_BUFFER_ENDS, 1);
1775 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1777 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1779 G_TYPE_BOOLEAN, FALSE);
1780 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1782 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1784 G_TYPE_BOOLEAN, TRUE);
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1788 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1790 G_TYPE_BOOLEAN, FALSE);
1791 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1793 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1795 G_TYPE_BOOLEAN, TRUE);
1798 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1800 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1802 G_TYPE_BOOLEAN, FALSE);
1803 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1805 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1807 G_TYPE_BOOLEAN, FALSE);
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1813 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1815 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1819 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1820 "delete-from-cursor", 2,
1821 G_TYPE_ENUM, GTK_DELETE_CHARS,
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1825 "delete-from-cursor", 2,
1826 G_TYPE_ENUM, GTK_DELETE_CHARS,
1829 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1832 /* Make this do the same as Backspace, to help with mis-typing */
1833 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1836 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1837 "delete-from-cursor", 2,
1838 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1841 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1842 "delete-from-cursor", 2,
1843 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1846 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1847 "delete-from-cursor", 2,
1848 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1851 /* Cut/copy/paste */
1853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1854 "cut-clipboard", 0);
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1856 "copy-clipboard", 0);
1857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1858 "paste-clipboard", 0);
1860 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1861 "cut-clipboard", 0);
1862 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1863 "copy-clipboard", 0);
1864 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1865 "paste-clipboard", 0);
1868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1869 "toggle-overwrite", 0);
1870 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1871 "toggle-overwrite", 0);
1874 * GtkEntry:inner-border:
1876 * Sets the text area's border between the text and the frame.
1880 * Deprecated: 3.4: Use the standard border and padding CSS properties;
1881 * the value of this style property is ignored.
1883 gtk_widget_class_install_style_property (widget_class,
1884 g_param_spec_boxed ("inner-border",
1886 P_("Border between text and frame."),
1888 GTK_PARAM_READABLE |
1889 G_PARAM_DEPRECATED));
1891 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1893 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1897 gtk_entry_editable_init (GtkEditableInterface *iface)
1899 iface->do_insert_text = gtk_entry_insert_text;
1900 iface->do_delete_text = gtk_entry_delete_text;
1901 iface->insert_text = gtk_entry_real_insert_text;
1902 iface->delete_text = gtk_entry_real_delete_text;
1903 iface->get_chars = gtk_entry_get_chars;
1904 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1905 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1906 iface->set_position = gtk_entry_real_set_position;
1907 iface->get_position = gtk_entry_get_position;
1911 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1913 iface->start_editing = gtk_entry_start_editing;
1916 /* for deprecated properties */
1918 gtk_entry_do_set_inner_border (GtkEntry *entry,
1919 const GtkBorder *border)
1922 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1923 gtk_border_copy (border),
1924 (GDestroyNotify) gtk_border_free);
1926 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1928 g_object_notify (G_OBJECT (entry), "inner-border");
1931 static const GtkBorder *
1932 gtk_entry_do_get_inner_border (GtkEntry *entry)
1934 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1938 gtk_entry_set_property (GObject *object,
1940 const GValue *value,
1943 GtkEntry *entry = GTK_ENTRY (object);
1944 GtkEntryPrivate *priv = entry->priv;
1949 gtk_entry_set_buffer (entry, g_value_get_object (value));
1954 gboolean new_value = g_value_get_boolean (value);
1956 if (new_value != priv->editable)
1958 GtkWidget *widget = GTK_WIDGET (entry);
1962 _gtk_entry_reset_im_context (entry);
1963 if (gtk_widget_has_focus (widget))
1964 gtk_im_context_focus_out (priv->im_context);
1966 priv->preedit_length = 0;
1967 priv->preedit_cursor = 0;
1970 priv->editable = new_value;
1972 if (new_value && gtk_widget_has_focus (widget))
1973 gtk_im_context_focus_in (priv->im_context);
1975 gtk_widget_queue_draw (widget);
1980 case PROP_MAX_LENGTH:
1981 gtk_entry_set_max_length (entry, g_value_get_int (value));
1984 case PROP_VISIBILITY:
1985 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1988 case PROP_HAS_FRAME:
1989 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1992 case PROP_INNER_BORDER:
1993 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1996 case PROP_INVISIBLE_CHAR:
1997 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2000 case PROP_ACTIVATES_DEFAULT:
2001 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2004 case PROP_WIDTH_CHARS:
2005 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2009 gtk_entry_set_text (entry, g_value_get_string (value));
2013 gtk_entry_set_alignment (entry, g_value_get_float (value));
2016 case PROP_TRUNCATE_MULTILINE:
2017 priv->truncate_multiline = g_value_get_boolean (value);
2020 case PROP_SHADOW_TYPE:
2021 priv->shadow_type = g_value_get_enum (value);
2024 case PROP_OVERWRITE_MODE:
2025 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2028 case PROP_INVISIBLE_CHAR_SET:
2029 if (g_value_get_boolean (value))
2030 priv->invisible_char_set = TRUE;
2032 gtk_entry_unset_invisible_char (entry);
2035 case PROP_CAPS_LOCK_WARNING:
2036 priv->caps_lock_warning = g_value_get_boolean (value);
2039 case PROP_PROGRESS_FRACTION:
2040 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2043 case PROP_PROGRESS_PULSE_STEP:
2044 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2047 case PROP_PLACEHOLDER_TEXT:
2048 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2051 case PROP_PIXBUF_PRIMARY:
2052 gtk_entry_set_icon_from_pixbuf (entry,
2053 GTK_ENTRY_ICON_PRIMARY,
2054 g_value_get_object (value));
2057 case PROP_PIXBUF_SECONDARY:
2058 gtk_entry_set_icon_from_pixbuf (entry,
2059 GTK_ENTRY_ICON_SECONDARY,
2060 g_value_get_object (value));
2063 case PROP_STOCK_PRIMARY:
2064 gtk_entry_set_icon_from_stock (entry,
2065 GTK_ENTRY_ICON_PRIMARY,
2066 g_value_get_string (value));
2069 case PROP_STOCK_SECONDARY:
2070 gtk_entry_set_icon_from_stock (entry,
2071 GTK_ENTRY_ICON_SECONDARY,
2072 g_value_get_string (value));
2075 case PROP_ICON_NAME_PRIMARY:
2076 gtk_entry_set_icon_from_icon_name (entry,
2077 GTK_ENTRY_ICON_PRIMARY,
2078 g_value_get_string (value));
2081 case PROP_ICON_NAME_SECONDARY:
2082 gtk_entry_set_icon_from_icon_name (entry,
2083 GTK_ENTRY_ICON_SECONDARY,
2084 g_value_get_string (value));
2087 case PROP_GICON_PRIMARY:
2088 gtk_entry_set_icon_from_gicon (entry,
2089 GTK_ENTRY_ICON_PRIMARY,
2090 g_value_get_object (value));
2093 case PROP_GICON_SECONDARY:
2094 gtk_entry_set_icon_from_gicon (entry,
2095 GTK_ENTRY_ICON_SECONDARY,
2096 g_value_get_object (value));
2099 case PROP_ACTIVATABLE_PRIMARY:
2100 gtk_entry_set_icon_activatable (entry,
2101 GTK_ENTRY_ICON_PRIMARY,
2102 g_value_get_boolean (value));
2105 case PROP_ACTIVATABLE_SECONDARY:
2106 gtk_entry_set_icon_activatable (entry,
2107 GTK_ENTRY_ICON_SECONDARY,
2108 g_value_get_boolean (value));
2111 case PROP_SENSITIVE_PRIMARY:
2112 gtk_entry_set_icon_sensitive (entry,
2113 GTK_ENTRY_ICON_PRIMARY,
2114 g_value_get_boolean (value));
2117 case PROP_SENSITIVE_SECONDARY:
2118 gtk_entry_set_icon_sensitive (entry,
2119 GTK_ENTRY_ICON_SECONDARY,
2120 g_value_get_boolean (value));
2123 case PROP_TOOLTIP_TEXT_PRIMARY:
2124 gtk_entry_set_icon_tooltip_text (entry,
2125 GTK_ENTRY_ICON_PRIMARY,
2126 g_value_get_string (value));
2129 case PROP_TOOLTIP_TEXT_SECONDARY:
2130 gtk_entry_set_icon_tooltip_text (entry,
2131 GTK_ENTRY_ICON_SECONDARY,
2132 g_value_get_string (value));
2135 case PROP_TOOLTIP_MARKUP_PRIMARY:
2136 gtk_entry_set_icon_tooltip_markup (entry,
2137 GTK_ENTRY_ICON_PRIMARY,
2138 g_value_get_string (value));
2141 case PROP_TOOLTIP_MARKUP_SECONDARY:
2142 gtk_entry_set_icon_tooltip_markup (entry,
2143 GTK_ENTRY_ICON_SECONDARY,
2144 g_value_get_string (value));
2147 case PROP_IM_MODULE:
2148 g_free (priv->im_module);
2149 priv->im_module = g_value_dup_string (value);
2150 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2151 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2154 case PROP_EDITING_CANCELED:
2155 priv->editing_canceled = g_value_get_boolean (value);
2158 case PROP_COMPLETION:
2159 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2162 case PROP_SCROLL_OFFSET:
2163 case PROP_CURSOR_POSITION:
2165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2171 gtk_entry_get_property (GObject *object,
2176 GtkEntry *entry = GTK_ENTRY (object);
2177 GtkEntryPrivate *priv = entry->priv;
2182 g_value_set_object (value, gtk_entry_get_buffer (entry));
2185 case PROP_CURSOR_POSITION:
2186 g_value_set_int (value, priv->current_pos);
2189 case PROP_SELECTION_BOUND:
2190 g_value_set_int (value, priv->selection_bound);
2194 g_value_set_boolean (value, priv->editable);
2197 case PROP_MAX_LENGTH:
2198 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2201 case PROP_VISIBILITY:
2202 g_value_set_boolean (value, priv->visible);
2205 case PROP_HAS_FRAME:
2206 g_value_set_boolean (value, priv->has_frame);
2209 case PROP_INNER_BORDER:
2210 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2213 case PROP_INVISIBLE_CHAR:
2214 g_value_set_uint (value, priv->invisible_char);
2217 case PROP_ACTIVATES_DEFAULT:
2218 g_value_set_boolean (value, priv->activates_default);
2221 case PROP_WIDTH_CHARS:
2222 g_value_set_int (value, priv->width_chars);
2225 case PROP_SCROLL_OFFSET:
2226 g_value_set_int (value, priv->scroll_offset);
2230 g_value_set_string (value, gtk_entry_get_text (entry));
2234 g_value_set_float (value, gtk_entry_get_alignment (entry));
2237 case PROP_TRUNCATE_MULTILINE:
2238 g_value_set_boolean (value, priv->truncate_multiline);
2241 case PROP_SHADOW_TYPE:
2242 g_value_set_enum (value, priv->shadow_type);
2245 case PROP_OVERWRITE_MODE:
2246 g_value_set_boolean (value, priv->overwrite_mode);
2249 case PROP_TEXT_LENGTH:
2250 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2253 case PROP_INVISIBLE_CHAR_SET:
2254 g_value_set_boolean (value, priv->invisible_char_set);
2257 case PROP_IM_MODULE:
2258 g_value_set_string (value, priv->im_module);
2261 case PROP_CAPS_LOCK_WARNING:
2262 g_value_set_boolean (value, priv->caps_lock_warning);
2265 case PROP_PROGRESS_FRACTION:
2266 g_value_set_double (value, priv->progress_fraction);
2269 case PROP_PROGRESS_PULSE_STEP:
2270 g_value_set_double (value, priv->progress_pulse_fraction);
2273 case PROP_PLACEHOLDER_TEXT:
2274 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2277 case PROP_PIXBUF_PRIMARY:
2278 g_value_set_object (value,
2279 gtk_entry_get_icon_pixbuf (entry,
2280 GTK_ENTRY_ICON_PRIMARY));
2283 case PROP_PIXBUF_SECONDARY:
2284 g_value_set_object (value,
2285 gtk_entry_get_icon_pixbuf (entry,
2286 GTK_ENTRY_ICON_SECONDARY));
2289 case PROP_STOCK_PRIMARY:
2290 g_value_set_string (value,
2291 gtk_entry_get_icon_stock (entry,
2292 GTK_ENTRY_ICON_PRIMARY));
2295 case PROP_STOCK_SECONDARY:
2296 g_value_set_string (value,
2297 gtk_entry_get_icon_stock (entry,
2298 GTK_ENTRY_ICON_SECONDARY));
2301 case PROP_ICON_NAME_PRIMARY:
2302 g_value_set_string (value,
2303 gtk_entry_get_icon_name (entry,
2304 GTK_ENTRY_ICON_PRIMARY));
2307 case PROP_ICON_NAME_SECONDARY:
2308 g_value_set_string (value,
2309 gtk_entry_get_icon_name (entry,
2310 GTK_ENTRY_ICON_SECONDARY));
2313 case PROP_GICON_PRIMARY:
2314 g_value_set_object (value,
2315 gtk_entry_get_icon_gicon (entry,
2316 GTK_ENTRY_ICON_PRIMARY));
2319 case PROP_GICON_SECONDARY:
2320 g_value_set_object (value,
2321 gtk_entry_get_icon_gicon (entry,
2322 GTK_ENTRY_ICON_SECONDARY));
2325 case PROP_STORAGE_TYPE_PRIMARY:
2326 g_value_set_enum (value,
2327 gtk_entry_get_icon_storage_type (entry,
2328 GTK_ENTRY_ICON_PRIMARY));
2331 case PROP_STORAGE_TYPE_SECONDARY:
2332 g_value_set_enum (value,
2333 gtk_entry_get_icon_storage_type (entry,
2334 GTK_ENTRY_ICON_SECONDARY));
2337 case PROP_ACTIVATABLE_PRIMARY:
2338 g_value_set_boolean (value,
2339 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2342 case PROP_ACTIVATABLE_SECONDARY:
2343 g_value_set_boolean (value,
2344 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2347 case PROP_SENSITIVE_PRIMARY:
2348 g_value_set_boolean (value,
2349 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2352 case PROP_SENSITIVE_SECONDARY:
2353 g_value_set_boolean (value,
2354 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2357 case PROP_TOOLTIP_TEXT_PRIMARY:
2358 g_value_take_string (value,
2359 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2362 case PROP_TOOLTIP_TEXT_SECONDARY:
2363 g_value_take_string (value,
2364 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2367 case PROP_TOOLTIP_MARKUP_PRIMARY:
2368 g_value_take_string (value,
2369 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2372 case PROP_TOOLTIP_MARKUP_SECONDARY:
2373 g_value_take_string (value,
2374 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2377 case PROP_EDITING_CANCELED:
2378 g_value_set_boolean (value,
2379 priv->editing_canceled);
2382 case PROP_COMPLETION:
2383 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2387 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2393 find_invisible_char (GtkWidget *widget)
2395 PangoLayout *layout;
2396 PangoAttrList *attr_list;
2398 gunichar invisible_chars [] = {
2400 0x25cf, /* BLACK CIRCLE */
2401 0x2022, /* BULLET */
2402 0x2731, /* HEAVY ASTERISK */
2403 0x273a /* SIXTEEN POINTED ASTERISK */
2406 gtk_widget_style_get (widget,
2407 "invisible-char", &invisible_chars[0],
2410 layout = gtk_widget_create_pango_layout (widget, NULL);
2412 attr_list = pango_attr_list_new ();
2413 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2415 pango_layout_set_attributes (layout, attr_list);
2416 pango_attr_list_unref (attr_list);
2418 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2420 gchar text[7] = { 0, };
2423 len = g_unichar_to_utf8 (invisible_chars[i], text);
2424 pango_layout_set_text (layout, text, len);
2426 count = pango_layout_get_unknown_glyphs_count (layout);
2430 g_object_unref (layout);
2431 return invisible_chars[i];
2435 g_object_unref (layout);
2441 gtk_entry_init (GtkEntry *entry)
2443 GtkStyleContext *context;
2444 GtkEntryPrivate *priv;
2446 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2451 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2452 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2454 priv->editable = TRUE;
2455 priv->visible = TRUE;
2456 priv->dnd_position = -1;
2457 priv->width_chars = -1;
2458 priv->is_cell_renderer = FALSE;
2459 priv->editing_canceled = FALSE;
2460 priv->has_frame = TRUE;
2461 priv->truncate_multiline = FALSE;
2462 priv->shadow_type = GTK_SHADOW_IN;
2464 priv->caps_lock_warning = TRUE;
2465 priv->caps_lock_warning_shown = FALSE;
2466 priv->progress_fraction = 0.0;
2467 priv->progress_pulse_fraction = 0.1;
2469 gtk_drag_dest_set (GTK_WIDGET (entry),
2470 GTK_DEST_DEFAULT_HIGHLIGHT,
2472 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2473 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2475 /* This object is completely private. No external entity can gain a reference
2476 * to it; so we create it here and destroy it in finalize().
2478 priv->im_context = gtk_im_multicontext_new ();
2480 g_signal_connect (priv->im_context, "commit",
2481 G_CALLBACK (gtk_entry_commit_cb), entry);
2482 g_signal_connect (priv->im_context, "preedit-changed",
2483 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2484 g_signal_connect (priv->im_context, "retrieve-surrounding",
2485 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2486 g_signal_connect (priv->im_context, "delete-surrounding",
2487 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2489 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2490 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2492 gtk_entry_update_cached_style_values (entry);
2496 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2497 GtkStyleContext *context,
2498 GtkEntryIconPosition icon_pos)
2500 GtkEntryPrivate *priv = entry->priv;
2501 EntryIconInfo *icon_info = priv->icons[icon_pos];
2503 GtkStateFlags state;
2505 widget = GTK_WIDGET (entry);
2506 state = gtk_widget_get_state_flags (widget);
2508 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2510 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2511 state |= GTK_STATE_FLAG_INSENSITIVE;
2512 else if (icon_info->prelight)
2513 state |= GTK_STATE_FLAG_PRELIGHT;
2515 gtk_style_context_save (context);
2517 gtk_style_context_set_state (context, state);
2518 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2520 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2522 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2523 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2525 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2529 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2530 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2532 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2537 get_icon_width (GtkEntry *entry,
2538 GtkEntryIconPosition icon_pos)
2540 GtkEntryPrivate *priv = entry->priv;
2541 EntryIconInfo *icon_info = priv->icons[icon_pos];
2542 GtkStyleContext *context;
2549 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2550 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2551 gtk_style_context_get_padding (context, 0, &padding);
2553 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2555 gtk_style_context_restore (context);
2558 width += padding.left + padding.right;
2564 get_icon_allocations (GtkEntry *entry,
2565 GtkAllocation *primary,
2566 GtkAllocation *secondary)
2569 GtkEntryPrivate *priv = entry->priv;
2570 gint x, y, width, height;
2572 get_text_area_size (entry, &x, &y, &width, &height);
2574 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2575 y += priv->focus_width;
2578 primary->height = height;
2579 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2582 secondary->height = height;
2583 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2585 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2587 primary->x = x + width - primary->width;
2593 secondary->x = x + width - secondary->width;
2599 begin_change (GtkEntry *entry)
2601 GtkEntryPrivate *priv = entry->priv;
2603 priv->change_count++;
2605 g_object_freeze_notify (G_OBJECT (entry));
2609 end_change (GtkEntry *entry)
2611 GtkEditable *editable = GTK_EDITABLE (entry);
2612 GtkEntryPrivate *priv = entry->priv;
2614 g_return_if_fail (priv->change_count > 0);
2616 g_object_thaw_notify (G_OBJECT (entry));
2618 priv->change_count--;
2620 if (priv->change_count == 0)
2622 if (priv->real_changed)
2624 g_signal_emit_by_name (editable, "changed");
2625 priv->real_changed = FALSE;
2631 emit_changed (GtkEntry *entry)
2633 GtkEditable *editable = GTK_EDITABLE (entry);
2634 GtkEntryPrivate *priv = entry->priv;
2636 if (priv->change_count == 0)
2637 g_signal_emit_by_name (editable, "changed");
2639 priv->real_changed = TRUE;
2643 gtk_entry_destroy (GtkWidget *widget)
2645 GtkEntry *entry = GTK_ENTRY (widget);
2646 GtkEntryPrivate *priv = entry->priv;
2648 priv->current_pos = priv->selection_bound = 0;
2649 _gtk_entry_reset_im_context (entry);
2650 gtk_entry_reset_layout (entry);
2652 if (priv->blink_timeout)
2654 g_source_remove (priv->blink_timeout);
2655 priv->blink_timeout = 0;
2658 if (priv->recompute_idle)
2660 g_source_remove (priv->recompute_idle);
2661 priv->recompute_idle = 0;
2664 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2668 gtk_entry_dispose (GObject *object)
2670 GtkEntry *entry = GTK_ENTRY (object);
2671 GtkEntryPrivate *priv = entry->priv;
2674 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2675 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2676 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2677 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2681 buffer_disconnect_signals (entry);
2682 g_object_unref (priv->buffer);
2683 priv->buffer = NULL;
2686 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2687 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2688 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2689 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2693 gtk_entry_finalize (GObject *object)
2695 GtkEntry *entry = GTK_ENTRY (object);
2696 GtkEntryPrivate *priv = entry->priv;
2697 EntryIconInfo *icon_info = NULL;
2700 for (i = 0; i < MAX_ICONS; i++)
2702 if ((icon_info = priv->icons[i]) != NULL)
2704 if (icon_info->target_list != NULL)
2706 gtk_target_list_unref (icon_info->target_list);
2707 icon_info->target_list = NULL;
2710 g_clear_object (&icon_info->icon_helper);
2712 g_slice_free (EntryIconInfo, icon_info);
2713 priv->icons[i] = NULL;
2717 gtk_entry_set_completion (entry, NULL);
2719 if (priv->cached_layout)
2720 g_object_unref (priv->cached_layout);
2722 g_object_unref (priv->im_context);
2724 if (priv->blink_timeout)
2725 g_source_remove (priv->blink_timeout);
2727 if (priv->recompute_idle)
2728 g_source_remove (priv->recompute_idle);
2730 g_free (priv->placeholder_text);
2731 g_free (priv->im_module);
2733 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2737 gtk_entry_get_display_mode (GtkEntry *entry)
2739 GtkEntryPrivate *priv = entry->priv;
2742 return DISPLAY_NORMAL;
2744 if (priv->invisible_char == 0 && priv->invisible_char_set)
2745 return DISPLAY_BLANK;
2747 return DISPLAY_INVISIBLE;
2751 gtk_entry_get_display_text (GtkEntry *entry,
2755 GtkEntryPasswordHint *password_hint;
2756 GtkEntryPrivate *priv;
2757 gunichar invisible_char;
2768 text = gtk_entry_buffer_get_text (get_buffer (entry));
2769 length = gtk_entry_buffer_get_length (get_buffer (entry));
2773 if (start_pos > length)
2776 if (end_pos <= start_pos)
2777 return g_strdup ("");
2778 else if (priv->visible)
2780 start = g_utf8_offset_to_pointer (text, start_pos);
2781 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2782 return g_strndup (start, end - start);
2786 str = g_string_sized_new (length * 2);
2788 /* Figure out what our invisible char is and encode it */
2789 if (!priv->invisible_char)
2790 invisible_char = priv->invisible_char_set ? ' ' : '*';
2792 invisible_char = priv->invisible_char;
2793 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2796 * Add hidden characters for each character in the text
2797 * buffer. If there is a password hint, then keep that
2798 * character visible.
2801 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2802 for (i = start_pos; i < end_pos; ++i)
2804 if (password_hint && i == password_hint->position)
2806 start = g_utf8_offset_to_pointer (text, i);
2807 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2811 g_string_append_len (str, char_str, char_len);
2815 return g_string_free (str, FALSE);
2820 update_cursors (GtkWidget *widget)
2822 GtkEntry *entry = GTK_ENTRY (widget);
2823 GtkEntryPrivate *priv = entry->priv;
2824 EntryIconInfo *icon_info = NULL;
2825 GdkDisplay *display;
2829 for (i = 0; i < MAX_ICONS; i++)
2831 if ((icon_info = priv->icons[i]) != NULL)
2833 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2834 icon_info->window != NULL)
2835 gdk_window_show_unraised (icon_info->window);
2837 /* The icon windows are not children of the visible entry window,
2838 * thus we can't just inherit the xterm cursor. Slight complication
2839 * here is that for the entry, insensitive => arrow cursor, but for
2840 * an icon in a sensitive entry, insensitive => xterm cursor.
2842 if (gtk_widget_is_sensitive (widget) &&
2843 (icon_info->insensitive ||
2844 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2846 display = gtk_widget_get_display (widget);
2847 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2848 gdk_window_set_cursor (icon_info->window, cursor);
2849 g_object_unref (cursor);
2853 gdk_window_set_cursor (icon_info->window, NULL);
2860 realize_icon_info (GtkWidget *widget,
2861 GtkEntryIconPosition icon_pos)
2863 GtkEntry *entry = GTK_ENTRY (widget);
2864 GtkEntryPrivate *priv = entry->priv;
2865 EntryIconInfo *icon_info = priv->icons[icon_pos];
2866 GdkWindowAttr attributes;
2867 gint attributes_mask;
2869 g_return_if_fail (icon_info != NULL);
2873 attributes.width = 1;
2874 attributes.height = 1;
2875 attributes.window_type = GDK_WINDOW_CHILD;
2876 attributes.wclass = GDK_INPUT_ONLY;
2877 attributes.event_mask = gtk_widget_get_events (widget);
2878 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2879 GDK_BUTTON_RELEASE_MASK |
2880 GDK_BUTTON1_MOTION_MASK |
2881 GDK_BUTTON3_MOTION_MASK |
2882 GDK_POINTER_MOTION_HINT_MASK |
2883 GDK_POINTER_MOTION_MASK |
2884 GDK_ENTER_NOTIFY_MASK |
2885 GDK_LEAVE_NOTIFY_MASK);
2886 attributes_mask = GDK_WA_X | GDK_WA_Y;
2888 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2891 gdk_window_set_user_data (icon_info->window, widget);
2893 gtk_widget_queue_resize (widget);
2896 static EntryIconInfo*
2897 construct_icon_info (GtkWidget *widget,
2898 GtkEntryIconPosition icon_pos)
2900 GtkEntry *entry = GTK_ENTRY (widget);
2901 GtkEntryPrivate *priv = entry->priv;
2902 EntryIconInfo *icon_info;
2904 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2906 icon_info = g_slice_new0 (EntryIconInfo);
2907 priv->icons[icon_pos] = icon_info;
2909 icon_info->icon_helper = _gtk_icon_helper_new ();
2911 if (gtk_widget_get_realized (widget))
2912 realize_icon_info (widget, icon_pos);
2918 gtk_entry_map (GtkWidget *widget)
2920 GtkEntry *entry = GTK_ENTRY (widget);
2921 GtkEntryPrivate *priv = entry->priv;
2922 EntryIconInfo *icon_info = NULL;
2925 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2927 gdk_window_show (priv->text_area);
2929 for (i = 0; i < MAX_ICONS; i++)
2931 if ((icon_info = priv->icons[i]) != NULL)
2933 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2934 icon_info->window != NULL)
2935 gdk_window_show (icon_info->window);
2939 update_cursors (widget);
2943 gtk_entry_unmap (GtkWidget *widget)
2945 GtkEntry *entry = GTK_ENTRY (widget);
2946 GtkEntryPrivate *priv = entry->priv;
2947 EntryIconInfo *icon_info = NULL;
2950 for (i = 0; i < MAX_ICONS; i++)
2952 if ((icon_info = priv->icons[i]) != NULL)
2954 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2955 icon_info->window != NULL)
2956 gdk_window_hide (icon_info->window);
2960 gdk_window_hide (priv->text_area);
2962 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2966 gtk_entry_realize (GtkWidget *widget)
2969 GtkEntryPrivate *priv;
2970 EntryIconInfo *icon_info;
2972 GdkWindowAttr attributes;
2973 gint attributes_mask;
2974 gint frame_x, frame_y;
2977 gtk_widget_set_realized (widget, TRUE);
2978 window = gtk_widget_get_parent_window (widget);
2979 gtk_widget_set_window (widget, window);
2980 g_object_ref (window);
2982 entry = GTK_ENTRY (widget);
2985 attributes.window_type = GDK_WINDOW_CHILD;
2986 attributes.wclass = GDK_INPUT_ONLY;
2987 attributes.event_mask = gtk_widget_get_events (widget);
2988 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2989 GDK_BUTTON_RELEASE_MASK |
2990 GDK_BUTTON1_MOTION_MASK |
2991 GDK_BUTTON3_MOTION_MASK |
2992 GDK_POINTER_MOTION_HINT_MASK |
2993 GDK_POINTER_MOTION_MASK |
2994 GDK_ENTER_NOTIFY_MASK |
2995 GDK_LEAVE_NOTIFY_MASK);
2996 attributes_mask = GDK_WA_X | GDK_WA_Y;
2998 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3000 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3001 attributes.x += frame_x;
3002 attributes.y += frame_y;
3004 if (gtk_widget_is_sensitive (widget))
3006 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3007 attributes_mask |= GDK_WA_CURSOR;
3010 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3014 gdk_window_set_user_data (priv->text_area, entry);
3016 if (attributes_mask & GDK_WA_CURSOR)
3017 g_object_unref (attributes.cursor);
3019 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3021 gtk_entry_adjust_scroll (entry);
3022 gtk_entry_update_primary_selection (entry);
3025 /* If the icon positions are already setup, create their windows.
3026 * Otherwise if they don't exist yet, then construct_icon_info()
3027 * will create the windows once the widget is already realized.
3029 for (i = 0; i < MAX_ICONS; i++)
3031 if ((icon_info = priv->icons[i]) != NULL)
3033 if (icon_info->window == NULL)
3034 realize_icon_info (widget, i);
3040 gtk_entry_unrealize (GtkWidget *widget)
3042 GtkEntry *entry = GTK_ENTRY (widget);
3043 GtkEntryPrivate *priv = entry->priv;
3044 GtkClipboard *clipboard;
3045 EntryIconInfo *icon_info;
3048 gtk_entry_reset_layout (entry);
3050 gtk_im_context_set_client_window (priv->im_context, NULL);
3052 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3053 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3054 gtk_clipboard_clear (clipboard);
3056 if (priv->text_area)
3058 gdk_window_set_user_data (priv->text_area, NULL);
3059 gdk_window_destroy (priv->text_area);
3060 priv->text_area = NULL;
3063 if (priv->popup_menu)
3065 gtk_widget_destroy (priv->popup_menu);
3066 priv->popup_menu = NULL;
3069 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3071 for (i = 0; i < MAX_ICONS; i++)
3073 if ((icon_info = priv->icons[i]) != NULL)
3075 if (icon_info->window != NULL)
3077 gdk_window_destroy (icon_info->window);
3078 icon_info->window = NULL;
3085 _gtk_entry_get_borders (GtkEntry *entry,
3086 GtkBorder *border_out)
3088 GtkEntryPrivate *priv = entry->priv;
3089 GtkWidget *widget = GTK_WIDGET (entry);
3090 GtkBorder tmp = { 0, 0, 0, 0 };
3091 GtkStyleContext *context;
3093 context = gtk_widget_get_style_context (widget);
3094 gtk_style_context_get_padding (context, 0, &tmp);
3096 if (priv->has_frame)
3100 gtk_style_context_get_border (context, 0, &border);
3101 tmp.top += border.top;
3102 tmp.right += border.right;
3103 tmp.bottom += border.bottom;
3104 tmp.left += border.left;
3107 if (!priv->interior_focus)
3109 tmp.top += priv->focus_width;
3110 tmp.right += priv->focus_width;
3111 tmp.bottom += priv->focus_width;
3112 tmp.left += priv->focus_width;
3115 if (border_out != NULL)
3120 gtk_entry_get_preferred_width (GtkWidget *widget,
3124 GtkEntry *entry = GTK_ENTRY (widget);
3125 GtkEntryPrivate *priv = entry->priv;
3126 PangoFontMetrics *metrics;
3128 PangoContext *context;
3129 GtkStyleContext *style_context;
3130 GtkStateFlags state;
3131 gint icon_widths = 0;
3135 context = gtk_widget_get_pango_context (widget);
3137 style_context = gtk_widget_get_style_context (widget);
3138 state = gtk_widget_get_state_flags (widget);
3140 metrics = pango_context_get_metrics (context,
3141 gtk_style_context_get_font (style_context, state),
3142 pango_context_get_language (context));
3144 _gtk_entry_get_borders (entry, &borders);
3146 if (priv->width_chars < 0)
3147 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3150 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3151 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3152 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3154 width = char_pixels * priv->width_chars + borders.left + borders.right;
3157 for (i = 0; i < MAX_ICONS; i++)
3159 icon_width = get_icon_width (entry, i);
3161 icon_widths += icon_width;
3164 if (icon_widths > width)
3165 width += icon_widths;
3167 pango_font_metrics_unref (metrics);
3174 gtk_entry_get_preferred_height (GtkWidget *widget,
3178 GtkEntry *entry = GTK_ENTRY (widget);
3179 GtkEntryPrivate *priv = entry->priv;
3180 PangoFontMetrics *metrics;
3182 GtkStyleContext *style_context;
3183 GtkStateFlags state;
3184 PangoContext *context;
3187 context = gtk_widget_get_pango_context (widget);
3189 style_context = gtk_widget_get_style_context (widget);
3190 state = gtk_widget_get_state_flags (widget);
3192 metrics = pango_context_get_metrics (context,
3193 gtk_style_context_get_font (style_context, state),
3194 pango_context_get_language (context));
3196 priv->ascent = pango_font_metrics_get_ascent (metrics);
3197 priv->descent = pango_font_metrics_get_descent (metrics);
3199 _gtk_entry_get_borders (entry, &borders);
3201 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3203 pango_font_metrics_unref (metrics);
3210 place_windows (GtkEntry *entry)
3212 GtkWidget *widget = GTK_WIDGET (entry);
3213 GtkEntryPrivate *priv = entry->priv;
3214 gint x, y, width, height;
3215 gint frame_x, frame_y;
3216 GtkAllocation primary;
3217 GtkAllocation secondary;
3218 EntryIconInfo *icon_info = NULL;
3220 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3221 get_text_area_size (entry, &x, &y, &width, &height);
3222 get_icon_allocations (entry, &primary, &secondary);
3224 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3225 y += priv->focus_width;
3227 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3228 x += secondary.width;
3231 width -= primary.width + secondary.width;
3235 primary.x += frame_x;
3236 primary.y += frame_y;
3237 secondary.x += frame_x;
3238 secondary.y += frame_y;
3240 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3241 gdk_window_move_resize (icon_info->window,
3242 primary.x, primary.y,
3243 primary.width, primary.height);
3245 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3246 gdk_window_move_resize (icon_info->window,
3247 secondary.x, secondary.y,
3248 secondary.width, secondary.height);
3250 gdk_window_move_resize (priv->text_area, x, y, width, height);
3254 gtk_entry_get_text_area_size (GtkEntry *entry,
3260 GtkEntryPrivate *priv = entry->priv;
3261 GtkWidget *widget = GTK_WIDGET (entry);
3262 GtkAllocation allocation;
3263 GtkRequisition requisition;
3268 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3269 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3271 gtk_widget_get_allocation (widget, &allocation);
3272 _gtk_entry_get_borders (entry, &borders);
3274 if (gtk_widget_get_realized (widget))
3275 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3277 frame_height = req_height;
3279 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3280 frame_height -= 2 * priv->focus_width;
3286 *y = floor ((frame_height - req_height) / 2) + borders.top;
3289 *width = allocation.width - borders.left - borders.right;
3292 *height = req_height - borders.top - borders.bottom;
3296 get_text_area_size (GtkEntry *entry,
3302 GtkEntryClass *class;
3304 g_return_if_fail (GTK_IS_ENTRY (entry));
3306 class = GTK_ENTRY_GET_CLASS (entry);
3308 if (class->get_text_area_size)
3309 class->get_text_area_size (entry, x, y, width, height);
3314 get_frame_size (GtkEntry *entry,
3315 gboolean relative_to_window,
3321 GtkEntryPrivate *priv = entry->priv;
3322 GtkAllocation allocation;
3323 GtkRequisition requisition;
3324 GtkWidget *widget = GTK_WIDGET (entry);
3327 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3329 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3331 gtk_widget_get_allocation (widget, &allocation);
3334 *x = relative_to_window ? allocation.x : 0;
3338 if (priv->is_cell_renderer)
3341 *y = (allocation.height - req_height) / 2;
3343 if (relative_to_window)
3348 *width = allocation.width;
3352 if (priv->is_cell_renderer)
3353 *height = allocation.height;
3355 *height = req_height;
3360 gtk_entry_size_allocate (GtkWidget *widget,
3361 GtkAllocation *allocation)
3363 GtkEntry *entry = GTK_ENTRY (widget);
3365 gtk_widget_set_allocation (widget, allocation);
3367 if (gtk_widget_get_realized (widget))
3369 GtkEntryCompletion* completion;
3371 place_windows (entry);
3372 gtk_entry_recompute (entry);
3374 completion = gtk_entry_get_completion (entry);
3375 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3376 _gtk_entry_completion_resize_popup (completion);
3381 should_prelight (GtkEntry *entry,
3382 GtkEntryIconPosition icon_pos)
3384 GtkEntryPrivate *priv = entry->priv;
3385 EntryIconInfo *icon_info = priv->icons[icon_pos];
3391 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3394 if (icon_info->pressed)
3397 gtk_widget_style_get (GTK_WIDGET (entry),
3398 "icon-prelight", &prelight,
3405 draw_icon (GtkWidget *widget,
3407 GtkEntryIconPosition icon_pos)
3409 GtkEntry *entry = GTK_ENTRY (widget);
3410 GtkEntryPrivate *priv = entry->priv;
3411 EntryIconInfo *icon_info = priv->icons[icon_pos];
3412 gint x, y, width, height, pix_width, pix_height;
3413 GtkStyleContext *context;
3419 width = gdk_window_get_width (icon_info->window);
3420 height = gdk_window_get_height (icon_info->window);
3422 /* size_allocate hasn't been called yet. These are the default values.
3424 if (width == 1 || height == 1)
3428 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3430 context = gtk_widget_get_style_context (widget);
3431 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3432 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3433 &pix_width, &pix_height);
3434 gtk_style_context_get_padding (context, 0, &padding);
3436 x = MAX (0, padding.left);
3437 y = MAX (0, (height - pix_height) / 2);
3439 _gtk_icon_helper_draw (icon_info->icon_helper,
3443 gtk_style_context_restore (context);
3449 gtk_entry_draw_frame (GtkWidget *widget,
3450 GtkStyleContext *context,
3453 GtkEntry *entry = GTK_ENTRY (widget);
3454 GtkEntryPrivate *priv = entry->priv;
3455 gint x = 0, y = 0, width, height;
3456 gint frame_x, frame_y;
3460 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3462 cairo_translate (cr, frame_x, frame_y);
3464 /* Fix a problem with some themes which assume that entry->text_area's
3465 * width equals widget->window's width
3466 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3467 if (GTK_IS_SPIN_BUTTON (widget))
3471 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3472 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3475 width += borders.left + borders.right;
3478 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3480 x += priv->focus_width;
3481 y += priv->focus_width;
3482 width -= 2 * priv->focus_width;
3483 height -= 2 * priv->focus_width;
3486 gtk_render_background (context, cr,
3487 x, y, width, height);
3489 if (priv->has_frame)
3490 gtk_render_frame (context, cr,
3491 x, y, width, height);
3493 gtk_entry_draw_progress (widget, context, cr);
3495 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3497 x -= priv->focus_width;
3498 y -= priv->focus_width;
3499 width += 2 * priv->focus_width;
3500 height += 2 * priv->focus_width;
3502 gtk_render_focus (context, cr,
3503 0, 0, width, height);
3510 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3511 GtkStyleContext *context)
3513 GtkEntryPrivate *private = entry->priv;
3515 gtk_style_context_save (context);
3516 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3517 if (private->progress_pulse_mode)
3518 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3522 get_progress_area (GtkWidget *widget,
3528 GtkEntry *entry = GTK_ENTRY (widget);
3529 GtkEntryPrivate *private = entry->priv;
3530 GtkStyleContext *context;
3531 GtkBorder margin, border, entry_borders;
3532 gint frame_width, text_area_width, text_area_height;
3534 context = gtk_widget_get_style_context (widget);
3535 _gtk_entry_get_borders (entry, &entry_borders);
3536 get_text_area_size (entry,
3538 &text_area_width, &text_area_height);
3539 get_frame_size (entry, FALSE,
3541 &frame_width, NULL);
3545 *width = text_area_width + entry_borders.left + entry_borders.right;
3546 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3548 /* if the text area got resized by a subclass, subtract the left/right
3549 * border width, so that the progress bar won't extend over the resized
3552 if (frame_width > *width)
3554 gtk_style_context_get_border (context, 0, &border);
3555 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3557 *x = (frame_width - *width) + border.left;
3558 *width -= border.left;
3562 *width -= border.right;
3566 gtk_entry_prepare_context_for_progress (entry, context);
3567 gtk_style_context_get_margin (context, 0, &margin);
3569 gtk_style_context_restore (context);
3573 *width -= margin.left + margin.right;
3574 *height -= margin.top + margin.bottom;
3576 if (private->progress_pulse_mode)
3578 gdouble value = private->progress_pulse_current;
3580 *x += (gint) floor(value * (*width));
3581 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3583 else if (private->progress_fraction > 0)
3585 gdouble value = private->progress_fraction;
3587 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3591 bar_width = floor(value * (*width) + 0.5);
3592 *x += *width - bar_width;
3597 *width = (gint) floor(value * (*width) + 0.5);
3608 gtk_entry_draw_progress (GtkWidget *widget,
3609 GtkStyleContext *context,
3612 GtkEntry *entry = GTK_ENTRY (widget);
3613 gint x, y, width, height;
3615 get_progress_area (widget, &x, &y, &width, &height);
3617 if ((width <= 0) || (height <= 0))
3620 gtk_entry_prepare_context_for_progress (entry, context);
3621 gtk_render_activity (context, cr,
3622 x, y, width, height);
3624 gtk_style_context_restore (context);
3628 gtk_entry_draw (GtkWidget *widget,
3631 GtkEntry *entry = GTK_ENTRY (widget);
3632 GtkStyleContext *context;
3633 GtkEntryPrivate *priv = entry->priv;
3636 context = gtk_widget_get_style_context (widget);
3638 /* Draw entry_bg, shadow, progress and focus */
3639 gtk_entry_draw_frame (widget, context, cr);
3641 /* Draw text and cursor */
3644 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3646 if (priv->dnd_position != -1)
3647 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3649 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3651 /* When no text is being displayed at all, don't show the cursor */
3652 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3653 gtk_widget_has_focus (widget) &&
3654 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3655 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3660 for (i = 0; i < MAX_ICONS; i++)
3662 EntryIconInfo *icon_info = priv->icons[i];
3664 if (icon_info != NULL)
3665 draw_icon (widget, cr, i);
3672 gtk_entry_enter_notify (GtkWidget *widget,
3673 GdkEventCrossing *event)
3675 GtkEntry *entry = GTK_ENTRY (widget);
3676 GtkEntryPrivate *priv = entry->priv;
3679 for (i = 0; i < MAX_ICONS; i++)
3681 EntryIconInfo *icon_info = priv->icons[i];
3683 if (icon_info != NULL && event->window == icon_info->window)
3685 if (should_prelight (entry, i))
3687 icon_info->prelight = TRUE;
3688 gtk_widget_queue_draw (widget);
3699 gtk_entry_leave_notify (GtkWidget *widget,
3700 GdkEventCrossing *event)
3702 GtkEntry *entry = GTK_ENTRY (widget);
3703 GtkEntryPrivate *priv = entry->priv;
3706 for (i = 0; i < MAX_ICONS; i++)
3708 EntryIconInfo *icon_info = priv->icons[i];
3710 if (icon_info != NULL && event->window == icon_info->window)
3712 /* a grab means that we may never see the button release */
3713 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3714 icon_info->pressed = FALSE;
3716 if (should_prelight (entry, i))
3718 icon_info->prelight = FALSE;
3719 gtk_widget_queue_draw (widget);
3730 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3734 gint start_char, end_char;
3736 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3738 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3739 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3740 const char *text = pango_layout_get_text (layout);
3741 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3742 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3743 gint real_n_ranges, i;
3745 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3751 for (i = 0; i < real_n_ranges; ++i)
3753 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3754 r[2 * i] = r[2 * i] / PANGO_SCALE;
3759 *n_ranges = real_n_ranges;
3771 in_selection (GtkEntry *entry,
3776 gint retval = FALSE;
3778 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3780 for (i = 0; i < n_ranges; ++i)
3782 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3794 gtk_entry_button_press (GtkWidget *widget,
3795 GdkEventButton *event)
3797 GtkEntry *entry = GTK_ENTRY (widget);
3798 GtkEditable *editable = GTK_EDITABLE (widget);
3799 GtkEntryPrivate *priv = entry->priv;
3800 EntryIconInfo *icon_info = NULL;
3802 gint sel_start, sel_end;
3805 for (i = 0; i < MAX_ICONS; i++)
3807 icon_info = priv->icons[i];
3809 if (!icon_info || icon_info->insensitive)
3812 if (event->window == icon_info->window)
3814 if (should_prelight (entry, i))
3816 icon_info->prelight = FALSE;
3817 gtk_widget_queue_draw (widget);
3820 priv->start_x = event->x;
3821 priv->start_y = event->y;
3822 icon_info->pressed = TRUE;
3824 if (!icon_info->nonactivatable)
3825 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3831 if (event->window != priv->text_area ||
3832 (priv->button && event->button != priv->button))
3835 gtk_entry_reset_blink_time (entry);
3837 priv->button = event->button;
3838 priv->device = gdk_event_get_device ((GdkEvent *) event);
3840 if (!gtk_widget_has_focus (widget))
3842 priv->in_click = TRUE;
3843 gtk_widget_grab_focus (widget);
3844 priv->in_click = FALSE;
3847 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3849 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3851 gtk_entry_do_popup (entry, event);
3852 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3853 priv->device = NULL;
3857 else if (event->button == GDK_BUTTON_PRIMARY)
3859 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3861 priv->select_words = FALSE;
3862 priv->select_lines = FALSE;
3865 gtk_widget_get_modifier_mask (widget,
3866 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3868 _gtk_entry_reset_im_context (entry);
3870 if (!have_selection) /* select from the current position to the clicked position */
3871 sel_start = sel_end = priv->current_pos;
3873 if (tmp_pos > sel_start && tmp_pos < sel_end)
3875 /* Truncate current selection, but keep it as big as possible */
3876 if (tmp_pos - sel_start > sel_end - tmp_pos)
3877 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3879 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3883 gboolean extend_to_left;
3886 /* Figure out what click selects and extend current selection */
3887 switch (event->type)
3889 case GDK_BUTTON_PRESS:
3890 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3893 case GDK_2BUTTON_PRESS:
3894 priv->select_words = TRUE;
3895 gtk_entry_select_word (entry);
3898 case GDK_3BUTTON_PRESS:
3899 priv->select_lines = TRUE;
3900 gtk_entry_select_line (entry);
3907 start = MIN (priv->current_pos, priv->selection_bound);
3908 start = MIN (sel_start, start);
3910 end = MAX (priv->current_pos, priv->selection_bound);
3911 end = MAX (sel_end, end);
3913 if (tmp_pos == sel_start || tmp_pos == sel_end)
3914 extend_to_left = (tmp_pos == start);
3916 extend_to_left = (end == sel_end);
3919 gtk_entry_set_positions (entry, start, end);
3921 gtk_entry_set_positions (entry, end, start);
3924 else /* no shift key */
3925 switch (event->type)
3927 case GDK_BUTTON_PRESS:
3928 if (in_selection (entry, event->x + priv->scroll_offset))
3930 /* Click inside the selection - we'll either start a drag, or
3931 * clear the selection
3933 priv->in_drag = TRUE;
3934 priv->drag_start_x = event->x + priv->scroll_offset;
3935 priv->drag_start_y = event->y;
3938 gtk_editable_set_position (editable, tmp_pos);
3941 case GDK_2BUTTON_PRESS:
3942 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3943 * receiving a GDK_2BUTTON_PRESS so we need to reset
3944 * priv->in_drag which may have been set above
3946 priv->in_drag = FALSE;
3947 priv->select_words = TRUE;
3948 gtk_entry_select_word (entry);
3951 case GDK_3BUTTON_PRESS:
3952 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3953 * receiving a GDK_3BUTTON_PRESS so we need to reset
3954 * priv->in_drag which may have been set above
3956 priv->in_drag = FALSE;
3957 priv->select_lines = TRUE;
3958 gtk_entry_select_line (entry);
3967 else if (event->button == GDK_BUTTON_MIDDLE && event->type == GDK_BUTTON_PRESS)
3971 priv->insert_pos = tmp_pos;
3972 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3977 gtk_widget_error_bell (widget);
3985 gtk_entry_button_release (GtkWidget *widget,
3986 GdkEventButton *event)
3988 GtkEntry *entry = GTK_ENTRY (widget);
3989 GtkEntryPrivate *priv = entry->priv;
3990 EntryIconInfo *icon_info = NULL;
3993 for (i = 0; i < MAX_ICONS; i++)
3995 icon_info = priv->icons[i];
3997 if (!icon_info || icon_info->insensitive)
4000 if (event->window == icon_info->window)
4002 icon_info->pressed = FALSE;
4004 if (should_prelight (entry, i) &&
4005 event->x >= 0 && event->y >= 0 &&
4006 event->x < gdk_window_get_width (icon_info->window) &&
4007 event->y < gdk_window_get_height (icon_info->window))
4009 icon_info->prelight = TRUE;
4010 gtk_widget_queue_draw (widget);
4013 if (!icon_info->nonactivatable)
4014 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4020 if (event->window != priv->text_area || priv->button != event->button)
4025 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4027 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4033 priv->device = NULL;
4035 gtk_entry_update_primary_selection (entry);
4041 _gtk_entry_get_selected_text (GtkEntry *entry)
4043 GtkEditable *editable = GTK_EDITABLE (entry);
4044 gint start_text, end_text;
4047 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4048 text = gtk_editable_get_chars (editable, start_text, end_text);
4054 gtk_entry_motion_notify (GtkWidget *widget,
4055 GdkEventMotion *event)
4057 GtkEntry *entry = GTK_ENTRY (widget);
4058 GtkEntryPrivate *priv = entry->priv;
4059 EntryIconInfo *icon_info = NULL;
4063 for (i = 0; i < MAX_ICONS; i++)
4065 icon_info = priv->icons[i];
4067 if (!icon_info || icon_info->insensitive)
4070 if (event->window == icon_info->window)
4072 if (icon_info->pressed &&
4073 icon_info->target_list != NULL &&
4074 gtk_drag_check_threshold (widget,
4080 icon_info->in_drag = TRUE;
4081 icon_info->pressed = FALSE;
4082 gtk_drag_begin (widget,
4083 icon_info->target_list,
4093 if (priv->mouse_cursor_obscured)
4097 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4098 gdk_window_set_cursor (priv->text_area, cursor);
4099 g_object_unref (cursor);
4100 priv->mouse_cursor_obscured = FALSE;
4103 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4106 if (priv->select_lines)
4109 gdk_event_request_motions (event);
4113 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4114 gtk_drag_check_threshold (widget,
4115 priv->drag_start_x, priv->drag_start_y,
4116 event->x + priv->scroll_offset, event->y))
4118 GdkDragContext *context;
4119 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4120 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4122 cairo_surface_t *surface;
4124 gtk_target_list_add_text_targets (target_list, 0);
4126 text = _gtk_entry_get_selected_text (entry);
4127 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4129 context = gtk_drag_begin (widget, target_list, actions,
4130 priv->button, (GdkEvent *)event);
4133 gtk_drag_set_icon_surface (context, surface);
4135 gtk_drag_set_icon_default (context);
4138 cairo_surface_destroy (surface);
4141 priv->in_drag = FALSE;
4143 priv->device = NULL;
4145 gtk_target_list_unref (target_list);
4152 else if (event->y >= gdk_window_get_height (priv->text_area))
4153 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4155 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4157 if (priv->select_words)
4160 gint old_min, old_max;
4163 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4164 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4166 pos = priv->current_pos;
4167 bound = priv->selection_bound;
4169 old_min = MIN(priv->current_pos, priv->selection_bound);
4170 old_max = MAX(priv->current_pos, priv->selection_bound);
4177 else if (old_max < max)
4182 else if (pos == old_min)
4184 if (priv->current_pos != min)
4189 if (priv->current_pos != max)
4193 gtk_entry_set_positions (entry, pos, bound);
4196 gtk_entry_set_positions (entry, tmp_pos, -1);
4203 set_invisible_cursor (GdkWindow *window)
4205 GdkDisplay *display;
4208 display = gdk_window_get_display (window);
4209 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4211 gdk_window_set_cursor (window, cursor);
4213 g_object_unref (cursor);
4217 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4219 GtkEntryPrivate *priv = entry->priv;
4221 if (priv->mouse_cursor_obscured)
4224 set_invisible_cursor (priv->text_area);
4226 priv->mouse_cursor_obscured = TRUE;
4230 gtk_entry_key_press (GtkWidget *widget,
4233 GtkEntry *entry = GTK_ENTRY (widget);
4234 GtkEntryPrivate *priv = entry->priv;
4236 gtk_entry_reset_blink_time (entry);
4237 gtk_entry_pend_cursor_blink (entry);
4241 if (gtk_im_context_filter_keypress (priv->im_context, event))
4243 gtk_entry_obscure_mouse_cursor (entry);
4244 priv->need_im_reset = TRUE;
4249 if (event->keyval == GDK_KEY_Return ||
4250 event->keyval == GDK_KEY_KP_Enter ||
4251 event->keyval == GDK_KEY_ISO_Enter ||
4252 event->keyval == GDK_KEY_Escape)
4254 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4256 if (completion && completion->priv->completion_timeout)
4258 g_source_remove (completion->priv->completion_timeout);
4259 completion->priv->completion_timeout = 0;
4262 _gtk_entry_reset_im_context (entry);
4265 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4266 /* Activate key bindings
4270 if (!priv->editable && event->length)
4271 gtk_widget_error_bell (widget);
4277 gtk_entry_key_release (GtkWidget *widget,
4280 GtkEntry *entry = GTK_ENTRY (widget);
4281 GtkEntryPrivate *priv = entry->priv;
4285 if (gtk_im_context_filter_keypress (priv->im_context, event))
4287 priv->need_im_reset = TRUE;
4292 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4296 gtk_entry_focus_in (GtkWidget *widget,
4297 GdkEventFocus *event)
4299 GtkEntry *entry = GTK_ENTRY (widget);
4300 GtkEntryPrivate *priv = entry->priv;
4303 gtk_widget_queue_draw (widget);
4305 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4309 priv->need_im_reset = TRUE;
4310 gtk_im_context_focus_in (priv->im_context);
4311 keymap_state_changed (keymap, entry);
4312 g_signal_connect (keymap, "state-changed",
4313 G_CALLBACK (keymap_state_changed), entry);
4316 g_signal_connect (keymap, "direction-changed",
4317 G_CALLBACK (keymap_direction_changed), entry);
4319 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4320 priv->placeholder_text != NULL)
4322 gtk_entry_recompute (entry);
4326 gtk_entry_reset_blink_time (entry);
4327 gtk_entry_check_cursor_blink (entry);
4334 gtk_entry_focus_out (GtkWidget *widget,
4335 GdkEventFocus *event)
4337 GtkEntry *entry = GTK_ENTRY (widget);
4338 GtkEntryPrivate *priv = entry->priv;
4339 GtkEntryCompletion *completion;
4342 gtk_widget_queue_draw (widget);
4344 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4348 priv->need_im_reset = TRUE;
4349 gtk_im_context_focus_out (priv->im_context);
4350 remove_capslock_feedback (entry);
4353 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4354 priv->placeholder_text != NULL)
4356 gtk_entry_recompute (entry);
4360 gtk_entry_check_cursor_blink (entry);
4363 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4364 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4366 completion = gtk_entry_get_completion (entry);
4368 _gtk_entry_completion_popdown (completion);
4374 gtk_entry_grab_focus (GtkWidget *widget)
4376 GtkEntry *entry = GTK_ENTRY (widget);
4377 GtkEntryPrivate *priv = entry->priv;
4378 gboolean select_on_focus;
4380 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4382 if (priv->editable && !priv->in_click)
4384 g_object_get (gtk_widget_get_settings (widget),
4385 "gtk-entry-select-on-focus",
4389 if (select_on_focus)
4390 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4395 gtk_entry_direction_changed (GtkWidget *widget,
4396 GtkTextDirection previous_dir)
4398 GtkEntry *entry = GTK_ENTRY (widget);
4400 gtk_entry_recompute (entry);
4402 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4406 gtk_entry_state_flags_changed (GtkWidget *widget,
4407 GtkStateFlags previous_state)
4409 GtkEntry *entry = GTK_ENTRY (widget);
4410 GtkEntryPrivate *priv = entry->priv;
4413 if (gtk_widget_get_realized (widget))
4415 if (gtk_widget_is_sensitive (widget))
4416 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4420 gdk_window_set_cursor (priv->text_area, cursor);
4423 g_object_unref (cursor);
4425 priv->mouse_cursor_obscured = FALSE;
4427 update_cursors (widget);
4430 if (!gtk_widget_is_sensitive (widget))
4432 /* Clear any selection */
4433 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4436 gtk_entry_update_cached_style_values (entry);
4440 gtk_entry_screen_changed (GtkWidget *widget,
4441 GdkScreen *old_screen)
4443 gtk_entry_recompute (GTK_ENTRY (widget));
4446 /* GtkEditable method implementations
4449 gtk_entry_insert_text (GtkEditable *editable,
4450 const gchar *new_text,
4451 gint new_text_length,
4454 g_object_ref (editable);
4457 * The incoming text may a password or other secret. We make sure
4458 * not to copy it into temporary buffers.
4461 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4463 g_object_unref (editable);
4467 gtk_entry_delete_text (GtkEditable *editable,
4471 g_object_ref (editable);
4473 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4475 g_object_unref (editable);
4479 gtk_entry_get_chars (GtkEditable *editable,
4483 GtkEntry *entry = GTK_ENTRY (editable);
4486 gint start_index, end_index;
4488 text = gtk_entry_buffer_get_text (get_buffer (entry));
4489 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4492 end_pos = text_length;
4494 start_pos = MIN (text_length, start_pos);
4495 end_pos = MIN (text_length, end_pos);
4497 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4498 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4500 return g_strndup (text + start_index, end_index - start_index);
4504 gtk_entry_real_set_position (GtkEditable *editable,
4507 GtkEntry *entry = GTK_ENTRY (editable);
4508 GtkEntryPrivate *priv = entry->priv;
4512 length = gtk_entry_buffer_get_length (get_buffer (entry));
4513 if (position < 0 || position > length)
4516 if (position != priv->current_pos ||
4517 position != priv->selection_bound)
4519 _gtk_entry_reset_im_context (entry);
4520 gtk_entry_set_positions (entry, position, position);
4525 gtk_entry_get_position (GtkEditable *editable)
4527 GtkEntry *entry = GTK_ENTRY (editable);
4528 GtkEntryPrivate *priv = entry->priv;
4530 return priv->current_pos;
4534 gtk_entry_set_selection_bounds (GtkEditable *editable,
4538 GtkEntry *entry = GTK_ENTRY (editable);
4541 length = gtk_entry_buffer_get_length (get_buffer (entry));
4547 _gtk_entry_reset_im_context (entry);
4549 gtk_entry_set_positions (entry,
4551 MIN (start, length));
4553 gtk_entry_update_primary_selection (entry);
4557 gtk_entry_get_selection_bounds (GtkEditable *editable,
4561 GtkEntry *entry = GTK_ENTRY (editable);
4562 GtkEntryPrivate *priv = entry->priv;
4564 *start = priv->selection_bound;
4565 *end = priv->current_pos;
4567 return (priv->selection_bound != priv->current_pos);
4571 icon_theme_changed (GtkEntry *entry)
4573 GtkEntryPrivate *priv = entry->priv;
4576 for (i = 0; i < MAX_ICONS; i++)
4578 EntryIconInfo *icon_info = priv->icons[i];
4579 if (icon_info != NULL)
4580 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4583 gtk_widget_queue_draw (GTK_WIDGET (entry));
4587 gtk_entry_update_cached_style_values (GtkEntry *entry)
4589 GtkEntryPrivate *priv = entry->priv;
4591 gboolean interior_focus;
4593 gtk_widget_style_get (GTK_WIDGET (entry),
4594 "focus-line-width", &focus_width,
4595 "interior-focus", &interior_focus,
4597 priv->focus_width = focus_width;
4598 priv->interior_focus = interior_focus;
4600 if (!priv->invisible_char_set)
4602 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4604 if (priv->invisible_char != ch)
4606 priv->invisible_char = ch;
4607 g_object_notify (G_OBJECT (entry), "invisible-char");
4613 gtk_entry_style_updated (GtkWidget *widget)
4615 GtkEntry *entry = GTK_ENTRY (widget);
4617 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4619 gtk_entry_update_cached_style_values (entry);
4621 gtk_entry_recompute (entry);
4623 icon_theme_changed (entry);
4626 /* GtkCellEditable method implementations
4629 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4631 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4632 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4636 gtk_cell_editable_key_press_event (GtkEntry *entry,
4637 GdkEventKey *key_event,
4640 GtkEntryPrivate *priv = entry->priv;
4642 if (key_event->keyval == GDK_KEY_Escape)
4644 priv->editing_canceled = TRUE;
4645 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4646 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4651 /* override focus */
4652 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4654 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4655 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4664 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4667 GtkEntry *entry = GTK_ENTRY (cell_editable);
4668 GtkEntryPrivate *priv = entry->priv;
4670 priv->is_cell_renderer = TRUE;
4672 g_signal_connect (cell_editable, "activate",
4673 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4674 g_signal_connect (cell_editable, "key-press-event",
4675 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4679 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4681 if (password_hint->source_id)
4682 g_source_remove (password_hint->source_id);
4684 g_slice_free (GtkEntryPasswordHint, password_hint);
4689 gtk_entry_remove_password_hint (gpointer data)
4691 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4692 password_hint->position = -1;
4694 /* Force the string to be redrawn, but now without a visible character */
4695 gtk_entry_recompute (GTK_ENTRY (data));
4699 /* Default signal handlers
4702 gtk_entry_real_insert_text (GtkEditable *editable,
4703 const gchar *new_text,
4704 gint new_text_length,
4710 n_chars = g_utf8_strlen (new_text, new_text_length);
4713 * The actual insertion into the buffer. This will end up firing the
4714 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4715 * buffer_notify_text(), buffer_notify_length()
4717 begin_change (GTK_ENTRY (editable));
4719 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4721 end_change (GTK_ENTRY (editable));
4723 if (n_inserted != n_chars)
4724 gtk_widget_error_bell (GTK_WIDGET (editable));
4726 *position += n_inserted;
4730 gtk_entry_real_delete_text (GtkEditable *editable,
4735 * The actual deletion from the buffer. This will end up firing the
4736 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4737 * buffer_notify_text(), buffer_notify_length()
4740 begin_change (GTK_ENTRY (editable));
4742 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4744 end_change (GTK_ENTRY (editable));
4747 /* GtkEntryBuffer signal handlers
4750 buffer_inserted_text (GtkEntryBuffer *buffer,
4756 GtkEntryPrivate *priv = entry->priv;
4757 guint password_hint_timeout;
4759 gint selection_bound;
4761 current_pos = priv->current_pos;
4762 if (current_pos > position)
4763 current_pos += n_chars;
4765 selection_bound = priv->selection_bound;
4766 if (selection_bound > position)
4767 selection_bound += n_chars;
4769 gtk_entry_set_positions (entry, current_pos, selection_bound);
4771 /* Calculate the password hint if it needs to be displayed. */
4772 if (n_chars == 1 && !priv->visible)
4774 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4775 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4778 if (password_hint_timeout > 0)
4780 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4781 quark_password_hint);
4784 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4785 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4786 (GDestroyNotify)gtk_entry_password_hint_free);
4789 password_hint->position = position;
4790 if (password_hint->source_id)
4791 g_source_remove (password_hint->source_id);
4792 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4793 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4799 buffer_deleted_text (GtkEntryBuffer *buffer,
4804 GtkEntryPrivate *priv = entry->priv;
4805 guint end_pos = position + n_chars;
4806 gint selection_bound;
4809 current_pos = priv->current_pos;
4810 if (current_pos > position)
4811 current_pos -= MIN (current_pos, end_pos) - position;
4813 selection_bound = priv->selection_bound;
4814 if (selection_bound > position)
4815 selection_bound -= MIN (selection_bound, end_pos) - position;
4817 gtk_entry_set_positions (entry, current_pos, selection_bound);
4819 /* We might have deleted the selection */
4820 gtk_entry_update_primary_selection (entry);
4822 /* Disable the password hint if one exists. */
4825 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4826 quark_password_hint);
4829 if (password_hint->source_id)
4830 g_source_remove (password_hint->source_id);
4831 password_hint->source_id = 0;
4832 password_hint->position = -1;
4838 buffer_notify_text (GtkEntryBuffer *buffer,
4842 gtk_entry_recompute (entry);
4843 emit_changed (entry);
4844 g_object_notify (G_OBJECT (entry), "text");
4848 buffer_notify_length (GtkEntryBuffer *buffer,
4852 g_object_notify (G_OBJECT (entry), "text-length");
4856 buffer_notify_max_length (GtkEntryBuffer *buffer,
4860 g_object_notify (G_OBJECT (entry), "max-length");
4864 buffer_connect_signals (GtkEntry *entry)
4866 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4867 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4868 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4869 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4870 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4874 buffer_disconnect_signals (GtkEntry *entry)
4876 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4877 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4878 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4879 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4880 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4883 /* Compute the X position for an offset that corresponds to the "more important
4884 * cursor position for that offset. We use this when trying to guess to which
4885 * end of the selection we should go to when the user hits the left or
4889 get_better_cursor_x (GtkEntry *entry,
4892 GtkEntryPrivate *priv = entry->priv;
4893 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4894 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4895 gboolean split_cursor;
4897 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4898 const gchar *text = pango_layout_get_text (layout);
4899 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4901 PangoRectangle strong_pos, weak_pos;
4903 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4904 "gtk-split-cursor", &split_cursor,
4907 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4910 return strong_pos.x / PANGO_SCALE;
4912 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4916 gtk_entry_move_cursor (GtkEntry *entry,
4917 GtkMovementStep step,
4919 gboolean extend_selection)
4921 GtkEntryPrivate *priv = entry->priv;
4922 gint new_pos = priv->current_pos;
4924 _gtk_entry_reset_im_context (entry);
4926 if (priv->current_pos != priv->selection_bound && !extend_selection)
4928 /* If we have a current selection and aren't extending it, move to the
4929 * start/or end of the selection as appropriate
4933 case GTK_MOVEMENT_VISUAL_POSITIONS:
4935 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4936 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4939 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4941 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4944 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4945 case GTK_MOVEMENT_WORDS:
4947 new_pos = MIN (priv->current_pos, priv->selection_bound);
4949 new_pos = MAX (priv->current_pos, priv->selection_bound);
4951 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4952 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4953 case GTK_MOVEMENT_BUFFER_ENDS:
4954 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4956 case GTK_MOVEMENT_DISPLAY_LINES:
4957 case GTK_MOVEMENT_PARAGRAPHS:
4958 case GTK_MOVEMENT_PAGES:
4959 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4967 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4968 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4970 case GTK_MOVEMENT_VISUAL_POSITIONS:
4971 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4972 if (priv->current_pos == new_pos)
4974 if (!extend_selection)
4976 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4978 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4980 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4983 gtk_widget_child_focus (toplevel,
4985 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4990 gtk_widget_error_bell (GTK_WIDGET (entry));
4994 case GTK_MOVEMENT_WORDS:
4997 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5002 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5005 if (priv->current_pos == new_pos)
5006 gtk_widget_error_bell (GTK_WIDGET (entry));
5008 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5009 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5010 case GTK_MOVEMENT_BUFFER_ENDS:
5011 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5012 if (priv->current_pos == new_pos)
5013 gtk_widget_error_bell (GTK_WIDGET (entry));
5015 case GTK_MOVEMENT_DISPLAY_LINES:
5016 case GTK_MOVEMENT_PARAGRAPHS:
5017 case GTK_MOVEMENT_PAGES:
5018 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5023 if (extend_selection)
5024 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5026 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5028 gtk_entry_pend_cursor_blink (entry);
5032 gtk_entry_insert_at_cursor (GtkEntry *entry,
5035 GtkEntryPrivate *priv = entry->priv;
5036 GtkEditable *editable = GTK_EDITABLE (entry);
5037 gint pos = priv->current_pos;
5041 _gtk_entry_reset_im_context (entry);
5043 gtk_editable_insert_text (editable, str, -1, &pos);
5044 gtk_editable_set_position (editable, pos);
5049 gtk_entry_delete_from_cursor (GtkEntry *entry,
5053 GtkEntryPrivate *priv = entry->priv;
5054 GtkEditable *editable = GTK_EDITABLE (entry);
5055 gint start_pos = priv->current_pos;
5056 gint end_pos = priv->current_pos;
5057 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5059 _gtk_entry_reset_im_context (entry);
5061 if (!priv->editable)
5063 gtk_widget_error_bell (GTK_WIDGET (entry));
5067 if (priv->selection_bound != priv->current_pos)
5069 gtk_editable_delete_selection (editable);
5075 case GTK_DELETE_CHARS:
5076 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5077 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5079 case GTK_DELETE_WORDS:
5082 /* Move to end of current word, or if not on a word, end of previous word */
5083 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5084 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5088 /* Move to beginning of current word, or if not on a word, begining of next word */
5089 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5090 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5094 case GTK_DELETE_WORD_ENDS:
5097 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5102 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5105 gtk_editable_delete_text (editable, start_pos, end_pos);
5107 case GTK_DELETE_DISPLAY_LINE_ENDS:
5108 case GTK_DELETE_PARAGRAPH_ENDS:
5110 gtk_editable_delete_text (editable, 0, priv->current_pos);
5112 gtk_editable_delete_text (editable, priv->current_pos, -1);
5114 case GTK_DELETE_DISPLAY_LINES:
5115 case GTK_DELETE_PARAGRAPHS:
5116 gtk_editable_delete_text (editable, 0, -1);
5118 case GTK_DELETE_WHITESPACE:
5119 gtk_entry_delete_whitespace (entry);
5123 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5124 gtk_widget_error_bell (GTK_WIDGET (entry));
5126 gtk_entry_pend_cursor_blink (entry);
5130 gtk_entry_backspace (GtkEntry *entry)
5132 GtkEntryPrivate *priv = entry->priv;
5133 GtkEditable *editable = GTK_EDITABLE (entry);
5136 _gtk_entry_reset_im_context (entry);
5138 if (!priv->editable)
5140 gtk_widget_error_bell (GTK_WIDGET (entry));
5144 if (priv->selection_bound != priv->current_pos)
5146 gtk_editable_delete_selection (editable);
5150 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5152 if (prev_pos < priv->current_pos)
5154 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5155 PangoLogAttr *log_attrs;
5158 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5160 /* Deleting parts of characters */
5161 if (log_attrs[priv->current_pos].backspace_deletes_character)
5163 gchar *cluster_text;
5164 gchar *normalized_text;
5167 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5169 normalized_text = g_utf8_normalize (cluster_text,
5170 strlen (cluster_text),
5172 len = g_utf8_strlen (normalized_text, -1);
5174 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5177 gint pos = priv->current_pos;
5179 gtk_editable_insert_text (editable, normalized_text,
5180 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5182 gtk_editable_set_position (editable, pos);
5185 g_free (normalized_text);
5186 g_free (cluster_text);
5190 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5197 gtk_widget_error_bell (GTK_WIDGET (entry));
5200 gtk_entry_pend_cursor_blink (entry);
5204 gtk_entry_copy_clipboard (GtkEntry *entry)
5206 GtkEntryPrivate *priv = entry->priv;
5207 GtkEditable *editable = GTK_EDITABLE (entry);
5211 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5215 gtk_widget_error_bell (GTK_WIDGET (entry));
5219 str = gtk_entry_get_display_text (entry, start, end);
5220 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5221 GDK_SELECTION_CLIPBOARD),
5228 gtk_entry_cut_clipboard (GtkEntry *entry)
5230 GtkEntryPrivate *priv = entry->priv;
5231 GtkEditable *editable = GTK_EDITABLE (entry);
5236 gtk_widget_error_bell (GTK_WIDGET (entry));
5240 gtk_entry_copy_clipboard (entry);
5244 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5245 gtk_editable_delete_text (editable, start, end);
5249 gtk_widget_error_bell (GTK_WIDGET (entry));
5254 gtk_entry_paste_clipboard (GtkEntry *entry)
5256 GtkEntryPrivate *priv = entry->priv;
5259 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5261 gtk_widget_error_bell (GTK_WIDGET (entry));
5265 gtk_entry_delete_cb (GtkEntry *entry)
5267 GtkEntryPrivate *priv = entry->priv;
5268 GtkEditable *editable = GTK_EDITABLE (entry);
5273 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5274 gtk_editable_delete_text (editable, start, end);
5279 gtk_entry_toggle_overwrite (GtkEntry *entry)
5281 GtkEntryPrivate *priv = entry->priv;
5283 priv->overwrite_mode = !priv->overwrite_mode;
5284 gtk_entry_pend_cursor_blink (entry);
5285 gtk_widget_queue_draw (GTK_WIDGET (entry));
5289 gtk_entry_select_all (GtkEntry *entry)
5291 gtk_entry_select_line (entry);
5295 gtk_entry_real_activate (GtkEntry *entry)
5297 GtkEntryPrivate *priv = entry->priv;
5299 GtkWidget *default_widget, *focus_widget;
5300 GtkWidget *toplevel;
5303 widget = GTK_WIDGET (entry);
5305 if (priv->activates_default)
5307 toplevel = gtk_widget_get_toplevel (widget);
5308 if (GTK_IS_WINDOW (toplevel))
5310 window = GTK_WINDOW (toplevel);
5314 default_widget = gtk_window_get_default_widget (window);
5315 focus_widget = gtk_window_get_focus (window);
5316 if (widget != default_widget &&
5317 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5318 gtk_window_activate_default (window);
5325 keymap_direction_changed (GdkKeymap *keymap,
5328 gtk_entry_recompute (entry);
5331 /* IM Context Callbacks
5335 gtk_entry_commit_cb (GtkIMContext *context,
5339 GtkEntryPrivate *priv = entry->priv;
5342 gtk_entry_enter_text (entry, str);
5346 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5349 GtkEntryPrivate *priv = entry->priv;
5353 gchar *preedit_string;
5356 gtk_im_context_get_preedit_string (priv->im_context,
5357 &preedit_string, NULL,
5359 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5360 priv->preedit_length = strlen (preedit_string);
5361 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5362 priv->preedit_cursor = cursor_pos;
5363 g_free (preedit_string);
5365 gtk_entry_recompute (entry);
5370 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5373 GtkEntryPrivate *priv = entry->priv;
5376 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5377 text = gtk_entry_get_display_text (entry, 0, -1);
5378 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5379 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5386 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5391 GtkEntryPrivate *priv = entry->priv;
5394 gtk_editable_delete_text (GTK_EDITABLE (entry),
5395 priv->current_pos + offset,
5396 priv->current_pos + offset + n_chars);
5401 /* Internal functions
5404 /* Used for im_commit_cb and inserting Unicode chars */
5406 gtk_entry_enter_text (GtkEntry *entry,
5409 GtkEntryPrivate *priv = entry->priv;
5410 GtkEditable *editable = GTK_EDITABLE (entry);
5412 gboolean old_need_im_reset;
5414 old_need_im_reset = priv->need_im_reset;
5415 priv->need_im_reset = FALSE;
5417 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5418 gtk_editable_delete_selection (editable);
5421 if (priv->overwrite_mode)
5422 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5425 tmp_pos = priv->current_pos;
5426 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5427 gtk_editable_set_position (editable, tmp_pos);
5429 priv->need_im_reset = old_need_im_reset;
5432 /* All changes to priv->current_pos and priv->selection_bound
5433 * should go through this function.
5436 gtk_entry_set_positions (GtkEntry *entry,
5438 gint selection_bound)
5440 GtkEntryPrivate *priv = entry->priv;
5441 gboolean changed = FALSE;
5443 g_object_freeze_notify (G_OBJECT (entry));
5445 if (current_pos != -1 &&
5446 priv->current_pos != current_pos)
5448 priv->current_pos = current_pos;
5451 g_object_notify (G_OBJECT (entry), "cursor-position");
5454 if (selection_bound != -1 &&
5455 priv->selection_bound != selection_bound)
5457 priv->selection_bound = selection_bound;
5460 g_object_notify (G_OBJECT (entry), "selection-bound");
5463 g_object_thaw_notify (G_OBJECT (entry));
5467 gtk_entry_move_adjustments (entry);
5468 gtk_entry_recompute (entry);
5473 gtk_entry_reset_layout (GtkEntry *entry)
5475 GtkEntryPrivate *priv = entry->priv;
5477 if (priv->cached_layout)
5479 g_object_unref (priv->cached_layout);
5480 priv->cached_layout = NULL;
5485 update_im_cursor_location (GtkEntry *entry)
5487 GtkEntryPrivate *priv = entry->priv;
5490 gint strong_xoffset;
5491 gint area_width, area_height;
5493 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5494 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5496 strong_xoffset = strong_x - priv->scroll_offset;
5497 if (strong_xoffset < 0)
5501 else if (strong_xoffset > area_width)
5503 strong_xoffset = area_width;
5505 area.x = strong_xoffset;
5508 area.height = area_height;
5510 gtk_im_context_set_cursor_location (priv->im_context, &area);
5514 recompute_idle_func (gpointer data)
5516 GtkEntry *entry = GTK_ENTRY (data);
5517 GtkEntryPrivate *priv = entry->priv;
5519 priv->recompute_idle = 0;
5521 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5523 gtk_entry_adjust_scroll (entry);
5524 gtk_widget_queue_draw (GTK_WIDGET (entry));
5526 update_im_cursor_location (entry);
5533 gtk_entry_recompute (GtkEntry *entry)
5535 GtkEntryPrivate *priv = entry->priv;
5537 gtk_entry_reset_layout (entry);
5538 gtk_entry_check_cursor_blink (entry);
5540 if (!priv->recompute_idle)
5542 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5543 recompute_idle_func, entry, NULL);
5548 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5551 GtkWidget *widget = GTK_WIDGET (entry);
5552 GtkStyleContext *context;
5553 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5555 context = gtk_widget_get_style_context (widget);
5556 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5558 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5559 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5560 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5563 static inline gboolean
5564 show_placeholder_text (GtkEntry *entry)
5566 GtkEntryPrivate *priv = entry->priv;
5568 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5569 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5570 priv->placeholder_text != NULL)
5576 static PangoLayout *
5577 gtk_entry_create_layout (GtkEntry *entry,
5578 gboolean include_preedit)
5580 GtkEntryPrivate *priv = entry->priv;
5581 GtkWidget *widget = GTK_WIDGET (entry);
5582 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5583 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5584 gboolean placeholder_layout = show_placeholder_text (entry);
5586 gchar *preedit_string = NULL;
5587 gint preedit_length = 0;
5588 PangoAttrList *preedit_attrs = NULL;
5593 pango_layout_set_single_paragraph_mode (layout, TRUE);
5595 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5596 n_bytes = strlen (display);
5598 if (!placeholder_layout && include_preedit)
5600 gtk_im_context_get_preedit_string (priv->im_context,
5601 &preedit_string, &preedit_attrs, NULL);
5602 preedit_length = priv->preedit_length;
5604 else if (placeholder_layout)
5607 PangoAttribute *attr;
5609 gtk_entry_get_placeholder_text_color (entry, &color);
5610 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5611 attr->start_index = 0;
5612 attr->end_index = G_MAXINT;
5613 pango_attr_list_insert (tmp_attrs, attr);
5618 GString *tmp_string = g_string_new (display);
5619 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5621 g_string_insert (tmp_string, cursor_index, preedit_string);
5623 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5625 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5626 cursor_index, preedit_length);
5628 g_string_free (tmp_string, TRUE);
5632 PangoDirection pango_dir;
5634 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5635 pango_dir = pango_find_base_dir (display, n_bytes);
5637 pango_dir = PANGO_DIRECTION_NEUTRAL;
5639 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5641 if (gtk_widget_has_focus (widget))
5643 GdkDisplay *display = gtk_widget_get_display (widget);
5644 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5645 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5646 pango_dir = PANGO_DIRECTION_RTL;
5648 pango_dir = PANGO_DIRECTION_LTR;
5652 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5653 pango_dir = PANGO_DIRECTION_RTL;
5655 pango_dir = PANGO_DIRECTION_LTR;
5659 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5662 priv->resolved_dir = pango_dir;
5664 pango_layout_set_text (layout, display, n_bytes);
5667 pango_layout_set_attributes (layout, tmp_attrs);
5669 g_free (preedit_string);
5673 pango_attr_list_unref (preedit_attrs);
5675 pango_attr_list_unref (tmp_attrs);
5680 static PangoLayout *
5681 gtk_entry_ensure_layout (GtkEntry *entry,
5682 gboolean include_preedit)
5684 GtkEntryPrivate *priv = entry->priv;
5686 if (priv->preedit_length > 0 &&
5687 !include_preedit != !priv->cache_includes_preedit)
5688 gtk_entry_reset_layout (entry);
5690 if (!priv->cached_layout)
5692 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5693 priv->cache_includes_preedit = include_preedit;
5696 return priv->cached_layout;
5700 get_layout_position (GtkEntry *entry,
5704 GtkEntryPrivate *priv = entry->priv;
5705 PangoLayout *layout;
5706 PangoRectangle logical_rect;
5707 gint area_width, area_height;
5709 PangoLayoutLine *line;
5711 layout = gtk_entry_ensure_layout (entry, TRUE);
5713 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5714 area_height = PANGO_SCALE * area_height;
5716 line = pango_layout_get_lines_readonly (layout)->data;
5717 pango_layout_line_get_extents (line, NULL, &logical_rect);
5719 /* Align primarily for locale's ascent/descent */
5720 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5721 priv->ascent + logical_rect.y);
5723 /* Now see if we need to adjust to fit in actual drawn string */
5724 if (logical_rect.height > area_height)
5725 y_pos = (area_height - logical_rect.height) / 2;
5728 else if (y_pos + logical_rect.height > area_height)
5729 y_pos = area_height - logical_rect.height;
5731 y_pos = y_pos / PANGO_SCALE;
5734 *x = - priv->scroll_offset;
5741 draw_text_with_color (GtkEntry *entry,
5743 GdkRGBA *default_color)
5745 GtkEntryPrivate *priv = entry->priv;
5746 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5749 gint start_pos, end_pos;
5751 widget = GTK_WIDGET (entry);
5755 get_layout_position (entry, &x, &y);
5757 cairo_move_to (cr, x, y);
5758 gdk_cairo_set_source_rgba (cr, default_color);
5759 pango_cairo_show_layout (cr, layout);
5761 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5765 PangoRectangle logical_rect;
5766 GdkRGBA selection_color, text_color;
5767 GtkStyleContext *context;
5768 GtkStateFlags state;
5770 context = gtk_widget_get_style_context (widget);
5771 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5772 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5774 state = gtk_widget_get_state_flags (widget);
5775 state |= GTK_STATE_FLAG_SELECTED;
5777 gtk_style_context_get_background_color (context, state, &selection_color);
5778 gtk_style_context_get_color (context, state, &text_color);
5780 for (i = 0; i < n_ranges; ++i)
5781 cairo_rectangle (cr,
5782 - priv->scroll_offset + ranges[2 * i],
5785 logical_rect.height);
5789 gdk_cairo_set_source_rgba (cr, &selection_color);
5792 cairo_move_to (cr, x, y);
5793 gdk_cairo_set_source_rgba (cr, &text_color);
5794 pango_cairo_show_layout (cr, layout);
5802 gtk_entry_draw_text (GtkEntry *entry,
5805 GtkEntryPrivate *priv = entry->priv;
5806 GtkWidget *widget = GTK_WIDGET (entry);
5807 GtkStateFlags state = 0;
5808 GdkRGBA text_color, bar_text_color;
5809 GtkStyleContext *context;
5811 gint progress_x, progress_y, progress_width, progress_height;
5812 gint clip_width, clip_height;
5814 /* Nothing to display at all */
5815 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5818 state = gtk_widget_get_state_flags (widget);
5819 context = gtk_widget_get_style_context (widget);
5821 gtk_style_context_get_color (context, state, &text_color);
5823 /* Get foreground color for progressbars */
5824 gtk_entry_prepare_context_for_progress (entry, context);
5825 gtk_style_context_get_color (context, state, &bar_text_color);
5826 gtk_style_context_restore (context);
5828 get_progress_area (widget,
5829 &progress_x, &progress_y,
5830 &progress_width, &progress_height);
5834 clip_width = gdk_window_get_width (priv->text_area);
5835 clip_height = gdk_window_get_height (priv->text_area);
5836 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5839 /* If the color is the same, or the progress area has a zero
5840 * size, then we only need to draw once. */
5841 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5842 ((progress_width == 0) || (progress_height == 0)))
5844 draw_text_with_color (entry, cr, &text_color);
5848 int frame_x, frame_y, area_x, area_y;
5850 width = gdk_window_get_width (priv->text_area);
5851 height = gdk_window_get_height (priv->text_area);
5855 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5856 cairo_rectangle (cr, 0, 0, width, height);
5858 /* progres area is frame-relative, we need it text-area window
5860 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5861 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5862 progress_x += frame_x - area_x;
5863 progress_y += frame_y - area_y;
5865 cairo_rectangle (cr, progress_x, progress_y,
5866 progress_width, progress_height);
5868 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5870 draw_text_with_color (entry, cr, &text_color);
5875 cairo_rectangle (cr, progress_x, progress_y,
5876 progress_width, progress_height);
5879 draw_text_with_color (entry, cr, &bar_text_color);
5888 gtk_entry_draw_cursor (GtkEntry *entry,
5892 GtkEntryPrivate *priv = entry->priv;
5893 GtkWidget *widget = GTK_WIDGET (entry);
5894 GtkStyleContext *context;
5895 PangoRectangle cursor_rect;
5898 gboolean block_at_line_end;
5899 PangoLayout *layout;
5903 context = gtk_widget_get_style_context (widget);
5905 layout = gtk_entry_ensure_layout (entry, TRUE);
5906 text = pango_layout_get_text (layout);
5907 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5908 get_layout_position (entry, &x, &y);
5910 if (!priv->overwrite_mode)
5913 block = _gtk_text_util_get_block_cursor_location (layout,
5914 cursor_index, &cursor_rect, &block_at_line_end);
5918 gtk_render_insertion_cursor (context, cr,
5920 layout, cursor_index, priv->resolved_dir);
5922 else /* overwrite_mode */
5924 GdkRGBA cursor_color;
5929 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5930 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5931 rect.width = PANGO_PIXELS (cursor_rect.width);
5932 rect.height = PANGO_PIXELS (cursor_rect.height);
5934 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5935 gdk_cairo_set_source_rgba (cr, &cursor_color);
5936 gdk_cairo_rectangle (cr, &rect);
5939 if (!block_at_line_end)
5941 GtkStateFlags state;
5944 state = gtk_widget_get_state_flags (widget);
5945 gtk_style_context_get_background_color (context, state, &color);
5947 gdk_cairo_rectangle (cr, &rect);
5949 cairo_move_to (cr, x, y);
5950 gdk_cairo_set_source_rgba (cr, &color);
5951 pango_cairo_show_layout (cr, layout);
5959 _gtk_entry_reset_im_context (GtkEntry *entry)
5961 GtkEntryPrivate *priv = entry->priv;
5963 if (priv->need_im_reset)
5965 priv->need_im_reset = FALSE;
5966 gtk_im_context_reset (priv->im_context);
5971 * gtk_entry_reset_im_context:
5972 * @entry: a #GtkEntry
5974 * Reset the input method context of the entry if needed.
5976 * This can be necessary in the case where modifying the buffer
5977 * would confuse on-going input method behavior.
5982 gtk_entry_reset_im_context (GtkEntry *entry)
5984 g_return_if_fail (GTK_IS_ENTRY (entry));
5986 _gtk_entry_reset_im_context (entry);
5990 * gtk_entry_im_context_filter_keypress:
5991 * @entry: a #GtkEntry
5992 * @event: (type Gdk.EventKey): the key event
5994 * Allow the #GtkEntry input method to internally handle key press
5995 * and release events. If this function returns %TRUE, then no further
5996 * processing should be done for this key event. See
5997 * gtk_im_context_filter_keypress().
5999 * Note that you are expected to call this function from your handler
6000 * when overriding key event handling. This is needed in the case when
6001 * you need to insert your own key handling between the input method
6002 * and the default key event handling of the #GtkEntry.
6003 * See gtk_text_view_reset_im_context() for an example of use.
6005 * Return value: %TRUE if the input method handled the key event.
6010 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6013 GtkEntryPrivate *priv;
6015 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6019 return gtk_im_context_filter_keypress (priv->im_context, event);
6023 _gtk_entry_get_im_context (GtkEntry *entry)
6025 return entry->priv->im_context;
6029 gtk_entry_find_position (GtkEntry *entry,
6032 GtkEntryPrivate *priv = entry->priv;
6033 PangoLayout *layout;
6034 PangoLayoutLine *line;
6041 layout = gtk_entry_ensure_layout (entry, TRUE);
6042 text = pango_layout_get_text (layout);
6043 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6045 line = pango_layout_get_lines_readonly (layout)->data;
6046 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6048 if (index >= cursor_index && priv->preedit_length)
6050 if (index >= cursor_index + priv->preedit_length)
6051 index -= priv->preedit_length;
6054 index = cursor_index;
6059 pos = g_utf8_pointer_to_offset (text, text + index);
6066 gtk_entry_get_cursor_locations (GtkEntry *entry,
6071 GtkEntryPrivate *priv = entry->priv;
6072 DisplayMode mode = gtk_entry_get_display_mode (entry);
6074 /* Nothing to display at all, so no cursor is relevant */
6075 if (mode == DISPLAY_BLANK)
6085 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6086 const gchar *text = pango_layout_get_text (layout);
6087 PangoRectangle strong_pos, weak_pos;
6090 if (type == CURSOR_STANDARD)
6092 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6094 else /* type == CURSOR_DND */
6096 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6098 if (priv->dnd_position > priv->current_pos)
6100 if (mode == DISPLAY_NORMAL)
6101 index += priv->preedit_length;
6104 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6105 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6110 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6113 *strong_x = strong_pos.x / PANGO_SCALE;
6116 *weak_x = weak_pos.x / PANGO_SCALE;
6121 gtk_entry_adjust_scroll (GtkEntry *entry)
6123 GtkEntryPrivate *priv = entry->priv;
6124 gint min_offset, max_offset;
6125 gint text_area_width, text_width;
6126 gint strong_x, weak_x;
6127 gint strong_xoffset, weak_xoffset;
6129 PangoLayout *layout;
6130 PangoLayoutLine *line;
6131 PangoRectangle logical_rect;
6133 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6136 text_area_width = gdk_window_get_width (priv->text_area);
6138 if (text_area_width < 0)
6139 text_area_width = 0;
6141 layout = gtk_entry_ensure_layout (entry, TRUE);
6142 line = pango_layout_get_lines_readonly (layout)->data;
6144 pango_layout_line_get_extents (line, NULL, &logical_rect);
6146 /* Display as much text as we can */
6148 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6149 xalign = priv->xalign;
6151 xalign = 1.0 - priv->xalign;
6153 text_width = PANGO_PIXELS(logical_rect.width);
6155 if (text_width > text_area_width)
6158 max_offset = text_width - text_area_width;
6162 min_offset = (text_width - text_area_width) * xalign;
6163 max_offset = min_offset;
6166 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6168 /* And make sure cursors are on screen. Note that the cursor is
6169 * actually drawn one pixel into the INNER_BORDER space on
6170 * the right, when the scroll is at the utmost right. This
6171 * looks better to to me than confining the cursor inside the
6172 * border entirely, though it means that the cursor gets one
6173 * pixel closer to the edge of the widget on the right than
6174 * on the left. This might need changing if one changed
6175 * INNER_BORDER from 2 to 1, as one would do on a
6176 * small-screen-real-estate display.
6178 * We always make sure that the strong cursor is on screen, and
6179 * put the weak cursor on screen if possible.
6182 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6184 strong_xoffset = strong_x - priv->scroll_offset;
6186 if (strong_xoffset < 0)
6188 priv->scroll_offset += strong_xoffset;
6191 else if (strong_xoffset > text_area_width)
6193 priv->scroll_offset += strong_xoffset - text_area_width;
6194 strong_xoffset = text_area_width;
6197 weak_xoffset = weak_x - priv->scroll_offset;
6199 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6201 priv->scroll_offset += weak_xoffset;
6203 else if (weak_xoffset > text_area_width &&
6204 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6206 priv->scroll_offset += weak_xoffset - text_area_width;
6209 g_object_notify (G_OBJECT (entry), "scroll-offset");
6213 gtk_entry_move_adjustments (GtkEntry *entry)
6215 GtkWidget *widget = GTK_WIDGET (entry);
6216 GtkAllocation allocation;
6217 GtkAdjustment *adjustment;
6218 PangoContext *context;
6219 PangoFontMetrics *metrics;
6220 GtkStyleContext *style_context;
6221 GtkStateFlags state;
6226 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6230 gtk_widget_get_allocation (widget, &allocation);
6232 /* Cursor position, layout offset, border width, and widget allocation */
6233 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6234 get_layout_position (entry, &layout_x, NULL);
6235 _gtk_entry_get_borders (entry, &borders);
6236 x += allocation.x + layout_x + borders.left;
6238 /* Approximate width of a char, so user can see what is ahead/behind */
6239 context = gtk_widget_get_pango_context (widget);
6240 style_context = gtk_widget_get_style_context (widget);
6241 state = gtk_widget_get_state_flags (widget);
6243 metrics = pango_context_get_metrics (context,
6244 gtk_style_context_get_font (style_context, state),
6245 pango_context_get_language (context));
6246 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6249 gtk_adjustment_clamp_page (adjustment,
6250 x - (char_width + 1), /* one char + one pixel before */
6251 x + (char_width + 2)); /* one char + cursor + one pixel after */
6255 gtk_entry_move_visually (GtkEntry *entry,
6259 GtkEntryPrivate *priv = entry->priv;
6261 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6264 text = pango_layout_get_text (layout);
6266 index = g_utf8_offset_to_pointer (text, start) - text;
6270 int new_index, new_trailing;
6271 gboolean split_cursor;
6274 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6275 "gtk-split-cursor", &split_cursor,
6282 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6283 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6285 strong = keymap_direction == priv->resolved_dir;
6290 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6295 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6301 else if (new_index != G_MAXINT)
6304 while (new_trailing--)
6305 index = g_utf8_next_char (text + index) - text;
6308 return g_utf8_pointer_to_offset (text, text + index);
6312 gtk_entry_move_logically (GtkEntry *entry,
6316 gint new_pos = start;
6319 length = gtk_entry_buffer_get_length (get_buffer (entry));
6321 /* Prevent any leak of information */
6322 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6324 new_pos = CLAMP (start + count, 0, length);
6328 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6329 PangoLogAttr *log_attrs;
6332 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6334 while (count > 0 && new_pos < length)
6338 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6342 while (count < 0 && new_pos > 0)
6346 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6358 gtk_entry_move_forward_word (GtkEntry *entry,
6360 gboolean allow_whitespace)
6362 gint new_pos = start;
6365 length = gtk_entry_buffer_get_length (get_buffer (entry));
6367 /* Prevent any leak of information */
6368 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6372 else if (new_pos < length)
6374 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6375 PangoLogAttr *log_attrs;
6378 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6380 /* Find the next word boundary */
6382 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6383 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6394 gtk_entry_move_backward_word (GtkEntry *entry,
6396 gboolean allow_whitespace)
6398 gint new_pos = start;
6400 /* Prevent any leak of information */
6401 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6407 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6408 PangoLogAttr *log_attrs;
6411 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6413 new_pos = start - 1;
6415 /* Find the previous word boundary */
6416 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6417 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6427 gtk_entry_delete_whitespace (GtkEntry *entry)
6429 GtkEntryPrivate *priv = entry->priv;
6430 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6431 PangoLogAttr *log_attrs;
6435 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6437 start = end = priv->current_pos;
6439 while (start > 0 && log_attrs[start-1].is_white)
6442 while (end < n_attrs && log_attrs[end].is_white)
6448 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6453 gtk_entry_select_word (GtkEntry *entry)
6455 GtkEntryPrivate *priv = entry->priv;
6456 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6457 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6459 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6463 gtk_entry_select_line (GtkEntry *entry)
6465 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6469 truncate_multiline (const gchar *text)
6474 text[length] && text[length] != '\n' && text[length] != '\r';
6481 paste_received (GtkClipboard *clipboard,
6485 GtkEntry *entry = GTK_ENTRY (data);
6486 GtkEditable *editable = GTK_EDITABLE (entry);
6487 GtkEntryPrivate *priv = entry->priv;
6489 if (priv->button == GDK_BUTTON_MIDDLE)
6491 gint pos, start, end;
6492 pos = priv->insert_pos;
6493 gtk_editable_get_selection_bounds (editable, &start, &end);
6494 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6495 gtk_editable_select_region (editable, pos, pos);
6500 gint pos, start, end;
6502 gboolean popup_completion;
6503 GtkEntryCompletion *completion;
6505 completion = gtk_entry_get_completion (entry);
6507 if (priv->truncate_multiline)
6508 length = truncate_multiline (text);
6510 /* only complete if the selection is at the end */
6511 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6512 MAX (priv->current_pos, priv->selection_bound));
6516 if (gtk_widget_get_mapped (completion->priv->popup_window))
6517 _gtk_entry_completion_popdown (completion);
6519 if (!popup_completion && completion->priv->changed_id > 0)
6520 g_signal_handler_block (entry, completion->priv->changed_id);
6523 begin_change (entry);
6524 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6525 gtk_editable_delete_text (editable, start, end);
6527 pos = priv->current_pos;
6528 gtk_editable_insert_text (editable, text, length, &pos);
6529 gtk_editable_set_position (editable, pos);
6533 !popup_completion && completion->priv->changed_id > 0)
6534 g_signal_handler_unblock (entry, completion->priv->changed_id);
6537 g_object_unref (entry);
6541 gtk_entry_paste (GtkEntry *entry,
6544 g_object_ref (entry);
6545 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6546 paste_received, entry);
6550 primary_get_cb (GtkClipboard *clipboard,
6551 GtkSelectionData *selection_data,
6555 GtkEntry *entry = GTK_ENTRY (data);
6558 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6560 gchar *str = gtk_entry_get_display_text (entry, start, end);
6561 gtk_selection_data_set_text (selection_data, str, -1);
6567 primary_clear_cb (GtkClipboard *clipboard,
6570 GtkEntry *entry = GTK_ENTRY (data);
6571 GtkEntryPrivate *priv = entry->priv;
6573 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6577 gtk_entry_update_primary_selection (GtkEntry *entry)
6579 GtkTargetList *list;
6580 GtkTargetEntry *targets;
6581 GtkClipboard *clipboard;
6585 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6588 list = gtk_target_list_new (NULL, 0);
6589 gtk_target_list_add_text_targets (list, 0);
6591 targets = gtk_target_table_new_from_list (list, &n_targets);
6593 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6595 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6597 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6598 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6599 primary_clear_cb (clipboard, entry);
6603 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6604 gtk_clipboard_clear (clipboard);
6607 gtk_target_table_free (targets, n_targets);
6608 gtk_target_list_unref (list);
6612 gtk_entry_clear (GtkEntry *entry,
6613 GtkEntryIconPosition icon_pos)
6615 GtkEntryPrivate *priv = entry->priv;
6616 EntryIconInfo *icon_info = priv->icons[icon_pos];
6617 GtkImageType storage_type;
6619 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6622 g_object_freeze_notify (G_OBJECT (entry));
6624 /* Explicitly check, as the pointer may become invalidated
6625 * during destruction.
6627 if (GDK_IS_WINDOW (icon_info->window))
6628 gdk_window_hide (icon_info->window);
6630 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6632 switch (storage_type)
6634 case GTK_IMAGE_PIXBUF:
6635 g_object_notify (G_OBJECT (entry),
6636 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6639 case GTK_IMAGE_STOCK:
6640 g_object_notify (G_OBJECT (entry),
6641 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6644 case GTK_IMAGE_ICON_NAME:
6645 g_object_notify (G_OBJECT (entry),
6646 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6649 case GTK_IMAGE_GICON:
6650 g_object_notify (G_OBJECT (entry),
6651 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6655 g_assert_not_reached ();
6659 _gtk_icon_helper_clear (icon_info->icon_helper);
6661 g_object_notify (G_OBJECT (entry),
6662 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6664 g_object_thaw_notify (G_OBJECT (entry));
6668 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6669 GtkEntryIconPosition icon_pos)
6671 GtkEntryPrivate *priv = entry->priv;
6672 EntryIconInfo *icon_info = priv->icons[icon_pos];
6673 GtkStyleContext *context;
6676 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6677 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6679 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6682 gtk_style_context_restore (context);
6693 * Creates a new entry.
6695 * Return value: a new #GtkEntry.
6698 gtk_entry_new (void)
6700 return g_object_new (GTK_TYPE_ENTRY, NULL);
6704 * gtk_entry_new_with_buffer:
6705 * @buffer: The buffer to use for the new #GtkEntry.
6707 * Creates a new entry with the specified text buffer.
6709 * Return value: a new #GtkEntry
6714 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6716 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6717 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6720 static GtkEntryBuffer*
6721 get_buffer (GtkEntry *entry)
6723 GtkEntryPrivate *priv = entry->priv;
6725 if (priv->buffer == NULL)
6727 GtkEntryBuffer *buffer;
6728 buffer = gtk_entry_buffer_new (NULL, 0);
6729 gtk_entry_set_buffer (entry, buffer);
6730 g_object_unref (buffer);
6733 return priv->buffer;
6737 * gtk_entry_get_buffer:
6738 * @entry: a #GtkEntry
6740 * Get the #GtkEntryBuffer object which holds the text for
6745 * Returns: (transfer none): A #GtkEntryBuffer object.
6748 gtk_entry_get_buffer (GtkEntry *entry)
6750 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6752 return get_buffer (entry);
6756 * gtk_entry_set_buffer:
6757 * @entry: a #GtkEntry
6758 * @buffer: a #GtkEntryBuffer
6760 * Set the #GtkEntryBuffer object which holds the text for
6766 gtk_entry_set_buffer (GtkEntry *entry,
6767 GtkEntryBuffer *buffer)
6769 GtkEntryPrivate *priv;
6772 g_return_if_fail (GTK_IS_ENTRY (entry));
6778 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6779 g_object_ref (buffer);
6784 buffer_disconnect_signals (entry);
6785 g_object_unref (priv->buffer);
6788 priv->buffer = buffer;
6791 buffer_connect_signals (entry);
6793 obj = G_OBJECT (entry);
6794 g_object_freeze_notify (obj);
6795 g_object_notify (obj, "buffer");
6796 g_object_notify (obj, "text");
6797 g_object_notify (obj, "text-length");
6798 g_object_notify (obj, "max-length");
6799 g_object_notify (obj, "visibility");
6800 g_object_notify (obj, "invisible-char");
6801 g_object_notify (obj, "invisible-char-set");
6802 g_object_thaw_notify (obj);
6804 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6805 gtk_entry_recompute (entry);
6809 * gtk_entry_get_text_area:
6810 * @entry: a #GtkEntry
6811 * @text_area: (out): Return location for the text area.
6813 * Gets the area where the entry's text is drawn. This function is
6814 * useful when drawing something to the entry in a draw callback.
6816 * If the entry is not realized, @text_area is filled with zeros.
6818 * See also gtk_entry_get_icon_area().
6823 gtk_entry_get_text_area (GtkEntry *entry,
6824 GdkRectangle *text_area)
6826 GtkEntryPrivate *priv;
6828 g_return_if_fail (GTK_IS_ENTRY (entry));
6829 g_return_if_fail (text_area != NULL);
6833 if (priv->text_area)
6835 GtkAllocation allocation;
6838 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6839 gdk_window_get_position (priv->text_area, &x, &y);
6841 text_area->x = x - allocation.x;
6842 text_area->y = y - allocation.y;
6843 text_area->width = gdk_window_get_width (priv->text_area);
6844 text_area->height = gdk_window_get_height (priv->text_area);
6850 text_area->width = 0;
6851 text_area->height = 0;
6856 * gtk_entry_set_text:
6857 * @entry: a #GtkEntry
6858 * @text: the new text
6860 * Sets the text in the widget to the given
6861 * value, replacing the current contents.
6863 * See gtk_entry_buffer_set_text().
6866 gtk_entry_set_text (GtkEntry *entry,
6870 GtkEntryCompletion *completion;
6872 g_return_if_fail (GTK_IS_ENTRY (entry));
6873 g_return_if_fail (text != NULL);
6875 /* Actually setting the text will affect the cursor and selection;
6876 * if the contents don't actually change, this will look odd to the user.
6878 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6881 completion = gtk_entry_get_completion (entry);
6882 if (completion && completion->priv->changed_id > 0)
6883 g_signal_handler_block (entry, completion->priv->changed_id);
6885 begin_change (entry);
6886 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6888 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6891 if (completion && completion->priv->changed_id > 0)
6892 g_signal_handler_unblock (entry, completion->priv->changed_id);
6896 * gtk_entry_set_visibility:
6897 * @entry: a #GtkEntry
6898 * @visible: %TRUE if the contents of the entry are displayed
6901 * Sets whether the contents of the entry are visible or not.
6902 * When visibility is set to %FALSE, characters are displayed
6903 * as the invisible char, and will also appear that way when
6904 * the text in the entry widget is copied elsewhere.
6906 * By default, GTK+ picks the best invisible character available
6907 * in the current font, but it can be changed with
6908 * gtk_entry_set_invisible_char().
6911 gtk_entry_set_visibility (GtkEntry *entry,
6914 GtkEntryPrivate *priv;
6916 g_return_if_fail (GTK_IS_ENTRY (entry));
6920 visible = visible != FALSE;
6922 if (priv->visible != visible)
6924 priv->visible = visible;
6926 g_object_notify (G_OBJECT (entry), "visibility");
6927 gtk_entry_recompute (entry);
6932 * gtk_entry_get_visibility:
6933 * @entry: a #GtkEntry
6935 * Retrieves whether the text in @entry is visible. See
6936 * gtk_entry_set_visibility().
6938 * Return value: %TRUE if the text is currently visible
6941 gtk_entry_get_visibility (GtkEntry *entry)
6943 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6945 return entry->priv->visible;
6949 * gtk_entry_set_invisible_char:
6950 * @entry: a #GtkEntry
6951 * @ch: a Unicode character
6953 * Sets the character to use in place of the actual text when
6954 * gtk_entry_set_visibility() has been called to set text visibility
6955 * to %FALSE. i.e. this is the character used in "password mode" to
6956 * show the user how many characters have been typed. By default, GTK+
6957 * picks the best invisible char available in the current font. If you
6958 * set the invisible char to 0, then the user will get no feedback
6959 * at all; there will be no text on the screen as they type.
6962 gtk_entry_set_invisible_char (GtkEntry *entry,
6965 GtkEntryPrivate *priv;
6967 g_return_if_fail (GTK_IS_ENTRY (entry));
6971 if (!priv->invisible_char_set)
6973 priv->invisible_char_set = TRUE;
6974 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6977 if (ch == priv->invisible_char)
6980 priv->invisible_char = ch;
6981 g_object_notify (G_OBJECT (entry), "invisible-char");
6982 gtk_entry_recompute (entry);
6986 * gtk_entry_get_invisible_char:
6987 * @entry: a #GtkEntry
6989 * Retrieves the character displayed in place of the real characters
6990 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6992 * Return value: the current invisible char, or 0, if the entry does not
6993 * show invisible text at all.
6996 gtk_entry_get_invisible_char (GtkEntry *entry)
6998 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7000 return entry->priv->invisible_char;
7004 * gtk_entry_unset_invisible_char:
7005 * @entry: a #GtkEntry
7007 * Unsets the invisible char previously set with
7008 * gtk_entry_set_invisible_char(). So that the
7009 * default invisible char is used again.
7014 gtk_entry_unset_invisible_char (GtkEntry *entry)
7016 GtkEntryPrivate *priv;
7019 g_return_if_fail (GTK_IS_ENTRY (entry));
7023 if (!priv->invisible_char_set)
7026 priv->invisible_char_set = FALSE;
7027 ch = find_invisible_char (GTK_WIDGET (entry));
7029 if (priv->invisible_char != ch)
7031 priv->invisible_char = ch;
7032 g_object_notify (G_OBJECT (entry), "invisible-char");
7035 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7036 gtk_entry_recompute (entry);
7040 * gtk_entry_set_overwrite_mode:
7041 * @entry: a #GtkEntry
7042 * @overwrite: new value
7044 * Sets whether the text is overwritten when typing in the #GtkEntry.
7049 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7052 GtkEntryPrivate *priv = entry->priv;
7054 g_return_if_fail (GTK_IS_ENTRY (entry));
7056 if (priv->overwrite_mode == overwrite)
7059 gtk_entry_toggle_overwrite (entry);
7061 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7065 * gtk_entry_get_overwrite_mode:
7066 * @entry: a #GtkEntry
7068 * Gets the value set by gtk_entry_set_overwrite_mode().
7070 * Return value: whether the text is overwritten when typing.
7075 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7077 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7079 return entry->priv->overwrite_mode;
7083 * gtk_entry_get_text:
7084 * @entry: a #GtkEntry
7086 * Retrieves the contents of the entry widget.
7087 * See also gtk_editable_get_chars().
7089 * This is equivalent to:
7091 * <informalexample><programlisting>
7092 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7093 * </programlisting></informalexample>
7095 * Return value: a pointer to the contents of the widget as a
7096 * string. This string points to internally allocated
7097 * storage in the widget and must not be freed, modified or
7101 gtk_entry_get_text (GtkEntry *entry)
7103 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7105 return gtk_entry_buffer_get_text (get_buffer (entry));
7109 * gtk_entry_set_max_length:
7110 * @entry: a #GtkEntry
7111 * @max: the maximum length of the entry, or 0 for no maximum.
7112 * (other than the maximum length of entries.) The value passed in will
7113 * be clamped to the range 0-65536.
7115 * Sets the maximum allowed length of the contents of the widget. If
7116 * the current contents are longer than the given length, then they
7117 * will be truncated to fit.
7119 * This is equivalent to:
7121 * <informalexample><programlisting>
7122 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7123 * </programlisting></informalexample>
7126 gtk_entry_set_max_length (GtkEntry *entry,
7129 g_return_if_fail (GTK_IS_ENTRY (entry));
7130 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7134 * gtk_entry_get_max_length:
7135 * @entry: a #GtkEntry
7137 * Retrieves the maximum allowed length of the text in
7138 * @entry. See gtk_entry_set_max_length().
7140 * This is equivalent to:
7142 * <informalexample><programlisting>
7143 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7144 * </programlisting></informalexample>
7146 * Return value: the maximum allowed number of characters
7147 * in #GtkEntry, or 0 if there is no maximum.
7150 gtk_entry_get_max_length (GtkEntry *entry)
7152 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7154 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7158 * gtk_entry_get_text_length:
7159 * @entry: a #GtkEntry
7161 * Retrieves the current length of the text in
7164 * This is equivalent to:
7166 * <informalexample><programlisting>
7167 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7168 * </programlisting></informalexample>
7170 * Return value: the current number of characters
7171 * in #GtkEntry, or 0 if there are none.
7176 gtk_entry_get_text_length (GtkEntry *entry)
7178 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7180 return gtk_entry_buffer_get_length (get_buffer (entry));
7184 * gtk_entry_set_activates_default:
7185 * @entry: a #GtkEntry
7186 * @setting: %TRUE to activate window's default widget on Enter keypress
7188 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7189 * widget for the window containing the entry. This usually means that
7190 * the dialog box containing the entry will be closed, since the default
7191 * widget is usually one of the dialog buttons.
7193 * (For experts: if @setting is %TRUE, the entry calls
7194 * gtk_window_activate_default() on the window containing the entry, in
7195 * the default handler for the #GtkWidget::activate signal.)
7198 gtk_entry_set_activates_default (GtkEntry *entry,
7201 GtkEntryPrivate *priv;
7203 g_return_if_fail (GTK_IS_ENTRY (entry));
7207 setting = setting != FALSE;
7209 if (setting != priv->activates_default)
7211 priv->activates_default = setting;
7212 g_object_notify (G_OBJECT (entry), "activates-default");
7217 * gtk_entry_get_activates_default:
7218 * @entry: a #GtkEntry
7220 * Retrieves the value set by gtk_entry_set_activates_default().
7222 * Return value: %TRUE if the entry will activate the default widget
7225 gtk_entry_get_activates_default (GtkEntry *entry)
7227 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7229 return entry->priv->activates_default;
7233 * gtk_entry_set_width_chars:
7234 * @entry: a #GtkEntry
7235 * @n_chars: width in chars
7237 * Changes the size request of the entry to be about the right size
7238 * for @n_chars characters. Note that it changes the size
7239 * <emphasis>request</emphasis>, the size can still be affected by
7240 * how you pack the widget into containers. If @n_chars is -1, the
7241 * size reverts to the default entry size.
7244 gtk_entry_set_width_chars (GtkEntry *entry,
7247 GtkEntryPrivate *priv;
7249 g_return_if_fail (GTK_IS_ENTRY (entry));
7253 if (priv->width_chars != n_chars)
7255 priv->width_chars = n_chars;
7256 g_object_notify (G_OBJECT (entry), "width-chars");
7257 gtk_widget_queue_resize (GTK_WIDGET (entry));
7262 * gtk_entry_get_width_chars:
7263 * @entry: a #GtkEntry
7265 * Gets the value set by gtk_entry_set_width_chars().
7267 * Return value: number of chars to request space for, or negative if unset
7270 gtk_entry_get_width_chars (GtkEntry *entry)
7272 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7274 return entry->priv->width_chars;
7278 * gtk_entry_set_has_frame:
7279 * @entry: a #GtkEntry
7280 * @setting: new value
7282 * Sets whether the entry has a beveled frame around it.
7285 gtk_entry_set_has_frame (GtkEntry *entry,
7288 GtkEntryPrivate *priv;
7290 g_return_if_fail (GTK_IS_ENTRY (entry));
7294 setting = (setting != FALSE);
7296 if (priv->has_frame == setting)
7299 gtk_widget_queue_resize (GTK_WIDGET (entry));
7300 priv->has_frame = setting;
7301 g_object_notify (G_OBJECT (entry), "has-frame");
7305 * gtk_entry_get_has_frame:
7306 * @entry: a #GtkEntry
7308 * Gets the value set by gtk_entry_set_has_frame().
7310 * Return value: whether the entry has a beveled frame
7313 gtk_entry_get_has_frame (GtkEntry *entry)
7315 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7317 return entry->priv->has_frame;
7321 * gtk_entry_set_inner_border:
7322 * @entry: a #GtkEntry
7323 * @border: (allow-none): a #GtkBorder, or %NULL
7325 * Sets %entry's inner-border property to %border, or clears it if %NULL
7326 * is passed. The inner-border is the area around the entry's text, but
7329 * If set, this property overrides the inner-border style property.
7330 * Overriding the style-provided border is useful when you want to do
7331 * in-place editing of some text in a canvas or list widget, where
7332 * pixel-exact positioning of the entry is important.
7336 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7337 * the value set with this function is ignored by #GtkEntry.
7340 gtk_entry_set_inner_border (GtkEntry *entry,
7341 const GtkBorder *border)
7343 g_return_if_fail (GTK_IS_ENTRY (entry));
7345 gtk_entry_do_set_inner_border (entry, border);
7349 * gtk_entry_get_inner_border:
7350 * @entry: a #GtkEntry
7352 * This function returns the entry's #GtkEntry:inner-border property. See
7353 * gtk_entry_set_inner_border() for more information.
7355 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7359 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7360 * the value returned by this function is ignored by #GtkEntry.
7363 gtk_entry_get_inner_border (GtkEntry *entry)
7365 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7367 return gtk_entry_do_get_inner_border (entry);
7371 * gtk_entry_get_layout:
7372 * @entry: a #GtkEntry
7374 * Gets the #PangoLayout used to display the entry.
7375 * The layout is useful to e.g. convert text positions to
7376 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7377 * The returned layout is owned by the entry and must not be
7378 * modified or freed by the caller.
7380 * Keep in mind that the layout text may contain a preedit string, so
7381 * gtk_entry_layout_index_to_text_index() and
7382 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7383 * indices in the layout to byte indices in the entry contents.
7385 * Return value: (transfer none): the #PangoLayout for this entry
7388 gtk_entry_get_layout (GtkEntry *entry)
7390 PangoLayout *layout;
7392 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7394 layout = gtk_entry_ensure_layout (entry, TRUE);
7401 * gtk_entry_layout_index_to_text_index:
7402 * @entry: a #GtkEntry
7403 * @layout_index: byte index into the entry layout text
7405 * Converts from a position in the entry contents (returned
7406 * by gtk_entry_get_text()) to a position in the
7407 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7408 * with text retrieved via pango_layout_get_text()).
7410 * Return value: byte index into the entry contents
7413 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7416 GtkEntryPrivate *priv;
7417 PangoLayout *layout;
7421 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7425 layout = gtk_entry_ensure_layout (entry, TRUE);
7426 text = pango_layout_get_text (layout);
7427 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7429 if (layout_index >= cursor_index && priv->preedit_length)
7431 if (layout_index >= cursor_index + priv->preedit_length)
7432 layout_index -= priv->preedit_length;
7434 layout_index = cursor_index;
7437 return layout_index;
7441 * gtk_entry_text_index_to_layout_index:
7442 * @entry: a #GtkEntry
7443 * @text_index: byte index into the entry contents
7445 * Converts from a position in the entry's #PangoLayout (returned by
7446 * gtk_entry_get_layout()) to a position in the entry contents
7447 * (returned by gtk_entry_get_text()).
7449 * Return value: byte index into the entry layout text
7452 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7455 GtkEntryPrivate *priv;
7456 PangoLayout *layout;
7460 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7464 layout = gtk_entry_ensure_layout (entry, TRUE);
7465 text = pango_layout_get_text (layout);
7466 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7468 if (text_index > cursor_index)
7469 text_index += priv->preedit_length;
7475 * gtk_entry_get_layout_offsets:
7476 * @entry: a #GtkEntry
7477 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7478 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7481 * Obtains the position of the #PangoLayout used to render text
7482 * in the entry, in widget coordinates. Useful if you want to line
7483 * up the text in an entry with some other text, e.g. when using the
7484 * entry to implement editable cells in a sheet widget.
7486 * Also useful to convert mouse events into coordinates inside the
7487 * #PangoLayout, e.g. to take some action if some part of the entry text
7490 * Note that as the user scrolls around in the entry the offsets will
7491 * change; you'll need to connect to the "notify::scroll-offset"
7492 * signal to track this. Remember when using the #PangoLayout
7493 * functions you need to convert to and from pixels using
7494 * PANGO_PIXELS() or #PANGO_SCALE.
7496 * Keep in mind that the layout text may contain a preedit string, so
7497 * gtk_entry_layout_index_to_text_index() and
7498 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7499 * indices in the layout to byte indices in the entry contents.
7502 gtk_entry_get_layout_offsets (GtkEntry *entry,
7506 gint text_area_x, text_area_y;
7508 g_return_if_fail (GTK_IS_ENTRY (entry));
7510 /* this gets coords relative to text area */
7511 get_layout_position (entry, x, y);
7513 /* convert to widget coords */
7514 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7525 * gtk_entry_set_alignment:
7526 * @entry: a #GtkEntry
7527 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7528 * Reversed for RTL layouts
7530 * Sets the alignment for the contents of the entry. This controls
7531 * the horizontal positioning of the contents when the displayed
7532 * text is shorter than the width of the entry.
7537 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7539 GtkEntryPrivate *priv;
7541 g_return_if_fail (GTK_IS_ENTRY (entry));
7547 else if (xalign > 1.0)
7550 if (xalign != priv->xalign)
7552 priv->xalign = xalign;
7554 gtk_entry_recompute (entry);
7556 g_object_notify (G_OBJECT (entry), "xalign");
7561 * gtk_entry_get_alignment:
7562 * @entry: a #GtkEntry
7564 * Gets the value set by gtk_entry_set_alignment().
7566 * Return value: the alignment
7571 gtk_entry_get_alignment (GtkEntry *entry)
7573 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7575 return entry->priv->xalign;
7579 * gtk_entry_set_icon_from_pixbuf:
7580 * @entry: a #GtkEntry
7581 * @icon_pos: Icon position
7582 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7584 * Sets the icon shown in the specified position using a pixbuf.
7586 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7591 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7592 GtkEntryIconPosition icon_pos,
7595 GtkEntryPrivate *priv;
7596 EntryIconInfo *icon_info;
7598 g_return_if_fail (GTK_IS_ENTRY (entry));
7599 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7603 if ((icon_info = priv->icons[icon_pos]) == NULL)
7604 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7606 g_object_freeze_notify (G_OBJECT (entry));
7609 g_object_ref (pixbuf);
7611 gtk_entry_clear (entry, icon_pos);
7615 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7617 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7619 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7620 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7624 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7625 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7628 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7629 gdk_window_show_unraised (icon_info->window);
7631 g_object_unref (pixbuf);
7634 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7635 gtk_widget_queue_resize (GTK_WIDGET (entry));
7637 g_object_thaw_notify (G_OBJECT (entry));
7641 * gtk_entry_set_icon_from_stock:
7642 * @entry: A #GtkEntry
7643 * @icon_pos: Icon position
7644 * @stock_id: (allow-none): The name of the stock item, or %NULL
7646 * Sets the icon shown in the entry at the specified position from
7649 * If @stock_id is %NULL, no icon will be shown in the specified position.
7654 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7655 GtkEntryIconPosition icon_pos,
7656 const gchar *stock_id)
7658 GtkEntryPrivate *priv;
7659 EntryIconInfo *icon_info;
7662 g_return_if_fail (GTK_IS_ENTRY (entry));
7663 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7667 if ((icon_info = priv->icons[icon_pos]) == NULL)
7668 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7670 g_object_freeze_notify (G_OBJECT (entry));
7672 /* need to dup before clearing */
7673 new_id = g_strdup (stock_id);
7675 gtk_entry_clear (entry, icon_pos);
7679 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7681 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7683 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7684 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7688 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7689 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7692 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7693 gdk_window_show_unraised (icon_info->window);
7698 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7699 gtk_widget_queue_resize (GTK_WIDGET (entry));
7701 g_object_thaw_notify (G_OBJECT (entry));
7705 * gtk_entry_set_icon_from_icon_name:
7706 * @entry: A #GtkEntry
7707 * @icon_pos: The position at which to set the icon
7708 * @icon_name: (allow-none): An icon name, or %NULL
7710 * Sets the icon shown in the entry at the specified position
7711 * from the current icon theme.
7713 * If the icon name isn't known, a "broken image" icon will be displayed
7716 * If @icon_name is %NULL, no icon will be shown in the specified position.
7721 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7722 GtkEntryIconPosition icon_pos,
7723 const gchar *icon_name)
7725 GtkEntryPrivate *priv;
7726 EntryIconInfo *icon_info;
7729 g_return_if_fail (GTK_IS_ENTRY (entry));
7730 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7734 if ((icon_info = priv->icons[icon_pos]) == NULL)
7735 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7737 g_object_freeze_notify (G_OBJECT (entry));
7739 /* need to dup before clearing */
7740 new_name = g_strdup (icon_name);
7742 gtk_entry_clear (entry, icon_pos);
7744 if (new_name != NULL)
7746 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7748 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7750 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7751 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7755 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7756 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7759 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7760 gdk_window_show_unraised (icon_info->window);
7765 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7766 gtk_widget_queue_resize (GTK_WIDGET (entry));
7768 g_object_thaw_notify (G_OBJECT (entry));
7772 * gtk_entry_set_icon_from_gicon:
7773 * @entry: A #GtkEntry
7774 * @icon_pos: The position at which to set the icon
7775 * @icon: (allow-none): The icon to set, or %NULL
7777 * Sets the icon shown in the entry at the specified position
7778 * from the current icon theme.
7779 * If the icon isn't known, a "broken image" icon will be displayed
7782 * If @icon is %NULL, no icon will be shown in the specified position.
7787 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7788 GtkEntryIconPosition icon_pos,
7791 GtkEntryPrivate *priv;
7792 EntryIconInfo *icon_info;
7794 g_return_if_fail (GTK_IS_ENTRY (entry));
7795 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7799 if ((icon_info = priv->icons[icon_pos]) == NULL)
7800 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7802 g_object_freeze_notify (G_OBJECT (entry));
7804 /* need to ref before clearing */
7806 g_object_ref (icon);
7808 gtk_entry_clear (entry, icon_pos);
7812 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7814 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7816 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7817 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7821 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7822 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7825 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7826 gdk_window_show_unraised (icon_info->window);
7828 g_object_unref (icon);
7831 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7832 gtk_widget_queue_resize (GTK_WIDGET (entry));
7834 g_object_thaw_notify (G_OBJECT (entry));
7838 * gtk_entry_set_icon_activatable:
7839 * @entry: A #GtkEntry
7840 * @icon_pos: Icon position
7841 * @activatable: %TRUE if the icon should be activatable
7843 * Sets whether the icon is activatable.
7848 gtk_entry_set_icon_activatable (GtkEntry *entry,
7849 GtkEntryIconPosition icon_pos,
7850 gboolean activatable)
7852 GtkEntryPrivate *priv;
7853 EntryIconInfo *icon_info;
7855 g_return_if_fail (GTK_IS_ENTRY (entry));
7856 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7860 if ((icon_info = priv->icons[icon_pos]) == NULL)
7861 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7863 activatable = activatable != FALSE;
7865 if (icon_info->nonactivatable != !activatable)
7867 icon_info->nonactivatable = !activatable;
7869 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7870 update_cursors (GTK_WIDGET (entry));
7872 g_object_notify (G_OBJECT (entry),
7873 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7878 * gtk_entry_get_icon_activatable:
7879 * @entry: a #GtkEntry
7880 * @icon_pos: Icon position
7882 * Returns whether the icon is activatable.
7884 * Returns: %TRUE if the icon is activatable.
7889 gtk_entry_get_icon_activatable (GtkEntry *entry,
7890 GtkEntryIconPosition icon_pos)
7892 GtkEntryPrivate *priv;
7893 EntryIconInfo *icon_info;
7895 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7896 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7899 icon_info = priv->icons[icon_pos];
7901 return (!icon_info || !icon_info->nonactivatable);
7905 * gtk_entry_get_icon_pixbuf:
7906 * @entry: A #GtkEntry
7907 * @icon_pos: Icon position
7909 * Retrieves the image used for the icon.
7911 * Unlike the other methods of setting and getting icon data, this
7912 * method will work regardless of whether the icon was set using a
7913 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7915 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7916 * set for this position.
7921 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7922 GtkEntryIconPosition icon_pos)
7924 GtkEntryPrivate *priv;
7925 EntryIconInfo *icon_info;
7928 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7929 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7933 icon_info = priv->icons[icon_pos];
7938 /* HACK: unfortunately this is transfer none, so we need to return
7939 * the icon helper's cache ref directly.
7941 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7942 g_object_unref (pixbuf);
7948 * gtk_entry_get_icon_gicon:
7949 * @entry: A #GtkEntry
7950 * @icon_pos: Icon position
7952 * Retrieves the #GIcon used for the icon, or %NULL if there is
7953 * no icon or if the icon was set by some other method (e.g., by
7954 * stock, pixbuf, or icon name).
7956 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7957 * or if the icon is not a #GIcon
7962 gtk_entry_get_icon_gicon (GtkEntry *entry,
7963 GtkEntryIconPosition icon_pos)
7965 GtkEntryPrivate *priv;
7966 EntryIconInfo *icon_info;
7968 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7969 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7972 icon_info = priv->icons[icon_pos];
7977 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7981 * gtk_entry_get_icon_stock:
7982 * @entry: A #GtkEntry
7983 * @icon_pos: Icon position
7985 * Retrieves the stock id used for the icon, or %NULL if there is
7986 * no icon or if the icon was set by some other method (e.g., by
7987 * pixbuf, icon name or gicon).
7989 * Returns: A stock id, or %NULL if no icon is set or if the icon
7990 * wasn't set from a stock id
7995 gtk_entry_get_icon_stock (GtkEntry *entry,
7996 GtkEntryIconPosition icon_pos)
7998 GtkEntryPrivate *priv;
7999 EntryIconInfo *icon_info;
8001 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8002 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8005 icon_info = priv->icons[icon_pos];
8010 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8014 * gtk_entry_get_icon_name:
8015 * @entry: A #GtkEntry
8016 * @icon_pos: Icon position
8018 * Retrieves the icon name used for the icon, or %NULL if there is
8019 * no icon or if the icon was set by some other method (e.g., by
8020 * pixbuf, stock or gicon).
8022 * Returns: An icon name, or %NULL if no icon is set or if the icon
8023 * wasn't set from an icon name
8028 gtk_entry_get_icon_name (GtkEntry *entry,
8029 GtkEntryIconPosition icon_pos)
8031 GtkEntryPrivate *priv;
8032 EntryIconInfo *icon_info;
8034 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8035 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8038 icon_info = priv->icons[icon_pos];
8043 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8047 * gtk_entry_set_icon_sensitive:
8048 * @entry: A #GtkEntry
8049 * @icon_pos: Icon position
8050 * @sensitive: Specifies whether the icon should appear
8051 * sensitive or insensitive
8053 * Sets the sensitivity for the specified icon.
8058 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8059 GtkEntryIconPosition icon_pos,
8062 GtkEntryPrivate *priv;
8063 EntryIconInfo *icon_info;
8065 g_return_if_fail (GTK_IS_ENTRY (entry));
8066 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8070 if ((icon_info = priv->icons[icon_pos]) == NULL)
8071 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8073 if (icon_info->insensitive != !sensitive)
8075 icon_info->insensitive = !sensitive;
8077 icon_info->pressed = FALSE;
8078 icon_info->prelight = FALSE;
8080 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8081 update_cursors (GTK_WIDGET (entry));
8083 gtk_widget_queue_draw (GTK_WIDGET (entry));
8085 g_object_notify (G_OBJECT (entry),
8086 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8091 * gtk_entry_get_icon_sensitive:
8092 * @entry: a #GtkEntry
8093 * @icon_pos: Icon position
8095 * Returns whether the icon appears sensitive or insensitive.
8097 * Returns: %TRUE if the icon is sensitive.
8102 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8103 GtkEntryIconPosition icon_pos)
8105 GtkEntryPrivate *priv;
8106 EntryIconInfo *icon_info;
8108 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8109 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8113 icon_info = priv->icons[icon_pos];
8115 return (!icon_info || !icon_info->insensitive);
8120 * gtk_entry_get_icon_storage_type:
8121 * @entry: a #GtkEntry
8122 * @icon_pos: Icon position
8124 * Gets the type of representation being used by the icon
8125 * to store image data. If the icon has no image data,
8126 * the return value will be %GTK_IMAGE_EMPTY.
8128 * Return value: image representation being used
8133 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8134 GtkEntryIconPosition icon_pos)
8136 GtkEntryPrivate *priv;
8137 EntryIconInfo *icon_info;
8139 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8140 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8144 icon_info = priv->icons[icon_pos];
8147 return GTK_IMAGE_EMPTY;
8149 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8153 * gtk_entry_get_icon_at_pos:
8154 * @entry: a #GtkEntry
8155 * @x: the x coordinate of the position to find
8156 * @y: the y coordinate of the position to find
8158 * Finds the icon at the given position and return its index. The
8159 * position's coordinates are relative to the @entry's top left corner.
8160 * If @x, @y doesn't lie inside an icon, -1 is returned.
8161 * This function is intended for use in a #GtkWidget::query-tooltip
8164 * Returns: the index of the icon at the given position, or -1
8169 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8173 GtkAllocation primary;
8174 GtkAllocation secondary;
8175 gint frame_x, frame_y;
8177 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8179 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8183 get_icon_allocations (entry, &primary, &secondary);
8185 if (primary.x <= x && x < primary.x + primary.width &&
8186 primary.y <= y && y < primary.y + primary.height)
8187 return GTK_ENTRY_ICON_PRIMARY;
8189 if (secondary.x <= x && x < secondary.x + secondary.width &&
8190 secondary.y <= y && y < secondary.y + secondary.height)
8191 return GTK_ENTRY_ICON_SECONDARY;
8197 * gtk_entry_set_icon_drag_source:
8198 * @entry: a #GtkIconEntry
8199 * @icon_pos: icon position
8200 * @target_list: the targets (data formats) in which the data can be provided
8201 * @actions: a bitmask of the allowed drag actions
8203 * Sets up the icon at the given position so that GTK+ will start a drag
8204 * operation when the user clicks and drags the icon.
8206 * To handle the drag operation, you need to connect to the usual
8207 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8208 * signal, and use gtk_entry_get_current_icon_drag_source() in
8209 * your signal handler to find out if the drag was started from
8212 * By default, GTK+ uses the icon as the drag icon. You can use the
8213 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8214 * have to use g_signal_connect_after() to ensure that your signal handler
8215 * gets executed after the default handler.
8220 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8221 GtkEntryIconPosition icon_pos,
8222 GtkTargetList *target_list,
8223 GdkDragAction actions)
8225 GtkEntryPrivate *priv;
8226 EntryIconInfo *icon_info;
8228 g_return_if_fail (GTK_IS_ENTRY (entry));
8229 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8233 if ((icon_info = priv->icons[icon_pos]) == NULL)
8234 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8236 if (icon_info->target_list)
8237 gtk_target_list_unref (icon_info->target_list);
8238 icon_info->target_list = target_list;
8239 if (icon_info->target_list)
8240 gtk_target_list_ref (icon_info->target_list);
8242 icon_info->actions = actions;
8246 * gtk_entry_get_current_icon_drag_source:
8247 * @entry: a #GtkIconEntry
8249 * Returns the index of the icon which is the source of the current
8250 * DND operation, or -1.
8252 * This function is meant to be used in a #GtkWidget::drag-data-get
8255 * Returns: index of the icon which is the source of the current
8256 * DND operation, or -1.
8261 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8263 GtkEntryPrivate *priv;
8264 EntryIconInfo *icon_info = NULL;
8267 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8271 for (i = 0; i < MAX_ICONS; i++)
8273 if ((icon_info = priv->icons[i]))
8275 if (icon_info->in_drag)
8284 * gtk_entry_get_icon_area:
8285 * @entry: A #GtkEntry
8286 * @icon_pos: Icon position
8287 * @icon_area: (out): Return location for the icon's area
8289 * Gets the area where entry's icon at @icon_pos is drawn.
8290 * This function is useful when drawing something to the
8291 * entry in a draw callback.
8293 * If the entry is not realized or has no icon at the given position,
8294 * @icon_area is filled with zeros.
8296 * See also gtk_entry_get_text_area()
8301 gtk_entry_get_icon_area (GtkEntry *entry,
8302 GtkEntryIconPosition icon_pos,
8303 GdkRectangle *icon_area)
8305 GtkEntryPrivate *priv;
8306 EntryIconInfo *icon_info;
8308 g_return_if_fail (GTK_IS_ENTRY (entry));
8309 g_return_if_fail (icon_area != NULL);
8313 icon_info = priv->icons[icon_pos];
8317 GtkAllocation primary;
8318 GtkAllocation secondary;
8320 get_icon_allocations (entry, &primary, &secondary);
8322 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8323 *icon_area = primary;
8325 *icon_area = secondary;
8331 icon_area->width = 0;
8332 icon_area->height = 0;
8337 ensure_has_tooltip (GtkEntry *entry)
8339 GtkEntryPrivate *priv;
8340 EntryIconInfo *icon_info;
8342 gboolean has_tooltip = FALSE;
8346 for (i = 0; i < MAX_ICONS; i++)
8348 if ((icon_info = priv->icons[i]) != NULL)
8350 if (icon_info->tooltip != NULL)
8358 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8362 * gtk_entry_get_icon_tooltip_text:
8363 * @entry: a #GtkEntry
8364 * @icon_pos: the icon position
8366 * Gets the contents of the tooltip on the icon at the specified
8367 * position in @entry.
8369 * Returns: the tooltip text, or %NULL. Free the returned string
8370 * with g_free() when done.
8375 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8376 GtkEntryIconPosition icon_pos)
8378 GtkEntryPrivate *priv;
8379 EntryIconInfo *icon_info;
8382 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8383 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8387 icon_info = priv->icons[icon_pos];
8392 if (icon_info->tooltip &&
8393 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8394 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8400 * gtk_entry_set_icon_tooltip_text:
8401 * @entry: a #GtkEntry
8402 * @icon_pos: the icon position
8403 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8405 * Sets @tooltip as the contents of the tooltip for the icon
8406 * at the specified position.
8408 * Use %NULL for @tooltip to remove an existing tooltip.
8410 * See also gtk_widget_set_tooltip_text() and
8411 * gtk_entry_set_icon_tooltip_markup().
8416 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8417 GtkEntryIconPosition icon_pos,
8418 const gchar *tooltip)
8420 GtkEntryPrivate *priv;
8421 EntryIconInfo *icon_info;
8423 g_return_if_fail (GTK_IS_ENTRY (entry));
8424 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8428 if ((icon_info = priv->icons[icon_pos]) == NULL)
8429 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8431 if (icon_info->tooltip)
8432 g_free (icon_info->tooltip);
8434 /* Treat an empty string as a NULL string,
8435 * because an empty string would be useless for a tooltip:
8437 if (tooltip && tooltip[0] == '\0')
8440 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8442 ensure_has_tooltip (entry);
8446 * gtk_entry_get_icon_tooltip_markup:
8447 * @entry: a #GtkEntry
8448 * @icon_pos: the icon position
8450 * Gets the contents of the tooltip on the icon at the specified
8451 * position in @entry.
8453 * Returns: the tooltip text, or %NULL. Free the returned string
8454 * with g_free() when done.
8459 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8460 GtkEntryIconPosition icon_pos)
8462 GtkEntryPrivate *priv;
8463 EntryIconInfo *icon_info;
8465 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8466 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8470 icon_info = priv->icons[icon_pos];
8475 return g_strdup (icon_info->tooltip);
8479 * gtk_entry_set_icon_tooltip_markup:
8480 * @entry: a #GtkEntry
8481 * @icon_pos: the icon position
8482 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8484 * Sets @tooltip as the contents of the tooltip for the icon at
8485 * the specified position. @tooltip is assumed to be marked up with
8486 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8488 * Use %NULL for @tooltip to remove an existing tooltip.
8490 * See also gtk_widget_set_tooltip_markup() and
8491 * gtk_enty_set_icon_tooltip_text().
8496 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8497 GtkEntryIconPosition icon_pos,
8498 const gchar *tooltip)
8500 GtkEntryPrivate *priv;
8501 EntryIconInfo *icon_info;
8503 g_return_if_fail (GTK_IS_ENTRY (entry));
8504 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8508 if ((icon_info = priv->icons[icon_pos]) == NULL)
8509 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8511 if (icon_info->tooltip)
8512 g_free (icon_info->tooltip);
8514 /* Treat an empty string as a NULL string,
8515 * because an empty string would be useless for a tooltip:
8517 if (tooltip && tooltip[0] == '\0')
8520 icon_info->tooltip = g_strdup (tooltip);
8522 ensure_has_tooltip (entry);
8526 gtk_entry_query_tooltip (GtkWidget *widget,
8529 gboolean keyboard_tip,
8530 GtkTooltip *tooltip)
8533 GtkEntryPrivate *priv;
8534 EntryIconInfo *icon_info;
8537 entry = GTK_ENTRY (widget);
8542 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8545 if ((icon_info = priv->icons[icon_pos]) != NULL)
8547 if (icon_info->tooltip)
8549 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8558 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8565 /* Quick hack of a popup menu
8568 activate_cb (GtkWidget *menuitem,
8571 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8572 g_signal_emit_by_name (entry, signal);
8577 gtk_entry_mnemonic_activate (GtkWidget *widget,
8578 gboolean group_cycling)
8580 gtk_widget_grab_focus (widget);
8585 gtk_entry_grab_notify (GtkWidget *widget,
8586 gboolean was_grabbed)
8588 GtkEntryPrivate *priv;
8590 priv = GTK_ENTRY (widget)->priv;
8593 gtk_widget_device_is_shadowed (widget, priv->device))
8595 /* Unset button so we don't expect
8596 * a button release anymore
8599 priv->device = NULL;
8600 priv->in_drag = FALSE;
8605 append_action_signal (GtkEntry *entry,
8607 const gchar *stock_id,
8608 const gchar *signal,
8611 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8613 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8614 g_signal_connect (menuitem, "activate",
8615 G_CALLBACK (activate_cb), entry);
8617 gtk_widget_set_sensitive (menuitem, sensitive);
8619 gtk_widget_show (menuitem);
8620 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8624 popup_menu_detach (GtkWidget *attach_widget,
8627 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8628 GtkEntryPrivate *priv_attach = entry_attach->priv;
8630 priv_attach->popup_menu = NULL;
8634 popup_position_func (GtkMenu *menu,
8640 GtkEntry *entry = GTK_ENTRY (user_data);
8641 GtkEntryPrivate *priv = entry->priv;
8642 GtkWidget *widget = GTK_WIDGET (entry);
8644 GtkRequisition menu_req;
8645 GdkRectangle monitor;
8647 gint monitor_num, strong_x, height;
8649 g_return_if_fail (gtk_widget_get_realized (widget));
8651 gdk_window_get_origin (priv->text_area, x, y);
8653 screen = gtk_widget_get_screen (widget);
8654 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8655 if (monitor_num < 0)
8657 gtk_menu_set_monitor (menu, monitor_num);
8659 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8660 gtk_widget_get_preferred_size (priv->popup_menu,
8662 height = gdk_window_get_height (priv->text_area);
8663 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8664 _gtk_entry_get_borders (entry, &borders);
8666 *x += borders.left + strong_x - priv->scroll_offset;
8667 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8668 *x -= menu_req.width;
8670 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8672 else if ((*y - menu_req.height) >= monitor.y)
8673 *y -= menu_req.height;
8674 else if (monitor.y + monitor.height - (*y + height) > *y)
8677 *y -= menu_req.height;
8683 unichar_chosen_func (const char *text,
8686 GtkEntry *entry = GTK_ENTRY (data);
8687 GtkEntryPrivate *priv = entry->priv;
8690 gtk_entry_enter_text (entry, text);
8702 popup_targets_received (GtkClipboard *clipboard,
8703 GtkSelectionData *data,
8706 PopupInfo *info = user_data;
8707 GtkEntry *entry = info->entry;
8708 GtkEntryPrivate *info_entry_priv = entry->priv;
8710 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8713 gboolean clipboard_contains_text;
8714 GtkWidget *menuitem;
8716 gboolean show_input_method_menu;
8717 gboolean show_unicode_menu;
8719 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8720 if (info_entry_priv->popup_menu)
8721 gtk_widget_destroy (info_entry_priv->popup_menu);
8723 info_entry_priv->popup_menu = gtk_menu_new ();
8725 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8729 mode = gtk_entry_get_display_mode (entry);
8730 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8731 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8732 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8734 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8735 mode == DISPLAY_NORMAL &&
8736 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8738 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8739 info_entry_priv->editable && clipboard_contains_text);
8741 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8742 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8743 g_signal_connect_swapped (menuitem, "activate",
8744 G_CALLBACK (gtk_entry_delete_cb), entry);
8745 gtk_widget_show (menuitem);
8746 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8748 menuitem = gtk_separator_menu_item_new ();
8749 gtk_widget_show (menuitem);
8750 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8752 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8753 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8754 g_signal_connect_swapped (menuitem, "activate",
8755 G_CALLBACK (gtk_entry_select_all), entry);
8756 gtk_widget_show (menuitem);
8757 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8759 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8760 "gtk-show-input-method-menu", &show_input_method_menu,
8761 "gtk-show-unicode-menu", &show_unicode_menu,
8764 if (show_input_method_menu || show_unicode_menu)
8766 menuitem = gtk_separator_menu_item_new ();
8767 gtk_widget_show (menuitem);
8768 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8771 if (show_input_method_menu)
8773 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8774 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8775 gtk_widget_show (menuitem);
8776 submenu = gtk_menu_new ();
8777 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8779 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8781 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8782 GTK_MENU_SHELL (submenu));
8785 if (show_unicode_menu)
8787 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8788 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8789 gtk_widget_show (menuitem);
8791 submenu = gtk_menu_new ();
8792 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8793 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8795 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8796 unichar_chosen_func,
8800 g_signal_emit (entry,
8801 signals[POPULATE_POPUP],
8803 info_entry_priv->popup_menu);
8807 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8808 info->device, NULL, NULL, NULL, NULL, NULL,
8809 info->button, info->time);
8812 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8813 popup_position_func, entry,
8814 0, gtk_get_current_event_time ());
8815 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8819 g_object_unref (entry);
8820 g_slice_free (PopupInfo, info);
8824 gtk_entry_do_popup (GtkEntry *entry,
8825 GdkEventButton *event)
8827 PopupInfo *info = g_slice_new (PopupInfo);
8829 /* In order to know what entries we should make sensitive, we
8830 * ask for the current targets of the clipboard, and when
8831 * we get them, then we actually pop up the menu.
8833 info->entry = g_object_ref (entry);
8837 info->button = event->button;
8838 info->time = event->time;
8839 info->device = event->device;
8844 info->time = gtk_get_current_event_time ();
8845 info->device = NULL;
8848 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8849 gdk_atom_intern_static_string ("TARGETS"),
8850 popup_targets_received,
8855 gtk_entry_popup_menu (GtkWidget *widget)
8857 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8862 gtk_entry_drag_begin (GtkWidget *widget,
8863 GdkDragContext *context)
8865 GtkEntry *entry = GTK_ENTRY (widget);
8866 GtkEntryPrivate *priv = entry->priv;
8869 for (i = 0; i < MAX_ICONS; i++)
8871 EntryIconInfo *icon_info = priv->icons[i];
8873 if (icon_info != NULL)
8875 if (icon_info->in_drag)
8879 pix = _gtk_icon_helper_ensure_pixbuf
8880 (icon_info->icon_helper,
8881 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8882 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8884 g_object_unref (pix);
8891 gtk_entry_drag_end (GtkWidget *widget,
8892 GdkDragContext *context)
8894 GtkEntry *entry = GTK_ENTRY (widget);
8895 GtkEntryPrivate *priv = entry->priv;
8898 for (i = 0; i < MAX_ICONS; i++)
8900 EntryIconInfo *icon_info = priv->icons[i];
8902 if (icon_info != NULL)
8903 icon_info->in_drag = 0;
8908 gtk_entry_drag_leave (GtkWidget *widget,
8909 GdkDragContext *context,
8912 GtkEntry *entry = GTK_ENTRY (widget);
8913 GtkEntryPrivate *priv = entry->priv;
8915 priv->dnd_position = -1;
8916 gtk_widget_queue_draw (widget);
8920 gtk_entry_drag_drop (GtkWidget *widget,
8921 GdkDragContext *context,
8926 GtkEntry *entry = GTK_ENTRY (widget);
8927 GtkEntryPrivate *priv = entry->priv;
8928 GdkAtom target = GDK_NONE;
8931 target = gtk_drag_dest_find_target (widget, context, NULL);
8933 if (target != GDK_NONE)
8934 gtk_drag_get_data (widget, context, target, time);
8936 gtk_drag_finish (context, FALSE, FALSE, time);
8942 gtk_entry_drag_motion (GtkWidget *widget,
8943 GdkDragContext *context,
8948 GtkEntry *entry = GTK_ENTRY (widget);
8949 GtkEntryPrivate *priv = entry->priv;
8950 GtkStyleContext *style_context;
8951 GtkWidget *source_widget;
8952 GdkDragAction suggested_action;
8953 gint new_position, old_position;
8957 style_context = gtk_widget_get_style_context (widget);
8958 gtk_style_context_get_padding (style_context, 0, &padding);
8962 old_position = priv->dnd_position;
8963 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8965 if (priv->editable &&
8966 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8968 source_widget = gtk_drag_get_source_widget (context);
8969 suggested_action = gdk_drag_context_get_suggested_action (context);
8971 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8972 new_position < sel1 || new_position > sel2)
8974 if (source_widget == widget)
8976 /* Default to MOVE, unless the user has
8977 * pressed ctrl or alt to affect available actions
8979 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8980 suggested_action = GDK_ACTION_MOVE;
8983 priv->dnd_position = new_position;
8987 if (source_widget == widget)
8988 suggested_action = 0; /* Can't drop in selection where drag started */
8990 priv->dnd_position = -1;
8995 /* Entry not editable, or no text */
8996 suggested_action = 0;
8997 priv->dnd_position = -1;
9000 gdk_drag_status (context, suggested_action, time);
9002 if (priv->dnd_position != old_position)
9003 gtk_widget_queue_draw (widget);
9009 gtk_entry_drag_data_received (GtkWidget *widget,
9010 GdkDragContext *context,
9013 GtkSelectionData *selection_data,
9017 GtkEntry *entry = GTK_ENTRY (widget);
9018 GtkEntryPrivate *priv = entry->priv;
9019 GtkEditable *editable = GTK_EDITABLE (widget);
9020 GtkStyleContext *style_context;
9024 str = (gchar *) gtk_selection_data_get_text (selection_data);
9026 style_context = gtk_widget_get_style_context (widget);
9027 gtk_style_context_get_padding (style_context, 0, &padding);
9031 if (str && priv->editable)
9037 if (priv->truncate_multiline)
9038 length = truncate_multiline (str);
9040 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9042 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9043 new_position < sel1 || new_position > sel2)
9045 gtk_editable_insert_text (editable, str, length, &new_position);
9049 /* Replacing selection */
9050 begin_change (entry);
9051 gtk_editable_delete_text (editable, sel1, sel2);
9052 gtk_editable_insert_text (editable, str, length, &sel1);
9056 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9060 /* Drag and drop didn't happen! */
9061 gtk_drag_finish (context, FALSE, FALSE, time);
9068 gtk_entry_drag_data_get (GtkWidget *widget,
9069 GdkDragContext *context,
9070 GtkSelectionData *selection_data,
9074 GtkEntry *entry = GTK_ENTRY (widget);
9075 GtkEntryPrivate *priv = entry->priv;
9076 GtkEditable *editable = GTK_EDITABLE (widget);
9077 gint sel_start, sel_end;
9080 /* If there is an icon drag going on, exit early. */
9081 for (i = 0; i < MAX_ICONS; i++)
9083 EntryIconInfo *icon_info = priv->icons[i];
9085 if (icon_info != NULL)
9087 if (icon_info->in_drag)
9092 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9094 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9096 gtk_selection_data_set_text (selection_data, str, -1);
9104 gtk_entry_drag_data_delete (GtkWidget *widget,
9105 GdkDragContext *context)
9107 GtkEntry *entry = GTK_ENTRY (widget);
9108 GtkEntryPrivate *priv = entry->priv;
9109 GtkEditable *editable = GTK_EDITABLE (widget);
9110 gint sel_start, sel_end;
9113 /* If there is an icon drag going on, exit early. */
9114 for (i = 0; i < MAX_ICONS; i++)
9116 EntryIconInfo *icon_info = priv->icons[i];
9118 if (icon_info != NULL)
9120 if (icon_info->in_drag)
9125 if (priv->editable &&
9126 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9127 gtk_editable_delete_text (editable, sel_start, sel_end);
9130 /* We display the cursor when
9132 * - the selection is empty, AND
9133 * - the widget has focus
9136 #define CURSOR_ON_MULTIPLIER 2
9137 #define CURSOR_OFF_MULTIPLIER 1
9138 #define CURSOR_PEND_MULTIPLIER 3
9139 #define CURSOR_DIVIDER 3
9142 cursor_blinks (GtkEntry *entry)
9144 GtkEntryPrivate *priv = entry->priv;
9146 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9148 priv->selection_bound == priv->current_pos)
9150 GtkSettings *settings;
9153 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9154 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9163 get_cursor_time (GtkEntry *entry)
9165 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9168 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9174 get_cursor_blink_timeout (GtkEntry *entry)
9176 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9179 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9185 show_cursor (GtkEntry *entry)
9187 GtkEntryPrivate *priv = entry->priv;
9190 if (!priv->cursor_visible)
9192 priv->cursor_visible = TRUE;
9194 widget = GTK_WIDGET (entry);
9195 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9196 gtk_widget_queue_draw (widget);
9201 hide_cursor (GtkEntry *entry)
9203 GtkEntryPrivate *priv = entry->priv;
9206 if (priv->cursor_visible)
9208 priv->cursor_visible = FALSE;
9210 widget = GTK_WIDGET (entry);
9211 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9212 gtk_widget_queue_draw (widget);
9220 blink_cb (gpointer data)
9223 GtkEntryPrivate *priv;
9226 entry = GTK_ENTRY (data);
9229 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9231 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9232 "connect a handler to this signal, it must return\n"
9233 "FALSE so the entry gets the event as well");
9235 gtk_entry_check_cursor_blink (entry);
9240 g_assert (priv->selection_bound == priv->current_pos);
9242 blink_timeout = get_cursor_blink_timeout (entry);
9243 if (priv->blink_time > 1000 * blink_timeout &&
9244 blink_timeout < G_MAXINT/1000)
9246 /* we've blinked enough without the user doing anything, stop blinking */
9247 show_cursor (entry);
9248 priv->blink_timeout = 0;
9250 else if (priv->cursor_visible)
9252 hide_cursor (entry);
9253 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9259 show_cursor (entry);
9260 priv->blink_time += get_cursor_time (entry);
9261 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9266 /* Remove ourselves */
9271 gtk_entry_check_cursor_blink (GtkEntry *entry)
9273 GtkEntryPrivate *priv = entry->priv;
9275 if (cursor_blinks (entry))
9277 if (!priv->blink_timeout)
9279 show_cursor (entry);
9280 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9287 if (priv->blink_timeout)
9289 g_source_remove (priv->blink_timeout);
9290 priv->blink_timeout = 0;
9293 priv->cursor_visible = TRUE;
9298 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9300 GtkEntryPrivate *priv = entry->priv;
9302 if (cursor_blinks (entry))
9304 if (priv->blink_timeout != 0)
9305 g_source_remove (priv->blink_timeout);
9307 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9310 show_cursor (entry);
9315 gtk_entry_reset_blink_time (GtkEntry *entry)
9317 GtkEntryPrivate *priv = entry->priv;
9319 priv->blink_time = 0;
9325 gtk_entry_completion_timeout (gpointer data)
9327 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9328 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9330 completion->priv->completion_timeout = 0;
9332 if (completion->priv->filter_model &&
9333 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9334 >= completion->priv->minimum_key_length)
9338 GtkTreeSelection *s;
9339 gboolean popup_single;
9341 gtk_entry_completion_complete (completion);
9342 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9344 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9346 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9348 gtk_tree_selection_unselect_all (s);
9350 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9352 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9353 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9355 if (gtk_widget_get_visible (completion->priv->popup_window))
9356 _gtk_entry_completion_resize_popup (completion);
9358 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9361 _gtk_entry_completion_popdown (completion);
9363 else if (gtk_widget_get_visible (completion->priv->popup_window))
9364 _gtk_entry_completion_popdown (completion);
9369 static inline gboolean
9370 keyval_is_cursor_move (guint keyval)
9372 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9375 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9378 if (keyval == GDK_KEY_Page_Up)
9381 if (keyval == GDK_KEY_Page_Down)
9388 gtk_entry_completion_key_press (GtkWidget *widget,
9392 gint matches, actions = 0;
9393 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9395 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9398 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9400 if (completion->priv->actions)
9401 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9403 if (keyval_is_cursor_move (event->keyval))
9405 GtkTreePath *path = NULL;
9407 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9409 if (completion->priv->current_selected < 0)
9410 completion->priv->current_selected = matches + actions - 1;
9412 completion->priv->current_selected--;
9414 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9416 if (completion->priv->current_selected < matches + actions - 1)
9417 completion->priv->current_selected++;
9419 completion->priv->current_selected = -1;
9421 else if (event->keyval == GDK_KEY_Page_Up)
9423 if (completion->priv->current_selected < 0)
9424 completion->priv->current_selected = matches + actions - 1;
9425 else if (completion->priv->current_selected == 0)
9426 completion->priv->current_selected = -1;
9427 else if (completion->priv->current_selected < matches)
9429 completion->priv->current_selected -= PAGE_STEP;
9430 if (completion->priv->current_selected < 0)
9431 completion->priv->current_selected = 0;
9435 completion->priv->current_selected -= PAGE_STEP;
9436 if (completion->priv->current_selected < matches - 1)
9437 completion->priv->current_selected = matches - 1;
9440 else if (event->keyval == GDK_KEY_Page_Down)
9442 if (completion->priv->current_selected < 0)
9443 completion->priv->current_selected = 0;
9444 else if (completion->priv->current_selected < matches - 1)
9446 completion->priv->current_selected += PAGE_STEP;
9447 if (completion->priv->current_selected > matches - 1)
9448 completion->priv->current_selected = matches - 1;
9450 else if (completion->priv->current_selected == matches + actions - 1)
9452 completion->priv->current_selected = -1;
9456 completion->priv->current_selected += PAGE_STEP;
9457 if (completion->priv->current_selected > matches + actions - 1)
9458 completion->priv->current_selected = matches + actions - 1;
9462 if (completion->priv->current_selected < 0)
9464 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9465 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9467 if (completion->priv->inline_selection &&
9468 completion->priv->completion_prefix)
9470 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9471 completion->priv->completion_prefix);
9472 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9475 else if (completion->priv->current_selected < matches)
9477 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9479 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9480 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9483 if (completion->priv->inline_selection)
9487 GtkTreeIter child_iter;
9488 GtkTreeModel *model = NULL;
9489 GtkTreeSelection *sel;
9492 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9493 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9496 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9497 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9499 if (completion->priv->completion_prefix == NULL)
9500 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9502 g_signal_emit_by_name (completion, "cursor-on-match", model,
9503 &child_iter, &entry_set);
9506 else if (completion->priv->current_selected - matches >= 0)
9508 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9510 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9511 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9514 if (completion->priv->inline_selection &&
9515 completion->priv->completion_prefix)
9517 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9518 completion->priv->completion_prefix);
9519 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9523 gtk_tree_path_free (path);
9527 else if (event->keyval == GDK_KEY_Escape ||
9528 event->keyval == GDK_KEY_Left ||
9529 event->keyval == GDK_KEY_KP_Left ||
9530 event->keyval == GDK_KEY_Right ||
9531 event->keyval == GDK_KEY_KP_Right)
9533 gboolean retval = TRUE;
9535 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9536 _gtk_entry_completion_popdown (completion);
9538 if (completion->priv->current_selected < 0)
9541 goto keypress_completion_out;
9543 else if (completion->priv->inline_selection)
9545 /* Escape rejects the tentative completion */
9546 if (event->keyval == GDK_KEY_Escape)
9548 if (completion->priv->completion_prefix)
9549 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9550 completion->priv->completion_prefix);
9552 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9555 /* Move the cursor to the end for Right/Esc, to the
9556 beginning for Left */
9557 if (event->keyval == GDK_KEY_Right ||
9558 event->keyval == GDK_KEY_KP_Right ||
9559 event->keyval == GDK_KEY_Escape)
9560 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9562 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9565 keypress_completion_out:
9566 if (completion->priv->inline_selection)
9568 g_free (completion->priv->completion_prefix);
9569 completion->priv->completion_prefix = NULL;
9574 else if (event->keyval == GDK_KEY_Tab ||
9575 event->keyval == GDK_KEY_KP_Tab ||
9576 event->keyval == GDK_KEY_ISO_Left_Tab)
9578 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9579 _gtk_entry_completion_popdown (completion);
9581 g_free (completion->priv->completion_prefix);
9582 completion->priv->completion_prefix = NULL;
9586 else if (event->keyval == GDK_KEY_ISO_Enter ||
9587 event->keyval == GDK_KEY_KP_Enter ||
9588 event->keyval == GDK_KEY_Return)
9591 GtkTreeModel *model = NULL;
9592 GtkTreeModel *child_model;
9593 GtkTreeIter child_iter;
9594 GtkTreeSelection *sel;
9595 gboolean retval = TRUE;
9597 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9598 _gtk_entry_completion_popdown (completion);
9600 if (completion->priv->current_selected < matches)
9604 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9605 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9607 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9608 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9609 g_signal_handler_block (widget, completion->priv->changed_id);
9610 g_signal_emit_by_name (completion, "match-selected",
9611 child_model, &child_iter, &entry_set);
9612 g_signal_handler_unblock (widget, completion->priv->changed_id);
9618 gtk_tree_model_get (model, &iter,
9619 completion->priv->text_column, &str,
9622 gtk_entry_set_text (GTK_ENTRY (widget), str);
9624 /* move the cursor to the end */
9625 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9633 else if (completion->priv->current_selected - matches >= 0)
9635 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9636 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9640 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9641 g_signal_emit_by_name (completion, "action-activated",
9642 gtk_tree_path_get_indices (path)[0]);
9643 gtk_tree_path_free (path);
9649 g_free (completion->priv->completion_prefix);
9650 completion->priv->completion_prefix = NULL;
9659 gtk_entry_completion_changed (GtkWidget *widget,
9662 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9663 GtkEntry *entry = GTK_ENTRY (widget);
9664 GtkEntryPrivate *priv = entry->priv;
9667 /* (re)install completion timeout */
9668 if (completion->priv->completion_timeout)
9669 g_source_remove (completion->priv->completion_timeout);
9671 if (!gtk_entry_get_text (entry))
9674 /* no need to normalize for this test */
9675 if (completion->priv->minimum_key_length > 0 &&
9676 strcmp ("", gtk_entry_get_text (entry)) == 0)
9678 if (gtk_widget_get_visible (completion->priv->popup_window))
9679 _gtk_entry_completion_popdown (completion);
9683 device = gtk_get_current_event_device ();
9685 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9686 device = gdk_device_get_associated_device (device);
9689 priv->completion_device = device;
9691 completion->priv->completion_timeout =
9692 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9693 gtk_entry_completion_timeout,
9698 check_completion_callback (GtkEntryCompletion *completion)
9700 completion->priv->check_completion_idle = NULL;
9702 gtk_entry_completion_complete (completion);
9703 gtk_entry_completion_insert_prefix (completion);
9709 clear_completion_callback (GtkEntry *entry,
9712 if (pspec->name == I_("cursor-position") ||
9713 pspec->name == I_("selection-bound"))
9715 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9717 completion->priv->has_completion = FALSE;
9722 accept_completion_callback (GtkEntry *entry)
9724 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9726 if (completion->priv->has_completion)
9727 gtk_editable_set_position (GTK_EDITABLE (entry),
9728 gtk_entry_buffer_get_length (get_buffer (entry)));
9734 completion_insert_text_callback (GtkEntry *entry,
9738 GtkEntryCompletion *completion)
9740 /* idle to update the selection based on the file list */
9741 if (completion->priv->check_completion_idle == NULL)
9743 completion->priv->check_completion_idle = g_idle_source_new ();
9744 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9745 g_source_set_closure (completion->priv->check_completion_idle,
9746 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9747 G_OBJECT (completion)));
9748 g_source_attach (completion->priv->check_completion_idle, NULL);
9753 completion_changed (GtkEntryCompletion *completion,
9757 GtkEntry *entry = GTK_ENTRY (data);
9759 if (pspec->name == I_("popup-completion") ||
9760 pspec->name == I_("inline-completion"))
9762 disconnect_completion_signals (entry, completion);
9763 connect_completion_signals (entry, completion);
9768 disconnect_completion_signals (GtkEntry *entry,
9769 GtkEntryCompletion *completion)
9771 g_signal_handlers_disconnect_by_func (completion,
9772 G_CALLBACK (completion_changed), entry);
9773 if (completion->priv->changed_id > 0 &&
9774 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9776 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9777 completion->priv->changed_id = 0;
9779 g_signal_handlers_disconnect_by_func (entry,
9780 G_CALLBACK (gtk_entry_completion_key_press), completion);
9781 if (completion->priv->insert_text_id > 0 &&
9782 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9784 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9785 completion->priv->insert_text_id = 0;
9787 g_signal_handlers_disconnect_by_func (entry,
9788 G_CALLBACK (completion_insert_text_callback), completion);
9789 g_signal_handlers_disconnect_by_func (entry,
9790 G_CALLBACK (clear_completion_callback), completion);
9791 g_signal_handlers_disconnect_by_func (entry,
9792 G_CALLBACK (accept_completion_callback), completion);
9796 connect_completion_signals (GtkEntry *entry,
9797 GtkEntryCompletion *completion)
9799 if (completion->priv->popup_completion)
9801 completion->priv->changed_id =
9802 g_signal_connect (entry, "changed",
9803 G_CALLBACK (gtk_entry_completion_changed), completion);
9804 g_signal_connect (entry, "key-press-event",
9805 G_CALLBACK (gtk_entry_completion_key_press), completion);
9808 if (completion->priv->inline_completion)
9810 completion->priv->insert_text_id =
9811 g_signal_connect (entry, "insert-text",
9812 G_CALLBACK (completion_insert_text_callback), completion);
9813 g_signal_connect (entry, "notify",
9814 G_CALLBACK (clear_completion_callback), completion);
9815 g_signal_connect (entry, "activate",
9816 G_CALLBACK (accept_completion_callback), completion);
9817 g_signal_connect (entry, "focus-out-event",
9818 G_CALLBACK (accept_completion_callback), completion);
9821 g_signal_connect (completion, "notify",
9822 G_CALLBACK (completion_changed), entry);
9826 * gtk_entry_set_completion:
9827 * @entry: A #GtkEntry
9828 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9830 * Sets @completion to be the auxiliary completion object to use with @entry.
9831 * All further configuration of the completion mechanism is done on
9832 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9833 * @completion is set to %NULL.
9838 gtk_entry_set_completion (GtkEntry *entry,
9839 GtkEntryCompletion *completion)
9841 GtkEntryCompletion *old;
9843 g_return_if_fail (GTK_IS_ENTRY (entry));
9844 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9846 old = gtk_entry_get_completion (entry);
9848 if (old == completion)
9853 if (old->priv->completion_timeout)
9855 g_source_remove (old->priv->completion_timeout);
9856 old->priv->completion_timeout = 0;
9859 if (old->priv->check_completion_idle)
9861 g_source_destroy (old->priv->check_completion_idle);
9862 old->priv->check_completion_idle = NULL;
9865 if (gtk_widget_get_mapped (old->priv->popup_window))
9866 _gtk_entry_completion_popdown (old);
9868 disconnect_completion_signals (entry, old);
9869 old->priv->entry = NULL;
9871 g_object_unref (old);
9876 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9880 /* hook into the entry */
9881 g_object_ref (completion);
9883 connect_completion_signals (entry, completion);
9884 completion->priv->entry = GTK_WIDGET (entry);
9885 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9887 g_object_notify (G_OBJECT (entry), "completion");
9891 * gtk_entry_get_completion:
9892 * @entry: A #GtkEntry
9894 * Returns the auxiliary completion object currently in use by @entry.
9896 * Return value: (transfer none): The auxiliary completion object currently
9901 GtkEntryCompletion *
9902 gtk_entry_get_completion (GtkEntry *entry)
9904 GtkEntryCompletion *completion;
9906 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9908 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9909 GTK_ENTRY_COMPLETION_KEY));
9915 * gtk_entry_set_cursor_hadjustment:
9916 * @entry: a #GtkEntry
9917 * @adjustment: an adjustment which should be adjusted when the cursor
9918 * is moved, or %NULL
9920 * Hooks up an adjustment to the cursor position in an entry, so that when
9921 * the cursor is moved, the adjustment is scrolled to show that position.
9922 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9925 * The adjustment has to be in pixel units and in the same coordinate system
9931 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9932 GtkAdjustment *adjustment)
9934 g_return_if_fail (GTK_IS_ENTRY (entry));
9936 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9939 g_object_ref (adjustment);
9941 g_object_set_qdata_full (G_OBJECT (entry),
9942 quark_cursor_hadjustment,
9948 * gtk_entry_get_cursor_hadjustment:
9949 * @entry: a #GtkEntry
9951 * Retrieves the horizontal cursor adjustment for the entry.
9952 * See gtk_entry_set_cursor_hadjustment().
9954 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9955 * if none has been set.
9960 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9962 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9964 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9968 * gtk_entry_set_progress_fraction:
9969 * @entry: a #GtkEntry
9970 * @fraction: fraction of the task that's been completed
9972 * Causes the entry's progress indicator to "fill in" the given
9973 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9979 gtk_entry_set_progress_fraction (GtkEntry *entry,
9983 GtkEntryPrivate *private;
9984 gdouble old_fraction;
9985 gint x, y, width, height;
9986 gint old_x, old_y, old_width, old_height;
9988 g_return_if_fail (GTK_IS_ENTRY (entry));
9990 widget = GTK_WIDGET (entry);
9991 private = entry->priv;
9993 if (private->progress_pulse_mode)
9996 old_fraction = private->progress_fraction;
9998 if (gtk_widget_is_drawable (widget))
9999 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10001 fraction = CLAMP (fraction, 0.0, 1.0);
10003 private->progress_fraction = fraction;
10004 private->progress_pulse_mode = FALSE;
10005 private->progress_pulse_current = 0.0;
10007 if (gtk_widget_is_drawable (widget))
10009 get_progress_area (widget, &x, &y, &width, &height);
10011 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10012 gtk_widget_queue_draw (widget);
10015 if (fraction != old_fraction)
10016 g_object_notify (G_OBJECT (entry), "progress-fraction");
10020 * gtk_entry_get_progress_fraction:
10021 * @entry: a #GtkEntry
10023 * Returns the current fraction of the task that's been completed.
10024 * See gtk_entry_set_progress_fraction().
10026 * Return value: a fraction from 0.0 to 1.0
10031 gtk_entry_get_progress_fraction (GtkEntry *entry)
10033 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10035 return entry->priv->progress_fraction;
10039 * gtk_entry_set_progress_pulse_step:
10040 * @entry: a #GtkEntry
10041 * @fraction: fraction between 0.0 and 1.0
10043 * Sets the fraction of total entry width to move the progress
10044 * bouncing block for each call to gtk_entry_progress_pulse().
10049 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10052 GtkEntryPrivate *private;
10054 g_return_if_fail (GTK_IS_ENTRY (entry));
10056 private = entry->priv;
10058 fraction = CLAMP (fraction, 0.0, 1.0);
10060 if (fraction != private->progress_pulse_fraction)
10062 private->progress_pulse_fraction = fraction;
10064 gtk_widget_queue_draw (GTK_WIDGET (entry));
10066 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10071 * gtk_entry_get_progress_pulse_step:
10072 * @entry: a #GtkEntry
10074 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10076 * Return value: a fraction from 0.0 to 1.0
10081 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10083 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10085 return entry->priv->progress_pulse_fraction;
10089 * gtk_entry_progress_pulse:
10090 * @entry: a #GtkEntry
10092 * Indicates that some progress is made, but you don't know how much.
10093 * Causes the entry's progress indicator to enter "activity mode,"
10094 * where a block bounces back and forth. Each call to
10095 * gtk_entry_progress_pulse() causes the block to move by a little bit
10096 * (the amount of movement per pulse is determined by
10097 * gtk_entry_set_progress_pulse_step()).
10102 gtk_entry_progress_pulse (GtkEntry *entry)
10104 GtkEntryPrivate *private;
10106 g_return_if_fail (GTK_IS_ENTRY (entry));
10108 private = entry->priv;
10110 if (private->progress_pulse_mode)
10112 if (private->progress_pulse_way_back)
10114 private->progress_pulse_current -= private->progress_pulse_fraction;
10116 if (private->progress_pulse_current < 0.0)
10118 private->progress_pulse_current = 0.0;
10119 private->progress_pulse_way_back = FALSE;
10124 private->progress_pulse_current += private->progress_pulse_fraction;
10126 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10128 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10129 private->progress_pulse_way_back = TRUE;
10135 private->progress_fraction = 0.0;
10136 private->progress_pulse_mode = TRUE;
10137 private->progress_pulse_way_back = FALSE;
10138 private->progress_pulse_current = 0.0;
10141 gtk_widget_queue_draw (GTK_WIDGET (entry));
10145 * gtk_entry_set_placeholder_text:
10146 * @entry: a #GtkEntry
10147 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10149 * Sets text to be displayed in @entry when it is empty and unfocused.
10150 * This can be used to give a visual hint of the expected contents of
10153 * Note that since the placeholder text gets removed when the entry
10154 * received focus, using this feature is a bit problematic if the entry
10155 * is given the initial focus in a window. Sometimes this can be
10156 * worked around by delaying the initial focus setting until the
10157 * first key event arrives.
10162 gtk_entry_set_placeholder_text (GtkEntry *entry,
10165 GtkEntryPrivate *priv;
10167 g_return_if_fail (GTK_IS_ENTRY (entry));
10169 priv = entry->priv;
10171 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10174 g_free (priv->placeholder_text);
10175 priv->placeholder_text = g_strdup (text);
10177 gtk_entry_recompute (entry);
10179 g_object_notify (G_OBJECT (entry), "placeholder-text");
10183 * gtk_entry_get_placeholder_text:
10184 * @entry: a #GtkEntry
10186 * Retrieves the text that will be displayed when @entry is empty and unfocused
10188 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10189 * storage in the widget and must not be freed, modified or stored.
10194 gtk_entry_get_placeholder_text (GtkEntry *entry)
10196 GtkEntryPrivate *priv;
10198 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10200 priv = entry->priv;
10202 return priv->placeholder_text;
10205 /* Caps Lock warning for password entries */
10208 show_capslock_feedback (GtkEntry *entry,
10211 GtkEntryPrivate *priv = entry->priv;
10213 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10215 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10216 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10217 priv->caps_lock_warning_shown = TRUE;
10220 if (priv->caps_lock_warning_shown)
10221 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10223 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10227 remove_capslock_feedback (GtkEntry *entry)
10229 GtkEntryPrivate *priv = entry->priv;
10231 if (priv->caps_lock_warning_shown)
10233 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10234 priv->caps_lock_warning_shown = FALSE;
10239 keymap_state_changed (GdkKeymap *keymap,
10242 GtkEntryPrivate *priv = entry->priv;
10245 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10247 if (gdk_keymap_get_num_lock_state (keymap)
10248 && gdk_keymap_get_caps_lock_state (keymap))
10249 text = _("Caps Lock and Num Lock are on");
10250 else if (gdk_keymap_get_num_lock_state (keymap))
10251 text = _("Num Lock is on");
10252 else if (gdk_keymap_get_caps_lock_state (keymap))
10253 text = _("Caps Lock is on");
10257 show_capslock_feedback (entry, text);
10259 remove_capslock_feedback (entry);
10263 * _gtk_entry_set_is_cell_renderer:
10264 * @entry: a #GtkEntry
10265 * @is_cell_renderer: new value
10267 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10268 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10270 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10274 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10275 gboolean is_cell_renderer)
10277 entry->priv->is_cell_renderer = is_cell_renderer;