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 * the value of this style property is ignored.
797 g_object_class_install_property (gobject_class,
799 g_param_spec_boxed ("inner-border",
801 P_("Border between text and frame. Overrides the inner-border style property"),
803 GTK_PARAM_READWRITE |
804 G_PARAM_DEPRECATED));
806 g_object_class_install_property (gobject_class,
808 g_param_spec_unichar ("invisible-char",
809 P_("Invisible character"),
810 P_("The character to use when masking entry contents (in \"password mode\")"),
812 GTK_PARAM_READWRITE));
814 g_object_class_install_property (gobject_class,
815 PROP_ACTIVATES_DEFAULT,
816 g_param_spec_boolean ("activates-default",
817 P_("Activates default"),
818 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
820 GTK_PARAM_READWRITE));
821 g_object_class_install_property (gobject_class,
823 g_param_spec_int ("width-chars",
824 P_("Width in chars"),
825 P_("Number of characters to leave space for in the entry"),
829 GTK_PARAM_READWRITE));
831 g_object_class_install_property (gobject_class,
833 g_param_spec_int ("scroll-offset",
835 P_("Number of pixels of the entry scrolled off the screen to the left"),
839 GTK_PARAM_READABLE));
841 g_object_class_install_property (gobject_class,
843 g_param_spec_string ("text",
845 P_("The contents of the entry"),
847 GTK_PARAM_READWRITE));
852 * The horizontal alignment, from 0 (left) to 1 (right).
853 * Reversed for RTL layouts.
857 g_object_class_install_property (gobject_class,
859 g_param_spec_float ("xalign",
861 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
865 GTK_PARAM_READWRITE));
868 * GtkEntry:truncate-multiline:
870 * When %TRUE, pasted multi-line text is truncated to the first line.
874 g_object_class_install_property (gobject_class,
875 PROP_TRUNCATE_MULTILINE,
876 g_param_spec_boolean ("truncate-multiline",
877 P_("Truncate multiline"),
878 P_("Whether to truncate multiline pastes to one line."),
880 GTK_PARAM_READWRITE));
883 * GtkEntry:shadow-type:
885 * Which kind of shadow to draw around the entry when
886 * #GtkEntry:has-frame is set to %TRUE.
890 g_object_class_install_property (gobject_class,
892 g_param_spec_enum ("shadow-type",
894 P_("Which kind of shadow to draw around the entry when has-frame is set"),
895 GTK_TYPE_SHADOW_TYPE,
897 GTK_PARAM_READWRITE));
900 * GtkEntry:overwrite-mode:
902 * If text is overwritten when typing in the #GtkEntry.
906 g_object_class_install_property (gobject_class,
908 g_param_spec_boolean ("overwrite-mode",
909 P_("Overwrite mode"),
910 P_("Whether new text overwrites existing text"),
912 GTK_PARAM_READWRITE));
915 * GtkEntry:text-length:
917 * The length of the text in the #GtkEntry.
921 g_object_class_install_property (gobject_class,
923 g_param_spec_uint ("text-length",
925 P_("Length of the text currently in the entry"),
929 GTK_PARAM_READABLE));
931 * GtkEntry:invisible-char-set:
933 * Whether the invisible char has been set for the #GtkEntry.
937 g_object_class_install_property (gobject_class,
938 PROP_INVISIBLE_CHAR_SET,
939 g_param_spec_boolean ("invisible-char-set",
940 P_("Invisible character set"),
941 P_("Whether the invisible character has been set"),
943 GTK_PARAM_READWRITE));
946 * GtkEntry:caps-lock-warning:
948 * Whether password entries will show a warning when Caps Lock is on.
950 * Note that the warning is shown using a secondary icon, and thus
951 * does not work if you are using the secondary icon position for some
956 g_object_class_install_property (gobject_class,
957 PROP_CAPS_LOCK_WARNING,
958 g_param_spec_boolean ("caps-lock-warning",
959 P_("Caps Lock warning"),
960 P_("Whether password entries will show a warning when Caps Lock is on"),
962 GTK_PARAM_READWRITE));
965 * GtkEntry:progress-fraction:
967 * The current fraction of the task that's been completed.
971 g_object_class_install_property (gobject_class,
972 PROP_PROGRESS_FRACTION,
973 g_param_spec_double ("progress-fraction",
974 P_("Progress Fraction"),
975 P_("The current fraction of the task that's been completed"),
979 GTK_PARAM_READWRITE));
982 * GtkEntry:progress-pulse-step:
984 * The fraction of total entry width to move the progress
985 * bouncing block for each call to gtk_entry_progress_pulse().
989 g_object_class_install_property (gobject_class,
990 PROP_PROGRESS_PULSE_STEP,
991 g_param_spec_double ("progress-pulse-step",
992 P_("Progress Pulse Step"),
993 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
997 GTK_PARAM_READWRITE));
1000 * GtkEntry:placeholder-text:
1002 * The text that will be displayed in the #GtkEntry when it is empty
1007 g_object_class_install_property (gobject_class,
1008 PROP_PLACEHOLDER_TEXT,
1009 g_param_spec_string ("placeholder-text",
1010 P_("Placeholder text"),
1011 P_("Show text in the entry when it's empty and unfocused"),
1013 GTK_PARAM_READWRITE));
1016 * GtkEntry:primary-icon-pixbuf:
1018 * A pixbuf to use as the primary icon for the entry.
1022 g_object_class_install_property (gobject_class,
1023 PROP_PIXBUF_PRIMARY,
1024 g_param_spec_object ("primary-icon-pixbuf",
1025 P_("Primary pixbuf"),
1026 P_("Primary pixbuf for the entry"),
1028 GTK_PARAM_READWRITE));
1031 * GtkEntry:secondary-icon-pixbuf:
1033 * An pixbuf to use as the secondary icon for the entry.
1037 g_object_class_install_property (gobject_class,
1038 PROP_PIXBUF_SECONDARY,
1039 g_param_spec_object ("secondary-icon-pixbuf",
1040 P_("Secondary pixbuf"),
1041 P_("Secondary pixbuf for the entry"),
1043 GTK_PARAM_READWRITE));
1046 * GtkEntry:primary-icon-stock:
1048 * The stock id to use for the primary icon for the entry.
1052 g_object_class_install_property (gobject_class,
1054 g_param_spec_string ("primary-icon-stock",
1055 P_("Primary stock ID"),
1056 P_("Stock ID for primary icon"),
1058 GTK_PARAM_READWRITE));
1061 * GtkEntry:secondary-icon-stock:
1063 * The stock id to use for the secondary icon for the entry.
1067 g_object_class_install_property (gobject_class,
1068 PROP_STOCK_SECONDARY,
1069 g_param_spec_string ("secondary-icon-stock",
1070 P_("Secondary stock ID"),
1071 P_("Stock ID for secondary icon"),
1073 GTK_PARAM_READWRITE));
1076 * GtkEntry:primary-icon-name:
1078 * The icon name to use for the primary icon for the entry.
1082 g_object_class_install_property (gobject_class,
1083 PROP_ICON_NAME_PRIMARY,
1084 g_param_spec_string ("primary-icon-name",
1085 P_("Primary icon name"),
1086 P_("Icon name for primary icon"),
1088 GTK_PARAM_READWRITE));
1091 * GtkEntry:secondary-icon-name:
1093 * The icon name to use for the secondary icon for the entry.
1097 g_object_class_install_property (gobject_class,
1098 PROP_ICON_NAME_SECONDARY,
1099 g_param_spec_string ("secondary-icon-name",
1100 P_("Secondary icon name"),
1101 P_("Icon name for secondary icon"),
1103 GTK_PARAM_READWRITE));
1106 * GtkEntry:primary-icon-gicon:
1108 * The #GIcon to use for the primary icon for the entry.
1112 g_object_class_install_property (gobject_class,
1114 g_param_spec_object ("primary-icon-gicon",
1115 P_("Primary GIcon"),
1116 P_("GIcon for primary icon"),
1118 GTK_PARAM_READWRITE));
1121 * GtkEntry:secondary-icon-gicon:
1123 * The #GIcon to use for the secondary icon for the entry.
1127 g_object_class_install_property (gobject_class,
1128 PROP_GICON_SECONDARY,
1129 g_param_spec_object ("secondary-icon-gicon",
1130 P_("Secondary GIcon"),
1131 P_("GIcon for secondary icon"),
1133 GTK_PARAM_READWRITE));
1136 * GtkEntry:primary-icon-storage-type:
1138 * The representation which is used for the primary icon of the entry.
1142 g_object_class_install_property (gobject_class,
1143 PROP_STORAGE_TYPE_PRIMARY,
1144 g_param_spec_enum ("primary-icon-storage-type",
1145 P_("Primary storage type"),
1146 P_("The representation being used for primary icon"),
1147 GTK_TYPE_IMAGE_TYPE,
1149 GTK_PARAM_READABLE));
1152 * GtkEntry:secondary-icon-storage-type:
1154 * The representation which is used for the secondary icon of the entry.
1158 g_object_class_install_property (gobject_class,
1159 PROP_STORAGE_TYPE_SECONDARY,
1160 g_param_spec_enum ("secondary-icon-storage-type",
1161 P_("Secondary storage type"),
1162 P_("The representation being used for secondary icon"),
1163 GTK_TYPE_IMAGE_TYPE,
1165 GTK_PARAM_READABLE));
1168 * GtkEntry:primary-icon-activatable:
1170 * Whether the primary icon is activatable.
1172 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1173 * signals only on sensitive, activatable icons.
1175 * Sensitive, but non-activatable icons can be used for purely
1176 * informational purposes.
1180 g_object_class_install_property (gobject_class,
1181 PROP_ACTIVATABLE_PRIMARY,
1182 g_param_spec_boolean ("primary-icon-activatable",
1183 P_("Primary icon activatable"),
1184 P_("Whether the primary icon is activatable"),
1186 GTK_PARAM_READWRITE));
1189 * GtkEntry:secondary-icon-activatable:
1191 * Whether the secondary icon is activatable.
1193 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1194 * signals only on sensitive, activatable icons.
1196 * Sensitive, but non-activatable icons can be used for purely
1197 * informational purposes.
1201 g_object_class_install_property (gobject_class,
1202 PROP_ACTIVATABLE_SECONDARY,
1203 g_param_spec_boolean ("secondary-icon-activatable",
1204 P_("Secondary icon activatable"),
1205 P_("Whether the secondary icon is activatable"),
1207 GTK_PARAM_READWRITE));
1211 * GtkEntry:primary-icon-sensitive:
1213 * Whether the primary icon is sensitive.
1215 * An insensitive icon appears grayed out. GTK+ does not emit the
1216 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1217 * does not allow DND from insensitive icons.
1219 * An icon should be set insensitive if the action that would trigger
1220 * when clicked is currently not available.
1224 g_object_class_install_property (gobject_class,
1225 PROP_SENSITIVE_PRIMARY,
1226 g_param_spec_boolean ("primary-icon-sensitive",
1227 P_("Primary icon sensitive"),
1228 P_("Whether the primary icon is sensitive"),
1230 GTK_PARAM_READWRITE));
1233 * GtkEntry:secondary-icon-sensitive:
1235 * Whether the secondary icon is sensitive.
1237 * An insensitive icon appears grayed out. GTK+ does not emit the
1238 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1239 * does not allow DND from insensitive icons.
1241 * An icon should be set insensitive if the action that would trigger
1242 * when clicked is currently not available.
1246 g_object_class_install_property (gobject_class,
1247 PROP_SENSITIVE_SECONDARY,
1248 g_param_spec_boolean ("secondary-icon-sensitive",
1249 P_("Secondary icon sensitive"),
1250 P_("Whether the secondary icon is sensitive"),
1252 GTK_PARAM_READWRITE));
1255 * GtkEntry:primary-icon-tooltip-text:
1257 * The contents of the tooltip on the primary icon.
1259 * Also see gtk_entry_set_icon_tooltip_text().
1263 g_object_class_install_property (gobject_class,
1264 PROP_TOOLTIP_TEXT_PRIMARY,
1265 g_param_spec_string ("primary-icon-tooltip-text",
1266 P_("Primary icon tooltip text"),
1267 P_("The contents of the tooltip on the primary icon"),
1269 GTK_PARAM_READWRITE));
1272 * GtkEntry:secondary-icon-tooltip-text:
1274 * The contents of the tooltip on the secondary icon.
1276 * Also see gtk_entry_set_icon_tooltip_text().
1280 g_object_class_install_property (gobject_class,
1281 PROP_TOOLTIP_TEXT_SECONDARY,
1282 g_param_spec_string ("secondary-icon-tooltip-text",
1283 P_("Secondary icon tooltip text"),
1284 P_("The contents of the tooltip on the secondary icon"),
1286 GTK_PARAM_READWRITE));
1289 * GtkEntry:primary-icon-tooltip-markup:
1291 * The contents of the tooltip on the primary icon, which is marked up
1292 * with the <link linkend="PangoMarkupFormat">Pango text markup
1295 * Also see gtk_entry_set_icon_tooltip_markup().
1299 g_object_class_install_property (gobject_class,
1300 PROP_TOOLTIP_MARKUP_PRIMARY,
1301 g_param_spec_string ("primary-icon-tooltip-markup",
1302 P_("Primary icon tooltip markup"),
1303 P_("The contents of the tooltip on the primary icon"),
1305 GTK_PARAM_READWRITE));
1308 * GtkEntry:secondary-icon-tooltip-markup:
1310 * The contents of the tooltip on the secondary icon, which is marked up
1311 * with the <link linkend="PangoMarkupFormat">Pango text markup
1314 * Also see gtk_entry_set_icon_tooltip_markup().
1318 g_object_class_install_property (gobject_class,
1319 PROP_TOOLTIP_MARKUP_SECONDARY,
1320 g_param_spec_string ("secondary-icon-tooltip-markup",
1321 P_("Secondary icon tooltip markup"),
1322 P_("The contents of the tooltip on the secondary icon"),
1324 GTK_PARAM_READWRITE));
1327 * GtkEntry:im-module:
1329 * Which IM (input method) module should be used for this entry.
1330 * See #GtkIMContext.
1332 * Setting this to a non-%NULL value overrides the
1333 * system-wide IM module setting. See the GtkSettings
1334 * #GtkSettings:gtk-im-module property.
1338 g_object_class_install_property (gobject_class,
1340 g_param_spec_string ("im-module",
1342 P_("Which IM module should be used"),
1344 GTK_PARAM_READWRITE));
1347 * GtkEntry:completion:
1349 * The auxiliary completion object to use with the entry.
1353 g_object_class_install_property (gobject_class,
1355 g_param_spec_object ("completion",
1357 P_("The auxiliary completion object"),
1358 GTK_TYPE_ENTRY_COMPLETION,
1359 GTK_PARAM_READWRITE));
1362 * GtkEntry:icon-prelight:
1364 * The prelight style property determines whether activatable
1365 * icons prelight on mouseover.
1369 gtk_widget_class_install_style_property (widget_class,
1370 g_param_spec_boolean ("icon-prelight",
1371 P_("Icon Prelight"),
1372 P_("Whether activatable icons should prelight when hovered"),
1374 GTK_PARAM_READABLE));
1377 * GtkEntry:progress-border:
1379 * The border around the progress bar in the entry.
1383 * Deprecated: 3.4: Use the standard margin CSS property;
1384 * the value of this style property is ignored.
1386 gtk_widget_class_install_style_property (widget_class,
1387 g_param_spec_boxed ("progress-border",
1388 P_("Progress Border"),
1389 P_("Border around the progress bar"),
1391 GTK_PARAM_READABLE |
1392 G_PARAM_DEPRECATED));
1395 * GtkEntry:invisible-char:
1397 * The invisible character is used when masking entry contents (in
1398 * \"password mode\")"). When it is not explicitly set with the
1399 * #GtkEntry:invisible-char property, GTK+ determines the character
1400 * to use from a list of possible candidates, depending on availability
1401 * in the current font.
1403 * This style property allows the theme to prepend a character
1404 * to the list of candidates.
1408 gtk_widget_class_install_style_property (widget_class,
1409 g_param_spec_unichar ("invisible-char",
1410 P_("Invisible character"),
1411 P_("The character to use when masking entry contents (in \"password mode\")"),
1413 GTK_PARAM_READABLE));
1416 * GtkEntry::populate-popup:
1417 * @entry: The entry on which the signal is emitted
1418 * @menu: the menu that is being populated
1420 * The ::populate-popup signal gets emitted before showing the
1421 * context menu of the entry.
1423 * If you need to add items to the context menu, connect
1424 * to this signal and append your menuitems to the @menu.
1426 signals[POPULATE_POPUP] =
1427 g_signal_new (I_("populate-popup"),
1428 G_OBJECT_CLASS_TYPE (gobject_class),
1430 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1432 _gtk_marshal_VOID__OBJECT,
1436 /* Action signals */
1439 * GtkEntry::activate:
1440 * @entry: The entry on which the signal is emitted
1442 * A <link linkend="keybinding-signals">keybinding signal</link>
1443 * which gets emitted when the user activates the entry.
1445 * Applications should not connect to it, but may emit it with
1446 * g_signal_emit_by_name() if they need to control activation
1449 * The default bindings for this signal are all forms of the Enter key.
1452 g_signal_new (I_("activate"),
1453 G_OBJECT_CLASS_TYPE (gobject_class),
1454 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1455 G_STRUCT_OFFSET (GtkEntryClass, activate),
1457 _gtk_marshal_VOID__VOID,
1459 widget_class->activate_signal = signals[ACTIVATE];
1462 * GtkEntry::move-cursor:
1463 * @entry: the object which received the signal
1464 * @step: the granularity of the move, as a #GtkMovementStep
1465 * @count: the number of @step units to move
1466 * @extend_selection: %TRUE if the move should extend the selection
1468 * The ::move-cursor signal is a
1469 * <link linkend="keybinding-signals">keybinding signal</link>
1470 * which gets emitted when the user initiates a cursor movement.
1471 * If the cursor is not visible in @entry, this signal causes
1472 * the viewport to be moved instead.
1474 * Applications should not connect to it, but may emit it with
1475 * g_signal_emit_by_name() if they need to control the cursor
1478 * The default bindings for this signal come in two variants,
1479 * the variant with the Shift modifier extends the selection,
1480 * the variant without the Shift modifer does not.
1481 * There are too many key combinations to list them all here.
1483 * <listitem>Arrow keys move by individual characters/lines</listitem>
1484 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1485 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1488 signals[MOVE_CURSOR] =
1489 g_signal_new (I_("move-cursor"),
1490 G_OBJECT_CLASS_TYPE (gobject_class),
1491 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1492 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1494 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1496 GTK_TYPE_MOVEMENT_STEP,
1501 * GtkEntry::insert-at-cursor:
1502 * @entry: the object which received the signal
1503 * @string: the string to insert
1505 * The ::insert-at-cursor signal is a
1506 * <link linkend="keybinding-signals">keybinding signal</link>
1507 * which gets emitted when the user initiates the insertion of a
1508 * fixed string at the cursor.
1510 * This signal has no default bindings.
1512 signals[INSERT_AT_CURSOR] =
1513 g_signal_new (I_("insert-at-cursor"),
1514 G_OBJECT_CLASS_TYPE (gobject_class),
1515 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1516 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1518 _gtk_marshal_VOID__STRING,
1523 * GtkEntry::delete-from-cursor:
1524 * @entry: the object which received the signal
1525 * @type: the granularity of the deletion, as a #GtkDeleteType
1526 * @count: the number of @type units to delete
1528 * The ::delete-from-cursor signal is a
1529 * <link linkend="keybinding-signals">keybinding signal</link>
1530 * which gets emitted when the user initiates a text deletion.
1532 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1533 * if there is one, otherwise it deletes the requested number
1536 * The default bindings for this signal are
1537 * Delete for deleting a character and Ctrl-Delete for
1540 signals[DELETE_FROM_CURSOR] =
1541 g_signal_new (I_("delete-from-cursor"),
1542 G_OBJECT_CLASS_TYPE (gobject_class),
1543 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1544 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1546 _gtk_marshal_VOID__ENUM_INT,
1548 GTK_TYPE_DELETE_TYPE,
1552 * GtkEntry::backspace:
1553 * @entry: the object which received the signal
1555 * The ::backspace signal is a
1556 * <link linkend="keybinding-signals">keybinding signal</link>
1557 * which gets emitted when the user asks for it.
1559 * The default bindings for this signal are
1560 * Backspace and Shift-Backspace.
1562 signals[BACKSPACE] =
1563 g_signal_new (I_("backspace"),
1564 G_OBJECT_CLASS_TYPE (gobject_class),
1565 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1566 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1568 _gtk_marshal_VOID__VOID,
1572 * GtkEntry::cut-clipboard:
1573 * @entry: the object which received the signal
1575 * The ::cut-clipboard signal is a
1576 * <link linkend="keybinding-signals">keybinding signal</link>
1577 * which gets emitted to cut the selection to the clipboard.
1579 * The default bindings for this signal are
1580 * Ctrl-x and Shift-Delete.
1582 signals[CUT_CLIPBOARD] =
1583 g_signal_new (I_("cut-clipboard"),
1584 G_OBJECT_CLASS_TYPE (gobject_class),
1585 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1586 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1588 _gtk_marshal_VOID__VOID,
1592 * GtkEntry::copy-clipboard:
1593 * @entry: the object which received the signal
1595 * The ::copy-clipboard signal is a
1596 * <link linkend="keybinding-signals">keybinding signal</link>
1597 * which gets emitted to copy the selection to the clipboard.
1599 * The default bindings for this signal are
1600 * Ctrl-c and Ctrl-Insert.
1602 signals[COPY_CLIPBOARD] =
1603 g_signal_new (I_("copy-clipboard"),
1604 G_OBJECT_CLASS_TYPE (gobject_class),
1605 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1606 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1608 _gtk_marshal_VOID__VOID,
1612 * GtkEntry::paste-clipboard:
1613 * @entry: the object which received the signal
1615 * The ::paste-clipboard signal is a
1616 * <link linkend="keybinding-signals">keybinding signal</link>
1617 * which gets emitted to paste the contents of the clipboard
1618 * into the text view.
1620 * The default bindings for this signal are
1621 * Ctrl-v and Shift-Insert.
1623 signals[PASTE_CLIPBOARD] =
1624 g_signal_new (I_("paste-clipboard"),
1625 G_OBJECT_CLASS_TYPE (gobject_class),
1626 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1627 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1629 _gtk_marshal_VOID__VOID,
1633 * GtkEntry::toggle-overwrite:
1634 * @entry: the object which received the signal
1636 * The ::toggle-overwrite signal is a
1637 * <link linkend="keybinding-signals">keybinding signal</link>
1638 * which gets emitted to toggle the overwrite mode of the entry.
1640 * The default bindings for this signal is Insert.
1642 signals[TOGGLE_OVERWRITE] =
1643 g_signal_new (I_("toggle-overwrite"),
1644 G_OBJECT_CLASS_TYPE (gobject_class),
1645 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1646 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1648 _gtk_marshal_VOID__VOID,
1652 * GtkEntry::icon-press:
1653 * @entry: The entry on which the signal is emitted
1654 * @icon_pos: The position of the clicked icon
1655 * @event: (type Gdk.EventButton): the button press event
1657 * The ::icon-press signal is emitted when an activatable icon
1662 signals[ICON_PRESS] =
1663 g_signal_new (I_("icon-press"),
1664 G_TYPE_FROM_CLASS (gobject_class),
1668 _gtk_marshal_VOID__ENUM_BOXED,
1670 GTK_TYPE_ENTRY_ICON_POSITION,
1671 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1674 * GtkEntry::icon-release:
1675 * @entry: The entry on which the signal is emitted
1676 * @icon_pos: The position of the clicked icon
1677 * @event: (type Gdk.EventButton): the button release event
1679 * The ::icon-release signal is emitted on the button release from a
1680 * mouse click over an activatable icon.
1684 signals[ICON_RELEASE] =
1685 g_signal_new (I_("icon-release"),
1686 G_TYPE_FROM_CLASS (gobject_class),
1690 _gtk_marshal_VOID__ENUM_BOXED,
1692 GTK_TYPE_ENTRY_ICON_POSITION,
1693 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1696 * GtkEntry::preedit-changed:
1697 * @entry: the object which received the signal
1698 * @preedit: the current preedit string
1700 * If an input method is used, the typed text will not immediately
1701 * be committed to the buffer. So if you are interested in the text,
1702 * connect to this signal.
1706 signals[PREEDIT_CHANGED] =
1707 g_signal_new_class_handler (I_("preedit-changed"),
1708 G_OBJECT_CLASS_TYPE (gobject_class),
1709 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1712 _gtk_marshal_VOID__STRING,
1721 binding_set = gtk_binding_set_by_class (class);
1723 /* Moving the insertion point */
1724 add_move_binding (binding_set, GDK_KEY_Right, 0,
1725 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1727 add_move_binding (binding_set, GDK_KEY_Left, 0,
1728 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1730 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1731 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1733 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1734 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1736 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1737 GTK_MOVEMENT_WORDS, 1);
1739 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1740 GTK_MOVEMENT_WORDS, -1);
1742 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1743 GTK_MOVEMENT_WORDS, 1);
1745 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1746 GTK_MOVEMENT_WORDS, -1);
1748 add_move_binding (binding_set, GDK_KEY_Home, 0,
1749 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1751 add_move_binding (binding_set, GDK_KEY_End, 0,
1752 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1754 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1755 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1757 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1758 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1760 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1761 GTK_MOVEMENT_BUFFER_ENDS, -1);
1763 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1764 GTK_MOVEMENT_BUFFER_ENDS, 1);
1766 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1767 GTK_MOVEMENT_BUFFER_ENDS, -1);
1769 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1770 GTK_MOVEMENT_BUFFER_ENDS, 1);
1774 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1776 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1778 G_TYPE_BOOLEAN, FALSE);
1779 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1781 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1783 G_TYPE_BOOLEAN, TRUE);
1785 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1787 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1789 G_TYPE_BOOLEAN, FALSE);
1790 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1792 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1794 G_TYPE_BOOLEAN, TRUE);
1797 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1799 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1801 G_TYPE_BOOLEAN, FALSE);
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1804 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1806 G_TYPE_BOOLEAN, FALSE);
1810 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1814 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1818 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1819 "delete-from-cursor", 2,
1820 G_TYPE_ENUM, GTK_DELETE_CHARS,
1823 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1824 "delete-from-cursor", 2,
1825 G_TYPE_ENUM, GTK_DELETE_CHARS,
1828 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1831 /* Make this do the same as Backspace, to help with mis-typing */
1832 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1835 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1836 "delete-from-cursor", 2,
1837 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1840 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1841 "delete-from-cursor", 2,
1842 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1846 "delete-from-cursor", 2,
1847 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1850 /* Cut/copy/paste */
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1853 "cut-clipboard", 0);
1854 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1855 "copy-clipboard", 0);
1856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1857 "paste-clipboard", 0);
1859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1860 "cut-clipboard", 0);
1861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1862 "copy-clipboard", 0);
1863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1864 "paste-clipboard", 0);
1867 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1868 "toggle-overwrite", 0);
1869 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1870 "toggle-overwrite", 0);
1873 * GtkEntry:inner-border:
1875 * Sets the text area's border between the text and the frame.
1879 * Deprecated: 3.4: Use the standard border and padding CSS properties;
1880 * the value of this style property is ignored.
1882 gtk_widget_class_install_style_property (widget_class,
1883 g_param_spec_boxed ("inner-border",
1885 P_("Border between text and frame."),
1887 GTK_PARAM_READABLE |
1888 G_PARAM_DEPRECATED));
1890 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1892 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1896 gtk_entry_editable_init (GtkEditableInterface *iface)
1898 iface->do_insert_text = gtk_entry_insert_text;
1899 iface->do_delete_text = gtk_entry_delete_text;
1900 iface->insert_text = gtk_entry_real_insert_text;
1901 iface->delete_text = gtk_entry_real_delete_text;
1902 iface->get_chars = gtk_entry_get_chars;
1903 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1904 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1905 iface->set_position = gtk_entry_real_set_position;
1906 iface->get_position = gtk_entry_get_position;
1910 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1912 iface->start_editing = gtk_entry_start_editing;
1915 /* for deprecated properties */
1917 gtk_entry_do_set_inner_border (GtkEntry *entry,
1918 const GtkBorder *border)
1921 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1922 gtk_border_copy (border),
1923 (GDestroyNotify) gtk_border_free);
1925 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1927 g_object_notify (G_OBJECT (entry), "inner-border");
1930 static const GtkBorder *
1931 gtk_entry_do_get_inner_border (GtkEntry *entry)
1933 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1937 gtk_entry_set_property (GObject *object,
1939 const GValue *value,
1942 GtkEntry *entry = GTK_ENTRY (object);
1943 GtkEntryPrivate *priv = entry->priv;
1948 gtk_entry_set_buffer (entry, g_value_get_object (value));
1953 gboolean new_value = g_value_get_boolean (value);
1955 if (new_value != priv->editable)
1957 GtkWidget *widget = GTK_WIDGET (entry);
1961 _gtk_entry_reset_im_context (entry);
1962 if (gtk_widget_has_focus (widget))
1963 gtk_im_context_focus_out (priv->im_context);
1965 priv->preedit_length = 0;
1966 priv->preedit_cursor = 0;
1969 priv->editable = new_value;
1971 if (new_value && gtk_widget_has_focus (widget))
1972 gtk_im_context_focus_in (priv->im_context);
1974 gtk_widget_queue_draw (widget);
1979 case PROP_MAX_LENGTH:
1980 gtk_entry_set_max_length (entry, g_value_get_int (value));
1983 case PROP_VISIBILITY:
1984 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1987 case PROP_HAS_FRAME:
1988 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1991 case PROP_INNER_BORDER:
1992 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1995 case PROP_INVISIBLE_CHAR:
1996 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1999 case PROP_ACTIVATES_DEFAULT:
2000 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2003 case PROP_WIDTH_CHARS:
2004 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2008 gtk_entry_set_text (entry, g_value_get_string (value));
2012 gtk_entry_set_alignment (entry, g_value_get_float (value));
2015 case PROP_TRUNCATE_MULTILINE:
2016 priv->truncate_multiline = g_value_get_boolean (value);
2019 case PROP_SHADOW_TYPE:
2020 priv->shadow_type = g_value_get_enum (value);
2023 case PROP_OVERWRITE_MODE:
2024 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2027 case PROP_INVISIBLE_CHAR_SET:
2028 if (g_value_get_boolean (value))
2029 priv->invisible_char_set = TRUE;
2031 gtk_entry_unset_invisible_char (entry);
2034 case PROP_CAPS_LOCK_WARNING:
2035 priv->caps_lock_warning = g_value_get_boolean (value);
2038 case PROP_PROGRESS_FRACTION:
2039 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2042 case PROP_PROGRESS_PULSE_STEP:
2043 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2046 case PROP_PLACEHOLDER_TEXT:
2047 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2050 case PROP_PIXBUF_PRIMARY:
2051 gtk_entry_set_icon_from_pixbuf (entry,
2052 GTK_ENTRY_ICON_PRIMARY,
2053 g_value_get_object (value));
2056 case PROP_PIXBUF_SECONDARY:
2057 gtk_entry_set_icon_from_pixbuf (entry,
2058 GTK_ENTRY_ICON_SECONDARY,
2059 g_value_get_object (value));
2062 case PROP_STOCK_PRIMARY:
2063 gtk_entry_set_icon_from_stock (entry,
2064 GTK_ENTRY_ICON_PRIMARY,
2065 g_value_get_string (value));
2068 case PROP_STOCK_SECONDARY:
2069 gtk_entry_set_icon_from_stock (entry,
2070 GTK_ENTRY_ICON_SECONDARY,
2071 g_value_get_string (value));
2074 case PROP_ICON_NAME_PRIMARY:
2075 gtk_entry_set_icon_from_icon_name (entry,
2076 GTK_ENTRY_ICON_PRIMARY,
2077 g_value_get_string (value));
2080 case PROP_ICON_NAME_SECONDARY:
2081 gtk_entry_set_icon_from_icon_name (entry,
2082 GTK_ENTRY_ICON_SECONDARY,
2083 g_value_get_string (value));
2086 case PROP_GICON_PRIMARY:
2087 gtk_entry_set_icon_from_gicon (entry,
2088 GTK_ENTRY_ICON_PRIMARY,
2089 g_value_get_object (value));
2092 case PROP_GICON_SECONDARY:
2093 gtk_entry_set_icon_from_gicon (entry,
2094 GTK_ENTRY_ICON_SECONDARY,
2095 g_value_get_object (value));
2098 case PROP_ACTIVATABLE_PRIMARY:
2099 gtk_entry_set_icon_activatable (entry,
2100 GTK_ENTRY_ICON_PRIMARY,
2101 g_value_get_boolean (value));
2104 case PROP_ACTIVATABLE_SECONDARY:
2105 gtk_entry_set_icon_activatable (entry,
2106 GTK_ENTRY_ICON_SECONDARY,
2107 g_value_get_boolean (value));
2110 case PROP_SENSITIVE_PRIMARY:
2111 gtk_entry_set_icon_sensitive (entry,
2112 GTK_ENTRY_ICON_PRIMARY,
2113 g_value_get_boolean (value));
2116 case PROP_SENSITIVE_SECONDARY:
2117 gtk_entry_set_icon_sensitive (entry,
2118 GTK_ENTRY_ICON_SECONDARY,
2119 g_value_get_boolean (value));
2122 case PROP_TOOLTIP_TEXT_PRIMARY:
2123 gtk_entry_set_icon_tooltip_text (entry,
2124 GTK_ENTRY_ICON_PRIMARY,
2125 g_value_get_string (value));
2128 case PROP_TOOLTIP_TEXT_SECONDARY:
2129 gtk_entry_set_icon_tooltip_text (entry,
2130 GTK_ENTRY_ICON_SECONDARY,
2131 g_value_get_string (value));
2134 case PROP_TOOLTIP_MARKUP_PRIMARY:
2135 gtk_entry_set_icon_tooltip_markup (entry,
2136 GTK_ENTRY_ICON_PRIMARY,
2137 g_value_get_string (value));
2140 case PROP_TOOLTIP_MARKUP_SECONDARY:
2141 gtk_entry_set_icon_tooltip_markup (entry,
2142 GTK_ENTRY_ICON_SECONDARY,
2143 g_value_get_string (value));
2146 case PROP_IM_MODULE:
2147 g_free (priv->im_module);
2148 priv->im_module = g_value_dup_string (value);
2149 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2150 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2153 case PROP_EDITING_CANCELED:
2154 priv->editing_canceled = g_value_get_boolean (value);
2157 case PROP_COMPLETION:
2158 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2161 case PROP_SCROLL_OFFSET:
2162 case PROP_CURSOR_POSITION:
2164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2170 gtk_entry_get_property (GObject *object,
2175 GtkEntry *entry = GTK_ENTRY (object);
2176 GtkEntryPrivate *priv = entry->priv;
2181 g_value_set_object (value, gtk_entry_get_buffer (entry));
2184 case PROP_CURSOR_POSITION:
2185 g_value_set_int (value, priv->current_pos);
2188 case PROP_SELECTION_BOUND:
2189 g_value_set_int (value, priv->selection_bound);
2193 g_value_set_boolean (value, priv->editable);
2196 case PROP_MAX_LENGTH:
2197 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2200 case PROP_VISIBILITY:
2201 g_value_set_boolean (value, priv->visible);
2204 case PROP_HAS_FRAME:
2205 g_value_set_boolean (value, priv->has_frame);
2208 case PROP_INNER_BORDER:
2209 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2212 case PROP_INVISIBLE_CHAR:
2213 g_value_set_uint (value, priv->invisible_char);
2216 case PROP_ACTIVATES_DEFAULT:
2217 g_value_set_boolean (value, priv->activates_default);
2220 case PROP_WIDTH_CHARS:
2221 g_value_set_int (value, priv->width_chars);
2224 case PROP_SCROLL_OFFSET:
2225 g_value_set_int (value, priv->scroll_offset);
2229 g_value_set_string (value, gtk_entry_get_text (entry));
2233 g_value_set_float (value, gtk_entry_get_alignment (entry));
2236 case PROP_TRUNCATE_MULTILINE:
2237 g_value_set_boolean (value, priv->truncate_multiline);
2240 case PROP_SHADOW_TYPE:
2241 g_value_set_enum (value, priv->shadow_type);
2244 case PROP_OVERWRITE_MODE:
2245 g_value_set_boolean (value, priv->overwrite_mode);
2248 case PROP_TEXT_LENGTH:
2249 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2252 case PROP_INVISIBLE_CHAR_SET:
2253 g_value_set_boolean (value, priv->invisible_char_set);
2256 case PROP_IM_MODULE:
2257 g_value_set_string (value, priv->im_module);
2260 case PROP_CAPS_LOCK_WARNING:
2261 g_value_set_boolean (value, priv->caps_lock_warning);
2264 case PROP_PROGRESS_FRACTION:
2265 g_value_set_double (value, priv->progress_fraction);
2268 case PROP_PROGRESS_PULSE_STEP:
2269 g_value_set_double (value, priv->progress_pulse_fraction);
2272 case PROP_PLACEHOLDER_TEXT:
2273 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2276 case PROP_PIXBUF_PRIMARY:
2277 g_value_set_object (value,
2278 gtk_entry_get_icon_pixbuf (entry,
2279 GTK_ENTRY_ICON_PRIMARY));
2282 case PROP_PIXBUF_SECONDARY:
2283 g_value_set_object (value,
2284 gtk_entry_get_icon_pixbuf (entry,
2285 GTK_ENTRY_ICON_SECONDARY));
2288 case PROP_STOCK_PRIMARY:
2289 g_value_set_string (value,
2290 gtk_entry_get_icon_stock (entry,
2291 GTK_ENTRY_ICON_PRIMARY));
2294 case PROP_STOCK_SECONDARY:
2295 g_value_set_string (value,
2296 gtk_entry_get_icon_stock (entry,
2297 GTK_ENTRY_ICON_SECONDARY));
2300 case PROP_ICON_NAME_PRIMARY:
2301 g_value_set_string (value,
2302 gtk_entry_get_icon_name (entry,
2303 GTK_ENTRY_ICON_PRIMARY));
2306 case PROP_ICON_NAME_SECONDARY:
2307 g_value_set_string (value,
2308 gtk_entry_get_icon_name (entry,
2309 GTK_ENTRY_ICON_SECONDARY));
2312 case PROP_GICON_PRIMARY:
2313 g_value_set_object (value,
2314 gtk_entry_get_icon_gicon (entry,
2315 GTK_ENTRY_ICON_PRIMARY));
2318 case PROP_GICON_SECONDARY:
2319 g_value_set_object (value,
2320 gtk_entry_get_icon_gicon (entry,
2321 GTK_ENTRY_ICON_SECONDARY));
2324 case PROP_STORAGE_TYPE_PRIMARY:
2325 g_value_set_enum (value,
2326 gtk_entry_get_icon_storage_type (entry,
2327 GTK_ENTRY_ICON_PRIMARY));
2330 case PROP_STORAGE_TYPE_SECONDARY:
2331 g_value_set_enum (value,
2332 gtk_entry_get_icon_storage_type (entry,
2333 GTK_ENTRY_ICON_SECONDARY));
2336 case PROP_ACTIVATABLE_PRIMARY:
2337 g_value_set_boolean (value,
2338 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2341 case PROP_ACTIVATABLE_SECONDARY:
2342 g_value_set_boolean (value,
2343 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2346 case PROP_SENSITIVE_PRIMARY:
2347 g_value_set_boolean (value,
2348 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2351 case PROP_SENSITIVE_SECONDARY:
2352 g_value_set_boolean (value,
2353 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2356 case PROP_TOOLTIP_TEXT_PRIMARY:
2357 g_value_take_string (value,
2358 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2361 case PROP_TOOLTIP_TEXT_SECONDARY:
2362 g_value_take_string (value,
2363 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2366 case PROP_TOOLTIP_MARKUP_PRIMARY:
2367 g_value_take_string (value,
2368 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2371 case PROP_TOOLTIP_MARKUP_SECONDARY:
2372 g_value_take_string (value,
2373 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2376 case PROP_EDITING_CANCELED:
2377 g_value_set_boolean (value,
2378 priv->editing_canceled);
2381 case PROP_COMPLETION:
2382 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2386 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2392 find_invisible_char (GtkWidget *widget)
2394 PangoLayout *layout;
2395 PangoAttrList *attr_list;
2397 gunichar invisible_chars [] = {
2399 0x25cf, /* BLACK CIRCLE */
2400 0x2022, /* BULLET */
2401 0x2731, /* HEAVY ASTERISK */
2402 0x273a /* SIXTEEN POINTED ASTERISK */
2405 gtk_widget_style_get (widget,
2406 "invisible-char", &invisible_chars[0],
2409 layout = gtk_widget_create_pango_layout (widget, NULL);
2411 attr_list = pango_attr_list_new ();
2412 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2414 pango_layout_set_attributes (layout, attr_list);
2415 pango_attr_list_unref (attr_list);
2417 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2419 gchar text[7] = { 0, };
2422 len = g_unichar_to_utf8 (invisible_chars[i], text);
2423 pango_layout_set_text (layout, text, len);
2425 count = pango_layout_get_unknown_glyphs_count (layout);
2429 g_object_unref (layout);
2430 return invisible_chars[i];
2434 g_object_unref (layout);
2440 gtk_entry_init (GtkEntry *entry)
2442 GtkStyleContext *context;
2443 GtkEntryPrivate *priv;
2445 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2450 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2451 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2453 priv->editable = TRUE;
2454 priv->visible = TRUE;
2455 priv->dnd_position = -1;
2456 priv->width_chars = -1;
2457 priv->is_cell_renderer = FALSE;
2458 priv->editing_canceled = FALSE;
2459 priv->has_frame = TRUE;
2460 priv->truncate_multiline = FALSE;
2461 priv->shadow_type = GTK_SHADOW_IN;
2463 priv->caps_lock_warning = TRUE;
2464 priv->caps_lock_warning_shown = FALSE;
2465 priv->progress_fraction = 0.0;
2466 priv->progress_pulse_fraction = 0.1;
2468 gtk_drag_dest_set (GTK_WIDGET (entry),
2469 GTK_DEST_DEFAULT_HIGHLIGHT,
2471 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2472 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2474 /* This object is completely private. No external entity can gain a reference
2475 * to it; so we create it here and destroy it in finalize().
2477 priv->im_context = gtk_im_multicontext_new ();
2479 g_signal_connect (priv->im_context, "commit",
2480 G_CALLBACK (gtk_entry_commit_cb), entry);
2481 g_signal_connect (priv->im_context, "preedit-changed",
2482 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2483 g_signal_connect (priv->im_context, "retrieve-surrounding",
2484 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2485 g_signal_connect (priv->im_context, "delete-surrounding",
2486 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2488 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2489 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2491 gtk_entry_update_cached_style_values (entry);
2495 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2496 GtkStyleContext *context,
2497 GtkEntryIconPosition icon_pos)
2499 GtkEntryPrivate *priv = entry->priv;
2500 EntryIconInfo *icon_info = priv->icons[icon_pos];
2502 GtkStateFlags state;
2504 widget = GTK_WIDGET (entry);
2505 state = gtk_widget_get_state_flags (widget);
2507 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2509 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2510 state |= GTK_STATE_FLAG_INSENSITIVE;
2511 else if (icon_info->prelight)
2512 state |= GTK_STATE_FLAG_PRELIGHT;
2514 gtk_style_context_save (context);
2516 gtk_style_context_set_state (context, state);
2517 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2519 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2521 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2522 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2524 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2528 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2529 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2531 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2536 get_icon_width (GtkEntry *entry,
2537 GtkEntryIconPosition icon_pos)
2539 GtkEntryPrivate *priv = entry->priv;
2540 EntryIconInfo *icon_info = priv->icons[icon_pos];
2541 GtkStyleContext *context;
2548 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2549 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2550 gtk_style_context_get_padding (context, 0, &padding);
2552 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2554 gtk_style_context_restore (context);
2557 width += padding.left + padding.right;
2563 get_icon_allocations (GtkEntry *entry,
2564 GtkAllocation *primary,
2565 GtkAllocation *secondary)
2568 GtkEntryPrivate *priv = entry->priv;
2569 gint x, y, width, height;
2571 get_text_area_size (entry, &x, &y, &width, &height);
2573 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2574 y += priv->focus_width;
2577 primary->height = height;
2578 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2581 secondary->height = height;
2582 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2584 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2586 primary->x = x + width - primary->width;
2592 secondary->x = x + width - secondary->width;
2598 begin_change (GtkEntry *entry)
2600 GtkEntryPrivate *priv = entry->priv;
2602 priv->change_count++;
2604 g_object_freeze_notify (G_OBJECT (entry));
2608 end_change (GtkEntry *entry)
2610 GtkEditable *editable = GTK_EDITABLE (entry);
2611 GtkEntryPrivate *priv = entry->priv;
2613 g_return_if_fail (priv->change_count > 0);
2615 g_object_thaw_notify (G_OBJECT (entry));
2617 priv->change_count--;
2619 if (priv->change_count == 0)
2621 if (priv->real_changed)
2623 g_signal_emit_by_name (editable, "changed");
2624 priv->real_changed = FALSE;
2630 emit_changed (GtkEntry *entry)
2632 GtkEditable *editable = GTK_EDITABLE (entry);
2633 GtkEntryPrivate *priv = entry->priv;
2635 if (priv->change_count == 0)
2636 g_signal_emit_by_name (editable, "changed");
2638 priv->real_changed = TRUE;
2642 gtk_entry_destroy (GtkWidget *widget)
2644 GtkEntry *entry = GTK_ENTRY (widget);
2645 GtkEntryPrivate *priv = entry->priv;
2647 priv->current_pos = priv->selection_bound = 0;
2648 _gtk_entry_reset_im_context (entry);
2649 gtk_entry_reset_layout (entry);
2651 if (priv->blink_timeout)
2653 g_source_remove (priv->blink_timeout);
2654 priv->blink_timeout = 0;
2657 if (priv->recompute_idle)
2659 g_source_remove (priv->recompute_idle);
2660 priv->recompute_idle = 0;
2663 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2667 gtk_entry_dispose (GObject *object)
2669 GtkEntry *entry = GTK_ENTRY (object);
2670 GtkEntryPrivate *priv = entry->priv;
2673 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2674 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2675 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2676 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2680 buffer_disconnect_signals (entry);
2681 g_object_unref (priv->buffer);
2682 priv->buffer = NULL;
2685 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2686 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2687 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2688 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2692 gtk_entry_finalize (GObject *object)
2694 GtkEntry *entry = GTK_ENTRY (object);
2695 GtkEntryPrivate *priv = entry->priv;
2696 EntryIconInfo *icon_info = NULL;
2699 for (i = 0; i < MAX_ICONS; i++)
2701 if ((icon_info = priv->icons[i]) != NULL)
2703 if (icon_info->target_list != NULL)
2705 gtk_target_list_unref (icon_info->target_list);
2706 icon_info->target_list = NULL;
2709 g_clear_object (&icon_info->icon_helper);
2711 g_slice_free (EntryIconInfo, icon_info);
2712 priv->icons[i] = NULL;
2716 gtk_entry_set_completion (entry, NULL);
2718 if (priv->cached_layout)
2719 g_object_unref (priv->cached_layout);
2721 g_object_unref (priv->im_context);
2723 if (priv->blink_timeout)
2724 g_source_remove (priv->blink_timeout);
2726 if (priv->recompute_idle)
2727 g_source_remove (priv->recompute_idle);
2729 g_free (priv->placeholder_text);
2730 g_free (priv->im_module);
2732 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2736 gtk_entry_get_display_mode (GtkEntry *entry)
2738 GtkEntryPrivate *priv = entry->priv;
2741 return DISPLAY_NORMAL;
2743 if (priv->invisible_char == 0 && priv->invisible_char_set)
2744 return DISPLAY_BLANK;
2746 return DISPLAY_INVISIBLE;
2750 gtk_entry_get_display_text (GtkEntry *entry,
2754 GtkEntryPasswordHint *password_hint;
2755 GtkEntryPrivate *priv;
2756 gunichar invisible_char;
2767 text = gtk_entry_buffer_get_text (get_buffer (entry));
2768 length = gtk_entry_buffer_get_length (get_buffer (entry));
2772 if (start_pos > length)
2775 if (end_pos <= start_pos)
2776 return g_strdup ("");
2777 else if (priv->visible)
2779 start = g_utf8_offset_to_pointer (text, start_pos);
2780 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2781 return g_strndup (start, end - start);
2785 str = g_string_sized_new (length * 2);
2787 /* Figure out what our invisible char is and encode it */
2788 if (!priv->invisible_char)
2789 invisible_char = priv->invisible_char_set ? ' ' : '*';
2791 invisible_char = priv->invisible_char;
2792 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2795 * Add hidden characters for each character in the text
2796 * buffer. If there is a password hint, then keep that
2797 * character visible.
2800 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2801 for (i = start_pos; i < end_pos; ++i)
2803 if (password_hint && i == password_hint->position)
2805 start = g_utf8_offset_to_pointer (text, i);
2806 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2810 g_string_append_len (str, char_str, char_len);
2814 return g_string_free (str, FALSE);
2819 update_cursors (GtkWidget *widget)
2821 GtkEntry *entry = GTK_ENTRY (widget);
2822 GtkEntryPrivate *priv = entry->priv;
2823 EntryIconInfo *icon_info = NULL;
2824 GdkDisplay *display;
2828 for (i = 0; i < MAX_ICONS; i++)
2830 if ((icon_info = priv->icons[i]) != NULL)
2832 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2833 icon_info->window != NULL)
2834 gdk_window_show_unraised (icon_info->window);
2836 /* The icon windows are not children of the visible entry window,
2837 * thus we can't just inherit the xterm cursor. Slight complication
2838 * here is that for the entry, insensitive => arrow cursor, but for
2839 * an icon in a sensitive entry, insensitive => xterm cursor.
2841 if (gtk_widget_is_sensitive (widget) &&
2842 (icon_info->insensitive ||
2843 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2845 display = gtk_widget_get_display (widget);
2846 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2847 gdk_window_set_cursor (icon_info->window, cursor);
2848 g_object_unref (cursor);
2852 gdk_window_set_cursor (icon_info->window, NULL);
2859 realize_icon_info (GtkWidget *widget,
2860 GtkEntryIconPosition icon_pos)
2862 GtkEntry *entry = GTK_ENTRY (widget);
2863 GtkEntryPrivate *priv = entry->priv;
2864 EntryIconInfo *icon_info = priv->icons[icon_pos];
2865 GdkWindowAttr attributes;
2866 gint attributes_mask;
2868 g_return_if_fail (icon_info != NULL);
2872 attributes.width = 1;
2873 attributes.height = 1;
2874 attributes.window_type = GDK_WINDOW_CHILD;
2875 attributes.wclass = GDK_INPUT_ONLY;
2876 attributes.event_mask = gtk_widget_get_events (widget);
2877 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2878 GDK_BUTTON_RELEASE_MASK |
2879 GDK_BUTTON1_MOTION_MASK |
2880 GDK_BUTTON3_MOTION_MASK |
2881 GDK_POINTER_MOTION_HINT_MASK |
2882 GDK_POINTER_MOTION_MASK |
2883 GDK_ENTER_NOTIFY_MASK |
2884 GDK_LEAVE_NOTIFY_MASK);
2885 attributes_mask = GDK_WA_X | GDK_WA_Y;
2887 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2890 gdk_window_set_user_data (icon_info->window, widget);
2892 gtk_widget_queue_resize (widget);
2895 static EntryIconInfo*
2896 construct_icon_info (GtkWidget *widget,
2897 GtkEntryIconPosition icon_pos)
2899 GtkEntry *entry = GTK_ENTRY (widget);
2900 GtkEntryPrivate *priv = entry->priv;
2901 EntryIconInfo *icon_info;
2903 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2905 icon_info = g_slice_new0 (EntryIconInfo);
2906 priv->icons[icon_pos] = icon_info;
2908 icon_info->icon_helper = _gtk_icon_helper_new ();
2910 if (gtk_widget_get_realized (widget))
2911 realize_icon_info (widget, icon_pos);
2917 gtk_entry_map (GtkWidget *widget)
2919 GtkEntry *entry = GTK_ENTRY (widget);
2920 GtkEntryPrivate *priv = entry->priv;
2921 EntryIconInfo *icon_info = NULL;
2924 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2926 gdk_window_show (priv->text_area);
2928 for (i = 0; i < MAX_ICONS; i++)
2930 if ((icon_info = priv->icons[i]) != NULL)
2932 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2933 icon_info->window != NULL)
2934 gdk_window_show (icon_info->window);
2938 update_cursors (widget);
2942 gtk_entry_unmap (GtkWidget *widget)
2944 GtkEntry *entry = GTK_ENTRY (widget);
2945 GtkEntryPrivate *priv = entry->priv;
2946 EntryIconInfo *icon_info = NULL;
2949 for (i = 0; i < MAX_ICONS; i++)
2951 if ((icon_info = priv->icons[i]) != NULL)
2953 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2954 icon_info->window != NULL)
2955 gdk_window_hide (icon_info->window);
2959 gdk_window_hide (priv->text_area);
2961 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2965 gtk_entry_realize (GtkWidget *widget)
2968 GtkEntryPrivate *priv;
2969 EntryIconInfo *icon_info;
2971 GdkWindowAttr attributes;
2972 gint attributes_mask;
2973 gint frame_x, frame_y;
2976 gtk_widget_set_realized (widget, TRUE);
2977 window = gtk_widget_get_parent_window (widget);
2978 gtk_widget_set_window (widget, window);
2979 g_object_ref (window);
2981 entry = GTK_ENTRY (widget);
2984 attributes.window_type = GDK_WINDOW_CHILD;
2985 attributes.wclass = GDK_INPUT_ONLY;
2986 attributes.event_mask = gtk_widget_get_events (widget);
2987 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2988 GDK_BUTTON_RELEASE_MASK |
2989 GDK_BUTTON1_MOTION_MASK |
2990 GDK_BUTTON3_MOTION_MASK |
2991 GDK_POINTER_MOTION_HINT_MASK |
2992 GDK_POINTER_MOTION_MASK |
2993 GDK_ENTER_NOTIFY_MASK |
2994 GDK_LEAVE_NOTIFY_MASK);
2995 attributes_mask = GDK_WA_X | GDK_WA_Y;
2997 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2999 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3000 attributes.x += frame_x;
3001 attributes.y += frame_y;
3003 if (gtk_widget_is_sensitive (widget))
3005 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3006 attributes_mask |= GDK_WA_CURSOR;
3009 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3013 gdk_window_set_user_data (priv->text_area, entry);
3015 if (attributes_mask & GDK_WA_CURSOR)
3016 g_object_unref (attributes.cursor);
3018 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3020 gtk_entry_adjust_scroll (entry);
3021 gtk_entry_update_primary_selection (entry);
3024 /* If the icon positions are already setup, create their windows.
3025 * Otherwise if they don't exist yet, then construct_icon_info()
3026 * will create the windows once the widget is already realized.
3028 for (i = 0; i < MAX_ICONS; i++)
3030 if ((icon_info = priv->icons[i]) != NULL)
3032 if (icon_info->window == NULL)
3033 realize_icon_info (widget, i);
3039 gtk_entry_unrealize (GtkWidget *widget)
3041 GtkEntry *entry = GTK_ENTRY (widget);
3042 GtkEntryPrivate *priv = entry->priv;
3043 GtkClipboard *clipboard;
3044 EntryIconInfo *icon_info;
3047 gtk_entry_reset_layout (entry);
3049 gtk_im_context_set_client_window (priv->im_context, NULL);
3051 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3052 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3053 gtk_clipboard_clear (clipboard);
3055 if (priv->text_area)
3057 gdk_window_set_user_data (priv->text_area, NULL);
3058 gdk_window_destroy (priv->text_area);
3059 priv->text_area = NULL;
3062 if (priv->popup_menu)
3064 gtk_widget_destroy (priv->popup_menu);
3065 priv->popup_menu = NULL;
3068 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3070 for (i = 0; i < MAX_ICONS; i++)
3072 if ((icon_info = priv->icons[i]) != NULL)
3074 if (icon_info->window != NULL)
3076 gdk_window_destroy (icon_info->window);
3077 icon_info->window = NULL;
3084 _gtk_entry_get_borders (GtkEntry *entry,
3085 GtkBorder *border_out)
3087 GtkEntryPrivate *priv = entry->priv;
3088 GtkWidget *widget = GTK_WIDGET (entry);
3089 GtkBorder tmp = { 0, 0, 0, 0 };
3090 GtkStyleContext *context;
3092 context = gtk_widget_get_style_context (widget);
3093 gtk_style_context_get_padding (context, 0, &tmp);
3095 if (priv->has_frame)
3099 gtk_style_context_get_border (context, 0, &border);
3100 tmp.top += border.top;
3101 tmp.right += border.right;
3102 tmp.bottom += border.bottom;
3103 tmp.left += border.left;
3106 if (!priv->interior_focus)
3108 tmp.top += priv->focus_width;
3109 tmp.right += priv->focus_width;
3110 tmp.bottom += priv->focus_width;
3111 tmp.left += priv->focus_width;
3114 if (border_out != NULL)
3119 gtk_entry_get_preferred_width (GtkWidget *widget,
3123 GtkEntry *entry = GTK_ENTRY (widget);
3124 GtkEntryPrivate *priv = entry->priv;
3125 PangoFontMetrics *metrics;
3127 PangoContext *context;
3128 GtkStyleContext *style_context;
3129 GtkStateFlags state;
3130 gint icon_widths = 0;
3134 context = gtk_widget_get_pango_context (widget);
3136 style_context = gtk_widget_get_style_context (widget);
3137 state = gtk_widget_get_state_flags (widget);
3139 metrics = pango_context_get_metrics (context,
3140 gtk_style_context_get_font (style_context, state),
3141 pango_context_get_language (context));
3143 _gtk_entry_get_borders (entry, &borders);
3145 if (priv->width_chars < 0)
3146 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3149 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3150 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3151 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3153 width = char_pixels * priv->width_chars + borders.left + borders.right;
3156 for (i = 0; i < MAX_ICONS; i++)
3158 icon_width = get_icon_width (entry, i);
3160 icon_widths += icon_width;
3163 if (icon_widths > width)
3164 width += icon_widths;
3166 pango_font_metrics_unref (metrics);
3173 gtk_entry_get_preferred_height (GtkWidget *widget,
3177 GtkEntry *entry = GTK_ENTRY (widget);
3178 GtkEntryPrivate *priv = entry->priv;
3179 PangoFontMetrics *metrics;
3181 GtkStyleContext *style_context;
3182 GtkStateFlags state;
3183 PangoContext *context;
3186 context = gtk_widget_get_pango_context (widget);
3188 style_context = gtk_widget_get_style_context (widget);
3189 state = gtk_widget_get_state_flags (widget);
3191 metrics = pango_context_get_metrics (context,
3192 gtk_style_context_get_font (style_context, state),
3193 pango_context_get_language (context));
3195 priv->ascent = pango_font_metrics_get_ascent (metrics);
3196 priv->descent = pango_font_metrics_get_descent (metrics);
3198 _gtk_entry_get_borders (entry, &borders);
3200 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3202 pango_font_metrics_unref (metrics);
3209 place_windows (GtkEntry *entry)
3211 GtkWidget *widget = GTK_WIDGET (entry);
3212 GtkEntryPrivate *priv = entry->priv;
3213 gint x, y, width, height;
3214 gint frame_x, frame_y;
3215 GtkAllocation primary;
3216 GtkAllocation secondary;
3217 EntryIconInfo *icon_info = NULL;
3219 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3220 get_text_area_size (entry, &x, &y, &width, &height);
3221 get_icon_allocations (entry, &primary, &secondary);
3223 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3224 y += priv->focus_width;
3226 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3227 x += secondary.width;
3230 width -= primary.width + secondary.width;
3234 primary.x += frame_x;
3235 primary.y += frame_y;
3236 secondary.x += frame_x;
3237 secondary.y += frame_y;
3239 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3240 gdk_window_move_resize (icon_info->window,
3241 primary.x, primary.y,
3242 primary.width, primary.height);
3244 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3245 gdk_window_move_resize (icon_info->window,
3246 secondary.x, secondary.y,
3247 secondary.width, secondary.height);
3249 gdk_window_move_resize (priv->text_area, x, y, width, height);
3253 gtk_entry_get_text_area_size (GtkEntry *entry,
3259 GtkEntryPrivate *priv = entry->priv;
3260 GtkWidget *widget = GTK_WIDGET (entry);
3261 GtkAllocation allocation;
3262 GtkRequisition requisition;
3267 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3268 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3270 gtk_widget_get_allocation (widget, &allocation);
3271 _gtk_entry_get_borders (entry, &borders);
3273 if (gtk_widget_get_realized (widget))
3274 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3276 frame_height = req_height;
3278 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3279 frame_height -= 2 * priv->focus_width;
3285 *y = floor ((frame_height - req_height) / 2) + borders.top;
3288 *width = allocation.width - borders.left - borders.right;
3291 *height = req_height - borders.top - borders.bottom;
3295 get_text_area_size (GtkEntry *entry,
3301 GtkEntryClass *class;
3303 g_return_if_fail (GTK_IS_ENTRY (entry));
3305 class = GTK_ENTRY_GET_CLASS (entry);
3307 if (class->get_text_area_size)
3308 class->get_text_area_size (entry, x, y, width, height);
3313 get_frame_size (GtkEntry *entry,
3314 gboolean relative_to_window,
3320 GtkEntryPrivate *priv = entry->priv;
3321 GtkAllocation allocation;
3322 GtkRequisition requisition;
3323 GtkWidget *widget = GTK_WIDGET (entry);
3326 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3328 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3330 gtk_widget_get_allocation (widget, &allocation);
3333 *x = relative_to_window ? allocation.x : 0;
3337 if (priv->is_cell_renderer)
3340 *y = (allocation.height - req_height) / 2;
3342 if (relative_to_window)
3347 *width = allocation.width;
3351 if (priv->is_cell_renderer)
3352 *height = allocation.height;
3354 *height = req_height;
3359 gtk_entry_size_allocate (GtkWidget *widget,
3360 GtkAllocation *allocation)
3362 GtkEntry *entry = GTK_ENTRY (widget);
3364 gtk_widget_set_allocation (widget, allocation);
3366 if (gtk_widget_get_realized (widget))
3368 GtkEntryCompletion* completion;
3370 place_windows (entry);
3371 gtk_entry_recompute (entry);
3373 completion = gtk_entry_get_completion (entry);
3374 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3375 _gtk_entry_completion_resize_popup (completion);
3380 should_prelight (GtkEntry *entry,
3381 GtkEntryIconPosition icon_pos)
3383 GtkEntryPrivate *priv = entry->priv;
3384 EntryIconInfo *icon_info = priv->icons[icon_pos];
3390 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3393 if (icon_info->pressed)
3396 gtk_widget_style_get (GTK_WIDGET (entry),
3397 "icon-prelight", &prelight,
3404 draw_icon (GtkWidget *widget,
3406 GtkEntryIconPosition icon_pos)
3408 GtkEntry *entry = GTK_ENTRY (widget);
3409 GtkEntryPrivate *priv = entry->priv;
3410 EntryIconInfo *icon_info = priv->icons[icon_pos];
3411 gint x, y, width, height, pix_width, pix_height;
3412 GtkStyleContext *context;
3418 width = gdk_window_get_width (icon_info->window);
3419 height = gdk_window_get_height (icon_info->window);
3421 /* size_allocate hasn't been called yet. These are the default values.
3423 if (width == 1 || height == 1)
3427 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3429 context = gtk_widget_get_style_context (widget);
3430 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3431 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3432 &pix_width, &pix_height);
3433 gtk_style_context_get_padding (context, 0, &padding);
3435 x = MAX (0, padding.left);
3436 y = MAX (0, (height - pix_height) / 2);
3438 _gtk_icon_helper_draw (icon_info->icon_helper,
3442 gtk_style_context_restore (context);
3448 gtk_entry_draw_frame (GtkWidget *widget,
3449 GtkStyleContext *context,
3452 GtkEntry *entry = GTK_ENTRY (widget);
3453 GtkEntryPrivate *priv = entry->priv;
3454 gint x = 0, y = 0, width, height;
3455 gint frame_x, frame_y;
3459 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3461 cairo_translate (cr, frame_x, frame_y);
3463 /* Fix a problem with some themes which assume that entry->text_area's
3464 * width equals widget->window's width
3465 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3466 if (GTK_IS_SPIN_BUTTON (widget))
3470 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3471 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3474 width += borders.left + borders.right;
3477 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3479 x += priv->focus_width;
3480 y += priv->focus_width;
3481 width -= 2 * priv->focus_width;
3482 height -= 2 * priv->focus_width;
3485 gtk_render_background (context, cr,
3486 x, y, width, height);
3488 if (priv->has_frame)
3489 gtk_render_frame (context, cr,
3490 x, y, width, height);
3492 gtk_entry_draw_progress (widget, context, cr);
3494 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3496 x -= priv->focus_width;
3497 y -= priv->focus_width;
3498 width += 2 * priv->focus_width;
3499 height += 2 * priv->focus_width;
3501 gtk_render_focus (context, cr,
3502 0, 0, width, height);
3509 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3510 GtkStyleContext *context)
3512 GtkEntryPrivate *private = entry->priv;
3514 gtk_style_context_save (context);
3515 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3516 if (private->progress_pulse_mode)
3517 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3521 get_progress_area (GtkWidget *widget,
3527 GtkEntry *entry = GTK_ENTRY (widget);
3528 GtkEntryPrivate *private = entry->priv;
3529 GtkStyleContext *context;
3530 GtkBorder margin, border, entry_borders;
3531 gint frame_width, text_area_width, text_area_height;
3533 context = gtk_widget_get_style_context (widget);
3534 _gtk_entry_get_borders (entry, &entry_borders);
3535 get_text_area_size (entry,
3537 &text_area_width, &text_area_height);
3538 get_frame_size (entry, FALSE,
3540 &frame_width, NULL);
3544 *width = text_area_width + entry_borders.left + entry_borders.right;
3545 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3547 /* if the text area got resized by a subclass, subtract the left/right
3548 * border width, so that the progress bar won't extend over the resized
3551 if (frame_width > *width)
3553 gtk_style_context_get_border (context, 0, &border);
3554 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3556 *x = (frame_width - *width) + border.left;
3557 *width -= border.left;
3561 *width -= border.right;
3565 gtk_entry_prepare_context_for_progress (entry, context);
3566 gtk_style_context_get_margin (context, 0, &margin);
3568 gtk_style_context_restore (context);
3572 *width -= margin.left + margin.right;
3573 *height -= margin.top + margin.bottom;
3575 if (private->progress_pulse_mode)
3577 gdouble value = private->progress_pulse_current;
3579 *x += (gint) floor(value * (*width));
3580 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3582 else if (private->progress_fraction > 0)
3584 gdouble value = private->progress_fraction;
3586 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3590 bar_width = floor(value * (*width) + 0.5);
3591 *x += *width - bar_width;
3596 *width = (gint) floor(value * (*width) + 0.5);
3607 gtk_entry_draw_progress (GtkWidget *widget,
3608 GtkStyleContext *context,
3611 GtkEntry *entry = GTK_ENTRY (widget);
3612 gint x, y, width, height;
3614 get_progress_area (widget, &x, &y, &width, &height);
3616 if ((width <= 0) || (height <= 0))
3619 gtk_entry_prepare_context_for_progress (entry, context);
3620 gtk_render_activity (context, cr,
3621 x, y, width, height);
3623 gtk_style_context_restore (context);
3627 gtk_entry_draw (GtkWidget *widget,
3630 GtkEntry *entry = GTK_ENTRY (widget);
3631 GtkStyleContext *context;
3632 GtkEntryPrivate *priv = entry->priv;
3635 context = gtk_widget_get_style_context (widget);
3637 /* Draw entry_bg, shadow, progress and focus */
3638 gtk_entry_draw_frame (widget, context, cr);
3640 /* Draw text and cursor */
3643 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3645 if (priv->dnd_position != -1)
3646 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3648 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3650 /* When no text is being displayed at all, don't show the cursor */
3651 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3652 gtk_widget_has_focus (widget) &&
3653 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3654 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3659 for (i = 0; i < MAX_ICONS; i++)
3661 EntryIconInfo *icon_info = priv->icons[i];
3663 if (icon_info != NULL)
3664 draw_icon (widget, cr, i);
3671 gtk_entry_enter_notify (GtkWidget *widget,
3672 GdkEventCrossing *event)
3674 GtkEntry *entry = GTK_ENTRY (widget);
3675 GtkEntryPrivate *priv = entry->priv;
3678 for (i = 0; i < MAX_ICONS; i++)
3680 EntryIconInfo *icon_info = priv->icons[i];
3682 if (icon_info != NULL && event->window == icon_info->window)
3684 if (should_prelight (entry, i))
3686 icon_info->prelight = TRUE;
3687 gtk_widget_queue_draw (widget);
3698 gtk_entry_leave_notify (GtkWidget *widget,
3699 GdkEventCrossing *event)
3701 GtkEntry *entry = GTK_ENTRY (widget);
3702 GtkEntryPrivate *priv = entry->priv;
3705 for (i = 0; i < MAX_ICONS; i++)
3707 EntryIconInfo *icon_info = priv->icons[i];
3709 if (icon_info != NULL && event->window == icon_info->window)
3711 /* a grab means that we may never see the button release */
3712 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3713 icon_info->pressed = FALSE;
3715 if (should_prelight (entry, i))
3717 icon_info->prelight = FALSE;
3718 gtk_widget_queue_draw (widget);
3729 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3733 gint start_char, end_char;
3735 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3737 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3738 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3739 const char *text = pango_layout_get_text (layout);
3740 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3741 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3742 gint real_n_ranges, i;
3744 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3750 for (i = 0; i < real_n_ranges; ++i)
3752 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3753 r[2 * i] = r[2 * i] / PANGO_SCALE;
3758 *n_ranges = real_n_ranges;
3770 in_selection (GtkEntry *entry,
3775 gint retval = FALSE;
3777 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3779 for (i = 0; i < n_ranges; ++i)
3781 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3793 gtk_entry_button_press (GtkWidget *widget,
3794 GdkEventButton *event)
3796 GtkEntry *entry = GTK_ENTRY (widget);
3797 GtkEditable *editable = GTK_EDITABLE (widget);
3798 GtkEntryPrivate *priv = entry->priv;
3799 EntryIconInfo *icon_info = NULL;
3801 gint sel_start, sel_end;
3804 for (i = 0; i < MAX_ICONS; i++)
3806 icon_info = priv->icons[i];
3808 if (!icon_info || icon_info->insensitive)
3811 if (event->window == icon_info->window)
3813 if (should_prelight (entry, i))
3815 icon_info->prelight = FALSE;
3816 gtk_widget_queue_draw (widget);
3819 priv->start_x = event->x;
3820 priv->start_y = event->y;
3821 icon_info->pressed = TRUE;
3823 if (!icon_info->nonactivatable)
3824 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3830 if (event->window != priv->text_area ||
3831 (priv->button && event->button != priv->button))
3834 gtk_entry_reset_blink_time (entry);
3836 priv->button = event->button;
3837 priv->device = gdk_event_get_device ((GdkEvent *) event);
3839 if (!gtk_widget_has_focus (widget))
3841 priv->in_click = TRUE;
3842 gtk_widget_grab_focus (widget);
3843 priv->in_click = FALSE;
3846 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3848 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3850 gtk_entry_do_popup (entry, event);
3851 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3852 priv->device = NULL;
3856 else if (event->button == GDK_BUTTON_PRIMARY)
3858 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3860 priv->select_words = FALSE;
3861 priv->select_lines = FALSE;
3864 gtk_widget_get_modifier_mask (widget,
3865 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3867 _gtk_entry_reset_im_context (entry);
3869 if (!have_selection) /* select from the current position to the clicked position */
3870 sel_start = sel_end = priv->current_pos;
3872 if (tmp_pos > sel_start && tmp_pos < sel_end)
3874 /* Truncate current selection, but keep it as big as possible */
3875 if (tmp_pos - sel_start > sel_end - tmp_pos)
3876 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3878 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3882 gboolean extend_to_left;
3885 /* Figure out what click selects and extend current selection */
3886 switch (event->type)
3888 case GDK_BUTTON_PRESS:
3889 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3892 case GDK_2BUTTON_PRESS:
3893 priv->select_words = TRUE;
3894 gtk_entry_select_word (entry);
3897 case GDK_3BUTTON_PRESS:
3898 priv->select_lines = TRUE;
3899 gtk_entry_select_line (entry);
3906 start = MIN (priv->current_pos, priv->selection_bound);
3907 start = MIN (sel_start, start);
3909 end = MAX (priv->current_pos, priv->selection_bound);
3910 end = MAX (sel_end, end);
3912 if (tmp_pos == sel_start || tmp_pos == sel_end)
3913 extend_to_left = (tmp_pos == start);
3915 extend_to_left = (end == sel_end);
3918 gtk_entry_set_positions (entry, start, end);
3920 gtk_entry_set_positions (entry, end, start);
3923 else /* no shift key */
3924 switch (event->type)
3926 case GDK_BUTTON_PRESS:
3927 if (in_selection (entry, event->x + priv->scroll_offset))
3929 /* Click inside the selection - we'll either start a drag, or
3930 * clear the selection
3932 priv->in_drag = TRUE;
3933 priv->drag_start_x = event->x + priv->scroll_offset;
3934 priv->drag_start_y = event->y;
3937 gtk_editable_set_position (editable, tmp_pos);
3940 case GDK_2BUTTON_PRESS:
3941 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3942 * receiving a GDK_2BUTTON_PRESS so we need to reset
3943 * priv->in_drag which may have been set above
3945 priv->in_drag = FALSE;
3946 priv->select_words = TRUE;
3947 gtk_entry_select_word (entry);
3950 case GDK_3BUTTON_PRESS:
3951 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3952 * receiving a GDK_3BUTTON_PRESS so we need to reset
3953 * priv->in_drag which may have been set above
3955 priv->in_drag = FALSE;
3956 priv->select_lines = TRUE;
3957 gtk_entry_select_line (entry);
3966 else if (event->type == GDK_BUTTON_PRESS &&
3967 event->button == GDK_BUTTON_MIDDLE &&
3968 get_middle_click_paste (entry))
3972 priv->insert_pos = tmp_pos;
3973 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3978 gtk_widget_error_bell (widget);
3986 gtk_entry_button_release (GtkWidget *widget,
3987 GdkEventButton *event)
3989 GtkEntry *entry = GTK_ENTRY (widget);
3990 GtkEntryPrivate *priv = entry->priv;
3991 EntryIconInfo *icon_info = NULL;
3994 for (i = 0; i < MAX_ICONS; i++)
3996 icon_info = priv->icons[i];
3998 if (!icon_info || icon_info->insensitive)
4001 if (event->window == icon_info->window)
4003 icon_info->pressed = FALSE;
4005 if (should_prelight (entry, i) &&
4006 event->x >= 0 && event->y >= 0 &&
4007 event->x < gdk_window_get_width (icon_info->window) &&
4008 event->y < gdk_window_get_height (icon_info->window))
4010 icon_info->prelight = TRUE;
4011 gtk_widget_queue_draw (widget);
4014 if (!icon_info->nonactivatable)
4015 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4021 if (event->window != priv->text_area || priv->button != event->button)
4026 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4028 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4034 priv->device = NULL;
4036 gtk_entry_update_primary_selection (entry);
4042 _gtk_entry_get_selected_text (GtkEntry *entry)
4044 GtkEditable *editable = GTK_EDITABLE (entry);
4045 gint start_text, end_text;
4048 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4049 text = gtk_editable_get_chars (editable, start_text, end_text);
4055 gtk_entry_motion_notify (GtkWidget *widget,
4056 GdkEventMotion *event)
4058 GtkEntry *entry = GTK_ENTRY (widget);
4059 GtkEntryPrivate *priv = entry->priv;
4060 EntryIconInfo *icon_info = NULL;
4064 for (i = 0; i < MAX_ICONS; i++)
4066 icon_info = priv->icons[i];
4068 if (!icon_info || icon_info->insensitive)
4071 if (event->window == icon_info->window)
4073 if (icon_info->pressed &&
4074 icon_info->target_list != NULL &&
4075 gtk_drag_check_threshold (widget,
4081 icon_info->in_drag = TRUE;
4082 icon_info->pressed = FALSE;
4083 gtk_drag_begin (widget,
4084 icon_info->target_list,
4094 if (priv->mouse_cursor_obscured)
4098 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4099 gdk_window_set_cursor (priv->text_area, cursor);
4100 g_object_unref (cursor);
4101 priv->mouse_cursor_obscured = FALSE;
4104 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4107 if (priv->select_lines)
4110 gdk_event_request_motions (event);
4114 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4115 gtk_drag_check_threshold (widget,
4116 priv->drag_start_x, priv->drag_start_y,
4117 event->x + priv->scroll_offset, event->y))
4119 GdkDragContext *context;
4120 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4121 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4123 cairo_surface_t *surface;
4125 gtk_target_list_add_text_targets (target_list, 0);
4127 text = _gtk_entry_get_selected_text (entry);
4128 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4130 context = gtk_drag_begin (widget, target_list, actions,
4131 priv->button, (GdkEvent *)event);
4134 gtk_drag_set_icon_surface (context, surface);
4136 gtk_drag_set_icon_default (context);
4139 cairo_surface_destroy (surface);
4142 priv->in_drag = FALSE;
4144 priv->device = NULL;
4146 gtk_target_list_unref (target_list);
4153 else if (event->y >= gdk_window_get_height (priv->text_area))
4154 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4156 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4158 if (priv->select_words)
4161 gint old_min, old_max;
4164 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4165 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4167 pos = priv->current_pos;
4168 bound = priv->selection_bound;
4170 old_min = MIN(priv->current_pos, priv->selection_bound);
4171 old_max = MAX(priv->current_pos, priv->selection_bound);
4178 else if (old_max < max)
4183 else if (pos == old_min)
4185 if (priv->current_pos != min)
4190 if (priv->current_pos != max)
4194 gtk_entry_set_positions (entry, pos, bound);
4197 gtk_entry_set_positions (entry, tmp_pos, -1);
4204 set_invisible_cursor (GdkWindow *window)
4206 GdkDisplay *display;
4209 display = gdk_window_get_display (window);
4210 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4212 gdk_window_set_cursor (window, cursor);
4214 g_object_unref (cursor);
4218 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4220 GtkEntryPrivate *priv = entry->priv;
4222 if (priv->mouse_cursor_obscured)
4225 set_invisible_cursor (priv->text_area);
4227 priv->mouse_cursor_obscured = TRUE;
4231 gtk_entry_key_press (GtkWidget *widget,
4234 GtkEntry *entry = GTK_ENTRY (widget);
4235 GtkEntryPrivate *priv = entry->priv;
4237 gtk_entry_reset_blink_time (entry);
4238 gtk_entry_pend_cursor_blink (entry);
4242 if (gtk_im_context_filter_keypress (priv->im_context, event))
4244 gtk_entry_obscure_mouse_cursor (entry);
4245 priv->need_im_reset = TRUE;
4250 if (event->keyval == GDK_KEY_Return ||
4251 event->keyval == GDK_KEY_KP_Enter ||
4252 event->keyval == GDK_KEY_ISO_Enter ||
4253 event->keyval == GDK_KEY_Escape)
4255 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4257 if (completion && completion->priv->completion_timeout)
4259 g_source_remove (completion->priv->completion_timeout);
4260 completion->priv->completion_timeout = 0;
4263 _gtk_entry_reset_im_context (entry);
4266 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4267 /* Activate key bindings
4271 if (!priv->editable && event->length)
4272 gtk_widget_error_bell (widget);
4278 gtk_entry_key_release (GtkWidget *widget,
4281 GtkEntry *entry = GTK_ENTRY (widget);
4282 GtkEntryPrivate *priv = entry->priv;
4286 if (gtk_im_context_filter_keypress (priv->im_context, event))
4288 priv->need_im_reset = TRUE;
4293 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4297 gtk_entry_focus_in (GtkWidget *widget,
4298 GdkEventFocus *event)
4300 GtkEntry *entry = GTK_ENTRY (widget);
4301 GtkEntryPrivate *priv = entry->priv;
4304 gtk_widget_queue_draw (widget);
4306 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4310 priv->need_im_reset = TRUE;
4311 gtk_im_context_focus_in (priv->im_context);
4312 keymap_state_changed (keymap, entry);
4313 g_signal_connect (keymap, "state-changed",
4314 G_CALLBACK (keymap_state_changed), entry);
4317 g_signal_connect (keymap, "direction-changed",
4318 G_CALLBACK (keymap_direction_changed), entry);
4320 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4321 priv->placeholder_text != NULL)
4323 gtk_entry_recompute (entry);
4327 gtk_entry_reset_blink_time (entry);
4328 gtk_entry_check_cursor_blink (entry);
4335 gtk_entry_focus_out (GtkWidget *widget,
4336 GdkEventFocus *event)
4338 GtkEntry *entry = GTK_ENTRY (widget);
4339 GtkEntryPrivate *priv = entry->priv;
4340 GtkEntryCompletion *completion;
4343 gtk_widget_queue_draw (widget);
4345 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4349 priv->need_im_reset = TRUE;
4350 gtk_im_context_focus_out (priv->im_context);
4351 remove_capslock_feedback (entry);
4354 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4355 priv->placeholder_text != NULL)
4357 gtk_entry_recompute (entry);
4361 gtk_entry_check_cursor_blink (entry);
4364 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4365 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4367 completion = gtk_entry_get_completion (entry);
4369 _gtk_entry_completion_popdown (completion);
4375 gtk_entry_grab_focus (GtkWidget *widget)
4377 GtkEntry *entry = GTK_ENTRY (widget);
4378 GtkEntryPrivate *priv = entry->priv;
4379 gboolean select_on_focus;
4381 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4383 if (priv->editable && !priv->in_click)
4385 g_object_get (gtk_widget_get_settings (widget),
4386 "gtk-entry-select-on-focus",
4390 if (select_on_focus)
4391 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4396 gtk_entry_direction_changed (GtkWidget *widget,
4397 GtkTextDirection previous_dir)
4399 GtkEntry *entry = GTK_ENTRY (widget);
4401 gtk_entry_recompute (entry);
4403 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4407 gtk_entry_state_flags_changed (GtkWidget *widget,
4408 GtkStateFlags previous_state)
4410 GtkEntry *entry = GTK_ENTRY (widget);
4411 GtkEntryPrivate *priv = entry->priv;
4414 if (gtk_widget_get_realized (widget))
4416 if (gtk_widget_is_sensitive (widget))
4417 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4421 gdk_window_set_cursor (priv->text_area, cursor);
4424 g_object_unref (cursor);
4426 priv->mouse_cursor_obscured = FALSE;
4428 update_cursors (widget);
4431 if (!gtk_widget_is_sensitive (widget))
4433 /* Clear any selection */
4434 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4437 gtk_entry_update_cached_style_values (entry);
4441 gtk_entry_screen_changed (GtkWidget *widget,
4442 GdkScreen *old_screen)
4444 gtk_entry_recompute (GTK_ENTRY (widget));
4447 /* GtkEditable method implementations
4450 gtk_entry_insert_text (GtkEditable *editable,
4451 const gchar *new_text,
4452 gint new_text_length,
4455 g_object_ref (editable);
4458 * The incoming text may a password or other secret. We make sure
4459 * not to copy it into temporary buffers.
4462 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4464 g_object_unref (editable);
4468 gtk_entry_delete_text (GtkEditable *editable,
4472 g_object_ref (editable);
4474 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4476 g_object_unref (editable);
4480 gtk_entry_get_chars (GtkEditable *editable,
4484 GtkEntry *entry = GTK_ENTRY (editable);
4487 gint start_index, end_index;
4489 text = gtk_entry_buffer_get_text (get_buffer (entry));
4490 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4493 end_pos = text_length;
4495 start_pos = MIN (text_length, start_pos);
4496 end_pos = MIN (text_length, end_pos);
4498 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4499 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4501 return g_strndup (text + start_index, end_index - start_index);
4505 gtk_entry_real_set_position (GtkEditable *editable,
4508 GtkEntry *entry = GTK_ENTRY (editable);
4509 GtkEntryPrivate *priv = entry->priv;
4513 length = gtk_entry_buffer_get_length (get_buffer (entry));
4514 if (position < 0 || position > length)
4517 if (position != priv->current_pos ||
4518 position != priv->selection_bound)
4520 _gtk_entry_reset_im_context (entry);
4521 gtk_entry_set_positions (entry, position, position);
4526 gtk_entry_get_position (GtkEditable *editable)
4528 GtkEntry *entry = GTK_ENTRY (editable);
4529 GtkEntryPrivate *priv = entry->priv;
4531 return priv->current_pos;
4535 gtk_entry_set_selection_bounds (GtkEditable *editable,
4539 GtkEntry *entry = GTK_ENTRY (editable);
4542 length = gtk_entry_buffer_get_length (get_buffer (entry));
4548 _gtk_entry_reset_im_context (entry);
4550 gtk_entry_set_positions (entry,
4552 MIN (start, length));
4554 gtk_entry_update_primary_selection (entry);
4558 gtk_entry_get_selection_bounds (GtkEditable *editable,
4562 GtkEntry *entry = GTK_ENTRY (editable);
4563 GtkEntryPrivate *priv = entry->priv;
4565 *start = priv->selection_bound;
4566 *end = priv->current_pos;
4568 return (priv->selection_bound != priv->current_pos);
4572 icon_theme_changed (GtkEntry *entry)
4574 GtkEntryPrivate *priv = entry->priv;
4577 for (i = 0; i < MAX_ICONS; i++)
4579 EntryIconInfo *icon_info = priv->icons[i];
4580 if (icon_info != NULL)
4581 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4584 gtk_widget_queue_draw (GTK_WIDGET (entry));
4588 gtk_entry_update_cached_style_values (GtkEntry *entry)
4590 GtkEntryPrivate *priv = entry->priv;
4592 gboolean interior_focus;
4594 gtk_widget_style_get (GTK_WIDGET (entry),
4595 "focus-line-width", &focus_width,
4596 "interior-focus", &interior_focus,
4598 priv->focus_width = focus_width;
4599 priv->interior_focus = interior_focus;
4601 if (!priv->invisible_char_set)
4603 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4605 if (priv->invisible_char != ch)
4607 priv->invisible_char = ch;
4608 g_object_notify (G_OBJECT (entry), "invisible-char");
4614 gtk_entry_style_updated (GtkWidget *widget)
4616 GtkEntry *entry = GTK_ENTRY (widget);
4618 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4620 gtk_entry_update_cached_style_values (entry);
4622 gtk_entry_recompute (entry);
4624 icon_theme_changed (entry);
4627 /* GtkCellEditable method implementations
4630 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4632 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4633 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4637 gtk_cell_editable_key_press_event (GtkEntry *entry,
4638 GdkEventKey *key_event,
4641 GtkEntryPrivate *priv = entry->priv;
4643 if (key_event->keyval == GDK_KEY_Escape)
4645 priv->editing_canceled = TRUE;
4646 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4647 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4652 /* override focus */
4653 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4655 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4656 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4665 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4668 GtkEntry *entry = GTK_ENTRY (cell_editable);
4669 GtkEntryPrivate *priv = entry->priv;
4671 priv->is_cell_renderer = TRUE;
4673 g_signal_connect (cell_editable, "activate",
4674 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4675 g_signal_connect (cell_editable, "key-press-event",
4676 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4680 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4682 if (password_hint->source_id)
4683 g_source_remove (password_hint->source_id);
4685 g_slice_free (GtkEntryPasswordHint, password_hint);
4690 gtk_entry_remove_password_hint (gpointer data)
4692 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4693 password_hint->position = -1;
4695 /* Force the string to be redrawn, but now without a visible character */
4696 gtk_entry_recompute (GTK_ENTRY (data));
4700 /* Default signal handlers
4703 gtk_entry_real_insert_text (GtkEditable *editable,
4704 const gchar *new_text,
4705 gint new_text_length,
4711 n_chars = g_utf8_strlen (new_text, new_text_length);
4714 * The actual insertion into the buffer. This will end up firing the
4715 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4716 * buffer_notify_text(), buffer_notify_length()
4718 begin_change (GTK_ENTRY (editable));
4720 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4722 end_change (GTK_ENTRY (editable));
4724 if (n_inserted != n_chars)
4725 gtk_widget_error_bell (GTK_WIDGET (editable));
4727 *position += n_inserted;
4731 gtk_entry_real_delete_text (GtkEditable *editable,
4736 * The actual deletion from the buffer. This will end up firing the
4737 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4738 * buffer_notify_text(), buffer_notify_length()
4741 begin_change (GTK_ENTRY (editable));
4743 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4745 end_change (GTK_ENTRY (editable));
4748 /* GtkEntryBuffer signal handlers
4751 buffer_inserted_text (GtkEntryBuffer *buffer,
4757 GtkEntryPrivate *priv = entry->priv;
4758 guint password_hint_timeout;
4760 gint selection_bound;
4762 current_pos = priv->current_pos;
4763 if (current_pos > position)
4764 current_pos += n_chars;
4766 selection_bound = priv->selection_bound;
4767 if (selection_bound > position)
4768 selection_bound += n_chars;
4770 gtk_entry_set_positions (entry, current_pos, selection_bound);
4772 /* Calculate the password hint if it needs to be displayed. */
4773 if (n_chars == 1 && !priv->visible)
4775 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4776 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4779 if (password_hint_timeout > 0)
4781 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4782 quark_password_hint);
4785 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4786 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4787 (GDestroyNotify)gtk_entry_password_hint_free);
4790 password_hint->position = position;
4791 if (password_hint->source_id)
4792 g_source_remove (password_hint->source_id);
4793 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4794 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4800 buffer_deleted_text (GtkEntryBuffer *buffer,
4805 GtkEntryPrivate *priv = entry->priv;
4806 guint end_pos = position + n_chars;
4807 gint selection_bound;
4810 current_pos = priv->current_pos;
4811 if (current_pos > position)
4812 current_pos -= MIN (current_pos, end_pos) - position;
4814 selection_bound = priv->selection_bound;
4815 if (selection_bound > position)
4816 selection_bound -= MIN (selection_bound, end_pos) - position;
4818 gtk_entry_set_positions (entry, current_pos, selection_bound);
4820 /* We might have deleted the selection */
4821 gtk_entry_update_primary_selection (entry);
4823 /* Disable the password hint if one exists. */
4826 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4827 quark_password_hint);
4830 if (password_hint->source_id)
4831 g_source_remove (password_hint->source_id);
4832 password_hint->source_id = 0;
4833 password_hint->position = -1;
4839 buffer_notify_text (GtkEntryBuffer *buffer,
4843 gtk_entry_recompute (entry);
4844 emit_changed (entry);
4845 g_object_notify (G_OBJECT (entry), "text");
4849 buffer_notify_length (GtkEntryBuffer *buffer,
4853 g_object_notify (G_OBJECT (entry), "text-length");
4857 buffer_notify_max_length (GtkEntryBuffer *buffer,
4861 g_object_notify (G_OBJECT (entry), "max-length");
4865 buffer_connect_signals (GtkEntry *entry)
4867 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4868 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4869 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4870 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4871 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4875 buffer_disconnect_signals (GtkEntry *entry)
4877 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4878 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4879 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4880 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4881 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4884 /* Compute the X position for an offset that corresponds to the "more important
4885 * cursor position for that offset. We use this when trying to guess to which
4886 * end of the selection we should go to when the user hits the left or
4890 get_better_cursor_x (GtkEntry *entry,
4893 GtkEntryPrivate *priv = entry->priv;
4894 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4895 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4896 gboolean split_cursor;
4898 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4899 const gchar *text = pango_layout_get_text (layout);
4900 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4902 PangoRectangle strong_pos, weak_pos;
4904 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4905 "gtk-split-cursor", &split_cursor,
4908 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4911 return strong_pos.x / PANGO_SCALE;
4913 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4917 gtk_entry_move_cursor (GtkEntry *entry,
4918 GtkMovementStep step,
4920 gboolean extend_selection)
4922 GtkEntryPrivate *priv = entry->priv;
4923 gint new_pos = priv->current_pos;
4925 _gtk_entry_reset_im_context (entry);
4927 if (priv->current_pos != priv->selection_bound && !extend_selection)
4929 /* If we have a current selection and aren't extending it, move to the
4930 * start/or end of the selection as appropriate
4934 case GTK_MOVEMENT_VISUAL_POSITIONS:
4936 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4937 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4940 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4942 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4945 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4946 case GTK_MOVEMENT_WORDS:
4948 new_pos = MIN (priv->current_pos, priv->selection_bound);
4950 new_pos = MAX (priv->current_pos, priv->selection_bound);
4952 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4953 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4954 case GTK_MOVEMENT_BUFFER_ENDS:
4955 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4957 case GTK_MOVEMENT_DISPLAY_LINES:
4958 case GTK_MOVEMENT_PARAGRAPHS:
4959 case GTK_MOVEMENT_PAGES:
4960 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4968 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4969 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4971 case GTK_MOVEMENT_VISUAL_POSITIONS:
4972 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4973 if (priv->current_pos == new_pos)
4975 if (!extend_selection)
4977 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4979 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4981 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4984 gtk_widget_child_focus (toplevel,
4986 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4991 gtk_widget_error_bell (GTK_WIDGET (entry));
4995 case GTK_MOVEMENT_WORDS:
4998 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5003 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5006 if (priv->current_pos == new_pos)
5007 gtk_widget_error_bell (GTK_WIDGET (entry));
5009 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5010 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5011 case GTK_MOVEMENT_BUFFER_ENDS:
5012 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5013 if (priv->current_pos == new_pos)
5014 gtk_widget_error_bell (GTK_WIDGET (entry));
5016 case GTK_MOVEMENT_DISPLAY_LINES:
5017 case GTK_MOVEMENT_PARAGRAPHS:
5018 case GTK_MOVEMENT_PAGES:
5019 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5024 if (extend_selection)
5025 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5027 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5029 gtk_entry_pend_cursor_blink (entry);
5033 gtk_entry_insert_at_cursor (GtkEntry *entry,
5036 GtkEntryPrivate *priv = entry->priv;
5037 GtkEditable *editable = GTK_EDITABLE (entry);
5038 gint pos = priv->current_pos;
5042 _gtk_entry_reset_im_context (entry);
5044 gtk_editable_insert_text (editable, str, -1, &pos);
5045 gtk_editable_set_position (editable, pos);
5050 gtk_entry_delete_from_cursor (GtkEntry *entry,
5054 GtkEntryPrivate *priv = entry->priv;
5055 GtkEditable *editable = GTK_EDITABLE (entry);
5056 gint start_pos = priv->current_pos;
5057 gint end_pos = priv->current_pos;
5058 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5060 _gtk_entry_reset_im_context (entry);
5062 if (!priv->editable)
5064 gtk_widget_error_bell (GTK_WIDGET (entry));
5068 if (priv->selection_bound != priv->current_pos)
5070 gtk_editable_delete_selection (editable);
5076 case GTK_DELETE_CHARS:
5077 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5078 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5080 case GTK_DELETE_WORDS:
5083 /* Move to end of current word, or if not on a word, end of previous word */
5084 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5085 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5089 /* Move to beginning of current word, or if not on a word, begining of next word */
5090 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5091 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5095 case GTK_DELETE_WORD_ENDS:
5098 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5103 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5106 gtk_editable_delete_text (editable, start_pos, end_pos);
5108 case GTK_DELETE_DISPLAY_LINE_ENDS:
5109 case GTK_DELETE_PARAGRAPH_ENDS:
5111 gtk_editable_delete_text (editable, 0, priv->current_pos);
5113 gtk_editable_delete_text (editable, priv->current_pos, -1);
5115 case GTK_DELETE_DISPLAY_LINES:
5116 case GTK_DELETE_PARAGRAPHS:
5117 gtk_editable_delete_text (editable, 0, -1);
5119 case GTK_DELETE_WHITESPACE:
5120 gtk_entry_delete_whitespace (entry);
5124 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5125 gtk_widget_error_bell (GTK_WIDGET (entry));
5127 gtk_entry_pend_cursor_blink (entry);
5131 gtk_entry_backspace (GtkEntry *entry)
5133 GtkEntryPrivate *priv = entry->priv;
5134 GtkEditable *editable = GTK_EDITABLE (entry);
5137 _gtk_entry_reset_im_context (entry);
5139 if (!priv->editable)
5141 gtk_widget_error_bell (GTK_WIDGET (entry));
5145 if (priv->selection_bound != priv->current_pos)
5147 gtk_editable_delete_selection (editable);
5151 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5153 if (prev_pos < priv->current_pos)
5155 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5156 PangoLogAttr *log_attrs;
5159 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5161 /* Deleting parts of characters */
5162 if (log_attrs[priv->current_pos].backspace_deletes_character)
5164 gchar *cluster_text;
5165 gchar *normalized_text;
5168 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5170 normalized_text = g_utf8_normalize (cluster_text,
5171 strlen (cluster_text),
5173 len = g_utf8_strlen (normalized_text, -1);
5175 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5178 gint pos = priv->current_pos;
5180 gtk_editable_insert_text (editable, normalized_text,
5181 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5183 gtk_editable_set_position (editable, pos);
5186 g_free (normalized_text);
5187 g_free (cluster_text);
5191 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5198 gtk_widget_error_bell (GTK_WIDGET (entry));
5201 gtk_entry_pend_cursor_blink (entry);
5205 gtk_entry_copy_clipboard (GtkEntry *entry)
5207 GtkEntryPrivate *priv = entry->priv;
5208 GtkEditable *editable = GTK_EDITABLE (entry);
5212 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5216 gtk_widget_error_bell (GTK_WIDGET (entry));
5220 str = gtk_entry_get_display_text (entry, start, end);
5221 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5222 GDK_SELECTION_CLIPBOARD),
5229 gtk_entry_cut_clipboard (GtkEntry *entry)
5231 GtkEntryPrivate *priv = entry->priv;
5232 GtkEditable *editable = GTK_EDITABLE (entry);
5237 gtk_widget_error_bell (GTK_WIDGET (entry));
5241 gtk_entry_copy_clipboard (entry);
5245 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5246 gtk_editable_delete_text (editable, start, end);
5250 gtk_widget_error_bell (GTK_WIDGET (entry));
5255 gtk_entry_paste_clipboard (GtkEntry *entry)
5257 GtkEntryPrivate *priv = entry->priv;
5260 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5262 gtk_widget_error_bell (GTK_WIDGET (entry));
5266 gtk_entry_delete_cb (GtkEntry *entry)
5268 GtkEntryPrivate *priv = entry->priv;
5269 GtkEditable *editable = GTK_EDITABLE (entry);
5274 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5275 gtk_editable_delete_text (editable, start, end);
5280 gtk_entry_toggle_overwrite (GtkEntry *entry)
5282 GtkEntryPrivate *priv = entry->priv;
5284 priv->overwrite_mode = !priv->overwrite_mode;
5285 gtk_entry_pend_cursor_blink (entry);
5286 gtk_widget_queue_draw (GTK_WIDGET (entry));
5290 gtk_entry_select_all (GtkEntry *entry)
5292 gtk_entry_select_line (entry);
5296 gtk_entry_real_activate (GtkEntry *entry)
5298 GtkEntryPrivate *priv = entry->priv;
5300 GtkWidget *default_widget, *focus_widget;
5301 GtkWidget *toplevel;
5304 widget = GTK_WIDGET (entry);
5306 if (priv->activates_default)
5308 toplevel = gtk_widget_get_toplevel (widget);
5309 if (GTK_IS_WINDOW (toplevel))
5311 window = GTK_WINDOW (toplevel);
5315 default_widget = gtk_window_get_default_widget (window);
5316 focus_widget = gtk_window_get_focus (window);
5317 if (widget != default_widget &&
5318 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5319 gtk_window_activate_default (window);
5326 keymap_direction_changed (GdkKeymap *keymap,
5329 gtk_entry_recompute (entry);
5332 /* IM Context Callbacks
5336 gtk_entry_commit_cb (GtkIMContext *context,
5340 GtkEntryPrivate *priv = entry->priv;
5343 gtk_entry_enter_text (entry, str);
5347 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5350 GtkEntryPrivate *priv = entry->priv;
5354 gchar *preedit_string;
5357 gtk_im_context_get_preedit_string (priv->im_context,
5358 &preedit_string, NULL,
5360 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5361 priv->preedit_length = strlen (preedit_string);
5362 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5363 priv->preedit_cursor = cursor_pos;
5364 g_free (preedit_string);
5366 gtk_entry_recompute (entry);
5371 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5374 GtkEntryPrivate *priv = entry->priv;
5377 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5378 text = gtk_entry_get_display_text (entry, 0, -1);
5379 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5380 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5387 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5392 GtkEntryPrivate *priv = entry->priv;
5395 gtk_editable_delete_text (GTK_EDITABLE (entry),
5396 priv->current_pos + offset,
5397 priv->current_pos + offset + n_chars);
5402 /* Internal functions
5405 /* Used for im_commit_cb and inserting Unicode chars */
5407 gtk_entry_enter_text (GtkEntry *entry,
5410 GtkEntryPrivate *priv = entry->priv;
5411 GtkEditable *editable = GTK_EDITABLE (entry);
5413 gboolean old_need_im_reset;
5415 old_need_im_reset = priv->need_im_reset;
5416 priv->need_im_reset = FALSE;
5418 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5419 gtk_editable_delete_selection (editable);
5422 if (priv->overwrite_mode)
5423 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5426 tmp_pos = priv->current_pos;
5427 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5428 gtk_editable_set_position (editable, tmp_pos);
5430 priv->need_im_reset = old_need_im_reset;
5433 /* All changes to priv->current_pos and priv->selection_bound
5434 * should go through this function.
5437 gtk_entry_set_positions (GtkEntry *entry,
5439 gint selection_bound)
5441 GtkEntryPrivate *priv = entry->priv;
5442 gboolean changed = FALSE;
5444 g_object_freeze_notify (G_OBJECT (entry));
5446 if (current_pos != -1 &&
5447 priv->current_pos != current_pos)
5449 priv->current_pos = current_pos;
5452 g_object_notify (G_OBJECT (entry), "cursor-position");
5455 if (selection_bound != -1 &&
5456 priv->selection_bound != selection_bound)
5458 priv->selection_bound = selection_bound;
5461 g_object_notify (G_OBJECT (entry), "selection-bound");
5464 g_object_thaw_notify (G_OBJECT (entry));
5468 gtk_entry_move_adjustments (entry);
5469 gtk_entry_recompute (entry);
5474 gtk_entry_reset_layout (GtkEntry *entry)
5476 GtkEntryPrivate *priv = entry->priv;
5478 if (priv->cached_layout)
5480 g_object_unref (priv->cached_layout);
5481 priv->cached_layout = NULL;
5486 update_im_cursor_location (GtkEntry *entry)
5488 GtkEntryPrivate *priv = entry->priv;
5491 gint strong_xoffset;
5492 gint area_width, area_height;
5494 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5495 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5497 strong_xoffset = strong_x - priv->scroll_offset;
5498 if (strong_xoffset < 0)
5502 else if (strong_xoffset > area_width)
5504 strong_xoffset = area_width;
5506 area.x = strong_xoffset;
5509 area.height = area_height;
5511 gtk_im_context_set_cursor_location (priv->im_context, &area);
5515 recompute_idle_func (gpointer data)
5517 GtkEntry *entry = GTK_ENTRY (data);
5518 GtkEntryPrivate *priv = entry->priv;
5520 priv->recompute_idle = 0;
5522 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5524 gtk_entry_adjust_scroll (entry);
5525 gtk_widget_queue_draw (GTK_WIDGET (entry));
5527 update_im_cursor_location (entry);
5534 gtk_entry_recompute (GtkEntry *entry)
5536 GtkEntryPrivate *priv = entry->priv;
5538 gtk_entry_reset_layout (entry);
5539 gtk_entry_check_cursor_blink (entry);
5541 if (!priv->recompute_idle)
5543 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5544 recompute_idle_func, entry, NULL);
5549 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5552 GtkWidget *widget = GTK_WIDGET (entry);
5553 GtkStyleContext *context;
5554 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5556 context = gtk_widget_get_style_context (widget);
5557 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5559 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5560 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5561 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5564 static inline gboolean
5565 show_placeholder_text (GtkEntry *entry)
5567 GtkEntryPrivate *priv = entry->priv;
5569 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5570 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5571 priv->placeholder_text != NULL)
5577 static PangoLayout *
5578 gtk_entry_create_layout (GtkEntry *entry,
5579 gboolean include_preedit)
5581 GtkEntryPrivate *priv = entry->priv;
5582 GtkWidget *widget = GTK_WIDGET (entry);
5583 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5584 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5585 gboolean placeholder_layout = show_placeholder_text (entry);
5587 gchar *preedit_string = NULL;
5588 gint preedit_length = 0;
5589 PangoAttrList *preedit_attrs = NULL;
5594 pango_layout_set_single_paragraph_mode (layout, TRUE);
5596 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5597 n_bytes = strlen (display);
5599 if (!placeholder_layout && include_preedit)
5601 gtk_im_context_get_preedit_string (priv->im_context,
5602 &preedit_string, &preedit_attrs, NULL);
5603 preedit_length = priv->preedit_length;
5605 else if (placeholder_layout)
5608 PangoAttribute *attr;
5610 gtk_entry_get_placeholder_text_color (entry, &color);
5611 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5612 attr->start_index = 0;
5613 attr->end_index = G_MAXINT;
5614 pango_attr_list_insert (tmp_attrs, attr);
5619 GString *tmp_string = g_string_new (display);
5620 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5622 g_string_insert (tmp_string, cursor_index, preedit_string);
5624 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5626 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5627 cursor_index, preedit_length);
5629 g_string_free (tmp_string, TRUE);
5633 PangoDirection pango_dir;
5635 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5636 pango_dir = pango_find_base_dir (display, n_bytes);
5638 pango_dir = PANGO_DIRECTION_NEUTRAL;
5640 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5642 if (gtk_widget_has_focus (widget))
5644 GdkDisplay *display = gtk_widget_get_display (widget);
5645 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5646 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5647 pango_dir = PANGO_DIRECTION_RTL;
5649 pango_dir = PANGO_DIRECTION_LTR;
5653 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5654 pango_dir = PANGO_DIRECTION_RTL;
5656 pango_dir = PANGO_DIRECTION_LTR;
5660 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5663 priv->resolved_dir = pango_dir;
5665 pango_layout_set_text (layout, display, n_bytes);
5668 pango_layout_set_attributes (layout, tmp_attrs);
5670 g_free (preedit_string);
5674 pango_attr_list_unref (preedit_attrs);
5676 pango_attr_list_unref (tmp_attrs);
5681 static PangoLayout *
5682 gtk_entry_ensure_layout (GtkEntry *entry,
5683 gboolean include_preedit)
5685 GtkEntryPrivate *priv = entry->priv;
5687 if (priv->preedit_length > 0 &&
5688 !include_preedit != !priv->cache_includes_preedit)
5689 gtk_entry_reset_layout (entry);
5691 if (!priv->cached_layout)
5693 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5694 priv->cache_includes_preedit = include_preedit;
5697 return priv->cached_layout;
5701 get_layout_position (GtkEntry *entry,
5705 GtkEntryPrivate *priv = entry->priv;
5706 PangoLayout *layout;
5707 PangoRectangle logical_rect;
5708 gint area_width, area_height;
5710 PangoLayoutLine *line;
5712 layout = gtk_entry_ensure_layout (entry, TRUE);
5714 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5715 area_height = PANGO_SCALE * area_height;
5717 line = pango_layout_get_lines_readonly (layout)->data;
5718 pango_layout_line_get_extents (line, NULL, &logical_rect);
5720 /* Align primarily for locale's ascent/descent */
5721 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5722 priv->ascent + logical_rect.y);
5724 /* Now see if we need to adjust to fit in actual drawn string */
5725 if (logical_rect.height > area_height)
5726 y_pos = (area_height - logical_rect.height) / 2;
5729 else if (y_pos + logical_rect.height > area_height)
5730 y_pos = area_height - logical_rect.height;
5732 y_pos = y_pos / PANGO_SCALE;
5735 *x = - priv->scroll_offset;
5742 draw_text_with_color (GtkEntry *entry,
5744 GdkRGBA *default_color)
5746 GtkEntryPrivate *priv = entry->priv;
5747 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5750 gint start_pos, end_pos;
5752 widget = GTK_WIDGET (entry);
5756 get_layout_position (entry, &x, &y);
5758 cairo_move_to (cr, x, y);
5759 gdk_cairo_set_source_rgba (cr, default_color);
5760 pango_cairo_show_layout (cr, layout);
5762 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5766 PangoRectangle logical_rect;
5767 GdkRGBA selection_color, text_color;
5768 GtkStyleContext *context;
5769 GtkStateFlags state;
5771 context = gtk_widget_get_style_context (widget);
5772 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5773 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5775 state = gtk_widget_get_state_flags (widget);
5776 state |= GTK_STATE_FLAG_SELECTED;
5778 gtk_style_context_get_background_color (context, state, &selection_color);
5779 gtk_style_context_get_color (context, state, &text_color);
5781 for (i = 0; i < n_ranges; ++i)
5782 cairo_rectangle (cr,
5783 - priv->scroll_offset + ranges[2 * i],
5786 logical_rect.height);
5790 gdk_cairo_set_source_rgba (cr, &selection_color);
5793 cairo_move_to (cr, x, y);
5794 gdk_cairo_set_source_rgba (cr, &text_color);
5795 pango_cairo_show_layout (cr, layout);
5803 gtk_entry_draw_text (GtkEntry *entry,
5806 GtkEntryPrivate *priv = entry->priv;
5807 GtkWidget *widget = GTK_WIDGET (entry);
5808 GtkStateFlags state = 0;
5809 GdkRGBA text_color, bar_text_color;
5810 GtkStyleContext *context;
5812 gint progress_x, progress_y, progress_width, progress_height;
5813 gint clip_width, clip_height;
5815 /* Nothing to display at all */
5816 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5819 state = gtk_widget_get_state_flags (widget);
5820 context = gtk_widget_get_style_context (widget);
5822 gtk_style_context_get_color (context, state, &text_color);
5824 /* Get foreground color for progressbars */
5825 gtk_entry_prepare_context_for_progress (entry, context);
5826 gtk_style_context_get_color (context, state, &bar_text_color);
5827 gtk_style_context_restore (context);
5829 get_progress_area (widget,
5830 &progress_x, &progress_y,
5831 &progress_width, &progress_height);
5835 clip_width = gdk_window_get_width (priv->text_area);
5836 clip_height = gdk_window_get_height (priv->text_area);
5837 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5840 /* If the color is the same, or the progress area has a zero
5841 * size, then we only need to draw once. */
5842 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5843 ((progress_width == 0) || (progress_height == 0)))
5845 draw_text_with_color (entry, cr, &text_color);
5849 int frame_x, frame_y, area_x, area_y;
5851 width = gdk_window_get_width (priv->text_area);
5852 height = gdk_window_get_height (priv->text_area);
5856 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5857 cairo_rectangle (cr, 0, 0, width, height);
5859 /* progres area is frame-relative, we need it text-area window
5861 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5862 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5863 progress_x += frame_x - area_x;
5864 progress_y += frame_y - area_y;
5866 cairo_rectangle (cr, progress_x, progress_y,
5867 progress_width, progress_height);
5869 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5871 draw_text_with_color (entry, cr, &text_color);
5876 cairo_rectangle (cr, progress_x, progress_y,
5877 progress_width, progress_height);
5880 draw_text_with_color (entry, cr, &bar_text_color);
5889 gtk_entry_draw_cursor (GtkEntry *entry,
5893 GtkEntryPrivate *priv = entry->priv;
5894 GtkWidget *widget = GTK_WIDGET (entry);
5895 GtkStyleContext *context;
5896 PangoRectangle cursor_rect;
5899 gboolean block_at_line_end;
5900 PangoLayout *layout;
5904 context = gtk_widget_get_style_context (widget);
5906 layout = gtk_entry_ensure_layout (entry, TRUE);
5907 text = pango_layout_get_text (layout);
5908 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5909 get_layout_position (entry, &x, &y);
5911 if (!priv->overwrite_mode)
5914 block = _gtk_text_util_get_block_cursor_location (layout,
5915 cursor_index, &cursor_rect, &block_at_line_end);
5919 gtk_render_insertion_cursor (context, cr,
5921 layout, cursor_index, priv->resolved_dir);
5923 else /* overwrite_mode */
5925 GdkRGBA cursor_color;
5930 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5931 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5932 rect.width = PANGO_PIXELS (cursor_rect.width);
5933 rect.height = PANGO_PIXELS (cursor_rect.height);
5935 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5936 gdk_cairo_set_source_rgba (cr, &cursor_color);
5937 gdk_cairo_rectangle (cr, &rect);
5940 if (!block_at_line_end)
5942 GtkStateFlags state;
5945 state = gtk_widget_get_state_flags (widget);
5946 gtk_style_context_get_background_color (context, state, &color);
5948 gdk_cairo_rectangle (cr, &rect);
5950 cairo_move_to (cr, x, y);
5951 gdk_cairo_set_source_rgba (cr, &color);
5952 pango_cairo_show_layout (cr, layout);
5960 _gtk_entry_reset_im_context (GtkEntry *entry)
5962 GtkEntryPrivate *priv = entry->priv;
5964 if (priv->need_im_reset)
5966 priv->need_im_reset = FALSE;
5967 gtk_im_context_reset (priv->im_context);
5972 * gtk_entry_reset_im_context:
5973 * @entry: a #GtkEntry
5975 * Reset the input method context of the entry if needed.
5977 * This can be necessary in the case where modifying the buffer
5978 * would confuse on-going input method behavior.
5983 gtk_entry_reset_im_context (GtkEntry *entry)
5985 g_return_if_fail (GTK_IS_ENTRY (entry));
5987 _gtk_entry_reset_im_context (entry);
5991 * gtk_entry_im_context_filter_keypress:
5992 * @entry: a #GtkEntry
5993 * @event: (type Gdk.EventKey): the key event
5995 * Allow the #GtkEntry input method to internally handle key press
5996 * and release events. If this function returns %TRUE, then no further
5997 * processing should be done for this key event. See
5998 * gtk_im_context_filter_keypress().
6000 * Note that you are expected to call this function from your handler
6001 * when overriding key event handling. This is needed in the case when
6002 * you need to insert your own key handling between the input method
6003 * and the default key event handling of the #GtkEntry.
6004 * See gtk_text_view_reset_im_context() for an example of use.
6006 * Return value: %TRUE if the input method handled the key event.
6011 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6014 GtkEntryPrivate *priv;
6016 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6020 return gtk_im_context_filter_keypress (priv->im_context, event);
6024 _gtk_entry_get_im_context (GtkEntry *entry)
6026 return entry->priv->im_context;
6030 gtk_entry_find_position (GtkEntry *entry,
6033 GtkEntryPrivate *priv = entry->priv;
6034 PangoLayout *layout;
6035 PangoLayoutLine *line;
6042 layout = gtk_entry_ensure_layout (entry, TRUE);
6043 text = pango_layout_get_text (layout);
6044 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6046 line = pango_layout_get_lines_readonly (layout)->data;
6047 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6049 if (index >= cursor_index && priv->preedit_length)
6051 if (index >= cursor_index + priv->preedit_length)
6052 index -= priv->preedit_length;
6055 index = cursor_index;
6060 pos = g_utf8_pointer_to_offset (text, text + index);
6067 gtk_entry_get_cursor_locations (GtkEntry *entry,
6072 GtkEntryPrivate *priv = entry->priv;
6073 DisplayMode mode = gtk_entry_get_display_mode (entry);
6075 /* Nothing to display at all, so no cursor is relevant */
6076 if (mode == DISPLAY_BLANK)
6086 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6087 const gchar *text = pango_layout_get_text (layout);
6088 PangoRectangle strong_pos, weak_pos;
6091 if (type == CURSOR_STANDARD)
6093 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6095 else /* type == CURSOR_DND */
6097 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6099 if (priv->dnd_position > priv->current_pos)
6101 if (mode == DISPLAY_NORMAL)
6102 index += priv->preedit_length;
6105 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6106 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6111 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6114 *strong_x = strong_pos.x / PANGO_SCALE;
6117 *weak_x = weak_pos.x / PANGO_SCALE;
6122 gtk_entry_adjust_scroll (GtkEntry *entry)
6124 GtkEntryPrivate *priv = entry->priv;
6125 gint min_offset, max_offset;
6126 gint text_area_width, text_width;
6127 gint strong_x, weak_x;
6128 gint strong_xoffset, weak_xoffset;
6130 PangoLayout *layout;
6131 PangoLayoutLine *line;
6132 PangoRectangle logical_rect;
6134 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6137 text_area_width = gdk_window_get_width (priv->text_area);
6139 if (text_area_width < 0)
6140 text_area_width = 0;
6142 layout = gtk_entry_ensure_layout (entry, TRUE);
6143 line = pango_layout_get_lines_readonly (layout)->data;
6145 pango_layout_line_get_extents (line, NULL, &logical_rect);
6147 /* Display as much text as we can */
6149 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6150 xalign = priv->xalign;
6152 xalign = 1.0 - priv->xalign;
6154 text_width = PANGO_PIXELS(logical_rect.width);
6156 if (text_width > text_area_width)
6159 max_offset = text_width - text_area_width;
6163 min_offset = (text_width - text_area_width) * xalign;
6164 max_offset = min_offset;
6167 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6169 /* And make sure cursors are on screen. Note that the cursor is
6170 * actually drawn one pixel into the INNER_BORDER space on
6171 * the right, when the scroll is at the utmost right. This
6172 * looks better to to me than confining the cursor inside the
6173 * border entirely, though it means that the cursor gets one
6174 * pixel closer to the edge of the widget on the right than
6175 * on the left. This might need changing if one changed
6176 * INNER_BORDER from 2 to 1, as one would do on a
6177 * small-screen-real-estate display.
6179 * We always make sure that the strong cursor is on screen, and
6180 * put the weak cursor on screen if possible.
6183 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6185 strong_xoffset = strong_x - priv->scroll_offset;
6187 if (strong_xoffset < 0)
6189 priv->scroll_offset += strong_xoffset;
6192 else if (strong_xoffset > text_area_width)
6194 priv->scroll_offset += strong_xoffset - text_area_width;
6195 strong_xoffset = text_area_width;
6198 weak_xoffset = weak_x - priv->scroll_offset;
6200 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6202 priv->scroll_offset += weak_xoffset;
6204 else if (weak_xoffset > text_area_width &&
6205 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6207 priv->scroll_offset += weak_xoffset - text_area_width;
6210 g_object_notify (G_OBJECT (entry), "scroll-offset");
6214 gtk_entry_move_adjustments (GtkEntry *entry)
6216 GtkWidget *widget = GTK_WIDGET (entry);
6217 GtkAllocation allocation;
6218 GtkAdjustment *adjustment;
6219 PangoContext *context;
6220 PangoFontMetrics *metrics;
6221 GtkStyleContext *style_context;
6222 GtkStateFlags state;
6227 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6231 gtk_widget_get_allocation (widget, &allocation);
6233 /* Cursor position, layout offset, border width, and widget allocation */
6234 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6235 get_layout_position (entry, &layout_x, NULL);
6236 _gtk_entry_get_borders (entry, &borders);
6237 x += allocation.x + layout_x + borders.left;
6239 /* Approximate width of a char, so user can see what is ahead/behind */
6240 context = gtk_widget_get_pango_context (widget);
6241 style_context = gtk_widget_get_style_context (widget);
6242 state = gtk_widget_get_state_flags (widget);
6244 metrics = pango_context_get_metrics (context,
6245 gtk_style_context_get_font (style_context, state),
6246 pango_context_get_language (context));
6247 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6250 gtk_adjustment_clamp_page (adjustment,
6251 x - (char_width + 1), /* one char + one pixel before */
6252 x + (char_width + 2)); /* one char + cursor + one pixel after */
6256 gtk_entry_move_visually (GtkEntry *entry,
6260 GtkEntryPrivate *priv = entry->priv;
6262 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6265 text = pango_layout_get_text (layout);
6267 index = g_utf8_offset_to_pointer (text, start) - text;
6271 int new_index, new_trailing;
6272 gboolean split_cursor;
6275 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6276 "gtk-split-cursor", &split_cursor,
6283 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6284 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6286 strong = keymap_direction == priv->resolved_dir;
6291 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6296 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6302 else if (new_index != G_MAXINT)
6305 while (new_trailing--)
6306 index = g_utf8_next_char (text + index) - text;
6309 return g_utf8_pointer_to_offset (text, text + index);
6313 gtk_entry_move_logically (GtkEntry *entry,
6317 gint new_pos = start;
6320 length = gtk_entry_buffer_get_length (get_buffer (entry));
6322 /* Prevent any leak of information */
6323 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6325 new_pos = CLAMP (start + count, 0, length);
6329 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6330 PangoLogAttr *log_attrs;
6333 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6335 while (count > 0 && new_pos < length)
6339 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6343 while (count < 0 && new_pos > 0)
6347 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6359 gtk_entry_move_forward_word (GtkEntry *entry,
6361 gboolean allow_whitespace)
6363 gint new_pos = start;
6366 length = gtk_entry_buffer_get_length (get_buffer (entry));
6368 /* Prevent any leak of information */
6369 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6373 else if (new_pos < length)
6375 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6376 PangoLogAttr *log_attrs;
6379 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6381 /* Find the next word boundary */
6383 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6384 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6395 gtk_entry_move_backward_word (GtkEntry *entry,
6397 gboolean allow_whitespace)
6399 gint new_pos = start;
6401 /* Prevent any leak of information */
6402 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6408 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6409 PangoLogAttr *log_attrs;
6412 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6414 new_pos = start - 1;
6416 /* Find the previous word boundary */
6417 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6418 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6428 gtk_entry_delete_whitespace (GtkEntry *entry)
6430 GtkEntryPrivate *priv = entry->priv;
6431 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6432 PangoLogAttr *log_attrs;
6436 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6438 start = end = priv->current_pos;
6440 while (start > 0 && log_attrs[start-1].is_white)
6443 while (end < n_attrs && log_attrs[end].is_white)
6449 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6454 gtk_entry_select_word (GtkEntry *entry)
6456 GtkEntryPrivate *priv = entry->priv;
6457 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6458 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6460 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6464 gtk_entry_select_line (GtkEntry *entry)
6466 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6470 truncate_multiline (const gchar *text)
6475 text[length] && text[length] != '\n' && text[length] != '\r';
6482 paste_received (GtkClipboard *clipboard,
6486 GtkEntry *entry = GTK_ENTRY (data);
6487 GtkEditable *editable = GTK_EDITABLE (entry);
6488 GtkEntryPrivate *priv = entry->priv;
6490 if (priv->button == GDK_BUTTON_MIDDLE)
6492 gint pos, start, end;
6493 pos = priv->insert_pos;
6494 gtk_editable_get_selection_bounds (editable, &start, &end);
6495 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6496 gtk_editable_select_region (editable, pos, pos);
6501 gint pos, start, end;
6503 gboolean popup_completion;
6504 GtkEntryCompletion *completion;
6506 completion = gtk_entry_get_completion (entry);
6508 if (priv->truncate_multiline)
6509 length = truncate_multiline (text);
6511 /* only complete if the selection is at the end */
6512 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6513 MAX (priv->current_pos, priv->selection_bound));
6517 if (gtk_widget_get_mapped (completion->priv->popup_window))
6518 _gtk_entry_completion_popdown (completion);
6520 if (!popup_completion && completion->priv->changed_id > 0)
6521 g_signal_handler_block (entry, completion->priv->changed_id);
6524 begin_change (entry);
6525 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6526 gtk_editable_delete_text (editable, start, end);
6528 pos = priv->current_pos;
6529 gtk_editable_insert_text (editable, text, length, &pos);
6530 gtk_editable_set_position (editable, pos);
6534 !popup_completion && completion->priv->changed_id > 0)
6535 g_signal_handler_unblock (entry, completion->priv->changed_id);
6538 g_object_unref (entry);
6542 gtk_entry_paste (GtkEntry *entry,
6545 g_object_ref (entry);
6546 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6547 paste_received, entry);
6551 primary_get_cb (GtkClipboard *clipboard,
6552 GtkSelectionData *selection_data,
6556 GtkEntry *entry = GTK_ENTRY (data);
6559 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6561 gchar *str = gtk_entry_get_display_text (entry, start, end);
6562 gtk_selection_data_set_text (selection_data, str, -1);
6568 primary_clear_cb (GtkClipboard *clipboard,
6571 GtkEntry *entry = GTK_ENTRY (data);
6572 GtkEntryPrivate *priv = entry->priv;
6574 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6578 gtk_entry_update_primary_selection (GtkEntry *entry)
6580 GtkTargetList *list;
6581 GtkTargetEntry *targets;
6582 GtkClipboard *clipboard;
6586 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6589 list = gtk_target_list_new (NULL, 0);
6590 gtk_target_list_add_text_targets (list, 0);
6592 targets = gtk_target_table_new_from_list (list, &n_targets);
6594 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6596 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6598 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6599 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6600 primary_clear_cb (clipboard, entry);
6604 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6605 gtk_clipboard_clear (clipboard);
6608 gtk_target_table_free (targets, n_targets);
6609 gtk_target_list_unref (list);
6613 gtk_entry_clear (GtkEntry *entry,
6614 GtkEntryIconPosition icon_pos)
6616 GtkEntryPrivate *priv = entry->priv;
6617 EntryIconInfo *icon_info = priv->icons[icon_pos];
6618 GtkImageType storage_type;
6620 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6623 g_object_freeze_notify (G_OBJECT (entry));
6625 /* Explicitly check, as the pointer may become invalidated
6626 * during destruction.
6628 if (GDK_IS_WINDOW (icon_info->window))
6629 gdk_window_hide (icon_info->window);
6631 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6633 switch (storage_type)
6635 case GTK_IMAGE_PIXBUF:
6636 g_object_notify (G_OBJECT (entry),
6637 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6640 case GTK_IMAGE_STOCK:
6641 g_object_notify (G_OBJECT (entry),
6642 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6645 case GTK_IMAGE_ICON_NAME:
6646 g_object_notify (G_OBJECT (entry),
6647 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6650 case GTK_IMAGE_GICON:
6651 g_object_notify (G_OBJECT (entry),
6652 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6656 g_assert_not_reached ();
6660 _gtk_icon_helper_clear (icon_info->icon_helper);
6662 g_object_notify (G_OBJECT (entry),
6663 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6665 g_object_thaw_notify (G_OBJECT (entry));
6669 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6670 GtkEntryIconPosition icon_pos)
6672 GtkEntryPrivate *priv = entry->priv;
6673 EntryIconInfo *icon_info = priv->icons[icon_pos];
6674 GtkStyleContext *context;
6677 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6678 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6680 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6683 gtk_style_context_restore (context);
6694 * Creates a new entry.
6696 * Return value: a new #GtkEntry.
6699 gtk_entry_new (void)
6701 return g_object_new (GTK_TYPE_ENTRY, NULL);
6705 * gtk_entry_new_with_buffer:
6706 * @buffer: The buffer to use for the new #GtkEntry.
6708 * Creates a new entry with the specified text buffer.
6710 * Return value: a new #GtkEntry
6715 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6717 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6718 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6721 static GtkEntryBuffer*
6722 get_buffer (GtkEntry *entry)
6724 GtkEntryPrivate *priv = entry->priv;
6726 if (priv->buffer == NULL)
6728 GtkEntryBuffer *buffer;
6729 buffer = gtk_entry_buffer_new (NULL, 0);
6730 gtk_entry_set_buffer (entry, buffer);
6731 g_object_unref (buffer);
6734 return priv->buffer;
6738 * gtk_entry_get_buffer:
6739 * @entry: a #GtkEntry
6741 * Get the #GtkEntryBuffer object which holds the text for
6746 * Returns: (transfer none): A #GtkEntryBuffer object.
6749 gtk_entry_get_buffer (GtkEntry *entry)
6751 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6753 return get_buffer (entry);
6757 * gtk_entry_set_buffer:
6758 * @entry: a #GtkEntry
6759 * @buffer: a #GtkEntryBuffer
6761 * Set the #GtkEntryBuffer object which holds the text for
6767 gtk_entry_set_buffer (GtkEntry *entry,
6768 GtkEntryBuffer *buffer)
6770 GtkEntryPrivate *priv;
6773 g_return_if_fail (GTK_IS_ENTRY (entry));
6779 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6780 g_object_ref (buffer);
6785 buffer_disconnect_signals (entry);
6786 g_object_unref (priv->buffer);
6789 priv->buffer = buffer;
6792 buffer_connect_signals (entry);
6794 obj = G_OBJECT (entry);
6795 g_object_freeze_notify (obj);
6796 g_object_notify (obj, "buffer");
6797 g_object_notify (obj, "text");
6798 g_object_notify (obj, "text-length");
6799 g_object_notify (obj, "max-length");
6800 g_object_notify (obj, "visibility");
6801 g_object_notify (obj, "invisible-char");
6802 g_object_notify (obj, "invisible-char-set");
6803 g_object_thaw_notify (obj);
6805 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6806 gtk_entry_recompute (entry);
6810 * gtk_entry_get_text_area:
6811 * @entry: a #GtkEntry
6812 * @text_area: (out): Return location for the text area.
6814 * Gets the area where the entry's text is drawn. This function is
6815 * useful when drawing something to the entry in a draw callback.
6817 * If the entry is not realized, @text_area is filled with zeros.
6819 * See also gtk_entry_get_icon_area().
6824 gtk_entry_get_text_area (GtkEntry *entry,
6825 GdkRectangle *text_area)
6827 GtkEntryPrivate *priv;
6829 g_return_if_fail (GTK_IS_ENTRY (entry));
6830 g_return_if_fail (text_area != NULL);
6834 if (priv->text_area)
6836 GtkAllocation allocation;
6839 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6840 gdk_window_get_position (priv->text_area, &x, &y);
6842 text_area->x = x - allocation.x;
6843 text_area->y = y - allocation.y;
6844 text_area->width = gdk_window_get_width (priv->text_area);
6845 text_area->height = gdk_window_get_height (priv->text_area);
6851 text_area->width = 0;
6852 text_area->height = 0;
6857 * gtk_entry_set_text:
6858 * @entry: a #GtkEntry
6859 * @text: the new text
6861 * Sets the text in the widget to the given
6862 * value, replacing the current contents.
6864 * See gtk_entry_buffer_set_text().
6867 gtk_entry_set_text (GtkEntry *entry,
6871 GtkEntryCompletion *completion;
6873 g_return_if_fail (GTK_IS_ENTRY (entry));
6874 g_return_if_fail (text != NULL);
6876 /* Actually setting the text will affect the cursor and selection;
6877 * if the contents don't actually change, this will look odd to the user.
6879 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6882 completion = gtk_entry_get_completion (entry);
6883 if (completion && completion->priv->changed_id > 0)
6884 g_signal_handler_block (entry, completion->priv->changed_id);
6886 begin_change (entry);
6887 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6889 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6892 if (completion && completion->priv->changed_id > 0)
6893 g_signal_handler_unblock (entry, completion->priv->changed_id);
6897 * gtk_entry_set_visibility:
6898 * @entry: a #GtkEntry
6899 * @visible: %TRUE if the contents of the entry are displayed
6902 * Sets whether the contents of the entry are visible or not.
6903 * When visibility is set to %FALSE, characters are displayed
6904 * as the invisible char, and will also appear that way when
6905 * the text in the entry widget is copied elsewhere.
6907 * By default, GTK+ picks the best invisible character available
6908 * in the current font, but it can be changed with
6909 * gtk_entry_set_invisible_char().
6912 gtk_entry_set_visibility (GtkEntry *entry,
6915 GtkEntryPrivate *priv;
6917 g_return_if_fail (GTK_IS_ENTRY (entry));
6921 visible = visible != FALSE;
6923 if (priv->visible != visible)
6925 priv->visible = visible;
6927 g_object_notify (G_OBJECT (entry), "visibility");
6928 gtk_entry_recompute (entry);
6933 * gtk_entry_get_visibility:
6934 * @entry: a #GtkEntry
6936 * Retrieves whether the text in @entry is visible. See
6937 * gtk_entry_set_visibility().
6939 * Return value: %TRUE if the text is currently visible
6942 gtk_entry_get_visibility (GtkEntry *entry)
6944 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6946 return entry->priv->visible;
6950 * gtk_entry_set_invisible_char:
6951 * @entry: a #GtkEntry
6952 * @ch: a Unicode character
6954 * Sets the character to use in place of the actual text when
6955 * gtk_entry_set_visibility() has been called to set text visibility
6956 * to %FALSE. i.e. this is the character used in "password mode" to
6957 * show the user how many characters have been typed. By default, GTK+
6958 * picks the best invisible char available in the current font. If you
6959 * set the invisible char to 0, then the user will get no feedback
6960 * at all; there will be no text on the screen as they type.
6963 gtk_entry_set_invisible_char (GtkEntry *entry,
6966 GtkEntryPrivate *priv;
6968 g_return_if_fail (GTK_IS_ENTRY (entry));
6972 if (!priv->invisible_char_set)
6974 priv->invisible_char_set = TRUE;
6975 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6978 if (ch == priv->invisible_char)
6981 priv->invisible_char = ch;
6982 g_object_notify (G_OBJECT (entry), "invisible-char");
6983 gtk_entry_recompute (entry);
6987 * gtk_entry_get_invisible_char:
6988 * @entry: a #GtkEntry
6990 * Retrieves the character displayed in place of the real characters
6991 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6993 * Return value: the current invisible char, or 0, if the entry does not
6994 * show invisible text at all.
6997 gtk_entry_get_invisible_char (GtkEntry *entry)
6999 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7001 return entry->priv->invisible_char;
7005 * gtk_entry_unset_invisible_char:
7006 * @entry: a #GtkEntry
7008 * Unsets the invisible char previously set with
7009 * gtk_entry_set_invisible_char(). So that the
7010 * default invisible char is used again.
7015 gtk_entry_unset_invisible_char (GtkEntry *entry)
7017 GtkEntryPrivate *priv;
7020 g_return_if_fail (GTK_IS_ENTRY (entry));
7024 if (!priv->invisible_char_set)
7027 priv->invisible_char_set = FALSE;
7028 ch = find_invisible_char (GTK_WIDGET (entry));
7030 if (priv->invisible_char != ch)
7032 priv->invisible_char = ch;
7033 g_object_notify (G_OBJECT (entry), "invisible-char");
7036 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7037 gtk_entry_recompute (entry);
7041 * gtk_entry_set_overwrite_mode:
7042 * @entry: a #GtkEntry
7043 * @overwrite: new value
7045 * Sets whether the text is overwritten when typing in the #GtkEntry.
7050 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7053 GtkEntryPrivate *priv = entry->priv;
7055 g_return_if_fail (GTK_IS_ENTRY (entry));
7057 if (priv->overwrite_mode == overwrite)
7060 gtk_entry_toggle_overwrite (entry);
7062 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7066 * gtk_entry_get_overwrite_mode:
7067 * @entry: a #GtkEntry
7069 * Gets the value set by gtk_entry_set_overwrite_mode().
7071 * Return value: whether the text is overwritten when typing.
7076 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7078 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7080 return entry->priv->overwrite_mode;
7084 * gtk_entry_get_text:
7085 * @entry: a #GtkEntry
7087 * Retrieves the contents of the entry widget.
7088 * See also gtk_editable_get_chars().
7090 * This is equivalent to:
7092 * <informalexample><programlisting>
7093 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7094 * </programlisting></informalexample>
7096 * Return value: a pointer to the contents of the widget as a
7097 * string. This string points to internally allocated
7098 * storage in the widget and must not be freed, modified or
7102 gtk_entry_get_text (GtkEntry *entry)
7104 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7106 return gtk_entry_buffer_get_text (get_buffer (entry));
7110 * gtk_entry_set_max_length:
7111 * @entry: a #GtkEntry
7112 * @max: the maximum length of the entry, or 0 for no maximum.
7113 * (other than the maximum length of entries.) The value passed in will
7114 * be clamped to the range 0-65536.
7116 * Sets the maximum allowed length of the contents of the widget. If
7117 * the current contents are longer than the given length, then they
7118 * will be truncated to fit.
7120 * This is equivalent to:
7122 * <informalexample><programlisting>
7123 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7124 * </programlisting></informalexample>
7127 gtk_entry_set_max_length (GtkEntry *entry,
7130 g_return_if_fail (GTK_IS_ENTRY (entry));
7131 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7135 * gtk_entry_get_max_length:
7136 * @entry: a #GtkEntry
7138 * Retrieves the maximum allowed length of the text in
7139 * @entry. See gtk_entry_set_max_length().
7141 * This is equivalent to:
7143 * <informalexample><programlisting>
7144 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7145 * </programlisting></informalexample>
7147 * Return value: the maximum allowed number of characters
7148 * in #GtkEntry, or 0 if there is no maximum.
7151 gtk_entry_get_max_length (GtkEntry *entry)
7153 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7155 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7159 * gtk_entry_get_text_length:
7160 * @entry: a #GtkEntry
7162 * Retrieves the current length of the text in
7165 * This is equivalent to:
7167 * <informalexample><programlisting>
7168 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7169 * </programlisting></informalexample>
7171 * Return value: the current number of characters
7172 * in #GtkEntry, or 0 if there are none.
7177 gtk_entry_get_text_length (GtkEntry *entry)
7179 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7181 return gtk_entry_buffer_get_length (get_buffer (entry));
7185 * gtk_entry_set_activates_default:
7186 * @entry: a #GtkEntry
7187 * @setting: %TRUE to activate window's default widget on Enter keypress
7189 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7190 * widget for the window containing the entry. This usually means that
7191 * the dialog box containing the entry will be closed, since the default
7192 * widget is usually one of the dialog buttons.
7194 * (For experts: if @setting is %TRUE, the entry calls
7195 * gtk_window_activate_default() on the window containing the entry, in
7196 * the default handler for the #GtkWidget::activate signal.)
7199 gtk_entry_set_activates_default (GtkEntry *entry,
7202 GtkEntryPrivate *priv;
7204 g_return_if_fail (GTK_IS_ENTRY (entry));
7208 setting = setting != FALSE;
7210 if (setting != priv->activates_default)
7212 priv->activates_default = setting;
7213 g_object_notify (G_OBJECT (entry), "activates-default");
7218 * gtk_entry_get_activates_default:
7219 * @entry: a #GtkEntry
7221 * Retrieves the value set by gtk_entry_set_activates_default().
7223 * Return value: %TRUE if the entry will activate the default widget
7226 gtk_entry_get_activates_default (GtkEntry *entry)
7228 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7230 return entry->priv->activates_default;
7234 * gtk_entry_set_width_chars:
7235 * @entry: a #GtkEntry
7236 * @n_chars: width in chars
7238 * Changes the size request of the entry to be about the right size
7239 * for @n_chars characters. Note that it changes the size
7240 * <emphasis>request</emphasis>, the size can still be affected by
7241 * how you pack the widget into containers. If @n_chars is -1, the
7242 * size reverts to the default entry size.
7245 gtk_entry_set_width_chars (GtkEntry *entry,
7248 GtkEntryPrivate *priv;
7250 g_return_if_fail (GTK_IS_ENTRY (entry));
7254 if (priv->width_chars != n_chars)
7256 priv->width_chars = n_chars;
7257 g_object_notify (G_OBJECT (entry), "width-chars");
7258 gtk_widget_queue_resize (GTK_WIDGET (entry));
7263 * gtk_entry_get_width_chars:
7264 * @entry: a #GtkEntry
7266 * Gets the value set by gtk_entry_set_width_chars().
7268 * Return value: number of chars to request space for, or negative if unset
7271 gtk_entry_get_width_chars (GtkEntry *entry)
7273 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7275 return entry->priv->width_chars;
7279 * gtk_entry_set_has_frame:
7280 * @entry: a #GtkEntry
7281 * @setting: new value
7283 * Sets whether the entry has a beveled frame around it.
7286 gtk_entry_set_has_frame (GtkEntry *entry,
7289 GtkEntryPrivate *priv;
7291 g_return_if_fail (GTK_IS_ENTRY (entry));
7295 setting = (setting != FALSE);
7297 if (priv->has_frame == setting)
7300 gtk_widget_queue_resize (GTK_WIDGET (entry));
7301 priv->has_frame = setting;
7302 g_object_notify (G_OBJECT (entry), "has-frame");
7306 * gtk_entry_get_has_frame:
7307 * @entry: a #GtkEntry
7309 * Gets the value set by gtk_entry_set_has_frame().
7311 * Return value: whether the entry has a beveled frame
7314 gtk_entry_get_has_frame (GtkEntry *entry)
7316 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7318 return entry->priv->has_frame;
7322 * gtk_entry_set_inner_border:
7323 * @entry: a #GtkEntry
7324 * @border: (allow-none): a #GtkBorder, or %NULL
7326 * Sets %entry's inner-border property to %border, or clears it if %NULL
7327 * is passed. The inner-border is the area around the entry's text, but
7330 * If set, this property overrides the inner-border style property.
7331 * Overriding the style-provided border is useful when you want to do
7332 * in-place editing of some text in a canvas or list widget, where
7333 * pixel-exact positioning of the entry is important.
7337 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7338 * the value set with this function is ignored by #GtkEntry.
7341 gtk_entry_set_inner_border (GtkEntry *entry,
7342 const GtkBorder *border)
7344 g_return_if_fail (GTK_IS_ENTRY (entry));
7346 gtk_entry_do_set_inner_border (entry, border);
7350 * gtk_entry_get_inner_border:
7351 * @entry: a #GtkEntry
7353 * This function returns the entry's #GtkEntry:inner-border property. See
7354 * gtk_entry_set_inner_border() for more information.
7356 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7360 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7361 * the value returned by this function is ignored by #GtkEntry.
7364 gtk_entry_get_inner_border (GtkEntry *entry)
7366 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7368 return gtk_entry_do_get_inner_border (entry);
7372 * gtk_entry_get_layout:
7373 * @entry: a #GtkEntry
7375 * Gets the #PangoLayout used to display the entry.
7376 * The layout is useful to e.g. convert text positions to
7377 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7378 * The returned layout is owned by the entry and must not be
7379 * modified or freed by the caller.
7381 * Keep in mind that the layout text may contain a preedit string, so
7382 * gtk_entry_layout_index_to_text_index() and
7383 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7384 * indices in the layout to byte indices in the entry contents.
7386 * Return value: (transfer none): the #PangoLayout for this entry
7389 gtk_entry_get_layout (GtkEntry *entry)
7391 PangoLayout *layout;
7393 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7395 layout = gtk_entry_ensure_layout (entry, TRUE);
7402 * gtk_entry_layout_index_to_text_index:
7403 * @entry: a #GtkEntry
7404 * @layout_index: byte index into the entry layout text
7406 * Converts from a position in the entry contents (returned
7407 * by gtk_entry_get_text()) to a position in the
7408 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7409 * with text retrieved via pango_layout_get_text()).
7411 * Return value: byte index into the entry contents
7414 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7417 GtkEntryPrivate *priv;
7418 PangoLayout *layout;
7422 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7426 layout = gtk_entry_ensure_layout (entry, TRUE);
7427 text = pango_layout_get_text (layout);
7428 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7430 if (layout_index >= cursor_index && priv->preedit_length)
7432 if (layout_index >= cursor_index + priv->preedit_length)
7433 layout_index -= priv->preedit_length;
7435 layout_index = cursor_index;
7438 return layout_index;
7442 * gtk_entry_text_index_to_layout_index:
7443 * @entry: a #GtkEntry
7444 * @text_index: byte index into the entry contents
7446 * Converts from a position in the entry's #PangoLayout (returned by
7447 * gtk_entry_get_layout()) to a position in the entry contents
7448 * (returned by gtk_entry_get_text()).
7450 * Return value: byte index into the entry layout text
7453 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7456 GtkEntryPrivate *priv;
7457 PangoLayout *layout;
7461 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7465 layout = gtk_entry_ensure_layout (entry, TRUE);
7466 text = pango_layout_get_text (layout);
7467 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7469 if (text_index > cursor_index)
7470 text_index += priv->preedit_length;
7476 * gtk_entry_get_layout_offsets:
7477 * @entry: a #GtkEntry
7478 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7479 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7482 * Obtains the position of the #PangoLayout used to render text
7483 * in the entry, in widget coordinates. Useful if you want to line
7484 * up the text in an entry with some other text, e.g. when using the
7485 * entry to implement editable cells in a sheet widget.
7487 * Also useful to convert mouse events into coordinates inside the
7488 * #PangoLayout, e.g. to take some action if some part of the entry text
7491 * Note that as the user scrolls around in the entry the offsets will
7492 * change; you'll need to connect to the "notify::scroll-offset"
7493 * signal to track this. Remember when using the #PangoLayout
7494 * functions you need to convert to and from pixels using
7495 * PANGO_PIXELS() or #PANGO_SCALE.
7497 * Keep in mind that the layout text may contain a preedit string, so
7498 * gtk_entry_layout_index_to_text_index() and
7499 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7500 * indices in the layout to byte indices in the entry contents.
7503 gtk_entry_get_layout_offsets (GtkEntry *entry,
7507 gint text_area_x, text_area_y;
7509 g_return_if_fail (GTK_IS_ENTRY (entry));
7511 /* this gets coords relative to text area */
7512 get_layout_position (entry, x, y);
7514 /* convert to widget coords */
7515 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7526 * gtk_entry_set_alignment:
7527 * @entry: a #GtkEntry
7528 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7529 * Reversed for RTL layouts
7531 * Sets the alignment for the contents of the entry. This controls
7532 * the horizontal positioning of the contents when the displayed
7533 * text is shorter than the width of the entry.
7538 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7540 GtkEntryPrivate *priv;
7542 g_return_if_fail (GTK_IS_ENTRY (entry));
7548 else if (xalign > 1.0)
7551 if (xalign != priv->xalign)
7553 priv->xalign = xalign;
7555 gtk_entry_recompute (entry);
7557 g_object_notify (G_OBJECT (entry), "xalign");
7562 * gtk_entry_get_alignment:
7563 * @entry: a #GtkEntry
7565 * Gets the value set by gtk_entry_set_alignment().
7567 * Return value: the alignment
7572 gtk_entry_get_alignment (GtkEntry *entry)
7574 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7576 return entry->priv->xalign;
7580 * gtk_entry_set_icon_from_pixbuf:
7581 * @entry: a #GtkEntry
7582 * @icon_pos: Icon position
7583 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7585 * Sets the icon shown in the specified position using a pixbuf.
7587 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7592 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7593 GtkEntryIconPosition icon_pos,
7596 GtkEntryPrivate *priv;
7597 EntryIconInfo *icon_info;
7599 g_return_if_fail (GTK_IS_ENTRY (entry));
7600 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7604 if ((icon_info = priv->icons[icon_pos]) == NULL)
7605 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7607 g_object_freeze_notify (G_OBJECT (entry));
7610 g_object_ref (pixbuf);
7612 gtk_entry_clear (entry, icon_pos);
7616 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7618 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7620 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7621 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7625 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7626 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7629 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7630 gdk_window_show_unraised (icon_info->window);
7632 g_object_unref (pixbuf);
7635 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7636 gtk_widget_queue_resize (GTK_WIDGET (entry));
7638 g_object_thaw_notify (G_OBJECT (entry));
7642 * gtk_entry_set_icon_from_stock:
7643 * @entry: A #GtkEntry
7644 * @icon_pos: Icon position
7645 * @stock_id: (allow-none): The name of the stock item, or %NULL
7647 * Sets the icon shown in the entry at the specified position from
7650 * If @stock_id is %NULL, no icon will be shown in the specified position.
7655 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7656 GtkEntryIconPosition icon_pos,
7657 const gchar *stock_id)
7659 GtkEntryPrivate *priv;
7660 EntryIconInfo *icon_info;
7663 g_return_if_fail (GTK_IS_ENTRY (entry));
7664 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7668 if ((icon_info = priv->icons[icon_pos]) == NULL)
7669 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7671 g_object_freeze_notify (G_OBJECT (entry));
7673 /* need to dup before clearing */
7674 new_id = g_strdup (stock_id);
7676 gtk_entry_clear (entry, icon_pos);
7680 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7682 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7684 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7685 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7689 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7690 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7693 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7694 gdk_window_show_unraised (icon_info->window);
7699 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7700 gtk_widget_queue_resize (GTK_WIDGET (entry));
7702 g_object_thaw_notify (G_OBJECT (entry));
7706 * gtk_entry_set_icon_from_icon_name:
7707 * @entry: A #GtkEntry
7708 * @icon_pos: The position at which to set the icon
7709 * @icon_name: (allow-none): An icon name, or %NULL
7711 * Sets the icon shown in the entry at the specified position
7712 * from the current icon theme.
7714 * If the icon name isn't known, a "broken image" icon will be displayed
7717 * If @icon_name is %NULL, no icon will be shown in the specified position.
7722 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7723 GtkEntryIconPosition icon_pos,
7724 const gchar *icon_name)
7726 GtkEntryPrivate *priv;
7727 EntryIconInfo *icon_info;
7730 g_return_if_fail (GTK_IS_ENTRY (entry));
7731 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7735 if ((icon_info = priv->icons[icon_pos]) == NULL)
7736 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7738 g_object_freeze_notify (G_OBJECT (entry));
7740 /* need to dup before clearing */
7741 new_name = g_strdup (icon_name);
7743 gtk_entry_clear (entry, icon_pos);
7745 if (new_name != NULL)
7747 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7749 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7751 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7752 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7756 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7757 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7760 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7761 gdk_window_show_unraised (icon_info->window);
7766 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7767 gtk_widget_queue_resize (GTK_WIDGET (entry));
7769 g_object_thaw_notify (G_OBJECT (entry));
7773 * gtk_entry_set_icon_from_gicon:
7774 * @entry: A #GtkEntry
7775 * @icon_pos: The position at which to set the icon
7776 * @icon: (allow-none): The icon to set, or %NULL
7778 * Sets the icon shown in the entry at the specified position
7779 * from the current icon theme.
7780 * If the icon isn't known, a "broken image" icon will be displayed
7783 * If @icon is %NULL, no icon will be shown in the specified position.
7788 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7789 GtkEntryIconPosition icon_pos,
7792 GtkEntryPrivate *priv;
7793 EntryIconInfo *icon_info;
7795 g_return_if_fail (GTK_IS_ENTRY (entry));
7796 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7800 if ((icon_info = priv->icons[icon_pos]) == NULL)
7801 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7803 g_object_freeze_notify (G_OBJECT (entry));
7805 /* need to ref before clearing */
7807 g_object_ref (icon);
7809 gtk_entry_clear (entry, icon_pos);
7813 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7815 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7817 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7818 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7822 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7823 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7826 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7827 gdk_window_show_unraised (icon_info->window);
7829 g_object_unref (icon);
7832 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7833 gtk_widget_queue_resize (GTK_WIDGET (entry));
7835 g_object_thaw_notify (G_OBJECT (entry));
7839 * gtk_entry_set_icon_activatable:
7840 * @entry: A #GtkEntry
7841 * @icon_pos: Icon position
7842 * @activatable: %TRUE if the icon should be activatable
7844 * Sets whether the icon is activatable.
7849 gtk_entry_set_icon_activatable (GtkEntry *entry,
7850 GtkEntryIconPosition icon_pos,
7851 gboolean activatable)
7853 GtkEntryPrivate *priv;
7854 EntryIconInfo *icon_info;
7856 g_return_if_fail (GTK_IS_ENTRY (entry));
7857 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7861 if ((icon_info = priv->icons[icon_pos]) == NULL)
7862 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7864 activatable = activatable != FALSE;
7866 if (icon_info->nonactivatable != !activatable)
7868 icon_info->nonactivatable = !activatable;
7870 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7871 update_cursors (GTK_WIDGET (entry));
7873 g_object_notify (G_OBJECT (entry),
7874 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7879 * gtk_entry_get_icon_activatable:
7880 * @entry: a #GtkEntry
7881 * @icon_pos: Icon position
7883 * Returns whether the icon is activatable.
7885 * Returns: %TRUE if the icon is activatable.
7890 gtk_entry_get_icon_activatable (GtkEntry *entry,
7891 GtkEntryIconPosition icon_pos)
7893 GtkEntryPrivate *priv;
7894 EntryIconInfo *icon_info;
7896 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7897 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7900 icon_info = priv->icons[icon_pos];
7902 return (!icon_info || !icon_info->nonactivatable);
7906 * gtk_entry_get_icon_pixbuf:
7907 * @entry: A #GtkEntry
7908 * @icon_pos: Icon position
7910 * Retrieves the image used for the icon.
7912 * Unlike the other methods of setting and getting icon data, this
7913 * method will work regardless of whether the icon was set using a
7914 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7916 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7917 * set for this position.
7922 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7923 GtkEntryIconPosition icon_pos)
7925 GtkEntryPrivate *priv;
7926 EntryIconInfo *icon_info;
7929 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7930 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7934 icon_info = priv->icons[icon_pos];
7939 /* HACK: unfortunately this is transfer none, so we need to return
7940 * the icon helper's cache ref directly.
7942 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7943 g_object_unref (pixbuf);
7949 * gtk_entry_get_icon_gicon:
7950 * @entry: A #GtkEntry
7951 * @icon_pos: Icon position
7953 * Retrieves the #GIcon used for the icon, or %NULL if there is
7954 * no icon or if the icon was set by some other method (e.g., by
7955 * stock, pixbuf, or icon name).
7957 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7958 * or if the icon is not a #GIcon
7963 gtk_entry_get_icon_gicon (GtkEntry *entry,
7964 GtkEntryIconPosition icon_pos)
7966 GtkEntryPrivate *priv;
7967 EntryIconInfo *icon_info;
7969 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7970 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7973 icon_info = priv->icons[icon_pos];
7978 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7982 * gtk_entry_get_icon_stock:
7983 * @entry: A #GtkEntry
7984 * @icon_pos: Icon position
7986 * Retrieves the stock id used for the icon, or %NULL if there is
7987 * no icon or if the icon was set by some other method (e.g., by
7988 * pixbuf, icon name or gicon).
7990 * Returns: A stock id, or %NULL if no icon is set or if the icon
7991 * wasn't set from a stock id
7996 gtk_entry_get_icon_stock (GtkEntry *entry,
7997 GtkEntryIconPosition icon_pos)
7999 GtkEntryPrivate *priv;
8000 EntryIconInfo *icon_info;
8002 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8003 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8006 icon_info = priv->icons[icon_pos];
8011 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8015 * gtk_entry_get_icon_name:
8016 * @entry: A #GtkEntry
8017 * @icon_pos: Icon position
8019 * Retrieves the icon name used for the icon, or %NULL if there is
8020 * no icon or if the icon was set by some other method (e.g., by
8021 * pixbuf, stock or gicon).
8023 * Returns: An icon name, or %NULL if no icon is set or if the icon
8024 * wasn't set from an icon name
8029 gtk_entry_get_icon_name (GtkEntry *entry,
8030 GtkEntryIconPosition icon_pos)
8032 GtkEntryPrivate *priv;
8033 EntryIconInfo *icon_info;
8035 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8036 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8039 icon_info = priv->icons[icon_pos];
8044 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8048 * gtk_entry_set_icon_sensitive:
8049 * @entry: A #GtkEntry
8050 * @icon_pos: Icon position
8051 * @sensitive: Specifies whether the icon should appear
8052 * sensitive or insensitive
8054 * Sets the sensitivity for the specified icon.
8059 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8060 GtkEntryIconPosition icon_pos,
8063 GtkEntryPrivate *priv;
8064 EntryIconInfo *icon_info;
8066 g_return_if_fail (GTK_IS_ENTRY (entry));
8067 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8071 if ((icon_info = priv->icons[icon_pos]) == NULL)
8072 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8074 if (icon_info->insensitive != !sensitive)
8076 icon_info->insensitive = !sensitive;
8078 icon_info->pressed = FALSE;
8079 icon_info->prelight = FALSE;
8081 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8082 update_cursors (GTK_WIDGET (entry));
8084 gtk_widget_queue_draw (GTK_WIDGET (entry));
8086 g_object_notify (G_OBJECT (entry),
8087 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8092 * gtk_entry_get_icon_sensitive:
8093 * @entry: a #GtkEntry
8094 * @icon_pos: Icon position
8096 * Returns whether the icon appears sensitive or insensitive.
8098 * Returns: %TRUE if the icon is sensitive.
8103 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8104 GtkEntryIconPosition icon_pos)
8106 GtkEntryPrivate *priv;
8107 EntryIconInfo *icon_info;
8109 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8110 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8114 icon_info = priv->icons[icon_pos];
8116 return (!icon_info || !icon_info->insensitive);
8121 * gtk_entry_get_icon_storage_type:
8122 * @entry: a #GtkEntry
8123 * @icon_pos: Icon position
8125 * Gets the type of representation being used by the icon
8126 * to store image data. If the icon has no image data,
8127 * the return value will be %GTK_IMAGE_EMPTY.
8129 * Return value: image representation being used
8134 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8135 GtkEntryIconPosition icon_pos)
8137 GtkEntryPrivate *priv;
8138 EntryIconInfo *icon_info;
8140 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8141 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8145 icon_info = priv->icons[icon_pos];
8148 return GTK_IMAGE_EMPTY;
8150 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8154 * gtk_entry_get_icon_at_pos:
8155 * @entry: a #GtkEntry
8156 * @x: the x coordinate of the position to find
8157 * @y: the y coordinate of the position to find
8159 * Finds the icon at the given position and return its index. The
8160 * position's coordinates are relative to the @entry's top left corner.
8161 * If @x, @y doesn't lie inside an icon, -1 is returned.
8162 * This function is intended for use in a #GtkWidget::query-tooltip
8165 * Returns: the index of the icon at the given position, or -1
8170 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8174 GtkAllocation primary;
8175 GtkAllocation secondary;
8176 gint frame_x, frame_y;
8178 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8180 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8184 get_icon_allocations (entry, &primary, &secondary);
8186 if (primary.x <= x && x < primary.x + primary.width &&
8187 primary.y <= y && y < primary.y + primary.height)
8188 return GTK_ENTRY_ICON_PRIMARY;
8190 if (secondary.x <= x && x < secondary.x + secondary.width &&
8191 secondary.y <= y && y < secondary.y + secondary.height)
8192 return GTK_ENTRY_ICON_SECONDARY;
8198 * gtk_entry_set_icon_drag_source:
8199 * @entry: a #GtkIconEntry
8200 * @icon_pos: icon position
8201 * @target_list: the targets (data formats) in which the data can be provided
8202 * @actions: a bitmask of the allowed drag actions
8204 * Sets up the icon at the given position so that GTK+ will start a drag
8205 * operation when the user clicks and drags the icon.
8207 * To handle the drag operation, you need to connect to the usual
8208 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8209 * signal, and use gtk_entry_get_current_icon_drag_source() in
8210 * your signal handler to find out if the drag was started from
8213 * By default, GTK+ uses the icon as the drag icon. You can use the
8214 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8215 * have to use g_signal_connect_after() to ensure that your signal handler
8216 * gets executed after the default handler.
8221 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8222 GtkEntryIconPosition icon_pos,
8223 GtkTargetList *target_list,
8224 GdkDragAction actions)
8226 GtkEntryPrivate *priv;
8227 EntryIconInfo *icon_info;
8229 g_return_if_fail (GTK_IS_ENTRY (entry));
8230 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8234 if ((icon_info = priv->icons[icon_pos]) == NULL)
8235 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8237 if (icon_info->target_list)
8238 gtk_target_list_unref (icon_info->target_list);
8239 icon_info->target_list = target_list;
8240 if (icon_info->target_list)
8241 gtk_target_list_ref (icon_info->target_list);
8243 icon_info->actions = actions;
8247 * gtk_entry_get_current_icon_drag_source:
8248 * @entry: a #GtkIconEntry
8250 * Returns the index of the icon which is the source of the current
8251 * DND operation, or -1.
8253 * This function is meant to be used in a #GtkWidget::drag-data-get
8256 * Returns: index of the icon which is the source of the current
8257 * DND operation, or -1.
8262 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8264 GtkEntryPrivate *priv;
8265 EntryIconInfo *icon_info = NULL;
8268 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8272 for (i = 0; i < MAX_ICONS; i++)
8274 if ((icon_info = priv->icons[i]))
8276 if (icon_info->in_drag)
8285 * gtk_entry_get_icon_area:
8286 * @entry: A #GtkEntry
8287 * @icon_pos: Icon position
8288 * @icon_area: (out): Return location for the icon's area
8290 * Gets the area where entry's icon at @icon_pos is drawn.
8291 * This function is useful when drawing something to the
8292 * entry in a draw callback.
8294 * If the entry is not realized or has no icon at the given position,
8295 * @icon_area is filled with zeros.
8297 * See also gtk_entry_get_text_area()
8302 gtk_entry_get_icon_area (GtkEntry *entry,
8303 GtkEntryIconPosition icon_pos,
8304 GdkRectangle *icon_area)
8306 GtkEntryPrivate *priv;
8307 EntryIconInfo *icon_info;
8309 g_return_if_fail (GTK_IS_ENTRY (entry));
8310 g_return_if_fail (icon_area != NULL);
8314 icon_info = priv->icons[icon_pos];
8318 GtkAllocation primary;
8319 GtkAllocation secondary;
8321 get_icon_allocations (entry, &primary, &secondary);
8323 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8324 *icon_area = primary;
8326 *icon_area = secondary;
8332 icon_area->width = 0;
8333 icon_area->height = 0;
8338 ensure_has_tooltip (GtkEntry *entry)
8340 GtkEntryPrivate *priv;
8341 EntryIconInfo *icon_info;
8343 gboolean has_tooltip = FALSE;
8347 for (i = 0; i < MAX_ICONS; i++)
8349 if ((icon_info = priv->icons[i]) != NULL)
8351 if (icon_info->tooltip != NULL)
8359 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8363 * gtk_entry_get_icon_tooltip_text:
8364 * @entry: a #GtkEntry
8365 * @icon_pos: the icon position
8367 * Gets the contents of the tooltip on the icon at the specified
8368 * position in @entry.
8370 * Returns: the tooltip text, or %NULL. Free the returned string
8371 * with g_free() when done.
8376 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8377 GtkEntryIconPosition icon_pos)
8379 GtkEntryPrivate *priv;
8380 EntryIconInfo *icon_info;
8383 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8384 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8388 icon_info = priv->icons[icon_pos];
8393 if (icon_info->tooltip &&
8394 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8395 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8401 * gtk_entry_set_icon_tooltip_text:
8402 * @entry: a #GtkEntry
8403 * @icon_pos: the icon position
8404 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8406 * Sets @tooltip as the contents of the tooltip for the icon
8407 * at the specified position.
8409 * Use %NULL for @tooltip to remove an existing tooltip.
8411 * See also gtk_widget_set_tooltip_text() and
8412 * gtk_entry_set_icon_tooltip_markup().
8417 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8418 GtkEntryIconPosition icon_pos,
8419 const gchar *tooltip)
8421 GtkEntryPrivate *priv;
8422 EntryIconInfo *icon_info;
8424 g_return_if_fail (GTK_IS_ENTRY (entry));
8425 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8429 if ((icon_info = priv->icons[icon_pos]) == NULL)
8430 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8432 if (icon_info->tooltip)
8433 g_free (icon_info->tooltip);
8435 /* Treat an empty string as a NULL string,
8436 * because an empty string would be useless for a tooltip:
8438 if (tooltip && tooltip[0] == '\0')
8441 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8443 ensure_has_tooltip (entry);
8447 * gtk_entry_get_icon_tooltip_markup:
8448 * @entry: a #GtkEntry
8449 * @icon_pos: the icon position
8451 * Gets the contents of the tooltip on the icon at the specified
8452 * position in @entry.
8454 * Returns: the tooltip text, or %NULL. Free the returned string
8455 * with g_free() when done.
8460 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8461 GtkEntryIconPosition icon_pos)
8463 GtkEntryPrivate *priv;
8464 EntryIconInfo *icon_info;
8466 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8467 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8471 icon_info = priv->icons[icon_pos];
8476 return g_strdup (icon_info->tooltip);
8480 * gtk_entry_set_icon_tooltip_markup:
8481 * @entry: a #GtkEntry
8482 * @icon_pos: the icon position
8483 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8485 * Sets @tooltip as the contents of the tooltip for the icon at
8486 * the specified position. @tooltip is assumed to be marked up with
8487 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8489 * Use %NULL for @tooltip to remove an existing tooltip.
8491 * See also gtk_widget_set_tooltip_markup() and
8492 * gtk_enty_set_icon_tooltip_text().
8497 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8498 GtkEntryIconPosition icon_pos,
8499 const gchar *tooltip)
8501 GtkEntryPrivate *priv;
8502 EntryIconInfo *icon_info;
8504 g_return_if_fail (GTK_IS_ENTRY (entry));
8505 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8509 if ((icon_info = priv->icons[icon_pos]) == NULL)
8510 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8512 if (icon_info->tooltip)
8513 g_free (icon_info->tooltip);
8515 /* Treat an empty string as a NULL string,
8516 * because an empty string would be useless for a tooltip:
8518 if (tooltip && tooltip[0] == '\0')
8521 icon_info->tooltip = g_strdup (tooltip);
8523 ensure_has_tooltip (entry);
8527 gtk_entry_query_tooltip (GtkWidget *widget,
8530 gboolean keyboard_tip,
8531 GtkTooltip *tooltip)
8534 GtkEntryPrivate *priv;
8535 EntryIconInfo *icon_info;
8538 entry = GTK_ENTRY (widget);
8543 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8546 if ((icon_info = priv->icons[icon_pos]) != NULL)
8548 if (icon_info->tooltip)
8550 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8559 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8566 /* Quick hack of a popup menu
8569 activate_cb (GtkWidget *menuitem,
8572 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8573 g_signal_emit_by_name (entry, signal);
8578 gtk_entry_mnemonic_activate (GtkWidget *widget,
8579 gboolean group_cycling)
8581 gtk_widget_grab_focus (widget);
8586 gtk_entry_grab_notify (GtkWidget *widget,
8587 gboolean was_grabbed)
8589 GtkEntryPrivate *priv;
8591 priv = GTK_ENTRY (widget)->priv;
8594 gtk_widget_device_is_shadowed (widget, priv->device))
8596 /* Unset button so we don't expect
8597 * a button release anymore
8600 priv->device = NULL;
8601 priv->in_drag = FALSE;
8606 append_action_signal (GtkEntry *entry,
8608 const gchar *stock_id,
8609 const gchar *signal,
8612 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8614 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8615 g_signal_connect (menuitem, "activate",
8616 G_CALLBACK (activate_cb), entry);
8618 gtk_widget_set_sensitive (menuitem, sensitive);
8620 gtk_widget_show (menuitem);
8621 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8625 popup_menu_detach (GtkWidget *attach_widget,
8628 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8629 GtkEntryPrivate *priv_attach = entry_attach->priv;
8631 priv_attach->popup_menu = NULL;
8635 popup_position_func (GtkMenu *menu,
8641 GtkEntry *entry = GTK_ENTRY (user_data);
8642 GtkEntryPrivate *priv = entry->priv;
8643 GtkWidget *widget = GTK_WIDGET (entry);
8645 GtkRequisition menu_req;
8646 GdkRectangle monitor;
8648 gint monitor_num, strong_x, height;
8650 g_return_if_fail (gtk_widget_get_realized (widget));
8652 gdk_window_get_origin (priv->text_area, x, y);
8654 screen = gtk_widget_get_screen (widget);
8655 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8656 if (monitor_num < 0)
8658 gtk_menu_set_monitor (menu, monitor_num);
8660 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8661 gtk_widget_get_preferred_size (priv->popup_menu,
8663 height = gdk_window_get_height (priv->text_area);
8664 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8665 _gtk_entry_get_borders (entry, &borders);
8667 *x += borders.left + strong_x - priv->scroll_offset;
8668 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8669 *x -= menu_req.width;
8671 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8673 else if ((*y - menu_req.height) >= monitor.y)
8674 *y -= menu_req.height;
8675 else if (monitor.y + monitor.height - (*y + height) > *y)
8678 *y -= menu_req.height;
8684 unichar_chosen_func (const char *text,
8687 GtkEntry *entry = GTK_ENTRY (data);
8688 GtkEntryPrivate *priv = entry->priv;
8691 gtk_entry_enter_text (entry, text);
8703 popup_targets_received (GtkClipboard *clipboard,
8704 GtkSelectionData *data,
8707 PopupInfo *info = user_data;
8708 GtkEntry *entry = info->entry;
8709 GtkEntryPrivate *info_entry_priv = entry->priv;
8711 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8714 gboolean clipboard_contains_text;
8715 GtkWidget *menuitem;
8717 gboolean show_input_method_menu;
8718 gboolean show_unicode_menu;
8720 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8721 if (info_entry_priv->popup_menu)
8722 gtk_widget_destroy (info_entry_priv->popup_menu);
8724 info_entry_priv->popup_menu = gtk_menu_new ();
8726 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8730 mode = gtk_entry_get_display_mode (entry);
8731 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8732 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8733 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8735 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8736 mode == DISPLAY_NORMAL &&
8737 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8739 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8740 info_entry_priv->editable && clipboard_contains_text);
8742 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8743 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8744 g_signal_connect_swapped (menuitem, "activate",
8745 G_CALLBACK (gtk_entry_delete_cb), entry);
8746 gtk_widget_show (menuitem);
8747 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8749 menuitem = gtk_separator_menu_item_new ();
8750 gtk_widget_show (menuitem);
8751 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8753 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8754 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8755 g_signal_connect_swapped (menuitem, "activate",
8756 G_CALLBACK (gtk_entry_select_all), entry);
8757 gtk_widget_show (menuitem);
8758 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8760 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8761 "gtk-show-input-method-menu", &show_input_method_menu,
8762 "gtk-show-unicode-menu", &show_unicode_menu,
8765 if (show_input_method_menu || show_unicode_menu)
8767 menuitem = gtk_separator_menu_item_new ();
8768 gtk_widget_show (menuitem);
8769 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8772 if (show_input_method_menu)
8774 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8775 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8776 gtk_widget_show (menuitem);
8777 submenu = gtk_menu_new ();
8778 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8780 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8782 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8783 GTK_MENU_SHELL (submenu));
8786 if (show_unicode_menu)
8788 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8789 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8790 gtk_widget_show (menuitem);
8792 submenu = gtk_menu_new ();
8793 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8794 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8796 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8797 unichar_chosen_func,
8801 g_signal_emit (entry,
8802 signals[POPULATE_POPUP],
8804 info_entry_priv->popup_menu);
8808 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8809 info->device, NULL, NULL, NULL, NULL, NULL,
8810 info->button, info->time);
8813 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8814 popup_position_func, entry,
8815 0, gtk_get_current_event_time ());
8816 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8820 g_object_unref (entry);
8821 g_slice_free (PopupInfo, info);
8825 gtk_entry_do_popup (GtkEntry *entry,
8826 GdkEventButton *event)
8828 PopupInfo *info = g_slice_new (PopupInfo);
8830 /* In order to know what entries we should make sensitive, we
8831 * ask for the current targets of the clipboard, and when
8832 * we get them, then we actually pop up the menu.
8834 info->entry = g_object_ref (entry);
8838 info->button = event->button;
8839 info->time = event->time;
8840 info->device = event->device;
8845 info->time = gtk_get_current_event_time ();
8846 info->device = NULL;
8849 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8850 gdk_atom_intern_static_string ("TARGETS"),
8851 popup_targets_received,
8856 gtk_entry_popup_menu (GtkWidget *widget)
8858 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8863 gtk_entry_drag_begin (GtkWidget *widget,
8864 GdkDragContext *context)
8866 GtkEntry *entry = GTK_ENTRY (widget);
8867 GtkEntryPrivate *priv = entry->priv;
8870 for (i = 0; i < MAX_ICONS; i++)
8872 EntryIconInfo *icon_info = priv->icons[i];
8874 if (icon_info != NULL)
8876 if (icon_info->in_drag)
8880 pix = _gtk_icon_helper_ensure_pixbuf
8881 (icon_info->icon_helper,
8882 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8883 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8885 g_object_unref (pix);
8892 gtk_entry_drag_end (GtkWidget *widget,
8893 GdkDragContext *context)
8895 GtkEntry *entry = GTK_ENTRY (widget);
8896 GtkEntryPrivate *priv = entry->priv;
8899 for (i = 0; i < MAX_ICONS; i++)
8901 EntryIconInfo *icon_info = priv->icons[i];
8903 if (icon_info != NULL)
8904 icon_info->in_drag = 0;
8909 gtk_entry_drag_leave (GtkWidget *widget,
8910 GdkDragContext *context,
8913 GtkEntry *entry = GTK_ENTRY (widget);
8914 GtkEntryPrivate *priv = entry->priv;
8916 priv->dnd_position = -1;
8917 gtk_widget_queue_draw (widget);
8921 gtk_entry_drag_drop (GtkWidget *widget,
8922 GdkDragContext *context,
8927 GtkEntry *entry = GTK_ENTRY (widget);
8928 GtkEntryPrivate *priv = entry->priv;
8929 GdkAtom target = GDK_NONE;
8932 target = gtk_drag_dest_find_target (widget, context, NULL);
8934 if (target != GDK_NONE)
8935 gtk_drag_get_data (widget, context, target, time);
8937 gtk_drag_finish (context, FALSE, FALSE, time);
8943 gtk_entry_drag_motion (GtkWidget *widget,
8944 GdkDragContext *context,
8949 GtkEntry *entry = GTK_ENTRY (widget);
8950 GtkEntryPrivate *priv = entry->priv;
8951 GtkStyleContext *style_context;
8952 GtkWidget *source_widget;
8953 GdkDragAction suggested_action;
8954 gint new_position, old_position;
8958 style_context = gtk_widget_get_style_context (widget);
8959 gtk_style_context_get_padding (style_context, 0, &padding);
8963 old_position = priv->dnd_position;
8964 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8966 if (priv->editable &&
8967 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8969 source_widget = gtk_drag_get_source_widget (context);
8970 suggested_action = gdk_drag_context_get_suggested_action (context);
8972 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8973 new_position < sel1 || new_position > sel2)
8975 if (source_widget == widget)
8977 /* Default to MOVE, unless the user has
8978 * pressed ctrl or alt to affect available actions
8980 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8981 suggested_action = GDK_ACTION_MOVE;
8984 priv->dnd_position = new_position;
8988 if (source_widget == widget)
8989 suggested_action = 0; /* Can't drop in selection where drag started */
8991 priv->dnd_position = -1;
8996 /* Entry not editable, or no text */
8997 suggested_action = 0;
8998 priv->dnd_position = -1;
9001 gdk_drag_status (context, suggested_action, time);
9003 if (priv->dnd_position != old_position)
9004 gtk_widget_queue_draw (widget);
9010 gtk_entry_drag_data_received (GtkWidget *widget,
9011 GdkDragContext *context,
9014 GtkSelectionData *selection_data,
9018 GtkEntry *entry = GTK_ENTRY (widget);
9019 GtkEntryPrivate *priv = entry->priv;
9020 GtkEditable *editable = GTK_EDITABLE (widget);
9021 GtkStyleContext *style_context;
9025 str = (gchar *) gtk_selection_data_get_text (selection_data);
9027 style_context = gtk_widget_get_style_context (widget);
9028 gtk_style_context_get_padding (style_context, 0, &padding);
9032 if (str && priv->editable)
9038 if (priv->truncate_multiline)
9039 length = truncate_multiline (str);
9041 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9043 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9044 new_position < sel1 || new_position > sel2)
9046 gtk_editable_insert_text (editable, str, length, &new_position);
9050 /* Replacing selection */
9051 begin_change (entry);
9052 gtk_editable_delete_text (editable, sel1, sel2);
9053 gtk_editable_insert_text (editable, str, length, &sel1);
9057 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9061 /* Drag and drop didn't happen! */
9062 gtk_drag_finish (context, FALSE, FALSE, time);
9069 gtk_entry_drag_data_get (GtkWidget *widget,
9070 GdkDragContext *context,
9071 GtkSelectionData *selection_data,
9075 GtkEntry *entry = GTK_ENTRY (widget);
9076 GtkEntryPrivate *priv = entry->priv;
9077 GtkEditable *editable = GTK_EDITABLE (widget);
9078 gint sel_start, sel_end;
9081 /* If there is an icon drag going on, exit early. */
9082 for (i = 0; i < MAX_ICONS; i++)
9084 EntryIconInfo *icon_info = priv->icons[i];
9086 if (icon_info != NULL)
9088 if (icon_info->in_drag)
9093 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9095 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9097 gtk_selection_data_set_text (selection_data, str, -1);
9105 gtk_entry_drag_data_delete (GtkWidget *widget,
9106 GdkDragContext *context)
9108 GtkEntry *entry = GTK_ENTRY (widget);
9109 GtkEntryPrivate *priv = entry->priv;
9110 GtkEditable *editable = GTK_EDITABLE (widget);
9111 gint sel_start, sel_end;
9114 /* If there is an icon drag going on, exit early. */
9115 for (i = 0; i < MAX_ICONS; i++)
9117 EntryIconInfo *icon_info = priv->icons[i];
9119 if (icon_info != NULL)
9121 if (icon_info->in_drag)
9126 if (priv->editable &&
9127 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9128 gtk_editable_delete_text (editable, sel_start, sel_end);
9131 /* We display the cursor when
9133 * - the selection is empty, AND
9134 * - the widget has focus
9137 #define CURSOR_ON_MULTIPLIER 2
9138 #define CURSOR_OFF_MULTIPLIER 1
9139 #define CURSOR_PEND_MULTIPLIER 3
9140 #define CURSOR_DIVIDER 3
9143 cursor_blinks (GtkEntry *entry)
9145 GtkEntryPrivate *priv = entry->priv;
9147 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9149 priv->selection_bound == priv->current_pos)
9151 GtkSettings *settings;
9154 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9155 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9164 get_middle_click_paste (GtkEntry *entry)
9166 GtkSettings *settings;
9169 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9170 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9176 get_cursor_time (GtkEntry *entry)
9178 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9181 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9187 get_cursor_blink_timeout (GtkEntry *entry)
9189 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9192 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9198 show_cursor (GtkEntry *entry)
9200 GtkEntryPrivate *priv = entry->priv;
9203 if (!priv->cursor_visible)
9205 priv->cursor_visible = TRUE;
9207 widget = GTK_WIDGET (entry);
9208 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9209 gtk_widget_queue_draw (widget);
9214 hide_cursor (GtkEntry *entry)
9216 GtkEntryPrivate *priv = entry->priv;
9219 if (priv->cursor_visible)
9221 priv->cursor_visible = FALSE;
9223 widget = GTK_WIDGET (entry);
9224 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9225 gtk_widget_queue_draw (widget);
9233 blink_cb (gpointer data)
9236 GtkEntryPrivate *priv;
9239 entry = GTK_ENTRY (data);
9242 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9244 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9245 "connect a handler to this signal, it must return\n"
9246 "FALSE so the entry gets the event as well");
9248 gtk_entry_check_cursor_blink (entry);
9253 g_assert (priv->selection_bound == priv->current_pos);
9255 blink_timeout = get_cursor_blink_timeout (entry);
9256 if (priv->blink_time > 1000 * blink_timeout &&
9257 blink_timeout < G_MAXINT/1000)
9259 /* we've blinked enough without the user doing anything, stop blinking */
9260 show_cursor (entry);
9261 priv->blink_timeout = 0;
9263 else if (priv->cursor_visible)
9265 hide_cursor (entry);
9266 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9272 show_cursor (entry);
9273 priv->blink_time += get_cursor_time (entry);
9274 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9279 /* Remove ourselves */
9284 gtk_entry_check_cursor_blink (GtkEntry *entry)
9286 GtkEntryPrivate *priv = entry->priv;
9288 if (cursor_blinks (entry))
9290 if (!priv->blink_timeout)
9292 show_cursor (entry);
9293 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9300 if (priv->blink_timeout)
9302 g_source_remove (priv->blink_timeout);
9303 priv->blink_timeout = 0;
9306 priv->cursor_visible = TRUE;
9311 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9313 GtkEntryPrivate *priv = entry->priv;
9315 if (cursor_blinks (entry))
9317 if (priv->blink_timeout != 0)
9318 g_source_remove (priv->blink_timeout);
9320 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9323 show_cursor (entry);
9328 gtk_entry_reset_blink_time (GtkEntry *entry)
9330 GtkEntryPrivate *priv = entry->priv;
9332 priv->blink_time = 0;
9338 gtk_entry_completion_timeout (gpointer data)
9340 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9341 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9343 completion->priv->completion_timeout = 0;
9345 if (completion->priv->filter_model &&
9346 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9347 >= completion->priv->minimum_key_length)
9351 GtkTreeSelection *s;
9352 gboolean popup_single;
9354 gtk_entry_completion_complete (completion);
9355 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9357 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9359 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9361 gtk_tree_selection_unselect_all (s);
9363 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9365 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9366 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9368 if (gtk_widget_get_visible (completion->priv->popup_window))
9369 _gtk_entry_completion_resize_popup (completion);
9371 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9374 _gtk_entry_completion_popdown (completion);
9376 else if (gtk_widget_get_visible (completion->priv->popup_window))
9377 _gtk_entry_completion_popdown (completion);
9382 static inline gboolean
9383 keyval_is_cursor_move (guint keyval)
9385 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9388 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9391 if (keyval == GDK_KEY_Page_Up)
9394 if (keyval == GDK_KEY_Page_Down)
9401 gtk_entry_completion_key_press (GtkWidget *widget,
9405 gint matches, actions = 0;
9406 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9408 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9411 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9413 if (completion->priv->actions)
9414 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9416 if (keyval_is_cursor_move (event->keyval))
9418 GtkTreePath *path = NULL;
9420 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9422 if (completion->priv->current_selected < 0)
9423 completion->priv->current_selected = matches + actions - 1;
9425 completion->priv->current_selected--;
9427 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9429 if (completion->priv->current_selected < matches + actions - 1)
9430 completion->priv->current_selected++;
9432 completion->priv->current_selected = -1;
9434 else if (event->keyval == GDK_KEY_Page_Up)
9436 if (completion->priv->current_selected < 0)
9437 completion->priv->current_selected = matches + actions - 1;
9438 else if (completion->priv->current_selected == 0)
9439 completion->priv->current_selected = -1;
9440 else if (completion->priv->current_selected < matches)
9442 completion->priv->current_selected -= PAGE_STEP;
9443 if (completion->priv->current_selected < 0)
9444 completion->priv->current_selected = 0;
9448 completion->priv->current_selected -= PAGE_STEP;
9449 if (completion->priv->current_selected < matches - 1)
9450 completion->priv->current_selected = matches - 1;
9453 else if (event->keyval == GDK_KEY_Page_Down)
9455 if (completion->priv->current_selected < 0)
9456 completion->priv->current_selected = 0;
9457 else if (completion->priv->current_selected < matches - 1)
9459 completion->priv->current_selected += PAGE_STEP;
9460 if (completion->priv->current_selected > matches - 1)
9461 completion->priv->current_selected = matches - 1;
9463 else if (completion->priv->current_selected == matches + actions - 1)
9465 completion->priv->current_selected = -1;
9469 completion->priv->current_selected += PAGE_STEP;
9470 if (completion->priv->current_selected > matches + actions - 1)
9471 completion->priv->current_selected = matches + actions - 1;
9475 if (completion->priv->current_selected < 0)
9477 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9478 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9480 if (completion->priv->inline_selection &&
9481 completion->priv->completion_prefix)
9483 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9484 completion->priv->completion_prefix);
9485 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9488 else if (completion->priv->current_selected < matches)
9490 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9492 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9493 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9496 if (completion->priv->inline_selection)
9500 GtkTreeIter child_iter;
9501 GtkTreeModel *model = NULL;
9502 GtkTreeSelection *sel;
9505 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9506 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9509 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9510 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9512 if (completion->priv->completion_prefix == NULL)
9513 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9515 g_signal_emit_by_name (completion, "cursor-on-match", model,
9516 &child_iter, &entry_set);
9519 else if (completion->priv->current_selected - matches >= 0)
9521 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9523 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9524 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9527 if (completion->priv->inline_selection &&
9528 completion->priv->completion_prefix)
9530 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9531 completion->priv->completion_prefix);
9532 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9536 gtk_tree_path_free (path);
9540 else if (event->keyval == GDK_KEY_Escape ||
9541 event->keyval == GDK_KEY_Left ||
9542 event->keyval == GDK_KEY_KP_Left ||
9543 event->keyval == GDK_KEY_Right ||
9544 event->keyval == GDK_KEY_KP_Right)
9546 gboolean retval = TRUE;
9548 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9549 _gtk_entry_completion_popdown (completion);
9551 if (completion->priv->current_selected < 0)
9554 goto keypress_completion_out;
9556 else if (completion->priv->inline_selection)
9558 /* Escape rejects the tentative completion */
9559 if (event->keyval == GDK_KEY_Escape)
9561 if (completion->priv->completion_prefix)
9562 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9563 completion->priv->completion_prefix);
9565 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9568 /* Move the cursor to the end for Right/Esc, to the
9569 beginning for Left */
9570 if (event->keyval == GDK_KEY_Right ||
9571 event->keyval == GDK_KEY_KP_Right ||
9572 event->keyval == GDK_KEY_Escape)
9573 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9575 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9578 keypress_completion_out:
9579 if (completion->priv->inline_selection)
9581 g_free (completion->priv->completion_prefix);
9582 completion->priv->completion_prefix = NULL;
9587 else if (event->keyval == GDK_KEY_Tab ||
9588 event->keyval == GDK_KEY_KP_Tab ||
9589 event->keyval == GDK_KEY_ISO_Left_Tab)
9591 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9592 _gtk_entry_completion_popdown (completion);
9594 g_free (completion->priv->completion_prefix);
9595 completion->priv->completion_prefix = NULL;
9599 else if (event->keyval == GDK_KEY_ISO_Enter ||
9600 event->keyval == GDK_KEY_KP_Enter ||
9601 event->keyval == GDK_KEY_Return)
9604 GtkTreeModel *model = NULL;
9605 GtkTreeModel *child_model;
9606 GtkTreeIter child_iter;
9607 GtkTreeSelection *sel;
9608 gboolean retval = TRUE;
9610 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9611 _gtk_entry_completion_popdown (completion);
9613 if (completion->priv->current_selected < matches)
9617 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9618 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9620 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9621 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9622 g_signal_handler_block (widget, completion->priv->changed_id);
9623 g_signal_emit_by_name (completion, "match-selected",
9624 child_model, &child_iter, &entry_set);
9625 g_signal_handler_unblock (widget, completion->priv->changed_id);
9631 gtk_tree_model_get (model, &iter,
9632 completion->priv->text_column, &str,
9635 gtk_entry_set_text (GTK_ENTRY (widget), str);
9637 /* move the cursor to the end */
9638 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9646 else if (completion->priv->current_selected - matches >= 0)
9648 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9649 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9653 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9654 g_signal_emit_by_name (completion, "action-activated",
9655 gtk_tree_path_get_indices (path)[0]);
9656 gtk_tree_path_free (path);
9662 g_free (completion->priv->completion_prefix);
9663 completion->priv->completion_prefix = NULL;
9672 gtk_entry_completion_changed (GtkWidget *widget,
9675 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9676 GtkEntry *entry = GTK_ENTRY (widget);
9677 GtkEntryPrivate *priv = entry->priv;
9680 /* (re)install completion timeout */
9681 if (completion->priv->completion_timeout)
9682 g_source_remove (completion->priv->completion_timeout);
9684 if (!gtk_entry_get_text (entry))
9687 /* no need to normalize for this test */
9688 if (completion->priv->minimum_key_length > 0 &&
9689 strcmp ("", gtk_entry_get_text (entry)) == 0)
9691 if (gtk_widget_get_visible (completion->priv->popup_window))
9692 _gtk_entry_completion_popdown (completion);
9696 device = gtk_get_current_event_device ();
9698 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9699 device = gdk_device_get_associated_device (device);
9702 priv->completion_device = device;
9704 completion->priv->completion_timeout =
9705 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9706 gtk_entry_completion_timeout,
9711 check_completion_callback (GtkEntryCompletion *completion)
9713 completion->priv->check_completion_idle = NULL;
9715 gtk_entry_completion_complete (completion);
9716 gtk_entry_completion_insert_prefix (completion);
9722 clear_completion_callback (GtkEntry *entry,
9725 if (pspec->name == I_("cursor-position") ||
9726 pspec->name == I_("selection-bound"))
9728 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9730 completion->priv->has_completion = FALSE;
9735 accept_completion_callback (GtkEntry *entry)
9737 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9739 if (completion->priv->has_completion)
9740 gtk_editable_set_position (GTK_EDITABLE (entry),
9741 gtk_entry_buffer_get_length (get_buffer (entry)));
9747 completion_insert_text_callback (GtkEntry *entry,
9751 GtkEntryCompletion *completion)
9753 /* idle to update the selection based on the file list */
9754 if (completion->priv->check_completion_idle == NULL)
9756 completion->priv->check_completion_idle = g_idle_source_new ();
9757 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9758 g_source_set_closure (completion->priv->check_completion_idle,
9759 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9760 G_OBJECT (completion)));
9761 g_source_attach (completion->priv->check_completion_idle, NULL);
9766 completion_changed (GtkEntryCompletion *completion,
9770 GtkEntry *entry = GTK_ENTRY (data);
9772 if (pspec->name == I_("popup-completion") ||
9773 pspec->name == I_("inline-completion"))
9775 disconnect_completion_signals (entry, completion);
9776 connect_completion_signals (entry, completion);
9781 disconnect_completion_signals (GtkEntry *entry,
9782 GtkEntryCompletion *completion)
9784 g_signal_handlers_disconnect_by_func (completion,
9785 G_CALLBACK (completion_changed), entry);
9786 if (completion->priv->changed_id > 0 &&
9787 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9789 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9790 completion->priv->changed_id = 0;
9792 g_signal_handlers_disconnect_by_func (entry,
9793 G_CALLBACK (gtk_entry_completion_key_press), completion);
9794 if (completion->priv->insert_text_id > 0 &&
9795 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9797 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9798 completion->priv->insert_text_id = 0;
9800 g_signal_handlers_disconnect_by_func (entry,
9801 G_CALLBACK (completion_insert_text_callback), completion);
9802 g_signal_handlers_disconnect_by_func (entry,
9803 G_CALLBACK (clear_completion_callback), completion);
9804 g_signal_handlers_disconnect_by_func (entry,
9805 G_CALLBACK (accept_completion_callback), completion);
9809 connect_completion_signals (GtkEntry *entry,
9810 GtkEntryCompletion *completion)
9812 if (completion->priv->popup_completion)
9814 completion->priv->changed_id =
9815 g_signal_connect (entry, "changed",
9816 G_CALLBACK (gtk_entry_completion_changed), completion);
9817 g_signal_connect (entry, "key-press-event",
9818 G_CALLBACK (gtk_entry_completion_key_press), completion);
9821 if (completion->priv->inline_completion)
9823 completion->priv->insert_text_id =
9824 g_signal_connect (entry, "insert-text",
9825 G_CALLBACK (completion_insert_text_callback), completion);
9826 g_signal_connect (entry, "notify",
9827 G_CALLBACK (clear_completion_callback), completion);
9828 g_signal_connect (entry, "activate",
9829 G_CALLBACK (accept_completion_callback), completion);
9830 g_signal_connect (entry, "focus-out-event",
9831 G_CALLBACK (accept_completion_callback), completion);
9834 g_signal_connect (completion, "notify",
9835 G_CALLBACK (completion_changed), entry);
9839 * gtk_entry_set_completion:
9840 * @entry: A #GtkEntry
9841 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9843 * Sets @completion to be the auxiliary completion object to use with @entry.
9844 * All further configuration of the completion mechanism is done on
9845 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9846 * @completion is set to %NULL.
9851 gtk_entry_set_completion (GtkEntry *entry,
9852 GtkEntryCompletion *completion)
9854 GtkEntryCompletion *old;
9856 g_return_if_fail (GTK_IS_ENTRY (entry));
9857 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9859 old = gtk_entry_get_completion (entry);
9861 if (old == completion)
9866 if (old->priv->completion_timeout)
9868 g_source_remove (old->priv->completion_timeout);
9869 old->priv->completion_timeout = 0;
9872 if (old->priv->check_completion_idle)
9874 g_source_destroy (old->priv->check_completion_idle);
9875 old->priv->check_completion_idle = NULL;
9878 if (gtk_widget_get_mapped (old->priv->popup_window))
9879 _gtk_entry_completion_popdown (old);
9881 disconnect_completion_signals (entry, old);
9882 old->priv->entry = NULL;
9884 g_object_unref (old);
9889 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9893 /* hook into the entry */
9894 g_object_ref (completion);
9896 connect_completion_signals (entry, completion);
9897 completion->priv->entry = GTK_WIDGET (entry);
9898 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9900 g_object_notify (G_OBJECT (entry), "completion");
9904 * gtk_entry_get_completion:
9905 * @entry: A #GtkEntry
9907 * Returns the auxiliary completion object currently in use by @entry.
9909 * Return value: (transfer none): The auxiliary completion object currently
9914 GtkEntryCompletion *
9915 gtk_entry_get_completion (GtkEntry *entry)
9917 GtkEntryCompletion *completion;
9919 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9921 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9922 GTK_ENTRY_COMPLETION_KEY));
9928 * gtk_entry_set_cursor_hadjustment:
9929 * @entry: a #GtkEntry
9930 * @adjustment: an adjustment which should be adjusted when the cursor
9931 * is moved, or %NULL
9933 * Hooks up an adjustment to the cursor position in an entry, so that when
9934 * the cursor is moved, the adjustment is scrolled to show that position.
9935 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9938 * The adjustment has to be in pixel units and in the same coordinate system
9944 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9945 GtkAdjustment *adjustment)
9947 g_return_if_fail (GTK_IS_ENTRY (entry));
9949 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9952 g_object_ref (adjustment);
9954 g_object_set_qdata_full (G_OBJECT (entry),
9955 quark_cursor_hadjustment,
9961 * gtk_entry_get_cursor_hadjustment:
9962 * @entry: a #GtkEntry
9964 * Retrieves the horizontal cursor adjustment for the entry.
9965 * See gtk_entry_set_cursor_hadjustment().
9967 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9968 * if none has been set.
9973 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9975 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9977 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9981 * gtk_entry_set_progress_fraction:
9982 * @entry: a #GtkEntry
9983 * @fraction: fraction of the task that's been completed
9985 * Causes the entry's progress indicator to "fill in" the given
9986 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9992 gtk_entry_set_progress_fraction (GtkEntry *entry,
9996 GtkEntryPrivate *private;
9997 gdouble old_fraction;
9998 gint x, y, width, height;
9999 gint old_x, old_y, old_width, old_height;
10001 g_return_if_fail (GTK_IS_ENTRY (entry));
10003 widget = GTK_WIDGET (entry);
10004 private = entry->priv;
10006 if (private->progress_pulse_mode)
10009 old_fraction = private->progress_fraction;
10011 if (gtk_widget_is_drawable (widget))
10012 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10014 fraction = CLAMP (fraction, 0.0, 1.0);
10016 private->progress_fraction = fraction;
10017 private->progress_pulse_mode = FALSE;
10018 private->progress_pulse_current = 0.0;
10020 if (gtk_widget_is_drawable (widget))
10022 get_progress_area (widget, &x, &y, &width, &height);
10024 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10025 gtk_widget_queue_draw (widget);
10028 if (fraction != old_fraction)
10029 g_object_notify (G_OBJECT (entry), "progress-fraction");
10033 * gtk_entry_get_progress_fraction:
10034 * @entry: a #GtkEntry
10036 * Returns the current fraction of the task that's been completed.
10037 * See gtk_entry_set_progress_fraction().
10039 * Return value: a fraction from 0.0 to 1.0
10044 gtk_entry_get_progress_fraction (GtkEntry *entry)
10046 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10048 return entry->priv->progress_fraction;
10052 * gtk_entry_set_progress_pulse_step:
10053 * @entry: a #GtkEntry
10054 * @fraction: fraction between 0.0 and 1.0
10056 * Sets the fraction of total entry width to move the progress
10057 * bouncing block for each call to gtk_entry_progress_pulse().
10062 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10065 GtkEntryPrivate *private;
10067 g_return_if_fail (GTK_IS_ENTRY (entry));
10069 private = entry->priv;
10071 fraction = CLAMP (fraction, 0.0, 1.0);
10073 if (fraction != private->progress_pulse_fraction)
10075 private->progress_pulse_fraction = fraction;
10077 gtk_widget_queue_draw (GTK_WIDGET (entry));
10079 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10084 * gtk_entry_get_progress_pulse_step:
10085 * @entry: a #GtkEntry
10087 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10089 * Return value: a fraction from 0.0 to 1.0
10094 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10096 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10098 return entry->priv->progress_pulse_fraction;
10102 * gtk_entry_progress_pulse:
10103 * @entry: a #GtkEntry
10105 * Indicates that some progress is made, but you don't know how much.
10106 * Causes the entry's progress indicator to enter "activity mode,"
10107 * where a block bounces back and forth. Each call to
10108 * gtk_entry_progress_pulse() causes the block to move by a little bit
10109 * (the amount of movement per pulse is determined by
10110 * gtk_entry_set_progress_pulse_step()).
10115 gtk_entry_progress_pulse (GtkEntry *entry)
10117 GtkEntryPrivate *private;
10119 g_return_if_fail (GTK_IS_ENTRY (entry));
10121 private = entry->priv;
10123 if (private->progress_pulse_mode)
10125 if (private->progress_pulse_way_back)
10127 private->progress_pulse_current -= private->progress_pulse_fraction;
10129 if (private->progress_pulse_current < 0.0)
10131 private->progress_pulse_current = 0.0;
10132 private->progress_pulse_way_back = FALSE;
10137 private->progress_pulse_current += private->progress_pulse_fraction;
10139 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10141 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10142 private->progress_pulse_way_back = TRUE;
10148 private->progress_fraction = 0.0;
10149 private->progress_pulse_mode = TRUE;
10150 private->progress_pulse_way_back = FALSE;
10151 private->progress_pulse_current = 0.0;
10154 gtk_widget_queue_draw (GTK_WIDGET (entry));
10158 * gtk_entry_set_placeholder_text:
10159 * @entry: a #GtkEntry
10160 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10162 * Sets text to be displayed in @entry when it is empty and unfocused.
10163 * This can be used to give a visual hint of the expected contents of
10166 * Note that since the placeholder text gets removed when the entry
10167 * received focus, using this feature is a bit problematic if the entry
10168 * is given the initial focus in a window. Sometimes this can be
10169 * worked around by delaying the initial focus setting until the
10170 * first key event arrives.
10175 gtk_entry_set_placeholder_text (GtkEntry *entry,
10178 GtkEntryPrivate *priv;
10180 g_return_if_fail (GTK_IS_ENTRY (entry));
10182 priv = entry->priv;
10184 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10187 g_free (priv->placeholder_text);
10188 priv->placeholder_text = g_strdup (text);
10190 gtk_entry_recompute (entry);
10192 g_object_notify (G_OBJECT (entry), "placeholder-text");
10196 * gtk_entry_get_placeholder_text:
10197 * @entry: a #GtkEntry
10199 * Retrieves the text that will be displayed when @entry is empty and unfocused
10201 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10202 * storage in the widget and must not be freed, modified or stored.
10207 gtk_entry_get_placeholder_text (GtkEntry *entry)
10209 GtkEntryPrivate *priv;
10211 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10213 priv = entry->priv;
10215 return priv->placeholder_text;
10218 /* Caps Lock warning for password entries */
10221 show_capslock_feedback (GtkEntry *entry,
10224 GtkEntryPrivate *priv = entry->priv;
10226 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10228 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10229 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10230 priv->caps_lock_warning_shown = TRUE;
10233 if (priv->caps_lock_warning_shown)
10234 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10236 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10240 remove_capslock_feedback (GtkEntry *entry)
10242 GtkEntryPrivate *priv = entry->priv;
10244 if (priv->caps_lock_warning_shown)
10246 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10247 priv->caps_lock_warning_shown = FALSE;
10252 keymap_state_changed (GdkKeymap *keymap,
10255 GtkEntryPrivate *priv = entry->priv;
10258 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10260 if (gdk_keymap_get_caps_lock_state (keymap))
10261 text = _("Caps Lock is on");
10265 show_capslock_feedback (entry, text);
10267 remove_capslock_feedback (entry);
10271 * _gtk_entry_set_is_cell_renderer:
10272 * @entry: a #GtkEntry
10273 * @is_cell_renderer: new value
10275 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10276 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10278 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10282 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10283 gboolean is_cell_renderer)
10285 entry->priv->is_cell_renderer = is_cell_renderer;