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;
150 GdkDevice *completion_device;
151 GdkWindow *text_area;
153 PangoLayout *cached_layout;
157 gdouble progress_fraction;
158 gdouble progress_pulse_fraction;
159 gdouble progress_pulse_current;
161 gchar *placeholder_text;
165 gint ascent; /* font ascent in pango units */
167 gint descent; /* font descent in pango units */
168 gint dnd_position; /* In chars, -1 == no DND cursor */
173 gint selection_bound;
179 gunichar invisible_char;
182 guint blink_time; /* time in msec the cursor has blinked since last user event */
184 guint recompute_idle;
186 guint16 x_text_size; /* allocated size, in bytes */
187 guint16 x_n_bytes; /* length in use, in bytes */
189 guint16 preedit_length; /* length of preedit string, in bytes */
190 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
194 guint overwrite_mode : 1;
197 guint activates_default : 1;
198 guint cache_includes_preedit : 1;
199 guint caps_lock_warning : 1;
200 guint caps_lock_warning_shown : 1;
201 guint change_count : 8;
202 guint cursor_visible : 1;
203 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
205 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
206 guint is_cell_renderer : 1;
207 guint invisible_char_set : 1;
208 guint interior_focus : 1;
209 guint mouse_cursor_obscured : 1;
210 guint need_im_reset : 1;
211 guint progress_pulse_mode : 1;
212 guint progress_pulse_way_back : 1;
213 guint real_changed : 1;
214 guint resolved_dir : 4; /* PangoDirection */
215 guint select_words : 1;
216 guint select_lines : 1;
217 guint truncate_multiline : 1;
220 struct _EntryIconInfo
224 guint insensitive : 1;
225 guint nonactivatable : 1;
230 GtkIconHelper *icon_helper;
232 GtkTargetList *target_list;
233 GdkDragAction actions;
236 struct _GtkEntryPasswordHint
238 gint position; /* Position (in text) of the last password hint */
239 guint source_id; /* Timeout source id */
242 struct _GtkEntryCapslockFeedback
269 PROP_CURSOR_POSITION,
270 PROP_SELECTION_BOUND,
277 PROP_ACTIVATES_DEFAULT,
282 PROP_TRUNCATE_MULTILINE,
286 PROP_INVISIBLE_CHAR_SET,
287 PROP_CAPS_LOCK_WARNING,
288 PROP_PROGRESS_FRACTION,
289 PROP_PROGRESS_PULSE_STEP,
291 PROP_PIXBUF_SECONDARY,
293 PROP_STOCK_SECONDARY,
294 PROP_ICON_NAME_PRIMARY,
295 PROP_ICON_NAME_SECONDARY,
297 PROP_GICON_SECONDARY,
298 PROP_STORAGE_TYPE_PRIMARY,
299 PROP_STORAGE_TYPE_SECONDARY,
300 PROP_ACTIVATABLE_PRIMARY,
301 PROP_ACTIVATABLE_SECONDARY,
302 PROP_SENSITIVE_PRIMARY,
303 PROP_SENSITIVE_SECONDARY,
304 PROP_TOOLTIP_TEXT_PRIMARY,
305 PROP_TOOLTIP_TEXT_SECONDARY,
306 PROP_TOOLTIP_MARKUP_PRIMARY,
307 PROP_TOOLTIP_MARKUP_SECONDARY,
309 PROP_EDITING_CANCELED,
310 PROP_PLACEHOLDER_TEXT,
314 static guint signals[LAST_SIGNAL] = { 0 };
323 DISPLAY_NORMAL, /* The entry text is being shown */
324 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
325 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
330 static void gtk_entry_editable_init (GtkEditableInterface *iface);
331 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
332 static void gtk_entry_set_property (GObject *object,
336 static void gtk_entry_get_property (GObject *object,
340 static void gtk_entry_finalize (GObject *object);
341 static void gtk_entry_dispose (GObject *object);
345 static void gtk_entry_destroy (GtkWidget *widget);
346 static void gtk_entry_realize (GtkWidget *widget);
347 static void gtk_entry_unrealize (GtkWidget *widget);
348 static void gtk_entry_map (GtkWidget *widget);
349 static void gtk_entry_unmap (GtkWidget *widget);
350 static void gtk_entry_get_preferred_width (GtkWidget *widget,
353 static void gtk_entry_get_preferred_height (GtkWidget *widget,
356 static void gtk_entry_size_allocate (GtkWidget *widget,
357 GtkAllocation *allocation);
358 static void gtk_entry_draw_frame (GtkWidget *widget,
359 GtkStyleContext *context,
361 static void gtk_entry_draw_progress (GtkWidget *widget,
362 GtkStyleContext *context,
364 static gint gtk_entry_draw (GtkWidget *widget,
366 static gint gtk_entry_button_press (GtkWidget *widget,
367 GdkEventButton *event);
368 static gint gtk_entry_button_release (GtkWidget *widget,
369 GdkEventButton *event);
370 static gint gtk_entry_enter_notify (GtkWidget *widget,
371 GdkEventCrossing *event);
372 static gint gtk_entry_leave_notify (GtkWidget *widget,
373 GdkEventCrossing *event);
374 static gint gtk_entry_motion_notify (GtkWidget *widget,
375 GdkEventMotion *event);
376 static gint gtk_entry_key_press (GtkWidget *widget,
378 static gint gtk_entry_key_release (GtkWidget *widget,
380 static gint gtk_entry_focus_in (GtkWidget *widget,
381 GdkEventFocus *event);
382 static gint gtk_entry_focus_out (GtkWidget *widget,
383 GdkEventFocus *event);
384 static void gtk_entry_grab_focus (GtkWidget *widget);
385 static void gtk_entry_style_updated (GtkWidget *widget);
386 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
389 gboolean keyboard_tip,
390 GtkTooltip *tooltip);
391 static void gtk_entry_direction_changed (GtkWidget *widget,
392 GtkTextDirection previous_dir);
393 static void gtk_entry_state_flags_changed (GtkWidget *widget,
394 GtkStateFlags previous_state);
395 static void gtk_entry_screen_changed (GtkWidget *widget,
396 GdkScreen *old_screen);
398 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
399 GdkDragContext *context,
403 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
404 GdkDragContext *context,
408 static void gtk_entry_drag_leave (GtkWidget *widget,
409 GdkDragContext *context,
411 static void gtk_entry_drag_data_received (GtkWidget *widget,
412 GdkDragContext *context,
415 GtkSelectionData *selection_data,
418 static void gtk_entry_drag_data_get (GtkWidget *widget,
419 GdkDragContext *context,
420 GtkSelectionData *selection_data,
423 static void gtk_entry_drag_data_delete (GtkWidget *widget,
424 GdkDragContext *context);
425 static void gtk_entry_drag_begin (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_entry_drag_end (GtkWidget *widget,
428 GdkDragContext *context);
431 /* GtkEditable method implementations
433 static void gtk_entry_insert_text (GtkEditable *editable,
434 const gchar *new_text,
435 gint new_text_length,
437 static void gtk_entry_delete_text (GtkEditable *editable,
440 static gchar * gtk_entry_get_chars (GtkEditable *editable,
443 static void gtk_entry_real_set_position (GtkEditable *editable,
445 static gint gtk_entry_get_position (GtkEditable *editable);
446 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
449 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
453 /* GtkCellEditable method implementations
455 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
458 /* Default signal handlers
460 static void gtk_entry_real_insert_text (GtkEditable *editable,
461 const gchar *new_text,
462 gint new_text_length,
464 static void gtk_entry_real_delete_text (GtkEditable *editable,
467 static void gtk_entry_move_cursor (GtkEntry *entry,
468 GtkMovementStep step,
470 gboolean extend_selection);
471 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
473 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
476 static void gtk_entry_backspace (GtkEntry *entry);
477 static void gtk_entry_cut_clipboard (GtkEntry *entry);
478 static void gtk_entry_copy_clipboard (GtkEntry *entry);
479 static void gtk_entry_paste_clipboard (GtkEntry *entry);
480 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
481 static void gtk_entry_select_all (GtkEntry *entry);
482 static void gtk_entry_real_activate (GtkEntry *entry);
483 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
485 static void keymap_direction_changed (GdkKeymap *keymap,
487 static void keymap_state_changed (GdkKeymap *keymap,
489 static void remove_capslock_feedback (GtkEntry *entry);
491 /* IM Context Callbacks
493 static void gtk_entry_commit_cb (GtkIMContext *context,
496 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
498 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
500 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
507 static void gtk_entry_enter_text (GtkEntry *entry,
509 static void gtk_entry_set_positions (GtkEntry *entry,
511 gint selection_bound);
512 static void gtk_entry_draw_text (GtkEntry *entry,
514 static void gtk_entry_draw_cursor (GtkEntry *entry,
517 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
518 gboolean include_preedit);
519 static void gtk_entry_reset_layout (GtkEntry *entry);
520 static void gtk_entry_recompute (GtkEntry *entry);
521 static gint gtk_entry_find_position (GtkEntry *entry,
523 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
527 static void gtk_entry_adjust_scroll (GtkEntry *entry);
528 static gint gtk_entry_move_visually (GtkEntry *editable,
531 static gint gtk_entry_move_logically (GtkEntry *entry,
534 static gint gtk_entry_move_forward_word (GtkEntry *entry,
536 gboolean allow_whitespace);
537 static gint gtk_entry_move_backward_word (GtkEntry *entry,
539 gboolean allow_whitespace);
540 static void gtk_entry_delete_whitespace (GtkEntry *entry);
541 static void gtk_entry_select_word (GtkEntry *entry);
542 static void gtk_entry_select_line (GtkEntry *entry);
543 static void gtk_entry_paste (GtkEntry *entry,
545 static void gtk_entry_update_primary_selection (GtkEntry *entry);
546 static void gtk_entry_do_popup (GtkEntry *entry,
547 GdkEventButton *event);
548 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
549 gboolean group_cycling);
550 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
551 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
552 static void gtk_entry_reset_blink_time (GtkEntry *entry);
553 static void gtk_entry_get_text_area_size (GtkEntry *entry,
558 static void get_text_area_size (GtkEntry *entry,
563 static void get_frame_size (GtkEntry *entry,
564 gboolean relative_to_window,
569 static void gtk_entry_move_adjustments (GtkEntry *entry);
570 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
571 GtkEntryIconPosition icon_pos);
572 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
575 static gint gtk_entry_completion_timeout (gpointer data);
576 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
579 static void gtk_entry_completion_changed (GtkWidget *entry,
581 static gboolean check_completion_callback (GtkEntryCompletion *completion);
582 static void clear_completion_callback (GtkEntry *entry,
584 static gboolean accept_completion_callback (GtkEntry *entry);
585 static void completion_insert_text_callback (GtkEntry *entry,
589 GtkEntryCompletion *completion);
590 static void completion_changed (GtkEntryCompletion *completion,
593 static void disconnect_completion_signals (GtkEntry *entry,
594 GtkEntryCompletion *completion);
595 static void connect_completion_signals (GtkEntry *entry,
596 GtkEntryCompletion *completion);
598 static void begin_change (GtkEntry *entry);
599 static void end_change (GtkEntry *entry);
600 static void emit_changed (GtkEntry *entry);
602 static void buffer_inserted_text (GtkEntryBuffer *buffer,
607 static void buffer_deleted_text (GtkEntryBuffer *buffer,
611 static void buffer_notify_text (GtkEntryBuffer *buffer,
614 static void buffer_notify_length (GtkEntryBuffer *buffer,
617 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
620 static void buffer_connect_signals (GtkEntry *entry);
621 static void buffer_disconnect_signals (GtkEntry *entry);
622 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
624 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
625 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
626 gtk_entry_editable_init)
627 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
628 gtk_entry_cell_editable_init))
631 add_move_binding (GtkBindingSet *binding_set,
634 GtkMovementStep step,
637 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
639 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
643 G_TYPE_BOOLEAN, FALSE);
645 /* Selection-extending version */
646 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
650 G_TYPE_BOOLEAN, TRUE);
654 gtk_entry_class_init (GtkEntryClass *class)
656 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
657 GtkWidgetClass *widget_class;
658 GtkBindingSet *binding_set;
660 widget_class = (GtkWidgetClass*) class;
662 gobject_class->dispose = gtk_entry_dispose;
663 gobject_class->finalize = gtk_entry_finalize;
664 gobject_class->set_property = gtk_entry_set_property;
665 gobject_class->get_property = gtk_entry_get_property;
667 widget_class->destroy = gtk_entry_destroy;
668 widget_class->map = gtk_entry_map;
669 widget_class->unmap = gtk_entry_unmap;
670 widget_class->realize = gtk_entry_realize;
671 widget_class->unrealize = gtk_entry_unrealize;
672 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
673 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
674 widget_class->size_allocate = gtk_entry_size_allocate;
675 widget_class->draw = gtk_entry_draw;
676 widget_class->enter_notify_event = gtk_entry_enter_notify;
677 widget_class->leave_notify_event = gtk_entry_leave_notify;
678 widget_class->button_press_event = gtk_entry_button_press;
679 widget_class->button_release_event = gtk_entry_button_release;
680 widget_class->motion_notify_event = gtk_entry_motion_notify;
681 widget_class->key_press_event = gtk_entry_key_press;
682 widget_class->key_release_event = gtk_entry_key_release;
683 widget_class->focus_in_event = gtk_entry_focus_in;
684 widget_class->focus_out_event = gtk_entry_focus_out;
685 widget_class->grab_focus = gtk_entry_grab_focus;
686 widget_class->style_updated = gtk_entry_style_updated;
687 widget_class->query_tooltip = gtk_entry_query_tooltip;
688 widget_class->drag_begin = gtk_entry_drag_begin;
689 widget_class->drag_end = gtk_entry_drag_end;
690 widget_class->direction_changed = gtk_entry_direction_changed;
691 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
692 widget_class->screen_changed = gtk_entry_screen_changed;
693 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
695 widget_class->drag_drop = gtk_entry_drag_drop;
696 widget_class->drag_motion = gtk_entry_drag_motion;
697 widget_class->drag_leave = gtk_entry_drag_leave;
698 widget_class->drag_data_received = gtk_entry_drag_data_received;
699 widget_class->drag_data_get = gtk_entry_drag_data_get;
700 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
702 widget_class->popup_menu = gtk_entry_popup_menu;
704 class->move_cursor = gtk_entry_move_cursor;
705 class->insert_at_cursor = gtk_entry_insert_at_cursor;
706 class->delete_from_cursor = gtk_entry_delete_from_cursor;
707 class->backspace = gtk_entry_backspace;
708 class->cut_clipboard = gtk_entry_cut_clipboard;
709 class->copy_clipboard = gtk_entry_copy_clipboard;
710 class->paste_clipboard = gtk_entry_paste_clipboard;
711 class->toggle_overwrite = gtk_entry_toggle_overwrite;
712 class->activate = gtk_entry_real_activate;
713 class->get_text_area_size = gtk_entry_get_text_area_size;
715 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
716 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
717 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
718 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
720 g_object_class_override_property (gobject_class,
721 PROP_EDITING_CANCELED,
724 g_object_class_install_property (gobject_class,
726 g_param_spec_object ("buffer",
728 P_("Text buffer object which actually stores entry text"),
729 GTK_TYPE_ENTRY_BUFFER,
730 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
732 g_object_class_install_property (gobject_class,
733 PROP_CURSOR_POSITION,
734 g_param_spec_int ("cursor-position",
735 P_("Cursor Position"),
736 P_("The current position of the insertion cursor in chars"),
738 GTK_ENTRY_BUFFER_MAX_SIZE,
740 GTK_PARAM_READABLE));
742 g_object_class_install_property (gobject_class,
743 PROP_SELECTION_BOUND,
744 g_param_spec_int ("selection-bound",
745 P_("Selection Bound"),
746 P_("The position of the opposite end of the selection from the cursor in chars"),
748 GTK_ENTRY_BUFFER_MAX_SIZE,
750 GTK_PARAM_READABLE));
752 g_object_class_install_property (gobject_class,
754 g_param_spec_boolean ("editable",
756 P_("Whether the entry contents can be edited"),
758 GTK_PARAM_READWRITE));
760 g_object_class_install_property (gobject_class,
762 g_param_spec_int ("max-length",
763 P_("Maximum length"),
764 P_("Maximum number of characters for this entry. Zero if no maximum"),
766 GTK_ENTRY_BUFFER_MAX_SIZE,
768 GTK_PARAM_READWRITE));
769 g_object_class_install_property (gobject_class,
771 g_param_spec_boolean ("visibility",
773 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
775 GTK_PARAM_READWRITE));
777 g_object_class_install_property (gobject_class,
779 g_param_spec_boolean ("has-frame",
781 P_("FALSE removes outside bevel from entry"),
783 GTK_PARAM_READWRITE));
786 * GtkEntry:inner-border:
788 * Sets the text area's border between the text and the frame.
790 * Deprecated: 3.4: Use the standard border and padding CSS properties;
791 * the value of this style property is ignored.
793 g_object_class_install_property (gobject_class,
795 g_param_spec_boxed ("inner-border",
797 P_("Border between text and frame. Overrides the inner-border style property"),
799 GTK_PARAM_READWRITE |
800 G_PARAM_DEPRECATED));
802 g_object_class_install_property (gobject_class,
804 g_param_spec_unichar ("invisible-char",
805 P_("Invisible character"),
806 P_("The character to use when masking entry contents (in \"password mode\")"),
808 GTK_PARAM_READWRITE));
810 g_object_class_install_property (gobject_class,
811 PROP_ACTIVATES_DEFAULT,
812 g_param_spec_boolean ("activates-default",
813 P_("Activates default"),
814 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
816 GTK_PARAM_READWRITE));
817 g_object_class_install_property (gobject_class,
819 g_param_spec_int ("width-chars",
820 P_("Width in chars"),
821 P_("Number of characters to leave space for in the entry"),
825 GTK_PARAM_READWRITE));
827 g_object_class_install_property (gobject_class,
829 g_param_spec_int ("scroll-offset",
831 P_("Number of pixels of the entry scrolled off the screen to the left"),
835 GTK_PARAM_READABLE));
837 g_object_class_install_property (gobject_class,
839 g_param_spec_string ("text",
841 P_("The contents of the entry"),
843 GTK_PARAM_READWRITE));
848 * The horizontal alignment, from 0 (left) to 1 (right).
849 * Reversed for RTL layouts.
853 g_object_class_install_property (gobject_class,
855 g_param_spec_float ("xalign",
857 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
861 GTK_PARAM_READWRITE));
864 * GtkEntry:truncate-multiline:
866 * When %TRUE, pasted multi-line text is truncated to the first line.
870 g_object_class_install_property (gobject_class,
871 PROP_TRUNCATE_MULTILINE,
872 g_param_spec_boolean ("truncate-multiline",
873 P_("Truncate multiline"),
874 P_("Whether to truncate multiline pastes to one line."),
876 GTK_PARAM_READWRITE));
879 * GtkEntry:shadow-type:
881 * Which kind of shadow to draw around the entry when
882 * #GtkEntry:has-frame is set to %TRUE.
886 g_object_class_install_property (gobject_class,
888 g_param_spec_enum ("shadow-type",
890 P_("Which kind of shadow to draw around the entry when has-frame is set"),
891 GTK_TYPE_SHADOW_TYPE,
893 GTK_PARAM_READWRITE));
896 * GtkEntry:overwrite-mode:
898 * If text is overwritten when typing in the #GtkEntry.
902 g_object_class_install_property (gobject_class,
904 g_param_spec_boolean ("overwrite-mode",
905 P_("Overwrite mode"),
906 P_("Whether new text overwrites existing text"),
908 GTK_PARAM_READWRITE));
911 * GtkEntry:text-length:
913 * The length of the text in the #GtkEntry.
917 g_object_class_install_property (gobject_class,
919 g_param_spec_uint ("text-length",
921 P_("Length of the text currently in the entry"),
925 GTK_PARAM_READABLE));
927 * GtkEntry:invisible-char-set:
929 * Whether the invisible char has been set for the #GtkEntry.
933 g_object_class_install_property (gobject_class,
934 PROP_INVISIBLE_CHAR_SET,
935 g_param_spec_boolean ("invisible-char-set",
936 P_("Invisible character set"),
937 P_("Whether the invisible character has been set"),
939 GTK_PARAM_READWRITE));
942 * GtkEntry:caps-lock-warning
944 * Whether password entries will show a warning when Caps Lock is on.
946 * Note that the warning is shown using a secondary icon, and thus
947 * does not work if you are using the secondary icon position for some
952 g_object_class_install_property (gobject_class,
953 PROP_CAPS_LOCK_WARNING,
954 g_param_spec_boolean ("caps-lock-warning",
955 P_("Caps Lock warning"),
956 P_("Whether password entries will show a warning when Caps Lock is on"),
958 GTK_PARAM_READWRITE));
961 * GtkEntry:progress-fraction:
963 * The current fraction of the task that's been completed.
967 g_object_class_install_property (gobject_class,
968 PROP_PROGRESS_FRACTION,
969 g_param_spec_double ("progress-fraction",
970 P_("Progress Fraction"),
971 P_("The current fraction of the task that's been completed"),
975 GTK_PARAM_READWRITE));
978 * GtkEntry:progress-pulse-step:
980 * The fraction of total entry width to move the progress
981 * bouncing block for each call to gtk_entry_progress_pulse().
985 g_object_class_install_property (gobject_class,
986 PROP_PROGRESS_PULSE_STEP,
987 g_param_spec_double ("progress-pulse-step",
988 P_("Progress Pulse Step"),
989 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
993 GTK_PARAM_READWRITE));
996 * GtkEntry:placeholder-text:
998 * The text that will be displayed in the #GtkEntry when it is empty
1003 g_object_class_install_property (gobject_class,
1004 PROP_PLACEHOLDER_TEXT,
1005 g_param_spec_string ("placeholder-text",
1006 P_("Placeholder text"),
1007 P_("Show text in the entry when it's empty and unfocused"),
1009 GTK_PARAM_READWRITE));
1012 * GtkEntry:primary-icon-pixbuf:
1014 * A pixbuf to use as the primary icon for the entry.
1018 g_object_class_install_property (gobject_class,
1019 PROP_PIXBUF_PRIMARY,
1020 g_param_spec_object ("primary-icon-pixbuf",
1021 P_("Primary pixbuf"),
1022 P_("Primary pixbuf for the entry"),
1024 GTK_PARAM_READWRITE));
1027 * GtkEntry:secondary-icon-pixbuf:
1029 * An pixbuf to use as the secondary icon for the entry.
1033 g_object_class_install_property (gobject_class,
1034 PROP_PIXBUF_SECONDARY,
1035 g_param_spec_object ("secondary-icon-pixbuf",
1036 P_("Secondary pixbuf"),
1037 P_("Secondary pixbuf for the entry"),
1039 GTK_PARAM_READWRITE));
1042 * GtkEntry:primary-icon-stock:
1044 * The stock id to use for the primary icon for the entry.
1048 g_object_class_install_property (gobject_class,
1050 g_param_spec_string ("primary-icon-stock",
1051 P_("Primary stock ID"),
1052 P_("Stock ID for primary icon"),
1054 GTK_PARAM_READWRITE));
1057 * GtkEntry:secondary-icon-stock:
1059 * The stock id to use for the secondary icon for the entry.
1063 g_object_class_install_property (gobject_class,
1064 PROP_STOCK_SECONDARY,
1065 g_param_spec_string ("secondary-icon-stock",
1066 P_("Secondary stock ID"),
1067 P_("Stock ID for secondary icon"),
1069 GTK_PARAM_READWRITE));
1072 * GtkEntry:primary-icon-name:
1074 * The icon name to use for the primary icon for the entry.
1078 g_object_class_install_property (gobject_class,
1079 PROP_ICON_NAME_PRIMARY,
1080 g_param_spec_string ("primary-icon-name",
1081 P_("Primary icon name"),
1082 P_("Icon name for primary icon"),
1084 GTK_PARAM_READWRITE));
1087 * GtkEntry:secondary-icon-name:
1089 * The icon name to use for the secondary icon for the entry.
1093 g_object_class_install_property (gobject_class,
1094 PROP_ICON_NAME_SECONDARY,
1095 g_param_spec_string ("secondary-icon-name",
1096 P_("Secondary icon name"),
1097 P_("Icon name for secondary icon"),
1099 GTK_PARAM_READWRITE));
1102 * GtkEntry:primary-icon-gicon:
1104 * The #GIcon to use for the primary icon for the entry.
1108 g_object_class_install_property (gobject_class,
1110 g_param_spec_object ("primary-icon-gicon",
1111 P_("Primary GIcon"),
1112 P_("GIcon for primary icon"),
1114 GTK_PARAM_READWRITE));
1117 * GtkEntry:secondary-icon-gicon:
1119 * The #GIcon to use for the secondary icon for the entry.
1123 g_object_class_install_property (gobject_class,
1124 PROP_GICON_SECONDARY,
1125 g_param_spec_object ("secondary-icon-gicon",
1126 P_("Secondary GIcon"),
1127 P_("GIcon for secondary icon"),
1129 GTK_PARAM_READWRITE));
1132 * GtkEntry:primary-icon-storage-type:
1134 * The representation which is used for the primary icon of the entry.
1138 g_object_class_install_property (gobject_class,
1139 PROP_STORAGE_TYPE_PRIMARY,
1140 g_param_spec_enum ("primary-icon-storage-type",
1141 P_("Primary storage type"),
1142 P_("The representation being used for primary icon"),
1143 GTK_TYPE_IMAGE_TYPE,
1145 GTK_PARAM_READABLE));
1148 * GtkEntry:secondary-icon-storage-type:
1150 * The representation which is used for the secondary icon of the entry.
1154 g_object_class_install_property (gobject_class,
1155 PROP_STORAGE_TYPE_SECONDARY,
1156 g_param_spec_enum ("secondary-icon-storage-type",
1157 P_("Secondary storage type"),
1158 P_("The representation being used for secondary icon"),
1159 GTK_TYPE_IMAGE_TYPE,
1161 GTK_PARAM_READABLE));
1164 * GtkEntry:primary-icon-activatable:
1166 * Whether the primary icon is activatable.
1168 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1169 * signals only on sensitive, activatable icons.
1171 * Sensitive, but non-activatable icons can be used for purely
1172 * informational purposes.
1176 g_object_class_install_property (gobject_class,
1177 PROP_ACTIVATABLE_PRIMARY,
1178 g_param_spec_boolean ("primary-icon-activatable",
1179 P_("Primary icon activatable"),
1180 P_("Whether the primary icon is activatable"),
1182 GTK_PARAM_READWRITE));
1185 * GtkEntry:secondary-icon-activatable:
1187 * Whether the secondary icon is activatable.
1189 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1190 * signals only on sensitive, activatable icons.
1192 * Sensitive, but non-activatable icons can be used for purely
1193 * informational purposes.
1197 g_object_class_install_property (gobject_class,
1198 PROP_ACTIVATABLE_SECONDARY,
1199 g_param_spec_boolean ("secondary-icon-activatable",
1200 P_("Secondary icon activatable"),
1201 P_("Whether the secondary icon is activatable"),
1203 GTK_PARAM_READWRITE));
1207 * GtkEntry:primary-icon-sensitive:
1209 * Whether the primary icon is sensitive.
1211 * An insensitive icon appears grayed out. GTK+ does not emit the
1212 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1213 * does not allow DND from insensitive icons.
1215 * An icon should be set insensitive if the action that would trigger
1216 * when clicked is currently not available.
1220 g_object_class_install_property (gobject_class,
1221 PROP_SENSITIVE_PRIMARY,
1222 g_param_spec_boolean ("primary-icon-sensitive",
1223 P_("Primary icon sensitive"),
1224 P_("Whether the primary icon is sensitive"),
1226 GTK_PARAM_READWRITE));
1229 * GtkEntry:secondary-icon-sensitive:
1231 * Whether the secondary icon is sensitive.
1233 * An insensitive icon appears grayed out. GTK+ does not emit the
1234 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1235 * does not allow DND from insensitive icons.
1237 * An icon should be set insensitive if the action that would trigger
1238 * when clicked is currently not available.
1242 g_object_class_install_property (gobject_class,
1243 PROP_SENSITIVE_SECONDARY,
1244 g_param_spec_boolean ("secondary-icon-sensitive",
1245 P_("Secondary icon sensitive"),
1246 P_("Whether the secondary icon is sensitive"),
1248 GTK_PARAM_READWRITE));
1251 * GtkEntry:primary-icon-tooltip-text:
1253 * The contents of the tooltip on the primary icon.
1255 * Also see gtk_entry_set_icon_tooltip_text().
1259 g_object_class_install_property (gobject_class,
1260 PROP_TOOLTIP_TEXT_PRIMARY,
1261 g_param_spec_string ("primary-icon-tooltip-text",
1262 P_("Primary icon tooltip text"),
1263 P_("The contents of the tooltip on the primary icon"),
1265 GTK_PARAM_READWRITE));
1268 * GtkEntry:secondary-icon-tooltip-text:
1270 * The contents of the tooltip on the secondary icon.
1272 * Also see gtk_entry_set_icon_tooltip_text().
1276 g_object_class_install_property (gobject_class,
1277 PROP_TOOLTIP_TEXT_SECONDARY,
1278 g_param_spec_string ("secondary-icon-tooltip-text",
1279 P_("Secondary icon tooltip text"),
1280 P_("The contents of the tooltip on the secondary icon"),
1282 GTK_PARAM_READWRITE));
1285 * GtkEntry:primary-icon-tooltip-markup:
1287 * The contents of the tooltip on the primary icon, which is marked up
1288 * with the <link linkend="PangoMarkupFormat">Pango text markup
1291 * Also see gtk_entry_set_icon_tooltip_markup().
1295 g_object_class_install_property (gobject_class,
1296 PROP_TOOLTIP_MARKUP_PRIMARY,
1297 g_param_spec_string ("primary-icon-tooltip-markup",
1298 P_("Primary icon tooltip markup"),
1299 P_("The contents of the tooltip on the primary icon"),
1301 GTK_PARAM_READWRITE));
1304 * GtkEntry:secondary-icon-tooltip-markup:
1306 * The contents of the tooltip on the secondary icon, which is marked up
1307 * with the <link linkend="PangoMarkupFormat">Pango text markup
1310 * Also see gtk_entry_set_icon_tooltip_markup().
1314 g_object_class_install_property (gobject_class,
1315 PROP_TOOLTIP_MARKUP_SECONDARY,
1316 g_param_spec_string ("secondary-icon-tooltip-markup",
1317 P_("Secondary icon tooltip markup"),
1318 P_("The contents of the tooltip on the secondary icon"),
1320 GTK_PARAM_READWRITE));
1323 * GtkEntry:im-module:
1325 * Which IM (input method) module should be used for this entry.
1326 * See #GtkIMContext.
1328 * Setting this to a non-%NULL value overrides the
1329 * system-wide IM module setting. See the GtkSettings
1330 * #GtkSettings:gtk-im-module property.
1334 g_object_class_install_property (gobject_class,
1336 g_param_spec_string ("im-module",
1338 P_("Which IM module should be used"),
1340 GTK_PARAM_READWRITE));
1343 * GtkEntry:completion:
1345 * The auxiliary completion object to use with the entry.
1349 g_object_class_install_property (gobject_class,
1351 g_param_spec_object ("completion",
1353 P_("The auxiliary completion object"),
1354 GTK_TYPE_ENTRY_COMPLETION,
1355 GTK_PARAM_READWRITE));
1358 * GtkEntry:icon-prelight:
1360 * The prelight style property determines whether activatable
1361 * icons prelight on mouseover.
1365 gtk_widget_class_install_style_property (widget_class,
1366 g_param_spec_boolean ("icon-prelight",
1367 P_("Icon Prelight"),
1368 P_("Whether activatable icons should prelight when hovered"),
1370 GTK_PARAM_READABLE));
1373 * GtkEntry:progress-border:
1375 * The border around the progress bar in the entry.
1379 gtk_widget_class_install_style_property (widget_class,
1380 g_param_spec_boxed ("progress-border",
1381 P_("Progress Border"),
1382 P_("Border around the progress bar"),
1384 GTK_PARAM_READABLE));
1387 * GtkEntry:invisible-char:
1389 * The invisible character is used when masking entry contents (in
1390 * \"password mode\")"). When it is not explicitly set with the
1391 * #GtkEntry::invisible-char property, GTK+ determines the character
1392 * to use from a list of possible candidates, depending on availability
1393 * in the current font.
1395 * This style property allows the theme to prepend a character
1396 * to the list of candidates.
1400 gtk_widget_class_install_style_property (widget_class,
1401 g_param_spec_unichar ("invisible-char",
1402 P_("Invisible character"),
1403 P_("The character to use when masking entry contents (in \"password mode\")"),
1405 GTK_PARAM_READABLE));
1408 * GtkEntry::populate-popup:
1409 * @entry: The entry on which the signal is emitted
1410 * @menu: the menu that is being populated
1412 * The ::populate-popup signal gets emitted before showing the
1413 * context menu of the entry.
1415 * If you need to add items to the context menu, connect
1416 * to this signal and append your menuitems to the @menu.
1418 signals[POPULATE_POPUP] =
1419 g_signal_new (I_("populate-popup"),
1420 G_OBJECT_CLASS_TYPE (gobject_class),
1422 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1424 _gtk_marshal_VOID__OBJECT,
1428 /* Action signals */
1431 * GtkEntry::activate:
1432 * @entry: The entry on which the signal is emitted
1434 * A <link linkend="keybinding-signals">keybinding signal</link>
1435 * which gets emitted when the user activates the entry.
1437 * Applications should not connect to it, but may emit it with
1438 * g_signal_emit_by_name() if they need to control activation
1441 * The default bindings for this signal are all forms of the Enter key.
1444 g_signal_new (I_("activate"),
1445 G_OBJECT_CLASS_TYPE (gobject_class),
1446 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1447 G_STRUCT_OFFSET (GtkEntryClass, activate),
1449 _gtk_marshal_VOID__VOID,
1451 widget_class->activate_signal = signals[ACTIVATE];
1454 * GtkEntry::move-cursor:
1455 * @entry: the object which received the signal
1456 * @step: the granularity of the move, as a #GtkMovementStep
1457 * @count: the number of @step units to move
1458 * @extend_selection: %TRUE if the move should extend the selection
1460 * The ::move-cursor signal is a
1461 * <link linkend="keybinding-signals">keybinding signal</link>
1462 * which gets emitted when the user initiates a cursor movement.
1463 * If the cursor is not visible in @entry, this signal causes
1464 * the viewport to be moved instead.
1466 * Applications should not connect to it, but may emit it with
1467 * g_signal_emit_by_name() if they need to control the cursor
1470 * The default bindings for this signal come in two variants,
1471 * the variant with the Shift modifier extends the selection,
1472 * the variant without the Shift modifer does not.
1473 * There are too many key combinations to list them all here.
1475 * <listitem>Arrow keys move by individual characters/lines</listitem>
1476 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1477 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1480 signals[MOVE_CURSOR] =
1481 g_signal_new (I_("move-cursor"),
1482 G_OBJECT_CLASS_TYPE (gobject_class),
1483 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1484 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1486 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1488 GTK_TYPE_MOVEMENT_STEP,
1493 * GtkEntry::insert-at-cursor:
1494 * @entry: the object which received the signal
1495 * @string: the string to insert
1497 * The ::insert-at-cursor signal is a
1498 * <link linkend="keybinding-signals">keybinding signal</link>
1499 * which gets emitted when the user initiates the insertion of a
1500 * fixed string at the cursor.
1502 * This signal has no default bindings.
1504 signals[INSERT_AT_CURSOR] =
1505 g_signal_new (I_("insert-at-cursor"),
1506 G_OBJECT_CLASS_TYPE (gobject_class),
1507 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1508 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1510 _gtk_marshal_VOID__STRING,
1515 * GtkEntry::delete-from-cursor:
1516 * @entry: the object which received the signal
1517 * @type: the granularity of the deletion, as a #GtkDeleteType
1518 * @count: the number of @type units to delete
1520 * The ::delete-from-cursor signal is a
1521 * <link linkend="keybinding-signals">keybinding signal</link>
1522 * which gets emitted when the user initiates a text deletion.
1524 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1525 * if there is one, otherwise it deletes the requested number
1528 * The default bindings for this signal are
1529 * Delete for deleting a character and Ctrl-Delete for
1532 signals[DELETE_FROM_CURSOR] =
1533 g_signal_new (I_("delete-from-cursor"),
1534 G_OBJECT_CLASS_TYPE (gobject_class),
1535 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1536 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1538 _gtk_marshal_VOID__ENUM_INT,
1540 GTK_TYPE_DELETE_TYPE,
1544 * GtkEntry::backspace:
1545 * @entry: the object which received the signal
1547 * The ::backspace signal is a
1548 * <link linkend="keybinding-signals">keybinding signal</link>
1549 * which gets emitted when the user asks for it.
1551 * The default bindings for this signal are
1552 * Backspace and Shift-Backspace.
1554 signals[BACKSPACE] =
1555 g_signal_new (I_("backspace"),
1556 G_OBJECT_CLASS_TYPE (gobject_class),
1557 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1558 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1560 _gtk_marshal_VOID__VOID,
1564 * GtkEntry::cut-clipboard:
1565 * @entry: the object which received the signal
1567 * The ::cut-clipboard signal is a
1568 * <link linkend="keybinding-signals">keybinding signal</link>
1569 * which gets emitted to cut the selection to the clipboard.
1571 * The default bindings for this signal are
1572 * Ctrl-x and Shift-Delete.
1574 signals[CUT_CLIPBOARD] =
1575 g_signal_new (I_("cut-clipboard"),
1576 G_OBJECT_CLASS_TYPE (gobject_class),
1577 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1578 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1580 _gtk_marshal_VOID__VOID,
1584 * GtkEntry::copy-clipboard:
1585 * @entry: the object which received the signal
1587 * The ::copy-clipboard signal is a
1588 * <link linkend="keybinding-signals">keybinding signal</link>
1589 * which gets emitted to copy the selection to the clipboard.
1591 * The default bindings for this signal are
1592 * Ctrl-c and Ctrl-Insert.
1594 signals[COPY_CLIPBOARD] =
1595 g_signal_new (I_("copy-clipboard"),
1596 G_OBJECT_CLASS_TYPE (gobject_class),
1597 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1598 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1600 _gtk_marshal_VOID__VOID,
1604 * GtkEntry::paste-clipboard:
1605 * @entry: the object which received the signal
1607 * The ::paste-clipboard signal is a
1608 * <link linkend="keybinding-signals">keybinding signal</link>
1609 * which gets emitted to paste the contents of the clipboard
1610 * into the text view.
1612 * The default bindings for this signal are
1613 * Ctrl-v and Shift-Insert.
1615 signals[PASTE_CLIPBOARD] =
1616 g_signal_new (I_("paste-clipboard"),
1617 G_OBJECT_CLASS_TYPE (gobject_class),
1618 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1619 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1621 _gtk_marshal_VOID__VOID,
1625 * GtkEntry::toggle-overwrite:
1626 * @entry: the object which received the signal
1628 * The ::toggle-overwrite signal is a
1629 * <link linkend="keybinding-signals">keybinding signal</link>
1630 * which gets emitted to toggle the overwrite mode of the entry.
1632 * The default bindings for this signal is Insert.
1634 signals[TOGGLE_OVERWRITE] =
1635 g_signal_new (I_("toggle-overwrite"),
1636 G_OBJECT_CLASS_TYPE (gobject_class),
1637 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1638 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1640 _gtk_marshal_VOID__VOID,
1644 * GtkEntry::icon-press:
1645 * @entry: The entry on which the signal is emitted
1646 * @icon_pos: The position of the clicked icon
1647 * @event: (type Gdk.EventButton): the button press event
1649 * The ::icon-press signal is emitted when an activatable icon
1654 signals[ICON_PRESS] =
1655 g_signal_new (I_("icon-press"),
1656 G_TYPE_FROM_CLASS (gobject_class),
1660 _gtk_marshal_VOID__ENUM_BOXED,
1662 GTK_TYPE_ENTRY_ICON_POSITION,
1663 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1666 * GtkEntry::icon-release:
1667 * @entry: The entry on which the signal is emitted
1668 * @icon_pos: The position of the clicked icon
1669 * @event: (type Gdk.EventButton): the button release event
1671 * The ::icon-release signal is emitted on the button release from a
1672 * mouse click over an activatable icon.
1676 signals[ICON_RELEASE] =
1677 g_signal_new (I_("icon-release"),
1678 G_TYPE_FROM_CLASS (gobject_class),
1682 _gtk_marshal_VOID__ENUM_BOXED,
1684 GTK_TYPE_ENTRY_ICON_POSITION,
1685 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1688 * GtkEntry::preedit-changed:
1689 * @entry: the object which received the signal
1690 * @preedit: the current preedit string
1692 * If an input method is used, the typed text will not immediately
1693 * be committed to the buffer. So if you are interested in the text,
1694 * connect to this signal.
1698 signals[PREEDIT_CHANGED] =
1699 g_signal_new_class_handler (I_("preedit-changed"),
1700 G_OBJECT_CLASS_TYPE (gobject_class),
1701 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1704 _gtk_marshal_VOID__STRING,
1713 binding_set = gtk_binding_set_by_class (class);
1715 /* Moving the insertion point */
1716 add_move_binding (binding_set, GDK_KEY_Right, 0,
1717 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1719 add_move_binding (binding_set, GDK_KEY_Left, 0,
1720 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1722 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1723 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1725 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1726 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1728 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1729 GTK_MOVEMENT_WORDS, 1);
1731 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1732 GTK_MOVEMENT_WORDS, -1);
1734 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1735 GTK_MOVEMENT_WORDS, 1);
1737 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1738 GTK_MOVEMENT_WORDS, -1);
1740 add_move_binding (binding_set, GDK_KEY_Home, 0,
1741 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1743 add_move_binding (binding_set, GDK_KEY_End, 0,
1744 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1746 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1747 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1749 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1750 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1752 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1753 GTK_MOVEMENT_BUFFER_ENDS, -1);
1755 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1756 GTK_MOVEMENT_BUFFER_ENDS, 1);
1758 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1759 GTK_MOVEMENT_BUFFER_ENDS, -1);
1761 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1762 GTK_MOVEMENT_BUFFER_ENDS, 1);
1766 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1768 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1770 G_TYPE_BOOLEAN, FALSE);
1771 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1773 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1775 G_TYPE_BOOLEAN, TRUE);
1777 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1779 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1781 G_TYPE_BOOLEAN, FALSE);
1782 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1784 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1786 G_TYPE_BOOLEAN, TRUE);
1789 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1791 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1793 G_TYPE_BOOLEAN, FALSE);
1794 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1796 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1798 G_TYPE_BOOLEAN, FALSE);
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1804 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1810 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1811 "delete-from-cursor", 2,
1812 G_TYPE_ENUM, GTK_DELETE_CHARS,
1815 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1816 "delete-from-cursor", 2,
1817 G_TYPE_ENUM, GTK_DELETE_CHARS,
1820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1823 /* Make this do the same as Backspace, to help with mis-typing */
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1827 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1828 "delete-from-cursor", 2,
1829 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1832 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1833 "delete-from-cursor", 2,
1834 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1837 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1838 "delete-from-cursor", 2,
1839 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1842 /* Cut/copy/paste */
1844 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1845 "cut-clipboard", 0);
1846 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1847 "copy-clipboard", 0);
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1849 "paste-clipboard", 0);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1852 "cut-clipboard", 0);
1853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1854 "copy-clipboard", 0);
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1856 "paste-clipboard", 0);
1859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1860 "toggle-overwrite", 0);
1861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1862 "toggle-overwrite", 0);
1865 * GtkEntry:inner-border:
1867 * Sets the text area's border between the text and the frame.
1871 * Deprecated: 3.4: Use the standard border and padding CSS properties;
1872 * the value of this style property is ignored.
1874 gtk_widget_class_install_style_property (widget_class,
1875 g_param_spec_boxed ("inner-border",
1877 P_("Border between text and frame."),
1879 GTK_PARAM_READABLE |
1880 G_PARAM_DEPRECATED));
1882 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1884 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1888 gtk_entry_editable_init (GtkEditableInterface *iface)
1890 iface->do_insert_text = gtk_entry_insert_text;
1891 iface->do_delete_text = gtk_entry_delete_text;
1892 iface->insert_text = gtk_entry_real_insert_text;
1893 iface->delete_text = gtk_entry_real_delete_text;
1894 iface->get_chars = gtk_entry_get_chars;
1895 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1896 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1897 iface->set_position = gtk_entry_real_set_position;
1898 iface->get_position = gtk_entry_get_position;
1902 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1904 iface->start_editing = gtk_entry_start_editing;
1907 /* for deprecated properties */
1909 gtk_entry_do_set_inner_border (GtkEntry *entry,
1910 const GtkBorder *border)
1913 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1914 gtk_border_copy (border),
1915 (GDestroyNotify) gtk_border_free);
1917 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1919 g_object_notify (G_OBJECT (entry), "inner-border");
1922 static const GtkBorder *
1923 gtk_entry_do_get_inner_border (GtkEntry *entry)
1925 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1929 gtk_entry_set_property (GObject *object,
1931 const GValue *value,
1934 GtkEntry *entry = GTK_ENTRY (object);
1935 GtkEntryPrivate *priv = entry->priv;
1940 gtk_entry_set_buffer (entry, g_value_get_object (value));
1945 gboolean new_value = g_value_get_boolean (value);
1947 if (new_value != priv->editable)
1949 GtkWidget *widget = GTK_WIDGET (entry);
1953 _gtk_entry_reset_im_context (entry);
1954 if (gtk_widget_has_focus (widget))
1955 gtk_im_context_focus_out (priv->im_context);
1957 priv->preedit_length = 0;
1958 priv->preedit_cursor = 0;
1961 priv->editable = new_value;
1963 if (new_value && gtk_widget_has_focus (widget))
1964 gtk_im_context_focus_in (priv->im_context);
1966 gtk_widget_queue_draw (widget);
1971 case PROP_MAX_LENGTH:
1972 gtk_entry_set_max_length (entry, g_value_get_int (value));
1975 case PROP_VISIBILITY:
1976 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1979 case PROP_HAS_FRAME:
1980 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1983 case PROP_INNER_BORDER:
1984 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1987 case PROP_INVISIBLE_CHAR:
1988 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1991 case PROP_ACTIVATES_DEFAULT:
1992 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1995 case PROP_WIDTH_CHARS:
1996 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2000 gtk_entry_set_text (entry, g_value_get_string (value));
2004 gtk_entry_set_alignment (entry, g_value_get_float (value));
2007 case PROP_TRUNCATE_MULTILINE:
2008 priv->truncate_multiline = g_value_get_boolean (value);
2011 case PROP_SHADOW_TYPE:
2012 priv->shadow_type = g_value_get_enum (value);
2015 case PROP_OVERWRITE_MODE:
2016 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2019 case PROP_INVISIBLE_CHAR_SET:
2020 if (g_value_get_boolean (value))
2021 priv->invisible_char_set = TRUE;
2023 gtk_entry_unset_invisible_char (entry);
2026 case PROP_CAPS_LOCK_WARNING:
2027 priv->caps_lock_warning = g_value_get_boolean (value);
2030 case PROP_PROGRESS_FRACTION:
2031 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2034 case PROP_PROGRESS_PULSE_STEP:
2035 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2038 case PROP_PLACEHOLDER_TEXT:
2039 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2042 case PROP_PIXBUF_PRIMARY:
2043 gtk_entry_set_icon_from_pixbuf (entry,
2044 GTK_ENTRY_ICON_PRIMARY,
2045 g_value_get_object (value));
2048 case PROP_PIXBUF_SECONDARY:
2049 gtk_entry_set_icon_from_pixbuf (entry,
2050 GTK_ENTRY_ICON_SECONDARY,
2051 g_value_get_object (value));
2054 case PROP_STOCK_PRIMARY:
2055 gtk_entry_set_icon_from_stock (entry,
2056 GTK_ENTRY_ICON_PRIMARY,
2057 g_value_get_string (value));
2060 case PROP_STOCK_SECONDARY:
2061 gtk_entry_set_icon_from_stock (entry,
2062 GTK_ENTRY_ICON_SECONDARY,
2063 g_value_get_string (value));
2066 case PROP_ICON_NAME_PRIMARY:
2067 gtk_entry_set_icon_from_icon_name (entry,
2068 GTK_ENTRY_ICON_PRIMARY,
2069 g_value_get_string (value));
2072 case PROP_ICON_NAME_SECONDARY:
2073 gtk_entry_set_icon_from_icon_name (entry,
2074 GTK_ENTRY_ICON_SECONDARY,
2075 g_value_get_string (value));
2078 case PROP_GICON_PRIMARY:
2079 gtk_entry_set_icon_from_gicon (entry,
2080 GTK_ENTRY_ICON_PRIMARY,
2081 g_value_get_object (value));
2084 case PROP_GICON_SECONDARY:
2085 gtk_entry_set_icon_from_gicon (entry,
2086 GTK_ENTRY_ICON_SECONDARY,
2087 g_value_get_object (value));
2090 case PROP_ACTIVATABLE_PRIMARY:
2091 gtk_entry_set_icon_activatable (entry,
2092 GTK_ENTRY_ICON_PRIMARY,
2093 g_value_get_boolean (value));
2096 case PROP_ACTIVATABLE_SECONDARY:
2097 gtk_entry_set_icon_activatable (entry,
2098 GTK_ENTRY_ICON_SECONDARY,
2099 g_value_get_boolean (value));
2102 case PROP_SENSITIVE_PRIMARY:
2103 gtk_entry_set_icon_sensitive (entry,
2104 GTK_ENTRY_ICON_PRIMARY,
2105 g_value_get_boolean (value));
2108 case PROP_SENSITIVE_SECONDARY:
2109 gtk_entry_set_icon_sensitive (entry,
2110 GTK_ENTRY_ICON_SECONDARY,
2111 g_value_get_boolean (value));
2114 case PROP_TOOLTIP_TEXT_PRIMARY:
2115 gtk_entry_set_icon_tooltip_text (entry,
2116 GTK_ENTRY_ICON_PRIMARY,
2117 g_value_get_string (value));
2120 case PROP_TOOLTIP_TEXT_SECONDARY:
2121 gtk_entry_set_icon_tooltip_text (entry,
2122 GTK_ENTRY_ICON_SECONDARY,
2123 g_value_get_string (value));
2126 case PROP_TOOLTIP_MARKUP_PRIMARY:
2127 gtk_entry_set_icon_tooltip_markup (entry,
2128 GTK_ENTRY_ICON_PRIMARY,
2129 g_value_get_string (value));
2132 case PROP_TOOLTIP_MARKUP_SECONDARY:
2133 gtk_entry_set_icon_tooltip_markup (entry,
2134 GTK_ENTRY_ICON_SECONDARY,
2135 g_value_get_string (value));
2138 case PROP_IM_MODULE:
2139 g_free (priv->im_module);
2140 priv->im_module = g_value_dup_string (value);
2141 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2142 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2145 case PROP_EDITING_CANCELED:
2146 priv->editing_canceled = g_value_get_boolean (value);
2149 case PROP_COMPLETION:
2150 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2153 case PROP_SCROLL_OFFSET:
2154 case PROP_CURSOR_POSITION:
2156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2162 gtk_entry_get_property (GObject *object,
2167 GtkEntry *entry = GTK_ENTRY (object);
2168 GtkEntryPrivate *priv = entry->priv;
2173 g_value_set_object (value, gtk_entry_get_buffer (entry));
2176 case PROP_CURSOR_POSITION:
2177 g_value_set_int (value, priv->current_pos);
2180 case PROP_SELECTION_BOUND:
2181 g_value_set_int (value, priv->selection_bound);
2185 g_value_set_boolean (value, priv->editable);
2188 case PROP_MAX_LENGTH:
2189 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2192 case PROP_VISIBILITY:
2193 g_value_set_boolean (value, priv->visible);
2196 case PROP_HAS_FRAME:
2197 g_value_set_boolean (value, priv->has_frame);
2200 case PROP_INNER_BORDER:
2201 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2204 case PROP_INVISIBLE_CHAR:
2205 g_value_set_uint (value, priv->invisible_char);
2208 case PROP_ACTIVATES_DEFAULT:
2209 g_value_set_boolean (value, priv->activates_default);
2212 case PROP_WIDTH_CHARS:
2213 g_value_set_int (value, priv->width_chars);
2216 case PROP_SCROLL_OFFSET:
2217 g_value_set_int (value, priv->scroll_offset);
2221 g_value_set_string (value, gtk_entry_get_text (entry));
2225 g_value_set_float (value, gtk_entry_get_alignment (entry));
2228 case PROP_TRUNCATE_MULTILINE:
2229 g_value_set_boolean (value, priv->truncate_multiline);
2232 case PROP_SHADOW_TYPE:
2233 g_value_set_enum (value, priv->shadow_type);
2236 case PROP_OVERWRITE_MODE:
2237 g_value_set_boolean (value, priv->overwrite_mode);
2240 case PROP_TEXT_LENGTH:
2241 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2244 case PROP_INVISIBLE_CHAR_SET:
2245 g_value_set_boolean (value, priv->invisible_char_set);
2248 case PROP_IM_MODULE:
2249 g_value_set_string (value, priv->im_module);
2252 case PROP_CAPS_LOCK_WARNING:
2253 g_value_set_boolean (value, priv->caps_lock_warning);
2256 case PROP_PROGRESS_FRACTION:
2257 g_value_set_double (value, priv->progress_fraction);
2260 case PROP_PROGRESS_PULSE_STEP:
2261 g_value_set_double (value, priv->progress_pulse_fraction);
2264 case PROP_PLACEHOLDER_TEXT:
2265 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2268 case PROP_PIXBUF_PRIMARY:
2269 g_value_set_object (value,
2270 gtk_entry_get_icon_pixbuf (entry,
2271 GTK_ENTRY_ICON_PRIMARY));
2274 case PROP_PIXBUF_SECONDARY:
2275 g_value_set_object (value,
2276 gtk_entry_get_icon_pixbuf (entry,
2277 GTK_ENTRY_ICON_SECONDARY));
2280 case PROP_STOCK_PRIMARY:
2281 g_value_set_string (value,
2282 gtk_entry_get_icon_stock (entry,
2283 GTK_ENTRY_ICON_PRIMARY));
2286 case PROP_STOCK_SECONDARY:
2287 g_value_set_string (value,
2288 gtk_entry_get_icon_stock (entry,
2289 GTK_ENTRY_ICON_SECONDARY));
2292 case PROP_ICON_NAME_PRIMARY:
2293 g_value_set_string (value,
2294 gtk_entry_get_icon_name (entry,
2295 GTK_ENTRY_ICON_PRIMARY));
2298 case PROP_ICON_NAME_SECONDARY:
2299 g_value_set_string (value,
2300 gtk_entry_get_icon_name (entry,
2301 GTK_ENTRY_ICON_SECONDARY));
2304 case PROP_GICON_PRIMARY:
2305 g_value_set_object (value,
2306 gtk_entry_get_icon_gicon (entry,
2307 GTK_ENTRY_ICON_PRIMARY));
2310 case PROP_GICON_SECONDARY:
2311 g_value_set_object (value,
2312 gtk_entry_get_icon_gicon (entry,
2313 GTK_ENTRY_ICON_SECONDARY));
2316 case PROP_STORAGE_TYPE_PRIMARY:
2317 g_value_set_enum (value,
2318 gtk_entry_get_icon_storage_type (entry,
2319 GTK_ENTRY_ICON_PRIMARY));
2322 case PROP_STORAGE_TYPE_SECONDARY:
2323 g_value_set_enum (value,
2324 gtk_entry_get_icon_storage_type (entry,
2325 GTK_ENTRY_ICON_SECONDARY));
2328 case PROP_ACTIVATABLE_PRIMARY:
2329 g_value_set_boolean (value,
2330 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2333 case PROP_ACTIVATABLE_SECONDARY:
2334 g_value_set_boolean (value,
2335 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2338 case PROP_SENSITIVE_PRIMARY:
2339 g_value_set_boolean (value,
2340 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2343 case PROP_SENSITIVE_SECONDARY:
2344 g_value_set_boolean (value,
2345 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2348 case PROP_TOOLTIP_TEXT_PRIMARY:
2349 g_value_take_string (value,
2350 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2353 case PROP_TOOLTIP_TEXT_SECONDARY:
2354 g_value_take_string (value,
2355 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2358 case PROP_TOOLTIP_MARKUP_PRIMARY:
2359 g_value_take_string (value,
2360 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2363 case PROP_TOOLTIP_MARKUP_SECONDARY:
2364 g_value_take_string (value,
2365 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2368 case PROP_EDITING_CANCELED:
2369 g_value_set_boolean (value,
2370 priv->editing_canceled);
2373 case PROP_COMPLETION:
2374 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2378 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2384 find_invisible_char (GtkWidget *widget)
2386 PangoLayout *layout;
2387 PangoAttrList *attr_list;
2389 gunichar invisible_chars [] = {
2391 0x25cf, /* BLACK CIRCLE */
2392 0x2022, /* BULLET */
2393 0x2731, /* HEAVY ASTERISK */
2394 0x273a /* SIXTEEN POINTED ASTERISK */
2397 gtk_widget_style_get (widget,
2398 "invisible-char", &invisible_chars[0],
2401 layout = gtk_widget_create_pango_layout (widget, NULL);
2403 attr_list = pango_attr_list_new ();
2404 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2406 pango_layout_set_attributes (layout, attr_list);
2407 pango_attr_list_unref (attr_list);
2409 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2411 gchar text[7] = { 0, };
2414 len = g_unichar_to_utf8 (invisible_chars[i], text);
2415 pango_layout_set_text (layout, text, len);
2417 count = pango_layout_get_unknown_glyphs_count (layout);
2421 g_object_unref (layout);
2422 return invisible_chars[i];
2426 g_object_unref (layout);
2432 gtk_entry_init (GtkEntry *entry)
2434 GtkStyleContext *context;
2435 GtkEntryPrivate *priv;
2437 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2442 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2443 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2445 priv->editable = TRUE;
2446 priv->visible = TRUE;
2447 priv->dnd_position = -1;
2448 priv->width_chars = -1;
2449 priv->is_cell_renderer = FALSE;
2450 priv->editing_canceled = FALSE;
2451 priv->has_frame = TRUE;
2452 priv->truncate_multiline = FALSE;
2453 priv->shadow_type = GTK_SHADOW_IN;
2455 priv->caps_lock_warning = TRUE;
2456 priv->caps_lock_warning_shown = FALSE;
2457 priv->progress_fraction = 0.0;
2458 priv->progress_pulse_fraction = 0.1;
2460 gtk_drag_dest_set (GTK_WIDGET (entry),
2461 GTK_DEST_DEFAULT_HIGHLIGHT,
2463 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2464 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2466 /* This object is completely private. No external entity can gain a reference
2467 * to it; so we create it here and destroy it in finalize().
2469 priv->im_context = gtk_im_multicontext_new ();
2471 g_signal_connect (priv->im_context, "commit",
2472 G_CALLBACK (gtk_entry_commit_cb), entry);
2473 g_signal_connect (priv->im_context, "preedit-changed",
2474 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2475 g_signal_connect (priv->im_context, "retrieve-surrounding",
2476 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2477 g_signal_connect (priv->im_context, "delete-surrounding",
2478 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2480 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2481 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2483 gtk_entry_update_cached_style_values (entry);
2487 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2488 GtkStyleContext *context,
2489 GtkEntryIconPosition icon_pos)
2491 GtkEntryPrivate *priv = entry->priv;
2492 EntryIconInfo *icon_info = priv->icons[icon_pos];
2494 GtkStateFlags state;
2496 widget = GTK_WIDGET (entry);
2497 state = gtk_widget_get_state_flags (widget);
2499 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2501 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2502 state |= GTK_STATE_FLAG_INSENSITIVE;
2503 else if (icon_info->prelight)
2504 state |= GTK_STATE_FLAG_PRELIGHT;
2506 gtk_style_context_save (context);
2508 gtk_style_context_set_state (context, state);
2509 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2511 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2513 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2514 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2516 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2520 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2521 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2523 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2528 get_icon_width (GtkEntry *entry,
2529 GtkEntryIconPosition icon_pos)
2531 GtkEntryPrivate *priv = entry->priv;
2532 EntryIconInfo *icon_info = priv->icons[icon_pos];
2533 GtkStyleContext *context;
2540 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2541 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2542 gtk_style_context_get_padding (context, 0, &padding);
2544 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2546 gtk_style_context_restore (context);
2549 width += padding.left + padding.right;
2555 get_icon_allocations (GtkEntry *entry,
2556 GtkAllocation *primary,
2557 GtkAllocation *secondary)
2560 GtkEntryPrivate *priv = entry->priv;
2561 gint x, y, width, height;
2563 get_text_area_size (entry, &x, &y, &width, &height);
2565 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2566 y += priv->focus_width;
2569 primary->height = height;
2570 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2573 secondary->height = height;
2574 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2576 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2578 primary->x = x + width - primary->width;
2584 secondary->x = x + width - secondary->width;
2590 begin_change (GtkEntry *entry)
2592 GtkEntryPrivate *priv = entry->priv;
2594 priv->change_count++;
2596 g_object_freeze_notify (G_OBJECT (entry));
2600 end_change (GtkEntry *entry)
2602 GtkEditable *editable = GTK_EDITABLE (entry);
2603 GtkEntryPrivate *priv = entry->priv;
2605 g_return_if_fail (priv->change_count > 0);
2607 g_object_thaw_notify (G_OBJECT (entry));
2609 priv->change_count--;
2611 if (priv->change_count == 0)
2613 if (priv->real_changed)
2615 g_signal_emit_by_name (editable, "changed");
2616 priv->real_changed = FALSE;
2622 emit_changed (GtkEntry *entry)
2624 GtkEditable *editable = GTK_EDITABLE (entry);
2625 GtkEntryPrivate *priv = entry->priv;
2627 if (priv->change_count == 0)
2628 g_signal_emit_by_name (editable, "changed");
2630 priv->real_changed = TRUE;
2634 gtk_entry_destroy (GtkWidget *widget)
2636 GtkEntry *entry = GTK_ENTRY (widget);
2637 GtkEntryPrivate *priv = entry->priv;
2639 priv->current_pos = priv->selection_bound = 0;
2640 _gtk_entry_reset_im_context (entry);
2641 gtk_entry_reset_layout (entry);
2643 if (priv->blink_timeout)
2645 g_source_remove (priv->blink_timeout);
2646 priv->blink_timeout = 0;
2649 if (priv->recompute_idle)
2651 g_source_remove (priv->recompute_idle);
2652 priv->recompute_idle = 0;
2655 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2659 gtk_entry_dispose (GObject *object)
2661 GtkEntry *entry = GTK_ENTRY (object);
2662 GtkEntryPrivate *priv = entry->priv;
2665 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2666 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2667 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2668 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2672 buffer_disconnect_signals (entry);
2673 g_object_unref (priv->buffer);
2674 priv->buffer = NULL;
2677 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2678 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2679 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2680 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2684 gtk_entry_finalize (GObject *object)
2686 GtkEntry *entry = GTK_ENTRY (object);
2687 GtkEntryPrivate *priv = entry->priv;
2688 EntryIconInfo *icon_info = NULL;
2691 for (i = 0; i < MAX_ICONS; i++)
2693 if ((icon_info = priv->icons[i]) != NULL)
2695 if (icon_info->target_list != NULL)
2697 gtk_target_list_unref (icon_info->target_list);
2698 icon_info->target_list = NULL;
2701 g_clear_object (&icon_info->icon_helper);
2703 g_slice_free (EntryIconInfo, icon_info);
2704 priv->icons[i] = NULL;
2708 gtk_entry_set_completion (entry, NULL);
2710 if (priv->cached_layout)
2711 g_object_unref (priv->cached_layout);
2713 g_object_unref (priv->im_context);
2715 if (priv->blink_timeout)
2716 g_source_remove (priv->blink_timeout);
2718 if (priv->recompute_idle)
2719 g_source_remove (priv->recompute_idle);
2721 g_free (priv->placeholder_text);
2722 g_free (priv->im_module);
2724 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2728 gtk_entry_get_display_mode (GtkEntry *entry)
2730 GtkEntryPrivate *priv = entry->priv;
2733 return DISPLAY_NORMAL;
2735 if (priv->invisible_char == 0 && priv->invisible_char_set)
2736 return DISPLAY_BLANK;
2738 return DISPLAY_INVISIBLE;
2742 gtk_entry_get_display_text (GtkEntry *entry,
2746 GtkEntryPasswordHint *password_hint;
2747 GtkEntryPrivate *priv;
2748 gunichar invisible_char;
2759 text = gtk_entry_buffer_get_text (get_buffer (entry));
2760 length = gtk_entry_buffer_get_length (get_buffer (entry));
2764 if (start_pos > length)
2767 if (end_pos <= start_pos)
2768 return g_strdup ("");
2769 else if (priv->visible)
2771 start = g_utf8_offset_to_pointer (text, start_pos);
2772 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2773 return g_strndup (start, end - start);
2777 str = g_string_sized_new (length * 2);
2779 /* Figure out what our invisible char is and encode it */
2780 if (!priv->invisible_char)
2781 invisible_char = priv->invisible_char_set ? ' ' : '*';
2783 invisible_char = priv->invisible_char;
2784 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2787 * Add hidden characters for each character in the text
2788 * buffer. If there is a password hint, then keep that
2789 * character visible.
2792 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2793 for (i = start_pos; i < end_pos; ++i)
2795 if (password_hint && i == password_hint->position)
2797 start = g_utf8_offset_to_pointer (text, i);
2798 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2802 g_string_append_len (str, char_str, char_len);
2806 return g_string_free (str, FALSE);
2811 update_cursors (GtkWidget *widget)
2813 GtkEntry *entry = GTK_ENTRY (widget);
2814 GtkEntryPrivate *priv = entry->priv;
2815 EntryIconInfo *icon_info = NULL;
2816 GdkDisplay *display;
2820 for (i = 0; i < MAX_ICONS; i++)
2822 if ((icon_info = priv->icons[i]) != NULL)
2824 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2825 icon_info->window != NULL)
2826 gdk_window_show_unraised (icon_info->window);
2828 /* The icon windows are not children of the visible entry window,
2829 * thus we can't just inherit the xterm cursor. Slight complication
2830 * here is that for the entry, insensitive => arrow cursor, but for
2831 * an icon in a sensitive entry, insensitive => xterm cursor.
2833 if (gtk_widget_is_sensitive (widget) &&
2834 (icon_info->insensitive ||
2835 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2837 display = gtk_widget_get_display (widget);
2838 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2839 gdk_window_set_cursor (icon_info->window, cursor);
2840 g_object_unref (cursor);
2844 gdk_window_set_cursor (icon_info->window, NULL);
2851 realize_icon_info (GtkWidget *widget,
2852 GtkEntryIconPosition icon_pos)
2854 GtkEntry *entry = GTK_ENTRY (widget);
2855 GtkEntryPrivate *priv = entry->priv;
2856 EntryIconInfo *icon_info = priv->icons[icon_pos];
2857 GdkWindowAttr attributes;
2858 gint attributes_mask;
2860 g_return_if_fail (icon_info != NULL);
2864 attributes.width = 1;
2865 attributes.height = 1;
2866 attributes.window_type = GDK_WINDOW_CHILD;
2867 attributes.wclass = GDK_INPUT_ONLY;
2868 attributes.event_mask = gtk_widget_get_events (widget);
2869 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2870 GDK_BUTTON_RELEASE_MASK |
2871 GDK_BUTTON1_MOTION_MASK |
2872 GDK_BUTTON3_MOTION_MASK |
2873 GDK_POINTER_MOTION_HINT_MASK |
2874 GDK_POINTER_MOTION_MASK |
2875 GDK_ENTER_NOTIFY_MASK |
2876 GDK_LEAVE_NOTIFY_MASK);
2877 attributes_mask = GDK_WA_X | GDK_WA_Y;
2879 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2882 gdk_window_set_user_data (icon_info->window, widget);
2884 gtk_widget_queue_resize (widget);
2887 static EntryIconInfo*
2888 construct_icon_info (GtkWidget *widget,
2889 GtkEntryIconPosition icon_pos)
2891 GtkEntry *entry = GTK_ENTRY (widget);
2892 GtkEntryPrivate *priv = entry->priv;
2893 EntryIconInfo *icon_info;
2895 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2897 icon_info = g_slice_new0 (EntryIconInfo);
2898 priv->icons[icon_pos] = icon_info;
2900 icon_info->icon_helper = _gtk_icon_helper_new ();
2902 if (gtk_widget_get_realized (widget))
2903 realize_icon_info (widget, icon_pos);
2909 gtk_entry_map (GtkWidget *widget)
2911 GtkEntry *entry = GTK_ENTRY (widget);
2912 GtkEntryPrivate *priv = entry->priv;
2913 EntryIconInfo *icon_info = NULL;
2916 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2918 gdk_window_show (priv->text_area);
2920 for (i = 0; i < MAX_ICONS; i++)
2922 if ((icon_info = priv->icons[i]) != NULL)
2924 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2925 icon_info->window != NULL)
2926 gdk_window_show (icon_info->window);
2930 update_cursors (widget);
2934 gtk_entry_unmap (GtkWidget *widget)
2936 GtkEntry *entry = GTK_ENTRY (widget);
2937 GtkEntryPrivate *priv = entry->priv;
2938 EntryIconInfo *icon_info = NULL;
2941 for (i = 0; i < MAX_ICONS; i++)
2943 if ((icon_info = priv->icons[i]) != NULL)
2945 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2946 icon_info->window != NULL)
2947 gdk_window_hide (icon_info->window);
2951 gdk_window_hide (priv->text_area);
2953 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2957 gtk_entry_realize (GtkWidget *widget)
2960 GtkEntryPrivate *priv;
2961 EntryIconInfo *icon_info;
2963 GdkWindowAttr attributes;
2964 gint attributes_mask;
2965 gint frame_x, frame_y;
2968 gtk_widget_set_realized (widget, TRUE);
2969 window = gtk_widget_get_parent_window (widget);
2970 gtk_widget_set_window (widget, window);
2971 g_object_ref (window);
2973 entry = GTK_ENTRY (widget);
2976 attributes.window_type = GDK_WINDOW_CHILD;
2977 attributes.wclass = GDK_INPUT_ONLY;
2978 attributes.event_mask = gtk_widget_get_events (widget);
2979 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2980 GDK_BUTTON_RELEASE_MASK |
2981 GDK_BUTTON1_MOTION_MASK |
2982 GDK_BUTTON3_MOTION_MASK |
2983 GDK_POINTER_MOTION_HINT_MASK |
2984 GDK_POINTER_MOTION_MASK |
2985 GDK_ENTER_NOTIFY_MASK |
2986 GDK_LEAVE_NOTIFY_MASK);
2987 attributes_mask = GDK_WA_X | GDK_WA_Y;
2989 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2991 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2992 attributes.x += frame_x;
2993 attributes.y += frame_y;
2995 if (gtk_widget_is_sensitive (widget))
2997 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2998 attributes_mask |= GDK_WA_CURSOR;
3001 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3005 gdk_window_set_user_data (priv->text_area, entry);
3007 if (attributes_mask & GDK_WA_CURSOR)
3008 g_object_unref (attributes.cursor);
3010 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3012 gtk_entry_adjust_scroll (entry);
3013 gtk_entry_update_primary_selection (entry);
3016 /* If the icon positions are already setup, create their windows.
3017 * Otherwise if they don't exist yet, then construct_icon_info()
3018 * will create the windows once the widget is already realized.
3020 for (i = 0; i < MAX_ICONS; i++)
3022 if ((icon_info = priv->icons[i]) != NULL)
3024 if (icon_info->window == NULL)
3025 realize_icon_info (widget, i);
3031 gtk_entry_unrealize (GtkWidget *widget)
3033 GtkEntry *entry = GTK_ENTRY (widget);
3034 GtkEntryPrivate *priv = entry->priv;
3035 GtkClipboard *clipboard;
3036 EntryIconInfo *icon_info;
3039 gtk_entry_reset_layout (entry);
3041 gtk_im_context_set_client_window (priv->im_context, NULL);
3043 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3044 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3045 gtk_clipboard_clear (clipboard);
3047 if (priv->text_area)
3049 gdk_window_set_user_data (priv->text_area, NULL);
3050 gdk_window_destroy (priv->text_area);
3051 priv->text_area = NULL;
3054 if (priv->popup_menu)
3056 gtk_widget_destroy (priv->popup_menu);
3057 priv->popup_menu = NULL;
3060 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3062 for (i = 0; i < MAX_ICONS; i++)
3064 if ((icon_info = priv->icons[i]) != NULL)
3066 if (icon_info->window != NULL)
3068 gdk_window_destroy (icon_info->window);
3069 icon_info->window = NULL;
3076 _gtk_entry_get_borders (GtkEntry *entry,
3077 GtkBorder *border_out)
3079 GtkEntryPrivate *priv = entry->priv;
3080 GtkWidget *widget = GTK_WIDGET (entry);
3081 GtkBorder tmp = { 0, 0, 0, 0 };
3082 GtkStyleContext *context;
3084 context = gtk_widget_get_style_context (widget);
3085 gtk_style_context_get_padding (context, 0, &tmp);
3087 if (priv->has_frame)
3091 gtk_style_context_get_border (context, 0, &border);
3092 tmp.top += border.top;
3093 tmp.right += border.right;
3094 tmp.bottom += border.bottom;
3095 tmp.left += border.left;
3098 if (!priv->interior_focus)
3100 tmp.top += priv->focus_width;
3101 tmp.right += priv->focus_width;
3102 tmp.bottom += priv->focus_width;
3103 tmp.left += priv->focus_width;
3106 if (border_out != NULL)
3111 gtk_entry_get_preferred_width (GtkWidget *widget,
3115 GtkEntry *entry = GTK_ENTRY (widget);
3116 GtkEntryPrivate *priv = entry->priv;
3117 PangoFontMetrics *metrics;
3119 PangoContext *context;
3120 GtkStyleContext *style_context;
3121 GtkStateFlags state;
3122 gint icon_widths = 0;
3126 context = gtk_widget_get_pango_context (widget);
3128 style_context = gtk_widget_get_style_context (widget);
3129 state = gtk_widget_get_state_flags (widget);
3131 metrics = pango_context_get_metrics (context,
3132 gtk_style_context_get_font (style_context, state),
3133 pango_context_get_language (context));
3135 _gtk_entry_get_borders (entry, &borders);
3137 if (priv->width_chars < 0)
3138 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3141 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3142 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3143 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3145 width = char_pixels * priv->width_chars + borders.left + borders.right;
3148 for (i = 0; i < MAX_ICONS; i++)
3150 icon_width = get_icon_width (entry, i);
3152 icon_widths += icon_width;
3155 if (icon_widths > width)
3156 width += icon_widths;
3158 pango_font_metrics_unref (metrics);
3165 gtk_entry_get_preferred_height (GtkWidget *widget,
3169 GtkEntry *entry = GTK_ENTRY (widget);
3170 GtkEntryPrivate *priv = entry->priv;
3171 PangoFontMetrics *metrics;
3173 GtkStyleContext *style_context;
3174 GtkStateFlags state;
3175 PangoContext *context;
3178 context = gtk_widget_get_pango_context (widget);
3180 style_context = gtk_widget_get_style_context (widget);
3181 state = gtk_widget_get_state_flags (widget);
3183 metrics = pango_context_get_metrics (context,
3184 gtk_style_context_get_font (style_context, state),
3185 pango_context_get_language (context));
3187 priv->ascent = pango_font_metrics_get_ascent (metrics);
3188 priv->descent = pango_font_metrics_get_descent (metrics);
3190 _gtk_entry_get_borders (entry, &borders);
3192 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3194 pango_font_metrics_unref (metrics);
3201 place_windows (GtkEntry *entry)
3203 GtkWidget *widget = GTK_WIDGET (entry);
3204 GtkEntryPrivate *priv = entry->priv;
3205 gint x, y, width, height;
3206 gint frame_x, frame_y;
3207 GtkAllocation primary;
3208 GtkAllocation secondary;
3209 EntryIconInfo *icon_info = NULL;
3211 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3212 get_text_area_size (entry, &x, &y, &width, &height);
3213 get_icon_allocations (entry, &primary, &secondary);
3215 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3216 y += priv->focus_width;
3218 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3219 x += secondary.width;
3222 width -= primary.width + secondary.width;
3226 primary.x += frame_x;
3227 primary.y += frame_y;
3228 secondary.x += frame_x;
3229 secondary.y += frame_y;
3231 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3232 gdk_window_move_resize (icon_info->window,
3233 primary.x, primary.y,
3234 primary.width, primary.height);
3236 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3237 gdk_window_move_resize (icon_info->window,
3238 secondary.x, secondary.y,
3239 secondary.width, secondary.height);
3241 gdk_window_move_resize (priv->text_area, x, y, width, height);
3245 gtk_entry_get_text_area_size (GtkEntry *entry,
3251 GtkEntryPrivate *priv = entry->priv;
3252 GtkWidget *widget = GTK_WIDGET (entry);
3253 GtkAllocation allocation;
3254 GtkRequisition requisition;
3259 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3260 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3262 gtk_widget_get_allocation (widget, &allocation);
3263 _gtk_entry_get_borders (entry, &borders);
3265 if (gtk_widget_get_realized (widget))
3266 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3268 frame_height = req_height;
3270 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3271 frame_height -= 2 * priv->focus_width;
3277 *y = floor ((frame_height - req_height) / 2) + borders.top;
3280 *width = allocation.width - borders.left - borders.right;
3283 *height = req_height - borders.top - borders.bottom;
3287 get_text_area_size (GtkEntry *entry,
3293 GtkEntryClass *class;
3295 g_return_if_fail (GTK_IS_ENTRY (entry));
3297 class = GTK_ENTRY_GET_CLASS (entry);
3299 if (class->get_text_area_size)
3300 class->get_text_area_size (entry, x, y, width, height);
3305 get_frame_size (GtkEntry *entry,
3306 gboolean relative_to_window,
3312 GtkEntryPrivate *priv = entry->priv;
3313 GtkAllocation allocation;
3314 GtkRequisition requisition;
3315 GtkWidget *widget = GTK_WIDGET (entry);
3318 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3320 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3322 gtk_widget_get_allocation (widget, &allocation);
3325 *x = relative_to_window ? allocation.x : 0;
3329 if (priv->is_cell_renderer)
3332 *y = (allocation.height - req_height) / 2;
3334 if (relative_to_window)
3339 *width = allocation.width;
3343 if (priv->is_cell_renderer)
3344 *height = allocation.height;
3346 *height = req_height;
3351 gtk_entry_size_allocate (GtkWidget *widget,
3352 GtkAllocation *allocation)
3354 GtkEntry *entry = GTK_ENTRY (widget);
3356 gtk_widget_set_allocation (widget, allocation);
3358 if (gtk_widget_get_realized (widget))
3360 GtkEntryCompletion* completion;
3362 place_windows (entry);
3363 gtk_entry_recompute (entry);
3365 completion = gtk_entry_get_completion (entry);
3366 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3367 _gtk_entry_completion_resize_popup (completion);
3372 should_prelight (GtkEntry *entry,
3373 GtkEntryIconPosition icon_pos)
3375 GtkEntryPrivate *priv = entry->priv;
3376 EntryIconInfo *icon_info = priv->icons[icon_pos];
3382 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3385 if (icon_info->pressed)
3388 gtk_widget_style_get (GTK_WIDGET (entry),
3389 "icon-prelight", &prelight,
3396 draw_icon (GtkWidget *widget,
3398 GtkEntryIconPosition icon_pos)
3400 GtkEntry *entry = GTK_ENTRY (widget);
3401 GtkEntryPrivate *priv = entry->priv;
3402 EntryIconInfo *icon_info = priv->icons[icon_pos];
3403 gint x, y, width, height, pix_width, pix_height;
3404 GtkStyleContext *context;
3410 width = gdk_window_get_width (icon_info->window);
3411 height = gdk_window_get_height (icon_info->window);
3413 /* size_allocate hasn't been called yet. These are the default values.
3415 if (width == 1 || height == 1)
3419 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3421 context = gtk_widget_get_style_context (widget);
3422 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3423 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3424 &pix_width, &pix_height);
3425 gtk_style_context_get_padding (context, 0, &padding);
3427 x = MAX (0, padding.left);
3428 y = MAX (0, (height - pix_height) / 2);
3430 _gtk_icon_helper_draw (icon_info->icon_helper,
3434 gtk_style_context_restore (context);
3440 gtk_entry_draw_frame (GtkWidget *widget,
3441 GtkStyleContext *context,
3444 GtkEntry *entry = GTK_ENTRY (widget);
3445 GtkEntryPrivate *priv = entry->priv;
3446 gint x = 0, y = 0, width, height;
3447 gint frame_x, frame_y;
3451 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3453 cairo_translate (cr, frame_x, frame_y);
3455 /* Fix a problem with some themes which assume that entry->text_area's
3456 * width equals widget->window's width
3457 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3458 if (GTK_IS_SPIN_BUTTON (widget))
3462 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3463 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3466 width += borders.left + borders.right;
3469 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3471 x += priv->focus_width;
3472 y += priv->focus_width;
3473 width -= 2 * priv->focus_width;
3474 height -= 2 * priv->focus_width;
3477 gtk_render_background (context, cr,
3478 x, y, width, height);
3480 if (priv->has_frame)
3481 gtk_render_frame (context, cr,
3482 x, y, width, height);
3484 gtk_entry_draw_progress (widget, context, cr);
3486 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3488 x -= priv->focus_width;
3489 y -= priv->focus_width;
3490 width += 2 * priv->focus_width;
3491 height += 2 * priv->focus_width;
3493 gtk_render_focus (context, cr,
3494 0, 0, width, height);
3501 get_progress_area (GtkWidget *widget,
3507 GtkEntry *entry = GTK_ENTRY (widget);
3508 GtkEntryPrivate *private = entry->priv;
3509 GtkBorder *progress_border;
3511 get_text_area_size (entry, x, y, width, height);
3513 if (!private->interior_focus)
3515 *x -= private->focus_width;
3516 *y -= private->focus_width;
3517 *width += 2 * private->focus_width;
3518 *height += 2 * private->focus_width;
3521 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3523 if (progress_border)
3525 *x += progress_border->left;
3526 *y += progress_border->top;
3527 *width -= progress_border->left + progress_border->right;
3528 *height -= progress_border->top + progress_border->bottom;
3530 gtk_border_free (progress_border);
3533 if (private->progress_pulse_mode)
3535 gdouble value = private->progress_pulse_current;
3537 *x += (gint) floor(value * (*width));
3538 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3540 else if (private->progress_fraction > 0)
3542 gdouble value = private->progress_fraction;
3544 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3548 bar_width = floor(value * (*width) + 0.5);
3549 *x += *width - bar_width;
3554 *width = (gint) floor(value * (*width) + 0.5);
3565 gtk_entry_draw_progress (GtkWidget *widget,
3566 GtkStyleContext *context,
3569 GtkEntry *entry = GTK_ENTRY (widget);
3570 GtkEntryPrivate *private = entry->priv;
3571 gint x, y, width, height;
3573 get_progress_area (widget, &x, &y, &width, &height);
3575 if ((width <= 0) || (height <= 0))
3578 gtk_style_context_save (context);
3579 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3580 if (private->progress_pulse_mode)
3581 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3583 gtk_render_activity (context, cr,
3584 x, y, width, height);
3586 gtk_style_context_restore (context);
3590 gtk_entry_draw (GtkWidget *widget,
3593 GtkEntry *entry = GTK_ENTRY (widget);
3594 GtkStyleContext *context;
3595 GtkEntryPrivate *priv = entry->priv;
3598 context = gtk_widget_get_style_context (widget);
3600 /* Draw entry_bg, shadow, progress and focus */
3601 gtk_entry_draw_frame (widget, context, cr);
3603 /* Draw text and cursor */
3606 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3608 if (priv->dnd_position != -1)
3609 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3611 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3613 /* When no text is being displayed at all, don't show the cursor */
3614 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3615 gtk_widget_has_focus (widget) &&
3616 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3617 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3622 for (i = 0; i < MAX_ICONS; i++)
3624 EntryIconInfo *icon_info = priv->icons[i];
3626 if (icon_info != NULL)
3627 draw_icon (widget, cr, i);
3634 gtk_entry_enter_notify (GtkWidget *widget,
3635 GdkEventCrossing *event)
3637 GtkEntry *entry = GTK_ENTRY (widget);
3638 GtkEntryPrivate *priv = entry->priv;
3641 for (i = 0; i < MAX_ICONS; i++)
3643 EntryIconInfo *icon_info = priv->icons[i];
3645 if (icon_info != NULL && event->window == icon_info->window)
3647 if (should_prelight (entry, i))
3649 icon_info->prelight = TRUE;
3650 gtk_widget_queue_draw (widget);
3661 gtk_entry_leave_notify (GtkWidget *widget,
3662 GdkEventCrossing *event)
3664 GtkEntry *entry = GTK_ENTRY (widget);
3665 GtkEntryPrivate *priv = entry->priv;
3668 for (i = 0; i < MAX_ICONS; i++)
3670 EntryIconInfo *icon_info = priv->icons[i];
3672 if (icon_info != NULL && event->window == icon_info->window)
3674 /* a grab means that we may never see the button release */
3675 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3676 icon_info->pressed = FALSE;
3678 if (should_prelight (entry, i))
3680 icon_info->prelight = FALSE;
3681 gtk_widget_queue_draw (widget);
3692 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3696 gint start_char, end_char;
3698 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3700 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3701 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3702 const char *text = pango_layout_get_text (layout);
3703 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3704 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3705 gint real_n_ranges, i;
3707 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3713 for (i = 0; i < real_n_ranges; ++i)
3715 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3716 r[2 * i] = r[2 * i] / PANGO_SCALE;
3721 *n_ranges = real_n_ranges;
3733 in_selection (GtkEntry *entry,
3738 gint retval = FALSE;
3740 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3742 for (i = 0; i < n_ranges; ++i)
3744 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3756 gtk_entry_button_press (GtkWidget *widget,
3757 GdkEventButton *event)
3759 GtkEntry *entry = GTK_ENTRY (widget);
3760 GtkEditable *editable = GTK_EDITABLE (widget);
3761 GtkEntryPrivate *priv = entry->priv;
3762 EntryIconInfo *icon_info = NULL;
3764 gint sel_start, sel_end;
3767 for (i = 0; i < MAX_ICONS; i++)
3769 icon_info = priv->icons[i];
3771 if (!icon_info || icon_info->insensitive)
3774 if (event->window == icon_info->window)
3776 if (should_prelight (entry, i))
3778 icon_info->prelight = FALSE;
3779 gtk_widget_queue_draw (widget);
3782 priv->start_x = event->x;
3783 priv->start_y = event->y;
3784 icon_info->pressed = TRUE;
3786 if (!icon_info->nonactivatable)
3787 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3793 if (event->window != priv->text_area ||
3794 (priv->button && event->button != priv->button))
3797 gtk_entry_reset_blink_time (entry);
3799 priv->button = event->button;
3801 if (!gtk_widget_has_focus (widget))
3803 priv->in_click = TRUE;
3804 gtk_widget_grab_focus (widget);
3805 priv->in_click = FALSE;
3808 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3810 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3812 gtk_entry_do_popup (entry, event);
3813 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3817 else if (event->button == GDK_BUTTON_PRIMARY)
3819 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3821 priv->select_words = FALSE;
3822 priv->select_lines = FALSE;
3825 gtk_widget_get_modifier_mask (widget,
3826 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3828 _gtk_entry_reset_im_context (entry);
3830 if (!have_selection) /* select from the current position to the clicked position */
3831 sel_start = sel_end = priv->current_pos;
3833 if (tmp_pos > sel_start && tmp_pos < sel_end)
3835 /* Truncate current selection, but keep it as big as possible */
3836 if (tmp_pos - sel_start > sel_end - tmp_pos)
3837 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3839 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3843 gboolean extend_to_left;
3846 /* Figure out what click selects and extend current selection */
3847 switch (event->type)
3849 case GDK_BUTTON_PRESS:
3850 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3853 case GDK_2BUTTON_PRESS:
3854 priv->select_words = TRUE;
3855 gtk_entry_select_word (entry);
3858 case GDK_3BUTTON_PRESS:
3859 priv->select_lines = TRUE;
3860 gtk_entry_select_line (entry);
3867 start = MIN (priv->current_pos, priv->selection_bound);
3868 start = MIN (sel_start, start);
3870 end = MAX (priv->current_pos, priv->selection_bound);
3871 end = MAX (sel_end, end);
3873 if (tmp_pos == sel_start || tmp_pos == sel_end)
3874 extend_to_left = (tmp_pos == start);
3876 extend_to_left = (end == sel_end);
3879 gtk_entry_set_positions (entry, start, end);
3881 gtk_entry_set_positions (entry, end, start);
3884 else /* no shift key */
3885 switch (event->type)
3887 case GDK_BUTTON_PRESS:
3888 if (in_selection (entry, event->x + priv->scroll_offset))
3890 /* Click inside the selection - we'll either start a drag, or
3891 * clear the selection
3893 priv->in_drag = TRUE;
3894 priv->drag_start_x = event->x + priv->scroll_offset;
3895 priv->drag_start_y = event->y;
3898 gtk_editable_set_position (editable, tmp_pos);
3901 case GDK_2BUTTON_PRESS:
3902 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3903 * receiving a GDK_2BUTTON_PRESS so we need to reset
3904 * priv->in_drag which may have been set above
3906 priv->in_drag = FALSE;
3907 priv->select_words = TRUE;
3908 gtk_entry_select_word (entry);
3911 case GDK_3BUTTON_PRESS:
3912 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3913 * receiving a GDK_3BUTTON_PRESS so we need to reset
3914 * priv->in_drag which may have been set above
3916 priv->in_drag = FALSE;
3917 priv->select_lines = TRUE;
3918 gtk_entry_select_line (entry);
3927 else if (event->button == GDK_BUTTON_MIDDLE && event->type == GDK_BUTTON_PRESS)
3931 priv->insert_pos = tmp_pos;
3932 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3937 gtk_widget_error_bell (widget);
3945 gtk_entry_button_release (GtkWidget *widget,
3946 GdkEventButton *event)
3948 GtkEntry *entry = GTK_ENTRY (widget);
3949 GtkEntryPrivate *priv = entry->priv;
3950 EntryIconInfo *icon_info = NULL;
3953 for (i = 0; i < MAX_ICONS; i++)
3955 icon_info = priv->icons[i];
3957 if (!icon_info || icon_info->insensitive)
3960 if (event->window == icon_info->window)
3962 icon_info->pressed = FALSE;
3964 if (should_prelight (entry, i) &&
3965 event->x >= 0 && event->y >= 0 &&
3966 event->x < gdk_window_get_width (icon_info->window) &&
3967 event->y < gdk_window_get_height (icon_info->window))
3969 icon_info->prelight = TRUE;
3970 gtk_widget_queue_draw (widget);
3973 if (!icon_info->nonactivatable)
3974 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3980 if (event->window != priv->text_area || priv->button != event->button)
3985 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3987 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3994 gtk_entry_update_primary_selection (entry);
4000 _gtk_entry_get_selected_text (GtkEntry *entry)
4002 GtkEditable *editable = GTK_EDITABLE (entry);
4003 gint start_text, end_text;
4006 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4007 text = gtk_editable_get_chars (editable, start_text, end_text);
4013 gtk_entry_motion_notify (GtkWidget *widget,
4014 GdkEventMotion *event)
4016 GtkEntry *entry = GTK_ENTRY (widget);
4017 GtkEntryPrivate *priv = entry->priv;
4018 EntryIconInfo *icon_info = NULL;
4022 for (i = 0; i < MAX_ICONS; i++)
4024 icon_info = priv->icons[i];
4026 if (!icon_info || icon_info->insensitive)
4029 if (event->window == icon_info->window)
4031 if (icon_info->pressed &&
4032 icon_info->target_list != NULL &&
4033 gtk_drag_check_threshold (widget,
4039 icon_info->in_drag = TRUE;
4040 icon_info->pressed = FALSE;
4041 gtk_drag_begin (widget,
4042 icon_info->target_list,
4052 if (priv->mouse_cursor_obscured)
4056 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4057 gdk_window_set_cursor (priv->text_area, cursor);
4058 g_object_unref (cursor);
4059 priv->mouse_cursor_obscured = FALSE;
4062 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4065 if (priv->select_lines)
4068 gdk_event_request_motions (event);
4072 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4073 gtk_drag_check_threshold (widget,
4074 priv->drag_start_x, priv->drag_start_y,
4075 event->x + priv->scroll_offset, event->y))
4077 GdkDragContext *context;
4078 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4079 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4081 cairo_surface_t *surface;
4083 gtk_target_list_add_text_targets (target_list, 0);
4085 text = _gtk_entry_get_selected_text (entry);
4086 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4088 context = gtk_drag_begin (widget, target_list, actions,
4089 priv->button, (GdkEvent *)event);
4092 gtk_drag_set_icon_surface (context, surface);
4094 gtk_drag_set_icon_default (context);
4097 cairo_surface_destroy (surface);
4100 priv->in_drag = FALSE;
4103 gtk_target_list_unref (target_list);
4110 else if (event->y >= gdk_window_get_height (priv->text_area))
4111 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4113 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4115 if (priv->select_words)
4118 gint old_min, old_max;
4121 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4122 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4124 pos = priv->current_pos;
4125 bound = priv->selection_bound;
4127 old_min = MIN(priv->current_pos, priv->selection_bound);
4128 old_max = MAX(priv->current_pos, priv->selection_bound);
4135 else if (old_max < max)
4140 else if (pos == old_min)
4142 if (priv->current_pos != min)
4147 if (priv->current_pos != max)
4151 gtk_entry_set_positions (entry, pos, bound);
4154 gtk_entry_set_positions (entry, tmp_pos, -1);
4161 set_invisible_cursor (GdkWindow *window)
4163 GdkDisplay *display;
4166 display = gdk_window_get_display (window);
4167 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4169 gdk_window_set_cursor (window, cursor);
4171 g_object_unref (cursor);
4175 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4177 GtkEntryPrivate *priv = entry->priv;
4179 if (priv->mouse_cursor_obscured)
4182 set_invisible_cursor (priv->text_area);
4184 priv->mouse_cursor_obscured = TRUE;
4188 gtk_entry_key_press (GtkWidget *widget,
4191 GtkEntry *entry = GTK_ENTRY (widget);
4192 GtkEntryPrivate *priv = entry->priv;
4194 gtk_entry_reset_blink_time (entry);
4195 gtk_entry_pend_cursor_blink (entry);
4199 if (gtk_im_context_filter_keypress (priv->im_context, event))
4201 gtk_entry_obscure_mouse_cursor (entry);
4202 priv->need_im_reset = TRUE;
4207 if (event->keyval == GDK_KEY_Return ||
4208 event->keyval == GDK_KEY_KP_Enter ||
4209 event->keyval == GDK_KEY_ISO_Enter ||
4210 event->keyval == GDK_KEY_Escape)
4212 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4214 if (completion && completion->priv->completion_timeout)
4216 g_source_remove (completion->priv->completion_timeout);
4217 completion->priv->completion_timeout = 0;
4220 _gtk_entry_reset_im_context (entry);
4223 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4224 /* Activate key bindings
4228 if (!priv->editable && event->length)
4229 gtk_widget_error_bell (widget);
4235 gtk_entry_key_release (GtkWidget *widget,
4238 GtkEntry *entry = GTK_ENTRY (widget);
4239 GtkEntryPrivate *priv = entry->priv;
4243 if (gtk_im_context_filter_keypress (priv->im_context, event))
4245 priv->need_im_reset = TRUE;
4250 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4254 gtk_entry_focus_in (GtkWidget *widget,
4255 GdkEventFocus *event)
4257 GtkEntry *entry = GTK_ENTRY (widget);
4258 GtkEntryPrivate *priv = entry->priv;
4261 gtk_widget_queue_draw (widget);
4263 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4267 priv->need_im_reset = TRUE;
4268 gtk_im_context_focus_in (priv->im_context);
4269 keymap_state_changed (keymap, entry);
4270 g_signal_connect (keymap, "state-changed",
4271 G_CALLBACK (keymap_state_changed), entry);
4274 g_signal_connect (keymap, "direction-changed",
4275 G_CALLBACK (keymap_direction_changed), entry);
4277 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4278 priv->placeholder_text != NULL)
4280 gtk_entry_recompute (entry);
4284 gtk_entry_reset_blink_time (entry);
4285 gtk_entry_check_cursor_blink (entry);
4292 gtk_entry_focus_out (GtkWidget *widget,
4293 GdkEventFocus *event)
4295 GtkEntry *entry = GTK_ENTRY (widget);
4296 GtkEntryPrivate *priv = entry->priv;
4297 GtkEntryCompletion *completion;
4300 gtk_widget_queue_draw (widget);
4302 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4306 priv->need_im_reset = TRUE;
4307 gtk_im_context_focus_out (priv->im_context);
4308 remove_capslock_feedback (entry);
4311 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4312 priv->placeholder_text != NULL)
4314 gtk_entry_recompute (entry);
4318 gtk_entry_check_cursor_blink (entry);
4321 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4322 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4324 completion = gtk_entry_get_completion (entry);
4326 _gtk_entry_completion_popdown (completion);
4332 gtk_entry_grab_focus (GtkWidget *widget)
4334 GtkEntry *entry = GTK_ENTRY (widget);
4335 GtkEntryPrivate *priv = entry->priv;
4336 gboolean select_on_focus;
4338 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4340 if (priv->editable && !priv->in_click)
4342 g_object_get (gtk_widget_get_settings (widget),
4343 "gtk-entry-select-on-focus",
4347 if (select_on_focus)
4348 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4353 gtk_entry_direction_changed (GtkWidget *widget,
4354 GtkTextDirection previous_dir)
4356 GtkEntry *entry = GTK_ENTRY (widget);
4358 gtk_entry_recompute (entry);
4360 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4364 gtk_entry_state_flags_changed (GtkWidget *widget,
4365 GtkStateFlags previous_state)
4367 GtkEntry *entry = GTK_ENTRY (widget);
4368 GtkEntryPrivate *priv = entry->priv;
4371 if (gtk_widget_get_realized (widget))
4373 if (gtk_widget_is_sensitive (widget))
4374 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4378 gdk_window_set_cursor (priv->text_area, cursor);
4381 g_object_unref (cursor);
4383 priv->mouse_cursor_obscured = FALSE;
4385 update_cursors (widget);
4388 if (!gtk_widget_is_sensitive (widget))
4390 /* Clear any selection */
4391 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4394 gtk_entry_update_cached_style_values (entry);
4398 gtk_entry_screen_changed (GtkWidget *widget,
4399 GdkScreen *old_screen)
4401 gtk_entry_recompute (GTK_ENTRY (widget));
4404 /* GtkEditable method implementations
4407 gtk_entry_insert_text (GtkEditable *editable,
4408 const gchar *new_text,
4409 gint new_text_length,
4412 g_object_ref (editable);
4415 * The incoming text may a password or other secret. We make sure
4416 * not to copy it into temporary buffers.
4419 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4421 g_object_unref (editable);
4425 gtk_entry_delete_text (GtkEditable *editable,
4429 g_object_ref (editable);
4431 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4433 g_object_unref (editable);
4437 gtk_entry_get_chars (GtkEditable *editable,
4441 GtkEntry *entry = GTK_ENTRY (editable);
4444 gint start_index, end_index;
4446 text = gtk_entry_buffer_get_text (get_buffer (entry));
4447 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4450 end_pos = text_length;
4452 start_pos = MIN (text_length, start_pos);
4453 end_pos = MIN (text_length, end_pos);
4455 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4456 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4458 return g_strndup (text + start_index, end_index - start_index);
4462 gtk_entry_real_set_position (GtkEditable *editable,
4465 GtkEntry *entry = GTK_ENTRY (editable);
4466 GtkEntryPrivate *priv = entry->priv;
4470 length = gtk_entry_buffer_get_length (get_buffer (entry));
4471 if (position < 0 || position > length)
4474 if (position != priv->current_pos ||
4475 position != priv->selection_bound)
4477 _gtk_entry_reset_im_context (entry);
4478 gtk_entry_set_positions (entry, position, position);
4483 gtk_entry_get_position (GtkEditable *editable)
4485 GtkEntry *entry = GTK_ENTRY (editable);
4486 GtkEntryPrivate *priv = entry->priv;
4488 return priv->current_pos;
4492 gtk_entry_set_selection_bounds (GtkEditable *editable,
4496 GtkEntry *entry = GTK_ENTRY (editable);
4499 length = gtk_entry_buffer_get_length (get_buffer (entry));
4505 _gtk_entry_reset_im_context (entry);
4507 gtk_entry_set_positions (entry,
4509 MIN (start, length));
4511 gtk_entry_update_primary_selection (entry);
4515 gtk_entry_get_selection_bounds (GtkEditable *editable,
4519 GtkEntry *entry = GTK_ENTRY (editable);
4520 GtkEntryPrivate *priv = entry->priv;
4522 *start = priv->selection_bound;
4523 *end = priv->current_pos;
4525 return (priv->selection_bound != priv->current_pos);
4529 icon_theme_changed (GtkEntry *entry)
4531 GtkEntryPrivate *priv = entry->priv;
4534 for (i = 0; i < MAX_ICONS; i++)
4536 EntryIconInfo *icon_info = priv->icons[i];
4537 if (icon_info != NULL)
4538 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4541 gtk_widget_queue_draw (GTK_WIDGET (entry));
4545 gtk_entry_update_cached_style_values (GtkEntry *entry)
4547 GtkEntryPrivate *priv = entry->priv;
4549 gboolean interior_focus;
4551 gtk_widget_style_get (GTK_WIDGET (entry),
4552 "focus-line-width", &focus_width,
4553 "interior-focus", &interior_focus,
4555 priv->focus_width = focus_width;
4556 priv->interior_focus = interior_focus;
4558 if (!priv->invisible_char_set)
4560 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4562 if (priv->invisible_char != ch)
4564 priv->invisible_char = ch;
4565 g_object_notify (G_OBJECT (entry), "invisible-char");
4571 gtk_entry_style_updated (GtkWidget *widget)
4573 GtkEntry *entry = GTK_ENTRY (widget);
4575 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4577 gtk_entry_update_cached_style_values (entry);
4579 gtk_entry_recompute (entry);
4581 icon_theme_changed (entry);
4584 /* GtkCellEditable method implementations
4587 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4589 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4590 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4594 gtk_cell_editable_key_press_event (GtkEntry *entry,
4595 GdkEventKey *key_event,
4598 GtkEntryPrivate *priv = entry->priv;
4600 if (key_event->keyval == GDK_KEY_Escape)
4602 priv->editing_canceled = TRUE;
4603 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4604 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4609 /* override focus */
4610 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4612 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4613 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4622 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4625 GtkEntry *entry = GTK_ENTRY (cell_editable);
4626 GtkEntryPrivate *priv = entry->priv;
4628 priv->is_cell_renderer = TRUE;
4630 g_signal_connect (cell_editable, "activate",
4631 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4632 g_signal_connect (cell_editable, "key-press-event",
4633 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4637 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4639 if (password_hint->source_id)
4640 g_source_remove (password_hint->source_id);
4642 g_slice_free (GtkEntryPasswordHint, password_hint);
4647 gtk_entry_remove_password_hint (gpointer data)
4649 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4650 password_hint->position = -1;
4652 /* Force the string to be redrawn, but now without a visible character */
4653 gtk_entry_recompute (GTK_ENTRY (data));
4657 /* Default signal handlers
4660 gtk_entry_real_insert_text (GtkEditable *editable,
4661 const gchar *new_text,
4662 gint new_text_length,
4668 n_chars = g_utf8_strlen (new_text, new_text_length);
4671 * The actual insertion into the buffer. This will end up firing the
4672 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4673 * buffer_notify_text(), buffer_notify_length()
4675 begin_change (GTK_ENTRY (editable));
4677 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4679 end_change (GTK_ENTRY (editable));
4681 if (n_inserted != n_chars)
4682 gtk_widget_error_bell (GTK_WIDGET (editable));
4684 *position += n_inserted;
4688 gtk_entry_real_delete_text (GtkEditable *editable,
4693 * The actual deletion from the buffer. This will end up firing the
4694 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4695 * buffer_notify_text(), buffer_notify_length()
4698 begin_change (GTK_ENTRY (editable));
4700 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4702 end_change (GTK_ENTRY (editable));
4705 /* GtkEntryBuffer signal handlers
4708 buffer_inserted_text (GtkEntryBuffer *buffer,
4714 GtkEntryPrivate *priv = entry->priv;
4715 guint password_hint_timeout;
4717 gint selection_bound;
4719 current_pos = priv->current_pos;
4720 if (current_pos > position)
4721 current_pos += n_chars;
4723 selection_bound = priv->selection_bound;
4724 if (selection_bound > position)
4725 selection_bound += n_chars;
4727 gtk_entry_set_positions (entry, current_pos, selection_bound);
4729 /* Calculate the password hint if it needs to be displayed. */
4730 if (n_chars == 1 && !priv->visible)
4732 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4733 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4736 if (password_hint_timeout > 0)
4738 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4739 quark_password_hint);
4742 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4743 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4744 (GDestroyNotify)gtk_entry_password_hint_free);
4747 password_hint->position = position;
4748 if (password_hint->source_id)
4749 g_source_remove (password_hint->source_id);
4750 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4751 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4757 buffer_deleted_text (GtkEntryBuffer *buffer,
4762 GtkEntryPrivate *priv = entry->priv;
4763 guint end_pos = position + n_chars;
4764 gint selection_bound;
4767 current_pos = priv->current_pos;
4768 if (current_pos > position)
4769 current_pos -= MIN (current_pos, end_pos) - position;
4771 selection_bound = priv->selection_bound;
4772 if (selection_bound > position)
4773 selection_bound -= MIN (selection_bound, end_pos) - position;
4775 gtk_entry_set_positions (entry, current_pos, selection_bound);
4777 /* We might have deleted the selection */
4778 gtk_entry_update_primary_selection (entry);
4780 /* Disable the password hint if one exists. */
4783 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4784 quark_password_hint);
4787 if (password_hint->source_id)
4788 g_source_remove (password_hint->source_id);
4789 password_hint->source_id = 0;
4790 password_hint->position = -1;
4796 buffer_notify_text (GtkEntryBuffer *buffer,
4800 gtk_entry_recompute (entry);
4801 emit_changed (entry);
4802 g_object_notify (G_OBJECT (entry), "text");
4806 buffer_notify_length (GtkEntryBuffer *buffer,
4810 g_object_notify (G_OBJECT (entry), "text-length");
4814 buffer_notify_max_length (GtkEntryBuffer *buffer,
4818 g_object_notify (G_OBJECT (entry), "max-length");
4822 buffer_connect_signals (GtkEntry *entry)
4824 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4825 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4826 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4827 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4828 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4832 buffer_disconnect_signals (GtkEntry *entry)
4834 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4835 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4836 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4837 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4838 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4841 /* Compute the X position for an offset that corresponds to the "more important
4842 * cursor position for that offset. We use this when trying to guess to which
4843 * end of the selection we should go to when the user hits the left or
4847 get_better_cursor_x (GtkEntry *entry,
4850 GtkEntryPrivate *priv = entry->priv;
4851 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4852 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4853 gboolean split_cursor;
4855 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4856 const gchar *text = pango_layout_get_text (layout);
4857 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4859 PangoRectangle strong_pos, weak_pos;
4861 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4862 "gtk-split-cursor", &split_cursor,
4865 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4868 return strong_pos.x / PANGO_SCALE;
4870 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4874 gtk_entry_move_cursor (GtkEntry *entry,
4875 GtkMovementStep step,
4877 gboolean extend_selection)
4879 GtkEntryPrivate *priv = entry->priv;
4880 gint new_pos = priv->current_pos;
4882 _gtk_entry_reset_im_context (entry);
4884 if (priv->current_pos != priv->selection_bound && !extend_selection)
4886 /* If we have a current selection and aren't extending it, move to the
4887 * start/or end of the selection as appropriate
4891 case GTK_MOVEMENT_VISUAL_POSITIONS:
4893 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4894 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4897 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4899 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4902 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4903 case GTK_MOVEMENT_WORDS:
4905 new_pos = MIN (priv->current_pos, priv->selection_bound);
4907 new_pos = MAX (priv->current_pos, priv->selection_bound);
4909 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4910 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4911 case GTK_MOVEMENT_BUFFER_ENDS:
4912 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4914 case GTK_MOVEMENT_DISPLAY_LINES:
4915 case GTK_MOVEMENT_PARAGRAPHS:
4916 case GTK_MOVEMENT_PAGES:
4917 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4925 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4926 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4928 case GTK_MOVEMENT_VISUAL_POSITIONS:
4929 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4930 if (priv->current_pos == new_pos)
4932 if (!extend_selection)
4934 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4936 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4938 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4941 gtk_widget_child_focus (toplevel,
4943 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4948 gtk_widget_error_bell (GTK_WIDGET (entry));
4952 case GTK_MOVEMENT_WORDS:
4955 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4960 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4963 if (priv->current_pos == new_pos)
4964 gtk_widget_error_bell (GTK_WIDGET (entry));
4966 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4967 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4968 case GTK_MOVEMENT_BUFFER_ENDS:
4969 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4970 if (priv->current_pos == new_pos)
4971 gtk_widget_error_bell (GTK_WIDGET (entry));
4973 case GTK_MOVEMENT_DISPLAY_LINES:
4974 case GTK_MOVEMENT_PARAGRAPHS:
4975 case GTK_MOVEMENT_PAGES:
4976 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4981 if (extend_selection)
4982 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4984 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4986 gtk_entry_pend_cursor_blink (entry);
4990 gtk_entry_insert_at_cursor (GtkEntry *entry,
4993 GtkEntryPrivate *priv = entry->priv;
4994 GtkEditable *editable = GTK_EDITABLE (entry);
4995 gint pos = priv->current_pos;
4999 _gtk_entry_reset_im_context (entry);
5001 gtk_editable_insert_text (editable, str, -1, &pos);
5002 gtk_editable_set_position (editable, pos);
5007 gtk_entry_delete_from_cursor (GtkEntry *entry,
5011 GtkEntryPrivate *priv = entry->priv;
5012 GtkEditable *editable = GTK_EDITABLE (entry);
5013 gint start_pos = priv->current_pos;
5014 gint end_pos = priv->current_pos;
5015 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5017 _gtk_entry_reset_im_context (entry);
5019 if (!priv->editable)
5021 gtk_widget_error_bell (GTK_WIDGET (entry));
5025 if (priv->selection_bound != priv->current_pos)
5027 gtk_editable_delete_selection (editable);
5033 case GTK_DELETE_CHARS:
5034 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5035 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5037 case GTK_DELETE_WORDS:
5040 /* Move to end of current word, or if not on a word, end of previous word */
5041 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5042 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5046 /* Move to beginning of current word, or if not on a word, begining of next word */
5047 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5048 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5052 case GTK_DELETE_WORD_ENDS:
5055 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5060 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5063 gtk_editable_delete_text (editable, start_pos, end_pos);
5065 case GTK_DELETE_DISPLAY_LINE_ENDS:
5066 case GTK_DELETE_PARAGRAPH_ENDS:
5068 gtk_editable_delete_text (editable, 0, priv->current_pos);
5070 gtk_editable_delete_text (editable, priv->current_pos, -1);
5072 case GTK_DELETE_DISPLAY_LINES:
5073 case GTK_DELETE_PARAGRAPHS:
5074 gtk_editable_delete_text (editable, 0, -1);
5076 case GTK_DELETE_WHITESPACE:
5077 gtk_entry_delete_whitespace (entry);
5081 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5082 gtk_widget_error_bell (GTK_WIDGET (entry));
5084 gtk_entry_pend_cursor_blink (entry);
5088 gtk_entry_backspace (GtkEntry *entry)
5090 GtkEntryPrivate *priv = entry->priv;
5091 GtkEditable *editable = GTK_EDITABLE (entry);
5094 _gtk_entry_reset_im_context (entry);
5096 if (!priv->editable)
5098 gtk_widget_error_bell (GTK_WIDGET (entry));
5102 if (priv->selection_bound != priv->current_pos)
5104 gtk_editable_delete_selection (editable);
5108 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5110 if (prev_pos < priv->current_pos)
5112 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5113 PangoLogAttr *log_attrs;
5116 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5118 /* Deleting parts of characters */
5119 if (log_attrs[priv->current_pos].backspace_deletes_character)
5121 gchar *cluster_text;
5122 gchar *normalized_text;
5125 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5127 normalized_text = g_utf8_normalize (cluster_text,
5128 strlen (cluster_text),
5130 len = g_utf8_strlen (normalized_text, -1);
5132 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5135 gint pos = priv->current_pos;
5137 gtk_editable_insert_text (editable, normalized_text,
5138 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5140 gtk_editable_set_position (editable, pos);
5143 g_free (normalized_text);
5144 g_free (cluster_text);
5148 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5155 gtk_widget_error_bell (GTK_WIDGET (entry));
5158 gtk_entry_pend_cursor_blink (entry);
5162 gtk_entry_copy_clipboard (GtkEntry *entry)
5164 GtkEntryPrivate *priv = entry->priv;
5165 GtkEditable *editable = GTK_EDITABLE (entry);
5169 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5173 gtk_widget_error_bell (GTK_WIDGET (entry));
5177 str = gtk_entry_get_display_text (entry, start, end);
5178 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5179 GDK_SELECTION_CLIPBOARD),
5186 gtk_entry_cut_clipboard (GtkEntry *entry)
5188 GtkEntryPrivate *priv = entry->priv;
5189 GtkEditable *editable = GTK_EDITABLE (entry);
5194 gtk_widget_error_bell (GTK_WIDGET (entry));
5198 gtk_entry_copy_clipboard (entry);
5202 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5203 gtk_editable_delete_text (editable, start, end);
5207 gtk_widget_error_bell (GTK_WIDGET (entry));
5212 gtk_entry_paste_clipboard (GtkEntry *entry)
5214 GtkEntryPrivate *priv = entry->priv;
5217 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5219 gtk_widget_error_bell (GTK_WIDGET (entry));
5223 gtk_entry_delete_cb (GtkEntry *entry)
5225 GtkEntryPrivate *priv = entry->priv;
5226 GtkEditable *editable = GTK_EDITABLE (entry);
5231 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5232 gtk_editable_delete_text (editable, start, end);
5237 gtk_entry_toggle_overwrite (GtkEntry *entry)
5239 GtkEntryPrivate *priv = entry->priv;
5241 priv->overwrite_mode = !priv->overwrite_mode;
5242 gtk_entry_pend_cursor_blink (entry);
5243 gtk_widget_queue_draw (GTK_WIDGET (entry));
5247 gtk_entry_select_all (GtkEntry *entry)
5249 gtk_entry_select_line (entry);
5253 gtk_entry_real_activate (GtkEntry *entry)
5255 GtkEntryPrivate *priv = entry->priv;
5257 GtkWidget *default_widget, *focus_widget;
5258 GtkWidget *toplevel;
5261 widget = GTK_WIDGET (entry);
5263 if (priv->activates_default)
5265 toplevel = gtk_widget_get_toplevel (widget);
5266 if (GTK_IS_WINDOW (toplevel))
5268 window = GTK_WINDOW (toplevel);
5272 default_widget = gtk_window_get_default_widget (window);
5273 focus_widget = gtk_window_get_focus (window);
5274 if (widget != default_widget &&
5275 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5276 gtk_window_activate_default (window);
5283 keymap_direction_changed (GdkKeymap *keymap,
5286 gtk_entry_recompute (entry);
5289 /* IM Context Callbacks
5293 gtk_entry_commit_cb (GtkIMContext *context,
5297 GtkEntryPrivate *priv = entry->priv;
5300 gtk_entry_enter_text (entry, str);
5304 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5307 GtkEntryPrivate *priv = entry->priv;
5311 gchar *preedit_string;
5314 gtk_im_context_get_preedit_string (priv->im_context,
5315 &preedit_string, NULL,
5317 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5318 priv->preedit_length = strlen (preedit_string);
5319 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5320 priv->preedit_cursor = cursor_pos;
5321 g_free (preedit_string);
5323 gtk_entry_recompute (entry);
5328 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5331 GtkEntryPrivate *priv = entry->priv;
5334 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5335 text = gtk_entry_get_display_text (entry, 0, -1);
5336 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5337 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5344 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5349 GtkEntryPrivate *priv = entry->priv;
5352 gtk_editable_delete_text (GTK_EDITABLE (entry),
5353 priv->current_pos + offset,
5354 priv->current_pos + offset + n_chars);
5359 /* Internal functions
5362 /* Used for im_commit_cb and inserting Unicode chars */
5364 gtk_entry_enter_text (GtkEntry *entry,
5367 GtkEntryPrivate *priv = entry->priv;
5368 GtkEditable *editable = GTK_EDITABLE (entry);
5370 gboolean old_need_im_reset;
5372 old_need_im_reset = priv->need_im_reset;
5373 priv->need_im_reset = FALSE;
5375 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5376 gtk_editable_delete_selection (editable);
5379 if (priv->overwrite_mode)
5380 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5383 tmp_pos = priv->current_pos;
5384 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5385 gtk_editable_set_position (editable, tmp_pos);
5387 priv->need_im_reset = old_need_im_reset;
5390 /* All changes to priv->current_pos and priv->selection_bound
5391 * should go through this function.
5394 gtk_entry_set_positions (GtkEntry *entry,
5396 gint selection_bound)
5398 GtkEntryPrivate *priv = entry->priv;
5399 gboolean changed = FALSE;
5401 g_object_freeze_notify (G_OBJECT (entry));
5403 if (current_pos != -1 &&
5404 priv->current_pos != current_pos)
5406 priv->current_pos = current_pos;
5409 g_object_notify (G_OBJECT (entry), "cursor-position");
5412 if (selection_bound != -1 &&
5413 priv->selection_bound != selection_bound)
5415 priv->selection_bound = selection_bound;
5418 g_object_notify (G_OBJECT (entry), "selection-bound");
5421 g_object_thaw_notify (G_OBJECT (entry));
5425 gtk_entry_move_adjustments (entry);
5426 gtk_entry_recompute (entry);
5431 gtk_entry_reset_layout (GtkEntry *entry)
5433 GtkEntryPrivate *priv = entry->priv;
5435 if (priv->cached_layout)
5437 g_object_unref (priv->cached_layout);
5438 priv->cached_layout = NULL;
5443 update_im_cursor_location (GtkEntry *entry)
5445 GtkEntryPrivate *priv = entry->priv;
5448 gint strong_xoffset;
5449 gint area_width, area_height;
5451 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5452 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5454 strong_xoffset = strong_x - priv->scroll_offset;
5455 if (strong_xoffset < 0)
5459 else if (strong_xoffset > area_width)
5461 strong_xoffset = area_width;
5463 area.x = strong_xoffset;
5466 area.height = area_height;
5468 gtk_im_context_set_cursor_location (priv->im_context, &area);
5472 recompute_idle_func (gpointer data)
5474 GtkEntry *entry = GTK_ENTRY (data);
5475 GtkEntryPrivate *priv = entry->priv;
5477 priv->recompute_idle = 0;
5479 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5481 gtk_entry_adjust_scroll (entry);
5482 gtk_widget_queue_draw (GTK_WIDGET (entry));
5484 update_im_cursor_location (entry);
5491 gtk_entry_recompute (GtkEntry *entry)
5493 GtkEntryPrivate *priv = entry->priv;
5495 gtk_entry_reset_layout (entry);
5496 gtk_entry_check_cursor_blink (entry);
5498 if (!priv->recompute_idle)
5500 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5501 recompute_idle_func, entry, NULL);
5506 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5509 GtkWidget *widget = GTK_WIDGET (entry);
5510 GtkStyleContext *context;
5511 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5513 context = gtk_widget_get_style_context (widget);
5514 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5516 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5517 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5518 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5521 static inline gboolean
5522 show_placeholder_text (GtkEntry *entry)
5524 GtkEntryPrivate *priv = entry->priv;
5526 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5527 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5528 priv->placeholder_text != NULL)
5534 static PangoLayout *
5535 gtk_entry_create_layout (GtkEntry *entry,
5536 gboolean include_preedit)
5538 GtkEntryPrivate *priv = entry->priv;
5539 GtkWidget *widget = GTK_WIDGET (entry);
5540 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5541 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5542 gboolean placeholder_layout = show_placeholder_text (entry);
5544 gchar *preedit_string = NULL;
5545 gint preedit_length = 0;
5546 PangoAttrList *preedit_attrs = NULL;
5551 pango_layout_set_single_paragraph_mode (layout, TRUE);
5553 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5554 n_bytes = strlen (display);
5556 if (!placeholder_layout && include_preedit)
5558 gtk_im_context_get_preedit_string (priv->im_context,
5559 &preedit_string, &preedit_attrs, NULL);
5560 preedit_length = priv->preedit_length;
5562 else if (placeholder_layout)
5565 PangoAttribute *attr;
5567 gtk_entry_get_placeholder_text_color (entry, &color);
5568 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5569 attr->start_index = 0;
5570 attr->end_index = G_MAXINT;
5571 pango_attr_list_insert (tmp_attrs, attr);
5576 GString *tmp_string = g_string_new (display);
5577 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5579 g_string_insert (tmp_string, cursor_index, preedit_string);
5581 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5583 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5584 cursor_index, preedit_length);
5586 g_string_free (tmp_string, TRUE);
5590 PangoDirection pango_dir;
5592 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5593 pango_dir = pango_find_base_dir (display, n_bytes);
5595 pango_dir = PANGO_DIRECTION_NEUTRAL;
5597 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5599 if (gtk_widget_has_focus (widget))
5601 GdkDisplay *display = gtk_widget_get_display (widget);
5602 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5603 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5604 pango_dir = PANGO_DIRECTION_RTL;
5606 pango_dir = PANGO_DIRECTION_LTR;
5610 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5611 pango_dir = PANGO_DIRECTION_RTL;
5613 pango_dir = PANGO_DIRECTION_LTR;
5617 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5620 priv->resolved_dir = pango_dir;
5622 pango_layout_set_text (layout, display, n_bytes);
5625 pango_layout_set_attributes (layout, tmp_attrs);
5627 g_free (preedit_string);
5631 pango_attr_list_unref (preedit_attrs);
5633 pango_attr_list_unref (tmp_attrs);
5638 static PangoLayout *
5639 gtk_entry_ensure_layout (GtkEntry *entry,
5640 gboolean include_preedit)
5642 GtkEntryPrivate *priv = entry->priv;
5644 if (priv->preedit_length > 0 &&
5645 !include_preedit != !priv->cache_includes_preedit)
5646 gtk_entry_reset_layout (entry);
5648 if (!priv->cached_layout)
5650 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5651 priv->cache_includes_preedit = include_preedit;
5654 return priv->cached_layout;
5658 get_layout_position (GtkEntry *entry,
5662 GtkEntryPrivate *priv = entry->priv;
5663 PangoLayout *layout;
5664 PangoRectangle logical_rect;
5665 gint area_width, area_height;
5667 PangoLayoutLine *line;
5669 layout = gtk_entry_ensure_layout (entry, TRUE);
5671 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5672 area_height = PANGO_SCALE * area_height;
5674 line = pango_layout_get_lines_readonly (layout)->data;
5675 pango_layout_line_get_extents (line, NULL, &logical_rect);
5677 /* Align primarily for locale's ascent/descent */
5678 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5679 priv->ascent + logical_rect.y);
5681 /* Now see if we need to adjust to fit in actual drawn string */
5682 if (logical_rect.height > area_height)
5683 y_pos = (area_height - logical_rect.height) / 2;
5686 else if (y_pos + logical_rect.height > area_height)
5687 y_pos = area_height - logical_rect.height;
5689 y_pos = y_pos / PANGO_SCALE;
5692 *x = - priv->scroll_offset;
5699 draw_text_with_color (GtkEntry *entry,
5701 GdkRGBA *default_color)
5703 GtkEntryPrivate *priv = entry->priv;
5704 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5707 gint start_pos, end_pos;
5709 widget = GTK_WIDGET (entry);
5713 get_layout_position (entry, &x, &y);
5715 cairo_move_to (cr, x, y);
5716 gdk_cairo_set_source_rgba (cr, default_color);
5717 pango_cairo_show_layout (cr, layout);
5719 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5723 PangoRectangle logical_rect;
5724 GdkRGBA selection_color, text_color;
5725 GtkStyleContext *context;
5726 GtkStateFlags state;
5728 context = gtk_widget_get_style_context (widget);
5729 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5730 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5732 state = gtk_widget_get_state_flags (widget);
5733 state |= GTK_STATE_FLAG_SELECTED;
5735 gtk_style_context_get_background_color (context, state, &selection_color);
5736 gtk_style_context_get_color (context, state, &text_color);
5738 for (i = 0; i < n_ranges; ++i)
5739 cairo_rectangle (cr,
5740 - priv->scroll_offset + ranges[2 * i],
5743 logical_rect.height);
5747 gdk_cairo_set_source_rgba (cr, &selection_color);
5750 cairo_move_to (cr, x, y);
5751 gdk_cairo_set_source_rgba (cr, &text_color);
5752 pango_cairo_show_layout (cr, layout);
5760 gtk_entry_draw_text (GtkEntry *entry,
5763 GtkEntryPrivate *priv = entry->priv;
5764 GtkWidget *widget = GTK_WIDGET (entry);
5765 GtkStateFlags state = 0;
5766 GdkRGBA text_color, bar_text_color;
5767 GtkStyleContext *context;
5769 gint progress_x, progress_y, progress_width, progress_height;
5770 gint clip_width, clip_height;
5772 /* Nothing to display at all */
5773 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5776 state = gtk_widget_get_state_flags (widget);
5777 context = gtk_widget_get_style_context (widget);
5779 gtk_style_context_get_color (context, state, &text_color);
5781 /* Get foreground color for progressbars */
5782 gtk_style_context_save (context);
5783 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5784 gtk_style_context_get_color (context, state, &bar_text_color);
5785 gtk_style_context_restore (context);
5787 get_progress_area (widget,
5788 &progress_x, &progress_y,
5789 &progress_width, &progress_height);
5793 clip_width = gdk_window_get_width (priv->text_area);
5794 clip_height = gdk_window_get_height (priv->text_area);
5795 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5798 /* If the color is the same, or the progress area has a zero
5799 * size, then we only need to draw once. */
5800 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5801 ((progress_width == 0) || (progress_height == 0)))
5803 draw_text_with_color (entry, cr, &text_color);
5807 int frame_x, frame_y, area_x, area_y;
5809 width = gdk_window_get_width (priv->text_area);
5810 height = gdk_window_get_height (priv->text_area);
5814 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5815 cairo_rectangle (cr, 0, 0, width, height);
5817 /* progres area is frame-relative, we need it text-area window
5819 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5820 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5821 progress_x += frame_x - area_x;
5822 progress_y += frame_y - area_y;
5824 cairo_rectangle (cr, progress_x, progress_y,
5825 progress_width, progress_height);
5827 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5829 draw_text_with_color (entry, cr, &text_color);
5834 cairo_rectangle (cr, progress_x, progress_y,
5835 progress_width, progress_height);
5838 draw_text_with_color (entry, cr, &bar_text_color);
5847 gtk_entry_draw_cursor (GtkEntry *entry,
5851 GtkEntryPrivate *priv = entry->priv;
5852 GtkWidget *widget = GTK_WIDGET (entry);
5853 GtkStyleContext *context;
5854 PangoRectangle cursor_rect;
5857 gboolean block_at_line_end;
5858 PangoLayout *layout;
5861 context = gtk_widget_get_style_context (widget);
5863 layout = gtk_entry_ensure_layout (entry, TRUE);
5864 text = pango_layout_get_text (layout);
5865 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5867 if (!priv->overwrite_mode)
5870 block = _gtk_text_util_get_block_cursor_location (layout,
5871 cursor_index, &cursor_rect, &block_at_line_end);
5875 gtk_render_insertion_cursor (context, cr,
5876 - priv->scroll_offset, 0,
5877 layout, cursor_index, priv->resolved_dir);
5879 else /* overwrite_mode */
5881 GdkRGBA cursor_color;
5887 get_layout_position (entry, &x, &y);
5889 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5890 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5891 rect.width = PANGO_PIXELS (cursor_rect.width);
5892 rect.height = PANGO_PIXELS (cursor_rect.height);
5894 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5895 gdk_cairo_set_source_rgba (cr, &cursor_color);
5896 gdk_cairo_rectangle (cr, &rect);
5899 if (!block_at_line_end)
5901 GtkStateFlags state;
5904 state = gtk_widget_get_state_flags (widget);
5905 gtk_style_context_get_background_color (context, state, &color);
5907 gdk_cairo_rectangle (cr, &rect);
5909 cairo_move_to (cr, x, y);
5910 gdk_cairo_set_source_rgba (cr, &color);
5911 pango_cairo_show_layout (cr, layout);
5919 _gtk_entry_reset_im_context (GtkEntry *entry)
5921 GtkEntryPrivate *priv = entry->priv;
5923 if (priv->need_im_reset)
5925 priv->need_im_reset = FALSE;
5926 gtk_im_context_reset (priv->im_context);
5931 * gtk_entry_reset_im_context:
5932 * @entry: a #GtkEntry
5934 * Reset the input method context of the entry if needed.
5936 * This can be necessary in the case where modifying the buffer
5937 * would confuse on-going input method behavior.
5942 gtk_entry_reset_im_context (GtkEntry *entry)
5944 g_return_if_fail (GTK_IS_ENTRY (entry));
5946 _gtk_entry_reset_im_context (entry);
5950 * gtk_entry_im_context_filter_keypress:
5951 * @entry: a #GtkEntry
5952 * @event: (type Gdk.EventKey): the key event
5954 * Allow the #GtkEntry input method to internally handle key press
5955 * and release events. If this function returns %TRUE, then no further
5956 * processing should be done for this key event. See
5957 * gtk_im_context_filter_keypress().
5959 * Note that you are expected to call this function from your handler
5960 * when overriding key event handling. This is needed in the case when
5961 * you need to insert your own key handling between the input method
5962 * and the default key event handling of the #GtkEntry.
5963 * See gtk_text_view_reset_im_context() for an example of use.
5965 * Return value: %TRUE if the input method handled the key event.
5970 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5973 GtkEntryPrivate *priv;
5975 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5979 return gtk_im_context_filter_keypress (priv->im_context, event);
5983 _gtk_entry_get_im_context (GtkEntry *entry)
5985 return entry->priv->im_context;
5989 gtk_entry_find_position (GtkEntry *entry,
5992 GtkEntryPrivate *priv = entry->priv;
5993 PangoLayout *layout;
5994 PangoLayoutLine *line;
6001 layout = gtk_entry_ensure_layout (entry, TRUE);
6002 text = pango_layout_get_text (layout);
6003 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6005 line = pango_layout_get_lines_readonly (layout)->data;
6006 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6008 if (index >= cursor_index && priv->preedit_length)
6010 if (index >= cursor_index + priv->preedit_length)
6011 index -= priv->preedit_length;
6014 index = cursor_index;
6019 pos = g_utf8_pointer_to_offset (text, text + index);
6026 gtk_entry_get_cursor_locations (GtkEntry *entry,
6031 GtkEntryPrivate *priv = entry->priv;
6032 DisplayMode mode = gtk_entry_get_display_mode (entry);
6034 /* Nothing to display at all, so no cursor is relevant */
6035 if (mode == DISPLAY_BLANK)
6045 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6046 const gchar *text = pango_layout_get_text (layout);
6047 PangoRectangle strong_pos, weak_pos;
6050 if (type == CURSOR_STANDARD)
6052 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6054 else /* type == CURSOR_DND */
6056 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6058 if (priv->dnd_position > priv->current_pos)
6060 if (mode == DISPLAY_NORMAL)
6061 index += priv->preedit_length;
6064 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6065 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6070 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6073 *strong_x = strong_pos.x / PANGO_SCALE;
6076 *weak_x = weak_pos.x / PANGO_SCALE;
6081 gtk_entry_adjust_scroll (GtkEntry *entry)
6083 GtkEntryPrivate *priv = entry->priv;
6084 gint min_offset, max_offset;
6085 gint text_area_width, text_width;
6087 gint strong_x, weak_x;
6088 gint strong_xoffset, weak_xoffset;
6090 PangoLayout *layout;
6091 PangoLayoutLine *line;
6092 PangoRectangle logical_rect;
6094 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6097 text_area_width = gdk_window_get_width (priv->text_area);
6099 if (text_area_width < 0)
6100 text_area_width = 0;
6102 layout = gtk_entry_ensure_layout (entry, TRUE);
6103 line = pango_layout_get_lines_readonly (layout)->data;
6105 pango_layout_line_get_extents (line, NULL, &logical_rect);
6107 /* Display as much text as we can */
6109 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6110 xalign = priv->xalign;
6112 xalign = 1.0 - priv->xalign;
6114 text_width = PANGO_PIXELS(logical_rect.width);
6116 if (text_width > text_area_width)
6119 max_offset = text_width - text_area_width;
6123 min_offset = (text_width - text_area_width) * xalign;
6124 max_offset = min_offset;
6127 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6129 /* And make sure cursors are on screen. Note that the cursor is
6130 * actually drawn one pixel into the INNER_BORDER space on
6131 * the right, when the scroll is at the utmost right. This
6132 * looks better to to me than confining the cursor inside the
6133 * border entirely, though it means that the cursor gets one
6134 * pixel closer to the edge of the widget on the right than
6135 * on the left. This might need changing if one changed
6136 * INNER_BORDER from 2 to 1, as one would do on a
6137 * small-screen-real-estate display.
6139 * We always make sure that the strong cursor is on screen, and
6140 * put the weak cursor on screen if possible.
6143 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6145 strong_xoffset = strong_x - priv->scroll_offset;
6147 if (strong_xoffset < 0)
6149 priv->scroll_offset += strong_xoffset;
6152 else if (strong_xoffset > text_area_width)
6154 priv->scroll_offset += strong_xoffset - text_area_width;
6155 strong_xoffset = text_area_width;
6158 weak_xoffset = weak_x - priv->scroll_offset;
6160 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6162 priv->scroll_offset += weak_xoffset;
6164 else if (weak_xoffset > text_area_width &&
6165 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6167 priv->scroll_offset += weak_xoffset - text_area_width;
6170 g_object_notify (G_OBJECT (entry), "scroll-offset");
6174 gtk_entry_move_adjustments (GtkEntry *entry)
6176 GtkWidget *widget = GTK_WIDGET (entry);
6177 GtkAllocation allocation;
6178 GtkAdjustment *adjustment;
6179 PangoContext *context;
6180 PangoFontMetrics *metrics;
6181 GtkStyleContext *style_context;
6182 GtkStateFlags state;
6187 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6191 gtk_widget_get_allocation (widget, &allocation);
6193 /* Cursor position, layout offset, border width, and widget allocation */
6194 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6195 get_layout_position (entry, &layout_x, NULL);
6196 _gtk_entry_get_borders (entry, &borders);
6197 x += allocation.x + layout_x + borders.left;
6199 /* Approximate width of a char, so user can see what is ahead/behind */
6200 context = gtk_widget_get_pango_context (widget);
6201 style_context = gtk_widget_get_style_context (widget);
6202 state = gtk_widget_get_state_flags (widget);
6204 metrics = pango_context_get_metrics (context,
6205 gtk_style_context_get_font (style_context, state),
6206 pango_context_get_language (context));
6207 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6210 gtk_adjustment_clamp_page (adjustment,
6211 x - (char_width + 1), /* one char + one pixel before */
6212 x + (char_width + 2)); /* one char + cursor + one pixel after */
6216 gtk_entry_move_visually (GtkEntry *entry,
6220 GtkEntryPrivate *priv = entry->priv;
6222 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6225 text = pango_layout_get_text (layout);
6227 index = g_utf8_offset_to_pointer (text, start) - text;
6231 int new_index, new_trailing;
6232 gboolean split_cursor;
6235 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6236 "gtk-split-cursor", &split_cursor,
6243 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6244 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6246 strong = keymap_direction == priv->resolved_dir;
6251 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6256 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6262 else if (new_index != G_MAXINT)
6265 while (new_trailing--)
6266 index = g_utf8_next_char (text + index) - text;
6269 return g_utf8_pointer_to_offset (text, text + index);
6273 gtk_entry_move_logically (GtkEntry *entry,
6277 gint new_pos = start;
6280 length = gtk_entry_buffer_get_length (get_buffer (entry));
6282 /* Prevent any leak of information */
6283 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6285 new_pos = CLAMP (start + count, 0, length);
6289 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6290 PangoLogAttr *log_attrs;
6293 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6295 while (count > 0 && new_pos < length)
6299 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6303 while (count < 0 && new_pos > 0)
6307 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6319 gtk_entry_move_forward_word (GtkEntry *entry,
6321 gboolean allow_whitespace)
6323 gint new_pos = start;
6326 length = gtk_entry_buffer_get_length (get_buffer (entry));
6328 /* Prevent any leak of information */
6329 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6333 else if (new_pos < length)
6335 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6336 PangoLogAttr *log_attrs;
6339 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6341 /* Find the next word boundary */
6343 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6344 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6355 gtk_entry_move_backward_word (GtkEntry *entry,
6357 gboolean allow_whitespace)
6359 gint new_pos = start;
6361 /* Prevent any leak of information */
6362 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6368 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6369 PangoLogAttr *log_attrs;
6372 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6374 new_pos = start - 1;
6376 /* Find the previous word boundary */
6377 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6378 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6388 gtk_entry_delete_whitespace (GtkEntry *entry)
6390 GtkEntryPrivate *priv = entry->priv;
6391 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6392 PangoLogAttr *log_attrs;
6396 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6398 start = end = priv->current_pos;
6400 while (start > 0 && log_attrs[start-1].is_white)
6403 while (end < n_attrs && log_attrs[end].is_white)
6409 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6414 gtk_entry_select_word (GtkEntry *entry)
6416 GtkEntryPrivate *priv = entry->priv;
6417 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6418 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6420 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6424 gtk_entry_select_line (GtkEntry *entry)
6426 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6430 truncate_multiline (const gchar *text)
6435 text[length] && text[length] != '\n' && text[length] != '\r';
6442 paste_received (GtkClipboard *clipboard,
6446 GtkEntry *entry = GTK_ENTRY (data);
6447 GtkEditable *editable = GTK_EDITABLE (entry);
6448 GtkEntryPrivate *priv = entry->priv;
6450 if (priv->button == GDK_BUTTON_MIDDLE)
6452 gint pos, start, end;
6453 pos = priv->insert_pos;
6454 gtk_editable_get_selection_bounds (editable, &start, &end);
6455 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6456 gtk_editable_select_region (editable, pos, pos);
6461 gint pos, start, end;
6463 gboolean popup_completion;
6464 GtkEntryCompletion *completion;
6466 completion = gtk_entry_get_completion (entry);
6468 if (priv->truncate_multiline)
6469 length = truncate_multiline (text);
6471 /* only complete if the selection is at the end */
6472 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6473 MAX (priv->current_pos, priv->selection_bound));
6477 if (gtk_widget_get_mapped (completion->priv->popup_window))
6478 _gtk_entry_completion_popdown (completion);
6480 if (!popup_completion && completion->priv->changed_id > 0)
6481 g_signal_handler_block (entry, completion->priv->changed_id);
6484 begin_change (entry);
6485 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6486 gtk_editable_delete_text (editable, start, end);
6488 pos = priv->current_pos;
6489 gtk_editable_insert_text (editable, text, length, &pos);
6490 gtk_editable_set_position (editable, pos);
6494 !popup_completion && completion->priv->changed_id > 0)
6495 g_signal_handler_unblock (entry, completion->priv->changed_id);
6498 g_object_unref (entry);
6502 gtk_entry_paste (GtkEntry *entry,
6505 g_object_ref (entry);
6506 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6507 paste_received, entry);
6511 primary_get_cb (GtkClipboard *clipboard,
6512 GtkSelectionData *selection_data,
6516 GtkEntry *entry = GTK_ENTRY (data);
6519 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6521 gchar *str = gtk_entry_get_display_text (entry, start, end);
6522 gtk_selection_data_set_text (selection_data, str, -1);
6528 primary_clear_cb (GtkClipboard *clipboard,
6531 GtkEntry *entry = GTK_ENTRY (data);
6532 GtkEntryPrivate *priv = entry->priv;
6534 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6538 gtk_entry_update_primary_selection (GtkEntry *entry)
6540 GtkTargetList *list;
6541 GtkTargetEntry *targets;
6542 GtkClipboard *clipboard;
6546 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6549 list = gtk_target_list_new (NULL, 0);
6550 gtk_target_list_add_text_targets (list, 0);
6552 targets = gtk_target_table_new_from_list (list, &n_targets);
6554 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6556 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6558 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6559 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6560 primary_clear_cb (clipboard, entry);
6564 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6565 gtk_clipboard_clear (clipboard);
6568 gtk_target_table_free (targets, n_targets);
6569 gtk_target_list_unref (list);
6573 gtk_entry_clear (GtkEntry *entry,
6574 GtkEntryIconPosition icon_pos)
6576 GtkEntryPrivate *priv = entry->priv;
6577 EntryIconInfo *icon_info = priv->icons[icon_pos];
6578 GtkImageType storage_type;
6580 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6583 g_object_freeze_notify (G_OBJECT (entry));
6585 /* Explicitly check, as the pointer may become invalidated
6586 * during destruction.
6588 if (GDK_IS_WINDOW (icon_info->window))
6589 gdk_window_hide (icon_info->window);
6591 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6593 switch (storage_type)
6595 case GTK_IMAGE_PIXBUF:
6596 g_object_notify (G_OBJECT (entry),
6597 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6600 case GTK_IMAGE_STOCK:
6601 g_object_notify (G_OBJECT (entry),
6602 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6605 case GTK_IMAGE_ICON_NAME:
6606 g_object_notify (G_OBJECT (entry),
6607 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6610 case GTK_IMAGE_GICON:
6611 g_object_notify (G_OBJECT (entry),
6612 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6616 g_assert_not_reached ();
6620 _gtk_icon_helper_clear (icon_info->icon_helper);
6622 g_object_notify (G_OBJECT (entry),
6623 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6625 g_object_thaw_notify (G_OBJECT (entry));
6629 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6630 GtkEntryIconPosition icon_pos)
6632 GtkEntryPrivate *priv = entry->priv;
6633 EntryIconInfo *icon_info = priv->icons[icon_pos];
6634 GtkStyleContext *context;
6637 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6638 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6640 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6643 gtk_style_context_restore (context);
6654 * Creates a new entry.
6656 * Return value: a new #GtkEntry.
6659 gtk_entry_new (void)
6661 return g_object_new (GTK_TYPE_ENTRY, NULL);
6665 * gtk_entry_new_with_buffer:
6666 * @buffer: The buffer to use for the new #GtkEntry.
6668 * Creates a new entry with the specified text buffer.
6670 * Return value: a new #GtkEntry
6675 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6677 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6678 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6681 static GtkEntryBuffer*
6682 get_buffer (GtkEntry *entry)
6684 GtkEntryPrivate *priv = entry->priv;
6686 if (priv->buffer == NULL)
6688 GtkEntryBuffer *buffer;
6689 buffer = gtk_entry_buffer_new (NULL, 0);
6690 gtk_entry_set_buffer (entry, buffer);
6691 g_object_unref (buffer);
6694 return priv->buffer;
6698 * gtk_entry_get_buffer:
6699 * @entry: a #GtkEntry
6701 * Get the #GtkEntryBuffer object which holds the text for
6706 * Returns: (transfer none): A #GtkEntryBuffer object.
6709 gtk_entry_get_buffer (GtkEntry *entry)
6711 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6713 return get_buffer (entry);
6717 * gtk_entry_set_buffer:
6718 * @entry: a #GtkEntry
6719 * @buffer: a #GtkEntryBuffer
6721 * Set the #GtkEntryBuffer object which holds the text for
6727 gtk_entry_set_buffer (GtkEntry *entry,
6728 GtkEntryBuffer *buffer)
6730 GtkEntryPrivate *priv;
6733 g_return_if_fail (GTK_IS_ENTRY (entry));
6739 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6740 g_object_ref (buffer);
6745 buffer_disconnect_signals (entry);
6746 g_object_unref (priv->buffer);
6749 priv->buffer = buffer;
6752 buffer_connect_signals (entry);
6754 obj = G_OBJECT (entry);
6755 g_object_freeze_notify (obj);
6756 g_object_notify (obj, "buffer");
6757 g_object_notify (obj, "text");
6758 g_object_notify (obj, "text-length");
6759 g_object_notify (obj, "max-length");
6760 g_object_notify (obj, "visibility");
6761 g_object_notify (obj, "invisible-char");
6762 g_object_notify (obj, "invisible-char-set");
6763 g_object_thaw_notify (obj);
6765 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6766 gtk_entry_recompute (entry);
6770 * gtk_entry_get_text_area:
6771 * @entry: a #GtkEntry
6772 * @text_area: (out): Return location for the text area.
6774 * Gets the area where the entry's text is drawn. This function is
6775 * useful when drawing something to the entry in a draw callback.
6777 * If the entry is not realized, @text_area is filled with zeros.
6779 * See also gtk_entry_get_icon_area().
6784 gtk_entry_get_text_area (GtkEntry *entry,
6785 GdkRectangle *text_area)
6787 GtkEntryPrivate *priv;
6789 g_return_if_fail (GTK_IS_ENTRY (entry));
6790 g_return_if_fail (text_area != NULL);
6794 if (priv->text_area)
6796 GtkAllocation allocation;
6799 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6800 gdk_window_get_position (priv->text_area, &x, &y);
6802 text_area->x = x - allocation.x;
6803 text_area->y = y - allocation.y;
6804 text_area->width = gdk_window_get_width (priv->text_area);
6805 text_area->height = gdk_window_get_height (priv->text_area);
6811 text_area->width = 0;
6812 text_area->height = 0;
6817 * gtk_entry_set_text:
6818 * @entry: a #GtkEntry
6819 * @text: the new text
6821 * Sets the text in the widget to the given
6822 * value, replacing the current contents.
6824 * See gtk_entry_buffer_set_text().
6827 gtk_entry_set_text (GtkEntry *entry,
6831 GtkEntryCompletion *completion;
6833 g_return_if_fail (GTK_IS_ENTRY (entry));
6834 g_return_if_fail (text != NULL);
6836 /* Actually setting the text will affect the cursor and selection;
6837 * if the contents don't actually change, this will look odd to the user.
6839 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6842 completion = gtk_entry_get_completion (entry);
6843 if (completion && completion->priv->changed_id > 0)
6844 g_signal_handler_block (entry, completion->priv->changed_id);
6846 begin_change (entry);
6847 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6849 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6852 if (completion && completion->priv->changed_id > 0)
6853 g_signal_handler_unblock (entry, completion->priv->changed_id);
6857 * gtk_entry_set_visibility:
6858 * @entry: a #GtkEntry
6859 * @visible: %TRUE if the contents of the entry are displayed
6862 * Sets whether the contents of the entry are visible or not.
6863 * When visibility is set to %FALSE, characters are displayed
6864 * as the invisible char, and will also appear that way when
6865 * the text in the entry widget is copied elsewhere.
6867 * By default, GTK+ picks the best invisible character available
6868 * in the current font, but it can be changed with
6869 * gtk_entry_set_invisible_char().
6872 gtk_entry_set_visibility (GtkEntry *entry,
6875 GtkEntryPrivate *priv;
6877 g_return_if_fail (GTK_IS_ENTRY (entry));
6881 visible = visible != FALSE;
6883 if (priv->visible != visible)
6885 priv->visible = visible;
6887 g_object_notify (G_OBJECT (entry), "visibility");
6888 gtk_entry_recompute (entry);
6893 * gtk_entry_get_visibility:
6894 * @entry: a #GtkEntry
6896 * Retrieves whether the text in @entry is visible. See
6897 * gtk_entry_set_visibility().
6899 * Return value: %TRUE if the text is currently visible
6902 gtk_entry_get_visibility (GtkEntry *entry)
6904 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6906 return entry->priv->visible;
6910 * gtk_entry_set_invisible_char:
6911 * @entry: a #GtkEntry
6912 * @ch: a Unicode character
6914 * Sets the character to use in place of the actual text when
6915 * gtk_entry_set_visibility() has been called to set text visibility
6916 * to %FALSE. i.e. this is the character used in "password mode" to
6917 * show the user how many characters have been typed. By default, GTK+
6918 * picks the best invisible char available in the current font. If you
6919 * set the invisible char to 0, then the user will get no feedback
6920 * at all; there will be no text on the screen as they type.
6923 gtk_entry_set_invisible_char (GtkEntry *entry,
6926 GtkEntryPrivate *priv;
6928 g_return_if_fail (GTK_IS_ENTRY (entry));
6932 if (!priv->invisible_char_set)
6934 priv->invisible_char_set = TRUE;
6935 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6938 if (ch == priv->invisible_char)
6941 priv->invisible_char = ch;
6942 g_object_notify (G_OBJECT (entry), "invisible-char");
6943 gtk_entry_recompute (entry);
6947 * gtk_entry_get_invisible_char:
6948 * @entry: a #GtkEntry
6950 * Retrieves the character displayed in place of the real characters
6951 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6953 * Return value: the current invisible char, or 0, if the entry does not
6954 * show invisible text at all.
6957 gtk_entry_get_invisible_char (GtkEntry *entry)
6959 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6961 return entry->priv->invisible_char;
6965 * gtk_entry_unset_invisible_char:
6966 * @entry: a #GtkEntry
6968 * Unsets the invisible char previously set with
6969 * gtk_entry_set_invisible_char(). So that the
6970 * default invisible char is used again.
6975 gtk_entry_unset_invisible_char (GtkEntry *entry)
6977 GtkEntryPrivate *priv;
6980 g_return_if_fail (GTK_IS_ENTRY (entry));
6984 if (!priv->invisible_char_set)
6987 priv->invisible_char_set = FALSE;
6988 ch = find_invisible_char (GTK_WIDGET (entry));
6990 if (priv->invisible_char != ch)
6992 priv->invisible_char = ch;
6993 g_object_notify (G_OBJECT (entry), "invisible-char");
6996 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6997 gtk_entry_recompute (entry);
7001 * gtk_entry_set_overwrite_mode:
7002 * @entry: a #GtkEntry
7003 * @overwrite: new value
7005 * Sets whether the text is overwritten when typing in the #GtkEntry.
7010 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7013 GtkEntryPrivate *priv = entry->priv;
7015 g_return_if_fail (GTK_IS_ENTRY (entry));
7017 if (priv->overwrite_mode == overwrite)
7020 gtk_entry_toggle_overwrite (entry);
7022 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7026 * gtk_entry_get_overwrite_mode:
7027 * @entry: a #GtkEntry
7029 * Gets the value set by gtk_entry_set_overwrite_mode().
7031 * Return value: whether the text is overwritten when typing.
7036 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7038 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7040 return entry->priv->overwrite_mode;
7044 * gtk_entry_get_text:
7045 * @entry: a #GtkEntry
7047 * Retrieves the contents of the entry widget.
7048 * See also gtk_editable_get_chars().
7050 * This is equivalent to:
7052 * <informalexample><programlisting>
7053 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7054 * </programlisting></informalexample>
7056 * Return value: a pointer to the contents of the widget as a
7057 * string. This string points to internally allocated
7058 * storage in the widget and must not be freed, modified or
7062 gtk_entry_get_text (GtkEntry *entry)
7064 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7066 return gtk_entry_buffer_get_text (get_buffer (entry));
7070 * gtk_entry_set_max_length:
7071 * @entry: a #GtkEntry
7072 * @max: the maximum length of the entry, or 0 for no maximum.
7073 * (other than the maximum length of entries.) The value passed in will
7074 * be clamped to the range 0-65536.
7076 * Sets the maximum allowed length of the contents of the widget. If
7077 * the current contents are longer than the given length, then they
7078 * will be truncated to fit.
7080 * This is equivalent to:
7082 * <informalexample><programlisting>
7083 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7084 * </programlisting></informalexample>
7087 gtk_entry_set_max_length (GtkEntry *entry,
7090 g_return_if_fail (GTK_IS_ENTRY (entry));
7091 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7095 * gtk_entry_get_max_length:
7096 * @entry: a #GtkEntry
7098 * Retrieves the maximum allowed length of the text in
7099 * @entry. See gtk_entry_set_max_length().
7101 * This is equivalent to:
7103 * <informalexample><programlisting>
7104 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7105 * </programlisting></informalexample>
7107 * Return value: the maximum allowed number of characters
7108 * in #GtkEntry, or 0 if there is no maximum.
7111 gtk_entry_get_max_length (GtkEntry *entry)
7113 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7115 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7119 * gtk_entry_get_text_length:
7120 * @entry: a #GtkEntry
7122 * Retrieves the current length of the text in
7125 * This is equivalent to:
7127 * <informalexample><programlisting>
7128 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7129 * </programlisting></informalexample>
7131 * Return value: the current number of characters
7132 * in #GtkEntry, or 0 if there are none.
7137 gtk_entry_get_text_length (GtkEntry *entry)
7139 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7141 return gtk_entry_buffer_get_length (get_buffer (entry));
7145 * gtk_entry_set_activates_default:
7146 * @entry: a #GtkEntry
7147 * @setting: %TRUE to activate window's default widget on Enter keypress
7149 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7150 * widget for the window containing the entry. This usually means that
7151 * the dialog box containing the entry will be closed, since the default
7152 * widget is usually one of the dialog buttons.
7154 * (For experts: if @setting is %TRUE, the entry calls
7155 * gtk_window_activate_default() on the window containing the entry, in
7156 * the default handler for the #GtkWidget::activate signal.)
7159 gtk_entry_set_activates_default (GtkEntry *entry,
7162 GtkEntryPrivate *priv;
7164 g_return_if_fail (GTK_IS_ENTRY (entry));
7168 setting = setting != FALSE;
7170 if (setting != priv->activates_default)
7172 priv->activates_default = setting;
7173 g_object_notify (G_OBJECT (entry), "activates-default");
7178 * gtk_entry_get_activates_default:
7179 * @entry: a #GtkEntry
7181 * Retrieves the value set by gtk_entry_set_activates_default().
7183 * Return value: %TRUE if the entry will activate the default widget
7186 gtk_entry_get_activates_default (GtkEntry *entry)
7188 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7190 return entry->priv->activates_default;
7194 * gtk_entry_set_width_chars:
7195 * @entry: a #GtkEntry
7196 * @n_chars: width in chars
7198 * Changes the size request of the entry to be about the right size
7199 * for @n_chars characters. Note that it changes the size
7200 * <emphasis>request</emphasis>, the size can still be affected by
7201 * how you pack the widget into containers. If @n_chars is -1, the
7202 * size reverts to the default entry size.
7205 gtk_entry_set_width_chars (GtkEntry *entry,
7208 GtkEntryPrivate *priv;
7210 g_return_if_fail (GTK_IS_ENTRY (entry));
7214 if (priv->width_chars != n_chars)
7216 priv->width_chars = n_chars;
7217 g_object_notify (G_OBJECT (entry), "width-chars");
7218 gtk_widget_queue_resize (GTK_WIDGET (entry));
7223 * gtk_entry_get_width_chars:
7224 * @entry: a #GtkEntry
7226 * Gets the value set by gtk_entry_set_width_chars().
7228 * Return value: number of chars to request space for, or negative if unset
7231 gtk_entry_get_width_chars (GtkEntry *entry)
7233 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7235 return entry->priv->width_chars;
7239 * gtk_entry_set_has_frame:
7240 * @entry: a #GtkEntry
7241 * @setting: new value
7243 * Sets whether the entry has a beveled frame around it.
7246 gtk_entry_set_has_frame (GtkEntry *entry,
7249 GtkEntryPrivate *priv;
7251 g_return_if_fail (GTK_IS_ENTRY (entry));
7255 setting = (setting != FALSE);
7257 if (priv->has_frame == setting)
7260 gtk_widget_queue_resize (GTK_WIDGET (entry));
7261 priv->has_frame = setting;
7262 g_object_notify (G_OBJECT (entry), "has-frame");
7266 * gtk_entry_get_has_frame:
7267 * @entry: a #GtkEntry
7269 * Gets the value set by gtk_entry_set_has_frame().
7271 * Return value: whether the entry has a beveled frame
7274 gtk_entry_get_has_frame (GtkEntry *entry)
7276 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7278 return entry->priv->has_frame;
7282 * gtk_entry_set_inner_border:
7283 * @entry: a #GtkEntry
7284 * @border: (allow-none): a #GtkBorder, or %NULL
7286 * Sets %entry's inner-border property to %border, or clears it if %NULL
7287 * is passed. The inner-border is the area around the entry's text, but
7290 * If set, this property overrides the inner-border style property.
7291 * Overriding the style-provided border is useful when you want to do
7292 * in-place editing of some text in a canvas or list widget, where
7293 * pixel-exact positioning of the entry is important.
7297 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7298 * the value set with this function is ignored by #GtkEntry.
7301 gtk_entry_set_inner_border (GtkEntry *entry,
7302 const GtkBorder *border)
7304 g_return_if_fail (GTK_IS_ENTRY (entry));
7306 gtk_entry_do_set_inner_border (entry, border);
7310 * gtk_entry_get_inner_border:
7311 * @entry: a #GtkEntry
7313 * This function returns the entry's #GtkEntry:inner-border property. See
7314 * gtk_entry_set_inner_border() for more information.
7316 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7320 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7321 * the value returned by this function is ignored by #GtkEntry.
7324 gtk_entry_get_inner_border (GtkEntry *entry)
7326 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7328 return gtk_entry_do_get_inner_border (entry);
7332 * gtk_entry_get_layout:
7333 * @entry: a #GtkEntry
7335 * Gets the #PangoLayout used to display the entry.
7336 * The layout is useful to e.g. convert text positions to
7337 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7338 * The returned layout is owned by the entry and must not be
7339 * modified or freed by the caller.
7341 * Keep in mind that the layout text may contain a preedit string, so
7342 * gtk_entry_layout_index_to_text_index() and
7343 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7344 * indices in the layout to byte indices in the entry contents.
7346 * Return value: (transfer none): the #PangoLayout for this entry
7349 gtk_entry_get_layout (GtkEntry *entry)
7351 PangoLayout *layout;
7353 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7355 layout = gtk_entry_ensure_layout (entry, TRUE);
7362 * gtk_entry_layout_index_to_text_index:
7363 * @entry: a #GtkEntry
7364 * @layout_index: byte index into the entry layout text
7366 * Converts from a position in the entry contents (returned
7367 * by gtk_entry_get_text()) to a position in the
7368 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7369 * with text retrieved via pango_layout_get_text()).
7371 * Return value: byte index into the entry contents
7374 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7377 GtkEntryPrivate *priv;
7378 PangoLayout *layout;
7382 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7386 layout = gtk_entry_ensure_layout (entry, TRUE);
7387 text = pango_layout_get_text (layout);
7388 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7390 if (layout_index >= cursor_index && priv->preedit_length)
7392 if (layout_index >= cursor_index + priv->preedit_length)
7393 layout_index -= priv->preedit_length;
7395 layout_index = cursor_index;
7398 return layout_index;
7402 * gtk_entry_text_index_to_layout_index:
7403 * @entry: a #GtkEntry
7404 * @text_index: byte index into the entry contents
7406 * Converts from a position in the entry's #PangoLayout (returned by
7407 * gtk_entry_get_layout()) to a position in the entry contents
7408 * (returned by gtk_entry_get_text()).
7410 * Return value: byte index into the entry layout text
7413 gtk_entry_text_index_to_layout_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 (text_index > cursor_index)
7430 text_index += priv->preedit_length;
7436 * gtk_entry_get_layout_offsets:
7437 * @entry: a #GtkEntry
7438 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7439 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7442 * Obtains the position of the #PangoLayout used to render text
7443 * in the entry, in widget coordinates. Useful if you want to line
7444 * up the text in an entry with some other text, e.g. when using the
7445 * entry to implement editable cells in a sheet widget.
7447 * Also useful to convert mouse events into coordinates inside the
7448 * #PangoLayout, e.g. to take some action if some part of the entry text
7451 * Note that as the user scrolls around in the entry the offsets will
7452 * change; you'll need to connect to the "notify::scroll-offset"
7453 * signal to track this. Remember when using the #PangoLayout
7454 * functions you need to convert to and from pixels using
7455 * PANGO_PIXELS() or #PANGO_SCALE.
7457 * Keep in mind that the layout text may contain a preedit string, so
7458 * gtk_entry_layout_index_to_text_index() and
7459 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7460 * indices in the layout to byte indices in the entry contents.
7463 gtk_entry_get_layout_offsets (GtkEntry *entry,
7467 gint text_area_x, text_area_y;
7469 g_return_if_fail (GTK_IS_ENTRY (entry));
7471 /* this gets coords relative to text area */
7472 get_layout_position (entry, x, y);
7474 /* convert to widget coords */
7475 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7486 * gtk_entry_set_alignment:
7487 * @entry: a #GtkEntry
7488 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7489 * Reversed for RTL layouts
7491 * Sets the alignment for the contents of the entry. This controls
7492 * the horizontal positioning of the contents when the displayed
7493 * text is shorter than the width of the entry.
7498 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7500 GtkEntryPrivate *priv;
7502 g_return_if_fail (GTK_IS_ENTRY (entry));
7508 else if (xalign > 1.0)
7511 if (xalign != priv->xalign)
7513 priv->xalign = xalign;
7515 gtk_entry_recompute (entry);
7517 g_object_notify (G_OBJECT (entry), "xalign");
7522 * gtk_entry_get_alignment:
7523 * @entry: a #GtkEntry
7525 * Gets the value set by gtk_entry_set_alignment().
7527 * Return value: the alignment
7532 gtk_entry_get_alignment (GtkEntry *entry)
7534 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7536 return entry->priv->xalign;
7540 * gtk_entry_set_icon_from_pixbuf:
7541 * @entry: a #GtkEntry
7542 * @icon_pos: Icon position
7543 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7545 * Sets the icon shown in the specified position using a pixbuf.
7547 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7552 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7553 GtkEntryIconPosition icon_pos,
7556 GtkEntryPrivate *priv;
7557 EntryIconInfo *icon_info;
7559 g_return_if_fail (GTK_IS_ENTRY (entry));
7560 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7564 if ((icon_info = priv->icons[icon_pos]) == NULL)
7565 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7567 g_object_freeze_notify (G_OBJECT (entry));
7570 g_object_ref (pixbuf);
7572 gtk_entry_clear (entry, icon_pos);
7576 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7578 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7580 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7581 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7585 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7586 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7589 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7590 gdk_window_show_unraised (icon_info->window);
7592 g_object_unref (pixbuf);
7595 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7596 gtk_widget_queue_resize (GTK_WIDGET (entry));
7598 g_object_thaw_notify (G_OBJECT (entry));
7602 * gtk_entry_set_icon_from_stock:
7603 * @entry: A #GtkEntry
7604 * @icon_pos: Icon position
7605 * @stock_id: (allow-none): The name of the stock item, or %NULL
7607 * Sets the icon shown in the entry at the specified position from
7610 * If @stock_id is %NULL, no icon will be shown in the specified position.
7615 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7616 GtkEntryIconPosition icon_pos,
7617 const gchar *stock_id)
7619 GtkEntryPrivate *priv;
7620 EntryIconInfo *icon_info;
7623 g_return_if_fail (GTK_IS_ENTRY (entry));
7624 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7628 if ((icon_info = priv->icons[icon_pos]) == NULL)
7629 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7631 g_object_freeze_notify (G_OBJECT (entry));
7633 /* need to dup before clearing */
7634 new_id = g_strdup (stock_id);
7636 gtk_entry_clear (entry, icon_pos);
7640 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7642 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7644 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7645 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7649 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7650 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7653 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7654 gdk_window_show_unraised (icon_info->window);
7659 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7660 gtk_widget_queue_resize (GTK_WIDGET (entry));
7662 g_object_thaw_notify (G_OBJECT (entry));
7666 * gtk_entry_set_icon_from_icon_name:
7667 * @entry: A #GtkEntry
7668 * @icon_pos: The position at which to set the icon
7669 * @icon_name: (allow-none): An icon name, or %NULL
7671 * Sets the icon shown in the entry at the specified position
7672 * from the current icon theme.
7674 * If the icon name isn't known, a "broken image" icon will be displayed
7677 * If @icon_name is %NULL, no icon will be shown in the specified position.
7682 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7683 GtkEntryIconPosition icon_pos,
7684 const gchar *icon_name)
7686 GtkEntryPrivate *priv;
7687 EntryIconInfo *icon_info;
7690 g_return_if_fail (GTK_IS_ENTRY (entry));
7691 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7695 if ((icon_info = priv->icons[icon_pos]) == NULL)
7696 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7698 g_object_freeze_notify (G_OBJECT (entry));
7700 /* need to dup before clearing */
7701 new_name = g_strdup (icon_name);
7703 gtk_entry_clear (entry, icon_pos);
7705 if (new_name != NULL)
7707 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7709 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7711 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7712 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7716 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7717 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7720 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7721 gdk_window_show_unraised (icon_info->window);
7726 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7727 gtk_widget_queue_resize (GTK_WIDGET (entry));
7729 g_object_thaw_notify (G_OBJECT (entry));
7733 * gtk_entry_set_icon_from_gicon:
7734 * @entry: A #GtkEntry
7735 * @icon_pos: The position at which to set the icon
7736 * @icon: (allow-none): The icon to set, or %NULL
7738 * Sets the icon shown in the entry at the specified position
7739 * from the current icon theme.
7740 * If the icon isn't known, a "broken image" icon will be displayed
7743 * If @icon is %NULL, no icon will be shown in the specified position.
7748 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7749 GtkEntryIconPosition icon_pos,
7752 GtkEntryPrivate *priv;
7753 EntryIconInfo *icon_info;
7755 g_return_if_fail (GTK_IS_ENTRY (entry));
7756 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7760 if ((icon_info = priv->icons[icon_pos]) == NULL)
7761 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7763 g_object_freeze_notify (G_OBJECT (entry));
7765 /* need to ref before clearing */
7767 g_object_ref (icon);
7769 gtk_entry_clear (entry, icon_pos);
7773 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7775 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7777 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7778 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7782 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7783 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7786 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7787 gdk_window_show_unraised (icon_info->window);
7789 g_object_unref (icon);
7792 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7793 gtk_widget_queue_resize (GTK_WIDGET (entry));
7795 g_object_thaw_notify (G_OBJECT (entry));
7799 * gtk_entry_set_icon_activatable:
7800 * @entry: A #GtkEntry
7801 * @icon_pos: Icon position
7802 * @activatable: %TRUE if the icon should be activatable
7804 * Sets whether the icon is activatable.
7809 gtk_entry_set_icon_activatable (GtkEntry *entry,
7810 GtkEntryIconPosition icon_pos,
7811 gboolean activatable)
7813 GtkEntryPrivate *priv;
7814 EntryIconInfo *icon_info;
7816 g_return_if_fail (GTK_IS_ENTRY (entry));
7817 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7821 if ((icon_info = priv->icons[icon_pos]) == NULL)
7822 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7824 activatable = activatable != FALSE;
7826 if (icon_info->nonactivatable != !activatable)
7828 icon_info->nonactivatable = !activatable;
7830 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7831 update_cursors (GTK_WIDGET (entry));
7833 g_object_notify (G_OBJECT (entry),
7834 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7839 * gtk_entry_get_icon_activatable:
7840 * @entry: a #GtkEntry
7841 * @icon_pos: Icon position
7843 * Returns whether the icon is activatable.
7845 * Returns: %TRUE if the icon is activatable.
7850 gtk_entry_get_icon_activatable (GtkEntry *entry,
7851 GtkEntryIconPosition icon_pos)
7853 GtkEntryPrivate *priv;
7854 EntryIconInfo *icon_info;
7856 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7857 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7860 icon_info = priv->icons[icon_pos];
7862 return (!icon_info || !icon_info->nonactivatable);
7866 * gtk_entry_get_icon_pixbuf:
7867 * @entry: A #GtkEntry
7868 * @icon_pos: Icon position
7870 * Retrieves the image used for the icon.
7872 * Unlike the other methods of setting and getting icon data, this
7873 * method will work regardless of whether the icon was set using a
7874 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7876 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7877 * set for this position.
7882 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7883 GtkEntryIconPosition icon_pos)
7885 GtkEntryPrivate *priv;
7886 EntryIconInfo *icon_info;
7889 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7890 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7894 icon_info = priv->icons[icon_pos];
7899 /* HACK: unfortunately this is transfer none, so we need to return
7900 * the icon helper's cache ref directly.
7902 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7903 g_object_unref (pixbuf);
7909 * gtk_entry_get_icon_gicon:
7910 * @entry: A #GtkEntry
7911 * @icon_pos: Icon position
7913 * Retrieves the #GIcon used for the icon, or %NULL if there is
7914 * no icon or if the icon was set by some other method (e.g., by
7915 * stock, pixbuf, or icon name).
7917 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7918 * or if the icon is not a #GIcon
7923 gtk_entry_get_icon_gicon (GtkEntry *entry,
7924 GtkEntryIconPosition icon_pos)
7926 GtkEntryPrivate *priv;
7927 EntryIconInfo *icon_info;
7929 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7930 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7933 icon_info = priv->icons[icon_pos];
7938 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7942 * gtk_entry_get_icon_stock:
7943 * @entry: A #GtkEntry
7944 * @icon_pos: Icon position
7946 * Retrieves the stock id used for the icon, or %NULL if there is
7947 * no icon or if the icon was set by some other method (e.g., by
7948 * pixbuf, icon name or gicon).
7950 * Returns: A stock id, or %NULL if no icon is set or if the icon
7951 * wasn't set from a stock id
7956 gtk_entry_get_icon_stock (GtkEntry *entry,
7957 GtkEntryIconPosition icon_pos)
7959 GtkEntryPrivate *priv;
7960 EntryIconInfo *icon_info;
7962 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7963 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7966 icon_info = priv->icons[icon_pos];
7971 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
7975 * gtk_entry_get_icon_name:
7976 * @entry: A #GtkEntry
7977 * @icon_pos: Icon position
7979 * Retrieves the icon name used for the icon, or %NULL if there is
7980 * no icon or if the icon was set by some other method (e.g., by
7981 * pixbuf, stock or gicon).
7983 * Returns: An icon name, or %NULL if no icon is set or if the icon
7984 * wasn't set from an icon name
7989 gtk_entry_get_icon_name (GtkEntry *entry,
7990 GtkEntryIconPosition icon_pos)
7992 GtkEntryPrivate *priv;
7993 EntryIconInfo *icon_info;
7995 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7996 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7999 icon_info = priv->icons[icon_pos];
8004 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8008 * gtk_entry_set_icon_sensitive:
8009 * @entry: A #GtkEntry
8010 * @icon_pos: Icon position
8011 * @sensitive: Specifies whether the icon should appear
8012 * sensitive or insensitive
8014 * Sets the sensitivity for the specified icon.
8019 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8020 GtkEntryIconPosition icon_pos,
8023 GtkEntryPrivate *priv;
8024 EntryIconInfo *icon_info;
8026 g_return_if_fail (GTK_IS_ENTRY (entry));
8027 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8031 if ((icon_info = priv->icons[icon_pos]) == NULL)
8032 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8034 if (icon_info->insensitive != !sensitive)
8036 icon_info->insensitive = !sensitive;
8038 icon_info->pressed = FALSE;
8039 icon_info->prelight = FALSE;
8041 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8042 update_cursors (GTK_WIDGET (entry));
8044 gtk_widget_queue_draw (GTK_WIDGET (entry));
8046 g_object_notify (G_OBJECT (entry),
8047 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8052 * gtk_entry_get_icon_sensitive:
8053 * @entry: a #GtkEntry
8054 * @icon_pos: Icon position
8056 * Returns whether the icon appears sensitive or insensitive.
8058 * Returns: %TRUE if the icon is sensitive.
8063 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8064 GtkEntryIconPosition icon_pos)
8066 GtkEntryPrivate *priv;
8067 EntryIconInfo *icon_info;
8069 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8070 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8074 icon_info = priv->icons[icon_pos];
8076 return (!icon_info || !icon_info->insensitive);
8081 * gtk_entry_get_icon_storage_type:
8082 * @entry: a #GtkEntry
8083 * @icon_pos: Icon position
8085 * Gets the type of representation being used by the icon
8086 * to store image data. If the icon has no image data,
8087 * the return value will be %GTK_IMAGE_EMPTY.
8089 * Return value: image representation being used
8094 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8095 GtkEntryIconPosition icon_pos)
8097 GtkEntryPrivate *priv;
8098 EntryIconInfo *icon_info;
8100 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8101 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8105 icon_info = priv->icons[icon_pos];
8108 return GTK_IMAGE_EMPTY;
8110 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8114 * gtk_entry_get_icon_at_pos:
8115 * @entry: a #GtkEntry
8116 * @x: the x coordinate of the position to find
8117 * @y: the y coordinate of the position to find
8119 * Finds the icon at the given position and return its index. The
8120 * position's coordinates are relative to the @entry's top left corner.
8121 * If @x, @y doesn't lie inside an icon, -1 is returned.
8122 * This function is intended for use in a #GtkWidget::query-tooltip
8125 * Returns: the index of the icon at the given position, or -1
8130 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8134 GtkAllocation primary;
8135 GtkAllocation secondary;
8136 gint frame_x, frame_y;
8138 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8140 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8144 get_icon_allocations (entry, &primary, &secondary);
8146 if (primary.x <= x && x < primary.x + primary.width &&
8147 primary.y <= y && y < primary.y + primary.height)
8148 return GTK_ENTRY_ICON_PRIMARY;
8150 if (secondary.x <= x && x < secondary.x + secondary.width &&
8151 secondary.y <= y && y < secondary.y + secondary.height)
8152 return GTK_ENTRY_ICON_SECONDARY;
8158 * gtk_entry_set_icon_drag_source:
8159 * @entry: a #GtkIconEntry
8160 * @icon_pos: icon position
8161 * @target_list: the targets (data formats) in which the data can be provided
8162 * @actions: a bitmask of the allowed drag actions
8164 * Sets up the icon at the given position so that GTK+ will start a drag
8165 * operation when the user clicks and drags the icon.
8167 * To handle the drag operation, you need to connect to the usual
8168 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8169 * signal, and use gtk_entry_get_current_icon_drag_source() in
8170 * your signal handler to find out if the drag was started from
8173 * By default, GTK+ uses the icon as the drag icon. You can use the
8174 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8175 * have to use g_signal_connect_after() to ensure that your signal handler
8176 * gets executed after the default handler.
8181 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8182 GtkEntryIconPosition icon_pos,
8183 GtkTargetList *target_list,
8184 GdkDragAction actions)
8186 GtkEntryPrivate *priv;
8187 EntryIconInfo *icon_info;
8189 g_return_if_fail (GTK_IS_ENTRY (entry));
8190 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8194 if ((icon_info = priv->icons[icon_pos]) == NULL)
8195 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8197 if (icon_info->target_list)
8198 gtk_target_list_unref (icon_info->target_list);
8199 icon_info->target_list = target_list;
8200 if (icon_info->target_list)
8201 gtk_target_list_ref (icon_info->target_list);
8203 icon_info->actions = actions;
8207 * gtk_entry_get_current_icon_drag_source:
8208 * @entry: a #GtkIconEntry
8210 * Returns the index of the icon which is the source of the current
8211 * DND operation, or -1.
8213 * This function is meant to be used in a #GtkWidget::drag-data-get
8216 * Returns: index of the icon which is the source of the current
8217 * DND operation, or -1.
8222 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8224 GtkEntryPrivate *priv;
8225 EntryIconInfo *icon_info = NULL;
8228 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8232 for (i = 0; i < MAX_ICONS; i++)
8234 if ((icon_info = priv->icons[i]))
8236 if (icon_info->in_drag)
8245 * gtk_entry_get_icon_area:
8246 * @entry: A #GtkEntry
8247 * @icon_pos: Icon position
8248 * @icon_area: (out): Return location for the icon's area
8250 * Gets the area where entry's icon at @icon_pos is drawn.
8251 * This function is useful when drawing something to the
8252 * entry in a draw callback.
8254 * If the entry is not realized or has no icon at the given position,
8255 * @icon_area is filled with zeros.
8257 * See also gtk_entry_get_text_area()
8262 gtk_entry_get_icon_area (GtkEntry *entry,
8263 GtkEntryIconPosition icon_pos,
8264 GdkRectangle *icon_area)
8266 GtkEntryPrivate *priv;
8267 EntryIconInfo *icon_info;
8269 g_return_if_fail (GTK_IS_ENTRY (entry));
8270 g_return_if_fail (icon_area != NULL);
8274 icon_info = priv->icons[icon_pos];
8278 GtkAllocation primary;
8279 GtkAllocation secondary;
8281 get_icon_allocations (entry, &primary, &secondary);
8283 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8284 *icon_area = primary;
8286 *icon_area = secondary;
8292 icon_area->width = 0;
8293 icon_area->height = 0;
8298 ensure_has_tooltip (GtkEntry *entry)
8300 GtkEntryPrivate *priv;
8301 EntryIconInfo *icon_info;
8303 gboolean has_tooltip = FALSE;
8307 for (i = 0; i < MAX_ICONS; i++)
8309 if ((icon_info = priv->icons[i]) != NULL)
8311 if (icon_info->tooltip != NULL)
8319 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8323 * gtk_entry_get_icon_tooltip_text:
8324 * @entry: a #GtkEntry
8325 * @icon_pos: the icon position
8327 * Gets the contents of the tooltip on the icon at the specified
8328 * position in @entry.
8330 * Returns: the tooltip text, or %NULL. Free the returned string
8331 * with g_free() when done.
8336 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8337 GtkEntryIconPosition icon_pos)
8339 GtkEntryPrivate *priv;
8340 EntryIconInfo *icon_info;
8343 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8344 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8348 icon_info = priv->icons[icon_pos];
8353 if (icon_info->tooltip &&
8354 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8355 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8361 * gtk_entry_set_icon_tooltip_text:
8362 * @entry: a #GtkEntry
8363 * @icon_pos: the icon position
8364 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8366 * Sets @tooltip as the contents of the tooltip for the icon
8367 * at the specified position.
8369 * Use %NULL for @tooltip to remove an existing tooltip.
8371 * See also gtk_widget_set_tooltip_text() and
8372 * gtk_entry_set_icon_tooltip_markup().
8377 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8378 GtkEntryIconPosition icon_pos,
8379 const gchar *tooltip)
8381 GtkEntryPrivate *priv;
8382 EntryIconInfo *icon_info;
8384 g_return_if_fail (GTK_IS_ENTRY (entry));
8385 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8389 if ((icon_info = priv->icons[icon_pos]) == NULL)
8390 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8392 if (icon_info->tooltip)
8393 g_free (icon_info->tooltip);
8395 /* Treat an empty string as a NULL string,
8396 * because an empty string would be useless for a tooltip:
8398 if (tooltip && tooltip[0] == '\0')
8401 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8403 ensure_has_tooltip (entry);
8407 * gtk_entry_get_icon_tooltip_markup:
8408 * @entry: a #GtkEntry
8409 * @icon_pos: the icon position
8411 * Gets the contents of the tooltip on the icon at the specified
8412 * position in @entry.
8414 * Returns: the tooltip text, or %NULL. Free the returned string
8415 * with g_free() when done.
8420 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8421 GtkEntryIconPosition icon_pos)
8423 GtkEntryPrivate *priv;
8424 EntryIconInfo *icon_info;
8426 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8427 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8431 icon_info = priv->icons[icon_pos];
8436 return g_strdup (icon_info->tooltip);
8440 * gtk_entry_set_icon_tooltip_markup:
8441 * @entry: a #GtkEntry
8442 * @icon_pos: the icon position
8443 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8445 * Sets @tooltip as the contents of the tooltip for the icon at
8446 * the specified position. @tooltip is assumed to be marked up with
8447 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8449 * Use %NULL for @tooltip to remove an existing tooltip.
8451 * See also gtk_widget_set_tooltip_markup() and
8452 * gtk_enty_set_icon_tooltip_text().
8457 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8458 GtkEntryIconPosition icon_pos,
8459 const gchar *tooltip)
8461 GtkEntryPrivate *priv;
8462 EntryIconInfo *icon_info;
8464 g_return_if_fail (GTK_IS_ENTRY (entry));
8465 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8469 if ((icon_info = priv->icons[icon_pos]) == NULL)
8470 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8472 if (icon_info->tooltip)
8473 g_free (icon_info->tooltip);
8475 /* Treat an empty string as a NULL string,
8476 * because an empty string would be useless for a tooltip:
8478 if (tooltip && tooltip[0] == '\0')
8481 icon_info->tooltip = g_strdup (tooltip);
8483 ensure_has_tooltip (entry);
8487 gtk_entry_query_tooltip (GtkWidget *widget,
8490 gboolean keyboard_tip,
8491 GtkTooltip *tooltip)
8494 GtkEntryPrivate *priv;
8495 EntryIconInfo *icon_info;
8498 entry = GTK_ENTRY (widget);
8503 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8506 if ((icon_info = priv->icons[icon_pos]) != NULL)
8508 if (icon_info->tooltip)
8510 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8519 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8526 /* Quick hack of a popup menu
8529 activate_cb (GtkWidget *menuitem,
8532 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8533 g_signal_emit_by_name (entry, signal);
8538 gtk_entry_mnemonic_activate (GtkWidget *widget,
8539 gboolean group_cycling)
8541 gtk_widget_grab_focus (widget);
8546 append_action_signal (GtkEntry *entry,
8548 const gchar *stock_id,
8549 const gchar *signal,
8552 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8554 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8555 g_signal_connect (menuitem, "activate",
8556 G_CALLBACK (activate_cb), entry);
8558 gtk_widget_set_sensitive (menuitem, sensitive);
8560 gtk_widget_show (menuitem);
8561 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8565 popup_menu_detach (GtkWidget *attach_widget,
8568 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8569 GtkEntryPrivate *priv_attach = entry_attach->priv;
8571 priv_attach->popup_menu = NULL;
8575 popup_position_func (GtkMenu *menu,
8581 GtkEntry *entry = GTK_ENTRY (user_data);
8582 GtkEntryPrivate *priv = entry->priv;
8583 GtkWidget *widget = GTK_WIDGET (entry);
8585 GtkRequisition menu_req;
8586 GdkRectangle monitor;
8588 gint monitor_num, strong_x, height;
8590 g_return_if_fail (gtk_widget_get_realized (widget));
8592 gdk_window_get_origin (priv->text_area, x, y);
8594 screen = gtk_widget_get_screen (widget);
8595 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8596 if (monitor_num < 0)
8598 gtk_menu_set_monitor (menu, monitor_num);
8600 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8601 gtk_widget_get_preferred_size (priv->popup_menu,
8603 height = gdk_window_get_height (priv->text_area);
8604 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8605 _gtk_entry_get_borders (entry, &borders);
8607 *x += borders.left + strong_x - priv->scroll_offset;
8608 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8609 *x -= menu_req.width;
8611 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8613 else if ((*y - menu_req.height) >= monitor.y)
8614 *y -= menu_req.height;
8615 else if (monitor.y + monitor.height - (*y + height) > *y)
8618 *y -= menu_req.height;
8624 unichar_chosen_func (const char *text,
8627 GtkEntry *entry = GTK_ENTRY (data);
8628 GtkEntryPrivate *priv = entry->priv;
8631 gtk_entry_enter_text (entry, text);
8643 popup_targets_received (GtkClipboard *clipboard,
8644 GtkSelectionData *data,
8647 PopupInfo *info = user_data;
8648 GtkEntry *entry = info->entry;
8649 GtkEntryPrivate *info_entry_priv = entry->priv;
8651 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8654 gboolean clipboard_contains_text;
8655 GtkWidget *menuitem;
8657 gboolean show_input_method_menu;
8658 gboolean show_unicode_menu;
8660 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8661 if (info_entry_priv->popup_menu)
8662 gtk_widget_destroy (info_entry_priv->popup_menu);
8664 info_entry_priv->popup_menu = gtk_menu_new ();
8666 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8670 mode = gtk_entry_get_display_mode (entry);
8671 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8672 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8673 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8675 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8676 mode == DISPLAY_NORMAL &&
8677 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8679 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8680 info_entry_priv->editable && clipboard_contains_text);
8682 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8683 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8684 g_signal_connect_swapped (menuitem, "activate",
8685 G_CALLBACK (gtk_entry_delete_cb), entry);
8686 gtk_widget_show (menuitem);
8687 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8689 menuitem = gtk_separator_menu_item_new ();
8690 gtk_widget_show (menuitem);
8691 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8693 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8694 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8695 g_signal_connect_swapped (menuitem, "activate",
8696 G_CALLBACK (gtk_entry_select_all), entry);
8697 gtk_widget_show (menuitem);
8698 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8700 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8701 "gtk-show-input-method-menu", &show_input_method_menu,
8702 "gtk-show-unicode-menu", &show_unicode_menu,
8705 if (show_input_method_menu || show_unicode_menu)
8707 menuitem = gtk_separator_menu_item_new ();
8708 gtk_widget_show (menuitem);
8709 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8712 if (show_input_method_menu)
8714 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8715 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8716 gtk_widget_show (menuitem);
8717 submenu = gtk_menu_new ();
8718 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8720 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8722 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8723 GTK_MENU_SHELL (submenu));
8726 if (show_unicode_menu)
8728 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8729 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8730 gtk_widget_show (menuitem);
8732 submenu = gtk_menu_new ();
8733 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8734 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8736 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8737 unichar_chosen_func,
8741 g_signal_emit (entry,
8742 signals[POPULATE_POPUP],
8744 info_entry_priv->popup_menu);
8748 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8749 info->device, NULL, NULL, NULL, NULL, NULL,
8750 info->button, info->time);
8753 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8754 popup_position_func, entry,
8755 0, gtk_get_current_event_time ());
8756 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8760 g_object_unref (entry);
8761 g_slice_free (PopupInfo, info);
8765 gtk_entry_do_popup (GtkEntry *entry,
8766 GdkEventButton *event)
8768 PopupInfo *info = g_slice_new (PopupInfo);
8770 /* In order to know what entries we should make sensitive, we
8771 * ask for the current targets of the clipboard, and when
8772 * we get them, then we actually pop up the menu.
8774 info->entry = g_object_ref (entry);
8778 info->button = event->button;
8779 info->time = event->time;
8780 info->device = event->device;
8785 info->time = gtk_get_current_event_time ();
8786 info->device = NULL;
8789 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8790 gdk_atom_intern_static_string ("TARGETS"),
8791 popup_targets_received,
8796 gtk_entry_popup_menu (GtkWidget *widget)
8798 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8803 gtk_entry_drag_begin (GtkWidget *widget,
8804 GdkDragContext *context)
8806 GtkEntry *entry = GTK_ENTRY (widget);
8807 GtkEntryPrivate *priv = entry->priv;
8810 for (i = 0; i < MAX_ICONS; i++)
8812 EntryIconInfo *icon_info = priv->icons[i];
8814 if (icon_info != NULL)
8816 if (icon_info->in_drag)
8820 pix = _gtk_icon_helper_ensure_pixbuf
8821 (icon_info->icon_helper,
8822 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8823 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8825 g_object_unref (pix);
8832 gtk_entry_drag_end (GtkWidget *widget,
8833 GdkDragContext *context)
8835 GtkEntry *entry = GTK_ENTRY (widget);
8836 GtkEntryPrivate *priv = entry->priv;
8839 for (i = 0; i < MAX_ICONS; i++)
8841 EntryIconInfo *icon_info = priv->icons[i];
8843 if (icon_info != NULL)
8844 icon_info->in_drag = 0;
8849 gtk_entry_drag_leave (GtkWidget *widget,
8850 GdkDragContext *context,
8853 GtkEntry *entry = GTK_ENTRY (widget);
8854 GtkEntryPrivate *priv = entry->priv;
8856 priv->dnd_position = -1;
8857 gtk_widget_queue_draw (widget);
8861 gtk_entry_drag_drop (GtkWidget *widget,
8862 GdkDragContext *context,
8867 GtkEntry *entry = GTK_ENTRY (widget);
8868 GtkEntryPrivate *priv = entry->priv;
8869 GdkAtom target = GDK_NONE;
8872 target = gtk_drag_dest_find_target (widget, context, NULL);
8874 if (target != GDK_NONE)
8875 gtk_drag_get_data (widget, context, target, time);
8877 gtk_drag_finish (context, FALSE, FALSE, time);
8883 gtk_entry_drag_motion (GtkWidget *widget,
8884 GdkDragContext *context,
8889 GtkEntry *entry = GTK_ENTRY (widget);
8890 GtkEntryPrivate *priv = entry->priv;
8891 GtkStyleContext *style_context;
8892 GtkWidget *source_widget;
8893 GdkDragAction suggested_action;
8894 gint new_position, old_position;
8898 style_context = gtk_widget_get_style_context (widget);
8899 gtk_style_context_get_padding (style_context, 0, &padding);
8903 old_position = priv->dnd_position;
8904 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8906 if (priv->editable &&
8907 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8909 source_widget = gtk_drag_get_source_widget (context);
8910 suggested_action = gdk_drag_context_get_suggested_action (context);
8912 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8913 new_position < sel1 || new_position > sel2)
8915 if (source_widget == widget)
8917 /* Default to MOVE, unless the user has
8918 * pressed ctrl or alt to affect available actions
8920 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8921 suggested_action = GDK_ACTION_MOVE;
8924 priv->dnd_position = new_position;
8928 if (source_widget == widget)
8929 suggested_action = 0; /* Can't drop in selection where drag started */
8931 priv->dnd_position = -1;
8936 /* Entry not editable, or no text */
8937 suggested_action = 0;
8938 priv->dnd_position = -1;
8941 gdk_drag_status (context, suggested_action, time);
8943 if (priv->dnd_position != old_position)
8944 gtk_widget_queue_draw (widget);
8950 gtk_entry_drag_data_received (GtkWidget *widget,
8951 GdkDragContext *context,
8954 GtkSelectionData *selection_data,
8958 GtkEntry *entry = GTK_ENTRY (widget);
8959 GtkEntryPrivate *priv = entry->priv;
8960 GtkEditable *editable = GTK_EDITABLE (widget);
8961 GtkStyleContext *style_context;
8965 str = (gchar *) gtk_selection_data_get_text (selection_data);
8967 style_context = gtk_widget_get_style_context (widget);
8968 gtk_style_context_get_padding (style_context, 0, &padding);
8972 if (str && priv->editable)
8978 if (priv->truncate_multiline)
8979 length = truncate_multiline (str);
8981 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8983 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8984 new_position < sel1 || new_position > sel2)
8986 gtk_editable_insert_text (editable, str, length, &new_position);
8990 /* Replacing selection */
8991 begin_change (entry);
8992 gtk_editable_delete_text (editable, sel1, sel2);
8993 gtk_editable_insert_text (editable, str, length, &sel1);
8997 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9001 /* Drag and drop didn't happen! */
9002 gtk_drag_finish (context, FALSE, FALSE, time);
9009 gtk_entry_drag_data_get (GtkWidget *widget,
9010 GdkDragContext *context,
9011 GtkSelectionData *selection_data,
9015 GtkEntry *entry = GTK_ENTRY (widget);
9016 GtkEntryPrivate *priv = entry->priv;
9017 GtkEditable *editable = GTK_EDITABLE (widget);
9018 gint sel_start, sel_end;
9021 /* If there is an icon drag going on, exit early. */
9022 for (i = 0; i < MAX_ICONS; i++)
9024 EntryIconInfo *icon_info = priv->icons[i];
9026 if (icon_info != NULL)
9028 if (icon_info->in_drag)
9033 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9035 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9037 gtk_selection_data_set_text (selection_data, str, -1);
9045 gtk_entry_drag_data_delete (GtkWidget *widget,
9046 GdkDragContext *context)
9048 GtkEntry *entry = GTK_ENTRY (widget);
9049 GtkEntryPrivate *priv = entry->priv;
9050 GtkEditable *editable = GTK_EDITABLE (widget);
9051 gint sel_start, sel_end;
9054 /* If there is an icon drag going on, exit early. */
9055 for (i = 0; i < MAX_ICONS; i++)
9057 EntryIconInfo *icon_info = priv->icons[i];
9059 if (icon_info != NULL)
9061 if (icon_info->in_drag)
9066 if (priv->editable &&
9067 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9068 gtk_editable_delete_text (editable, sel_start, sel_end);
9071 /* We display the cursor when
9073 * - the selection is empty, AND
9074 * - the widget has focus
9077 #define CURSOR_ON_MULTIPLIER 2
9078 #define CURSOR_OFF_MULTIPLIER 1
9079 #define CURSOR_PEND_MULTIPLIER 3
9080 #define CURSOR_DIVIDER 3
9083 cursor_blinks (GtkEntry *entry)
9085 GtkEntryPrivate *priv = entry->priv;
9087 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9089 priv->selection_bound == priv->current_pos)
9091 GtkSettings *settings;
9094 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9095 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9104 get_cursor_time (GtkEntry *entry)
9106 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9109 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9115 get_cursor_blink_timeout (GtkEntry *entry)
9117 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9120 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9126 show_cursor (GtkEntry *entry)
9128 GtkEntryPrivate *priv = entry->priv;
9131 if (!priv->cursor_visible)
9133 priv->cursor_visible = TRUE;
9135 widget = GTK_WIDGET (entry);
9136 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9137 gtk_widget_queue_draw (widget);
9142 hide_cursor (GtkEntry *entry)
9144 GtkEntryPrivate *priv = entry->priv;
9147 if (priv->cursor_visible)
9149 priv->cursor_visible = FALSE;
9151 widget = GTK_WIDGET (entry);
9152 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9153 gtk_widget_queue_draw (widget);
9161 blink_cb (gpointer data)
9164 GtkEntryPrivate *priv;
9167 entry = GTK_ENTRY (data);
9170 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9172 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9173 "connect a handler to this signal, it must return\n"
9174 "FALSE so the entry gets the event as well");
9176 gtk_entry_check_cursor_blink (entry);
9181 g_assert (priv->selection_bound == priv->current_pos);
9183 blink_timeout = get_cursor_blink_timeout (entry);
9184 if (priv->blink_time > 1000 * blink_timeout &&
9185 blink_timeout < G_MAXINT/1000)
9187 /* we've blinked enough without the user doing anything, stop blinking */
9188 show_cursor (entry);
9189 priv->blink_timeout = 0;
9191 else if (priv->cursor_visible)
9193 hide_cursor (entry);
9194 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9200 show_cursor (entry);
9201 priv->blink_time += get_cursor_time (entry);
9202 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9207 /* Remove ourselves */
9212 gtk_entry_check_cursor_blink (GtkEntry *entry)
9214 GtkEntryPrivate *priv = entry->priv;
9216 if (cursor_blinks (entry))
9218 if (!priv->blink_timeout)
9220 show_cursor (entry);
9221 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9228 if (priv->blink_timeout)
9230 g_source_remove (priv->blink_timeout);
9231 priv->blink_timeout = 0;
9234 priv->cursor_visible = TRUE;
9239 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9241 GtkEntryPrivate *priv = entry->priv;
9243 if (cursor_blinks (entry))
9245 if (priv->blink_timeout != 0)
9246 g_source_remove (priv->blink_timeout);
9248 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9251 show_cursor (entry);
9256 gtk_entry_reset_blink_time (GtkEntry *entry)
9258 GtkEntryPrivate *priv = entry->priv;
9260 priv->blink_time = 0;
9266 gtk_entry_completion_timeout (gpointer data)
9268 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9269 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9271 completion->priv->completion_timeout = 0;
9273 if (completion->priv->filter_model &&
9274 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9275 >= completion->priv->minimum_key_length)
9279 GtkTreeSelection *s;
9280 gboolean popup_single;
9282 gtk_entry_completion_complete (completion);
9283 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9285 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9287 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9289 gtk_tree_selection_unselect_all (s);
9291 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9293 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9294 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9296 if (gtk_widget_get_visible (completion->priv->popup_window))
9297 _gtk_entry_completion_resize_popup (completion);
9299 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9302 _gtk_entry_completion_popdown (completion);
9304 else if (gtk_widget_get_visible (completion->priv->popup_window))
9305 _gtk_entry_completion_popdown (completion);
9310 static inline gboolean
9311 keyval_is_cursor_move (guint keyval)
9313 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9316 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9319 if (keyval == GDK_KEY_Page_Up)
9322 if (keyval == GDK_KEY_Page_Down)
9329 gtk_entry_completion_key_press (GtkWidget *widget,
9333 gint matches, actions = 0;
9334 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9336 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9339 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9341 if (completion->priv->actions)
9342 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9344 if (keyval_is_cursor_move (event->keyval))
9346 GtkTreePath *path = NULL;
9348 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9350 if (completion->priv->current_selected < 0)
9351 completion->priv->current_selected = matches + actions - 1;
9353 completion->priv->current_selected--;
9355 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9357 if (completion->priv->current_selected < matches + actions - 1)
9358 completion->priv->current_selected++;
9360 completion->priv->current_selected = -1;
9362 else if (event->keyval == GDK_KEY_Page_Up)
9364 if (completion->priv->current_selected < 0)
9365 completion->priv->current_selected = matches + actions - 1;
9366 else if (completion->priv->current_selected == 0)
9367 completion->priv->current_selected = -1;
9368 else if (completion->priv->current_selected < matches)
9370 completion->priv->current_selected -= PAGE_STEP;
9371 if (completion->priv->current_selected < 0)
9372 completion->priv->current_selected = 0;
9376 completion->priv->current_selected -= PAGE_STEP;
9377 if (completion->priv->current_selected < matches - 1)
9378 completion->priv->current_selected = matches - 1;
9381 else if (event->keyval == GDK_KEY_Page_Down)
9383 if (completion->priv->current_selected < 0)
9384 completion->priv->current_selected = 0;
9385 else if (completion->priv->current_selected < matches - 1)
9387 completion->priv->current_selected += PAGE_STEP;
9388 if (completion->priv->current_selected > matches - 1)
9389 completion->priv->current_selected = matches - 1;
9391 else if (completion->priv->current_selected == matches + actions - 1)
9393 completion->priv->current_selected = -1;
9397 completion->priv->current_selected += PAGE_STEP;
9398 if (completion->priv->current_selected > matches + actions - 1)
9399 completion->priv->current_selected = matches + actions - 1;
9403 if (completion->priv->current_selected < 0)
9405 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9406 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9408 if (completion->priv->inline_selection &&
9409 completion->priv->completion_prefix)
9411 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9412 completion->priv->completion_prefix);
9413 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9416 else if (completion->priv->current_selected < matches)
9418 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9420 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9421 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9424 if (completion->priv->inline_selection)
9428 GtkTreeIter child_iter;
9429 GtkTreeModel *model = NULL;
9430 GtkTreeSelection *sel;
9433 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9434 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9437 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9438 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9440 if (completion->priv->completion_prefix == NULL)
9441 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9443 g_signal_emit_by_name (completion, "cursor-on-match", model,
9444 &child_iter, &entry_set);
9447 else if (completion->priv->current_selected - matches >= 0)
9449 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9451 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9452 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9455 if (completion->priv->inline_selection &&
9456 completion->priv->completion_prefix)
9458 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9459 completion->priv->completion_prefix);
9460 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9464 gtk_tree_path_free (path);
9468 else if (event->keyval == GDK_KEY_Escape ||
9469 event->keyval == GDK_KEY_Left ||
9470 event->keyval == GDK_KEY_KP_Left ||
9471 event->keyval == GDK_KEY_Right ||
9472 event->keyval == GDK_KEY_KP_Right)
9474 gboolean retval = TRUE;
9476 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9477 _gtk_entry_completion_popdown (completion);
9479 if (completion->priv->current_selected < 0)
9482 goto keypress_completion_out;
9484 else if (completion->priv->inline_selection)
9486 /* Escape rejects the tentative completion */
9487 if (event->keyval == GDK_KEY_Escape)
9489 if (completion->priv->completion_prefix)
9490 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9491 completion->priv->completion_prefix);
9493 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9496 /* Move the cursor to the end for Right/Esc, to the
9497 beginning for Left */
9498 if (event->keyval == GDK_KEY_Right ||
9499 event->keyval == GDK_KEY_KP_Right ||
9500 event->keyval == GDK_KEY_Escape)
9501 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9503 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9506 keypress_completion_out:
9507 if (completion->priv->inline_selection)
9509 g_free (completion->priv->completion_prefix);
9510 completion->priv->completion_prefix = NULL;
9515 else if (event->keyval == GDK_KEY_Tab ||
9516 event->keyval == GDK_KEY_KP_Tab ||
9517 event->keyval == GDK_KEY_ISO_Left_Tab)
9519 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9520 _gtk_entry_completion_popdown (completion);
9522 g_free (completion->priv->completion_prefix);
9523 completion->priv->completion_prefix = NULL;
9527 else if (event->keyval == GDK_KEY_ISO_Enter ||
9528 event->keyval == GDK_KEY_KP_Enter ||
9529 event->keyval == GDK_KEY_Return)
9532 GtkTreeModel *model = NULL;
9533 GtkTreeModel *child_model;
9534 GtkTreeIter child_iter;
9535 GtkTreeSelection *sel;
9536 gboolean retval = TRUE;
9538 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9539 _gtk_entry_completion_popdown (completion);
9541 if (completion->priv->current_selected < matches)
9545 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9546 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9548 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9549 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9550 g_signal_handler_block (widget, completion->priv->changed_id);
9551 g_signal_emit_by_name (completion, "match-selected",
9552 child_model, &child_iter, &entry_set);
9553 g_signal_handler_unblock (widget, completion->priv->changed_id);
9559 gtk_tree_model_get (model, &iter,
9560 completion->priv->text_column, &str,
9563 gtk_entry_set_text (GTK_ENTRY (widget), str);
9565 /* move the cursor to the end */
9566 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9574 else if (completion->priv->current_selected - matches >= 0)
9576 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9577 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9581 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9582 g_signal_emit_by_name (completion, "action-activated",
9583 gtk_tree_path_get_indices (path)[0]);
9584 gtk_tree_path_free (path);
9590 g_free (completion->priv->completion_prefix);
9591 completion->priv->completion_prefix = NULL;
9600 gtk_entry_completion_changed (GtkWidget *widget,
9603 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9604 GtkEntry *entry = GTK_ENTRY (widget);
9605 GtkEntryPrivate *priv = entry->priv;
9608 /* (re)install completion timeout */
9609 if (completion->priv->completion_timeout)
9610 g_source_remove (completion->priv->completion_timeout);
9612 if (!gtk_entry_get_text (entry))
9615 /* no need to normalize for this test */
9616 if (completion->priv->minimum_key_length > 0 &&
9617 strcmp ("", gtk_entry_get_text (entry)) == 0)
9619 if (gtk_widget_get_visible (completion->priv->popup_window))
9620 _gtk_entry_completion_popdown (completion);
9624 device = gtk_get_current_event_device ();
9626 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9627 device = gdk_device_get_associated_device (device);
9630 priv->completion_device = device;
9632 completion->priv->completion_timeout =
9633 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9634 gtk_entry_completion_timeout,
9639 check_completion_callback (GtkEntryCompletion *completion)
9641 completion->priv->check_completion_idle = NULL;
9643 gtk_entry_completion_complete (completion);
9644 gtk_entry_completion_insert_prefix (completion);
9650 clear_completion_callback (GtkEntry *entry,
9653 if (pspec->name == I_("cursor-position") ||
9654 pspec->name == I_("selection-bound"))
9656 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9658 completion->priv->has_completion = FALSE;
9663 accept_completion_callback (GtkEntry *entry)
9665 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9667 if (completion->priv->has_completion)
9668 gtk_editable_set_position (GTK_EDITABLE (entry),
9669 gtk_entry_buffer_get_length (get_buffer (entry)));
9675 completion_insert_text_callback (GtkEntry *entry,
9679 GtkEntryCompletion *completion)
9681 /* idle to update the selection based on the file list */
9682 if (completion->priv->check_completion_idle == NULL)
9684 completion->priv->check_completion_idle = g_idle_source_new ();
9685 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9686 g_source_set_closure (completion->priv->check_completion_idle,
9687 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9688 G_OBJECT (completion)));
9689 g_source_attach (completion->priv->check_completion_idle, NULL);
9694 completion_changed (GtkEntryCompletion *completion,
9698 GtkEntry *entry = GTK_ENTRY (data);
9700 if (pspec->name == I_("popup-completion") ||
9701 pspec->name == I_("inline-completion"))
9703 disconnect_completion_signals (entry, completion);
9704 connect_completion_signals (entry, completion);
9709 disconnect_completion_signals (GtkEntry *entry,
9710 GtkEntryCompletion *completion)
9712 g_signal_handlers_disconnect_by_func (completion,
9713 G_CALLBACK (completion_changed), entry);
9714 if (completion->priv->changed_id > 0 &&
9715 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9717 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9718 completion->priv->changed_id = 0;
9720 g_signal_handlers_disconnect_by_func (entry,
9721 G_CALLBACK (gtk_entry_completion_key_press), completion);
9722 if (completion->priv->insert_text_id > 0 &&
9723 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9725 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9726 completion->priv->insert_text_id = 0;
9728 g_signal_handlers_disconnect_by_func (entry,
9729 G_CALLBACK (completion_insert_text_callback), completion);
9730 g_signal_handlers_disconnect_by_func (entry,
9731 G_CALLBACK (clear_completion_callback), completion);
9732 g_signal_handlers_disconnect_by_func (entry,
9733 G_CALLBACK (accept_completion_callback), completion);
9737 connect_completion_signals (GtkEntry *entry,
9738 GtkEntryCompletion *completion)
9740 if (completion->priv->popup_completion)
9742 completion->priv->changed_id =
9743 g_signal_connect (entry, "changed",
9744 G_CALLBACK (gtk_entry_completion_changed), completion);
9745 g_signal_connect (entry, "key-press-event",
9746 G_CALLBACK (gtk_entry_completion_key_press), completion);
9749 if (completion->priv->inline_completion)
9751 completion->priv->insert_text_id =
9752 g_signal_connect (entry, "insert-text",
9753 G_CALLBACK (completion_insert_text_callback), completion);
9754 g_signal_connect (entry, "notify",
9755 G_CALLBACK (clear_completion_callback), completion);
9756 g_signal_connect (entry, "activate",
9757 G_CALLBACK (accept_completion_callback), completion);
9758 g_signal_connect (entry, "focus-out-event",
9759 G_CALLBACK (accept_completion_callback), completion);
9762 g_signal_connect (completion, "notify",
9763 G_CALLBACK (completion_changed), entry);
9767 * gtk_entry_set_completion:
9768 * @entry: A #GtkEntry
9769 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9771 * Sets @completion to be the auxiliary completion object to use with @entry.
9772 * All further configuration of the completion mechanism is done on
9773 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9774 * @completion is set to %NULL.
9779 gtk_entry_set_completion (GtkEntry *entry,
9780 GtkEntryCompletion *completion)
9782 GtkEntryCompletion *old;
9784 g_return_if_fail (GTK_IS_ENTRY (entry));
9785 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9787 old = gtk_entry_get_completion (entry);
9789 if (old == completion)
9794 if (old->priv->completion_timeout)
9796 g_source_remove (old->priv->completion_timeout);
9797 old->priv->completion_timeout = 0;
9800 if (old->priv->check_completion_idle)
9802 g_source_destroy (old->priv->check_completion_idle);
9803 old->priv->check_completion_idle = NULL;
9806 if (gtk_widget_get_mapped (old->priv->popup_window))
9807 _gtk_entry_completion_popdown (old);
9809 disconnect_completion_signals (entry, old);
9810 old->priv->entry = NULL;
9812 g_object_unref (old);
9817 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9821 /* hook into the entry */
9822 g_object_ref (completion);
9824 connect_completion_signals (entry, completion);
9825 completion->priv->entry = GTK_WIDGET (entry);
9826 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9828 g_object_notify (G_OBJECT (entry), "completion");
9832 * gtk_entry_get_completion:
9833 * @entry: A #GtkEntry
9835 * Returns the auxiliary completion object currently in use by @entry.
9837 * Return value: (transfer none): The auxiliary completion object currently
9842 GtkEntryCompletion *
9843 gtk_entry_get_completion (GtkEntry *entry)
9845 GtkEntryCompletion *completion;
9847 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9849 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9850 GTK_ENTRY_COMPLETION_KEY));
9856 * gtk_entry_set_cursor_hadjustment:
9857 * @entry: a #GtkEntry
9858 * @adjustment: an adjustment which should be adjusted when the cursor
9859 * is moved, or %NULL
9861 * Hooks up an adjustment to the cursor position in an entry, so that when
9862 * the cursor is moved, the adjustment is scrolled to show that position.
9863 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9866 * The adjustment has to be in pixel units and in the same coordinate system
9872 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9873 GtkAdjustment *adjustment)
9875 g_return_if_fail (GTK_IS_ENTRY (entry));
9877 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9880 g_object_ref (adjustment);
9882 g_object_set_qdata_full (G_OBJECT (entry),
9883 quark_cursor_hadjustment,
9889 * gtk_entry_get_cursor_hadjustment:
9890 * @entry: a #GtkEntry
9892 * Retrieves the horizontal cursor adjustment for the entry.
9893 * See gtk_entry_set_cursor_hadjustment().
9895 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9896 * if none has been set.
9901 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9903 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9905 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9909 * gtk_entry_set_progress_fraction:
9910 * @entry: a #GtkEntry
9911 * @fraction: fraction of the task that's been completed
9913 * Causes the entry's progress indicator to "fill in" the given
9914 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9920 gtk_entry_set_progress_fraction (GtkEntry *entry,
9924 GtkEntryPrivate *private;
9925 gdouble old_fraction;
9926 gint x, y, width, height;
9927 gint old_x, old_y, old_width, old_height;
9929 g_return_if_fail (GTK_IS_ENTRY (entry));
9931 widget = GTK_WIDGET (entry);
9932 private = entry->priv;
9934 if (private->progress_pulse_mode)
9937 old_fraction = private->progress_fraction;
9939 if (gtk_widget_is_drawable (widget))
9940 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9942 fraction = CLAMP (fraction, 0.0, 1.0);
9944 private->progress_fraction = fraction;
9945 private->progress_pulse_mode = FALSE;
9946 private->progress_pulse_current = 0.0;
9948 if (gtk_widget_is_drawable (widget))
9950 get_progress_area (widget, &x, &y, &width, &height);
9952 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9953 gtk_widget_queue_draw (widget);
9956 if (fraction != old_fraction)
9957 g_object_notify (G_OBJECT (entry), "progress-fraction");
9961 * gtk_entry_get_progress_fraction:
9962 * @entry: a #GtkEntry
9964 * Returns the current fraction of the task that's been completed.
9965 * See gtk_entry_set_progress_fraction().
9967 * Return value: a fraction from 0.0 to 1.0
9972 gtk_entry_get_progress_fraction (GtkEntry *entry)
9974 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9976 return entry->priv->progress_fraction;
9980 * gtk_entry_set_progress_pulse_step:
9981 * @entry: a #GtkEntry
9982 * @fraction: fraction between 0.0 and 1.0
9984 * Sets the fraction of total entry width to move the progress
9985 * bouncing block for each call to gtk_entry_progress_pulse().
9990 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9993 GtkEntryPrivate *private;
9995 g_return_if_fail (GTK_IS_ENTRY (entry));
9997 private = entry->priv;
9999 fraction = CLAMP (fraction, 0.0, 1.0);
10001 if (fraction != private->progress_pulse_fraction)
10003 private->progress_pulse_fraction = fraction;
10005 gtk_widget_queue_draw (GTK_WIDGET (entry));
10007 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10012 * gtk_entry_get_progress_pulse_step:
10013 * @entry: a #GtkEntry
10015 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10017 * Return value: a fraction from 0.0 to 1.0
10022 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10024 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10026 return entry->priv->progress_pulse_fraction;
10030 * gtk_entry_progress_pulse:
10031 * @entry: a #GtkEntry
10033 * Indicates that some progress is made, but you don't know how much.
10034 * Causes the entry's progress indicator to enter "activity mode,"
10035 * where a block bounces back and forth. Each call to
10036 * gtk_entry_progress_pulse() causes the block to move by a little bit
10037 * (the amount of movement per pulse is determined by
10038 * gtk_entry_set_progress_pulse_step()).
10043 gtk_entry_progress_pulse (GtkEntry *entry)
10045 GtkEntryPrivate *private;
10047 g_return_if_fail (GTK_IS_ENTRY (entry));
10049 private = entry->priv;
10051 if (private->progress_pulse_mode)
10053 if (private->progress_pulse_way_back)
10055 private->progress_pulse_current -= private->progress_pulse_fraction;
10057 if (private->progress_pulse_current < 0.0)
10059 private->progress_pulse_current = 0.0;
10060 private->progress_pulse_way_back = FALSE;
10065 private->progress_pulse_current += private->progress_pulse_fraction;
10067 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10069 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10070 private->progress_pulse_way_back = TRUE;
10076 private->progress_fraction = 0.0;
10077 private->progress_pulse_mode = TRUE;
10078 private->progress_pulse_way_back = FALSE;
10079 private->progress_pulse_current = 0.0;
10082 gtk_widget_queue_draw (GTK_WIDGET (entry));
10086 * gtk_entry_set_placeholder_text:
10087 * @entry: a #GtkEntry
10088 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10090 * Sets text to be displayed in @entry when it is empty and unfocused.
10091 * This can be used to give a visual hint of the expected contents of
10094 * Note that since the placeholder text gets removed when the entry
10095 * received focus, using this feature is a bit problematic if the entry
10096 * is given the initial focus in a window. Sometimes this can be
10097 * worked around by delaying the initial focus setting until the
10098 * first key event arrives.
10103 gtk_entry_set_placeholder_text (GtkEntry *entry,
10106 GtkEntryPrivate *priv;
10108 g_return_if_fail (GTK_IS_ENTRY (entry));
10110 priv = entry->priv;
10112 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10115 g_free (priv->placeholder_text);
10116 priv->placeholder_text = g_strdup (text);
10118 gtk_entry_recompute (entry);
10120 g_object_notify (G_OBJECT (entry), "placeholder-text");
10124 * gtk_entry_get_placeholder_text:
10125 * @entry: a #GtkEntry
10127 * Retrieves the text that will be displayed when @entry is empty and unfocused
10129 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10130 * storage in the widget and must not be freed, modified or stored.
10135 gtk_entry_get_placeholder_text (GtkEntry *entry)
10137 GtkEntryPrivate *priv;
10139 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10141 priv = entry->priv;
10143 return priv->placeholder_text;
10146 /* Caps Lock warning for password entries */
10149 show_capslock_feedback (GtkEntry *entry,
10152 GtkEntryPrivate *priv = entry->priv;
10154 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10156 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10157 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10158 priv->caps_lock_warning_shown = TRUE;
10161 if (priv->caps_lock_warning_shown)
10162 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10164 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10168 remove_capslock_feedback (GtkEntry *entry)
10170 GtkEntryPrivate *priv = entry->priv;
10172 if (priv->caps_lock_warning_shown)
10174 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10175 priv->caps_lock_warning_shown = FALSE;
10180 keymap_state_changed (GdkKeymap *keymap,
10183 GtkEntryPrivate *priv = entry->priv;
10186 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10188 if (gdk_keymap_get_num_lock_state (keymap)
10189 && gdk_keymap_get_caps_lock_state (keymap))
10190 text = _("Caps Lock and Num Lock are on");
10191 else if (gdk_keymap_get_num_lock_state (keymap))
10192 text = _("Num Lock is on");
10193 else if (gdk_keymap_get_caps_lock_state (keymap))
10194 text = _("Caps Lock is on");
10198 show_capslock_feedback (entry, text);
10200 remove_capslock_feedback (entry);
10204 * _gtk_entry_set_is_cell_renderer:
10205 * @entry: a #GtkEntry
10206 * @is_cell_renderer: new value
10208 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10209 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10211 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10215 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10216 gboolean is_cell_renderer)
10218 entry->priv->is_cell_renderer = is_cell_renderer;