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 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3502 GtkStyleContext *context)
3504 GtkEntryPrivate *private = entry->priv;
3506 gtk_style_context_save (context);
3507 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3508 if (private->progress_pulse_mode)
3509 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3513 get_progress_area (GtkWidget *widget,
3519 GtkEntry *entry = GTK_ENTRY (widget);
3520 GtkEntryPrivate *private = entry->priv;
3521 GtkStyleContext *context;
3524 get_frame_size (GTK_ENTRY (widget), FALSE, NULL, NULL, width, height);
3528 if (!private->interior_focus)
3530 *x -= private->focus_width;
3531 *y -= private->focus_width;
3532 *width += 2 * private->focus_width;
3533 *height += 2 * private->focus_width;
3536 context = gtk_widget_get_style_context (widget);
3537 gtk_entry_prepare_context_for_progress (entry, context);
3538 gtk_style_context_get_margin (context, 0, &margin);
3540 gtk_style_context_restore (context);
3544 *width -= margin.left + margin.right;
3545 *height -= margin.top + margin.bottom;
3547 if (private->progress_pulse_mode)
3549 gdouble value = private->progress_pulse_current;
3551 *x += (gint) floor(value * (*width));
3552 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3554 else if (private->progress_fraction > 0)
3556 gdouble value = private->progress_fraction;
3558 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3562 bar_width = floor(value * (*width) + 0.5);
3563 *x += *width - bar_width;
3568 *width = (gint) floor(value * (*width) + 0.5);
3579 gtk_entry_draw_progress (GtkWidget *widget,
3580 GtkStyleContext *context,
3583 GtkEntry *entry = GTK_ENTRY (widget);
3584 GtkEntryPrivate *private = entry->priv;
3585 gint x, y, width, height;
3587 get_progress_area (widget, &x, &y, &width, &height);
3589 if ((width <= 0) || (height <= 0))
3592 gtk_entry_prepare_context_for_progress (entry, context);
3593 gtk_render_activity (context, cr,
3594 x, y, width, height);
3596 gtk_style_context_restore (context);
3600 gtk_entry_draw (GtkWidget *widget,
3603 GtkEntry *entry = GTK_ENTRY (widget);
3604 GtkStyleContext *context;
3605 GtkEntryPrivate *priv = entry->priv;
3608 context = gtk_widget_get_style_context (widget);
3610 /* Draw entry_bg, shadow, progress and focus */
3611 gtk_entry_draw_frame (widget, context, cr);
3613 /* Draw text and cursor */
3616 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3618 if (priv->dnd_position != -1)
3619 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3621 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3623 /* When no text is being displayed at all, don't show the cursor */
3624 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3625 gtk_widget_has_focus (widget) &&
3626 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3627 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3632 for (i = 0; i < MAX_ICONS; i++)
3634 EntryIconInfo *icon_info = priv->icons[i];
3636 if (icon_info != NULL)
3637 draw_icon (widget, cr, i);
3644 gtk_entry_enter_notify (GtkWidget *widget,
3645 GdkEventCrossing *event)
3647 GtkEntry *entry = GTK_ENTRY (widget);
3648 GtkEntryPrivate *priv = entry->priv;
3651 for (i = 0; i < MAX_ICONS; i++)
3653 EntryIconInfo *icon_info = priv->icons[i];
3655 if (icon_info != NULL && event->window == icon_info->window)
3657 if (should_prelight (entry, i))
3659 icon_info->prelight = TRUE;
3660 gtk_widget_queue_draw (widget);
3671 gtk_entry_leave_notify (GtkWidget *widget,
3672 GdkEventCrossing *event)
3674 GtkEntry *entry = GTK_ENTRY (widget);
3675 GtkEntryPrivate *priv = entry->priv;
3678 for (i = 0; i < MAX_ICONS; i++)
3680 EntryIconInfo *icon_info = priv->icons[i];
3682 if (icon_info != NULL && event->window == icon_info->window)
3684 /* a grab means that we may never see the button release */
3685 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3686 icon_info->pressed = FALSE;
3688 if (should_prelight (entry, i))
3690 icon_info->prelight = FALSE;
3691 gtk_widget_queue_draw (widget);
3702 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3706 gint start_char, end_char;
3708 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3710 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3711 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3712 const char *text = pango_layout_get_text (layout);
3713 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3714 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3715 gint real_n_ranges, i;
3717 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3723 for (i = 0; i < real_n_ranges; ++i)
3725 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3726 r[2 * i] = r[2 * i] / PANGO_SCALE;
3731 *n_ranges = real_n_ranges;
3743 in_selection (GtkEntry *entry,
3748 gint retval = FALSE;
3750 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3752 for (i = 0; i < n_ranges; ++i)
3754 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3766 gtk_entry_button_press (GtkWidget *widget,
3767 GdkEventButton *event)
3769 GtkEntry *entry = GTK_ENTRY (widget);
3770 GtkEditable *editable = GTK_EDITABLE (widget);
3771 GtkEntryPrivate *priv = entry->priv;
3772 EntryIconInfo *icon_info = NULL;
3774 gint sel_start, sel_end;
3777 for (i = 0; i < MAX_ICONS; i++)
3779 icon_info = priv->icons[i];
3781 if (!icon_info || icon_info->insensitive)
3784 if (event->window == icon_info->window)
3786 if (should_prelight (entry, i))
3788 icon_info->prelight = FALSE;
3789 gtk_widget_queue_draw (widget);
3792 priv->start_x = event->x;
3793 priv->start_y = event->y;
3794 icon_info->pressed = TRUE;
3796 if (!icon_info->nonactivatable)
3797 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3803 if (event->window != priv->text_area ||
3804 (priv->button && event->button != priv->button))
3807 gtk_entry_reset_blink_time (entry);
3809 priv->button = event->button;
3811 if (!gtk_widget_has_focus (widget))
3813 priv->in_click = TRUE;
3814 gtk_widget_grab_focus (widget);
3815 priv->in_click = FALSE;
3818 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3820 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3822 gtk_entry_do_popup (entry, event);
3823 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3827 else if (event->button == GDK_BUTTON_PRIMARY)
3829 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3831 priv->select_words = FALSE;
3832 priv->select_lines = FALSE;
3835 gtk_widget_get_modifier_mask (widget,
3836 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3838 _gtk_entry_reset_im_context (entry);
3840 if (!have_selection) /* select from the current position to the clicked position */
3841 sel_start = sel_end = priv->current_pos;
3843 if (tmp_pos > sel_start && tmp_pos < sel_end)
3845 /* Truncate current selection, but keep it as big as possible */
3846 if (tmp_pos - sel_start > sel_end - tmp_pos)
3847 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3849 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3853 gboolean extend_to_left;
3856 /* Figure out what click selects and extend current selection */
3857 switch (event->type)
3859 case GDK_BUTTON_PRESS:
3860 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3863 case GDK_2BUTTON_PRESS:
3864 priv->select_words = TRUE;
3865 gtk_entry_select_word (entry);
3868 case GDK_3BUTTON_PRESS:
3869 priv->select_lines = TRUE;
3870 gtk_entry_select_line (entry);
3877 start = MIN (priv->current_pos, priv->selection_bound);
3878 start = MIN (sel_start, start);
3880 end = MAX (priv->current_pos, priv->selection_bound);
3881 end = MAX (sel_end, end);
3883 if (tmp_pos == sel_start || tmp_pos == sel_end)
3884 extend_to_left = (tmp_pos == start);
3886 extend_to_left = (end == sel_end);
3889 gtk_entry_set_positions (entry, start, end);
3891 gtk_entry_set_positions (entry, end, start);
3894 else /* no shift key */
3895 switch (event->type)
3897 case GDK_BUTTON_PRESS:
3898 if (in_selection (entry, event->x + priv->scroll_offset))
3900 /* Click inside the selection - we'll either start a drag, or
3901 * clear the selection
3903 priv->in_drag = TRUE;
3904 priv->drag_start_x = event->x + priv->scroll_offset;
3905 priv->drag_start_y = event->y;
3908 gtk_editable_set_position (editable, tmp_pos);
3911 case GDK_2BUTTON_PRESS:
3912 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3913 * receiving a GDK_2BUTTON_PRESS so we need to reset
3914 * priv->in_drag which may have been set above
3916 priv->in_drag = FALSE;
3917 priv->select_words = TRUE;
3918 gtk_entry_select_word (entry);
3921 case GDK_3BUTTON_PRESS:
3922 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3923 * receiving a GDK_3BUTTON_PRESS so we need to reset
3924 * priv->in_drag which may have been set above
3926 priv->in_drag = FALSE;
3927 priv->select_lines = TRUE;
3928 gtk_entry_select_line (entry);
3937 else if (event->button == GDK_BUTTON_MIDDLE && event->type == GDK_BUTTON_PRESS)
3941 priv->insert_pos = tmp_pos;
3942 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3947 gtk_widget_error_bell (widget);
3955 gtk_entry_button_release (GtkWidget *widget,
3956 GdkEventButton *event)
3958 GtkEntry *entry = GTK_ENTRY (widget);
3959 GtkEntryPrivate *priv = entry->priv;
3960 EntryIconInfo *icon_info = NULL;
3963 for (i = 0; i < MAX_ICONS; i++)
3965 icon_info = priv->icons[i];
3967 if (!icon_info || icon_info->insensitive)
3970 if (event->window == icon_info->window)
3972 icon_info->pressed = FALSE;
3974 if (should_prelight (entry, i) &&
3975 event->x >= 0 && event->y >= 0 &&
3976 event->x < gdk_window_get_width (icon_info->window) &&
3977 event->y < gdk_window_get_height (icon_info->window))
3979 icon_info->prelight = TRUE;
3980 gtk_widget_queue_draw (widget);
3983 if (!icon_info->nonactivatable)
3984 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3990 if (event->window != priv->text_area || priv->button != event->button)
3995 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3997 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4004 gtk_entry_update_primary_selection (entry);
4010 _gtk_entry_get_selected_text (GtkEntry *entry)
4012 GtkEditable *editable = GTK_EDITABLE (entry);
4013 gint start_text, end_text;
4016 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4017 text = gtk_editable_get_chars (editable, start_text, end_text);
4023 gtk_entry_motion_notify (GtkWidget *widget,
4024 GdkEventMotion *event)
4026 GtkEntry *entry = GTK_ENTRY (widget);
4027 GtkEntryPrivate *priv = entry->priv;
4028 EntryIconInfo *icon_info = NULL;
4032 for (i = 0; i < MAX_ICONS; i++)
4034 icon_info = priv->icons[i];
4036 if (!icon_info || icon_info->insensitive)
4039 if (event->window == icon_info->window)
4041 if (icon_info->pressed &&
4042 icon_info->target_list != NULL &&
4043 gtk_drag_check_threshold (widget,
4049 icon_info->in_drag = TRUE;
4050 icon_info->pressed = FALSE;
4051 gtk_drag_begin (widget,
4052 icon_info->target_list,
4062 if (priv->mouse_cursor_obscured)
4066 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4067 gdk_window_set_cursor (priv->text_area, cursor);
4068 g_object_unref (cursor);
4069 priv->mouse_cursor_obscured = FALSE;
4072 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4075 if (priv->select_lines)
4078 gdk_event_request_motions (event);
4082 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4083 gtk_drag_check_threshold (widget,
4084 priv->drag_start_x, priv->drag_start_y,
4085 event->x + priv->scroll_offset, event->y))
4087 GdkDragContext *context;
4088 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4089 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4091 cairo_surface_t *surface;
4093 gtk_target_list_add_text_targets (target_list, 0);
4095 text = _gtk_entry_get_selected_text (entry);
4096 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4098 context = gtk_drag_begin (widget, target_list, actions,
4099 priv->button, (GdkEvent *)event);
4102 gtk_drag_set_icon_surface (context, surface);
4104 gtk_drag_set_icon_default (context);
4107 cairo_surface_destroy (surface);
4110 priv->in_drag = FALSE;
4113 gtk_target_list_unref (target_list);
4120 else if (event->y >= gdk_window_get_height (priv->text_area))
4121 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4123 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4125 if (priv->select_words)
4128 gint old_min, old_max;
4131 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4132 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4134 pos = priv->current_pos;
4135 bound = priv->selection_bound;
4137 old_min = MIN(priv->current_pos, priv->selection_bound);
4138 old_max = MAX(priv->current_pos, priv->selection_bound);
4145 else if (old_max < max)
4150 else if (pos == old_min)
4152 if (priv->current_pos != min)
4157 if (priv->current_pos != max)
4161 gtk_entry_set_positions (entry, pos, bound);
4164 gtk_entry_set_positions (entry, tmp_pos, -1);
4171 set_invisible_cursor (GdkWindow *window)
4173 GdkDisplay *display;
4176 display = gdk_window_get_display (window);
4177 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4179 gdk_window_set_cursor (window, cursor);
4181 g_object_unref (cursor);
4185 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4187 GtkEntryPrivate *priv = entry->priv;
4189 if (priv->mouse_cursor_obscured)
4192 set_invisible_cursor (priv->text_area);
4194 priv->mouse_cursor_obscured = TRUE;
4198 gtk_entry_key_press (GtkWidget *widget,
4201 GtkEntry *entry = GTK_ENTRY (widget);
4202 GtkEntryPrivate *priv = entry->priv;
4204 gtk_entry_reset_blink_time (entry);
4205 gtk_entry_pend_cursor_blink (entry);
4209 if (gtk_im_context_filter_keypress (priv->im_context, event))
4211 gtk_entry_obscure_mouse_cursor (entry);
4212 priv->need_im_reset = TRUE;
4217 if (event->keyval == GDK_KEY_Return ||
4218 event->keyval == GDK_KEY_KP_Enter ||
4219 event->keyval == GDK_KEY_ISO_Enter ||
4220 event->keyval == GDK_KEY_Escape)
4222 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4224 if (completion && completion->priv->completion_timeout)
4226 g_source_remove (completion->priv->completion_timeout);
4227 completion->priv->completion_timeout = 0;
4230 _gtk_entry_reset_im_context (entry);
4233 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4234 /* Activate key bindings
4238 if (!priv->editable && event->length)
4239 gtk_widget_error_bell (widget);
4245 gtk_entry_key_release (GtkWidget *widget,
4248 GtkEntry *entry = GTK_ENTRY (widget);
4249 GtkEntryPrivate *priv = entry->priv;
4253 if (gtk_im_context_filter_keypress (priv->im_context, event))
4255 priv->need_im_reset = TRUE;
4260 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4264 gtk_entry_focus_in (GtkWidget *widget,
4265 GdkEventFocus *event)
4267 GtkEntry *entry = GTK_ENTRY (widget);
4268 GtkEntryPrivate *priv = entry->priv;
4271 gtk_widget_queue_draw (widget);
4273 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4277 priv->need_im_reset = TRUE;
4278 gtk_im_context_focus_in (priv->im_context);
4279 keymap_state_changed (keymap, entry);
4280 g_signal_connect (keymap, "state-changed",
4281 G_CALLBACK (keymap_state_changed), entry);
4284 g_signal_connect (keymap, "direction-changed",
4285 G_CALLBACK (keymap_direction_changed), entry);
4287 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4288 priv->placeholder_text != NULL)
4290 gtk_entry_recompute (entry);
4294 gtk_entry_reset_blink_time (entry);
4295 gtk_entry_check_cursor_blink (entry);
4302 gtk_entry_focus_out (GtkWidget *widget,
4303 GdkEventFocus *event)
4305 GtkEntry *entry = GTK_ENTRY (widget);
4306 GtkEntryPrivate *priv = entry->priv;
4307 GtkEntryCompletion *completion;
4310 gtk_widget_queue_draw (widget);
4312 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4316 priv->need_im_reset = TRUE;
4317 gtk_im_context_focus_out (priv->im_context);
4318 remove_capslock_feedback (entry);
4321 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4322 priv->placeholder_text != NULL)
4324 gtk_entry_recompute (entry);
4328 gtk_entry_check_cursor_blink (entry);
4331 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4332 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4334 completion = gtk_entry_get_completion (entry);
4336 _gtk_entry_completion_popdown (completion);
4342 gtk_entry_grab_focus (GtkWidget *widget)
4344 GtkEntry *entry = GTK_ENTRY (widget);
4345 GtkEntryPrivate *priv = entry->priv;
4346 gboolean select_on_focus;
4348 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4350 if (priv->editable && !priv->in_click)
4352 g_object_get (gtk_widget_get_settings (widget),
4353 "gtk-entry-select-on-focus",
4357 if (select_on_focus)
4358 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4363 gtk_entry_direction_changed (GtkWidget *widget,
4364 GtkTextDirection previous_dir)
4366 GtkEntry *entry = GTK_ENTRY (widget);
4368 gtk_entry_recompute (entry);
4370 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4374 gtk_entry_state_flags_changed (GtkWidget *widget,
4375 GtkStateFlags previous_state)
4377 GtkEntry *entry = GTK_ENTRY (widget);
4378 GtkEntryPrivate *priv = entry->priv;
4381 if (gtk_widget_get_realized (widget))
4383 if (gtk_widget_is_sensitive (widget))
4384 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4388 gdk_window_set_cursor (priv->text_area, cursor);
4391 g_object_unref (cursor);
4393 priv->mouse_cursor_obscured = FALSE;
4395 update_cursors (widget);
4398 if (!gtk_widget_is_sensitive (widget))
4400 /* Clear any selection */
4401 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4404 gtk_entry_update_cached_style_values (entry);
4408 gtk_entry_screen_changed (GtkWidget *widget,
4409 GdkScreen *old_screen)
4411 gtk_entry_recompute (GTK_ENTRY (widget));
4414 /* GtkEditable method implementations
4417 gtk_entry_insert_text (GtkEditable *editable,
4418 const gchar *new_text,
4419 gint new_text_length,
4422 g_object_ref (editable);
4425 * The incoming text may a password or other secret. We make sure
4426 * not to copy it into temporary buffers.
4429 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4431 g_object_unref (editable);
4435 gtk_entry_delete_text (GtkEditable *editable,
4439 g_object_ref (editable);
4441 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4443 g_object_unref (editable);
4447 gtk_entry_get_chars (GtkEditable *editable,
4451 GtkEntry *entry = GTK_ENTRY (editable);
4454 gint start_index, end_index;
4456 text = gtk_entry_buffer_get_text (get_buffer (entry));
4457 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4460 end_pos = text_length;
4462 start_pos = MIN (text_length, start_pos);
4463 end_pos = MIN (text_length, end_pos);
4465 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4466 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4468 return g_strndup (text + start_index, end_index - start_index);
4472 gtk_entry_real_set_position (GtkEditable *editable,
4475 GtkEntry *entry = GTK_ENTRY (editable);
4476 GtkEntryPrivate *priv = entry->priv;
4480 length = gtk_entry_buffer_get_length (get_buffer (entry));
4481 if (position < 0 || position > length)
4484 if (position != priv->current_pos ||
4485 position != priv->selection_bound)
4487 _gtk_entry_reset_im_context (entry);
4488 gtk_entry_set_positions (entry, position, position);
4493 gtk_entry_get_position (GtkEditable *editable)
4495 GtkEntry *entry = GTK_ENTRY (editable);
4496 GtkEntryPrivate *priv = entry->priv;
4498 return priv->current_pos;
4502 gtk_entry_set_selection_bounds (GtkEditable *editable,
4506 GtkEntry *entry = GTK_ENTRY (editable);
4509 length = gtk_entry_buffer_get_length (get_buffer (entry));
4515 _gtk_entry_reset_im_context (entry);
4517 gtk_entry_set_positions (entry,
4519 MIN (start, length));
4521 gtk_entry_update_primary_selection (entry);
4525 gtk_entry_get_selection_bounds (GtkEditable *editable,
4529 GtkEntry *entry = GTK_ENTRY (editable);
4530 GtkEntryPrivate *priv = entry->priv;
4532 *start = priv->selection_bound;
4533 *end = priv->current_pos;
4535 return (priv->selection_bound != priv->current_pos);
4539 icon_theme_changed (GtkEntry *entry)
4541 GtkEntryPrivate *priv = entry->priv;
4544 for (i = 0; i < MAX_ICONS; i++)
4546 EntryIconInfo *icon_info = priv->icons[i];
4547 if (icon_info != NULL)
4548 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4551 gtk_widget_queue_draw (GTK_WIDGET (entry));
4555 gtk_entry_update_cached_style_values (GtkEntry *entry)
4557 GtkEntryPrivate *priv = entry->priv;
4559 gboolean interior_focus;
4561 gtk_widget_style_get (GTK_WIDGET (entry),
4562 "focus-line-width", &focus_width,
4563 "interior-focus", &interior_focus,
4565 priv->focus_width = focus_width;
4566 priv->interior_focus = interior_focus;
4568 if (!priv->invisible_char_set)
4570 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4572 if (priv->invisible_char != ch)
4574 priv->invisible_char = ch;
4575 g_object_notify (G_OBJECT (entry), "invisible-char");
4581 gtk_entry_style_updated (GtkWidget *widget)
4583 GtkEntry *entry = GTK_ENTRY (widget);
4585 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4587 gtk_entry_update_cached_style_values (entry);
4589 gtk_entry_recompute (entry);
4591 icon_theme_changed (entry);
4594 /* GtkCellEditable method implementations
4597 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4599 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4600 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4604 gtk_cell_editable_key_press_event (GtkEntry *entry,
4605 GdkEventKey *key_event,
4608 GtkEntryPrivate *priv = entry->priv;
4610 if (key_event->keyval == GDK_KEY_Escape)
4612 priv->editing_canceled = TRUE;
4613 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4614 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4619 /* override focus */
4620 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4622 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4623 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4632 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4635 GtkEntry *entry = GTK_ENTRY (cell_editable);
4636 GtkEntryPrivate *priv = entry->priv;
4638 priv->is_cell_renderer = TRUE;
4640 g_signal_connect (cell_editable, "activate",
4641 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4642 g_signal_connect (cell_editable, "key-press-event",
4643 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4647 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4649 if (password_hint->source_id)
4650 g_source_remove (password_hint->source_id);
4652 g_slice_free (GtkEntryPasswordHint, password_hint);
4657 gtk_entry_remove_password_hint (gpointer data)
4659 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4660 password_hint->position = -1;
4662 /* Force the string to be redrawn, but now without a visible character */
4663 gtk_entry_recompute (GTK_ENTRY (data));
4667 /* Default signal handlers
4670 gtk_entry_real_insert_text (GtkEditable *editable,
4671 const gchar *new_text,
4672 gint new_text_length,
4678 n_chars = g_utf8_strlen (new_text, new_text_length);
4681 * The actual insertion into the buffer. This will end up firing the
4682 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4683 * buffer_notify_text(), buffer_notify_length()
4685 begin_change (GTK_ENTRY (editable));
4687 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4689 end_change (GTK_ENTRY (editable));
4691 if (n_inserted != n_chars)
4692 gtk_widget_error_bell (GTK_WIDGET (editable));
4694 *position += n_inserted;
4698 gtk_entry_real_delete_text (GtkEditable *editable,
4703 * The actual deletion from the buffer. This will end up firing the
4704 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4705 * buffer_notify_text(), buffer_notify_length()
4708 begin_change (GTK_ENTRY (editable));
4710 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4712 end_change (GTK_ENTRY (editable));
4715 /* GtkEntryBuffer signal handlers
4718 buffer_inserted_text (GtkEntryBuffer *buffer,
4724 GtkEntryPrivate *priv = entry->priv;
4725 guint password_hint_timeout;
4727 gint selection_bound;
4729 current_pos = priv->current_pos;
4730 if (current_pos > position)
4731 current_pos += n_chars;
4733 selection_bound = priv->selection_bound;
4734 if (selection_bound > position)
4735 selection_bound += n_chars;
4737 gtk_entry_set_positions (entry, current_pos, selection_bound);
4739 /* Calculate the password hint if it needs to be displayed. */
4740 if (n_chars == 1 && !priv->visible)
4742 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4743 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4746 if (password_hint_timeout > 0)
4748 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4749 quark_password_hint);
4752 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4753 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4754 (GDestroyNotify)gtk_entry_password_hint_free);
4757 password_hint->position = position;
4758 if (password_hint->source_id)
4759 g_source_remove (password_hint->source_id);
4760 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4761 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4767 buffer_deleted_text (GtkEntryBuffer *buffer,
4772 GtkEntryPrivate *priv = entry->priv;
4773 guint end_pos = position + n_chars;
4774 gint selection_bound;
4777 current_pos = priv->current_pos;
4778 if (current_pos > position)
4779 current_pos -= MIN (current_pos, end_pos) - position;
4781 selection_bound = priv->selection_bound;
4782 if (selection_bound > position)
4783 selection_bound -= MIN (selection_bound, end_pos) - position;
4785 gtk_entry_set_positions (entry, current_pos, selection_bound);
4787 /* We might have deleted the selection */
4788 gtk_entry_update_primary_selection (entry);
4790 /* Disable the password hint if one exists. */
4793 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4794 quark_password_hint);
4797 if (password_hint->source_id)
4798 g_source_remove (password_hint->source_id);
4799 password_hint->source_id = 0;
4800 password_hint->position = -1;
4806 buffer_notify_text (GtkEntryBuffer *buffer,
4810 gtk_entry_recompute (entry);
4811 emit_changed (entry);
4812 g_object_notify (G_OBJECT (entry), "text");
4816 buffer_notify_length (GtkEntryBuffer *buffer,
4820 g_object_notify (G_OBJECT (entry), "text-length");
4824 buffer_notify_max_length (GtkEntryBuffer *buffer,
4828 g_object_notify (G_OBJECT (entry), "max-length");
4832 buffer_connect_signals (GtkEntry *entry)
4834 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4835 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4836 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4837 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4838 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4842 buffer_disconnect_signals (GtkEntry *entry)
4844 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4845 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4846 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4847 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4848 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4851 /* Compute the X position for an offset that corresponds to the "more important
4852 * cursor position for that offset. We use this when trying to guess to which
4853 * end of the selection we should go to when the user hits the left or
4857 get_better_cursor_x (GtkEntry *entry,
4860 GtkEntryPrivate *priv = entry->priv;
4861 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4862 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4863 gboolean split_cursor;
4865 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4866 const gchar *text = pango_layout_get_text (layout);
4867 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4869 PangoRectangle strong_pos, weak_pos;
4871 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4872 "gtk-split-cursor", &split_cursor,
4875 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4878 return strong_pos.x / PANGO_SCALE;
4880 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4884 gtk_entry_move_cursor (GtkEntry *entry,
4885 GtkMovementStep step,
4887 gboolean extend_selection)
4889 GtkEntryPrivate *priv = entry->priv;
4890 gint new_pos = priv->current_pos;
4892 _gtk_entry_reset_im_context (entry);
4894 if (priv->current_pos != priv->selection_bound && !extend_selection)
4896 /* If we have a current selection and aren't extending it, move to the
4897 * start/or end of the selection as appropriate
4901 case GTK_MOVEMENT_VISUAL_POSITIONS:
4903 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4904 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4907 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4909 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4912 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4913 case GTK_MOVEMENT_WORDS:
4915 new_pos = MIN (priv->current_pos, priv->selection_bound);
4917 new_pos = MAX (priv->current_pos, priv->selection_bound);
4919 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4920 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4921 case GTK_MOVEMENT_BUFFER_ENDS:
4922 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4924 case GTK_MOVEMENT_DISPLAY_LINES:
4925 case GTK_MOVEMENT_PARAGRAPHS:
4926 case GTK_MOVEMENT_PAGES:
4927 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4935 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4936 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4938 case GTK_MOVEMENT_VISUAL_POSITIONS:
4939 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4940 if (priv->current_pos == new_pos)
4942 if (!extend_selection)
4944 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4946 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4948 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4951 gtk_widget_child_focus (toplevel,
4953 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4958 gtk_widget_error_bell (GTK_WIDGET (entry));
4962 case GTK_MOVEMENT_WORDS:
4965 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4970 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4973 if (priv->current_pos == new_pos)
4974 gtk_widget_error_bell (GTK_WIDGET (entry));
4976 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4977 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4978 case GTK_MOVEMENT_BUFFER_ENDS:
4979 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4980 if (priv->current_pos == new_pos)
4981 gtk_widget_error_bell (GTK_WIDGET (entry));
4983 case GTK_MOVEMENT_DISPLAY_LINES:
4984 case GTK_MOVEMENT_PARAGRAPHS:
4985 case GTK_MOVEMENT_PAGES:
4986 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4991 if (extend_selection)
4992 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4994 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4996 gtk_entry_pend_cursor_blink (entry);
5000 gtk_entry_insert_at_cursor (GtkEntry *entry,
5003 GtkEntryPrivate *priv = entry->priv;
5004 GtkEditable *editable = GTK_EDITABLE (entry);
5005 gint pos = priv->current_pos;
5009 _gtk_entry_reset_im_context (entry);
5011 gtk_editable_insert_text (editable, str, -1, &pos);
5012 gtk_editable_set_position (editable, pos);
5017 gtk_entry_delete_from_cursor (GtkEntry *entry,
5021 GtkEntryPrivate *priv = entry->priv;
5022 GtkEditable *editable = GTK_EDITABLE (entry);
5023 gint start_pos = priv->current_pos;
5024 gint end_pos = priv->current_pos;
5025 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5027 _gtk_entry_reset_im_context (entry);
5029 if (!priv->editable)
5031 gtk_widget_error_bell (GTK_WIDGET (entry));
5035 if (priv->selection_bound != priv->current_pos)
5037 gtk_editable_delete_selection (editable);
5043 case GTK_DELETE_CHARS:
5044 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5045 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5047 case GTK_DELETE_WORDS:
5050 /* Move to end of current word, or if not on a word, end of previous word */
5051 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5052 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5056 /* Move to beginning of current word, or if not on a word, begining of next word */
5057 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5058 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5062 case GTK_DELETE_WORD_ENDS:
5065 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5070 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5073 gtk_editable_delete_text (editable, start_pos, end_pos);
5075 case GTK_DELETE_DISPLAY_LINE_ENDS:
5076 case GTK_DELETE_PARAGRAPH_ENDS:
5078 gtk_editable_delete_text (editable, 0, priv->current_pos);
5080 gtk_editable_delete_text (editable, priv->current_pos, -1);
5082 case GTK_DELETE_DISPLAY_LINES:
5083 case GTK_DELETE_PARAGRAPHS:
5084 gtk_editable_delete_text (editable, 0, -1);
5086 case GTK_DELETE_WHITESPACE:
5087 gtk_entry_delete_whitespace (entry);
5091 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5092 gtk_widget_error_bell (GTK_WIDGET (entry));
5094 gtk_entry_pend_cursor_blink (entry);
5098 gtk_entry_backspace (GtkEntry *entry)
5100 GtkEntryPrivate *priv = entry->priv;
5101 GtkEditable *editable = GTK_EDITABLE (entry);
5104 _gtk_entry_reset_im_context (entry);
5106 if (!priv->editable)
5108 gtk_widget_error_bell (GTK_WIDGET (entry));
5112 if (priv->selection_bound != priv->current_pos)
5114 gtk_editable_delete_selection (editable);
5118 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5120 if (prev_pos < priv->current_pos)
5122 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5123 PangoLogAttr *log_attrs;
5126 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5128 /* Deleting parts of characters */
5129 if (log_attrs[priv->current_pos].backspace_deletes_character)
5131 gchar *cluster_text;
5132 gchar *normalized_text;
5135 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5137 normalized_text = g_utf8_normalize (cluster_text,
5138 strlen (cluster_text),
5140 len = g_utf8_strlen (normalized_text, -1);
5142 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5145 gint pos = priv->current_pos;
5147 gtk_editable_insert_text (editable, normalized_text,
5148 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5150 gtk_editable_set_position (editable, pos);
5153 g_free (normalized_text);
5154 g_free (cluster_text);
5158 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5165 gtk_widget_error_bell (GTK_WIDGET (entry));
5168 gtk_entry_pend_cursor_blink (entry);
5172 gtk_entry_copy_clipboard (GtkEntry *entry)
5174 GtkEntryPrivate *priv = entry->priv;
5175 GtkEditable *editable = GTK_EDITABLE (entry);
5179 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5183 gtk_widget_error_bell (GTK_WIDGET (entry));
5187 str = gtk_entry_get_display_text (entry, start, end);
5188 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5189 GDK_SELECTION_CLIPBOARD),
5196 gtk_entry_cut_clipboard (GtkEntry *entry)
5198 GtkEntryPrivate *priv = entry->priv;
5199 GtkEditable *editable = GTK_EDITABLE (entry);
5204 gtk_widget_error_bell (GTK_WIDGET (entry));
5208 gtk_entry_copy_clipboard (entry);
5212 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5213 gtk_editable_delete_text (editable, start, end);
5217 gtk_widget_error_bell (GTK_WIDGET (entry));
5222 gtk_entry_paste_clipboard (GtkEntry *entry)
5224 GtkEntryPrivate *priv = entry->priv;
5227 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5229 gtk_widget_error_bell (GTK_WIDGET (entry));
5233 gtk_entry_delete_cb (GtkEntry *entry)
5235 GtkEntryPrivate *priv = entry->priv;
5236 GtkEditable *editable = GTK_EDITABLE (entry);
5241 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5242 gtk_editable_delete_text (editable, start, end);
5247 gtk_entry_toggle_overwrite (GtkEntry *entry)
5249 GtkEntryPrivate *priv = entry->priv;
5251 priv->overwrite_mode = !priv->overwrite_mode;
5252 gtk_entry_pend_cursor_blink (entry);
5253 gtk_widget_queue_draw (GTK_WIDGET (entry));
5257 gtk_entry_select_all (GtkEntry *entry)
5259 gtk_entry_select_line (entry);
5263 gtk_entry_real_activate (GtkEntry *entry)
5265 GtkEntryPrivate *priv = entry->priv;
5267 GtkWidget *default_widget, *focus_widget;
5268 GtkWidget *toplevel;
5271 widget = GTK_WIDGET (entry);
5273 if (priv->activates_default)
5275 toplevel = gtk_widget_get_toplevel (widget);
5276 if (GTK_IS_WINDOW (toplevel))
5278 window = GTK_WINDOW (toplevel);
5282 default_widget = gtk_window_get_default_widget (window);
5283 focus_widget = gtk_window_get_focus (window);
5284 if (widget != default_widget &&
5285 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5286 gtk_window_activate_default (window);
5293 keymap_direction_changed (GdkKeymap *keymap,
5296 gtk_entry_recompute (entry);
5299 /* IM Context Callbacks
5303 gtk_entry_commit_cb (GtkIMContext *context,
5307 GtkEntryPrivate *priv = entry->priv;
5310 gtk_entry_enter_text (entry, str);
5314 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5317 GtkEntryPrivate *priv = entry->priv;
5321 gchar *preedit_string;
5324 gtk_im_context_get_preedit_string (priv->im_context,
5325 &preedit_string, NULL,
5327 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5328 priv->preedit_length = strlen (preedit_string);
5329 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5330 priv->preedit_cursor = cursor_pos;
5331 g_free (preedit_string);
5333 gtk_entry_recompute (entry);
5338 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5341 GtkEntryPrivate *priv = entry->priv;
5344 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5345 text = gtk_entry_get_display_text (entry, 0, -1);
5346 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5347 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5354 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5359 GtkEntryPrivate *priv = entry->priv;
5362 gtk_editable_delete_text (GTK_EDITABLE (entry),
5363 priv->current_pos + offset,
5364 priv->current_pos + offset + n_chars);
5369 /* Internal functions
5372 /* Used for im_commit_cb and inserting Unicode chars */
5374 gtk_entry_enter_text (GtkEntry *entry,
5377 GtkEntryPrivate *priv = entry->priv;
5378 GtkEditable *editable = GTK_EDITABLE (entry);
5380 gboolean old_need_im_reset;
5382 old_need_im_reset = priv->need_im_reset;
5383 priv->need_im_reset = FALSE;
5385 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5386 gtk_editable_delete_selection (editable);
5389 if (priv->overwrite_mode)
5390 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5393 tmp_pos = priv->current_pos;
5394 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5395 gtk_editable_set_position (editable, tmp_pos);
5397 priv->need_im_reset = old_need_im_reset;
5400 /* All changes to priv->current_pos and priv->selection_bound
5401 * should go through this function.
5404 gtk_entry_set_positions (GtkEntry *entry,
5406 gint selection_bound)
5408 GtkEntryPrivate *priv = entry->priv;
5409 gboolean changed = FALSE;
5411 g_object_freeze_notify (G_OBJECT (entry));
5413 if (current_pos != -1 &&
5414 priv->current_pos != current_pos)
5416 priv->current_pos = current_pos;
5419 g_object_notify (G_OBJECT (entry), "cursor-position");
5422 if (selection_bound != -1 &&
5423 priv->selection_bound != selection_bound)
5425 priv->selection_bound = selection_bound;
5428 g_object_notify (G_OBJECT (entry), "selection-bound");
5431 g_object_thaw_notify (G_OBJECT (entry));
5435 gtk_entry_move_adjustments (entry);
5436 gtk_entry_recompute (entry);
5441 gtk_entry_reset_layout (GtkEntry *entry)
5443 GtkEntryPrivate *priv = entry->priv;
5445 if (priv->cached_layout)
5447 g_object_unref (priv->cached_layout);
5448 priv->cached_layout = NULL;
5453 update_im_cursor_location (GtkEntry *entry)
5455 GtkEntryPrivate *priv = entry->priv;
5458 gint strong_xoffset;
5459 gint area_width, area_height;
5461 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5462 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5464 strong_xoffset = strong_x - priv->scroll_offset;
5465 if (strong_xoffset < 0)
5469 else if (strong_xoffset > area_width)
5471 strong_xoffset = area_width;
5473 area.x = strong_xoffset;
5476 area.height = area_height;
5478 gtk_im_context_set_cursor_location (priv->im_context, &area);
5482 recompute_idle_func (gpointer data)
5484 GtkEntry *entry = GTK_ENTRY (data);
5485 GtkEntryPrivate *priv = entry->priv;
5487 priv->recompute_idle = 0;
5489 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5491 gtk_entry_adjust_scroll (entry);
5492 gtk_widget_queue_draw (GTK_WIDGET (entry));
5494 update_im_cursor_location (entry);
5501 gtk_entry_recompute (GtkEntry *entry)
5503 GtkEntryPrivate *priv = entry->priv;
5505 gtk_entry_reset_layout (entry);
5506 gtk_entry_check_cursor_blink (entry);
5508 if (!priv->recompute_idle)
5510 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5511 recompute_idle_func, entry, NULL);
5516 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5519 GtkWidget *widget = GTK_WIDGET (entry);
5520 GtkStyleContext *context;
5521 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5523 context = gtk_widget_get_style_context (widget);
5524 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5526 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5527 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5528 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5531 static inline gboolean
5532 show_placeholder_text (GtkEntry *entry)
5534 GtkEntryPrivate *priv = entry->priv;
5536 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5537 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5538 priv->placeholder_text != NULL)
5544 static PangoLayout *
5545 gtk_entry_create_layout (GtkEntry *entry,
5546 gboolean include_preedit)
5548 GtkEntryPrivate *priv = entry->priv;
5549 GtkWidget *widget = GTK_WIDGET (entry);
5550 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5551 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5552 gboolean placeholder_layout = show_placeholder_text (entry);
5554 gchar *preedit_string = NULL;
5555 gint preedit_length = 0;
5556 PangoAttrList *preedit_attrs = NULL;
5561 pango_layout_set_single_paragraph_mode (layout, TRUE);
5563 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5564 n_bytes = strlen (display);
5566 if (!placeholder_layout && include_preedit)
5568 gtk_im_context_get_preedit_string (priv->im_context,
5569 &preedit_string, &preedit_attrs, NULL);
5570 preedit_length = priv->preedit_length;
5572 else if (placeholder_layout)
5575 PangoAttribute *attr;
5577 gtk_entry_get_placeholder_text_color (entry, &color);
5578 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5579 attr->start_index = 0;
5580 attr->end_index = G_MAXINT;
5581 pango_attr_list_insert (tmp_attrs, attr);
5586 GString *tmp_string = g_string_new (display);
5587 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5589 g_string_insert (tmp_string, cursor_index, preedit_string);
5591 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5593 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5594 cursor_index, preedit_length);
5596 g_string_free (tmp_string, TRUE);
5600 PangoDirection pango_dir;
5602 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5603 pango_dir = pango_find_base_dir (display, n_bytes);
5605 pango_dir = PANGO_DIRECTION_NEUTRAL;
5607 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5609 if (gtk_widget_has_focus (widget))
5611 GdkDisplay *display = gtk_widget_get_display (widget);
5612 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5613 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5614 pango_dir = PANGO_DIRECTION_RTL;
5616 pango_dir = PANGO_DIRECTION_LTR;
5620 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5621 pango_dir = PANGO_DIRECTION_RTL;
5623 pango_dir = PANGO_DIRECTION_LTR;
5627 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5630 priv->resolved_dir = pango_dir;
5632 pango_layout_set_text (layout, display, n_bytes);
5635 pango_layout_set_attributes (layout, tmp_attrs);
5637 g_free (preedit_string);
5641 pango_attr_list_unref (preedit_attrs);
5643 pango_attr_list_unref (tmp_attrs);
5648 static PangoLayout *
5649 gtk_entry_ensure_layout (GtkEntry *entry,
5650 gboolean include_preedit)
5652 GtkEntryPrivate *priv = entry->priv;
5654 if (priv->preedit_length > 0 &&
5655 !include_preedit != !priv->cache_includes_preedit)
5656 gtk_entry_reset_layout (entry);
5658 if (!priv->cached_layout)
5660 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5661 priv->cache_includes_preedit = include_preedit;
5664 return priv->cached_layout;
5668 get_layout_position (GtkEntry *entry,
5672 GtkEntryPrivate *priv = entry->priv;
5673 PangoLayout *layout;
5674 PangoRectangle logical_rect;
5675 gint area_width, area_height;
5677 PangoLayoutLine *line;
5679 layout = gtk_entry_ensure_layout (entry, TRUE);
5681 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5682 area_height = PANGO_SCALE * area_height;
5684 line = pango_layout_get_lines_readonly (layout)->data;
5685 pango_layout_line_get_extents (line, NULL, &logical_rect);
5687 /* Align primarily for locale's ascent/descent */
5688 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5689 priv->ascent + logical_rect.y);
5691 /* Now see if we need to adjust to fit in actual drawn string */
5692 if (logical_rect.height > area_height)
5693 y_pos = (area_height - logical_rect.height) / 2;
5696 else if (y_pos + logical_rect.height > area_height)
5697 y_pos = area_height - logical_rect.height;
5699 y_pos = y_pos / PANGO_SCALE;
5702 *x = - priv->scroll_offset;
5709 draw_text_with_color (GtkEntry *entry,
5711 GdkRGBA *default_color)
5713 GtkEntryPrivate *priv = entry->priv;
5714 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5717 gint start_pos, end_pos;
5719 widget = GTK_WIDGET (entry);
5723 get_layout_position (entry, &x, &y);
5725 cairo_move_to (cr, x, y);
5726 gdk_cairo_set_source_rgba (cr, default_color);
5727 pango_cairo_show_layout (cr, layout);
5729 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5733 PangoRectangle logical_rect;
5734 GdkRGBA selection_color, text_color;
5735 GtkStyleContext *context;
5736 GtkStateFlags state;
5738 context = gtk_widget_get_style_context (widget);
5739 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5740 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5742 state = gtk_widget_get_state_flags (widget);
5743 state |= GTK_STATE_FLAG_SELECTED;
5745 gtk_style_context_get_background_color (context, state, &selection_color);
5746 gtk_style_context_get_color (context, state, &text_color);
5748 for (i = 0; i < n_ranges; ++i)
5749 cairo_rectangle (cr,
5750 - priv->scroll_offset + ranges[2 * i],
5753 logical_rect.height);
5757 gdk_cairo_set_source_rgba (cr, &selection_color);
5760 cairo_move_to (cr, x, y);
5761 gdk_cairo_set_source_rgba (cr, &text_color);
5762 pango_cairo_show_layout (cr, layout);
5770 gtk_entry_draw_text (GtkEntry *entry,
5773 GtkEntryPrivate *priv = entry->priv;
5774 GtkWidget *widget = GTK_WIDGET (entry);
5775 GtkStateFlags state = 0;
5776 GdkRGBA text_color, bar_text_color;
5777 GtkStyleContext *context;
5779 gint progress_x, progress_y, progress_width, progress_height;
5780 gint clip_width, clip_height;
5782 /* Nothing to display at all */
5783 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5786 state = gtk_widget_get_state_flags (widget);
5787 context = gtk_widget_get_style_context (widget);
5789 gtk_style_context_get_color (context, state, &text_color);
5791 /* Get foreground color for progressbars */
5792 gtk_entry_prepare_context_for_progress (entry, context);
5793 gtk_style_context_get_color (context, state, &bar_text_color);
5794 gtk_style_context_restore (context);
5796 get_progress_area (widget,
5797 &progress_x, &progress_y,
5798 &progress_width, &progress_height);
5802 clip_width = gdk_window_get_width (priv->text_area);
5803 clip_height = gdk_window_get_height (priv->text_area);
5804 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5807 /* If the color is the same, or the progress area has a zero
5808 * size, then we only need to draw once. */
5809 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5810 ((progress_width == 0) || (progress_height == 0)))
5812 draw_text_with_color (entry, cr, &text_color);
5816 int frame_x, frame_y, area_x, area_y;
5818 width = gdk_window_get_width (priv->text_area);
5819 height = gdk_window_get_height (priv->text_area);
5823 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5824 cairo_rectangle (cr, 0, 0, width, height);
5826 /* progres area is frame-relative, we need it text-area window
5828 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5829 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5830 progress_x += frame_x - area_x;
5831 progress_y += frame_y - area_y;
5833 cairo_rectangle (cr, progress_x, progress_y,
5834 progress_width, progress_height);
5836 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5838 draw_text_with_color (entry, cr, &text_color);
5843 cairo_rectangle (cr, progress_x, progress_y,
5844 progress_width, progress_height);
5847 draw_text_with_color (entry, cr, &bar_text_color);
5856 gtk_entry_draw_cursor (GtkEntry *entry,
5860 GtkEntryPrivate *priv = entry->priv;
5861 GtkWidget *widget = GTK_WIDGET (entry);
5862 GtkStyleContext *context;
5863 PangoRectangle cursor_rect;
5866 gboolean block_at_line_end;
5867 PangoLayout *layout;
5870 context = gtk_widget_get_style_context (widget);
5872 layout = gtk_entry_ensure_layout (entry, TRUE);
5873 text = pango_layout_get_text (layout);
5874 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5876 if (!priv->overwrite_mode)
5879 block = _gtk_text_util_get_block_cursor_location (layout,
5880 cursor_index, &cursor_rect, &block_at_line_end);
5884 gtk_render_insertion_cursor (context, cr,
5885 - priv->scroll_offset, 0,
5886 layout, cursor_index, priv->resolved_dir);
5888 else /* overwrite_mode */
5890 GdkRGBA cursor_color;
5896 get_layout_position (entry, &x, &y);
5898 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5899 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5900 rect.width = PANGO_PIXELS (cursor_rect.width);
5901 rect.height = PANGO_PIXELS (cursor_rect.height);
5903 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5904 gdk_cairo_set_source_rgba (cr, &cursor_color);
5905 gdk_cairo_rectangle (cr, &rect);
5908 if (!block_at_line_end)
5910 GtkStateFlags state;
5913 state = gtk_widget_get_state_flags (widget);
5914 gtk_style_context_get_background_color (context, state, &color);
5916 gdk_cairo_rectangle (cr, &rect);
5918 cairo_move_to (cr, x, y);
5919 gdk_cairo_set_source_rgba (cr, &color);
5920 pango_cairo_show_layout (cr, layout);
5928 _gtk_entry_reset_im_context (GtkEntry *entry)
5930 GtkEntryPrivate *priv = entry->priv;
5932 if (priv->need_im_reset)
5934 priv->need_im_reset = FALSE;
5935 gtk_im_context_reset (priv->im_context);
5940 * gtk_entry_reset_im_context:
5941 * @entry: a #GtkEntry
5943 * Reset the input method context of the entry if needed.
5945 * This can be necessary in the case where modifying the buffer
5946 * would confuse on-going input method behavior.
5951 gtk_entry_reset_im_context (GtkEntry *entry)
5953 g_return_if_fail (GTK_IS_ENTRY (entry));
5955 _gtk_entry_reset_im_context (entry);
5959 * gtk_entry_im_context_filter_keypress:
5960 * @entry: a #GtkEntry
5961 * @event: (type Gdk.EventKey): the key event
5963 * Allow the #GtkEntry input method to internally handle key press
5964 * and release events. If this function returns %TRUE, then no further
5965 * processing should be done for this key event. See
5966 * gtk_im_context_filter_keypress().
5968 * Note that you are expected to call this function from your handler
5969 * when overriding key event handling. This is needed in the case when
5970 * you need to insert your own key handling between the input method
5971 * and the default key event handling of the #GtkEntry.
5972 * See gtk_text_view_reset_im_context() for an example of use.
5974 * Return value: %TRUE if the input method handled the key event.
5979 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5982 GtkEntryPrivate *priv;
5984 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5988 return gtk_im_context_filter_keypress (priv->im_context, event);
5992 _gtk_entry_get_im_context (GtkEntry *entry)
5994 return entry->priv->im_context;
5998 gtk_entry_find_position (GtkEntry *entry,
6001 GtkEntryPrivate *priv = entry->priv;
6002 PangoLayout *layout;
6003 PangoLayoutLine *line;
6010 layout = gtk_entry_ensure_layout (entry, TRUE);
6011 text = pango_layout_get_text (layout);
6012 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6014 line = pango_layout_get_lines_readonly (layout)->data;
6015 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6017 if (index >= cursor_index && priv->preedit_length)
6019 if (index >= cursor_index + priv->preedit_length)
6020 index -= priv->preedit_length;
6023 index = cursor_index;
6028 pos = g_utf8_pointer_to_offset (text, text + index);
6035 gtk_entry_get_cursor_locations (GtkEntry *entry,
6040 GtkEntryPrivate *priv = entry->priv;
6041 DisplayMode mode = gtk_entry_get_display_mode (entry);
6043 /* Nothing to display at all, so no cursor is relevant */
6044 if (mode == DISPLAY_BLANK)
6054 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6055 const gchar *text = pango_layout_get_text (layout);
6056 PangoRectangle strong_pos, weak_pos;
6059 if (type == CURSOR_STANDARD)
6061 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6063 else /* type == CURSOR_DND */
6065 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6067 if (priv->dnd_position > priv->current_pos)
6069 if (mode == DISPLAY_NORMAL)
6070 index += priv->preedit_length;
6073 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6074 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6079 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6082 *strong_x = strong_pos.x / PANGO_SCALE;
6085 *weak_x = weak_pos.x / PANGO_SCALE;
6090 gtk_entry_adjust_scroll (GtkEntry *entry)
6092 GtkEntryPrivate *priv = entry->priv;
6093 gint min_offset, max_offset;
6094 gint text_area_width, text_width;
6096 gint strong_x, weak_x;
6097 gint strong_xoffset, weak_xoffset;
6099 PangoLayout *layout;
6100 PangoLayoutLine *line;
6101 PangoRectangle logical_rect;
6103 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6106 text_area_width = gdk_window_get_width (priv->text_area);
6108 if (text_area_width < 0)
6109 text_area_width = 0;
6111 layout = gtk_entry_ensure_layout (entry, TRUE);
6112 line = pango_layout_get_lines_readonly (layout)->data;
6114 pango_layout_line_get_extents (line, NULL, &logical_rect);
6116 /* Display as much text as we can */
6118 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6119 xalign = priv->xalign;
6121 xalign = 1.0 - priv->xalign;
6123 text_width = PANGO_PIXELS(logical_rect.width);
6125 if (text_width > text_area_width)
6128 max_offset = text_width - text_area_width;
6132 min_offset = (text_width - text_area_width) * xalign;
6133 max_offset = min_offset;
6136 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6138 /* And make sure cursors are on screen. Note that the cursor is
6139 * actually drawn one pixel into the INNER_BORDER space on
6140 * the right, when the scroll is at the utmost right. This
6141 * looks better to to me than confining the cursor inside the
6142 * border entirely, though it means that the cursor gets one
6143 * pixel closer to the edge of the widget on the right than
6144 * on the left. This might need changing if one changed
6145 * INNER_BORDER from 2 to 1, as one would do on a
6146 * small-screen-real-estate display.
6148 * We always make sure that the strong cursor is on screen, and
6149 * put the weak cursor on screen if possible.
6152 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6154 strong_xoffset = strong_x - priv->scroll_offset;
6156 if (strong_xoffset < 0)
6158 priv->scroll_offset += strong_xoffset;
6161 else if (strong_xoffset > text_area_width)
6163 priv->scroll_offset += strong_xoffset - text_area_width;
6164 strong_xoffset = text_area_width;
6167 weak_xoffset = weak_x - priv->scroll_offset;
6169 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6171 priv->scroll_offset += weak_xoffset;
6173 else if (weak_xoffset > text_area_width &&
6174 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6176 priv->scroll_offset += weak_xoffset - text_area_width;
6179 g_object_notify (G_OBJECT (entry), "scroll-offset");
6183 gtk_entry_move_adjustments (GtkEntry *entry)
6185 GtkWidget *widget = GTK_WIDGET (entry);
6186 GtkAllocation allocation;
6187 GtkAdjustment *adjustment;
6188 PangoContext *context;
6189 PangoFontMetrics *metrics;
6190 GtkStyleContext *style_context;
6191 GtkStateFlags state;
6196 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6200 gtk_widget_get_allocation (widget, &allocation);
6202 /* Cursor position, layout offset, border width, and widget allocation */
6203 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6204 get_layout_position (entry, &layout_x, NULL);
6205 _gtk_entry_get_borders (entry, &borders);
6206 x += allocation.x + layout_x + borders.left;
6208 /* Approximate width of a char, so user can see what is ahead/behind */
6209 context = gtk_widget_get_pango_context (widget);
6210 style_context = gtk_widget_get_style_context (widget);
6211 state = gtk_widget_get_state_flags (widget);
6213 metrics = pango_context_get_metrics (context,
6214 gtk_style_context_get_font (style_context, state),
6215 pango_context_get_language (context));
6216 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6219 gtk_adjustment_clamp_page (adjustment,
6220 x - (char_width + 1), /* one char + one pixel before */
6221 x + (char_width + 2)); /* one char + cursor + one pixel after */
6225 gtk_entry_move_visually (GtkEntry *entry,
6229 GtkEntryPrivate *priv = entry->priv;
6231 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6234 text = pango_layout_get_text (layout);
6236 index = g_utf8_offset_to_pointer (text, start) - text;
6240 int new_index, new_trailing;
6241 gboolean split_cursor;
6244 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6245 "gtk-split-cursor", &split_cursor,
6252 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6253 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6255 strong = keymap_direction == priv->resolved_dir;
6260 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6265 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6271 else if (new_index != G_MAXINT)
6274 while (new_trailing--)
6275 index = g_utf8_next_char (text + index) - text;
6278 return g_utf8_pointer_to_offset (text, text + index);
6282 gtk_entry_move_logically (GtkEntry *entry,
6286 gint new_pos = start;
6289 length = gtk_entry_buffer_get_length (get_buffer (entry));
6291 /* Prevent any leak of information */
6292 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6294 new_pos = CLAMP (start + count, 0, length);
6298 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6299 PangoLogAttr *log_attrs;
6302 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6304 while (count > 0 && new_pos < length)
6308 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6312 while (count < 0 && new_pos > 0)
6316 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6328 gtk_entry_move_forward_word (GtkEntry *entry,
6330 gboolean allow_whitespace)
6332 gint new_pos = start;
6335 length = gtk_entry_buffer_get_length (get_buffer (entry));
6337 /* Prevent any leak of information */
6338 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6342 else if (new_pos < length)
6344 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6345 PangoLogAttr *log_attrs;
6348 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6350 /* Find the next word boundary */
6352 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6353 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6364 gtk_entry_move_backward_word (GtkEntry *entry,
6366 gboolean allow_whitespace)
6368 gint new_pos = start;
6370 /* Prevent any leak of information */
6371 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6377 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6378 PangoLogAttr *log_attrs;
6381 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6383 new_pos = start - 1;
6385 /* Find the previous word boundary */
6386 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6387 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6397 gtk_entry_delete_whitespace (GtkEntry *entry)
6399 GtkEntryPrivate *priv = entry->priv;
6400 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6401 PangoLogAttr *log_attrs;
6405 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6407 start = end = priv->current_pos;
6409 while (start > 0 && log_attrs[start-1].is_white)
6412 while (end < n_attrs && log_attrs[end].is_white)
6418 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6423 gtk_entry_select_word (GtkEntry *entry)
6425 GtkEntryPrivate *priv = entry->priv;
6426 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6427 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6429 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6433 gtk_entry_select_line (GtkEntry *entry)
6435 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6439 truncate_multiline (const gchar *text)
6444 text[length] && text[length] != '\n' && text[length] != '\r';
6451 paste_received (GtkClipboard *clipboard,
6455 GtkEntry *entry = GTK_ENTRY (data);
6456 GtkEditable *editable = GTK_EDITABLE (entry);
6457 GtkEntryPrivate *priv = entry->priv;
6459 if (priv->button == GDK_BUTTON_MIDDLE)
6461 gint pos, start, end;
6462 pos = priv->insert_pos;
6463 gtk_editable_get_selection_bounds (editable, &start, &end);
6464 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6465 gtk_editable_select_region (editable, pos, pos);
6470 gint pos, start, end;
6472 gboolean popup_completion;
6473 GtkEntryCompletion *completion;
6475 completion = gtk_entry_get_completion (entry);
6477 if (priv->truncate_multiline)
6478 length = truncate_multiline (text);
6480 /* only complete if the selection is at the end */
6481 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6482 MAX (priv->current_pos, priv->selection_bound));
6486 if (gtk_widget_get_mapped (completion->priv->popup_window))
6487 _gtk_entry_completion_popdown (completion);
6489 if (!popup_completion && completion->priv->changed_id > 0)
6490 g_signal_handler_block (entry, completion->priv->changed_id);
6493 begin_change (entry);
6494 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6495 gtk_editable_delete_text (editable, start, end);
6497 pos = priv->current_pos;
6498 gtk_editable_insert_text (editable, text, length, &pos);
6499 gtk_editable_set_position (editable, pos);
6503 !popup_completion && completion->priv->changed_id > 0)
6504 g_signal_handler_unblock (entry, completion->priv->changed_id);
6507 g_object_unref (entry);
6511 gtk_entry_paste (GtkEntry *entry,
6514 g_object_ref (entry);
6515 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6516 paste_received, entry);
6520 primary_get_cb (GtkClipboard *clipboard,
6521 GtkSelectionData *selection_data,
6525 GtkEntry *entry = GTK_ENTRY (data);
6528 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6530 gchar *str = gtk_entry_get_display_text (entry, start, end);
6531 gtk_selection_data_set_text (selection_data, str, -1);
6537 primary_clear_cb (GtkClipboard *clipboard,
6540 GtkEntry *entry = GTK_ENTRY (data);
6541 GtkEntryPrivate *priv = entry->priv;
6543 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6547 gtk_entry_update_primary_selection (GtkEntry *entry)
6549 GtkTargetList *list;
6550 GtkTargetEntry *targets;
6551 GtkClipboard *clipboard;
6555 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6558 list = gtk_target_list_new (NULL, 0);
6559 gtk_target_list_add_text_targets (list, 0);
6561 targets = gtk_target_table_new_from_list (list, &n_targets);
6563 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6565 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6567 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6568 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6569 primary_clear_cb (clipboard, entry);
6573 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6574 gtk_clipboard_clear (clipboard);
6577 gtk_target_table_free (targets, n_targets);
6578 gtk_target_list_unref (list);
6582 gtk_entry_clear (GtkEntry *entry,
6583 GtkEntryIconPosition icon_pos)
6585 GtkEntryPrivate *priv = entry->priv;
6586 EntryIconInfo *icon_info = priv->icons[icon_pos];
6587 GtkImageType storage_type;
6589 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6592 g_object_freeze_notify (G_OBJECT (entry));
6594 /* Explicitly check, as the pointer may become invalidated
6595 * during destruction.
6597 if (GDK_IS_WINDOW (icon_info->window))
6598 gdk_window_hide (icon_info->window);
6600 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6602 switch (storage_type)
6604 case GTK_IMAGE_PIXBUF:
6605 g_object_notify (G_OBJECT (entry),
6606 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6609 case GTK_IMAGE_STOCK:
6610 g_object_notify (G_OBJECT (entry),
6611 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6614 case GTK_IMAGE_ICON_NAME:
6615 g_object_notify (G_OBJECT (entry),
6616 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6619 case GTK_IMAGE_GICON:
6620 g_object_notify (G_OBJECT (entry),
6621 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6625 g_assert_not_reached ();
6629 _gtk_icon_helper_clear (icon_info->icon_helper);
6631 g_object_notify (G_OBJECT (entry),
6632 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6634 g_object_thaw_notify (G_OBJECT (entry));
6638 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6639 GtkEntryIconPosition icon_pos)
6641 GtkEntryPrivate *priv = entry->priv;
6642 EntryIconInfo *icon_info = priv->icons[icon_pos];
6643 GtkStyleContext *context;
6646 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6647 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6649 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6652 gtk_style_context_restore (context);
6663 * Creates a new entry.
6665 * Return value: a new #GtkEntry.
6668 gtk_entry_new (void)
6670 return g_object_new (GTK_TYPE_ENTRY, NULL);
6674 * gtk_entry_new_with_buffer:
6675 * @buffer: The buffer to use for the new #GtkEntry.
6677 * Creates a new entry with the specified text buffer.
6679 * Return value: a new #GtkEntry
6684 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6686 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6687 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6690 static GtkEntryBuffer*
6691 get_buffer (GtkEntry *entry)
6693 GtkEntryPrivate *priv = entry->priv;
6695 if (priv->buffer == NULL)
6697 GtkEntryBuffer *buffer;
6698 buffer = gtk_entry_buffer_new (NULL, 0);
6699 gtk_entry_set_buffer (entry, buffer);
6700 g_object_unref (buffer);
6703 return priv->buffer;
6707 * gtk_entry_get_buffer:
6708 * @entry: a #GtkEntry
6710 * Get the #GtkEntryBuffer object which holds the text for
6715 * Returns: (transfer none): A #GtkEntryBuffer object.
6718 gtk_entry_get_buffer (GtkEntry *entry)
6720 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6722 return get_buffer (entry);
6726 * gtk_entry_set_buffer:
6727 * @entry: a #GtkEntry
6728 * @buffer: a #GtkEntryBuffer
6730 * Set the #GtkEntryBuffer object which holds the text for
6736 gtk_entry_set_buffer (GtkEntry *entry,
6737 GtkEntryBuffer *buffer)
6739 GtkEntryPrivate *priv;
6742 g_return_if_fail (GTK_IS_ENTRY (entry));
6748 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6749 g_object_ref (buffer);
6754 buffer_disconnect_signals (entry);
6755 g_object_unref (priv->buffer);
6758 priv->buffer = buffer;
6761 buffer_connect_signals (entry);
6763 obj = G_OBJECT (entry);
6764 g_object_freeze_notify (obj);
6765 g_object_notify (obj, "buffer");
6766 g_object_notify (obj, "text");
6767 g_object_notify (obj, "text-length");
6768 g_object_notify (obj, "max-length");
6769 g_object_notify (obj, "visibility");
6770 g_object_notify (obj, "invisible-char");
6771 g_object_notify (obj, "invisible-char-set");
6772 g_object_thaw_notify (obj);
6774 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6775 gtk_entry_recompute (entry);
6779 * gtk_entry_get_text_area:
6780 * @entry: a #GtkEntry
6781 * @text_area: (out): Return location for the text area.
6783 * Gets the area where the entry's text is drawn. This function is
6784 * useful when drawing something to the entry in a draw callback.
6786 * If the entry is not realized, @text_area is filled with zeros.
6788 * See also gtk_entry_get_icon_area().
6793 gtk_entry_get_text_area (GtkEntry *entry,
6794 GdkRectangle *text_area)
6796 GtkEntryPrivate *priv;
6798 g_return_if_fail (GTK_IS_ENTRY (entry));
6799 g_return_if_fail (text_area != NULL);
6803 if (priv->text_area)
6805 GtkAllocation allocation;
6808 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6809 gdk_window_get_position (priv->text_area, &x, &y);
6811 text_area->x = x - allocation.x;
6812 text_area->y = y - allocation.y;
6813 text_area->width = gdk_window_get_width (priv->text_area);
6814 text_area->height = gdk_window_get_height (priv->text_area);
6820 text_area->width = 0;
6821 text_area->height = 0;
6826 * gtk_entry_set_text:
6827 * @entry: a #GtkEntry
6828 * @text: the new text
6830 * Sets the text in the widget to the given
6831 * value, replacing the current contents.
6833 * See gtk_entry_buffer_set_text().
6836 gtk_entry_set_text (GtkEntry *entry,
6840 GtkEntryCompletion *completion;
6842 g_return_if_fail (GTK_IS_ENTRY (entry));
6843 g_return_if_fail (text != NULL);
6845 /* Actually setting the text will affect the cursor and selection;
6846 * if the contents don't actually change, this will look odd to the user.
6848 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6851 completion = gtk_entry_get_completion (entry);
6852 if (completion && completion->priv->changed_id > 0)
6853 g_signal_handler_block (entry, completion->priv->changed_id);
6855 begin_change (entry);
6856 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6858 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6861 if (completion && completion->priv->changed_id > 0)
6862 g_signal_handler_unblock (entry, completion->priv->changed_id);
6866 * gtk_entry_set_visibility:
6867 * @entry: a #GtkEntry
6868 * @visible: %TRUE if the contents of the entry are displayed
6871 * Sets whether the contents of the entry are visible or not.
6872 * When visibility is set to %FALSE, characters are displayed
6873 * as the invisible char, and will also appear that way when
6874 * the text in the entry widget is copied elsewhere.
6876 * By default, GTK+ picks the best invisible character available
6877 * in the current font, but it can be changed with
6878 * gtk_entry_set_invisible_char().
6881 gtk_entry_set_visibility (GtkEntry *entry,
6884 GtkEntryPrivate *priv;
6886 g_return_if_fail (GTK_IS_ENTRY (entry));
6890 visible = visible != FALSE;
6892 if (priv->visible != visible)
6894 priv->visible = visible;
6896 g_object_notify (G_OBJECT (entry), "visibility");
6897 gtk_entry_recompute (entry);
6902 * gtk_entry_get_visibility:
6903 * @entry: a #GtkEntry
6905 * Retrieves whether the text in @entry is visible. See
6906 * gtk_entry_set_visibility().
6908 * Return value: %TRUE if the text is currently visible
6911 gtk_entry_get_visibility (GtkEntry *entry)
6913 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6915 return entry->priv->visible;
6919 * gtk_entry_set_invisible_char:
6920 * @entry: a #GtkEntry
6921 * @ch: a Unicode character
6923 * Sets the character to use in place of the actual text when
6924 * gtk_entry_set_visibility() has been called to set text visibility
6925 * to %FALSE. i.e. this is the character used in "password mode" to
6926 * show the user how many characters have been typed. By default, GTK+
6927 * picks the best invisible char available in the current font. If you
6928 * set the invisible char to 0, then the user will get no feedback
6929 * at all; there will be no text on the screen as they type.
6932 gtk_entry_set_invisible_char (GtkEntry *entry,
6935 GtkEntryPrivate *priv;
6937 g_return_if_fail (GTK_IS_ENTRY (entry));
6941 if (!priv->invisible_char_set)
6943 priv->invisible_char_set = TRUE;
6944 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6947 if (ch == priv->invisible_char)
6950 priv->invisible_char = ch;
6951 g_object_notify (G_OBJECT (entry), "invisible-char");
6952 gtk_entry_recompute (entry);
6956 * gtk_entry_get_invisible_char:
6957 * @entry: a #GtkEntry
6959 * Retrieves the character displayed in place of the real characters
6960 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6962 * Return value: the current invisible char, or 0, if the entry does not
6963 * show invisible text at all.
6966 gtk_entry_get_invisible_char (GtkEntry *entry)
6968 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6970 return entry->priv->invisible_char;
6974 * gtk_entry_unset_invisible_char:
6975 * @entry: a #GtkEntry
6977 * Unsets the invisible char previously set with
6978 * gtk_entry_set_invisible_char(). So that the
6979 * default invisible char is used again.
6984 gtk_entry_unset_invisible_char (GtkEntry *entry)
6986 GtkEntryPrivate *priv;
6989 g_return_if_fail (GTK_IS_ENTRY (entry));
6993 if (!priv->invisible_char_set)
6996 priv->invisible_char_set = FALSE;
6997 ch = find_invisible_char (GTK_WIDGET (entry));
6999 if (priv->invisible_char != ch)
7001 priv->invisible_char = ch;
7002 g_object_notify (G_OBJECT (entry), "invisible-char");
7005 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7006 gtk_entry_recompute (entry);
7010 * gtk_entry_set_overwrite_mode:
7011 * @entry: a #GtkEntry
7012 * @overwrite: new value
7014 * Sets whether the text is overwritten when typing in the #GtkEntry.
7019 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7022 GtkEntryPrivate *priv = entry->priv;
7024 g_return_if_fail (GTK_IS_ENTRY (entry));
7026 if (priv->overwrite_mode == overwrite)
7029 gtk_entry_toggle_overwrite (entry);
7031 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7035 * gtk_entry_get_overwrite_mode:
7036 * @entry: a #GtkEntry
7038 * Gets the value set by gtk_entry_set_overwrite_mode().
7040 * Return value: whether the text is overwritten when typing.
7045 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7047 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7049 return entry->priv->overwrite_mode;
7053 * gtk_entry_get_text:
7054 * @entry: a #GtkEntry
7056 * Retrieves the contents of the entry widget.
7057 * See also gtk_editable_get_chars().
7059 * This is equivalent to:
7061 * <informalexample><programlisting>
7062 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7063 * </programlisting></informalexample>
7065 * Return value: a pointer to the contents of the widget as a
7066 * string. This string points to internally allocated
7067 * storage in the widget and must not be freed, modified or
7071 gtk_entry_get_text (GtkEntry *entry)
7073 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7075 return gtk_entry_buffer_get_text (get_buffer (entry));
7079 * gtk_entry_set_max_length:
7080 * @entry: a #GtkEntry
7081 * @max: the maximum length of the entry, or 0 for no maximum.
7082 * (other than the maximum length of entries.) The value passed in will
7083 * be clamped to the range 0-65536.
7085 * Sets the maximum allowed length of the contents of the widget. If
7086 * the current contents are longer than the given length, then they
7087 * will be truncated to fit.
7089 * This is equivalent to:
7091 * <informalexample><programlisting>
7092 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7093 * </programlisting></informalexample>
7096 gtk_entry_set_max_length (GtkEntry *entry,
7099 g_return_if_fail (GTK_IS_ENTRY (entry));
7100 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7104 * gtk_entry_get_max_length:
7105 * @entry: a #GtkEntry
7107 * Retrieves the maximum allowed length of the text in
7108 * @entry. See gtk_entry_set_max_length().
7110 * This is equivalent to:
7112 * <informalexample><programlisting>
7113 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7114 * </programlisting></informalexample>
7116 * Return value: the maximum allowed number of characters
7117 * in #GtkEntry, or 0 if there is no maximum.
7120 gtk_entry_get_max_length (GtkEntry *entry)
7122 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7124 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7128 * gtk_entry_get_text_length:
7129 * @entry: a #GtkEntry
7131 * Retrieves the current length of the text in
7134 * This is equivalent to:
7136 * <informalexample><programlisting>
7137 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7138 * </programlisting></informalexample>
7140 * Return value: the current number of characters
7141 * in #GtkEntry, or 0 if there are none.
7146 gtk_entry_get_text_length (GtkEntry *entry)
7148 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7150 return gtk_entry_buffer_get_length (get_buffer (entry));
7154 * gtk_entry_set_activates_default:
7155 * @entry: a #GtkEntry
7156 * @setting: %TRUE to activate window's default widget on Enter keypress
7158 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7159 * widget for the window containing the entry. This usually means that
7160 * the dialog box containing the entry will be closed, since the default
7161 * widget is usually one of the dialog buttons.
7163 * (For experts: if @setting is %TRUE, the entry calls
7164 * gtk_window_activate_default() on the window containing the entry, in
7165 * the default handler for the #GtkWidget::activate signal.)
7168 gtk_entry_set_activates_default (GtkEntry *entry,
7171 GtkEntryPrivate *priv;
7173 g_return_if_fail (GTK_IS_ENTRY (entry));
7177 setting = setting != FALSE;
7179 if (setting != priv->activates_default)
7181 priv->activates_default = setting;
7182 g_object_notify (G_OBJECT (entry), "activates-default");
7187 * gtk_entry_get_activates_default:
7188 * @entry: a #GtkEntry
7190 * Retrieves the value set by gtk_entry_set_activates_default().
7192 * Return value: %TRUE if the entry will activate the default widget
7195 gtk_entry_get_activates_default (GtkEntry *entry)
7197 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7199 return entry->priv->activates_default;
7203 * gtk_entry_set_width_chars:
7204 * @entry: a #GtkEntry
7205 * @n_chars: width in chars
7207 * Changes the size request of the entry to be about the right size
7208 * for @n_chars characters. Note that it changes the size
7209 * <emphasis>request</emphasis>, the size can still be affected by
7210 * how you pack the widget into containers. If @n_chars is -1, the
7211 * size reverts to the default entry size.
7214 gtk_entry_set_width_chars (GtkEntry *entry,
7217 GtkEntryPrivate *priv;
7219 g_return_if_fail (GTK_IS_ENTRY (entry));
7223 if (priv->width_chars != n_chars)
7225 priv->width_chars = n_chars;
7226 g_object_notify (G_OBJECT (entry), "width-chars");
7227 gtk_widget_queue_resize (GTK_WIDGET (entry));
7232 * gtk_entry_get_width_chars:
7233 * @entry: a #GtkEntry
7235 * Gets the value set by gtk_entry_set_width_chars().
7237 * Return value: number of chars to request space for, or negative if unset
7240 gtk_entry_get_width_chars (GtkEntry *entry)
7242 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7244 return entry->priv->width_chars;
7248 * gtk_entry_set_has_frame:
7249 * @entry: a #GtkEntry
7250 * @setting: new value
7252 * Sets whether the entry has a beveled frame around it.
7255 gtk_entry_set_has_frame (GtkEntry *entry,
7258 GtkEntryPrivate *priv;
7260 g_return_if_fail (GTK_IS_ENTRY (entry));
7264 setting = (setting != FALSE);
7266 if (priv->has_frame == setting)
7269 gtk_widget_queue_resize (GTK_WIDGET (entry));
7270 priv->has_frame = setting;
7271 g_object_notify (G_OBJECT (entry), "has-frame");
7275 * gtk_entry_get_has_frame:
7276 * @entry: a #GtkEntry
7278 * Gets the value set by gtk_entry_set_has_frame().
7280 * Return value: whether the entry has a beveled frame
7283 gtk_entry_get_has_frame (GtkEntry *entry)
7285 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7287 return entry->priv->has_frame;
7291 * gtk_entry_set_inner_border:
7292 * @entry: a #GtkEntry
7293 * @border: (allow-none): a #GtkBorder, or %NULL
7295 * Sets %entry's inner-border property to %border, or clears it if %NULL
7296 * is passed. The inner-border is the area around the entry's text, but
7299 * If set, this property overrides the inner-border style property.
7300 * Overriding the style-provided border is useful when you want to do
7301 * in-place editing of some text in a canvas or list widget, where
7302 * pixel-exact positioning of the entry is important.
7306 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7307 * the value set with this function is ignored by #GtkEntry.
7310 gtk_entry_set_inner_border (GtkEntry *entry,
7311 const GtkBorder *border)
7313 g_return_if_fail (GTK_IS_ENTRY (entry));
7315 gtk_entry_do_set_inner_border (entry, border);
7319 * gtk_entry_get_inner_border:
7320 * @entry: a #GtkEntry
7322 * This function returns the entry's #GtkEntry:inner-border property. See
7323 * gtk_entry_set_inner_border() for more information.
7325 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7329 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7330 * the value returned by this function is ignored by #GtkEntry.
7333 gtk_entry_get_inner_border (GtkEntry *entry)
7335 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7337 return gtk_entry_do_get_inner_border (entry);
7341 * gtk_entry_get_layout:
7342 * @entry: a #GtkEntry
7344 * Gets the #PangoLayout used to display the entry.
7345 * The layout is useful to e.g. convert text positions to
7346 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7347 * The returned layout is owned by the entry and must not be
7348 * modified or freed by the caller.
7350 * Keep in mind that the layout text may contain a preedit string, so
7351 * gtk_entry_layout_index_to_text_index() and
7352 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7353 * indices in the layout to byte indices in the entry contents.
7355 * Return value: (transfer none): the #PangoLayout for this entry
7358 gtk_entry_get_layout (GtkEntry *entry)
7360 PangoLayout *layout;
7362 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7364 layout = gtk_entry_ensure_layout (entry, TRUE);
7371 * gtk_entry_layout_index_to_text_index:
7372 * @entry: a #GtkEntry
7373 * @layout_index: byte index into the entry layout text
7375 * Converts from a position in the entry contents (returned
7376 * by gtk_entry_get_text()) to a position in the
7377 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7378 * with text retrieved via pango_layout_get_text()).
7380 * Return value: byte index into the entry contents
7383 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7386 GtkEntryPrivate *priv;
7387 PangoLayout *layout;
7391 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7395 layout = gtk_entry_ensure_layout (entry, TRUE);
7396 text = pango_layout_get_text (layout);
7397 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7399 if (layout_index >= cursor_index && priv->preedit_length)
7401 if (layout_index >= cursor_index + priv->preedit_length)
7402 layout_index -= priv->preedit_length;
7404 layout_index = cursor_index;
7407 return layout_index;
7411 * gtk_entry_text_index_to_layout_index:
7412 * @entry: a #GtkEntry
7413 * @text_index: byte index into the entry contents
7415 * Converts from a position in the entry's #PangoLayout (returned by
7416 * gtk_entry_get_layout()) to a position in the entry contents
7417 * (returned by gtk_entry_get_text()).
7419 * Return value: byte index into the entry layout text
7422 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7425 GtkEntryPrivate *priv;
7426 PangoLayout *layout;
7430 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7434 layout = gtk_entry_ensure_layout (entry, TRUE);
7435 text = pango_layout_get_text (layout);
7436 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7438 if (text_index > cursor_index)
7439 text_index += priv->preedit_length;
7445 * gtk_entry_get_layout_offsets:
7446 * @entry: a #GtkEntry
7447 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7448 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7451 * Obtains the position of the #PangoLayout used to render text
7452 * in the entry, in widget coordinates. Useful if you want to line
7453 * up the text in an entry with some other text, e.g. when using the
7454 * entry to implement editable cells in a sheet widget.
7456 * Also useful to convert mouse events into coordinates inside the
7457 * #PangoLayout, e.g. to take some action if some part of the entry text
7460 * Note that as the user scrolls around in the entry the offsets will
7461 * change; you'll need to connect to the "notify::scroll-offset"
7462 * signal to track this. Remember when using the #PangoLayout
7463 * functions you need to convert to and from pixels using
7464 * PANGO_PIXELS() or #PANGO_SCALE.
7466 * Keep in mind that the layout text may contain a preedit string, so
7467 * gtk_entry_layout_index_to_text_index() and
7468 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7469 * indices in the layout to byte indices in the entry contents.
7472 gtk_entry_get_layout_offsets (GtkEntry *entry,
7476 gint text_area_x, text_area_y;
7478 g_return_if_fail (GTK_IS_ENTRY (entry));
7480 /* this gets coords relative to text area */
7481 get_layout_position (entry, x, y);
7483 /* convert to widget coords */
7484 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7495 * gtk_entry_set_alignment:
7496 * @entry: a #GtkEntry
7497 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7498 * Reversed for RTL layouts
7500 * Sets the alignment for the contents of the entry. This controls
7501 * the horizontal positioning of the contents when the displayed
7502 * text is shorter than the width of the entry.
7507 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7509 GtkEntryPrivate *priv;
7511 g_return_if_fail (GTK_IS_ENTRY (entry));
7517 else if (xalign > 1.0)
7520 if (xalign != priv->xalign)
7522 priv->xalign = xalign;
7524 gtk_entry_recompute (entry);
7526 g_object_notify (G_OBJECT (entry), "xalign");
7531 * gtk_entry_get_alignment:
7532 * @entry: a #GtkEntry
7534 * Gets the value set by gtk_entry_set_alignment().
7536 * Return value: the alignment
7541 gtk_entry_get_alignment (GtkEntry *entry)
7543 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7545 return entry->priv->xalign;
7549 * gtk_entry_set_icon_from_pixbuf:
7550 * @entry: a #GtkEntry
7551 * @icon_pos: Icon position
7552 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7554 * Sets the icon shown in the specified position using a pixbuf.
7556 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7561 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7562 GtkEntryIconPosition icon_pos,
7565 GtkEntryPrivate *priv;
7566 EntryIconInfo *icon_info;
7568 g_return_if_fail (GTK_IS_ENTRY (entry));
7569 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7573 if ((icon_info = priv->icons[icon_pos]) == NULL)
7574 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7576 g_object_freeze_notify (G_OBJECT (entry));
7579 g_object_ref (pixbuf);
7581 gtk_entry_clear (entry, icon_pos);
7585 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7587 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7589 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7590 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7594 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7595 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7598 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7599 gdk_window_show_unraised (icon_info->window);
7601 g_object_unref (pixbuf);
7604 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7605 gtk_widget_queue_resize (GTK_WIDGET (entry));
7607 g_object_thaw_notify (G_OBJECT (entry));
7611 * gtk_entry_set_icon_from_stock:
7612 * @entry: A #GtkEntry
7613 * @icon_pos: Icon position
7614 * @stock_id: (allow-none): The name of the stock item, or %NULL
7616 * Sets the icon shown in the entry at the specified position from
7619 * If @stock_id is %NULL, no icon will be shown in the specified position.
7624 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7625 GtkEntryIconPosition icon_pos,
7626 const gchar *stock_id)
7628 GtkEntryPrivate *priv;
7629 EntryIconInfo *icon_info;
7632 g_return_if_fail (GTK_IS_ENTRY (entry));
7633 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7637 if ((icon_info = priv->icons[icon_pos]) == NULL)
7638 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7640 g_object_freeze_notify (G_OBJECT (entry));
7642 /* need to dup before clearing */
7643 new_id = g_strdup (stock_id);
7645 gtk_entry_clear (entry, icon_pos);
7649 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7651 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7653 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7654 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7658 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7659 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7662 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7663 gdk_window_show_unraised (icon_info->window);
7668 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7669 gtk_widget_queue_resize (GTK_WIDGET (entry));
7671 g_object_thaw_notify (G_OBJECT (entry));
7675 * gtk_entry_set_icon_from_icon_name:
7676 * @entry: A #GtkEntry
7677 * @icon_pos: The position at which to set the icon
7678 * @icon_name: (allow-none): An icon name, or %NULL
7680 * Sets the icon shown in the entry at the specified position
7681 * from the current icon theme.
7683 * If the icon name isn't known, a "broken image" icon will be displayed
7686 * If @icon_name is %NULL, no icon will be shown in the specified position.
7691 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7692 GtkEntryIconPosition icon_pos,
7693 const gchar *icon_name)
7695 GtkEntryPrivate *priv;
7696 EntryIconInfo *icon_info;
7699 g_return_if_fail (GTK_IS_ENTRY (entry));
7700 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7704 if ((icon_info = priv->icons[icon_pos]) == NULL)
7705 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7707 g_object_freeze_notify (G_OBJECT (entry));
7709 /* need to dup before clearing */
7710 new_name = g_strdup (icon_name);
7712 gtk_entry_clear (entry, icon_pos);
7714 if (new_name != NULL)
7716 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7718 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7720 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7721 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7725 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7726 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7729 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7730 gdk_window_show_unraised (icon_info->window);
7735 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7736 gtk_widget_queue_resize (GTK_WIDGET (entry));
7738 g_object_thaw_notify (G_OBJECT (entry));
7742 * gtk_entry_set_icon_from_gicon:
7743 * @entry: A #GtkEntry
7744 * @icon_pos: The position at which to set the icon
7745 * @icon: (allow-none): The icon to set, or %NULL
7747 * Sets the icon shown in the entry at the specified position
7748 * from the current icon theme.
7749 * If the icon isn't known, a "broken image" icon will be displayed
7752 * If @icon is %NULL, no icon will be shown in the specified position.
7757 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7758 GtkEntryIconPosition icon_pos,
7761 GtkEntryPrivate *priv;
7762 EntryIconInfo *icon_info;
7764 g_return_if_fail (GTK_IS_ENTRY (entry));
7765 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7769 if ((icon_info = priv->icons[icon_pos]) == NULL)
7770 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7772 g_object_freeze_notify (G_OBJECT (entry));
7774 /* need to ref before clearing */
7776 g_object_ref (icon);
7778 gtk_entry_clear (entry, icon_pos);
7782 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7784 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7786 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7787 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7791 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7792 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7795 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7796 gdk_window_show_unraised (icon_info->window);
7798 g_object_unref (icon);
7801 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7802 gtk_widget_queue_resize (GTK_WIDGET (entry));
7804 g_object_thaw_notify (G_OBJECT (entry));
7808 * gtk_entry_set_icon_activatable:
7809 * @entry: A #GtkEntry
7810 * @icon_pos: Icon position
7811 * @activatable: %TRUE if the icon should be activatable
7813 * Sets whether the icon is activatable.
7818 gtk_entry_set_icon_activatable (GtkEntry *entry,
7819 GtkEntryIconPosition icon_pos,
7820 gboolean activatable)
7822 GtkEntryPrivate *priv;
7823 EntryIconInfo *icon_info;
7825 g_return_if_fail (GTK_IS_ENTRY (entry));
7826 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7830 if ((icon_info = priv->icons[icon_pos]) == NULL)
7831 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7833 activatable = activatable != FALSE;
7835 if (icon_info->nonactivatable != !activatable)
7837 icon_info->nonactivatable = !activatable;
7839 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7840 update_cursors (GTK_WIDGET (entry));
7842 g_object_notify (G_OBJECT (entry),
7843 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7848 * gtk_entry_get_icon_activatable:
7849 * @entry: a #GtkEntry
7850 * @icon_pos: Icon position
7852 * Returns whether the icon is activatable.
7854 * Returns: %TRUE if the icon is activatable.
7859 gtk_entry_get_icon_activatable (GtkEntry *entry,
7860 GtkEntryIconPosition icon_pos)
7862 GtkEntryPrivate *priv;
7863 EntryIconInfo *icon_info;
7865 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7866 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7869 icon_info = priv->icons[icon_pos];
7871 return (!icon_info || !icon_info->nonactivatable);
7875 * gtk_entry_get_icon_pixbuf:
7876 * @entry: A #GtkEntry
7877 * @icon_pos: Icon position
7879 * Retrieves the image used for the icon.
7881 * Unlike the other methods of setting and getting icon data, this
7882 * method will work regardless of whether the icon was set using a
7883 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7885 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7886 * set for this position.
7891 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7892 GtkEntryIconPosition icon_pos)
7894 GtkEntryPrivate *priv;
7895 EntryIconInfo *icon_info;
7898 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7899 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7903 icon_info = priv->icons[icon_pos];
7908 /* HACK: unfortunately this is transfer none, so we need to return
7909 * the icon helper's cache ref directly.
7911 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7912 g_object_unref (pixbuf);
7918 * gtk_entry_get_icon_gicon:
7919 * @entry: A #GtkEntry
7920 * @icon_pos: Icon position
7922 * Retrieves the #GIcon used for the icon, or %NULL if there is
7923 * no icon or if the icon was set by some other method (e.g., by
7924 * stock, pixbuf, or icon name).
7926 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7927 * or if the icon is not a #GIcon
7932 gtk_entry_get_icon_gicon (GtkEntry *entry,
7933 GtkEntryIconPosition icon_pos)
7935 GtkEntryPrivate *priv;
7936 EntryIconInfo *icon_info;
7938 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7939 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7942 icon_info = priv->icons[icon_pos];
7947 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7951 * gtk_entry_get_icon_stock:
7952 * @entry: A #GtkEntry
7953 * @icon_pos: Icon position
7955 * Retrieves the stock id used for the icon, or %NULL if there is
7956 * no icon or if the icon was set by some other method (e.g., by
7957 * pixbuf, icon name or gicon).
7959 * Returns: A stock id, or %NULL if no icon is set or if the icon
7960 * wasn't set from a stock id
7965 gtk_entry_get_icon_stock (GtkEntry *entry,
7966 GtkEntryIconPosition icon_pos)
7968 GtkEntryPrivate *priv;
7969 EntryIconInfo *icon_info;
7971 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7972 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7975 icon_info = priv->icons[icon_pos];
7980 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
7984 * gtk_entry_get_icon_name:
7985 * @entry: A #GtkEntry
7986 * @icon_pos: Icon position
7988 * Retrieves the icon name used for the icon, or %NULL if there is
7989 * no icon or if the icon was set by some other method (e.g., by
7990 * pixbuf, stock or gicon).
7992 * Returns: An icon name, or %NULL if no icon is set or if the icon
7993 * wasn't set from an icon name
7998 gtk_entry_get_icon_name (GtkEntry *entry,
7999 GtkEntryIconPosition icon_pos)
8001 GtkEntryPrivate *priv;
8002 EntryIconInfo *icon_info;
8004 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8005 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8008 icon_info = priv->icons[icon_pos];
8013 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8017 * gtk_entry_set_icon_sensitive:
8018 * @entry: A #GtkEntry
8019 * @icon_pos: Icon position
8020 * @sensitive: Specifies whether the icon should appear
8021 * sensitive or insensitive
8023 * Sets the sensitivity for the specified icon.
8028 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8029 GtkEntryIconPosition icon_pos,
8032 GtkEntryPrivate *priv;
8033 EntryIconInfo *icon_info;
8035 g_return_if_fail (GTK_IS_ENTRY (entry));
8036 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8040 if ((icon_info = priv->icons[icon_pos]) == NULL)
8041 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8043 if (icon_info->insensitive != !sensitive)
8045 icon_info->insensitive = !sensitive;
8047 icon_info->pressed = FALSE;
8048 icon_info->prelight = FALSE;
8050 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8051 update_cursors (GTK_WIDGET (entry));
8053 gtk_widget_queue_draw (GTK_WIDGET (entry));
8055 g_object_notify (G_OBJECT (entry),
8056 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8061 * gtk_entry_get_icon_sensitive:
8062 * @entry: a #GtkEntry
8063 * @icon_pos: Icon position
8065 * Returns whether the icon appears sensitive or insensitive.
8067 * Returns: %TRUE if the icon is sensitive.
8072 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8073 GtkEntryIconPosition icon_pos)
8075 GtkEntryPrivate *priv;
8076 EntryIconInfo *icon_info;
8078 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8079 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8083 icon_info = priv->icons[icon_pos];
8085 return (!icon_info || !icon_info->insensitive);
8090 * gtk_entry_get_icon_storage_type:
8091 * @entry: a #GtkEntry
8092 * @icon_pos: Icon position
8094 * Gets the type of representation being used by the icon
8095 * to store image data. If the icon has no image data,
8096 * the return value will be %GTK_IMAGE_EMPTY.
8098 * Return value: image representation being used
8103 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8104 GtkEntryIconPosition icon_pos)
8106 GtkEntryPrivate *priv;
8107 EntryIconInfo *icon_info;
8109 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8110 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8114 icon_info = priv->icons[icon_pos];
8117 return GTK_IMAGE_EMPTY;
8119 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8123 * gtk_entry_get_icon_at_pos:
8124 * @entry: a #GtkEntry
8125 * @x: the x coordinate of the position to find
8126 * @y: the y coordinate of the position to find
8128 * Finds the icon at the given position and return its index. The
8129 * position's coordinates are relative to the @entry's top left corner.
8130 * If @x, @y doesn't lie inside an icon, -1 is returned.
8131 * This function is intended for use in a #GtkWidget::query-tooltip
8134 * Returns: the index of the icon at the given position, or -1
8139 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8143 GtkAllocation primary;
8144 GtkAllocation secondary;
8145 gint frame_x, frame_y;
8147 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8149 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8153 get_icon_allocations (entry, &primary, &secondary);
8155 if (primary.x <= x && x < primary.x + primary.width &&
8156 primary.y <= y && y < primary.y + primary.height)
8157 return GTK_ENTRY_ICON_PRIMARY;
8159 if (secondary.x <= x && x < secondary.x + secondary.width &&
8160 secondary.y <= y && y < secondary.y + secondary.height)
8161 return GTK_ENTRY_ICON_SECONDARY;
8167 * gtk_entry_set_icon_drag_source:
8168 * @entry: a #GtkIconEntry
8169 * @icon_pos: icon position
8170 * @target_list: the targets (data formats) in which the data can be provided
8171 * @actions: a bitmask of the allowed drag actions
8173 * Sets up the icon at the given position so that GTK+ will start a drag
8174 * operation when the user clicks and drags the icon.
8176 * To handle the drag operation, you need to connect to the usual
8177 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8178 * signal, and use gtk_entry_get_current_icon_drag_source() in
8179 * your signal handler to find out if the drag was started from
8182 * By default, GTK+ uses the icon as the drag icon. You can use the
8183 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8184 * have to use g_signal_connect_after() to ensure that your signal handler
8185 * gets executed after the default handler.
8190 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8191 GtkEntryIconPosition icon_pos,
8192 GtkTargetList *target_list,
8193 GdkDragAction actions)
8195 GtkEntryPrivate *priv;
8196 EntryIconInfo *icon_info;
8198 g_return_if_fail (GTK_IS_ENTRY (entry));
8199 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8203 if ((icon_info = priv->icons[icon_pos]) == NULL)
8204 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8206 if (icon_info->target_list)
8207 gtk_target_list_unref (icon_info->target_list);
8208 icon_info->target_list = target_list;
8209 if (icon_info->target_list)
8210 gtk_target_list_ref (icon_info->target_list);
8212 icon_info->actions = actions;
8216 * gtk_entry_get_current_icon_drag_source:
8217 * @entry: a #GtkIconEntry
8219 * Returns the index of the icon which is the source of the current
8220 * DND operation, or -1.
8222 * This function is meant to be used in a #GtkWidget::drag-data-get
8225 * Returns: index of the icon which is the source of the current
8226 * DND operation, or -1.
8231 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8233 GtkEntryPrivate *priv;
8234 EntryIconInfo *icon_info = NULL;
8237 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8241 for (i = 0; i < MAX_ICONS; i++)
8243 if ((icon_info = priv->icons[i]))
8245 if (icon_info->in_drag)
8254 * gtk_entry_get_icon_area:
8255 * @entry: A #GtkEntry
8256 * @icon_pos: Icon position
8257 * @icon_area: (out): Return location for the icon's area
8259 * Gets the area where entry's icon at @icon_pos is drawn.
8260 * This function is useful when drawing something to the
8261 * entry in a draw callback.
8263 * If the entry is not realized or has no icon at the given position,
8264 * @icon_area is filled with zeros.
8266 * See also gtk_entry_get_text_area()
8271 gtk_entry_get_icon_area (GtkEntry *entry,
8272 GtkEntryIconPosition icon_pos,
8273 GdkRectangle *icon_area)
8275 GtkEntryPrivate *priv;
8276 EntryIconInfo *icon_info;
8278 g_return_if_fail (GTK_IS_ENTRY (entry));
8279 g_return_if_fail (icon_area != NULL);
8283 icon_info = priv->icons[icon_pos];
8287 GtkAllocation primary;
8288 GtkAllocation secondary;
8290 get_icon_allocations (entry, &primary, &secondary);
8292 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8293 *icon_area = primary;
8295 *icon_area = secondary;
8301 icon_area->width = 0;
8302 icon_area->height = 0;
8307 ensure_has_tooltip (GtkEntry *entry)
8309 GtkEntryPrivate *priv;
8310 EntryIconInfo *icon_info;
8312 gboolean has_tooltip = FALSE;
8316 for (i = 0; i < MAX_ICONS; i++)
8318 if ((icon_info = priv->icons[i]) != NULL)
8320 if (icon_info->tooltip != NULL)
8328 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8332 * gtk_entry_get_icon_tooltip_text:
8333 * @entry: a #GtkEntry
8334 * @icon_pos: the icon position
8336 * Gets the contents of the tooltip on the icon at the specified
8337 * position in @entry.
8339 * Returns: the tooltip text, or %NULL. Free the returned string
8340 * with g_free() when done.
8345 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8346 GtkEntryIconPosition icon_pos)
8348 GtkEntryPrivate *priv;
8349 EntryIconInfo *icon_info;
8352 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8353 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8357 icon_info = priv->icons[icon_pos];
8362 if (icon_info->tooltip &&
8363 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8364 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8370 * gtk_entry_set_icon_tooltip_text:
8371 * @entry: a #GtkEntry
8372 * @icon_pos: the icon position
8373 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8375 * Sets @tooltip as the contents of the tooltip for the icon
8376 * at the specified position.
8378 * Use %NULL for @tooltip to remove an existing tooltip.
8380 * See also gtk_widget_set_tooltip_text() and
8381 * gtk_entry_set_icon_tooltip_markup().
8386 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8387 GtkEntryIconPosition icon_pos,
8388 const gchar *tooltip)
8390 GtkEntryPrivate *priv;
8391 EntryIconInfo *icon_info;
8393 g_return_if_fail (GTK_IS_ENTRY (entry));
8394 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8398 if ((icon_info = priv->icons[icon_pos]) == NULL)
8399 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8401 if (icon_info->tooltip)
8402 g_free (icon_info->tooltip);
8404 /* Treat an empty string as a NULL string,
8405 * because an empty string would be useless for a tooltip:
8407 if (tooltip && tooltip[0] == '\0')
8410 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8412 ensure_has_tooltip (entry);
8416 * gtk_entry_get_icon_tooltip_markup:
8417 * @entry: a #GtkEntry
8418 * @icon_pos: the icon position
8420 * Gets the contents of the tooltip on the icon at the specified
8421 * position in @entry.
8423 * Returns: the tooltip text, or %NULL. Free the returned string
8424 * with g_free() when done.
8429 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8430 GtkEntryIconPosition icon_pos)
8432 GtkEntryPrivate *priv;
8433 EntryIconInfo *icon_info;
8435 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8436 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8440 icon_info = priv->icons[icon_pos];
8445 return g_strdup (icon_info->tooltip);
8449 * gtk_entry_set_icon_tooltip_markup:
8450 * @entry: a #GtkEntry
8451 * @icon_pos: the icon position
8452 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8454 * Sets @tooltip as the contents of the tooltip for the icon at
8455 * the specified position. @tooltip is assumed to be marked up with
8456 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8458 * Use %NULL for @tooltip to remove an existing tooltip.
8460 * See also gtk_widget_set_tooltip_markup() and
8461 * gtk_enty_set_icon_tooltip_text().
8466 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8467 GtkEntryIconPosition icon_pos,
8468 const gchar *tooltip)
8470 GtkEntryPrivate *priv;
8471 EntryIconInfo *icon_info;
8473 g_return_if_fail (GTK_IS_ENTRY (entry));
8474 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8478 if ((icon_info = priv->icons[icon_pos]) == NULL)
8479 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8481 if (icon_info->tooltip)
8482 g_free (icon_info->tooltip);
8484 /* Treat an empty string as a NULL string,
8485 * because an empty string would be useless for a tooltip:
8487 if (tooltip && tooltip[0] == '\0')
8490 icon_info->tooltip = g_strdup (tooltip);
8492 ensure_has_tooltip (entry);
8496 gtk_entry_query_tooltip (GtkWidget *widget,
8499 gboolean keyboard_tip,
8500 GtkTooltip *tooltip)
8503 GtkEntryPrivate *priv;
8504 EntryIconInfo *icon_info;
8507 entry = GTK_ENTRY (widget);
8512 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8515 if ((icon_info = priv->icons[icon_pos]) != NULL)
8517 if (icon_info->tooltip)
8519 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8528 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8535 /* Quick hack of a popup menu
8538 activate_cb (GtkWidget *menuitem,
8541 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8542 g_signal_emit_by_name (entry, signal);
8547 gtk_entry_mnemonic_activate (GtkWidget *widget,
8548 gboolean group_cycling)
8550 gtk_widget_grab_focus (widget);
8555 append_action_signal (GtkEntry *entry,
8557 const gchar *stock_id,
8558 const gchar *signal,
8561 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8563 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8564 g_signal_connect (menuitem, "activate",
8565 G_CALLBACK (activate_cb), entry);
8567 gtk_widget_set_sensitive (menuitem, sensitive);
8569 gtk_widget_show (menuitem);
8570 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8574 popup_menu_detach (GtkWidget *attach_widget,
8577 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8578 GtkEntryPrivate *priv_attach = entry_attach->priv;
8580 priv_attach->popup_menu = NULL;
8584 popup_position_func (GtkMenu *menu,
8590 GtkEntry *entry = GTK_ENTRY (user_data);
8591 GtkEntryPrivate *priv = entry->priv;
8592 GtkWidget *widget = GTK_WIDGET (entry);
8594 GtkRequisition menu_req;
8595 GdkRectangle monitor;
8597 gint monitor_num, strong_x, height;
8599 g_return_if_fail (gtk_widget_get_realized (widget));
8601 gdk_window_get_origin (priv->text_area, x, y);
8603 screen = gtk_widget_get_screen (widget);
8604 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8605 if (monitor_num < 0)
8607 gtk_menu_set_monitor (menu, monitor_num);
8609 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8610 gtk_widget_get_preferred_size (priv->popup_menu,
8612 height = gdk_window_get_height (priv->text_area);
8613 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8614 _gtk_entry_get_borders (entry, &borders);
8616 *x += borders.left + strong_x - priv->scroll_offset;
8617 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8618 *x -= menu_req.width;
8620 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8622 else if ((*y - menu_req.height) >= monitor.y)
8623 *y -= menu_req.height;
8624 else if (monitor.y + monitor.height - (*y + height) > *y)
8627 *y -= menu_req.height;
8633 unichar_chosen_func (const char *text,
8636 GtkEntry *entry = GTK_ENTRY (data);
8637 GtkEntryPrivate *priv = entry->priv;
8640 gtk_entry_enter_text (entry, text);
8652 popup_targets_received (GtkClipboard *clipboard,
8653 GtkSelectionData *data,
8656 PopupInfo *info = user_data;
8657 GtkEntry *entry = info->entry;
8658 GtkEntryPrivate *info_entry_priv = entry->priv;
8660 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8663 gboolean clipboard_contains_text;
8664 GtkWidget *menuitem;
8666 gboolean show_input_method_menu;
8667 gboolean show_unicode_menu;
8669 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8670 if (info_entry_priv->popup_menu)
8671 gtk_widget_destroy (info_entry_priv->popup_menu);
8673 info_entry_priv->popup_menu = gtk_menu_new ();
8675 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8679 mode = gtk_entry_get_display_mode (entry);
8680 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8681 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8682 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8684 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8685 mode == DISPLAY_NORMAL &&
8686 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8688 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8689 info_entry_priv->editable && clipboard_contains_text);
8691 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8692 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8693 g_signal_connect_swapped (menuitem, "activate",
8694 G_CALLBACK (gtk_entry_delete_cb), entry);
8695 gtk_widget_show (menuitem);
8696 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8698 menuitem = gtk_separator_menu_item_new ();
8699 gtk_widget_show (menuitem);
8700 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8702 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8703 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8704 g_signal_connect_swapped (menuitem, "activate",
8705 G_CALLBACK (gtk_entry_select_all), entry);
8706 gtk_widget_show (menuitem);
8707 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8709 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8710 "gtk-show-input-method-menu", &show_input_method_menu,
8711 "gtk-show-unicode-menu", &show_unicode_menu,
8714 if (show_input_method_menu || show_unicode_menu)
8716 menuitem = gtk_separator_menu_item_new ();
8717 gtk_widget_show (menuitem);
8718 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8721 if (show_input_method_menu)
8723 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8724 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8725 gtk_widget_show (menuitem);
8726 submenu = gtk_menu_new ();
8727 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8729 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8731 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8732 GTK_MENU_SHELL (submenu));
8735 if (show_unicode_menu)
8737 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8738 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8739 gtk_widget_show (menuitem);
8741 submenu = gtk_menu_new ();
8742 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8743 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8745 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8746 unichar_chosen_func,
8750 g_signal_emit (entry,
8751 signals[POPULATE_POPUP],
8753 info_entry_priv->popup_menu);
8757 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8758 info->device, NULL, NULL, NULL, NULL, NULL,
8759 info->button, info->time);
8762 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8763 popup_position_func, entry,
8764 0, gtk_get_current_event_time ());
8765 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8769 g_object_unref (entry);
8770 g_slice_free (PopupInfo, info);
8774 gtk_entry_do_popup (GtkEntry *entry,
8775 GdkEventButton *event)
8777 PopupInfo *info = g_slice_new (PopupInfo);
8779 /* In order to know what entries we should make sensitive, we
8780 * ask for the current targets of the clipboard, and when
8781 * we get them, then we actually pop up the menu.
8783 info->entry = g_object_ref (entry);
8787 info->button = event->button;
8788 info->time = event->time;
8789 info->device = event->device;
8794 info->time = gtk_get_current_event_time ();
8795 info->device = NULL;
8798 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8799 gdk_atom_intern_static_string ("TARGETS"),
8800 popup_targets_received,
8805 gtk_entry_popup_menu (GtkWidget *widget)
8807 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8812 gtk_entry_drag_begin (GtkWidget *widget,
8813 GdkDragContext *context)
8815 GtkEntry *entry = GTK_ENTRY (widget);
8816 GtkEntryPrivate *priv = entry->priv;
8819 for (i = 0; i < MAX_ICONS; i++)
8821 EntryIconInfo *icon_info = priv->icons[i];
8823 if (icon_info != NULL)
8825 if (icon_info->in_drag)
8829 pix = _gtk_icon_helper_ensure_pixbuf
8830 (icon_info->icon_helper,
8831 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8832 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8834 g_object_unref (pix);
8841 gtk_entry_drag_end (GtkWidget *widget,
8842 GdkDragContext *context)
8844 GtkEntry *entry = GTK_ENTRY (widget);
8845 GtkEntryPrivate *priv = entry->priv;
8848 for (i = 0; i < MAX_ICONS; i++)
8850 EntryIconInfo *icon_info = priv->icons[i];
8852 if (icon_info != NULL)
8853 icon_info->in_drag = 0;
8858 gtk_entry_drag_leave (GtkWidget *widget,
8859 GdkDragContext *context,
8862 GtkEntry *entry = GTK_ENTRY (widget);
8863 GtkEntryPrivate *priv = entry->priv;
8865 priv->dnd_position = -1;
8866 gtk_widget_queue_draw (widget);
8870 gtk_entry_drag_drop (GtkWidget *widget,
8871 GdkDragContext *context,
8876 GtkEntry *entry = GTK_ENTRY (widget);
8877 GtkEntryPrivate *priv = entry->priv;
8878 GdkAtom target = GDK_NONE;
8881 target = gtk_drag_dest_find_target (widget, context, NULL);
8883 if (target != GDK_NONE)
8884 gtk_drag_get_data (widget, context, target, time);
8886 gtk_drag_finish (context, FALSE, FALSE, time);
8892 gtk_entry_drag_motion (GtkWidget *widget,
8893 GdkDragContext *context,
8898 GtkEntry *entry = GTK_ENTRY (widget);
8899 GtkEntryPrivate *priv = entry->priv;
8900 GtkStyleContext *style_context;
8901 GtkWidget *source_widget;
8902 GdkDragAction suggested_action;
8903 gint new_position, old_position;
8907 style_context = gtk_widget_get_style_context (widget);
8908 gtk_style_context_get_padding (style_context, 0, &padding);
8912 old_position = priv->dnd_position;
8913 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8915 if (priv->editable &&
8916 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8918 source_widget = gtk_drag_get_source_widget (context);
8919 suggested_action = gdk_drag_context_get_suggested_action (context);
8921 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8922 new_position < sel1 || new_position > sel2)
8924 if (source_widget == widget)
8926 /* Default to MOVE, unless the user has
8927 * pressed ctrl or alt to affect available actions
8929 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8930 suggested_action = GDK_ACTION_MOVE;
8933 priv->dnd_position = new_position;
8937 if (source_widget == widget)
8938 suggested_action = 0; /* Can't drop in selection where drag started */
8940 priv->dnd_position = -1;
8945 /* Entry not editable, or no text */
8946 suggested_action = 0;
8947 priv->dnd_position = -1;
8950 gdk_drag_status (context, suggested_action, time);
8952 if (priv->dnd_position != old_position)
8953 gtk_widget_queue_draw (widget);
8959 gtk_entry_drag_data_received (GtkWidget *widget,
8960 GdkDragContext *context,
8963 GtkSelectionData *selection_data,
8967 GtkEntry *entry = GTK_ENTRY (widget);
8968 GtkEntryPrivate *priv = entry->priv;
8969 GtkEditable *editable = GTK_EDITABLE (widget);
8970 GtkStyleContext *style_context;
8974 str = (gchar *) gtk_selection_data_get_text (selection_data);
8976 style_context = gtk_widget_get_style_context (widget);
8977 gtk_style_context_get_padding (style_context, 0, &padding);
8981 if (str && priv->editable)
8987 if (priv->truncate_multiline)
8988 length = truncate_multiline (str);
8990 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8992 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8993 new_position < sel1 || new_position > sel2)
8995 gtk_editable_insert_text (editable, str, length, &new_position);
8999 /* Replacing selection */
9000 begin_change (entry);
9001 gtk_editable_delete_text (editable, sel1, sel2);
9002 gtk_editable_insert_text (editable, str, length, &sel1);
9006 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9010 /* Drag and drop didn't happen! */
9011 gtk_drag_finish (context, FALSE, FALSE, time);
9018 gtk_entry_drag_data_get (GtkWidget *widget,
9019 GdkDragContext *context,
9020 GtkSelectionData *selection_data,
9024 GtkEntry *entry = GTK_ENTRY (widget);
9025 GtkEntryPrivate *priv = entry->priv;
9026 GtkEditable *editable = GTK_EDITABLE (widget);
9027 gint sel_start, sel_end;
9030 /* If there is an icon drag going on, exit early. */
9031 for (i = 0; i < MAX_ICONS; i++)
9033 EntryIconInfo *icon_info = priv->icons[i];
9035 if (icon_info != NULL)
9037 if (icon_info->in_drag)
9042 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9044 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9046 gtk_selection_data_set_text (selection_data, str, -1);
9054 gtk_entry_drag_data_delete (GtkWidget *widget,
9055 GdkDragContext *context)
9057 GtkEntry *entry = GTK_ENTRY (widget);
9058 GtkEntryPrivate *priv = entry->priv;
9059 GtkEditable *editable = GTK_EDITABLE (widget);
9060 gint sel_start, sel_end;
9063 /* If there is an icon drag going on, exit early. */
9064 for (i = 0; i < MAX_ICONS; i++)
9066 EntryIconInfo *icon_info = priv->icons[i];
9068 if (icon_info != NULL)
9070 if (icon_info->in_drag)
9075 if (priv->editable &&
9076 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9077 gtk_editable_delete_text (editable, sel_start, sel_end);
9080 /* We display the cursor when
9082 * - the selection is empty, AND
9083 * - the widget has focus
9086 #define CURSOR_ON_MULTIPLIER 2
9087 #define CURSOR_OFF_MULTIPLIER 1
9088 #define CURSOR_PEND_MULTIPLIER 3
9089 #define CURSOR_DIVIDER 3
9092 cursor_blinks (GtkEntry *entry)
9094 GtkEntryPrivate *priv = entry->priv;
9096 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9098 priv->selection_bound == priv->current_pos)
9100 GtkSettings *settings;
9103 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9104 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9113 get_cursor_time (GtkEntry *entry)
9115 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9118 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9124 get_cursor_blink_timeout (GtkEntry *entry)
9126 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9129 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9135 show_cursor (GtkEntry *entry)
9137 GtkEntryPrivate *priv = entry->priv;
9140 if (!priv->cursor_visible)
9142 priv->cursor_visible = TRUE;
9144 widget = GTK_WIDGET (entry);
9145 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9146 gtk_widget_queue_draw (widget);
9151 hide_cursor (GtkEntry *entry)
9153 GtkEntryPrivate *priv = entry->priv;
9156 if (priv->cursor_visible)
9158 priv->cursor_visible = FALSE;
9160 widget = GTK_WIDGET (entry);
9161 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9162 gtk_widget_queue_draw (widget);
9170 blink_cb (gpointer data)
9173 GtkEntryPrivate *priv;
9176 entry = GTK_ENTRY (data);
9179 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9181 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9182 "connect a handler to this signal, it must return\n"
9183 "FALSE so the entry gets the event as well");
9185 gtk_entry_check_cursor_blink (entry);
9190 g_assert (priv->selection_bound == priv->current_pos);
9192 blink_timeout = get_cursor_blink_timeout (entry);
9193 if (priv->blink_time > 1000 * blink_timeout &&
9194 blink_timeout < G_MAXINT/1000)
9196 /* we've blinked enough without the user doing anything, stop blinking */
9197 show_cursor (entry);
9198 priv->blink_timeout = 0;
9200 else if (priv->cursor_visible)
9202 hide_cursor (entry);
9203 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9209 show_cursor (entry);
9210 priv->blink_time += get_cursor_time (entry);
9211 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9216 /* Remove ourselves */
9221 gtk_entry_check_cursor_blink (GtkEntry *entry)
9223 GtkEntryPrivate *priv = entry->priv;
9225 if (cursor_blinks (entry))
9227 if (!priv->blink_timeout)
9229 show_cursor (entry);
9230 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9237 if (priv->blink_timeout)
9239 g_source_remove (priv->blink_timeout);
9240 priv->blink_timeout = 0;
9243 priv->cursor_visible = TRUE;
9248 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9250 GtkEntryPrivate *priv = entry->priv;
9252 if (cursor_blinks (entry))
9254 if (priv->blink_timeout != 0)
9255 g_source_remove (priv->blink_timeout);
9257 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9260 show_cursor (entry);
9265 gtk_entry_reset_blink_time (GtkEntry *entry)
9267 GtkEntryPrivate *priv = entry->priv;
9269 priv->blink_time = 0;
9275 gtk_entry_completion_timeout (gpointer data)
9277 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9278 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9280 completion->priv->completion_timeout = 0;
9282 if (completion->priv->filter_model &&
9283 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9284 >= completion->priv->minimum_key_length)
9288 GtkTreeSelection *s;
9289 gboolean popup_single;
9291 gtk_entry_completion_complete (completion);
9292 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9294 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9296 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9298 gtk_tree_selection_unselect_all (s);
9300 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9302 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9303 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9305 if (gtk_widget_get_visible (completion->priv->popup_window))
9306 _gtk_entry_completion_resize_popup (completion);
9308 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9311 _gtk_entry_completion_popdown (completion);
9313 else if (gtk_widget_get_visible (completion->priv->popup_window))
9314 _gtk_entry_completion_popdown (completion);
9319 static inline gboolean
9320 keyval_is_cursor_move (guint keyval)
9322 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9325 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9328 if (keyval == GDK_KEY_Page_Up)
9331 if (keyval == GDK_KEY_Page_Down)
9338 gtk_entry_completion_key_press (GtkWidget *widget,
9342 gint matches, actions = 0;
9343 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9345 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9348 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9350 if (completion->priv->actions)
9351 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9353 if (keyval_is_cursor_move (event->keyval))
9355 GtkTreePath *path = NULL;
9357 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9359 if (completion->priv->current_selected < 0)
9360 completion->priv->current_selected = matches + actions - 1;
9362 completion->priv->current_selected--;
9364 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9366 if (completion->priv->current_selected < matches + actions - 1)
9367 completion->priv->current_selected++;
9369 completion->priv->current_selected = -1;
9371 else if (event->keyval == GDK_KEY_Page_Up)
9373 if (completion->priv->current_selected < 0)
9374 completion->priv->current_selected = matches + actions - 1;
9375 else if (completion->priv->current_selected == 0)
9376 completion->priv->current_selected = -1;
9377 else if (completion->priv->current_selected < matches)
9379 completion->priv->current_selected -= PAGE_STEP;
9380 if (completion->priv->current_selected < 0)
9381 completion->priv->current_selected = 0;
9385 completion->priv->current_selected -= PAGE_STEP;
9386 if (completion->priv->current_selected < matches - 1)
9387 completion->priv->current_selected = matches - 1;
9390 else if (event->keyval == GDK_KEY_Page_Down)
9392 if (completion->priv->current_selected < 0)
9393 completion->priv->current_selected = 0;
9394 else if (completion->priv->current_selected < matches - 1)
9396 completion->priv->current_selected += PAGE_STEP;
9397 if (completion->priv->current_selected > matches - 1)
9398 completion->priv->current_selected = matches - 1;
9400 else if (completion->priv->current_selected == matches + actions - 1)
9402 completion->priv->current_selected = -1;
9406 completion->priv->current_selected += PAGE_STEP;
9407 if (completion->priv->current_selected > matches + actions - 1)
9408 completion->priv->current_selected = matches + actions - 1;
9412 if (completion->priv->current_selected < 0)
9414 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9415 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9417 if (completion->priv->inline_selection &&
9418 completion->priv->completion_prefix)
9420 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9421 completion->priv->completion_prefix);
9422 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9425 else if (completion->priv->current_selected < matches)
9427 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9429 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9430 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9433 if (completion->priv->inline_selection)
9437 GtkTreeIter child_iter;
9438 GtkTreeModel *model = NULL;
9439 GtkTreeSelection *sel;
9442 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9443 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9446 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9447 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9449 if (completion->priv->completion_prefix == NULL)
9450 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9452 g_signal_emit_by_name (completion, "cursor-on-match", model,
9453 &child_iter, &entry_set);
9456 else if (completion->priv->current_selected - matches >= 0)
9458 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9460 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9461 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9464 if (completion->priv->inline_selection &&
9465 completion->priv->completion_prefix)
9467 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9468 completion->priv->completion_prefix);
9469 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9473 gtk_tree_path_free (path);
9477 else if (event->keyval == GDK_KEY_Escape ||
9478 event->keyval == GDK_KEY_Left ||
9479 event->keyval == GDK_KEY_KP_Left ||
9480 event->keyval == GDK_KEY_Right ||
9481 event->keyval == GDK_KEY_KP_Right)
9483 gboolean retval = TRUE;
9485 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9486 _gtk_entry_completion_popdown (completion);
9488 if (completion->priv->current_selected < 0)
9491 goto keypress_completion_out;
9493 else if (completion->priv->inline_selection)
9495 /* Escape rejects the tentative completion */
9496 if (event->keyval == GDK_KEY_Escape)
9498 if (completion->priv->completion_prefix)
9499 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9500 completion->priv->completion_prefix);
9502 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9505 /* Move the cursor to the end for Right/Esc, to the
9506 beginning for Left */
9507 if (event->keyval == GDK_KEY_Right ||
9508 event->keyval == GDK_KEY_KP_Right ||
9509 event->keyval == GDK_KEY_Escape)
9510 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9512 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9515 keypress_completion_out:
9516 if (completion->priv->inline_selection)
9518 g_free (completion->priv->completion_prefix);
9519 completion->priv->completion_prefix = NULL;
9524 else if (event->keyval == GDK_KEY_Tab ||
9525 event->keyval == GDK_KEY_KP_Tab ||
9526 event->keyval == GDK_KEY_ISO_Left_Tab)
9528 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9529 _gtk_entry_completion_popdown (completion);
9531 g_free (completion->priv->completion_prefix);
9532 completion->priv->completion_prefix = NULL;
9536 else if (event->keyval == GDK_KEY_ISO_Enter ||
9537 event->keyval == GDK_KEY_KP_Enter ||
9538 event->keyval == GDK_KEY_Return)
9541 GtkTreeModel *model = NULL;
9542 GtkTreeModel *child_model;
9543 GtkTreeIter child_iter;
9544 GtkTreeSelection *sel;
9545 gboolean retval = TRUE;
9547 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9548 _gtk_entry_completion_popdown (completion);
9550 if (completion->priv->current_selected < matches)
9554 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9555 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9557 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9558 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9559 g_signal_handler_block (widget, completion->priv->changed_id);
9560 g_signal_emit_by_name (completion, "match-selected",
9561 child_model, &child_iter, &entry_set);
9562 g_signal_handler_unblock (widget, completion->priv->changed_id);
9568 gtk_tree_model_get (model, &iter,
9569 completion->priv->text_column, &str,
9572 gtk_entry_set_text (GTK_ENTRY (widget), str);
9574 /* move the cursor to the end */
9575 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9583 else if (completion->priv->current_selected - matches >= 0)
9585 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9586 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9590 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9591 g_signal_emit_by_name (completion, "action-activated",
9592 gtk_tree_path_get_indices (path)[0]);
9593 gtk_tree_path_free (path);
9599 g_free (completion->priv->completion_prefix);
9600 completion->priv->completion_prefix = NULL;
9609 gtk_entry_completion_changed (GtkWidget *widget,
9612 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9613 GtkEntry *entry = GTK_ENTRY (widget);
9614 GtkEntryPrivate *priv = entry->priv;
9617 /* (re)install completion timeout */
9618 if (completion->priv->completion_timeout)
9619 g_source_remove (completion->priv->completion_timeout);
9621 if (!gtk_entry_get_text (entry))
9624 /* no need to normalize for this test */
9625 if (completion->priv->minimum_key_length > 0 &&
9626 strcmp ("", gtk_entry_get_text (entry)) == 0)
9628 if (gtk_widget_get_visible (completion->priv->popup_window))
9629 _gtk_entry_completion_popdown (completion);
9633 device = gtk_get_current_event_device ();
9635 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9636 device = gdk_device_get_associated_device (device);
9639 priv->completion_device = device;
9641 completion->priv->completion_timeout =
9642 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9643 gtk_entry_completion_timeout,
9648 check_completion_callback (GtkEntryCompletion *completion)
9650 completion->priv->check_completion_idle = NULL;
9652 gtk_entry_completion_complete (completion);
9653 gtk_entry_completion_insert_prefix (completion);
9659 clear_completion_callback (GtkEntry *entry,
9662 if (pspec->name == I_("cursor-position") ||
9663 pspec->name == I_("selection-bound"))
9665 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9667 completion->priv->has_completion = FALSE;
9672 accept_completion_callback (GtkEntry *entry)
9674 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9676 if (completion->priv->has_completion)
9677 gtk_editable_set_position (GTK_EDITABLE (entry),
9678 gtk_entry_buffer_get_length (get_buffer (entry)));
9684 completion_insert_text_callback (GtkEntry *entry,
9688 GtkEntryCompletion *completion)
9690 /* idle to update the selection based on the file list */
9691 if (completion->priv->check_completion_idle == NULL)
9693 completion->priv->check_completion_idle = g_idle_source_new ();
9694 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9695 g_source_set_closure (completion->priv->check_completion_idle,
9696 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9697 G_OBJECT (completion)));
9698 g_source_attach (completion->priv->check_completion_idle, NULL);
9703 completion_changed (GtkEntryCompletion *completion,
9707 GtkEntry *entry = GTK_ENTRY (data);
9709 if (pspec->name == I_("popup-completion") ||
9710 pspec->name == I_("inline-completion"))
9712 disconnect_completion_signals (entry, completion);
9713 connect_completion_signals (entry, completion);
9718 disconnect_completion_signals (GtkEntry *entry,
9719 GtkEntryCompletion *completion)
9721 g_signal_handlers_disconnect_by_func (completion,
9722 G_CALLBACK (completion_changed), entry);
9723 if (completion->priv->changed_id > 0 &&
9724 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9726 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9727 completion->priv->changed_id = 0;
9729 g_signal_handlers_disconnect_by_func (entry,
9730 G_CALLBACK (gtk_entry_completion_key_press), completion);
9731 if (completion->priv->insert_text_id > 0 &&
9732 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9734 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9735 completion->priv->insert_text_id = 0;
9737 g_signal_handlers_disconnect_by_func (entry,
9738 G_CALLBACK (completion_insert_text_callback), completion);
9739 g_signal_handlers_disconnect_by_func (entry,
9740 G_CALLBACK (clear_completion_callback), completion);
9741 g_signal_handlers_disconnect_by_func (entry,
9742 G_CALLBACK (accept_completion_callback), completion);
9746 connect_completion_signals (GtkEntry *entry,
9747 GtkEntryCompletion *completion)
9749 if (completion->priv->popup_completion)
9751 completion->priv->changed_id =
9752 g_signal_connect (entry, "changed",
9753 G_CALLBACK (gtk_entry_completion_changed), completion);
9754 g_signal_connect (entry, "key-press-event",
9755 G_CALLBACK (gtk_entry_completion_key_press), completion);
9758 if (completion->priv->inline_completion)
9760 completion->priv->insert_text_id =
9761 g_signal_connect (entry, "insert-text",
9762 G_CALLBACK (completion_insert_text_callback), completion);
9763 g_signal_connect (entry, "notify",
9764 G_CALLBACK (clear_completion_callback), completion);
9765 g_signal_connect (entry, "activate",
9766 G_CALLBACK (accept_completion_callback), completion);
9767 g_signal_connect (entry, "focus-out-event",
9768 G_CALLBACK (accept_completion_callback), completion);
9771 g_signal_connect (completion, "notify",
9772 G_CALLBACK (completion_changed), entry);
9776 * gtk_entry_set_completion:
9777 * @entry: A #GtkEntry
9778 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9780 * Sets @completion to be the auxiliary completion object to use with @entry.
9781 * All further configuration of the completion mechanism is done on
9782 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9783 * @completion is set to %NULL.
9788 gtk_entry_set_completion (GtkEntry *entry,
9789 GtkEntryCompletion *completion)
9791 GtkEntryCompletion *old;
9793 g_return_if_fail (GTK_IS_ENTRY (entry));
9794 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9796 old = gtk_entry_get_completion (entry);
9798 if (old == completion)
9803 if (old->priv->completion_timeout)
9805 g_source_remove (old->priv->completion_timeout);
9806 old->priv->completion_timeout = 0;
9809 if (old->priv->check_completion_idle)
9811 g_source_destroy (old->priv->check_completion_idle);
9812 old->priv->check_completion_idle = NULL;
9815 if (gtk_widget_get_mapped (old->priv->popup_window))
9816 _gtk_entry_completion_popdown (old);
9818 disconnect_completion_signals (entry, old);
9819 old->priv->entry = NULL;
9821 g_object_unref (old);
9826 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9830 /* hook into the entry */
9831 g_object_ref (completion);
9833 connect_completion_signals (entry, completion);
9834 completion->priv->entry = GTK_WIDGET (entry);
9835 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9837 g_object_notify (G_OBJECT (entry), "completion");
9841 * gtk_entry_get_completion:
9842 * @entry: A #GtkEntry
9844 * Returns the auxiliary completion object currently in use by @entry.
9846 * Return value: (transfer none): The auxiliary completion object currently
9851 GtkEntryCompletion *
9852 gtk_entry_get_completion (GtkEntry *entry)
9854 GtkEntryCompletion *completion;
9856 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9858 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9859 GTK_ENTRY_COMPLETION_KEY));
9865 * gtk_entry_set_cursor_hadjustment:
9866 * @entry: a #GtkEntry
9867 * @adjustment: an adjustment which should be adjusted when the cursor
9868 * is moved, or %NULL
9870 * Hooks up an adjustment to the cursor position in an entry, so that when
9871 * the cursor is moved, the adjustment is scrolled to show that position.
9872 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9875 * The adjustment has to be in pixel units and in the same coordinate system
9881 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9882 GtkAdjustment *adjustment)
9884 g_return_if_fail (GTK_IS_ENTRY (entry));
9886 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9889 g_object_ref (adjustment);
9891 g_object_set_qdata_full (G_OBJECT (entry),
9892 quark_cursor_hadjustment,
9898 * gtk_entry_get_cursor_hadjustment:
9899 * @entry: a #GtkEntry
9901 * Retrieves the horizontal cursor adjustment for the entry.
9902 * See gtk_entry_set_cursor_hadjustment().
9904 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9905 * if none has been set.
9910 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9912 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9914 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9918 * gtk_entry_set_progress_fraction:
9919 * @entry: a #GtkEntry
9920 * @fraction: fraction of the task that's been completed
9922 * Causes the entry's progress indicator to "fill in" the given
9923 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9929 gtk_entry_set_progress_fraction (GtkEntry *entry,
9933 GtkEntryPrivate *private;
9934 gdouble old_fraction;
9935 gint x, y, width, height;
9936 gint old_x, old_y, old_width, old_height;
9938 g_return_if_fail (GTK_IS_ENTRY (entry));
9940 widget = GTK_WIDGET (entry);
9941 private = entry->priv;
9943 if (private->progress_pulse_mode)
9946 old_fraction = private->progress_fraction;
9948 if (gtk_widget_is_drawable (widget))
9949 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9951 fraction = CLAMP (fraction, 0.0, 1.0);
9953 private->progress_fraction = fraction;
9954 private->progress_pulse_mode = FALSE;
9955 private->progress_pulse_current = 0.0;
9957 if (gtk_widget_is_drawable (widget))
9959 get_progress_area (widget, &x, &y, &width, &height);
9961 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9962 gtk_widget_queue_draw (widget);
9965 if (fraction != old_fraction)
9966 g_object_notify (G_OBJECT (entry), "progress-fraction");
9970 * gtk_entry_get_progress_fraction:
9971 * @entry: a #GtkEntry
9973 * Returns the current fraction of the task that's been completed.
9974 * See gtk_entry_set_progress_fraction().
9976 * Return value: a fraction from 0.0 to 1.0
9981 gtk_entry_get_progress_fraction (GtkEntry *entry)
9983 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9985 return entry->priv->progress_fraction;
9989 * gtk_entry_set_progress_pulse_step:
9990 * @entry: a #GtkEntry
9991 * @fraction: fraction between 0.0 and 1.0
9993 * Sets the fraction of total entry width to move the progress
9994 * bouncing block for each call to gtk_entry_progress_pulse().
9999 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10002 GtkEntryPrivate *private;
10004 g_return_if_fail (GTK_IS_ENTRY (entry));
10006 private = entry->priv;
10008 fraction = CLAMP (fraction, 0.0, 1.0);
10010 if (fraction != private->progress_pulse_fraction)
10012 private->progress_pulse_fraction = fraction;
10014 gtk_widget_queue_draw (GTK_WIDGET (entry));
10016 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10021 * gtk_entry_get_progress_pulse_step:
10022 * @entry: a #GtkEntry
10024 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10026 * Return value: a fraction from 0.0 to 1.0
10031 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10033 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10035 return entry->priv->progress_pulse_fraction;
10039 * gtk_entry_progress_pulse:
10040 * @entry: a #GtkEntry
10042 * Indicates that some progress is made, but you don't know how much.
10043 * Causes the entry's progress indicator to enter "activity mode,"
10044 * where a block bounces back and forth. Each call to
10045 * gtk_entry_progress_pulse() causes the block to move by a little bit
10046 * (the amount of movement per pulse is determined by
10047 * gtk_entry_set_progress_pulse_step()).
10052 gtk_entry_progress_pulse (GtkEntry *entry)
10054 GtkEntryPrivate *private;
10056 g_return_if_fail (GTK_IS_ENTRY (entry));
10058 private = entry->priv;
10060 if (private->progress_pulse_mode)
10062 if (private->progress_pulse_way_back)
10064 private->progress_pulse_current -= private->progress_pulse_fraction;
10066 if (private->progress_pulse_current < 0.0)
10068 private->progress_pulse_current = 0.0;
10069 private->progress_pulse_way_back = FALSE;
10074 private->progress_pulse_current += private->progress_pulse_fraction;
10076 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10078 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10079 private->progress_pulse_way_back = TRUE;
10085 private->progress_fraction = 0.0;
10086 private->progress_pulse_mode = TRUE;
10087 private->progress_pulse_way_back = FALSE;
10088 private->progress_pulse_current = 0.0;
10091 gtk_widget_queue_draw (GTK_WIDGET (entry));
10095 * gtk_entry_set_placeholder_text:
10096 * @entry: a #GtkEntry
10097 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10099 * Sets text to be displayed in @entry when it is empty and unfocused.
10100 * This can be used to give a visual hint of the expected contents of
10103 * Note that since the placeholder text gets removed when the entry
10104 * received focus, using this feature is a bit problematic if the entry
10105 * is given the initial focus in a window. Sometimes this can be
10106 * worked around by delaying the initial focus setting until the
10107 * first key event arrives.
10112 gtk_entry_set_placeholder_text (GtkEntry *entry,
10115 GtkEntryPrivate *priv;
10117 g_return_if_fail (GTK_IS_ENTRY (entry));
10119 priv = entry->priv;
10121 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10124 g_free (priv->placeholder_text);
10125 priv->placeholder_text = g_strdup (text);
10127 gtk_entry_recompute (entry);
10129 g_object_notify (G_OBJECT (entry), "placeholder-text");
10133 * gtk_entry_get_placeholder_text:
10134 * @entry: a #GtkEntry
10136 * Retrieves the text that will be displayed when @entry is empty and unfocused
10138 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10139 * storage in the widget and must not be freed, modified or stored.
10144 gtk_entry_get_placeholder_text (GtkEntry *entry)
10146 GtkEntryPrivate *priv;
10148 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10150 priv = entry->priv;
10152 return priv->placeholder_text;
10155 /* Caps Lock warning for password entries */
10158 show_capslock_feedback (GtkEntry *entry,
10161 GtkEntryPrivate *priv = entry->priv;
10163 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10165 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10166 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10167 priv->caps_lock_warning_shown = TRUE;
10170 if (priv->caps_lock_warning_shown)
10171 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10173 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10177 remove_capslock_feedback (GtkEntry *entry)
10179 GtkEntryPrivate *priv = entry->priv;
10181 if (priv->caps_lock_warning_shown)
10183 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10184 priv->caps_lock_warning_shown = FALSE;
10189 keymap_state_changed (GdkKeymap *keymap,
10192 GtkEntryPrivate *priv = entry->priv;
10195 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10197 if (gdk_keymap_get_num_lock_state (keymap)
10198 && gdk_keymap_get_caps_lock_state (keymap))
10199 text = _("Caps Lock and Num Lock are on");
10200 else if (gdk_keymap_get_num_lock_state (keymap))
10201 text = _("Num Lock is on");
10202 else if (gdk_keymap_get_caps_lock_state (keymap))
10203 text = _("Caps Lock is on");
10207 show_capslock_feedback (entry, text);
10209 remove_capslock_feedback (entry);
10213 * _gtk_entry_set_is_cell_renderer:
10214 * @entry: a #GtkEntry
10215 * @is_cell_renderer: new value
10217 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10218 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10220 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10224 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10225 gboolean is_cell_renderer)
10227 entry->priv->is_cell_renderer = is_cell_renderer;