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, see <http://www.gnu.org/licenses/>.
23 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
24 * file for a list of people on the GTK+ Team. See the ChangeLog
25 * files for a list of changes. These files are distributed with
26 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #include "gtkbindings.h"
35 #include "gtkcelleditable.h"
36 #include "gtkclipboard.h"
39 #include "gtkentrybuffer.h"
40 #include "gtkiconhelperprivate.h"
41 #include "gtkimagemenuitem.h"
42 #include "gtkimcontextsimple.h"
43 #include "gtkimmulticontext.h"
47 #include "gtkmarshalers.h"
49 #include "gtkmenuitem.h"
50 #include "gtkseparatormenuitem.h"
51 #include "gtkselection.h"
52 #include "gtksettings.h"
53 #include "gtkspinbutton.h"
55 #include "gtktextutil.h"
56 #include "gtkwindow.h"
57 #include "gtktreeview.h"
58 #include "gtktreeselection.h"
59 #include "gtktypebuiltins.h"
60 #include "gtkprivate.h"
61 #include "gtkentryprivate.h"
62 #include "gtkcelllayout.h"
63 #include "gtktooltip.h"
64 #include "gtkiconfactory.h"
65 #include "gtkicontheme.h"
66 #include "gtkwidgetprivate.h"
67 #include "gtkstylecontextprivate.h"
68 #include "gtktexthandleprivate.h"
70 #include "a11y/gtkentryaccessible.h"
74 * @Short_description: A single line text entry field
76 * @See_also: #GtkTextView, #GtkEntryCompletion
78 * The #GtkEntry widget is a single line text entry
79 * widget. A fairly large set of key bindings are supported
80 * by default. If the entered text is longer than the allocation
81 * of the widget, the widget will scroll so that the cursor
82 * position is visible.
84 * When using an entry for passwords and other sensitive information,
85 * it can be put into "password mode" using gtk_entry_set_visibility().
86 * In this mode, entered text is displayed using a 'invisible' character.
87 * By default, GTK+ picks the best invisible character that is available
88 * in the current font, but it can be changed with
89 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
90 * when Caps Lock or input methods might interfere with entering text in
91 * a password entry. The warning can be turned off with the
92 * #GtkEntry:caps-lock-warning property.
94 * Since 2.16, GtkEntry has the ability to display progress or activity
95 * information behind the text. To make an entry display such information,
96 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
98 * Additionally, GtkEntry can show icons at either side of the entry. These
99 * icons can be activatable by clicking, can be set up as drag source and
100 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
101 * one of the various other functions that set an icon from a stock id, an
102 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
103 * connect to the #GtkEntry::icon-press signal. To allow DND operations
104 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
105 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
108 * Note that functionality or information that is only available by clicking
109 * on an icon in an entry may not be accessible at all to users which are not
110 * able to use a mouse or other pointing device. It is therefore recommended
111 * that any such functionality should also be available by other means, e.g.
112 * via the context menu of the entry.
116 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
118 #define MIN_ENTRY_WIDTH 150
119 #define DRAW_TIMEOUT 20
120 #define PASSWORD_HINT_MAX 8
124 #define IS_VALID_ICON_POSITION(pos) \
125 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
126 (pos) == GTK_ENTRY_ICON_SECONDARY)
128 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
129 static GQuark quark_inner_border = 0;
130 static GQuark quark_password_hint = 0;
131 static GQuark quark_cursor_hadjustment = 0;
132 static GQuark quark_capslock_feedback = 0;
134 typedef struct _EntryIconInfo EntryIconInfo;
135 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
136 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
138 struct _GtkEntryPrivate
140 EntryIconInfo *icons[MAX_ICONS];
142 GtkEntryBuffer *buffer;
143 GtkIMContext *im_context;
144 GtkWidget *popup_menu;
148 GdkWindow *text_area;
150 PangoLayout *cached_layout;
151 PangoAttrList *attrs;
155 gdouble progress_fraction;
156 gdouble progress_pulse_fraction;
157 gdouble progress_pulse_current;
159 gchar *placeholder_text;
161 GtkTextHandle *text_handle;
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 */
192 guint shadow_type : 4;
195 guint overwrite_mode : 1;
198 guint activates_default : 1;
199 guint cache_includes_preedit : 1;
200 guint caps_lock_warning : 1;
201 guint caps_lock_warning_shown : 1;
202 guint change_count : 8;
203 guint cursor_visible : 1;
204 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
206 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
207 guint is_cell_renderer : 1;
208 guint invisible_char_set : 1;
209 guint interior_focus : 1;
210 guint mouse_cursor_obscured : 1;
211 guint need_im_reset : 1;
212 guint progress_pulse_mode : 1;
213 guint progress_pulse_way_back : 1;
214 guint real_changed : 1;
215 guint resolved_dir : 4; /* PangoDirection */
216 guint select_words : 1;
217 guint select_lines : 1;
218 guint truncate_multiline : 1;
219 guint cursor_handle_dragged : 1;
220 guint selection_handle_dragged : 1;
223 struct _EntryIconInfo
227 guint insensitive : 1;
228 guint nonactivatable : 1;
233 GtkIconHelper *icon_helper;
235 GtkTargetList *target_list;
236 GdkDragAction actions;
239 struct _GtkEntryPasswordHint
241 gint position; /* Position (in text) of the last password hint */
242 guint source_id; /* Timeout source id */
245 struct _GtkEntryCapslockFeedback
272 PROP_CURSOR_POSITION,
273 PROP_SELECTION_BOUND,
280 PROP_ACTIVATES_DEFAULT,
285 PROP_TRUNCATE_MULTILINE,
289 PROP_INVISIBLE_CHAR_SET,
290 PROP_CAPS_LOCK_WARNING,
291 PROP_PROGRESS_FRACTION,
292 PROP_PROGRESS_PULSE_STEP,
294 PROP_PIXBUF_SECONDARY,
296 PROP_STOCK_SECONDARY,
297 PROP_ICON_NAME_PRIMARY,
298 PROP_ICON_NAME_SECONDARY,
300 PROP_GICON_SECONDARY,
301 PROP_STORAGE_TYPE_PRIMARY,
302 PROP_STORAGE_TYPE_SECONDARY,
303 PROP_ACTIVATABLE_PRIMARY,
304 PROP_ACTIVATABLE_SECONDARY,
305 PROP_SENSITIVE_PRIMARY,
306 PROP_SENSITIVE_SECONDARY,
307 PROP_TOOLTIP_TEXT_PRIMARY,
308 PROP_TOOLTIP_TEXT_SECONDARY,
309 PROP_TOOLTIP_MARKUP_PRIMARY,
310 PROP_TOOLTIP_MARKUP_SECONDARY,
312 PROP_EDITING_CANCELED,
313 PROP_PLACEHOLDER_TEXT,
320 static guint signals[LAST_SIGNAL] = { 0 };
321 static gboolean test_touchscreen = FALSE;
330 DISPLAY_NORMAL, /* The entry text is being shown */
331 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
332 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
337 static void gtk_entry_editable_init (GtkEditableInterface *iface);
338 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
339 static void gtk_entry_set_property (GObject *object,
343 static void gtk_entry_get_property (GObject *object,
347 static void gtk_entry_finalize (GObject *object);
348 static void gtk_entry_dispose (GObject *object);
352 static void gtk_entry_destroy (GtkWidget *widget);
353 static void gtk_entry_realize (GtkWidget *widget);
354 static void gtk_entry_unrealize (GtkWidget *widget);
355 static void gtk_entry_map (GtkWidget *widget);
356 static void gtk_entry_unmap (GtkWidget *widget);
357 static void gtk_entry_get_preferred_width (GtkWidget *widget,
360 static void gtk_entry_get_preferred_height (GtkWidget *widget,
363 static void gtk_entry_size_allocate (GtkWidget *widget,
364 GtkAllocation *allocation);
365 static void gtk_entry_draw_frame (GtkWidget *widget,
366 GtkStyleContext *context,
368 static void gtk_entry_draw_progress (GtkWidget *widget,
369 GtkStyleContext *context,
371 static gint gtk_entry_draw (GtkWidget *widget,
373 static gint gtk_entry_button_press (GtkWidget *widget,
374 GdkEventButton *event);
375 static gint gtk_entry_button_release (GtkWidget *widget,
376 GdkEventButton *event);
377 static gint gtk_entry_enter_notify (GtkWidget *widget,
378 GdkEventCrossing *event);
379 static gint gtk_entry_leave_notify (GtkWidget *widget,
380 GdkEventCrossing *event);
381 static gint gtk_entry_motion_notify (GtkWidget *widget,
382 GdkEventMotion *event);
383 static gint gtk_entry_key_press (GtkWidget *widget,
385 static gint gtk_entry_key_release (GtkWidget *widget,
387 static gint gtk_entry_focus_in (GtkWidget *widget,
388 GdkEventFocus *event);
389 static gint gtk_entry_focus_out (GtkWidget *widget,
390 GdkEventFocus *event);
391 static void gtk_entry_grab_focus (GtkWidget *widget);
392 static void gtk_entry_style_updated (GtkWidget *widget);
393 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
396 gboolean keyboard_tip,
397 GtkTooltip *tooltip);
398 static void gtk_entry_direction_changed (GtkWidget *widget,
399 GtkTextDirection previous_dir);
400 static void gtk_entry_state_flags_changed (GtkWidget *widget,
401 GtkStateFlags previous_state);
402 static void gtk_entry_screen_changed (GtkWidget *widget,
403 GdkScreen *old_screen);
405 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
406 GdkDragContext *context,
410 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
411 GdkDragContext *context,
415 static void gtk_entry_drag_leave (GtkWidget *widget,
416 GdkDragContext *context,
418 static void gtk_entry_drag_data_received (GtkWidget *widget,
419 GdkDragContext *context,
422 GtkSelectionData *selection_data,
425 static void gtk_entry_drag_data_get (GtkWidget *widget,
426 GdkDragContext *context,
427 GtkSelectionData *selection_data,
430 static void gtk_entry_drag_data_delete (GtkWidget *widget,
431 GdkDragContext *context);
432 static void gtk_entry_drag_begin (GtkWidget *widget,
433 GdkDragContext *context);
434 static void gtk_entry_drag_end (GtkWidget *widget,
435 GdkDragContext *context);
438 /* GtkEditable method implementations
440 static void gtk_entry_insert_text (GtkEditable *editable,
441 const gchar *new_text,
442 gint new_text_length,
444 static void gtk_entry_delete_text (GtkEditable *editable,
447 static gchar * gtk_entry_get_chars (GtkEditable *editable,
450 static void gtk_entry_real_set_position (GtkEditable *editable,
452 static gint gtk_entry_get_position (GtkEditable *editable);
453 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
456 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
460 /* GtkCellEditable method implementations
462 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
465 /* Default signal handlers
467 static void gtk_entry_real_insert_text (GtkEditable *editable,
468 const gchar *new_text,
469 gint new_text_length,
471 static void gtk_entry_real_delete_text (GtkEditable *editable,
474 static void gtk_entry_move_cursor (GtkEntry *entry,
475 GtkMovementStep step,
477 gboolean extend_selection);
478 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
480 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
483 static void gtk_entry_backspace (GtkEntry *entry);
484 static void gtk_entry_cut_clipboard (GtkEntry *entry);
485 static void gtk_entry_copy_clipboard (GtkEntry *entry);
486 static void gtk_entry_paste_clipboard (GtkEntry *entry);
487 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
488 static void gtk_entry_select_all (GtkEntry *entry);
489 static void gtk_entry_real_activate (GtkEntry *entry);
490 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
492 static void keymap_direction_changed (GdkKeymap *keymap,
494 static void keymap_state_changed (GdkKeymap *keymap,
496 static void remove_capslock_feedback (GtkEntry *entry);
498 /* IM Context Callbacks
500 static void gtk_entry_commit_cb (GtkIMContext *context,
503 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
505 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
507 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
514 static void gtk_entry_enter_text (GtkEntry *entry,
516 static void gtk_entry_set_positions (GtkEntry *entry,
518 gint selection_bound);
519 static void gtk_entry_draw_text (GtkEntry *entry,
521 static void gtk_entry_draw_cursor (GtkEntry *entry,
524 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
525 gboolean include_preedit);
526 static void gtk_entry_reset_layout (GtkEntry *entry);
527 static void gtk_entry_recompute (GtkEntry *entry);
528 static gint gtk_entry_find_position (GtkEntry *entry,
530 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
534 static void gtk_entry_adjust_scroll (GtkEntry *entry);
535 static gint gtk_entry_move_visually (GtkEntry *editable,
538 static gint gtk_entry_move_logically (GtkEntry *entry,
541 static gint gtk_entry_move_forward_word (GtkEntry *entry,
543 gboolean allow_whitespace);
544 static gint gtk_entry_move_backward_word (GtkEntry *entry,
546 gboolean allow_whitespace);
547 static void gtk_entry_delete_whitespace (GtkEntry *entry);
548 static void gtk_entry_select_word (GtkEntry *entry);
549 static void gtk_entry_select_line (GtkEntry *entry);
550 static void gtk_entry_paste (GtkEntry *entry,
552 static void gtk_entry_update_primary_selection (GtkEntry *entry);
553 static void gtk_entry_do_popup (GtkEntry *entry,
554 GdkEventButton *event);
555 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
556 gboolean group_cycling);
557 static void gtk_entry_grab_notify (GtkWidget *widget,
558 gboolean was_grabbed);
559 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
560 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
561 static void gtk_entry_reset_blink_time (GtkEntry *entry);
562 static void gtk_entry_get_text_area_size (GtkEntry *entry,
567 static void gtk_entry_get_frame_size (GtkEntry *entry,
572 static void get_text_area_size (GtkEntry *entry,
577 static void get_frame_size (GtkEntry *entry,
578 gboolean relative_to_window,
583 static void gtk_entry_move_adjustments (GtkEntry *entry);
584 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
585 GtkEntryIconPosition icon_pos);
586 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
587 static gboolean get_middle_click_paste (GtkEntry *entry);
589 /* GtkTextHandle handlers */
590 static void gtk_entry_handle_dragged (GtkTextHandle *handle,
591 GtkTextHandlePosition pos,
596 static void begin_change (GtkEntry *entry);
597 static void end_change (GtkEntry *entry);
598 static void emit_changed (GtkEntry *entry);
600 static void buffer_inserted_text (GtkEntryBuffer *buffer,
605 static void buffer_deleted_text (GtkEntryBuffer *buffer,
609 static void buffer_notify_text (GtkEntryBuffer *buffer,
612 static void buffer_notify_length (GtkEntryBuffer *buffer,
615 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
618 static void buffer_connect_signals (GtkEntry *entry);
619 static void buffer_disconnect_signals (GtkEntry *entry);
620 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
622 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
623 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
624 gtk_entry_editable_init)
625 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
626 gtk_entry_cell_editable_init))
629 add_move_binding (GtkBindingSet *binding_set,
632 GtkMovementStep step,
635 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
637 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
641 G_TYPE_BOOLEAN, FALSE);
643 /* Selection-extending version */
644 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
648 G_TYPE_BOOLEAN, TRUE);
652 gtk_entry_class_init (GtkEntryClass *class)
654 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
655 GtkWidgetClass *widget_class;
656 GtkBindingSet *binding_set;
658 widget_class = (GtkWidgetClass*) class;
660 gobject_class->dispose = gtk_entry_dispose;
661 gobject_class->finalize = gtk_entry_finalize;
662 gobject_class->set_property = gtk_entry_set_property;
663 gobject_class->get_property = gtk_entry_get_property;
665 widget_class->destroy = gtk_entry_destroy;
666 widget_class->map = gtk_entry_map;
667 widget_class->unmap = gtk_entry_unmap;
668 widget_class->realize = gtk_entry_realize;
669 widget_class->unrealize = gtk_entry_unrealize;
670 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
671 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
672 widget_class->size_allocate = gtk_entry_size_allocate;
673 widget_class->draw = gtk_entry_draw;
674 widget_class->enter_notify_event = gtk_entry_enter_notify;
675 widget_class->leave_notify_event = gtk_entry_leave_notify;
676 widget_class->button_press_event = gtk_entry_button_press;
677 widget_class->button_release_event = gtk_entry_button_release;
678 widget_class->motion_notify_event = gtk_entry_motion_notify;
679 widget_class->key_press_event = gtk_entry_key_press;
680 widget_class->key_release_event = gtk_entry_key_release;
681 widget_class->focus_in_event = gtk_entry_focus_in;
682 widget_class->focus_out_event = gtk_entry_focus_out;
683 widget_class->grab_focus = gtk_entry_grab_focus;
684 widget_class->style_updated = gtk_entry_style_updated;
685 widget_class->query_tooltip = gtk_entry_query_tooltip;
686 widget_class->drag_begin = gtk_entry_drag_begin;
687 widget_class->drag_end = gtk_entry_drag_end;
688 widget_class->direction_changed = gtk_entry_direction_changed;
689 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
690 widget_class->screen_changed = gtk_entry_screen_changed;
691 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
692 widget_class->grab_notify = gtk_entry_grab_notify;
694 widget_class->drag_drop = gtk_entry_drag_drop;
695 widget_class->drag_motion = gtk_entry_drag_motion;
696 widget_class->drag_leave = gtk_entry_drag_leave;
697 widget_class->drag_data_received = gtk_entry_drag_data_received;
698 widget_class->drag_data_get = gtk_entry_drag_data_get;
699 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
701 widget_class->popup_menu = gtk_entry_popup_menu;
703 class->move_cursor = gtk_entry_move_cursor;
704 class->insert_at_cursor = gtk_entry_insert_at_cursor;
705 class->delete_from_cursor = gtk_entry_delete_from_cursor;
706 class->backspace = gtk_entry_backspace;
707 class->cut_clipboard = gtk_entry_cut_clipboard;
708 class->copy_clipboard = gtk_entry_copy_clipboard;
709 class->paste_clipboard = gtk_entry_paste_clipboard;
710 class->toggle_overwrite = gtk_entry_toggle_overwrite;
711 class->activate = gtk_entry_real_activate;
712 class->get_text_area_size = gtk_entry_get_text_area_size;
713 class->get_frame_size = gtk_entry_get_frame_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 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
792 * of this style property is ignored.
794 g_object_class_install_property (gobject_class,
796 g_param_spec_boxed ("inner-border",
798 P_("Border between text and frame. Overrides the inner-border style property"),
800 GTK_PARAM_READWRITE |
801 G_PARAM_DEPRECATED));
803 g_object_class_install_property (gobject_class,
805 g_param_spec_unichar ("invisible-char",
806 P_("Invisible character"),
807 P_("The character to use when masking entry contents (in \"password mode\")"),
809 GTK_PARAM_READWRITE));
811 g_object_class_install_property (gobject_class,
812 PROP_ACTIVATES_DEFAULT,
813 g_param_spec_boolean ("activates-default",
814 P_("Activates default"),
815 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
817 GTK_PARAM_READWRITE));
818 g_object_class_install_property (gobject_class,
820 g_param_spec_int ("width-chars",
821 P_("Width in chars"),
822 P_("Number of characters to leave space for in the entry"),
826 GTK_PARAM_READWRITE));
828 g_object_class_install_property (gobject_class,
830 g_param_spec_int ("scroll-offset",
832 P_("Number of pixels of the entry scrolled off the screen to the left"),
836 GTK_PARAM_READABLE));
838 g_object_class_install_property (gobject_class,
840 g_param_spec_string ("text",
842 P_("The contents of the entry"),
844 GTK_PARAM_READWRITE));
849 * The horizontal alignment, from 0 (left) to 1 (right).
850 * Reversed for RTL layouts.
854 g_object_class_install_property (gobject_class,
856 g_param_spec_float ("xalign",
858 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
862 GTK_PARAM_READWRITE));
865 * GtkEntry:truncate-multiline:
867 * When %TRUE, pasted multi-line text is truncated to the first line.
871 g_object_class_install_property (gobject_class,
872 PROP_TRUNCATE_MULTILINE,
873 g_param_spec_boolean ("truncate-multiline",
874 P_("Truncate multiline"),
875 P_("Whether to truncate multiline pastes to one line."),
877 GTK_PARAM_READWRITE));
880 * GtkEntry:shadow-type:
882 * Which kind of shadow to draw around the entry when
883 * #GtkEntry:has-frame is set to %TRUE.
887 g_object_class_install_property (gobject_class,
889 g_param_spec_enum ("shadow-type",
891 P_("Which kind of shadow to draw around the entry when has-frame is set"),
892 GTK_TYPE_SHADOW_TYPE,
894 GTK_PARAM_READWRITE));
897 * GtkEntry:overwrite-mode:
899 * If text is overwritten when typing in the #GtkEntry.
903 g_object_class_install_property (gobject_class,
905 g_param_spec_boolean ("overwrite-mode",
906 P_("Overwrite mode"),
907 P_("Whether new text overwrites existing text"),
909 GTK_PARAM_READWRITE));
912 * GtkEntry:text-length:
914 * The length of the text in the #GtkEntry.
918 g_object_class_install_property (gobject_class,
920 g_param_spec_uint ("text-length",
922 P_("Length of the text currently in the entry"),
926 GTK_PARAM_READABLE));
928 * GtkEntry:invisible-char-set:
930 * Whether the invisible char has been set for the #GtkEntry.
934 g_object_class_install_property (gobject_class,
935 PROP_INVISIBLE_CHAR_SET,
936 g_param_spec_boolean ("invisible-char-set",
937 P_("Invisible character set"),
938 P_("Whether the invisible character has been set"),
940 GTK_PARAM_READWRITE));
943 * GtkEntry:caps-lock-warning:
945 * Whether password entries will show a warning when Caps Lock is on.
947 * Note that the warning is shown using a secondary icon, and thus
948 * does not work if you are using the secondary icon position for some
953 g_object_class_install_property (gobject_class,
954 PROP_CAPS_LOCK_WARNING,
955 g_param_spec_boolean ("caps-lock-warning",
956 P_("Caps Lock warning"),
957 P_("Whether password entries will show a warning when Caps Lock is on"),
959 GTK_PARAM_READWRITE));
962 * GtkEntry:progress-fraction:
964 * The current fraction of the task that's been completed.
968 g_object_class_install_property (gobject_class,
969 PROP_PROGRESS_FRACTION,
970 g_param_spec_double ("progress-fraction",
971 P_("Progress Fraction"),
972 P_("The current fraction of the task that's been completed"),
976 GTK_PARAM_READWRITE));
979 * GtkEntry:progress-pulse-step:
981 * The fraction of total entry width to move the progress
982 * bouncing block for each call to gtk_entry_progress_pulse().
986 g_object_class_install_property (gobject_class,
987 PROP_PROGRESS_PULSE_STEP,
988 g_param_spec_double ("progress-pulse-step",
989 P_("Progress Pulse Step"),
990 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
994 GTK_PARAM_READWRITE));
997 * GtkEntry:placeholder-text:
999 * The text that will be displayed in the #GtkEntry when it is empty
1004 g_object_class_install_property (gobject_class,
1005 PROP_PLACEHOLDER_TEXT,
1006 g_param_spec_string ("placeholder-text",
1007 P_("Placeholder text"),
1008 P_("Show text in the entry when it's empty and unfocused"),
1010 GTK_PARAM_READWRITE));
1013 * GtkEntry:primary-icon-pixbuf:
1015 * A pixbuf to use as the primary icon for the entry.
1019 g_object_class_install_property (gobject_class,
1020 PROP_PIXBUF_PRIMARY,
1021 g_param_spec_object ("primary-icon-pixbuf",
1022 P_("Primary pixbuf"),
1023 P_("Primary pixbuf for the entry"),
1025 GTK_PARAM_READWRITE));
1028 * GtkEntry:secondary-icon-pixbuf:
1030 * An pixbuf to use as the secondary icon for the entry.
1034 g_object_class_install_property (gobject_class,
1035 PROP_PIXBUF_SECONDARY,
1036 g_param_spec_object ("secondary-icon-pixbuf",
1037 P_("Secondary pixbuf"),
1038 P_("Secondary pixbuf for the entry"),
1040 GTK_PARAM_READWRITE));
1043 * GtkEntry:primary-icon-stock:
1045 * The stock id to use for the primary icon for the entry.
1049 g_object_class_install_property (gobject_class,
1051 g_param_spec_string ("primary-icon-stock",
1052 P_("Primary stock ID"),
1053 P_("Stock ID for primary icon"),
1055 GTK_PARAM_READWRITE));
1058 * GtkEntry:secondary-icon-stock:
1060 * The stock id to use for the secondary icon for the entry.
1064 g_object_class_install_property (gobject_class,
1065 PROP_STOCK_SECONDARY,
1066 g_param_spec_string ("secondary-icon-stock",
1067 P_("Secondary stock ID"),
1068 P_("Stock ID for secondary icon"),
1070 GTK_PARAM_READWRITE));
1073 * GtkEntry:primary-icon-name:
1075 * The icon name to use for the primary icon for the entry.
1079 g_object_class_install_property (gobject_class,
1080 PROP_ICON_NAME_PRIMARY,
1081 g_param_spec_string ("primary-icon-name",
1082 P_("Primary icon name"),
1083 P_("Icon name for primary icon"),
1085 GTK_PARAM_READWRITE));
1088 * GtkEntry:secondary-icon-name:
1090 * The icon name to use for the secondary icon for the entry.
1094 g_object_class_install_property (gobject_class,
1095 PROP_ICON_NAME_SECONDARY,
1096 g_param_spec_string ("secondary-icon-name",
1097 P_("Secondary icon name"),
1098 P_("Icon name for secondary icon"),
1100 GTK_PARAM_READWRITE));
1103 * GtkEntry:primary-icon-gicon:
1105 * The #GIcon to use for the primary icon for the entry.
1109 g_object_class_install_property (gobject_class,
1111 g_param_spec_object ("primary-icon-gicon",
1112 P_("Primary GIcon"),
1113 P_("GIcon for primary icon"),
1115 GTK_PARAM_READWRITE));
1118 * GtkEntry:secondary-icon-gicon:
1120 * The #GIcon to use for the secondary icon for the entry.
1124 g_object_class_install_property (gobject_class,
1125 PROP_GICON_SECONDARY,
1126 g_param_spec_object ("secondary-icon-gicon",
1127 P_("Secondary GIcon"),
1128 P_("GIcon for secondary icon"),
1130 GTK_PARAM_READWRITE));
1133 * GtkEntry:primary-icon-storage-type:
1135 * The representation which is used for the primary icon of the entry.
1139 g_object_class_install_property (gobject_class,
1140 PROP_STORAGE_TYPE_PRIMARY,
1141 g_param_spec_enum ("primary-icon-storage-type",
1142 P_("Primary storage type"),
1143 P_("The representation being used for primary icon"),
1144 GTK_TYPE_IMAGE_TYPE,
1146 GTK_PARAM_READABLE));
1149 * GtkEntry:secondary-icon-storage-type:
1151 * The representation which is used for the secondary icon of the entry.
1155 g_object_class_install_property (gobject_class,
1156 PROP_STORAGE_TYPE_SECONDARY,
1157 g_param_spec_enum ("secondary-icon-storage-type",
1158 P_("Secondary storage type"),
1159 P_("The representation being used for secondary icon"),
1160 GTK_TYPE_IMAGE_TYPE,
1162 GTK_PARAM_READABLE));
1165 * GtkEntry:primary-icon-activatable:
1167 * Whether the primary icon is activatable.
1169 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1170 * signals only on sensitive, activatable icons.
1172 * Sensitive, but non-activatable icons can be used for purely
1173 * informational purposes.
1177 g_object_class_install_property (gobject_class,
1178 PROP_ACTIVATABLE_PRIMARY,
1179 g_param_spec_boolean ("primary-icon-activatable",
1180 P_("Primary icon activatable"),
1181 P_("Whether the primary icon is activatable"),
1183 GTK_PARAM_READWRITE));
1186 * GtkEntry:secondary-icon-activatable:
1188 * Whether the secondary icon is activatable.
1190 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1191 * signals only on sensitive, activatable icons.
1193 * Sensitive, but non-activatable icons can be used for purely
1194 * informational purposes.
1198 g_object_class_install_property (gobject_class,
1199 PROP_ACTIVATABLE_SECONDARY,
1200 g_param_spec_boolean ("secondary-icon-activatable",
1201 P_("Secondary icon activatable"),
1202 P_("Whether the secondary icon is activatable"),
1204 GTK_PARAM_READWRITE));
1208 * GtkEntry:primary-icon-sensitive:
1210 * Whether the primary icon is sensitive.
1212 * An insensitive icon appears grayed out. GTK+ does not emit the
1213 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1214 * does not allow DND from insensitive icons.
1216 * An icon should be set insensitive if the action that would trigger
1217 * when clicked is currently not available.
1221 g_object_class_install_property (gobject_class,
1222 PROP_SENSITIVE_PRIMARY,
1223 g_param_spec_boolean ("primary-icon-sensitive",
1224 P_("Primary icon sensitive"),
1225 P_("Whether the primary icon is sensitive"),
1227 GTK_PARAM_READWRITE));
1230 * GtkEntry:secondary-icon-sensitive:
1232 * Whether the secondary icon is sensitive.
1234 * An insensitive icon appears grayed out. GTK+ does not emit the
1235 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1236 * does not allow DND from insensitive icons.
1238 * An icon should be set insensitive if the action that would trigger
1239 * when clicked is currently not available.
1243 g_object_class_install_property (gobject_class,
1244 PROP_SENSITIVE_SECONDARY,
1245 g_param_spec_boolean ("secondary-icon-sensitive",
1246 P_("Secondary icon sensitive"),
1247 P_("Whether the secondary icon is sensitive"),
1249 GTK_PARAM_READWRITE));
1252 * GtkEntry:primary-icon-tooltip-text:
1254 * The contents of the tooltip on the primary icon.
1256 * Also see gtk_entry_set_icon_tooltip_text().
1260 g_object_class_install_property (gobject_class,
1261 PROP_TOOLTIP_TEXT_PRIMARY,
1262 g_param_spec_string ("primary-icon-tooltip-text",
1263 P_("Primary icon tooltip text"),
1264 P_("The contents of the tooltip on the primary icon"),
1266 GTK_PARAM_READWRITE));
1269 * GtkEntry:secondary-icon-tooltip-text:
1271 * The contents of the tooltip on the secondary icon.
1273 * Also see gtk_entry_set_icon_tooltip_text().
1277 g_object_class_install_property (gobject_class,
1278 PROP_TOOLTIP_TEXT_SECONDARY,
1279 g_param_spec_string ("secondary-icon-tooltip-text",
1280 P_("Secondary icon tooltip text"),
1281 P_("The contents of the tooltip on the secondary icon"),
1283 GTK_PARAM_READWRITE));
1286 * GtkEntry:primary-icon-tooltip-markup:
1288 * The contents of the tooltip on the primary icon, which is marked up
1289 * with the <link linkend="PangoMarkupFormat">Pango text markup
1292 * Also see gtk_entry_set_icon_tooltip_markup().
1296 g_object_class_install_property (gobject_class,
1297 PROP_TOOLTIP_MARKUP_PRIMARY,
1298 g_param_spec_string ("primary-icon-tooltip-markup",
1299 P_("Primary icon tooltip markup"),
1300 P_("The contents of the tooltip on the primary icon"),
1302 GTK_PARAM_READWRITE));
1305 * GtkEntry:secondary-icon-tooltip-markup:
1307 * The contents of the tooltip on the secondary icon, which is marked up
1308 * with the <link linkend="PangoMarkupFormat">Pango text markup
1311 * Also see gtk_entry_set_icon_tooltip_markup().
1315 g_object_class_install_property (gobject_class,
1316 PROP_TOOLTIP_MARKUP_SECONDARY,
1317 g_param_spec_string ("secondary-icon-tooltip-markup",
1318 P_("Secondary icon tooltip markup"),
1319 P_("The contents of the tooltip on the secondary icon"),
1321 GTK_PARAM_READWRITE));
1324 * GtkEntry:im-module:
1326 * Which IM (input method) module should be used for this entry.
1327 * See #GtkIMContext.
1329 * Setting this to a non-%NULL value overrides the
1330 * system-wide IM module setting. See the GtkSettings
1331 * #GtkSettings:gtk-im-module property.
1335 g_object_class_install_property (gobject_class,
1337 g_param_spec_string ("im-module",
1339 P_("Which IM module should be used"),
1341 GTK_PARAM_READWRITE));
1344 * GtkEntry:completion:
1346 * The auxiliary completion object to use with the entry.
1350 g_object_class_install_property (gobject_class,
1352 g_param_spec_object ("completion",
1354 P_("The auxiliary completion object"),
1355 GTK_TYPE_ENTRY_COMPLETION,
1356 GTK_PARAM_READWRITE));
1359 * GtkEntry:input-purpose:
1361 * The purpose of this text field.
1363 * This property can be used by on-screen keyboards and other input
1364 * methods to adjust their behaviour.
1366 * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
1367 * %GTK_INPUT_PURPOSE_PIN is independent from setting
1368 * #GtkEntry:visibility.
1372 g_object_class_install_property (gobject_class,
1374 g_param_spec_enum ("input-purpose",
1376 P_("Purpose of the text field"),
1377 GTK_TYPE_INPUT_PURPOSE,
1378 GTK_INPUT_PURPOSE_FREE_FORM,
1379 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1382 * GtkEntry:input-hints:
1384 * Additional hints (beyond #GtkEntry:input-purpose) that
1385 * allow input methods to fine-tune their behaviour.
1389 g_object_class_install_property (gobject_class,
1391 g_param_spec_flags ("input-hints",
1393 P_("Hints for the text field behaviour"),
1394 GTK_TYPE_INPUT_HINTS,
1395 GTK_INPUT_HINT_NONE,
1396 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1399 * GtkEntry:attributes:
1401 * A list of Pango attributes to apply to the text of the entry.
1403 * This is mainly useful to change the size or weight of the text.
1407 g_object_class_install_property (gobject_class,
1409 g_param_spec_boxed ("attributes",
1411 P_("A list of style attributes to apply to the text of the label"),
1412 PANGO_TYPE_ATTR_LIST,
1413 GTK_PARAM_READWRITE));
1416 * GtkEntry:icon-prelight:
1418 * The prelight style property determines whether activatable
1419 * icons prelight on mouseover.
1423 gtk_widget_class_install_style_property (widget_class,
1424 g_param_spec_boolean ("icon-prelight",
1425 P_("Icon Prelight"),
1426 P_("Whether activatable icons should prelight when hovered"),
1428 GTK_PARAM_READABLE));
1431 * GtkEntry:progress-border:
1433 * The border around the progress bar in the entry.
1437 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1438 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1439 * property is ignored.
1441 gtk_widget_class_install_style_property (widget_class,
1442 g_param_spec_boxed ("progress-border",
1443 P_("Progress Border"),
1444 P_("Border around the progress bar"),
1446 GTK_PARAM_READABLE |
1447 G_PARAM_DEPRECATED));
1450 * GtkEntry:invisible-char:
1452 * The invisible character is used when masking entry contents (in
1453 * \"password mode\")"). When it is not explicitly set with the
1454 * #GtkEntry:invisible-char property, GTK+ determines the character
1455 * to use from a list of possible candidates, depending on availability
1456 * in the current font.
1458 * This style property allows the theme to prepend a character
1459 * to the list of candidates.
1463 gtk_widget_class_install_style_property (widget_class,
1464 g_param_spec_unichar ("invisible-char",
1465 P_("Invisible character"),
1466 P_("The character to use when masking entry contents (in \"password mode\")"),
1468 GTK_PARAM_READABLE));
1471 * GtkEntry::populate-popup:
1472 * @entry: The entry on which the signal is emitted
1473 * @menu: the menu that is being populated
1475 * The ::populate-popup signal gets emitted before showing the
1476 * context menu of the entry.
1478 * If you need to add items to the context menu, connect
1479 * to this signal and append your menuitems to the @menu.
1481 signals[POPULATE_POPUP] =
1482 g_signal_new (I_("populate-popup"),
1483 G_OBJECT_CLASS_TYPE (gobject_class),
1485 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1487 _gtk_marshal_VOID__OBJECT,
1491 /* Action signals */
1494 * GtkEntry::activate:
1495 * @entry: The entry on which the signal is emitted
1497 * The ::activate signal is emitted when the user hits
1500 * While this signal is used as a
1501 * <link linkend="keybinding-signals">keybinding signal</link>,
1502 * it is also commonly used by applications to intercept
1503 * activation of entries.
1505 * The default bindings for this signal are all forms of the Enter key.
1508 g_signal_new (I_("activate"),
1509 G_OBJECT_CLASS_TYPE (gobject_class),
1510 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1511 G_STRUCT_OFFSET (GtkEntryClass, activate),
1513 _gtk_marshal_VOID__VOID,
1515 widget_class->activate_signal = signals[ACTIVATE];
1518 * GtkEntry::move-cursor:
1519 * @entry: the object which received the signal
1520 * @step: the granularity of the move, as a #GtkMovementStep
1521 * @count: the number of @step units to move
1522 * @extend_selection: %TRUE if the move should extend the selection
1524 * The ::move-cursor signal is a
1525 * <link linkend="keybinding-signals">keybinding signal</link>
1526 * which gets emitted when the user initiates a cursor movement.
1527 * If the cursor is not visible in @entry, this signal causes
1528 * the viewport to be moved instead.
1530 * Applications should not connect to it, but may emit it with
1531 * g_signal_emit_by_name() if they need to control the cursor
1534 * The default bindings for this signal come in two variants,
1535 * the variant with the Shift modifier extends the selection,
1536 * the variant without the Shift modifer does not.
1537 * There are too many key combinations to list them all here.
1539 * <listitem>Arrow keys move by individual characters/lines</listitem>
1540 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1541 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1544 signals[MOVE_CURSOR] =
1545 g_signal_new (I_("move-cursor"),
1546 G_OBJECT_CLASS_TYPE (gobject_class),
1547 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1548 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1550 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1552 GTK_TYPE_MOVEMENT_STEP,
1557 * GtkEntry::insert-at-cursor:
1558 * @entry: the object which received the signal
1559 * @string: the string to insert
1561 * The ::insert-at-cursor signal is a
1562 * <link linkend="keybinding-signals">keybinding signal</link>
1563 * which gets emitted when the user initiates the insertion of a
1564 * fixed string at the cursor.
1566 * This signal has no default bindings.
1568 signals[INSERT_AT_CURSOR] =
1569 g_signal_new (I_("insert-at-cursor"),
1570 G_OBJECT_CLASS_TYPE (gobject_class),
1571 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1572 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1574 _gtk_marshal_VOID__STRING,
1579 * GtkEntry::delete-from-cursor:
1580 * @entry: the object which received the signal
1581 * @type: the granularity of the deletion, as a #GtkDeleteType
1582 * @count: the number of @type units to delete
1584 * The ::delete-from-cursor signal is a
1585 * <link linkend="keybinding-signals">keybinding signal</link>
1586 * which gets emitted when the user initiates a text deletion.
1588 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1589 * if there is one, otherwise it deletes the requested number
1592 * The default bindings for this signal are
1593 * Delete for deleting a character and Ctrl-Delete for
1596 signals[DELETE_FROM_CURSOR] =
1597 g_signal_new (I_("delete-from-cursor"),
1598 G_OBJECT_CLASS_TYPE (gobject_class),
1599 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1600 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1602 _gtk_marshal_VOID__ENUM_INT,
1604 GTK_TYPE_DELETE_TYPE,
1608 * GtkEntry::backspace:
1609 * @entry: the object which received the signal
1611 * The ::backspace signal is a
1612 * <link linkend="keybinding-signals">keybinding signal</link>
1613 * which gets emitted when the user asks for it.
1615 * The default bindings for this signal are
1616 * Backspace and Shift-Backspace.
1618 signals[BACKSPACE] =
1619 g_signal_new (I_("backspace"),
1620 G_OBJECT_CLASS_TYPE (gobject_class),
1621 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1622 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1624 _gtk_marshal_VOID__VOID,
1628 * GtkEntry::cut-clipboard:
1629 * @entry: the object which received the signal
1631 * The ::cut-clipboard signal is a
1632 * <link linkend="keybinding-signals">keybinding signal</link>
1633 * which gets emitted to cut the selection to the clipboard.
1635 * The default bindings for this signal are
1636 * Ctrl-x and Shift-Delete.
1638 signals[CUT_CLIPBOARD] =
1639 g_signal_new (I_("cut-clipboard"),
1640 G_OBJECT_CLASS_TYPE (gobject_class),
1641 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1642 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1644 _gtk_marshal_VOID__VOID,
1648 * GtkEntry::copy-clipboard:
1649 * @entry: the object which received the signal
1651 * The ::copy-clipboard signal is a
1652 * <link linkend="keybinding-signals">keybinding signal</link>
1653 * which gets emitted to copy the selection to the clipboard.
1655 * The default bindings for this signal are
1656 * Ctrl-c and Ctrl-Insert.
1658 signals[COPY_CLIPBOARD] =
1659 g_signal_new (I_("copy-clipboard"),
1660 G_OBJECT_CLASS_TYPE (gobject_class),
1661 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1662 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1664 _gtk_marshal_VOID__VOID,
1668 * GtkEntry::paste-clipboard:
1669 * @entry: the object which received the signal
1671 * The ::paste-clipboard signal is a
1672 * <link linkend="keybinding-signals">keybinding signal</link>
1673 * which gets emitted to paste the contents of the clipboard
1674 * into the text view.
1676 * The default bindings for this signal are
1677 * Ctrl-v and Shift-Insert.
1679 signals[PASTE_CLIPBOARD] =
1680 g_signal_new (I_("paste-clipboard"),
1681 G_OBJECT_CLASS_TYPE (gobject_class),
1682 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1683 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1685 _gtk_marshal_VOID__VOID,
1689 * GtkEntry::toggle-overwrite:
1690 * @entry: the object which received the signal
1692 * The ::toggle-overwrite signal is a
1693 * <link linkend="keybinding-signals">keybinding signal</link>
1694 * which gets emitted to toggle the overwrite mode of the entry.
1696 * The default bindings for this signal is Insert.
1698 signals[TOGGLE_OVERWRITE] =
1699 g_signal_new (I_("toggle-overwrite"),
1700 G_OBJECT_CLASS_TYPE (gobject_class),
1701 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1702 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1704 _gtk_marshal_VOID__VOID,
1708 * GtkEntry::icon-press:
1709 * @entry: The entry on which the signal is emitted
1710 * @icon_pos: The position of the clicked icon
1711 * @event: (type Gdk.EventButton): the button press event
1713 * The ::icon-press signal is emitted when an activatable icon
1718 signals[ICON_PRESS] =
1719 g_signal_new (I_("icon-press"),
1720 G_TYPE_FROM_CLASS (gobject_class),
1724 _gtk_marshal_VOID__ENUM_BOXED,
1726 GTK_TYPE_ENTRY_ICON_POSITION,
1727 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1730 * GtkEntry::icon-release:
1731 * @entry: The entry on which the signal is emitted
1732 * @icon_pos: The position of the clicked icon
1733 * @event: (type Gdk.EventButton): the button release event
1735 * The ::icon-release signal is emitted on the button release from a
1736 * mouse click over an activatable icon.
1740 signals[ICON_RELEASE] =
1741 g_signal_new (I_("icon-release"),
1742 G_TYPE_FROM_CLASS (gobject_class),
1746 _gtk_marshal_VOID__ENUM_BOXED,
1748 GTK_TYPE_ENTRY_ICON_POSITION,
1749 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1752 * GtkEntry::preedit-changed:
1753 * @entry: the object which received the signal
1754 * @preedit: the current preedit string
1756 * If an input method is used, the typed text will not immediately
1757 * be committed to the buffer. So if you are interested in the text,
1758 * connect to this signal.
1762 signals[PREEDIT_CHANGED] =
1763 g_signal_new_class_handler (I_("preedit-changed"),
1764 G_OBJECT_CLASS_TYPE (gobject_class),
1765 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1768 _gtk_marshal_VOID__STRING,
1777 binding_set = gtk_binding_set_by_class (class);
1779 /* Moving the insertion point */
1780 add_move_binding (binding_set, GDK_KEY_Right, 0,
1781 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1783 add_move_binding (binding_set, GDK_KEY_Left, 0,
1784 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1786 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1787 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1789 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1790 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1792 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1793 GTK_MOVEMENT_WORDS, 1);
1795 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1796 GTK_MOVEMENT_WORDS, -1);
1798 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1799 GTK_MOVEMENT_WORDS, 1);
1801 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1802 GTK_MOVEMENT_WORDS, -1);
1804 add_move_binding (binding_set, GDK_KEY_Home, 0,
1805 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1807 add_move_binding (binding_set, GDK_KEY_End, 0,
1808 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1810 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1811 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1813 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1814 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1816 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1817 GTK_MOVEMENT_BUFFER_ENDS, -1);
1819 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1820 GTK_MOVEMENT_BUFFER_ENDS, 1);
1822 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1823 GTK_MOVEMENT_BUFFER_ENDS, -1);
1825 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1826 GTK_MOVEMENT_BUFFER_ENDS, 1);
1830 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1832 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1834 G_TYPE_BOOLEAN, FALSE);
1835 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1837 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1839 G_TYPE_BOOLEAN, TRUE);
1841 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1843 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1845 G_TYPE_BOOLEAN, FALSE);
1846 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1848 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1850 G_TYPE_BOOLEAN, TRUE);
1853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1855 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1857 G_TYPE_BOOLEAN, FALSE);
1858 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1860 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1862 G_TYPE_BOOLEAN, FALSE);
1866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1870 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1874 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1875 "delete-from-cursor", 2,
1876 G_TYPE_ENUM, GTK_DELETE_CHARS,
1879 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1880 "delete-from-cursor", 2,
1881 G_TYPE_ENUM, GTK_DELETE_CHARS,
1884 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1887 /* Make this do the same as Backspace, to help with mis-typing */
1888 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1891 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1892 "delete-from-cursor", 2,
1893 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1896 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1897 "delete-from-cursor", 2,
1898 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1901 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1902 "delete-from-cursor", 2,
1903 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1906 /* Cut/copy/paste */
1908 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1909 "cut-clipboard", 0);
1910 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1911 "copy-clipboard", 0);
1912 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1913 "paste-clipboard", 0);
1915 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1916 "cut-clipboard", 0);
1917 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1918 "copy-clipboard", 0);
1919 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1920 "paste-clipboard", 0);
1923 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1924 "toggle-overwrite", 0);
1925 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1926 "toggle-overwrite", 0);
1929 * GtkEntry:inner-border:
1931 * Sets the text area's border between the text and the frame.
1935 * Deprecated: 3.4: Use the standard border and padding CSS properties
1936 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1937 * of this style property is ignored.
1939 gtk_widget_class_install_style_property (widget_class,
1940 g_param_spec_boxed ("inner-border",
1942 P_("Border between text and frame."),
1944 GTK_PARAM_READABLE |
1945 G_PARAM_DEPRECATED));
1947 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1948 test_touchscreen = g_getenv ("GTK_TEST_TOUCHSCREEN") != NULL;
1950 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1954 gtk_entry_editable_init (GtkEditableInterface *iface)
1956 iface->do_insert_text = gtk_entry_insert_text;
1957 iface->do_delete_text = gtk_entry_delete_text;
1958 iface->insert_text = gtk_entry_real_insert_text;
1959 iface->delete_text = gtk_entry_real_delete_text;
1960 iface->get_chars = gtk_entry_get_chars;
1961 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1962 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1963 iface->set_position = gtk_entry_real_set_position;
1964 iface->get_position = gtk_entry_get_position;
1968 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1970 iface->start_editing = gtk_entry_start_editing;
1973 /* for deprecated properties */
1975 gtk_entry_do_set_inner_border (GtkEntry *entry,
1976 const GtkBorder *border)
1979 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1980 gtk_border_copy (border),
1981 (GDestroyNotify) gtk_border_free);
1983 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1985 g_object_notify (G_OBJECT (entry), "inner-border");
1988 static const GtkBorder *
1989 gtk_entry_do_get_inner_border (GtkEntry *entry)
1991 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1995 gtk_entry_set_property (GObject *object,
1997 const GValue *value,
2000 GtkEntry *entry = GTK_ENTRY (object);
2001 GtkEntryPrivate *priv = entry->priv;
2006 gtk_entry_set_buffer (entry, g_value_get_object (value));
2011 gboolean new_value = g_value_get_boolean (value);
2013 if (new_value != priv->editable)
2015 GtkWidget *widget = GTK_WIDGET (entry);
2019 gtk_entry_reset_im_context (entry);
2020 if (gtk_widget_has_focus (widget))
2021 gtk_im_context_focus_out (priv->im_context);
2023 priv->preedit_length = 0;
2024 priv->preedit_cursor = 0;
2027 priv->editable = new_value;
2029 if (new_value && gtk_widget_has_focus (widget))
2030 gtk_im_context_focus_in (priv->im_context);
2032 gtk_widget_queue_draw (widget);
2037 case PROP_MAX_LENGTH:
2038 gtk_entry_set_max_length (entry, g_value_get_int (value));
2041 case PROP_VISIBILITY:
2042 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
2045 case PROP_HAS_FRAME:
2046 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
2049 case PROP_INNER_BORDER:
2050 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
2053 case PROP_INVISIBLE_CHAR:
2054 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2057 case PROP_ACTIVATES_DEFAULT:
2058 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2061 case PROP_WIDTH_CHARS:
2062 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2066 gtk_entry_set_text (entry, g_value_get_string (value));
2070 gtk_entry_set_alignment (entry, g_value_get_float (value));
2073 case PROP_TRUNCATE_MULTILINE:
2074 priv->truncate_multiline = g_value_get_boolean (value);
2077 case PROP_SHADOW_TYPE:
2078 priv->shadow_type = g_value_get_enum (value);
2081 case PROP_OVERWRITE_MODE:
2082 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2085 case PROP_INVISIBLE_CHAR_SET:
2086 if (g_value_get_boolean (value))
2087 priv->invisible_char_set = TRUE;
2089 gtk_entry_unset_invisible_char (entry);
2092 case PROP_CAPS_LOCK_WARNING:
2093 priv->caps_lock_warning = g_value_get_boolean (value);
2096 case PROP_PROGRESS_FRACTION:
2097 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2100 case PROP_PROGRESS_PULSE_STEP:
2101 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2104 case PROP_PLACEHOLDER_TEXT:
2105 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2108 case PROP_PIXBUF_PRIMARY:
2109 gtk_entry_set_icon_from_pixbuf (entry,
2110 GTK_ENTRY_ICON_PRIMARY,
2111 g_value_get_object (value));
2114 case PROP_PIXBUF_SECONDARY:
2115 gtk_entry_set_icon_from_pixbuf (entry,
2116 GTK_ENTRY_ICON_SECONDARY,
2117 g_value_get_object (value));
2120 case PROP_STOCK_PRIMARY:
2121 gtk_entry_set_icon_from_stock (entry,
2122 GTK_ENTRY_ICON_PRIMARY,
2123 g_value_get_string (value));
2126 case PROP_STOCK_SECONDARY:
2127 gtk_entry_set_icon_from_stock (entry,
2128 GTK_ENTRY_ICON_SECONDARY,
2129 g_value_get_string (value));
2132 case PROP_ICON_NAME_PRIMARY:
2133 gtk_entry_set_icon_from_icon_name (entry,
2134 GTK_ENTRY_ICON_PRIMARY,
2135 g_value_get_string (value));
2138 case PROP_ICON_NAME_SECONDARY:
2139 gtk_entry_set_icon_from_icon_name (entry,
2140 GTK_ENTRY_ICON_SECONDARY,
2141 g_value_get_string (value));
2144 case PROP_GICON_PRIMARY:
2145 gtk_entry_set_icon_from_gicon (entry,
2146 GTK_ENTRY_ICON_PRIMARY,
2147 g_value_get_object (value));
2150 case PROP_GICON_SECONDARY:
2151 gtk_entry_set_icon_from_gicon (entry,
2152 GTK_ENTRY_ICON_SECONDARY,
2153 g_value_get_object (value));
2156 case PROP_ACTIVATABLE_PRIMARY:
2157 gtk_entry_set_icon_activatable (entry,
2158 GTK_ENTRY_ICON_PRIMARY,
2159 g_value_get_boolean (value));
2162 case PROP_ACTIVATABLE_SECONDARY:
2163 gtk_entry_set_icon_activatable (entry,
2164 GTK_ENTRY_ICON_SECONDARY,
2165 g_value_get_boolean (value));
2168 case PROP_SENSITIVE_PRIMARY:
2169 gtk_entry_set_icon_sensitive (entry,
2170 GTK_ENTRY_ICON_PRIMARY,
2171 g_value_get_boolean (value));
2174 case PROP_SENSITIVE_SECONDARY:
2175 gtk_entry_set_icon_sensitive (entry,
2176 GTK_ENTRY_ICON_SECONDARY,
2177 g_value_get_boolean (value));
2180 case PROP_TOOLTIP_TEXT_PRIMARY:
2181 gtk_entry_set_icon_tooltip_text (entry,
2182 GTK_ENTRY_ICON_PRIMARY,
2183 g_value_get_string (value));
2186 case PROP_TOOLTIP_TEXT_SECONDARY:
2187 gtk_entry_set_icon_tooltip_text (entry,
2188 GTK_ENTRY_ICON_SECONDARY,
2189 g_value_get_string (value));
2192 case PROP_TOOLTIP_MARKUP_PRIMARY:
2193 gtk_entry_set_icon_tooltip_markup (entry,
2194 GTK_ENTRY_ICON_PRIMARY,
2195 g_value_get_string (value));
2198 case PROP_TOOLTIP_MARKUP_SECONDARY:
2199 gtk_entry_set_icon_tooltip_markup (entry,
2200 GTK_ENTRY_ICON_SECONDARY,
2201 g_value_get_string (value));
2204 case PROP_IM_MODULE:
2205 g_free (priv->im_module);
2206 priv->im_module = g_value_dup_string (value);
2207 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2208 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2211 case PROP_EDITING_CANCELED:
2212 priv->editing_canceled = g_value_get_boolean (value);
2215 case PROP_COMPLETION:
2216 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2219 case PROP_INPUT_PURPOSE:
2220 gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
2223 case PROP_INPUT_HINTS:
2224 gtk_entry_set_input_hints (entry, g_value_get_flags (value));
2227 case PROP_ATTRIBUTES:
2228 gtk_entry_set_attributes (entry, g_value_get_boxed (value));
2231 case PROP_SCROLL_OFFSET:
2232 case PROP_CURSOR_POSITION:
2234 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2240 gtk_entry_get_property (GObject *object,
2245 GtkEntry *entry = GTK_ENTRY (object);
2246 GtkEntryPrivate *priv = entry->priv;
2251 g_value_set_object (value, gtk_entry_get_buffer (entry));
2254 case PROP_CURSOR_POSITION:
2255 g_value_set_int (value, priv->current_pos);
2258 case PROP_SELECTION_BOUND:
2259 g_value_set_int (value, priv->selection_bound);
2263 g_value_set_boolean (value, priv->editable);
2266 case PROP_MAX_LENGTH:
2267 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2270 case PROP_VISIBILITY:
2271 g_value_set_boolean (value, priv->visible);
2274 case PROP_HAS_FRAME:
2275 g_value_set_boolean (value, priv->has_frame);
2278 case PROP_INNER_BORDER:
2279 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2282 case PROP_INVISIBLE_CHAR:
2283 g_value_set_uint (value, priv->invisible_char);
2286 case PROP_ACTIVATES_DEFAULT:
2287 g_value_set_boolean (value, priv->activates_default);
2290 case PROP_WIDTH_CHARS:
2291 g_value_set_int (value, priv->width_chars);
2294 case PROP_SCROLL_OFFSET:
2295 g_value_set_int (value, priv->scroll_offset);
2299 g_value_set_string (value, gtk_entry_get_text (entry));
2303 g_value_set_float (value, gtk_entry_get_alignment (entry));
2306 case PROP_TRUNCATE_MULTILINE:
2307 g_value_set_boolean (value, priv->truncate_multiline);
2310 case PROP_SHADOW_TYPE:
2311 g_value_set_enum (value, priv->shadow_type);
2314 case PROP_OVERWRITE_MODE:
2315 g_value_set_boolean (value, priv->overwrite_mode);
2318 case PROP_TEXT_LENGTH:
2319 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2322 case PROP_INVISIBLE_CHAR_SET:
2323 g_value_set_boolean (value, priv->invisible_char_set);
2326 case PROP_IM_MODULE:
2327 g_value_set_string (value, priv->im_module);
2330 case PROP_CAPS_LOCK_WARNING:
2331 g_value_set_boolean (value, priv->caps_lock_warning);
2334 case PROP_PROGRESS_FRACTION:
2335 g_value_set_double (value, priv->progress_fraction);
2338 case PROP_PROGRESS_PULSE_STEP:
2339 g_value_set_double (value, priv->progress_pulse_fraction);
2342 case PROP_PLACEHOLDER_TEXT:
2343 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2346 case PROP_PIXBUF_PRIMARY:
2347 g_value_set_object (value,
2348 gtk_entry_get_icon_pixbuf (entry,
2349 GTK_ENTRY_ICON_PRIMARY));
2352 case PROP_PIXBUF_SECONDARY:
2353 g_value_set_object (value,
2354 gtk_entry_get_icon_pixbuf (entry,
2355 GTK_ENTRY_ICON_SECONDARY));
2358 case PROP_STOCK_PRIMARY:
2359 g_value_set_string (value,
2360 gtk_entry_get_icon_stock (entry,
2361 GTK_ENTRY_ICON_PRIMARY));
2364 case PROP_STOCK_SECONDARY:
2365 g_value_set_string (value,
2366 gtk_entry_get_icon_stock (entry,
2367 GTK_ENTRY_ICON_SECONDARY));
2370 case PROP_ICON_NAME_PRIMARY:
2371 g_value_set_string (value,
2372 gtk_entry_get_icon_name (entry,
2373 GTK_ENTRY_ICON_PRIMARY));
2376 case PROP_ICON_NAME_SECONDARY:
2377 g_value_set_string (value,
2378 gtk_entry_get_icon_name (entry,
2379 GTK_ENTRY_ICON_SECONDARY));
2382 case PROP_GICON_PRIMARY:
2383 g_value_set_object (value,
2384 gtk_entry_get_icon_gicon (entry,
2385 GTK_ENTRY_ICON_PRIMARY));
2388 case PROP_GICON_SECONDARY:
2389 g_value_set_object (value,
2390 gtk_entry_get_icon_gicon (entry,
2391 GTK_ENTRY_ICON_SECONDARY));
2394 case PROP_STORAGE_TYPE_PRIMARY:
2395 g_value_set_enum (value,
2396 gtk_entry_get_icon_storage_type (entry,
2397 GTK_ENTRY_ICON_PRIMARY));
2400 case PROP_STORAGE_TYPE_SECONDARY:
2401 g_value_set_enum (value,
2402 gtk_entry_get_icon_storage_type (entry,
2403 GTK_ENTRY_ICON_SECONDARY));
2406 case PROP_ACTIVATABLE_PRIMARY:
2407 g_value_set_boolean (value,
2408 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2411 case PROP_ACTIVATABLE_SECONDARY:
2412 g_value_set_boolean (value,
2413 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2416 case PROP_SENSITIVE_PRIMARY:
2417 g_value_set_boolean (value,
2418 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2421 case PROP_SENSITIVE_SECONDARY:
2422 g_value_set_boolean (value,
2423 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2426 case PROP_TOOLTIP_TEXT_PRIMARY:
2427 g_value_take_string (value,
2428 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2431 case PROP_TOOLTIP_TEXT_SECONDARY:
2432 g_value_take_string (value,
2433 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2436 case PROP_TOOLTIP_MARKUP_PRIMARY:
2437 g_value_take_string (value,
2438 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2441 case PROP_TOOLTIP_MARKUP_SECONDARY:
2442 g_value_take_string (value,
2443 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2446 case PROP_EDITING_CANCELED:
2447 g_value_set_boolean (value,
2448 priv->editing_canceled);
2451 case PROP_COMPLETION:
2452 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2455 case PROP_INPUT_PURPOSE:
2456 g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
2459 case PROP_INPUT_HINTS:
2460 g_value_set_flags (value, gtk_entry_get_input_hints (entry));
2463 case PROP_ATTRIBUTES:
2464 g_value_set_boxed (value, priv->attrs);
2468 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2474 find_invisible_char (GtkWidget *widget)
2476 PangoLayout *layout;
2477 PangoAttrList *attr_list;
2479 gunichar invisible_chars [] = {
2481 0x25cf, /* BLACK CIRCLE */
2482 0x2022, /* BULLET */
2483 0x2731, /* HEAVY ASTERISK */
2484 0x273a /* SIXTEEN POINTED ASTERISK */
2487 gtk_widget_style_get (widget,
2488 "invisible-char", &invisible_chars[0],
2491 layout = gtk_widget_create_pango_layout (widget, NULL);
2493 attr_list = pango_attr_list_new ();
2494 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2496 pango_layout_set_attributes (layout, attr_list);
2497 pango_attr_list_unref (attr_list);
2499 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2501 gchar text[7] = { 0, };
2504 len = g_unichar_to_utf8 (invisible_chars[i], text);
2505 pango_layout_set_text (layout, text, len);
2507 count = pango_layout_get_unknown_glyphs_count (layout);
2511 g_object_unref (layout);
2512 return invisible_chars[i];
2516 g_object_unref (layout);
2522 gtk_entry_init (GtkEntry *entry)
2524 GtkStyleContext *context;
2525 GtkEntryPrivate *priv;
2527 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2532 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2533 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2535 priv->editable = TRUE;
2536 priv->visible = TRUE;
2537 priv->dnd_position = -1;
2538 priv->width_chars = -1;
2539 priv->is_cell_renderer = FALSE;
2540 priv->editing_canceled = FALSE;
2541 priv->has_frame = TRUE;
2542 priv->truncate_multiline = FALSE;
2543 priv->shadow_type = GTK_SHADOW_IN;
2545 priv->caps_lock_warning = TRUE;
2546 priv->caps_lock_warning_shown = FALSE;
2547 priv->progress_fraction = 0.0;
2548 priv->progress_pulse_fraction = 0.1;
2550 gtk_drag_dest_set (GTK_WIDGET (entry),
2551 GTK_DEST_DEFAULT_HIGHLIGHT,
2553 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2554 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2556 /* This object is completely private. No external entity can gain a reference
2557 * to it; so we create it here and destroy it in finalize().
2559 priv->im_context = gtk_im_multicontext_new ();
2561 g_signal_connect (priv->im_context, "commit",
2562 G_CALLBACK (gtk_entry_commit_cb), entry);
2563 g_signal_connect (priv->im_context, "preedit-changed",
2564 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2565 g_signal_connect (priv->im_context, "retrieve-surrounding",
2566 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2567 g_signal_connect (priv->im_context, "delete-surrounding",
2568 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2570 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2571 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2573 gtk_entry_update_cached_style_values (entry);
2575 priv->text_handle = _gtk_text_handle_new (GTK_WIDGET (entry));
2576 g_signal_connect (priv->text_handle, "handle-dragged",
2577 G_CALLBACK (gtk_entry_handle_dragged), entry);
2581 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2582 GtkStyleContext *context,
2583 GtkEntryIconPosition icon_pos)
2585 GtkEntryPrivate *priv = entry->priv;
2586 EntryIconInfo *icon_info = priv->icons[icon_pos];
2588 GtkStateFlags state;
2590 widget = GTK_WIDGET (entry);
2591 state = gtk_widget_get_state_flags (widget);
2593 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2595 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2596 state |= GTK_STATE_FLAG_INSENSITIVE;
2597 else if (icon_info->prelight)
2598 state |= GTK_STATE_FLAG_PRELIGHT;
2600 gtk_style_context_save (context);
2602 gtk_style_context_set_state (context, state);
2603 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2605 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2607 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2608 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2610 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2614 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2615 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2617 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2622 get_icon_width (GtkEntry *entry,
2623 GtkEntryIconPosition icon_pos)
2625 GtkEntryPrivate *priv = entry->priv;
2626 EntryIconInfo *icon_info = priv->icons[icon_pos];
2627 GtkStyleContext *context;
2634 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2635 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2636 gtk_style_context_get_padding (context, 0, &padding);
2638 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2640 gtk_style_context_restore (context);
2643 width += padding.left + padding.right;
2649 get_icon_allocations (GtkEntry *entry,
2650 GtkAllocation *primary,
2651 GtkAllocation *secondary)
2654 GtkEntryPrivate *priv = entry->priv;
2655 gint x, y, width, height;
2657 get_text_area_size (entry, &x, &y, &width, &height);
2659 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2660 y += priv->focus_width;
2663 primary->height = height;
2664 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2667 secondary->height = height;
2668 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2670 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2672 primary->x = x + width - primary->width;
2678 secondary->x = x + width - secondary->width;
2684 begin_change (GtkEntry *entry)
2686 GtkEntryPrivate *priv = entry->priv;
2688 priv->change_count++;
2690 g_object_freeze_notify (G_OBJECT (entry));
2694 end_change (GtkEntry *entry)
2696 GtkEditable *editable = GTK_EDITABLE (entry);
2697 GtkEntryPrivate *priv = entry->priv;
2699 g_return_if_fail (priv->change_count > 0);
2701 g_object_thaw_notify (G_OBJECT (entry));
2703 priv->change_count--;
2705 if (priv->change_count == 0)
2707 if (priv->real_changed)
2709 g_signal_emit_by_name (editable, "changed");
2710 priv->real_changed = FALSE;
2716 emit_changed (GtkEntry *entry)
2718 GtkEditable *editable = GTK_EDITABLE (entry);
2719 GtkEntryPrivate *priv = entry->priv;
2721 if (priv->change_count == 0)
2722 g_signal_emit_by_name (editable, "changed");
2724 priv->real_changed = TRUE;
2728 gtk_entry_destroy (GtkWidget *widget)
2730 GtkEntry *entry = GTK_ENTRY (widget);
2731 GtkEntryPrivate *priv = entry->priv;
2733 priv->current_pos = priv->selection_bound = 0;
2734 gtk_entry_reset_im_context (entry);
2735 gtk_entry_reset_layout (entry);
2737 if (priv->blink_timeout)
2739 g_source_remove (priv->blink_timeout);
2740 priv->blink_timeout = 0;
2743 if (priv->recompute_idle)
2745 g_source_remove (priv->recompute_idle);
2746 priv->recompute_idle = 0;
2749 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2753 gtk_entry_dispose (GObject *object)
2755 GtkEntry *entry = GTK_ENTRY (object);
2756 GtkEntryPrivate *priv = entry->priv;
2759 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2760 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2761 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2762 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2763 gtk_entry_set_completion (entry, NULL);
2767 buffer_disconnect_signals (entry);
2768 g_object_unref (priv->buffer);
2769 priv->buffer = NULL;
2772 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2773 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2774 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2775 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2779 gtk_entry_finalize (GObject *object)
2781 GtkEntry *entry = GTK_ENTRY (object);
2782 GtkEntryPrivate *priv = entry->priv;
2783 EntryIconInfo *icon_info = NULL;
2786 for (i = 0; i < MAX_ICONS; i++)
2788 if ((icon_info = priv->icons[i]) != NULL)
2790 if (icon_info->target_list != NULL)
2792 gtk_target_list_unref (icon_info->target_list);
2793 icon_info->target_list = NULL;
2796 g_clear_object (&icon_info->icon_helper);
2798 g_slice_free (EntryIconInfo, icon_info);
2799 priv->icons[i] = NULL;
2803 if (priv->cached_layout)
2804 g_object_unref (priv->cached_layout);
2806 g_object_unref (priv->im_context);
2808 if (priv->blink_timeout)
2809 g_source_remove (priv->blink_timeout);
2811 if (priv->recompute_idle)
2812 g_source_remove (priv->recompute_idle);
2814 g_object_unref (priv->text_handle);
2815 g_free (priv->placeholder_text);
2816 g_free (priv->im_module);
2818 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2822 gtk_entry_get_display_mode (GtkEntry *entry)
2824 GtkEntryPrivate *priv = entry->priv;
2827 return DISPLAY_NORMAL;
2829 if (priv->invisible_char == 0 && priv->invisible_char_set)
2830 return DISPLAY_BLANK;
2832 return DISPLAY_INVISIBLE;
2836 _gtk_entry_get_display_text (GtkEntry *entry,
2840 GtkEntryPasswordHint *password_hint;
2841 GtkEntryPrivate *priv;
2842 gunichar invisible_char;
2853 text = gtk_entry_buffer_get_text (get_buffer (entry));
2854 length = gtk_entry_buffer_get_length (get_buffer (entry));
2858 if (start_pos > length)
2861 if (end_pos <= start_pos)
2862 return g_strdup ("");
2863 else if (priv->visible)
2865 start = g_utf8_offset_to_pointer (text, start_pos);
2866 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2867 return g_strndup (start, end - start);
2871 str = g_string_sized_new (length * 2);
2873 /* Figure out what our invisible char is and encode it */
2874 if (!priv->invisible_char)
2875 invisible_char = priv->invisible_char_set ? ' ' : '*';
2877 invisible_char = priv->invisible_char;
2878 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2881 * Add hidden characters for each character in the text
2882 * buffer. If there is a password hint, then keep that
2883 * character visible.
2886 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2887 for (i = start_pos; i < end_pos; ++i)
2889 if (password_hint && i == password_hint->position)
2891 start = g_utf8_offset_to_pointer (text, i);
2892 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2896 g_string_append_len (str, char_str, char_len);
2900 return g_string_free (str, FALSE);
2905 update_cursors (GtkWidget *widget)
2907 GtkEntry *entry = GTK_ENTRY (widget);
2908 GtkEntryPrivate *priv = entry->priv;
2909 EntryIconInfo *icon_info = NULL;
2910 GdkDisplay *display;
2914 for (i = 0; i < MAX_ICONS; i++)
2916 if ((icon_info = priv->icons[i]) != NULL)
2918 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2919 icon_info->window != NULL)
2920 gdk_window_show_unraised (icon_info->window);
2922 /* The icon windows are not children of the visible entry window,
2923 * thus we can't just inherit the xterm cursor. Slight complication
2924 * here is that for the entry, insensitive => arrow cursor, but for
2925 * an icon in a sensitive entry, insensitive => xterm cursor.
2927 if (gtk_widget_is_sensitive (widget) &&
2928 (icon_info->insensitive ||
2929 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2931 display = gtk_widget_get_display (widget);
2932 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2933 gdk_window_set_cursor (icon_info->window, cursor);
2934 g_object_unref (cursor);
2938 gdk_window_set_cursor (icon_info->window, NULL);
2945 realize_icon_info (GtkWidget *widget,
2946 GtkEntryIconPosition icon_pos)
2948 GtkEntry *entry = GTK_ENTRY (widget);
2949 GtkEntryPrivate *priv = entry->priv;
2950 EntryIconInfo *icon_info = priv->icons[icon_pos];
2951 GdkWindowAttr attributes;
2952 gint attributes_mask;
2954 g_return_if_fail (icon_info != NULL);
2958 attributes.width = 1;
2959 attributes.height = 1;
2960 attributes.window_type = GDK_WINDOW_CHILD;
2961 attributes.wclass = GDK_INPUT_ONLY;
2962 attributes.event_mask = gtk_widget_get_events (widget);
2963 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2964 GDK_BUTTON_RELEASE_MASK |
2965 GDK_BUTTON1_MOTION_MASK |
2966 GDK_BUTTON3_MOTION_MASK |
2967 GDK_POINTER_MOTION_HINT_MASK |
2968 GDK_POINTER_MOTION_MASK |
2969 GDK_ENTER_NOTIFY_MASK |
2970 GDK_LEAVE_NOTIFY_MASK);
2971 attributes_mask = GDK_WA_X | GDK_WA_Y;
2973 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2976 gtk_widget_register_window (widget, icon_info->window);
2978 gtk_widget_queue_resize (widget);
2981 static EntryIconInfo*
2982 construct_icon_info (GtkWidget *widget,
2983 GtkEntryIconPosition icon_pos)
2985 GtkEntry *entry = GTK_ENTRY (widget);
2986 GtkEntryPrivate *priv = entry->priv;
2987 EntryIconInfo *icon_info;
2989 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2991 icon_info = g_slice_new0 (EntryIconInfo);
2992 priv->icons[icon_pos] = icon_info;
2994 icon_info->icon_helper = _gtk_icon_helper_new ();
2995 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
2997 if (gtk_widget_get_realized (widget))
2998 realize_icon_info (widget, icon_pos);
3004 gtk_entry_map (GtkWidget *widget)
3006 GtkEntry *entry = GTK_ENTRY (widget);
3007 GtkEntryPrivate *priv = entry->priv;
3008 EntryIconInfo *icon_info = NULL;
3011 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
3013 gdk_window_show (priv->text_area);
3015 for (i = 0; i < MAX_ICONS; i++)
3017 if ((icon_info = priv->icons[i]) != NULL)
3019 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3020 icon_info->window != NULL)
3021 gdk_window_show (icon_info->window);
3025 update_cursors (widget);
3029 gtk_entry_unmap (GtkWidget *widget)
3031 GtkEntry *entry = GTK_ENTRY (widget);
3032 GtkEntryPrivate *priv = entry->priv;
3033 EntryIconInfo *icon_info = NULL;
3036 _gtk_text_handle_set_mode (priv->text_handle,
3037 GTK_TEXT_HANDLE_MODE_NONE);
3039 for (i = 0; i < MAX_ICONS; i++)
3041 if ((icon_info = priv->icons[i]) != NULL)
3043 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3044 icon_info->window != NULL)
3045 gdk_window_hide (icon_info->window);
3049 gdk_window_hide (priv->text_area);
3051 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
3055 gtk_entry_realize (GtkWidget *widget)
3058 GtkEntryPrivate *priv;
3059 EntryIconInfo *icon_info;
3061 GdkWindowAttr attributes;
3062 gint attributes_mask;
3063 gint frame_x, frame_y;
3066 gtk_widget_set_realized (widget, TRUE);
3067 window = gtk_widget_get_parent_window (widget);
3068 gtk_widget_set_window (widget, window);
3069 g_object_ref (window);
3071 entry = GTK_ENTRY (widget);
3074 attributes.window_type = GDK_WINDOW_CHILD;
3075 attributes.wclass = GDK_INPUT_ONLY;
3076 attributes.event_mask = gtk_widget_get_events (widget);
3077 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3078 GDK_BUTTON_RELEASE_MASK |
3079 GDK_BUTTON1_MOTION_MASK |
3080 GDK_BUTTON3_MOTION_MASK |
3081 GDK_POINTER_MOTION_HINT_MASK |
3082 GDK_POINTER_MOTION_MASK |
3083 GDK_ENTER_NOTIFY_MASK |
3084 GDK_LEAVE_NOTIFY_MASK);
3085 attributes_mask = GDK_WA_X | GDK_WA_Y;
3087 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3089 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3090 attributes.x += frame_x;
3091 attributes.y += frame_y;
3093 if (gtk_widget_is_sensitive (widget))
3095 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3096 attributes_mask |= GDK_WA_CURSOR;
3099 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3103 gtk_widget_register_window (widget, priv->text_area);
3105 if (attributes_mask & GDK_WA_CURSOR)
3106 g_object_unref (attributes.cursor);
3108 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3110 gtk_entry_adjust_scroll (entry);
3111 gtk_entry_update_primary_selection (entry);
3112 _gtk_text_handle_set_relative_to (priv->text_handle, priv->text_area);
3114 /* If the icon positions are already setup, create their windows.
3115 * Otherwise if they don't exist yet, then construct_icon_info()
3116 * will create the windows once the widget is already realized.
3118 for (i = 0; i < MAX_ICONS; i++)
3120 if ((icon_info = priv->icons[i]) != NULL)
3122 if (icon_info->window == NULL)
3123 realize_icon_info (widget, i);
3129 gtk_entry_unrealize (GtkWidget *widget)
3131 GtkEntry *entry = GTK_ENTRY (widget);
3132 GtkEntryPrivate *priv = entry->priv;
3133 GtkClipboard *clipboard;
3134 EntryIconInfo *icon_info;
3137 gtk_entry_reset_layout (entry);
3139 gtk_im_context_set_client_window (priv->im_context, NULL);
3140 _gtk_text_handle_set_relative_to (priv->text_handle, NULL);
3142 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3143 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3144 gtk_clipboard_clear (clipboard);
3146 if (priv->text_area)
3148 gtk_widget_unregister_window (widget, priv->text_area);
3149 gdk_window_destroy (priv->text_area);
3150 priv->text_area = NULL;
3153 if (priv->popup_menu)
3155 gtk_widget_destroy (priv->popup_menu);
3156 priv->popup_menu = NULL;
3159 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3161 for (i = 0; i < MAX_ICONS; i++)
3163 if ((icon_info = priv->icons[i]) != NULL)
3165 if (icon_info->window != NULL)
3167 gtk_widget_unregister_window (widget, icon_info->window);
3168 gdk_window_destroy (icon_info->window);
3169 icon_info->window = NULL;
3176 _gtk_entry_get_borders (GtkEntry *entry,
3177 GtkBorder *border_out)
3179 GtkEntryPrivate *priv = entry->priv;
3180 GtkWidget *widget = GTK_WIDGET (entry);
3181 GtkBorder tmp = { 0, 0, 0, 0 };
3182 GtkStyleContext *context;
3184 context = gtk_widget_get_style_context (widget);
3185 gtk_style_context_get_padding (context, 0, &tmp);
3187 if (priv->has_frame)
3191 gtk_style_context_get_border (context, 0, &border);
3192 tmp.top += border.top;
3193 tmp.right += border.right;
3194 tmp.bottom += border.bottom;
3195 tmp.left += border.left;
3198 if (!priv->interior_focus)
3200 tmp.top += priv->focus_width;
3201 tmp.right += priv->focus_width;
3202 tmp.bottom += priv->focus_width;
3203 tmp.left += priv->focus_width;
3206 if (border_out != NULL)
3211 gtk_entry_get_preferred_width (GtkWidget *widget,
3215 GtkEntry *entry = GTK_ENTRY (widget);
3216 GtkEntryPrivate *priv = entry->priv;
3217 PangoFontMetrics *metrics;
3219 PangoContext *context;
3220 gint icon_widths = 0;
3224 context = gtk_widget_get_pango_context (widget);
3226 metrics = pango_context_get_metrics (context,
3227 pango_context_get_font_description (context),
3228 pango_context_get_language (context));
3230 _gtk_entry_get_borders (entry, &borders);
3232 if (priv->width_chars < 0)
3233 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3236 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3237 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3238 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3240 width = char_pixels * priv->width_chars + borders.left + borders.right;
3243 for (i = 0; i < MAX_ICONS; i++)
3245 icon_width = get_icon_width (entry, i);
3247 icon_widths += icon_width;
3250 if (icon_widths > width)
3251 width += icon_widths;
3253 pango_font_metrics_unref (metrics);
3260 gtk_entry_get_preferred_height (GtkWidget *widget,
3264 GtkEntry *entry = GTK_ENTRY (widget);
3265 GtkEntryPrivate *priv = entry->priv;
3266 PangoFontMetrics *metrics;
3268 PangoContext *context;
3270 PangoLayout *layout;
3272 layout = gtk_entry_ensure_layout (entry, TRUE);
3273 context = gtk_widget_get_pango_context (widget);
3275 metrics = pango_context_get_metrics (context,
3276 pango_context_get_font_description (context),
3277 pango_context_get_language (context));
3279 priv->ascent = pango_font_metrics_get_ascent (metrics);
3280 priv->descent = pango_font_metrics_get_descent (metrics);
3281 pango_font_metrics_unref (metrics);
3283 _gtk_entry_get_borders (entry, &borders);
3284 pango_layout_get_pixel_size (layout, NULL, &height);
3286 height += borders.top + borders.bottom;
3293 place_windows (GtkEntry *entry)
3295 GtkWidget *widget = GTK_WIDGET (entry);
3296 GtkEntryPrivate *priv = entry->priv;
3297 gint x, y, width, height;
3298 gint frame_x, frame_y;
3299 GtkAllocation primary;
3300 GtkAllocation secondary;
3301 EntryIconInfo *icon_info = NULL;
3303 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3304 get_text_area_size (entry, &x, &y, &width, &height);
3305 get_icon_allocations (entry, &primary, &secondary);
3307 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3308 y += priv->focus_width;
3310 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3311 x += secondary.width;
3314 width -= primary.width + secondary.width;
3318 primary.x += frame_x;
3319 primary.y += frame_y;
3320 secondary.x += frame_x;
3321 secondary.y += frame_y;
3323 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3324 gdk_window_move_resize (icon_info->window,
3325 primary.x, primary.y,
3326 primary.width, primary.height);
3328 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3329 gdk_window_move_resize (icon_info->window,
3330 secondary.x, secondary.y,
3331 secondary.width, secondary.height);
3333 gdk_window_move_resize (priv->text_area, x, y, width, height);
3337 gtk_entry_get_text_area_size (GtkEntry *entry,
3343 GtkEntryPrivate *priv = entry->priv;
3344 GtkWidget *widget = GTK_WIDGET (entry);
3345 GtkAllocation allocation;
3346 GtkRequisition requisition;
3351 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3352 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3354 gtk_widget_get_allocation (widget, &allocation);
3355 _gtk_entry_get_borders (entry, &borders);
3357 if (gtk_widget_get_realized (widget))
3358 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3360 frame_height = req_height;
3362 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3363 frame_height -= 2 * priv->focus_width;
3369 *y = floor ((frame_height - req_height) / 2) + borders.top;
3372 *width = allocation.width - borders.left - borders.right;
3375 *height = req_height - borders.top - borders.bottom;
3379 get_text_area_size (GtkEntry *entry,
3385 GtkEntryClass *class;
3387 g_return_if_fail (GTK_IS_ENTRY (entry));
3389 class = GTK_ENTRY_GET_CLASS (entry);
3391 if (class->get_text_area_size)
3392 class->get_text_area_size (entry, x, y, width, height);
3397 gtk_entry_get_frame_size (GtkEntry *entry,
3403 GtkEntryPrivate *priv = entry->priv;
3404 GtkAllocation allocation;
3405 GtkRequisition requisition;
3406 GtkWidget *widget = GTK_WIDGET (entry);
3409 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3411 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3413 gtk_widget_get_allocation (widget, &allocation);
3420 if (priv->is_cell_renderer)
3423 *y = (allocation.height - req_height) / 2;
3429 *width = allocation.width;
3433 if (priv->is_cell_renderer)
3434 *height = allocation.height;
3436 *height = req_height;
3441 get_frame_size (GtkEntry *entry,
3442 gboolean relative_to_window,
3448 GtkEntryClass *class;
3449 GtkWidget *widget = GTK_WIDGET (entry);
3451 g_return_if_fail (GTK_IS_ENTRY (entry));
3453 class = GTK_ENTRY_GET_CLASS (entry);
3455 if (class->get_frame_size)
3456 class->get_frame_size (entry, x, y, width, height);
3458 if (!relative_to_window)
3460 GtkAllocation allocation;
3461 gtk_widget_get_allocation (widget, &allocation);
3471 gtk_entry_size_allocate (GtkWidget *widget,
3472 GtkAllocation *allocation)
3474 GtkEntry *entry = GTK_ENTRY (widget);
3476 gtk_widget_set_allocation (widget, allocation);
3478 if (gtk_widget_get_realized (widget))
3480 GtkEntryCompletion* completion;
3482 place_windows (entry);
3483 gtk_entry_recompute (entry);
3485 completion = gtk_entry_get_completion (entry);
3487 _gtk_entry_completion_resize_popup (completion);
3492 should_prelight (GtkEntry *entry,
3493 GtkEntryIconPosition icon_pos)
3495 GtkEntryPrivate *priv = entry->priv;
3496 EntryIconInfo *icon_info = priv->icons[icon_pos];
3502 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3505 if (icon_info->pressed)
3508 gtk_widget_style_get (GTK_WIDGET (entry),
3509 "icon-prelight", &prelight,
3516 draw_icon (GtkWidget *widget,
3518 GtkEntryIconPosition icon_pos)
3520 GtkEntry *entry = GTK_ENTRY (widget);
3521 GtkEntryPrivate *priv = entry->priv;
3522 EntryIconInfo *icon_info = priv->icons[icon_pos];
3523 gint x, y, width, height, pix_width, pix_height;
3524 GtkStyleContext *context;
3530 width = gdk_window_get_width (icon_info->window);
3531 height = gdk_window_get_height (icon_info->window);
3533 /* size_allocate hasn't been called yet. These are the default values.
3535 if (width == 1 || height == 1)
3539 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3541 context = gtk_widget_get_style_context (widget);
3542 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3543 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3544 &pix_width, &pix_height);
3545 gtk_style_context_get_padding (context, 0, &padding);
3547 x = MAX (0, padding.left);
3548 y = MAX (0, (height - pix_height) / 2);
3550 _gtk_icon_helper_draw (icon_info->icon_helper,
3554 gtk_style_context_restore (context);
3560 gtk_entry_draw_frame (GtkWidget *widget,
3561 GtkStyleContext *context,
3564 GtkEntry *entry = GTK_ENTRY (widget);
3565 GtkEntryPrivate *priv = entry->priv;
3566 gint x = 0, y = 0, width, height;
3567 gint frame_x, frame_y;
3571 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3573 cairo_translate (cr, frame_x, frame_y);
3575 /* Fix a problem with some themes which assume that entry->text_area's
3576 * width equals widget->window's width
3577 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3578 if (GTK_IS_SPIN_BUTTON (widget))
3582 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3583 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3586 width += borders.left + borders.right;
3589 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3591 x += priv->focus_width;
3592 y += priv->focus_width;
3593 width -= 2 * priv->focus_width;
3594 height -= 2 * priv->focus_width;
3597 gtk_render_background (context, cr,
3598 x, y, width, height);
3600 if (priv->has_frame)
3601 gtk_render_frame (context, cr,
3602 x, y, width, height);
3604 gtk_entry_draw_progress (widget, context, cr);
3606 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3608 x -= priv->focus_width;
3609 y -= priv->focus_width;
3610 width += 2 * priv->focus_width;
3611 height += 2 * priv->focus_width;
3613 gtk_render_focus (context, cr,
3614 0, 0, width, height);
3621 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3622 GtkStyleContext *context)
3624 GtkEntryPrivate *private = entry->priv;
3626 gtk_style_context_save (context);
3627 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3628 if (private->progress_pulse_mode)
3629 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3633 get_progress_area (GtkWidget *widget,
3639 GtkEntry *entry = GTK_ENTRY (widget);
3640 GtkEntryPrivate *private = entry->priv;
3641 GtkStyleContext *context;
3642 GtkBorder margin, border, entry_borders;
3643 gint frame_width, text_area_width, text_area_height;
3645 context = gtk_widget_get_style_context (widget);
3646 _gtk_entry_get_borders (entry, &entry_borders);
3647 get_text_area_size (entry,
3649 &text_area_width, &text_area_height);
3650 get_frame_size (entry, FALSE,
3652 &frame_width, NULL);
3656 *width = text_area_width + entry_borders.left + entry_borders.right;
3657 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3659 /* if the text area got resized by a subclass, subtract the left/right
3660 * border width, so that the progress bar won't extend over the resized
3663 if (frame_width > *width)
3665 gtk_style_context_get_border (context, 0, &border);
3666 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3668 *x = (frame_width - *width) + border.left;
3669 *width -= border.left;
3673 *width -= border.right;
3677 gtk_entry_prepare_context_for_progress (entry, context);
3678 gtk_style_context_get_margin (context, 0, &margin);
3680 gtk_style_context_restore (context);
3684 *width -= margin.left + margin.right;
3685 *height -= margin.top + margin.bottom;
3687 if (private->progress_pulse_mode)
3689 gdouble value = private->progress_pulse_current;
3691 *x += (gint) floor(value * (*width));
3692 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3694 else if (private->progress_fraction > 0)
3696 gdouble value = private->progress_fraction;
3698 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3702 bar_width = floor(value * (*width) + 0.5);
3703 *x += *width - bar_width;
3708 *width = (gint) floor(value * (*width) + 0.5);
3719 gtk_entry_draw_progress (GtkWidget *widget,
3720 GtkStyleContext *context,
3723 GtkEntry *entry = GTK_ENTRY (widget);
3724 gint x, y, width, height;
3726 get_progress_area (widget, &x, &y, &width, &height);
3728 if ((width <= 0) || (height <= 0))
3731 gtk_entry_prepare_context_for_progress (entry, context);
3732 gtk_render_activity (context, cr,
3733 x, y, width, height);
3735 gtk_style_context_restore (context);
3739 gtk_entry_draw (GtkWidget *widget,
3742 GtkEntry *entry = GTK_ENTRY (widget);
3743 GtkStyleContext *context;
3744 GtkEntryPrivate *priv = entry->priv;
3747 if (gtk_cairo_should_draw_window (cr,
3748 gtk_widget_get_window (widget)))
3750 context = gtk_widget_get_style_context (widget);
3752 /* Draw entry_bg, shadow, progress and focus */
3753 gtk_entry_draw_frame (widget, context, cr);
3755 /* Draw text and cursor */
3758 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3760 if (priv->dnd_position != -1)
3761 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3763 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3765 /* When no text is being displayed at all, don't show the cursor */
3766 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3767 gtk_widget_has_focus (widget) &&
3768 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3769 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3774 for (i = 0; i < MAX_ICONS; i++)
3776 EntryIconInfo *icon_info = priv->icons[i];
3778 if (icon_info != NULL)
3779 draw_icon (widget, cr, i);
3787 gtk_entry_enter_notify (GtkWidget *widget,
3788 GdkEventCrossing *event)
3790 GtkEntry *entry = GTK_ENTRY (widget);
3791 GtkEntryPrivate *priv = entry->priv;
3794 for (i = 0; i < MAX_ICONS; i++)
3796 EntryIconInfo *icon_info = priv->icons[i];
3798 if (icon_info != NULL && event->window == icon_info->window)
3800 if (should_prelight (entry, i))
3802 icon_info->prelight = TRUE;
3803 gtk_widget_queue_draw (widget);
3814 gtk_entry_leave_notify (GtkWidget *widget,
3815 GdkEventCrossing *event)
3817 GtkEntry *entry = GTK_ENTRY (widget);
3818 GtkEntryPrivate *priv = entry->priv;
3821 for (i = 0; i < MAX_ICONS; i++)
3823 EntryIconInfo *icon_info = priv->icons[i];
3825 if (icon_info != NULL && event->window == icon_info->window)
3827 /* a grab means that we may never see the button release */
3828 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3829 icon_info->pressed = FALSE;
3831 if (should_prelight (entry, i))
3833 icon_info->prelight = FALSE;
3834 gtk_widget_queue_draw (widget);
3845 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3849 gint start_char, end_char;
3851 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3853 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3854 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3855 const char *text = pango_layout_get_text (layout);
3856 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3857 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3858 gint real_n_ranges, i;
3860 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3866 for (i = 0; i < real_n_ranges; ++i)
3868 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3869 r[2 * i] = r[2 * i] / PANGO_SCALE;
3874 *n_ranges = real_n_ranges;
3886 in_selection (GtkEntry *entry,
3891 gint retval = FALSE;
3893 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3895 for (i = 0; i < n_ranges; ++i)
3897 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3909 gtk_entry_move_handle (GtkEntry *entry,
3910 GtkTextHandlePosition pos,
3915 GtkEntryPrivate *priv = entry->priv;
3917 if (!_gtk_text_handle_get_is_dragged (priv->text_handle, pos) &&
3918 (x < 0 || x > gdk_window_get_width (priv->text_area)))
3920 /* Hide the handle if it's not being manipulated
3921 * and fell outside of the visible text area.
3923 _gtk_text_handle_set_visible (priv->text_handle, pos, FALSE);
3929 rect.x = CLAMP (x, 0, gdk_window_get_width (priv->text_area));
3932 rect.height = height;
3934 _gtk_text_handle_set_visible (priv->text_handle, pos, TRUE);
3935 _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
3940 gtk_entry_get_selection_bound_location (GtkEntry *entry)
3942 GtkEntryPrivate *priv = entry->priv;
3943 PangoLayout *layout;
3949 layout = gtk_entry_ensure_layout (entry, FALSE);
3950 text = pango_layout_get_text (layout);
3951 index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text;
3952 pango_layout_index_to_pos (layout, index, &pos);
3954 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3955 x = (pos.x + pos.width) / PANGO_SCALE;
3957 x = pos.x / PANGO_SCALE;
3963 gtk_entry_update_handles (GtkEntry *entry,
3964 GtkTextHandleMode mode)
3966 GtkEntryPrivate *priv = entry->priv;
3967 gint strong_x, height;
3970 _gtk_text_handle_set_mode (priv->text_handle, mode);
3972 /* Wait for recomputation before repositioning */
3973 if (priv->recompute_idle != 0)
3976 height = gdk_window_get_height (priv->text_area);
3978 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
3979 cursor = strong_x - priv->scroll_offset;
3981 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
3985 bound = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
3987 if (priv->selection_bound > priv->current_pos)
3998 /* Update start selection bound */
3999 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_START,
4001 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_END,
4005 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_CURSOR,
4010 gtk_entry_button_press (GtkWidget *widget,
4011 GdkEventButton *event)
4013 GtkEntry *entry = GTK_ENTRY (widget);
4014 GtkEditable *editable = GTK_EDITABLE (widget);
4015 GtkEntryPrivate *priv = entry->priv;
4016 EntryIconInfo *icon_info = NULL;
4018 gint sel_start, sel_end;
4021 for (i = 0; i < MAX_ICONS; i++)
4023 icon_info = priv->icons[i];
4025 if (!icon_info || icon_info->insensitive)
4028 if (event->window == icon_info->window)
4030 if (should_prelight (entry, i))
4032 icon_info->prelight = FALSE;
4033 gtk_widget_queue_draw (widget);
4036 priv->start_x = event->x;
4037 priv->start_y = event->y;
4038 icon_info->pressed = TRUE;
4040 if (!icon_info->nonactivatable)
4041 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
4047 if (event->window != priv->text_area ||
4048 (priv->button && event->button != priv->button))
4051 gtk_entry_reset_blink_time (entry);
4053 priv->button = event->button;
4054 priv->device = gdk_event_get_device ((GdkEvent *) event);
4056 if (!gtk_widget_has_focus (widget))
4058 priv->in_click = TRUE;
4059 gtk_widget_grab_focus (widget);
4060 priv->in_click = FALSE;
4063 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4065 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
4067 gtk_entry_do_popup (entry, event);
4068 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
4069 priv->device = NULL;
4073 else if (event->button == GDK_BUTTON_PRIMARY)
4075 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
4076 gboolean is_touchscreen;
4079 source = gdk_event_get_source_device ((GdkEvent *) event);
4080 is_touchscreen = test_touchscreen ||
4081 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN;
4083 priv->select_words = FALSE;
4084 priv->select_lines = FALSE;
4087 gtk_widget_get_modifier_mask (widget,
4088 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
4090 gtk_entry_reset_im_context (entry);
4092 if (!have_selection) /* select from the current position to the clicked position */
4093 sel_start = sel_end = priv->current_pos;
4095 if (tmp_pos > sel_start && tmp_pos < sel_end)
4097 /* Truncate current selection, but keep it as big as possible */
4098 if (tmp_pos - sel_start > sel_end - tmp_pos)
4099 gtk_entry_set_positions (entry, sel_start, tmp_pos);
4101 gtk_entry_set_positions (entry, tmp_pos, sel_end);
4105 gboolean extend_to_left;
4108 /* Figure out what click selects and extend current selection */
4109 switch (event->type)
4111 case GDK_BUTTON_PRESS:
4112 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
4115 case GDK_2BUTTON_PRESS:
4116 priv->select_words = TRUE;
4117 gtk_entry_select_word (entry);
4120 case GDK_3BUTTON_PRESS:
4121 priv->select_lines = TRUE;
4122 gtk_entry_select_line (entry);
4129 start = MIN (priv->current_pos, priv->selection_bound);
4130 start = MIN (sel_start, start);
4132 end = MAX (priv->current_pos, priv->selection_bound);
4133 end = MAX (sel_end, end);
4135 if (tmp_pos == sel_start || tmp_pos == sel_end)
4136 extend_to_left = (tmp_pos == start);
4138 extend_to_left = (end == sel_end);
4141 gtk_entry_set_positions (entry, start, end);
4143 gtk_entry_set_positions (entry, end, start);
4146 else /* no shift key */
4147 switch (event->type)
4149 case GDK_BUTTON_PRESS:
4150 if (in_selection (entry, event->x + priv->scroll_offset))
4152 /* Click inside the selection - we'll either start a drag, or
4153 * clear the selection
4155 priv->in_drag = TRUE;
4156 priv->drag_start_x = event->x + priv->scroll_offset;
4157 priv->drag_start_y = event->y;
4161 gtk_editable_set_position (editable, tmp_pos);
4164 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4168 case GDK_2BUTTON_PRESS:
4169 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4170 * receiving a GDK_2BUTTON_PRESS so we need to reset
4171 * priv->in_drag which may have been set above
4173 priv->in_drag = FALSE;
4174 priv->select_words = TRUE;
4175 gtk_entry_select_word (entry);
4178 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4181 case GDK_3BUTTON_PRESS:
4182 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4183 * receiving a GDK_3BUTTON_PRESS so we need to reset
4184 * priv->in_drag which may have been set above
4186 priv->in_drag = FALSE;
4187 priv->select_lines = TRUE;
4188 gtk_entry_select_line (entry);
4190 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4199 else if (event->type == GDK_BUTTON_PRESS &&
4200 event->button == GDK_BUTTON_MIDDLE &&
4201 get_middle_click_paste (entry))
4205 priv->insert_pos = tmp_pos;
4206 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
4211 gtk_widget_error_bell (widget);
4219 gtk_entry_button_release (GtkWidget *widget,
4220 GdkEventButton *event)
4222 GtkEntry *entry = GTK_ENTRY (widget);
4223 GtkEntryPrivate *priv = entry->priv;
4224 EntryIconInfo *icon_info = NULL;
4227 for (i = 0; i < MAX_ICONS; i++)
4229 icon_info = priv->icons[i];
4231 if (!icon_info || icon_info->insensitive)
4234 if (event->window == icon_info->window)
4236 icon_info->pressed = FALSE;
4238 if (should_prelight (entry, i) &&
4239 event->x >= 0 && event->y >= 0 &&
4240 event->x < gdk_window_get_width (icon_info->window) &&
4241 event->y < gdk_window_get_height (icon_info->window))
4243 icon_info->prelight = TRUE;
4244 gtk_widget_queue_draw (widget);
4247 if (!icon_info->nonactivatable)
4248 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4254 if (event->window != priv->text_area || priv->button != event->button)
4259 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4262 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4264 source = gdk_event_get_source_device ((GdkEvent *) event);
4266 if (test_touchscreen ||
4267 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN)
4268 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4274 priv->device = NULL;
4276 gtk_entry_update_primary_selection (entry);
4282 _gtk_entry_get_selected_text (GtkEntry *entry)
4284 GtkEditable *editable = GTK_EDITABLE (entry);
4285 gint start_text, end_text;
4288 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4289 text = gtk_editable_get_chars (editable, start_text, end_text);
4295 gtk_entry_motion_notify (GtkWidget *widget,
4296 GdkEventMotion *event)
4298 GtkEntry *entry = GTK_ENTRY (widget);
4299 GtkEntryPrivate *priv = entry->priv;
4300 EntryIconInfo *icon_info = NULL;
4304 for (i = 0; i < MAX_ICONS; i++)
4306 icon_info = priv->icons[i];
4308 if (!icon_info || icon_info->insensitive)
4311 if (event->window == icon_info->window)
4313 if (icon_info->pressed &&
4314 icon_info->target_list != NULL &&
4315 gtk_drag_check_threshold (widget,
4321 icon_info->in_drag = TRUE;
4322 icon_info->pressed = FALSE;
4323 gtk_drag_begin (widget,
4324 icon_info->target_list,
4334 if (priv->mouse_cursor_obscured)
4338 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4339 gdk_window_set_cursor (priv->text_area, cursor);
4340 g_object_unref (cursor);
4341 priv->mouse_cursor_obscured = FALSE;
4344 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4347 if (priv->select_lines)
4350 gdk_event_request_motions (event);
4354 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4355 gtk_drag_check_threshold (widget,
4356 priv->drag_start_x, priv->drag_start_y,
4357 event->x + priv->scroll_offset, event->y))
4359 GdkDragContext *context;
4360 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4361 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4363 cairo_surface_t *surface;
4365 gtk_target_list_add_text_targets (target_list, 0);
4367 text = _gtk_entry_get_selected_text (entry);
4368 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4370 context = gtk_drag_begin (widget, target_list, actions,
4371 priv->button, (GdkEvent *)event);
4374 gtk_drag_set_icon_surface (context, surface);
4376 gtk_drag_set_icon_default (context);
4379 cairo_surface_destroy (surface);
4382 priv->in_drag = FALSE;
4384 priv->device = NULL;
4386 gtk_target_list_unref (target_list);
4391 GdkInputSource input_source;
4395 length = gtk_entry_buffer_get_length (get_buffer (entry));
4399 else if (event->y >= gdk_window_get_height (priv->text_area))
4402 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4404 source = gdk_event_get_source_device ((GdkEvent *) event);
4405 input_source = gdk_device_get_source (source);
4407 if (priv->select_words)
4410 gint old_min, old_max;
4413 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4414 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4416 pos = priv->current_pos;
4417 bound = priv->selection_bound;
4419 old_min = MIN(priv->current_pos, priv->selection_bound);
4420 old_max = MAX(priv->current_pos, priv->selection_bound);
4427 else if (old_max < max)
4432 else if (pos == old_min)
4434 if (priv->current_pos != min)
4439 if (priv->current_pos != max)
4443 gtk_entry_set_positions (entry, pos, bound);
4446 gtk_entry_set_positions (entry, tmp_pos, -1);
4448 /* Update touch handles' position */
4449 if (test_touchscreen || input_source == GDK_SOURCE_TOUCHSCREEN)
4450 gtk_entry_update_handles (entry,
4451 (priv->current_pos == priv->selection_bound) ?
4452 GTK_TEXT_HANDLE_MODE_CURSOR :
4453 GTK_TEXT_HANDLE_MODE_SELECTION);
4460 set_invisible_cursor (GdkWindow *window)
4462 GdkDisplay *display;
4465 display = gdk_window_get_display (window);
4466 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4468 gdk_window_set_cursor (window, cursor);
4470 g_object_unref (cursor);
4474 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4476 GtkEntryPrivate *priv = entry->priv;
4478 if (priv->mouse_cursor_obscured)
4481 set_invisible_cursor (priv->text_area);
4483 priv->mouse_cursor_obscured = TRUE;
4487 gtk_entry_key_press (GtkWidget *widget,
4490 GtkEntry *entry = GTK_ENTRY (widget);
4491 GtkEntryPrivate *priv = entry->priv;
4493 gtk_entry_reset_blink_time (entry);
4494 gtk_entry_pend_cursor_blink (entry);
4495 _gtk_text_handle_set_mode (priv->text_handle,
4496 GTK_TEXT_HANDLE_MODE_NONE);
4500 if (gtk_im_context_filter_keypress (priv->im_context, event))
4502 gtk_entry_obscure_mouse_cursor (entry);
4503 priv->need_im_reset = TRUE;
4508 if (event->keyval == GDK_KEY_Return ||
4509 event->keyval == GDK_KEY_KP_Enter ||
4510 event->keyval == GDK_KEY_ISO_Enter ||
4511 event->keyval == GDK_KEY_Escape)
4512 gtk_entry_reset_im_context (entry);
4514 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4515 /* Activate key bindings
4519 if (!priv->editable && event->length)
4520 gtk_widget_error_bell (widget);
4526 gtk_entry_key_release (GtkWidget *widget,
4529 GtkEntry *entry = GTK_ENTRY (widget);
4530 GtkEntryPrivate *priv = entry->priv;
4534 if (gtk_im_context_filter_keypress (priv->im_context, event))
4536 priv->need_im_reset = TRUE;
4541 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4545 gtk_entry_focus_in (GtkWidget *widget,
4546 GdkEventFocus *event)
4548 GtkEntry *entry = GTK_ENTRY (widget);
4549 GtkEntryPrivate *priv = entry->priv;
4552 gtk_widget_queue_draw (widget);
4554 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4558 priv->need_im_reset = TRUE;
4559 gtk_im_context_focus_in (priv->im_context);
4560 keymap_state_changed (keymap, entry);
4561 g_signal_connect (keymap, "state-changed",
4562 G_CALLBACK (keymap_state_changed), entry);
4565 g_signal_connect (keymap, "direction-changed",
4566 G_CALLBACK (keymap_direction_changed), entry);
4568 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4569 priv->placeholder_text != NULL)
4571 gtk_entry_recompute (entry);
4575 gtk_entry_reset_blink_time (entry);
4576 gtk_entry_check_cursor_blink (entry);
4583 gtk_entry_focus_out (GtkWidget *widget,
4584 GdkEventFocus *event)
4586 GtkEntry *entry = GTK_ENTRY (widget);
4587 GtkEntryPrivate *priv = entry->priv;
4588 GtkEntryCompletion *completion;
4591 _gtk_text_handle_set_mode (priv->text_handle,
4592 GTK_TEXT_HANDLE_MODE_NONE);
4594 gtk_widget_queue_draw (widget);
4596 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4600 priv->need_im_reset = TRUE;
4601 gtk_im_context_focus_out (priv->im_context);
4602 remove_capslock_feedback (entry);
4605 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4606 priv->placeholder_text != NULL)
4608 gtk_entry_recompute (entry);
4612 gtk_entry_check_cursor_blink (entry);
4615 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4616 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4618 completion = gtk_entry_get_completion (entry);
4620 _gtk_entry_completion_popdown (completion);
4626 gtk_entry_grab_focus (GtkWidget *widget)
4628 GtkEntry *entry = GTK_ENTRY (widget);
4629 GtkEntryPrivate *priv = entry->priv;
4630 gboolean select_on_focus;
4632 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4634 if (priv->editable && !priv->in_click)
4636 g_object_get (gtk_widget_get_settings (widget),
4637 "gtk-entry-select-on-focus",
4641 if (select_on_focus)
4642 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4647 gtk_entry_direction_changed (GtkWidget *widget,
4648 GtkTextDirection previous_dir)
4650 GtkEntry *entry = GTK_ENTRY (widget);
4652 gtk_entry_recompute (entry);
4654 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4658 gtk_entry_state_flags_changed (GtkWidget *widget,
4659 GtkStateFlags previous_state)
4661 GtkEntry *entry = GTK_ENTRY (widget);
4662 GtkEntryPrivate *priv = entry->priv;
4665 if (gtk_widget_get_realized (widget))
4667 if (gtk_widget_is_sensitive (widget))
4668 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4672 gdk_window_set_cursor (priv->text_area, cursor);
4675 g_object_unref (cursor);
4677 priv->mouse_cursor_obscured = FALSE;
4679 update_cursors (widget);
4682 if (!gtk_widget_is_sensitive (widget))
4684 /* Clear any selection */
4685 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4688 gtk_entry_update_cached_style_values (entry);
4692 gtk_entry_screen_changed (GtkWidget *widget,
4693 GdkScreen *old_screen)
4695 gtk_entry_recompute (GTK_ENTRY (widget));
4698 /* GtkEditable method implementations
4701 gtk_entry_insert_text (GtkEditable *editable,
4702 const gchar *new_text,
4703 gint new_text_length,
4706 g_object_ref (editable);
4709 * The incoming text may a password or other secret. We make sure
4710 * not to copy it into temporary buffers.
4713 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4715 g_object_unref (editable);
4719 gtk_entry_delete_text (GtkEditable *editable,
4723 g_object_ref (editable);
4725 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4727 g_object_unref (editable);
4731 gtk_entry_get_chars (GtkEditable *editable,
4735 GtkEntry *entry = GTK_ENTRY (editable);
4738 gint start_index, end_index;
4740 text = gtk_entry_buffer_get_text (get_buffer (entry));
4741 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4744 end_pos = text_length;
4746 start_pos = MIN (text_length, start_pos);
4747 end_pos = MIN (text_length, end_pos);
4749 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4750 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4752 return g_strndup (text + start_index, end_index - start_index);
4756 gtk_entry_real_set_position (GtkEditable *editable,
4759 GtkEntry *entry = GTK_ENTRY (editable);
4760 GtkEntryPrivate *priv = entry->priv;
4764 length = gtk_entry_buffer_get_length (get_buffer (entry));
4765 if (position < 0 || position > length)
4768 if (position != priv->current_pos ||
4769 position != priv->selection_bound)
4771 gtk_entry_reset_im_context (entry);
4772 gtk_entry_set_positions (entry, position, position);
4777 gtk_entry_get_position (GtkEditable *editable)
4779 GtkEntry *entry = GTK_ENTRY (editable);
4780 GtkEntryPrivate *priv = entry->priv;
4782 return priv->current_pos;
4786 gtk_entry_set_selection_bounds (GtkEditable *editable,
4790 GtkEntry *entry = GTK_ENTRY (editable);
4793 length = gtk_entry_buffer_get_length (get_buffer (entry));
4799 gtk_entry_reset_im_context (entry);
4801 gtk_entry_set_positions (entry,
4803 MIN (start, length));
4805 gtk_entry_update_primary_selection (entry);
4809 gtk_entry_get_selection_bounds (GtkEditable *editable,
4813 GtkEntry *entry = GTK_ENTRY (editable);
4814 GtkEntryPrivate *priv = entry->priv;
4816 *start = priv->selection_bound;
4817 *end = priv->current_pos;
4819 return (priv->selection_bound != priv->current_pos);
4823 icon_theme_changed (GtkEntry *entry)
4825 GtkEntryPrivate *priv = entry->priv;
4828 for (i = 0; i < MAX_ICONS; i++)
4830 EntryIconInfo *icon_info = priv->icons[i];
4831 if (icon_info != NULL)
4832 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4835 gtk_widget_queue_draw (GTK_WIDGET (entry));
4839 gtk_entry_update_cached_style_values (GtkEntry *entry)
4841 GtkEntryPrivate *priv = entry->priv;
4843 gboolean interior_focus;
4845 gtk_widget_style_get (GTK_WIDGET (entry),
4846 "focus-line-width", &focus_width,
4847 "interior-focus", &interior_focus,
4849 priv->focus_width = focus_width;
4850 priv->interior_focus = interior_focus;
4852 if (!priv->invisible_char_set)
4854 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4856 if (priv->invisible_char != ch)
4858 priv->invisible_char = ch;
4859 g_object_notify (G_OBJECT (entry), "invisible-char");
4865 gtk_entry_style_updated (GtkWidget *widget)
4867 GtkEntry *entry = GTK_ENTRY (widget);
4869 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4871 gtk_entry_update_cached_style_values (entry);
4873 icon_theme_changed (entry);
4876 /* GtkCellEditable method implementations
4879 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4881 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4882 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4886 gtk_cell_editable_key_press_event (GtkEntry *entry,
4887 GdkEventKey *key_event,
4890 GtkEntryPrivate *priv = entry->priv;
4892 if (key_event->keyval == GDK_KEY_Escape)
4894 priv->editing_canceled = TRUE;
4895 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4896 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4901 /* override focus */
4902 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4904 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4905 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4914 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4917 GtkEntry *entry = GTK_ENTRY (cell_editable);
4918 GtkEntryPrivate *priv = entry->priv;
4920 priv->is_cell_renderer = TRUE;
4922 g_signal_connect (cell_editable, "activate",
4923 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4924 g_signal_connect (cell_editable, "key-press-event",
4925 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4929 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4931 if (password_hint->source_id)
4932 g_source_remove (password_hint->source_id);
4934 g_slice_free (GtkEntryPasswordHint, password_hint);
4939 gtk_entry_remove_password_hint (gpointer data)
4941 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4942 password_hint->position = -1;
4944 /* Force the string to be redrawn, but now without a visible character */
4945 gtk_entry_recompute (GTK_ENTRY (data));
4949 /* Default signal handlers
4952 gtk_entry_real_insert_text (GtkEditable *editable,
4953 const gchar *new_text,
4954 gint new_text_length,
4960 n_chars = g_utf8_strlen (new_text, new_text_length);
4963 * The actual insertion into the buffer. This will end up firing the
4964 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4965 * buffer_notify_text(), buffer_notify_length()
4967 begin_change (GTK_ENTRY (editable));
4969 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4971 end_change (GTK_ENTRY (editable));
4973 if (n_inserted != n_chars)
4974 gtk_widget_error_bell (GTK_WIDGET (editable));
4976 *position += n_inserted;
4980 gtk_entry_real_delete_text (GtkEditable *editable,
4985 * The actual deletion from the buffer. This will end up firing the
4986 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4987 * buffer_notify_text(), buffer_notify_length()
4990 begin_change (GTK_ENTRY (editable));
4992 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4994 end_change (GTK_ENTRY (editable));
4997 /* GtkEntryBuffer signal handlers
5000 buffer_inserted_text (GtkEntryBuffer *buffer,
5006 GtkEntryPrivate *priv = entry->priv;
5007 guint password_hint_timeout;
5009 gint selection_bound;
5011 current_pos = priv->current_pos;
5012 if (current_pos > position)
5013 current_pos += n_chars;
5015 selection_bound = priv->selection_bound;
5016 if (selection_bound > position)
5017 selection_bound += n_chars;
5019 gtk_entry_set_positions (entry, current_pos, selection_bound);
5021 /* Calculate the password hint if it needs to be displayed. */
5022 if (n_chars == 1 && !priv->visible)
5024 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5025 "gtk-entry-password-hint-timeout", &password_hint_timeout,
5028 if (password_hint_timeout > 0)
5030 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5031 quark_password_hint);
5034 password_hint = g_slice_new0 (GtkEntryPasswordHint);
5035 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
5036 (GDestroyNotify)gtk_entry_password_hint_free);
5039 password_hint->position = position;
5040 if (password_hint->source_id)
5041 g_source_remove (password_hint->source_id);
5042 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
5043 (GSourceFunc)gtk_entry_remove_password_hint, entry);
5049 buffer_deleted_text (GtkEntryBuffer *buffer,
5054 GtkEntryPrivate *priv = entry->priv;
5055 guint end_pos = position + n_chars;
5056 gint selection_bound;
5059 current_pos = priv->current_pos;
5060 if (current_pos > position)
5061 current_pos -= MIN (current_pos, end_pos) - position;
5063 selection_bound = priv->selection_bound;
5064 if (selection_bound > position)
5065 selection_bound -= MIN (selection_bound, end_pos) - position;
5067 gtk_entry_set_positions (entry, current_pos, selection_bound);
5069 /* We might have deleted the selection */
5070 gtk_entry_update_primary_selection (entry);
5072 /* Disable the password hint if one exists. */
5075 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5076 quark_password_hint);
5079 if (password_hint->source_id)
5080 g_source_remove (password_hint->source_id);
5081 password_hint->source_id = 0;
5082 password_hint->position = -1;
5088 buffer_notify_text (GtkEntryBuffer *buffer,
5092 gtk_entry_recompute (entry);
5093 emit_changed (entry);
5094 g_object_notify (G_OBJECT (entry), "text");
5098 buffer_notify_length (GtkEntryBuffer *buffer,
5102 g_object_notify (G_OBJECT (entry), "text-length");
5106 buffer_notify_max_length (GtkEntryBuffer *buffer,
5110 g_object_notify (G_OBJECT (entry), "max-length");
5114 buffer_connect_signals (GtkEntry *entry)
5116 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
5117 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
5118 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
5119 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
5120 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
5124 buffer_disconnect_signals (GtkEntry *entry)
5126 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
5127 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
5128 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
5129 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
5130 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
5133 /* Compute the X position for an offset that corresponds to the "more important
5134 * cursor position for that offset. We use this when trying to guess to which
5135 * end of the selection we should go to when the user hits the left or
5139 get_better_cursor_x (GtkEntry *entry,
5142 GtkEntryPrivate *priv = entry->priv;
5143 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5144 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5145 gboolean split_cursor;
5147 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5148 const gchar *text = pango_layout_get_text (layout);
5149 gint index = g_utf8_offset_to_pointer (text, offset) - text;
5151 PangoRectangle strong_pos, weak_pos;
5153 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5154 "gtk-split-cursor", &split_cursor,
5157 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5160 return strong_pos.x / PANGO_SCALE;
5162 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
5166 gtk_entry_move_cursor (GtkEntry *entry,
5167 GtkMovementStep step,
5169 gboolean extend_selection)
5171 GtkEntryPrivate *priv = entry->priv;
5172 gint new_pos = priv->current_pos;
5174 gtk_entry_reset_im_context (entry);
5176 if (priv->current_pos != priv->selection_bound && !extend_selection)
5178 /* If we have a current selection and aren't extending it, move to the
5179 * start/or end of the selection as appropriate
5183 case GTK_MOVEMENT_VISUAL_POSITIONS:
5185 gint current_x = get_better_cursor_x (entry, priv->current_pos);
5186 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
5189 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
5191 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
5194 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5195 case GTK_MOVEMENT_WORDS:
5197 new_pos = MIN (priv->current_pos, priv->selection_bound);
5199 new_pos = MAX (priv->current_pos, priv->selection_bound);
5201 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5202 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5203 case GTK_MOVEMENT_BUFFER_ENDS:
5204 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5206 case GTK_MOVEMENT_DISPLAY_LINES:
5207 case GTK_MOVEMENT_PARAGRAPHS:
5208 case GTK_MOVEMENT_PAGES:
5209 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5217 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5218 new_pos = gtk_entry_move_logically (entry, new_pos, count);
5220 case GTK_MOVEMENT_VISUAL_POSITIONS:
5221 new_pos = gtk_entry_move_visually (entry, new_pos, count);
5222 if (priv->current_pos == new_pos)
5224 if (!extend_selection)
5226 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
5228 GTK_DIR_RIGHT : GTK_DIR_LEFT))
5230 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
5233 gtk_widget_child_focus (toplevel,
5235 GTK_DIR_RIGHT : GTK_DIR_LEFT);
5240 gtk_widget_error_bell (GTK_WIDGET (entry));
5244 case GTK_MOVEMENT_WORDS:
5247 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5252 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5255 if (priv->current_pos == new_pos)
5256 gtk_widget_error_bell (GTK_WIDGET (entry));
5258 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5259 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5260 case GTK_MOVEMENT_BUFFER_ENDS:
5261 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5262 if (priv->current_pos == new_pos)
5263 gtk_widget_error_bell (GTK_WIDGET (entry));
5265 case GTK_MOVEMENT_DISPLAY_LINES:
5266 case GTK_MOVEMENT_PARAGRAPHS:
5267 case GTK_MOVEMENT_PAGES:
5268 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5273 if (extend_selection)
5274 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5276 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5278 gtk_entry_pend_cursor_blink (entry);
5282 gtk_entry_insert_at_cursor (GtkEntry *entry,
5285 GtkEntryPrivate *priv = entry->priv;
5286 GtkEditable *editable = GTK_EDITABLE (entry);
5287 gint pos = priv->current_pos;
5291 gtk_entry_reset_im_context (entry);
5292 gtk_editable_insert_text (editable, str, -1, &pos);
5293 gtk_editable_set_position (editable, pos);
5298 gtk_entry_delete_from_cursor (GtkEntry *entry,
5302 GtkEntryPrivate *priv = entry->priv;
5303 GtkEditable *editable = GTK_EDITABLE (entry);
5304 gint start_pos = priv->current_pos;
5305 gint end_pos = priv->current_pos;
5306 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5308 gtk_entry_reset_im_context (entry);
5310 if (!priv->editable)
5312 gtk_widget_error_bell (GTK_WIDGET (entry));
5316 if (priv->selection_bound != priv->current_pos)
5318 gtk_editable_delete_selection (editable);
5324 case GTK_DELETE_CHARS:
5325 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5326 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5328 case GTK_DELETE_WORDS:
5331 /* Move to end of current word, or if not on a word, end of previous word */
5332 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5333 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5337 /* Move to beginning of current word, or if not on a word, begining of next word */
5338 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5339 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5343 case GTK_DELETE_WORD_ENDS:
5346 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5351 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5354 gtk_editable_delete_text (editable, start_pos, end_pos);
5356 case GTK_DELETE_DISPLAY_LINE_ENDS:
5357 case GTK_DELETE_PARAGRAPH_ENDS:
5359 gtk_editable_delete_text (editable, 0, priv->current_pos);
5361 gtk_editable_delete_text (editable, priv->current_pos, -1);
5363 case GTK_DELETE_DISPLAY_LINES:
5364 case GTK_DELETE_PARAGRAPHS:
5365 gtk_editable_delete_text (editable, 0, -1);
5367 case GTK_DELETE_WHITESPACE:
5368 gtk_entry_delete_whitespace (entry);
5372 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5373 gtk_widget_error_bell (GTK_WIDGET (entry));
5375 gtk_entry_pend_cursor_blink (entry);
5379 gtk_entry_backspace (GtkEntry *entry)
5381 GtkEntryPrivate *priv = entry->priv;
5382 GtkEditable *editable = GTK_EDITABLE (entry);
5385 gtk_entry_reset_im_context (entry);
5387 if (!priv->editable)
5389 gtk_widget_error_bell (GTK_WIDGET (entry));
5393 if (priv->selection_bound != priv->current_pos)
5395 gtk_editable_delete_selection (editable);
5399 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5401 if (prev_pos < priv->current_pos)
5403 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5404 PangoLogAttr *log_attrs;
5407 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5409 /* Deleting parts of characters */
5410 if (log_attrs[priv->current_pos].backspace_deletes_character)
5412 gchar *cluster_text;
5413 gchar *normalized_text;
5416 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5418 normalized_text = g_utf8_normalize (cluster_text,
5419 strlen (cluster_text),
5421 len = g_utf8_strlen (normalized_text, -1);
5423 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5426 gint pos = priv->current_pos;
5428 gtk_editable_insert_text (editable, normalized_text,
5429 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5431 gtk_editable_set_position (editable, pos);
5434 g_free (normalized_text);
5435 g_free (cluster_text);
5439 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5446 gtk_widget_error_bell (GTK_WIDGET (entry));
5449 gtk_entry_pend_cursor_blink (entry);
5453 gtk_entry_copy_clipboard (GtkEntry *entry)
5455 GtkEntryPrivate *priv = entry->priv;
5456 GtkEditable *editable = GTK_EDITABLE (entry);
5460 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5464 gtk_widget_error_bell (GTK_WIDGET (entry));
5468 str = _gtk_entry_get_display_text (entry, start, end);
5469 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5470 GDK_SELECTION_CLIPBOARD),
5477 gtk_entry_cut_clipboard (GtkEntry *entry)
5479 GtkEntryPrivate *priv = entry->priv;
5480 GtkEditable *editable = GTK_EDITABLE (entry);
5485 gtk_widget_error_bell (GTK_WIDGET (entry));
5489 gtk_entry_copy_clipboard (entry);
5493 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5494 gtk_editable_delete_text (editable, start, end);
5498 gtk_widget_error_bell (GTK_WIDGET (entry));
5503 gtk_entry_paste_clipboard (GtkEntry *entry)
5505 GtkEntryPrivate *priv = entry->priv;
5508 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5510 gtk_widget_error_bell (GTK_WIDGET (entry));
5514 gtk_entry_delete_cb (GtkEntry *entry)
5516 GtkEntryPrivate *priv = entry->priv;
5517 GtkEditable *editable = GTK_EDITABLE (entry);
5522 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5523 gtk_editable_delete_text (editable, start, end);
5528 gtk_entry_toggle_overwrite (GtkEntry *entry)
5530 GtkEntryPrivate *priv = entry->priv;
5532 priv->overwrite_mode = !priv->overwrite_mode;
5533 gtk_entry_pend_cursor_blink (entry);
5534 gtk_widget_queue_draw (GTK_WIDGET (entry));
5538 gtk_entry_select_all (GtkEntry *entry)
5540 gtk_entry_select_line (entry);
5544 gtk_entry_real_activate (GtkEntry *entry)
5546 GtkEntryPrivate *priv = entry->priv;
5548 GtkWidget *default_widget, *focus_widget;
5549 GtkWidget *toplevel;
5552 widget = GTK_WIDGET (entry);
5554 if (priv->activates_default)
5556 toplevel = gtk_widget_get_toplevel (widget);
5557 if (GTK_IS_WINDOW (toplevel))
5559 window = GTK_WINDOW (toplevel);
5563 default_widget = gtk_window_get_default_widget (window);
5564 focus_widget = gtk_window_get_focus (window);
5565 if (widget != default_widget &&
5566 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5567 gtk_window_activate_default (window);
5574 keymap_direction_changed (GdkKeymap *keymap,
5577 gtk_entry_recompute (entry);
5580 /* IM Context Callbacks
5584 gtk_entry_commit_cb (GtkIMContext *context,
5588 GtkEntryPrivate *priv = entry->priv;
5591 gtk_entry_enter_text (entry, str);
5595 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5598 GtkEntryPrivate *priv = entry->priv;
5602 gchar *preedit_string;
5605 gtk_im_context_get_preedit_string (priv->im_context,
5606 &preedit_string, NULL,
5608 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5609 priv->preedit_length = strlen (preedit_string);
5610 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5611 priv->preedit_cursor = cursor_pos;
5612 g_free (preedit_string);
5614 gtk_entry_recompute (entry);
5619 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5622 GtkEntryPrivate *priv = entry->priv;
5625 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5626 text = _gtk_entry_get_display_text (entry, 0, -1);
5627 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5628 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5635 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5640 GtkEntryPrivate *priv = entry->priv;
5643 gtk_editable_delete_text (GTK_EDITABLE (entry),
5644 priv->current_pos + offset,
5645 priv->current_pos + offset + n_chars);
5650 /* Internal functions
5653 /* Used for im_commit_cb and inserting Unicode chars */
5655 gtk_entry_enter_text (GtkEntry *entry,
5658 GtkEntryPrivate *priv = entry->priv;
5659 GtkEditable *editable = GTK_EDITABLE (entry);
5661 gboolean old_need_im_reset;
5663 old_need_im_reset = priv->need_im_reset;
5664 priv->need_im_reset = FALSE;
5666 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5667 gtk_editable_delete_selection (editable);
5670 if (priv->overwrite_mode)
5671 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5674 tmp_pos = priv->current_pos;
5675 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5676 gtk_editable_set_position (editable, tmp_pos);
5678 priv->need_im_reset = old_need_im_reset;
5681 /* All changes to priv->current_pos and priv->selection_bound
5682 * should go through this function.
5685 gtk_entry_set_positions (GtkEntry *entry,
5687 gint selection_bound)
5689 GtkEntryPrivate *priv = entry->priv;
5690 gboolean changed = FALSE;
5692 g_object_freeze_notify (G_OBJECT (entry));
5694 if (current_pos != -1 &&
5695 priv->current_pos != current_pos)
5697 priv->current_pos = current_pos;
5700 g_object_notify (G_OBJECT (entry), "cursor-position");
5703 if (selection_bound != -1 &&
5704 priv->selection_bound != selection_bound)
5706 priv->selection_bound = selection_bound;
5709 g_object_notify (G_OBJECT (entry), "selection-bound");
5712 g_object_thaw_notify (G_OBJECT (entry));
5716 gtk_entry_move_adjustments (entry);
5717 gtk_entry_recompute (entry);
5722 gtk_entry_reset_layout (GtkEntry *entry)
5724 GtkEntryPrivate *priv = entry->priv;
5726 if (priv->cached_layout)
5728 g_object_unref (priv->cached_layout);
5729 priv->cached_layout = NULL;
5734 update_im_cursor_location (GtkEntry *entry)
5736 GtkEntryPrivate *priv = entry->priv;
5739 gint strong_xoffset;
5740 gint area_width, area_height;
5742 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5743 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5745 strong_xoffset = strong_x - priv->scroll_offset;
5746 if (strong_xoffset < 0)
5750 else if (strong_xoffset > area_width)
5752 strong_xoffset = area_width;
5754 area.x = strong_xoffset;
5757 area.height = area_height;
5759 gtk_im_context_set_cursor_location (priv->im_context, &area);
5763 recompute_idle_func (gpointer data)
5765 GtkEntry *entry = GTK_ENTRY (data);
5766 GtkEntryPrivate *priv = entry->priv;
5768 priv->recompute_idle = 0;
5770 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5772 GtkTextHandleMode handle_mode;
5774 gtk_entry_adjust_scroll (entry);
5775 gtk_widget_queue_draw (GTK_WIDGET (entry));
5777 update_im_cursor_location (entry);
5779 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
5781 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
5782 gtk_entry_update_handles (entry, handle_mode);
5789 gtk_entry_recompute (GtkEntry *entry)
5791 GtkEntryPrivate *priv = entry->priv;
5793 gtk_entry_reset_layout (entry);
5794 gtk_entry_check_cursor_blink (entry);
5796 if (!priv->recompute_idle)
5798 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5799 recompute_idle_func, entry, NULL);
5804 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5807 GtkWidget *widget = GTK_WIDGET (entry);
5808 GtkStyleContext *context;
5809 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5811 context = gtk_widget_get_style_context (widget);
5812 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5814 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5815 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5816 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5819 static inline gboolean
5820 show_placeholder_text (GtkEntry *entry)
5822 GtkEntryPrivate *priv = entry->priv;
5824 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5825 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5826 priv->placeholder_text != NULL)
5832 static PangoLayout *
5833 gtk_entry_create_layout (GtkEntry *entry,
5834 gboolean include_preedit)
5836 GtkEntryPrivate *priv = entry->priv;
5837 GtkWidget *widget = GTK_WIDGET (entry);
5838 PangoLayout *layout;
5839 PangoAttrList *tmp_attrs;
5840 gboolean placeholder_layout;
5842 gchar *preedit_string = NULL;
5843 gint preedit_length = 0;
5844 PangoAttrList *preedit_attrs = NULL;
5849 layout = gtk_widget_create_pango_layout (widget, NULL);
5850 pango_layout_set_single_paragraph_mode (layout, TRUE);
5852 tmp_attrs = priv->attrs ? pango_attr_list_ref (priv->attrs)
5853 : pango_attr_list_new ();
5855 placeholder_layout = show_placeholder_text (entry);
5856 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5857 n_bytes = strlen (display);
5859 if (!placeholder_layout && include_preedit)
5861 gtk_im_context_get_preedit_string (priv->im_context,
5862 &preedit_string, &preedit_attrs, NULL);
5863 preedit_length = priv->preedit_length;
5865 else if (placeholder_layout)
5868 PangoAttribute *attr;
5870 gtk_entry_get_placeholder_text_color (entry, &color);
5871 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5872 attr->start_index = 0;
5873 attr->end_index = G_MAXINT;
5874 pango_attr_list_insert (tmp_attrs, attr);
5879 GString *tmp_string = g_string_new (display);
5880 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5882 g_string_insert (tmp_string, cursor_index, preedit_string);
5883 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5884 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5885 cursor_index, preedit_length);
5886 g_string_free (tmp_string, TRUE);
5890 PangoDirection pango_dir;
5892 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5893 pango_dir = pango_find_base_dir (display, n_bytes);
5895 pango_dir = PANGO_DIRECTION_NEUTRAL;
5897 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5899 if (gtk_widget_has_focus (widget))
5901 GdkDisplay *display = gtk_widget_get_display (widget);
5902 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5903 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5904 pango_dir = PANGO_DIRECTION_RTL;
5906 pango_dir = PANGO_DIRECTION_LTR;
5910 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5911 pango_dir = PANGO_DIRECTION_RTL;
5913 pango_dir = PANGO_DIRECTION_LTR;
5917 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5920 priv->resolved_dir = pango_dir;
5922 pango_layout_set_text (layout, display, n_bytes);
5925 pango_layout_set_attributes (layout, tmp_attrs);
5927 g_free (preedit_string);
5931 pango_attr_list_unref (preedit_attrs);
5933 pango_attr_list_unref (tmp_attrs);
5938 static PangoLayout *
5939 gtk_entry_ensure_layout (GtkEntry *entry,
5940 gboolean include_preedit)
5942 GtkEntryPrivate *priv = entry->priv;
5944 if (priv->preedit_length > 0 &&
5945 !include_preedit != !priv->cache_includes_preedit)
5946 gtk_entry_reset_layout (entry);
5948 if (!priv->cached_layout)
5950 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5951 priv->cache_includes_preedit = include_preedit;
5954 return priv->cached_layout;
5958 get_layout_position (GtkEntry *entry,
5962 GtkEntryPrivate *priv = entry->priv;
5963 PangoLayout *layout;
5964 PangoRectangle logical_rect;
5965 gint area_width, area_height;
5967 PangoLayoutLine *line;
5969 layout = gtk_entry_ensure_layout (entry, TRUE);
5971 get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5972 area_height = PANGO_SCALE * area_height;
5974 line = pango_layout_get_lines_readonly (layout)->data;
5975 pango_layout_line_get_extents (line, NULL, &logical_rect);
5977 /* Align primarily for locale's ascent/descent */
5978 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5979 priv->ascent + logical_rect.y);
5981 /* Now see if we need to adjust to fit in actual drawn string */
5982 if (logical_rect.height > area_height)
5983 y_pos = (area_height - logical_rect.height) / 2;
5986 else if (y_pos + logical_rect.height > area_height)
5987 y_pos = area_height - logical_rect.height;
5989 y_pos = y_pos / PANGO_SCALE;
5992 *x = - priv->scroll_offset;
5999 draw_text_with_color (GtkEntry *entry,
6001 GdkRGBA *default_color)
6003 GtkEntryPrivate *priv = entry->priv;
6004 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6007 gint start_pos, end_pos;
6009 widget = GTK_WIDGET (entry);
6013 get_layout_position (entry, &x, &y);
6015 cairo_move_to (cr, x, y);
6016 gdk_cairo_set_source_rgba (cr, default_color);
6017 pango_cairo_show_layout (cr, layout);
6019 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
6023 PangoRectangle logical_rect;
6024 GdkRGBA selection_color, text_color;
6025 GtkStyleContext *context;
6026 GtkStateFlags state;
6028 context = gtk_widget_get_style_context (widget);
6029 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
6030 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
6032 state = gtk_widget_get_state_flags (widget);
6033 state |= GTK_STATE_FLAG_SELECTED;
6035 gtk_style_context_get_background_color (context, state, &selection_color);
6036 gtk_style_context_get_color (context, state, &text_color);
6038 for (i = 0; i < n_ranges; ++i)
6039 cairo_rectangle (cr,
6040 - priv->scroll_offset + ranges[2 * i],
6043 logical_rect.height);
6047 gdk_cairo_set_source_rgba (cr, &selection_color);
6050 cairo_move_to (cr, x, y);
6051 gdk_cairo_set_source_rgba (cr, &text_color);
6052 pango_cairo_show_layout (cr, layout);
6060 gtk_entry_draw_text (GtkEntry *entry,
6063 GtkEntryPrivate *priv = entry->priv;
6064 GtkWidget *widget = GTK_WIDGET (entry);
6065 GtkStateFlags state = 0;
6066 GdkRGBA text_color, bar_text_color;
6067 GtkStyleContext *context;
6069 gint progress_x, progress_y, progress_width, progress_height;
6070 gint clip_width, clip_height;
6072 /* Nothing to display at all */
6073 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
6076 state = gtk_widget_get_state_flags (widget);
6077 context = gtk_widget_get_style_context (widget);
6079 gtk_style_context_get_color (context, state, &text_color);
6081 /* Get foreground color for progressbars */
6082 gtk_entry_prepare_context_for_progress (entry, context);
6083 gtk_style_context_get_color (context, state, &bar_text_color);
6084 gtk_style_context_restore (context);
6086 get_progress_area (widget,
6087 &progress_x, &progress_y,
6088 &progress_width, &progress_height);
6092 clip_width = gdk_window_get_width (priv->text_area);
6093 clip_height = gdk_window_get_height (priv->text_area);
6094 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
6097 /* If the color is the same, or the progress area has a zero
6098 * size, then we only need to draw once. */
6099 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
6100 ((progress_width == 0) || (progress_height == 0)))
6102 draw_text_with_color (entry, cr, &text_color);
6106 int frame_x, frame_y, area_x, area_y;
6108 width = gdk_window_get_width (priv->text_area);
6109 height = gdk_window_get_height (priv->text_area);
6113 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
6114 cairo_rectangle (cr, 0, 0, width, height);
6116 /* progres area is frame-relative, we need it text-area window
6118 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
6119 gdk_window_get_position (priv->text_area, &area_x, &area_y);
6120 progress_x += frame_x - area_x;
6121 progress_y += frame_y - area_y;
6123 cairo_rectangle (cr, progress_x, progress_y,
6124 progress_width, progress_height);
6126 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
6128 draw_text_with_color (entry, cr, &text_color);
6133 cairo_rectangle (cr, progress_x, progress_y,
6134 progress_width, progress_height);
6137 draw_text_with_color (entry, cr, &bar_text_color);
6146 gtk_entry_draw_cursor (GtkEntry *entry,
6150 GtkEntryPrivate *priv = entry->priv;
6151 GtkWidget *widget = GTK_WIDGET (entry);
6152 GtkStyleContext *context;
6153 PangoRectangle cursor_rect;
6156 gboolean block_at_line_end;
6157 PangoLayout *layout;
6161 context = gtk_widget_get_style_context (widget);
6163 layout = gtk_entry_ensure_layout (entry, TRUE);
6164 text = pango_layout_get_text (layout);
6165 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6166 get_layout_position (entry, &x, &y);
6168 if (!priv->overwrite_mode)
6171 block = _gtk_text_util_get_block_cursor_location (layout,
6172 cursor_index, &cursor_rect, &block_at_line_end);
6176 gtk_render_insertion_cursor (context, cr,
6178 layout, cursor_index, priv->resolved_dir);
6180 else /* overwrite_mode */
6182 GdkRGBA cursor_color;
6187 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
6188 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
6189 rect.width = PANGO_PIXELS (cursor_rect.width);
6190 rect.height = PANGO_PIXELS (cursor_rect.height);
6192 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
6193 gdk_cairo_set_source_rgba (cr, &cursor_color);
6194 gdk_cairo_rectangle (cr, &rect);
6197 if (!block_at_line_end)
6199 GtkStateFlags state;
6202 state = gtk_widget_get_state_flags (widget);
6203 gtk_style_context_get_background_color (context, state, &color);
6205 gdk_cairo_rectangle (cr, &rect);
6207 cairo_move_to (cr, x, y);
6208 gdk_cairo_set_source_rgba (cr, &color);
6209 pango_cairo_show_layout (cr, layout);
6217 gtk_entry_handle_dragged (GtkTextHandle *handle,
6218 GtkTextHandlePosition pos,
6223 gint cursor_pos, selection_bound_pos, tmp_pos;
6224 GtkEntryPrivate *priv = entry->priv;
6225 GtkTextHandleMode mode;
6228 cursor_pos = priv->current_pos;
6229 selection_bound_pos = priv->selection_bound;
6230 mode = _gtk_text_handle_get_mode (handle);
6231 tmp_pos = gtk_entry_find_position (entry, x + priv->scroll_offset);
6233 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR ||
6234 cursor_pos >= selection_bound_pos)
6237 min = &selection_bound_pos;
6241 max = &selection_bound_pos;
6245 if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
6247 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6251 min_pos = MAX (*min + 1, 0);
6252 tmp_pos = MAX (tmp_pos, min_pos);
6259 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6264 *min = MIN (tmp_pos, max_pos);
6268 if (cursor_pos != priv->current_pos ||
6269 selection_bound_pos != priv->selection_bound)
6271 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
6272 gtk_entry_set_positions (entry, cursor_pos, cursor_pos);
6274 gtk_entry_set_positions (entry, cursor_pos, selection_bound_pos);
6276 gtk_entry_update_handles (entry, mode);
6281 * gtk_entry_reset_im_context:
6282 * @entry: a #GtkEntry
6284 * Reset the input method context of the entry if needed.
6286 * This can be necessary in the case where modifying the buffer
6287 * would confuse on-going input method behavior.
6292 gtk_entry_reset_im_context (GtkEntry *entry)
6294 GtkEntryPrivate *priv = entry->priv;
6296 g_return_if_fail (GTK_IS_ENTRY (entry));
6298 if (priv->need_im_reset)
6300 priv->need_im_reset = FALSE;
6301 gtk_im_context_reset (priv->im_context);
6306 * gtk_entry_im_context_filter_keypress:
6307 * @entry: a #GtkEntry
6308 * @event: (type Gdk.EventKey): the key event
6310 * Allow the #GtkEntry input method to internally handle key press
6311 * and release events. If this function returns %TRUE, then no further
6312 * processing should be done for this key event. See
6313 * gtk_im_context_filter_keypress().
6315 * Note that you are expected to call this function from your handler
6316 * when overriding key event handling. This is needed in the case when
6317 * you need to insert your own key handling between the input method
6318 * and the default key event handling of the #GtkEntry.
6319 * See gtk_text_view_reset_im_context() for an example of use.
6321 * Return value: %TRUE if the input method handled the key event.
6326 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6329 GtkEntryPrivate *priv;
6331 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6335 return gtk_im_context_filter_keypress (priv->im_context, event);
6339 _gtk_entry_get_im_context (GtkEntry *entry)
6341 return entry->priv->im_context;
6345 gtk_entry_find_position (GtkEntry *entry,
6348 GtkEntryPrivate *priv = entry->priv;
6349 PangoLayout *layout;
6350 PangoLayoutLine *line;
6357 layout = gtk_entry_ensure_layout (entry, TRUE);
6358 text = pango_layout_get_text (layout);
6359 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6361 line = pango_layout_get_lines_readonly (layout)->data;
6362 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6364 if (index >= cursor_index && priv->preedit_length)
6366 if (index >= cursor_index + priv->preedit_length)
6367 index -= priv->preedit_length;
6370 index = cursor_index;
6375 pos = g_utf8_pointer_to_offset (text, text + index);
6382 gtk_entry_get_cursor_locations (GtkEntry *entry,
6387 GtkEntryPrivate *priv = entry->priv;
6388 DisplayMode mode = gtk_entry_get_display_mode (entry);
6390 /* Nothing to display at all, so no cursor is relevant */
6391 if (mode == DISPLAY_BLANK)
6401 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6402 const gchar *text = pango_layout_get_text (layout);
6403 PangoRectangle strong_pos, weak_pos;
6406 if (type == CURSOR_STANDARD)
6408 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6410 else /* type == CURSOR_DND */
6412 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6414 if (priv->dnd_position > priv->current_pos)
6416 if (mode == DISPLAY_NORMAL)
6417 index += priv->preedit_length;
6420 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6421 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6426 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6429 *strong_x = strong_pos.x / PANGO_SCALE;
6432 *weak_x = weak_pos.x / PANGO_SCALE;
6437 gtk_entry_get_is_selection_handle_dragged (GtkEntry *entry)
6439 GtkEntryPrivate *priv = entry->priv;
6440 GtkTextHandlePosition pos;
6442 if (_gtk_text_handle_get_mode (priv->text_handle) != GTK_TEXT_HANDLE_MODE_SELECTION)
6445 if (priv->current_pos >= priv->selection_bound)
6446 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
6448 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
6450 return _gtk_text_handle_get_is_dragged (priv->text_handle, pos);
6454 gtk_entry_adjust_scroll (GtkEntry *entry)
6456 GtkEntryPrivate *priv = entry->priv;
6457 gint min_offset, max_offset;
6458 gint text_area_width, text_width;
6459 gint strong_x, weak_x;
6460 gint strong_xoffset, weak_xoffset;
6462 PangoLayout *layout;
6463 PangoLayoutLine *line;
6464 PangoRectangle logical_rect;
6465 GtkTextHandleMode handle_mode;
6467 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6470 text_area_width = gdk_window_get_width (priv->text_area);
6472 if (text_area_width < 0)
6473 text_area_width = 0;
6475 layout = gtk_entry_ensure_layout (entry, TRUE);
6476 line = pango_layout_get_lines_readonly (layout)->data;
6478 pango_layout_line_get_extents (line, NULL, &logical_rect);
6480 /* Display as much text as we can */
6482 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6483 xalign = priv->xalign;
6485 xalign = 1.0 - priv->xalign;
6487 text_width = PANGO_PIXELS(logical_rect.width);
6489 if (text_width > text_area_width)
6492 max_offset = text_width - text_area_width;
6496 min_offset = (text_width - text_area_width) * xalign;
6497 max_offset = min_offset;
6500 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6502 if (gtk_entry_get_is_selection_handle_dragged (entry))
6504 /* The text handle corresponding to the selection bound is
6505 * being dragged, ensure it stays onscreen even if we scroll
6506 * cursors away, this is so both handles can cause content
6509 strong_x = weak_x = gtk_entry_get_selection_bound_location (entry);
6513 /* And make sure cursors are on screen. Note that the cursor is
6514 * actually drawn one pixel into the INNER_BORDER space on
6515 * the right, when the scroll is at the utmost right. This
6516 * looks better to to me than confining the cursor inside the
6517 * border entirely, though it means that the cursor gets one
6518 * pixel closer to the edge of the widget on the right than
6519 * on the left. This might need changing if one changed
6520 * INNER_BORDER from 2 to 1, as one would do on a
6521 * small-screen-real-estate display.
6523 * We always make sure that the strong cursor is on screen, and
6524 * put the weak cursor on screen if possible.
6526 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6529 strong_xoffset = strong_x - priv->scroll_offset;
6531 if (strong_xoffset < 0)
6533 priv->scroll_offset += strong_xoffset;
6536 else if (strong_xoffset > text_area_width)
6538 priv->scroll_offset += strong_xoffset - text_area_width;
6539 strong_xoffset = text_area_width;
6542 weak_xoffset = weak_x - priv->scroll_offset;
6544 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6546 priv->scroll_offset += weak_xoffset;
6548 else if (weak_xoffset > text_area_width &&
6549 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6551 priv->scroll_offset += weak_xoffset - text_area_width;
6554 g_object_notify (G_OBJECT (entry), "scroll-offset");
6556 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
6558 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
6559 gtk_entry_update_handles (entry, handle_mode);
6563 gtk_entry_move_adjustments (GtkEntry *entry)
6565 GtkWidget *widget = GTK_WIDGET (entry);
6566 GtkAllocation allocation;
6567 GtkAdjustment *adjustment;
6568 PangoContext *context;
6569 PangoFontMetrics *metrics;
6574 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6578 gtk_widget_get_allocation (widget, &allocation);
6580 /* Cursor/char position, layout offset, border width, and widget allocation */
6581 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6582 get_layout_position (entry, &layout_x, NULL);
6583 _gtk_entry_get_borders (entry, &borders);
6584 x += allocation.x + layout_x + borders.left;
6586 /* Approximate width of a char, so user can see what is ahead/behind */
6587 context = gtk_widget_get_pango_context (widget);
6589 metrics = pango_context_get_metrics (context,
6590 pango_context_get_font_description (context),
6591 pango_context_get_language (context));
6592 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6595 gtk_adjustment_clamp_page (adjustment,
6596 x - (char_width + 1), /* one char + one pixel before */
6597 x + (char_width + 2)); /* one char + cursor + one pixel after */
6601 gtk_entry_move_visually (GtkEntry *entry,
6605 GtkEntryPrivate *priv = entry->priv;
6607 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6610 text = pango_layout_get_text (layout);
6612 index = g_utf8_offset_to_pointer (text, start) - text;
6616 int new_index, new_trailing;
6617 gboolean split_cursor;
6620 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6621 "gtk-split-cursor", &split_cursor,
6628 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6629 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6631 strong = keymap_direction == priv->resolved_dir;
6636 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6641 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6647 else if (new_index != G_MAXINT)
6650 while (new_trailing--)
6651 index = g_utf8_next_char (text + index) - text;
6654 return g_utf8_pointer_to_offset (text, text + index);
6658 gtk_entry_move_logically (GtkEntry *entry,
6662 gint new_pos = start;
6665 length = gtk_entry_buffer_get_length (get_buffer (entry));
6667 /* Prevent any leak of information */
6668 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6670 new_pos = CLAMP (start + count, 0, length);
6674 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6675 PangoLogAttr *log_attrs;
6678 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6680 while (count > 0 && new_pos < length)
6684 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6688 while (count < 0 && new_pos > 0)
6692 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6704 gtk_entry_move_forward_word (GtkEntry *entry,
6706 gboolean allow_whitespace)
6708 gint new_pos = start;
6711 length = gtk_entry_buffer_get_length (get_buffer (entry));
6713 /* Prevent any leak of information */
6714 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6718 else if (new_pos < length)
6720 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6721 PangoLogAttr *log_attrs;
6724 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6726 /* Find the next word boundary */
6728 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6729 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6740 gtk_entry_move_backward_word (GtkEntry *entry,
6742 gboolean allow_whitespace)
6744 gint new_pos = start;
6746 /* Prevent any leak of information */
6747 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6753 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6754 PangoLogAttr *log_attrs;
6757 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6759 new_pos = start - 1;
6761 /* Find the previous word boundary */
6762 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6763 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6773 gtk_entry_delete_whitespace (GtkEntry *entry)
6775 GtkEntryPrivate *priv = entry->priv;
6776 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6777 PangoLogAttr *log_attrs;
6781 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6783 start = end = priv->current_pos;
6785 while (start > 0 && log_attrs[start-1].is_white)
6788 while (end < n_attrs && log_attrs[end].is_white)
6794 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6799 gtk_entry_select_word (GtkEntry *entry)
6801 GtkEntryPrivate *priv = entry->priv;
6802 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6803 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6805 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6809 gtk_entry_select_line (GtkEntry *entry)
6811 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6815 truncate_multiline (const gchar *text)
6820 text[length] && text[length] != '\n' && text[length] != '\r';
6827 paste_received (GtkClipboard *clipboard,
6831 GtkEntry *entry = GTK_ENTRY (data);
6832 GtkEditable *editable = GTK_EDITABLE (entry);
6833 GtkEntryPrivate *priv = entry->priv;
6835 if (priv->button == GDK_BUTTON_MIDDLE)
6837 gint pos, start, end;
6838 pos = priv->insert_pos;
6839 gtk_editable_get_selection_bounds (editable, &start, &end);
6840 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6841 gtk_editable_select_region (editable, pos, pos);
6846 gint pos, start, end;
6848 gboolean popup_completion;
6849 GtkEntryCompletion *completion;
6851 completion = gtk_entry_get_completion (entry);
6853 if (priv->truncate_multiline)
6854 length = truncate_multiline (text);
6856 /* only complete if the selection is at the end */
6857 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6858 MAX (priv->current_pos, priv->selection_bound));
6862 if (gtk_widget_get_mapped (completion->priv->popup_window))
6863 _gtk_entry_completion_popdown (completion);
6865 if (!popup_completion && completion->priv->changed_id > 0)
6866 g_signal_handler_block (entry, completion->priv->changed_id);
6869 begin_change (entry);
6870 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6871 gtk_editable_delete_text (editable, start, end);
6873 pos = priv->current_pos;
6874 gtk_editable_insert_text (editable, text, length, &pos);
6875 gtk_editable_set_position (editable, pos);
6879 !popup_completion && completion->priv->changed_id > 0)
6880 g_signal_handler_unblock (entry, completion->priv->changed_id);
6883 g_object_unref (entry);
6887 gtk_entry_paste (GtkEntry *entry,
6890 g_object_ref (entry);
6891 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6892 paste_received, entry);
6896 primary_get_cb (GtkClipboard *clipboard,
6897 GtkSelectionData *selection_data,
6901 GtkEntry *entry = GTK_ENTRY (data);
6904 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6906 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6907 gtk_selection_data_set_text (selection_data, str, -1);
6913 primary_clear_cb (GtkClipboard *clipboard,
6916 GtkEntry *entry = GTK_ENTRY (data);
6917 GtkEntryPrivate *priv = entry->priv;
6919 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6923 gtk_entry_update_primary_selection (GtkEntry *entry)
6925 GtkTargetList *list;
6926 GtkTargetEntry *targets;
6927 GtkClipboard *clipboard;
6931 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6934 list = gtk_target_list_new (NULL, 0);
6935 gtk_target_list_add_text_targets (list, 0);
6937 targets = gtk_target_table_new_from_list (list, &n_targets);
6939 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6941 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6943 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6944 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6945 primary_clear_cb (clipboard, entry);
6949 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6950 gtk_clipboard_clear (clipboard);
6953 gtk_target_table_free (targets, n_targets);
6954 gtk_target_list_unref (list);
6958 gtk_entry_clear (GtkEntry *entry,
6959 GtkEntryIconPosition icon_pos)
6961 GtkEntryPrivate *priv = entry->priv;
6962 EntryIconInfo *icon_info = priv->icons[icon_pos];
6963 GtkImageType storage_type;
6965 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6968 g_object_freeze_notify (G_OBJECT (entry));
6970 /* Explicitly check, as the pointer may become invalidated
6971 * during destruction.
6973 if (GDK_IS_WINDOW (icon_info->window))
6974 gdk_window_hide (icon_info->window);
6976 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6978 switch (storage_type)
6980 case GTK_IMAGE_PIXBUF:
6981 g_object_notify (G_OBJECT (entry),
6982 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6985 case GTK_IMAGE_STOCK:
6986 g_object_notify (G_OBJECT (entry),
6987 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6990 case GTK_IMAGE_ICON_NAME:
6991 g_object_notify (G_OBJECT (entry),
6992 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6995 case GTK_IMAGE_GICON:
6996 g_object_notify (G_OBJECT (entry),
6997 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
7001 g_assert_not_reached ();
7005 _gtk_icon_helper_clear (icon_info->icon_helper);
7007 g_object_notify (G_OBJECT (entry),
7008 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
7010 g_object_thaw_notify (G_OBJECT (entry));
7014 gtk_entry_ensure_pixbuf (GtkEntry *entry,
7015 GtkEntryIconPosition icon_pos)
7017 GtkEntryPrivate *priv = entry->priv;
7018 EntryIconInfo *icon_info = priv->icons[icon_pos];
7019 GtkStyleContext *context;
7022 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
7023 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
7025 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
7028 gtk_style_context_restore (context);
7039 * Creates a new entry.
7041 * Return value: a new #GtkEntry.
7044 gtk_entry_new (void)
7046 return g_object_new (GTK_TYPE_ENTRY, NULL);
7050 * gtk_entry_new_with_buffer:
7051 * @buffer: The buffer to use for the new #GtkEntry.
7053 * Creates a new entry with the specified text buffer.
7055 * Return value: a new #GtkEntry
7060 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
7062 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
7063 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
7066 static GtkEntryBuffer*
7067 get_buffer (GtkEntry *entry)
7069 GtkEntryPrivate *priv = entry->priv;
7071 if (priv->buffer == NULL)
7073 GtkEntryBuffer *buffer;
7074 buffer = gtk_entry_buffer_new (NULL, 0);
7075 gtk_entry_set_buffer (entry, buffer);
7076 g_object_unref (buffer);
7079 return priv->buffer;
7083 * gtk_entry_get_buffer:
7084 * @entry: a #GtkEntry
7086 * Get the #GtkEntryBuffer object which holds the text for
7091 * Returns: (transfer none): A #GtkEntryBuffer object.
7094 gtk_entry_get_buffer (GtkEntry *entry)
7096 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7098 return get_buffer (entry);
7102 * gtk_entry_set_buffer:
7103 * @entry: a #GtkEntry
7104 * @buffer: a #GtkEntryBuffer
7106 * Set the #GtkEntryBuffer object which holds the text for
7112 gtk_entry_set_buffer (GtkEntry *entry,
7113 GtkEntryBuffer *buffer)
7115 GtkEntryPrivate *priv;
7118 g_return_if_fail (GTK_IS_ENTRY (entry));
7124 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
7125 g_object_ref (buffer);
7130 buffer_disconnect_signals (entry);
7131 g_object_unref (priv->buffer);
7134 priv->buffer = buffer;
7137 buffer_connect_signals (entry);
7139 obj = G_OBJECT (entry);
7140 g_object_freeze_notify (obj);
7141 g_object_notify (obj, "buffer");
7142 g_object_notify (obj, "text");
7143 g_object_notify (obj, "text-length");
7144 g_object_notify (obj, "max-length");
7145 g_object_notify (obj, "visibility");
7146 g_object_notify (obj, "invisible-char");
7147 g_object_notify (obj, "invisible-char-set");
7148 g_object_thaw_notify (obj);
7150 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7151 gtk_entry_recompute (entry);
7155 * gtk_entry_get_text_area:
7156 * @entry: a #GtkEntry
7157 * @text_area: (out): Return location for the text area.
7159 * Gets the area where the entry's text is drawn. This function is
7160 * useful when drawing something to the entry in a draw callback.
7162 * If the entry is not realized, @text_area is filled with zeros.
7164 * See also gtk_entry_get_icon_area().
7169 gtk_entry_get_text_area (GtkEntry *entry,
7170 GdkRectangle *text_area)
7172 GtkEntryPrivate *priv;
7174 g_return_if_fail (GTK_IS_ENTRY (entry));
7175 g_return_if_fail (text_area != NULL);
7179 if (priv->text_area)
7181 GtkAllocation allocation;
7184 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7185 gdk_window_get_position (priv->text_area, &x, &y);
7187 text_area->x = x - allocation.x;
7188 text_area->y = y - allocation.y;
7189 text_area->width = gdk_window_get_width (priv->text_area);
7190 text_area->height = gdk_window_get_height (priv->text_area);
7196 text_area->width = 0;
7197 text_area->height = 0;
7202 * gtk_entry_set_text:
7203 * @entry: a #GtkEntry
7204 * @text: the new text
7206 * Sets the text in the widget to the given
7207 * value, replacing the current contents.
7209 * See gtk_entry_buffer_set_text().
7212 gtk_entry_set_text (GtkEntry *entry,
7216 GtkEntryCompletion *completion;
7218 g_return_if_fail (GTK_IS_ENTRY (entry));
7219 g_return_if_fail (text != NULL);
7221 /* Actually setting the text will affect the cursor and selection;
7222 * if the contents don't actually change, this will look odd to the user.
7224 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7227 completion = gtk_entry_get_completion (entry);
7228 if (completion && completion->priv->changed_id > 0)
7229 g_signal_handler_block (entry, completion->priv->changed_id);
7231 begin_change (entry);
7232 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7234 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7237 if (completion && completion->priv->changed_id > 0)
7238 g_signal_handler_unblock (entry, completion->priv->changed_id);
7242 * gtk_entry_set_visibility:
7243 * @entry: a #GtkEntry
7244 * @visible: %TRUE if the contents of the entry are displayed
7247 * Sets whether the contents of the entry are visible or not.
7248 * When visibility is set to %FALSE, characters are displayed
7249 * as the invisible char, and will also appear that way when
7250 * the text in the entry widget is copied elsewhere.
7252 * By default, GTK+ picks the best invisible character available
7253 * in the current font, but it can be changed with
7254 * gtk_entry_set_invisible_char().
7256 * Note that you probably want to set #GtkEntry:input-purpose
7257 * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
7258 * inform input methods about the purpose of this entry,
7259 * in addition to setting visibility to %FALSE.
7262 gtk_entry_set_visibility (GtkEntry *entry,
7265 GtkEntryPrivate *priv;
7267 g_return_if_fail (GTK_IS_ENTRY (entry));
7271 visible = visible != FALSE;
7273 if (priv->visible != visible)
7275 priv->visible = visible;
7277 g_object_notify (G_OBJECT (entry), "visibility");
7278 gtk_entry_recompute (entry);
7283 * gtk_entry_get_visibility:
7284 * @entry: a #GtkEntry
7286 * Retrieves whether the text in @entry is visible. See
7287 * gtk_entry_set_visibility().
7289 * Return value: %TRUE if the text is currently visible
7292 gtk_entry_get_visibility (GtkEntry *entry)
7294 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7296 return entry->priv->visible;
7300 * gtk_entry_set_invisible_char:
7301 * @entry: a #GtkEntry
7302 * @ch: a Unicode character
7304 * Sets the character to use in place of the actual text when
7305 * gtk_entry_set_visibility() has been called to set text visibility
7306 * to %FALSE. i.e. this is the character used in "password mode" to
7307 * show the user how many characters have been typed. By default, GTK+
7308 * picks the best invisible char available in the current font. If you
7309 * set the invisible char to 0, then the user will get no feedback
7310 * at all; there will be no text on the screen as they type.
7313 gtk_entry_set_invisible_char (GtkEntry *entry,
7316 GtkEntryPrivate *priv;
7318 g_return_if_fail (GTK_IS_ENTRY (entry));
7322 if (!priv->invisible_char_set)
7324 priv->invisible_char_set = TRUE;
7325 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7328 if (ch == priv->invisible_char)
7331 priv->invisible_char = ch;
7332 g_object_notify (G_OBJECT (entry), "invisible-char");
7333 gtk_entry_recompute (entry);
7337 * gtk_entry_get_invisible_char:
7338 * @entry: a #GtkEntry
7340 * Retrieves the character displayed in place of the real characters
7341 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7343 * Return value: the current invisible char, or 0, if the entry does not
7344 * show invisible text at all.
7347 gtk_entry_get_invisible_char (GtkEntry *entry)
7349 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7351 return entry->priv->invisible_char;
7355 * gtk_entry_unset_invisible_char:
7356 * @entry: a #GtkEntry
7358 * Unsets the invisible char previously set with
7359 * gtk_entry_set_invisible_char(). So that the
7360 * default invisible char is used again.
7365 gtk_entry_unset_invisible_char (GtkEntry *entry)
7367 GtkEntryPrivate *priv;
7370 g_return_if_fail (GTK_IS_ENTRY (entry));
7374 if (!priv->invisible_char_set)
7377 priv->invisible_char_set = FALSE;
7378 ch = find_invisible_char (GTK_WIDGET (entry));
7380 if (priv->invisible_char != ch)
7382 priv->invisible_char = ch;
7383 g_object_notify (G_OBJECT (entry), "invisible-char");
7386 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7387 gtk_entry_recompute (entry);
7391 * gtk_entry_set_overwrite_mode:
7392 * @entry: a #GtkEntry
7393 * @overwrite: new value
7395 * Sets whether the text is overwritten when typing in the #GtkEntry.
7400 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7403 GtkEntryPrivate *priv = entry->priv;
7405 g_return_if_fail (GTK_IS_ENTRY (entry));
7407 if (priv->overwrite_mode == overwrite)
7410 gtk_entry_toggle_overwrite (entry);
7412 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7416 * gtk_entry_get_overwrite_mode:
7417 * @entry: a #GtkEntry
7419 * Gets the value set by gtk_entry_set_overwrite_mode().
7421 * Return value: whether the text is overwritten when typing.
7426 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7428 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7430 return entry->priv->overwrite_mode;
7434 * gtk_entry_get_text:
7435 * @entry: a #GtkEntry
7437 * Retrieves the contents of the entry widget.
7438 * See also gtk_editable_get_chars().
7440 * This is equivalent to:
7442 * <informalexample><programlisting>
7443 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7444 * </programlisting></informalexample>
7446 * Return value: a pointer to the contents of the widget as a
7447 * string. This string points to internally allocated
7448 * storage in the widget and must not be freed, modified or
7452 gtk_entry_get_text (GtkEntry *entry)
7454 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7456 return gtk_entry_buffer_get_text (get_buffer (entry));
7460 * gtk_entry_set_max_length:
7461 * @entry: a #GtkEntry
7462 * @max: the maximum length of the entry, or 0 for no maximum.
7463 * (other than the maximum length of entries.) The value passed in will
7464 * be clamped to the range 0-65536.
7466 * Sets the maximum allowed length of the contents of the widget. If
7467 * the current contents are longer than the given length, then they
7468 * will be truncated to fit.
7470 * This is equivalent to:
7472 * <informalexample><programlisting>
7473 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7474 * </programlisting></informalexample>
7477 gtk_entry_set_max_length (GtkEntry *entry,
7480 g_return_if_fail (GTK_IS_ENTRY (entry));
7481 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7485 * gtk_entry_get_max_length:
7486 * @entry: a #GtkEntry
7488 * Retrieves the maximum allowed length of the text in
7489 * @entry. See gtk_entry_set_max_length().
7491 * This is equivalent to:
7493 * <informalexample><programlisting>
7494 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7495 * </programlisting></informalexample>
7497 * Return value: the maximum allowed number of characters
7498 * in #GtkEntry, or 0 if there is no maximum.
7501 gtk_entry_get_max_length (GtkEntry *entry)
7503 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7505 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7509 * gtk_entry_get_text_length:
7510 * @entry: a #GtkEntry
7512 * Retrieves the current length of the text in
7515 * This is equivalent to:
7517 * <informalexample><programlisting>
7518 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7519 * </programlisting></informalexample>
7521 * Return value: the current number of characters
7522 * in #GtkEntry, or 0 if there are none.
7527 gtk_entry_get_text_length (GtkEntry *entry)
7529 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7531 return gtk_entry_buffer_get_length (get_buffer (entry));
7535 * gtk_entry_set_activates_default:
7536 * @entry: a #GtkEntry
7537 * @setting: %TRUE to activate window's default widget on Enter keypress
7539 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7540 * widget for the window containing the entry. This usually means that
7541 * the dialog box containing the entry will be closed, since the default
7542 * widget is usually one of the dialog buttons.
7544 * (For experts: if @setting is %TRUE, the entry calls
7545 * gtk_window_activate_default() on the window containing the entry, in
7546 * the default handler for the #GtkEntry::activate signal.)
7549 gtk_entry_set_activates_default (GtkEntry *entry,
7552 GtkEntryPrivate *priv;
7554 g_return_if_fail (GTK_IS_ENTRY (entry));
7558 setting = setting != FALSE;
7560 if (setting != priv->activates_default)
7562 priv->activates_default = setting;
7563 g_object_notify (G_OBJECT (entry), "activates-default");
7568 * gtk_entry_get_activates_default:
7569 * @entry: a #GtkEntry
7571 * Retrieves the value set by gtk_entry_set_activates_default().
7573 * Return value: %TRUE if the entry will activate the default widget
7576 gtk_entry_get_activates_default (GtkEntry *entry)
7578 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7580 return entry->priv->activates_default;
7584 * gtk_entry_set_width_chars:
7585 * @entry: a #GtkEntry
7586 * @n_chars: width in chars
7588 * Changes the size request of the entry to be about the right size
7589 * for @n_chars characters. Note that it changes the size
7590 * <emphasis>request</emphasis>, the size can still be affected by
7591 * how you pack the widget into containers. If @n_chars is -1, the
7592 * size reverts to the default entry size.
7595 gtk_entry_set_width_chars (GtkEntry *entry,
7598 GtkEntryPrivate *priv;
7600 g_return_if_fail (GTK_IS_ENTRY (entry));
7604 if (priv->width_chars != n_chars)
7606 priv->width_chars = n_chars;
7607 g_object_notify (G_OBJECT (entry), "width-chars");
7608 gtk_widget_queue_resize (GTK_WIDGET (entry));
7613 * gtk_entry_get_width_chars:
7614 * @entry: a #GtkEntry
7616 * Gets the value set by gtk_entry_set_width_chars().
7618 * Return value: number of chars to request space for, or negative if unset
7621 gtk_entry_get_width_chars (GtkEntry *entry)
7623 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7625 return entry->priv->width_chars;
7629 * gtk_entry_set_has_frame:
7630 * @entry: a #GtkEntry
7631 * @setting: new value
7633 * Sets whether the entry has a beveled frame around it.
7636 gtk_entry_set_has_frame (GtkEntry *entry,
7639 GtkEntryPrivate *priv;
7641 g_return_if_fail (GTK_IS_ENTRY (entry));
7645 setting = (setting != FALSE);
7647 if (priv->has_frame == setting)
7650 gtk_widget_queue_resize (GTK_WIDGET (entry));
7651 priv->has_frame = setting;
7652 g_object_notify (G_OBJECT (entry), "has-frame");
7656 * gtk_entry_get_has_frame:
7657 * @entry: a #GtkEntry
7659 * Gets the value set by gtk_entry_set_has_frame().
7661 * Return value: whether the entry has a beveled frame
7664 gtk_entry_get_has_frame (GtkEntry *entry)
7666 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7668 return entry->priv->has_frame;
7672 * gtk_entry_set_inner_border:
7673 * @entry: a #GtkEntry
7674 * @border: (allow-none): a #GtkBorder, or %NULL
7676 * Sets %entry's inner-border property to %border, or clears it if %NULL
7677 * is passed. The inner-border is the area around the entry's text, but
7680 * If set, this property overrides the inner-border style property.
7681 * Overriding the style-provided border is useful when you want to do
7682 * in-place editing of some text in a canvas or list widget, where
7683 * pixel-exact positioning of the entry is important.
7687 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7688 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7689 * this function is ignored by #GtkEntry.
7692 gtk_entry_set_inner_border (GtkEntry *entry,
7693 const GtkBorder *border)
7695 g_return_if_fail (GTK_IS_ENTRY (entry));
7697 gtk_entry_do_set_inner_border (entry, border);
7701 * gtk_entry_get_inner_border:
7702 * @entry: a #GtkEntry
7704 * This function returns the entry's #GtkEntry:inner-border property. See
7705 * gtk_entry_set_inner_border() for more information.
7707 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7711 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7712 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7713 * this function is ignored by #GtkEntry.
7716 gtk_entry_get_inner_border (GtkEntry *entry)
7718 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7720 return gtk_entry_do_get_inner_border (entry);
7724 * gtk_entry_get_layout:
7725 * @entry: a #GtkEntry
7727 * Gets the #PangoLayout used to display the entry.
7728 * The layout is useful to e.g. convert text positions to
7729 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7730 * The returned layout is owned by the entry and must not be
7731 * modified or freed by the caller.
7733 * Keep in mind that the layout text may contain a preedit string, so
7734 * gtk_entry_layout_index_to_text_index() and
7735 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7736 * indices in the layout to byte indices in the entry contents.
7738 * Return value: (transfer none): the #PangoLayout for this entry
7741 gtk_entry_get_layout (GtkEntry *entry)
7743 PangoLayout *layout;
7745 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7747 layout = gtk_entry_ensure_layout (entry, TRUE);
7754 * gtk_entry_layout_index_to_text_index:
7755 * @entry: a #GtkEntry
7756 * @layout_index: byte index into the entry layout text
7758 * Converts from a position in the entry contents (returned
7759 * by gtk_entry_get_text()) to a position in the
7760 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7761 * with text retrieved via pango_layout_get_text()).
7763 * Return value: byte index into the entry contents
7766 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7769 GtkEntryPrivate *priv;
7770 PangoLayout *layout;
7774 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7778 layout = gtk_entry_ensure_layout (entry, TRUE);
7779 text = pango_layout_get_text (layout);
7780 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7782 if (layout_index >= cursor_index && priv->preedit_length)
7784 if (layout_index >= cursor_index + priv->preedit_length)
7785 layout_index -= priv->preedit_length;
7787 layout_index = cursor_index;
7790 return layout_index;
7794 * gtk_entry_text_index_to_layout_index:
7795 * @entry: a #GtkEntry
7796 * @text_index: byte index into the entry contents
7798 * Converts from a position in the entry's #PangoLayout (returned by
7799 * gtk_entry_get_layout()) to a position in the entry contents
7800 * (returned by gtk_entry_get_text()).
7802 * Return value: byte index into the entry layout text
7805 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7808 GtkEntryPrivate *priv;
7809 PangoLayout *layout;
7813 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7817 layout = gtk_entry_ensure_layout (entry, TRUE);
7818 text = pango_layout_get_text (layout);
7819 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7821 if (text_index > cursor_index)
7822 text_index += priv->preedit_length;
7828 * gtk_entry_get_layout_offsets:
7829 * @entry: a #GtkEntry
7830 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7831 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7834 * Obtains the position of the #PangoLayout used to render text
7835 * in the entry, in widget coordinates. Useful if you want to line
7836 * up the text in an entry with some other text, e.g. when using the
7837 * entry to implement editable cells in a sheet widget.
7839 * Also useful to convert mouse events into coordinates inside the
7840 * #PangoLayout, e.g. to take some action if some part of the entry text
7843 * Note that as the user scrolls around in the entry the offsets will
7844 * change; you'll need to connect to the "notify::scroll-offset"
7845 * signal to track this. Remember when using the #PangoLayout
7846 * functions you need to convert to and from pixels using
7847 * PANGO_PIXELS() or #PANGO_SCALE.
7849 * Keep in mind that the layout text may contain a preedit string, so
7850 * gtk_entry_layout_index_to_text_index() and
7851 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7852 * indices in the layout to byte indices in the entry contents.
7855 gtk_entry_get_layout_offsets (GtkEntry *entry,
7859 gint text_area_x, text_area_y;
7861 g_return_if_fail (GTK_IS_ENTRY (entry));
7863 /* this gets coords relative to text area */
7864 get_layout_position (entry, x, y);
7866 /* convert to widget coords */
7867 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7878 * gtk_entry_set_alignment:
7879 * @entry: a #GtkEntry
7880 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7881 * Reversed for RTL layouts
7883 * Sets the alignment for the contents of the entry. This controls
7884 * the horizontal positioning of the contents when the displayed
7885 * text is shorter than the width of the entry.
7890 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7892 GtkEntryPrivate *priv;
7894 g_return_if_fail (GTK_IS_ENTRY (entry));
7900 else if (xalign > 1.0)
7903 if (xalign != priv->xalign)
7905 priv->xalign = xalign;
7907 gtk_entry_recompute (entry);
7909 g_object_notify (G_OBJECT (entry), "xalign");
7914 * gtk_entry_get_alignment:
7915 * @entry: a #GtkEntry
7917 * Gets the value set by gtk_entry_set_alignment().
7919 * Return value: the alignment
7924 gtk_entry_get_alignment (GtkEntry *entry)
7926 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7928 return entry->priv->xalign;
7932 * gtk_entry_set_icon_from_pixbuf:
7933 * @entry: a #GtkEntry
7934 * @icon_pos: Icon position
7935 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7937 * Sets the icon shown in the specified position using a pixbuf.
7939 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7944 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7945 GtkEntryIconPosition icon_pos,
7948 GtkEntryPrivate *priv;
7949 EntryIconInfo *icon_info;
7951 g_return_if_fail (GTK_IS_ENTRY (entry));
7952 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7956 if ((icon_info = priv->icons[icon_pos]) == NULL)
7957 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7959 g_object_freeze_notify (G_OBJECT (entry));
7962 g_object_ref (pixbuf);
7964 gtk_entry_clear (entry, icon_pos);
7968 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7969 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
7970 GTK_ICON_SIZE_MENU);
7972 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7974 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7975 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7979 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7980 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7983 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7984 gdk_window_show_unraised (icon_info->window);
7986 g_object_unref (pixbuf);
7989 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7990 gtk_widget_queue_resize (GTK_WIDGET (entry));
7992 g_object_thaw_notify (G_OBJECT (entry));
7996 * gtk_entry_set_icon_from_stock:
7997 * @entry: A #GtkEntry
7998 * @icon_pos: Icon position
7999 * @stock_id: (allow-none): The name of the stock item, or %NULL
8001 * Sets the icon shown in the entry at the specified position from
8004 * If @stock_id is %NULL, no icon will be shown in the specified position.
8009 gtk_entry_set_icon_from_stock (GtkEntry *entry,
8010 GtkEntryIconPosition icon_pos,
8011 const gchar *stock_id)
8013 GtkEntryPrivate *priv;
8014 EntryIconInfo *icon_info;
8017 g_return_if_fail (GTK_IS_ENTRY (entry));
8018 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8022 if ((icon_info = priv->icons[icon_pos]) == NULL)
8023 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8025 g_object_freeze_notify (G_OBJECT (entry));
8027 /* need to dup before clearing */
8028 new_id = g_strdup (stock_id);
8030 gtk_entry_clear (entry, icon_pos);
8034 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
8036 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8038 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
8039 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8043 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
8044 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8047 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8048 gdk_window_show_unraised (icon_info->window);
8053 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8054 gtk_widget_queue_resize (GTK_WIDGET (entry));
8056 g_object_thaw_notify (G_OBJECT (entry));
8060 * gtk_entry_set_icon_from_icon_name:
8061 * @entry: A #GtkEntry
8062 * @icon_pos: The position at which to set the icon
8063 * @icon_name: (allow-none): An icon name, or %NULL
8065 * Sets the icon shown in the entry at the specified position
8066 * from the current icon theme.
8068 * If the icon name isn't known, a "broken image" icon will be displayed
8071 * If @icon_name is %NULL, no icon will be shown in the specified position.
8076 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
8077 GtkEntryIconPosition icon_pos,
8078 const gchar *icon_name)
8080 GtkEntryPrivate *priv;
8081 EntryIconInfo *icon_info;
8084 g_return_if_fail (GTK_IS_ENTRY (entry));
8085 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8089 if ((icon_info = priv->icons[icon_pos]) == NULL)
8090 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8092 g_object_freeze_notify (G_OBJECT (entry));
8094 /* need to dup before clearing */
8095 new_name = g_strdup (icon_name);
8097 gtk_entry_clear (entry, icon_pos);
8099 if (new_name != NULL)
8101 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
8103 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8105 g_object_notify (G_OBJECT (entry), "primary-icon-name");
8106 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8110 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
8111 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8114 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8115 gdk_window_show_unraised (icon_info->window);
8120 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8121 gtk_widget_queue_resize (GTK_WIDGET (entry));
8123 g_object_thaw_notify (G_OBJECT (entry));
8127 * gtk_entry_set_icon_from_gicon:
8128 * @entry: A #GtkEntry
8129 * @icon_pos: The position at which to set the icon
8130 * @icon: (allow-none): The icon to set, or %NULL
8132 * Sets the icon shown in the entry at the specified position
8133 * from the current icon theme.
8134 * If the icon isn't known, a "broken image" icon will be displayed
8137 * If @icon is %NULL, no icon will be shown in the specified position.
8142 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
8143 GtkEntryIconPosition icon_pos,
8146 GtkEntryPrivate *priv;
8147 EntryIconInfo *icon_info;
8149 g_return_if_fail (GTK_IS_ENTRY (entry));
8150 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8154 if ((icon_info = priv->icons[icon_pos]) == NULL)
8155 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8157 g_object_freeze_notify (G_OBJECT (entry));
8159 /* need to ref before clearing */
8161 g_object_ref (icon);
8163 gtk_entry_clear (entry, icon_pos);
8167 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
8169 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8171 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8172 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8176 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8177 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8180 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8181 gdk_window_show_unraised (icon_info->window);
8183 g_object_unref (icon);
8186 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8187 gtk_widget_queue_resize (GTK_WIDGET (entry));
8189 g_object_thaw_notify (G_OBJECT (entry));
8193 * gtk_entry_set_icon_activatable:
8194 * @entry: A #GtkEntry
8195 * @icon_pos: Icon position
8196 * @activatable: %TRUE if the icon should be activatable
8198 * Sets whether the icon is activatable.
8203 gtk_entry_set_icon_activatable (GtkEntry *entry,
8204 GtkEntryIconPosition icon_pos,
8205 gboolean activatable)
8207 GtkEntryPrivate *priv;
8208 EntryIconInfo *icon_info;
8210 g_return_if_fail (GTK_IS_ENTRY (entry));
8211 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8215 if ((icon_info = priv->icons[icon_pos]) == NULL)
8216 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8218 activatable = activatable != FALSE;
8220 if (icon_info->nonactivatable != !activatable)
8222 icon_info->nonactivatable = !activatable;
8224 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8225 update_cursors (GTK_WIDGET (entry));
8227 g_object_notify (G_OBJECT (entry),
8228 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8233 * gtk_entry_get_icon_activatable:
8234 * @entry: a #GtkEntry
8235 * @icon_pos: Icon position
8237 * Returns whether the icon is activatable.
8239 * Returns: %TRUE if the icon is activatable.
8244 gtk_entry_get_icon_activatable (GtkEntry *entry,
8245 GtkEntryIconPosition icon_pos)
8247 GtkEntryPrivate *priv;
8248 EntryIconInfo *icon_info;
8250 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8251 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8254 icon_info = priv->icons[icon_pos];
8256 return (!icon_info || !icon_info->nonactivatable);
8260 * gtk_entry_get_icon_pixbuf:
8261 * @entry: A #GtkEntry
8262 * @icon_pos: Icon position
8264 * Retrieves the image used for the icon.
8266 * Unlike the other methods of setting and getting icon data, this
8267 * method will work regardless of whether the icon was set using a
8268 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8270 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8271 * set for this position.
8276 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8277 GtkEntryIconPosition icon_pos)
8279 GtkEntryPrivate *priv;
8280 EntryIconInfo *icon_info;
8283 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8284 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8288 icon_info = priv->icons[icon_pos];
8293 /* HACK: unfortunately this is transfer none, so we need to return
8294 * the icon helper's cache ref directly.
8296 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
8298 g_object_unref (pixbuf);
8304 * gtk_entry_get_icon_gicon:
8305 * @entry: A #GtkEntry
8306 * @icon_pos: Icon position
8308 * Retrieves the #GIcon used for the icon, or %NULL if there is
8309 * no icon or if the icon was set by some other method (e.g., by
8310 * stock, pixbuf, or icon name).
8312 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8313 * or if the icon is not a #GIcon
8318 gtk_entry_get_icon_gicon (GtkEntry *entry,
8319 GtkEntryIconPosition icon_pos)
8321 GtkEntryPrivate *priv;
8322 EntryIconInfo *icon_info;
8324 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8325 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8328 icon_info = priv->icons[icon_pos];
8333 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
8337 * gtk_entry_get_icon_stock:
8338 * @entry: A #GtkEntry
8339 * @icon_pos: Icon position
8341 * Retrieves the stock id used for the icon, or %NULL if there is
8342 * no icon or if the icon was set by some other method (e.g., by
8343 * pixbuf, icon name or gicon).
8345 * Returns: A stock id, or %NULL if no icon is set or if the icon
8346 * wasn't set from a stock id
8351 gtk_entry_get_icon_stock (GtkEntry *entry,
8352 GtkEntryIconPosition icon_pos)
8354 GtkEntryPrivate *priv;
8355 EntryIconInfo *icon_info;
8357 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8358 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8361 icon_info = priv->icons[icon_pos];
8366 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8370 * gtk_entry_get_icon_name:
8371 * @entry: A #GtkEntry
8372 * @icon_pos: Icon position
8374 * Retrieves the icon name used for the icon, or %NULL if there is
8375 * no icon or if the icon was set by some other method (e.g., by
8376 * pixbuf, stock or gicon).
8378 * Returns: An icon name, or %NULL if no icon is set or if the icon
8379 * wasn't set from an icon name
8384 gtk_entry_get_icon_name (GtkEntry *entry,
8385 GtkEntryIconPosition icon_pos)
8387 GtkEntryPrivate *priv;
8388 EntryIconInfo *icon_info;
8390 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8391 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8394 icon_info = priv->icons[icon_pos];
8399 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8403 * gtk_entry_set_icon_sensitive:
8404 * @entry: A #GtkEntry
8405 * @icon_pos: Icon position
8406 * @sensitive: Specifies whether the icon should appear
8407 * sensitive or insensitive
8409 * Sets the sensitivity for the specified icon.
8414 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8415 GtkEntryIconPosition icon_pos,
8418 GtkEntryPrivate *priv;
8419 EntryIconInfo *icon_info;
8421 g_return_if_fail (GTK_IS_ENTRY (entry));
8422 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8426 if ((icon_info = priv->icons[icon_pos]) == NULL)
8427 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8429 if (icon_info->insensitive != !sensitive)
8431 icon_info->insensitive = !sensitive;
8433 icon_info->pressed = FALSE;
8434 icon_info->prelight = FALSE;
8436 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8437 update_cursors (GTK_WIDGET (entry));
8439 gtk_widget_queue_draw (GTK_WIDGET (entry));
8441 g_object_notify (G_OBJECT (entry),
8442 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8447 * gtk_entry_get_icon_sensitive:
8448 * @entry: a #GtkEntry
8449 * @icon_pos: Icon position
8451 * Returns whether the icon appears sensitive or insensitive.
8453 * Returns: %TRUE if the icon is sensitive.
8458 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8459 GtkEntryIconPosition icon_pos)
8461 GtkEntryPrivate *priv;
8462 EntryIconInfo *icon_info;
8464 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8465 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8469 icon_info = priv->icons[icon_pos];
8471 return (!icon_info || !icon_info->insensitive);
8476 * gtk_entry_get_icon_storage_type:
8477 * @entry: a #GtkEntry
8478 * @icon_pos: Icon position
8480 * Gets the type of representation being used by the icon
8481 * to store image data. If the icon has no image data,
8482 * the return value will be %GTK_IMAGE_EMPTY.
8484 * Return value: image representation being used
8489 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8490 GtkEntryIconPosition icon_pos)
8492 GtkEntryPrivate *priv;
8493 EntryIconInfo *icon_info;
8495 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8496 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8500 icon_info = priv->icons[icon_pos];
8503 return GTK_IMAGE_EMPTY;
8505 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8509 * gtk_entry_get_icon_at_pos:
8510 * @entry: a #GtkEntry
8511 * @x: the x coordinate of the position to find
8512 * @y: the y coordinate of the position to find
8514 * Finds the icon at the given position and return its index. The
8515 * position's coordinates are relative to the @entry's top left corner.
8516 * If @x, @y doesn't lie inside an icon, -1 is returned.
8517 * This function is intended for use in a #GtkWidget::query-tooltip
8520 * Returns: the index of the icon at the given position, or -1
8525 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8529 GtkAllocation primary;
8530 GtkAllocation secondary;
8531 gint frame_x, frame_y;
8533 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8535 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8539 get_icon_allocations (entry, &primary, &secondary);
8541 if (primary.x <= x && x < primary.x + primary.width &&
8542 primary.y <= y && y < primary.y + primary.height)
8543 return GTK_ENTRY_ICON_PRIMARY;
8545 if (secondary.x <= x && x < secondary.x + secondary.width &&
8546 secondary.y <= y && y < secondary.y + secondary.height)
8547 return GTK_ENTRY_ICON_SECONDARY;
8553 * gtk_entry_set_icon_drag_source:
8554 * @entry: a #GtkEntry
8555 * @icon_pos: icon position
8556 * @target_list: the targets (data formats) in which the data can be provided
8557 * @actions: a bitmask of the allowed drag actions
8559 * Sets up the icon at the given position so that GTK+ will start a drag
8560 * operation when the user clicks and drags the icon.
8562 * To handle the drag operation, you need to connect to the usual
8563 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8564 * signal, and use gtk_entry_get_current_icon_drag_source() in
8565 * your signal handler to find out if the drag was started from
8568 * By default, GTK+ uses the icon as the drag icon. You can use the
8569 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8570 * have to use g_signal_connect_after() to ensure that your signal handler
8571 * gets executed after the default handler.
8576 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8577 GtkEntryIconPosition icon_pos,
8578 GtkTargetList *target_list,
8579 GdkDragAction actions)
8581 GtkEntryPrivate *priv;
8582 EntryIconInfo *icon_info;
8584 g_return_if_fail (GTK_IS_ENTRY (entry));
8585 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8589 if ((icon_info = priv->icons[icon_pos]) == NULL)
8590 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8592 if (icon_info->target_list)
8593 gtk_target_list_unref (icon_info->target_list);
8594 icon_info->target_list = target_list;
8595 if (icon_info->target_list)
8596 gtk_target_list_ref (icon_info->target_list);
8598 icon_info->actions = actions;
8602 * gtk_entry_get_current_icon_drag_source:
8603 * @entry: a #GtkIconEntry
8605 * Returns the index of the icon which is the source of the current
8606 * DND operation, or -1.
8608 * This function is meant to be used in a #GtkWidget::drag-data-get
8611 * Returns: index of the icon which is the source of the current
8612 * DND operation, or -1.
8617 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8619 GtkEntryPrivate *priv;
8620 EntryIconInfo *icon_info = NULL;
8623 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8627 for (i = 0; i < MAX_ICONS; i++)
8629 if ((icon_info = priv->icons[i]))
8631 if (icon_info->in_drag)
8640 * gtk_entry_get_icon_area:
8641 * @entry: A #GtkEntry
8642 * @icon_pos: Icon position
8643 * @icon_area: (out): Return location for the icon's area
8645 * Gets the area where entry's icon at @icon_pos is drawn.
8646 * This function is useful when drawing something to the
8647 * entry in a draw callback.
8649 * If the entry is not realized or has no icon at the given position,
8650 * @icon_area is filled with zeros.
8652 * See also gtk_entry_get_text_area()
8657 gtk_entry_get_icon_area (GtkEntry *entry,
8658 GtkEntryIconPosition icon_pos,
8659 GdkRectangle *icon_area)
8661 GtkEntryPrivate *priv;
8662 EntryIconInfo *icon_info;
8664 g_return_if_fail (GTK_IS_ENTRY (entry));
8665 g_return_if_fail (icon_area != NULL);
8669 icon_info = priv->icons[icon_pos];
8673 GtkAllocation primary;
8674 GtkAllocation secondary;
8676 get_icon_allocations (entry, &primary, &secondary);
8678 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8679 *icon_area = primary;
8681 *icon_area = secondary;
8687 icon_area->width = 0;
8688 icon_area->height = 0;
8693 ensure_has_tooltip (GtkEntry *entry)
8695 GtkEntryPrivate *priv;
8696 EntryIconInfo *icon_info;
8698 gboolean has_tooltip = FALSE;
8702 for (i = 0; i < MAX_ICONS; i++)
8704 if ((icon_info = priv->icons[i]) != NULL)
8706 if (icon_info->tooltip != NULL)
8714 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8718 * gtk_entry_get_icon_tooltip_text:
8719 * @entry: a #GtkEntry
8720 * @icon_pos: the icon position
8722 * Gets the contents of the tooltip on the icon at the specified
8723 * position in @entry.
8725 * Returns: the tooltip text, or %NULL. Free the returned string
8726 * with g_free() when done.
8731 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8732 GtkEntryIconPosition icon_pos)
8734 GtkEntryPrivate *priv;
8735 EntryIconInfo *icon_info;
8738 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8739 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8743 icon_info = priv->icons[icon_pos];
8748 if (icon_info->tooltip &&
8749 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8750 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8756 * gtk_entry_set_icon_tooltip_text:
8757 * @entry: a #GtkEntry
8758 * @icon_pos: the icon position
8759 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8761 * Sets @tooltip as the contents of the tooltip for the icon
8762 * at the specified position.
8764 * Use %NULL for @tooltip to remove an existing tooltip.
8766 * See also gtk_widget_set_tooltip_text() and
8767 * gtk_entry_set_icon_tooltip_markup().
8772 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8773 GtkEntryIconPosition icon_pos,
8774 const gchar *tooltip)
8776 GtkEntryPrivate *priv;
8777 EntryIconInfo *icon_info;
8779 g_return_if_fail (GTK_IS_ENTRY (entry));
8780 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8784 if ((icon_info = priv->icons[icon_pos]) == NULL)
8785 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8787 if (icon_info->tooltip)
8788 g_free (icon_info->tooltip);
8790 /* Treat an empty string as a NULL string,
8791 * because an empty string would be useless for a tooltip:
8793 if (tooltip && tooltip[0] == '\0')
8796 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8798 ensure_has_tooltip (entry);
8800 g_object_notify (G_OBJECT (entry),
8801 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-tooltip-text" : "secondary-icon-tooltip-text");
8805 * gtk_entry_get_icon_tooltip_markup:
8806 * @entry: a #GtkEntry
8807 * @icon_pos: the icon position
8809 * Gets the contents of the tooltip on the icon at the specified
8810 * position in @entry.
8812 * Returns: the tooltip text, or %NULL. Free the returned string
8813 * with g_free() when done.
8818 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8819 GtkEntryIconPosition icon_pos)
8821 GtkEntryPrivate *priv;
8822 EntryIconInfo *icon_info;
8824 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8825 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8829 icon_info = priv->icons[icon_pos];
8834 return g_strdup (icon_info->tooltip);
8838 * gtk_entry_set_icon_tooltip_markup:
8839 * @entry: a #GtkEntry
8840 * @icon_pos: the icon position
8841 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8843 * Sets @tooltip as the contents of the tooltip for the icon at
8844 * the specified position. @tooltip is assumed to be marked up with
8845 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8847 * Use %NULL for @tooltip to remove an existing tooltip.
8849 * See also gtk_widget_set_tooltip_markup() and
8850 * gtk_entry_set_icon_tooltip_text().
8855 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8856 GtkEntryIconPosition icon_pos,
8857 const gchar *tooltip)
8859 GtkEntryPrivate *priv;
8860 EntryIconInfo *icon_info;
8862 g_return_if_fail (GTK_IS_ENTRY (entry));
8863 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8867 if ((icon_info = priv->icons[icon_pos]) == NULL)
8868 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8870 if (icon_info->tooltip)
8871 g_free (icon_info->tooltip);
8873 /* Treat an empty string as a NULL string,
8874 * because an empty string would be useless for a tooltip:
8876 if (tooltip && tooltip[0] == '\0')
8879 icon_info->tooltip = g_strdup (tooltip);
8881 ensure_has_tooltip (entry);
8885 gtk_entry_query_tooltip (GtkWidget *widget,
8888 gboolean keyboard_tip,
8889 GtkTooltip *tooltip)
8892 GtkEntryPrivate *priv;
8893 EntryIconInfo *icon_info;
8896 entry = GTK_ENTRY (widget);
8901 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8904 if ((icon_info = priv->icons[icon_pos]) != NULL)
8906 if (icon_info->tooltip)
8908 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8917 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8924 /* Quick hack of a popup menu
8927 activate_cb (GtkWidget *menuitem,
8930 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8931 g_signal_emit_by_name (entry, signal);
8936 gtk_entry_mnemonic_activate (GtkWidget *widget,
8937 gboolean group_cycling)
8939 gtk_widget_grab_focus (widget);
8944 gtk_entry_grab_notify (GtkWidget *widget,
8945 gboolean was_grabbed)
8947 GtkEntryPrivate *priv;
8949 priv = GTK_ENTRY (widget)->priv;
8952 gtk_widget_device_is_shadowed (widget, priv->device))
8954 /* Unset button so we don't expect
8955 * a button release anymore
8958 priv->device = NULL;
8959 priv->in_drag = FALSE;
8964 append_action_signal (GtkEntry *entry,
8966 const gchar *stock_id,
8967 const gchar *signal,
8970 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8972 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8973 g_signal_connect (menuitem, "activate",
8974 G_CALLBACK (activate_cb), entry);
8976 gtk_widget_set_sensitive (menuitem, sensitive);
8978 gtk_widget_show (menuitem);
8979 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8983 popup_menu_detach (GtkWidget *attach_widget,
8986 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8987 GtkEntryPrivate *priv_attach = entry_attach->priv;
8989 priv_attach->popup_menu = NULL;
8993 popup_position_func (GtkMenu *menu,
8999 GtkEntry *entry = GTK_ENTRY (user_data);
9000 GtkEntryPrivate *priv = entry->priv;
9001 GtkWidget *widget = GTK_WIDGET (entry);
9003 GtkRequisition menu_req;
9004 GdkRectangle monitor;
9006 gint monitor_num, strong_x, height;
9008 g_return_if_fail (gtk_widget_get_realized (widget));
9010 gdk_window_get_origin (priv->text_area, x, y);
9012 screen = gtk_widget_get_screen (widget);
9013 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
9014 if (monitor_num < 0)
9016 gtk_menu_set_monitor (menu, monitor_num);
9018 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
9019 gtk_widget_get_preferred_size (priv->popup_menu,
9021 height = gdk_window_get_height (priv->text_area);
9022 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
9023 _gtk_entry_get_borders (entry, &borders);
9025 *x += borders.left + strong_x - priv->scroll_offset;
9026 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
9027 *x -= menu_req.width;
9029 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
9031 else if ((*y - menu_req.height) >= monitor.y)
9032 *y -= menu_req.height;
9033 else if (monitor.y + monitor.height - (*y + height) > *y)
9036 *y -= menu_req.height;
9042 unichar_chosen_func (const char *text,
9045 GtkEntry *entry = GTK_ENTRY (data);
9046 GtkEntryPrivate *priv = entry->priv;
9049 gtk_entry_enter_text (entry, text);
9061 popup_targets_received (GtkClipboard *clipboard,
9062 GtkSelectionData *data,
9065 PopupInfo *info = user_data;
9066 GtkEntry *entry = info->entry;
9067 GtkEntryPrivate *info_entry_priv = entry->priv;
9069 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
9072 gboolean clipboard_contains_text;
9073 GtkWidget *menuitem;
9075 gboolean show_input_method_menu;
9076 gboolean show_unicode_menu;
9078 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
9079 if (info_entry_priv->popup_menu)
9080 gtk_widget_destroy (info_entry_priv->popup_menu);
9082 info_entry_priv->popup_menu = gtk_menu_new ();
9084 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
9088 mode = gtk_entry_get_display_mode (entry);
9089 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
9090 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
9091 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9093 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
9094 mode == DISPLAY_NORMAL &&
9095 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9097 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
9098 info_entry_priv->editable && clipboard_contains_text);
9100 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
9101 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
9102 g_signal_connect_swapped (menuitem, "activate",
9103 G_CALLBACK (gtk_entry_delete_cb), entry);
9104 gtk_widget_show (menuitem);
9105 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9107 menuitem = gtk_separator_menu_item_new ();
9108 gtk_widget_show (menuitem);
9109 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9111 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
9112 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
9113 g_signal_connect_swapped (menuitem, "activate",
9114 G_CALLBACK (gtk_entry_select_all), entry);
9115 gtk_widget_show (menuitem);
9116 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9118 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
9119 "gtk-show-input-method-menu", &show_input_method_menu,
9120 "gtk-show-unicode-menu", &show_unicode_menu,
9123 if (show_input_method_menu || show_unicode_menu)
9125 menuitem = gtk_separator_menu_item_new ();
9126 gtk_widget_show (menuitem);
9127 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9130 if (show_input_method_menu)
9132 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
9133 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9134 gtk_widget_show (menuitem);
9135 submenu = gtk_menu_new ();
9136 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9138 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9140 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
9141 GTK_MENU_SHELL (submenu));
9144 if (show_unicode_menu)
9146 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
9147 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9148 gtk_widget_show (menuitem);
9150 submenu = gtk_menu_new ();
9151 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9152 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9154 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
9155 unichar_chosen_func,
9159 g_signal_emit (entry,
9160 signals[POPULATE_POPUP],
9162 info_entry_priv->popup_menu);
9166 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
9167 info->device, NULL, NULL, NULL, NULL, NULL,
9168 info->button, info->time);
9171 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
9172 popup_position_func, entry,
9173 0, gtk_get_current_event_time ());
9174 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9178 g_object_unref (entry);
9179 g_slice_free (PopupInfo, info);
9183 gtk_entry_do_popup (GtkEntry *entry,
9184 GdkEventButton *event)
9186 PopupInfo *info = g_slice_new (PopupInfo);
9188 /* In order to know what entries we should make sensitive, we
9189 * ask for the current targets of the clipboard, and when
9190 * we get them, then we actually pop up the menu.
9192 info->entry = g_object_ref (entry);
9196 info->button = event->button;
9197 info->time = event->time;
9198 info->device = event->device;
9203 info->time = gtk_get_current_event_time ();
9204 info->device = NULL;
9207 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9208 gdk_atom_intern_static_string ("TARGETS"),
9209 popup_targets_received,
9214 gtk_entry_popup_menu (GtkWidget *widget)
9216 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9221 gtk_entry_drag_begin (GtkWidget *widget,
9222 GdkDragContext *context)
9224 GtkEntry *entry = GTK_ENTRY (widget);
9225 GtkEntryPrivate *priv = entry->priv;
9228 for (i = 0; i < MAX_ICONS; i++)
9230 EntryIconInfo *icon_info = priv->icons[i];
9232 if (icon_info != NULL)
9234 if (icon_info->in_drag)
9238 pix = _gtk_icon_helper_ensure_pixbuf
9239 (icon_info->icon_helper,
9240 gtk_widget_get_style_context (GTK_WIDGET (entry)));
9241 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
9243 g_object_unref (pix);
9250 gtk_entry_drag_end (GtkWidget *widget,
9251 GdkDragContext *context)
9253 GtkEntry *entry = GTK_ENTRY (widget);
9254 GtkEntryPrivate *priv = entry->priv;
9257 for (i = 0; i < MAX_ICONS; i++)
9259 EntryIconInfo *icon_info = priv->icons[i];
9261 if (icon_info != NULL)
9262 icon_info->in_drag = 0;
9267 gtk_entry_drag_leave (GtkWidget *widget,
9268 GdkDragContext *context,
9271 GtkEntry *entry = GTK_ENTRY (widget);
9272 GtkEntryPrivate *priv = entry->priv;
9274 priv->dnd_position = -1;
9275 gtk_widget_queue_draw (widget);
9279 gtk_entry_drag_drop (GtkWidget *widget,
9280 GdkDragContext *context,
9285 GtkEntry *entry = GTK_ENTRY (widget);
9286 GtkEntryPrivate *priv = entry->priv;
9287 GdkAtom target = GDK_NONE;
9290 target = gtk_drag_dest_find_target (widget, context, NULL);
9292 if (target != GDK_NONE)
9293 gtk_drag_get_data (widget, context, target, time);
9295 gtk_drag_finish (context, FALSE, FALSE, time);
9301 gtk_entry_drag_motion (GtkWidget *widget,
9302 GdkDragContext *context,
9307 GtkEntry *entry = GTK_ENTRY (widget);
9308 GtkEntryPrivate *priv = entry->priv;
9309 GtkStyleContext *style_context;
9310 GtkWidget *source_widget;
9311 GdkDragAction suggested_action;
9312 gint new_position, old_position;
9316 style_context = gtk_widget_get_style_context (widget);
9317 gtk_style_context_get_padding (style_context, 0, &padding);
9321 old_position = priv->dnd_position;
9322 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9324 if (priv->editable &&
9325 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9327 source_widget = gtk_drag_get_source_widget (context);
9328 suggested_action = gdk_drag_context_get_suggested_action (context);
9330 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9331 new_position < sel1 || new_position > sel2)
9333 if (source_widget == widget)
9335 /* Default to MOVE, unless the user has
9336 * pressed ctrl or alt to affect available actions
9338 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9339 suggested_action = GDK_ACTION_MOVE;
9342 priv->dnd_position = new_position;
9346 if (source_widget == widget)
9347 suggested_action = 0; /* Can't drop in selection where drag started */
9349 priv->dnd_position = -1;
9354 /* Entry not editable, or no text */
9355 suggested_action = 0;
9356 priv->dnd_position = -1;
9359 gdk_drag_status (context, suggested_action, time);
9361 if (priv->dnd_position != old_position)
9362 gtk_widget_queue_draw (widget);
9368 gtk_entry_drag_data_received (GtkWidget *widget,
9369 GdkDragContext *context,
9372 GtkSelectionData *selection_data,
9376 GtkEntry *entry = GTK_ENTRY (widget);
9377 GtkEntryPrivate *priv = entry->priv;
9378 GtkEditable *editable = GTK_EDITABLE (widget);
9379 GtkStyleContext *style_context;
9383 str = (gchar *) gtk_selection_data_get_text (selection_data);
9385 style_context = gtk_widget_get_style_context (widget);
9386 gtk_style_context_get_padding (style_context, 0, &padding);
9390 if (str && priv->editable)
9396 if (priv->truncate_multiline)
9397 length = truncate_multiline (str);
9399 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9401 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9402 new_position < sel1 || new_position > sel2)
9404 gtk_editable_insert_text (editable, str, length, &new_position);
9408 /* Replacing selection */
9409 begin_change (entry);
9410 gtk_editable_delete_text (editable, sel1, sel2);
9411 gtk_editable_insert_text (editable, str, length, &sel1);
9415 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9419 /* Drag and drop didn't happen! */
9420 gtk_drag_finish (context, FALSE, FALSE, time);
9427 gtk_entry_drag_data_get (GtkWidget *widget,
9428 GdkDragContext *context,
9429 GtkSelectionData *selection_data,
9433 GtkEntry *entry = GTK_ENTRY (widget);
9434 GtkEntryPrivate *priv = entry->priv;
9435 GtkEditable *editable = GTK_EDITABLE (widget);
9436 gint sel_start, sel_end;
9439 /* If there is an icon drag going on, exit early. */
9440 for (i = 0; i < MAX_ICONS; i++)
9442 EntryIconInfo *icon_info = priv->icons[i];
9444 if (icon_info != NULL)
9446 if (icon_info->in_drag)
9451 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9453 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9455 gtk_selection_data_set_text (selection_data, str, -1);
9463 gtk_entry_drag_data_delete (GtkWidget *widget,
9464 GdkDragContext *context)
9466 GtkEntry *entry = GTK_ENTRY (widget);
9467 GtkEntryPrivate *priv = entry->priv;
9468 GtkEditable *editable = GTK_EDITABLE (widget);
9469 gint sel_start, sel_end;
9472 /* If there is an icon drag going on, exit early. */
9473 for (i = 0; i < MAX_ICONS; i++)
9475 EntryIconInfo *icon_info = priv->icons[i];
9477 if (icon_info != NULL)
9479 if (icon_info->in_drag)
9484 if (priv->editable &&
9485 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9486 gtk_editable_delete_text (editable, sel_start, sel_end);
9489 /* We display the cursor when
9491 * - the selection is empty, AND
9492 * - the widget has focus
9495 #define CURSOR_ON_MULTIPLIER 2
9496 #define CURSOR_OFF_MULTIPLIER 1
9497 #define CURSOR_PEND_MULTIPLIER 3
9498 #define CURSOR_DIVIDER 3
9501 cursor_blinks (GtkEntry *entry)
9503 GtkEntryPrivate *priv = entry->priv;
9505 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9507 priv->selection_bound == priv->current_pos)
9509 GtkSettings *settings;
9512 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9513 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9522 get_middle_click_paste (GtkEntry *entry)
9524 GtkSettings *settings;
9527 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9528 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9534 get_cursor_time (GtkEntry *entry)
9536 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9539 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9545 get_cursor_blink_timeout (GtkEntry *entry)
9547 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9550 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9556 show_cursor (GtkEntry *entry)
9558 GtkEntryPrivate *priv = entry->priv;
9561 if (!priv->cursor_visible)
9563 priv->cursor_visible = TRUE;
9565 widget = GTK_WIDGET (entry);
9566 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9567 gtk_widget_queue_draw (widget);
9572 hide_cursor (GtkEntry *entry)
9574 GtkEntryPrivate *priv = entry->priv;
9577 if (priv->cursor_visible)
9579 priv->cursor_visible = FALSE;
9581 widget = GTK_WIDGET (entry);
9582 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9583 gtk_widget_queue_draw (widget);
9591 blink_cb (gpointer data)
9594 GtkEntryPrivate *priv;
9597 entry = GTK_ENTRY (data);
9600 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9602 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9603 "connect a handler to this signal, it must return\n"
9604 "FALSE so the entry gets the event as well");
9606 gtk_entry_check_cursor_blink (entry);
9611 g_assert (priv->selection_bound == priv->current_pos);
9613 blink_timeout = get_cursor_blink_timeout (entry);
9614 if (priv->blink_time > 1000 * blink_timeout &&
9615 blink_timeout < G_MAXINT/1000)
9617 /* we've blinked enough without the user doing anything, stop blinking */
9618 show_cursor (entry);
9619 priv->blink_timeout = 0;
9621 else if (priv->cursor_visible)
9623 hide_cursor (entry);
9624 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9630 show_cursor (entry);
9631 priv->blink_time += get_cursor_time (entry);
9632 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9637 /* Remove ourselves */
9642 gtk_entry_check_cursor_blink (GtkEntry *entry)
9644 GtkEntryPrivate *priv = entry->priv;
9646 if (cursor_blinks (entry))
9648 if (!priv->blink_timeout)
9650 show_cursor (entry);
9651 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9658 if (priv->blink_timeout)
9660 g_source_remove (priv->blink_timeout);
9661 priv->blink_timeout = 0;
9664 priv->cursor_visible = TRUE;
9669 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9671 GtkEntryPrivate *priv = entry->priv;
9673 if (cursor_blinks (entry))
9675 if (priv->blink_timeout != 0)
9676 g_source_remove (priv->blink_timeout);
9678 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9681 show_cursor (entry);
9686 gtk_entry_reset_blink_time (GtkEntry *entry)
9688 GtkEntryPrivate *priv = entry->priv;
9690 priv->blink_time = 0;
9694 * gtk_entry_set_completion:
9695 * @entry: A #GtkEntry
9696 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9698 * Sets @completion to be the auxiliary completion object to use with @entry.
9699 * All further configuration of the completion mechanism is done on
9700 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9701 * @completion is set to %NULL.
9706 gtk_entry_set_completion (GtkEntry *entry,
9707 GtkEntryCompletion *completion)
9709 GtkEntryCompletion *old;
9711 g_return_if_fail (GTK_IS_ENTRY (entry));
9712 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9714 old = gtk_entry_get_completion (entry);
9716 if (old == completion)
9721 _gtk_entry_completion_disconnect (old);
9722 g_object_unref (old);
9727 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9731 /* hook into the entry */
9732 g_object_ref (completion);
9734 _gtk_entry_completion_connect (completion, entry);
9736 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9738 g_object_notify (G_OBJECT (entry), "completion");
9742 * gtk_entry_get_completion:
9743 * @entry: A #GtkEntry
9745 * Returns the auxiliary completion object currently in use by @entry.
9747 * Return value: (transfer none): The auxiliary completion object currently
9752 GtkEntryCompletion *
9753 gtk_entry_get_completion (GtkEntry *entry)
9755 GtkEntryCompletion *completion;
9757 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9759 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9760 GTK_ENTRY_COMPLETION_KEY));
9766 * gtk_entry_set_cursor_hadjustment:
9767 * @entry: a #GtkEntry
9768 * @adjustment: an adjustment which should be adjusted when the cursor
9769 * is moved, or %NULL
9771 * Hooks up an adjustment to the cursor position in an entry, so that when
9772 * the cursor is moved, the adjustment is scrolled to show that position.
9773 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9776 * The adjustment has to be in pixel units and in the same coordinate system
9782 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9783 GtkAdjustment *adjustment)
9785 g_return_if_fail (GTK_IS_ENTRY (entry));
9787 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9790 g_object_ref (adjustment);
9792 g_object_set_qdata_full (G_OBJECT (entry),
9793 quark_cursor_hadjustment,
9799 * gtk_entry_get_cursor_hadjustment:
9800 * @entry: a #GtkEntry
9802 * Retrieves the horizontal cursor adjustment for the entry.
9803 * See gtk_entry_set_cursor_hadjustment().
9805 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9806 * if none has been set.
9811 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9813 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9815 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9819 * gtk_entry_set_progress_fraction:
9820 * @entry: a #GtkEntry
9821 * @fraction: fraction of the task that's been completed
9823 * Causes the entry's progress indicator to "fill in" the given
9824 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9830 gtk_entry_set_progress_fraction (GtkEntry *entry,
9834 GtkEntryPrivate *private;
9835 gdouble old_fraction;
9836 gint x, y, width, height;
9837 gint old_x, old_y, old_width, old_height;
9839 g_return_if_fail (GTK_IS_ENTRY (entry));
9841 widget = GTK_WIDGET (entry);
9842 private = entry->priv;
9844 if (private->progress_pulse_mode)
9847 old_fraction = private->progress_fraction;
9849 if (gtk_widget_is_drawable (widget))
9850 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9852 fraction = CLAMP (fraction, 0.0, 1.0);
9854 private->progress_fraction = fraction;
9855 private->progress_pulse_mode = FALSE;
9856 private->progress_pulse_current = 0.0;
9858 if (gtk_widget_is_drawable (widget))
9860 get_progress_area (widget, &x, &y, &width, &height);
9862 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9863 gtk_widget_queue_draw (widget);
9866 if (fraction != old_fraction)
9867 g_object_notify (G_OBJECT (entry), "progress-fraction");
9871 * gtk_entry_get_progress_fraction:
9872 * @entry: a #GtkEntry
9874 * Returns the current fraction of the task that's been completed.
9875 * See gtk_entry_set_progress_fraction().
9877 * Return value: a fraction from 0.0 to 1.0
9882 gtk_entry_get_progress_fraction (GtkEntry *entry)
9884 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9886 return entry->priv->progress_fraction;
9890 * gtk_entry_set_progress_pulse_step:
9891 * @entry: a #GtkEntry
9892 * @fraction: fraction between 0.0 and 1.0
9894 * Sets the fraction of total entry width to move the progress
9895 * bouncing block for each call to gtk_entry_progress_pulse().
9900 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9903 GtkEntryPrivate *private;
9905 g_return_if_fail (GTK_IS_ENTRY (entry));
9907 private = entry->priv;
9909 fraction = CLAMP (fraction, 0.0, 1.0);
9911 if (fraction != private->progress_pulse_fraction)
9913 private->progress_pulse_fraction = fraction;
9915 gtk_widget_queue_draw (GTK_WIDGET (entry));
9917 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9922 * gtk_entry_get_progress_pulse_step:
9923 * @entry: a #GtkEntry
9925 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9927 * Return value: a fraction from 0.0 to 1.0
9932 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9934 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9936 return entry->priv->progress_pulse_fraction;
9940 * gtk_entry_progress_pulse:
9941 * @entry: a #GtkEntry
9943 * Indicates that some progress is made, but you don't know how much.
9944 * Causes the entry's progress indicator to enter "activity mode,"
9945 * where a block bounces back and forth. Each call to
9946 * gtk_entry_progress_pulse() causes the block to move by a little bit
9947 * (the amount of movement per pulse is determined by
9948 * gtk_entry_set_progress_pulse_step()).
9953 gtk_entry_progress_pulse (GtkEntry *entry)
9955 GtkEntryPrivate *private;
9957 g_return_if_fail (GTK_IS_ENTRY (entry));
9959 private = entry->priv;
9961 if (private->progress_pulse_mode)
9963 if (private->progress_pulse_way_back)
9965 private->progress_pulse_current -= private->progress_pulse_fraction;
9967 if (private->progress_pulse_current < 0.0)
9969 private->progress_pulse_current = 0.0;
9970 private->progress_pulse_way_back = FALSE;
9975 private->progress_pulse_current += private->progress_pulse_fraction;
9977 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9979 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9980 private->progress_pulse_way_back = TRUE;
9986 private->progress_fraction = 0.0;
9987 private->progress_pulse_mode = TRUE;
9988 private->progress_pulse_way_back = FALSE;
9989 private->progress_pulse_current = 0.0;
9992 gtk_widget_queue_draw (GTK_WIDGET (entry));
9996 * gtk_entry_set_placeholder_text:
9997 * @entry: a #GtkEntry
9998 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10000 * Sets text to be displayed in @entry when it is empty and unfocused.
10001 * This can be used to give a visual hint of the expected contents of
10004 * Note that since the placeholder text gets removed when the entry
10005 * received focus, using this feature is a bit problematic if the entry
10006 * is given the initial focus in a window. Sometimes this can be
10007 * worked around by delaying the initial focus setting until the
10008 * first key event arrives.
10013 gtk_entry_set_placeholder_text (GtkEntry *entry,
10016 GtkEntryPrivate *priv;
10018 g_return_if_fail (GTK_IS_ENTRY (entry));
10020 priv = entry->priv;
10022 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10025 g_free (priv->placeholder_text);
10026 priv->placeholder_text = g_strdup (text);
10028 gtk_entry_recompute (entry);
10030 g_object_notify (G_OBJECT (entry), "placeholder-text");
10034 * gtk_entry_get_placeholder_text:
10035 * @entry: a #GtkEntry
10037 * Retrieves the text that will be displayed when @entry is empty and unfocused
10039 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10040 * storage in the widget and must not be freed, modified or stored.
10045 gtk_entry_get_placeholder_text (GtkEntry *entry)
10047 GtkEntryPrivate *priv;
10049 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10051 priv = entry->priv;
10053 return priv->placeholder_text;
10056 /* Caps Lock warning for password entries */
10059 show_capslock_feedback (GtkEntry *entry,
10062 GtkEntryPrivate *priv = entry->priv;
10064 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10066 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10067 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10068 priv->caps_lock_warning_shown = TRUE;
10071 if (priv->caps_lock_warning_shown)
10072 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10074 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10078 remove_capslock_feedback (GtkEntry *entry)
10080 GtkEntryPrivate *priv = entry->priv;
10082 if (priv->caps_lock_warning_shown)
10084 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10085 priv->caps_lock_warning_shown = FALSE;
10090 keymap_state_changed (GdkKeymap *keymap,
10093 GtkEntryPrivate *priv = entry->priv;
10096 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10098 if (gdk_keymap_get_caps_lock_state (keymap))
10099 text = _("Caps Lock is on");
10103 show_capslock_feedback (entry, text);
10105 remove_capslock_feedback (entry);
10109 * _gtk_entry_set_is_cell_renderer:
10110 * @entry: a #GtkEntry
10111 * @is_cell_renderer: new value
10113 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10114 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10116 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10120 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10121 gboolean is_cell_renderer)
10123 entry->priv->is_cell_renderer = is_cell_renderer;
10127 * gtk_entry_set_input_purpose:
10128 * @entry: a #GtkEntry
10129 * @purpose: the purpose
10131 * Sets the #GtkEntry:input-purpose property which
10132 * can be used by on-screen keyboards and other input
10133 * methods to adjust their behaviour.
10138 gtk_entry_set_input_purpose (GtkEntry *entry,
10139 GtkInputPurpose purpose)
10142 g_return_if_fail (GTK_IS_ENTRY (entry));
10144 if (gtk_entry_get_input_purpose (entry) != purpose)
10146 g_object_set (G_OBJECT (entry->priv->im_context),
10147 "input-purpose", purpose,
10150 g_object_notify (G_OBJECT (entry), "input-purpose");
10155 * gtk_entry_get_input_purpose:
10156 * @entry: a #GtkEntry
10158 * Gets the value of the #GtkEntry:input-purpose property.
10163 gtk_entry_get_input_purpose (GtkEntry *entry)
10165 GtkInputPurpose purpose;
10167 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
10169 g_object_get (G_OBJECT (entry->priv->im_context),
10170 "input-purpose", &purpose,
10177 * gtk_entry_set_input_hints:
10178 * @entry: a #GtkEntry
10179 * @hints: the hints
10181 * Sets the #GtkEntry:input-hints property, which
10182 * allows input methods to fine-tune their behaviour.
10187 gtk_entry_set_input_hints (GtkEntry *entry,
10188 GtkInputHints hints)
10191 g_return_if_fail (GTK_IS_ENTRY (entry));
10193 if (gtk_entry_get_input_hints (entry) != hints)
10195 g_object_set (G_OBJECT (entry->priv->im_context),
10196 "input-hints", hints,
10199 g_object_notify (G_OBJECT (entry), "input-hints");
10204 * gtk_entry_get_input_hints:
10205 * @entry: a #GtkEntry
10207 * Gets the value of the #GtkEntry:input-hints property.
10212 gtk_entry_get_input_hints (GtkEntry *entry)
10214 GtkInputHints hints;
10216 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
10218 g_object_get (G_OBJECT (entry->priv->im_context),
10219 "input-hints", &hints,
10226 * gtk_entry_set_attributes:
10227 * @entry: a #GtkEntry
10228 * @attrs: a #PangoAttrList
10230 * Sets a #PangoAttrList; the attributes in the list are applied to the
10236 gtk_entry_set_attributes (GtkEntry *entry,
10237 PangoAttrList *attrs)
10239 GtkEntryPrivate *priv = entry->priv;
10240 g_return_if_fail (GTK_IS_ENTRY (entry));
10243 pango_attr_list_ref (attrs);
10246 pango_attr_list_unref (priv->attrs);
10247 priv->attrs = attrs;
10249 g_object_notify (G_OBJECT (entry), "attributes");
10251 gtk_entry_recompute (entry);
10252 gtk_widget_queue_resize (GTK_WIDGET (entry));
10256 * gtk_entry_get_attributes:
10257 * @entry: a #GtkEntry
10259 * Gets the attribute list that was set on the entry using
10260 * gtk_entry_set_attributes(), if any.
10262 * Return value: (transfer none): the attribute list, or %NULL
10268 gtk_entry_get_attributes (GtkEntry *entry)
10270 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10272 return entry->priv->attrs;