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 * Deprecated: 3.4: Use the standard margin CSS property;
1380 * the value of this style property is ignored.
1382 gtk_widget_class_install_style_property (widget_class,
1383 g_param_spec_boxed ("progress-border",
1384 P_("Progress Border"),
1385 P_("Border around the progress bar"),
1387 GTK_PARAM_READABLE |
1388 G_PARAM_DEPRECATED));
1391 * GtkEntry:invisible-char:
1393 * The invisible character is used when masking entry contents (in
1394 * \"password mode\")"). When it is not explicitly set with the
1395 * #GtkEntry::invisible-char property, GTK+ determines the character
1396 * to use from a list of possible candidates, depending on availability
1397 * in the current font.
1399 * This style property allows the theme to prepend a character
1400 * to the list of candidates.
1404 gtk_widget_class_install_style_property (widget_class,
1405 g_param_spec_unichar ("invisible-char",
1406 P_("Invisible character"),
1407 P_("The character to use when masking entry contents (in \"password mode\")"),
1409 GTK_PARAM_READABLE));
1412 * GtkEntry::populate-popup:
1413 * @entry: The entry on which the signal is emitted
1414 * @menu: the menu that is being populated
1416 * The ::populate-popup signal gets emitted before showing the
1417 * context menu of the entry.
1419 * If you need to add items to the context menu, connect
1420 * to this signal and append your menuitems to the @menu.
1422 signals[POPULATE_POPUP] =
1423 g_signal_new (I_("populate-popup"),
1424 G_OBJECT_CLASS_TYPE (gobject_class),
1426 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1428 _gtk_marshal_VOID__OBJECT,
1432 /* Action signals */
1435 * GtkEntry::activate:
1436 * @entry: The entry on which the signal is emitted
1438 * A <link linkend="keybinding-signals">keybinding signal</link>
1439 * which gets emitted when the user activates the entry.
1441 * Applications should not connect to it, but may emit it with
1442 * g_signal_emit_by_name() if they need to control activation
1445 * The default bindings for this signal are all forms of the Enter key.
1448 g_signal_new (I_("activate"),
1449 G_OBJECT_CLASS_TYPE (gobject_class),
1450 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1451 G_STRUCT_OFFSET (GtkEntryClass, activate),
1453 _gtk_marshal_VOID__VOID,
1455 widget_class->activate_signal = signals[ACTIVATE];
1458 * GtkEntry::move-cursor:
1459 * @entry: the object which received the signal
1460 * @step: the granularity of the move, as a #GtkMovementStep
1461 * @count: the number of @step units to move
1462 * @extend_selection: %TRUE if the move should extend the selection
1464 * The ::move-cursor signal is a
1465 * <link linkend="keybinding-signals">keybinding signal</link>
1466 * which gets emitted when the user initiates a cursor movement.
1467 * If the cursor is not visible in @entry, this signal causes
1468 * the viewport to be moved instead.
1470 * Applications should not connect to it, but may emit it with
1471 * g_signal_emit_by_name() if they need to control the cursor
1474 * The default bindings for this signal come in two variants,
1475 * the variant with the Shift modifier extends the selection,
1476 * the variant without the Shift modifer does not.
1477 * There are too many key combinations to list them all here.
1479 * <listitem>Arrow keys move by individual characters/lines</listitem>
1480 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1481 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1484 signals[MOVE_CURSOR] =
1485 g_signal_new (I_("move-cursor"),
1486 G_OBJECT_CLASS_TYPE (gobject_class),
1487 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1488 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1490 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1492 GTK_TYPE_MOVEMENT_STEP,
1497 * GtkEntry::insert-at-cursor:
1498 * @entry: the object which received the signal
1499 * @string: the string to insert
1501 * The ::insert-at-cursor signal is a
1502 * <link linkend="keybinding-signals">keybinding signal</link>
1503 * which gets emitted when the user initiates the insertion of a
1504 * fixed string at the cursor.
1506 * This signal has no default bindings.
1508 signals[INSERT_AT_CURSOR] =
1509 g_signal_new (I_("insert-at-cursor"),
1510 G_OBJECT_CLASS_TYPE (gobject_class),
1511 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1512 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1514 _gtk_marshal_VOID__STRING,
1519 * GtkEntry::delete-from-cursor:
1520 * @entry: the object which received the signal
1521 * @type: the granularity of the deletion, as a #GtkDeleteType
1522 * @count: the number of @type units to delete
1524 * The ::delete-from-cursor signal is a
1525 * <link linkend="keybinding-signals">keybinding signal</link>
1526 * which gets emitted when the user initiates a text deletion.
1528 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1529 * if there is one, otherwise it deletes the requested number
1532 * The default bindings for this signal are
1533 * Delete for deleting a character and Ctrl-Delete for
1536 signals[DELETE_FROM_CURSOR] =
1537 g_signal_new (I_("delete-from-cursor"),
1538 G_OBJECT_CLASS_TYPE (gobject_class),
1539 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1540 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1542 _gtk_marshal_VOID__ENUM_INT,
1544 GTK_TYPE_DELETE_TYPE,
1548 * GtkEntry::backspace:
1549 * @entry: the object which received the signal
1551 * The ::backspace signal is a
1552 * <link linkend="keybinding-signals">keybinding signal</link>
1553 * which gets emitted when the user asks for it.
1555 * The default bindings for this signal are
1556 * Backspace and Shift-Backspace.
1558 signals[BACKSPACE] =
1559 g_signal_new (I_("backspace"),
1560 G_OBJECT_CLASS_TYPE (gobject_class),
1561 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1562 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1564 _gtk_marshal_VOID__VOID,
1568 * GtkEntry::cut-clipboard:
1569 * @entry: the object which received the signal
1571 * The ::cut-clipboard signal is a
1572 * <link linkend="keybinding-signals">keybinding signal</link>
1573 * which gets emitted to cut the selection to the clipboard.
1575 * The default bindings for this signal are
1576 * Ctrl-x and Shift-Delete.
1578 signals[CUT_CLIPBOARD] =
1579 g_signal_new (I_("cut-clipboard"),
1580 G_OBJECT_CLASS_TYPE (gobject_class),
1581 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1582 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1584 _gtk_marshal_VOID__VOID,
1588 * GtkEntry::copy-clipboard:
1589 * @entry: the object which received the signal
1591 * The ::copy-clipboard signal is a
1592 * <link linkend="keybinding-signals">keybinding signal</link>
1593 * which gets emitted to copy the selection to the clipboard.
1595 * The default bindings for this signal are
1596 * Ctrl-c and Ctrl-Insert.
1598 signals[COPY_CLIPBOARD] =
1599 g_signal_new (I_("copy-clipboard"),
1600 G_OBJECT_CLASS_TYPE (gobject_class),
1601 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1602 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1604 _gtk_marshal_VOID__VOID,
1608 * GtkEntry::paste-clipboard:
1609 * @entry: the object which received the signal
1611 * The ::paste-clipboard signal is a
1612 * <link linkend="keybinding-signals">keybinding signal</link>
1613 * which gets emitted to paste the contents of the clipboard
1614 * into the text view.
1616 * The default bindings for this signal are
1617 * Ctrl-v and Shift-Insert.
1619 signals[PASTE_CLIPBOARD] =
1620 g_signal_new (I_("paste-clipboard"),
1621 G_OBJECT_CLASS_TYPE (gobject_class),
1622 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1623 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1625 _gtk_marshal_VOID__VOID,
1629 * GtkEntry::toggle-overwrite:
1630 * @entry: the object which received the signal
1632 * The ::toggle-overwrite signal is a
1633 * <link linkend="keybinding-signals">keybinding signal</link>
1634 * which gets emitted to toggle the overwrite mode of the entry.
1636 * The default bindings for this signal is Insert.
1638 signals[TOGGLE_OVERWRITE] =
1639 g_signal_new (I_("toggle-overwrite"),
1640 G_OBJECT_CLASS_TYPE (gobject_class),
1641 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1642 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1644 _gtk_marshal_VOID__VOID,
1648 * GtkEntry::icon-press:
1649 * @entry: The entry on which the signal is emitted
1650 * @icon_pos: The position of the clicked icon
1651 * @event: (type Gdk.EventButton): the button press event
1653 * The ::icon-press signal is emitted when an activatable icon
1658 signals[ICON_PRESS] =
1659 g_signal_new (I_("icon-press"),
1660 G_TYPE_FROM_CLASS (gobject_class),
1664 _gtk_marshal_VOID__ENUM_BOXED,
1666 GTK_TYPE_ENTRY_ICON_POSITION,
1667 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1670 * GtkEntry::icon-release:
1671 * @entry: The entry on which the signal is emitted
1672 * @icon_pos: The position of the clicked icon
1673 * @event: (type Gdk.EventButton): the button release event
1675 * The ::icon-release signal is emitted on the button release from a
1676 * mouse click over an activatable icon.
1680 signals[ICON_RELEASE] =
1681 g_signal_new (I_("icon-release"),
1682 G_TYPE_FROM_CLASS (gobject_class),
1686 _gtk_marshal_VOID__ENUM_BOXED,
1688 GTK_TYPE_ENTRY_ICON_POSITION,
1689 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1692 * GtkEntry::preedit-changed:
1693 * @entry: the object which received the signal
1694 * @preedit: the current preedit string
1696 * If an input method is used, the typed text will not immediately
1697 * be committed to the buffer. So if you are interested in the text,
1698 * connect to this signal.
1702 signals[PREEDIT_CHANGED] =
1703 g_signal_new_class_handler (I_("preedit-changed"),
1704 G_OBJECT_CLASS_TYPE (gobject_class),
1705 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1708 _gtk_marshal_VOID__STRING,
1717 binding_set = gtk_binding_set_by_class (class);
1719 /* Moving the insertion point */
1720 add_move_binding (binding_set, GDK_KEY_Right, 0,
1721 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1723 add_move_binding (binding_set, GDK_KEY_Left, 0,
1724 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1726 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1727 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1729 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1730 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1732 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1733 GTK_MOVEMENT_WORDS, 1);
1735 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1736 GTK_MOVEMENT_WORDS, -1);
1738 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1739 GTK_MOVEMENT_WORDS, 1);
1741 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1742 GTK_MOVEMENT_WORDS, -1);
1744 add_move_binding (binding_set, GDK_KEY_Home, 0,
1745 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1747 add_move_binding (binding_set, GDK_KEY_End, 0,
1748 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1750 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1751 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1753 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1754 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1756 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1757 GTK_MOVEMENT_BUFFER_ENDS, -1);
1759 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1760 GTK_MOVEMENT_BUFFER_ENDS, 1);
1762 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1763 GTK_MOVEMENT_BUFFER_ENDS, -1);
1765 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1766 GTK_MOVEMENT_BUFFER_ENDS, 1);
1770 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1772 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1774 G_TYPE_BOOLEAN, FALSE);
1775 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1777 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1779 G_TYPE_BOOLEAN, TRUE);
1781 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1783 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1785 G_TYPE_BOOLEAN, FALSE);
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1788 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1790 G_TYPE_BOOLEAN, TRUE);
1793 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1795 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1797 G_TYPE_BOOLEAN, FALSE);
1798 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1800 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1802 G_TYPE_BOOLEAN, FALSE);
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1808 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1810 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1814 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1815 "delete-from-cursor", 2,
1816 G_TYPE_ENUM, GTK_DELETE_CHARS,
1819 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1820 "delete-from-cursor", 2,
1821 G_TYPE_ENUM, GTK_DELETE_CHARS,
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1827 /* Make this do the same as Backspace, to help with mis-typing */
1828 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1831 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1832 "delete-from-cursor", 2,
1833 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1836 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1837 "delete-from-cursor", 2,
1838 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1841 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1842 "delete-from-cursor", 2,
1843 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1846 /* Cut/copy/paste */
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1849 "cut-clipboard", 0);
1850 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1851 "copy-clipboard", 0);
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1853 "paste-clipboard", 0);
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1856 "cut-clipboard", 0);
1857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1858 "copy-clipboard", 0);
1859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1860 "paste-clipboard", 0);
1863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1864 "toggle-overwrite", 0);
1865 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1866 "toggle-overwrite", 0);
1869 * GtkEntry:inner-border:
1871 * Sets the text area's border between the text and the frame.
1875 * Deprecated: 3.4: Use the standard border and padding CSS properties;
1876 * the value of this style property is ignored.
1878 gtk_widget_class_install_style_property (widget_class,
1879 g_param_spec_boxed ("inner-border",
1881 P_("Border between text and frame."),
1883 GTK_PARAM_READABLE |
1884 G_PARAM_DEPRECATED));
1886 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1888 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1892 gtk_entry_editable_init (GtkEditableInterface *iface)
1894 iface->do_insert_text = gtk_entry_insert_text;
1895 iface->do_delete_text = gtk_entry_delete_text;
1896 iface->insert_text = gtk_entry_real_insert_text;
1897 iface->delete_text = gtk_entry_real_delete_text;
1898 iface->get_chars = gtk_entry_get_chars;
1899 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1900 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1901 iface->set_position = gtk_entry_real_set_position;
1902 iface->get_position = gtk_entry_get_position;
1906 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1908 iface->start_editing = gtk_entry_start_editing;
1911 /* for deprecated properties */
1913 gtk_entry_do_set_inner_border (GtkEntry *entry,
1914 const GtkBorder *border)
1917 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1918 gtk_border_copy (border),
1919 (GDestroyNotify) gtk_border_free);
1921 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1923 g_object_notify (G_OBJECT (entry), "inner-border");
1926 static const GtkBorder *
1927 gtk_entry_do_get_inner_border (GtkEntry *entry)
1929 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1933 gtk_entry_set_property (GObject *object,
1935 const GValue *value,
1938 GtkEntry *entry = GTK_ENTRY (object);
1939 GtkEntryPrivate *priv = entry->priv;
1944 gtk_entry_set_buffer (entry, g_value_get_object (value));
1949 gboolean new_value = g_value_get_boolean (value);
1951 if (new_value != priv->editable)
1953 GtkWidget *widget = GTK_WIDGET (entry);
1957 _gtk_entry_reset_im_context (entry);
1958 if (gtk_widget_has_focus (widget))
1959 gtk_im_context_focus_out (priv->im_context);
1961 priv->preedit_length = 0;
1962 priv->preedit_cursor = 0;
1965 priv->editable = new_value;
1967 if (new_value && gtk_widget_has_focus (widget))
1968 gtk_im_context_focus_in (priv->im_context);
1970 gtk_widget_queue_draw (widget);
1975 case PROP_MAX_LENGTH:
1976 gtk_entry_set_max_length (entry, g_value_get_int (value));
1979 case PROP_VISIBILITY:
1980 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1983 case PROP_HAS_FRAME:
1984 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1987 case PROP_INNER_BORDER:
1988 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1991 case PROP_INVISIBLE_CHAR:
1992 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1995 case PROP_ACTIVATES_DEFAULT:
1996 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1999 case PROP_WIDTH_CHARS:
2000 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2004 gtk_entry_set_text (entry, g_value_get_string (value));
2008 gtk_entry_set_alignment (entry, g_value_get_float (value));
2011 case PROP_TRUNCATE_MULTILINE:
2012 priv->truncate_multiline = g_value_get_boolean (value);
2015 case PROP_SHADOW_TYPE:
2016 priv->shadow_type = g_value_get_enum (value);
2019 case PROP_OVERWRITE_MODE:
2020 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2023 case PROP_INVISIBLE_CHAR_SET:
2024 if (g_value_get_boolean (value))
2025 priv->invisible_char_set = TRUE;
2027 gtk_entry_unset_invisible_char (entry);
2030 case PROP_CAPS_LOCK_WARNING:
2031 priv->caps_lock_warning = g_value_get_boolean (value);
2034 case PROP_PROGRESS_FRACTION:
2035 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2038 case PROP_PROGRESS_PULSE_STEP:
2039 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2042 case PROP_PLACEHOLDER_TEXT:
2043 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2046 case PROP_PIXBUF_PRIMARY:
2047 gtk_entry_set_icon_from_pixbuf (entry,
2048 GTK_ENTRY_ICON_PRIMARY,
2049 g_value_get_object (value));
2052 case PROP_PIXBUF_SECONDARY:
2053 gtk_entry_set_icon_from_pixbuf (entry,
2054 GTK_ENTRY_ICON_SECONDARY,
2055 g_value_get_object (value));
2058 case PROP_STOCK_PRIMARY:
2059 gtk_entry_set_icon_from_stock (entry,
2060 GTK_ENTRY_ICON_PRIMARY,
2061 g_value_get_string (value));
2064 case PROP_STOCK_SECONDARY:
2065 gtk_entry_set_icon_from_stock (entry,
2066 GTK_ENTRY_ICON_SECONDARY,
2067 g_value_get_string (value));
2070 case PROP_ICON_NAME_PRIMARY:
2071 gtk_entry_set_icon_from_icon_name (entry,
2072 GTK_ENTRY_ICON_PRIMARY,
2073 g_value_get_string (value));
2076 case PROP_ICON_NAME_SECONDARY:
2077 gtk_entry_set_icon_from_icon_name (entry,
2078 GTK_ENTRY_ICON_SECONDARY,
2079 g_value_get_string (value));
2082 case PROP_GICON_PRIMARY:
2083 gtk_entry_set_icon_from_gicon (entry,
2084 GTK_ENTRY_ICON_PRIMARY,
2085 g_value_get_object (value));
2088 case PROP_GICON_SECONDARY:
2089 gtk_entry_set_icon_from_gicon (entry,
2090 GTK_ENTRY_ICON_SECONDARY,
2091 g_value_get_object (value));
2094 case PROP_ACTIVATABLE_PRIMARY:
2095 gtk_entry_set_icon_activatable (entry,
2096 GTK_ENTRY_ICON_PRIMARY,
2097 g_value_get_boolean (value));
2100 case PROP_ACTIVATABLE_SECONDARY:
2101 gtk_entry_set_icon_activatable (entry,
2102 GTK_ENTRY_ICON_SECONDARY,
2103 g_value_get_boolean (value));
2106 case PROP_SENSITIVE_PRIMARY:
2107 gtk_entry_set_icon_sensitive (entry,
2108 GTK_ENTRY_ICON_PRIMARY,
2109 g_value_get_boolean (value));
2112 case PROP_SENSITIVE_SECONDARY:
2113 gtk_entry_set_icon_sensitive (entry,
2114 GTK_ENTRY_ICON_SECONDARY,
2115 g_value_get_boolean (value));
2118 case PROP_TOOLTIP_TEXT_PRIMARY:
2119 gtk_entry_set_icon_tooltip_text (entry,
2120 GTK_ENTRY_ICON_PRIMARY,
2121 g_value_get_string (value));
2124 case PROP_TOOLTIP_TEXT_SECONDARY:
2125 gtk_entry_set_icon_tooltip_text (entry,
2126 GTK_ENTRY_ICON_SECONDARY,
2127 g_value_get_string (value));
2130 case PROP_TOOLTIP_MARKUP_PRIMARY:
2131 gtk_entry_set_icon_tooltip_markup (entry,
2132 GTK_ENTRY_ICON_PRIMARY,
2133 g_value_get_string (value));
2136 case PROP_TOOLTIP_MARKUP_SECONDARY:
2137 gtk_entry_set_icon_tooltip_markup (entry,
2138 GTK_ENTRY_ICON_SECONDARY,
2139 g_value_get_string (value));
2142 case PROP_IM_MODULE:
2143 g_free (priv->im_module);
2144 priv->im_module = g_value_dup_string (value);
2145 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2146 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2149 case PROP_EDITING_CANCELED:
2150 priv->editing_canceled = g_value_get_boolean (value);
2153 case PROP_COMPLETION:
2154 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2157 case PROP_SCROLL_OFFSET:
2158 case PROP_CURSOR_POSITION:
2160 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2166 gtk_entry_get_property (GObject *object,
2171 GtkEntry *entry = GTK_ENTRY (object);
2172 GtkEntryPrivate *priv = entry->priv;
2177 g_value_set_object (value, gtk_entry_get_buffer (entry));
2180 case PROP_CURSOR_POSITION:
2181 g_value_set_int (value, priv->current_pos);
2184 case PROP_SELECTION_BOUND:
2185 g_value_set_int (value, priv->selection_bound);
2189 g_value_set_boolean (value, priv->editable);
2192 case PROP_MAX_LENGTH:
2193 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2196 case PROP_VISIBILITY:
2197 g_value_set_boolean (value, priv->visible);
2200 case PROP_HAS_FRAME:
2201 g_value_set_boolean (value, priv->has_frame);
2204 case PROP_INNER_BORDER:
2205 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2208 case PROP_INVISIBLE_CHAR:
2209 g_value_set_uint (value, priv->invisible_char);
2212 case PROP_ACTIVATES_DEFAULT:
2213 g_value_set_boolean (value, priv->activates_default);
2216 case PROP_WIDTH_CHARS:
2217 g_value_set_int (value, priv->width_chars);
2220 case PROP_SCROLL_OFFSET:
2221 g_value_set_int (value, priv->scroll_offset);
2225 g_value_set_string (value, gtk_entry_get_text (entry));
2229 g_value_set_float (value, gtk_entry_get_alignment (entry));
2232 case PROP_TRUNCATE_MULTILINE:
2233 g_value_set_boolean (value, priv->truncate_multiline);
2236 case PROP_SHADOW_TYPE:
2237 g_value_set_enum (value, priv->shadow_type);
2240 case PROP_OVERWRITE_MODE:
2241 g_value_set_boolean (value, priv->overwrite_mode);
2244 case PROP_TEXT_LENGTH:
2245 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2248 case PROP_INVISIBLE_CHAR_SET:
2249 g_value_set_boolean (value, priv->invisible_char_set);
2252 case PROP_IM_MODULE:
2253 g_value_set_string (value, priv->im_module);
2256 case PROP_CAPS_LOCK_WARNING:
2257 g_value_set_boolean (value, priv->caps_lock_warning);
2260 case PROP_PROGRESS_FRACTION:
2261 g_value_set_double (value, priv->progress_fraction);
2264 case PROP_PROGRESS_PULSE_STEP:
2265 g_value_set_double (value, priv->progress_pulse_fraction);
2268 case PROP_PLACEHOLDER_TEXT:
2269 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2272 case PROP_PIXBUF_PRIMARY:
2273 g_value_set_object (value,
2274 gtk_entry_get_icon_pixbuf (entry,
2275 GTK_ENTRY_ICON_PRIMARY));
2278 case PROP_PIXBUF_SECONDARY:
2279 g_value_set_object (value,
2280 gtk_entry_get_icon_pixbuf (entry,
2281 GTK_ENTRY_ICON_SECONDARY));
2284 case PROP_STOCK_PRIMARY:
2285 g_value_set_string (value,
2286 gtk_entry_get_icon_stock (entry,
2287 GTK_ENTRY_ICON_PRIMARY));
2290 case PROP_STOCK_SECONDARY:
2291 g_value_set_string (value,
2292 gtk_entry_get_icon_stock (entry,
2293 GTK_ENTRY_ICON_SECONDARY));
2296 case PROP_ICON_NAME_PRIMARY:
2297 g_value_set_string (value,
2298 gtk_entry_get_icon_name (entry,
2299 GTK_ENTRY_ICON_PRIMARY));
2302 case PROP_ICON_NAME_SECONDARY:
2303 g_value_set_string (value,
2304 gtk_entry_get_icon_name (entry,
2305 GTK_ENTRY_ICON_SECONDARY));
2308 case PROP_GICON_PRIMARY:
2309 g_value_set_object (value,
2310 gtk_entry_get_icon_gicon (entry,
2311 GTK_ENTRY_ICON_PRIMARY));
2314 case PROP_GICON_SECONDARY:
2315 g_value_set_object (value,
2316 gtk_entry_get_icon_gicon (entry,
2317 GTK_ENTRY_ICON_SECONDARY));
2320 case PROP_STORAGE_TYPE_PRIMARY:
2321 g_value_set_enum (value,
2322 gtk_entry_get_icon_storage_type (entry,
2323 GTK_ENTRY_ICON_PRIMARY));
2326 case PROP_STORAGE_TYPE_SECONDARY:
2327 g_value_set_enum (value,
2328 gtk_entry_get_icon_storage_type (entry,
2329 GTK_ENTRY_ICON_SECONDARY));
2332 case PROP_ACTIVATABLE_PRIMARY:
2333 g_value_set_boolean (value,
2334 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2337 case PROP_ACTIVATABLE_SECONDARY:
2338 g_value_set_boolean (value,
2339 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2342 case PROP_SENSITIVE_PRIMARY:
2343 g_value_set_boolean (value,
2344 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2347 case PROP_SENSITIVE_SECONDARY:
2348 g_value_set_boolean (value,
2349 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2352 case PROP_TOOLTIP_TEXT_PRIMARY:
2353 g_value_take_string (value,
2354 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2357 case PROP_TOOLTIP_TEXT_SECONDARY:
2358 g_value_take_string (value,
2359 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2362 case PROP_TOOLTIP_MARKUP_PRIMARY:
2363 g_value_take_string (value,
2364 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2367 case PROP_TOOLTIP_MARKUP_SECONDARY:
2368 g_value_take_string (value,
2369 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2372 case PROP_EDITING_CANCELED:
2373 g_value_set_boolean (value,
2374 priv->editing_canceled);
2377 case PROP_COMPLETION:
2378 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2382 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2388 find_invisible_char (GtkWidget *widget)
2390 PangoLayout *layout;
2391 PangoAttrList *attr_list;
2393 gunichar invisible_chars [] = {
2395 0x25cf, /* BLACK CIRCLE */
2396 0x2022, /* BULLET */
2397 0x2731, /* HEAVY ASTERISK */
2398 0x273a /* SIXTEEN POINTED ASTERISK */
2401 gtk_widget_style_get (widget,
2402 "invisible-char", &invisible_chars[0],
2405 layout = gtk_widget_create_pango_layout (widget, NULL);
2407 attr_list = pango_attr_list_new ();
2408 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2410 pango_layout_set_attributes (layout, attr_list);
2411 pango_attr_list_unref (attr_list);
2413 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2415 gchar text[7] = { 0, };
2418 len = g_unichar_to_utf8 (invisible_chars[i], text);
2419 pango_layout_set_text (layout, text, len);
2421 count = pango_layout_get_unknown_glyphs_count (layout);
2425 g_object_unref (layout);
2426 return invisible_chars[i];
2430 g_object_unref (layout);
2436 gtk_entry_init (GtkEntry *entry)
2438 GtkStyleContext *context;
2439 GtkEntryPrivate *priv;
2441 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2446 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2447 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2449 priv->editable = TRUE;
2450 priv->visible = TRUE;
2451 priv->dnd_position = -1;
2452 priv->width_chars = -1;
2453 priv->is_cell_renderer = FALSE;
2454 priv->editing_canceled = FALSE;
2455 priv->has_frame = TRUE;
2456 priv->truncate_multiline = FALSE;
2457 priv->shadow_type = GTK_SHADOW_IN;
2459 priv->caps_lock_warning = TRUE;
2460 priv->caps_lock_warning_shown = FALSE;
2461 priv->progress_fraction = 0.0;
2462 priv->progress_pulse_fraction = 0.1;
2464 gtk_drag_dest_set (GTK_WIDGET (entry),
2465 GTK_DEST_DEFAULT_HIGHLIGHT,
2467 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2468 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2470 /* This object is completely private. No external entity can gain a reference
2471 * to it; so we create it here and destroy it in finalize().
2473 priv->im_context = gtk_im_multicontext_new ();
2475 g_signal_connect (priv->im_context, "commit",
2476 G_CALLBACK (gtk_entry_commit_cb), entry);
2477 g_signal_connect (priv->im_context, "preedit-changed",
2478 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2479 g_signal_connect (priv->im_context, "retrieve-surrounding",
2480 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2481 g_signal_connect (priv->im_context, "delete-surrounding",
2482 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2484 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2485 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2487 gtk_entry_update_cached_style_values (entry);
2491 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2492 GtkStyleContext *context,
2493 GtkEntryIconPosition icon_pos)
2495 GtkEntryPrivate *priv = entry->priv;
2496 EntryIconInfo *icon_info = priv->icons[icon_pos];
2498 GtkStateFlags state;
2500 widget = GTK_WIDGET (entry);
2501 state = gtk_widget_get_state_flags (widget);
2503 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2505 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2506 state |= GTK_STATE_FLAG_INSENSITIVE;
2507 else if (icon_info->prelight)
2508 state |= GTK_STATE_FLAG_PRELIGHT;
2510 gtk_style_context_save (context);
2512 gtk_style_context_set_state (context, state);
2513 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2515 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2517 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2518 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2520 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2524 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2525 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2527 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2532 get_icon_width (GtkEntry *entry,
2533 GtkEntryIconPosition icon_pos)
2535 GtkEntryPrivate *priv = entry->priv;
2536 EntryIconInfo *icon_info = priv->icons[icon_pos];
2537 GtkStyleContext *context;
2544 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2545 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2546 gtk_style_context_get_padding (context, 0, &padding);
2548 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2550 gtk_style_context_restore (context);
2553 width += padding.left + padding.right;
2559 get_icon_allocations (GtkEntry *entry,
2560 GtkAllocation *primary,
2561 GtkAllocation *secondary)
2564 GtkEntryPrivate *priv = entry->priv;
2565 gint x, y, width, height;
2567 get_text_area_size (entry, &x, &y, &width, &height);
2569 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2570 y += priv->focus_width;
2573 primary->height = height;
2574 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2577 secondary->height = height;
2578 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2580 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2582 primary->x = x + width - primary->width;
2588 secondary->x = x + width - secondary->width;
2594 begin_change (GtkEntry *entry)
2596 GtkEntryPrivate *priv = entry->priv;
2598 priv->change_count++;
2600 g_object_freeze_notify (G_OBJECT (entry));
2604 end_change (GtkEntry *entry)
2606 GtkEditable *editable = GTK_EDITABLE (entry);
2607 GtkEntryPrivate *priv = entry->priv;
2609 g_return_if_fail (priv->change_count > 0);
2611 g_object_thaw_notify (G_OBJECT (entry));
2613 priv->change_count--;
2615 if (priv->change_count == 0)
2617 if (priv->real_changed)
2619 g_signal_emit_by_name (editable, "changed");
2620 priv->real_changed = FALSE;
2626 emit_changed (GtkEntry *entry)
2628 GtkEditable *editable = GTK_EDITABLE (entry);
2629 GtkEntryPrivate *priv = entry->priv;
2631 if (priv->change_count == 0)
2632 g_signal_emit_by_name (editable, "changed");
2634 priv->real_changed = TRUE;
2638 gtk_entry_destroy (GtkWidget *widget)
2640 GtkEntry *entry = GTK_ENTRY (widget);
2641 GtkEntryPrivate *priv = entry->priv;
2643 priv->current_pos = priv->selection_bound = 0;
2644 _gtk_entry_reset_im_context (entry);
2645 gtk_entry_reset_layout (entry);
2647 if (priv->blink_timeout)
2649 g_source_remove (priv->blink_timeout);
2650 priv->blink_timeout = 0;
2653 if (priv->recompute_idle)
2655 g_source_remove (priv->recompute_idle);
2656 priv->recompute_idle = 0;
2659 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2663 gtk_entry_dispose (GObject *object)
2665 GtkEntry *entry = GTK_ENTRY (object);
2666 GtkEntryPrivate *priv = entry->priv;
2669 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2670 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2671 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2672 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2676 buffer_disconnect_signals (entry);
2677 g_object_unref (priv->buffer);
2678 priv->buffer = NULL;
2681 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2682 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2683 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2684 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2688 gtk_entry_finalize (GObject *object)
2690 GtkEntry *entry = GTK_ENTRY (object);
2691 GtkEntryPrivate *priv = entry->priv;
2692 EntryIconInfo *icon_info = NULL;
2695 for (i = 0; i < MAX_ICONS; i++)
2697 if ((icon_info = priv->icons[i]) != NULL)
2699 if (icon_info->target_list != NULL)
2701 gtk_target_list_unref (icon_info->target_list);
2702 icon_info->target_list = NULL;
2705 g_clear_object (&icon_info->icon_helper);
2707 g_slice_free (EntryIconInfo, icon_info);
2708 priv->icons[i] = NULL;
2712 gtk_entry_set_completion (entry, NULL);
2714 if (priv->cached_layout)
2715 g_object_unref (priv->cached_layout);
2717 g_object_unref (priv->im_context);
2719 if (priv->blink_timeout)
2720 g_source_remove (priv->blink_timeout);
2722 if (priv->recompute_idle)
2723 g_source_remove (priv->recompute_idle);
2725 g_free (priv->placeholder_text);
2726 g_free (priv->im_module);
2728 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2732 gtk_entry_get_display_mode (GtkEntry *entry)
2734 GtkEntryPrivate *priv = entry->priv;
2737 return DISPLAY_NORMAL;
2739 if (priv->invisible_char == 0 && priv->invisible_char_set)
2740 return DISPLAY_BLANK;
2742 return DISPLAY_INVISIBLE;
2746 gtk_entry_get_display_text (GtkEntry *entry,
2750 GtkEntryPasswordHint *password_hint;
2751 GtkEntryPrivate *priv;
2752 gunichar invisible_char;
2763 text = gtk_entry_buffer_get_text (get_buffer (entry));
2764 length = gtk_entry_buffer_get_length (get_buffer (entry));
2768 if (start_pos > length)
2771 if (end_pos <= start_pos)
2772 return g_strdup ("");
2773 else if (priv->visible)
2775 start = g_utf8_offset_to_pointer (text, start_pos);
2776 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2777 return g_strndup (start, end - start);
2781 str = g_string_sized_new (length * 2);
2783 /* Figure out what our invisible char is and encode it */
2784 if (!priv->invisible_char)
2785 invisible_char = priv->invisible_char_set ? ' ' : '*';
2787 invisible_char = priv->invisible_char;
2788 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2791 * Add hidden characters for each character in the text
2792 * buffer. If there is a password hint, then keep that
2793 * character visible.
2796 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2797 for (i = start_pos; i < end_pos; ++i)
2799 if (password_hint && i == password_hint->position)
2801 start = g_utf8_offset_to_pointer (text, i);
2802 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2806 g_string_append_len (str, char_str, char_len);
2810 return g_string_free (str, FALSE);
2815 update_cursors (GtkWidget *widget)
2817 GtkEntry *entry = GTK_ENTRY (widget);
2818 GtkEntryPrivate *priv = entry->priv;
2819 EntryIconInfo *icon_info = NULL;
2820 GdkDisplay *display;
2824 for (i = 0; i < MAX_ICONS; i++)
2826 if ((icon_info = priv->icons[i]) != NULL)
2828 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2829 icon_info->window != NULL)
2830 gdk_window_show_unraised (icon_info->window);
2832 /* The icon windows are not children of the visible entry window,
2833 * thus we can't just inherit the xterm cursor. Slight complication
2834 * here is that for the entry, insensitive => arrow cursor, but for
2835 * an icon in a sensitive entry, insensitive => xterm cursor.
2837 if (gtk_widget_is_sensitive (widget) &&
2838 (icon_info->insensitive ||
2839 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2841 display = gtk_widget_get_display (widget);
2842 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2843 gdk_window_set_cursor (icon_info->window, cursor);
2844 g_object_unref (cursor);
2848 gdk_window_set_cursor (icon_info->window, NULL);
2855 realize_icon_info (GtkWidget *widget,
2856 GtkEntryIconPosition icon_pos)
2858 GtkEntry *entry = GTK_ENTRY (widget);
2859 GtkEntryPrivate *priv = entry->priv;
2860 EntryIconInfo *icon_info = priv->icons[icon_pos];
2861 GdkWindowAttr attributes;
2862 gint attributes_mask;
2864 g_return_if_fail (icon_info != NULL);
2868 attributes.width = 1;
2869 attributes.height = 1;
2870 attributes.window_type = GDK_WINDOW_CHILD;
2871 attributes.wclass = GDK_INPUT_ONLY;
2872 attributes.event_mask = gtk_widget_get_events (widget);
2873 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2874 GDK_BUTTON_RELEASE_MASK |
2875 GDK_BUTTON1_MOTION_MASK |
2876 GDK_BUTTON3_MOTION_MASK |
2877 GDK_POINTER_MOTION_HINT_MASK |
2878 GDK_POINTER_MOTION_MASK |
2879 GDK_ENTER_NOTIFY_MASK |
2880 GDK_LEAVE_NOTIFY_MASK);
2881 attributes_mask = GDK_WA_X | GDK_WA_Y;
2883 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2886 gdk_window_set_user_data (icon_info->window, widget);
2888 gtk_widget_queue_resize (widget);
2891 static EntryIconInfo*
2892 construct_icon_info (GtkWidget *widget,
2893 GtkEntryIconPosition icon_pos)
2895 GtkEntry *entry = GTK_ENTRY (widget);
2896 GtkEntryPrivate *priv = entry->priv;
2897 EntryIconInfo *icon_info;
2899 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2901 icon_info = g_slice_new0 (EntryIconInfo);
2902 priv->icons[icon_pos] = icon_info;
2904 icon_info->icon_helper = _gtk_icon_helper_new ();
2906 if (gtk_widget_get_realized (widget))
2907 realize_icon_info (widget, icon_pos);
2913 gtk_entry_map (GtkWidget *widget)
2915 GtkEntry *entry = GTK_ENTRY (widget);
2916 GtkEntryPrivate *priv = entry->priv;
2917 EntryIconInfo *icon_info = NULL;
2920 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2922 gdk_window_show (priv->text_area);
2924 for (i = 0; i < MAX_ICONS; i++)
2926 if ((icon_info = priv->icons[i]) != NULL)
2928 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2929 icon_info->window != NULL)
2930 gdk_window_show (icon_info->window);
2934 update_cursors (widget);
2938 gtk_entry_unmap (GtkWidget *widget)
2940 GtkEntry *entry = GTK_ENTRY (widget);
2941 GtkEntryPrivate *priv = entry->priv;
2942 EntryIconInfo *icon_info = NULL;
2945 for (i = 0; i < MAX_ICONS; i++)
2947 if ((icon_info = priv->icons[i]) != NULL)
2949 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2950 icon_info->window != NULL)
2951 gdk_window_hide (icon_info->window);
2955 gdk_window_hide (priv->text_area);
2957 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2961 gtk_entry_realize (GtkWidget *widget)
2964 GtkEntryPrivate *priv;
2965 EntryIconInfo *icon_info;
2967 GdkWindowAttr attributes;
2968 gint attributes_mask;
2969 gint frame_x, frame_y;
2972 gtk_widget_set_realized (widget, TRUE);
2973 window = gtk_widget_get_parent_window (widget);
2974 gtk_widget_set_window (widget, window);
2975 g_object_ref (window);
2977 entry = GTK_ENTRY (widget);
2980 attributes.window_type = GDK_WINDOW_CHILD;
2981 attributes.wclass = GDK_INPUT_ONLY;
2982 attributes.event_mask = gtk_widget_get_events (widget);
2983 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2984 GDK_BUTTON_RELEASE_MASK |
2985 GDK_BUTTON1_MOTION_MASK |
2986 GDK_BUTTON3_MOTION_MASK |
2987 GDK_POINTER_MOTION_HINT_MASK |
2988 GDK_POINTER_MOTION_MASK |
2989 GDK_ENTER_NOTIFY_MASK |
2990 GDK_LEAVE_NOTIFY_MASK);
2991 attributes_mask = GDK_WA_X | GDK_WA_Y;
2993 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2995 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2996 attributes.x += frame_x;
2997 attributes.y += frame_y;
2999 if (gtk_widget_is_sensitive (widget))
3001 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3002 attributes_mask |= GDK_WA_CURSOR;
3005 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3009 gdk_window_set_user_data (priv->text_area, entry);
3011 if (attributes_mask & GDK_WA_CURSOR)
3012 g_object_unref (attributes.cursor);
3014 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3016 gtk_entry_adjust_scroll (entry);
3017 gtk_entry_update_primary_selection (entry);
3020 /* If the icon positions are already setup, create their windows.
3021 * Otherwise if they don't exist yet, then construct_icon_info()
3022 * will create the windows once the widget is already realized.
3024 for (i = 0; i < MAX_ICONS; i++)
3026 if ((icon_info = priv->icons[i]) != NULL)
3028 if (icon_info->window == NULL)
3029 realize_icon_info (widget, i);
3035 gtk_entry_unrealize (GtkWidget *widget)
3037 GtkEntry *entry = GTK_ENTRY (widget);
3038 GtkEntryPrivate *priv = entry->priv;
3039 GtkClipboard *clipboard;
3040 EntryIconInfo *icon_info;
3043 gtk_entry_reset_layout (entry);
3045 gtk_im_context_set_client_window (priv->im_context, NULL);
3047 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3048 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3049 gtk_clipboard_clear (clipboard);
3051 if (priv->text_area)
3053 gdk_window_set_user_data (priv->text_area, NULL);
3054 gdk_window_destroy (priv->text_area);
3055 priv->text_area = NULL;
3058 if (priv->popup_menu)
3060 gtk_widget_destroy (priv->popup_menu);
3061 priv->popup_menu = NULL;
3064 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3066 for (i = 0; i < MAX_ICONS; i++)
3068 if ((icon_info = priv->icons[i]) != NULL)
3070 if (icon_info->window != NULL)
3072 gdk_window_destroy (icon_info->window);
3073 icon_info->window = NULL;
3080 _gtk_entry_get_borders (GtkEntry *entry,
3081 GtkBorder *border_out)
3083 GtkEntryPrivate *priv = entry->priv;
3084 GtkWidget *widget = GTK_WIDGET (entry);
3085 GtkBorder tmp = { 0, 0, 0, 0 };
3086 GtkStyleContext *context;
3088 context = gtk_widget_get_style_context (widget);
3089 gtk_style_context_get_padding (context, 0, &tmp);
3091 if (priv->has_frame)
3095 gtk_style_context_get_border (context, 0, &border);
3096 tmp.top += border.top;
3097 tmp.right += border.right;
3098 tmp.bottom += border.bottom;
3099 tmp.left += border.left;
3102 if (!priv->interior_focus)
3104 tmp.top += priv->focus_width;
3105 tmp.right += priv->focus_width;
3106 tmp.bottom += priv->focus_width;
3107 tmp.left += priv->focus_width;
3110 if (border_out != NULL)
3115 gtk_entry_get_preferred_width (GtkWidget *widget,
3119 GtkEntry *entry = GTK_ENTRY (widget);
3120 GtkEntryPrivate *priv = entry->priv;
3121 PangoFontMetrics *metrics;
3123 PangoContext *context;
3124 GtkStyleContext *style_context;
3125 GtkStateFlags state;
3126 gint icon_widths = 0;
3130 context = gtk_widget_get_pango_context (widget);
3132 style_context = gtk_widget_get_style_context (widget);
3133 state = gtk_widget_get_state_flags (widget);
3135 metrics = pango_context_get_metrics (context,
3136 gtk_style_context_get_font (style_context, state),
3137 pango_context_get_language (context));
3139 _gtk_entry_get_borders (entry, &borders);
3141 if (priv->width_chars < 0)
3142 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3145 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3146 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3147 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3149 width = char_pixels * priv->width_chars + borders.left + borders.right;
3152 for (i = 0; i < MAX_ICONS; i++)
3154 icon_width = get_icon_width (entry, i);
3156 icon_widths += icon_width;
3159 if (icon_widths > width)
3160 width += icon_widths;
3162 pango_font_metrics_unref (metrics);
3169 gtk_entry_get_preferred_height (GtkWidget *widget,
3173 GtkEntry *entry = GTK_ENTRY (widget);
3174 GtkEntryPrivate *priv = entry->priv;
3175 PangoFontMetrics *metrics;
3177 GtkStyleContext *style_context;
3178 GtkStateFlags state;
3179 PangoContext *context;
3182 context = gtk_widget_get_pango_context (widget);
3184 style_context = gtk_widget_get_style_context (widget);
3185 state = gtk_widget_get_state_flags (widget);
3187 metrics = pango_context_get_metrics (context,
3188 gtk_style_context_get_font (style_context, state),
3189 pango_context_get_language (context));
3191 priv->ascent = pango_font_metrics_get_ascent (metrics);
3192 priv->descent = pango_font_metrics_get_descent (metrics);
3194 _gtk_entry_get_borders (entry, &borders);
3196 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3198 pango_font_metrics_unref (metrics);
3205 place_windows (GtkEntry *entry)
3207 GtkWidget *widget = GTK_WIDGET (entry);
3208 GtkEntryPrivate *priv = entry->priv;
3209 gint x, y, width, height;
3210 gint frame_x, frame_y;
3211 GtkAllocation primary;
3212 GtkAllocation secondary;
3213 EntryIconInfo *icon_info = NULL;
3215 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3216 get_text_area_size (entry, &x, &y, &width, &height);
3217 get_icon_allocations (entry, &primary, &secondary);
3219 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3220 y += priv->focus_width;
3222 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3223 x += secondary.width;
3226 width -= primary.width + secondary.width;
3230 primary.x += frame_x;
3231 primary.y += frame_y;
3232 secondary.x += frame_x;
3233 secondary.y += frame_y;
3235 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3236 gdk_window_move_resize (icon_info->window,
3237 primary.x, primary.y,
3238 primary.width, primary.height);
3240 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3241 gdk_window_move_resize (icon_info->window,
3242 secondary.x, secondary.y,
3243 secondary.width, secondary.height);
3245 gdk_window_move_resize (priv->text_area, x, y, width, height);
3249 gtk_entry_get_text_area_size (GtkEntry *entry,
3255 GtkEntryPrivate *priv = entry->priv;
3256 GtkWidget *widget = GTK_WIDGET (entry);
3257 GtkAllocation allocation;
3258 GtkRequisition requisition;
3263 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3264 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3266 gtk_widget_get_allocation (widget, &allocation);
3267 _gtk_entry_get_borders (entry, &borders);
3269 if (gtk_widget_get_realized (widget))
3270 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3272 frame_height = req_height;
3274 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3275 frame_height -= 2 * priv->focus_width;
3281 *y = floor ((frame_height - req_height) / 2) + borders.top;
3284 *width = allocation.width - borders.left - borders.right;
3287 *height = req_height - borders.top - borders.bottom;
3291 get_text_area_size (GtkEntry *entry,
3297 GtkEntryClass *class;
3299 g_return_if_fail (GTK_IS_ENTRY (entry));
3301 class = GTK_ENTRY_GET_CLASS (entry);
3303 if (class->get_text_area_size)
3304 class->get_text_area_size (entry, x, y, width, height);
3309 get_frame_size (GtkEntry *entry,
3310 gboolean relative_to_window,
3316 GtkEntryPrivate *priv = entry->priv;
3317 GtkAllocation allocation;
3318 GtkRequisition requisition;
3319 GtkWidget *widget = GTK_WIDGET (entry);
3322 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3324 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3326 gtk_widget_get_allocation (widget, &allocation);
3329 *x = relative_to_window ? allocation.x : 0;
3333 if (priv->is_cell_renderer)
3336 *y = (allocation.height - req_height) / 2;
3338 if (relative_to_window)
3343 *width = allocation.width;
3347 if (priv->is_cell_renderer)
3348 *height = allocation.height;
3350 *height = req_height;
3355 gtk_entry_size_allocate (GtkWidget *widget,
3356 GtkAllocation *allocation)
3358 GtkEntry *entry = GTK_ENTRY (widget);
3360 gtk_widget_set_allocation (widget, allocation);
3362 if (gtk_widget_get_realized (widget))
3364 GtkEntryCompletion* completion;
3366 place_windows (entry);
3367 gtk_entry_recompute (entry);
3369 completion = gtk_entry_get_completion (entry);
3370 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3371 _gtk_entry_completion_resize_popup (completion);
3376 should_prelight (GtkEntry *entry,
3377 GtkEntryIconPosition icon_pos)
3379 GtkEntryPrivate *priv = entry->priv;
3380 EntryIconInfo *icon_info = priv->icons[icon_pos];
3386 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3389 if (icon_info->pressed)
3392 gtk_widget_style_get (GTK_WIDGET (entry),
3393 "icon-prelight", &prelight,
3400 draw_icon (GtkWidget *widget,
3402 GtkEntryIconPosition icon_pos)
3404 GtkEntry *entry = GTK_ENTRY (widget);
3405 GtkEntryPrivate *priv = entry->priv;
3406 EntryIconInfo *icon_info = priv->icons[icon_pos];
3407 gint x, y, width, height, pix_width, pix_height;
3408 GtkStyleContext *context;
3414 width = gdk_window_get_width (icon_info->window);
3415 height = gdk_window_get_height (icon_info->window);
3417 /* size_allocate hasn't been called yet. These are the default values.
3419 if (width == 1 || height == 1)
3423 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3425 context = gtk_widget_get_style_context (widget);
3426 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3427 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3428 &pix_width, &pix_height);
3429 gtk_style_context_get_padding (context, 0, &padding);
3431 x = MAX (0, padding.left);
3432 y = MAX (0, (height - pix_height) / 2);
3434 _gtk_icon_helper_draw (icon_info->icon_helper,
3438 gtk_style_context_restore (context);
3444 gtk_entry_draw_frame (GtkWidget *widget,
3445 GtkStyleContext *context,
3448 GtkEntry *entry = GTK_ENTRY (widget);
3449 GtkEntryPrivate *priv = entry->priv;
3450 gint x = 0, y = 0, width, height;
3451 gint frame_x, frame_y;
3455 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3457 cairo_translate (cr, frame_x, frame_y);
3459 /* Fix a problem with some themes which assume that entry->text_area's
3460 * width equals widget->window's width
3461 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3462 if (GTK_IS_SPIN_BUTTON (widget))
3466 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3467 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3470 width += borders.left + borders.right;
3473 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3475 x += priv->focus_width;
3476 y += priv->focus_width;
3477 width -= 2 * priv->focus_width;
3478 height -= 2 * priv->focus_width;
3481 gtk_render_background (context, cr,
3482 x, y, width, height);
3484 if (priv->has_frame)
3485 gtk_render_frame (context, cr,
3486 x, y, width, height);
3488 gtk_entry_draw_progress (widget, context, cr);
3490 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3492 x -= priv->focus_width;
3493 y -= priv->focus_width;
3494 width += 2 * priv->focus_width;
3495 height += 2 * priv->focus_width;
3497 gtk_render_focus (context, cr,
3498 0, 0, width, height);
3505 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3506 GtkStyleContext *context)
3508 GtkEntryPrivate *private = entry->priv;
3510 gtk_style_context_save (context);
3511 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3512 if (private->progress_pulse_mode)
3513 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3517 get_progress_area (GtkWidget *widget,
3523 GtkEntry *entry = GTK_ENTRY (widget);
3524 GtkEntryPrivate *private = entry->priv;
3525 GtkStyleContext *context;
3528 get_frame_size (GTK_ENTRY (widget), FALSE, NULL, NULL, width, height);
3532 if (!private->interior_focus)
3534 *x -= private->focus_width;
3535 *y -= private->focus_width;
3536 *width += 2 * private->focus_width;
3537 *height += 2 * private->focus_width;
3540 context = gtk_widget_get_style_context (widget);
3541 gtk_entry_prepare_context_for_progress (entry, context);
3542 gtk_style_context_get_margin (context, 0, &margin);
3544 gtk_style_context_restore (context);
3548 *width -= margin.left + margin.right;
3549 *height -= margin.top + margin.bottom;
3551 if (private->progress_pulse_mode)
3553 gdouble value = private->progress_pulse_current;
3555 *x += (gint) floor(value * (*width));
3556 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3558 else if (private->progress_fraction > 0)
3560 gdouble value = private->progress_fraction;
3562 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3566 bar_width = floor(value * (*width) + 0.5);
3567 *x += *width - bar_width;
3572 *width = (gint) floor(value * (*width) + 0.5);
3583 gtk_entry_draw_progress (GtkWidget *widget,
3584 GtkStyleContext *context,
3587 GtkEntry *entry = GTK_ENTRY (widget);
3588 GtkEntryPrivate *private = entry->priv;
3589 gint x, y, width, height;
3591 get_progress_area (widget, &x, &y, &width, &height);
3593 if ((width <= 0) || (height <= 0))
3596 gtk_entry_prepare_context_for_progress (entry, context);
3597 gtk_render_activity (context, cr,
3598 x, y, width, height);
3600 gtk_style_context_restore (context);
3604 gtk_entry_draw (GtkWidget *widget,
3607 GtkEntry *entry = GTK_ENTRY (widget);
3608 GtkStyleContext *context;
3609 GtkEntryPrivate *priv = entry->priv;
3612 context = gtk_widget_get_style_context (widget);
3614 /* Draw entry_bg, shadow, progress and focus */
3615 gtk_entry_draw_frame (widget, context, cr);
3617 /* Draw text and cursor */
3620 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3622 if (priv->dnd_position != -1)
3623 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3625 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3627 /* When no text is being displayed at all, don't show the cursor */
3628 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3629 gtk_widget_has_focus (widget) &&
3630 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3631 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3636 for (i = 0; i < MAX_ICONS; i++)
3638 EntryIconInfo *icon_info = priv->icons[i];
3640 if (icon_info != NULL)
3641 draw_icon (widget, cr, i);
3648 gtk_entry_enter_notify (GtkWidget *widget,
3649 GdkEventCrossing *event)
3651 GtkEntry *entry = GTK_ENTRY (widget);
3652 GtkEntryPrivate *priv = entry->priv;
3655 for (i = 0; i < MAX_ICONS; i++)
3657 EntryIconInfo *icon_info = priv->icons[i];
3659 if (icon_info != NULL && event->window == icon_info->window)
3661 if (should_prelight (entry, i))
3663 icon_info->prelight = TRUE;
3664 gtk_widget_queue_draw (widget);
3675 gtk_entry_leave_notify (GtkWidget *widget,
3676 GdkEventCrossing *event)
3678 GtkEntry *entry = GTK_ENTRY (widget);
3679 GtkEntryPrivate *priv = entry->priv;
3682 for (i = 0; i < MAX_ICONS; i++)
3684 EntryIconInfo *icon_info = priv->icons[i];
3686 if (icon_info != NULL && event->window == icon_info->window)
3688 /* a grab means that we may never see the button release */
3689 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3690 icon_info->pressed = FALSE;
3692 if (should_prelight (entry, i))
3694 icon_info->prelight = FALSE;
3695 gtk_widget_queue_draw (widget);
3706 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3710 gint start_char, end_char;
3712 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3714 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3715 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3716 const char *text = pango_layout_get_text (layout);
3717 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3718 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3719 gint real_n_ranges, i;
3721 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3727 for (i = 0; i < real_n_ranges; ++i)
3729 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3730 r[2 * i] = r[2 * i] / PANGO_SCALE;
3735 *n_ranges = real_n_ranges;
3747 in_selection (GtkEntry *entry,
3752 gint retval = FALSE;
3754 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3756 for (i = 0; i < n_ranges; ++i)
3758 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3770 gtk_entry_button_press (GtkWidget *widget,
3771 GdkEventButton *event)
3773 GtkEntry *entry = GTK_ENTRY (widget);
3774 GtkEditable *editable = GTK_EDITABLE (widget);
3775 GtkEntryPrivate *priv = entry->priv;
3776 EntryIconInfo *icon_info = NULL;
3778 gint sel_start, sel_end;
3781 for (i = 0; i < MAX_ICONS; i++)
3783 icon_info = priv->icons[i];
3785 if (!icon_info || icon_info->insensitive)
3788 if (event->window == icon_info->window)
3790 if (should_prelight (entry, i))
3792 icon_info->prelight = FALSE;
3793 gtk_widget_queue_draw (widget);
3796 priv->start_x = event->x;
3797 priv->start_y = event->y;
3798 icon_info->pressed = TRUE;
3800 if (!icon_info->nonactivatable)
3801 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3807 if (event->window != priv->text_area ||
3808 (priv->button && event->button != priv->button))
3811 gtk_entry_reset_blink_time (entry);
3813 priv->button = event->button;
3815 if (!gtk_widget_has_focus (widget))
3817 priv->in_click = TRUE;
3818 gtk_widget_grab_focus (widget);
3819 priv->in_click = FALSE;
3822 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3824 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3826 gtk_entry_do_popup (entry, event);
3827 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3831 else if (event->button == GDK_BUTTON_PRIMARY)
3833 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3835 priv->select_words = FALSE;
3836 priv->select_lines = FALSE;
3839 gtk_widget_get_modifier_mask (widget,
3840 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3842 _gtk_entry_reset_im_context (entry);
3844 if (!have_selection) /* select from the current position to the clicked position */
3845 sel_start = sel_end = priv->current_pos;
3847 if (tmp_pos > sel_start && tmp_pos < sel_end)
3849 /* Truncate current selection, but keep it as big as possible */
3850 if (tmp_pos - sel_start > sel_end - tmp_pos)
3851 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3853 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3857 gboolean extend_to_left;
3860 /* Figure out what click selects and extend current selection */
3861 switch (event->type)
3863 case GDK_BUTTON_PRESS:
3864 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3867 case GDK_2BUTTON_PRESS:
3868 priv->select_words = TRUE;
3869 gtk_entry_select_word (entry);
3872 case GDK_3BUTTON_PRESS:
3873 priv->select_lines = TRUE;
3874 gtk_entry_select_line (entry);
3881 start = MIN (priv->current_pos, priv->selection_bound);
3882 start = MIN (sel_start, start);
3884 end = MAX (priv->current_pos, priv->selection_bound);
3885 end = MAX (sel_end, end);
3887 if (tmp_pos == sel_start || tmp_pos == sel_end)
3888 extend_to_left = (tmp_pos == start);
3890 extend_to_left = (end == sel_end);
3893 gtk_entry_set_positions (entry, start, end);
3895 gtk_entry_set_positions (entry, end, start);
3898 else /* no shift key */
3899 switch (event->type)
3901 case GDK_BUTTON_PRESS:
3902 if (in_selection (entry, event->x + priv->scroll_offset))
3904 /* Click inside the selection - we'll either start a drag, or
3905 * clear the selection
3907 priv->in_drag = TRUE;
3908 priv->drag_start_x = event->x + priv->scroll_offset;
3909 priv->drag_start_y = event->y;
3912 gtk_editable_set_position (editable, tmp_pos);
3915 case GDK_2BUTTON_PRESS:
3916 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3917 * receiving a GDK_2BUTTON_PRESS so we need to reset
3918 * priv->in_drag which may have been set above
3920 priv->in_drag = FALSE;
3921 priv->select_words = TRUE;
3922 gtk_entry_select_word (entry);
3925 case GDK_3BUTTON_PRESS:
3926 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3927 * receiving a GDK_3BUTTON_PRESS so we need to reset
3928 * priv->in_drag which may have been set above
3930 priv->in_drag = FALSE;
3931 priv->select_lines = TRUE;
3932 gtk_entry_select_line (entry);
3941 else if (event->button == GDK_BUTTON_MIDDLE && event->type == GDK_BUTTON_PRESS)
3945 priv->insert_pos = tmp_pos;
3946 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3951 gtk_widget_error_bell (widget);
3959 gtk_entry_button_release (GtkWidget *widget,
3960 GdkEventButton *event)
3962 GtkEntry *entry = GTK_ENTRY (widget);
3963 GtkEntryPrivate *priv = entry->priv;
3964 EntryIconInfo *icon_info = NULL;
3967 for (i = 0; i < MAX_ICONS; i++)
3969 icon_info = priv->icons[i];
3971 if (!icon_info || icon_info->insensitive)
3974 if (event->window == icon_info->window)
3976 icon_info->pressed = FALSE;
3978 if (should_prelight (entry, i) &&
3979 event->x >= 0 && event->y >= 0 &&
3980 event->x < gdk_window_get_width (icon_info->window) &&
3981 event->y < gdk_window_get_height (icon_info->window))
3983 icon_info->prelight = TRUE;
3984 gtk_widget_queue_draw (widget);
3987 if (!icon_info->nonactivatable)
3988 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3994 if (event->window != priv->text_area || priv->button != event->button)
3999 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4001 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4008 gtk_entry_update_primary_selection (entry);
4014 _gtk_entry_get_selected_text (GtkEntry *entry)
4016 GtkEditable *editable = GTK_EDITABLE (entry);
4017 gint start_text, end_text;
4020 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4021 text = gtk_editable_get_chars (editable, start_text, end_text);
4027 gtk_entry_motion_notify (GtkWidget *widget,
4028 GdkEventMotion *event)
4030 GtkEntry *entry = GTK_ENTRY (widget);
4031 GtkEntryPrivate *priv = entry->priv;
4032 EntryIconInfo *icon_info = NULL;
4036 for (i = 0; i < MAX_ICONS; i++)
4038 icon_info = priv->icons[i];
4040 if (!icon_info || icon_info->insensitive)
4043 if (event->window == icon_info->window)
4045 if (icon_info->pressed &&
4046 icon_info->target_list != NULL &&
4047 gtk_drag_check_threshold (widget,
4053 icon_info->in_drag = TRUE;
4054 icon_info->pressed = FALSE;
4055 gtk_drag_begin (widget,
4056 icon_info->target_list,
4066 if (priv->mouse_cursor_obscured)
4070 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4071 gdk_window_set_cursor (priv->text_area, cursor);
4072 g_object_unref (cursor);
4073 priv->mouse_cursor_obscured = FALSE;
4076 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4079 if (priv->select_lines)
4082 gdk_event_request_motions (event);
4086 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4087 gtk_drag_check_threshold (widget,
4088 priv->drag_start_x, priv->drag_start_y,
4089 event->x + priv->scroll_offset, event->y))
4091 GdkDragContext *context;
4092 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4093 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4095 cairo_surface_t *surface;
4097 gtk_target_list_add_text_targets (target_list, 0);
4099 text = _gtk_entry_get_selected_text (entry);
4100 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4102 context = gtk_drag_begin (widget, target_list, actions,
4103 priv->button, (GdkEvent *)event);
4106 gtk_drag_set_icon_surface (context, surface);
4108 gtk_drag_set_icon_default (context);
4111 cairo_surface_destroy (surface);
4114 priv->in_drag = FALSE;
4117 gtk_target_list_unref (target_list);
4124 else if (event->y >= gdk_window_get_height (priv->text_area))
4125 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4127 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4129 if (priv->select_words)
4132 gint old_min, old_max;
4135 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4136 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4138 pos = priv->current_pos;
4139 bound = priv->selection_bound;
4141 old_min = MIN(priv->current_pos, priv->selection_bound);
4142 old_max = MAX(priv->current_pos, priv->selection_bound);
4149 else if (old_max < max)
4154 else if (pos == old_min)
4156 if (priv->current_pos != min)
4161 if (priv->current_pos != max)
4165 gtk_entry_set_positions (entry, pos, bound);
4168 gtk_entry_set_positions (entry, tmp_pos, -1);
4175 set_invisible_cursor (GdkWindow *window)
4177 GdkDisplay *display;
4180 display = gdk_window_get_display (window);
4181 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4183 gdk_window_set_cursor (window, cursor);
4185 g_object_unref (cursor);
4189 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4191 GtkEntryPrivate *priv = entry->priv;
4193 if (priv->mouse_cursor_obscured)
4196 set_invisible_cursor (priv->text_area);
4198 priv->mouse_cursor_obscured = TRUE;
4202 gtk_entry_key_press (GtkWidget *widget,
4205 GtkEntry *entry = GTK_ENTRY (widget);
4206 GtkEntryPrivate *priv = entry->priv;
4208 gtk_entry_reset_blink_time (entry);
4209 gtk_entry_pend_cursor_blink (entry);
4213 if (gtk_im_context_filter_keypress (priv->im_context, event))
4215 gtk_entry_obscure_mouse_cursor (entry);
4216 priv->need_im_reset = TRUE;
4221 if (event->keyval == GDK_KEY_Return ||
4222 event->keyval == GDK_KEY_KP_Enter ||
4223 event->keyval == GDK_KEY_ISO_Enter ||
4224 event->keyval == GDK_KEY_Escape)
4226 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4228 if (completion && completion->priv->completion_timeout)
4230 g_source_remove (completion->priv->completion_timeout);
4231 completion->priv->completion_timeout = 0;
4234 _gtk_entry_reset_im_context (entry);
4237 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4238 /* Activate key bindings
4242 if (!priv->editable && event->length)
4243 gtk_widget_error_bell (widget);
4249 gtk_entry_key_release (GtkWidget *widget,
4252 GtkEntry *entry = GTK_ENTRY (widget);
4253 GtkEntryPrivate *priv = entry->priv;
4257 if (gtk_im_context_filter_keypress (priv->im_context, event))
4259 priv->need_im_reset = TRUE;
4264 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4268 gtk_entry_focus_in (GtkWidget *widget,
4269 GdkEventFocus *event)
4271 GtkEntry *entry = GTK_ENTRY (widget);
4272 GtkEntryPrivate *priv = entry->priv;
4275 gtk_widget_queue_draw (widget);
4277 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4281 priv->need_im_reset = TRUE;
4282 gtk_im_context_focus_in (priv->im_context);
4283 keymap_state_changed (keymap, entry);
4284 g_signal_connect (keymap, "state-changed",
4285 G_CALLBACK (keymap_state_changed), entry);
4288 g_signal_connect (keymap, "direction-changed",
4289 G_CALLBACK (keymap_direction_changed), entry);
4291 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4292 priv->placeholder_text != NULL)
4294 gtk_entry_recompute (entry);
4298 gtk_entry_reset_blink_time (entry);
4299 gtk_entry_check_cursor_blink (entry);
4306 gtk_entry_focus_out (GtkWidget *widget,
4307 GdkEventFocus *event)
4309 GtkEntry *entry = GTK_ENTRY (widget);
4310 GtkEntryPrivate *priv = entry->priv;
4311 GtkEntryCompletion *completion;
4314 gtk_widget_queue_draw (widget);
4316 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4320 priv->need_im_reset = TRUE;
4321 gtk_im_context_focus_out (priv->im_context);
4322 remove_capslock_feedback (entry);
4325 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4326 priv->placeholder_text != NULL)
4328 gtk_entry_recompute (entry);
4332 gtk_entry_check_cursor_blink (entry);
4335 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4336 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4338 completion = gtk_entry_get_completion (entry);
4340 _gtk_entry_completion_popdown (completion);
4346 gtk_entry_grab_focus (GtkWidget *widget)
4348 GtkEntry *entry = GTK_ENTRY (widget);
4349 GtkEntryPrivate *priv = entry->priv;
4350 gboolean select_on_focus;
4352 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4354 if (priv->editable && !priv->in_click)
4356 g_object_get (gtk_widget_get_settings (widget),
4357 "gtk-entry-select-on-focus",
4361 if (select_on_focus)
4362 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4367 gtk_entry_direction_changed (GtkWidget *widget,
4368 GtkTextDirection previous_dir)
4370 GtkEntry *entry = GTK_ENTRY (widget);
4372 gtk_entry_recompute (entry);
4374 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4378 gtk_entry_state_flags_changed (GtkWidget *widget,
4379 GtkStateFlags previous_state)
4381 GtkEntry *entry = GTK_ENTRY (widget);
4382 GtkEntryPrivate *priv = entry->priv;
4385 if (gtk_widget_get_realized (widget))
4387 if (gtk_widget_is_sensitive (widget))
4388 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4392 gdk_window_set_cursor (priv->text_area, cursor);
4395 g_object_unref (cursor);
4397 priv->mouse_cursor_obscured = FALSE;
4399 update_cursors (widget);
4402 if (!gtk_widget_is_sensitive (widget))
4404 /* Clear any selection */
4405 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4408 gtk_entry_update_cached_style_values (entry);
4412 gtk_entry_screen_changed (GtkWidget *widget,
4413 GdkScreen *old_screen)
4415 gtk_entry_recompute (GTK_ENTRY (widget));
4418 /* GtkEditable method implementations
4421 gtk_entry_insert_text (GtkEditable *editable,
4422 const gchar *new_text,
4423 gint new_text_length,
4426 g_object_ref (editable);
4429 * The incoming text may a password or other secret. We make sure
4430 * not to copy it into temporary buffers.
4433 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4435 g_object_unref (editable);
4439 gtk_entry_delete_text (GtkEditable *editable,
4443 g_object_ref (editable);
4445 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4447 g_object_unref (editable);
4451 gtk_entry_get_chars (GtkEditable *editable,
4455 GtkEntry *entry = GTK_ENTRY (editable);
4458 gint start_index, end_index;
4460 text = gtk_entry_buffer_get_text (get_buffer (entry));
4461 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4464 end_pos = text_length;
4466 start_pos = MIN (text_length, start_pos);
4467 end_pos = MIN (text_length, end_pos);
4469 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4470 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4472 return g_strndup (text + start_index, end_index - start_index);
4476 gtk_entry_real_set_position (GtkEditable *editable,
4479 GtkEntry *entry = GTK_ENTRY (editable);
4480 GtkEntryPrivate *priv = entry->priv;
4484 length = gtk_entry_buffer_get_length (get_buffer (entry));
4485 if (position < 0 || position > length)
4488 if (position != priv->current_pos ||
4489 position != priv->selection_bound)
4491 _gtk_entry_reset_im_context (entry);
4492 gtk_entry_set_positions (entry, position, position);
4497 gtk_entry_get_position (GtkEditable *editable)
4499 GtkEntry *entry = GTK_ENTRY (editable);
4500 GtkEntryPrivate *priv = entry->priv;
4502 return priv->current_pos;
4506 gtk_entry_set_selection_bounds (GtkEditable *editable,
4510 GtkEntry *entry = GTK_ENTRY (editable);
4513 length = gtk_entry_buffer_get_length (get_buffer (entry));
4519 _gtk_entry_reset_im_context (entry);
4521 gtk_entry_set_positions (entry,
4523 MIN (start, length));
4525 gtk_entry_update_primary_selection (entry);
4529 gtk_entry_get_selection_bounds (GtkEditable *editable,
4533 GtkEntry *entry = GTK_ENTRY (editable);
4534 GtkEntryPrivate *priv = entry->priv;
4536 *start = priv->selection_bound;
4537 *end = priv->current_pos;
4539 return (priv->selection_bound != priv->current_pos);
4543 icon_theme_changed (GtkEntry *entry)
4545 GtkEntryPrivate *priv = entry->priv;
4548 for (i = 0; i < MAX_ICONS; i++)
4550 EntryIconInfo *icon_info = priv->icons[i];
4551 if (icon_info != NULL)
4552 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4555 gtk_widget_queue_draw (GTK_WIDGET (entry));
4559 gtk_entry_update_cached_style_values (GtkEntry *entry)
4561 GtkEntryPrivate *priv = entry->priv;
4563 gboolean interior_focus;
4565 gtk_widget_style_get (GTK_WIDGET (entry),
4566 "focus-line-width", &focus_width,
4567 "interior-focus", &interior_focus,
4569 priv->focus_width = focus_width;
4570 priv->interior_focus = interior_focus;
4572 if (!priv->invisible_char_set)
4574 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4576 if (priv->invisible_char != ch)
4578 priv->invisible_char = ch;
4579 g_object_notify (G_OBJECT (entry), "invisible-char");
4585 gtk_entry_style_updated (GtkWidget *widget)
4587 GtkEntry *entry = GTK_ENTRY (widget);
4589 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4591 gtk_entry_update_cached_style_values (entry);
4593 gtk_entry_recompute (entry);
4595 icon_theme_changed (entry);
4598 /* GtkCellEditable method implementations
4601 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4603 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4604 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4608 gtk_cell_editable_key_press_event (GtkEntry *entry,
4609 GdkEventKey *key_event,
4612 GtkEntryPrivate *priv = entry->priv;
4614 if (key_event->keyval == GDK_KEY_Escape)
4616 priv->editing_canceled = TRUE;
4617 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4618 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4623 /* override focus */
4624 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4626 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4627 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4636 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4639 GtkEntry *entry = GTK_ENTRY (cell_editable);
4640 GtkEntryPrivate *priv = entry->priv;
4642 priv->is_cell_renderer = TRUE;
4644 g_signal_connect (cell_editable, "activate",
4645 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4646 g_signal_connect (cell_editable, "key-press-event",
4647 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4651 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4653 if (password_hint->source_id)
4654 g_source_remove (password_hint->source_id);
4656 g_slice_free (GtkEntryPasswordHint, password_hint);
4661 gtk_entry_remove_password_hint (gpointer data)
4663 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4664 password_hint->position = -1;
4666 /* Force the string to be redrawn, but now without a visible character */
4667 gtk_entry_recompute (GTK_ENTRY (data));
4671 /* Default signal handlers
4674 gtk_entry_real_insert_text (GtkEditable *editable,
4675 const gchar *new_text,
4676 gint new_text_length,
4682 n_chars = g_utf8_strlen (new_text, new_text_length);
4685 * The actual insertion into the buffer. This will end up firing the
4686 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4687 * buffer_notify_text(), buffer_notify_length()
4689 begin_change (GTK_ENTRY (editable));
4691 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4693 end_change (GTK_ENTRY (editable));
4695 if (n_inserted != n_chars)
4696 gtk_widget_error_bell (GTK_WIDGET (editable));
4698 *position += n_inserted;
4702 gtk_entry_real_delete_text (GtkEditable *editable,
4707 * The actual deletion from the buffer. This will end up firing the
4708 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4709 * buffer_notify_text(), buffer_notify_length()
4712 begin_change (GTK_ENTRY (editable));
4714 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4716 end_change (GTK_ENTRY (editable));
4719 /* GtkEntryBuffer signal handlers
4722 buffer_inserted_text (GtkEntryBuffer *buffer,
4728 GtkEntryPrivate *priv = entry->priv;
4729 guint password_hint_timeout;
4731 gint selection_bound;
4733 current_pos = priv->current_pos;
4734 if (current_pos > position)
4735 current_pos += n_chars;
4737 selection_bound = priv->selection_bound;
4738 if (selection_bound > position)
4739 selection_bound += n_chars;
4741 gtk_entry_set_positions (entry, current_pos, selection_bound);
4743 /* Calculate the password hint if it needs to be displayed. */
4744 if (n_chars == 1 && !priv->visible)
4746 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4747 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4750 if (password_hint_timeout > 0)
4752 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4753 quark_password_hint);
4756 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4757 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4758 (GDestroyNotify)gtk_entry_password_hint_free);
4761 password_hint->position = position;
4762 if (password_hint->source_id)
4763 g_source_remove (password_hint->source_id);
4764 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4765 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4771 buffer_deleted_text (GtkEntryBuffer *buffer,
4776 GtkEntryPrivate *priv = entry->priv;
4777 guint end_pos = position + n_chars;
4778 gint selection_bound;
4781 current_pos = priv->current_pos;
4782 if (current_pos > position)
4783 current_pos -= MIN (current_pos, end_pos) - position;
4785 selection_bound = priv->selection_bound;
4786 if (selection_bound > position)
4787 selection_bound -= MIN (selection_bound, end_pos) - position;
4789 gtk_entry_set_positions (entry, current_pos, selection_bound);
4791 /* We might have deleted the selection */
4792 gtk_entry_update_primary_selection (entry);
4794 /* Disable the password hint if one exists. */
4797 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4798 quark_password_hint);
4801 if (password_hint->source_id)
4802 g_source_remove (password_hint->source_id);
4803 password_hint->source_id = 0;
4804 password_hint->position = -1;
4810 buffer_notify_text (GtkEntryBuffer *buffer,
4814 gtk_entry_recompute (entry);
4815 emit_changed (entry);
4816 g_object_notify (G_OBJECT (entry), "text");
4820 buffer_notify_length (GtkEntryBuffer *buffer,
4824 g_object_notify (G_OBJECT (entry), "text-length");
4828 buffer_notify_max_length (GtkEntryBuffer *buffer,
4832 g_object_notify (G_OBJECT (entry), "max-length");
4836 buffer_connect_signals (GtkEntry *entry)
4838 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4839 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4840 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4841 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4842 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4846 buffer_disconnect_signals (GtkEntry *entry)
4848 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4849 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4850 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4851 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4852 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4855 /* Compute the X position for an offset that corresponds to the "more important
4856 * cursor position for that offset. We use this when trying to guess to which
4857 * end of the selection we should go to when the user hits the left or
4861 get_better_cursor_x (GtkEntry *entry,
4864 GtkEntryPrivate *priv = entry->priv;
4865 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4866 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4867 gboolean split_cursor;
4869 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4870 const gchar *text = pango_layout_get_text (layout);
4871 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4873 PangoRectangle strong_pos, weak_pos;
4875 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4876 "gtk-split-cursor", &split_cursor,
4879 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4882 return strong_pos.x / PANGO_SCALE;
4884 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4888 gtk_entry_move_cursor (GtkEntry *entry,
4889 GtkMovementStep step,
4891 gboolean extend_selection)
4893 GtkEntryPrivate *priv = entry->priv;
4894 gint new_pos = priv->current_pos;
4896 _gtk_entry_reset_im_context (entry);
4898 if (priv->current_pos != priv->selection_bound && !extend_selection)
4900 /* If we have a current selection and aren't extending it, move to the
4901 * start/or end of the selection as appropriate
4905 case GTK_MOVEMENT_VISUAL_POSITIONS:
4907 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4908 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4911 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4913 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4916 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4917 case GTK_MOVEMENT_WORDS:
4919 new_pos = MIN (priv->current_pos, priv->selection_bound);
4921 new_pos = MAX (priv->current_pos, priv->selection_bound);
4923 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4924 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4925 case GTK_MOVEMENT_BUFFER_ENDS:
4926 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4928 case GTK_MOVEMENT_DISPLAY_LINES:
4929 case GTK_MOVEMENT_PARAGRAPHS:
4930 case GTK_MOVEMENT_PAGES:
4931 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4939 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4940 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4942 case GTK_MOVEMENT_VISUAL_POSITIONS:
4943 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4944 if (priv->current_pos == new_pos)
4946 if (!extend_selection)
4948 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4950 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4952 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4955 gtk_widget_child_focus (toplevel,
4957 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4962 gtk_widget_error_bell (GTK_WIDGET (entry));
4966 case GTK_MOVEMENT_WORDS:
4969 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4974 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4977 if (priv->current_pos == new_pos)
4978 gtk_widget_error_bell (GTK_WIDGET (entry));
4980 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4981 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4982 case GTK_MOVEMENT_BUFFER_ENDS:
4983 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4984 if (priv->current_pos == new_pos)
4985 gtk_widget_error_bell (GTK_WIDGET (entry));
4987 case GTK_MOVEMENT_DISPLAY_LINES:
4988 case GTK_MOVEMENT_PARAGRAPHS:
4989 case GTK_MOVEMENT_PAGES:
4990 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4995 if (extend_selection)
4996 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4998 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5000 gtk_entry_pend_cursor_blink (entry);
5004 gtk_entry_insert_at_cursor (GtkEntry *entry,
5007 GtkEntryPrivate *priv = entry->priv;
5008 GtkEditable *editable = GTK_EDITABLE (entry);
5009 gint pos = priv->current_pos;
5013 _gtk_entry_reset_im_context (entry);
5015 gtk_editable_insert_text (editable, str, -1, &pos);
5016 gtk_editable_set_position (editable, pos);
5021 gtk_entry_delete_from_cursor (GtkEntry *entry,
5025 GtkEntryPrivate *priv = entry->priv;
5026 GtkEditable *editable = GTK_EDITABLE (entry);
5027 gint start_pos = priv->current_pos;
5028 gint end_pos = priv->current_pos;
5029 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5031 _gtk_entry_reset_im_context (entry);
5033 if (!priv->editable)
5035 gtk_widget_error_bell (GTK_WIDGET (entry));
5039 if (priv->selection_bound != priv->current_pos)
5041 gtk_editable_delete_selection (editable);
5047 case GTK_DELETE_CHARS:
5048 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5049 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5051 case GTK_DELETE_WORDS:
5054 /* Move to end of current word, or if not on a word, end of previous word */
5055 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5056 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5060 /* Move to beginning of current word, or if not on a word, begining of next word */
5061 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5062 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5066 case GTK_DELETE_WORD_ENDS:
5069 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5074 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5077 gtk_editable_delete_text (editable, start_pos, end_pos);
5079 case GTK_DELETE_DISPLAY_LINE_ENDS:
5080 case GTK_DELETE_PARAGRAPH_ENDS:
5082 gtk_editable_delete_text (editable, 0, priv->current_pos);
5084 gtk_editable_delete_text (editable, priv->current_pos, -1);
5086 case GTK_DELETE_DISPLAY_LINES:
5087 case GTK_DELETE_PARAGRAPHS:
5088 gtk_editable_delete_text (editable, 0, -1);
5090 case GTK_DELETE_WHITESPACE:
5091 gtk_entry_delete_whitespace (entry);
5095 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5096 gtk_widget_error_bell (GTK_WIDGET (entry));
5098 gtk_entry_pend_cursor_blink (entry);
5102 gtk_entry_backspace (GtkEntry *entry)
5104 GtkEntryPrivate *priv = entry->priv;
5105 GtkEditable *editable = GTK_EDITABLE (entry);
5108 _gtk_entry_reset_im_context (entry);
5110 if (!priv->editable)
5112 gtk_widget_error_bell (GTK_WIDGET (entry));
5116 if (priv->selection_bound != priv->current_pos)
5118 gtk_editable_delete_selection (editable);
5122 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5124 if (prev_pos < priv->current_pos)
5126 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5127 PangoLogAttr *log_attrs;
5130 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5132 /* Deleting parts of characters */
5133 if (log_attrs[priv->current_pos].backspace_deletes_character)
5135 gchar *cluster_text;
5136 gchar *normalized_text;
5139 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5141 normalized_text = g_utf8_normalize (cluster_text,
5142 strlen (cluster_text),
5144 len = g_utf8_strlen (normalized_text, -1);
5146 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5149 gint pos = priv->current_pos;
5151 gtk_editable_insert_text (editable, normalized_text,
5152 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5154 gtk_editable_set_position (editable, pos);
5157 g_free (normalized_text);
5158 g_free (cluster_text);
5162 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5169 gtk_widget_error_bell (GTK_WIDGET (entry));
5172 gtk_entry_pend_cursor_blink (entry);
5176 gtk_entry_copy_clipboard (GtkEntry *entry)
5178 GtkEntryPrivate *priv = entry->priv;
5179 GtkEditable *editable = GTK_EDITABLE (entry);
5183 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5187 gtk_widget_error_bell (GTK_WIDGET (entry));
5191 str = gtk_entry_get_display_text (entry, start, end);
5192 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5193 GDK_SELECTION_CLIPBOARD),
5200 gtk_entry_cut_clipboard (GtkEntry *entry)
5202 GtkEntryPrivate *priv = entry->priv;
5203 GtkEditable *editable = GTK_EDITABLE (entry);
5208 gtk_widget_error_bell (GTK_WIDGET (entry));
5212 gtk_entry_copy_clipboard (entry);
5216 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5217 gtk_editable_delete_text (editable, start, end);
5221 gtk_widget_error_bell (GTK_WIDGET (entry));
5226 gtk_entry_paste_clipboard (GtkEntry *entry)
5228 GtkEntryPrivate *priv = entry->priv;
5231 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5233 gtk_widget_error_bell (GTK_WIDGET (entry));
5237 gtk_entry_delete_cb (GtkEntry *entry)
5239 GtkEntryPrivate *priv = entry->priv;
5240 GtkEditable *editable = GTK_EDITABLE (entry);
5245 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5246 gtk_editable_delete_text (editable, start, end);
5251 gtk_entry_toggle_overwrite (GtkEntry *entry)
5253 GtkEntryPrivate *priv = entry->priv;
5255 priv->overwrite_mode = !priv->overwrite_mode;
5256 gtk_entry_pend_cursor_blink (entry);
5257 gtk_widget_queue_draw (GTK_WIDGET (entry));
5261 gtk_entry_select_all (GtkEntry *entry)
5263 gtk_entry_select_line (entry);
5267 gtk_entry_real_activate (GtkEntry *entry)
5269 GtkEntryPrivate *priv = entry->priv;
5271 GtkWidget *default_widget, *focus_widget;
5272 GtkWidget *toplevel;
5275 widget = GTK_WIDGET (entry);
5277 if (priv->activates_default)
5279 toplevel = gtk_widget_get_toplevel (widget);
5280 if (GTK_IS_WINDOW (toplevel))
5282 window = GTK_WINDOW (toplevel);
5286 default_widget = gtk_window_get_default_widget (window);
5287 focus_widget = gtk_window_get_focus (window);
5288 if (widget != default_widget &&
5289 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5290 gtk_window_activate_default (window);
5297 keymap_direction_changed (GdkKeymap *keymap,
5300 gtk_entry_recompute (entry);
5303 /* IM Context Callbacks
5307 gtk_entry_commit_cb (GtkIMContext *context,
5311 GtkEntryPrivate *priv = entry->priv;
5314 gtk_entry_enter_text (entry, str);
5318 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5321 GtkEntryPrivate *priv = entry->priv;
5325 gchar *preedit_string;
5328 gtk_im_context_get_preedit_string (priv->im_context,
5329 &preedit_string, NULL,
5331 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5332 priv->preedit_length = strlen (preedit_string);
5333 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5334 priv->preedit_cursor = cursor_pos;
5335 g_free (preedit_string);
5337 gtk_entry_recompute (entry);
5342 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5345 GtkEntryPrivate *priv = entry->priv;
5348 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5349 text = gtk_entry_get_display_text (entry, 0, -1);
5350 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5351 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5358 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5363 GtkEntryPrivate *priv = entry->priv;
5366 gtk_editable_delete_text (GTK_EDITABLE (entry),
5367 priv->current_pos + offset,
5368 priv->current_pos + offset + n_chars);
5373 /* Internal functions
5376 /* Used for im_commit_cb and inserting Unicode chars */
5378 gtk_entry_enter_text (GtkEntry *entry,
5381 GtkEntryPrivate *priv = entry->priv;
5382 GtkEditable *editable = GTK_EDITABLE (entry);
5384 gboolean old_need_im_reset;
5386 old_need_im_reset = priv->need_im_reset;
5387 priv->need_im_reset = FALSE;
5389 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5390 gtk_editable_delete_selection (editable);
5393 if (priv->overwrite_mode)
5394 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5397 tmp_pos = priv->current_pos;
5398 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5399 gtk_editable_set_position (editable, tmp_pos);
5401 priv->need_im_reset = old_need_im_reset;
5404 /* All changes to priv->current_pos and priv->selection_bound
5405 * should go through this function.
5408 gtk_entry_set_positions (GtkEntry *entry,
5410 gint selection_bound)
5412 GtkEntryPrivate *priv = entry->priv;
5413 gboolean changed = FALSE;
5415 g_object_freeze_notify (G_OBJECT (entry));
5417 if (current_pos != -1 &&
5418 priv->current_pos != current_pos)
5420 priv->current_pos = current_pos;
5423 g_object_notify (G_OBJECT (entry), "cursor-position");
5426 if (selection_bound != -1 &&
5427 priv->selection_bound != selection_bound)
5429 priv->selection_bound = selection_bound;
5432 g_object_notify (G_OBJECT (entry), "selection-bound");
5435 g_object_thaw_notify (G_OBJECT (entry));
5439 gtk_entry_move_adjustments (entry);
5440 gtk_entry_recompute (entry);
5445 gtk_entry_reset_layout (GtkEntry *entry)
5447 GtkEntryPrivate *priv = entry->priv;
5449 if (priv->cached_layout)
5451 g_object_unref (priv->cached_layout);
5452 priv->cached_layout = NULL;
5457 update_im_cursor_location (GtkEntry *entry)
5459 GtkEntryPrivate *priv = entry->priv;
5462 gint strong_xoffset;
5463 gint area_width, area_height;
5465 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5466 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5468 strong_xoffset = strong_x - priv->scroll_offset;
5469 if (strong_xoffset < 0)
5473 else if (strong_xoffset > area_width)
5475 strong_xoffset = area_width;
5477 area.x = strong_xoffset;
5480 area.height = area_height;
5482 gtk_im_context_set_cursor_location (priv->im_context, &area);
5486 recompute_idle_func (gpointer data)
5488 GtkEntry *entry = GTK_ENTRY (data);
5489 GtkEntryPrivate *priv = entry->priv;
5491 priv->recompute_idle = 0;
5493 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5495 gtk_entry_adjust_scroll (entry);
5496 gtk_widget_queue_draw (GTK_WIDGET (entry));
5498 update_im_cursor_location (entry);
5505 gtk_entry_recompute (GtkEntry *entry)
5507 GtkEntryPrivate *priv = entry->priv;
5509 gtk_entry_reset_layout (entry);
5510 gtk_entry_check_cursor_blink (entry);
5512 if (!priv->recompute_idle)
5514 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5515 recompute_idle_func, entry, NULL);
5520 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5523 GtkWidget *widget = GTK_WIDGET (entry);
5524 GtkStyleContext *context;
5525 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5527 context = gtk_widget_get_style_context (widget);
5528 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5530 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5531 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5532 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5535 static inline gboolean
5536 show_placeholder_text (GtkEntry *entry)
5538 GtkEntryPrivate *priv = entry->priv;
5540 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5541 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5542 priv->placeholder_text != NULL)
5548 static PangoLayout *
5549 gtk_entry_create_layout (GtkEntry *entry,
5550 gboolean include_preedit)
5552 GtkEntryPrivate *priv = entry->priv;
5553 GtkWidget *widget = GTK_WIDGET (entry);
5554 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5555 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5556 gboolean placeholder_layout = show_placeholder_text (entry);
5558 gchar *preedit_string = NULL;
5559 gint preedit_length = 0;
5560 PangoAttrList *preedit_attrs = NULL;
5565 pango_layout_set_single_paragraph_mode (layout, TRUE);
5567 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5568 n_bytes = strlen (display);
5570 if (!placeholder_layout && include_preedit)
5572 gtk_im_context_get_preedit_string (priv->im_context,
5573 &preedit_string, &preedit_attrs, NULL);
5574 preedit_length = priv->preedit_length;
5576 else if (placeholder_layout)
5579 PangoAttribute *attr;
5581 gtk_entry_get_placeholder_text_color (entry, &color);
5582 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5583 attr->start_index = 0;
5584 attr->end_index = G_MAXINT;
5585 pango_attr_list_insert (tmp_attrs, attr);
5590 GString *tmp_string = g_string_new (display);
5591 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5593 g_string_insert (tmp_string, cursor_index, preedit_string);
5595 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5597 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5598 cursor_index, preedit_length);
5600 g_string_free (tmp_string, TRUE);
5604 PangoDirection pango_dir;
5606 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5607 pango_dir = pango_find_base_dir (display, n_bytes);
5609 pango_dir = PANGO_DIRECTION_NEUTRAL;
5611 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5613 if (gtk_widget_has_focus (widget))
5615 GdkDisplay *display = gtk_widget_get_display (widget);
5616 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5617 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5618 pango_dir = PANGO_DIRECTION_RTL;
5620 pango_dir = PANGO_DIRECTION_LTR;
5624 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5625 pango_dir = PANGO_DIRECTION_RTL;
5627 pango_dir = PANGO_DIRECTION_LTR;
5631 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5634 priv->resolved_dir = pango_dir;
5636 pango_layout_set_text (layout, display, n_bytes);
5639 pango_layout_set_attributes (layout, tmp_attrs);
5641 g_free (preedit_string);
5645 pango_attr_list_unref (preedit_attrs);
5647 pango_attr_list_unref (tmp_attrs);
5652 static PangoLayout *
5653 gtk_entry_ensure_layout (GtkEntry *entry,
5654 gboolean include_preedit)
5656 GtkEntryPrivate *priv = entry->priv;
5658 if (priv->preedit_length > 0 &&
5659 !include_preedit != !priv->cache_includes_preedit)
5660 gtk_entry_reset_layout (entry);
5662 if (!priv->cached_layout)
5664 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5665 priv->cache_includes_preedit = include_preedit;
5668 return priv->cached_layout;
5672 get_layout_position (GtkEntry *entry,
5676 GtkEntryPrivate *priv = entry->priv;
5677 PangoLayout *layout;
5678 PangoRectangle logical_rect;
5679 gint area_width, area_height;
5681 PangoLayoutLine *line;
5683 layout = gtk_entry_ensure_layout (entry, TRUE);
5685 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5686 area_height = PANGO_SCALE * area_height;
5688 line = pango_layout_get_lines_readonly (layout)->data;
5689 pango_layout_line_get_extents (line, NULL, &logical_rect);
5691 /* Align primarily for locale's ascent/descent */
5692 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5693 priv->ascent + logical_rect.y);
5695 /* Now see if we need to adjust to fit in actual drawn string */
5696 if (logical_rect.height > area_height)
5697 y_pos = (area_height - logical_rect.height) / 2;
5700 else if (y_pos + logical_rect.height > area_height)
5701 y_pos = area_height - logical_rect.height;
5703 y_pos = y_pos / PANGO_SCALE;
5706 *x = - priv->scroll_offset;
5713 draw_text_with_color (GtkEntry *entry,
5715 GdkRGBA *default_color)
5717 GtkEntryPrivate *priv = entry->priv;
5718 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5721 gint start_pos, end_pos;
5723 widget = GTK_WIDGET (entry);
5727 get_layout_position (entry, &x, &y);
5729 cairo_move_to (cr, x, y);
5730 gdk_cairo_set_source_rgba (cr, default_color);
5731 pango_cairo_show_layout (cr, layout);
5733 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5737 PangoRectangle logical_rect;
5738 GdkRGBA selection_color, text_color;
5739 GtkStyleContext *context;
5740 GtkStateFlags state;
5742 context = gtk_widget_get_style_context (widget);
5743 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5744 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5746 state = gtk_widget_get_state_flags (widget);
5747 state |= GTK_STATE_FLAG_SELECTED;
5749 gtk_style_context_get_background_color (context, state, &selection_color);
5750 gtk_style_context_get_color (context, state, &text_color);
5752 for (i = 0; i < n_ranges; ++i)
5753 cairo_rectangle (cr,
5754 - priv->scroll_offset + ranges[2 * i],
5757 logical_rect.height);
5761 gdk_cairo_set_source_rgba (cr, &selection_color);
5764 cairo_move_to (cr, x, y);
5765 gdk_cairo_set_source_rgba (cr, &text_color);
5766 pango_cairo_show_layout (cr, layout);
5774 gtk_entry_draw_text (GtkEntry *entry,
5777 GtkEntryPrivate *priv = entry->priv;
5778 GtkWidget *widget = GTK_WIDGET (entry);
5779 GtkStateFlags state = 0;
5780 GdkRGBA text_color, bar_text_color;
5781 GtkStyleContext *context;
5783 gint progress_x, progress_y, progress_width, progress_height;
5784 gint clip_width, clip_height;
5786 /* Nothing to display at all */
5787 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5790 state = gtk_widget_get_state_flags (widget);
5791 context = gtk_widget_get_style_context (widget);
5793 gtk_style_context_get_color (context, state, &text_color);
5795 /* Get foreground color for progressbars */
5796 gtk_entry_prepare_context_for_progress (entry, context);
5797 gtk_style_context_get_color (context, state, &bar_text_color);
5798 gtk_style_context_restore (context);
5800 get_progress_area (widget,
5801 &progress_x, &progress_y,
5802 &progress_width, &progress_height);
5806 clip_width = gdk_window_get_width (priv->text_area);
5807 clip_height = gdk_window_get_height (priv->text_area);
5808 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5811 /* If the color is the same, or the progress area has a zero
5812 * size, then we only need to draw once. */
5813 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5814 ((progress_width == 0) || (progress_height == 0)))
5816 draw_text_with_color (entry, cr, &text_color);
5820 int frame_x, frame_y, area_x, area_y;
5822 width = gdk_window_get_width (priv->text_area);
5823 height = gdk_window_get_height (priv->text_area);
5827 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5828 cairo_rectangle (cr, 0, 0, width, height);
5830 /* progres area is frame-relative, we need it text-area window
5832 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5833 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5834 progress_x += frame_x - area_x;
5835 progress_y += frame_y - area_y;
5837 cairo_rectangle (cr, progress_x, progress_y,
5838 progress_width, progress_height);
5840 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5842 draw_text_with_color (entry, cr, &text_color);
5847 cairo_rectangle (cr, progress_x, progress_y,
5848 progress_width, progress_height);
5851 draw_text_with_color (entry, cr, &bar_text_color);
5860 gtk_entry_draw_cursor (GtkEntry *entry,
5864 GtkEntryPrivate *priv = entry->priv;
5865 GtkWidget *widget = GTK_WIDGET (entry);
5866 GtkStyleContext *context;
5867 PangoRectangle cursor_rect;
5870 gboolean block_at_line_end;
5871 PangoLayout *layout;
5874 context = gtk_widget_get_style_context (widget);
5876 layout = gtk_entry_ensure_layout (entry, TRUE);
5877 text = pango_layout_get_text (layout);
5878 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5880 if (!priv->overwrite_mode)
5883 block = _gtk_text_util_get_block_cursor_location (layout,
5884 cursor_index, &cursor_rect, &block_at_line_end);
5888 gtk_render_insertion_cursor (context, cr,
5889 - priv->scroll_offset, 0,
5890 layout, cursor_index, priv->resolved_dir);
5892 else /* overwrite_mode */
5894 GdkRGBA cursor_color;
5900 get_layout_position (entry, &x, &y);
5902 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5903 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5904 rect.width = PANGO_PIXELS (cursor_rect.width);
5905 rect.height = PANGO_PIXELS (cursor_rect.height);
5907 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5908 gdk_cairo_set_source_rgba (cr, &cursor_color);
5909 gdk_cairo_rectangle (cr, &rect);
5912 if (!block_at_line_end)
5914 GtkStateFlags state;
5917 state = gtk_widget_get_state_flags (widget);
5918 gtk_style_context_get_background_color (context, state, &color);
5920 gdk_cairo_rectangle (cr, &rect);
5922 cairo_move_to (cr, x, y);
5923 gdk_cairo_set_source_rgba (cr, &color);
5924 pango_cairo_show_layout (cr, layout);
5932 _gtk_entry_reset_im_context (GtkEntry *entry)
5934 GtkEntryPrivate *priv = entry->priv;
5936 if (priv->need_im_reset)
5938 priv->need_im_reset = FALSE;
5939 gtk_im_context_reset (priv->im_context);
5944 * gtk_entry_reset_im_context:
5945 * @entry: a #GtkEntry
5947 * Reset the input method context of the entry if needed.
5949 * This can be necessary in the case where modifying the buffer
5950 * would confuse on-going input method behavior.
5955 gtk_entry_reset_im_context (GtkEntry *entry)
5957 g_return_if_fail (GTK_IS_ENTRY (entry));
5959 _gtk_entry_reset_im_context (entry);
5963 * gtk_entry_im_context_filter_keypress:
5964 * @entry: a #GtkEntry
5965 * @event: (type Gdk.EventKey): the key event
5967 * Allow the #GtkEntry input method to internally handle key press
5968 * and release events. If this function returns %TRUE, then no further
5969 * processing should be done for this key event. See
5970 * gtk_im_context_filter_keypress().
5972 * Note that you are expected to call this function from your handler
5973 * when overriding key event handling. This is needed in the case when
5974 * you need to insert your own key handling between the input method
5975 * and the default key event handling of the #GtkEntry.
5976 * See gtk_text_view_reset_im_context() for an example of use.
5978 * Return value: %TRUE if the input method handled the key event.
5983 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5986 GtkEntryPrivate *priv;
5988 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5992 return gtk_im_context_filter_keypress (priv->im_context, event);
5996 _gtk_entry_get_im_context (GtkEntry *entry)
5998 return entry->priv->im_context;
6002 gtk_entry_find_position (GtkEntry *entry,
6005 GtkEntryPrivate *priv = entry->priv;
6006 PangoLayout *layout;
6007 PangoLayoutLine *line;
6014 layout = gtk_entry_ensure_layout (entry, TRUE);
6015 text = pango_layout_get_text (layout);
6016 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6018 line = pango_layout_get_lines_readonly (layout)->data;
6019 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6021 if (index >= cursor_index && priv->preedit_length)
6023 if (index >= cursor_index + priv->preedit_length)
6024 index -= priv->preedit_length;
6027 index = cursor_index;
6032 pos = g_utf8_pointer_to_offset (text, text + index);
6039 gtk_entry_get_cursor_locations (GtkEntry *entry,
6044 GtkEntryPrivate *priv = entry->priv;
6045 DisplayMode mode = gtk_entry_get_display_mode (entry);
6047 /* Nothing to display at all, so no cursor is relevant */
6048 if (mode == DISPLAY_BLANK)
6058 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6059 const gchar *text = pango_layout_get_text (layout);
6060 PangoRectangle strong_pos, weak_pos;
6063 if (type == CURSOR_STANDARD)
6065 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6067 else /* type == CURSOR_DND */
6069 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6071 if (priv->dnd_position > priv->current_pos)
6073 if (mode == DISPLAY_NORMAL)
6074 index += priv->preedit_length;
6077 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6078 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6083 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6086 *strong_x = strong_pos.x / PANGO_SCALE;
6089 *weak_x = weak_pos.x / PANGO_SCALE;
6094 gtk_entry_adjust_scroll (GtkEntry *entry)
6096 GtkEntryPrivate *priv = entry->priv;
6097 gint min_offset, max_offset;
6098 gint text_area_width, text_width;
6100 gint strong_x, weak_x;
6101 gint strong_xoffset, weak_xoffset;
6103 PangoLayout *layout;
6104 PangoLayoutLine *line;
6105 PangoRectangle logical_rect;
6107 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6110 text_area_width = gdk_window_get_width (priv->text_area);
6112 if (text_area_width < 0)
6113 text_area_width = 0;
6115 layout = gtk_entry_ensure_layout (entry, TRUE);
6116 line = pango_layout_get_lines_readonly (layout)->data;
6118 pango_layout_line_get_extents (line, NULL, &logical_rect);
6120 /* Display as much text as we can */
6122 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6123 xalign = priv->xalign;
6125 xalign = 1.0 - priv->xalign;
6127 text_width = PANGO_PIXELS(logical_rect.width);
6129 if (text_width > text_area_width)
6132 max_offset = text_width - text_area_width;
6136 min_offset = (text_width - text_area_width) * xalign;
6137 max_offset = min_offset;
6140 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6142 /* And make sure cursors are on screen. Note that the cursor is
6143 * actually drawn one pixel into the INNER_BORDER space on
6144 * the right, when the scroll is at the utmost right. This
6145 * looks better to to me than confining the cursor inside the
6146 * border entirely, though it means that the cursor gets one
6147 * pixel closer to the edge of the widget on the right than
6148 * on the left. This might need changing if one changed
6149 * INNER_BORDER from 2 to 1, as one would do on a
6150 * small-screen-real-estate display.
6152 * We always make sure that the strong cursor is on screen, and
6153 * put the weak cursor on screen if possible.
6156 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6158 strong_xoffset = strong_x - priv->scroll_offset;
6160 if (strong_xoffset < 0)
6162 priv->scroll_offset += strong_xoffset;
6165 else if (strong_xoffset > text_area_width)
6167 priv->scroll_offset += strong_xoffset - text_area_width;
6168 strong_xoffset = text_area_width;
6171 weak_xoffset = weak_x - priv->scroll_offset;
6173 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6175 priv->scroll_offset += weak_xoffset;
6177 else if (weak_xoffset > text_area_width &&
6178 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6180 priv->scroll_offset += weak_xoffset - text_area_width;
6183 g_object_notify (G_OBJECT (entry), "scroll-offset");
6187 gtk_entry_move_adjustments (GtkEntry *entry)
6189 GtkWidget *widget = GTK_WIDGET (entry);
6190 GtkAllocation allocation;
6191 GtkAdjustment *adjustment;
6192 PangoContext *context;
6193 PangoFontMetrics *metrics;
6194 GtkStyleContext *style_context;
6195 GtkStateFlags state;
6200 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6204 gtk_widget_get_allocation (widget, &allocation);
6206 /* Cursor position, layout offset, border width, and widget allocation */
6207 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6208 get_layout_position (entry, &layout_x, NULL);
6209 _gtk_entry_get_borders (entry, &borders);
6210 x += allocation.x + layout_x + borders.left;
6212 /* Approximate width of a char, so user can see what is ahead/behind */
6213 context = gtk_widget_get_pango_context (widget);
6214 style_context = gtk_widget_get_style_context (widget);
6215 state = gtk_widget_get_state_flags (widget);
6217 metrics = pango_context_get_metrics (context,
6218 gtk_style_context_get_font (style_context, state),
6219 pango_context_get_language (context));
6220 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6223 gtk_adjustment_clamp_page (adjustment,
6224 x - (char_width + 1), /* one char + one pixel before */
6225 x + (char_width + 2)); /* one char + cursor + one pixel after */
6229 gtk_entry_move_visually (GtkEntry *entry,
6233 GtkEntryPrivate *priv = entry->priv;
6235 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6238 text = pango_layout_get_text (layout);
6240 index = g_utf8_offset_to_pointer (text, start) - text;
6244 int new_index, new_trailing;
6245 gboolean split_cursor;
6248 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6249 "gtk-split-cursor", &split_cursor,
6256 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6257 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6259 strong = keymap_direction == priv->resolved_dir;
6264 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6269 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6275 else if (new_index != G_MAXINT)
6278 while (new_trailing--)
6279 index = g_utf8_next_char (text + index) - text;
6282 return g_utf8_pointer_to_offset (text, text + index);
6286 gtk_entry_move_logically (GtkEntry *entry,
6290 gint new_pos = start;
6293 length = gtk_entry_buffer_get_length (get_buffer (entry));
6295 /* Prevent any leak of information */
6296 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6298 new_pos = CLAMP (start + count, 0, length);
6302 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6303 PangoLogAttr *log_attrs;
6306 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6308 while (count > 0 && new_pos < length)
6312 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6316 while (count < 0 && new_pos > 0)
6320 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6332 gtk_entry_move_forward_word (GtkEntry *entry,
6334 gboolean allow_whitespace)
6336 gint new_pos = start;
6339 length = gtk_entry_buffer_get_length (get_buffer (entry));
6341 /* Prevent any leak of information */
6342 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6346 else if (new_pos < length)
6348 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6349 PangoLogAttr *log_attrs;
6352 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6354 /* Find the next word boundary */
6356 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6357 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6368 gtk_entry_move_backward_word (GtkEntry *entry,
6370 gboolean allow_whitespace)
6372 gint new_pos = start;
6374 /* Prevent any leak of information */
6375 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6381 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6382 PangoLogAttr *log_attrs;
6385 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6387 new_pos = start - 1;
6389 /* Find the previous word boundary */
6390 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6391 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6401 gtk_entry_delete_whitespace (GtkEntry *entry)
6403 GtkEntryPrivate *priv = entry->priv;
6404 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6405 PangoLogAttr *log_attrs;
6409 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6411 start = end = priv->current_pos;
6413 while (start > 0 && log_attrs[start-1].is_white)
6416 while (end < n_attrs && log_attrs[end].is_white)
6422 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6427 gtk_entry_select_word (GtkEntry *entry)
6429 GtkEntryPrivate *priv = entry->priv;
6430 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6431 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6433 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6437 gtk_entry_select_line (GtkEntry *entry)
6439 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6443 truncate_multiline (const gchar *text)
6448 text[length] && text[length] != '\n' && text[length] != '\r';
6455 paste_received (GtkClipboard *clipboard,
6459 GtkEntry *entry = GTK_ENTRY (data);
6460 GtkEditable *editable = GTK_EDITABLE (entry);
6461 GtkEntryPrivate *priv = entry->priv;
6463 if (priv->button == GDK_BUTTON_MIDDLE)
6465 gint pos, start, end;
6466 pos = priv->insert_pos;
6467 gtk_editable_get_selection_bounds (editable, &start, &end);
6468 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6469 gtk_editable_select_region (editable, pos, pos);
6474 gint pos, start, end;
6476 gboolean popup_completion;
6477 GtkEntryCompletion *completion;
6479 completion = gtk_entry_get_completion (entry);
6481 if (priv->truncate_multiline)
6482 length = truncate_multiline (text);
6484 /* only complete if the selection is at the end */
6485 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6486 MAX (priv->current_pos, priv->selection_bound));
6490 if (gtk_widget_get_mapped (completion->priv->popup_window))
6491 _gtk_entry_completion_popdown (completion);
6493 if (!popup_completion && completion->priv->changed_id > 0)
6494 g_signal_handler_block (entry, completion->priv->changed_id);
6497 begin_change (entry);
6498 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6499 gtk_editable_delete_text (editable, start, end);
6501 pos = priv->current_pos;
6502 gtk_editable_insert_text (editable, text, length, &pos);
6503 gtk_editable_set_position (editable, pos);
6507 !popup_completion && completion->priv->changed_id > 0)
6508 g_signal_handler_unblock (entry, completion->priv->changed_id);
6511 g_object_unref (entry);
6515 gtk_entry_paste (GtkEntry *entry,
6518 g_object_ref (entry);
6519 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6520 paste_received, entry);
6524 primary_get_cb (GtkClipboard *clipboard,
6525 GtkSelectionData *selection_data,
6529 GtkEntry *entry = GTK_ENTRY (data);
6532 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6534 gchar *str = gtk_entry_get_display_text (entry, start, end);
6535 gtk_selection_data_set_text (selection_data, str, -1);
6541 primary_clear_cb (GtkClipboard *clipboard,
6544 GtkEntry *entry = GTK_ENTRY (data);
6545 GtkEntryPrivate *priv = entry->priv;
6547 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6551 gtk_entry_update_primary_selection (GtkEntry *entry)
6553 GtkTargetList *list;
6554 GtkTargetEntry *targets;
6555 GtkClipboard *clipboard;
6559 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6562 list = gtk_target_list_new (NULL, 0);
6563 gtk_target_list_add_text_targets (list, 0);
6565 targets = gtk_target_table_new_from_list (list, &n_targets);
6567 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6569 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6571 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6572 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6573 primary_clear_cb (clipboard, entry);
6577 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6578 gtk_clipboard_clear (clipboard);
6581 gtk_target_table_free (targets, n_targets);
6582 gtk_target_list_unref (list);
6586 gtk_entry_clear (GtkEntry *entry,
6587 GtkEntryIconPosition icon_pos)
6589 GtkEntryPrivate *priv = entry->priv;
6590 EntryIconInfo *icon_info = priv->icons[icon_pos];
6591 GtkImageType storage_type;
6593 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6596 g_object_freeze_notify (G_OBJECT (entry));
6598 /* Explicitly check, as the pointer may become invalidated
6599 * during destruction.
6601 if (GDK_IS_WINDOW (icon_info->window))
6602 gdk_window_hide (icon_info->window);
6604 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6606 switch (storage_type)
6608 case GTK_IMAGE_PIXBUF:
6609 g_object_notify (G_OBJECT (entry),
6610 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6613 case GTK_IMAGE_STOCK:
6614 g_object_notify (G_OBJECT (entry),
6615 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6618 case GTK_IMAGE_ICON_NAME:
6619 g_object_notify (G_OBJECT (entry),
6620 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6623 case GTK_IMAGE_GICON:
6624 g_object_notify (G_OBJECT (entry),
6625 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6629 g_assert_not_reached ();
6633 _gtk_icon_helper_clear (icon_info->icon_helper);
6635 g_object_notify (G_OBJECT (entry),
6636 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6638 g_object_thaw_notify (G_OBJECT (entry));
6642 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6643 GtkEntryIconPosition icon_pos)
6645 GtkEntryPrivate *priv = entry->priv;
6646 EntryIconInfo *icon_info = priv->icons[icon_pos];
6647 GtkStyleContext *context;
6650 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6651 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6653 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6656 gtk_style_context_restore (context);
6667 * Creates a new entry.
6669 * Return value: a new #GtkEntry.
6672 gtk_entry_new (void)
6674 return g_object_new (GTK_TYPE_ENTRY, NULL);
6678 * gtk_entry_new_with_buffer:
6679 * @buffer: The buffer to use for the new #GtkEntry.
6681 * Creates a new entry with the specified text buffer.
6683 * Return value: a new #GtkEntry
6688 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6690 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6691 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6694 static GtkEntryBuffer*
6695 get_buffer (GtkEntry *entry)
6697 GtkEntryPrivate *priv = entry->priv;
6699 if (priv->buffer == NULL)
6701 GtkEntryBuffer *buffer;
6702 buffer = gtk_entry_buffer_new (NULL, 0);
6703 gtk_entry_set_buffer (entry, buffer);
6704 g_object_unref (buffer);
6707 return priv->buffer;
6711 * gtk_entry_get_buffer:
6712 * @entry: a #GtkEntry
6714 * Get the #GtkEntryBuffer object which holds the text for
6719 * Returns: (transfer none): A #GtkEntryBuffer object.
6722 gtk_entry_get_buffer (GtkEntry *entry)
6724 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6726 return get_buffer (entry);
6730 * gtk_entry_set_buffer:
6731 * @entry: a #GtkEntry
6732 * @buffer: a #GtkEntryBuffer
6734 * Set the #GtkEntryBuffer object which holds the text for
6740 gtk_entry_set_buffer (GtkEntry *entry,
6741 GtkEntryBuffer *buffer)
6743 GtkEntryPrivate *priv;
6746 g_return_if_fail (GTK_IS_ENTRY (entry));
6752 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6753 g_object_ref (buffer);
6758 buffer_disconnect_signals (entry);
6759 g_object_unref (priv->buffer);
6762 priv->buffer = buffer;
6765 buffer_connect_signals (entry);
6767 obj = G_OBJECT (entry);
6768 g_object_freeze_notify (obj);
6769 g_object_notify (obj, "buffer");
6770 g_object_notify (obj, "text");
6771 g_object_notify (obj, "text-length");
6772 g_object_notify (obj, "max-length");
6773 g_object_notify (obj, "visibility");
6774 g_object_notify (obj, "invisible-char");
6775 g_object_notify (obj, "invisible-char-set");
6776 g_object_thaw_notify (obj);
6778 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6779 gtk_entry_recompute (entry);
6783 * gtk_entry_get_text_area:
6784 * @entry: a #GtkEntry
6785 * @text_area: (out): Return location for the text area.
6787 * Gets the area where the entry's text is drawn. This function is
6788 * useful when drawing something to the entry in a draw callback.
6790 * If the entry is not realized, @text_area is filled with zeros.
6792 * See also gtk_entry_get_icon_area().
6797 gtk_entry_get_text_area (GtkEntry *entry,
6798 GdkRectangle *text_area)
6800 GtkEntryPrivate *priv;
6802 g_return_if_fail (GTK_IS_ENTRY (entry));
6803 g_return_if_fail (text_area != NULL);
6807 if (priv->text_area)
6809 GtkAllocation allocation;
6812 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6813 gdk_window_get_position (priv->text_area, &x, &y);
6815 text_area->x = x - allocation.x;
6816 text_area->y = y - allocation.y;
6817 text_area->width = gdk_window_get_width (priv->text_area);
6818 text_area->height = gdk_window_get_height (priv->text_area);
6824 text_area->width = 0;
6825 text_area->height = 0;
6830 * gtk_entry_set_text:
6831 * @entry: a #GtkEntry
6832 * @text: the new text
6834 * Sets the text in the widget to the given
6835 * value, replacing the current contents.
6837 * See gtk_entry_buffer_set_text().
6840 gtk_entry_set_text (GtkEntry *entry,
6844 GtkEntryCompletion *completion;
6846 g_return_if_fail (GTK_IS_ENTRY (entry));
6847 g_return_if_fail (text != NULL);
6849 /* Actually setting the text will affect the cursor and selection;
6850 * if the contents don't actually change, this will look odd to the user.
6852 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6855 completion = gtk_entry_get_completion (entry);
6856 if (completion && completion->priv->changed_id > 0)
6857 g_signal_handler_block (entry, completion->priv->changed_id);
6859 begin_change (entry);
6860 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6862 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6865 if (completion && completion->priv->changed_id > 0)
6866 g_signal_handler_unblock (entry, completion->priv->changed_id);
6870 * gtk_entry_set_visibility:
6871 * @entry: a #GtkEntry
6872 * @visible: %TRUE if the contents of the entry are displayed
6875 * Sets whether the contents of the entry are visible or not.
6876 * When visibility is set to %FALSE, characters are displayed
6877 * as the invisible char, and will also appear that way when
6878 * the text in the entry widget is copied elsewhere.
6880 * By default, GTK+ picks the best invisible character available
6881 * in the current font, but it can be changed with
6882 * gtk_entry_set_invisible_char().
6885 gtk_entry_set_visibility (GtkEntry *entry,
6888 GtkEntryPrivate *priv;
6890 g_return_if_fail (GTK_IS_ENTRY (entry));
6894 visible = visible != FALSE;
6896 if (priv->visible != visible)
6898 priv->visible = visible;
6900 g_object_notify (G_OBJECT (entry), "visibility");
6901 gtk_entry_recompute (entry);
6906 * gtk_entry_get_visibility:
6907 * @entry: a #GtkEntry
6909 * Retrieves whether the text in @entry is visible. See
6910 * gtk_entry_set_visibility().
6912 * Return value: %TRUE if the text is currently visible
6915 gtk_entry_get_visibility (GtkEntry *entry)
6917 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6919 return entry->priv->visible;
6923 * gtk_entry_set_invisible_char:
6924 * @entry: a #GtkEntry
6925 * @ch: a Unicode character
6927 * Sets the character to use in place of the actual text when
6928 * gtk_entry_set_visibility() has been called to set text visibility
6929 * to %FALSE. i.e. this is the character used in "password mode" to
6930 * show the user how many characters have been typed. By default, GTK+
6931 * picks the best invisible char available in the current font. If you
6932 * set the invisible char to 0, then the user will get no feedback
6933 * at all; there will be no text on the screen as they type.
6936 gtk_entry_set_invisible_char (GtkEntry *entry,
6939 GtkEntryPrivate *priv;
6941 g_return_if_fail (GTK_IS_ENTRY (entry));
6945 if (!priv->invisible_char_set)
6947 priv->invisible_char_set = TRUE;
6948 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6951 if (ch == priv->invisible_char)
6954 priv->invisible_char = ch;
6955 g_object_notify (G_OBJECT (entry), "invisible-char");
6956 gtk_entry_recompute (entry);
6960 * gtk_entry_get_invisible_char:
6961 * @entry: a #GtkEntry
6963 * Retrieves the character displayed in place of the real characters
6964 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6966 * Return value: the current invisible char, or 0, if the entry does not
6967 * show invisible text at all.
6970 gtk_entry_get_invisible_char (GtkEntry *entry)
6972 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6974 return entry->priv->invisible_char;
6978 * gtk_entry_unset_invisible_char:
6979 * @entry: a #GtkEntry
6981 * Unsets the invisible char previously set with
6982 * gtk_entry_set_invisible_char(). So that the
6983 * default invisible char is used again.
6988 gtk_entry_unset_invisible_char (GtkEntry *entry)
6990 GtkEntryPrivate *priv;
6993 g_return_if_fail (GTK_IS_ENTRY (entry));
6997 if (!priv->invisible_char_set)
7000 priv->invisible_char_set = FALSE;
7001 ch = find_invisible_char (GTK_WIDGET (entry));
7003 if (priv->invisible_char != ch)
7005 priv->invisible_char = ch;
7006 g_object_notify (G_OBJECT (entry), "invisible-char");
7009 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7010 gtk_entry_recompute (entry);
7014 * gtk_entry_set_overwrite_mode:
7015 * @entry: a #GtkEntry
7016 * @overwrite: new value
7018 * Sets whether the text is overwritten when typing in the #GtkEntry.
7023 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7026 GtkEntryPrivate *priv = entry->priv;
7028 g_return_if_fail (GTK_IS_ENTRY (entry));
7030 if (priv->overwrite_mode == overwrite)
7033 gtk_entry_toggle_overwrite (entry);
7035 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7039 * gtk_entry_get_overwrite_mode:
7040 * @entry: a #GtkEntry
7042 * Gets the value set by gtk_entry_set_overwrite_mode().
7044 * Return value: whether the text is overwritten when typing.
7049 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7051 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7053 return entry->priv->overwrite_mode;
7057 * gtk_entry_get_text:
7058 * @entry: a #GtkEntry
7060 * Retrieves the contents of the entry widget.
7061 * See also gtk_editable_get_chars().
7063 * This is equivalent to:
7065 * <informalexample><programlisting>
7066 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7067 * </programlisting></informalexample>
7069 * Return value: a pointer to the contents of the widget as a
7070 * string. This string points to internally allocated
7071 * storage in the widget and must not be freed, modified or
7075 gtk_entry_get_text (GtkEntry *entry)
7077 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7079 return gtk_entry_buffer_get_text (get_buffer (entry));
7083 * gtk_entry_set_max_length:
7084 * @entry: a #GtkEntry
7085 * @max: the maximum length of the entry, or 0 for no maximum.
7086 * (other than the maximum length of entries.) The value passed in will
7087 * be clamped to the range 0-65536.
7089 * Sets the maximum allowed length of the contents of the widget. If
7090 * the current contents are longer than the given length, then they
7091 * will be truncated to fit.
7093 * This is equivalent to:
7095 * <informalexample><programlisting>
7096 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7097 * </programlisting></informalexample>
7100 gtk_entry_set_max_length (GtkEntry *entry,
7103 g_return_if_fail (GTK_IS_ENTRY (entry));
7104 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7108 * gtk_entry_get_max_length:
7109 * @entry: a #GtkEntry
7111 * Retrieves the maximum allowed length of the text in
7112 * @entry. See gtk_entry_set_max_length().
7114 * This is equivalent to:
7116 * <informalexample><programlisting>
7117 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7118 * </programlisting></informalexample>
7120 * Return value: the maximum allowed number of characters
7121 * in #GtkEntry, or 0 if there is no maximum.
7124 gtk_entry_get_max_length (GtkEntry *entry)
7126 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7128 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7132 * gtk_entry_get_text_length:
7133 * @entry: a #GtkEntry
7135 * Retrieves the current length of the text in
7138 * This is equivalent to:
7140 * <informalexample><programlisting>
7141 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7142 * </programlisting></informalexample>
7144 * Return value: the current number of characters
7145 * in #GtkEntry, or 0 if there are none.
7150 gtk_entry_get_text_length (GtkEntry *entry)
7152 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7154 return gtk_entry_buffer_get_length (get_buffer (entry));
7158 * gtk_entry_set_activates_default:
7159 * @entry: a #GtkEntry
7160 * @setting: %TRUE to activate window's default widget on Enter keypress
7162 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7163 * widget for the window containing the entry. This usually means that
7164 * the dialog box containing the entry will be closed, since the default
7165 * widget is usually one of the dialog buttons.
7167 * (For experts: if @setting is %TRUE, the entry calls
7168 * gtk_window_activate_default() on the window containing the entry, in
7169 * the default handler for the #GtkWidget::activate signal.)
7172 gtk_entry_set_activates_default (GtkEntry *entry,
7175 GtkEntryPrivate *priv;
7177 g_return_if_fail (GTK_IS_ENTRY (entry));
7181 setting = setting != FALSE;
7183 if (setting != priv->activates_default)
7185 priv->activates_default = setting;
7186 g_object_notify (G_OBJECT (entry), "activates-default");
7191 * gtk_entry_get_activates_default:
7192 * @entry: a #GtkEntry
7194 * Retrieves the value set by gtk_entry_set_activates_default().
7196 * Return value: %TRUE if the entry will activate the default widget
7199 gtk_entry_get_activates_default (GtkEntry *entry)
7201 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7203 return entry->priv->activates_default;
7207 * gtk_entry_set_width_chars:
7208 * @entry: a #GtkEntry
7209 * @n_chars: width in chars
7211 * Changes the size request of the entry to be about the right size
7212 * for @n_chars characters. Note that it changes the size
7213 * <emphasis>request</emphasis>, the size can still be affected by
7214 * how you pack the widget into containers. If @n_chars is -1, the
7215 * size reverts to the default entry size.
7218 gtk_entry_set_width_chars (GtkEntry *entry,
7221 GtkEntryPrivate *priv;
7223 g_return_if_fail (GTK_IS_ENTRY (entry));
7227 if (priv->width_chars != n_chars)
7229 priv->width_chars = n_chars;
7230 g_object_notify (G_OBJECT (entry), "width-chars");
7231 gtk_widget_queue_resize (GTK_WIDGET (entry));
7236 * gtk_entry_get_width_chars:
7237 * @entry: a #GtkEntry
7239 * Gets the value set by gtk_entry_set_width_chars().
7241 * Return value: number of chars to request space for, or negative if unset
7244 gtk_entry_get_width_chars (GtkEntry *entry)
7246 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7248 return entry->priv->width_chars;
7252 * gtk_entry_set_has_frame:
7253 * @entry: a #GtkEntry
7254 * @setting: new value
7256 * Sets whether the entry has a beveled frame around it.
7259 gtk_entry_set_has_frame (GtkEntry *entry,
7262 GtkEntryPrivate *priv;
7264 g_return_if_fail (GTK_IS_ENTRY (entry));
7268 setting = (setting != FALSE);
7270 if (priv->has_frame == setting)
7273 gtk_widget_queue_resize (GTK_WIDGET (entry));
7274 priv->has_frame = setting;
7275 g_object_notify (G_OBJECT (entry), "has-frame");
7279 * gtk_entry_get_has_frame:
7280 * @entry: a #GtkEntry
7282 * Gets the value set by gtk_entry_set_has_frame().
7284 * Return value: whether the entry has a beveled frame
7287 gtk_entry_get_has_frame (GtkEntry *entry)
7289 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7291 return entry->priv->has_frame;
7295 * gtk_entry_set_inner_border:
7296 * @entry: a #GtkEntry
7297 * @border: (allow-none): a #GtkBorder, or %NULL
7299 * Sets %entry's inner-border property to %border, or clears it if %NULL
7300 * is passed. The inner-border is the area around the entry's text, but
7303 * If set, this property overrides the inner-border style property.
7304 * Overriding the style-provided border is useful when you want to do
7305 * in-place editing of some text in a canvas or list widget, where
7306 * pixel-exact positioning of the entry is important.
7310 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7311 * the value set with this function is ignored by #GtkEntry.
7314 gtk_entry_set_inner_border (GtkEntry *entry,
7315 const GtkBorder *border)
7317 g_return_if_fail (GTK_IS_ENTRY (entry));
7319 gtk_entry_do_set_inner_border (entry, border);
7323 * gtk_entry_get_inner_border:
7324 * @entry: a #GtkEntry
7326 * This function returns the entry's #GtkEntry:inner-border property. See
7327 * gtk_entry_set_inner_border() for more information.
7329 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7333 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7334 * the value returned by this function is ignored by #GtkEntry.
7337 gtk_entry_get_inner_border (GtkEntry *entry)
7339 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7341 return gtk_entry_do_get_inner_border (entry);
7345 * gtk_entry_get_layout:
7346 * @entry: a #GtkEntry
7348 * Gets the #PangoLayout used to display the entry.
7349 * The layout is useful to e.g. convert text positions to
7350 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7351 * The returned layout is owned by the entry and must not be
7352 * modified or freed by the caller.
7354 * Keep in mind that the layout text may contain a preedit string, so
7355 * gtk_entry_layout_index_to_text_index() and
7356 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7357 * indices in the layout to byte indices in the entry contents.
7359 * Return value: (transfer none): the #PangoLayout for this entry
7362 gtk_entry_get_layout (GtkEntry *entry)
7364 PangoLayout *layout;
7366 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7368 layout = gtk_entry_ensure_layout (entry, TRUE);
7375 * gtk_entry_layout_index_to_text_index:
7376 * @entry: a #GtkEntry
7377 * @layout_index: byte index into the entry layout text
7379 * Converts from a position in the entry contents (returned
7380 * by gtk_entry_get_text()) to a position in the
7381 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7382 * with text retrieved via pango_layout_get_text()).
7384 * Return value: byte index into the entry contents
7387 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7390 GtkEntryPrivate *priv;
7391 PangoLayout *layout;
7395 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7399 layout = gtk_entry_ensure_layout (entry, TRUE);
7400 text = pango_layout_get_text (layout);
7401 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7403 if (layout_index >= cursor_index && priv->preedit_length)
7405 if (layout_index >= cursor_index + priv->preedit_length)
7406 layout_index -= priv->preedit_length;
7408 layout_index = cursor_index;
7411 return layout_index;
7415 * gtk_entry_text_index_to_layout_index:
7416 * @entry: a #GtkEntry
7417 * @text_index: byte index into the entry contents
7419 * Converts from a position in the entry's #PangoLayout (returned by
7420 * gtk_entry_get_layout()) to a position in the entry contents
7421 * (returned by gtk_entry_get_text()).
7423 * Return value: byte index into the entry layout text
7426 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7429 GtkEntryPrivate *priv;
7430 PangoLayout *layout;
7434 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7438 layout = gtk_entry_ensure_layout (entry, TRUE);
7439 text = pango_layout_get_text (layout);
7440 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7442 if (text_index > cursor_index)
7443 text_index += priv->preedit_length;
7449 * gtk_entry_get_layout_offsets:
7450 * @entry: a #GtkEntry
7451 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7452 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7455 * Obtains the position of the #PangoLayout used to render text
7456 * in the entry, in widget coordinates. Useful if you want to line
7457 * up the text in an entry with some other text, e.g. when using the
7458 * entry to implement editable cells in a sheet widget.
7460 * Also useful to convert mouse events into coordinates inside the
7461 * #PangoLayout, e.g. to take some action if some part of the entry text
7464 * Note that as the user scrolls around in the entry the offsets will
7465 * change; you'll need to connect to the "notify::scroll-offset"
7466 * signal to track this. Remember when using the #PangoLayout
7467 * functions you need to convert to and from pixels using
7468 * PANGO_PIXELS() or #PANGO_SCALE.
7470 * Keep in mind that the layout text may contain a preedit string, so
7471 * gtk_entry_layout_index_to_text_index() and
7472 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7473 * indices in the layout to byte indices in the entry contents.
7476 gtk_entry_get_layout_offsets (GtkEntry *entry,
7480 gint text_area_x, text_area_y;
7482 g_return_if_fail (GTK_IS_ENTRY (entry));
7484 /* this gets coords relative to text area */
7485 get_layout_position (entry, x, y);
7487 /* convert to widget coords */
7488 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7499 * gtk_entry_set_alignment:
7500 * @entry: a #GtkEntry
7501 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7502 * Reversed for RTL layouts
7504 * Sets the alignment for the contents of the entry. This controls
7505 * the horizontal positioning of the contents when the displayed
7506 * text is shorter than the width of the entry.
7511 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7513 GtkEntryPrivate *priv;
7515 g_return_if_fail (GTK_IS_ENTRY (entry));
7521 else if (xalign > 1.0)
7524 if (xalign != priv->xalign)
7526 priv->xalign = xalign;
7528 gtk_entry_recompute (entry);
7530 g_object_notify (G_OBJECT (entry), "xalign");
7535 * gtk_entry_get_alignment:
7536 * @entry: a #GtkEntry
7538 * Gets the value set by gtk_entry_set_alignment().
7540 * Return value: the alignment
7545 gtk_entry_get_alignment (GtkEntry *entry)
7547 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7549 return entry->priv->xalign;
7553 * gtk_entry_set_icon_from_pixbuf:
7554 * @entry: a #GtkEntry
7555 * @icon_pos: Icon position
7556 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7558 * Sets the icon shown in the specified position using a pixbuf.
7560 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7565 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7566 GtkEntryIconPosition icon_pos,
7569 GtkEntryPrivate *priv;
7570 EntryIconInfo *icon_info;
7572 g_return_if_fail (GTK_IS_ENTRY (entry));
7573 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7577 if ((icon_info = priv->icons[icon_pos]) == NULL)
7578 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7580 g_object_freeze_notify (G_OBJECT (entry));
7583 g_object_ref (pixbuf);
7585 gtk_entry_clear (entry, icon_pos);
7589 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7591 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7593 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7594 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7598 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7599 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7602 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7603 gdk_window_show_unraised (icon_info->window);
7605 g_object_unref (pixbuf);
7608 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7609 gtk_widget_queue_resize (GTK_WIDGET (entry));
7611 g_object_thaw_notify (G_OBJECT (entry));
7615 * gtk_entry_set_icon_from_stock:
7616 * @entry: A #GtkEntry
7617 * @icon_pos: Icon position
7618 * @stock_id: (allow-none): The name of the stock item, or %NULL
7620 * Sets the icon shown in the entry at the specified position from
7623 * If @stock_id is %NULL, no icon will be shown in the specified position.
7628 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7629 GtkEntryIconPosition icon_pos,
7630 const gchar *stock_id)
7632 GtkEntryPrivate *priv;
7633 EntryIconInfo *icon_info;
7636 g_return_if_fail (GTK_IS_ENTRY (entry));
7637 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7641 if ((icon_info = priv->icons[icon_pos]) == NULL)
7642 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7644 g_object_freeze_notify (G_OBJECT (entry));
7646 /* need to dup before clearing */
7647 new_id = g_strdup (stock_id);
7649 gtk_entry_clear (entry, icon_pos);
7653 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7655 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7657 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7658 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7662 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7663 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7666 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7667 gdk_window_show_unraised (icon_info->window);
7672 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7673 gtk_widget_queue_resize (GTK_WIDGET (entry));
7675 g_object_thaw_notify (G_OBJECT (entry));
7679 * gtk_entry_set_icon_from_icon_name:
7680 * @entry: A #GtkEntry
7681 * @icon_pos: The position at which to set the icon
7682 * @icon_name: (allow-none): An icon name, or %NULL
7684 * Sets the icon shown in the entry at the specified position
7685 * from the current icon theme.
7687 * If the icon name isn't known, a "broken image" icon will be displayed
7690 * If @icon_name is %NULL, no icon will be shown in the specified position.
7695 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7696 GtkEntryIconPosition icon_pos,
7697 const gchar *icon_name)
7699 GtkEntryPrivate *priv;
7700 EntryIconInfo *icon_info;
7703 g_return_if_fail (GTK_IS_ENTRY (entry));
7704 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7708 if ((icon_info = priv->icons[icon_pos]) == NULL)
7709 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7711 g_object_freeze_notify (G_OBJECT (entry));
7713 /* need to dup before clearing */
7714 new_name = g_strdup (icon_name);
7716 gtk_entry_clear (entry, icon_pos);
7718 if (new_name != NULL)
7720 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7722 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7724 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7725 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7729 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7730 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7733 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7734 gdk_window_show_unraised (icon_info->window);
7739 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7740 gtk_widget_queue_resize (GTK_WIDGET (entry));
7742 g_object_thaw_notify (G_OBJECT (entry));
7746 * gtk_entry_set_icon_from_gicon:
7747 * @entry: A #GtkEntry
7748 * @icon_pos: The position at which to set the icon
7749 * @icon: (allow-none): The icon to set, or %NULL
7751 * Sets the icon shown in the entry at the specified position
7752 * from the current icon theme.
7753 * If the icon isn't known, a "broken image" icon will be displayed
7756 * If @icon is %NULL, no icon will be shown in the specified position.
7761 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7762 GtkEntryIconPosition icon_pos,
7765 GtkEntryPrivate *priv;
7766 EntryIconInfo *icon_info;
7768 g_return_if_fail (GTK_IS_ENTRY (entry));
7769 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7773 if ((icon_info = priv->icons[icon_pos]) == NULL)
7774 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7776 g_object_freeze_notify (G_OBJECT (entry));
7778 /* need to ref before clearing */
7780 g_object_ref (icon);
7782 gtk_entry_clear (entry, icon_pos);
7786 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7788 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7790 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7791 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7795 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7796 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7799 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7800 gdk_window_show_unraised (icon_info->window);
7802 g_object_unref (icon);
7805 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7806 gtk_widget_queue_resize (GTK_WIDGET (entry));
7808 g_object_thaw_notify (G_OBJECT (entry));
7812 * gtk_entry_set_icon_activatable:
7813 * @entry: A #GtkEntry
7814 * @icon_pos: Icon position
7815 * @activatable: %TRUE if the icon should be activatable
7817 * Sets whether the icon is activatable.
7822 gtk_entry_set_icon_activatable (GtkEntry *entry,
7823 GtkEntryIconPosition icon_pos,
7824 gboolean activatable)
7826 GtkEntryPrivate *priv;
7827 EntryIconInfo *icon_info;
7829 g_return_if_fail (GTK_IS_ENTRY (entry));
7830 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7834 if ((icon_info = priv->icons[icon_pos]) == NULL)
7835 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7837 activatable = activatable != FALSE;
7839 if (icon_info->nonactivatable != !activatable)
7841 icon_info->nonactivatable = !activatable;
7843 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7844 update_cursors (GTK_WIDGET (entry));
7846 g_object_notify (G_OBJECT (entry),
7847 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7852 * gtk_entry_get_icon_activatable:
7853 * @entry: a #GtkEntry
7854 * @icon_pos: Icon position
7856 * Returns whether the icon is activatable.
7858 * Returns: %TRUE if the icon is activatable.
7863 gtk_entry_get_icon_activatable (GtkEntry *entry,
7864 GtkEntryIconPosition icon_pos)
7866 GtkEntryPrivate *priv;
7867 EntryIconInfo *icon_info;
7869 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7870 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7873 icon_info = priv->icons[icon_pos];
7875 return (!icon_info || !icon_info->nonactivatable);
7879 * gtk_entry_get_icon_pixbuf:
7880 * @entry: A #GtkEntry
7881 * @icon_pos: Icon position
7883 * Retrieves the image used for the icon.
7885 * Unlike the other methods of setting and getting icon data, this
7886 * method will work regardless of whether the icon was set using a
7887 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7889 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7890 * set for this position.
7895 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7896 GtkEntryIconPosition icon_pos)
7898 GtkEntryPrivate *priv;
7899 EntryIconInfo *icon_info;
7902 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7903 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7907 icon_info = priv->icons[icon_pos];
7912 /* HACK: unfortunately this is transfer none, so we need to return
7913 * the icon helper's cache ref directly.
7915 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7916 g_object_unref (pixbuf);
7922 * gtk_entry_get_icon_gicon:
7923 * @entry: A #GtkEntry
7924 * @icon_pos: Icon position
7926 * Retrieves the #GIcon used for the icon, or %NULL if there is
7927 * no icon or if the icon was set by some other method (e.g., by
7928 * stock, pixbuf, or icon name).
7930 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7931 * or if the icon is not a #GIcon
7936 gtk_entry_get_icon_gicon (GtkEntry *entry,
7937 GtkEntryIconPosition icon_pos)
7939 GtkEntryPrivate *priv;
7940 EntryIconInfo *icon_info;
7942 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7943 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7946 icon_info = priv->icons[icon_pos];
7951 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7955 * gtk_entry_get_icon_stock:
7956 * @entry: A #GtkEntry
7957 * @icon_pos: Icon position
7959 * Retrieves the stock id used for the icon, or %NULL if there is
7960 * no icon or if the icon was set by some other method (e.g., by
7961 * pixbuf, icon name or gicon).
7963 * Returns: A stock id, or %NULL if no icon is set or if the icon
7964 * wasn't set from a stock id
7969 gtk_entry_get_icon_stock (GtkEntry *entry,
7970 GtkEntryIconPosition icon_pos)
7972 GtkEntryPrivate *priv;
7973 EntryIconInfo *icon_info;
7975 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7976 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7979 icon_info = priv->icons[icon_pos];
7984 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
7988 * gtk_entry_get_icon_name:
7989 * @entry: A #GtkEntry
7990 * @icon_pos: Icon position
7992 * Retrieves the icon name used for the icon, or %NULL if there is
7993 * no icon or if the icon was set by some other method (e.g., by
7994 * pixbuf, stock or gicon).
7996 * Returns: An icon name, or %NULL if no icon is set or if the icon
7997 * wasn't set from an icon name
8002 gtk_entry_get_icon_name (GtkEntry *entry,
8003 GtkEntryIconPosition icon_pos)
8005 GtkEntryPrivate *priv;
8006 EntryIconInfo *icon_info;
8008 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8009 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8012 icon_info = priv->icons[icon_pos];
8017 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8021 * gtk_entry_set_icon_sensitive:
8022 * @entry: A #GtkEntry
8023 * @icon_pos: Icon position
8024 * @sensitive: Specifies whether the icon should appear
8025 * sensitive or insensitive
8027 * Sets the sensitivity for the specified icon.
8032 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8033 GtkEntryIconPosition icon_pos,
8036 GtkEntryPrivate *priv;
8037 EntryIconInfo *icon_info;
8039 g_return_if_fail (GTK_IS_ENTRY (entry));
8040 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8044 if ((icon_info = priv->icons[icon_pos]) == NULL)
8045 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8047 if (icon_info->insensitive != !sensitive)
8049 icon_info->insensitive = !sensitive;
8051 icon_info->pressed = FALSE;
8052 icon_info->prelight = FALSE;
8054 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8055 update_cursors (GTK_WIDGET (entry));
8057 gtk_widget_queue_draw (GTK_WIDGET (entry));
8059 g_object_notify (G_OBJECT (entry),
8060 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8065 * gtk_entry_get_icon_sensitive:
8066 * @entry: a #GtkEntry
8067 * @icon_pos: Icon position
8069 * Returns whether the icon appears sensitive or insensitive.
8071 * Returns: %TRUE if the icon is sensitive.
8076 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8077 GtkEntryIconPosition icon_pos)
8079 GtkEntryPrivate *priv;
8080 EntryIconInfo *icon_info;
8082 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8083 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8087 icon_info = priv->icons[icon_pos];
8089 return (!icon_info || !icon_info->insensitive);
8094 * gtk_entry_get_icon_storage_type:
8095 * @entry: a #GtkEntry
8096 * @icon_pos: Icon position
8098 * Gets the type of representation being used by the icon
8099 * to store image data. If the icon has no image data,
8100 * the return value will be %GTK_IMAGE_EMPTY.
8102 * Return value: image representation being used
8107 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8108 GtkEntryIconPosition icon_pos)
8110 GtkEntryPrivate *priv;
8111 EntryIconInfo *icon_info;
8113 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8114 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8118 icon_info = priv->icons[icon_pos];
8121 return GTK_IMAGE_EMPTY;
8123 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8127 * gtk_entry_get_icon_at_pos:
8128 * @entry: a #GtkEntry
8129 * @x: the x coordinate of the position to find
8130 * @y: the y coordinate of the position to find
8132 * Finds the icon at the given position and return its index. The
8133 * position's coordinates are relative to the @entry's top left corner.
8134 * If @x, @y doesn't lie inside an icon, -1 is returned.
8135 * This function is intended for use in a #GtkWidget::query-tooltip
8138 * Returns: the index of the icon at the given position, or -1
8143 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8147 GtkAllocation primary;
8148 GtkAllocation secondary;
8149 gint frame_x, frame_y;
8151 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8153 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8157 get_icon_allocations (entry, &primary, &secondary);
8159 if (primary.x <= x && x < primary.x + primary.width &&
8160 primary.y <= y && y < primary.y + primary.height)
8161 return GTK_ENTRY_ICON_PRIMARY;
8163 if (secondary.x <= x && x < secondary.x + secondary.width &&
8164 secondary.y <= y && y < secondary.y + secondary.height)
8165 return GTK_ENTRY_ICON_SECONDARY;
8171 * gtk_entry_set_icon_drag_source:
8172 * @entry: a #GtkIconEntry
8173 * @icon_pos: icon position
8174 * @target_list: the targets (data formats) in which the data can be provided
8175 * @actions: a bitmask of the allowed drag actions
8177 * Sets up the icon at the given position so that GTK+ will start a drag
8178 * operation when the user clicks and drags the icon.
8180 * To handle the drag operation, you need to connect to the usual
8181 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8182 * signal, and use gtk_entry_get_current_icon_drag_source() in
8183 * your signal handler to find out if the drag was started from
8186 * By default, GTK+ uses the icon as the drag icon. You can use the
8187 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8188 * have to use g_signal_connect_after() to ensure that your signal handler
8189 * gets executed after the default handler.
8194 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8195 GtkEntryIconPosition icon_pos,
8196 GtkTargetList *target_list,
8197 GdkDragAction actions)
8199 GtkEntryPrivate *priv;
8200 EntryIconInfo *icon_info;
8202 g_return_if_fail (GTK_IS_ENTRY (entry));
8203 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8207 if ((icon_info = priv->icons[icon_pos]) == NULL)
8208 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8210 if (icon_info->target_list)
8211 gtk_target_list_unref (icon_info->target_list);
8212 icon_info->target_list = target_list;
8213 if (icon_info->target_list)
8214 gtk_target_list_ref (icon_info->target_list);
8216 icon_info->actions = actions;
8220 * gtk_entry_get_current_icon_drag_source:
8221 * @entry: a #GtkIconEntry
8223 * Returns the index of the icon which is the source of the current
8224 * DND operation, or -1.
8226 * This function is meant to be used in a #GtkWidget::drag-data-get
8229 * Returns: index of the icon which is the source of the current
8230 * DND operation, or -1.
8235 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8237 GtkEntryPrivate *priv;
8238 EntryIconInfo *icon_info = NULL;
8241 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8245 for (i = 0; i < MAX_ICONS; i++)
8247 if ((icon_info = priv->icons[i]))
8249 if (icon_info->in_drag)
8258 * gtk_entry_get_icon_area:
8259 * @entry: A #GtkEntry
8260 * @icon_pos: Icon position
8261 * @icon_area: (out): Return location for the icon's area
8263 * Gets the area where entry's icon at @icon_pos is drawn.
8264 * This function is useful when drawing something to the
8265 * entry in a draw callback.
8267 * If the entry is not realized or has no icon at the given position,
8268 * @icon_area is filled with zeros.
8270 * See also gtk_entry_get_text_area()
8275 gtk_entry_get_icon_area (GtkEntry *entry,
8276 GtkEntryIconPosition icon_pos,
8277 GdkRectangle *icon_area)
8279 GtkEntryPrivate *priv;
8280 EntryIconInfo *icon_info;
8282 g_return_if_fail (GTK_IS_ENTRY (entry));
8283 g_return_if_fail (icon_area != NULL);
8287 icon_info = priv->icons[icon_pos];
8291 GtkAllocation primary;
8292 GtkAllocation secondary;
8294 get_icon_allocations (entry, &primary, &secondary);
8296 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8297 *icon_area = primary;
8299 *icon_area = secondary;
8305 icon_area->width = 0;
8306 icon_area->height = 0;
8311 ensure_has_tooltip (GtkEntry *entry)
8313 GtkEntryPrivate *priv;
8314 EntryIconInfo *icon_info;
8316 gboolean has_tooltip = FALSE;
8320 for (i = 0; i < MAX_ICONS; i++)
8322 if ((icon_info = priv->icons[i]) != NULL)
8324 if (icon_info->tooltip != NULL)
8332 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8336 * gtk_entry_get_icon_tooltip_text:
8337 * @entry: a #GtkEntry
8338 * @icon_pos: the icon position
8340 * Gets the contents of the tooltip on the icon at the specified
8341 * position in @entry.
8343 * Returns: the tooltip text, or %NULL. Free the returned string
8344 * with g_free() when done.
8349 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8350 GtkEntryIconPosition icon_pos)
8352 GtkEntryPrivate *priv;
8353 EntryIconInfo *icon_info;
8356 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8357 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8361 icon_info = priv->icons[icon_pos];
8366 if (icon_info->tooltip &&
8367 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8368 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8374 * gtk_entry_set_icon_tooltip_text:
8375 * @entry: a #GtkEntry
8376 * @icon_pos: the icon position
8377 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8379 * Sets @tooltip as the contents of the tooltip for the icon
8380 * at the specified position.
8382 * Use %NULL for @tooltip to remove an existing tooltip.
8384 * See also gtk_widget_set_tooltip_text() and
8385 * gtk_entry_set_icon_tooltip_markup().
8390 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8391 GtkEntryIconPosition icon_pos,
8392 const gchar *tooltip)
8394 GtkEntryPrivate *priv;
8395 EntryIconInfo *icon_info;
8397 g_return_if_fail (GTK_IS_ENTRY (entry));
8398 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8402 if ((icon_info = priv->icons[icon_pos]) == NULL)
8403 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8405 if (icon_info->tooltip)
8406 g_free (icon_info->tooltip);
8408 /* Treat an empty string as a NULL string,
8409 * because an empty string would be useless for a tooltip:
8411 if (tooltip && tooltip[0] == '\0')
8414 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8416 ensure_has_tooltip (entry);
8420 * gtk_entry_get_icon_tooltip_markup:
8421 * @entry: a #GtkEntry
8422 * @icon_pos: the icon position
8424 * Gets the contents of the tooltip on the icon at the specified
8425 * position in @entry.
8427 * Returns: the tooltip text, or %NULL. Free the returned string
8428 * with g_free() when done.
8433 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8434 GtkEntryIconPosition icon_pos)
8436 GtkEntryPrivate *priv;
8437 EntryIconInfo *icon_info;
8439 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8440 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8444 icon_info = priv->icons[icon_pos];
8449 return g_strdup (icon_info->tooltip);
8453 * gtk_entry_set_icon_tooltip_markup:
8454 * @entry: a #GtkEntry
8455 * @icon_pos: the icon position
8456 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8458 * Sets @tooltip as the contents of the tooltip for the icon at
8459 * the specified position. @tooltip is assumed to be marked up with
8460 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8462 * Use %NULL for @tooltip to remove an existing tooltip.
8464 * See also gtk_widget_set_tooltip_markup() and
8465 * gtk_enty_set_icon_tooltip_text().
8470 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8471 GtkEntryIconPosition icon_pos,
8472 const gchar *tooltip)
8474 GtkEntryPrivate *priv;
8475 EntryIconInfo *icon_info;
8477 g_return_if_fail (GTK_IS_ENTRY (entry));
8478 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8482 if ((icon_info = priv->icons[icon_pos]) == NULL)
8483 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8485 if (icon_info->tooltip)
8486 g_free (icon_info->tooltip);
8488 /* Treat an empty string as a NULL string,
8489 * because an empty string would be useless for a tooltip:
8491 if (tooltip && tooltip[0] == '\0')
8494 icon_info->tooltip = g_strdup (tooltip);
8496 ensure_has_tooltip (entry);
8500 gtk_entry_query_tooltip (GtkWidget *widget,
8503 gboolean keyboard_tip,
8504 GtkTooltip *tooltip)
8507 GtkEntryPrivate *priv;
8508 EntryIconInfo *icon_info;
8511 entry = GTK_ENTRY (widget);
8516 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8519 if ((icon_info = priv->icons[icon_pos]) != NULL)
8521 if (icon_info->tooltip)
8523 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8532 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8539 /* Quick hack of a popup menu
8542 activate_cb (GtkWidget *menuitem,
8545 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8546 g_signal_emit_by_name (entry, signal);
8551 gtk_entry_mnemonic_activate (GtkWidget *widget,
8552 gboolean group_cycling)
8554 gtk_widget_grab_focus (widget);
8559 append_action_signal (GtkEntry *entry,
8561 const gchar *stock_id,
8562 const gchar *signal,
8565 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8567 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8568 g_signal_connect (menuitem, "activate",
8569 G_CALLBACK (activate_cb), entry);
8571 gtk_widget_set_sensitive (menuitem, sensitive);
8573 gtk_widget_show (menuitem);
8574 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8578 popup_menu_detach (GtkWidget *attach_widget,
8581 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8582 GtkEntryPrivate *priv_attach = entry_attach->priv;
8584 priv_attach->popup_menu = NULL;
8588 popup_position_func (GtkMenu *menu,
8594 GtkEntry *entry = GTK_ENTRY (user_data);
8595 GtkEntryPrivate *priv = entry->priv;
8596 GtkWidget *widget = GTK_WIDGET (entry);
8598 GtkRequisition menu_req;
8599 GdkRectangle monitor;
8601 gint monitor_num, strong_x, height;
8603 g_return_if_fail (gtk_widget_get_realized (widget));
8605 gdk_window_get_origin (priv->text_area, x, y);
8607 screen = gtk_widget_get_screen (widget);
8608 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8609 if (monitor_num < 0)
8611 gtk_menu_set_monitor (menu, monitor_num);
8613 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8614 gtk_widget_get_preferred_size (priv->popup_menu,
8616 height = gdk_window_get_height (priv->text_area);
8617 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8618 _gtk_entry_get_borders (entry, &borders);
8620 *x += borders.left + strong_x - priv->scroll_offset;
8621 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8622 *x -= menu_req.width;
8624 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8626 else if ((*y - menu_req.height) >= monitor.y)
8627 *y -= menu_req.height;
8628 else if (monitor.y + monitor.height - (*y + height) > *y)
8631 *y -= menu_req.height;
8637 unichar_chosen_func (const char *text,
8640 GtkEntry *entry = GTK_ENTRY (data);
8641 GtkEntryPrivate *priv = entry->priv;
8644 gtk_entry_enter_text (entry, text);
8656 popup_targets_received (GtkClipboard *clipboard,
8657 GtkSelectionData *data,
8660 PopupInfo *info = user_data;
8661 GtkEntry *entry = info->entry;
8662 GtkEntryPrivate *info_entry_priv = entry->priv;
8664 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8667 gboolean clipboard_contains_text;
8668 GtkWidget *menuitem;
8670 gboolean show_input_method_menu;
8671 gboolean show_unicode_menu;
8673 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8674 if (info_entry_priv->popup_menu)
8675 gtk_widget_destroy (info_entry_priv->popup_menu);
8677 info_entry_priv->popup_menu = gtk_menu_new ();
8679 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8683 mode = gtk_entry_get_display_mode (entry);
8684 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8685 info_entry_priv->editable && 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_COPY, "copy-clipboard",
8689 mode == DISPLAY_NORMAL &&
8690 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8692 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8693 info_entry_priv->editable && clipboard_contains_text);
8695 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8696 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8697 g_signal_connect_swapped (menuitem, "activate",
8698 G_CALLBACK (gtk_entry_delete_cb), entry);
8699 gtk_widget_show (menuitem);
8700 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8702 menuitem = gtk_separator_menu_item_new ();
8703 gtk_widget_show (menuitem);
8704 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8706 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8707 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8708 g_signal_connect_swapped (menuitem, "activate",
8709 G_CALLBACK (gtk_entry_select_all), entry);
8710 gtk_widget_show (menuitem);
8711 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8713 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8714 "gtk-show-input-method-menu", &show_input_method_menu,
8715 "gtk-show-unicode-menu", &show_unicode_menu,
8718 if (show_input_method_menu || show_unicode_menu)
8720 menuitem = gtk_separator_menu_item_new ();
8721 gtk_widget_show (menuitem);
8722 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8725 if (show_input_method_menu)
8727 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8728 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8729 gtk_widget_show (menuitem);
8730 submenu = gtk_menu_new ();
8731 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8733 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8735 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8736 GTK_MENU_SHELL (submenu));
8739 if (show_unicode_menu)
8741 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8742 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8743 gtk_widget_show (menuitem);
8745 submenu = gtk_menu_new ();
8746 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8747 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8749 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8750 unichar_chosen_func,
8754 g_signal_emit (entry,
8755 signals[POPULATE_POPUP],
8757 info_entry_priv->popup_menu);
8761 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8762 info->device, NULL, NULL, NULL, NULL, NULL,
8763 info->button, info->time);
8766 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8767 popup_position_func, entry,
8768 0, gtk_get_current_event_time ());
8769 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8773 g_object_unref (entry);
8774 g_slice_free (PopupInfo, info);
8778 gtk_entry_do_popup (GtkEntry *entry,
8779 GdkEventButton *event)
8781 PopupInfo *info = g_slice_new (PopupInfo);
8783 /* In order to know what entries we should make sensitive, we
8784 * ask for the current targets of the clipboard, and when
8785 * we get them, then we actually pop up the menu.
8787 info->entry = g_object_ref (entry);
8791 info->button = event->button;
8792 info->time = event->time;
8793 info->device = event->device;
8798 info->time = gtk_get_current_event_time ();
8799 info->device = NULL;
8802 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8803 gdk_atom_intern_static_string ("TARGETS"),
8804 popup_targets_received,
8809 gtk_entry_popup_menu (GtkWidget *widget)
8811 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8816 gtk_entry_drag_begin (GtkWidget *widget,
8817 GdkDragContext *context)
8819 GtkEntry *entry = GTK_ENTRY (widget);
8820 GtkEntryPrivate *priv = entry->priv;
8823 for (i = 0; i < MAX_ICONS; i++)
8825 EntryIconInfo *icon_info = priv->icons[i];
8827 if (icon_info != NULL)
8829 if (icon_info->in_drag)
8833 pix = _gtk_icon_helper_ensure_pixbuf
8834 (icon_info->icon_helper,
8835 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8836 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8838 g_object_unref (pix);
8845 gtk_entry_drag_end (GtkWidget *widget,
8846 GdkDragContext *context)
8848 GtkEntry *entry = GTK_ENTRY (widget);
8849 GtkEntryPrivate *priv = entry->priv;
8852 for (i = 0; i < MAX_ICONS; i++)
8854 EntryIconInfo *icon_info = priv->icons[i];
8856 if (icon_info != NULL)
8857 icon_info->in_drag = 0;
8862 gtk_entry_drag_leave (GtkWidget *widget,
8863 GdkDragContext *context,
8866 GtkEntry *entry = GTK_ENTRY (widget);
8867 GtkEntryPrivate *priv = entry->priv;
8869 priv->dnd_position = -1;
8870 gtk_widget_queue_draw (widget);
8874 gtk_entry_drag_drop (GtkWidget *widget,
8875 GdkDragContext *context,
8880 GtkEntry *entry = GTK_ENTRY (widget);
8881 GtkEntryPrivate *priv = entry->priv;
8882 GdkAtom target = GDK_NONE;
8885 target = gtk_drag_dest_find_target (widget, context, NULL);
8887 if (target != GDK_NONE)
8888 gtk_drag_get_data (widget, context, target, time);
8890 gtk_drag_finish (context, FALSE, FALSE, time);
8896 gtk_entry_drag_motion (GtkWidget *widget,
8897 GdkDragContext *context,
8902 GtkEntry *entry = GTK_ENTRY (widget);
8903 GtkEntryPrivate *priv = entry->priv;
8904 GtkStyleContext *style_context;
8905 GtkWidget *source_widget;
8906 GdkDragAction suggested_action;
8907 gint new_position, old_position;
8911 style_context = gtk_widget_get_style_context (widget);
8912 gtk_style_context_get_padding (style_context, 0, &padding);
8916 old_position = priv->dnd_position;
8917 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8919 if (priv->editable &&
8920 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8922 source_widget = gtk_drag_get_source_widget (context);
8923 suggested_action = gdk_drag_context_get_suggested_action (context);
8925 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8926 new_position < sel1 || new_position > sel2)
8928 if (source_widget == widget)
8930 /* Default to MOVE, unless the user has
8931 * pressed ctrl or alt to affect available actions
8933 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8934 suggested_action = GDK_ACTION_MOVE;
8937 priv->dnd_position = new_position;
8941 if (source_widget == widget)
8942 suggested_action = 0; /* Can't drop in selection where drag started */
8944 priv->dnd_position = -1;
8949 /* Entry not editable, or no text */
8950 suggested_action = 0;
8951 priv->dnd_position = -1;
8954 gdk_drag_status (context, suggested_action, time);
8956 if (priv->dnd_position != old_position)
8957 gtk_widget_queue_draw (widget);
8963 gtk_entry_drag_data_received (GtkWidget *widget,
8964 GdkDragContext *context,
8967 GtkSelectionData *selection_data,
8971 GtkEntry *entry = GTK_ENTRY (widget);
8972 GtkEntryPrivate *priv = entry->priv;
8973 GtkEditable *editable = GTK_EDITABLE (widget);
8974 GtkStyleContext *style_context;
8978 str = (gchar *) gtk_selection_data_get_text (selection_data);
8980 style_context = gtk_widget_get_style_context (widget);
8981 gtk_style_context_get_padding (style_context, 0, &padding);
8985 if (str && priv->editable)
8991 if (priv->truncate_multiline)
8992 length = truncate_multiline (str);
8994 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8996 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8997 new_position < sel1 || new_position > sel2)
8999 gtk_editable_insert_text (editable, str, length, &new_position);
9003 /* Replacing selection */
9004 begin_change (entry);
9005 gtk_editable_delete_text (editable, sel1, sel2);
9006 gtk_editable_insert_text (editable, str, length, &sel1);
9010 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9014 /* Drag and drop didn't happen! */
9015 gtk_drag_finish (context, FALSE, FALSE, time);
9022 gtk_entry_drag_data_get (GtkWidget *widget,
9023 GdkDragContext *context,
9024 GtkSelectionData *selection_data,
9028 GtkEntry *entry = GTK_ENTRY (widget);
9029 GtkEntryPrivate *priv = entry->priv;
9030 GtkEditable *editable = GTK_EDITABLE (widget);
9031 gint sel_start, sel_end;
9034 /* If there is an icon drag going on, exit early. */
9035 for (i = 0; i < MAX_ICONS; i++)
9037 EntryIconInfo *icon_info = priv->icons[i];
9039 if (icon_info != NULL)
9041 if (icon_info->in_drag)
9046 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9048 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9050 gtk_selection_data_set_text (selection_data, str, -1);
9058 gtk_entry_drag_data_delete (GtkWidget *widget,
9059 GdkDragContext *context)
9061 GtkEntry *entry = GTK_ENTRY (widget);
9062 GtkEntryPrivate *priv = entry->priv;
9063 GtkEditable *editable = GTK_EDITABLE (widget);
9064 gint sel_start, sel_end;
9067 /* If there is an icon drag going on, exit early. */
9068 for (i = 0; i < MAX_ICONS; i++)
9070 EntryIconInfo *icon_info = priv->icons[i];
9072 if (icon_info != NULL)
9074 if (icon_info->in_drag)
9079 if (priv->editable &&
9080 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9081 gtk_editable_delete_text (editable, sel_start, sel_end);
9084 /* We display the cursor when
9086 * - the selection is empty, AND
9087 * - the widget has focus
9090 #define CURSOR_ON_MULTIPLIER 2
9091 #define CURSOR_OFF_MULTIPLIER 1
9092 #define CURSOR_PEND_MULTIPLIER 3
9093 #define CURSOR_DIVIDER 3
9096 cursor_blinks (GtkEntry *entry)
9098 GtkEntryPrivate *priv = entry->priv;
9100 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9102 priv->selection_bound == priv->current_pos)
9104 GtkSettings *settings;
9107 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9108 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9117 get_cursor_time (GtkEntry *entry)
9119 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9122 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9128 get_cursor_blink_timeout (GtkEntry *entry)
9130 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9133 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9139 show_cursor (GtkEntry *entry)
9141 GtkEntryPrivate *priv = entry->priv;
9144 if (!priv->cursor_visible)
9146 priv->cursor_visible = TRUE;
9148 widget = GTK_WIDGET (entry);
9149 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9150 gtk_widget_queue_draw (widget);
9155 hide_cursor (GtkEntry *entry)
9157 GtkEntryPrivate *priv = entry->priv;
9160 if (priv->cursor_visible)
9162 priv->cursor_visible = FALSE;
9164 widget = GTK_WIDGET (entry);
9165 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9166 gtk_widget_queue_draw (widget);
9174 blink_cb (gpointer data)
9177 GtkEntryPrivate *priv;
9180 entry = GTK_ENTRY (data);
9183 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9185 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9186 "connect a handler to this signal, it must return\n"
9187 "FALSE so the entry gets the event as well");
9189 gtk_entry_check_cursor_blink (entry);
9194 g_assert (priv->selection_bound == priv->current_pos);
9196 blink_timeout = get_cursor_blink_timeout (entry);
9197 if (priv->blink_time > 1000 * blink_timeout &&
9198 blink_timeout < G_MAXINT/1000)
9200 /* we've blinked enough without the user doing anything, stop blinking */
9201 show_cursor (entry);
9202 priv->blink_timeout = 0;
9204 else if (priv->cursor_visible)
9206 hide_cursor (entry);
9207 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9213 show_cursor (entry);
9214 priv->blink_time += get_cursor_time (entry);
9215 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9220 /* Remove ourselves */
9225 gtk_entry_check_cursor_blink (GtkEntry *entry)
9227 GtkEntryPrivate *priv = entry->priv;
9229 if (cursor_blinks (entry))
9231 if (!priv->blink_timeout)
9233 show_cursor (entry);
9234 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9241 if (priv->blink_timeout)
9243 g_source_remove (priv->blink_timeout);
9244 priv->blink_timeout = 0;
9247 priv->cursor_visible = TRUE;
9252 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9254 GtkEntryPrivate *priv = entry->priv;
9256 if (cursor_blinks (entry))
9258 if (priv->blink_timeout != 0)
9259 g_source_remove (priv->blink_timeout);
9261 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9264 show_cursor (entry);
9269 gtk_entry_reset_blink_time (GtkEntry *entry)
9271 GtkEntryPrivate *priv = entry->priv;
9273 priv->blink_time = 0;
9279 gtk_entry_completion_timeout (gpointer data)
9281 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9282 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9284 completion->priv->completion_timeout = 0;
9286 if (completion->priv->filter_model &&
9287 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9288 >= completion->priv->minimum_key_length)
9292 GtkTreeSelection *s;
9293 gboolean popup_single;
9295 gtk_entry_completion_complete (completion);
9296 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9298 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9300 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9302 gtk_tree_selection_unselect_all (s);
9304 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9306 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9307 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9309 if (gtk_widget_get_visible (completion->priv->popup_window))
9310 _gtk_entry_completion_resize_popup (completion);
9312 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9315 _gtk_entry_completion_popdown (completion);
9317 else if (gtk_widget_get_visible (completion->priv->popup_window))
9318 _gtk_entry_completion_popdown (completion);
9323 static inline gboolean
9324 keyval_is_cursor_move (guint keyval)
9326 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9329 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9332 if (keyval == GDK_KEY_Page_Up)
9335 if (keyval == GDK_KEY_Page_Down)
9342 gtk_entry_completion_key_press (GtkWidget *widget,
9346 gint matches, actions = 0;
9347 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9349 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9352 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9354 if (completion->priv->actions)
9355 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9357 if (keyval_is_cursor_move (event->keyval))
9359 GtkTreePath *path = NULL;
9361 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9363 if (completion->priv->current_selected < 0)
9364 completion->priv->current_selected = matches + actions - 1;
9366 completion->priv->current_selected--;
9368 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9370 if (completion->priv->current_selected < matches + actions - 1)
9371 completion->priv->current_selected++;
9373 completion->priv->current_selected = -1;
9375 else if (event->keyval == GDK_KEY_Page_Up)
9377 if (completion->priv->current_selected < 0)
9378 completion->priv->current_selected = matches + actions - 1;
9379 else if (completion->priv->current_selected == 0)
9380 completion->priv->current_selected = -1;
9381 else if (completion->priv->current_selected < matches)
9383 completion->priv->current_selected -= PAGE_STEP;
9384 if (completion->priv->current_selected < 0)
9385 completion->priv->current_selected = 0;
9389 completion->priv->current_selected -= PAGE_STEP;
9390 if (completion->priv->current_selected < matches - 1)
9391 completion->priv->current_selected = matches - 1;
9394 else if (event->keyval == GDK_KEY_Page_Down)
9396 if (completion->priv->current_selected < 0)
9397 completion->priv->current_selected = 0;
9398 else if (completion->priv->current_selected < matches - 1)
9400 completion->priv->current_selected += PAGE_STEP;
9401 if (completion->priv->current_selected > matches - 1)
9402 completion->priv->current_selected = matches - 1;
9404 else if (completion->priv->current_selected == matches + actions - 1)
9406 completion->priv->current_selected = -1;
9410 completion->priv->current_selected += PAGE_STEP;
9411 if (completion->priv->current_selected > matches + actions - 1)
9412 completion->priv->current_selected = matches + actions - 1;
9416 if (completion->priv->current_selected < 0)
9418 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9419 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9421 if (completion->priv->inline_selection &&
9422 completion->priv->completion_prefix)
9424 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9425 completion->priv->completion_prefix);
9426 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9429 else if (completion->priv->current_selected < matches)
9431 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9433 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9434 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9437 if (completion->priv->inline_selection)
9441 GtkTreeIter child_iter;
9442 GtkTreeModel *model = NULL;
9443 GtkTreeSelection *sel;
9446 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9447 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9450 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9451 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9453 if (completion->priv->completion_prefix == NULL)
9454 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9456 g_signal_emit_by_name (completion, "cursor-on-match", model,
9457 &child_iter, &entry_set);
9460 else if (completion->priv->current_selected - matches >= 0)
9462 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9464 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9465 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9468 if (completion->priv->inline_selection &&
9469 completion->priv->completion_prefix)
9471 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9472 completion->priv->completion_prefix);
9473 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9477 gtk_tree_path_free (path);
9481 else if (event->keyval == GDK_KEY_Escape ||
9482 event->keyval == GDK_KEY_Left ||
9483 event->keyval == GDK_KEY_KP_Left ||
9484 event->keyval == GDK_KEY_Right ||
9485 event->keyval == GDK_KEY_KP_Right)
9487 gboolean retval = TRUE;
9489 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9490 _gtk_entry_completion_popdown (completion);
9492 if (completion->priv->current_selected < 0)
9495 goto keypress_completion_out;
9497 else if (completion->priv->inline_selection)
9499 /* Escape rejects the tentative completion */
9500 if (event->keyval == GDK_KEY_Escape)
9502 if (completion->priv->completion_prefix)
9503 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9504 completion->priv->completion_prefix);
9506 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9509 /* Move the cursor to the end for Right/Esc, to the
9510 beginning for Left */
9511 if (event->keyval == GDK_KEY_Right ||
9512 event->keyval == GDK_KEY_KP_Right ||
9513 event->keyval == GDK_KEY_Escape)
9514 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9516 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9519 keypress_completion_out:
9520 if (completion->priv->inline_selection)
9522 g_free (completion->priv->completion_prefix);
9523 completion->priv->completion_prefix = NULL;
9528 else if (event->keyval == GDK_KEY_Tab ||
9529 event->keyval == GDK_KEY_KP_Tab ||
9530 event->keyval == GDK_KEY_ISO_Left_Tab)
9532 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9533 _gtk_entry_completion_popdown (completion);
9535 g_free (completion->priv->completion_prefix);
9536 completion->priv->completion_prefix = NULL;
9540 else if (event->keyval == GDK_KEY_ISO_Enter ||
9541 event->keyval == GDK_KEY_KP_Enter ||
9542 event->keyval == GDK_KEY_Return)
9545 GtkTreeModel *model = NULL;
9546 GtkTreeModel *child_model;
9547 GtkTreeIter child_iter;
9548 GtkTreeSelection *sel;
9549 gboolean retval = TRUE;
9551 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9552 _gtk_entry_completion_popdown (completion);
9554 if (completion->priv->current_selected < matches)
9558 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9559 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9561 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9562 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9563 g_signal_handler_block (widget, completion->priv->changed_id);
9564 g_signal_emit_by_name (completion, "match-selected",
9565 child_model, &child_iter, &entry_set);
9566 g_signal_handler_unblock (widget, completion->priv->changed_id);
9572 gtk_tree_model_get (model, &iter,
9573 completion->priv->text_column, &str,
9576 gtk_entry_set_text (GTK_ENTRY (widget), str);
9578 /* move the cursor to the end */
9579 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9587 else if (completion->priv->current_selected - matches >= 0)
9589 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9590 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9594 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9595 g_signal_emit_by_name (completion, "action-activated",
9596 gtk_tree_path_get_indices (path)[0]);
9597 gtk_tree_path_free (path);
9603 g_free (completion->priv->completion_prefix);
9604 completion->priv->completion_prefix = NULL;
9613 gtk_entry_completion_changed (GtkWidget *widget,
9616 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9617 GtkEntry *entry = GTK_ENTRY (widget);
9618 GtkEntryPrivate *priv = entry->priv;
9621 /* (re)install completion timeout */
9622 if (completion->priv->completion_timeout)
9623 g_source_remove (completion->priv->completion_timeout);
9625 if (!gtk_entry_get_text (entry))
9628 /* no need to normalize for this test */
9629 if (completion->priv->minimum_key_length > 0 &&
9630 strcmp ("", gtk_entry_get_text (entry)) == 0)
9632 if (gtk_widget_get_visible (completion->priv->popup_window))
9633 _gtk_entry_completion_popdown (completion);
9637 device = gtk_get_current_event_device ();
9639 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9640 device = gdk_device_get_associated_device (device);
9643 priv->completion_device = device;
9645 completion->priv->completion_timeout =
9646 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9647 gtk_entry_completion_timeout,
9652 check_completion_callback (GtkEntryCompletion *completion)
9654 completion->priv->check_completion_idle = NULL;
9656 gtk_entry_completion_complete (completion);
9657 gtk_entry_completion_insert_prefix (completion);
9663 clear_completion_callback (GtkEntry *entry,
9666 if (pspec->name == I_("cursor-position") ||
9667 pspec->name == I_("selection-bound"))
9669 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9671 completion->priv->has_completion = FALSE;
9676 accept_completion_callback (GtkEntry *entry)
9678 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9680 if (completion->priv->has_completion)
9681 gtk_editable_set_position (GTK_EDITABLE (entry),
9682 gtk_entry_buffer_get_length (get_buffer (entry)));
9688 completion_insert_text_callback (GtkEntry *entry,
9692 GtkEntryCompletion *completion)
9694 /* idle to update the selection based on the file list */
9695 if (completion->priv->check_completion_idle == NULL)
9697 completion->priv->check_completion_idle = g_idle_source_new ();
9698 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9699 g_source_set_closure (completion->priv->check_completion_idle,
9700 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9701 G_OBJECT (completion)));
9702 g_source_attach (completion->priv->check_completion_idle, NULL);
9707 completion_changed (GtkEntryCompletion *completion,
9711 GtkEntry *entry = GTK_ENTRY (data);
9713 if (pspec->name == I_("popup-completion") ||
9714 pspec->name == I_("inline-completion"))
9716 disconnect_completion_signals (entry, completion);
9717 connect_completion_signals (entry, completion);
9722 disconnect_completion_signals (GtkEntry *entry,
9723 GtkEntryCompletion *completion)
9725 g_signal_handlers_disconnect_by_func (completion,
9726 G_CALLBACK (completion_changed), entry);
9727 if (completion->priv->changed_id > 0 &&
9728 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9730 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9731 completion->priv->changed_id = 0;
9733 g_signal_handlers_disconnect_by_func (entry,
9734 G_CALLBACK (gtk_entry_completion_key_press), completion);
9735 if (completion->priv->insert_text_id > 0 &&
9736 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9738 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9739 completion->priv->insert_text_id = 0;
9741 g_signal_handlers_disconnect_by_func (entry,
9742 G_CALLBACK (completion_insert_text_callback), completion);
9743 g_signal_handlers_disconnect_by_func (entry,
9744 G_CALLBACK (clear_completion_callback), completion);
9745 g_signal_handlers_disconnect_by_func (entry,
9746 G_CALLBACK (accept_completion_callback), completion);
9750 connect_completion_signals (GtkEntry *entry,
9751 GtkEntryCompletion *completion)
9753 if (completion->priv->popup_completion)
9755 completion->priv->changed_id =
9756 g_signal_connect (entry, "changed",
9757 G_CALLBACK (gtk_entry_completion_changed), completion);
9758 g_signal_connect (entry, "key-press-event",
9759 G_CALLBACK (gtk_entry_completion_key_press), completion);
9762 if (completion->priv->inline_completion)
9764 completion->priv->insert_text_id =
9765 g_signal_connect (entry, "insert-text",
9766 G_CALLBACK (completion_insert_text_callback), completion);
9767 g_signal_connect (entry, "notify",
9768 G_CALLBACK (clear_completion_callback), completion);
9769 g_signal_connect (entry, "activate",
9770 G_CALLBACK (accept_completion_callback), completion);
9771 g_signal_connect (entry, "focus-out-event",
9772 G_CALLBACK (accept_completion_callback), completion);
9775 g_signal_connect (completion, "notify",
9776 G_CALLBACK (completion_changed), entry);
9780 * gtk_entry_set_completion:
9781 * @entry: A #GtkEntry
9782 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9784 * Sets @completion to be the auxiliary completion object to use with @entry.
9785 * All further configuration of the completion mechanism is done on
9786 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9787 * @completion is set to %NULL.
9792 gtk_entry_set_completion (GtkEntry *entry,
9793 GtkEntryCompletion *completion)
9795 GtkEntryCompletion *old;
9797 g_return_if_fail (GTK_IS_ENTRY (entry));
9798 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9800 old = gtk_entry_get_completion (entry);
9802 if (old == completion)
9807 if (old->priv->completion_timeout)
9809 g_source_remove (old->priv->completion_timeout);
9810 old->priv->completion_timeout = 0;
9813 if (old->priv->check_completion_idle)
9815 g_source_destroy (old->priv->check_completion_idle);
9816 old->priv->check_completion_idle = NULL;
9819 if (gtk_widget_get_mapped (old->priv->popup_window))
9820 _gtk_entry_completion_popdown (old);
9822 disconnect_completion_signals (entry, old);
9823 old->priv->entry = NULL;
9825 g_object_unref (old);
9830 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9834 /* hook into the entry */
9835 g_object_ref (completion);
9837 connect_completion_signals (entry, completion);
9838 completion->priv->entry = GTK_WIDGET (entry);
9839 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9841 g_object_notify (G_OBJECT (entry), "completion");
9845 * gtk_entry_get_completion:
9846 * @entry: A #GtkEntry
9848 * Returns the auxiliary completion object currently in use by @entry.
9850 * Return value: (transfer none): The auxiliary completion object currently
9855 GtkEntryCompletion *
9856 gtk_entry_get_completion (GtkEntry *entry)
9858 GtkEntryCompletion *completion;
9860 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9862 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9863 GTK_ENTRY_COMPLETION_KEY));
9869 * gtk_entry_set_cursor_hadjustment:
9870 * @entry: a #GtkEntry
9871 * @adjustment: an adjustment which should be adjusted when the cursor
9872 * is moved, or %NULL
9874 * Hooks up an adjustment to the cursor position in an entry, so that when
9875 * the cursor is moved, the adjustment is scrolled to show that position.
9876 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9879 * The adjustment has to be in pixel units and in the same coordinate system
9885 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9886 GtkAdjustment *adjustment)
9888 g_return_if_fail (GTK_IS_ENTRY (entry));
9890 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9893 g_object_ref (adjustment);
9895 g_object_set_qdata_full (G_OBJECT (entry),
9896 quark_cursor_hadjustment,
9902 * gtk_entry_get_cursor_hadjustment:
9903 * @entry: a #GtkEntry
9905 * Retrieves the horizontal cursor adjustment for the entry.
9906 * See gtk_entry_set_cursor_hadjustment().
9908 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9909 * if none has been set.
9914 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9916 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9918 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9922 * gtk_entry_set_progress_fraction:
9923 * @entry: a #GtkEntry
9924 * @fraction: fraction of the task that's been completed
9926 * Causes the entry's progress indicator to "fill in" the given
9927 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9933 gtk_entry_set_progress_fraction (GtkEntry *entry,
9937 GtkEntryPrivate *private;
9938 gdouble old_fraction;
9939 gint x, y, width, height;
9940 gint old_x, old_y, old_width, old_height;
9942 g_return_if_fail (GTK_IS_ENTRY (entry));
9944 widget = GTK_WIDGET (entry);
9945 private = entry->priv;
9947 if (private->progress_pulse_mode)
9950 old_fraction = private->progress_fraction;
9952 if (gtk_widget_is_drawable (widget))
9953 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9955 fraction = CLAMP (fraction, 0.0, 1.0);
9957 private->progress_fraction = fraction;
9958 private->progress_pulse_mode = FALSE;
9959 private->progress_pulse_current = 0.0;
9961 if (gtk_widget_is_drawable (widget))
9963 get_progress_area (widget, &x, &y, &width, &height);
9965 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9966 gtk_widget_queue_draw (widget);
9969 if (fraction != old_fraction)
9970 g_object_notify (G_OBJECT (entry), "progress-fraction");
9974 * gtk_entry_get_progress_fraction:
9975 * @entry: a #GtkEntry
9977 * Returns the current fraction of the task that's been completed.
9978 * See gtk_entry_set_progress_fraction().
9980 * Return value: a fraction from 0.0 to 1.0
9985 gtk_entry_get_progress_fraction (GtkEntry *entry)
9987 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9989 return entry->priv->progress_fraction;
9993 * gtk_entry_set_progress_pulse_step:
9994 * @entry: a #GtkEntry
9995 * @fraction: fraction between 0.0 and 1.0
9997 * Sets the fraction of total entry width to move the progress
9998 * bouncing block for each call to gtk_entry_progress_pulse().
10003 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10006 GtkEntryPrivate *private;
10008 g_return_if_fail (GTK_IS_ENTRY (entry));
10010 private = entry->priv;
10012 fraction = CLAMP (fraction, 0.0, 1.0);
10014 if (fraction != private->progress_pulse_fraction)
10016 private->progress_pulse_fraction = fraction;
10018 gtk_widget_queue_draw (GTK_WIDGET (entry));
10020 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10025 * gtk_entry_get_progress_pulse_step:
10026 * @entry: a #GtkEntry
10028 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10030 * Return value: a fraction from 0.0 to 1.0
10035 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10037 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10039 return entry->priv->progress_pulse_fraction;
10043 * gtk_entry_progress_pulse:
10044 * @entry: a #GtkEntry
10046 * Indicates that some progress is made, but you don't know how much.
10047 * Causes the entry's progress indicator to enter "activity mode,"
10048 * where a block bounces back and forth. Each call to
10049 * gtk_entry_progress_pulse() causes the block to move by a little bit
10050 * (the amount of movement per pulse is determined by
10051 * gtk_entry_set_progress_pulse_step()).
10056 gtk_entry_progress_pulse (GtkEntry *entry)
10058 GtkEntryPrivate *private;
10060 g_return_if_fail (GTK_IS_ENTRY (entry));
10062 private = entry->priv;
10064 if (private->progress_pulse_mode)
10066 if (private->progress_pulse_way_back)
10068 private->progress_pulse_current -= private->progress_pulse_fraction;
10070 if (private->progress_pulse_current < 0.0)
10072 private->progress_pulse_current = 0.0;
10073 private->progress_pulse_way_back = FALSE;
10078 private->progress_pulse_current += private->progress_pulse_fraction;
10080 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10082 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10083 private->progress_pulse_way_back = TRUE;
10089 private->progress_fraction = 0.0;
10090 private->progress_pulse_mode = TRUE;
10091 private->progress_pulse_way_back = FALSE;
10092 private->progress_pulse_current = 0.0;
10095 gtk_widget_queue_draw (GTK_WIDGET (entry));
10099 * gtk_entry_set_placeholder_text:
10100 * @entry: a #GtkEntry
10101 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10103 * Sets text to be displayed in @entry when it is empty and unfocused.
10104 * This can be used to give a visual hint of the expected contents of
10107 * Note that since the placeholder text gets removed when the entry
10108 * received focus, using this feature is a bit problematic if the entry
10109 * is given the initial focus in a window. Sometimes this can be
10110 * worked around by delaying the initial focus setting until the
10111 * first key event arrives.
10116 gtk_entry_set_placeholder_text (GtkEntry *entry,
10119 GtkEntryPrivate *priv;
10121 g_return_if_fail (GTK_IS_ENTRY (entry));
10123 priv = entry->priv;
10125 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10128 g_free (priv->placeholder_text);
10129 priv->placeholder_text = g_strdup (text);
10131 gtk_entry_recompute (entry);
10133 g_object_notify (G_OBJECT (entry), "placeholder-text");
10137 * gtk_entry_get_placeholder_text:
10138 * @entry: a #GtkEntry
10140 * Retrieves the text that will be displayed when @entry is empty and unfocused
10142 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10143 * storage in the widget and must not be freed, modified or stored.
10148 gtk_entry_get_placeholder_text (GtkEntry *entry)
10150 GtkEntryPrivate *priv;
10152 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10154 priv = entry->priv;
10156 return priv->placeholder_text;
10159 /* Caps Lock warning for password entries */
10162 show_capslock_feedback (GtkEntry *entry,
10165 GtkEntryPrivate *priv = entry->priv;
10167 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10169 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10170 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10171 priv->caps_lock_warning_shown = TRUE;
10174 if (priv->caps_lock_warning_shown)
10175 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10177 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10181 remove_capslock_feedback (GtkEntry *entry)
10183 GtkEntryPrivate *priv = entry->priv;
10185 if (priv->caps_lock_warning_shown)
10187 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10188 priv->caps_lock_warning_shown = FALSE;
10193 keymap_state_changed (GdkKeymap *keymap,
10196 GtkEntryPrivate *priv = entry->priv;
10199 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10201 if (gdk_keymap_get_num_lock_state (keymap)
10202 && gdk_keymap_get_caps_lock_state (keymap))
10203 text = _("Caps Lock and Num Lock are on");
10204 else if (gdk_keymap_get_num_lock_state (keymap))
10205 text = _("Num Lock is on");
10206 else if (gdk_keymap_get_caps_lock_state (keymap))
10207 text = _("Caps Lock is on");
10211 show_capslock_feedback (entry, text);
10213 remove_capslock_feedback (entry);
10217 * _gtk_entry_set_is_cell_renderer:
10218 * @entry: a #GtkEntry
10219 * @is_cell_renderer: new value
10221 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10222 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10224 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10228 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10229 gboolean is_cell_renderer)
10231 entry->priv->is_cell_renderer = is_cell_renderer;