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"
69 #include "a11y/gtkentryaccessible.h"
73 * @Short_description: A single line text entry field
75 * @See_also: #GtkTextView, #GtkEntryCompletion
77 * The #GtkEntry widget is a single line text entry
78 * widget. A fairly large set of key bindings are supported
79 * by default. If the entered text is longer than the allocation
80 * of the widget, the widget will scroll so that the cursor
81 * position is visible.
83 * When using an entry for passwords and other sensitive information,
84 * it can be put into "password mode" using gtk_entry_set_visibility().
85 * In this mode, entered text is displayed using a 'invisible' character.
86 * By default, GTK+ picks the best invisible character that is available
87 * in the current font, but it can be changed with
88 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
89 * when Caps Lock or input methods might interfere with entering text in
90 * a password entry. The warning can be turned off with the
91 * #GtkEntry:caps-lock-warning property.
93 * Since 2.16, GtkEntry has the ability to display progress or activity
94 * information behind the text. To make an entry display such information,
95 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
97 * Additionally, GtkEntry can show icons at either side of the entry. These
98 * icons can be activatable by clicking, can be set up as drag source and
99 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
100 * one of the various other functions that set an icon from a stock id, an
101 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
102 * connect to the #GtkEntry::icon-press signal. To allow DND operations
103 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
104 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
107 * Note that functionality or information that is only available by clicking
108 * on an icon in an entry may not be accessible at all to users which are not
109 * able to use a mouse or other pointing device. It is therefore recommended
110 * that any such functionality should also be available by other means, e.g.
111 * via the context menu of the entry.
115 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
117 #define MIN_ENTRY_WIDTH 150
118 #define DRAW_TIMEOUT 20
119 #define COMPLETION_TIMEOUT 300
120 #define PASSWORD_HINT_MAX 8
125 #define IS_VALID_ICON_POSITION(pos) \
126 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
127 (pos) == GTK_ENTRY_ICON_SECONDARY)
129 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
130 static GQuark quark_inner_border = 0;
131 static GQuark quark_password_hint = 0;
132 static GQuark quark_cursor_hadjustment = 0;
133 static GQuark quark_capslock_feedback = 0;
135 typedef struct _EntryIconInfo EntryIconInfo;
136 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
137 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
139 struct _GtkEntryPrivate
141 EntryIconInfo *icons[MAX_ICONS];
143 GtkEntryBuffer *buffer;
144 GtkIMContext *im_context;
145 GtkShadowType shadow_type;
146 GtkWidget *popup_menu;
150 GdkDevice *completion_device;
151 GdkWindow *text_area;
153 PangoLayout *cached_layout;
157 gdouble progress_fraction;
158 gdouble progress_pulse_fraction;
159 gdouble progress_pulse_current;
161 gchar *placeholder_text;
165 gint ascent; /* font ascent in pango units */
167 gint descent; /* font descent in pango units */
168 gint dnd_position; /* In chars, -1 == no DND cursor */
173 gint selection_bound;
179 gunichar invisible_char;
182 guint blink_time; /* time in msec the cursor has blinked since last user event */
184 guint recompute_idle;
186 guint16 x_text_size; /* allocated size, in bytes */
187 guint16 x_n_bytes; /* length in use, in bytes */
189 guint16 preedit_length; /* length of preedit string, in bytes */
190 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
194 guint overwrite_mode : 1;
197 guint activates_default : 1;
198 guint cache_includes_preedit : 1;
199 guint caps_lock_warning : 1;
200 guint caps_lock_warning_shown : 1;
201 guint change_count : 8;
202 guint cursor_visible : 1;
203 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
205 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
206 guint is_cell_renderer : 1;
207 guint invisible_char_set : 1;
208 guint interior_focus : 1;
209 guint mouse_cursor_obscured : 1;
210 guint need_im_reset : 1;
211 guint progress_pulse_mode : 1;
212 guint progress_pulse_way_back : 1;
213 guint real_changed : 1;
214 guint resolved_dir : 4; /* PangoDirection */
215 guint select_words : 1;
216 guint select_lines : 1;
217 guint truncate_multiline : 1;
220 struct _EntryIconInfo
224 guint insensitive : 1;
225 guint nonactivatable : 1;
230 GtkIconHelper *icon_helper;
232 GtkTargetList *target_list;
233 GdkDragAction actions;
236 struct _GtkEntryPasswordHint
238 gint position; /* Position (in text) of the last password hint */
239 guint source_id; /* Timeout source id */
242 struct _GtkEntryCapslockFeedback
269 PROP_CURSOR_POSITION,
270 PROP_SELECTION_BOUND,
277 PROP_ACTIVATES_DEFAULT,
282 PROP_TRUNCATE_MULTILINE,
286 PROP_INVISIBLE_CHAR_SET,
287 PROP_CAPS_LOCK_WARNING,
288 PROP_PROGRESS_FRACTION,
289 PROP_PROGRESS_PULSE_STEP,
291 PROP_PIXBUF_SECONDARY,
293 PROP_STOCK_SECONDARY,
294 PROP_ICON_NAME_PRIMARY,
295 PROP_ICON_NAME_SECONDARY,
297 PROP_GICON_SECONDARY,
298 PROP_STORAGE_TYPE_PRIMARY,
299 PROP_STORAGE_TYPE_SECONDARY,
300 PROP_ACTIVATABLE_PRIMARY,
301 PROP_ACTIVATABLE_SECONDARY,
302 PROP_SENSITIVE_PRIMARY,
303 PROP_SENSITIVE_SECONDARY,
304 PROP_TOOLTIP_TEXT_PRIMARY,
305 PROP_TOOLTIP_TEXT_SECONDARY,
306 PROP_TOOLTIP_MARKUP_PRIMARY,
307 PROP_TOOLTIP_MARKUP_SECONDARY,
309 PROP_EDITING_CANCELED,
310 PROP_PLACEHOLDER_TEXT,
314 static guint signals[LAST_SIGNAL] = { 0 };
323 DISPLAY_NORMAL, /* The entry text is being shown */
324 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
325 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
330 static void gtk_entry_editable_init (GtkEditableInterface *iface);
331 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
332 static void gtk_entry_set_property (GObject *object,
336 static void gtk_entry_get_property (GObject *object,
340 static void gtk_entry_finalize (GObject *object);
341 static void gtk_entry_dispose (GObject *object);
345 static void gtk_entry_destroy (GtkWidget *widget);
346 static void gtk_entry_realize (GtkWidget *widget);
347 static void gtk_entry_unrealize (GtkWidget *widget);
348 static void gtk_entry_map (GtkWidget *widget);
349 static void gtk_entry_unmap (GtkWidget *widget);
350 static void gtk_entry_get_preferred_width (GtkWidget *widget,
353 static void gtk_entry_get_preferred_height (GtkWidget *widget,
356 static void gtk_entry_size_allocate (GtkWidget *widget,
357 GtkAllocation *allocation);
358 static void gtk_entry_draw_frame (GtkWidget *widget,
359 GtkStyleContext *context,
361 static void gtk_entry_draw_progress (GtkWidget *widget,
362 GtkStyleContext *context,
364 static gint gtk_entry_draw (GtkWidget *widget,
366 static gint gtk_entry_button_press (GtkWidget *widget,
367 GdkEventButton *event);
368 static gint gtk_entry_button_release (GtkWidget *widget,
369 GdkEventButton *event);
370 static gint gtk_entry_enter_notify (GtkWidget *widget,
371 GdkEventCrossing *event);
372 static gint gtk_entry_leave_notify (GtkWidget *widget,
373 GdkEventCrossing *event);
374 static gint gtk_entry_motion_notify (GtkWidget *widget,
375 GdkEventMotion *event);
376 static gint gtk_entry_key_press (GtkWidget *widget,
378 static gint gtk_entry_key_release (GtkWidget *widget,
380 static gint gtk_entry_focus_in (GtkWidget *widget,
381 GdkEventFocus *event);
382 static gint gtk_entry_focus_out (GtkWidget *widget,
383 GdkEventFocus *event);
384 static void gtk_entry_grab_focus (GtkWidget *widget);
385 static void gtk_entry_style_updated (GtkWidget *widget);
386 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
389 gboolean keyboard_tip,
390 GtkTooltip *tooltip);
391 static void gtk_entry_direction_changed (GtkWidget *widget,
392 GtkTextDirection previous_dir);
393 static void gtk_entry_state_flags_changed (GtkWidget *widget,
394 GtkStateFlags previous_state);
395 static void gtk_entry_screen_changed (GtkWidget *widget,
396 GdkScreen *old_screen);
398 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
399 GdkDragContext *context,
403 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
404 GdkDragContext *context,
408 static void gtk_entry_drag_leave (GtkWidget *widget,
409 GdkDragContext *context,
411 static void gtk_entry_drag_data_received (GtkWidget *widget,
412 GdkDragContext *context,
415 GtkSelectionData *selection_data,
418 static void gtk_entry_drag_data_get (GtkWidget *widget,
419 GdkDragContext *context,
420 GtkSelectionData *selection_data,
423 static void gtk_entry_drag_data_delete (GtkWidget *widget,
424 GdkDragContext *context);
425 static void gtk_entry_drag_begin (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_entry_drag_end (GtkWidget *widget,
428 GdkDragContext *context);
431 /* GtkEditable method implementations
433 static void gtk_entry_insert_text (GtkEditable *editable,
434 const gchar *new_text,
435 gint new_text_length,
437 static void gtk_entry_delete_text (GtkEditable *editable,
440 static gchar * gtk_entry_get_chars (GtkEditable *editable,
443 static void gtk_entry_real_set_position (GtkEditable *editable,
445 static gint gtk_entry_get_position (GtkEditable *editable);
446 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
449 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
453 /* GtkCellEditable method implementations
455 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
458 /* Default signal handlers
460 static void gtk_entry_real_insert_text (GtkEditable *editable,
461 const gchar *new_text,
462 gint new_text_length,
464 static void gtk_entry_real_delete_text (GtkEditable *editable,
467 static void gtk_entry_move_cursor (GtkEntry *entry,
468 GtkMovementStep step,
470 gboolean extend_selection);
471 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
473 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
476 static void gtk_entry_backspace (GtkEntry *entry);
477 static void gtk_entry_cut_clipboard (GtkEntry *entry);
478 static void gtk_entry_copy_clipboard (GtkEntry *entry);
479 static void gtk_entry_paste_clipboard (GtkEntry *entry);
480 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
481 static void gtk_entry_select_all (GtkEntry *entry);
482 static void gtk_entry_real_activate (GtkEntry *entry);
483 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
485 static void keymap_direction_changed (GdkKeymap *keymap,
487 static void keymap_state_changed (GdkKeymap *keymap,
489 static void remove_capslock_feedback (GtkEntry *entry);
491 /* IM Context Callbacks
493 static void gtk_entry_commit_cb (GtkIMContext *context,
496 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
498 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
500 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
507 static void gtk_entry_enter_text (GtkEntry *entry,
509 static void gtk_entry_set_positions (GtkEntry *entry,
511 gint selection_bound);
512 static void gtk_entry_draw_text (GtkEntry *entry,
514 static void gtk_entry_draw_cursor (GtkEntry *entry,
517 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
518 gboolean include_preedit);
519 static void gtk_entry_reset_layout (GtkEntry *entry);
520 static void gtk_entry_recompute (GtkEntry *entry);
521 static gint gtk_entry_find_position (GtkEntry *entry,
523 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
527 static void gtk_entry_adjust_scroll (GtkEntry *entry);
528 static gint gtk_entry_move_visually (GtkEntry *editable,
531 static gint gtk_entry_move_logically (GtkEntry *entry,
534 static gint gtk_entry_move_forward_word (GtkEntry *entry,
536 gboolean allow_whitespace);
537 static gint gtk_entry_move_backward_word (GtkEntry *entry,
539 gboolean allow_whitespace);
540 static void gtk_entry_delete_whitespace (GtkEntry *entry);
541 static void gtk_entry_select_word (GtkEntry *entry);
542 static void gtk_entry_select_line (GtkEntry *entry);
543 static void gtk_entry_paste (GtkEntry *entry,
545 static void gtk_entry_update_primary_selection (GtkEntry *entry);
546 static void gtk_entry_do_popup (GtkEntry *entry,
547 GdkEventButton *event);
548 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
549 gboolean group_cycling);
550 static void gtk_entry_grab_notify (GtkWidget *widget,
551 gboolean was_grabbed);
552 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
553 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
554 static void gtk_entry_reset_blink_time (GtkEntry *entry);
555 static void gtk_entry_get_text_area_size (GtkEntry *entry,
560 static void get_text_area_size (GtkEntry *entry,
565 static void get_frame_size (GtkEntry *entry,
566 gboolean relative_to_window,
571 static void gtk_entry_move_adjustments (GtkEntry *entry);
572 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
573 GtkEntryIconPosition icon_pos);
574 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
575 static gboolean get_middle_click_paste (GtkEntry *entry);
578 static gint gtk_entry_completion_timeout (gpointer data);
579 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
582 static void gtk_entry_completion_changed (GtkWidget *entry,
584 static gboolean check_completion_callback (GtkEntryCompletion *completion);
585 static void clear_completion_callback (GtkEntry *entry,
587 static gboolean accept_completion_callback (GtkEntry *entry);
588 static void completion_insert_text_callback (GtkEntry *entry,
592 GtkEntryCompletion *completion);
593 static void completion_changed (GtkEntryCompletion *completion,
596 static void disconnect_completion_signals (GtkEntry *entry,
597 GtkEntryCompletion *completion);
598 static void connect_completion_signals (GtkEntry *entry,
599 GtkEntryCompletion *completion);
601 static void begin_change (GtkEntry *entry);
602 static void end_change (GtkEntry *entry);
603 static void emit_changed (GtkEntry *entry);
605 static void buffer_inserted_text (GtkEntryBuffer *buffer,
610 static void buffer_deleted_text (GtkEntryBuffer *buffer,
614 static void buffer_notify_text (GtkEntryBuffer *buffer,
617 static void buffer_notify_length (GtkEntryBuffer *buffer,
620 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
623 static void buffer_connect_signals (GtkEntry *entry);
624 static void buffer_disconnect_signals (GtkEntry *entry);
625 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
627 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
628 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
629 gtk_entry_editable_init)
630 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
631 gtk_entry_cell_editable_init))
634 add_move_binding (GtkBindingSet *binding_set,
637 GtkMovementStep step,
640 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
642 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
646 G_TYPE_BOOLEAN, FALSE);
648 /* Selection-extending version */
649 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
653 G_TYPE_BOOLEAN, TRUE);
657 gtk_entry_class_init (GtkEntryClass *class)
659 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
660 GtkWidgetClass *widget_class;
661 GtkBindingSet *binding_set;
663 widget_class = (GtkWidgetClass*) class;
665 gobject_class->dispose = gtk_entry_dispose;
666 gobject_class->finalize = gtk_entry_finalize;
667 gobject_class->set_property = gtk_entry_set_property;
668 gobject_class->get_property = gtk_entry_get_property;
670 widget_class->destroy = gtk_entry_destroy;
671 widget_class->map = gtk_entry_map;
672 widget_class->unmap = gtk_entry_unmap;
673 widget_class->realize = gtk_entry_realize;
674 widget_class->unrealize = gtk_entry_unrealize;
675 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
676 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
677 widget_class->size_allocate = gtk_entry_size_allocate;
678 widget_class->draw = gtk_entry_draw;
679 widget_class->enter_notify_event = gtk_entry_enter_notify;
680 widget_class->leave_notify_event = gtk_entry_leave_notify;
681 widget_class->button_press_event = gtk_entry_button_press;
682 widget_class->button_release_event = gtk_entry_button_release;
683 widget_class->motion_notify_event = gtk_entry_motion_notify;
684 widget_class->key_press_event = gtk_entry_key_press;
685 widget_class->key_release_event = gtk_entry_key_release;
686 widget_class->focus_in_event = gtk_entry_focus_in;
687 widget_class->focus_out_event = gtk_entry_focus_out;
688 widget_class->grab_focus = gtk_entry_grab_focus;
689 widget_class->style_updated = gtk_entry_style_updated;
690 widget_class->query_tooltip = gtk_entry_query_tooltip;
691 widget_class->drag_begin = gtk_entry_drag_begin;
692 widget_class->drag_end = gtk_entry_drag_end;
693 widget_class->direction_changed = gtk_entry_direction_changed;
694 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
695 widget_class->screen_changed = gtk_entry_screen_changed;
696 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
697 widget_class->grab_notify = gtk_entry_grab_notify;
699 widget_class->drag_drop = gtk_entry_drag_drop;
700 widget_class->drag_motion = gtk_entry_drag_motion;
701 widget_class->drag_leave = gtk_entry_drag_leave;
702 widget_class->drag_data_received = gtk_entry_drag_data_received;
703 widget_class->drag_data_get = gtk_entry_drag_data_get;
704 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
706 widget_class->popup_menu = gtk_entry_popup_menu;
708 class->move_cursor = gtk_entry_move_cursor;
709 class->insert_at_cursor = gtk_entry_insert_at_cursor;
710 class->delete_from_cursor = gtk_entry_delete_from_cursor;
711 class->backspace = gtk_entry_backspace;
712 class->cut_clipboard = gtk_entry_cut_clipboard;
713 class->copy_clipboard = gtk_entry_copy_clipboard;
714 class->paste_clipboard = gtk_entry_paste_clipboard;
715 class->toggle_overwrite = gtk_entry_toggle_overwrite;
716 class->activate = gtk_entry_real_activate;
717 class->get_text_area_size = gtk_entry_get_text_area_size;
719 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
720 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
721 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
722 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
724 g_object_class_override_property (gobject_class,
725 PROP_EDITING_CANCELED,
728 g_object_class_install_property (gobject_class,
730 g_param_spec_object ("buffer",
732 P_("Text buffer object which actually stores entry text"),
733 GTK_TYPE_ENTRY_BUFFER,
734 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
736 g_object_class_install_property (gobject_class,
737 PROP_CURSOR_POSITION,
738 g_param_spec_int ("cursor-position",
739 P_("Cursor Position"),
740 P_("The current position of the insertion cursor in chars"),
742 GTK_ENTRY_BUFFER_MAX_SIZE,
744 GTK_PARAM_READABLE));
746 g_object_class_install_property (gobject_class,
747 PROP_SELECTION_BOUND,
748 g_param_spec_int ("selection-bound",
749 P_("Selection Bound"),
750 P_("The position of the opposite end of the selection from the cursor in chars"),
752 GTK_ENTRY_BUFFER_MAX_SIZE,
754 GTK_PARAM_READABLE));
756 g_object_class_install_property (gobject_class,
758 g_param_spec_boolean ("editable",
760 P_("Whether the entry contents can be edited"),
762 GTK_PARAM_READWRITE));
764 g_object_class_install_property (gobject_class,
766 g_param_spec_int ("max-length",
767 P_("Maximum length"),
768 P_("Maximum number of characters for this entry. Zero if no maximum"),
770 GTK_ENTRY_BUFFER_MAX_SIZE,
772 GTK_PARAM_READWRITE));
773 g_object_class_install_property (gobject_class,
775 g_param_spec_boolean ("visibility",
777 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
779 GTK_PARAM_READWRITE));
781 g_object_class_install_property (gobject_class,
783 g_param_spec_boolean ("has-frame",
785 P_("FALSE removes outside bevel from entry"),
787 GTK_PARAM_READWRITE));
790 * GtkEntry:inner-border:
792 * Sets the text area's border between the text and the frame.
794 * Deprecated: 3.4: Use the standard border and padding CSS properties
795 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
796 * of this style property is ignored.
798 g_object_class_install_property (gobject_class,
800 g_param_spec_boxed ("inner-border",
802 P_("Border between text and frame. Overrides the inner-border style property"),
804 GTK_PARAM_READWRITE |
805 G_PARAM_DEPRECATED));
807 g_object_class_install_property (gobject_class,
809 g_param_spec_unichar ("invisible-char",
810 P_("Invisible character"),
811 P_("The character to use when masking entry contents (in \"password mode\")"),
813 GTK_PARAM_READWRITE));
815 g_object_class_install_property (gobject_class,
816 PROP_ACTIVATES_DEFAULT,
817 g_param_spec_boolean ("activates-default",
818 P_("Activates default"),
819 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
821 GTK_PARAM_READWRITE));
822 g_object_class_install_property (gobject_class,
824 g_param_spec_int ("width-chars",
825 P_("Width in chars"),
826 P_("Number of characters to leave space for in the entry"),
830 GTK_PARAM_READWRITE));
832 g_object_class_install_property (gobject_class,
834 g_param_spec_int ("scroll-offset",
836 P_("Number of pixels of the entry scrolled off the screen to the left"),
840 GTK_PARAM_READABLE));
842 g_object_class_install_property (gobject_class,
844 g_param_spec_string ("text",
846 P_("The contents of the entry"),
848 GTK_PARAM_READWRITE));
853 * The horizontal alignment, from 0 (left) to 1 (right).
854 * Reversed for RTL layouts.
858 g_object_class_install_property (gobject_class,
860 g_param_spec_float ("xalign",
862 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
866 GTK_PARAM_READWRITE));
869 * GtkEntry:truncate-multiline:
871 * When %TRUE, pasted multi-line text is truncated to the first line.
875 g_object_class_install_property (gobject_class,
876 PROP_TRUNCATE_MULTILINE,
877 g_param_spec_boolean ("truncate-multiline",
878 P_("Truncate multiline"),
879 P_("Whether to truncate multiline pastes to one line."),
881 GTK_PARAM_READWRITE));
884 * GtkEntry:shadow-type:
886 * Which kind of shadow to draw around the entry when
887 * #GtkEntry:has-frame is set to %TRUE.
891 g_object_class_install_property (gobject_class,
893 g_param_spec_enum ("shadow-type",
895 P_("Which kind of shadow to draw around the entry when has-frame is set"),
896 GTK_TYPE_SHADOW_TYPE,
898 GTK_PARAM_READWRITE));
901 * GtkEntry:overwrite-mode:
903 * If text is overwritten when typing in the #GtkEntry.
907 g_object_class_install_property (gobject_class,
909 g_param_spec_boolean ("overwrite-mode",
910 P_("Overwrite mode"),
911 P_("Whether new text overwrites existing text"),
913 GTK_PARAM_READWRITE));
916 * GtkEntry:text-length:
918 * The length of the text in the #GtkEntry.
922 g_object_class_install_property (gobject_class,
924 g_param_spec_uint ("text-length",
926 P_("Length of the text currently in the entry"),
930 GTK_PARAM_READABLE));
932 * GtkEntry:invisible-char-set:
934 * Whether the invisible char has been set for the #GtkEntry.
938 g_object_class_install_property (gobject_class,
939 PROP_INVISIBLE_CHAR_SET,
940 g_param_spec_boolean ("invisible-char-set",
941 P_("Invisible character set"),
942 P_("Whether the invisible character has been set"),
944 GTK_PARAM_READWRITE));
947 * GtkEntry:caps-lock-warning:
949 * Whether password entries will show a warning when Caps Lock is on.
951 * Note that the warning is shown using a secondary icon, and thus
952 * does not work if you are using the secondary icon position for some
957 g_object_class_install_property (gobject_class,
958 PROP_CAPS_LOCK_WARNING,
959 g_param_spec_boolean ("caps-lock-warning",
960 P_("Caps Lock warning"),
961 P_("Whether password entries will show a warning when Caps Lock is on"),
963 GTK_PARAM_READWRITE));
966 * GtkEntry:progress-fraction:
968 * The current fraction of the task that's been completed.
972 g_object_class_install_property (gobject_class,
973 PROP_PROGRESS_FRACTION,
974 g_param_spec_double ("progress-fraction",
975 P_("Progress Fraction"),
976 P_("The current fraction of the task that's been completed"),
980 GTK_PARAM_READWRITE));
983 * GtkEntry:progress-pulse-step:
985 * The fraction of total entry width to move the progress
986 * bouncing block for each call to gtk_entry_progress_pulse().
990 g_object_class_install_property (gobject_class,
991 PROP_PROGRESS_PULSE_STEP,
992 g_param_spec_double ("progress-pulse-step",
993 P_("Progress Pulse Step"),
994 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
998 GTK_PARAM_READWRITE));
1001 * GtkEntry:placeholder-text:
1003 * The text that will be displayed in the #GtkEntry when it is empty
1008 g_object_class_install_property (gobject_class,
1009 PROP_PLACEHOLDER_TEXT,
1010 g_param_spec_string ("placeholder-text",
1011 P_("Placeholder text"),
1012 P_("Show text in the entry when it's empty and unfocused"),
1014 GTK_PARAM_READWRITE));
1017 * GtkEntry:primary-icon-pixbuf:
1019 * A pixbuf to use as the primary icon for the entry.
1023 g_object_class_install_property (gobject_class,
1024 PROP_PIXBUF_PRIMARY,
1025 g_param_spec_object ("primary-icon-pixbuf",
1026 P_("Primary pixbuf"),
1027 P_("Primary pixbuf for the entry"),
1029 GTK_PARAM_READWRITE));
1032 * GtkEntry:secondary-icon-pixbuf:
1034 * An pixbuf to use as the secondary icon for the entry.
1038 g_object_class_install_property (gobject_class,
1039 PROP_PIXBUF_SECONDARY,
1040 g_param_spec_object ("secondary-icon-pixbuf",
1041 P_("Secondary pixbuf"),
1042 P_("Secondary pixbuf for the entry"),
1044 GTK_PARAM_READWRITE));
1047 * GtkEntry:primary-icon-stock:
1049 * The stock id to use for the primary icon for the entry.
1053 g_object_class_install_property (gobject_class,
1055 g_param_spec_string ("primary-icon-stock",
1056 P_("Primary stock ID"),
1057 P_("Stock ID for primary icon"),
1059 GTK_PARAM_READWRITE));
1062 * GtkEntry:secondary-icon-stock:
1064 * The stock id to use for the secondary icon for the entry.
1068 g_object_class_install_property (gobject_class,
1069 PROP_STOCK_SECONDARY,
1070 g_param_spec_string ("secondary-icon-stock",
1071 P_("Secondary stock ID"),
1072 P_("Stock ID for secondary icon"),
1074 GTK_PARAM_READWRITE));
1077 * GtkEntry:primary-icon-name:
1079 * The icon name to use for the primary icon for the entry.
1083 g_object_class_install_property (gobject_class,
1084 PROP_ICON_NAME_PRIMARY,
1085 g_param_spec_string ("primary-icon-name",
1086 P_("Primary icon name"),
1087 P_("Icon name for primary icon"),
1089 GTK_PARAM_READWRITE));
1092 * GtkEntry:secondary-icon-name:
1094 * The icon name to use for the secondary icon for the entry.
1098 g_object_class_install_property (gobject_class,
1099 PROP_ICON_NAME_SECONDARY,
1100 g_param_spec_string ("secondary-icon-name",
1101 P_("Secondary icon name"),
1102 P_("Icon name for secondary icon"),
1104 GTK_PARAM_READWRITE));
1107 * GtkEntry:primary-icon-gicon:
1109 * The #GIcon to use for the primary icon for the entry.
1113 g_object_class_install_property (gobject_class,
1115 g_param_spec_object ("primary-icon-gicon",
1116 P_("Primary GIcon"),
1117 P_("GIcon for primary icon"),
1119 GTK_PARAM_READWRITE));
1122 * GtkEntry:secondary-icon-gicon:
1124 * The #GIcon to use for the secondary icon for the entry.
1128 g_object_class_install_property (gobject_class,
1129 PROP_GICON_SECONDARY,
1130 g_param_spec_object ("secondary-icon-gicon",
1131 P_("Secondary GIcon"),
1132 P_("GIcon for secondary icon"),
1134 GTK_PARAM_READWRITE));
1137 * GtkEntry:primary-icon-storage-type:
1139 * The representation which is used for the primary icon of the entry.
1143 g_object_class_install_property (gobject_class,
1144 PROP_STORAGE_TYPE_PRIMARY,
1145 g_param_spec_enum ("primary-icon-storage-type",
1146 P_("Primary storage type"),
1147 P_("The representation being used for primary icon"),
1148 GTK_TYPE_IMAGE_TYPE,
1150 GTK_PARAM_READABLE));
1153 * GtkEntry:secondary-icon-storage-type:
1155 * The representation which is used for the secondary icon of the entry.
1159 g_object_class_install_property (gobject_class,
1160 PROP_STORAGE_TYPE_SECONDARY,
1161 g_param_spec_enum ("secondary-icon-storage-type",
1162 P_("Secondary storage type"),
1163 P_("The representation being used for secondary icon"),
1164 GTK_TYPE_IMAGE_TYPE,
1166 GTK_PARAM_READABLE));
1169 * GtkEntry:primary-icon-activatable:
1171 * Whether the primary icon is activatable.
1173 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1174 * signals only on sensitive, activatable icons.
1176 * Sensitive, but non-activatable icons can be used for purely
1177 * informational purposes.
1181 g_object_class_install_property (gobject_class,
1182 PROP_ACTIVATABLE_PRIMARY,
1183 g_param_spec_boolean ("primary-icon-activatable",
1184 P_("Primary icon activatable"),
1185 P_("Whether the primary icon is activatable"),
1187 GTK_PARAM_READWRITE));
1190 * GtkEntry:secondary-icon-activatable:
1192 * Whether the secondary icon is activatable.
1194 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1195 * signals only on sensitive, activatable icons.
1197 * Sensitive, but non-activatable icons can be used for purely
1198 * informational purposes.
1202 g_object_class_install_property (gobject_class,
1203 PROP_ACTIVATABLE_SECONDARY,
1204 g_param_spec_boolean ("secondary-icon-activatable",
1205 P_("Secondary icon activatable"),
1206 P_("Whether the secondary icon is activatable"),
1208 GTK_PARAM_READWRITE));
1212 * GtkEntry:primary-icon-sensitive:
1214 * Whether the primary icon is sensitive.
1216 * An insensitive icon appears grayed out. GTK+ does not emit the
1217 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1218 * does not allow DND from insensitive icons.
1220 * An icon should be set insensitive if the action that would trigger
1221 * when clicked is currently not available.
1225 g_object_class_install_property (gobject_class,
1226 PROP_SENSITIVE_PRIMARY,
1227 g_param_spec_boolean ("primary-icon-sensitive",
1228 P_("Primary icon sensitive"),
1229 P_("Whether the primary icon is sensitive"),
1231 GTK_PARAM_READWRITE));
1234 * GtkEntry:secondary-icon-sensitive:
1236 * Whether the secondary icon is sensitive.
1238 * An insensitive icon appears grayed out. GTK+ does not emit the
1239 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1240 * does not allow DND from insensitive icons.
1242 * An icon should be set insensitive if the action that would trigger
1243 * when clicked is currently not available.
1247 g_object_class_install_property (gobject_class,
1248 PROP_SENSITIVE_SECONDARY,
1249 g_param_spec_boolean ("secondary-icon-sensitive",
1250 P_("Secondary icon sensitive"),
1251 P_("Whether the secondary icon is sensitive"),
1253 GTK_PARAM_READWRITE));
1256 * GtkEntry:primary-icon-tooltip-text:
1258 * The contents of the tooltip on the primary icon.
1260 * Also see gtk_entry_set_icon_tooltip_text().
1264 g_object_class_install_property (gobject_class,
1265 PROP_TOOLTIP_TEXT_PRIMARY,
1266 g_param_spec_string ("primary-icon-tooltip-text",
1267 P_("Primary icon tooltip text"),
1268 P_("The contents of the tooltip on the primary icon"),
1270 GTK_PARAM_READWRITE));
1273 * GtkEntry:secondary-icon-tooltip-text:
1275 * The contents of the tooltip on the secondary icon.
1277 * Also see gtk_entry_set_icon_tooltip_text().
1281 g_object_class_install_property (gobject_class,
1282 PROP_TOOLTIP_TEXT_SECONDARY,
1283 g_param_spec_string ("secondary-icon-tooltip-text",
1284 P_("Secondary icon tooltip text"),
1285 P_("The contents of the tooltip on the secondary icon"),
1287 GTK_PARAM_READWRITE));
1290 * GtkEntry:primary-icon-tooltip-markup:
1292 * The contents of the tooltip on the primary icon, which is marked up
1293 * with the <link linkend="PangoMarkupFormat">Pango text markup
1296 * Also see gtk_entry_set_icon_tooltip_markup().
1300 g_object_class_install_property (gobject_class,
1301 PROP_TOOLTIP_MARKUP_PRIMARY,
1302 g_param_spec_string ("primary-icon-tooltip-markup",
1303 P_("Primary icon tooltip markup"),
1304 P_("The contents of the tooltip on the primary icon"),
1306 GTK_PARAM_READWRITE));
1309 * GtkEntry:secondary-icon-tooltip-markup:
1311 * The contents of the tooltip on the secondary icon, which is marked up
1312 * with the <link linkend="PangoMarkupFormat">Pango text markup
1315 * Also see gtk_entry_set_icon_tooltip_markup().
1319 g_object_class_install_property (gobject_class,
1320 PROP_TOOLTIP_MARKUP_SECONDARY,
1321 g_param_spec_string ("secondary-icon-tooltip-markup",
1322 P_("Secondary icon tooltip markup"),
1323 P_("The contents of the tooltip on the secondary icon"),
1325 GTK_PARAM_READWRITE));
1328 * GtkEntry:im-module:
1330 * Which IM (input method) module should be used for this entry.
1331 * See #GtkIMContext.
1333 * Setting this to a non-%NULL value overrides the
1334 * system-wide IM module setting. See the GtkSettings
1335 * #GtkSettings:gtk-im-module property.
1339 g_object_class_install_property (gobject_class,
1341 g_param_spec_string ("im-module",
1343 P_("Which IM module should be used"),
1345 GTK_PARAM_READWRITE));
1348 * GtkEntry:completion:
1350 * The auxiliary completion object to use with the entry.
1354 g_object_class_install_property (gobject_class,
1356 g_param_spec_object ("completion",
1358 P_("The auxiliary completion object"),
1359 GTK_TYPE_ENTRY_COMPLETION,
1360 GTK_PARAM_READWRITE));
1363 * GtkEntry:icon-prelight:
1365 * The prelight style property determines whether activatable
1366 * icons prelight on mouseover.
1370 gtk_widget_class_install_style_property (widget_class,
1371 g_param_spec_boolean ("icon-prelight",
1372 P_("Icon Prelight"),
1373 P_("Whether activatable icons should prelight when hovered"),
1375 GTK_PARAM_READABLE));
1378 * GtkEntry:progress-border:
1380 * The border around the progress bar in the entry.
1384 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1385 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1386 * property is ignored.
1388 gtk_widget_class_install_style_property (widget_class,
1389 g_param_spec_boxed ("progress-border",
1390 P_("Progress Border"),
1391 P_("Border around the progress bar"),
1393 GTK_PARAM_READABLE |
1394 G_PARAM_DEPRECATED));
1397 * GtkEntry:invisible-char:
1399 * The invisible character is used when masking entry contents (in
1400 * \"password mode\")"). When it is not explicitly set with the
1401 * #GtkEntry:invisible-char property, GTK+ determines the character
1402 * to use from a list of possible candidates, depending on availability
1403 * in the current font.
1405 * This style property allows the theme to prepend a character
1406 * to the list of candidates.
1410 gtk_widget_class_install_style_property (widget_class,
1411 g_param_spec_unichar ("invisible-char",
1412 P_("Invisible character"),
1413 P_("The character to use when masking entry contents (in \"password mode\")"),
1415 GTK_PARAM_READABLE));
1418 * GtkEntry::populate-popup:
1419 * @entry: The entry on which the signal is emitted
1420 * @menu: the menu that is being populated
1422 * The ::populate-popup signal gets emitted before showing the
1423 * context menu of the entry.
1425 * If you need to add items to the context menu, connect
1426 * to this signal and append your menuitems to the @menu.
1428 signals[POPULATE_POPUP] =
1429 g_signal_new (I_("populate-popup"),
1430 G_OBJECT_CLASS_TYPE (gobject_class),
1432 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1434 _gtk_marshal_VOID__OBJECT,
1438 /* Action signals */
1441 * GtkEntry::activate:
1442 * @entry: The entry on which the signal is emitted
1444 * The ::activate signal is emitted when the user hits
1447 * While this signal is used as a
1448 * <link linkend="keybinding-signals">keybinding signal</link>,
1449 * it is also commonly used by applications to intercept
1450 * activation of entries.
1452 * The default bindings for this signal are all forms of the Enter key.
1455 g_signal_new (I_("activate"),
1456 G_OBJECT_CLASS_TYPE (gobject_class),
1457 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1458 G_STRUCT_OFFSET (GtkEntryClass, activate),
1460 _gtk_marshal_VOID__VOID,
1462 widget_class->activate_signal = signals[ACTIVATE];
1465 * GtkEntry::move-cursor:
1466 * @entry: the object which received the signal
1467 * @step: the granularity of the move, as a #GtkMovementStep
1468 * @count: the number of @step units to move
1469 * @extend_selection: %TRUE if the move should extend the selection
1471 * The ::move-cursor signal is a
1472 * <link linkend="keybinding-signals">keybinding signal</link>
1473 * which gets emitted when the user initiates a cursor movement.
1474 * If the cursor is not visible in @entry, this signal causes
1475 * the viewport to be moved instead.
1477 * Applications should not connect to it, but may emit it with
1478 * g_signal_emit_by_name() if they need to control the cursor
1481 * The default bindings for this signal come in two variants,
1482 * the variant with the Shift modifier extends the selection,
1483 * the variant without the Shift modifer does not.
1484 * There are too many key combinations to list them all here.
1486 * <listitem>Arrow keys move by individual characters/lines</listitem>
1487 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1488 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1491 signals[MOVE_CURSOR] =
1492 g_signal_new (I_("move-cursor"),
1493 G_OBJECT_CLASS_TYPE (gobject_class),
1494 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1495 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1497 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1499 GTK_TYPE_MOVEMENT_STEP,
1504 * GtkEntry::insert-at-cursor:
1505 * @entry: the object which received the signal
1506 * @string: the string to insert
1508 * The ::insert-at-cursor signal is a
1509 * <link linkend="keybinding-signals">keybinding signal</link>
1510 * which gets emitted when the user initiates the insertion of a
1511 * fixed string at the cursor.
1513 * This signal has no default bindings.
1515 signals[INSERT_AT_CURSOR] =
1516 g_signal_new (I_("insert-at-cursor"),
1517 G_OBJECT_CLASS_TYPE (gobject_class),
1518 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1519 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1521 _gtk_marshal_VOID__STRING,
1526 * GtkEntry::delete-from-cursor:
1527 * @entry: the object which received the signal
1528 * @type: the granularity of the deletion, as a #GtkDeleteType
1529 * @count: the number of @type units to delete
1531 * The ::delete-from-cursor signal is a
1532 * <link linkend="keybinding-signals">keybinding signal</link>
1533 * which gets emitted when the user initiates a text deletion.
1535 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1536 * if there is one, otherwise it deletes the requested number
1539 * The default bindings for this signal are
1540 * Delete for deleting a character and Ctrl-Delete for
1543 signals[DELETE_FROM_CURSOR] =
1544 g_signal_new (I_("delete-from-cursor"),
1545 G_OBJECT_CLASS_TYPE (gobject_class),
1546 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1547 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1549 _gtk_marshal_VOID__ENUM_INT,
1551 GTK_TYPE_DELETE_TYPE,
1555 * GtkEntry::backspace:
1556 * @entry: the object which received the signal
1558 * The ::backspace signal is a
1559 * <link linkend="keybinding-signals">keybinding signal</link>
1560 * which gets emitted when the user asks for it.
1562 * The default bindings for this signal are
1563 * Backspace and Shift-Backspace.
1565 signals[BACKSPACE] =
1566 g_signal_new (I_("backspace"),
1567 G_OBJECT_CLASS_TYPE (gobject_class),
1568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1569 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1571 _gtk_marshal_VOID__VOID,
1575 * GtkEntry::cut-clipboard:
1576 * @entry: the object which received the signal
1578 * The ::cut-clipboard signal is a
1579 * <link linkend="keybinding-signals">keybinding signal</link>
1580 * which gets emitted to cut the selection to the clipboard.
1582 * The default bindings for this signal are
1583 * Ctrl-x and Shift-Delete.
1585 signals[CUT_CLIPBOARD] =
1586 g_signal_new (I_("cut-clipboard"),
1587 G_OBJECT_CLASS_TYPE (gobject_class),
1588 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1589 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1591 _gtk_marshal_VOID__VOID,
1595 * GtkEntry::copy-clipboard:
1596 * @entry: the object which received the signal
1598 * The ::copy-clipboard signal is a
1599 * <link linkend="keybinding-signals">keybinding signal</link>
1600 * which gets emitted to copy the selection to the clipboard.
1602 * The default bindings for this signal are
1603 * Ctrl-c and Ctrl-Insert.
1605 signals[COPY_CLIPBOARD] =
1606 g_signal_new (I_("copy-clipboard"),
1607 G_OBJECT_CLASS_TYPE (gobject_class),
1608 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1609 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1611 _gtk_marshal_VOID__VOID,
1615 * GtkEntry::paste-clipboard:
1616 * @entry: the object which received the signal
1618 * The ::paste-clipboard signal is a
1619 * <link linkend="keybinding-signals">keybinding signal</link>
1620 * which gets emitted to paste the contents of the clipboard
1621 * into the text view.
1623 * The default bindings for this signal are
1624 * Ctrl-v and Shift-Insert.
1626 signals[PASTE_CLIPBOARD] =
1627 g_signal_new (I_("paste-clipboard"),
1628 G_OBJECT_CLASS_TYPE (gobject_class),
1629 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1630 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1632 _gtk_marshal_VOID__VOID,
1636 * GtkEntry::toggle-overwrite:
1637 * @entry: the object which received the signal
1639 * The ::toggle-overwrite signal is a
1640 * <link linkend="keybinding-signals">keybinding signal</link>
1641 * which gets emitted to toggle the overwrite mode of the entry.
1643 * The default bindings for this signal is Insert.
1645 signals[TOGGLE_OVERWRITE] =
1646 g_signal_new (I_("toggle-overwrite"),
1647 G_OBJECT_CLASS_TYPE (gobject_class),
1648 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1649 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1651 _gtk_marshal_VOID__VOID,
1655 * GtkEntry::icon-press:
1656 * @entry: The entry on which the signal is emitted
1657 * @icon_pos: The position of the clicked icon
1658 * @event: (type Gdk.EventButton): the button press event
1660 * The ::icon-press signal is emitted when an activatable icon
1665 signals[ICON_PRESS] =
1666 g_signal_new (I_("icon-press"),
1667 G_TYPE_FROM_CLASS (gobject_class),
1671 _gtk_marshal_VOID__ENUM_BOXED,
1673 GTK_TYPE_ENTRY_ICON_POSITION,
1674 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1677 * GtkEntry::icon-release:
1678 * @entry: The entry on which the signal is emitted
1679 * @icon_pos: The position of the clicked icon
1680 * @event: (type Gdk.EventButton): the button release event
1682 * The ::icon-release signal is emitted on the button release from a
1683 * mouse click over an activatable icon.
1687 signals[ICON_RELEASE] =
1688 g_signal_new (I_("icon-release"),
1689 G_TYPE_FROM_CLASS (gobject_class),
1693 _gtk_marshal_VOID__ENUM_BOXED,
1695 GTK_TYPE_ENTRY_ICON_POSITION,
1696 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1699 * GtkEntry::preedit-changed:
1700 * @entry: the object which received the signal
1701 * @preedit: the current preedit string
1703 * If an input method is used, the typed text will not immediately
1704 * be committed to the buffer. So if you are interested in the text,
1705 * connect to this signal.
1709 signals[PREEDIT_CHANGED] =
1710 g_signal_new_class_handler (I_("preedit-changed"),
1711 G_OBJECT_CLASS_TYPE (gobject_class),
1712 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1715 _gtk_marshal_VOID__STRING,
1724 binding_set = gtk_binding_set_by_class (class);
1726 /* Moving the insertion point */
1727 add_move_binding (binding_set, GDK_KEY_Right, 0,
1728 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1730 add_move_binding (binding_set, GDK_KEY_Left, 0,
1731 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1733 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1734 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1736 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1737 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1739 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1740 GTK_MOVEMENT_WORDS, 1);
1742 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1743 GTK_MOVEMENT_WORDS, -1);
1745 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1746 GTK_MOVEMENT_WORDS, 1);
1748 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1749 GTK_MOVEMENT_WORDS, -1);
1751 add_move_binding (binding_set, GDK_KEY_Home, 0,
1752 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1754 add_move_binding (binding_set, GDK_KEY_End, 0,
1755 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1757 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1758 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1760 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1761 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1763 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1764 GTK_MOVEMENT_BUFFER_ENDS, -1);
1766 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1767 GTK_MOVEMENT_BUFFER_ENDS, 1);
1769 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1770 GTK_MOVEMENT_BUFFER_ENDS, -1);
1772 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1773 GTK_MOVEMENT_BUFFER_ENDS, 1);
1777 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1779 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1781 G_TYPE_BOOLEAN, FALSE);
1782 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1784 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1786 G_TYPE_BOOLEAN, TRUE);
1788 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1790 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1792 G_TYPE_BOOLEAN, FALSE);
1793 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1795 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1797 G_TYPE_BOOLEAN, TRUE);
1800 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1802 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1804 G_TYPE_BOOLEAN, FALSE);
1805 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1807 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1809 G_TYPE_BOOLEAN, FALSE);
1813 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1815 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1817 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1821 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1822 "delete-from-cursor", 2,
1823 G_TYPE_ENUM, GTK_DELETE_CHARS,
1826 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1827 "delete-from-cursor", 2,
1828 G_TYPE_ENUM, GTK_DELETE_CHARS,
1831 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1834 /* Make this do the same as Backspace, to help with mis-typing */
1835 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1838 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1839 "delete-from-cursor", 2,
1840 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1844 "delete-from-cursor", 2,
1845 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1849 "delete-from-cursor", 2,
1850 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1853 /* Cut/copy/paste */
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1856 "cut-clipboard", 0);
1857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1858 "copy-clipboard", 0);
1859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1860 "paste-clipboard", 0);
1862 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1863 "cut-clipboard", 0);
1864 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1865 "copy-clipboard", 0);
1866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1867 "paste-clipboard", 0);
1870 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1871 "toggle-overwrite", 0);
1872 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1873 "toggle-overwrite", 0);
1876 * GtkEntry:inner-border:
1878 * Sets the text area's border between the text and the frame.
1882 * Deprecated: 3.4: Use the standard border and padding CSS properties
1883 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1884 * of this style property is ignored.
1886 gtk_widget_class_install_style_property (widget_class,
1887 g_param_spec_boxed ("inner-border",
1889 P_("Border between text and frame."),
1891 GTK_PARAM_READABLE |
1892 G_PARAM_DEPRECATED));
1894 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1896 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1900 gtk_entry_editable_init (GtkEditableInterface *iface)
1902 iface->do_insert_text = gtk_entry_insert_text;
1903 iface->do_delete_text = gtk_entry_delete_text;
1904 iface->insert_text = gtk_entry_real_insert_text;
1905 iface->delete_text = gtk_entry_real_delete_text;
1906 iface->get_chars = gtk_entry_get_chars;
1907 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1908 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1909 iface->set_position = gtk_entry_real_set_position;
1910 iface->get_position = gtk_entry_get_position;
1914 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1916 iface->start_editing = gtk_entry_start_editing;
1919 /* for deprecated properties */
1921 gtk_entry_do_set_inner_border (GtkEntry *entry,
1922 const GtkBorder *border)
1925 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1926 gtk_border_copy (border),
1927 (GDestroyNotify) gtk_border_free);
1929 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1931 g_object_notify (G_OBJECT (entry), "inner-border");
1934 static const GtkBorder *
1935 gtk_entry_do_get_inner_border (GtkEntry *entry)
1937 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1941 gtk_entry_set_property (GObject *object,
1943 const GValue *value,
1946 GtkEntry *entry = GTK_ENTRY (object);
1947 GtkEntryPrivate *priv = entry->priv;
1952 gtk_entry_set_buffer (entry, g_value_get_object (value));
1957 gboolean new_value = g_value_get_boolean (value);
1959 if (new_value != priv->editable)
1961 GtkWidget *widget = GTK_WIDGET (entry);
1965 _gtk_entry_reset_im_context (entry);
1966 if (gtk_widget_has_focus (widget))
1967 gtk_im_context_focus_out (priv->im_context);
1969 priv->preedit_length = 0;
1970 priv->preedit_cursor = 0;
1973 priv->editable = new_value;
1975 if (new_value && gtk_widget_has_focus (widget))
1976 gtk_im_context_focus_in (priv->im_context);
1978 gtk_widget_queue_draw (widget);
1983 case PROP_MAX_LENGTH:
1984 gtk_entry_set_max_length (entry, g_value_get_int (value));
1987 case PROP_VISIBILITY:
1988 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1991 case PROP_HAS_FRAME:
1992 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1995 case PROP_INNER_BORDER:
1996 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1999 case PROP_INVISIBLE_CHAR:
2000 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2003 case PROP_ACTIVATES_DEFAULT:
2004 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2007 case PROP_WIDTH_CHARS:
2008 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2012 gtk_entry_set_text (entry, g_value_get_string (value));
2016 gtk_entry_set_alignment (entry, g_value_get_float (value));
2019 case PROP_TRUNCATE_MULTILINE:
2020 priv->truncate_multiline = g_value_get_boolean (value);
2023 case PROP_SHADOW_TYPE:
2024 priv->shadow_type = g_value_get_enum (value);
2027 case PROP_OVERWRITE_MODE:
2028 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2031 case PROP_INVISIBLE_CHAR_SET:
2032 if (g_value_get_boolean (value))
2033 priv->invisible_char_set = TRUE;
2035 gtk_entry_unset_invisible_char (entry);
2038 case PROP_CAPS_LOCK_WARNING:
2039 priv->caps_lock_warning = g_value_get_boolean (value);
2042 case PROP_PROGRESS_FRACTION:
2043 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2046 case PROP_PROGRESS_PULSE_STEP:
2047 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2050 case PROP_PLACEHOLDER_TEXT:
2051 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2054 case PROP_PIXBUF_PRIMARY:
2055 gtk_entry_set_icon_from_pixbuf (entry,
2056 GTK_ENTRY_ICON_PRIMARY,
2057 g_value_get_object (value));
2060 case PROP_PIXBUF_SECONDARY:
2061 gtk_entry_set_icon_from_pixbuf (entry,
2062 GTK_ENTRY_ICON_SECONDARY,
2063 g_value_get_object (value));
2066 case PROP_STOCK_PRIMARY:
2067 gtk_entry_set_icon_from_stock (entry,
2068 GTK_ENTRY_ICON_PRIMARY,
2069 g_value_get_string (value));
2072 case PROP_STOCK_SECONDARY:
2073 gtk_entry_set_icon_from_stock (entry,
2074 GTK_ENTRY_ICON_SECONDARY,
2075 g_value_get_string (value));
2078 case PROP_ICON_NAME_PRIMARY:
2079 gtk_entry_set_icon_from_icon_name (entry,
2080 GTK_ENTRY_ICON_PRIMARY,
2081 g_value_get_string (value));
2084 case PROP_ICON_NAME_SECONDARY:
2085 gtk_entry_set_icon_from_icon_name (entry,
2086 GTK_ENTRY_ICON_SECONDARY,
2087 g_value_get_string (value));
2090 case PROP_GICON_PRIMARY:
2091 gtk_entry_set_icon_from_gicon (entry,
2092 GTK_ENTRY_ICON_PRIMARY,
2093 g_value_get_object (value));
2096 case PROP_GICON_SECONDARY:
2097 gtk_entry_set_icon_from_gicon (entry,
2098 GTK_ENTRY_ICON_SECONDARY,
2099 g_value_get_object (value));
2102 case PROP_ACTIVATABLE_PRIMARY:
2103 gtk_entry_set_icon_activatable (entry,
2104 GTK_ENTRY_ICON_PRIMARY,
2105 g_value_get_boolean (value));
2108 case PROP_ACTIVATABLE_SECONDARY:
2109 gtk_entry_set_icon_activatable (entry,
2110 GTK_ENTRY_ICON_SECONDARY,
2111 g_value_get_boolean (value));
2114 case PROP_SENSITIVE_PRIMARY:
2115 gtk_entry_set_icon_sensitive (entry,
2116 GTK_ENTRY_ICON_PRIMARY,
2117 g_value_get_boolean (value));
2120 case PROP_SENSITIVE_SECONDARY:
2121 gtk_entry_set_icon_sensitive (entry,
2122 GTK_ENTRY_ICON_SECONDARY,
2123 g_value_get_boolean (value));
2126 case PROP_TOOLTIP_TEXT_PRIMARY:
2127 gtk_entry_set_icon_tooltip_text (entry,
2128 GTK_ENTRY_ICON_PRIMARY,
2129 g_value_get_string (value));
2132 case PROP_TOOLTIP_TEXT_SECONDARY:
2133 gtk_entry_set_icon_tooltip_text (entry,
2134 GTK_ENTRY_ICON_SECONDARY,
2135 g_value_get_string (value));
2138 case PROP_TOOLTIP_MARKUP_PRIMARY:
2139 gtk_entry_set_icon_tooltip_markup (entry,
2140 GTK_ENTRY_ICON_PRIMARY,
2141 g_value_get_string (value));
2144 case PROP_TOOLTIP_MARKUP_SECONDARY:
2145 gtk_entry_set_icon_tooltip_markup (entry,
2146 GTK_ENTRY_ICON_SECONDARY,
2147 g_value_get_string (value));
2150 case PROP_IM_MODULE:
2151 g_free (priv->im_module);
2152 priv->im_module = g_value_dup_string (value);
2153 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2154 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2157 case PROP_EDITING_CANCELED:
2158 priv->editing_canceled = g_value_get_boolean (value);
2161 case PROP_COMPLETION:
2162 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2165 case PROP_SCROLL_OFFSET:
2166 case PROP_CURSOR_POSITION:
2168 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2174 gtk_entry_get_property (GObject *object,
2179 GtkEntry *entry = GTK_ENTRY (object);
2180 GtkEntryPrivate *priv = entry->priv;
2185 g_value_set_object (value, gtk_entry_get_buffer (entry));
2188 case PROP_CURSOR_POSITION:
2189 g_value_set_int (value, priv->current_pos);
2192 case PROP_SELECTION_BOUND:
2193 g_value_set_int (value, priv->selection_bound);
2197 g_value_set_boolean (value, priv->editable);
2200 case PROP_MAX_LENGTH:
2201 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2204 case PROP_VISIBILITY:
2205 g_value_set_boolean (value, priv->visible);
2208 case PROP_HAS_FRAME:
2209 g_value_set_boolean (value, priv->has_frame);
2212 case PROP_INNER_BORDER:
2213 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2216 case PROP_INVISIBLE_CHAR:
2217 g_value_set_uint (value, priv->invisible_char);
2220 case PROP_ACTIVATES_DEFAULT:
2221 g_value_set_boolean (value, priv->activates_default);
2224 case PROP_WIDTH_CHARS:
2225 g_value_set_int (value, priv->width_chars);
2228 case PROP_SCROLL_OFFSET:
2229 g_value_set_int (value, priv->scroll_offset);
2233 g_value_set_string (value, gtk_entry_get_text (entry));
2237 g_value_set_float (value, gtk_entry_get_alignment (entry));
2240 case PROP_TRUNCATE_MULTILINE:
2241 g_value_set_boolean (value, priv->truncate_multiline);
2244 case PROP_SHADOW_TYPE:
2245 g_value_set_enum (value, priv->shadow_type);
2248 case PROP_OVERWRITE_MODE:
2249 g_value_set_boolean (value, priv->overwrite_mode);
2252 case PROP_TEXT_LENGTH:
2253 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2256 case PROP_INVISIBLE_CHAR_SET:
2257 g_value_set_boolean (value, priv->invisible_char_set);
2260 case PROP_IM_MODULE:
2261 g_value_set_string (value, priv->im_module);
2264 case PROP_CAPS_LOCK_WARNING:
2265 g_value_set_boolean (value, priv->caps_lock_warning);
2268 case PROP_PROGRESS_FRACTION:
2269 g_value_set_double (value, priv->progress_fraction);
2272 case PROP_PROGRESS_PULSE_STEP:
2273 g_value_set_double (value, priv->progress_pulse_fraction);
2276 case PROP_PLACEHOLDER_TEXT:
2277 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2280 case PROP_PIXBUF_PRIMARY:
2281 g_value_set_object (value,
2282 gtk_entry_get_icon_pixbuf (entry,
2283 GTK_ENTRY_ICON_PRIMARY));
2286 case PROP_PIXBUF_SECONDARY:
2287 g_value_set_object (value,
2288 gtk_entry_get_icon_pixbuf (entry,
2289 GTK_ENTRY_ICON_SECONDARY));
2292 case PROP_STOCK_PRIMARY:
2293 g_value_set_string (value,
2294 gtk_entry_get_icon_stock (entry,
2295 GTK_ENTRY_ICON_PRIMARY));
2298 case PROP_STOCK_SECONDARY:
2299 g_value_set_string (value,
2300 gtk_entry_get_icon_stock (entry,
2301 GTK_ENTRY_ICON_SECONDARY));
2304 case PROP_ICON_NAME_PRIMARY:
2305 g_value_set_string (value,
2306 gtk_entry_get_icon_name (entry,
2307 GTK_ENTRY_ICON_PRIMARY));
2310 case PROP_ICON_NAME_SECONDARY:
2311 g_value_set_string (value,
2312 gtk_entry_get_icon_name (entry,
2313 GTK_ENTRY_ICON_SECONDARY));
2316 case PROP_GICON_PRIMARY:
2317 g_value_set_object (value,
2318 gtk_entry_get_icon_gicon (entry,
2319 GTK_ENTRY_ICON_PRIMARY));
2322 case PROP_GICON_SECONDARY:
2323 g_value_set_object (value,
2324 gtk_entry_get_icon_gicon (entry,
2325 GTK_ENTRY_ICON_SECONDARY));
2328 case PROP_STORAGE_TYPE_PRIMARY:
2329 g_value_set_enum (value,
2330 gtk_entry_get_icon_storage_type (entry,
2331 GTK_ENTRY_ICON_PRIMARY));
2334 case PROP_STORAGE_TYPE_SECONDARY:
2335 g_value_set_enum (value,
2336 gtk_entry_get_icon_storage_type (entry,
2337 GTK_ENTRY_ICON_SECONDARY));
2340 case PROP_ACTIVATABLE_PRIMARY:
2341 g_value_set_boolean (value,
2342 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2345 case PROP_ACTIVATABLE_SECONDARY:
2346 g_value_set_boolean (value,
2347 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2350 case PROP_SENSITIVE_PRIMARY:
2351 g_value_set_boolean (value,
2352 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2355 case PROP_SENSITIVE_SECONDARY:
2356 g_value_set_boolean (value,
2357 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2360 case PROP_TOOLTIP_TEXT_PRIMARY:
2361 g_value_take_string (value,
2362 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2365 case PROP_TOOLTIP_TEXT_SECONDARY:
2366 g_value_take_string (value,
2367 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2370 case PROP_TOOLTIP_MARKUP_PRIMARY:
2371 g_value_take_string (value,
2372 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2375 case PROP_TOOLTIP_MARKUP_SECONDARY:
2376 g_value_take_string (value,
2377 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2380 case PROP_EDITING_CANCELED:
2381 g_value_set_boolean (value,
2382 priv->editing_canceled);
2385 case PROP_COMPLETION:
2386 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2390 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2396 find_invisible_char (GtkWidget *widget)
2398 PangoLayout *layout;
2399 PangoAttrList *attr_list;
2401 gunichar invisible_chars [] = {
2403 0x25cf, /* BLACK CIRCLE */
2404 0x2022, /* BULLET */
2405 0x2731, /* HEAVY ASTERISK */
2406 0x273a /* SIXTEEN POINTED ASTERISK */
2409 gtk_widget_style_get (widget,
2410 "invisible-char", &invisible_chars[0],
2413 layout = gtk_widget_create_pango_layout (widget, NULL);
2415 attr_list = pango_attr_list_new ();
2416 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2418 pango_layout_set_attributes (layout, attr_list);
2419 pango_attr_list_unref (attr_list);
2421 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2423 gchar text[7] = { 0, };
2426 len = g_unichar_to_utf8 (invisible_chars[i], text);
2427 pango_layout_set_text (layout, text, len);
2429 count = pango_layout_get_unknown_glyphs_count (layout);
2433 g_object_unref (layout);
2434 return invisible_chars[i];
2438 g_object_unref (layout);
2444 gtk_entry_init (GtkEntry *entry)
2446 GtkStyleContext *context;
2447 GtkEntryPrivate *priv;
2449 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2454 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2455 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2457 priv->editable = TRUE;
2458 priv->visible = TRUE;
2459 priv->dnd_position = -1;
2460 priv->width_chars = -1;
2461 priv->is_cell_renderer = FALSE;
2462 priv->editing_canceled = FALSE;
2463 priv->has_frame = TRUE;
2464 priv->truncate_multiline = FALSE;
2465 priv->shadow_type = GTK_SHADOW_IN;
2467 priv->caps_lock_warning = TRUE;
2468 priv->caps_lock_warning_shown = FALSE;
2469 priv->progress_fraction = 0.0;
2470 priv->progress_pulse_fraction = 0.1;
2472 gtk_drag_dest_set (GTK_WIDGET (entry),
2473 GTK_DEST_DEFAULT_HIGHLIGHT,
2475 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2476 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2478 /* This object is completely private. No external entity can gain a reference
2479 * to it; so we create it here and destroy it in finalize().
2481 priv->im_context = gtk_im_multicontext_new ();
2483 g_signal_connect (priv->im_context, "commit",
2484 G_CALLBACK (gtk_entry_commit_cb), entry);
2485 g_signal_connect (priv->im_context, "preedit-changed",
2486 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2487 g_signal_connect (priv->im_context, "retrieve-surrounding",
2488 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2489 g_signal_connect (priv->im_context, "delete-surrounding",
2490 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2492 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2493 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2495 gtk_entry_update_cached_style_values (entry);
2499 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2500 GtkStyleContext *context,
2501 GtkEntryIconPosition icon_pos)
2503 GtkEntryPrivate *priv = entry->priv;
2504 EntryIconInfo *icon_info = priv->icons[icon_pos];
2506 GtkStateFlags state;
2508 widget = GTK_WIDGET (entry);
2509 state = gtk_widget_get_state_flags (widget);
2511 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2513 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2514 state |= GTK_STATE_FLAG_INSENSITIVE;
2515 else if (icon_info->prelight)
2516 state |= GTK_STATE_FLAG_PRELIGHT;
2518 gtk_style_context_save (context);
2520 gtk_style_context_set_state (context, state);
2521 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2523 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2525 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2526 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2528 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2532 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2533 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2535 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2540 get_icon_width (GtkEntry *entry,
2541 GtkEntryIconPosition icon_pos)
2543 GtkEntryPrivate *priv = entry->priv;
2544 EntryIconInfo *icon_info = priv->icons[icon_pos];
2545 GtkStyleContext *context;
2552 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2553 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2554 gtk_style_context_get_padding (context, 0, &padding);
2556 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2558 gtk_style_context_restore (context);
2561 width += padding.left + padding.right;
2567 get_icon_allocations (GtkEntry *entry,
2568 GtkAllocation *primary,
2569 GtkAllocation *secondary)
2572 GtkEntryPrivate *priv = entry->priv;
2573 gint x, y, width, height;
2575 get_text_area_size (entry, &x, &y, &width, &height);
2577 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2578 y += priv->focus_width;
2581 primary->height = height;
2582 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2585 secondary->height = height;
2586 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2588 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2590 primary->x = x + width - primary->width;
2596 secondary->x = x + width - secondary->width;
2602 begin_change (GtkEntry *entry)
2604 GtkEntryPrivate *priv = entry->priv;
2606 priv->change_count++;
2608 g_object_freeze_notify (G_OBJECT (entry));
2612 end_change (GtkEntry *entry)
2614 GtkEditable *editable = GTK_EDITABLE (entry);
2615 GtkEntryPrivate *priv = entry->priv;
2617 g_return_if_fail (priv->change_count > 0);
2619 g_object_thaw_notify (G_OBJECT (entry));
2621 priv->change_count--;
2623 if (priv->change_count == 0)
2625 if (priv->real_changed)
2627 g_signal_emit_by_name (editable, "changed");
2628 priv->real_changed = FALSE;
2634 emit_changed (GtkEntry *entry)
2636 GtkEditable *editable = GTK_EDITABLE (entry);
2637 GtkEntryPrivate *priv = entry->priv;
2639 if (priv->change_count == 0)
2640 g_signal_emit_by_name (editable, "changed");
2642 priv->real_changed = TRUE;
2646 gtk_entry_destroy (GtkWidget *widget)
2648 GtkEntry *entry = GTK_ENTRY (widget);
2649 GtkEntryPrivate *priv = entry->priv;
2651 priv->current_pos = priv->selection_bound = 0;
2652 _gtk_entry_reset_im_context (entry);
2653 gtk_entry_reset_layout (entry);
2655 if (priv->blink_timeout)
2657 g_source_remove (priv->blink_timeout);
2658 priv->blink_timeout = 0;
2661 if (priv->recompute_idle)
2663 g_source_remove (priv->recompute_idle);
2664 priv->recompute_idle = 0;
2667 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2671 gtk_entry_dispose (GObject *object)
2673 GtkEntry *entry = GTK_ENTRY (object);
2674 GtkEntryPrivate *priv = entry->priv;
2677 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2678 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2679 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2680 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2684 buffer_disconnect_signals (entry);
2685 g_object_unref (priv->buffer);
2686 priv->buffer = NULL;
2689 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2690 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2691 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2692 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2696 gtk_entry_finalize (GObject *object)
2698 GtkEntry *entry = GTK_ENTRY (object);
2699 GtkEntryPrivate *priv = entry->priv;
2700 EntryIconInfo *icon_info = NULL;
2703 for (i = 0; i < MAX_ICONS; i++)
2705 if ((icon_info = priv->icons[i]) != NULL)
2707 if (icon_info->target_list != NULL)
2709 gtk_target_list_unref (icon_info->target_list);
2710 icon_info->target_list = NULL;
2713 g_clear_object (&icon_info->icon_helper);
2715 g_slice_free (EntryIconInfo, icon_info);
2716 priv->icons[i] = NULL;
2720 gtk_entry_set_completion (entry, NULL);
2722 if (priv->cached_layout)
2723 g_object_unref (priv->cached_layout);
2725 g_object_unref (priv->im_context);
2727 if (priv->blink_timeout)
2728 g_source_remove (priv->blink_timeout);
2730 if (priv->recompute_idle)
2731 g_source_remove (priv->recompute_idle);
2733 g_free (priv->placeholder_text);
2734 g_free (priv->im_module);
2736 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2740 gtk_entry_get_display_mode (GtkEntry *entry)
2742 GtkEntryPrivate *priv = entry->priv;
2745 return DISPLAY_NORMAL;
2747 if (priv->invisible_char == 0 && priv->invisible_char_set)
2748 return DISPLAY_BLANK;
2750 return DISPLAY_INVISIBLE;
2754 _gtk_entry_get_display_text (GtkEntry *entry,
2758 GtkEntryPasswordHint *password_hint;
2759 GtkEntryPrivate *priv;
2760 gunichar invisible_char;
2771 text = gtk_entry_buffer_get_text (get_buffer (entry));
2772 length = gtk_entry_buffer_get_length (get_buffer (entry));
2776 if (start_pos > length)
2779 if (end_pos <= start_pos)
2780 return g_strdup ("");
2781 else if (priv->visible)
2783 start = g_utf8_offset_to_pointer (text, start_pos);
2784 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2785 return g_strndup (start, end - start);
2789 str = g_string_sized_new (length * 2);
2791 /* Figure out what our invisible char is and encode it */
2792 if (!priv->invisible_char)
2793 invisible_char = priv->invisible_char_set ? ' ' : '*';
2795 invisible_char = priv->invisible_char;
2796 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2799 * Add hidden characters for each character in the text
2800 * buffer. If there is a password hint, then keep that
2801 * character visible.
2804 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2805 for (i = start_pos; i < end_pos; ++i)
2807 if (password_hint && i == password_hint->position)
2809 start = g_utf8_offset_to_pointer (text, i);
2810 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2814 g_string_append_len (str, char_str, char_len);
2818 return g_string_free (str, FALSE);
2823 update_cursors (GtkWidget *widget)
2825 GtkEntry *entry = GTK_ENTRY (widget);
2826 GtkEntryPrivate *priv = entry->priv;
2827 EntryIconInfo *icon_info = NULL;
2828 GdkDisplay *display;
2832 for (i = 0; i < MAX_ICONS; i++)
2834 if ((icon_info = priv->icons[i]) != NULL)
2836 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2837 icon_info->window != NULL)
2838 gdk_window_show_unraised (icon_info->window);
2840 /* The icon windows are not children of the visible entry window,
2841 * thus we can't just inherit the xterm cursor. Slight complication
2842 * here is that for the entry, insensitive => arrow cursor, but for
2843 * an icon in a sensitive entry, insensitive => xterm cursor.
2845 if (gtk_widget_is_sensitive (widget) &&
2846 (icon_info->insensitive ||
2847 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2849 display = gtk_widget_get_display (widget);
2850 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2851 gdk_window_set_cursor (icon_info->window, cursor);
2852 g_object_unref (cursor);
2856 gdk_window_set_cursor (icon_info->window, NULL);
2863 realize_icon_info (GtkWidget *widget,
2864 GtkEntryIconPosition icon_pos)
2866 GtkEntry *entry = GTK_ENTRY (widget);
2867 GtkEntryPrivate *priv = entry->priv;
2868 EntryIconInfo *icon_info = priv->icons[icon_pos];
2869 GdkWindowAttr attributes;
2870 gint attributes_mask;
2872 g_return_if_fail (icon_info != NULL);
2876 attributes.width = 1;
2877 attributes.height = 1;
2878 attributes.window_type = GDK_WINDOW_CHILD;
2879 attributes.wclass = GDK_INPUT_ONLY;
2880 attributes.event_mask = gtk_widget_get_events (widget);
2881 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2882 GDK_BUTTON_RELEASE_MASK |
2883 GDK_BUTTON1_MOTION_MASK |
2884 GDK_BUTTON3_MOTION_MASK |
2885 GDK_POINTER_MOTION_HINT_MASK |
2886 GDK_POINTER_MOTION_MASK |
2887 GDK_ENTER_NOTIFY_MASK |
2888 GDK_LEAVE_NOTIFY_MASK);
2889 attributes_mask = GDK_WA_X | GDK_WA_Y;
2891 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2894 gdk_window_set_user_data (icon_info->window, widget);
2896 gtk_widget_queue_resize (widget);
2899 static EntryIconInfo*
2900 construct_icon_info (GtkWidget *widget,
2901 GtkEntryIconPosition icon_pos)
2903 GtkEntry *entry = GTK_ENTRY (widget);
2904 GtkEntryPrivate *priv = entry->priv;
2905 EntryIconInfo *icon_info;
2907 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2909 icon_info = g_slice_new0 (EntryIconInfo);
2910 priv->icons[icon_pos] = icon_info;
2912 icon_info->icon_helper = _gtk_icon_helper_new ();
2913 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
2915 if (gtk_widget_get_realized (widget))
2916 realize_icon_info (widget, icon_pos);
2922 gtk_entry_map (GtkWidget *widget)
2924 GtkEntry *entry = GTK_ENTRY (widget);
2925 GtkEntryPrivate *priv = entry->priv;
2926 EntryIconInfo *icon_info = NULL;
2929 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2931 gdk_window_show (priv->text_area);
2933 for (i = 0; i < MAX_ICONS; i++)
2935 if ((icon_info = priv->icons[i]) != NULL)
2937 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2938 icon_info->window != NULL)
2939 gdk_window_show (icon_info->window);
2943 update_cursors (widget);
2947 gtk_entry_unmap (GtkWidget *widget)
2949 GtkEntry *entry = GTK_ENTRY (widget);
2950 GtkEntryPrivate *priv = entry->priv;
2951 EntryIconInfo *icon_info = NULL;
2954 for (i = 0; i < MAX_ICONS; i++)
2956 if ((icon_info = priv->icons[i]) != NULL)
2958 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2959 icon_info->window != NULL)
2960 gdk_window_hide (icon_info->window);
2964 gdk_window_hide (priv->text_area);
2966 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2970 gtk_entry_realize (GtkWidget *widget)
2973 GtkEntryPrivate *priv;
2974 EntryIconInfo *icon_info;
2976 GdkWindowAttr attributes;
2977 gint attributes_mask;
2978 gint frame_x, frame_y;
2981 gtk_widget_set_realized (widget, TRUE);
2982 window = gtk_widget_get_parent_window (widget);
2983 gtk_widget_set_window (widget, window);
2984 g_object_ref (window);
2986 entry = GTK_ENTRY (widget);
2989 attributes.window_type = GDK_WINDOW_CHILD;
2990 attributes.wclass = GDK_INPUT_ONLY;
2991 attributes.event_mask = gtk_widget_get_events (widget);
2992 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2993 GDK_BUTTON_RELEASE_MASK |
2994 GDK_BUTTON1_MOTION_MASK |
2995 GDK_BUTTON3_MOTION_MASK |
2996 GDK_POINTER_MOTION_HINT_MASK |
2997 GDK_POINTER_MOTION_MASK |
2998 GDK_ENTER_NOTIFY_MASK |
2999 GDK_LEAVE_NOTIFY_MASK);
3000 attributes_mask = GDK_WA_X | GDK_WA_Y;
3002 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3004 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3005 attributes.x += frame_x;
3006 attributes.y += frame_y;
3008 if (gtk_widget_is_sensitive (widget))
3010 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3011 attributes_mask |= GDK_WA_CURSOR;
3014 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3018 gdk_window_set_user_data (priv->text_area, entry);
3020 if (attributes_mask & GDK_WA_CURSOR)
3021 g_object_unref (attributes.cursor);
3023 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3025 gtk_entry_adjust_scroll (entry);
3026 gtk_entry_update_primary_selection (entry);
3029 /* If the icon positions are already setup, create their windows.
3030 * Otherwise if they don't exist yet, then construct_icon_info()
3031 * will create the windows once the widget is already realized.
3033 for (i = 0; i < MAX_ICONS; i++)
3035 if ((icon_info = priv->icons[i]) != NULL)
3037 if (icon_info->window == NULL)
3038 realize_icon_info (widget, i);
3044 gtk_entry_unrealize (GtkWidget *widget)
3046 GtkEntry *entry = GTK_ENTRY (widget);
3047 GtkEntryPrivate *priv = entry->priv;
3048 GtkClipboard *clipboard;
3049 EntryIconInfo *icon_info;
3052 gtk_entry_reset_layout (entry);
3054 gtk_im_context_set_client_window (priv->im_context, NULL);
3056 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3057 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3058 gtk_clipboard_clear (clipboard);
3060 if (priv->text_area)
3062 gdk_window_set_user_data (priv->text_area, NULL);
3063 gdk_window_destroy (priv->text_area);
3064 priv->text_area = NULL;
3067 if (priv->popup_menu)
3069 gtk_widget_destroy (priv->popup_menu);
3070 priv->popup_menu = NULL;
3073 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3075 for (i = 0; i < MAX_ICONS; i++)
3077 if ((icon_info = priv->icons[i]) != NULL)
3079 if (icon_info->window != NULL)
3081 gdk_window_destroy (icon_info->window);
3082 icon_info->window = NULL;
3089 _gtk_entry_get_borders (GtkEntry *entry,
3090 GtkBorder *border_out)
3092 GtkEntryPrivate *priv = entry->priv;
3093 GtkWidget *widget = GTK_WIDGET (entry);
3094 GtkBorder tmp = { 0, 0, 0, 0 };
3095 GtkStyleContext *context;
3097 context = gtk_widget_get_style_context (widget);
3098 gtk_style_context_get_padding (context, 0, &tmp);
3100 if (priv->has_frame)
3104 gtk_style_context_get_border (context, 0, &border);
3105 tmp.top += border.top;
3106 tmp.right += border.right;
3107 tmp.bottom += border.bottom;
3108 tmp.left += border.left;
3111 if (!priv->interior_focus)
3113 tmp.top += priv->focus_width;
3114 tmp.right += priv->focus_width;
3115 tmp.bottom += priv->focus_width;
3116 tmp.left += priv->focus_width;
3119 if (border_out != NULL)
3124 gtk_entry_get_preferred_width (GtkWidget *widget,
3128 GtkEntry *entry = GTK_ENTRY (widget);
3129 GtkEntryPrivate *priv = entry->priv;
3130 PangoFontMetrics *metrics;
3132 PangoContext *context;
3133 GtkStyleContext *style_context;
3134 GtkStateFlags state;
3135 gint icon_widths = 0;
3139 context = gtk_widget_get_pango_context (widget);
3141 style_context = gtk_widget_get_style_context (widget);
3142 state = gtk_widget_get_state_flags (widget);
3144 metrics = pango_context_get_metrics (context,
3145 gtk_style_context_get_font (style_context, state),
3146 pango_context_get_language (context));
3148 _gtk_entry_get_borders (entry, &borders);
3150 if (priv->width_chars < 0)
3151 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3154 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3155 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3156 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3158 width = char_pixels * priv->width_chars + borders.left + borders.right;
3161 for (i = 0; i < MAX_ICONS; i++)
3163 icon_width = get_icon_width (entry, i);
3165 icon_widths += icon_width;
3168 if (icon_widths > width)
3169 width += icon_widths;
3171 pango_font_metrics_unref (metrics);
3178 gtk_entry_get_preferred_height (GtkWidget *widget,
3182 GtkEntry *entry = GTK_ENTRY (widget);
3183 GtkEntryPrivate *priv = entry->priv;
3184 PangoFontMetrics *metrics;
3186 GtkStyleContext *style_context;
3187 GtkStateFlags state;
3188 PangoContext *context;
3191 context = gtk_widget_get_pango_context (widget);
3193 style_context = gtk_widget_get_style_context (widget);
3194 state = gtk_widget_get_state_flags (widget);
3196 metrics = pango_context_get_metrics (context,
3197 gtk_style_context_get_font (style_context, state),
3198 pango_context_get_language (context));
3200 priv->ascent = pango_font_metrics_get_ascent (metrics);
3201 priv->descent = pango_font_metrics_get_descent (metrics);
3203 _gtk_entry_get_borders (entry, &borders);
3205 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3207 pango_font_metrics_unref (metrics);
3214 place_windows (GtkEntry *entry)
3216 GtkWidget *widget = GTK_WIDGET (entry);
3217 GtkEntryPrivate *priv = entry->priv;
3218 gint x, y, width, height;
3219 gint frame_x, frame_y;
3220 GtkAllocation primary;
3221 GtkAllocation secondary;
3222 EntryIconInfo *icon_info = NULL;
3224 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3225 get_text_area_size (entry, &x, &y, &width, &height);
3226 get_icon_allocations (entry, &primary, &secondary);
3228 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3229 y += priv->focus_width;
3231 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3232 x += secondary.width;
3235 width -= primary.width + secondary.width;
3239 primary.x += frame_x;
3240 primary.y += frame_y;
3241 secondary.x += frame_x;
3242 secondary.y += frame_y;
3244 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3245 gdk_window_move_resize (icon_info->window,
3246 primary.x, primary.y,
3247 primary.width, primary.height);
3249 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3250 gdk_window_move_resize (icon_info->window,
3251 secondary.x, secondary.y,
3252 secondary.width, secondary.height);
3254 gdk_window_move_resize (priv->text_area, x, y, width, height);
3258 gtk_entry_get_text_area_size (GtkEntry *entry,
3264 GtkEntryPrivate *priv = entry->priv;
3265 GtkWidget *widget = GTK_WIDGET (entry);
3266 GtkAllocation allocation;
3267 GtkRequisition requisition;
3272 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3273 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3275 gtk_widget_get_allocation (widget, &allocation);
3276 _gtk_entry_get_borders (entry, &borders);
3278 if (gtk_widget_get_realized (widget))
3279 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3281 frame_height = req_height;
3283 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3284 frame_height -= 2 * priv->focus_width;
3290 *y = floor ((frame_height - req_height) / 2) + borders.top;
3293 *width = allocation.width - borders.left - borders.right;
3296 *height = req_height - borders.top - borders.bottom;
3300 get_text_area_size (GtkEntry *entry,
3306 GtkEntryClass *class;
3308 g_return_if_fail (GTK_IS_ENTRY (entry));
3310 class = GTK_ENTRY_GET_CLASS (entry);
3312 if (class->get_text_area_size)
3313 class->get_text_area_size (entry, x, y, width, height);
3318 get_frame_size (GtkEntry *entry,
3319 gboolean relative_to_window,
3325 GtkEntryPrivate *priv = entry->priv;
3326 GtkAllocation allocation;
3327 GtkRequisition requisition;
3328 GtkWidget *widget = GTK_WIDGET (entry);
3331 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3333 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3335 gtk_widget_get_allocation (widget, &allocation);
3338 *x = relative_to_window ? allocation.x : 0;
3342 if (priv->is_cell_renderer)
3345 *y = (allocation.height - req_height) / 2;
3347 if (relative_to_window)
3352 *width = allocation.width;
3356 if (priv->is_cell_renderer)
3357 *height = allocation.height;
3359 *height = req_height;
3364 gtk_entry_size_allocate (GtkWidget *widget,
3365 GtkAllocation *allocation)
3367 GtkEntry *entry = GTK_ENTRY (widget);
3369 gtk_widget_set_allocation (widget, allocation);
3371 if (gtk_widget_get_realized (widget))
3373 GtkEntryCompletion* completion;
3375 place_windows (entry);
3376 gtk_entry_recompute (entry);
3378 completion = gtk_entry_get_completion (entry);
3379 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3380 _gtk_entry_completion_resize_popup (completion);
3385 should_prelight (GtkEntry *entry,
3386 GtkEntryIconPosition icon_pos)
3388 GtkEntryPrivate *priv = entry->priv;
3389 EntryIconInfo *icon_info = priv->icons[icon_pos];
3395 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3398 if (icon_info->pressed)
3401 gtk_widget_style_get (GTK_WIDGET (entry),
3402 "icon-prelight", &prelight,
3409 draw_icon (GtkWidget *widget,
3411 GtkEntryIconPosition icon_pos)
3413 GtkEntry *entry = GTK_ENTRY (widget);
3414 GtkEntryPrivate *priv = entry->priv;
3415 EntryIconInfo *icon_info = priv->icons[icon_pos];
3416 gint x, y, width, height, pix_width, pix_height;
3417 GtkStyleContext *context;
3423 width = gdk_window_get_width (icon_info->window);
3424 height = gdk_window_get_height (icon_info->window);
3426 /* size_allocate hasn't been called yet. These are the default values.
3428 if (width == 1 || height == 1)
3432 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3434 context = gtk_widget_get_style_context (widget);
3435 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3436 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3437 &pix_width, &pix_height);
3438 gtk_style_context_get_padding (context, 0, &padding);
3440 x = MAX (0, padding.left);
3441 y = MAX (0, (height - pix_height) / 2);
3443 _gtk_icon_helper_draw (icon_info->icon_helper,
3447 gtk_style_context_restore (context);
3453 gtk_entry_draw_frame (GtkWidget *widget,
3454 GtkStyleContext *context,
3457 GtkEntry *entry = GTK_ENTRY (widget);
3458 GtkEntryPrivate *priv = entry->priv;
3459 gint x = 0, y = 0, width, height;
3460 gint frame_x, frame_y;
3464 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3466 cairo_translate (cr, frame_x, frame_y);
3468 /* Fix a problem with some themes which assume that entry->text_area's
3469 * width equals widget->window's width
3470 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3471 if (GTK_IS_SPIN_BUTTON (widget))
3475 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3476 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3479 width += borders.left + borders.right;
3482 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3484 x += priv->focus_width;
3485 y += priv->focus_width;
3486 width -= 2 * priv->focus_width;
3487 height -= 2 * priv->focus_width;
3490 gtk_render_background (context, cr,
3491 x, y, width, height);
3493 if (priv->has_frame)
3494 gtk_render_frame (context, cr,
3495 x, y, width, height);
3497 gtk_entry_draw_progress (widget, context, cr);
3499 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3501 x -= priv->focus_width;
3502 y -= priv->focus_width;
3503 width += 2 * priv->focus_width;
3504 height += 2 * priv->focus_width;
3506 gtk_render_focus (context, cr,
3507 0, 0, width, height);
3514 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3515 GtkStyleContext *context)
3517 GtkEntryPrivate *private = entry->priv;
3519 gtk_style_context_save (context);
3520 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3521 if (private->progress_pulse_mode)
3522 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3526 get_progress_area (GtkWidget *widget,
3532 GtkEntry *entry = GTK_ENTRY (widget);
3533 GtkEntryPrivate *private = entry->priv;
3534 GtkStyleContext *context;
3535 GtkBorder margin, border, entry_borders;
3536 gint frame_width, text_area_width, text_area_height;
3538 context = gtk_widget_get_style_context (widget);
3539 _gtk_entry_get_borders (entry, &entry_borders);
3540 get_text_area_size (entry,
3542 &text_area_width, &text_area_height);
3543 get_frame_size (entry, FALSE,
3545 &frame_width, NULL);
3549 *width = text_area_width + entry_borders.left + entry_borders.right;
3550 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3552 /* if the text area got resized by a subclass, subtract the left/right
3553 * border width, so that the progress bar won't extend over the resized
3556 if (frame_width > *width)
3558 gtk_style_context_get_border (context, 0, &border);
3559 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3561 *x = (frame_width - *width) + border.left;
3562 *width -= border.left;
3566 *width -= border.right;
3570 gtk_entry_prepare_context_for_progress (entry, context);
3571 gtk_style_context_get_margin (context, 0, &margin);
3573 gtk_style_context_restore (context);
3577 *width -= margin.left + margin.right;
3578 *height -= margin.top + margin.bottom;
3580 if (private->progress_pulse_mode)
3582 gdouble value = private->progress_pulse_current;
3584 *x += (gint) floor(value * (*width));
3585 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3587 else if (private->progress_fraction > 0)
3589 gdouble value = private->progress_fraction;
3591 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3595 bar_width = floor(value * (*width) + 0.5);
3596 *x += *width - bar_width;
3601 *width = (gint) floor(value * (*width) + 0.5);
3612 gtk_entry_draw_progress (GtkWidget *widget,
3613 GtkStyleContext *context,
3616 GtkEntry *entry = GTK_ENTRY (widget);
3617 gint x, y, width, height;
3619 get_progress_area (widget, &x, &y, &width, &height);
3621 if ((width <= 0) || (height <= 0))
3624 gtk_entry_prepare_context_for_progress (entry, context);
3625 gtk_render_activity (context, cr,
3626 x, y, width, height);
3628 gtk_style_context_restore (context);
3632 gtk_entry_draw (GtkWidget *widget,
3635 GtkEntry *entry = GTK_ENTRY (widget);
3636 GtkStyleContext *context;
3637 GtkEntryPrivate *priv = entry->priv;
3640 context = gtk_widget_get_style_context (widget);
3642 /* Draw entry_bg, shadow, progress and focus */
3643 gtk_entry_draw_frame (widget, context, cr);
3645 /* Draw text and cursor */
3648 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3650 if (priv->dnd_position != -1)
3651 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3653 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3655 /* When no text is being displayed at all, don't show the cursor */
3656 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3657 gtk_widget_has_focus (widget) &&
3658 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3659 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3664 for (i = 0; i < MAX_ICONS; i++)
3666 EntryIconInfo *icon_info = priv->icons[i];
3668 if (icon_info != NULL)
3669 draw_icon (widget, cr, i);
3676 gtk_entry_enter_notify (GtkWidget *widget,
3677 GdkEventCrossing *event)
3679 GtkEntry *entry = GTK_ENTRY (widget);
3680 GtkEntryPrivate *priv = entry->priv;
3683 for (i = 0; i < MAX_ICONS; i++)
3685 EntryIconInfo *icon_info = priv->icons[i];
3687 if (icon_info != NULL && event->window == icon_info->window)
3689 if (should_prelight (entry, i))
3691 icon_info->prelight = TRUE;
3692 gtk_widget_queue_draw (widget);
3703 gtk_entry_leave_notify (GtkWidget *widget,
3704 GdkEventCrossing *event)
3706 GtkEntry *entry = GTK_ENTRY (widget);
3707 GtkEntryPrivate *priv = entry->priv;
3710 for (i = 0; i < MAX_ICONS; i++)
3712 EntryIconInfo *icon_info = priv->icons[i];
3714 if (icon_info != NULL && event->window == icon_info->window)
3716 /* a grab means that we may never see the button release */
3717 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3718 icon_info->pressed = FALSE;
3720 if (should_prelight (entry, i))
3722 icon_info->prelight = FALSE;
3723 gtk_widget_queue_draw (widget);
3734 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3738 gint start_char, end_char;
3740 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3742 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3743 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3744 const char *text = pango_layout_get_text (layout);
3745 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3746 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3747 gint real_n_ranges, i;
3749 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3755 for (i = 0; i < real_n_ranges; ++i)
3757 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3758 r[2 * i] = r[2 * i] / PANGO_SCALE;
3763 *n_ranges = real_n_ranges;
3775 in_selection (GtkEntry *entry,
3780 gint retval = FALSE;
3782 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3784 for (i = 0; i < n_ranges; ++i)
3786 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3798 gtk_entry_button_press (GtkWidget *widget,
3799 GdkEventButton *event)
3801 GtkEntry *entry = GTK_ENTRY (widget);
3802 GtkEditable *editable = GTK_EDITABLE (widget);
3803 GtkEntryPrivate *priv = entry->priv;
3804 EntryIconInfo *icon_info = NULL;
3806 gint sel_start, sel_end;
3809 for (i = 0; i < MAX_ICONS; i++)
3811 icon_info = priv->icons[i];
3813 if (!icon_info || icon_info->insensitive)
3816 if (event->window == icon_info->window)
3818 if (should_prelight (entry, i))
3820 icon_info->prelight = FALSE;
3821 gtk_widget_queue_draw (widget);
3824 priv->start_x = event->x;
3825 priv->start_y = event->y;
3826 icon_info->pressed = TRUE;
3828 if (!icon_info->nonactivatable)
3829 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3835 if (event->window != priv->text_area ||
3836 (priv->button && event->button != priv->button))
3839 gtk_entry_reset_blink_time (entry);
3841 priv->button = event->button;
3842 priv->device = gdk_event_get_device ((GdkEvent *) event);
3844 if (!gtk_widget_has_focus (widget))
3846 priv->in_click = TRUE;
3847 gtk_widget_grab_focus (widget);
3848 priv->in_click = FALSE;
3851 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3853 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3855 gtk_entry_do_popup (entry, event);
3856 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3857 priv->device = NULL;
3861 else if (event->button == GDK_BUTTON_PRIMARY)
3863 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3865 priv->select_words = FALSE;
3866 priv->select_lines = FALSE;
3869 gtk_widget_get_modifier_mask (widget,
3870 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3872 _gtk_entry_reset_im_context (entry);
3874 if (!have_selection) /* select from the current position to the clicked position */
3875 sel_start = sel_end = priv->current_pos;
3877 if (tmp_pos > sel_start && tmp_pos < sel_end)
3879 /* Truncate current selection, but keep it as big as possible */
3880 if (tmp_pos - sel_start > sel_end - tmp_pos)
3881 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3883 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3887 gboolean extend_to_left;
3890 /* Figure out what click selects and extend current selection */
3891 switch (event->type)
3893 case GDK_BUTTON_PRESS:
3894 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3897 case GDK_2BUTTON_PRESS:
3898 priv->select_words = TRUE;
3899 gtk_entry_select_word (entry);
3902 case GDK_3BUTTON_PRESS:
3903 priv->select_lines = TRUE;
3904 gtk_entry_select_line (entry);
3911 start = MIN (priv->current_pos, priv->selection_bound);
3912 start = MIN (sel_start, start);
3914 end = MAX (priv->current_pos, priv->selection_bound);
3915 end = MAX (sel_end, end);
3917 if (tmp_pos == sel_start || tmp_pos == sel_end)
3918 extend_to_left = (tmp_pos == start);
3920 extend_to_left = (end == sel_end);
3923 gtk_entry_set_positions (entry, start, end);
3925 gtk_entry_set_positions (entry, end, start);
3928 else /* no shift key */
3929 switch (event->type)
3931 case GDK_BUTTON_PRESS:
3932 if (in_selection (entry, event->x + priv->scroll_offset))
3934 /* Click inside the selection - we'll either start a drag, or
3935 * clear the selection
3937 priv->in_drag = TRUE;
3938 priv->drag_start_x = event->x + priv->scroll_offset;
3939 priv->drag_start_y = event->y;
3942 gtk_editable_set_position (editable, tmp_pos);
3945 case GDK_2BUTTON_PRESS:
3946 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3947 * receiving a GDK_2BUTTON_PRESS so we need to reset
3948 * priv->in_drag which may have been set above
3950 priv->in_drag = FALSE;
3951 priv->select_words = TRUE;
3952 gtk_entry_select_word (entry);
3955 case GDK_3BUTTON_PRESS:
3956 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3957 * receiving a GDK_3BUTTON_PRESS so we need to reset
3958 * priv->in_drag which may have been set above
3960 priv->in_drag = FALSE;
3961 priv->select_lines = TRUE;
3962 gtk_entry_select_line (entry);
3971 else if (event->type == GDK_BUTTON_PRESS &&
3972 event->button == GDK_BUTTON_MIDDLE &&
3973 get_middle_click_paste (entry))
3977 priv->insert_pos = tmp_pos;
3978 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3983 gtk_widget_error_bell (widget);
3991 gtk_entry_button_release (GtkWidget *widget,
3992 GdkEventButton *event)
3994 GtkEntry *entry = GTK_ENTRY (widget);
3995 GtkEntryPrivate *priv = entry->priv;
3996 EntryIconInfo *icon_info = NULL;
3999 for (i = 0; i < MAX_ICONS; i++)
4001 icon_info = priv->icons[i];
4003 if (!icon_info || icon_info->insensitive)
4006 if (event->window == icon_info->window)
4008 icon_info->pressed = FALSE;
4010 if (should_prelight (entry, i) &&
4011 event->x >= 0 && event->y >= 0 &&
4012 event->x < gdk_window_get_width (icon_info->window) &&
4013 event->y < gdk_window_get_height (icon_info->window))
4015 icon_info->prelight = TRUE;
4016 gtk_widget_queue_draw (widget);
4019 if (!icon_info->nonactivatable)
4020 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4026 if (event->window != priv->text_area || priv->button != event->button)
4031 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4033 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4039 priv->device = NULL;
4041 gtk_entry_update_primary_selection (entry);
4047 _gtk_entry_get_selected_text (GtkEntry *entry)
4049 GtkEditable *editable = GTK_EDITABLE (entry);
4050 gint start_text, end_text;
4053 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4054 text = gtk_editable_get_chars (editable, start_text, end_text);
4060 gtk_entry_motion_notify (GtkWidget *widget,
4061 GdkEventMotion *event)
4063 GtkEntry *entry = GTK_ENTRY (widget);
4064 GtkEntryPrivate *priv = entry->priv;
4065 EntryIconInfo *icon_info = NULL;
4069 for (i = 0; i < MAX_ICONS; i++)
4071 icon_info = priv->icons[i];
4073 if (!icon_info || icon_info->insensitive)
4076 if (event->window == icon_info->window)
4078 if (icon_info->pressed &&
4079 icon_info->target_list != NULL &&
4080 gtk_drag_check_threshold (widget,
4086 icon_info->in_drag = TRUE;
4087 icon_info->pressed = FALSE;
4088 gtk_drag_begin (widget,
4089 icon_info->target_list,
4099 if (priv->mouse_cursor_obscured)
4103 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4104 gdk_window_set_cursor (priv->text_area, cursor);
4105 g_object_unref (cursor);
4106 priv->mouse_cursor_obscured = FALSE;
4109 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4112 if (priv->select_lines)
4115 gdk_event_request_motions (event);
4119 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4120 gtk_drag_check_threshold (widget,
4121 priv->drag_start_x, priv->drag_start_y,
4122 event->x + priv->scroll_offset, event->y))
4124 GdkDragContext *context;
4125 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4126 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4128 cairo_surface_t *surface;
4130 gtk_target_list_add_text_targets (target_list, 0);
4132 text = _gtk_entry_get_selected_text (entry);
4133 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4135 context = gtk_drag_begin (widget, target_list, actions,
4136 priv->button, (GdkEvent *)event);
4139 gtk_drag_set_icon_surface (context, surface);
4141 gtk_drag_set_icon_default (context);
4144 cairo_surface_destroy (surface);
4147 priv->in_drag = FALSE;
4149 priv->device = NULL;
4151 gtk_target_list_unref (target_list);
4158 else if (event->y >= gdk_window_get_height (priv->text_area))
4159 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4161 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4163 if (priv->select_words)
4166 gint old_min, old_max;
4169 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4170 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4172 pos = priv->current_pos;
4173 bound = priv->selection_bound;
4175 old_min = MIN(priv->current_pos, priv->selection_bound);
4176 old_max = MAX(priv->current_pos, priv->selection_bound);
4183 else if (old_max < max)
4188 else if (pos == old_min)
4190 if (priv->current_pos != min)
4195 if (priv->current_pos != max)
4199 gtk_entry_set_positions (entry, pos, bound);
4202 gtk_entry_set_positions (entry, tmp_pos, -1);
4209 set_invisible_cursor (GdkWindow *window)
4211 GdkDisplay *display;
4214 display = gdk_window_get_display (window);
4215 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4217 gdk_window_set_cursor (window, cursor);
4219 g_object_unref (cursor);
4223 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4225 GtkEntryPrivate *priv = entry->priv;
4227 if (priv->mouse_cursor_obscured)
4230 set_invisible_cursor (priv->text_area);
4232 priv->mouse_cursor_obscured = TRUE;
4236 gtk_entry_key_press (GtkWidget *widget,
4239 GtkEntry *entry = GTK_ENTRY (widget);
4240 GtkEntryPrivate *priv = entry->priv;
4242 gtk_entry_reset_blink_time (entry);
4243 gtk_entry_pend_cursor_blink (entry);
4247 if (gtk_im_context_filter_keypress (priv->im_context, event))
4249 gtk_entry_obscure_mouse_cursor (entry);
4250 priv->need_im_reset = TRUE;
4255 if (event->keyval == GDK_KEY_Return ||
4256 event->keyval == GDK_KEY_KP_Enter ||
4257 event->keyval == GDK_KEY_ISO_Enter ||
4258 event->keyval == GDK_KEY_Escape)
4260 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4262 if (completion && completion->priv->completion_timeout)
4264 g_source_remove (completion->priv->completion_timeout);
4265 completion->priv->completion_timeout = 0;
4268 _gtk_entry_reset_im_context (entry);
4271 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4272 /* Activate key bindings
4276 if (!priv->editable && event->length)
4277 gtk_widget_error_bell (widget);
4283 gtk_entry_key_release (GtkWidget *widget,
4286 GtkEntry *entry = GTK_ENTRY (widget);
4287 GtkEntryPrivate *priv = entry->priv;
4291 if (gtk_im_context_filter_keypress (priv->im_context, event))
4293 priv->need_im_reset = TRUE;
4298 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4302 gtk_entry_focus_in (GtkWidget *widget,
4303 GdkEventFocus *event)
4305 GtkEntry *entry = GTK_ENTRY (widget);
4306 GtkEntryPrivate *priv = entry->priv;
4309 gtk_widget_queue_draw (widget);
4311 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4315 priv->need_im_reset = TRUE;
4316 gtk_im_context_focus_in (priv->im_context);
4317 keymap_state_changed (keymap, entry);
4318 g_signal_connect (keymap, "state-changed",
4319 G_CALLBACK (keymap_state_changed), entry);
4322 g_signal_connect (keymap, "direction-changed",
4323 G_CALLBACK (keymap_direction_changed), entry);
4325 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4326 priv->placeholder_text != NULL)
4328 gtk_entry_recompute (entry);
4332 gtk_entry_reset_blink_time (entry);
4333 gtk_entry_check_cursor_blink (entry);
4340 gtk_entry_focus_out (GtkWidget *widget,
4341 GdkEventFocus *event)
4343 GtkEntry *entry = GTK_ENTRY (widget);
4344 GtkEntryPrivate *priv = entry->priv;
4345 GtkEntryCompletion *completion;
4348 gtk_widget_queue_draw (widget);
4350 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4354 priv->need_im_reset = TRUE;
4355 gtk_im_context_focus_out (priv->im_context);
4356 remove_capslock_feedback (entry);
4359 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4360 priv->placeholder_text != NULL)
4362 gtk_entry_recompute (entry);
4366 gtk_entry_check_cursor_blink (entry);
4369 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4370 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4372 completion = gtk_entry_get_completion (entry);
4374 _gtk_entry_completion_popdown (completion);
4380 gtk_entry_grab_focus (GtkWidget *widget)
4382 GtkEntry *entry = GTK_ENTRY (widget);
4383 GtkEntryPrivate *priv = entry->priv;
4384 gboolean select_on_focus;
4386 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4388 if (priv->editable && !priv->in_click)
4390 g_object_get (gtk_widget_get_settings (widget),
4391 "gtk-entry-select-on-focus",
4395 if (select_on_focus)
4396 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4401 gtk_entry_direction_changed (GtkWidget *widget,
4402 GtkTextDirection previous_dir)
4404 GtkEntry *entry = GTK_ENTRY (widget);
4406 gtk_entry_recompute (entry);
4408 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4412 gtk_entry_state_flags_changed (GtkWidget *widget,
4413 GtkStateFlags previous_state)
4415 GtkEntry *entry = GTK_ENTRY (widget);
4416 GtkEntryPrivate *priv = entry->priv;
4419 if (gtk_widget_get_realized (widget))
4421 if (gtk_widget_is_sensitive (widget))
4422 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4426 gdk_window_set_cursor (priv->text_area, cursor);
4429 g_object_unref (cursor);
4431 priv->mouse_cursor_obscured = FALSE;
4433 update_cursors (widget);
4436 if (!gtk_widget_is_sensitive (widget))
4438 /* Clear any selection */
4439 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4442 gtk_entry_update_cached_style_values (entry);
4446 gtk_entry_screen_changed (GtkWidget *widget,
4447 GdkScreen *old_screen)
4449 gtk_entry_recompute (GTK_ENTRY (widget));
4452 /* GtkEditable method implementations
4455 gtk_entry_insert_text (GtkEditable *editable,
4456 const gchar *new_text,
4457 gint new_text_length,
4460 g_object_ref (editable);
4463 * The incoming text may a password or other secret. We make sure
4464 * not to copy it into temporary buffers.
4467 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4469 g_object_unref (editable);
4473 gtk_entry_delete_text (GtkEditable *editable,
4477 g_object_ref (editable);
4479 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4481 g_object_unref (editable);
4485 gtk_entry_get_chars (GtkEditable *editable,
4489 GtkEntry *entry = GTK_ENTRY (editable);
4492 gint start_index, end_index;
4494 text = gtk_entry_buffer_get_text (get_buffer (entry));
4495 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4498 end_pos = text_length;
4500 start_pos = MIN (text_length, start_pos);
4501 end_pos = MIN (text_length, end_pos);
4503 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4504 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4506 return g_strndup (text + start_index, end_index - start_index);
4510 gtk_entry_real_set_position (GtkEditable *editable,
4513 GtkEntry *entry = GTK_ENTRY (editable);
4514 GtkEntryPrivate *priv = entry->priv;
4518 length = gtk_entry_buffer_get_length (get_buffer (entry));
4519 if (position < 0 || position > length)
4522 if (position != priv->current_pos ||
4523 position != priv->selection_bound)
4525 _gtk_entry_reset_im_context (entry);
4526 gtk_entry_set_positions (entry, position, position);
4531 gtk_entry_get_position (GtkEditable *editable)
4533 GtkEntry *entry = GTK_ENTRY (editable);
4534 GtkEntryPrivate *priv = entry->priv;
4536 return priv->current_pos;
4540 gtk_entry_set_selection_bounds (GtkEditable *editable,
4544 GtkEntry *entry = GTK_ENTRY (editable);
4547 length = gtk_entry_buffer_get_length (get_buffer (entry));
4553 _gtk_entry_reset_im_context (entry);
4555 gtk_entry_set_positions (entry,
4557 MIN (start, length));
4559 gtk_entry_update_primary_selection (entry);
4563 gtk_entry_get_selection_bounds (GtkEditable *editable,
4567 GtkEntry *entry = GTK_ENTRY (editable);
4568 GtkEntryPrivate *priv = entry->priv;
4570 *start = priv->selection_bound;
4571 *end = priv->current_pos;
4573 return (priv->selection_bound != priv->current_pos);
4577 icon_theme_changed (GtkEntry *entry)
4579 GtkEntryPrivate *priv = entry->priv;
4582 for (i = 0; i < MAX_ICONS; i++)
4584 EntryIconInfo *icon_info = priv->icons[i];
4585 if (icon_info != NULL)
4586 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4589 gtk_widget_queue_draw (GTK_WIDGET (entry));
4593 gtk_entry_update_cached_style_values (GtkEntry *entry)
4595 GtkEntryPrivate *priv = entry->priv;
4597 gboolean interior_focus;
4599 gtk_widget_style_get (GTK_WIDGET (entry),
4600 "focus-line-width", &focus_width,
4601 "interior-focus", &interior_focus,
4603 priv->focus_width = focus_width;
4604 priv->interior_focus = interior_focus;
4606 if (!priv->invisible_char_set)
4608 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4610 if (priv->invisible_char != ch)
4612 priv->invisible_char = ch;
4613 g_object_notify (G_OBJECT (entry), "invisible-char");
4619 gtk_entry_style_updated (GtkWidget *widget)
4621 GtkEntry *entry = GTK_ENTRY (widget);
4623 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4625 gtk_entry_update_cached_style_values (entry);
4627 gtk_entry_recompute (entry);
4629 icon_theme_changed (entry);
4632 /* GtkCellEditable method implementations
4635 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4637 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4638 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4642 gtk_cell_editable_key_press_event (GtkEntry *entry,
4643 GdkEventKey *key_event,
4646 GtkEntryPrivate *priv = entry->priv;
4648 if (key_event->keyval == GDK_KEY_Escape)
4650 priv->editing_canceled = TRUE;
4651 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4652 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4657 /* override focus */
4658 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4660 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4661 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4670 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4673 GtkEntry *entry = GTK_ENTRY (cell_editable);
4674 GtkEntryPrivate *priv = entry->priv;
4676 priv->is_cell_renderer = TRUE;
4678 g_signal_connect (cell_editable, "activate",
4679 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4680 g_signal_connect (cell_editable, "key-press-event",
4681 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4685 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4687 if (password_hint->source_id)
4688 g_source_remove (password_hint->source_id);
4690 g_slice_free (GtkEntryPasswordHint, password_hint);
4695 gtk_entry_remove_password_hint (gpointer data)
4697 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4698 password_hint->position = -1;
4700 /* Force the string to be redrawn, but now without a visible character */
4701 gtk_entry_recompute (GTK_ENTRY (data));
4705 /* Default signal handlers
4708 gtk_entry_real_insert_text (GtkEditable *editable,
4709 const gchar *new_text,
4710 gint new_text_length,
4716 n_chars = g_utf8_strlen (new_text, new_text_length);
4719 * The actual insertion into the buffer. This will end up firing the
4720 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4721 * buffer_notify_text(), buffer_notify_length()
4723 begin_change (GTK_ENTRY (editable));
4725 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4727 end_change (GTK_ENTRY (editable));
4729 if (n_inserted != n_chars)
4730 gtk_widget_error_bell (GTK_WIDGET (editable));
4732 *position += n_inserted;
4736 gtk_entry_real_delete_text (GtkEditable *editable,
4741 * The actual deletion from the buffer. This will end up firing the
4742 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4743 * buffer_notify_text(), buffer_notify_length()
4746 begin_change (GTK_ENTRY (editable));
4748 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4750 end_change (GTK_ENTRY (editable));
4753 /* GtkEntryBuffer signal handlers
4756 buffer_inserted_text (GtkEntryBuffer *buffer,
4762 GtkEntryPrivate *priv = entry->priv;
4763 guint password_hint_timeout;
4765 gint selection_bound;
4767 current_pos = priv->current_pos;
4768 if (current_pos > position)
4769 current_pos += n_chars;
4771 selection_bound = priv->selection_bound;
4772 if (selection_bound > position)
4773 selection_bound += n_chars;
4775 gtk_entry_set_positions (entry, current_pos, selection_bound);
4777 /* Calculate the password hint if it needs to be displayed. */
4778 if (n_chars == 1 && !priv->visible)
4780 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4781 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4784 if (password_hint_timeout > 0)
4786 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4787 quark_password_hint);
4790 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4791 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4792 (GDestroyNotify)gtk_entry_password_hint_free);
4795 password_hint->position = position;
4796 if (password_hint->source_id)
4797 g_source_remove (password_hint->source_id);
4798 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4799 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4805 buffer_deleted_text (GtkEntryBuffer *buffer,
4810 GtkEntryPrivate *priv = entry->priv;
4811 guint end_pos = position + n_chars;
4812 gint selection_bound;
4815 current_pos = priv->current_pos;
4816 if (current_pos > position)
4817 current_pos -= MIN (current_pos, end_pos) - position;
4819 selection_bound = priv->selection_bound;
4820 if (selection_bound > position)
4821 selection_bound -= MIN (selection_bound, end_pos) - position;
4823 gtk_entry_set_positions (entry, current_pos, selection_bound);
4825 /* We might have deleted the selection */
4826 gtk_entry_update_primary_selection (entry);
4828 /* Disable the password hint if one exists. */
4831 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4832 quark_password_hint);
4835 if (password_hint->source_id)
4836 g_source_remove (password_hint->source_id);
4837 password_hint->source_id = 0;
4838 password_hint->position = -1;
4844 buffer_notify_text (GtkEntryBuffer *buffer,
4848 gtk_entry_recompute (entry);
4849 emit_changed (entry);
4850 g_object_notify (G_OBJECT (entry), "text");
4854 buffer_notify_length (GtkEntryBuffer *buffer,
4858 g_object_notify (G_OBJECT (entry), "text-length");
4862 buffer_notify_max_length (GtkEntryBuffer *buffer,
4866 g_object_notify (G_OBJECT (entry), "max-length");
4870 buffer_connect_signals (GtkEntry *entry)
4872 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4873 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4874 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4875 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4876 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4880 buffer_disconnect_signals (GtkEntry *entry)
4882 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4883 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4884 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4885 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4886 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4889 /* Compute the X position for an offset that corresponds to the "more important
4890 * cursor position for that offset. We use this when trying to guess to which
4891 * end of the selection we should go to when the user hits the left or
4895 get_better_cursor_x (GtkEntry *entry,
4898 GtkEntryPrivate *priv = entry->priv;
4899 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4900 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4901 gboolean split_cursor;
4903 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4904 const gchar *text = pango_layout_get_text (layout);
4905 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4907 PangoRectangle strong_pos, weak_pos;
4909 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4910 "gtk-split-cursor", &split_cursor,
4913 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4916 return strong_pos.x / PANGO_SCALE;
4918 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4922 gtk_entry_move_cursor (GtkEntry *entry,
4923 GtkMovementStep step,
4925 gboolean extend_selection)
4927 GtkEntryPrivate *priv = entry->priv;
4928 gint new_pos = priv->current_pos;
4930 _gtk_entry_reset_im_context (entry);
4932 if (priv->current_pos != priv->selection_bound && !extend_selection)
4934 /* If we have a current selection and aren't extending it, move to the
4935 * start/or end of the selection as appropriate
4939 case GTK_MOVEMENT_VISUAL_POSITIONS:
4941 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4942 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4945 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4947 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4950 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4951 case GTK_MOVEMENT_WORDS:
4953 new_pos = MIN (priv->current_pos, priv->selection_bound);
4955 new_pos = MAX (priv->current_pos, priv->selection_bound);
4957 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4958 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4959 case GTK_MOVEMENT_BUFFER_ENDS:
4960 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4962 case GTK_MOVEMENT_DISPLAY_LINES:
4963 case GTK_MOVEMENT_PARAGRAPHS:
4964 case GTK_MOVEMENT_PAGES:
4965 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4973 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4974 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4976 case GTK_MOVEMENT_VISUAL_POSITIONS:
4977 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4978 if (priv->current_pos == new_pos)
4980 if (!extend_selection)
4982 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4984 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4986 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4989 gtk_widget_child_focus (toplevel,
4991 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4996 gtk_widget_error_bell (GTK_WIDGET (entry));
5000 case GTK_MOVEMENT_WORDS:
5003 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5008 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5011 if (priv->current_pos == new_pos)
5012 gtk_widget_error_bell (GTK_WIDGET (entry));
5014 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5015 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5016 case GTK_MOVEMENT_BUFFER_ENDS:
5017 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5018 if (priv->current_pos == new_pos)
5019 gtk_widget_error_bell (GTK_WIDGET (entry));
5021 case GTK_MOVEMENT_DISPLAY_LINES:
5022 case GTK_MOVEMENT_PARAGRAPHS:
5023 case GTK_MOVEMENT_PAGES:
5024 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5029 if (extend_selection)
5030 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5032 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5034 gtk_entry_pend_cursor_blink (entry);
5038 gtk_entry_insert_at_cursor (GtkEntry *entry,
5041 GtkEntryPrivate *priv = entry->priv;
5042 GtkEditable *editable = GTK_EDITABLE (entry);
5043 gint pos = priv->current_pos;
5047 _gtk_entry_reset_im_context (entry);
5049 gtk_editable_insert_text (editable, str, -1, &pos);
5050 gtk_editable_set_position (editable, pos);
5055 gtk_entry_delete_from_cursor (GtkEntry *entry,
5059 GtkEntryPrivate *priv = entry->priv;
5060 GtkEditable *editable = GTK_EDITABLE (entry);
5061 gint start_pos = priv->current_pos;
5062 gint end_pos = priv->current_pos;
5063 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5065 _gtk_entry_reset_im_context (entry);
5067 if (!priv->editable)
5069 gtk_widget_error_bell (GTK_WIDGET (entry));
5073 if (priv->selection_bound != priv->current_pos)
5075 gtk_editable_delete_selection (editable);
5081 case GTK_DELETE_CHARS:
5082 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5083 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5085 case GTK_DELETE_WORDS:
5088 /* Move to end of current word, or if not on a word, end of previous word */
5089 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5090 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5094 /* Move to beginning of current word, or if not on a word, begining of next word */
5095 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5096 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5100 case GTK_DELETE_WORD_ENDS:
5103 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5108 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5111 gtk_editable_delete_text (editable, start_pos, end_pos);
5113 case GTK_DELETE_DISPLAY_LINE_ENDS:
5114 case GTK_DELETE_PARAGRAPH_ENDS:
5116 gtk_editable_delete_text (editable, 0, priv->current_pos);
5118 gtk_editable_delete_text (editable, priv->current_pos, -1);
5120 case GTK_DELETE_DISPLAY_LINES:
5121 case GTK_DELETE_PARAGRAPHS:
5122 gtk_editable_delete_text (editable, 0, -1);
5124 case GTK_DELETE_WHITESPACE:
5125 gtk_entry_delete_whitespace (entry);
5129 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5130 gtk_widget_error_bell (GTK_WIDGET (entry));
5132 gtk_entry_pend_cursor_blink (entry);
5136 gtk_entry_backspace (GtkEntry *entry)
5138 GtkEntryPrivate *priv = entry->priv;
5139 GtkEditable *editable = GTK_EDITABLE (entry);
5142 _gtk_entry_reset_im_context (entry);
5144 if (!priv->editable)
5146 gtk_widget_error_bell (GTK_WIDGET (entry));
5150 if (priv->selection_bound != priv->current_pos)
5152 gtk_editable_delete_selection (editable);
5156 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5158 if (prev_pos < priv->current_pos)
5160 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5161 PangoLogAttr *log_attrs;
5164 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5166 /* Deleting parts of characters */
5167 if (log_attrs[priv->current_pos].backspace_deletes_character)
5169 gchar *cluster_text;
5170 gchar *normalized_text;
5173 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5175 normalized_text = g_utf8_normalize (cluster_text,
5176 strlen (cluster_text),
5178 len = g_utf8_strlen (normalized_text, -1);
5180 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5183 gint pos = priv->current_pos;
5185 gtk_editable_insert_text (editable, normalized_text,
5186 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5188 gtk_editable_set_position (editable, pos);
5191 g_free (normalized_text);
5192 g_free (cluster_text);
5196 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5203 gtk_widget_error_bell (GTK_WIDGET (entry));
5206 gtk_entry_pend_cursor_blink (entry);
5210 gtk_entry_copy_clipboard (GtkEntry *entry)
5212 GtkEntryPrivate *priv = entry->priv;
5213 GtkEditable *editable = GTK_EDITABLE (entry);
5217 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5221 gtk_widget_error_bell (GTK_WIDGET (entry));
5225 str = _gtk_entry_get_display_text (entry, start, end);
5226 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5227 GDK_SELECTION_CLIPBOARD),
5234 gtk_entry_cut_clipboard (GtkEntry *entry)
5236 GtkEntryPrivate *priv = entry->priv;
5237 GtkEditable *editable = GTK_EDITABLE (entry);
5242 gtk_widget_error_bell (GTK_WIDGET (entry));
5246 gtk_entry_copy_clipboard (entry);
5250 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5251 gtk_editable_delete_text (editable, start, end);
5255 gtk_widget_error_bell (GTK_WIDGET (entry));
5260 gtk_entry_paste_clipboard (GtkEntry *entry)
5262 GtkEntryPrivate *priv = entry->priv;
5265 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5267 gtk_widget_error_bell (GTK_WIDGET (entry));
5271 gtk_entry_delete_cb (GtkEntry *entry)
5273 GtkEntryPrivate *priv = entry->priv;
5274 GtkEditable *editable = GTK_EDITABLE (entry);
5279 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5280 gtk_editable_delete_text (editable, start, end);
5285 gtk_entry_toggle_overwrite (GtkEntry *entry)
5287 GtkEntryPrivate *priv = entry->priv;
5289 priv->overwrite_mode = !priv->overwrite_mode;
5290 gtk_entry_pend_cursor_blink (entry);
5291 gtk_widget_queue_draw (GTK_WIDGET (entry));
5295 gtk_entry_select_all (GtkEntry *entry)
5297 gtk_entry_select_line (entry);
5301 gtk_entry_real_activate (GtkEntry *entry)
5303 GtkEntryPrivate *priv = entry->priv;
5305 GtkWidget *default_widget, *focus_widget;
5306 GtkWidget *toplevel;
5309 widget = GTK_WIDGET (entry);
5311 if (priv->activates_default)
5313 toplevel = gtk_widget_get_toplevel (widget);
5314 if (GTK_IS_WINDOW (toplevel))
5316 window = GTK_WINDOW (toplevel);
5320 default_widget = gtk_window_get_default_widget (window);
5321 focus_widget = gtk_window_get_focus (window);
5322 if (widget != default_widget &&
5323 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5324 gtk_window_activate_default (window);
5331 keymap_direction_changed (GdkKeymap *keymap,
5334 gtk_entry_recompute (entry);
5337 /* IM Context Callbacks
5341 gtk_entry_commit_cb (GtkIMContext *context,
5345 GtkEntryPrivate *priv = entry->priv;
5348 gtk_entry_enter_text (entry, str);
5352 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5355 GtkEntryPrivate *priv = entry->priv;
5359 gchar *preedit_string;
5362 gtk_im_context_get_preedit_string (priv->im_context,
5363 &preedit_string, NULL,
5365 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5366 priv->preedit_length = strlen (preedit_string);
5367 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5368 priv->preedit_cursor = cursor_pos;
5369 g_free (preedit_string);
5371 gtk_entry_recompute (entry);
5376 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5379 GtkEntryPrivate *priv = entry->priv;
5382 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5383 text = _gtk_entry_get_display_text (entry, 0, -1);
5384 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5385 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5392 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5397 GtkEntryPrivate *priv = entry->priv;
5400 gtk_editable_delete_text (GTK_EDITABLE (entry),
5401 priv->current_pos + offset,
5402 priv->current_pos + offset + n_chars);
5407 /* Internal functions
5410 /* Used for im_commit_cb and inserting Unicode chars */
5412 gtk_entry_enter_text (GtkEntry *entry,
5415 GtkEntryPrivate *priv = entry->priv;
5416 GtkEditable *editable = GTK_EDITABLE (entry);
5418 gboolean old_need_im_reset;
5420 old_need_im_reset = priv->need_im_reset;
5421 priv->need_im_reset = FALSE;
5423 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5424 gtk_editable_delete_selection (editable);
5427 if (priv->overwrite_mode)
5428 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5431 tmp_pos = priv->current_pos;
5432 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5433 gtk_editable_set_position (editable, tmp_pos);
5435 priv->need_im_reset = old_need_im_reset;
5438 /* All changes to priv->current_pos and priv->selection_bound
5439 * should go through this function.
5442 gtk_entry_set_positions (GtkEntry *entry,
5444 gint selection_bound)
5446 GtkEntryPrivate *priv = entry->priv;
5447 gboolean changed = FALSE;
5449 g_object_freeze_notify (G_OBJECT (entry));
5451 if (current_pos != -1 &&
5452 priv->current_pos != current_pos)
5454 priv->current_pos = current_pos;
5457 g_object_notify (G_OBJECT (entry), "cursor-position");
5460 if (selection_bound != -1 &&
5461 priv->selection_bound != selection_bound)
5463 priv->selection_bound = selection_bound;
5466 g_object_notify (G_OBJECT (entry), "selection-bound");
5469 g_object_thaw_notify (G_OBJECT (entry));
5473 gtk_entry_move_adjustments (entry);
5474 gtk_entry_recompute (entry);
5479 gtk_entry_reset_layout (GtkEntry *entry)
5481 GtkEntryPrivate *priv = entry->priv;
5483 if (priv->cached_layout)
5485 g_object_unref (priv->cached_layout);
5486 priv->cached_layout = NULL;
5491 update_im_cursor_location (GtkEntry *entry)
5493 GtkEntryPrivate *priv = entry->priv;
5496 gint strong_xoffset;
5497 gint area_width, area_height;
5499 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5500 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5502 strong_xoffset = strong_x - priv->scroll_offset;
5503 if (strong_xoffset < 0)
5507 else if (strong_xoffset > area_width)
5509 strong_xoffset = area_width;
5511 area.x = strong_xoffset;
5514 area.height = area_height;
5516 gtk_im_context_set_cursor_location (priv->im_context, &area);
5520 recompute_idle_func (gpointer data)
5522 GtkEntry *entry = GTK_ENTRY (data);
5523 GtkEntryPrivate *priv = entry->priv;
5525 priv->recompute_idle = 0;
5527 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5529 gtk_entry_adjust_scroll (entry);
5530 gtk_widget_queue_draw (GTK_WIDGET (entry));
5532 update_im_cursor_location (entry);
5539 gtk_entry_recompute (GtkEntry *entry)
5541 GtkEntryPrivate *priv = entry->priv;
5543 gtk_entry_reset_layout (entry);
5544 gtk_entry_check_cursor_blink (entry);
5546 if (!priv->recompute_idle)
5548 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5549 recompute_idle_func, entry, NULL);
5554 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5557 GtkWidget *widget = GTK_WIDGET (entry);
5558 GtkStyleContext *context;
5559 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5561 context = gtk_widget_get_style_context (widget);
5562 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5564 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5565 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5566 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5569 static inline gboolean
5570 show_placeholder_text (GtkEntry *entry)
5572 GtkEntryPrivate *priv = entry->priv;
5574 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5575 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5576 priv->placeholder_text != NULL)
5582 static PangoLayout *
5583 gtk_entry_create_layout (GtkEntry *entry,
5584 gboolean include_preedit)
5586 GtkEntryPrivate *priv = entry->priv;
5587 GtkWidget *widget = GTK_WIDGET (entry);
5588 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5589 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5590 gboolean placeholder_layout = show_placeholder_text (entry);
5592 gchar *preedit_string = NULL;
5593 gint preedit_length = 0;
5594 PangoAttrList *preedit_attrs = NULL;
5599 pango_layout_set_single_paragraph_mode (layout, TRUE);
5601 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5602 n_bytes = strlen (display);
5604 if (!placeholder_layout && include_preedit)
5606 gtk_im_context_get_preedit_string (priv->im_context,
5607 &preedit_string, &preedit_attrs, NULL);
5608 preedit_length = priv->preedit_length;
5610 else if (placeholder_layout)
5613 PangoAttribute *attr;
5615 gtk_entry_get_placeholder_text_color (entry, &color);
5616 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5617 attr->start_index = 0;
5618 attr->end_index = G_MAXINT;
5619 pango_attr_list_insert (tmp_attrs, attr);
5624 GString *tmp_string = g_string_new (display);
5625 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5627 g_string_insert (tmp_string, cursor_index, preedit_string);
5629 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5631 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5632 cursor_index, preedit_length);
5634 g_string_free (tmp_string, TRUE);
5638 PangoDirection pango_dir;
5640 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5641 pango_dir = pango_find_base_dir (display, n_bytes);
5643 pango_dir = PANGO_DIRECTION_NEUTRAL;
5645 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5647 if (gtk_widget_has_focus (widget))
5649 GdkDisplay *display = gtk_widget_get_display (widget);
5650 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5651 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5652 pango_dir = PANGO_DIRECTION_RTL;
5654 pango_dir = PANGO_DIRECTION_LTR;
5658 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5659 pango_dir = PANGO_DIRECTION_RTL;
5661 pango_dir = PANGO_DIRECTION_LTR;
5665 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5668 priv->resolved_dir = pango_dir;
5670 pango_layout_set_text (layout, display, n_bytes);
5673 pango_layout_set_attributes (layout, tmp_attrs);
5675 g_free (preedit_string);
5679 pango_attr_list_unref (preedit_attrs);
5681 pango_attr_list_unref (tmp_attrs);
5686 static PangoLayout *
5687 gtk_entry_ensure_layout (GtkEntry *entry,
5688 gboolean include_preedit)
5690 GtkEntryPrivate *priv = entry->priv;
5692 if (priv->preedit_length > 0 &&
5693 !include_preedit != !priv->cache_includes_preedit)
5694 gtk_entry_reset_layout (entry);
5696 if (!priv->cached_layout)
5698 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5699 priv->cache_includes_preedit = include_preedit;
5702 return priv->cached_layout;
5706 get_layout_position (GtkEntry *entry,
5710 GtkEntryPrivate *priv = entry->priv;
5711 PangoLayout *layout;
5712 PangoRectangle logical_rect;
5713 gint area_width, area_height;
5715 PangoLayoutLine *line;
5717 layout = gtk_entry_ensure_layout (entry, TRUE);
5719 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5720 area_height = PANGO_SCALE * area_height;
5722 line = pango_layout_get_lines_readonly (layout)->data;
5723 pango_layout_line_get_extents (line, NULL, &logical_rect);
5725 /* Align primarily for locale's ascent/descent */
5726 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5727 priv->ascent + logical_rect.y);
5729 /* Now see if we need to adjust to fit in actual drawn string */
5730 if (logical_rect.height > area_height)
5731 y_pos = (area_height - logical_rect.height) / 2;
5734 else if (y_pos + logical_rect.height > area_height)
5735 y_pos = area_height - logical_rect.height;
5737 y_pos = y_pos / PANGO_SCALE;
5740 *x = - priv->scroll_offset;
5747 draw_text_with_color (GtkEntry *entry,
5749 GdkRGBA *default_color)
5751 GtkEntryPrivate *priv = entry->priv;
5752 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5755 gint start_pos, end_pos;
5757 widget = GTK_WIDGET (entry);
5761 get_layout_position (entry, &x, &y);
5763 cairo_move_to (cr, x, y);
5764 gdk_cairo_set_source_rgba (cr, default_color);
5765 pango_cairo_show_layout (cr, layout);
5767 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5771 PangoRectangle logical_rect;
5772 GdkRGBA selection_color, text_color;
5773 GtkStyleContext *context;
5774 GtkStateFlags state;
5776 context = gtk_widget_get_style_context (widget);
5777 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5778 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5780 state = gtk_widget_get_state_flags (widget);
5781 state |= GTK_STATE_FLAG_SELECTED;
5783 gtk_style_context_get_background_color (context, state, &selection_color);
5784 gtk_style_context_get_color (context, state, &text_color);
5786 for (i = 0; i < n_ranges; ++i)
5787 cairo_rectangle (cr,
5788 - priv->scroll_offset + ranges[2 * i],
5791 logical_rect.height);
5795 gdk_cairo_set_source_rgba (cr, &selection_color);
5798 cairo_move_to (cr, x, y);
5799 gdk_cairo_set_source_rgba (cr, &text_color);
5800 pango_cairo_show_layout (cr, layout);
5808 gtk_entry_draw_text (GtkEntry *entry,
5811 GtkEntryPrivate *priv = entry->priv;
5812 GtkWidget *widget = GTK_WIDGET (entry);
5813 GtkStateFlags state = 0;
5814 GdkRGBA text_color, bar_text_color;
5815 GtkStyleContext *context;
5817 gint progress_x, progress_y, progress_width, progress_height;
5818 gint clip_width, clip_height;
5820 /* Nothing to display at all */
5821 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5824 state = gtk_widget_get_state_flags (widget);
5825 context = gtk_widget_get_style_context (widget);
5827 gtk_style_context_get_color (context, state, &text_color);
5829 /* Get foreground color for progressbars */
5830 gtk_entry_prepare_context_for_progress (entry, context);
5831 gtk_style_context_get_color (context, state, &bar_text_color);
5832 gtk_style_context_restore (context);
5834 get_progress_area (widget,
5835 &progress_x, &progress_y,
5836 &progress_width, &progress_height);
5840 clip_width = gdk_window_get_width (priv->text_area);
5841 clip_height = gdk_window_get_height (priv->text_area);
5842 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5845 /* If the color is the same, or the progress area has a zero
5846 * size, then we only need to draw once. */
5847 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5848 ((progress_width == 0) || (progress_height == 0)))
5850 draw_text_with_color (entry, cr, &text_color);
5854 int frame_x, frame_y, area_x, area_y;
5856 width = gdk_window_get_width (priv->text_area);
5857 height = gdk_window_get_height (priv->text_area);
5861 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5862 cairo_rectangle (cr, 0, 0, width, height);
5864 /* progres area is frame-relative, we need it text-area window
5866 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5867 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5868 progress_x += frame_x - area_x;
5869 progress_y += frame_y - area_y;
5871 cairo_rectangle (cr, progress_x, progress_y,
5872 progress_width, progress_height);
5874 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5876 draw_text_with_color (entry, cr, &text_color);
5881 cairo_rectangle (cr, progress_x, progress_y,
5882 progress_width, progress_height);
5885 draw_text_with_color (entry, cr, &bar_text_color);
5894 gtk_entry_draw_cursor (GtkEntry *entry,
5898 GtkEntryPrivate *priv = entry->priv;
5899 GtkWidget *widget = GTK_WIDGET (entry);
5900 GtkStyleContext *context;
5901 PangoRectangle cursor_rect;
5904 gboolean block_at_line_end;
5905 PangoLayout *layout;
5909 context = gtk_widget_get_style_context (widget);
5911 layout = gtk_entry_ensure_layout (entry, TRUE);
5912 text = pango_layout_get_text (layout);
5913 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5914 get_layout_position (entry, &x, &y);
5916 if (!priv->overwrite_mode)
5919 block = _gtk_text_util_get_block_cursor_location (layout,
5920 cursor_index, &cursor_rect, &block_at_line_end);
5924 gtk_render_insertion_cursor (context, cr,
5926 layout, cursor_index, priv->resolved_dir);
5928 else /* overwrite_mode */
5930 GdkRGBA cursor_color;
5935 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5936 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5937 rect.width = PANGO_PIXELS (cursor_rect.width);
5938 rect.height = PANGO_PIXELS (cursor_rect.height);
5940 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5941 gdk_cairo_set_source_rgba (cr, &cursor_color);
5942 gdk_cairo_rectangle (cr, &rect);
5945 if (!block_at_line_end)
5947 GtkStateFlags state;
5950 state = gtk_widget_get_state_flags (widget);
5951 gtk_style_context_get_background_color (context, state, &color);
5953 gdk_cairo_rectangle (cr, &rect);
5955 cairo_move_to (cr, x, y);
5956 gdk_cairo_set_source_rgba (cr, &color);
5957 pango_cairo_show_layout (cr, layout);
5965 _gtk_entry_reset_im_context (GtkEntry *entry)
5967 GtkEntryPrivate *priv = entry->priv;
5969 if (priv->need_im_reset)
5971 priv->need_im_reset = FALSE;
5972 gtk_im_context_reset (priv->im_context);
5977 * gtk_entry_reset_im_context:
5978 * @entry: a #GtkEntry
5980 * Reset the input method context of the entry if needed.
5982 * This can be necessary in the case where modifying the buffer
5983 * would confuse on-going input method behavior.
5988 gtk_entry_reset_im_context (GtkEntry *entry)
5990 g_return_if_fail (GTK_IS_ENTRY (entry));
5992 _gtk_entry_reset_im_context (entry);
5996 * gtk_entry_im_context_filter_keypress:
5997 * @entry: a #GtkEntry
5998 * @event: (type Gdk.EventKey): the key event
6000 * Allow the #GtkEntry input method to internally handle key press
6001 * and release events. If this function returns %TRUE, then no further
6002 * processing should be done for this key event. See
6003 * gtk_im_context_filter_keypress().
6005 * Note that you are expected to call this function from your handler
6006 * when overriding key event handling. This is needed in the case when
6007 * you need to insert your own key handling between the input method
6008 * and the default key event handling of the #GtkEntry.
6009 * See gtk_text_view_reset_im_context() for an example of use.
6011 * Return value: %TRUE if the input method handled the key event.
6016 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6019 GtkEntryPrivate *priv;
6021 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6025 return gtk_im_context_filter_keypress (priv->im_context, event);
6029 _gtk_entry_get_im_context (GtkEntry *entry)
6031 return entry->priv->im_context;
6035 gtk_entry_find_position (GtkEntry *entry,
6038 GtkEntryPrivate *priv = entry->priv;
6039 PangoLayout *layout;
6040 PangoLayoutLine *line;
6047 layout = gtk_entry_ensure_layout (entry, TRUE);
6048 text = pango_layout_get_text (layout);
6049 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6051 line = pango_layout_get_lines_readonly (layout)->data;
6052 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6054 if (index >= cursor_index && priv->preedit_length)
6056 if (index >= cursor_index + priv->preedit_length)
6057 index -= priv->preedit_length;
6060 index = cursor_index;
6065 pos = g_utf8_pointer_to_offset (text, text + index);
6072 gtk_entry_get_cursor_locations (GtkEntry *entry,
6077 GtkEntryPrivate *priv = entry->priv;
6078 DisplayMode mode = gtk_entry_get_display_mode (entry);
6080 /* Nothing to display at all, so no cursor is relevant */
6081 if (mode == DISPLAY_BLANK)
6091 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6092 const gchar *text = pango_layout_get_text (layout);
6093 PangoRectangle strong_pos, weak_pos;
6096 if (type == CURSOR_STANDARD)
6098 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6100 else /* type == CURSOR_DND */
6102 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6104 if (priv->dnd_position > priv->current_pos)
6106 if (mode == DISPLAY_NORMAL)
6107 index += priv->preedit_length;
6110 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6111 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6116 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6119 *strong_x = strong_pos.x / PANGO_SCALE;
6122 *weak_x = weak_pos.x / PANGO_SCALE;
6127 gtk_entry_adjust_scroll (GtkEntry *entry)
6129 GtkEntryPrivate *priv = entry->priv;
6130 gint min_offset, max_offset;
6131 gint text_area_width, text_width;
6132 gint strong_x, weak_x;
6133 gint strong_xoffset, weak_xoffset;
6135 PangoLayout *layout;
6136 PangoLayoutLine *line;
6137 PangoRectangle logical_rect;
6139 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6142 text_area_width = gdk_window_get_width (priv->text_area);
6144 if (text_area_width < 0)
6145 text_area_width = 0;
6147 layout = gtk_entry_ensure_layout (entry, TRUE);
6148 line = pango_layout_get_lines_readonly (layout)->data;
6150 pango_layout_line_get_extents (line, NULL, &logical_rect);
6152 /* Display as much text as we can */
6154 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6155 xalign = priv->xalign;
6157 xalign = 1.0 - priv->xalign;
6159 text_width = PANGO_PIXELS(logical_rect.width);
6161 if (text_width > text_area_width)
6164 max_offset = text_width - text_area_width;
6168 min_offset = (text_width - text_area_width) * xalign;
6169 max_offset = min_offset;
6172 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6174 /* And make sure cursors are on screen. Note that the cursor is
6175 * actually drawn one pixel into the INNER_BORDER space on
6176 * the right, when the scroll is at the utmost right. This
6177 * looks better to to me than confining the cursor inside the
6178 * border entirely, though it means that the cursor gets one
6179 * pixel closer to the edge of the widget on the right than
6180 * on the left. This might need changing if one changed
6181 * INNER_BORDER from 2 to 1, as one would do on a
6182 * small-screen-real-estate display.
6184 * We always make sure that the strong cursor is on screen, and
6185 * put the weak cursor on screen if possible.
6188 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6190 strong_xoffset = strong_x - priv->scroll_offset;
6192 if (strong_xoffset < 0)
6194 priv->scroll_offset += strong_xoffset;
6197 else if (strong_xoffset > text_area_width)
6199 priv->scroll_offset += strong_xoffset - text_area_width;
6200 strong_xoffset = text_area_width;
6203 weak_xoffset = weak_x - priv->scroll_offset;
6205 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6207 priv->scroll_offset += weak_xoffset;
6209 else if (weak_xoffset > text_area_width &&
6210 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6212 priv->scroll_offset += weak_xoffset - text_area_width;
6215 g_object_notify (G_OBJECT (entry), "scroll-offset");
6219 gtk_entry_move_adjustments (GtkEntry *entry)
6221 GtkWidget *widget = GTK_WIDGET (entry);
6222 GtkAllocation allocation;
6223 GtkAdjustment *adjustment;
6224 PangoContext *context;
6225 PangoFontMetrics *metrics;
6226 GtkStyleContext *style_context;
6227 GtkStateFlags state;
6232 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6236 gtk_widget_get_allocation (widget, &allocation);
6238 /* Cursor position, layout offset, border width, and widget allocation */
6239 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6240 get_layout_position (entry, &layout_x, NULL);
6241 _gtk_entry_get_borders (entry, &borders);
6242 x += allocation.x + layout_x + borders.left;
6244 /* Approximate width of a char, so user can see what is ahead/behind */
6245 context = gtk_widget_get_pango_context (widget);
6246 style_context = gtk_widget_get_style_context (widget);
6247 state = gtk_widget_get_state_flags (widget);
6249 metrics = pango_context_get_metrics (context,
6250 gtk_style_context_get_font (style_context, state),
6251 pango_context_get_language (context));
6252 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6255 gtk_adjustment_clamp_page (adjustment,
6256 x - (char_width + 1), /* one char + one pixel before */
6257 x + (char_width + 2)); /* one char + cursor + one pixel after */
6261 gtk_entry_move_visually (GtkEntry *entry,
6265 GtkEntryPrivate *priv = entry->priv;
6267 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6270 text = pango_layout_get_text (layout);
6272 index = g_utf8_offset_to_pointer (text, start) - text;
6276 int new_index, new_trailing;
6277 gboolean split_cursor;
6280 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6281 "gtk-split-cursor", &split_cursor,
6288 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6289 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6291 strong = keymap_direction == priv->resolved_dir;
6296 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6301 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6307 else if (new_index != G_MAXINT)
6310 while (new_trailing--)
6311 index = g_utf8_next_char (text + index) - text;
6314 return g_utf8_pointer_to_offset (text, text + index);
6318 gtk_entry_move_logically (GtkEntry *entry,
6322 gint new_pos = start;
6325 length = gtk_entry_buffer_get_length (get_buffer (entry));
6327 /* Prevent any leak of information */
6328 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6330 new_pos = CLAMP (start + count, 0, length);
6334 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6335 PangoLogAttr *log_attrs;
6338 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6340 while (count > 0 && new_pos < length)
6344 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6348 while (count < 0 && new_pos > 0)
6352 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6364 gtk_entry_move_forward_word (GtkEntry *entry,
6366 gboolean allow_whitespace)
6368 gint new_pos = start;
6371 length = gtk_entry_buffer_get_length (get_buffer (entry));
6373 /* Prevent any leak of information */
6374 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6378 else if (new_pos < length)
6380 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6381 PangoLogAttr *log_attrs;
6384 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6386 /* Find the next word boundary */
6388 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6389 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6400 gtk_entry_move_backward_word (GtkEntry *entry,
6402 gboolean allow_whitespace)
6404 gint new_pos = start;
6406 /* Prevent any leak of information */
6407 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6413 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6414 PangoLogAttr *log_attrs;
6417 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6419 new_pos = start - 1;
6421 /* Find the previous word boundary */
6422 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6423 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6433 gtk_entry_delete_whitespace (GtkEntry *entry)
6435 GtkEntryPrivate *priv = entry->priv;
6436 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6437 PangoLogAttr *log_attrs;
6441 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6443 start = end = priv->current_pos;
6445 while (start > 0 && log_attrs[start-1].is_white)
6448 while (end < n_attrs && log_attrs[end].is_white)
6454 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6459 gtk_entry_select_word (GtkEntry *entry)
6461 GtkEntryPrivate *priv = entry->priv;
6462 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6463 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6465 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6469 gtk_entry_select_line (GtkEntry *entry)
6471 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6475 truncate_multiline (const gchar *text)
6480 text[length] && text[length] != '\n' && text[length] != '\r';
6487 paste_received (GtkClipboard *clipboard,
6491 GtkEntry *entry = GTK_ENTRY (data);
6492 GtkEditable *editable = GTK_EDITABLE (entry);
6493 GtkEntryPrivate *priv = entry->priv;
6495 if (priv->button == GDK_BUTTON_MIDDLE)
6497 gint pos, start, end;
6498 pos = priv->insert_pos;
6499 gtk_editable_get_selection_bounds (editable, &start, &end);
6500 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6501 gtk_editable_select_region (editable, pos, pos);
6506 gint pos, start, end;
6508 gboolean popup_completion;
6509 GtkEntryCompletion *completion;
6511 completion = gtk_entry_get_completion (entry);
6513 if (priv->truncate_multiline)
6514 length = truncate_multiline (text);
6516 /* only complete if the selection is at the end */
6517 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6518 MAX (priv->current_pos, priv->selection_bound));
6522 if (gtk_widget_get_mapped (completion->priv->popup_window))
6523 _gtk_entry_completion_popdown (completion);
6525 if (!popup_completion && completion->priv->changed_id > 0)
6526 g_signal_handler_block (entry, completion->priv->changed_id);
6529 begin_change (entry);
6530 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6531 gtk_editable_delete_text (editable, start, end);
6533 pos = priv->current_pos;
6534 gtk_editable_insert_text (editable, text, length, &pos);
6535 gtk_editable_set_position (editable, pos);
6539 !popup_completion && completion->priv->changed_id > 0)
6540 g_signal_handler_unblock (entry, completion->priv->changed_id);
6543 g_object_unref (entry);
6547 gtk_entry_paste (GtkEntry *entry,
6550 g_object_ref (entry);
6551 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6552 paste_received, entry);
6556 primary_get_cb (GtkClipboard *clipboard,
6557 GtkSelectionData *selection_data,
6561 GtkEntry *entry = GTK_ENTRY (data);
6564 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6566 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6567 gtk_selection_data_set_text (selection_data, str, -1);
6573 primary_clear_cb (GtkClipboard *clipboard,
6576 GtkEntry *entry = GTK_ENTRY (data);
6577 GtkEntryPrivate *priv = entry->priv;
6579 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6583 gtk_entry_update_primary_selection (GtkEntry *entry)
6585 GtkTargetList *list;
6586 GtkTargetEntry *targets;
6587 GtkClipboard *clipboard;
6591 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6594 list = gtk_target_list_new (NULL, 0);
6595 gtk_target_list_add_text_targets (list, 0);
6597 targets = gtk_target_table_new_from_list (list, &n_targets);
6599 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6601 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6603 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6604 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6605 primary_clear_cb (clipboard, entry);
6609 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6610 gtk_clipboard_clear (clipboard);
6613 gtk_target_table_free (targets, n_targets);
6614 gtk_target_list_unref (list);
6618 gtk_entry_clear (GtkEntry *entry,
6619 GtkEntryIconPosition icon_pos)
6621 GtkEntryPrivate *priv = entry->priv;
6622 EntryIconInfo *icon_info = priv->icons[icon_pos];
6623 GtkImageType storage_type;
6625 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6628 g_object_freeze_notify (G_OBJECT (entry));
6630 /* Explicitly check, as the pointer may become invalidated
6631 * during destruction.
6633 if (GDK_IS_WINDOW (icon_info->window))
6634 gdk_window_hide (icon_info->window);
6636 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6638 switch (storage_type)
6640 case GTK_IMAGE_PIXBUF:
6641 g_object_notify (G_OBJECT (entry),
6642 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6645 case GTK_IMAGE_STOCK:
6646 g_object_notify (G_OBJECT (entry),
6647 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6650 case GTK_IMAGE_ICON_NAME:
6651 g_object_notify (G_OBJECT (entry),
6652 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6655 case GTK_IMAGE_GICON:
6656 g_object_notify (G_OBJECT (entry),
6657 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6661 g_assert_not_reached ();
6665 _gtk_icon_helper_clear (icon_info->icon_helper);
6667 g_object_notify (G_OBJECT (entry),
6668 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6670 g_object_thaw_notify (G_OBJECT (entry));
6674 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6675 GtkEntryIconPosition icon_pos)
6677 GtkEntryPrivate *priv = entry->priv;
6678 EntryIconInfo *icon_info = priv->icons[icon_pos];
6679 GtkStyleContext *context;
6682 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6683 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6685 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6688 gtk_style_context_restore (context);
6699 * Creates a new entry.
6701 * Return value: a new #GtkEntry.
6704 gtk_entry_new (void)
6706 return g_object_new (GTK_TYPE_ENTRY, NULL);
6710 * gtk_entry_new_with_buffer:
6711 * @buffer: The buffer to use for the new #GtkEntry.
6713 * Creates a new entry with the specified text buffer.
6715 * Return value: a new #GtkEntry
6720 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6722 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6723 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6726 static GtkEntryBuffer*
6727 get_buffer (GtkEntry *entry)
6729 GtkEntryPrivate *priv = entry->priv;
6731 if (priv->buffer == NULL)
6733 GtkEntryBuffer *buffer;
6734 buffer = gtk_entry_buffer_new (NULL, 0);
6735 gtk_entry_set_buffer (entry, buffer);
6736 g_object_unref (buffer);
6739 return priv->buffer;
6743 * gtk_entry_get_buffer:
6744 * @entry: a #GtkEntry
6746 * Get the #GtkEntryBuffer object which holds the text for
6751 * Returns: (transfer none): A #GtkEntryBuffer object.
6754 gtk_entry_get_buffer (GtkEntry *entry)
6756 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6758 return get_buffer (entry);
6762 * gtk_entry_set_buffer:
6763 * @entry: a #GtkEntry
6764 * @buffer: a #GtkEntryBuffer
6766 * Set the #GtkEntryBuffer object which holds the text for
6772 gtk_entry_set_buffer (GtkEntry *entry,
6773 GtkEntryBuffer *buffer)
6775 GtkEntryPrivate *priv;
6778 g_return_if_fail (GTK_IS_ENTRY (entry));
6784 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6785 g_object_ref (buffer);
6790 buffer_disconnect_signals (entry);
6791 g_object_unref (priv->buffer);
6794 priv->buffer = buffer;
6797 buffer_connect_signals (entry);
6799 obj = G_OBJECT (entry);
6800 g_object_freeze_notify (obj);
6801 g_object_notify (obj, "buffer");
6802 g_object_notify (obj, "text");
6803 g_object_notify (obj, "text-length");
6804 g_object_notify (obj, "max-length");
6805 g_object_notify (obj, "visibility");
6806 g_object_notify (obj, "invisible-char");
6807 g_object_notify (obj, "invisible-char-set");
6808 g_object_thaw_notify (obj);
6810 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6811 gtk_entry_recompute (entry);
6815 * gtk_entry_get_text_area:
6816 * @entry: a #GtkEntry
6817 * @text_area: (out): Return location for the text area.
6819 * Gets the area where the entry's text is drawn. This function is
6820 * useful when drawing something to the entry in a draw callback.
6822 * If the entry is not realized, @text_area is filled with zeros.
6824 * See also gtk_entry_get_icon_area().
6829 gtk_entry_get_text_area (GtkEntry *entry,
6830 GdkRectangle *text_area)
6832 GtkEntryPrivate *priv;
6834 g_return_if_fail (GTK_IS_ENTRY (entry));
6835 g_return_if_fail (text_area != NULL);
6839 if (priv->text_area)
6841 GtkAllocation allocation;
6844 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6845 gdk_window_get_position (priv->text_area, &x, &y);
6847 text_area->x = x - allocation.x;
6848 text_area->y = y - allocation.y;
6849 text_area->width = gdk_window_get_width (priv->text_area);
6850 text_area->height = gdk_window_get_height (priv->text_area);
6856 text_area->width = 0;
6857 text_area->height = 0;
6862 * gtk_entry_set_text:
6863 * @entry: a #GtkEntry
6864 * @text: the new text
6866 * Sets the text in the widget to the given
6867 * value, replacing the current contents.
6869 * See gtk_entry_buffer_set_text().
6872 gtk_entry_set_text (GtkEntry *entry,
6876 GtkEntryCompletion *completion;
6878 g_return_if_fail (GTK_IS_ENTRY (entry));
6879 g_return_if_fail (text != NULL);
6881 /* Actually setting the text will affect the cursor and selection;
6882 * if the contents don't actually change, this will look odd to the user.
6884 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6887 completion = gtk_entry_get_completion (entry);
6888 if (completion && completion->priv->changed_id > 0)
6889 g_signal_handler_block (entry, completion->priv->changed_id);
6891 begin_change (entry);
6892 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6894 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6897 if (completion && completion->priv->changed_id > 0)
6898 g_signal_handler_unblock (entry, completion->priv->changed_id);
6902 * gtk_entry_set_visibility:
6903 * @entry: a #GtkEntry
6904 * @visible: %TRUE if the contents of the entry are displayed
6907 * Sets whether the contents of the entry are visible or not.
6908 * When visibility is set to %FALSE, characters are displayed
6909 * as the invisible char, and will also appear that way when
6910 * the text in the entry widget is copied elsewhere.
6912 * By default, GTK+ picks the best invisible character available
6913 * in the current font, but it can be changed with
6914 * gtk_entry_set_invisible_char().
6917 gtk_entry_set_visibility (GtkEntry *entry,
6920 GtkEntryPrivate *priv;
6922 g_return_if_fail (GTK_IS_ENTRY (entry));
6926 visible = visible != FALSE;
6928 if (priv->visible != visible)
6930 priv->visible = visible;
6932 g_object_notify (G_OBJECT (entry), "visibility");
6933 gtk_entry_recompute (entry);
6938 * gtk_entry_get_visibility:
6939 * @entry: a #GtkEntry
6941 * Retrieves whether the text in @entry is visible. See
6942 * gtk_entry_set_visibility().
6944 * Return value: %TRUE if the text is currently visible
6947 gtk_entry_get_visibility (GtkEntry *entry)
6949 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6951 return entry->priv->visible;
6955 * gtk_entry_set_invisible_char:
6956 * @entry: a #GtkEntry
6957 * @ch: a Unicode character
6959 * Sets the character to use in place of the actual text when
6960 * gtk_entry_set_visibility() has been called to set text visibility
6961 * to %FALSE. i.e. this is the character used in "password mode" to
6962 * show the user how many characters have been typed. By default, GTK+
6963 * picks the best invisible char available in the current font. If you
6964 * set the invisible char to 0, then the user will get no feedback
6965 * at all; there will be no text on the screen as they type.
6968 gtk_entry_set_invisible_char (GtkEntry *entry,
6971 GtkEntryPrivate *priv;
6973 g_return_if_fail (GTK_IS_ENTRY (entry));
6977 if (!priv->invisible_char_set)
6979 priv->invisible_char_set = TRUE;
6980 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6983 if (ch == priv->invisible_char)
6986 priv->invisible_char = ch;
6987 g_object_notify (G_OBJECT (entry), "invisible-char");
6988 gtk_entry_recompute (entry);
6992 * gtk_entry_get_invisible_char:
6993 * @entry: a #GtkEntry
6995 * Retrieves the character displayed in place of the real characters
6996 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6998 * Return value: the current invisible char, or 0, if the entry does not
6999 * show invisible text at all.
7002 gtk_entry_get_invisible_char (GtkEntry *entry)
7004 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7006 return entry->priv->invisible_char;
7010 * gtk_entry_unset_invisible_char:
7011 * @entry: a #GtkEntry
7013 * Unsets the invisible char previously set with
7014 * gtk_entry_set_invisible_char(). So that the
7015 * default invisible char is used again.
7020 gtk_entry_unset_invisible_char (GtkEntry *entry)
7022 GtkEntryPrivate *priv;
7025 g_return_if_fail (GTK_IS_ENTRY (entry));
7029 if (!priv->invisible_char_set)
7032 priv->invisible_char_set = FALSE;
7033 ch = find_invisible_char (GTK_WIDGET (entry));
7035 if (priv->invisible_char != ch)
7037 priv->invisible_char = ch;
7038 g_object_notify (G_OBJECT (entry), "invisible-char");
7041 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7042 gtk_entry_recompute (entry);
7046 * gtk_entry_set_overwrite_mode:
7047 * @entry: a #GtkEntry
7048 * @overwrite: new value
7050 * Sets whether the text is overwritten when typing in the #GtkEntry.
7055 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7058 GtkEntryPrivate *priv = entry->priv;
7060 g_return_if_fail (GTK_IS_ENTRY (entry));
7062 if (priv->overwrite_mode == overwrite)
7065 gtk_entry_toggle_overwrite (entry);
7067 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7071 * gtk_entry_get_overwrite_mode:
7072 * @entry: a #GtkEntry
7074 * Gets the value set by gtk_entry_set_overwrite_mode().
7076 * Return value: whether the text is overwritten when typing.
7081 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7083 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7085 return entry->priv->overwrite_mode;
7089 * gtk_entry_get_text:
7090 * @entry: a #GtkEntry
7092 * Retrieves the contents of the entry widget.
7093 * See also gtk_editable_get_chars().
7095 * This is equivalent to:
7097 * <informalexample><programlisting>
7098 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7099 * </programlisting></informalexample>
7101 * Return value: a pointer to the contents of the widget as a
7102 * string. This string points to internally allocated
7103 * storage in the widget and must not be freed, modified or
7107 gtk_entry_get_text (GtkEntry *entry)
7109 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7111 return gtk_entry_buffer_get_text (get_buffer (entry));
7115 * gtk_entry_set_max_length:
7116 * @entry: a #GtkEntry
7117 * @max: the maximum length of the entry, or 0 for no maximum.
7118 * (other than the maximum length of entries.) The value passed in will
7119 * be clamped to the range 0-65536.
7121 * Sets the maximum allowed length of the contents of the widget. If
7122 * the current contents are longer than the given length, then they
7123 * will be truncated to fit.
7125 * This is equivalent to:
7127 * <informalexample><programlisting>
7128 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7129 * </programlisting></informalexample>
7132 gtk_entry_set_max_length (GtkEntry *entry,
7135 g_return_if_fail (GTK_IS_ENTRY (entry));
7136 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7140 * gtk_entry_get_max_length:
7141 * @entry: a #GtkEntry
7143 * Retrieves the maximum allowed length of the text in
7144 * @entry. See gtk_entry_set_max_length().
7146 * This is equivalent to:
7148 * <informalexample><programlisting>
7149 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7150 * </programlisting></informalexample>
7152 * Return value: the maximum allowed number of characters
7153 * in #GtkEntry, or 0 if there is no maximum.
7156 gtk_entry_get_max_length (GtkEntry *entry)
7158 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7160 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7164 * gtk_entry_get_text_length:
7165 * @entry: a #GtkEntry
7167 * Retrieves the current length of the text in
7170 * This is equivalent to:
7172 * <informalexample><programlisting>
7173 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7174 * </programlisting></informalexample>
7176 * Return value: the current number of characters
7177 * in #GtkEntry, or 0 if there are none.
7182 gtk_entry_get_text_length (GtkEntry *entry)
7184 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7186 return gtk_entry_buffer_get_length (get_buffer (entry));
7190 * gtk_entry_set_activates_default:
7191 * @entry: a #GtkEntry
7192 * @setting: %TRUE to activate window's default widget on Enter keypress
7194 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7195 * widget for the window containing the entry. This usually means that
7196 * the dialog box containing the entry will be closed, since the default
7197 * widget is usually one of the dialog buttons.
7199 * (For experts: if @setting is %TRUE, the entry calls
7200 * gtk_window_activate_default() on the window containing the entry, in
7201 * the default handler for the #GtkEntry::activate signal.)
7204 gtk_entry_set_activates_default (GtkEntry *entry,
7207 GtkEntryPrivate *priv;
7209 g_return_if_fail (GTK_IS_ENTRY (entry));
7213 setting = setting != FALSE;
7215 if (setting != priv->activates_default)
7217 priv->activates_default = setting;
7218 g_object_notify (G_OBJECT (entry), "activates-default");
7223 * gtk_entry_get_activates_default:
7224 * @entry: a #GtkEntry
7226 * Retrieves the value set by gtk_entry_set_activates_default().
7228 * Return value: %TRUE if the entry will activate the default widget
7231 gtk_entry_get_activates_default (GtkEntry *entry)
7233 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7235 return entry->priv->activates_default;
7239 * gtk_entry_set_width_chars:
7240 * @entry: a #GtkEntry
7241 * @n_chars: width in chars
7243 * Changes the size request of the entry to be about the right size
7244 * for @n_chars characters. Note that it changes the size
7245 * <emphasis>request</emphasis>, the size can still be affected by
7246 * how you pack the widget into containers. If @n_chars is -1, the
7247 * size reverts to the default entry size.
7250 gtk_entry_set_width_chars (GtkEntry *entry,
7253 GtkEntryPrivate *priv;
7255 g_return_if_fail (GTK_IS_ENTRY (entry));
7259 if (priv->width_chars != n_chars)
7261 priv->width_chars = n_chars;
7262 g_object_notify (G_OBJECT (entry), "width-chars");
7263 gtk_widget_queue_resize (GTK_WIDGET (entry));
7268 * gtk_entry_get_width_chars:
7269 * @entry: a #GtkEntry
7271 * Gets the value set by gtk_entry_set_width_chars().
7273 * Return value: number of chars to request space for, or negative if unset
7276 gtk_entry_get_width_chars (GtkEntry *entry)
7278 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7280 return entry->priv->width_chars;
7284 * gtk_entry_set_has_frame:
7285 * @entry: a #GtkEntry
7286 * @setting: new value
7288 * Sets whether the entry has a beveled frame around it.
7291 gtk_entry_set_has_frame (GtkEntry *entry,
7294 GtkEntryPrivate *priv;
7296 g_return_if_fail (GTK_IS_ENTRY (entry));
7300 setting = (setting != FALSE);
7302 if (priv->has_frame == setting)
7305 gtk_widget_queue_resize (GTK_WIDGET (entry));
7306 priv->has_frame = setting;
7307 g_object_notify (G_OBJECT (entry), "has-frame");
7311 * gtk_entry_get_has_frame:
7312 * @entry: a #GtkEntry
7314 * Gets the value set by gtk_entry_set_has_frame().
7316 * Return value: whether the entry has a beveled frame
7319 gtk_entry_get_has_frame (GtkEntry *entry)
7321 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7323 return entry->priv->has_frame;
7327 * gtk_entry_set_inner_border:
7328 * @entry: a #GtkEntry
7329 * @border: (allow-none): a #GtkBorder, or %NULL
7331 * Sets %entry's inner-border property to %border, or clears it if %NULL
7332 * is passed. The inner-border is the area around the entry's text, but
7335 * If set, this property overrides the inner-border style property.
7336 * Overriding the style-provided border is useful when you want to do
7337 * in-place editing of some text in a canvas or list widget, where
7338 * pixel-exact positioning of the entry is important.
7342 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7343 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7344 * this function is ignored by #GtkEntry.
7347 gtk_entry_set_inner_border (GtkEntry *entry,
7348 const GtkBorder *border)
7350 g_return_if_fail (GTK_IS_ENTRY (entry));
7352 gtk_entry_do_set_inner_border (entry, border);
7356 * gtk_entry_get_inner_border:
7357 * @entry: a #GtkEntry
7359 * This function returns the entry's #GtkEntry:inner-border property. See
7360 * gtk_entry_set_inner_border() for more information.
7362 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7366 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7367 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7368 * this function is ignored by #GtkEntry.
7371 gtk_entry_get_inner_border (GtkEntry *entry)
7373 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7375 return gtk_entry_do_get_inner_border (entry);
7379 * gtk_entry_get_layout:
7380 * @entry: a #GtkEntry
7382 * Gets the #PangoLayout used to display the entry.
7383 * The layout is useful to e.g. convert text positions to
7384 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7385 * The returned layout is owned by the entry and must not be
7386 * modified or freed by the caller.
7388 * Keep in mind that the layout text may contain a preedit string, so
7389 * gtk_entry_layout_index_to_text_index() and
7390 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7391 * indices in the layout to byte indices in the entry contents.
7393 * Return value: (transfer none): the #PangoLayout for this entry
7396 gtk_entry_get_layout (GtkEntry *entry)
7398 PangoLayout *layout;
7400 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7402 layout = gtk_entry_ensure_layout (entry, TRUE);
7409 * gtk_entry_layout_index_to_text_index:
7410 * @entry: a #GtkEntry
7411 * @layout_index: byte index into the entry layout text
7413 * Converts from a position in the entry contents (returned
7414 * by gtk_entry_get_text()) to a position in the
7415 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7416 * with text retrieved via pango_layout_get_text()).
7418 * Return value: byte index into the entry contents
7421 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7424 GtkEntryPrivate *priv;
7425 PangoLayout *layout;
7429 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7433 layout = gtk_entry_ensure_layout (entry, TRUE);
7434 text = pango_layout_get_text (layout);
7435 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7437 if (layout_index >= cursor_index && priv->preedit_length)
7439 if (layout_index >= cursor_index + priv->preedit_length)
7440 layout_index -= priv->preedit_length;
7442 layout_index = cursor_index;
7445 return layout_index;
7449 * gtk_entry_text_index_to_layout_index:
7450 * @entry: a #GtkEntry
7451 * @text_index: byte index into the entry contents
7453 * Converts from a position in the entry's #PangoLayout (returned by
7454 * gtk_entry_get_layout()) to a position in the entry contents
7455 * (returned by gtk_entry_get_text()).
7457 * Return value: byte index into the entry layout text
7460 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7463 GtkEntryPrivate *priv;
7464 PangoLayout *layout;
7468 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7472 layout = gtk_entry_ensure_layout (entry, TRUE);
7473 text = pango_layout_get_text (layout);
7474 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7476 if (text_index > cursor_index)
7477 text_index += priv->preedit_length;
7483 * gtk_entry_get_layout_offsets:
7484 * @entry: a #GtkEntry
7485 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7486 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7489 * Obtains the position of the #PangoLayout used to render text
7490 * in the entry, in widget coordinates. Useful if you want to line
7491 * up the text in an entry with some other text, e.g. when using the
7492 * entry to implement editable cells in a sheet widget.
7494 * Also useful to convert mouse events into coordinates inside the
7495 * #PangoLayout, e.g. to take some action if some part of the entry text
7498 * Note that as the user scrolls around in the entry the offsets will
7499 * change; you'll need to connect to the "notify::scroll-offset"
7500 * signal to track this. Remember when using the #PangoLayout
7501 * functions you need to convert to and from pixels using
7502 * PANGO_PIXELS() or #PANGO_SCALE.
7504 * Keep in mind that the layout text may contain a preedit string, so
7505 * gtk_entry_layout_index_to_text_index() and
7506 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7507 * indices in the layout to byte indices in the entry contents.
7510 gtk_entry_get_layout_offsets (GtkEntry *entry,
7514 gint text_area_x, text_area_y;
7516 g_return_if_fail (GTK_IS_ENTRY (entry));
7518 /* this gets coords relative to text area */
7519 get_layout_position (entry, x, y);
7521 /* convert to widget coords */
7522 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7533 * gtk_entry_set_alignment:
7534 * @entry: a #GtkEntry
7535 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7536 * Reversed for RTL layouts
7538 * Sets the alignment for the contents of the entry. This controls
7539 * the horizontal positioning of the contents when the displayed
7540 * text is shorter than the width of the entry.
7545 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7547 GtkEntryPrivate *priv;
7549 g_return_if_fail (GTK_IS_ENTRY (entry));
7555 else if (xalign > 1.0)
7558 if (xalign != priv->xalign)
7560 priv->xalign = xalign;
7562 gtk_entry_recompute (entry);
7564 g_object_notify (G_OBJECT (entry), "xalign");
7569 * gtk_entry_get_alignment:
7570 * @entry: a #GtkEntry
7572 * Gets the value set by gtk_entry_set_alignment().
7574 * Return value: the alignment
7579 gtk_entry_get_alignment (GtkEntry *entry)
7581 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7583 return entry->priv->xalign;
7587 * gtk_entry_set_icon_from_pixbuf:
7588 * @entry: a #GtkEntry
7589 * @icon_pos: Icon position
7590 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7592 * Sets the icon shown in the specified position using a pixbuf.
7594 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7599 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7600 GtkEntryIconPosition icon_pos,
7603 GtkEntryPrivate *priv;
7604 EntryIconInfo *icon_info;
7606 g_return_if_fail (GTK_IS_ENTRY (entry));
7607 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7611 if ((icon_info = priv->icons[icon_pos]) == NULL)
7612 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7614 g_object_freeze_notify (G_OBJECT (entry));
7617 g_object_ref (pixbuf);
7619 gtk_entry_clear (entry, icon_pos);
7623 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7624 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
7625 GTK_ICON_SIZE_MENU);
7627 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7629 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7630 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7634 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7635 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7638 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7639 gdk_window_show_unraised (icon_info->window);
7641 g_object_unref (pixbuf);
7644 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7645 gtk_widget_queue_resize (GTK_WIDGET (entry));
7647 g_object_thaw_notify (G_OBJECT (entry));
7651 * gtk_entry_set_icon_from_stock:
7652 * @entry: A #GtkEntry
7653 * @icon_pos: Icon position
7654 * @stock_id: (allow-none): The name of the stock item, or %NULL
7656 * Sets the icon shown in the entry at the specified position from
7659 * If @stock_id is %NULL, no icon will be shown in the specified position.
7664 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7665 GtkEntryIconPosition icon_pos,
7666 const gchar *stock_id)
7668 GtkEntryPrivate *priv;
7669 EntryIconInfo *icon_info;
7672 g_return_if_fail (GTK_IS_ENTRY (entry));
7673 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7677 if ((icon_info = priv->icons[icon_pos]) == NULL)
7678 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7680 g_object_freeze_notify (G_OBJECT (entry));
7682 /* need to dup before clearing */
7683 new_id = g_strdup (stock_id);
7685 gtk_entry_clear (entry, icon_pos);
7689 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7691 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7693 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7694 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7698 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7699 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7702 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7703 gdk_window_show_unraised (icon_info->window);
7708 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7709 gtk_widget_queue_resize (GTK_WIDGET (entry));
7711 g_object_thaw_notify (G_OBJECT (entry));
7715 * gtk_entry_set_icon_from_icon_name:
7716 * @entry: A #GtkEntry
7717 * @icon_pos: The position at which to set the icon
7718 * @icon_name: (allow-none): An icon name, or %NULL
7720 * Sets the icon shown in the entry at the specified position
7721 * from the current icon theme.
7723 * If the icon name isn't known, a "broken image" icon will be displayed
7726 * If @icon_name is %NULL, no icon will be shown in the specified position.
7731 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7732 GtkEntryIconPosition icon_pos,
7733 const gchar *icon_name)
7735 GtkEntryPrivate *priv;
7736 EntryIconInfo *icon_info;
7739 g_return_if_fail (GTK_IS_ENTRY (entry));
7740 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7744 if ((icon_info = priv->icons[icon_pos]) == NULL)
7745 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7747 g_object_freeze_notify (G_OBJECT (entry));
7749 /* need to dup before clearing */
7750 new_name = g_strdup (icon_name);
7752 gtk_entry_clear (entry, icon_pos);
7754 if (new_name != NULL)
7756 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7758 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7760 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7761 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7765 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7766 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7769 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7770 gdk_window_show_unraised (icon_info->window);
7775 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7776 gtk_widget_queue_resize (GTK_WIDGET (entry));
7778 g_object_thaw_notify (G_OBJECT (entry));
7782 * gtk_entry_set_icon_from_gicon:
7783 * @entry: A #GtkEntry
7784 * @icon_pos: The position at which to set the icon
7785 * @icon: (allow-none): The icon to set, or %NULL
7787 * Sets the icon shown in the entry at the specified position
7788 * from the current icon theme.
7789 * If the icon isn't known, a "broken image" icon will be displayed
7792 * If @icon is %NULL, no icon will be shown in the specified position.
7797 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7798 GtkEntryIconPosition icon_pos,
7801 GtkEntryPrivate *priv;
7802 EntryIconInfo *icon_info;
7804 g_return_if_fail (GTK_IS_ENTRY (entry));
7805 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7809 if ((icon_info = priv->icons[icon_pos]) == NULL)
7810 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7812 g_object_freeze_notify (G_OBJECT (entry));
7814 /* need to ref before clearing */
7816 g_object_ref (icon);
7818 gtk_entry_clear (entry, icon_pos);
7822 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7824 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7826 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7827 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7831 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7832 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7835 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7836 gdk_window_show_unraised (icon_info->window);
7838 g_object_unref (icon);
7841 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7842 gtk_widget_queue_resize (GTK_WIDGET (entry));
7844 g_object_thaw_notify (G_OBJECT (entry));
7848 * gtk_entry_set_icon_activatable:
7849 * @entry: A #GtkEntry
7850 * @icon_pos: Icon position
7851 * @activatable: %TRUE if the icon should be activatable
7853 * Sets whether the icon is activatable.
7858 gtk_entry_set_icon_activatable (GtkEntry *entry,
7859 GtkEntryIconPosition icon_pos,
7860 gboolean activatable)
7862 GtkEntryPrivate *priv;
7863 EntryIconInfo *icon_info;
7865 g_return_if_fail (GTK_IS_ENTRY (entry));
7866 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7870 if ((icon_info = priv->icons[icon_pos]) == NULL)
7871 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7873 activatable = activatable != FALSE;
7875 if (icon_info->nonactivatable != !activatable)
7877 icon_info->nonactivatable = !activatable;
7879 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7880 update_cursors (GTK_WIDGET (entry));
7882 g_object_notify (G_OBJECT (entry),
7883 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7888 * gtk_entry_get_icon_activatable:
7889 * @entry: a #GtkEntry
7890 * @icon_pos: Icon position
7892 * Returns whether the icon is activatable.
7894 * Returns: %TRUE if the icon is activatable.
7899 gtk_entry_get_icon_activatable (GtkEntry *entry,
7900 GtkEntryIconPosition icon_pos)
7902 GtkEntryPrivate *priv;
7903 EntryIconInfo *icon_info;
7905 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7906 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7909 icon_info = priv->icons[icon_pos];
7911 return (!icon_info || !icon_info->nonactivatable);
7915 * gtk_entry_get_icon_pixbuf:
7916 * @entry: A #GtkEntry
7917 * @icon_pos: Icon position
7919 * Retrieves the image used for the icon.
7921 * Unlike the other methods of setting and getting icon data, this
7922 * method will work regardless of whether the icon was set using a
7923 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7925 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7926 * set for this position.
7931 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7932 GtkEntryIconPosition icon_pos)
7934 GtkEntryPrivate *priv;
7935 EntryIconInfo *icon_info;
7938 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7939 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7943 icon_info = priv->icons[icon_pos];
7948 /* HACK: unfortunately this is transfer none, so we need to return
7949 * the icon helper's cache ref directly.
7951 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7953 g_object_unref (pixbuf);
7959 * gtk_entry_get_icon_gicon:
7960 * @entry: A #GtkEntry
7961 * @icon_pos: Icon position
7963 * Retrieves the #GIcon used for the icon, or %NULL if there is
7964 * no icon or if the icon was set by some other method (e.g., by
7965 * stock, pixbuf, or icon name).
7967 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7968 * or if the icon is not a #GIcon
7973 gtk_entry_get_icon_gicon (GtkEntry *entry,
7974 GtkEntryIconPosition icon_pos)
7976 GtkEntryPrivate *priv;
7977 EntryIconInfo *icon_info;
7979 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7980 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7983 icon_info = priv->icons[icon_pos];
7988 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7992 * gtk_entry_get_icon_stock:
7993 * @entry: A #GtkEntry
7994 * @icon_pos: Icon position
7996 * Retrieves the stock id used for the icon, or %NULL if there is
7997 * no icon or if the icon was set by some other method (e.g., by
7998 * pixbuf, icon name or gicon).
8000 * Returns: A stock id, or %NULL if no icon is set or if the icon
8001 * wasn't set from a stock id
8006 gtk_entry_get_icon_stock (GtkEntry *entry,
8007 GtkEntryIconPosition icon_pos)
8009 GtkEntryPrivate *priv;
8010 EntryIconInfo *icon_info;
8012 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8013 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8016 icon_info = priv->icons[icon_pos];
8021 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8025 * gtk_entry_get_icon_name:
8026 * @entry: A #GtkEntry
8027 * @icon_pos: Icon position
8029 * Retrieves the icon name used for the icon, or %NULL if there is
8030 * no icon or if the icon was set by some other method (e.g., by
8031 * pixbuf, stock or gicon).
8033 * Returns: An icon name, or %NULL if no icon is set or if the icon
8034 * wasn't set from an icon name
8039 gtk_entry_get_icon_name (GtkEntry *entry,
8040 GtkEntryIconPosition icon_pos)
8042 GtkEntryPrivate *priv;
8043 EntryIconInfo *icon_info;
8045 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8046 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8049 icon_info = priv->icons[icon_pos];
8054 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8058 * gtk_entry_set_icon_sensitive:
8059 * @entry: A #GtkEntry
8060 * @icon_pos: Icon position
8061 * @sensitive: Specifies whether the icon should appear
8062 * sensitive or insensitive
8064 * Sets the sensitivity for the specified icon.
8069 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8070 GtkEntryIconPosition icon_pos,
8073 GtkEntryPrivate *priv;
8074 EntryIconInfo *icon_info;
8076 g_return_if_fail (GTK_IS_ENTRY (entry));
8077 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8081 if ((icon_info = priv->icons[icon_pos]) == NULL)
8082 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8084 if (icon_info->insensitive != !sensitive)
8086 icon_info->insensitive = !sensitive;
8088 icon_info->pressed = FALSE;
8089 icon_info->prelight = FALSE;
8091 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8092 update_cursors (GTK_WIDGET (entry));
8094 gtk_widget_queue_draw (GTK_WIDGET (entry));
8096 g_object_notify (G_OBJECT (entry),
8097 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8102 * gtk_entry_get_icon_sensitive:
8103 * @entry: a #GtkEntry
8104 * @icon_pos: Icon position
8106 * Returns whether the icon appears sensitive or insensitive.
8108 * Returns: %TRUE if the icon is sensitive.
8113 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8114 GtkEntryIconPosition icon_pos)
8116 GtkEntryPrivate *priv;
8117 EntryIconInfo *icon_info;
8119 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8120 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8124 icon_info = priv->icons[icon_pos];
8126 return (!icon_info || !icon_info->insensitive);
8131 * gtk_entry_get_icon_storage_type:
8132 * @entry: a #GtkEntry
8133 * @icon_pos: Icon position
8135 * Gets the type of representation being used by the icon
8136 * to store image data. If the icon has no image data,
8137 * the return value will be %GTK_IMAGE_EMPTY.
8139 * Return value: image representation being used
8144 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8145 GtkEntryIconPosition icon_pos)
8147 GtkEntryPrivate *priv;
8148 EntryIconInfo *icon_info;
8150 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8151 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8155 icon_info = priv->icons[icon_pos];
8158 return GTK_IMAGE_EMPTY;
8160 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8164 * gtk_entry_get_icon_at_pos:
8165 * @entry: a #GtkEntry
8166 * @x: the x coordinate of the position to find
8167 * @y: the y coordinate of the position to find
8169 * Finds the icon at the given position and return its index. The
8170 * position's coordinates are relative to the @entry's top left corner.
8171 * If @x, @y doesn't lie inside an icon, -1 is returned.
8172 * This function is intended for use in a #GtkWidget::query-tooltip
8175 * Returns: the index of the icon at the given position, or -1
8180 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8184 GtkAllocation primary;
8185 GtkAllocation secondary;
8186 gint frame_x, frame_y;
8188 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8190 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8194 get_icon_allocations (entry, &primary, &secondary);
8196 if (primary.x <= x && x < primary.x + primary.width &&
8197 primary.y <= y && y < primary.y + primary.height)
8198 return GTK_ENTRY_ICON_PRIMARY;
8200 if (secondary.x <= x && x < secondary.x + secondary.width &&
8201 secondary.y <= y && y < secondary.y + secondary.height)
8202 return GTK_ENTRY_ICON_SECONDARY;
8208 * gtk_entry_set_icon_drag_source:
8209 * @entry: a #GtkEntry
8210 * @icon_pos: icon position
8211 * @target_list: the targets (data formats) in which the data can be provided
8212 * @actions: a bitmask of the allowed drag actions
8214 * Sets up the icon at the given position so that GTK+ will start a drag
8215 * operation when the user clicks and drags the icon.
8217 * To handle the drag operation, you need to connect to the usual
8218 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8219 * signal, and use gtk_entry_get_current_icon_drag_source() in
8220 * your signal handler to find out if the drag was started from
8223 * By default, GTK+ uses the icon as the drag icon. You can use the
8224 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8225 * have to use g_signal_connect_after() to ensure that your signal handler
8226 * gets executed after the default handler.
8231 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8232 GtkEntryIconPosition icon_pos,
8233 GtkTargetList *target_list,
8234 GdkDragAction actions)
8236 GtkEntryPrivate *priv;
8237 EntryIconInfo *icon_info;
8239 g_return_if_fail (GTK_IS_ENTRY (entry));
8240 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8244 if ((icon_info = priv->icons[icon_pos]) == NULL)
8245 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8247 if (icon_info->target_list)
8248 gtk_target_list_unref (icon_info->target_list);
8249 icon_info->target_list = target_list;
8250 if (icon_info->target_list)
8251 gtk_target_list_ref (icon_info->target_list);
8253 icon_info->actions = actions;
8257 * gtk_entry_get_current_icon_drag_source:
8258 * @entry: a #GtkIconEntry
8260 * Returns the index of the icon which is the source of the current
8261 * DND operation, or -1.
8263 * This function is meant to be used in a #GtkWidget::drag-data-get
8266 * Returns: index of the icon which is the source of the current
8267 * DND operation, or -1.
8272 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8274 GtkEntryPrivate *priv;
8275 EntryIconInfo *icon_info = NULL;
8278 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8282 for (i = 0; i < MAX_ICONS; i++)
8284 if ((icon_info = priv->icons[i]))
8286 if (icon_info->in_drag)
8295 * gtk_entry_get_icon_area:
8296 * @entry: A #GtkEntry
8297 * @icon_pos: Icon position
8298 * @icon_area: (out): Return location for the icon's area
8300 * Gets the area where entry's icon at @icon_pos is drawn.
8301 * This function is useful when drawing something to the
8302 * entry in a draw callback.
8304 * If the entry is not realized or has no icon at the given position,
8305 * @icon_area is filled with zeros.
8307 * See also gtk_entry_get_text_area()
8312 gtk_entry_get_icon_area (GtkEntry *entry,
8313 GtkEntryIconPosition icon_pos,
8314 GdkRectangle *icon_area)
8316 GtkEntryPrivate *priv;
8317 EntryIconInfo *icon_info;
8319 g_return_if_fail (GTK_IS_ENTRY (entry));
8320 g_return_if_fail (icon_area != NULL);
8324 icon_info = priv->icons[icon_pos];
8328 GtkAllocation primary;
8329 GtkAllocation secondary;
8331 get_icon_allocations (entry, &primary, &secondary);
8333 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8334 *icon_area = primary;
8336 *icon_area = secondary;
8342 icon_area->width = 0;
8343 icon_area->height = 0;
8348 ensure_has_tooltip (GtkEntry *entry)
8350 GtkEntryPrivate *priv;
8351 EntryIconInfo *icon_info;
8353 gboolean has_tooltip = FALSE;
8357 for (i = 0; i < MAX_ICONS; i++)
8359 if ((icon_info = priv->icons[i]) != NULL)
8361 if (icon_info->tooltip != NULL)
8369 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8373 * gtk_entry_get_icon_tooltip_text:
8374 * @entry: a #GtkEntry
8375 * @icon_pos: the icon position
8377 * Gets the contents of the tooltip on the icon at the specified
8378 * position in @entry.
8380 * Returns: the tooltip text, or %NULL. Free the returned string
8381 * with g_free() when done.
8386 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8387 GtkEntryIconPosition icon_pos)
8389 GtkEntryPrivate *priv;
8390 EntryIconInfo *icon_info;
8393 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8394 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8398 icon_info = priv->icons[icon_pos];
8403 if (icon_info->tooltip &&
8404 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8405 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8411 * gtk_entry_set_icon_tooltip_text:
8412 * @entry: a #GtkEntry
8413 * @icon_pos: the icon position
8414 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8416 * Sets @tooltip as the contents of the tooltip for the icon
8417 * at the specified position.
8419 * Use %NULL for @tooltip to remove an existing tooltip.
8421 * See also gtk_widget_set_tooltip_text() and
8422 * gtk_entry_set_icon_tooltip_markup().
8427 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8428 GtkEntryIconPosition icon_pos,
8429 const gchar *tooltip)
8431 GtkEntryPrivate *priv;
8432 EntryIconInfo *icon_info;
8434 g_return_if_fail (GTK_IS_ENTRY (entry));
8435 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8439 if ((icon_info = priv->icons[icon_pos]) == NULL)
8440 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8442 if (icon_info->tooltip)
8443 g_free (icon_info->tooltip);
8445 /* Treat an empty string as a NULL string,
8446 * because an empty string would be useless for a tooltip:
8448 if (tooltip && tooltip[0] == '\0')
8451 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8453 ensure_has_tooltip (entry);
8457 * gtk_entry_get_icon_tooltip_markup:
8458 * @entry: a #GtkEntry
8459 * @icon_pos: the icon position
8461 * Gets the contents of the tooltip on the icon at the specified
8462 * position in @entry.
8464 * Returns: the tooltip text, or %NULL. Free the returned string
8465 * with g_free() when done.
8470 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8471 GtkEntryIconPosition icon_pos)
8473 GtkEntryPrivate *priv;
8474 EntryIconInfo *icon_info;
8476 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8477 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8481 icon_info = priv->icons[icon_pos];
8486 return g_strdup (icon_info->tooltip);
8490 * gtk_entry_set_icon_tooltip_markup:
8491 * @entry: a #GtkEntry
8492 * @icon_pos: the icon position
8493 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8495 * Sets @tooltip as the contents of the tooltip for the icon at
8496 * the specified position. @tooltip is assumed to be marked up with
8497 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8499 * Use %NULL for @tooltip to remove an existing tooltip.
8501 * See also gtk_widget_set_tooltip_markup() and
8502 * gtk_entry_set_icon_tooltip_text().
8507 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8508 GtkEntryIconPosition icon_pos,
8509 const gchar *tooltip)
8511 GtkEntryPrivate *priv;
8512 EntryIconInfo *icon_info;
8514 g_return_if_fail (GTK_IS_ENTRY (entry));
8515 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8519 if ((icon_info = priv->icons[icon_pos]) == NULL)
8520 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8522 if (icon_info->tooltip)
8523 g_free (icon_info->tooltip);
8525 /* Treat an empty string as a NULL string,
8526 * because an empty string would be useless for a tooltip:
8528 if (tooltip && tooltip[0] == '\0')
8531 icon_info->tooltip = g_strdup (tooltip);
8533 ensure_has_tooltip (entry);
8537 gtk_entry_query_tooltip (GtkWidget *widget,
8540 gboolean keyboard_tip,
8541 GtkTooltip *tooltip)
8544 GtkEntryPrivate *priv;
8545 EntryIconInfo *icon_info;
8548 entry = GTK_ENTRY (widget);
8553 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8556 if ((icon_info = priv->icons[icon_pos]) != NULL)
8558 if (icon_info->tooltip)
8560 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8569 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8576 /* Quick hack of a popup menu
8579 activate_cb (GtkWidget *menuitem,
8582 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8583 g_signal_emit_by_name (entry, signal);
8588 gtk_entry_mnemonic_activate (GtkWidget *widget,
8589 gboolean group_cycling)
8591 gtk_widget_grab_focus (widget);
8596 gtk_entry_grab_notify (GtkWidget *widget,
8597 gboolean was_grabbed)
8599 GtkEntryPrivate *priv;
8601 priv = GTK_ENTRY (widget)->priv;
8604 gtk_widget_device_is_shadowed (widget, priv->device))
8606 /* Unset button so we don't expect
8607 * a button release anymore
8610 priv->device = NULL;
8611 priv->in_drag = FALSE;
8616 append_action_signal (GtkEntry *entry,
8618 const gchar *stock_id,
8619 const gchar *signal,
8622 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8624 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8625 g_signal_connect (menuitem, "activate",
8626 G_CALLBACK (activate_cb), entry);
8628 gtk_widget_set_sensitive (menuitem, sensitive);
8630 gtk_widget_show (menuitem);
8631 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8635 popup_menu_detach (GtkWidget *attach_widget,
8638 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8639 GtkEntryPrivate *priv_attach = entry_attach->priv;
8641 priv_attach->popup_menu = NULL;
8645 popup_position_func (GtkMenu *menu,
8651 GtkEntry *entry = GTK_ENTRY (user_data);
8652 GtkEntryPrivate *priv = entry->priv;
8653 GtkWidget *widget = GTK_WIDGET (entry);
8655 GtkRequisition menu_req;
8656 GdkRectangle monitor;
8658 gint monitor_num, strong_x, height;
8660 g_return_if_fail (gtk_widget_get_realized (widget));
8662 gdk_window_get_origin (priv->text_area, x, y);
8664 screen = gtk_widget_get_screen (widget);
8665 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8666 if (monitor_num < 0)
8668 gtk_menu_set_monitor (menu, monitor_num);
8670 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8671 gtk_widget_get_preferred_size (priv->popup_menu,
8673 height = gdk_window_get_height (priv->text_area);
8674 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8675 _gtk_entry_get_borders (entry, &borders);
8677 *x += borders.left + strong_x - priv->scroll_offset;
8678 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8679 *x -= menu_req.width;
8681 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8683 else if ((*y - menu_req.height) >= monitor.y)
8684 *y -= menu_req.height;
8685 else if (monitor.y + monitor.height - (*y + height) > *y)
8688 *y -= menu_req.height;
8694 unichar_chosen_func (const char *text,
8697 GtkEntry *entry = GTK_ENTRY (data);
8698 GtkEntryPrivate *priv = entry->priv;
8701 gtk_entry_enter_text (entry, text);
8713 popup_targets_received (GtkClipboard *clipboard,
8714 GtkSelectionData *data,
8717 PopupInfo *info = user_data;
8718 GtkEntry *entry = info->entry;
8719 GtkEntryPrivate *info_entry_priv = entry->priv;
8721 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8724 gboolean clipboard_contains_text;
8725 GtkWidget *menuitem;
8727 gboolean show_input_method_menu;
8728 gboolean show_unicode_menu;
8730 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8731 if (info_entry_priv->popup_menu)
8732 gtk_widget_destroy (info_entry_priv->popup_menu);
8734 info_entry_priv->popup_menu = gtk_menu_new ();
8736 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8740 mode = gtk_entry_get_display_mode (entry);
8741 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8742 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8743 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8745 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8746 mode == DISPLAY_NORMAL &&
8747 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8749 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8750 info_entry_priv->editable && clipboard_contains_text);
8752 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8753 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8754 g_signal_connect_swapped (menuitem, "activate",
8755 G_CALLBACK (gtk_entry_delete_cb), entry);
8756 gtk_widget_show (menuitem);
8757 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8759 menuitem = gtk_separator_menu_item_new ();
8760 gtk_widget_show (menuitem);
8761 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8763 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8764 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8765 g_signal_connect_swapped (menuitem, "activate",
8766 G_CALLBACK (gtk_entry_select_all), entry);
8767 gtk_widget_show (menuitem);
8768 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8770 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8771 "gtk-show-input-method-menu", &show_input_method_menu,
8772 "gtk-show-unicode-menu", &show_unicode_menu,
8775 if (show_input_method_menu || show_unicode_menu)
8777 menuitem = gtk_separator_menu_item_new ();
8778 gtk_widget_show (menuitem);
8779 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8782 if (show_input_method_menu)
8784 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8785 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8786 gtk_widget_show (menuitem);
8787 submenu = gtk_menu_new ();
8788 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8790 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8792 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8793 GTK_MENU_SHELL (submenu));
8796 if (show_unicode_menu)
8798 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8799 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8800 gtk_widget_show (menuitem);
8802 submenu = gtk_menu_new ();
8803 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8804 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8806 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8807 unichar_chosen_func,
8811 g_signal_emit (entry,
8812 signals[POPULATE_POPUP],
8814 info_entry_priv->popup_menu);
8818 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8819 info->device, NULL, NULL, NULL, NULL, NULL,
8820 info->button, info->time);
8823 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8824 popup_position_func, entry,
8825 0, gtk_get_current_event_time ());
8826 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8830 g_object_unref (entry);
8831 g_slice_free (PopupInfo, info);
8835 gtk_entry_do_popup (GtkEntry *entry,
8836 GdkEventButton *event)
8838 PopupInfo *info = g_slice_new (PopupInfo);
8840 /* In order to know what entries we should make sensitive, we
8841 * ask for the current targets of the clipboard, and when
8842 * we get them, then we actually pop up the menu.
8844 info->entry = g_object_ref (entry);
8848 info->button = event->button;
8849 info->time = event->time;
8850 info->device = event->device;
8855 info->time = gtk_get_current_event_time ();
8856 info->device = NULL;
8859 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8860 gdk_atom_intern_static_string ("TARGETS"),
8861 popup_targets_received,
8866 gtk_entry_popup_menu (GtkWidget *widget)
8868 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8873 gtk_entry_drag_begin (GtkWidget *widget,
8874 GdkDragContext *context)
8876 GtkEntry *entry = GTK_ENTRY (widget);
8877 GtkEntryPrivate *priv = entry->priv;
8880 for (i = 0; i < MAX_ICONS; i++)
8882 EntryIconInfo *icon_info = priv->icons[i];
8884 if (icon_info != NULL)
8886 if (icon_info->in_drag)
8890 pix = _gtk_icon_helper_ensure_pixbuf
8891 (icon_info->icon_helper,
8892 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8893 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8895 g_object_unref (pix);
8902 gtk_entry_drag_end (GtkWidget *widget,
8903 GdkDragContext *context)
8905 GtkEntry *entry = GTK_ENTRY (widget);
8906 GtkEntryPrivate *priv = entry->priv;
8909 for (i = 0; i < MAX_ICONS; i++)
8911 EntryIconInfo *icon_info = priv->icons[i];
8913 if (icon_info != NULL)
8914 icon_info->in_drag = 0;
8919 gtk_entry_drag_leave (GtkWidget *widget,
8920 GdkDragContext *context,
8923 GtkEntry *entry = GTK_ENTRY (widget);
8924 GtkEntryPrivate *priv = entry->priv;
8926 priv->dnd_position = -1;
8927 gtk_widget_queue_draw (widget);
8931 gtk_entry_drag_drop (GtkWidget *widget,
8932 GdkDragContext *context,
8937 GtkEntry *entry = GTK_ENTRY (widget);
8938 GtkEntryPrivate *priv = entry->priv;
8939 GdkAtom target = GDK_NONE;
8942 target = gtk_drag_dest_find_target (widget, context, NULL);
8944 if (target != GDK_NONE)
8945 gtk_drag_get_data (widget, context, target, time);
8947 gtk_drag_finish (context, FALSE, FALSE, time);
8953 gtk_entry_drag_motion (GtkWidget *widget,
8954 GdkDragContext *context,
8959 GtkEntry *entry = GTK_ENTRY (widget);
8960 GtkEntryPrivate *priv = entry->priv;
8961 GtkStyleContext *style_context;
8962 GtkWidget *source_widget;
8963 GdkDragAction suggested_action;
8964 gint new_position, old_position;
8968 style_context = gtk_widget_get_style_context (widget);
8969 gtk_style_context_get_padding (style_context, 0, &padding);
8973 old_position = priv->dnd_position;
8974 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8976 if (priv->editable &&
8977 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8979 source_widget = gtk_drag_get_source_widget (context);
8980 suggested_action = gdk_drag_context_get_suggested_action (context);
8982 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8983 new_position < sel1 || new_position > sel2)
8985 if (source_widget == widget)
8987 /* Default to MOVE, unless the user has
8988 * pressed ctrl or alt to affect available actions
8990 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8991 suggested_action = GDK_ACTION_MOVE;
8994 priv->dnd_position = new_position;
8998 if (source_widget == widget)
8999 suggested_action = 0; /* Can't drop in selection where drag started */
9001 priv->dnd_position = -1;
9006 /* Entry not editable, or no text */
9007 suggested_action = 0;
9008 priv->dnd_position = -1;
9011 gdk_drag_status (context, suggested_action, time);
9013 if (priv->dnd_position != old_position)
9014 gtk_widget_queue_draw (widget);
9020 gtk_entry_drag_data_received (GtkWidget *widget,
9021 GdkDragContext *context,
9024 GtkSelectionData *selection_data,
9028 GtkEntry *entry = GTK_ENTRY (widget);
9029 GtkEntryPrivate *priv = entry->priv;
9030 GtkEditable *editable = GTK_EDITABLE (widget);
9031 GtkStyleContext *style_context;
9035 str = (gchar *) gtk_selection_data_get_text (selection_data);
9037 style_context = gtk_widget_get_style_context (widget);
9038 gtk_style_context_get_padding (style_context, 0, &padding);
9042 if (str && priv->editable)
9048 if (priv->truncate_multiline)
9049 length = truncate_multiline (str);
9051 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9053 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9054 new_position < sel1 || new_position > sel2)
9056 gtk_editable_insert_text (editable, str, length, &new_position);
9060 /* Replacing selection */
9061 begin_change (entry);
9062 gtk_editable_delete_text (editable, sel1, sel2);
9063 gtk_editable_insert_text (editable, str, length, &sel1);
9067 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9071 /* Drag and drop didn't happen! */
9072 gtk_drag_finish (context, FALSE, FALSE, time);
9079 gtk_entry_drag_data_get (GtkWidget *widget,
9080 GdkDragContext *context,
9081 GtkSelectionData *selection_data,
9085 GtkEntry *entry = GTK_ENTRY (widget);
9086 GtkEntryPrivate *priv = entry->priv;
9087 GtkEditable *editable = GTK_EDITABLE (widget);
9088 gint sel_start, sel_end;
9091 /* If there is an icon drag going on, exit early. */
9092 for (i = 0; i < MAX_ICONS; i++)
9094 EntryIconInfo *icon_info = priv->icons[i];
9096 if (icon_info != NULL)
9098 if (icon_info->in_drag)
9103 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9105 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9107 gtk_selection_data_set_text (selection_data, str, -1);
9115 gtk_entry_drag_data_delete (GtkWidget *widget,
9116 GdkDragContext *context)
9118 GtkEntry *entry = GTK_ENTRY (widget);
9119 GtkEntryPrivate *priv = entry->priv;
9120 GtkEditable *editable = GTK_EDITABLE (widget);
9121 gint sel_start, sel_end;
9124 /* If there is an icon drag going on, exit early. */
9125 for (i = 0; i < MAX_ICONS; i++)
9127 EntryIconInfo *icon_info = priv->icons[i];
9129 if (icon_info != NULL)
9131 if (icon_info->in_drag)
9136 if (priv->editable &&
9137 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9138 gtk_editable_delete_text (editable, sel_start, sel_end);
9141 /* We display the cursor when
9143 * - the selection is empty, AND
9144 * - the widget has focus
9147 #define CURSOR_ON_MULTIPLIER 2
9148 #define CURSOR_OFF_MULTIPLIER 1
9149 #define CURSOR_PEND_MULTIPLIER 3
9150 #define CURSOR_DIVIDER 3
9153 cursor_blinks (GtkEntry *entry)
9155 GtkEntryPrivate *priv = entry->priv;
9157 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9159 priv->selection_bound == priv->current_pos)
9161 GtkSettings *settings;
9164 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9165 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9174 get_middle_click_paste (GtkEntry *entry)
9176 GtkSettings *settings;
9179 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9180 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9186 get_cursor_time (GtkEntry *entry)
9188 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9191 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9197 get_cursor_blink_timeout (GtkEntry *entry)
9199 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9202 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9208 show_cursor (GtkEntry *entry)
9210 GtkEntryPrivate *priv = entry->priv;
9213 if (!priv->cursor_visible)
9215 priv->cursor_visible = TRUE;
9217 widget = GTK_WIDGET (entry);
9218 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9219 gtk_widget_queue_draw (widget);
9224 hide_cursor (GtkEntry *entry)
9226 GtkEntryPrivate *priv = entry->priv;
9229 if (priv->cursor_visible)
9231 priv->cursor_visible = FALSE;
9233 widget = GTK_WIDGET (entry);
9234 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9235 gtk_widget_queue_draw (widget);
9243 blink_cb (gpointer data)
9246 GtkEntryPrivate *priv;
9249 entry = GTK_ENTRY (data);
9252 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9254 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9255 "connect a handler to this signal, it must return\n"
9256 "FALSE so the entry gets the event as well");
9258 gtk_entry_check_cursor_blink (entry);
9263 g_assert (priv->selection_bound == priv->current_pos);
9265 blink_timeout = get_cursor_blink_timeout (entry);
9266 if (priv->blink_time > 1000 * blink_timeout &&
9267 blink_timeout < G_MAXINT/1000)
9269 /* we've blinked enough without the user doing anything, stop blinking */
9270 show_cursor (entry);
9271 priv->blink_timeout = 0;
9273 else if (priv->cursor_visible)
9275 hide_cursor (entry);
9276 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9282 show_cursor (entry);
9283 priv->blink_time += get_cursor_time (entry);
9284 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9289 /* Remove ourselves */
9294 gtk_entry_check_cursor_blink (GtkEntry *entry)
9296 GtkEntryPrivate *priv = entry->priv;
9298 if (cursor_blinks (entry))
9300 if (!priv->blink_timeout)
9302 show_cursor (entry);
9303 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9310 if (priv->blink_timeout)
9312 g_source_remove (priv->blink_timeout);
9313 priv->blink_timeout = 0;
9316 priv->cursor_visible = TRUE;
9321 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9323 GtkEntryPrivate *priv = entry->priv;
9325 if (cursor_blinks (entry))
9327 if (priv->blink_timeout != 0)
9328 g_source_remove (priv->blink_timeout);
9330 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9333 show_cursor (entry);
9338 gtk_entry_reset_blink_time (GtkEntry *entry)
9340 GtkEntryPrivate *priv = entry->priv;
9342 priv->blink_time = 0;
9348 gtk_entry_completion_timeout (gpointer data)
9350 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9351 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9353 completion->priv->completion_timeout = 0;
9355 if (completion->priv->filter_model &&
9356 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9357 >= completion->priv->minimum_key_length)
9361 GtkTreeSelection *s;
9362 gboolean popup_single;
9364 gtk_entry_completion_complete (completion);
9365 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9367 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9369 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9371 gtk_tree_selection_unselect_all (s);
9373 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9375 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9376 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9378 if (gtk_widget_get_visible (completion->priv->popup_window))
9379 _gtk_entry_completion_resize_popup (completion);
9381 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9384 _gtk_entry_completion_popdown (completion);
9386 else if (gtk_widget_get_visible (completion->priv->popup_window))
9387 _gtk_entry_completion_popdown (completion);
9392 static inline gboolean
9393 keyval_is_cursor_move (guint keyval)
9395 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9398 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9401 if (keyval == GDK_KEY_Page_Up)
9404 if (keyval == GDK_KEY_Page_Down)
9411 gtk_entry_completion_key_press (GtkWidget *widget,
9415 gint matches, actions = 0;
9416 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9418 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9421 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9423 if (completion->priv->actions)
9424 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9426 if (keyval_is_cursor_move (event->keyval))
9428 GtkTreePath *path = NULL;
9430 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9432 if (completion->priv->current_selected < 0)
9433 completion->priv->current_selected = matches + actions - 1;
9435 completion->priv->current_selected--;
9437 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9439 if (completion->priv->current_selected < matches + actions - 1)
9440 completion->priv->current_selected++;
9442 completion->priv->current_selected = -1;
9444 else if (event->keyval == GDK_KEY_Page_Up)
9446 if (completion->priv->current_selected < 0)
9447 completion->priv->current_selected = matches + actions - 1;
9448 else if (completion->priv->current_selected == 0)
9449 completion->priv->current_selected = -1;
9450 else if (completion->priv->current_selected < matches)
9452 completion->priv->current_selected -= PAGE_STEP;
9453 if (completion->priv->current_selected < 0)
9454 completion->priv->current_selected = 0;
9458 completion->priv->current_selected -= PAGE_STEP;
9459 if (completion->priv->current_selected < matches - 1)
9460 completion->priv->current_selected = matches - 1;
9463 else if (event->keyval == GDK_KEY_Page_Down)
9465 if (completion->priv->current_selected < 0)
9466 completion->priv->current_selected = 0;
9467 else if (completion->priv->current_selected < matches - 1)
9469 completion->priv->current_selected += PAGE_STEP;
9470 if (completion->priv->current_selected > matches - 1)
9471 completion->priv->current_selected = matches - 1;
9473 else if (completion->priv->current_selected == matches + actions - 1)
9475 completion->priv->current_selected = -1;
9479 completion->priv->current_selected += PAGE_STEP;
9480 if (completion->priv->current_selected > matches + actions - 1)
9481 completion->priv->current_selected = matches + actions - 1;
9485 if (completion->priv->current_selected < 0)
9487 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9488 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9490 if (completion->priv->inline_selection &&
9491 completion->priv->completion_prefix)
9493 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9494 completion->priv->completion_prefix);
9495 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9498 else if (completion->priv->current_selected < matches)
9500 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9502 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9503 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9506 if (completion->priv->inline_selection)
9510 GtkTreeIter child_iter;
9511 GtkTreeModel *model = NULL;
9512 GtkTreeSelection *sel;
9515 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9516 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9519 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9520 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9522 if (completion->priv->completion_prefix == NULL)
9523 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9525 g_signal_emit_by_name (completion, "cursor-on-match", model,
9526 &child_iter, &entry_set);
9529 else if (completion->priv->current_selected - matches >= 0)
9531 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9533 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9534 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9537 if (completion->priv->inline_selection &&
9538 completion->priv->completion_prefix)
9540 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9541 completion->priv->completion_prefix);
9542 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9546 gtk_tree_path_free (path);
9550 else if (event->keyval == GDK_KEY_Escape ||
9551 event->keyval == GDK_KEY_Left ||
9552 event->keyval == GDK_KEY_KP_Left ||
9553 event->keyval == GDK_KEY_Right ||
9554 event->keyval == GDK_KEY_KP_Right)
9556 gboolean retval = TRUE;
9558 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9559 _gtk_entry_completion_popdown (completion);
9561 if (completion->priv->current_selected < 0)
9564 goto keypress_completion_out;
9566 else if (completion->priv->inline_selection)
9568 /* Escape rejects the tentative completion */
9569 if (event->keyval == GDK_KEY_Escape)
9571 if (completion->priv->completion_prefix)
9572 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9573 completion->priv->completion_prefix);
9575 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9578 /* Move the cursor to the end for Right/Esc */
9579 if (event->keyval == GDK_KEY_Right ||
9580 event->keyval == GDK_KEY_KP_Right ||
9581 event->keyval == GDK_KEY_Escape)
9582 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9583 /* Let the default keybindings run for Left, i.e. either move to the
9584 * previous character or select word if a modifier is used */
9589 keypress_completion_out:
9590 if (completion->priv->inline_selection)
9592 g_free (completion->priv->completion_prefix);
9593 completion->priv->completion_prefix = NULL;
9598 else if (event->keyval == GDK_KEY_Tab ||
9599 event->keyval == GDK_KEY_KP_Tab ||
9600 event->keyval == GDK_KEY_ISO_Left_Tab)
9602 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9603 _gtk_entry_completion_popdown (completion);
9605 g_free (completion->priv->completion_prefix);
9606 completion->priv->completion_prefix = NULL;
9610 else if (event->keyval == GDK_KEY_ISO_Enter ||
9611 event->keyval == GDK_KEY_KP_Enter ||
9612 event->keyval == GDK_KEY_Return)
9615 GtkTreeModel *model = NULL;
9616 GtkTreeModel *child_model;
9617 GtkTreeIter child_iter;
9618 GtkTreeSelection *sel;
9619 gboolean retval = TRUE;
9621 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9622 _gtk_entry_completion_popdown (completion);
9624 if (completion->priv->current_selected < matches)
9628 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9629 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9631 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9632 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9633 g_signal_handler_block (widget, completion->priv->changed_id);
9634 g_signal_emit_by_name (completion, "match-selected",
9635 child_model, &child_iter, &entry_set);
9636 g_signal_handler_unblock (widget, completion->priv->changed_id);
9642 gtk_tree_model_get (model, &iter,
9643 completion->priv->text_column, &str,
9646 gtk_entry_set_text (GTK_ENTRY (widget), str);
9648 /* move the cursor to the end */
9649 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9657 else if (completion->priv->current_selected - matches >= 0)
9659 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9660 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9664 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9665 g_signal_emit_by_name (completion, "action-activated",
9666 gtk_tree_path_get_indices (path)[0]);
9667 gtk_tree_path_free (path);
9673 g_free (completion->priv->completion_prefix);
9674 completion->priv->completion_prefix = NULL;
9683 gtk_entry_completion_changed (GtkWidget *widget,
9686 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9687 GtkEntry *entry = GTK_ENTRY (widget);
9688 GtkEntryPrivate *priv = entry->priv;
9691 /* (re)install completion timeout */
9692 if (completion->priv->completion_timeout)
9693 g_source_remove (completion->priv->completion_timeout);
9695 if (!gtk_entry_get_text (entry))
9698 /* no need to normalize for this test */
9699 if (completion->priv->minimum_key_length > 0 &&
9700 strcmp ("", gtk_entry_get_text (entry)) == 0)
9702 if (gtk_widget_get_visible (completion->priv->popup_window))
9703 _gtk_entry_completion_popdown (completion);
9707 device = gtk_get_current_event_device ();
9709 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9710 device = gdk_device_get_associated_device (device);
9713 priv->completion_device = device;
9715 completion->priv->completion_timeout =
9716 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9717 gtk_entry_completion_timeout,
9722 check_completion_callback (GtkEntryCompletion *completion)
9724 completion->priv->check_completion_idle = NULL;
9726 gtk_entry_completion_complete (completion);
9727 gtk_entry_completion_insert_prefix (completion);
9733 clear_completion_callback (GtkEntry *entry,
9736 if (pspec->name == I_("cursor-position") ||
9737 pspec->name == I_("selection-bound"))
9739 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9741 completion->priv->has_completion = FALSE;
9746 accept_completion_callback (GtkEntry *entry)
9748 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9750 if (completion->priv->has_completion)
9751 gtk_editable_set_position (GTK_EDITABLE (entry),
9752 gtk_entry_buffer_get_length (get_buffer (entry)));
9758 completion_insert_text_callback (GtkEntry *entry,
9762 GtkEntryCompletion *completion)
9764 /* idle to update the selection based on the file list */
9765 if (completion->priv->check_completion_idle == NULL)
9767 completion->priv->check_completion_idle = g_idle_source_new ();
9768 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9769 g_source_set_closure (completion->priv->check_completion_idle,
9770 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9771 G_OBJECT (completion)));
9772 g_source_attach (completion->priv->check_completion_idle, NULL);
9777 completion_changed (GtkEntryCompletion *completion,
9781 GtkEntry *entry = GTK_ENTRY (data);
9783 if (pspec->name == I_("popup-completion") ||
9784 pspec->name == I_("inline-completion"))
9786 disconnect_completion_signals (entry, completion);
9787 connect_completion_signals (entry, completion);
9792 disconnect_completion_signals (GtkEntry *entry,
9793 GtkEntryCompletion *completion)
9795 g_signal_handlers_disconnect_by_func (completion,
9796 G_CALLBACK (completion_changed), entry);
9797 if (completion->priv->changed_id > 0 &&
9798 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9800 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9801 completion->priv->changed_id = 0;
9803 g_signal_handlers_disconnect_by_func (entry,
9804 G_CALLBACK (gtk_entry_completion_key_press), completion);
9805 if (completion->priv->insert_text_id > 0 &&
9806 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9808 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9809 completion->priv->insert_text_id = 0;
9811 g_signal_handlers_disconnect_by_func (entry,
9812 G_CALLBACK (completion_insert_text_callback), completion);
9813 g_signal_handlers_disconnect_by_func (entry,
9814 G_CALLBACK (clear_completion_callback), completion);
9815 g_signal_handlers_disconnect_by_func (entry,
9816 G_CALLBACK (accept_completion_callback), completion);
9820 connect_completion_signals (GtkEntry *entry,
9821 GtkEntryCompletion *completion)
9823 if (completion->priv->popup_completion)
9825 completion->priv->changed_id =
9826 g_signal_connect (entry, "changed",
9827 G_CALLBACK (gtk_entry_completion_changed), completion);
9828 g_signal_connect (entry, "key-press-event",
9829 G_CALLBACK (gtk_entry_completion_key_press), completion);
9832 if (completion->priv->inline_completion)
9834 completion->priv->insert_text_id =
9835 g_signal_connect (entry, "insert-text",
9836 G_CALLBACK (completion_insert_text_callback), completion);
9837 g_signal_connect (entry, "notify",
9838 G_CALLBACK (clear_completion_callback), completion);
9839 g_signal_connect (entry, "activate",
9840 G_CALLBACK (accept_completion_callback), completion);
9841 g_signal_connect (entry, "focus-out-event",
9842 G_CALLBACK (accept_completion_callback), completion);
9845 g_signal_connect (completion, "notify",
9846 G_CALLBACK (completion_changed), entry);
9850 * gtk_entry_set_completion:
9851 * @entry: A #GtkEntry
9852 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9854 * Sets @completion to be the auxiliary completion object to use with @entry.
9855 * All further configuration of the completion mechanism is done on
9856 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9857 * @completion is set to %NULL.
9862 gtk_entry_set_completion (GtkEntry *entry,
9863 GtkEntryCompletion *completion)
9865 GtkEntryCompletion *old;
9867 g_return_if_fail (GTK_IS_ENTRY (entry));
9868 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9870 old = gtk_entry_get_completion (entry);
9872 if (old == completion)
9877 if (old->priv->completion_timeout)
9879 g_source_remove (old->priv->completion_timeout);
9880 old->priv->completion_timeout = 0;
9883 if (old->priv->check_completion_idle)
9885 g_source_destroy (old->priv->check_completion_idle);
9886 old->priv->check_completion_idle = NULL;
9889 if (gtk_widget_get_mapped (old->priv->popup_window))
9890 _gtk_entry_completion_popdown (old);
9892 disconnect_completion_signals (entry, old);
9893 old->priv->entry = NULL;
9895 g_object_unref (old);
9900 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9904 /* hook into the entry */
9905 g_object_ref (completion);
9907 connect_completion_signals (entry, completion);
9908 completion->priv->entry = GTK_WIDGET (entry);
9909 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9911 g_object_notify (G_OBJECT (entry), "completion");
9915 * gtk_entry_get_completion:
9916 * @entry: A #GtkEntry
9918 * Returns the auxiliary completion object currently in use by @entry.
9920 * Return value: (transfer none): The auxiliary completion object currently
9925 GtkEntryCompletion *
9926 gtk_entry_get_completion (GtkEntry *entry)
9928 GtkEntryCompletion *completion;
9930 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9932 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9933 GTK_ENTRY_COMPLETION_KEY));
9939 * gtk_entry_set_cursor_hadjustment:
9940 * @entry: a #GtkEntry
9941 * @adjustment: an adjustment which should be adjusted when the cursor
9942 * is moved, or %NULL
9944 * Hooks up an adjustment to the cursor position in an entry, so that when
9945 * the cursor is moved, the adjustment is scrolled to show that position.
9946 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9949 * The adjustment has to be in pixel units and in the same coordinate system
9955 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9956 GtkAdjustment *adjustment)
9958 g_return_if_fail (GTK_IS_ENTRY (entry));
9960 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9963 g_object_ref (adjustment);
9965 g_object_set_qdata_full (G_OBJECT (entry),
9966 quark_cursor_hadjustment,
9972 * gtk_entry_get_cursor_hadjustment:
9973 * @entry: a #GtkEntry
9975 * Retrieves the horizontal cursor adjustment for the entry.
9976 * See gtk_entry_set_cursor_hadjustment().
9978 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9979 * if none has been set.
9984 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9986 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9988 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9992 * gtk_entry_set_progress_fraction:
9993 * @entry: a #GtkEntry
9994 * @fraction: fraction of the task that's been completed
9996 * Causes the entry's progress indicator to "fill in" the given
9997 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10003 gtk_entry_set_progress_fraction (GtkEntry *entry,
10007 GtkEntryPrivate *private;
10008 gdouble old_fraction;
10009 gint x, y, width, height;
10010 gint old_x, old_y, old_width, old_height;
10012 g_return_if_fail (GTK_IS_ENTRY (entry));
10014 widget = GTK_WIDGET (entry);
10015 private = entry->priv;
10017 if (private->progress_pulse_mode)
10020 old_fraction = private->progress_fraction;
10022 if (gtk_widget_is_drawable (widget))
10023 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10025 fraction = CLAMP (fraction, 0.0, 1.0);
10027 private->progress_fraction = fraction;
10028 private->progress_pulse_mode = FALSE;
10029 private->progress_pulse_current = 0.0;
10031 if (gtk_widget_is_drawable (widget))
10033 get_progress_area (widget, &x, &y, &width, &height);
10035 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10036 gtk_widget_queue_draw (widget);
10039 if (fraction != old_fraction)
10040 g_object_notify (G_OBJECT (entry), "progress-fraction");
10044 * gtk_entry_get_progress_fraction:
10045 * @entry: a #GtkEntry
10047 * Returns the current fraction of the task that's been completed.
10048 * See gtk_entry_set_progress_fraction().
10050 * Return value: a fraction from 0.0 to 1.0
10055 gtk_entry_get_progress_fraction (GtkEntry *entry)
10057 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10059 return entry->priv->progress_fraction;
10063 * gtk_entry_set_progress_pulse_step:
10064 * @entry: a #GtkEntry
10065 * @fraction: fraction between 0.0 and 1.0
10067 * Sets the fraction of total entry width to move the progress
10068 * bouncing block for each call to gtk_entry_progress_pulse().
10073 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10076 GtkEntryPrivate *private;
10078 g_return_if_fail (GTK_IS_ENTRY (entry));
10080 private = entry->priv;
10082 fraction = CLAMP (fraction, 0.0, 1.0);
10084 if (fraction != private->progress_pulse_fraction)
10086 private->progress_pulse_fraction = fraction;
10088 gtk_widget_queue_draw (GTK_WIDGET (entry));
10090 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10095 * gtk_entry_get_progress_pulse_step:
10096 * @entry: a #GtkEntry
10098 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10100 * Return value: a fraction from 0.0 to 1.0
10105 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10107 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10109 return entry->priv->progress_pulse_fraction;
10113 * gtk_entry_progress_pulse:
10114 * @entry: a #GtkEntry
10116 * Indicates that some progress is made, but you don't know how much.
10117 * Causes the entry's progress indicator to enter "activity mode,"
10118 * where a block bounces back and forth. Each call to
10119 * gtk_entry_progress_pulse() causes the block to move by a little bit
10120 * (the amount of movement per pulse is determined by
10121 * gtk_entry_set_progress_pulse_step()).
10126 gtk_entry_progress_pulse (GtkEntry *entry)
10128 GtkEntryPrivate *private;
10130 g_return_if_fail (GTK_IS_ENTRY (entry));
10132 private = entry->priv;
10134 if (private->progress_pulse_mode)
10136 if (private->progress_pulse_way_back)
10138 private->progress_pulse_current -= private->progress_pulse_fraction;
10140 if (private->progress_pulse_current < 0.0)
10142 private->progress_pulse_current = 0.0;
10143 private->progress_pulse_way_back = FALSE;
10148 private->progress_pulse_current += private->progress_pulse_fraction;
10150 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10152 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10153 private->progress_pulse_way_back = TRUE;
10159 private->progress_fraction = 0.0;
10160 private->progress_pulse_mode = TRUE;
10161 private->progress_pulse_way_back = FALSE;
10162 private->progress_pulse_current = 0.0;
10165 gtk_widget_queue_draw (GTK_WIDGET (entry));
10169 * gtk_entry_set_placeholder_text:
10170 * @entry: a #GtkEntry
10171 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10173 * Sets text to be displayed in @entry when it is empty and unfocused.
10174 * This can be used to give a visual hint of the expected contents of
10177 * Note that since the placeholder text gets removed when the entry
10178 * received focus, using this feature is a bit problematic if the entry
10179 * is given the initial focus in a window. Sometimes this can be
10180 * worked around by delaying the initial focus setting until the
10181 * first key event arrives.
10186 gtk_entry_set_placeholder_text (GtkEntry *entry,
10189 GtkEntryPrivate *priv;
10191 g_return_if_fail (GTK_IS_ENTRY (entry));
10193 priv = entry->priv;
10195 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10198 g_free (priv->placeholder_text);
10199 priv->placeholder_text = g_strdup (text);
10201 gtk_entry_recompute (entry);
10203 g_object_notify (G_OBJECT (entry), "placeholder-text");
10207 * gtk_entry_get_placeholder_text:
10208 * @entry: a #GtkEntry
10210 * Retrieves the text that will be displayed when @entry is empty and unfocused
10212 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10213 * storage in the widget and must not be freed, modified or stored.
10218 gtk_entry_get_placeholder_text (GtkEntry *entry)
10220 GtkEntryPrivate *priv;
10222 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10224 priv = entry->priv;
10226 return priv->placeholder_text;
10229 /* Caps Lock warning for password entries */
10232 show_capslock_feedback (GtkEntry *entry,
10235 GtkEntryPrivate *priv = entry->priv;
10237 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10239 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10240 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10241 priv->caps_lock_warning_shown = TRUE;
10244 if (priv->caps_lock_warning_shown)
10245 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10247 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10251 remove_capslock_feedback (GtkEntry *entry)
10253 GtkEntryPrivate *priv = entry->priv;
10255 if (priv->caps_lock_warning_shown)
10257 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10258 priv->caps_lock_warning_shown = FALSE;
10263 keymap_state_changed (GdkKeymap *keymap,
10266 GtkEntryPrivate *priv = entry->priv;
10269 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10271 if (gdk_keymap_get_caps_lock_state (keymap))
10272 text = _("Caps Lock is on");
10276 show_capslock_feedback (entry, text);
10278 remove_capslock_feedback (entry);
10282 * _gtk_entry_set_is_cell_renderer:
10283 * @entry: a #GtkEntry
10284 * @is_cell_renderer: new value
10286 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10287 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10289 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10293 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10294 gboolean is_cell_renderer)
10296 entry->priv->is_cell_renderer = is_cell_renderer;