1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gtkbindings.h"
37 #include "gtkcelleditable.h"
38 #include "gtkclipboard.h"
41 #include "gtkentrybuffer.h"
42 #include "gtkimagemenuitem.h"
43 #include "gtkimcontextsimple.h"
44 #include "gtkimmulticontext.h"
48 #include "gtkmarshalers.h"
50 #include "gtkmenuitem.h"
51 #include "gtkseparatormenuitem.h"
52 #include "gtkselection.h"
53 #include "gtksettings.h"
54 #include "gtkspinbutton.h"
56 #include "gtktextutil.h"
57 #include "gtkwindow.h"
58 #include "gtktreeview.h"
59 #include "gtktreeselection.h"
60 #include "gtktypebuiltins.h"
61 #include "gtkprivate.h"
62 #include "gtkentryprivate.h"
63 #include "gtkcelllayout.h"
64 #include "gtktooltip.h"
65 #include "gtkiconfactory.h"
66 #include "gtkicontheme.h"
67 #include "gtkwidgetprivate.h"
68 #include "gtkstylecontextprivate.h"
72 * @Short_description: A single line text entry field
74 * @See_also: #GtkTextView, #GtkEntryCompletion
76 * The #GtkEntry widget is a single line text entry
77 * widget. A fairly large set of key bindings are supported
78 * by default. If the entered text is longer than the allocation
79 * of the widget, the widget will scroll so that the cursor
80 * position is visible.
82 * When using an entry for passwords and other sensitive information,
83 * it can be put into "password mode" using gtk_entry_set_visibility().
84 * In this mode, entered text is displayed using a 'invisible' character.
85 * By default, GTK+ picks the best invisible character that is available
86 * in the current font, but it can be changed with
87 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
88 * when Caps Lock or input methods might interfere with entering text in
89 * a password entry. The warning can be turned off with the
90 * #GtkEntry:caps-lock-warning property.
92 * Since 2.16, GtkEntry has the ability to display progress or activity
93 * information behind the text. To make an entry display such information,
94 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
96 * Additionally, GtkEntry can show icons at either side of the entry. These
97 * icons can be activatable by clicking, can be set up as drag source and
98 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
99 * one of the various other functions that set an icon from a stock id, an
100 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
101 * connect to the #GtkEntry::icon-press signal. To allow DND operations
102 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
103 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
106 * Note that functionality or information that is only available by clicking
107 * on an icon in an entry may not be accessible at all to users which are not
108 * able to use a mouse or other pointing device. It is therefore recommended
109 * that any such functionality should also be available by other means, e.g.
110 * via the context menu of the entry.
114 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
116 #define MIN_ENTRY_WIDTH 150
117 #define DRAW_TIMEOUT 20
118 #define COMPLETION_TIMEOUT 300
119 #define PASSWORD_HINT_MAX 8
123 #define IS_VALID_ICON_POSITION(pos) \
124 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
125 (pos) == GTK_ENTRY_ICON_SECONDARY)
127 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
128 static GQuark quark_inner_border = 0;
129 static GQuark quark_password_hint = 0;
130 static GQuark quark_cursor_hadjustment = 0;
131 static GQuark quark_capslock_feedback = 0;
133 typedef struct _EntryIconInfo EntryIconInfo;
134 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
135 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
137 struct _GtkEntryPrivate
139 EntryIconInfo *icons[MAX_ICONS];
141 GtkEntryBuffer *buffer;
142 GtkIMContext *im_context;
143 GtkShadowType shadow_type;
144 GtkWidget *popup_menu;
146 GdkDevice *completion_device;
147 GdkWindow *text_area;
149 PangoLayout *cached_layout;
153 gdouble progress_fraction;
154 gdouble progress_pulse_fraction;
155 gdouble progress_pulse_current;
157 gchar *placeholder_text;
161 gint ascent; /* font ascent in pango units */
163 gint descent; /* font descent in pango units */
164 gint dnd_position; /* In chars, -1 == no DND cursor */
170 gint selection_bound;
176 gunichar invisible_char;
179 guint blink_time; /* time in msec the cursor has blinked since last user event */
181 guint recompute_idle;
183 guint16 x_text_size; /* allocated size, in bytes */
184 guint16 x_n_bytes; /* length in use, in bytes */
186 guint16 preedit_length; /* length of preedit string, in bytes */
187 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
191 guint overwrite_mode : 1;
194 guint activates_default : 1;
195 guint cache_includes_preedit : 1;
196 guint caps_lock_warning : 1;
197 guint caps_lock_warning_shown : 1;
198 guint change_count : 8;
199 guint cursor_visible : 1;
200 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
202 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
203 guint is_cell_renderer : 1;
204 guint invisible_char_set : 1;
205 guint interior_focus : 1;
206 guint mouse_cursor_obscured : 1;
207 guint need_im_reset : 1;
208 guint progress_pulse_mode : 1;
209 guint progress_pulse_way_back : 1;
210 guint real_changed : 1;
211 guint resolved_dir : 4; /* PangoDirection */
212 guint select_words : 1;
213 guint select_lines : 1;
214 guint truncate_multiline : 1;
217 struct _EntryIconInfo
221 guint insensitive : 1;
222 guint nonactivatable : 1;
227 GtkImageType storage_type;
235 GtkTargetList *target_list;
236 GdkDragAction actions;
239 struct _GtkEntryPasswordHint
241 gint position; /* Position (in text) of the last password hint */
242 guint source_id; /* Timeout source id */
245 struct _GtkEntryCapslockFeedback
272 PROP_CURSOR_POSITION,
273 PROP_SELECTION_BOUND,
280 PROP_ACTIVATES_DEFAULT,
285 PROP_TRUNCATE_MULTILINE,
289 PROP_INVISIBLE_CHAR_SET,
290 PROP_CAPS_LOCK_WARNING,
291 PROP_PROGRESS_FRACTION,
292 PROP_PROGRESS_PULSE_STEP,
294 PROP_PIXBUF_SECONDARY,
296 PROP_STOCK_SECONDARY,
297 PROP_ICON_NAME_PRIMARY,
298 PROP_ICON_NAME_SECONDARY,
300 PROP_GICON_SECONDARY,
301 PROP_STORAGE_TYPE_PRIMARY,
302 PROP_STORAGE_TYPE_SECONDARY,
303 PROP_ACTIVATABLE_PRIMARY,
304 PROP_ACTIVATABLE_SECONDARY,
305 PROP_SENSITIVE_PRIMARY,
306 PROP_SENSITIVE_SECONDARY,
307 PROP_TOOLTIP_TEXT_PRIMARY,
308 PROP_TOOLTIP_TEXT_SECONDARY,
309 PROP_TOOLTIP_MARKUP_PRIMARY,
310 PROP_TOOLTIP_MARKUP_SECONDARY,
312 PROP_EDITING_CANCELED,
313 PROP_PLACEHOLDER_TEXT,
317 static guint signals[LAST_SIGNAL] = { 0 };
326 DISPLAY_NORMAL, /* The entry text is being shown */
327 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
328 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
333 static void gtk_entry_editable_init (GtkEditableInterface *iface);
334 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
335 static void gtk_entry_set_property (GObject *object,
339 static void gtk_entry_get_property (GObject *object,
343 static void gtk_entry_finalize (GObject *object);
344 static void gtk_entry_dispose (GObject *object);
348 static void gtk_entry_destroy (GtkWidget *widget);
349 static void gtk_entry_realize (GtkWidget *widget);
350 static void gtk_entry_unrealize (GtkWidget *widget);
351 static void gtk_entry_map (GtkWidget *widget);
352 static void gtk_entry_unmap (GtkWidget *widget);
353 static void gtk_entry_get_preferred_width (GtkWidget *widget,
356 static void gtk_entry_get_preferred_height (GtkWidget *widget,
359 static void gtk_entry_size_allocate (GtkWidget *widget,
360 GtkAllocation *allocation);
361 static void gtk_entry_draw_frame (GtkWidget *widget,
362 GtkStyleContext *context,
364 static void gtk_entry_draw_progress (GtkWidget *widget,
365 GtkStyleContext *context,
367 static gint gtk_entry_draw (GtkWidget *widget,
369 static gint gtk_entry_button_press (GtkWidget *widget,
370 GdkEventButton *event);
371 static gint gtk_entry_button_release (GtkWidget *widget,
372 GdkEventButton *event);
373 static gint gtk_entry_enter_notify (GtkWidget *widget,
374 GdkEventCrossing *event);
375 static gint gtk_entry_leave_notify (GtkWidget *widget,
376 GdkEventCrossing *event);
377 static gint gtk_entry_motion_notify (GtkWidget *widget,
378 GdkEventMotion *event);
379 static gint gtk_entry_key_press (GtkWidget *widget,
381 static gint gtk_entry_key_release (GtkWidget *widget,
383 static gint gtk_entry_focus_in (GtkWidget *widget,
384 GdkEventFocus *event);
385 static gint gtk_entry_focus_out (GtkWidget *widget,
386 GdkEventFocus *event);
387 static void gtk_entry_grab_focus (GtkWidget *widget);
388 static void gtk_entry_style_updated (GtkWidget *widget);
389 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
392 gboolean keyboard_tip,
393 GtkTooltip *tooltip);
394 static void gtk_entry_direction_changed (GtkWidget *widget,
395 GtkTextDirection previous_dir);
396 static void gtk_entry_state_flags_changed (GtkWidget *widget,
397 GtkStateFlags previous_state);
398 static void gtk_entry_screen_changed (GtkWidget *widget,
399 GdkScreen *old_screen);
401 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
402 GdkDragContext *context,
406 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
407 GdkDragContext *context,
411 static void gtk_entry_drag_leave (GtkWidget *widget,
412 GdkDragContext *context,
414 static void gtk_entry_drag_data_received (GtkWidget *widget,
415 GdkDragContext *context,
418 GtkSelectionData *selection_data,
421 static void gtk_entry_drag_data_get (GtkWidget *widget,
422 GdkDragContext *context,
423 GtkSelectionData *selection_data,
426 static void gtk_entry_drag_data_delete (GtkWidget *widget,
427 GdkDragContext *context);
428 static void gtk_entry_drag_begin (GtkWidget *widget,
429 GdkDragContext *context);
430 static void gtk_entry_drag_end (GtkWidget *widget,
431 GdkDragContext *context);
434 /* GtkEditable method implementations
436 static void gtk_entry_insert_text (GtkEditable *editable,
437 const gchar *new_text,
438 gint new_text_length,
440 static void gtk_entry_delete_text (GtkEditable *editable,
443 static gchar * gtk_entry_get_chars (GtkEditable *editable,
446 static void gtk_entry_real_set_position (GtkEditable *editable,
448 static gint gtk_entry_get_position (GtkEditable *editable);
449 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
452 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
456 /* GtkCellEditable method implementations
458 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
461 /* Default signal handlers
463 static void gtk_entry_real_insert_text (GtkEditable *editable,
464 const gchar *new_text,
465 gint new_text_length,
467 static void gtk_entry_real_delete_text (GtkEditable *editable,
470 static void gtk_entry_move_cursor (GtkEntry *entry,
471 GtkMovementStep step,
473 gboolean extend_selection);
474 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
476 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
479 static void gtk_entry_backspace (GtkEntry *entry);
480 static void gtk_entry_cut_clipboard (GtkEntry *entry);
481 static void gtk_entry_copy_clipboard (GtkEntry *entry);
482 static void gtk_entry_paste_clipboard (GtkEntry *entry);
483 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
484 static void gtk_entry_select_all (GtkEntry *entry);
485 static void gtk_entry_real_activate (GtkEntry *entry);
486 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
488 static void keymap_direction_changed (GdkKeymap *keymap,
490 static void keymap_state_changed (GdkKeymap *keymap,
492 static void remove_capslock_feedback (GtkEntry *entry);
494 /* IM Context Callbacks
496 static void gtk_entry_commit_cb (GtkIMContext *context,
499 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
501 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
503 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
510 static void gtk_entry_enter_text (GtkEntry *entry,
512 static void gtk_entry_set_positions (GtkEntry *entry,
514 gint selection_bound);
515 static void gtk_entry_draw_text (GtkEntry *entry,
517 static void gtk_entry_draw_cursor (GtkEntry *entry,
520 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
521 gboolean include_preedit);
522 static void gtk_entry_reset_layout (GtkEntry *entry);
523 static void gtk_entry_recompute (GtkEntry *entry);
524 static gint gtk_entry_find_position (GtkEntry *entry,
526 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
530 static void gtk_entry_adjust_scroll (GtkEntry *entry);
531 static gint gtk_entry_move_visually (GtkEntry *editable,
534 static gint gtk_entry_move_logically (GtkEntry *entry,
537 static gint gtk_entry_move_forward_word (GtkEntry *entry,
539 gboolean allow_whitespace);
540 static gint gtk_entry_move_backward_word (GtkEntry *entry,
542 gboolean allow_whitespace);
543 static void gtk_entry_delete_whitespace (GtkEntry *entry);
544 static void gtk_entry_select_word (GtkEntry *entry);
545 static void gtk_entry_select_line (GtkEntry *entry);
546 static void gtk_entry_paste (GtkEntry *entry,
548 static void gtk_entry_update_primary_selection (GtkEntry *entry);
549 static void gtk_entry_do_popup (GtkEntry *entry,
550 GdkEventButton *event);
551 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
552 gboolean group_cycling);
553 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
554 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
555 static void gtk_entry_reset_blink_time (GtkEntry *entry);
556 static void gtk_entry_get_text_area_size (GtkEntry *entry,
561 static void get_text_area_size (GtkEntry *entry,
566 static void get_frame_size (GtkEntry *entry,
567 gboolean relative_to_window,
572 static void gtk_entry_move_adjustments (GtkEntry *entry);
573 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
574 GtkEntryIconPosition icon_pos);
575 static void gtk_entry_update_cached_style_values(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;
698 widget_class->drag_drop = gtk_entry_drag_drop;
699 widget_class->drag_motion = gtk_entry_drag_motion;
700 widget_class->drag_leave = gtk_entry_drag_leave;
701 widget_class->drag_data_received = gtk_entry_drag_data_received;
702 widget_class->drag_data_get = gtk_entry_drag_data_get;
703 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
705 widget_class->popup_menu = gtk_entry_popup_menu;
707 class->move_cursor = gtk_entry_move_cursor;
708 class->insert_at_cursor = gtk_entry_insert_at_cursor;
709 class->delete_from_cursor = gtk_entry_delete_from_cursor;
710 class->backspace = gtk_entry_backspace;
711 class->cut_clipboard = gtk_entry_cut_clipboard;
712 class->copy_clipboard = gtk_entry_copy_clipboard;
713 class->paste_clipboard = gtk_entry_paste_clipboard;
714 class->toggle_overwrite = gtk_entry_toggle_overwrite;
715 class->activate = gtk_entry_real_activate;
716 class->get_text_area_size = gtk_entry_get_text_area_size;
718 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
719 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
720 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
721 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
723 g_object_class_override_property (gobject_class,
724 PROP_EDITING_CANCELED,
727 g_object_class_install_property (gobject_class,
729 g_param_spec_object ("buffer",
731 P_("Text buffer object which actually stores entry text"),
732 GTK_TYPE_ENTRY_BUFFER,
733 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
735 g_object_class_install_property (gobject_class,
736 PROP_CURSOR_POSITION,
737 g_param_spec_int ("cursor-position",
738 P_("Cursor Position"),
739 P_("The current position of the insertion cursor in chars"),
741 GTK_ENTRY_BUFFER_MAX_SIZE,
743 GTK_PARAM_READABLE));
745 g_object_class_install_property (gobject_class,
746 PROP_SELECTION_BOUND,
747 g_param_spec_int ("selection-bound",
748 P_("Selection Bound"),
749 P_("The position of the opposite end of the selection from the cursor in chars"),
751 GTK_ENTRY_BUFFER_MAX_SIZE,
753 GTK_PARAM_READABLE));
755 g_object_class_install_property (gobject_class,
757 g_param_spec_boolean ("editable",
759 P_("Whether the entry contents can be edited"),
761 GTK_PARAM_READWRITE));
763 g_object_class_install_property (gobject_class,
765 g_param_spec_int ("max-length",
766 P_("Maximum length"),
767 P_("Maximum number of characters for this entry. Zero if no maximum"),
769 GTK_ENTRY_BUFFER_MAX_SIZE,
771 GTK_PARAM_READWRITE));
772 g_object_class_install_property (gobject_class,
774 g_param_spec_boolean ("visibility",
776 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
778 GTK_PARAM_READWRITE));
780 g_object_class_install_property (gobject_class,
782 g_param_spec_boolean ("has-frame",
784 P_("FALSE removes outside bevel from entry"),
786 GTK_PARAM_READWRITE));
788 g_object_class_install_property (gobject_class,
790 g_param_spec_boxed ("inner-border",
792 P_("Border between text and frame. Overrides the inner-border style property"),
794 GTK_PARAM_READWRITE));
796 g_object_class_install_property (gobject_class,
798 g_param_spec_unichar ("invisible-char",
799 P_("Invisible character"),
800 P_("The character to use when masking entry contents (in \"password mode\")"),
802 GTK_PARAM_READWRITE));
804 g_object_class_install_property (gobject_class,
805 PROP_ACTIVATES_DEFAULT,
806 g_param_spec_boolean ("activates-default",
807 P_("Activates default"),
808 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
810 GTK_PARAM_READWRITE));
811 g_object_class_install_property (gobject_class,
813 g_param_spec_int ("width-chars",
814 P_("Width in chars"),
815 P_("Number of characters to leave space for in the entry"),
819 GTK_PARAM_READWRITE));
821 g_object_class_install_property (gobject_class,
823 g_param_spec_int ("scroll-offset",
825 P_("Number of pixels of the entry scrolled off the screen to the left"),
829 GTK_PARAM_READABLE));
831 g_object_class_install_property (gobject_class,
833 g_param_spec_string ("text",
835 P_("The contents of the entry"),
837 GTK_PARAM_READWRITE));
842 * The horizontal alignment, from 0 (left) to 1 (right).
843 * Reversed for RTL layouts.
847 g_object_class_install_property (gobject_class,
849 g_param_spec_float ("xalign",
851 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
855 GTK_PARAM_READWRITE));
858 * GtkEntry:truncate-multiline:
860 * When %TRUE, pasted multi-line text is truncated to the first line.
864 g_object_class_install_property (gobject_class,
865 PROP_TRUNCATE_MULTILINE,
866 g_param_spec_boolean ("truncate-multiline",
867 P_("Truncate multiline"),
868 P_("Whether to truncate multiline pastes to one line."),
870 GTK_PARAM_READWRITE));
873 * GtkEntry:shadow-type:
875 * Which kind of shadow to draw around the entry when
876 * #GtkEntry:has-frame is set to %TRUE.
880 g_object_class_install_property (gobject_class,
882 g_param_spec_enum ("shadow-type",
884 P_("Which kind of shadow to draw around the entry when has-frame is set"),
885 GTK_TYPE_SHADOW_TYPE,
887 GTK_PARAM_READWRITE));
890 * GtkEntry:overwrite-mode:
892 * If text is overwritten when typing in the #GtkEntry.
896 g_object_class_install_property (gobject_class,
898 g_param_spec_boolean ("overwrite-mode",
899 P_("Overwrite mode"),
900 P_("Whether new text overwrites existing text"),
902 GTK_PARAM_READWRITE));
905 * GtkEntry:text-length:
907 * The length of the text in the #GtkEntry.
911 g_object_class_install_property (gobject_class,
913 g_param_spec_uint ("text-length",
915 P_("Length of the text currently in the entry"),
919 GTK_PARAM_READABLE));
921 * GtkEntry:invisible-char-set:
923 * Whether the invisible char has been set for the #GtkEntry.
927 g_object_class_install_property (gobject_class,
928 PROP_INVISIBLE_CHAR_SET,
929 g_param_spec_boolean ("invisible-char-set",
930 P_("Invisible character set"),
931 P_("Whether the invisible character has been set"),
933 GTK_PARAM_READWRITE));
936 * GtkEntry:caps-lock-warning
938 * Whether password entries will show a warning when Caps Lock is on.
940 * Note that the warning is shown using a secondary icon, and thus
941 * does not work if you are using the secondary icon position for some
946 g_object_class_install_property (gobject_class,
947 PROP_CAPS_LOCK_WARNING,
948 g_param_spec_boolean ("caps-lock-warning",
949 P_("Caps Lock warning"),
950 P_("Whether password entries will show a warning when Caps Lock is on"),
952 GTK_PARAM_READWRITE));
955 * GtkEntry:progress-fraction:
957 * The current fraction of the task that's been completed.
961 g_object_class_install_property (gobject_class,
962 PROP_PROGRESS_FRACTION,
963 g_param_spec_double ("progress-fraction",
964 P_("Progress Fraction"),
965 P_("The current fraction of the task that's been completed"),
969 GTK_PARAM_READWRITE));
972 * GtkEntry:progress-pulse-step:
974 * The fraction of total entry width to move the progress
975 * bouncing block for each call to gtk_entry_progress_pulse().
979 g_object_class_install_property (gobject_class,
980 PROP_PROGRESS_PULSE_STEP,
981 g_param_spec_double ("progress-pulse-step",
982 P_("Progress Pulse Step"),
983 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
987 GTK_PARAM_READWRITE));
990 * GtkEntry:placeholder-text:
992 * The text that will be displayed in the #GtkEntry when it is empty and unfocused.
996 g_object_class_install_property (gobject_class,
997 PROP_PLACEHOLDER_TEXT,
998 g_param_spec_string ("placeholder-text",
999 P_("Placeholder text"),
1000 P_("Show text in the entry when it's empty and unfocused"),
1002 GTK_PARAM_READWRITE));
1005 * GtkEntry:primary-icon-pixbuf:
1007 * A pixbuf to use as the primary icon for the entry.
1011 g_object_class_install_property (gobject_class,
1012 PROP_PIXBUF_PRIMARY,
1013 g_param_spec_object ("primary-icon-pixbuf",
1014 P_("Primary pixbuf"),
1015 P_("Primary pixbuf for the entry"),
1017 GTK_PARAM_READWRITE));
1020 * GtkEntry:secondary-icon-pixbuf:
1022 * An pixbuf to use as the secondary icon for the entry.
1026 g_object_class_install_property (gobject_class,
1027 PROP_PIXBUF_SECONDARY,
1028 g_param_spec_object ("secondary-icon-pixbuf",
1029 P_("Secondary pixbuf"),
1030 P_("Secondary pixbuf for the entry"),
1032 GTK_PARAM_READWRITE));
1035 * GtkEntry:primary-icon-stock:
1037 * The stock id to use for the primary icon for the entry.
1041 g_object_class_install_property (gobject_class,
1043 g_param_spec_string ("primary-icon-stock",
1044 P_("Primary stock ID"),
1045 P_("Stock ID for primary icon"),
1047 GTK_PARAM_READWRITE));
1050 * GtkEntry:secondary-icon-stock:
1052 * The stock id to use for the secondary icon for the entry.
1056 g_object_class_install_property (gobject_class,
1057 PROP_STOCK_SECONDARY,
1058 g_param_spec_string ("secondary-icon-stock",
1059 P_("Secondary stock ID"),
1060 P_("Stock ID for secondary icon"),
1062 GTK_PARAM_READWRITE));
1065 * GtkEntry:primary-icon-name:
1067 * The icon name to use for the primary icon for the entry.
1071 g_object_class_install_property (gobject_class,
1072 PROP_ICON_NAME_PRIMARY,
1073 g_param_spec_string ("primary-icon-name",
1074 P_("Primary icon name"),
1075 P_("Icon name for primary icon"),
1077 GTK_PARAM_READWRITE));
1080 * GtkEntry:secondary-icon-name:
1082 * The icon name to use for the secondary icon for the entry.
1086 g_object_class_install_property (gobject_class,
1087 PROP_ICON_NAME_SECONDARY,
1088 g_param_spec_string ("secondary-icon-name",
1089 P_("Secondary icon name"),
1090 P_("Icon name for secondary icon"),
1092 GTK_PARAM_READWRITE));
1095 * GtkEntry:primary-icon-gicon:
1097 * The #GIcon to use for the primary icon for the entry.
1101 g_object_class_install_property (gobject_class,
1103 g_param_spec_object ("primary-icon-gicon",
1104 P_("Primary GIcon"),
1105 P_("GIcon for primary icon"),
1107 GTK_PARAM_READWRITE));
1110 * GtkEntry:secondary-icon-gicon:
1112 * The #GIcon to use for the secondary icon for the entry.
1116 g_object_class_install_property (gobject_class,
1117 PROP_GICON_SECONDARY,
1118 g_param_spec_object ("secondary-icon-gicon",
1119 P_("Secondary GIcon"),
1120 P_("GIcon for secondary icon"),
1122 GTK_PARAM_READWRITE));
1125 * GtkEntry:primary-icon-storage-type:
1127 * The representation which is used for the primary icon of the entry.
1131 g_object_class_install_property (gobject_class,
1132 PROP_STORAGE_TYPE_PRIMARY,
1133 g_param_spec_enum ("primary-icon-storage-type",
1134 P_("Primary storage type"),
1135 P_("The representation being used for primary icon"),
1136 GTK_TYPE_IMAGE_TYPE,
1138 GTK_PARAM_READABLE));
1141 * GtkEntry:secondary-icon-storage-type:
1143 * The representation which is used for the secondary icon of the entry.
1147 g_object_class_install_property (gobject_class,
1148 PROP_STORAGE_TYPE_SECONDARY,
1149 g_param_spec_enum ("secondary-icon-storage-type",
1150 P_("Secondary storage type"),
1151 P_("The representation being used for secondary icon"),
1152 GTK_TYPE_IMAGE_TYPE,
1154 GTK_PARAM_READABLE));
1157 * GtkEntry:primary-icon-activatable:
1159 * Whether the primary icon is activatable.
1161 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1162 * signals only on sensitive, activatable icons.
1164 * Sensitive, but non-activatable icons can be used for purely
1165 * informational purposes.
1169 g_object_class_install_property (gobject_class,
1170 PROP_ACTIVATABLE_PRIMARY,
1171 g_param_spec_boolean ("primary-icon-activatable",
1172 P_("Primary icon activatable"),
1173 P_("Whether the primary icon is activatable"),
1175 GTK_PARAM_READWRITE));
1178 * GtkEntry:secondary-icon-activatable:
1180 * Whether the secondary icon is activatable.
1182 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1183 * signals only on sensitive, activatable icons.
1185 * Sensitive, but non-activatable icons can be used for purely
1186 * informational purposes.
1190 g_object_class_install_property (gobject_class,
1191 PROP_ACTIVATABLE_SECONDARY,
1192 g_param_spec_boolean ("secondary-icon-activatable",
1193 P_("Secondary icon activatable"),
1194 P_("Whether the secondary icon is activatable"),
1196 GTK_PARAM_READWRITE));
1200 * GtkEntry:primary-icon-sensitive:
1202 * Whether the primary icon is sensitive.
1204 * An insensitive icon appears grayed out. GTK+ does not emit the
1205 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1206 * does not allow DND from insensitive icons.
1208 * An icon should be set insensitive if the action that would trigger
1209 * when clicked is currently not available.
1213 g_object_class_install_property (gobject_class,
1214 PROP_SENSITIVE_PRIMARY,
1215 g_param_spec_boolean ("primary-icon-sensitive",
1216 P_("Primary icon sensitive"),
1217 P_("Whether the primary icon is sensitive"),
1219 GTK_PARAM_READWRITE));
1222 * GtkEntry:secondary-icon-sensitive:
1224 * Whether the secondary icon is sensitive.
1226 * An insensitive icon appears grayed out. GTK+ does not emit the
1227 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1228 * does not allow DND from insensitive icons.
1230 * An icon should be set insensitive if the action that would trigger
1231 * when clicked is currently not available.
1235 g_object_class_install_property (gobject_class,
1236 PROP_SENSITIVE_SECONDARY,
1237 g_param_spec_boolean ("secondary-icon-sensitive",
1238 P_("Secondary icon sensitive"),
1239 P_("Whether the secondary icon is sensitive"),
1241 GTK_PARAM_READWRITE));
1244 * GtkEntry:primary-icon-tooltip-text:
1246 * The contents of the tooltip on the primary icon.
1248 * Also see gtk_entry_set_icon_tooltip_text().
1252 g_object_class_install_property (gobject_class,
1253 PROP_TOOLTIP_TEXT_PRIMARY,
1254 g_param_spec_string ("primary-icon-tooltip-text",
1255 P_("Primary icon tooltip text"),
1256 P_("The contents of the tooltip on the primary icon"),
1258 GTK_PARAM_READWRITE));
1261 * GtkEntry:secondary-icon-tooltip-text:
1263 * The contents of the tooltip on the secondary icon.
1265 * Also see gtk_entry_set_icon_tooltip_text().
1269 g_object_class_install_property (gobject_class,
1270 PROP_TOOLTIP_TEXT_SECONDARY,
1271 g_param_spec_string ("secondary-icon-tooltip-text",
1272 P_("Secondary icon tooltip text"),
1273 P_("The contents of the tooltip on the secondary icon"),
1275 GTK_PARAM_READWRITE));
1278 * GtkEntry:primary-icon-tooltip-markup:
1280 * The contents of the tooltip on the primary icon, which is marked up
1281 * with the <link linkend="PangoMarkupFormat">Pango text markup
1284 * Also see gtk_entry_set_icon_tooltip_markup().
1288 g_object_class_install_property (gobject_class,
1289 PROP_TOOLTIP_MARKUP_PRIMARY,
1290 g_param_spec_string ("primary-icon-tooltip-markup",
1291 P_("Primary icon tooltip markup"),
1292 P_("The contents of the tooltip on the primary icon"),
1294 GTK_PARAM_READWRITE));
1297 * GtkEntry:secondary-icon-tooltip-markup:
1299 * The contents of the tooltip on the secondary icon, which is marked up
1300 * with the <link linkend="PangoMarkupFormat">Pango text markup
1303 * Also see gtk_entry_set_icon_tooltip_markup().
1307 g_object_class_install_property (gobject_class,
1308 PROP_TOOLTIP_MARKUP_SECONDARY,
1309 g_param_spec_string ("secondary-icon-tooltip-markup",
1310 P_("Secondary icon tooltip markup"),
1311 P_("The contents of the tooltip on the secondary icon"),
1313 GTK_PARAM_READWRITE));
1316 * GtkEntry:im-module:
1318 * Which IM (input method) module should be used for this entry.
1319 * See #GtkIMContext.
1321 * Setting this to a non-%NULL value overrides the
1322 * system-wide IM module setting. See the GtkSettings
1323 * #GtkSettings:gtk-im-module property.
1327 g_object_class_install_property (gobject_class,
1329 g_param_spec_string ("im-module",
1331 P_("Which IM module should be used"),
1333 GTK_PARAM_READWRITE));
1336 * GtkEntry:completion:
1338 * The auxiliary completion object to use with the entry.
1342 g_object_class_install_property (gobject_class,
1344 g_param_spec_object ("completion",
1346 P_("The auxiliary completion object"),
1347 GTK_TYPE_ENTRY_COMPLETION,
1348 GTK_PARAM_READWRITE));
1351 * GtkEntry:icon-prelight:
1353 * The prelight style property determines whether activatable
1354 * icons prelight on mouseover.
1358 gtk_widget_class_install_style_property (widget_class,
1359 g_param_spec_boolean ("icon-prelight",
1360 P_("Icon Prelight"),
1361 P_("Whether activatable icons should prelight when hovered"),
1363 GTK_PARAM_READABLE));
1366 * GtkEntry:progress-border:
1368 * The border around the progress bar in the entry.
1372 gtk_widget_class_install_style_property (widget_class,
1373 g_param_spec_boxed ("progress-border",
1374 P_("Progress Border"),
1375 P_("Border around the progress bar"),
1377 GTK_PARAM_READABLE));
1380 * GtkEntry:invisible-char:
1382 * The invisible character is used when masking entry contents (in
1383 * \"password mode\")"). When it is not explicitly set with the
1384 * #GtkEntry::invisible-char property, GTK+ determines the character
1385 * to use from a list of possible candidates, depending on availability
1386 * in the current font.
1388 * This style property allows the theme to prepend a character
1389 * to the list of candidates.
1393 gtk_widget_class_install_style_property (widget_class,
1394 g_param_spec_unichar ("invisible-char",
1395 P_("Invisible character"),
1396 P_("The character to use when masking entry contents (in \"password mode\")"),
1398 GTK_PARAM_READABLE));
1401 * GtkEntry::populate-popup:
1402 * @entry: The entry on which the signal is emitted
1403 * @menu: the menu that is being populated
1405 * The ::populate-popup signal gets emitted before showing the
1406 * context menu of the entry.
1408 * If you need to add items to the context menu, connect
1409 * to this signal and append your menuitems to the @menu.
1411 signals[POPULATE_POPUP] =
1412 g_signal_new (I_("populate-popup"),
1413 G_OBJECT_CLASS_TYPE (gobject_class),
1415 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1417 _gtk_marshal_VOID__OBJECT,
1421 /* Action signals */
1424 * GtkEntry::activate:
1425 * @entry: The entry on which the signal is emitted
1427 * A <link linkend="keybinding-signals">keybinding signal</link>
1428 * which gets emitted when the user activates the entry.
1430 * Applications should not connect to it, but may emit it with
1431 * g_signal_emit_by_name() if they need to control activation
1434 * The default bindings for this signal are all forms of the Enter key.
1437 g_signal_new (I_("activate"),
1438 G_OBJECT_CLASS_TYPE (gobject_class),
1439 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1440 G_STRUCT_OFFSET (GtkEntryClass, activate),
1442 _gtk_marshal_VOID__VOID,
1444 widget_class->activate_signal = signals[ACTIVATE];
1447 * GtkEntry::move-cursor:
1448 * @entry: the object which received the signal
1449 * @step: the granularity of the move, as a #GtkMovementStep
1450 * @count: the number of @step units to move
1451 * @extend_selection: %TRUE if the move should extend the selection
1453 * The ::move-cursor signal is a
1454 * <link linkend="keybinding-signals">keybinding signal</link>
1455 * which gets emitted when the user initiates a cursor movement.
1456 * If the cursor is not visible in @entry, this signal causes
1457 * the viewport to be moved instead.
1459 * Applications should not connect to it, but may emit it with
1460 * g_signal_emit_by_name() if they need to control the cursor
1463 * The default bindings for this signal come in two variants,
1464 * the variant with the Shift modifier extends the selection,
1465 * the variant without the Shift modifer does not.
1466 * There are too many key combinations to list them all here.
1468 * <listitem>Arrow keys move by individual characters/lines</listitem>
1469 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1470 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1473 signals[MOVE_CURSOR] =
1474 g_signal_new (I_("move-cursor"),
1475 G_OBJECT_CLASS_TYPE (gobject_class),
1476 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1477 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1479 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1481 GTK_TYPE_MOVEMENT_STEP,
1486 * GtkEntry::insert-at-cursor:
1487 * @entry: the object which received the signal
1488 * @string: the string to insert
1490 * The ::insert-at-cursor signal is a
1491 * <link linkend="keybinding-signals">keybinding signal</link>
1492 * which gets emitted when the user initiates the insertion of a
1493 * fixed string at the cursor.
1495 * This signal has no default bindings.
1497 signals[INSERT_AT_CURSOR] =
1498 g_signal_new (I_("insert-at-cursor"),
1499 G_OBJECT_CLASS_TYPE (gobject_class),
1500 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1501 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1503 _gtk_marshal_VOID__STRING,
1508 * GtkEntry::delete-from-cursor:
1509 * @entry: the object which received the signal
1510 * @type: the granularity of the deletion, as a #GtkDeleteType
1511 * @count: the number of @type units to delete
1513 * The ::delete-from-cursor signal is a
1514 * <link linkend="keybinding-signals">keybinding signal</link>
1515 * which gets emitted when the user initiates a text deletion.
1517 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1518 * if there is one, otherwise it deletes the requested number
1521 * The default bindings for this signal are
1522 * Delete for deleting a character and Ctrl-Delete for
1525 signals[DELETE_FROM_CURSOR] =
1526 g_signal_new (I_("delete-from-cursor"),
1527 G_OBJECT_CLASS_TYPE (gobject_class),
1528 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1529 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1531 _gtk_marshal_VOID__ENUM_INT,
1533 GTK_TYPE_DELETE_TYPE,
1537 * GtkEntry::backspace:
1538 * @entry: the object which received the signal
1540 * The ::backspace signal is a
1541 * <link linkend="keybinding-signals">keybinding signal</link>
1542 * which gets emitted when the user asks for it.
1544 * The default bindings for this signal are
1545 * Backspace and Shift-Backspace.
1547 signals[BACKSPACE] =
1548 g_signal_new (I_("backspace"),
1549 G_OBJECT_CLASS_TYPE (gobject_class),
1550 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1551 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1553 _gtk_marshal_VOID__VOID,
1557 * GtkEntry::cut-clipboard:
1558 * @entry: the object which received the signal
1560 * The ::cut-clipboard signal is a
1561 * <link linkend="keybinding-signals">keybinding signal</link>
1562 * which gets emitted to cut the selection to the clipboard.
1564 * The default bindings for this signal are
1565 * Ctrl-x and Shift-Delete.
1567 signals[CUT_CLIPBOARD] =
1568 g_signal_new (I_("cut-clipboard"),
1569 G_OBJECT_CLASS_TYPE (gobject_class),
1570 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1571 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1573 _gtk_marshal_VOID__VOID,
1577 * GtkEntry::copy-clipboard:
1578 * @entry: the object which received the signal
1580 * The ::copy-clipboard signal is a
1581 * <link linkend="keybinding-signals">keybinding signal</link>
1582 * which gets emitted to copy the selection to the clipboard.
1584 * The default bindings for this signal are
1585 * Ctrl-c and Ctrl-Insert.
1587 signals[COPY_CLIPBOARD] =
1588 g_signal_new (I_("copy-clipboard"),
1589 G_OBJECT_CLASS_TYPE (gobject_class),
1590 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1591 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1593 _gtk_marshal_VOID__VOID,
1597 * GtkEntry::paste-clipboard:
1598 * @entry: the object which received the signal
1600 * The ::paste-clipboard signal is a
1601 * <link linkend="keybinding-signals">keybinding signal</link>
1602 * which gets emitted to paste the contents of the clipboard
1603 * into the text view.
1605 * The default bindings for this signal are
1606 * Ctrl-v and Shift-Insert.
1608 signals[PASTE_CLIPBOARD] =
1609 g_signal_new (I_("paste-clipboard"),
1610 G_OBJECT_CLASS_TYPE (gobject_class),
1611 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1612 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1614 _gtk_marshal_VOID__VOID,
1618 * GtkEntry::toggle-overwrite:
1619 * @entry: the object which received the signal
1621 * The ::toggle-overwrite signal is a
1622 * <link linkend="keybinding-signals">keybinding signal</link>
1623 * which gets emitted to toggle the overwrite mode of the entry.
1625 * The default bindings for this signal is Insert.
1627 signals[TOGGLE_OVERWRITE] =
1628 g_signal_new (I_("toggle-overwrite"),
1629 G_OBJECT_CLASS_TYPE (gobject_class),
1630 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1631 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1633 _gtk_marshal_VOID__VOID,
1637 * GtkEntry::icon-press:
1638 * @entry: The entry on which the signal is emitted
1639 * @icon_pos: The position of the clicked icon
1640 * @event: (type Gdk.EventButton): the button press event
1642 * The ::icon-press signal is emitted when an activatable icon
1647 signals[ICON_PRESS] =
1648 g_signal_new (I_("icon-press"),
1649 G_TYPE_FROM_CLASS (gobject_class),
1653 _gtk_marshal_VOID__ENUM_BOXED,
1655 GTK_TYPE_ENTRY_ICON_POSITION,
1656 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1659 * GtkEntry::icon-release:
1660 * @entry: The entry on which the signal is emitted
1661 * @icon_pos: The position of the clicked icon
1662 * @event: (type Gdk.EventButton): the button release event
1664 * The ::icon-release signal is emitted on the button release from a
1665 * mouse click over an activatable icon.
1669 signals[ICON_RELEASE] =
1670 g_signal_new (I_("icon-release"),
1671 G_TYPE_FROM_CLASS (gobject_class),
1675 _gtk_marshal_VOID__ENUM_BOXED,
1677 GTK_TYPE_ENTRY_ICON_POSITION,
1678 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1681 * GtkEntry::preedit-changed:
1682 * @entry: the object which received the signal
1683 * @preedit: the current preedit string
1685 * If an input method is used, the typed text will not immediately
1686 * be committed to the buffer. So if you are interested in the text,
1687 * connect to this signal.
1691 signals[PREEDIT_CHANGED] =
1692 g_signal_new_class_handler (I_("preedit-changed"),
1693 G_OBJECT_CLASS_TYPE (gobject_class),
1694 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1697 _gtk_marshal_VOID__STRING,
1706 binding_set = gtk_binding_set_by_class (class);
1708 /* Moving the insertion point */
1709 add_move_binding (binding_set, GDK_KEY_Right, 0,
1710 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1712 add_move_binding (binding_set, GDK_KEY_Left, 0,
1713 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1715 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1716 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1718 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1719 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1721 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1722 GTK_MOVEMENT_WORDS, 1);
1724 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1725 GTK_MOVEMENT_WORDS, -1);
1727 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1728 GTK_MOVEMENT_WORDS, 1);
1730 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1731 GTK_MOVEMENT_WORDS, -1);
1733 add_move_binding (binding_set, GDK_KEY_Home, 0,
1734 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1736 add_move_binding (binding_set, GDK_KEY_End, 0,
1737 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1739 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1740 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1742 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1743 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1745 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1746 GTK_MOVEMENT_BUFFER_ENDS, -1);
1748 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1749 GTK_MOVEMENT_BUFFER_ENDS, 1);
1751 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1752 GTK_MOVEMENT_BUFFER_ENDS, -1);
1754 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1755 GTK_MOVEMENT_BUFFER_ENDS, 1);
1759 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1761 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1763 G_TYPE_BOOLEAN, FALSE);
1764 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1766 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1768 G_TYPE_BOOLEAN, TRUE);
1770 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1772 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1774 G_TYPE_BOOLEAN, FALSE);
1775 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1777 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1779 G_TYPE_BOOLEAN, TRUE);
1782 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1784 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1786 G_TYPE_BOOLEAN, FALSE);
1787 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1789 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1791 G_TYPE_BOOLEAN, FALSE);
1795 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1797 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1799 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1803 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1804 "delete-from-cursor", 2,
1805 G_TYPE_ENUM, GTK_DELETE_CHARS,
1808 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1809 "delete-from-cursor", 2,
1810 G_TYPE_ENUM, GTK_DELETE_CHARS,
1813 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1816 /* Make this do the same as Backspace, to help with mis-typing */
1817 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1821 "delete-from-cursor", 2,
1822 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1825 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1826 "delete-from-cursor", 2,
1827 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1830 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1831 "delete-from-cursor", 2,
1832 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1835 /* Cut/copy/paste */
1837 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1838 "cut-clipboard", 0);
1839 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1840 "copy-clipboard", 0);
1841 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1842 "paste-clipboard", 0);
1844 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1845 "cut-clipboard", 0);
1846 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1847 "copy-clipboard", 0);
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1849 "paste-clipboard", 0);
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1853 "toggle-overwrite", 0);
1854 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1855 "toggle-overwrite", 0);
1858 * GtkEntry:inner-border:
1860 * Sets the text area's border between the text and the frame.
1864 gtk_widget_class_install_style_property (widget_class,
1865 g_param_spec_boxed ("inner-border",
1867 P_("Border between text and frame."),
1869 GTK_PARAM_READABLE));
1871 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1875 gtk_entry_editable_init (GtkEditableInterface *iface)
1877 iface->do_insert_text = gtk_entry_insert_text;
1878 iface->do_delete_text = gtk_entry_delete_text;
1879 iface->insert_text = gtk_entry_real_insert_text;
1880 iface->delete_text = gtk_entry_real_delete_text;
1881 iface->get_chars = gtk_entry_get_chars;
1882 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1883 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1884 iface->set_position = gtk_entry_real_set_position;
1885 iface->get_position = gtk_entry_get_position;
1889 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1891 iface->start_editing = gtk_entry_start_editing;
1895 gtk_entry_set_property (GObject *object,
1897 const GValue *value,
1900 GtkEntry *entry = GTK_ENTRY (object);
1901 GtkEntryPrivate *priv = entry->priv;
1906 gtk_entry_set_buffer (entry, g_value_get_object (value));
1911 gboolean new_value = g_value_get_boolean (value);
1913 if (new_value != priv->editable)
1915 GtkWidget *widget = GTK_WIDGET (entry);
1919 _gtk_entry_reset_im_context (entry);
1920 if (gtk_widget_has_focus (widget))
1921 gtk_im_context_focus_out (priv->im_context);
1923 priv->preedit_length = 0;
1924 priv->preedit_cursor = 0;
1927 priv->editable = new_value;
1929 if (new_value && gtk_widget_has_focus (widget))
1930 gtk_im_context_focus_in (priv->im_context);
1932 gtk_widget_queue_draw (widget);
1937 case PROP_MAX_LENGTH:
1938 gtk_entry_set_max_length (entry, g_value_get_int (value));
1941 case PROP_VISIBILITY:
1942 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1945 case PROP_HAS_FRAME:
1946 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1949 case PROP_INNER_BORDER:
1950 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1953 case PROP_INVISIBLE_CHAR:
1954 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1957 case PROP_ACTIVATES_DEFAULT:
1958 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1961 case PROP_WIDTH_CHARS:
1962 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1966 gtk_entry_set_text (entry, g_value_get_string (value));
1970 gtk_entry_set_alignment (entry, g_value_get_float (value));
1973 case PROP_TRUNCATE_MULTILINE:
1974 priv->truncate_multiline = g_value_get_boolean (value);
1977 case PROP_SHADOW_TYPE:
1978 priv->shadow_type = g_value_get_enum (value);
1981 case PROP_OVERWRITE_MODE:
1982 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1985 case PROP_INVISIBLE_CHAR_SET:
1986 if (g_value_get_boolean (value))
1987 priv->invisible_char_set = TRUE;
1989 gtk_entry_unset_invisible_char (entry);
1992 case PROP_CAPS_LOCK_WARNING:
1993 priv->caps_lock_warning = g_value_get_boolean (value);
1996 case PROP_PROGRESS_FRACTION:
1997 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2000 case PROP_PROGRESS_PULSE_STEP:
2001 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2004 case PROP_PLACEHOLDER_TEXT:
2005 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2008 case PROP_PIXBUF_PRIMARY:
2009 gtk_entry_set_icon_from_pixbuf (entry,
2010 GTK_ENTRY_ICON_PRIMARY,
2011 g_value_get_object (value));
2014 case PROP_PIXBUF_SECONDARY:
2015 gtk_entry_set_icon_from_pixbuf (entry,
2016 GTK_ENTRY_ICON_SECONDARY,
2017 g_value_get_object (value));
2020 case PROP_STOCK_PRIMARY:
2021 gtk_entry_set_icon_from_stock (entry,
2022 GTK_ENTRY_ICON_PRIMARY,
2023 g_value_get_string (value));
2026 case PROP_STOCK_SECONDARY:
2027 gtk_entry_set_icon_from_stock (entry,
2028 GTK_ENTRY_ICON_SECONDARY,
2029 g_value_get_string (value));
2032 case PROP_ICON_NAME_PRIMARY:
2033 gtk_entry_set_icon_from_icon_name (entry,
2034 GTK_ENTRY_ICON_PRIMARY,
2035 g_value_get_string (value));
2038 case PROP_ICON_NAME_SECONDARY:
2039 gtk_entry_set_icon_from_icon_name (entry,
2040 GTK_ENTRY_ICON_SECONDARY,
2041 g_value_get_string (value));
2044 case PROP_GICON_PRIMARY:
2045 gtk_entry_set_icon_from_gicon (entry,
2046 GTK_ENTRY_ICON_PRIMARY,
2047 g_value_get_object (value));
2050 case PROP_GICON_SECONDARY:
2051 gtk_entry_set_icon_from_gicon (entry,
2052 GTK_ENTRY_ICON_SECONDARY,
2053 g_value_get_object (value));
2056 case PROP_ACTIVATABLE_PRIMARY:
2057 gtk_entry_set_icon_activatable (entry,
2058 GTK_ENTRY_ICON_PRIMARY,
2059 g_value_get_boolean (value));
2062 case PROP_ACTIVATABLE_SECONDARY:
2063 gtk_entry_set_icon_activatable (entry,
2064 GTK_ENTRY_ICON_SECONDARY,
2065 g_value_get_boolean (value));
2068 case PROP_SENSITIVE_PRIMARY:
2069 gtk_entry_set_icon_sensitive (entry,
2070 GTK_ENTRY_ICON_PRIMARY,
2071 g_value_get_boolean (value));
2074 case PROP_SENSITIVE_SECONDARY:
2075 gtk_entry_set_icon_sensitive (entry,
2076 GTK_ENTRY_ICON_SECONDARY,
2077 g_value_get_boolean (value));
2080 case PROP_TOOLTIP_TEXT_PRIMARY:
2081 gtk_entry_set_icon_tooltip_text (entry,
2082 GTK_ENTRY_ICON_PRIMARY,
2083 g_value_get_string (value));
2086 case PROP_TOOLTIP_TEXT_SECONDARY:
2087 gtk_entry_set_icon_tooltip_text (entry,
2088 GTK_ENTRY_ICON_SECONDARY,
2089 g_value_get_string (value));
2092 case PROP_TOOLTIP_MARKUP_PRIMARY:
2093 gtk_entry_set_icon_tooltip_markup (entry,
2094 GTK_ENTRY_ICON_PRIMARY,
2095 g_value_get_string (value));
2098 case PROP_TOOLTIP_MARKUP_SECONDARY:
2099 gtk_entry_set_icon_tooltip_markup (entry,
2100 GTK_ENTRY_ICON_SECONDARY,
2101 g_value_get_string (value));
2104 case PROP_IM_MODULE:
2105 g_free (priv->im_module);
2106 priv->im_module = g_value_dup_string (value);
2107 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2108 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2111 case PROP_EDITING_CANCELED:
2112 priv->editing_canceled = g_value_get_boolean (value);
2115 case PROP_COMPLETION:
2116 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2119 case PROP_SCROLL_OFFSET:
2120 case PROP_CURSOR_POSITION:
2122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2128 gtk_entry_get_property (GObject *object,
2133 GtkEntry *entry = GTK_ENTRY (object);
2134 GtkEntryPrivate *priv = entry->priv;
2139 g_value_set_object (value, gtk_entry_get_buffer (entry));
2142 case PROP_CURSOR_POSITION:
2143 g_value_set_int (value, priv->current_pos);
2146 case PROP_SELECTION_BOUND:
2147 g_value_set_int (value, priv->selection_bound);
2151 g_value_set_boolean (value, priv->editable);
2154 case PROP_MAX_LENGTH:
2155 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2158 case PROP_VISIBILITY:
2159 g_value_set_boolean (value, priv->visible);
2162 case PROP_HAS_FRAME:
2163 g_value_set_boolean (value, priv->has_frame);
2166 case PROP_INNER_BORDER:
2167 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2170 case PROP_INVISIBLE_CHAR:
2171 g_value_set_uint (value, priv->invisible_char);
2174 case PROP_ACTIVATES_DEFAULT:
2175 g_value_set_boolean (value, priv->activates_default);
2178 case PROP_WIDTH_CHARS:
2179 g_value_set_int (value, priv->width_chars);
2182 case PROP_SCROLL_OFFSET:
2183 g_value_set_int (value, priv->scroll_offset);
2187 g_value_set_string (value, gtk_entry_get_text (entry));
2191 g_value_set_float (value, gtk_entry_get_alignment (entry));
2194 case PROP_TRUNCATE_MULTILINE:
2195 g_value_set_boolean (value, priv->truncate_multiline);
2198 case PROP_SHADOW_TYPE:
2199 g_value_set_enum (value, priv->shadow_type);
2202 case PROP_OVERWRITE_MODE:
2203 g_value_set_boolean (value, priv->overwrite_mode);
2206 case PROP_TEXT_LENGTH:
2207 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2210 case PROP_INVISIBLE_CHAR_SET:
2211 g_value_set_boolean (value, priv->invisible_char_set);
2214 case PROP_IM_MODULE:
2215 g_value_set_string (value, priv->im_module);
2218 case PROP_CAPS_LOCK_WARNING:
2219 g_value_set_boolean (value, priv->caps_lock_warning);
2222 case PROP_PROGRESS_FRACTION:
2223 g_value_set_double (value, priv->progress_fraction);
2226 case PROP_PROGRESS_PULSE_STEP:
2227 g_value_set_double (value, priv->progress_pulse_fraction);
2230 case PROP_PLACEHOLDER_TEXT:
2231 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2234 case PROP_PIXBUF_PRIMARY:
2235 g_value_set_object (value,
2236 gtk_entry_get_icon_pixbuf (entry,
2237 GTK_ENTRY_ICON_PRIMARY));
2240 case PROP_PIXBUF_SECONDARY:
2241 g_value_set_object (value,
2242 gtk_entry_get_icon_pixbuf (entry,
2243 GTK_ENTRY_ICON_SECONDARY));
2246 case PROP_STOCK_PRIMARY:
2247 g_value_set_string (value,
2248 gtk_entry_get_icon_stock (entry,
2249 GTK_ENTRY_ICON_PRIMARY));
2252 case PROP_STOCK_SECONDARY:
2253 g_value_set_string (value,
2254 gtk_entry_get_icon_stock (entry,
2255 GTK_ENTRY_ICON_SECONDARY));
2258 case PROP_ICON_NAME_PRIMARY:
2259 g_value_set_string (value,
2260 gtk_entry_get_icon_name (entry,
2261 GTK_ENTRY_ICON_PRIMARY));
2264 case PROP_ICON_NAME_SECONDARY:
2265 g_value_set_string (value,
2266 gtk_entry_get_icon_name (entry,
2267 GTK_ENTRY_ICON_SECONDARY));
2270 case PROP_GICON_PRIMARY:
2271 g_value_set_object (value,
2272 gtk_entry_get_icon_gicon (entry,
2273 GTK_ENTRY_ICON_PRIMARY));
2276 case PROP_GICON_SECONDARY:
2277 g_value_set_object (value,
2278 gtk_entry_get_icon_gicon (entry,
2279 GTK_ENTRY_ICON_SECONDARY));
2282 case PROP_STORAGE_TYPE_PRIMARY:
2283 g_value_set_enum (value,
2284 gtk_entry_get_icon_storage_type (entry,
2285 GTK_ENTRY_ICON_PRIMARY));
2288 case PROP_STORAGE_TYPE_SECONDARY:
2289 g_value_set_enum (value,
2290 gtk_entry_get_icon_storage_type (entry,
2291 GTK_ENTRY_ICON_SECONDARY));
2294 case PROP_ACTIVATABLE_PRIMARY:
2295 g_value_set_boolean (value,
2296 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2299 case PROP_ACTIVATABLE_SECONDARY:
2300 g_value_set_boolean (value,
2301 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2304 case PROP_SENSITIVE_PRIMARY:
2305 g_value_set_boolean (value,
2306 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2309 case PROP_SENSITIVE_SECONDARY:
2310 g_value_set_boolean (value,
2311 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2314 case PROP_TOOLTIP_TEXT_PRIMARY:
2315 g_value_take_string (value,
2316 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2319 case PROP_TOOLTIP_TEXT_SECONDARY:
2320 g_value_take_string (value,
2321 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2324 case PROP_TOOLTIP_MARKUP_PRIMARY:
2325 g_value_take_string (value,
2326 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2329 case PROP_TOOLTIP_MARKUP_SECONDARY:
2330 g_value_take_string (value,
2331 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2334 case PROP_EDITING_CANCELED:
2335 g_value_set_boolean (value,
2336 priv->editing_canceled);
2339 case PROP_COMPLETION:
2340 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2344 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2350 find_invisible_char (GtkWidget *widget)
2352 PangoLayout *layout;
2353 PangoAttrList *attr_list;
2355 gunichar invisible_chars [] = {
2357 0x25cf, /* BLACK CIRCLE */
2358 0x2022, /* BULLET */
2359 0x2731, /* HEAVY ASTERISK */
2360 0x273a /* SIXTEEN POINTED ASTERISK */
2363 gtk_widget_style_get (widget,
2364 "invisible-char", &invisible_chars[0],
2367 layout = gtk_widget_create_pango_layout (widget, NULL);
2369 attr_list = pango_attr_list_new ();
2370 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2372 pango_layout_set_attributes (layout, attr_list);
2373 pango_attr_list_unref (attr_list);
2375 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2377 gchar text[7] = { 0, };
2380 len = g_unichar_to_utf8 (invisible_chars[i], text);
2381 pango_layout_set_text (layout, text, len);
2383 count = pango_layout_get_unknown_glyphs_count (layout);
2387 g_object_unref (layout);
2388 return invisible_chars[i];
2392 g_object_unref (layout);
2398 gtk_entry_init (GtkEntry *entry)
2400 GtkStyleContext *context;
2401 GtkEntryPrivate *priv;
2403 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2408 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2409 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2411 priv->editable = TRUE;
2412 priv->visible = TRUE;
2413 priv->dnd_position = -1;
2414 priv->width_chars = -1;
2415 priv->is_cell_renderer = FALSE;
2416 priv->editing_canceled = FALSE;
2417 priv->has_frame = TRUE;
2418 priv->truncate_multiline = FALSE;
2419 priv->shadow_type = GTK_SHADOW_IN;
2421 priv->caps_lock_warning = TRUE;
2422 priv->caps_lock_warning_shown = FALSE;
2423 priv->progress_fraction = 0.0;
2424 priv->progress_pulse_fraction = 0.1;
2426 gtk_drag_dest_set (GTK_WIDGET (entry),
2427 GTK_DEST_DEFAULT_HIGHLIGHT,
2429 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2430 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2432 /* This object is completely private. No external entity can gain a reference
2433 * to it; so we create it here and destroy it in finalize().
2435 priv->im_context = gtk_im_multicontext_new ();
2437 g_signal_connect (priv->im_context, "commit",
2438 G_CALLBACK (gtk_entry_commit_cb), entry);
2439 g_signal_connect (priv->im_context, "preedit-changed",
2440 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2441 g_signal_connect (priv->im_context, "retrieve-surrounding",
2442 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2443 g_signal_connect (priv->im_context, "delete-surrounding",
2444 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2446 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2447 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2449 gtk_entry_update_cached_style_values (entry);
2453 get_icon_width (GtkEntry *entry,
2454 GtkEntryIconPosition icon_pos)
2456 GtkEntryPrivate *priv = entry->priv;
2457 EntryIconInfo *icon_info = priv->icons[icon_pos];
2459 GtkSettings *settings;
2460 gint menu_icon_width;
2462 if (!icon_info || icon_info->pixbuf == NULL)
2465 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2466 settings = gtk_settings_get_for_screen (screen);
2468 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2469 &menu_icon_width, NULL);
2471 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2475 get_icon_allocations (GtkEntry *entry,
2476 GtkAllocation *primary,
2477 GtkAllocation *secondary)
2480 GtkEntryPrivate *priv = entry->priv;
2481 gint x, y, width, height;
2483 get_text_area_size (entry, &x, &y, &width, &height);
2485 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2486 y += priv->focus_width;
2489 primary->height = height;
2490 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2491 if (primary->width > 0)
2492 primary->width += 2 * priv->icon_margin;
2495 secondary->height = height;
2496 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2497 if (secondary->width > 0)
2498 secondary->width += 2 * priv->icon_margin;
2500 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2502 primary->x = x + width - primary->width;
2508 secondary->x = x + width - secondary->width;
2514 begin_change (GtkEntry *entry)
2516 GtkEntryPrivate *priv = entry->priv;
2518 priv->change_count++;
2522 end_change (GtkEntry *entry)
2524 GtkEditable *editable = GTK_EDITABLE (entry);
2525 GtkEntryPrivate *priv = entry->priv;
2527 g_return_if_fail (priv->change_count > 0);
2529 priv->change_count--;
2531 if (priv->change_count == 0)
2533 if (priv->real_changed)
2535 g_signal_emit_by_name (editable, "changed");
2536 priv->real_changed = FALSE;
2542 emit_changed (GtkEntry *entry)
2544 GtkEditable *editable = GTK_EDITABLE (entry);
2545 GtkEntryPrivate *priv = entry->priv;
2547 if (priv->change_count == 0)
2548 g_signal_emit_by_name (editable, "changed");
2550 priv->real_changed = TRUE;
2554 gtk_entry_destroy (GtkWidget *widget)
2556 GtkEntry *entry = GTK_ENTRY (widget);
2557 GtkEntryPrivate *priv = entry->priv;
2559 priv->current_pos = priv->selection_bound = 0;
2560 _gtk_entry_reset_im_context (entry);
2561 gtk_entry_reset_layout (entry);
2563 if (priv->blink_timeout)
2565 g_source_remove (priv->blink_timeout);
2566 priv->blink_timeout = 0;
2569 if (priv->recompute_idle)
2571 g_source_remove (priv->recompute_idle);
2572 priv->recompute_idle = 0;
2575 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2579 gtk_entry_dispose (GObject *object)
2581 GtkEntry *entry = GTK_ENTRY (object);
2582 GtkEntryPrivate *priv = entry->priv;
2585 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2586 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2587 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2588 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2592 buffer_disconnect_signals (entry);
2593 g_object_unref (priv->buffer);
2594 priv->buffer = NULL;
2597 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2598 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2599 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2600 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2604 gtk_entry_finalize (GObject *object)
2606 GtkEntry *entry = GTK_ENTRY (object);
2607 GtkEntryPrivate *priv = entry->priv;
2608 EntryIconInfo *icon_info = NULL;
2611 for (i = 0; i < MAX_ICONS; i++)
2613 if ((icon_info = priv->icons[i]) != NULL)
2615 if (icon_info->target_list != NULL)
2617 gtk_target_list_unref (icon_info->target_list);
2618 icon_info->target_list = NULL;
2621 g_slice_free (EntryIconInfo, icon_info);
2622 priv->icons[i] = NULL;
2626 gtk_entry_set_completion (entry, NULL);
2628 if (priv->cached_layout)
2629 g_object_unref (priv->cached_layout);
2631 g_object_unref (priv->im_context);
2633 if (priv->blink_timeout)
2634 g_source_remove (priv->blink_timeout);
2636 if (priv->recompute_idle)
2637 g_source_remove (priv->recompute_idle);
2639 g_free (priv->placeholder_text);
2640 g_free (priv->im_module);
2642 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2646 gtk_entry_get_display_mode (GtkEntry *entry)
2648 GtkEntryPrivate *priv = entry->priv;
2651 return DISPLAY_NORMAL;
2653 if (priv->invisible_char == 0 && priv->invisible_char_set)
2654 return DISPLAY_BLANK;
2656 return DISPLAY_INVISIBLE;
2660 gtk_entry_get_display_text (GtkEntry *entry,
2664 GtkEntryPasswordHint *password_hint;
2665 GtkEntryPrivate *priv;
2666 gunichar invisible_char;
2677 text = gtk_entry_buffer_get_text (get_buffer (entry));
2678 length = gtk_entry_buffer_get_length (get_buffer (entry));
2682 if (start_pos > length)
2685 if (end_pos <= start_pos)
2686 return g_strdup ("");
2687 else if (priv->visible)
2689 start = g_utf8_offset_to_pointer (text, start_pos);
2690 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2691 return g_strndup (start, end - start);
2695 str = g_string_sized_new (length * 2);
2697 /* Figure out what our invisible char is and encode it */
2698 if (!priv->invisible_char)
2699 invisible_char = priv->invisible_char_set ? ' ' : '*';
2701 invisible_char = priv->invisible_char;
2702 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2705 * Add hidden characters for each character in the text
2706 * buffer. If there is a password hint, then keep that
2707 * character visible.
2710 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2711 for (i = start_pos; i < end_pos; ++i)
2713 if (password_hint && i == password_hint->position)
2715 start = g_utf8_offset_to_pointer (text, i);
2716 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2720 g_string_append_len (str, char_str, char_len);
2724 return g_string_free (str, FALSE);
2729 update_cursors (GtkWidget *widget)
2731 GtkEntry *entry = GTK_ENTRY (widget);
2732 GtkEntryPrivate *priv = entry->priv;
2733 EntryIconInfo *icon_info = NULL;
2734 GdkDisplay *display;
2738 for (i = 0; i < MAX_ICONS; i++)
2740 if ((icon_info = priv->icons[i]) != NULL)
2742 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2743 gdk_window_show_unraised (icon_info->window);
2745 /* The icon windows are not children of the visible entry window,
2746 * thus we can't just inherit the xterm cursor. Slight complication
2747 * here is that for the entry, insensitive => arrow cursor, but for
2748 * an icon in a sensitive entry, insensitive => xterm cursor.
2750 if (gtk_widget_is_sensitive (widget) &&
2751 (icon_info->insensitive ||
2752 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2754 display = gtk_widget_get_display (widget);
2755 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2756 gdk_window_set_cursor (icon_info->window, cursor);
2757 g_object_unref (cursor);
2761 gdk_window_set_cursor (icon_info->window, NULL);
2768 realize_icon_info (GtkWidget *widget,
2769 GtkEntryIconPosition icon_pos)
2771 GtkEntry *entry = GTK_ENTRY (widget);
2772 GtkEntryPrivate *priv = entry->priv;
2773 EntryIconInfo *icon_info = priv->icons[icon_pos];
2774 GdkWindowAttr attributes;
2775 gint attributes_mask;
2777 g_return_if_fail (icon_info != NULL);
2781 attributes.width = 1;
2782 attributes.height = 1;
2783 attributes.window_type = GDK_WINDOW_CHILD;
2784 attributes.wclass = GDK_INPUT_ONLY;
2785 attributes.event_mask = gtk_widget_get_events (widget);
2786 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2787 GDK_BUTTON_RELEASE_MASK |
2788 GDK_BUTTON1_MOTION_MASK |
2789 GDK_BUTTON3_MOTION_MASK |
2790 GDK_POINTER_MOTION_HINT_MASK |
2791 GDK_POINTER_MOTION_MASK |
2792 GDK_ENTER_NOTIFY_MASK |
2793 GDK_LEAVE_NOTIFY_MASK);
2794 attributes_mask = GDK_WA_X | GDK_WA_Y;
2796 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2799 gdk_window_set_user_data (icon_info->window, widget);
2801 gtk_widget_queue_resize (widget);
2804 static EntryIconInfo*
2805 construct_icon_info (GtkWidget *widget,
2806 GtkEntryIconPosition icon_pos)
2808 GtkEntry *entry = GTK_ENTRY (widget);
2809 GtkEntryPrivate *priv = entry->priv;
2810 EntryIconInfo *icon_info;
2812 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2814 icon_info = g_slice_new0 (EntryIconInfo);
2815 priv->icons[icon_pos] = icon_info;
2817 if (gtk_widget_get_realized (widget))
2818 realize_icon_info (widget, icon_pos);
2824 gtk_entry_map (GtkWidget *widget)
2826 GtkEntry *entry = GTK_ENTRY (widget);
2827 GtkEntryPrivate *priv = entry->priv;
2828 EntryIconInfo *icon_info = NULL;
2831 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2833 gdk_window_show (priv->text_area);
2835 for (i = 0; i < MAX_ICONS; i++)
2837 if ((icon_info = priv->icons[i]) != NULL)
2839 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2840 gdk_window_show (icon_info->window);
2844 update_cursors (widget);
2848 gtk_entry_unmap (GtkWidget *widget)
2850 GtkEntry *entry = GTK_ENTRY (widget);
2851 GtkEntryPrivate *priv = entry->priv;
2852 EntryIconInfo *icon_info = NULL;
2855 for (i = 0; i < MAX_ICONS; i++)
2857 if ((icon_info = priv->icons[i]) != NULL)
2859 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2860 gdk_window_hide (icon_info->window);
2864 gdk_window_hide (priv->text_area);
2866 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2870 gtk_entry_realize (GtkWidget *widget)
2873 GtkEntryPrivate *priv;
2874 EntryIconInfo *icon_info;
2876 GdkWindowAttr attributes;
2877 gint attributes_mask;
2878 gint frame_x, frame_y;
2881 gtk_widget_set_realized (widget, TRUE);
2882 window = gtk_widget_get_parent_window (widget);
2883 gtk_widget_set_window (widget, window);
2884 g_object_ref (window);
2886 entry = GTK_ENTRY (widget);
2889 attributes.window_type = GDK_WINDOW_CHILD;
2890 attributes.wclass = GDK_INPUT_ONLY;
2891 attributes.event_mask = gtk_widget_get_events (widget);
2892 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2893 GDK_BUTTON_RELEASE_MASK |
2894 GDK_BUTTON1_MOTION_MASK |
2895 GDK_BUTTON3_MOTION_MASK |
2896 GDK_POINTER_MOTION_HINT_MASK |
2897 GDK_POINTER_MOTION_MASK |
2898 GDK_ENTER_NOTIFY_MASK |
2899 GDK_LEAVE_NOTIFY_MASK);
2900 attributes_mask = GDK_WA_X | GDK_WA_Y;
2902 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2904 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2905 attributes.x += frame_x;
2906 attributes.y += frame_y;
2908 if (gtk_widget_is_sensitive (widget))
2910 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2911 attributes_mask |= GDK_WA_CURSOR;
2914 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2918 gdk_window_set_user_data (priv->text_area, entry);
2920 if (attributes_mask & GDK_WA_CURSOR)
2921 g_object_unref (attributes.cursor);
2923 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2925 gtk_entry_adjust_scroll (entry);
2926 gtk_entry_update_primary_selection (entry);
2929 /* If the icon positions are already setup, create their windows.
2930 * Otherwise if they don't exist yet, then construct_icon_info()
2931 * will create the windows once the widget is already realized.
2933 for (i = 0; i < MAX_ICONS; i++)
2935 if ((icon_info = priv->icons[i]) != NULL)
2937 if (icon_info->window == NULL)
2938 realize_icon_info (widget, i);
2944 gtk_entry_unrealize (GtkWidget *widget)
2946 GtkEntry *entry = GTK_ENTRY (widget);
2947 GtkEntryPrivate *priv = entry->priv;
2948 GtkClipboard *clipboard;
2949 EntryIconInfo *icon_info;
2952 gtk_entry_reset_layout (entry);
2954 gtk_im_context_set_client_window (priv->im_context, NULL);
2956 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2957 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2958 gtk_clipboard_clear (clipboard);
2960 if (priv->text_area)
2962 gdk_window_set_user_data (priv->text_area, NULL);
2963 gdk_window_destroy (priv->text_area);
2964 priv->text_area = NULL;
2967 if (priv->popup_menu)
2969 gtk_widget_destroy (priv->popup_menu);
2970 priv->popup_menu = NULL;
2973 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2975 for (i = 0; i < MAX_ICONS; i++)
2977 if ((icon_info = priv->icons[i]) != NULL)
2979 if (icon_info->window != NULL)
2981 gdk_window_destroy (icon_info->window);
2982 icon_info->window = NULL;
2989 _gtk_entry_get_borders (GtkEntry *entry,
2993 GtkEntryPrivate *priv = entry->priv;
2994 GtkWidget *widget = GTK_WIDGET (entry);
2996 if (priv->has_frame)
2998 GtkStyleContext *context;
3001 context = gtk_widget_get_style_context (widget);
3002 gtk_style_context_get_padding (context, 0, &padding);
3004 *xborder = padding.left;
3005 *yborder = padding.top;
3013 if (!priv->interior_focus)
3015 *xborder += priv->focus_width;
3016 *yborder += priv->focus_width;
3021 gtk_entry_get_preferred_width (GtkWidget *widget,
3025 GtkEntry *entry = GTK_ENTRY (widget);
3026 GtkEntryPrivate *priv = entry->priv;
3027 PangoFontMetrics *metrics;
3028 gint xborder, yborder;
3029 GtkBorder inner_border;
3030 PangoContext *context;
3031 GtkStyleContext *style_context;
3032 GtkStateFlags state;
3033 gint icon_widths = 0;
3037 context = gtk_widget_get_pango_context (widget);
3039 style_context = gtk_widget_get_style_context (widget);
3040 state = gtk_widget_get_state_flags (widget);
3042 metrics = pango_context_get_metrics (context,
3043 gtk_style_context_get_font (style_context, state),
3044 pango_context_get_language (context));
3046 _gtk_entry_get_borders (entry, &xborder, &yborder);
3047 _gtk_entry_effective_inner_border (entry, &inner_border);
3049 if (priv->width_chars < 0)
3050 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3053 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3054 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3055 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3057 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3060 for (i = 0; i < MAX_ICONS; i++)
3062 icon_width = get_icon_width (entry, i);
3064 icon_widths += icon_width + 2 * priv->icon_margin;
3067 if (icon_widths > width)
3068 width += icon_widths;
3070 pango_font_metrics_unref (metrics);
3077 gtk_entry_get_preferred_height (GtkWidget *widget,
3081 GtkEntry *entry = GTK_ENTRY (widget);
3082 GtkEntryPrivate *priv = entry->priv;
3083 PangoFontMetrics *metrics;
3084 gint xborder, yborder;
3085 GtkBorder inner_border;
3086 GtkStyleContext *style_context;
3087 GtkStateFlags state;
3088 PangoContext *context;
3091 context = gtk_widget_get_pango_context (widget);
3093 style_context = gtk_widget_get_style_context (widget);
3094 state = gtk_widget_get_state_flags (widget);
3096 metrics = pango_context_get_metrics (context,
3097 gtk_style_context_get_font (style_context, state),
3098 pango_context_get_language (context));
3100 priv->ascent = pango_font_metrics_get_ascent (metrics);
3101 priv->descent = pango_font_metrics_get_descent (metrics);
3103 _gtk_entry_get_borders (entry, &xborder, &yborder);
3104 _gtk_entry_effective_inner_border (entry, &inner_border);
3106 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3108 pango_font_metrics_unref (metrics);
3115 place_windows (GtkEntry *entry)
3117 GtkWidget *widget = GTK_WIDGET (entry);
3118 GtkEntryPrivate *priv = entry->priv;
3119 gint x, y, width, height;
3120 gint frame_x, frame_y;
3121 GtkAllocation primary;
3122 GtkAllocation secondary;
3123 EntryIconInfo *icon_info = NULL;
3125 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3126 get_text_area_size (entry, &x, &y, &width, &height);
3127 get_icon_allocations (entry, &primary, &secondary);
3129 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3130 y += priv->focus_width;
3132 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3133 x += secondary.width;
3136 width -= primary.width + secondary.width;
3140 primary.x += frame_x;
3141 primary.y += frame_y;
3142 secondary.x += frame_x;
3143 secondary.y += frame_y;
3145 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3146 gdk_window_move_resize (icon_info->window,
3147 primary.x, primary.y,
3148 primary.width, primary.height);
3150 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3151 gdk_window_move_resize (icon_info->window,
3152 secondary.x, secondary.y,
3153 secondary.width, secondary.height);
3155 gdk_window_move_resize (priv->text_area, x, y, width, height);
3159 gtk_entry_get_text_area_size (GtkEntry *entry,
3165 GtkEntryPrivate *priv = entry->priv;
3166 GtkWidget *widget = GTK_WIDGET (entry);
3167 GtkAllocation allocation;
3168 GtkRequisition requisition;
3170 gint xborder, yborder;
3172 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3173 gtk_widget_get_allocation (widget, &allocation);
3174 _gtk_entry_get_borders (entry, &xborder, &yborder);
3176 if (gtk_widget_get_realized (widget))
3177 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3179 frame_height = requisition.height;
3181 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3182 frame_height -= 2 * priv->focus_width;
3188 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3191 *width = allocation.width - xborder * 2;
3194 *height = requisition.height - yborder * 2;
3198 get_text_area_size (GtkEntry *entry,
3204 GtkEntryClass *class;
3206 g_return_if_fail (GTK_IS_ENTRY (entry));
3208 class = GTK_ENTRY_GET_CLASS (entry);
3210 if (class->get_text_area_size)
3211 class->get_text_area_size (entry, x, y, width, height);
3216 get_frame_size (GtkEntry *entry,
3217 gboolean relative_to_window,
3223 GtkEntryPrivate *priv = entry->priv;
3224 GtkAllocation allocation;
3225 GtkRequisition requisition;
3226 GtkWidget *widget = GTK_WIDGET (entry);
3228 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3229 gtk_widget_get_allocation (widget, &allocation);
3232 *x = relative_to_window ? allocation.x : 0;
3236 if (priv->is_cell_renderer)
3239 *y = (allocation.height - requisition.height) / 2;
3241 if (relative_to_window)
3246 *width = allocation.width;
3250 if (priv->is_cell_renderer)
3251 *height = allocation.height;
3253 *height = requisition.height;
3258 _gtk_entry_effective_inner_border (GtkEntry *entry,
3261 GtkBorder *tmp_border;
3263 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3267 *border = *tmp_border;
3271 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3275 *border = *tmp_border;
3276 gtk_border_free (tmp_border);
3280 *border = default_inner_border;
3284 gtk_entry_size_allocate (GtkWidget *widget,
3285 GtkAllocation *allocation)
3287 GtkEntry *entry = GTK_ENTRY (widget);
3289 gtk_widget_set_allocation (widget, allocation);
3291 if (gtk_widget_get_realized (widget))
3293 GtkEntryCompletion* completion;
3295 place_windows (entry);
3296 gtk_entry_recompute (entry);
3298 completion = gtk_entry_get_completion (entry);
3299 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3300 _gtk_entry_completion_resize_popup (completion);
3305 should_prelight (GtkEntry *entry,
3306 GtkEntryIconPosition icon_pos)
3308 GtkEntryPrivate *priv = entry->priv;
3309 EntryIconInfo *icon_info = priv->icons[icon_pos];
3315 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3318 if (icon_info->pressed)
3321 gtk_widget_style_get (GTK_WIDGET (entry),
3322 "icon-prelight", &prelight,
3329 draw_icon (GtkWidget *widget,
3331 GtkEntryIconPosition icon_pos)
3333 GtkEntry *entry = GTK_ENTRY (widget);
3334 GtkEntryPrivate *priv = entry->priv;
3335 EntryIconInfo *icon_info = priv->icons[icon_pos];
3337 gint x, y, width, height;
3338 GtkStyleContext *context;
3339 GtkIconSource *icon_source;
3340 GtkStateFlags state;
3345 gtk_entry_ensure_pixbuf (entry, icon_pos);
3347 if (icon_info->pixbuf == NULL)
3350 width = gdk_window_get_width (icon_info->window);
3351 height = gdk_window_get_height (icon_info->window);
3353 /* size_allocate hasn't been called yet. These are the default values.
3355 if (width == 1 || height == 1)
3358 pixbuf = icon_info->pixbuf;
3359 g_object_ref (pixbuf);
3361 if (gdk_pixbuf_get_height (pixbuf) > height)
3363 GdkPixbuf *temp_pixbuf;
3366 scale = height - 2 * priv->icon_margin;
3367 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3368 GDK_INTERP_BILINEAR);
3369 g_object_unref (pixbuf);
3370 pixbuf = temp_pixbuf;
3373 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3374 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3376 if (!icon_info->symbolic)
3378 GdkPixbuf *temp_pixbuf;
3380 icon_source = gtk_icon_source_new ();
3381 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
3382 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
3385 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
3386 state |= GTK_STATE_FLAG_INSENSITIVE;
3387 else if (icon_info->prelight)
3388 state |= GTK_STATE_FLAG_PRELIGHT;
3390 context = gtk_widget_get_style_context (widget);
3391 gtk_style_context_save (context);
3392 gtk_style_context_set_state (context, state);
3393 temp_pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
3394 gtk_style_context_restore (context);
3396 gtk_icon_source_free (icon_source);
3398 g_object_unref (pixbuf);
3399 pixbuf = temp_pixbuf;
3402 gtk_render_icon (context, cr, pixbuf, x, y);
3404 g_object_unref (pixbuf);
3409 gtk_entry_draw_frame (GtkWidget *widget,
3410 GtkStyleContext *context,
3413 GtkEntry *entry = GTK_ENTRY (widget);
3414 GtkEntryPrivate *priv = entry->priv;
3415 gint x = 0, y = 0, width, height;
3416 gint frame_x, frame_y;
3420 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3422 cairo_translate (cr, frame_x, frame_y);
3424 /* Fix a problem with some themes which assume that entry->text_area's
3425 * width equals widget->window's width
3426 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3427 if (GTK_IS_SPIN_BUTTON (widget))
3429 gint xborder, yborder;
3431 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3432 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3435 width += xborder * 2;
3438 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3440 x += priv->focus_width;
3441 y += priv->focus_width;
3442 width -= 2 * priv->focus_width;
3443 height -= 2 * priv->focus_width;
3446 gtk_render_background (context, cr,
3447 x, y, width, height);
3449 if (priv->has_frame)
3450 gtk_render_frame (context, cr,
3451 x, y, width, height);
3453 gtk_entry_draw_progress (widget, context, cr);
3455 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3457 x -= priv->focus_width;
3458 y -= priv->focus_width;
3459 width += 2 * priv->focus_width;
3460 height += 2 * priv->focus_width;
3462 gtk_render_focus (context, cr,
3463 0, 0, width, height);
3470 get_progress_area (GtkWidget *widget,
3476 GtkEntry *entry = GTK_ENTRY (widget);
3477 GtkEntryPrivate *private = entry->priv;
3478 GtkBorder *progress_border;
3480 get_text_area_size (entry, x, y, width, height);
3482 if (!private->interior_focus)
3484 *x -= private->focus_width;
3485 *y -= private->focus_width;
3486 *width += 2 * private->focus_width;
3487 *height += 2 * private->focus_width;
3490 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3492 if (progress_border)
3494 *x += progress_border->left;
3495 *y += progress_border->top;
3496 *width -= progress_border->left + progress_border->right;
3497 *height -= progress_border->top + progress_border->bottom;
3499 gtk_border_free (progress_border);
3502 if (private->progress_pulse_mode)
3504 gdouble value = private->progress_pulse_current;
3506 *x += (gint) floor(value * (*width));
3507 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3509 else if (private->progress_fraction > 0)
3511 gdouble value = private->progress_fraction;
3513 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3517 bar_width = floor(value * (*width) + 0.5);
3518 *x += *width - bar_width;
3523 *width = (gint) floor(value * (*width) + 0.5);
3534 gtk_entry_draw_progress (GtkWidget *widget,
3535 GtkStyleContext *context,
3538 gint x, y, width, height;
3540 get_progress_area (widget, &x, &y, &width, &height);
3542 if ((width <= 0) || (height <= 0))
3545 gtk_style_context_save (context);
3546 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3548 gtk_render_activity (context, cr,
3549 x, y, width, height);
3551 gtk_style_context_restore (context);
3555 gtk_entry_draw (GtkWidget *widget,
3558 GtkEntry *entry = GTK_ENTRY (widget);
3559 GtkStyleContext *context;
3560 GtkStateFlags state;
3561 GtkEntryPrivate *priv = entry->priv;
3564 context = gtk_widget_get_style_context (widget);
3565 state = gtk_widget_get_state_flags (widget);
3567 gtk_style_context_save (context);
3568 gtk_style_context_set_state (context, state);
3570 /* Draw entry_bg, shadow, progress and focus */
3571 gtk_entry_draw_frame (widget, context, cr);
3573 /* Draw text and cursor */
3576 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3578 if (priv->dnd_position != -1)
3579 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3581 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3583 /* When no text is being displayed at all, don't show the cursor */
3584 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3585 gtk_widget_has_focus (widget) &&
3586 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3587 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3592 for (i = 0; i < MAX_ICONS; i++)
3594 EntryIconInfo *icon_info = priv->icons[i];
3596 if (icon_info != NULL)
3600 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3602 draw_icon (widget, cr, i);
3608 gtk_style_context_restore (context);
3614 gtk_entry_enter_notify (GtkWidget *widget,
3615 GdkEventCrossing *event)
3617 GtkEntry *entry = GTK_ENTRY (widget);
3618 GtkEntryPrivate *priv = entry->priv;
3621 for (i = 0; i < MAX_ICONS; i++)
3623 EntryIconInfo *icon_info = priv->icons[i];
3625 if (icon_info != NULL && event->window == icon_info->window)
3627 if (should_prelight (entry, i))
3629 icon_info->prelight = TRUE;
3630 gtk_widget_queue_draw (widget);
3641 gtk_entry_leave_notify (GtkWidget *widget,
3642 GdkEventCrossing *event)
3644 GtkEntry *entry = GTK_ENTRY (widget);
3645 GtkEntryPrivate *priv = entry->priv;
3648 for (i = 0; i < MAX_ICONS; i++)
3650 EntryIconInfo *icon_info = priv->icons[i];
3652 if (icon_info != NULL && event->window == icon_info->window)
3654 /* a grab means that we may never see the button release */
3655 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3656 icon_info->pressed = FALSE;
3658 if (should_prelight (entry, i))
3660 icon_info->prelight = FALSE;
3661 gtk_widget_queue_draw (widget);
3672 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3676 gint start_char, end_char;
3678 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3680 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3681 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3682 const char *text = pango_layout_get_text (layout);
3683 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3684 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3685 gint real_n_ranges, i;
3687 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3693 for (i = 0; i < real_n_ranges; ++i)
3695 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3696 r[2 * i] = r[2 * i] / PANGO_SCALE;
3701 *n_ranges = real_n_ranges;
3713 in_selection (GtkEntry *entry,
3718 gint retval = FALSE;
3720 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3722 for (i = 0; i < n_ranges; ++i)
3724 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3736 gtk_entry_button_press (GtkWidget *widget,
3737 GdkEventButton *event)
3739 GtkEntry *entry = GTK_ENTRY (widget);
3740 GtkEditable *editable = GTK_EDITABLE (widget);
3741 GtkEntryPrivate *priv = entry->priv;
3742 EntryIconInfo *icon_info = NULL;
3744 gint sel_start, sel_end;
3747 for (i = 0; i < MAX_ICONS; i++)
3749 icon_info = priv->icons[i];
3751 if (!icon_info || icon_info->insensitive)
3754 if (event->window == icon_info->window)
3756 if (should_prelight (entry, i))
3758 icon_info->prelight = FALSE;
3759 gtk_widget_queue_draw (widget);
3762 priv->start_x = event->x;
3763 priv->start_y = event->y;
3764 icon_info->pressed = TRUE;
3766 if (!icon_info->nonactivatable)
3767 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3773 if (event->window != priv->text_area ||
3774 (priv->button && event->button != priv->button))
3777 gtk_entry_reset_blink_time (entry);
3779 priv->button = event->button;
3781 if (!gtk_widget_has_focus (widget))
3783 priv->in_click = TRUE;
3784 gtk_widget_grab_focus (widget);
3785 priv->in_click = FALSE;
3788 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3790 if (event->button == 1)
3792 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3794 priv->select_words = FALSE;
3795 priv->select_lines = FALSE;
3797 if (event->state & GDK_SHIFT_MASK)
3799 _gtk_entry_reset_im_context (entry);
3801 if (!have_selection) /* select from the current position to the clicked position */
3802 sel_start = sel_end = priv->current_pos;
3804 if (tmp_pos > sel_start && tmp_pos < sel_end)
3806 /* Truncate current selection, but keep it as big as possible */
3807 if (tmp_pos - sel_start > sel_end - tmp_pos)
3808 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3810 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3814 gboolean extend_to_left;
3817 /* Figure out what click selects and extend current selection */
3818 switch (event->type)
3820 case GDK_BUTTON_PRESS:
3821 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3824 case GDK_2BUTTON_PRESS:
3825 priv->select_words = TRUE;
3826 gtk_entry_select_word (entry);
3829 case GDK_3BUTTON_PRESS:
3830 priv->select_lines = TRUE;
3831 gtk_entry_select_line (entry);
3838 start = MIN (priv->current_pos, priv->selection_bound);
3839 start = MIN (sel_start, start);
3841 end = MAX (priv->current_pos, priv->selection_bound);
3842 end = MAX (sel_end, end);
3844 if (tmp_pos == sel_start || tmp_pos == sel_end)
3845 extend_to_left = (tmp_pos == start);
3847 extend_to_left = (end == sel_end);
3850 gtk_entry_set_positions (entry, start, end);
3852 gtk_entry_set_positions (entry, end, start);
3855 else /* no shift key */
3856 switch (event->type)
3858 case GDK_BUTTON_PRESS:
3859 if (in_selection (entry, event->x + priv->scroll_offset))
3861 /* Click inside the selection - we'll either start a drag, or
3862 * clear the selection
3864 priv->in_drag = TRUE;
3865 priv->drag_start_x = event->x + priv->scroll_offset;
3866 priv->drag_start_y = event->y;
3869 gtk_editable_set_position (editable, tmp_pos);
3872 case GDK_2BUTTON_PRESS:
3873 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3874 * receiving a GDK_2BUTTON_PRESS so we need to reset
3875 * priv->in_drag which may have been set above
3877 priv->in_drag = FALSE;
3878 priv->select_words = TRUE;
3879 gtk_entry_select_word (entry);
3882 case GDK_3BUTTON_PRESS:
3883 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3884 * receiving a GDK_3BUTTON_PRESS so we need to reset
3885 * priv->in_drag which may have been set above
3887 priv->in_drag = FALSE;
3888 priv->select_lines = TRUE;
3889 gtk_entry_select_line (entry);
3898 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3902 priv->insert_pos = tmp_pos;
3903 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3908 gtk_widget_error_bell (widget);
3911 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3913 gtk_entry_do_popup (entry, event);
3914 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3923 gtk_entry_button_release (GtkWidget *widget,
3924 GdkEventButton *event)
3926 GtkEntry *entry = GTK_ENTRY (widget);
3927 GtkEntryPrivate *priv = entry->priv;
3928 EntryIconInfo *icon_info = NULL;
3931 for (i = 0; i < MAX_ICONS; i++)
3933 icon_info = priv->icons[i];
3935 if (!icon_info || icon_info->insensitive)
3938 if (event->window == icon_info->window)
3940 icon_info->pressed = FALSE;
3942 if (should_prelight (entry, i) &&
3943 event->x >= 0 && event->y >= 0 &&
3944 event->x < gdk_window_get_width (icon_info->window) &&
3945 event->y < gdk_window_get_height (icon_info->window))
3947 icon_info->prelight = TRUE;
3948 gtk_widget_queue_draw (widget);
3951 if (!icon_info->nonactivatable)
3952 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3958 if (event->window != priv->text_area || priv->button != event->button)
3963 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3965 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3972 gtk_entry_update_primary_selection (entry);
3978 _gtk_entry_get_selected_text (GtkEntry *entry)
3980 GtkEditable *editable = GTK_EDITABLE (entry);
3981 gint start_text, end_text;
3984 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3985 text = gtk_editable_get_chars (editable, start_text, end_text);
3991 gtk_entry_motion_notify (GtkWidget *widget,
3992 GdkEventMotion *event)
3994 GtkEntry *entry = GTK_ENTRY (widget);
3995 GtkEntryPrivate *priv = entry->priv;
3996 EntryIconInfo *icon_info = NULL;
4000 for (i = 0; i < MAX_ICONS; i++)
4002 icon_info = priv->icons[i];
4004 if (!icon_info || icon_info->insensitive)
4007 if (event->window == icon_info->window)
4009 if (icon_info->pressed &&
4010 icon_info->target_list != NULL &&
4011 gtk_drag_check_threshold (widget,
4017 icon_info->in_drag = TRUE;
4018 icon_info->pressed = FALSE;
4019 gtk_drag_begin (widget,
4020 icon_info->target_list,
4030 if (priv->mouse_cursor_obscured)
4034 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4035 gdk_window_set_cursor (priv->text_area, cursor);
4036 g_object_unref (cursor);
4037 priv->mouse_cursor_obscured = FALSE;
4040 if (event->window != priv->text_area || priv->button != 1)
4043 if (priv->select_lines)
4046 gdk_event_request_motions (event);
4050 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4051 gtk_drag_check_threshold (widget,
4052 priv->drag_start_x, priv->drag_start_y,
4053 event->x + priv->scroll_offset, event->y))
4055 GdkDragContext *context;
4056 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4057 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4059 cairo_surface_t *surface;
4061 gtk_target_list_add_text_targets (target_list, 0);
4063 text = _gtk_entry_get_selected_text (entry);
4064 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4066 context = gtk_drag_begin (widget, target_list, actions,
4067 priv->button, (GdkEvent *)event);
4070 gtk_drag_set_icon_surface (context, surface);
4072 gtk_drag_set_icon_default (context);
4075 cairo_surface_destroy (surface);
4078 priv->in_drag = FALSE;
4081 gtk_target_list_unref (target_list);
4088 else if (event->y >= gdk_window_get_height (priv->text_area))
4089 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4091 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4093 if (priv->select_words)
4096 gint old_min, old_max;
4099 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4100 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4102 pos = priv->current_pos;
4103 bound = priv->selection_bound;
4105 old_min = MIN(priv->current_pos, priv->selection_bound);
4106 old_max = MAX(priv->current_pos, priv->selection_bound);
4113 else if (old_max < max)
4118 else if (pos == old_min)
4120 if (priv->current_pos != min)
4125 if (priv->current_pos != max)
4129 gtk_entry_set_positions (entry, pos, bound);
4132 gtk_entry_set_positions (entry, tmp_pos, -1);
4139 set_invisible_cursor (GdkWindow *window)
4141 GdkDisplay *display;
4144 display = gdk_window_get_display (window);
4145 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4147 gdk_window_set_cursor (window, cursor);
4149 g_object_unref (cursor);
4153 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4155 GtkEntryPrivate *priv = entry->priv;
4157 if (priv->mouse_cursor_obscured)
4160 set_invisible_cursor (priv->text_area);
4162 priv->mouse_cursor_obscured = TRUE;
4166 gtk_entry_key_press (GtkWidget *widget,
4169 GtkEntry *entry = GTK_ENTRY (widget);
4170 GtkEntryPrivate *priv = entry->priv;
4172 gtk_entry_reset_blink_time (entry);
4173 gtk_entry_pend_cursor_blink (entry);
4177 if (gtk_im_context_filter_keypress (priv->im_context, event))
4179 gtk_entry_obscure_mouse_cursor (entry);
4180 priv->need_im_reset = TRUE;
4185 if (event->keyval == GDK_KEY_Return ||
4186 event->keyval == GDK_KEY_KP_Enter ||
4187 event->keyval == GDK_KEY_ISO_Enter ||
4188 event->keyval == GDK_KEY_Escape)
4190 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4192 if (completion && completion->priv->completion_timeout)
4194 g_source_remove (completion->priv->completion_timeout);
4195 completion->priv->completion_timeout = 0;
4198 _gtk_entry_reset_im_context (entry);
4201 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4202 /* Activate key bindings
4206 if (!priv->editable && event->length)
4207 gtk_widget_error_bell (widget);
4213 gtk_entry_key_release (GtkWidget *widget,
4216 GtkEntry *entry = GTK_ENTRY (widget);
4217 GtkEntryPrivate *priv = entry->priv;
4221 if (gtk_im_context_filter_keypress (priv->im_context, event))
4223 priv->need_im_reset = TRUE;
4228 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4232 gtk_entry_focus_in (GtkWidget *widget,
4233 GdkEventFocus *event)
4235 GtkEntry *entry = GTK_ENTRY (widget);
4236 GtkEntryPrivate *priv = entry->priv;
4239 gtk_widget_queue_draw (widget);
4241 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4245 priv->need_im_reset = TRUE;
4246 gtk_im_context_focus_in (priv->im_context);
4247 keymap_state_changed (keymap, entry);
4248 g_signal_connect (keymap, "state-changed",
4249 G_CALLBACK (keymap_state_changed), entry);
4252 g_signal_connect (keymap, "direction-changed",
4253 G_CALLBACK (keymap_direction_changed), entry);
4255 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4256 priv->placeholder_text != NULL)
4258 gtk_entry_recompute (entry);
4262 gtk_entry_reset_blink_time (entry);
4263 gtk_entry_check_cursor_blink (entry);
4270 gtk_entry_focus_out (GtkWidget *widget,
4271 GdkEventFocus *event)
4273 GtkEntry *entry = GTK_ENTRY (widget);
4274 GtkEntryPrivate *priv = entry->priv;
4275 GtkEntryCompletion *completion;
4278 gtk_widget_queue_draw (widget);
4280 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4284 priv->need_im_reset = TRUE;
4285 gtk_im_context_focus_out (priv->im_context);
4286 remove_capslock_feedback (entry);
4289 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4290 priv->placeholder_text != NULL)
4292 gtk_entry_recompute (entry);
4296 gtk_entry_check_cursor_blink (entry);
4299 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4300 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4302 completion = gtk_entry_get_completion (entry);
4304 _gtk_entry_completion_popdown (completion);
4310 gtk_entry_grab_focus (GtkWidget *widget)
4312 GtkEntry *entry = GTK_ENTRY (widget);
4313 GtkEntryPrivate *priv = entry->priv;
4314 gboolean select_on_focus;
4316 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4318 if (priv->editable && !priv->in_click)
4320 g_object_get (gtk_widget_get_settings (widget),
4321 "gtk-entry-select-on-focus",
4325 if (select_on_focus)
4326 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4331 gtk_entry_direction_changed (GtkWidget *widget,
4332 GtkTextDirection previous_dir)
4334 GtkEntry *entry = GTK_ENTRY (widget);
4336 gtk_entry_recompute (entry);
4338 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4342 gtk_entry_state_flags_changed (GtkWidget *widget,
4343 GtkStateFlags previous_state)
4345 GtkEntry *entry = GTK_ENTRY (widget);
4346 GtkEntryPrivate *priv = entry->priv;
4349 if (gtk_widget_get_realized (widget))
4351 if (gtk_widget_is_sensitive (widget))
4352 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4356 gdk_window_set_cursor (priv->text_area, cursor);
4359 g_object_unref (cursor);
4361 priv->mouse_cursor_obscured = FALSE;
4363 update_cursors (widget);
4366 if (!gtk_widget_is_sensitive (widget))
4368 /* Clear any selection */
4369 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4372 gtk_entry_update_cached_style_values (entry);
4376 gtk_entry_screen_changed (GtkWidget *widget,
4377 GdkScreen *old_screen)
4379 gtk_entry_recompute (GTK_ENTRY (widget));
4382 /* GtkEditable method implementations
4385 gtk_entry_insert_text (GtkEditable *editable,
4386 const gchar *new_text,
4387 gint new_text_length,
4390 g_object_ref (editable);
4393 * The incoming text may a password or other secret. We make sure
4394 * not to copy it into temporary buffers.
4397 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4399 g_object_unref (editable);
4403 gtk_entry_delete_text (GtkEditable *editable,
4407 g_object_ref (editable);
4409 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4411 g_object_unref (editable);
4415 gtk_entry_get_chars (GtkEditable *editable,
4419 GtkEntry *entry = GTK_ENTRY (editable);
4422 gint start_index, end_index;
4424 text = gtk_entry_buffer_get_text (get_buffer (entry));
4425 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4428 end_pos = text_length;
4430 start_pos = MIN (text_length, start_pos);
4431 end_pos = MIN (text_length, end_pos);
4433 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4434 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4436 return g_strndup (text + start_index, end_index - start_index);
4440 gtk_entry_real_set_position (GtkEditable *editable,
4443 GtkEntry *entry = GTK_ENTRY (editable);
4444 GtkEntryPrivate *priv = entry->priv;
4448 length = gtk_entry_buffer_get_length (get_buffer (entry));
4449 if (position < 0 || position > length)
4452 if (position != priv->current_pos ||
4453 position != priv->selection_bound)
4455 _gtk_entry_reset_im_context (entry);
4456 gtk_entry_set_positions (entry, position, position);
4461 gtk_entry_get_position (GtkEditable *editable)
4463 GtkEntry *entry = GTK_ENTRY (editable);
4464 GtkEntryPrivate *priv = entry->priv;
4466 return priv->current_pos;
4470 gtk_entry_set_selection_bounds (GtkEditable *editable,
4474 GtkEntry *entry = GTK_ENTRY (editable);
4477 length = gtk_entry_buffer_get_length (get_buffer (entry));
4483 _gtk_entry_reset_im_context (entry);
4485 gtk_entry_set_positions (entry,
4487 MIN (start, length));
4489 gtk_entry_update_primary_selection (entry);
4493 gtk_entry_get_selection_bounds (GtkEditable *editable,
4497 GtkEntry *entry = GTK_ENTRY (editable);
4498 GtkEntryPrivate *priv = entry->priv;
4500 *start = priv->selection_bound;
4501 *end = priv->current_pos;
4503 return (priv->selection_bound != priv->current_pos);
4507 icon_theme_changed (GtkEntry *entry)
4509 GtkEntryPrivate *priv = entry->priv;
4512 for (i = 0; i < MAX_ICONS; i++)
4514 EntryIconInfo *icon_info = priv->icons[i];
4515 if (icon_info != NULL)
4517 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4518 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4519 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4520 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4521 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4522 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4526 gtk_widget_queue_draw (GTK_WIDGET (entry));
4530 icon_margin_changed (GtkEntry *entry)
4532 GtkEntryPrivate *priv = entry->priv;
4535 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4537 priv->icon_margin = border.left;
4541 gtk_entry_update_cached_style_values (GtkEntry *entry)
4543 GtkEntryPrivate *priv = entry->priv;
4545 gboolean interior_focus;
4547 gtk_widget_style_get (GTK_WIDGET (entry),
4548 "focus-line-width", &focus_width,
4549 "interior-focus", &interior_focus,
4551 priv->focus_width = focus_width;
4552 priv->interior_focus = interior_focus;
4554 if (!priv->invisible_char_set)
4556 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4558 if (priv->invisible_char != ch)
4560 priv->invisible_char = ch;
4561 g_object_notify (G_OBJECT (entry), "invisible-char");
4567 gtk_entry_style_updated (GtkWidget *widget)
4569 GtkEntry *entry = GTK_ENTRY (widget);
4571 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4573 gtk_entry_update_cached_style_values (entry);
4575 gtk_entry_recompute (entry);
4577 icon_theme_changed (entry);
4578 icon_margin_changed (entry);
4581 /* GtkCellEditable method implementations
4584 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4586 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4587 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4591 gtk_cell_editable_key_press_event (GtkEntry *entry,
4592 GdkEventKey *key_event,
4595 GtkEntryPrivate *priv = entry->priv;
4597 if (key_event->keyval == GDK_KEY_Escape)
4599 priv->editing_canceled = TRUE;
4600 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4601 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4606 /* override focus */
4607 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4609 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4610 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4619 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4622 GtkEntry *entry = GTK_ENTRY (cell_editable);
4623 GtkEntryPrivate *priv = entry->priv;
4625 priv->is_cell_renderer = TRUE;
4627 g_signal_connect (cell_editable, "activate",
4628 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4629 g_signal_connect (cell_editable, "key-press-event",
4630 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4634 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4636 if (password_hint->source_id)
4637 g_source_remove (password_hint->source_id);
4639 g_slice_free (GtkEntryPasswordHint, password_hint);
4644 gtk_entry_remove_password_hint (gpointer data)
4646 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4647 password_hint->position = -1;
4649 /* Force the string to be redrawn, but now without a visible character */
4650 gtk_entry_recompute (GTK_ENTRY (data));
4654 /* Default signal handlers
4657 gtk_entry_real_insert_text (GtkEditable *editable,
4658 const gchar *new_text,
4659 gint new_text_length,
4665 n_chars = g_utf8_strlen (new_text, new_text_length);
4668 * The actual insertion into the buffer. This will end up firing the
4669 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4670 * buffer_notify_text(), buffer_notify_length()
4672 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4674 if (n_inserted != n_chars)
4675 gtk_widget_error_bell (GTK_WIDGET (editable));
4677 *position += n_inserted;
4681 gtk_entry_real_delete_text (GtkEditable *editable,
4686 * The actual deletion from the buffer. This will end up firing the
4687 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4688 * buffer_notify_text(), buffer_notify_length()
4691 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4694 /* GtkEntryBuffer signal handlers
4697 buffer_inserted_text (GtkEntryBuffer *buffer,
4703 GtkEntryPrivate *priv = entry->priv;
4704 guint password_hint_timeout;
4706 if (priv->current_pos > position)
4707 priv->current_pos += n_chars;
4709 if (priv->selection_bound > position)
4710 priv->selection_bound += n_chars;
4712 /* Calculate the password hint if it needs to be displayed. */
4713 if (n_chars == 1 && !priv->visible)
4715 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4716 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4719 if (password_hint_timeout > 0)
4721 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4722 quark_password_hint);
4725 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4726 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4727 (GDestroyNotify)gtk_entry_password_hint_free);
4730 password_hint->position = position;
4731 if (password_hint->source_id)
4732 g_source_remove (password_hint->source_id);
4733 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4734 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4740 buffer_deleted_text (GtkEntryBuffer *buffer,
4745 GtkEntryPrivate *priv = entry->priv;
4746 guint end_pos = position + n_chars;
4747 gint selection_bound;
4750 current_pos = priv->current_pos;
4751 if (current_pos > position)
4752 current_pos -= MIN (current_pos, end_pos) - position;
4754 selection_bound = priv->selection_bound;
4755 if (selection_bound > position)
4756 selection_bound -= MIN (selection_bound, end_pos) - position;
4758 gtk_entry_set_positions (entry, current_pos, selection_bound);
4760 /* We might have deleted the selection */
4761 gtk_entry_update_primary_selection (entry);
4763 /* Disable the password hint if one exists. */
4766 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4767 quark_password_hint);
4770 if (password_hint->source_id)
4771 g_source_remove (password_hint->source_id);
4772 password_hint->source_id = 0;
4773 password_hint->position = -1;
4779 buffer_notify_text (GtkEntryBuffer *buffer,
4783 gtk_entry_recompute (entry);
4784 emit_changed (entry);
4785 g_object_notify (G_OBJECT (entry), "text");
4789 buffer_notify_length (GtkEntryBuffer *buffer,
4793 g_object_notify (G_OBJECT (entry), "text-length");
4797 buffer_notify_max_length (GtkEntryBuffer *buffer,
4801 g_object_notify (G_OBJECT (entry), "max-length");
4805 buffer_connect_signals (GtkEntry *entry)
4807 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4808 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4809 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4810 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4811 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4815 buffer_disconnect_signals (GtkEntry *entry)
4817 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4818 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4819 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4820 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4821 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4824 /* Compute the X position for an offset that corresponds to the "more important
4825 * cursor position for that offset. We use this when trying to guess to which
4826 * end of the selection we should go to when the user hits the left or
4830 get_better_cursor_x (GtkEntry *entry,
4833 GtkEntryPrivate *priv = entry->priv;
4834 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4835 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4836 gboolean split_cursor;
4838 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4839 const gchar *text = pango_layout_get_text (layout);
4840 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4842 PangoRectangle strong_pos, weak_pos;
4844 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4845 "gtk-split-cursor", &split_cursor,
4848 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4851 return strong_pos.x / PANGO_SCALE;
4853 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4857 gtk_entry_move_cursor (GtkEntry *entry,
4858 GtkMovementStep step,
4860 gboolean extend_selection)
4862 GtkEntryPrivate *priv = entry->priv;
4863 gint new_pos = priv->current_pos;
4865 _gtk_entry_reset_im_context (entry);
4867 if (priv->current_pos != priv->selection_bound && !extend_selection)
4869 /* If we have a current selection and aren't extending it, move to the
4870 * start/or end of the selection as appropriate
4874 case GTK_MOVEMENT_VISUAL_POSITIONS:
4876 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4877 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4880 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4882 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4885 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4886 case GTK_MOVEMENT_WORDS:
4888 new_pos = MIN (priv->current_pos, priv->selection_bound);
4890 new_pos = MAX (priv->current_pos, priv->selection_bound);
4892 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4893 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4894 case GTK_MOVEMENT_BUFFER_ENDS:
4895 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4897 case GTK_MOVEMENT_DISPLAY_LINES:
4898 case GTK_MOVEMENT_PARAGRAPHS:
4899 case GTK_MOVEMENT_PAGES:
4900 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4908 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4909 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4911 case GTK_MOVEMENT_VISUAL_POSITIONS:
4912 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4913 if (priv->current_pos == new_pos)
4915 if (!extend_selection)
4917 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4919 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4921 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4924 gtk_widget_child_focus (toplevel,
4926 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4931 gtk_widget_error_bell (GTK_WIDGET (entry));
4935 case GTK_MOVEMENT_WORDS:
4938 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4943 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4946 if (priv->current_pos == new_pos)
4947 gtk_widget_error_bell (GTK_WIDGET (entry));
4949 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4950 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4951 case GTK_MOVEMENT_BUFFER_ENDS:
4952 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4953 if (priv->current_pos == new_pos)
4954 gtk_widget_error_bell (GTK_WIDGET (entry));
4956 case GTK_MOVEMENT_DISPLAY_LINES:
4957 case GTK_MOVEMENT_PARAGRAPHS:
4958 case GTK_MOVEMENT_PAGES:
4959 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4964 if (extend_selection)
4965 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4967 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4969 gtk_entry_pend_cursor_blink (entry);
4973 gtk_entry_insert_at_cursor (GtkEntry *entry,
4976 GtkEntryPrivate *priv = entry->priv;
4977 GtkEditable *editable = GTK_EDITABLE (entry);
4978 gint pos = priv->current_pos;
4982 _gtk_entry_reset_im_context (entry);
4984 gtk_editable_insert_text (editable, str, -1, &pos);
4985 gtk_editable_set_position (editable, pos);
4990 gtk_entry_delete_from_cursor (GtkEntry *entry,
4994 GtkEntryPrivate *priv = entry->priv;
4995 GtkEditable *editable = GTK_EDITABLE (entry);
4996 gint start_pos = priv->current_pos;
4997 gint end_pos = priv->current_pos;
4998 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5000 _gtk_entry_reset_im_context (entry);
5002 if (!priv->editable)
5004 gtk_widget_error_bell (GTK_WIDGET (entry));
5008 if (priv->selection_bound != priv->current_pos)
5010 gtk_editable_delete_selection (editable);
5016 case GTK_DELETE_CHARS:
5017 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5018 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5020 case GTK_DELETE_WORDS:
5023 /* Move to end of current word, or if not on a word, end of previous word */
5024 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5025 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5029 /* Move to beginning of current word, or if not on a word, begining of next word */
5030 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5031 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5035 case GTK_DELETE_WORD_ENDS:
5038 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5043 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5046 gtk_editable_delete_text (editable, start_pos, end_pos);
5048 case GTK_DELETE_DISPLAY_LINE_ENDS:
5049 case GTK_DELETE_PARAGRAPH_ENDS:
5051 gtk_editable_delete_text (editable, 0, priv->current_pos);
5053 gtk_editable_delete_text (editable, priv->current_pos, -1);
5055 case GTK_DELETE_DISPLAY_LINES:
5056 case GTK_DELETE_PARAGRAPHS:
5057 gtk_editable_delete_text (editable, 0, -1);
5059 case GTK_DELETE_WHITESPACE:
5060 gtk_entry_delete_whitespace (entry);
5064 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5065 gtk_widget_error_bell (GTK_WIDGET (entry));
5067 gtk_entry_pend_cursor_blink (entry);
5071 gtk_entry_backspace (GtkEntry *entry)
5073 GtkEntryPrivate *priv = entry->priv;
5074 GtkEditable *editable = GTK_EDITABLE (entry);
5077 _gtk_entry_reset_im_context (entry);
5079 if (!priv->editable)
5081 gtk_widget_error_bell (GTK_WIDGET (entry));
5085 if (priv->selection_bound != priv->current_pos)
5087 gtk_editable_delete_selection (editable);
5091 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5093 if (prev_pos < priv->current_pos)
5095 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5096 PangoLogAttr *log_attrs;
5099 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5101 /* Deleting parts of characters */
5102 if (log_attrs[priv->current_pos].backspace_deletes_character)
5104 gchar *cluster_text;
5105 gchar *normalized_text;
5108 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5110 normalized_text = g_utf8_normalize (cluster_text,
5111 strlen (cluster_text),
5113 len = g_utf8_strlen (normalized_text, -1);
5115 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5118 gint pos = priv->current_pos;
5120 gtk_editable_insert_text (editable, normalized_text,
5121 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5123 gtk_editable_set_position (editable, pos);
5126 g_free (normalized_text);
5127 g_free (cluster_text);
5131 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5138 gtk_widget_error_bell (GTK_WIDGET (entry));
5141 gtk_entry_pend_cursor_blink (entry);
5145 gtk_entry_copy_clipboard (GtkEntry *entry)
5147 GtkEntryPrivate *priv = entry->priv;
5148 GtkEditable *editable = GTK_EDITABLE (entry);
5152 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5156 gtk_widget_error_bell (GTK_WIDGET (entry));
5160 str = gtk_entry_get_display_text (entry, start, end);
5161 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5162 GDK_SELECTION_CLIPBOARD),
5169 gtk_entry_cut_clipboard (GtkEntry *entry)
5171 GtkEntryPrivate *priv = entry->priv;
5172 GtkEditable *editable = GTK_EDITABLE (entry);
5177 gtk_widget_error_bell (GTK_WIDGET (entry));
5181 gtk_entry_copy_clipboard (entry);
5185 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5186 gtk_editable_delete_text (editable, start, end);
5190 gtk_widget_error_bell (GTK_WIDGET (entry));
5195 gtk_entry_paste_clipboard (GtkEntry *entry)
5197 GtkEntryPrivate *priv = entry->priv;
5200 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5202 gtk_widget_error_bell (GTK_WIDGET (entry));
5206 gtk_entry_delete_cb (GtkEntry *entry)
5208 GtkEntryPrivate *priv = entry->priv;
5209 GtkEditable *editable = GTK_EDITABLE (entry);
5214 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5215 gtk_editable_delete_text (editable, start, end);
5220 gtk_entry_toggle_overwrite (GtkEntry *entry)
5222 GtkEntryPrivate *priv = entry->priv;
5224 priv->overwrite_mode = !priv->overwrite_mode;
5225 gtk_entry_pend_cursor_blink (entry);
5226 gtk_widget_queue_draw (GTK_WIDGET (entry));
5230 gtk_entry_select_all (GtkEntry *entry)
5232 gtk_entry_select_line (entry);
5236 gtk_entry_real_activate (GtkEntry *entry)
5238 GtkEntryPrivate *priv = entry->priv;
5240 GtkWidget *default_widget, *focus_widget;
5241 GtkWidget *toplevel;
5244 widget = GTK_WIDGET (entry);
5246 if (priv->activates_default)
5248 toplevel = gtk_widget_get_toplevel (widget);
5249 if (GTK_IS_WINDOW (toplevel))
5251 window = GTK_WINDOW (toplevel);
5255 default_widget = gtk_window_get_default_widget (window);
5256 focus_widget = gtk_window_get_focus (window);
5257 if (widget != default_widget &&
5258 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5259 gtk_window_activate_default (window);
5266 keymap_direction_changed (GdkKeymap *keymap,
5269 gtk_entry_recompute (entry);
5272 /* IM Context Callbacks
5276 gtk_entry_commit_cb (GtkIMContext *context,
5280 GtkEntryPrivate *priv = entry->priv;
5283 gtk_entry_enter_text (entry, str);
5287 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5290 GtkEntryPrivate *priv = entry->priv;
5294 gchar *preedit_string;
5297 gtk_im_context_get_preedit_string (priv->im_context,
5298 &preedit_string, NULL,
5300 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5301 priv->preedit_length = strlen (preedit_string);
5302 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5303 priv->preedit_cursor = cursor_pos;
5304 g_free (preedit_string);
5306 gtk_entry_recompute (entry);
5311 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5314 GtkEntryPrivate *priv = entry->priv;
5317 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5318 text = gtk_entry_get_display_text (entry, 0, -1);
5319 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5320 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5327 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5332 GtkEntryPrivate *priv = entry->priv;
5335 gtk_editable_delete_text (GTK_EDITABLE (entry),
5336 priv->current_pos + offset,
5337 priv->current_pos + offset + n_chars);
5342 /* Internal functions
5345 /* Used for im_commit_cb and inserting Unicode chars */
5347 gtk_entry_enter_text (GtkEntry *entry,
5350 GtkEntryPrivate *priv = entry->priv;
5351 GtkEditable *editable = GTK_EDITABLE (entry);
5353 gboolean old_need_im_reset;
5355 old_need_im_reset = priv->need_im_reset;
5356 priv->need_im_reset = FALSE;
5358 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5359 gtk_editable_delete_selection (editable);
5362 if (priv->overwrite_mode)
5363 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5366 tmp_pos = priv->current_pos;
5367 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5368 gtk_editable_set_position (editable, tmp_pos);
5370 priv->need_im_reset = old_need_im_reset;
5373 /* All changes to priv->current_pos and priv->selection_bound
5374 * should go through this function.
5377 gtk_entry_set_positions (GtkEntry *entry,
5379 gint selection_bound)
5381 GtkEntryPrivate *priv = entry->priv;
5382 gboolean changed = FALSE;
5384 g_object_freeze_notify (G_OBJECT (entry));
5386 if (current_pos != -1 &&
5387 priv->current_pos != current_pos)
5389 priv->current_pos = current_pos;
5392 g_object_notify (G_OBJECT (entry), "cursor-position");
5395 if (selection_bound != -1 &&
5396 priv->selection_bound != selection_bound)
5398 priv->selection_bound = selection_bound;
5401 g_object_notify (G_OBJECT (entry), "selection-bound");
5404 g_object_thaw_notify (G_OBJECT (entry));
5408 gtk_entry_move_adjustments (entry);
5409 gtk_entry_recompute (entry);
5414 gtk_entry_reset_layout (GtkEntry *entry)
5416 GtkEntryPrivate *priv = entry->priv;
5418 if (priv->cached_layout)
5420 g_object_unref (priv->cached_layout);
5421 priv->cached_layout = NULL;
5426 update_im_cursor_location (GtkEntry *entry)
5428 GtkEntryPrivate *priv = entry->priv;
5431 gint strong_xoffset;
5432 gint area_width, area_height;
5434 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5435 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5437 strong_xoffset = strong_x - priv->scroll_offset;
5438 if (strong_xoffset < 0)
5442 else if (strong_xoffset > area_width)
5444 strong_xoffset = area_width;
5446 area.x = strong_xoffset;
5449 area.height = area_height;
5451 gtk_im_context_set_cursor_location (priv->im_context, &area);
5455 recompute_idle_func (gpointer data)
5457 GtkEntry *entry = GTK_ENTRY (data);
5458 GtkEntryPrivate *priv = entry->priv;
5460 priv->recompute_idle = 0;
5462 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5464 gtk_entry_adjust_scroll (entry);
5465 gtk_widget_queue_draw (GTK_WIDGET (entry));
5467 update_im_cursor_location (entry);
5474 gtk_entry_recompute (GtkEntry *entry)
5476 GtkEntryPrivate *priv = entry->priv;
5478 gtk_entry_reset_layout (entry);
5479 gtk_entry_check_cursor_blink (entry);
5481 if (!priv->recompute_idle)
5483 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5484 recompute_idle_func, entry, NULL);
5489 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5492 GtkWidget *widget = GTK_WIDGET (entry);
5493 GtkStyleContext *context;
5494 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5496 context = gtk_widget_get_style_context (widget);
5497 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5499 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5500 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5501 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5504 static inline gboolean
5505 show_placeholder_text (GtkEntry *entry)
5507 GtkEntryPrivate *priv = entry->priv;
5509 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5510 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5511 priv->placeholder_text != NULL)
5517 static PangoLayout *
5518 gtk_entry_create_layout (GtkEntry *entry,
5519 gboolean include_preedit)
5521 GtkEntryPrivate *priv = entry->priv;
5522 GtkWidget *widget = GTK_WIDGET (entry);
5523 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5524 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5525 gboolean placeholder_layout = show_placeholder_text (entry);
5527 gchar *preedit_string = NULL;
5528 gint preedit_length = 0;
5529 PangoAttrList *preedit_attrs = NULL;
5534 pango_layout_set_single_paragraph_mode (layout, TRUE);
5536 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5537 n_bytes = strlen (display);
5539 if (!placeholder_layout && include_preedit)
5541 gtk_im_context_get_preedit_string (priv->im_context,
5542 &preedit_string, &preedit_attrs, NULL);
5543 preedit_length = priv->preedit_length;
5545 else if (placeholder_layout)
5548 PangoAttribute *attr;
5550 gtk_entry_get_placeholder_text_color (entry, &color);
5551 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5552 attr->start_index = 0;
5553 attr->end_index = G_MAXINT;
5554 pango_attr_list_insert (tmp_attrs, attr);
5559 GString *tmp_string = g_string_new (display);
5560 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5562 g_string_insert (tmp_string, cursor_index, preedit_string);
5564 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5566 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5567 cursor_index, preedit_length);
5569 g_string_free (tmp_string, TRUE);
5573 PangoDirection pango_dir;
5575 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5576 pango_dir = pango_find_base_dir (display, n_bytes);
5578 pango_dir = PANGO_DIRECTION_NEUTRAL;
5580 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5582 if (gtk_widget_has_focus (widget))
5584 GdkDisplay *display = gtk_widget_get_display (widget);
5585 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5586 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5587 pango_dir = PANGO_DIRECTION_RTL;
5589 pango_dir = PANGO_DIRECTION_LTR;
5593 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5594 pango_dir = PANGO_DIRECTION_RTL;
5596 pango_dir = PANGO_DIRECTION_LTR;
5600 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5603 priv->resolved_dir = pango_dir;
5605 pango_layout_set_text (layout, display, n_bytes);
5608 pango_layout_set_attributes (layout, tmp_attrs);
5610 g_free (preedit_string);
5614 pango_attr_list_unref (preedit_attrs);
5616 pango_attr_list_unref (tmp_attrs);
5621 static PangoLayout *
5622 gtk_entry_ensure_layout (GtkEntry *entry,
5623 gboolean include_preedit)
5625 GtkEntryPrivate *priv = entry->priv;
5627 if (priv->preedit_length > 0 &&
5628 !include_preedit != !priv->cache_includes_preedit)
5629 gtk_entry_reset_layout (entry);
5631 if (!priv->cached_layout)
5633 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5634 priv->cache_includes_preedit = include_preedit;
5637 return priv->cached_layout;
5641 get_layout_position (GtkEntry *entry,
5645 GtkEntryPrivate *priv = entry->priv;
5646 PangoLayout *layout;
5647 PangoRectangle logical_rect;
5648 gint area_width, area_height;
5649 GtkBorder inner_border;
5651 PangoLayoutLine *line;
5653 layout = gtk_entry_ensure_layout (entry, TRUE);
5655 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5656 _gtk_entry_effective_inner_border (entry, &inner_border);
5658 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5660 line = pango_layout_get_lines_readonly (layout)->data;
5661 pango_layout_line_get_extents (line, NULL, &logical_rect);
5663 /* Align primarily for locale's ascent/descent */
5664 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5665 priv->ascent + logical_rect.y);
5667 /* Now see if we need to adjust to fit in actual drawn string */
5668 if (logical_rect.height > area_height)
5669 y_pos = (area_height - logical_rect.height) / 2;
5672 else if (y_pos + logical_rect.height > area_height)
5673 y_pos = area_height - logical_rect.height;
5675 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5678 *x = inner_border.left - priv->scroll_offset;
5685 draw_text_with_color (GtkEntry *entry,
5687 GdkRGBA *default_color)
5689 GtkEntryPrivate *priv = entry->priv;
5690 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5693 gint start_pos, end_pos;
5695 widget = GTK_WIDGET (entry);
5699 get_layout_position (entry, &x, &y);
5701 cairo_move_to (cr, x, y);
5702 gdk_cairo_set_source_rgba (cr, default_color);
5703 pango_cairo_show_layout (cr, layout);
5705 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5709 PangoRectangle logical_rect;
5710 GdkRGBA selection_color, text_color;
5711 GtkBorder inner_border;
5712 GtkStyleContext *context;
5713 GtkStateFlags state;
5715 context = gtk_widget_get_style_context (widget);
5716 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5717 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5719 state = GTK_STATE_FLAG_SELECTED;
5721 if (gtk_widget_has_focus (widget))
5722 state |= GTK_STATE_FLAG_FOCUSED;
5724 gtk_style_context_get_background_color (context, state, &selection_color);
5725 gtk_style_context_get_color (context, state, &text_color);
5727 _gtk_entry_effective_inner_border (entry, &inner_border);
5729 for (i = 0; i < n_ranges; ++i)
5730 cairo_rectangle (cr,
5731 inner_border.left - priv->scroll_offset + ranges[2 * i],
5734 logical_rect.height);
5738 gdk_cairo_set_source_rgba (cr, &selection_color);
5741 cairo_move_to (cr, x, y);
5742 gdk_cairo_set_source_rgba (cr, &text_color);
5743 pango_cairo_show_layout (cr, layout);
5751 gtk_entry_draw_text (GtkEntry *entry,
5754 GtkEntryPrivate *priv = entry->priv;
5755 GtkWidget *widget = GTK_WIDGET (entry);
5756 GtkStateFlags state = 0;
5757 GdkRGBA text_color, bar_text_color;
5758 GtkStyleContext *context;
5760 gint progress_x, progress_y, progress_width, progress_height;
5761 gint clip_width, clip_height;
5763 /* Nothing to display at all */
5764 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5767 state = gtk_widget_get_state_flags (widget);
5768 context = gtk_widget_get_style_context (widget);
5770 gtk_style_context_get_color (context, state, &text_color);
5772 /* Get foreground color for progressbars */
5773 gtk_style_context_save (context);
5774 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5775 gtk_style_context_get_color (context, state, &bar_text_color);
5776 gtk_style_context_restore (context);
5778 get_progress_area (widget,
5779 &progress_x, &progress_y,
5780 &progress_width, &progress_height);
5784 clip_width = gdk_window_get_width (priv->text_area);
5785 clip_height = gdk_window_get_height (priv->text_area);
5786 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5789 /* If the color is the same, or the progress area has a zero
5790 * size, then we only need to draw once. */
5791 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5792 ((progress_width == 0) || (progress_height == 0)))
5794 draw_text_with_color (entry, cr, &text_color);
5798 int frame_x, frame_y, area_x, area_y;
5800 width = gdk_window_get_width (priv->text_area);
5801 height = gdk_window_get_height (priv->text_area);
5805 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5806 cairo_rectangle (cr, 0, 0, width, height);
5808 /* progres area is frame-relative, we need it text-area window
5810 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5811 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5812 progress_x += frame_x - area_x;
5813 progress_y += frame_y - area_y;
5815 cairo_rectangle (cr, progress_x, progress_y,
5816 progress_width, progress_height);
5818 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5820 draw_text_with_color (entry, cr, &text_color);
5825 cairo_rectangle (cr, progress_x, progress_y,
5826 progress_width, progress_height);
5829 draw_text_with_color (entry, cr, &bar_text_color);
5838 draw_insertion_cursor (GtkEntry *entry,
5840 GdkRectangle *cursor_location,
5841 gboolean is_primary,
5842 PangoDirection direction,
5843 gboolean draw_arrow)
5845 GtkWidget *widget = GTK_WIDGET (entry);
5846 GtkTextDirection text_dir;
5848 if (direction == PANGO_DIRECTION_LTR)
5849 text_dir = GTK_TEXT_DIR_LTR;
5851 text_dir = GTK_TEXT_DIR_RTL;
5853 gtk_draw_insertion_cursor (widget, cr,
5855 is_primary, text_dir, draw_arrow);
5859 gtk_entry_draw_cursor (GtkEntry *entry,
5863 GtkEntryPrivate *priv = entry->priv;
5864 GtkWidget *widget = GTK_WIDGET (entry);
5865 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5866 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5867 GdkRectangle cursor_location;
5868 gboolean split_cursor;
5869 PangoRectangle cursor_rect;
5870 GtkBorder inner_border;
5872 gint text_area_height;
5875 gboolean block_at_line_end;
5876 PangoLayout *layout;
5879 _gtk_entry_effective_inner_border (entry, &inner_border);
5881 xoffset = inner_border.left - priv->scroll_offset;
5883 text_area_height = gdk_window_get_height (priv->text_area);
5885 layout = gtk_entry_ensure_layout (entry, TRUE);
5886 text = pango_layout_get_text (layout);
5887 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5888 if (!priv->overwrite_mode)
5891 block = _gtk_text_util_get_block_cursor_location (layout,
5892 cursor_index, &cursor_rect, &block_at_line_end);
5896 gint strong_x, weak_x;
5897 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5898 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5902 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5904 g_object_get (gtk_widget_get_settings (widget),
5905 "gtk-split-cursor", &split_cursor,
5908 dir1 = priv->resolved_dir;
5914 if (weak_x != strong_x)
5916 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5922 if (keymap_direction == priv->resolved_dir)
5928 cursor_location.x = xoffset + x1;
5929 cursor_location.y = inner_border.top;
5930 cursor_location.width = 0;
5931 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5933 draw_insertion_cursor (entry, cr,
5934 &cursor_location, TRUE, dir1,
5935 dir2 != PANGO_DIRECTION_NEUTRAL);
5937 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5939 cursor_location.x = xoffset + x2;
5940 draw_insertion_cursor (entry, cr,
5941 &cursor_location, FALSE, dir2,
5945 else /* overwrite_mode */
5947 GtkStyleContext *context;
5948 GdkRGBA cursor_color;
5954 get_layout_position (entry, &x, &y);
5956 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5957 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5958 rect.width = PANGO_PIXELS (cursor_rect.width);
5959 rect.height = PANGO_PIXELS (cursor_rect.height);
5961 context = gtk_widget_get_style_context (widget);
5963 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5964 gdk_cairo_set_source_rgba (cr, &cursor_color);
5965 gdk_cairo_rectangle (cr, &rect);
5968 if (!block_at_line_end)
5970 GtkStateFlags state;
5973 state = gtk_widget_get_state_flags (widget);
5974 gtk_style_context_get_background_color (context, state, &color);
5976 gdk_cairo_rectangle (cr, &rect);
5978 cairo_move_to (cr, x, y);
5979 gdk_cairo_set_source_rgba (cr, &color);
5980 pango_cairo_show_layout (cr, layout);
5988 _gtk_entry_reset_im_context (GtkEntry *entry)
5990 GtkEntryPrivate *priv = entry->priv;
5992 if (priv->need_im_reset)
5994 priv->need_im_reset = FALSE;
5995 gtk_im_context_reset (priv->im_context);
6000 * gtk_entry_reset_im_context:
6001 * @entry: a #GtkEntry
6003 * Reset the input method context of the entry if needed.
6005 * This can be necessary in the case where modifying the buffer
6006 * would confuse on-going input method behavior.
6011 gtk_entry_reset_im_context (GtkEntry *entry)
6013 g_return_if_fail (GTK_IS_ENTRY (entry));
6015 _gtk_entry_reset_im_context (entry);
6019 * gtk_entry_im_context_filter_keypress:
6020 * @entry: a #GtkEntry
6021 * @event: (type Gdk.EventKey): the key event
6023 * Allow the #GtkEntry input method to internally handle key press
6024 * and release events. If this function returns %TRUE, then no further
6025 * processing should be done for this key event. See
6026 * gtk_im_context_filter_keypress().
6028 * Note that you are expected to call this function from your handler
6029 * when overriding key event handling. This is needed in the case when
6030 * you need to insert your own key handling between the input method
6031 * and the default key event handling of the #GtkEntry.
6032 * See gtk_text_view_reset_im_context() for an example of use.
6034 * Return value: %TRUE if the input method handled the key event.
6039 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6042 GtkEntryPrivate *priv;
6044 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6048 return gtk_im_context_filter_keypress (priv->im_context, event);
6052 _gtk_entry_get_im_context (GtkEntry *entry)
6054 return entry->priv->im_context;
6058 gtk_entry_find_position (GtkEntry *entry,
6061 GtkEntryPrivate *priv = entry->priv;
6062 PangoLayout *layout;
6063 PangoLayoutLine *line;
6070 layout = gtk_entry_ensure_layout (entry, TRUE);
6071 text = pango_layout_get_text (layout);
6072 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6074 line = pango_layout_get_lines_readonly (layout)->data;
6075 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6077 if (index >= cursor_index && priv->preedit_length)
6079 if (index >= cursor_index + priv->preedit_length)
6080 index -= priv->preedit_length;
6083 index = cursor_index;
6088 pos = g_utf8_pointer_to_offset (text, text + index);
6095 gtk_entry_get_cursor_locations (GtkEntry *entry,
6100 GtkEntryPrivate *priv = entry->priv;
6101 DisplayMode mode = gtk_entry_get_display_mode (entry);
6103 /* Nothing to display at all, so no cursor is relevant */
6104 if (mode == DISPLAY_BLANK)
6114 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6115 const gchar *text = pango_layout_get_text (layout);
6116 PangoRectangle strong_pos, weak_pos;
6119 if (type == CURSOR_STANDARD)
6121 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6123 else /* type == CURSOR_DND */
6125 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6127 if (priv->dnd_position > priv->current_pos)
6129 if (mode == DISPLAY_NORMAL)
6130 index += priv->preedit_length;
6133 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6134 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6139 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6142 *strong_x = strong_pos.x / PANGO_SCALE;
6145 *weak_x = weak_pos.x / PANGO_SCALE;
6150 gtk_entry_adjust_scroll (GtkEntry *entry)
6152 GtkEntryPrivate *priv = entry->priv;
6153 gint min_offset, max_offset;
6154 gint text_area_width, text_width;
6155 GtkBorder inner_border;
6156 gint strong_x, weak_x;
6157 gint strong_xoffset, weak_xoffset;
6159 PangoLayout *layout;
6160 PangoLayoutLine *line;
6161 PangoRectangle logical_rect;
6163 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6166 _gtk_entry_effective_inner_border (entry, &inner_border);
6168 text_area_width = gdk_window_get_width (priv->text_area);
6169 text_area_width -= inner_border.left + inner_border.right;
6170 if (text_area_width < 0)
6171 text_area_width = 0;
6173 layout = gtk_entry_ensure_layout (entry, TRUE);
6174 line = pango_layout_get_lines_readonly (layout)->data;
6176 pango_layout_line_get_extents (line, NULL, &logical_rect);
6178 /* Display as much text as we can */
6180 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6181 xalign = priv->xalign;
6183 xalign = 1.0 - priv->xalign;
6185 text_width = PANGO_PIXELS(logical_rect.width);
6187 if (text_width > text_area_width)
6190 max_offset = text_width - text_area_width;
6194 min_offset = (text_width - text_area_width) * xalign;
6195 max_offset = min_offset;
6198 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6200 /* And make sure cursors are on screen. Note that the cursor is
6201 * actually drawn one pixel into the INNER_BORDER space on
6202 * the right, when the scroll is at the utmost right. This
6203 * looks better to to me than confining the cursor inside the
6204 * border entirely, though it means that the cursor gets one
6205 * pixel closer to the edge of the widget on the right than
6206 * on the left. This might need changing if one changed
6207 * INNER_BORDER from 2 to 1, as one would do on a
6208 * small-screen-real-estate display.
6210 * We always make sure that the strong cursor is on screen, and
6211 * put the weak cursor on screen if possible.
6214 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6216 strong_xoffset = strong_x - priv->scroll_offset;
6218 if (strong_xoffset < 0)
6220 priv->scroll_offset += strong_xoffset;
6223 else if (strong_xoffset > text_area_width)
6225 priv->scroll_offset += strong_xoffset - text_area_width;
6226 strong_xoffset = text_area_width;
6229 weak_xoffset = weak_x - priv->scroll_offset;
6231 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6233 priv->scroll_offset += weak_xoffset;
6235 else if (weak_xoffset > text_area_width &&
6236 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6238 priv->scroll_offset += weak_xoffset - text_area_width;
6241 g_object_notify (G_OBJECT (entry), "scroll-offset");
6245 gtk_entry_move_adjustments (GtkEntry *entry)
6247 GtkWidget *widget = GTK_WIDGET (entry);
6248 GtkAllocation allocation;
6249 GtkAdjustment *adjustment;
6250 PangoContext *context;
6251 PangoFontMetrics *metrics;
6252 GtkStyleContext *style_context;
6253 GtkStateFlags state;
6254 gint x, layout_x, border_x, border_y;
6257 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6261 gtk_widget_get_allocation (widget, &allocation);
6263 /* Cursor position, layout offset, border width, and widget allocation */
6264 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6265 get_layout_position (entry, &layout_x, NULL);
6266 _gtk_entry_get_borders (entry, &border_x, &border_y);
6267 x += allocation.x + layout_x + border_x;
6269 /* Approximate width of a char, so user can see what is ahead/behind */
6270 context = gtk_widget_get_pango_context (widget);
6271 style_context = gtk_widget_get_style_context (widget);
6272 state = gtk_widget_get_state_flags (widget);
6274 metrics = pango_context_get_metrics (context,
6275 gtk_style_context_get_font (style_context, state),
6276 pango_context_get_language (context));
6277 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6280 gtk_adjustment_clamp_page (adjustment,
6281 x - (char_width + 1), /* one char + one pixel before */
6282 x + (char_width + 2)); /* one char + cursor + one pixel after */
6286 gtk_entry_move_visually (GtkEntry *entry,
6290 GtkEntryPrivate *priv = entry->priv;
6292 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6295 text = pango_layout_get_text (layout);
6297 index = g_utf8_offset_to_pointer (text, start) - text;
6301 int new_index, new_trailing;
6302 gboolean split_cursor;
6305 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6306 "gtk-split-cursor", &split_cursor,
6313 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6314 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6316 strong = keymap_direction == priv->resolved_dir;
6321 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6326 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6332 else if (new_index != G_MAXINT)
6335 while (new_trailing--)
6336 index = g_utf8_next_char (text + index) - text;
6339 return g_utf8_pointer_to_offset (text, text + index);
6343 gtk_entry_move_logically (GtkEntry *entry,
6347 gint new_pos = start;
6350 length = gtk_entry_buffer_get_length (get_buffer (entry));
6352 /* Prevent any leak of information */
6353 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6355 new_pos = CLAMP (start + count, 0, length);
6359 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6360 PangoLogAttr *log_attrs;
6363 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6365 while (count > 0 && new_pos < length)
6369 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6373 while (count < 0 && new_pos > 0)
6377 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6389 gtk_entry_move_forward_word (GtkEntry *entry,
6391 gboolean allow_whitespace)
6393 gint new_pos = start;
6396 length = gtk_entry_buffer_get_length (get_buffer (entry));
6398 /* Prevent any leak of information */
6399 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6403 else if (new_pos < length)
6405 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6406 PangoLogAttr *log_attrs;
6409 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6411 /* Find the next word boundary */
6413 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6414 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6425 gtk_entry_move_backward_word (GtkEntry *entry,
6427 gboolean allow_whitespace)
6429 gint new_pos = start;
6431 /* Prevent any leak of information */
6432 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6438 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6439 PangoLogAttr *log_attrs;
6442 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6444 new_pos = start - 1;
6446 /* Find the previous word boundary */
6447 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6448 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6458 gtk_entry_delete_whitespace (GtkEntry *entry)
6460 GtkEntryPrivate *priv = entry->priv;
6461 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6462 PangoLogAttr *log_attrs;
6466 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6468 start = end = priv->current_pos;
6470 while (start > 0 && log_attrs[start-1].is_white)
6473 while (end < n_attrs && log_attrs[end].is_white)
6479 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6484 gtk_entry_select_word (GtkEntry *entry)
6486 GtkEntryPrivate *priv = entry->priv;
6487 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6488 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6490 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6494 gtk_entry_select_line (GtkEntry *entry)
6496 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6500 truncate_multiline (const gchar *text)
6505 text[length] && text[length] != '\n' && text[length] != '\r';
6512 paste_received (GtkClipboard *clipboard,
6516 GtkEntry *entry = GTK_ENTRY (data);
6517 GtkEditable *editable = GTK_EDITABLE (entry);
6518 GtkEntryPrivate *priv = entry->priv;
6520 if (priv->button == 2)
6522 gint pos, start, end;
6523 pos = priv->insert_pos;
6524 gtk_editable_get_selection_bounds (editable, &start, &end);
6525 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6526 gtk_editable_select_region (editable, pos, pos);
6531 gint pos, start, end;
6533 gboolean popup_completion;
6534 GtkEntryCompletion *completion;
6536 completion = gtk_entry_get_completion (entry);
6538 if (priv->truncate_multiline)
6539 length = truncate_multiline (text);
6541 /* only complete if the selection is at the end */
6542 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6543 MAX (priv->current_pos, priv->selection_bound));
6547 if (gtk_widget_get_mapped (completion->priv->popup_window))
6548 _gtk_entry_completion_popdown (completion);
6550 if (!popup_completion && completion->priv->changed_id > 0)
6551 g_signal_handler_block (entry, completion->priv->changed_id);
6554 begin_change (entry);
6555 g_object_freeze_notify (G_OBJECT (entry));
6556 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6557 gtk_editable_delete_text (editable, start, end);
6559 pos = priv->current_pos;
6560 gtk_editable_insert_text (editable, text, length, &pos);
6561 gtk_editable_set_position (editable, pos);
6562 g_object_thaw_notify (G_OBJECT (entry));
6566 !popup_completion && completion->priv->changed_id > 0)
6567 g_signal_handler_unblock (entry, completion->priv->changed_id);
6570 g_object_unref (entry);
6574 gtk_entry_paste (GtkEntry *entry,
6577 g_object_ref (entry);
6578 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6579 paste_received, entry);
6583 primary_get_cb (GtkClipboard *clipboard,
6584 GtkSelectionData *selection_data,
6588 GtkEntry *entry = GTK_ENTRY (data);
6591 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6593 gchar *str = gtk_entry_get_display_text (entry, start, end);
6594 gtk_selection_data_set_text (selection_data, str, -1);
6600 primary_clear_cb (GtkClipboard *clipboard,
6603 GtkEntry *entry = GTK_ENTRY (data);
6604 GtkEntryPrivate *priv = entry->priv;
6606 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6610 gtk_entry_update_primary_selection (GtkEntry *entry)
6612 GtkTargetList *list;
6613 GtkTargetEntry *targets;
6614 GtkClipboard *clipboard;
6618 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6621 list = gtk_target_list_new (NULL, 0);
6622 gtk_target_list_add_text_targets (list, 0);
6624 targets = gtk_target_table_new_from_list (list, &n_targets);
6626 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6628 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6630 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6631 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6632 primary_clear_cb (clipboard, entry);
6636 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6637 gtk_clipboard_clear (clipboard);
6640 gtk_target_table_free (targets, n_targets);
6641 gtk_target_list_unref (list);
6645 gtk_entry_clear (GtkEntry *entry,
6646 GtkEntryIconPosition icon_pos)
6648 GtkEntryPrivate *priv = entry->priv;
6649 EntryIconInfo *icon_info = priv->icons[icon_pos];
6651 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6654 g_object_freeze_notify (G_OBJECT (entry));
6656 /* Explicitly check, as the pointer may become invalidated
6657 * during destruction.
6659 if (GDK_IS_WINDOW (icon_info->window))
6660 gdk_window_hide (icon_info->window);
6662 if (icon_info->pixbuf)
6664 g_object_unref (icon_info->pixbuf);
6665 icon_info->pixbuf = NULL;
6668 switch (icon_info->storage_type)
6670 case GTK_IMAGE_PIXBUF:
6671 g_object_notify (G_OBJECT (entry),
6672 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6675 case GTK_IMAGE_STOCK:
6676 g_free (icon_info->stock_id);
6677 icon_info->stock_id = NULL;
6678 g_object_notify (G_OBJECT (entry),
6679 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6682 case GTK_IMAGE_ICON_NAME:
6683 g_free (icon_info->icon_name);
6684 icon_info->icon_name = NULL;
6685 g_object_notify (G_OBJECT (entry),
6686 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6689 case GTK_IMAGE_GICON:
6690 if (icon_info->gicon)
6692 g_object_unref (icon_info->gicon);
6693 icon_info->gicon = NULL;
6695 g_object_notify (G_OBJECT (entry),
6696 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6700 g_assert_not_reached ();
6704 icon_info->storage_type = GTK_IMAGE_EMPTY;
6705 g_object_notify (G_OBJECT (entry),
6706 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6708 g_object_thaw_notify (G_OBJECT (entry));
6712 create_normal_pixbuf (GtkStyleContext *context,
6713 const gchar *stock_id,
6714 GtkIconSize icon_size)
6716 GtkIconSet *icon_set;
6719 gtk_style_context_save (context);
6721 /* Unset any state */
6722 gtk_style_context_set_state (context, 0);
6724 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6725 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6727 gtk_style_context_restore (context);
6733 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6734 GtkEntryIconPosition icon_pos)
6736 GtkEntryPrivate *priv = entry->priv;
6737 EntryIconInfo *icon_info = priv->icons[icon_pos];
6738 GtkStyleContext *context;
6740 GtkIconTheme *icon_theme;
6741 GtkSettings *settings;
6746 if (!icon_info || icon_info->pixbuf)
6749 widget = GTK_WIDGET (entry);
6750 context = gtk_widget_get_style_context (widget);
6752 switch (icon_info->storage_type)
6754 case GTK_IMAGE_EMPTY:
6755 case GTK_IMAGE_PIXBUF:
6757 case GTK_IMAGE_STOCK:
6758 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6759 GTK_ICON_SIZE_MENU);
6761 if (!icon_info->pixbuf)
6762 icon_info->pixbuf = create_normal_pixbuf (context,
6763 GTK_STOCK_MISSING_IMAGE,
6764 GTK_ICON_SIZE_MENU);
6767 case GTK_IMAGE_ICON_NAME:
6768 screen = gtk_widget_get_screen (widget);
6771 icon_theme = gtk_icon_theme_get_for_screen (screen);
6772 settings = gtk_settings_get_for_screen (screen);
6774 gtk_icon_size_lookup_for_settings (settings,
6778 info = gtk_icon_theme_lookup_icon (icon_theme,
6779 icon_info->icon_name,
6780 MIN (width, height),
6785 gtk_icon_info_load_symbolic_for_context (info,
6787 &icon_info->symbolic,
6789 gtk_icon_info_free (info);
6792 if (icon_info->pixbuf == NULL)
6793 icon_info->pixbuf = create_normal_pixbuf (context,
6794 GTK_STOCK_MISSING_IMAGE,
6795 GTK_ICON_SIZE_MENU);
6799 case GTK_IMAGE_GICON:
6800 screen = gtk_widget_get_screen (widget);
6803 icon_theme = gtk_icon_theme_get_for_screen (screen);
6804 settings = gtk_settings_get_for_screen (screen);
6806 gtk_icon_size_lookup_for_settings (settings,
6810 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6812 MIN (width, height),
6813 GTK_ICON_LOOKUP_USE_BUILTIN);
6817 gtk_icon_info_load_symbolic_for_context (info,
6819 &icon_info->symbolic,
6821 gtk_icon_info_free (info);
6824 if (icon_info->pixbuf == NULL)
6825 icon_info->pixbuf = create_normal_pixbuf (context,
6826 GTK_STOCK_MISSING_IMAGE,
6827 GTK_ICON_SIZE_MENU);
6832 g_assert_not_reached ();
6836 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6837 gdk_window_show_unraised (icon_info->window);
6847 * Creates a new entry.
6849 * Return value: a new #GtkEntry.
6852 gtk_entry_new (void)
6854 return g_object_new (GTK_TYPE_ENTRY, NULL);
6858 * gtk_entry_new_with_buffer:
6859 * @buffer: The buffer to use for the new #GtkEntry.
6861 * Creates a new entry with the specified text buffer.
6863 * Return value: a new #GtkEntry
6868 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6870 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6871 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6874 static GtkEntryBuffer*
6875 get_buffer (GtkEntry *entry)
6877 GtkEntryPrivate *priv = entry->priv;
6879 if (priv->buffer == NULL)
6881 GtkEntryBuffer *buffer;
6882 buffer = gtk_entry_buffer_new (NULL, 0);
6883 gtk_entry_set_buffer (entry, buffer);
6884 g_object_unref (buffer);
6887 return priv->buffer;
6891 * gtk_entry_get_buffer:
6892 * @entry: a #GtkEntry
6894 * Get the #GtkEntryBuffer object which holds the text for
6899 * Returns: (transfer none): A #GtkEntryBuffer object.
6902 gtk_entry_get_buffer (GtkEntry *entry)
6904 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6906 return get_buffer (entry);
6910 * gtk_entry_set_buffer:
6911 * @entry: a #GtkEntry
6912 * @buffer: a #GtkEntryBuffer
6914 * Set the #GtkEntryBuffer object which holds the text for
6920 gtk_entry_set_buffer (GtkEntry *entry,
6921 GtkEntryBuffer *buffer)
6923 GtkEntryPrivate *priv;
6926 g_return_if_fail (GTK_IS_ENTRY (entry));
6932 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6933 g_object_ref (buffer);
6938 buffer_disconnect_signals (entry);
6939 g_object_unref (priv->buffer);
6942 priv->buffer = buffer;
6945 buffer_connect_signals (entry);
6947 obj = G_OBJECT (entry);
6948 g_object_freeze_notify (obj);
6949 g_object_notify (obj, "buffer");
6950 g_object_notify (obj, "text");
6951 g_object_notify (obj, "text-length");
6952 g_object_notify (obj, "max-length");
6953 g_object_notify (obj, "visibility");
6954 g_object_notify (obj, "invisible-char");
6955 g_object_notify (obj, "invisible-char-set");
6956 g_object_thaw_notify (obj);
6958 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6959 gtk_entry_recompute (entry);
6963 * gtk_entry_get_text_area:
6964 * @entry: a #GtkEntry
6965 * @text_area: (out): Return location for the text area.
6967 * Gets the area where the entry's text is drawn. This function is
6968 * useful when drawing something to the entry in a draw callback.
6970 * If the entry is not realized, @text_area is filled with zeros.
6972 * See also gtk_entry_get_icon_area().
6977 gtk_entry_get_text_area (GtkEntry *entry,
6978 GdkRectangle *text_area)
6980 GtkEntryPrivate *priv;
6982 g_return_if_fail (GTK_IS_ENTRY (entry));
6983 g_return_if_fail (text_area != NULL);
6987 if (priv->text_area)
6989 GtkAllocation allocation;
6992 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6993 gdk_window_get_position (priv->text_area, &x, &y);
6995 text_area->x = x - allocation.x;
6996 text_area->y = y - allocation.y;
6997 text_area->width = gdk_window_get_width (priv->text_area);
6998 text_area->height = gdk_window_get_height (priv->text_area);
7004 text_area->width = 0;
7005 text_area->height = 0;
7010 * gtk_entry_set_text:
7011 * @entry: a #GtkEntry
7012 * @text: the new text
7014 * Sets the text in the widget to the given
7015 * value, replacing the current contents.
7017 * See gtk_entry_buffer_set_text().
7020 gtk_entry_set_text (GtkEntry *entry,
7024 GtkEntryCompletion *completion;
7026 g_return_if_fail (GTK_IS_ENTRY (entry));
7027 g_return_if_fail (text != NULL);
7029 /* Actually setting the text will affect the cursor and selection;
7030 * if the contents don't actually change, this will look odd to the user.
7032 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7035 completion = gtk_entry_get_completion (entry);
7036 if (completion && completion->priv->changed_id > 0)
7037 g_signal_handler_block (entry, completion->priv->changed_id);
7039 begin_change (entry);
7040 g_object_freeze_notify (G_OBJECT (entry));
7041 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7043 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7044 g_object_thaw_notify (G_OBJECT (entry));
7047 if (completion && completion->priv->changed_id > 0)
7048 g_signal_handler_unblock (entry, completion->priv->changed_id);
7052 * gtk_entry_set_visibility:
7053 * @entry: a #GtkEntry
7054 * @visible: %TRUE if the contents of the entry are displayed
7057 * Sets whether the contents of the entry are visible or not.
7058 * When visibility is set to %FALSE, characters are displayed
7059 * as the invisible char, and will also appear that way when
7060 * the text in the entry widget is copied elsewhere.
7062 * By default, GTK+ picks the best invisible character available
7063 * in the current font, but it can be changed with
7064 * gtk_entry_set_invisible_char().
7067 gtk_entry_set_visibility (GtkEntry *entry,
7070 GtkEntryPrivate *priv;
7072 g_return_if_fail (GTK_IS_ENTRY (entry));
7076 visible = visible != FALSE;
7078 if (priv->visible != visible)
7080 priv->visible = visible;
7082 g_object_notify (G_OBJECT (entry), "visibility");
7083 gtk_entry_recompute (entry);
7088 * gtk_entry_get_visibility:
7089 * @entry: a #GtkEntry
7091 * Retrieves whether the text in @entry is visible. See
7092 * gtk_entry_set_visibility().
7094 * Return value: %TRUE if the text is currently visible
7097 gtk_entry_get_visibility (GtkEntry *entry)
7099 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7101 return entry->priv->visible;
7105 * gtk_entry_set_invisible_char:
7106 * @entry: a #GtkEntry
7107 * @ch: a Unicode character
7109 * Sets the character to use in place of the actual text when
7110 * gtk_entry_set_visibility() has been called to set text visibility
7111 * to %FALSE. i.e. this is the character used in "password mode" to
7112 * show the user how many characters have been typed. By default, GTK+
7113 * picks the best invisible char available in the current font. If you
7114 * set the invisible char to 0, then the user will get no feedback
7115 * at all; there will be no text on the screen as they type.
7118 gtk_entry_set_invisible_char (GtkEntry *entry,
7121 GtkEntryPrivate *priv;
7123 g_return_if_fail (GTK_IS_ENTRY (entry));
7127 if (!priv->invisible_char_set)
7129 priv->invisible_char_set = TRUE;
7130 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7133 if (ch == priv->invisible_char)
7136 priv->invisible_char = ch;
7137 g_object_notify (G_OBJECT (entry), "invisible-char");
7138 gtk_entry_recompute (entry);
7142 * gtk_entry_get_invisible_char:
7143 * @entry: a #GtkEntry
7145 * Retrieves the character displayed in place of the real characters
7146 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7148 * Return value: the current invisible char, or 0, if the entry does not
7149 * show invisible text at all.
7152 gtk_entry_get_invisible_char (GtkEntry *entry)
7154 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7156 return entry->priv->invisible_char;
7160 * gtk_entry_unset_invisible_char:
7161 * @entry: a #GtkEntry
7163 * Unsets the invisible char previously set with
7164 * gtk_entry_set_invisible_char(). So that the
7165 * default invisible char is used again.
7170 gtk_entry_unset_invisible_char (GtkEntry *entry)
7172 GtkEntryPrivate *priv;
7175 g_return_if_fail (GTK_IS_ENTRY (entry));
7179 if (!priv->invisible_char_set)
7182 priv->invisible_char_set = FALSE;
7183 ch = find_invisible_char (GTK_WIDGET (entry));
7185 if (priv->invisible_char != ch)
7187 priv->invisible_char = ch;
7188 g_object_notify (G_OBJECT (entry), "invisible-char");
7191 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7192 gtk_entry_recompute (entry);
7196 * gtk_entry_set_overwrite_mode:
7197 * @entry: a #GtkEntry
7198 * @overwrite: new value
7200 * Sets whether the text is overwritten when typing in the #GtkEntry.
7205 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7208 GtkEntryPrivate *priv = entry->priv;
7210 g_return_if_fail (GTK_IS_ENTRY (entry));
7212 if (priv->overwrite_mode == overwrite)
7215 gtk_entry_toggle_overwrite (entry);
7217 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7221 * gtk_entry_get_overwrite_mode:
7222 * @entry: a #GtkEntry
7224 * Gets the value set by gtk_entry_set_overwrite_mode().
7226 * Return value: whether the text is overwritten when typing.
7231 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7233 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7235 return entry->priv->overwrite_mode;
7239 * gtk_entry_get_text:
7240 * @entry: a #GtkEntry
7242 * Retrieves the contents of the entry widget.
7243 * See also gtk_editable_get_chars().
7245 * This is equivalent to:
7247 * <informalexample><programlisting>
7248 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7249 * </programlisting></informalexample>
7251 * Return value: a pointer to the contents of the widget as a
7252 * string. This string points to internally allocated
7253 * storage in the widget and must not be freed, modified or
7256 G_CONST_RETURN gchar*
7257 gtk_entry_get_text (GtkEntry *entry)
7259 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7261 return gtk_entry_buffer_get_text (get_buffer (entry));
7265 * gtk_entry_set_max_length:
7266 * @entry: a #GtkEntry
7267 * @max: the maximum length of the entry, or 0 for no maximum.
7268 * (other than the maximum length of entries.) The value passed in will
7269 * be clamped to the range 0-65536.
7271 * Sets the maximum allowed length of the contents of the widget. If
7272 * the current contents are longer than the given length, then they
7273 * will be truncated to fit.
7275 * This is equivalent to:
7277 * <informalexample><programlisting>
7278 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7279 * </programlisting></informalexample>
7282 gtk_entry_set_max_length (GtkEntry *entry,
7285 g_return_if_fail (GTK_IS_ENTRY (entry));
7286 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7290 * gtk_entry_get_max_length:
7291 * @entry: a #GtkEntry
7293 * Retrieves the maximum allowed length of the text in
7294 * @entry. See gtk_entry_set_max_length().
7296 * This is equivalent to:
7298 * <informalexample><programlisting>
7299 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7300 * </programlisting></informalexample>
7302 * Return value: the maximum allowed number of characters
7303 * in #GtkEntry, or 0 if there is no maximum.
7306 gtk_entry_get_max_length (GtkEntry *entry)
7308 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7310 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7314 * gtk_entry_get_text_length:
7315 * @entry: a #GtkEntry
7317 * Retrieves the current length of the text in
7320 * This is equivalent to:
7322 * <informalexample><programlisting>
7323 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7324 * </programlisting></informalexample>
7326 * Return value: the current number of characters
7327 * in #GtkEntry, or 0 if there are none.
7332 gtk_entry_get_text_length (GtkEntry *entry)
7334 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7336 return gtk_entry_buffer_get_length (get_buffer (entry));
7340 * gtk_entry_set_activates_default:
7341 * @entry: a #GtkEntry
7342 * @setting: %TRUE to activate window's default widget on Enter keypress
7344 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7345 * widget for the window containing the entry. This usually means that
7346 * the dialog box containing the entry will be closed, since the default
7347 * widget is usually one of the dialog buttons.
7349 * (For experts: if @setting is %TRUE, the entry calls
7350 * gtk_window_activate_default() on the window containing the entry, in
7351 * the default handler for the #GtkWidget::activate signal.)
7354 gtk_entry_set_activates_default (GtkEntry *entry,
7357 GtkEntryPrivate *priv;
7359 g_return_if_fail (GTK_IS_ENTRY (entry));
7363 setting = setting != FALSE;
7365 if (setting != priv->activates_default)
7367 priv->activates_default = setting;
7368 g_object_notify (G_OBJECT (entry), "activates-default");
7373 * gtk_entry_get_activates_default:
7374 * @entry: a #GtkEntry
7376 * Retrieves the value set by gtk_entry_set_activates_default().
7378 * Return value: %TRUE if the entry will activate the default widget
7381 gtk_entry_get_activates_default (GtkEntry *entry)
7383 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7385 return entry->priv->activates_default;
7389 * gtk_entry_set_width_chars:
7390 * @entry: a #GtkEntry
7391 * @n_chars: width in chars
7393 * Changes the size request of the entry to be about the right size
7394 * for @n_chars characters. Note that it changes the size
7395 * <emphasis>request</emphasis>, the size can still be affected by
7396 * how you pack the widget into containers. If @n_chars is -1, the
7397 * size reverts to the default entry size.
7400 gtk_entry_set_width_chars (GtkEntry *entry,
7403 GtkEntryPrivate *priv;
7405 g_return_if_fail (GTK_IS_ENTRY (entry));
7409 if (priv->width_chars != n_chars)
7411 priv->width_chars = n_chars;
7412 g_object_notify (G_OBJECT (entry), "width-chars");
7413 gtk_widget_queue_resize (GTK_WIDGET (entry));
7418 * gtk_entry_get_width_chars:
7419 * @entry: a #GtkEntry
7421 * Gets the value set by gtk_entry_set_width_chars().
7423 * Return value: number of chars to request space for, or negative if unset
7426 gtk_entry_get_width_chars (GtkEntry *entry)
7428 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7430 return entry->priv->width_chars;
7434 * gtk_entry_set_has_frame:
7435 * @entry: a #GtkEntry
7436 * @setting: new value
7438 * Sets whether the entry has a beveled frame around it.
7441 gtk_entry_set_has_frame (GtkEntry *entry,
7444 GtkEntryPrivate *priv;
7446 g_return_if_fail (GTK_IS_ENTRY (entry));
7450 setting = (setting != FALSE);
7452 if (priv->has_frame == setting)
7455 gtk_widget_queue_resize (GTK_WIDGET (entry));
7456 priv->has_frame = setting;
7457 g_object_notify (G_OBJECT (entry), "has-frame");
7461 * gtk_entry_get_has_frame:
7462 * @entry: a #GtkEntry
7464 * Gets the value set by gtk_entry_set_has_frame().
7466 * Return value: whether the entry has a beveled frame
7469 gtk_entry_get_has_frame (GtkEntry *entry)
7471 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7473 return entry->priv->has_frame;
7477 * gtk_entry_set_inner_border:
7478 * @entry: a #GtkEntry
7479 * @border: (allow-none): a #GtkBorder, or %NULL
7481 * Sets %entry's inner-border property to %border, or clears it if %NULL
7482 * is passed. The inner-border is the area around the entry's text, but
7485 * If set, this property overrides the inner-border style property.
7486 * Overriding the style-provided border is useful when you want to do
7487 * in-place editing of some text in a canvas or list widget, where
7488 * pixel-exact positioning of the entry is important.
7493 gtk_entry_set_inner_border (GtkEntry *entry,
7494 const GtkBorder *border)
7496 g_return_if_fail (GTK_IS_ENTRY (entry));
7498 gtk_widget_queue_resize (GTK_WIDGET (entry));
7501 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7502 gtk_border_copy (border),
7503 (GDestroyNotify) gtk_border_free);
7505 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7507 g_object_notify (G_OBJECT (entry), "inner-border");
7511 * gtk_entry_get_inner_border:
7512 * @entry: a #GtkEntry
7514 * This function returns the entry's #GtkEntry:inner-border property. See
7515 * gtk_entry_set_inner_border() for more information.
7517 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7521 G_CONST_RETURN GtkBorder *
7522 gtk_entry_get_inner_border (GtkEntry *entry)
7524 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7526 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7530 * gtk_entry_get_layout:
7531 * @entry: a #GtkEntry
7533 * Gets the #PangoLayout used to display the entry.
7534 * The layout is useful to e.g. convert text positions to
7535 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7536 * The returned layout is owned by the entry and must not be
7537 * modified or freed by the caller.
7539 * Keep in mind that the layout text may contain a preedit string, so
7540 * gtk_entry_layout_index_to_text_index() and
7541 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7542 * indices in the layout to byte indices in the entry contents.
7544 * Return value: (transfer none): the #PangoLayout for this entry
7547 gtk_entry_get_layout (GtkEntry *entry)
7549 PangoLayout *layout;
7551 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7553 layout = gtk_entry_ensure_layout (entry, TRUE);
7560 * gtk_entry_layout_index_to_text_index:
7561 * @entry: a #GtkEntry
7562 * @layout_index: byte index into the entry layout text
7564 * Converts from a position in the entry contents (returned
7565 * by gtk_entry_get_text()) to a position in the
7566 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7567 * with text retrieved via pango_layout_get_text()).
7569 * Return value: byte index into the entry contents
7572 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7575 GtkEntryPrivate *priv;
7576 PangoLayout *layout;
7580 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7584 layout = gtk_entry_ensure_layout (entry, TRUE);
7585 text = pango_layout_get_text (layout);
7586 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7588 if (layout_index >= cursor_index && priv->preedit_length)
7590 if (layout_index >= cursor_index + priv->preedit_length)
7591 layout_index -= priv->preedit_length;
7593 layout_index = cursor_index;
7596 return layout_index;
7600 * gtk_entry_text_index_to_layout_index:
7601 * @entry: a #GtkEntry
7602 * @text_index: byte index into the entry contents
7604 * Converts from a position in the entry's #PangoLayout (returned by
7605 * gtk_entry_get_layout()) to a position in the entry contents
7606 * (returned by gtk_entry_get_text()).
7608 * Return value: byte index into the entry layout text
7611 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7614 GtkEntryPrivate *priv;
7615 PangoLayout *layout;
7619 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7623 layout = gtk_entry_ensure_layout (entry, TRUE);
7624 text = pango_layout_get_text (layout);
7625 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7627 if (text_index > cursor_index)
7628 text_index += priv->preedit_length;
7634 * gtk_entry_get_layout_offsets:
7635 * @entry: a #GtkEntry
7636 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7637 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7640 * Obtains the position of the #PangoLayout used to render text
7641 * in the entry, in widget coordinates. Useful if you want to line
7642 * up the text in an entry with some other text, e.g. when using the
7643 * entry to implement editable cells in a sheet widget.
7645 * Also useful to convert mouse events into coordinates inside the
7646 * #PangoLayout, e.g. to take some action if some part of the entry text
7649 * Note that as the user scrolls around in the entry the offsets will
7650 * change; you'll need to connect to the "notify::scroll-offset"
7651 * signal to track this. Remember when using the #PangoLayout
7652 * functions you need to convert to and from pixels using
7653 * PANGO_PIXELS() or #PANGO_SCALE.
7655 * Keep in mind that the layout text may contain a preedit string, so
7656 * gtk_entry_layout_index_to_text_index() and
7657 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7658 * indices in the layout to byte indices in the entry contents.
7661 gtk_entry_get_layout_offsets (GtkEntry *entry,
7665 gint text_area_x, text_area_y;
7667 g_return_if_fail (GTK_IS_ENTRY (entry));
7669 /* this gets coords relative to text area */
7670 get_layout_position (entry, x, y);
7672 /* convert to widget coords */
7673 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7684 * gtk_entry_set_alignment:
7685 * @entry: a #GtkEntry
7686 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7687 * Reversed for RTL layouts
7689 * Sets the alignment for the contents of the entry. This controls
7690 * the horizontal positioning of the contents when the displayed
7691 * text is shorter than the width of the entry.
7696 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7698 GtkEntryPrivate *priv;
7700 g_return_if_fail (GTK_IS_ENTRY (entry));
7706 else if (xalign > 1.0)
7709 if (xalign != priv->xalign)
7711 priv->xalign = xalign;
7713 gtk_entry_recompute (entry);
7715 g_object_notify (G_OBJECT (entry), "xalign");
7720 * gtk_entry_get_alignment:
7721 * @entry: a #GtkEntry
7723 * Gets the value set by gtk_entry_set_alignment().
7725 * Return value: the alignment
7730 gtk_entry_get_alignment (GtkEntry *entry)
7732 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7734 return entry->priv->xalign;
7738 * gtk_entry_set_icon_from_pixbuf:
7739 * @entry: a #GtkEntry
7740 * @icon_pos: Icon position
7741 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7743 * Sets the icon shown in the specified position using a pixbuf.
7745 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7750 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7751 GtkEntryIconPosition icon_pos,
7754 GtkEntryPrivate *priv;
7755 EntryIconInfo *icon_info;
7757 g_return_if_fail (GTK_IS_ENTRY (entry));
7758 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7762 if ((icon_info = priv->icons[icon_pos]) == NULL)
7763 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7765 g_object_freeze_notify (G_OBJECT (entry));
7768 g_object_ref (pixbuf);
7770 gtk_entry_clear (entry, icon_pos);
7774 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7775 icon_info->pixbuf = pixbuf;
7777 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7779 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7780 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7784 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7785 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7788 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7789 gdk_window_show_unraised (icon_info->window);
7792 gtk_entry_ensure_pixbuf (entry, icon_pos);
7794 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7795 gtk_widget_queue_resize (GTK_WIDGET (entry));
7797 g_object_thaw_notify (G_OBJECT (entry));
7801 * gtk_entry_set_icon_from_stock:
7802 * @entry: A #GtkEntry
7803 * @icon_pos: Icon position
7804 * @stock_id: (allow-none): The name of the stock item, or %NULL
7806 * Sets the icon shown in the entry at the specified position from
7809 * If @stock_id is %NULL, no icon will be shown in the specified position.
7814 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7815 GtkEntryIconPosition icon_pos,
7816 const gchar *stock_id)
7818 GtkEntryPrivate *priv;
7819 EntryIconInfo *icon_info;
7822 g_return_if_fail (GTK_IS_ENTRY (entry));
7823 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7827 if ((icon_info = priv->icons[icon_pos]) == NULL)
7828 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7830 g_object_freeze_notify (G_OBJECT (entry));
7832 /* need to dup before clearing */
7833 new_id = g_strdup (stock_id);
7835 gtk_entry_clear (entry, icon_pos);
7839 icon_info->storage_type = GTK_IMAGE_STOCK;
7840 icon_info->stock_id = new_id;
7842 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7844 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7845 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7849 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7850 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7853 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7854 gdk_window_show_unraised (icon_info->window);
7857 gtk_entry_ensure_pixbuf (entry, icon_pos);
7859 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7860 gtk_widget_queue_resize (GTK_WIDGET (entry));
7862 g_object_thaw_notify (G_OBJECT (entry));
7866 * gtk_entry_set_icon_from_icon_name:
7867 * @entry: A #GtkEntry
7868 * @icon_pos: The position at which to set the icon
7869 * @icon_name: (allow-none): An icon name, or %NULL
7871 * Sets the icon shown in the entry at the specified position
7872 * from the current icon theme.
7874 * If the icon name isn't known, a "broken image" icon will be displayed
7877 * If @icon_name is %NULL, no icon will be shown in the specified position.
7882 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7883 GtkEntryIconPosition icon_pos,
7884 const gchar *icon_name)
7886 GtkEntryPrivate *priv;
7887 EntryIconInfo *icon_info;
7890 g_return_if_fail (GTK_IS_ENTRY (entry));
7891 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7895 if ((icon_info = priv->icons[icon_pos]) == NULL)
7896 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7898 g_object_freeze_notify (G_OBJECT (entry));
7900 /* need to dup before clearing */
7901 new_name = g_strdup (icon_name);
7903 gtk_entry_clear (entry, icon_pos);
7905 if (new_name != NULL)
7907 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7908 icon_info->icon_name = new_name;
7910 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7912 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7913 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7917 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7918 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7921 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7922 gdk_window_show_unraised (icon_info->window);
7925 gtk_entry_ensure_pixbuf (entry, icon_pos);
7927 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7928 gtk_widget_queue_resize (GTK_WIDGET (entry));
7930 g_object_thaw_notify (G_OBJECT (entry));
7934 * gtk_entry_set_icon_from_gicon:
7935 * @entry: A #GtkEntry
7936 * @icon_pos: The position at which to set the icon
7937 * @icon: (allow-none): The icon to set, or %NULL
7939 * Sets the icon shown in the entry at the specified position
7940 * from the current icon theme.
7941 * If the icon isn't known, a "broken image" icon will be displayed
7944 * If @icon is %NULL, no icon will be shown in the specified position.
7949 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7950 GtkEntryIconPosition icon_pos,
7953 GtkEntryPrivate *priv;
7954 EntryIconInfo *icon_info;
7956 g_return_if_fail (GTK_IS_ENTRY (entry));
7957 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7961 if ((icon_info = priv->icons[icon_pos]) == NULL)
7962 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7964 g_object_freeze_notify (G_OBJECT (entry));
7966 /* need to ref before clearing */
7968 g_object_ref (icon);
7970 gtk_entry_clear (entry, icon_pos);
7974 icon_info->storage_type = GTK_IMAGE_GICON;
7975 icon_info->gicon = icon;
7977 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7979 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7980 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7984 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7985 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7988 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7989 gdk_window_show_unraised (icon_info->window);
7992 gtk_entry_ensure_pixbuf (entry, icon_pos);
7994 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7995 gtk_widget_queue_resize (GTK_WIDGET (entry));
7997 g_object_thaw_notify (G_OBJECT (entry));
8001 * gtk_entry_set_icon_activatable:
8002 * @entry: A #GtkEntry
8003 * @icon_pos: Icon position
8004 * @activatable: %TRUE if the icon should be activatable
8006 * Sets whether the icon is activatable.
8011 gtk_entry_set_icon_activatable (GtkEntry *entry,
8012 GtkEntryIconPosition icon_pos,
8013 gboolean activatable)
8015 GtkEntryPrivate *priv;
8016 EntryIconInfo *icon_info;
8018 g_return_if_fail (GTK_IS_ENTRY (entry));
8019 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8023 if ((icon_info = priv->icons[icon_pos]) == NULL)
8024 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8026 activatable = activatable != FALSE;
8028 if (icon_info->nonactivatable != !activatable)
8030 icon_info->nonactivatable = !activatable;
8032 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8033 update_cursors (GTK_WIDGET (entry));
8035 g_object_notify (G_OBJECT (entry),
8036 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8041 * gtk_entry_get_icon_activatable:
8042 * @entry: a #GtkEntry
8043 * @icon_pos: Icon position
8045 * Returns whether the icon is activatable.
8047 * Returns: %TRUE if the icon is activatable.
8052 gtk_entry_get_icon_activatable (GtkEntry *entry,
8053 GtkEntryIconPosition icon_pos)
8055 GtkEntryPrivate *priv;
8056 EntryIconInfo *icon_info;
8058 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8059 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8062 icon_info = priv->icons[icon_pos];
8064 return (!icon_info || !icon_info->nonactivatable);
8068 * gtk_entry_get_icon_pixbuf:
8069 * @entry: A #GtkEntry
8070 * @icon_pos: Icon position
8072 * Retrieves the image used for the icon.
8074 * Unlike the other methods of setting and getting icon data, this
8075 * method will work regardless of whether the icon was set using a
8076 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8078 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8079 * set for this position.
8084 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8085 GtkEntryIconPosition icon_pos)
8087 GtkEntryPrivate *priv;
8088 EntryIconInfo *icon_info;
8090 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8091 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8095 icon_info = priv->icons[icon_pos];
8100 gtk_entry_ensure_pixbuf (entry, icon_pos);
8102 return icon_info->pixbuf;
8106 * gtk_entry_get_icon_gicon:
8107 * @entry: A #GtkEntry
8108 * @icon_pos: Icon position
8110 * Retrieves the #GIcon used for the icon, or %NULL if there is
8111 * no icon or if the icon was set by some other method (e.g., by
8112 * stock, pixbuf, or icon name).
8114 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8115 * or if the icon is not a #GIcon
8120 gtk_entry_get_icon_gicon (GtkEntry *entry,
8121 GtkEntryIconPosition icon_pos)
8123 GtkEntryPrivate *priv;
8124 EntryIconInfo *icon_info;
8126 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8127 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8130 icon_info = priv->icons[icon_pos];
8135 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8139 * gtk_entry_get_icon_stock:
8140 * @entry: A #GtkEntry
8141 * @icon_pos: Icon position
8143 * Retrieves the stock id used for the icon, or %NULL if there is
8144 * no icon or if the icon was set by some other method (e.g., by
8145 * pixbuf, icon name or gicon).
8147 * Returns: A stock id, or %NULL if no icon is set or if the icon
8148 * wasn't set from a stock id
8153 gtk_entry_get_icon_stock (GtkEntry *entry,
8154 GtkEntryIconPosition icon_pos)
8156 GtkEntryPrivate *priv;
8157 EntryIconInfo *icon_info;
8159 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8160 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8163 icon_info = priv->icons[icon_pos];
8168 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8172 * gtk_entry_get_icon_name:
8173 * @entry: A #GtkEntry
8174 * @icon_pos: Icon position
8176 * Retrieves the icon name used for the icon, or %NULL if there is
8177 * no icon or if the icon was set by some other method (e.g., by
8178 * pixbuf, stock or gicon).
8180 * Returns: An icon name, or %NULL if no icon is set or if the icon
8181 * wasn't set from an icon name
8186 gtk_entry_get_icon_name (GtkEntry *entry,
8187 GtkEntryIconPosition icon_pos)
8189 GtkEntryPrivate *priv;
8190 EntryIconInfo *icon_info;
8192 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8193 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8196 icon_info = priv->icons[icon_pos];
8201 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8205 * gtk_entry_set_icon_sensitive:
8206 * @entry: A #GtkEntry
8207 * @icon_pos: Icon position
8208 * @sensitive: Specifies whether the icon should appear
8209 * sensitive or insensitive
8211 * Sets the sensitivity for the specified icon.
8216 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8217 GtkEntryIconPosition icon_pos,
8220 GtkEntryPrivate *priv;
8221 EntryIconInfo *icon_info;
8223 g_return_if_fail (GTK_IS_ENTRY (entry));
8224 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8228 if ((icon_info = priv->icons[icon_pos]) == NULL)
8229 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8231 if (icon_info->insensitive != !sensitive)
8233 icon_info->insensitive = !sensitive;
8235 icon_info->pressed = FALSE;
8236 icon_info->prelight = FALSE;
8238 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8239 update_cursors (GTK_WIDGET (entry));
8241 gtk_widget_queue_draw (GTK_WIDGET (entry));
8243 g_object_notify (G_OBJECT (entry),
8244 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8249 * gtk_entry_get_icon_sensitive:
8250 * @entry: a #GtkEntry
8251 * @icon_pos: Icon position
8253 * Returns whether the icon appears sensitive or insensitive.
8255 * Returns: %TRUE if the icon is sensitive.
8260 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8261 GtkEntryIconPosition icon_pos)
8263 GtkEntryPrivate *priv;
8264 EntryIconInfo *icon_info;
8266 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8267 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8271 icon_info = priv->icons[icon_pos];
8273 return (!icon_info || !icon_info->insensitive);
8278 * gtk_entry_get_icon_storage_type:
8279 * @entry: a #GtkEntry
8280 * @icon_pos: Icon position
8282 * Gets the type of representation being used by the icon
8283 * to store image data. If the icon has no image data,
8284 * the return value will be %GTK_IMAGE_EMPTY.
8286 * Return value: image representation being used
8291 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8292 GtkEntryIconPosition icon_pos)
8294 GtkEntryPrivate *priv;
8295 EntryIconInfo *icon_info;
8297 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8298 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8302 icon_info = priv->icons[icon_pos];
8305 return GTK_IMAGE_EMPTY;
8307 return icon_info->storage_type;
8311 * gtk_entry_get_icon_at_pos:
8312 * @entry: a #GtkEntry
8313 * @x: the x coordinate of the position to find
8314 * @y: the y coordinate of the position to find
8316 * Finds the icon at the given position and return its index. The
8317 * position's coordinates are relative to the @entry's top left corner.
8318 * If @x, @y doesn't lie inside an icon, -1 is returned.
8319 * This function is intended for use in a #GtkWidget::query-tooltip
8322 * Returns: the index of the icon at the given position, or -1
8327 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8331 GtkAllocation primary;
8332 GtkAllocation secondary;
8333 gint frame_x, frame_y;
8335 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8337 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8341 get_icon_allocations (entry, &primary, &secondary);
8343 if (primary.x <= x && x < primary.x + primary.width &&
8344 primary.y <= y && y < primary.y + primary.height)
8345 return GTK_ENTRY_ICON_PRIMARY;
8347 if (secondary.x <= x && x < secondary.x + secondary.width &&
8348 secondary.y <= y && y < secondary.y + secondary.height)
8349 return GTK_ENTRY_ICON_SECONDARY;
8355 * gtk_entry_set_icon_drag_source:
8356 * @entry: a #GtkIconEntry
8357 * @icon_pos: icon position
8358 * @target_list: the targets (data formats) in which the data can be provided
8359 * @actions: a bitmask of the allowed drag actions
8361 * Sets up the icon at the given position so that GTK+ will start a drag
8362 * operation when the user clicks and drags the icon.
8364 * To handle the drag operation, you need to connect to the usual
8365 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8366 * signal, and use gtk_entry_get_current_icon_drag_source() in
8367 * your signal handler to find out if the drag was started from
8370 * By default, GTK+ uses the icon as the drag icon. You can use the
8371 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8372 * have to use g_signal_connect_after() to ensure that your signal handler
8373 * gets executed after the default handler.
8378 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8379 GtkEntryIconPosition icon_pos,
8380 GtkTargetList *target_list,
8381 GdkDragAction actions)
8383 GtkEntryPrivate *priv;
8384 EntryIconInfo *icon_info;
8386 g_return_if_fail (GTK_IS_ENTRY (entry));
8387 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8391 if ((icon_info = priv->icons[icon_pos]) == NULL)
8392 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8394 if (icon_info->target_list)
8395 gtk_target_list_unref (icon_info->target_list);
8396 icon_info->target_list = target_list;
8397 if (icon_info->target_list)
8398 gtk_target_list_ref (icon_info->target_list);
8400 icon_info->actions = actions;
8404 * gtk_entry_get_current_icon_drag_source:
8405 * @entry: a #GtkIconEntry
8407 * Returns the index of the icon which is the source of the current
8408 * DND operation, or -1.
8410 * This function is meant to be used in a #GtkWidget::drag-data-get
8413 * Returns: index of the icon which is the source of the current
8414 * DND operation, or -1.
8419 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8421 GtkEntryPrivate *priv;
8422 EntryIconInfo *icon_info = NULL;
8425 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8429 for (i = 0; i < MAX_ICONS; i++)
8431 if ((icon_info = priv->icons[i]))
8433 if (icon_info->in_drag)
8442 * gtk_entry_get_icon_area:
8443 * @entry: A #GtkEntry
8444 * @icon_pos: Icon position
8445 * @icon_area: (out): Return location for the icon's area
8447 * Gets the area where entry's icon at @icon_pos is drawn.
8448 * This function is useful when drawing something to the
8449 * entry in a draw callback.
8451 * If the entry is not realized or has no icon at the given position,
8452 * @icon_area is filled with zeros.
8454 * See also gtk_entry_get_text_area()
8459 gtk_entry_get_icon_area (GtkEntry *entry,
8460 GtkEntryIconPosition icon_pos,
8461 GdkRectangle *icon_area)
8463 GtkEntryPrivate *priv;
8464 EntryIconInfo *icon_info;
8466 g_return_if_fail (GTK_IS_ENTRY (entry));
8467 g_return_if_fail (icon_area != NULL);
8471 icon_info = priv->icons[icon_pos];
8475 GtkAllocation primary;
8476 GtkAllocation secondary;
8478 get_icon_allocations (entry, &primary, &secondary);
8480 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8481 *icon_area = primary;
8483 *icon_area = secondary;
8489 icon_area->width = 0;
8490 icon_area->height = 0;
8495 ensure_has_tooltip (GtkEntry *entry)
8497 GtkEntryPrivate *priv;
8498 EntryIconInfo *icon_info;
8500 gboolean has_tooltip = FALSE;
8504 for (i = 0; i < MAX_ICONS; i++)
8506 if ((icon_info = priv->icons[i]) != NULL)
8508 if (icon_info->tooltip != NULL)
8516 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8520 * gtk_entry_get_icon_tooltip_text:
8521 * @entry: a #GtkEntry
8522 * @icon_pos: the icon position
8524 * Gets the contents of the tooltip on the icon at the specified
8525 * position in @entry.
8527 * Returns: the tooltip text, or %NULL. Free the returned string
8528 * with g_free() when done.
8533 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8534 GtkEntryIconPosition icon_pos)
8536 GtkEntryPrivate *priv;
8537 EntryIconInfo *icon_info;
8540 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8541 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8545 icon_info = priv->icons[icon_pos];
8550 if (icon_info->tooltip &&
8551 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8552 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8558 * gtk_entry_set_icon_tooltip_text:
8559 * @entry: a #GtkEntry
8560 * @icon_pos: the icon position
8561 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8563 * Sets @tooltip as the contents of the tooltip for the icon
8564 * at the specified position.
8566 * Use %NULL for @tooltip to remove an existing tooltip.
8568 * See also gtk_widget_set_tooltip_text() and
8569 * gtk_entry_set_icon_tooltip_markup().
8574 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8575 GtkEntryIconPosition icon_pos,
8576 const gchar *tooltip)
8578 GtkEntryPrivate *priv;
8579 EntryIconInfo *icon_info;
8581 g_return_if_fail (GTK_IS_ENTRY (entry));
8582 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8586 if ((icon_info = priv->icons[icon_pos]) == NULL)
8587 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8589 if (icon_info->tooltip)
8590 g_free (icon_info->tooltip);
8592 /* Treat an empty string as a NULL string,
8593 * because an empty string would be useless for a tooltip:
8595 if (tooltip && tooltip[0] == '\0')
8598 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8600 ensure_has_tooltip (entry);
8604 * gtk_entry_get_icon_tooltip_markup:
8605 * @entry: a #GtkEntry
8606 * @icon_pos: the icon position
8608 * Gets the contents of the tooltip on the icon at the specified
8609 * position in @entry.
8611 * Returns: the tooltip text, or %NULL. Free the returned string
8612 * with g_free() when done.
8617 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8618 GtkEntryIconPosition icon_pos)
8620 GtkEntryPrivate *priv;
8621 EntryIconInfo *icon_info;
8623 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8624 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8628 icon_info = priv->icons[icon_pos];
8633 return g_strdup (icon_info->tooltip);
8637 * gtk_entry_set_icon_tooltip_markup:
8638 * @entry: a #GtkEntry
8639 * @icon_pos: the icon position
8640 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8642 * Sets @tooltip as the contents of the tooltip for the icon at
8643 * the specified position. @tooltip is assumed to be marked up with
8644 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8646 * Use %NULL for @tooltip to remove an existing tooltip.
8648 * See also gtk_widget_set_tooltip_markup() and
8649 * gtk_enty_set_icon_tooltip_text().
8654 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8655 GtkEntryIconPosition icon_pos,
8656 const gchar *tooltip)
8658 GtkEntryPrivate *priv;
8659 EntryIconInfo *icon_info;
8661 g_return_if_fail (GTK_IS_ENTRY (entry));
8662 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8666 if ((icon_info = priv->icons[icon_pos]) == NULL)
8667 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8669 if (icon_info->tooltip)
8670 g_free (icon_info->tooltip);
8672 /* Treat an empty string as a NULL string,
8673 * because an empty string would be useless for a tooltip:
8675 if (tooltip && tooltip[0] == '\0')
8678 icon_info->tooltip = g_strdup (tooltip);
8680 ensure_has_tooltip (entry);
8684 gtk_entry_query_tooltip (GtkWidget *widget,
8687 gboolean keyboard_tip,
8688 GtkTooltip *tooltip)
8691 GtkEntryPrivate *priv;
8692 EntryIconInfo *icon_info;
8695 entry = GTK_ENTRY (widget);
8700 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8703 if ((icon_info = priv->icons[icon_pos]) != NULL)
8705 if (icon_info->tooltip)
8707 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8716 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8723 /* Quick hack of a popup menu
8726 activate_cb (GtkWidget *menuitem,
8729 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8730 g_signal_emit_by_name (entry, signal);
8735 gtk_entry_mnemonic_activate (GtkWidget *widget,
8736 gboolean group_cycling)
8738 gtk_widget_grab_focus (widget);
8743 append_action_signal (GtkEntry *entry,
8745 const gchar *stock_id,
8746 const gchar *signal,
8749 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8751 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8752 g_signal_connect (menuitem, "activate",
8753 G_CALLBACK (activate_cb), entry);
8755 gtk_widget_set_sensitive (menuitem, sensitive);
8757 gtk_widget_show (menuitem);
8758 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8762 popup_menu_detach (GtkWidget *attach_widget,
8765 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8766 GtkEntryPrivate *priv_attach = entry_attach->priv;
8768 priv_attach->popup_menu = NULL;
8772 popup_position_func (GtkMenu *menu,
8778 GtkEntry *entry = GTK_ENTRY (user_data);
8779 GtkEntryPrivate *priv = entry->priv;
8780 GtkWidget *widget = GTK_WIDGET (entry);
8782 GtkRequisition menu_req;
8783 GdkRectangle monitor;
8784 GtkBorder inner_border;
8785 gint monitor_num, strong_x, height;
8787 g_return_if_fail (gtk_widget_get_realized (widget));
8789 gdk_window_get_origin (priv->text_area, x, y);
8791 screen = gtk_widget_get_screen (widget);
8792 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8793 if (monitor_num < 0)
8795 gtk_menu_set_monitor (menu, monitor_num);
8797 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8798 gtk_widget_get_preferred_size (priv->popup_menu,
8800 height = gdk_window_get_height (priv->text_area);
8801 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8802 _gtk_entry_effective_inner_border (entry, &inner_border);
8804 *x += inner_border.left + strong_x - priv->scroll_offset;
8805 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8806 *x -= menu_req.width;
8808 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8810 else if ((*y - menu_req.height) >= monitor.y)
8811 *y -= menu_req.height;
8812 else if (monitor.y + monitor.height - (*y + height) > *y)
8815 *y -= menu_req.height;
8821 unichar_chosen_func (const char *text,
8824 GtkEntry *entry = GTK_ENTRY (data);
8825 GtkEntryPrivate *priv = entry->priv;
8828 gtk_entry_enter_text (entry, text);
8839 popup_targets_received (GtkClipboard *clipboard,
8840 GtkSelectionData *data,
8843 PopupInfo *info = user_data;
8844 GtkEntry *entry = info->entry;
8845 GtkEntryPrivate *info_entry_priv = entry->priv;
8847 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8850 gboolean clipboard_contains_text;
8851 GtkWidget *menuitem;
8853 gboolean show_input_method_menu;
8854 gboolean show_unicode_menu;
8856 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8857 if (info_entry_priv->popup_menu)
8858 gtk_widget_destroy (info_entry_priv->popup_menu);
8860 info_entry_priv->popup_menu = gtk_menu_new ();
8862 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8866 mode = gtk_entry_get_display_mode (entry);
8867 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8868 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8869 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8871 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8872 mode == DISPLAY_NORMAL &&
8873 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8875 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8876 info_entry_priv->editable && clipboard_contains_text);
8878 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8879 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8880 g_signal_connect_swapped (menuitem, "activate",
8881 G_CALLBACK (gtk_entry_delete_cb), entry);
8882 gtk_widget_show (menuitem);
8883 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8885 menuitem = gtk_separator_menu_item_new ();
8886 gtk_widget_show (menuitem);
8887 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8889 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8890 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8891 g_signal_connect_swapped (menuitem, "activate",
8892 G_CALLBACK (gtk_entry_select_all), entry);
8893 gtk_widget_show (menuitem);
8894 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8896 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8897 "gtk-show-input-method-menu", &show_input_method_menu,
8898 "gtk-show-unicode-menu", &show_unicode_menu,
8901 if (show_input_method_menu || show_unicode_menu)
8903 menuitem = gtk_separator_menu_item_new ();
8904 gtk_widget_show (menuitem);
8905 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8908 if (show_input_method_menu)
8910 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8911 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8912 gtk_widget_show (menuitem);
8913 submenu = gtk_menu_new ();
8914 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8916 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8918 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8919 GTK_MENU_SHELL (submenu));
8922 if (show_unicode_menu)
8924 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8925 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8926 gtk_widget_show (menuitem);
8928 submenu = gtk_menu_new ();
8929 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8930 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8932 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8933 unichar_chosen_func,
8937 g_signal_emit (entry,
8938 signals[POPULATE_POPUP],
8940 info_entry_priv->popup_menu);
8944 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8946 info->button, info->time);
8949 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8950 popup_position_func, entry,
8951 info->button, info->time);
8952 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8956 g_object_unref (entry);
8957 g_slice_free (PopupInfo, info);
8961 gtk_entry_do_popup (GtkEntry *entry,
8962 GdkEventButton *event)
8964 PopupInfo *info = g_slice_new (PopupInfo);
8966 /* In order to know what entries we should make sensitive, we
8967 * ask for the current targets of the clipboard, and when
8968 * we get them, then we actually pop up the menu.
8970 info->entry = g_object_ref (entry);
8974 info->button = event->button;
8975 info->time = event->time;
8980 info->time = gtk_get_current_event_time ();
8983 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8984 gdk_atom_intern_static_string ("TARGETS"),
8985 popup_targets_received,
8990 gtk_entry_popup_menu (GtkWidget *widget)
8992 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8997 gtk_entry_drag_begin (GtkWidget *widget,
8998 GdkDragContext *context)
9000 GtkEntry *entry = GTK_ENTRY (widget);
9001 GtkEntryPrivate *priv = entry->priv;
9004 for (i = 0; i < MAX_ICONS; i++)
9006 EntryIconInfo *icon_info = priv->icons[i];
9008 if (icon_info != NULL)
9010 if (icon_info->in_drag)
9012 switch (icon_info->storage_type)
9014 case GTK_IMAGE_STOCK:
9015 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
9018 case GTK_IMAGE_ICON_NAME:
9019 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
9022 /* FIXME: No GIcon support for dnd icons */
9023 case GTK_IMAGE_GICON:
9024 case GTK_IMAGE_PIXBUF:
9025 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
9028 g_assert_not_reached ();
9036 gtk_entry_drag_end (GtkWidget *widget,
9037 GdkDragContext *context)
9039 GtkEntry *entry = GTK_ENTRY (widget);
9040 GtkEntryPrivate *priv = entry->priv;
9043 for (i = 0; i < MAX_ICONS; i++)
9045 EntryIconInfo *icon_info = priv->icons[i];
9047 if (icon_info != NULL)
9048 icon_info->in_drag = 0;
9053 gtk_entry_drag_leave (GtkWidget *widget,
9054 GdkDragContext *context,
9057 GtkEntry *entry = GTK_ENTRY (widget);
9058 GtkEntryPrivate *priv = entry->priv;
9060 priv->dnd_position = -1;
9061 gtk_widget_queue_draw (widget);
9065 gtk_entry_drag_drop (GtkWidget *widget,
9066 GdkDragContext *context,
9071 GtkEntry *entry = GTK_ENTRY (widget);
9072 GtkEntryPrivate *priv = entry->priv;
9073 GdkAtom target = GDK_NONE;
9076 target = gtk_drag_dest_find_target (widget, context, NULL);
9078 if (target != GDK_NONE)
9079 gtk_drag_get_data (widget, context, target, time);
9081 gtk_drag_finish (context, FALSE, FALSE, time);
9087 gtk_entry_drag_motion (GtkWidget *widget,
9088 GdkDragContext *context,
9093 GtkEntry *entry = GTK_ENTRY (widget);
9094 GtkEntryPrivate *priv = entry->priv;
9095 GtkStyleContext *style_context;
9096 GtkWidget *source_widget;
9097 GdkDragAction suggested_action;
9098 gint new_position, old_position;
9102 style_context = gtk_widget_get_style_context (widget);
9103 gtk_style_context_get_padding (style_context, 0, &padding);
9107 old_position = priv->dnd_position;
9108 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9110 if (priv->editable &&
9111 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9113 source_widget = gtk_drag_get_source_widget (context);
9114 suggested_action = gdk_drag_context_get_suggested_action (context);
9116 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9117 new_position < sel1 || new_position > sel2)
9119 if (source_widget == widget)
9121 /* Default to MOVE, unless the user has
9122 * pressed ctrl or alt to affect available actions
9124 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9125 suggested_action = GDK_ACTION_MOVE;
9128 priv->dnd_position = new_position;
9132 if (source_widget == widget)
9133 suggested_action = 0; /* Can't drop in selection where drag started */
9135 priv->dnd_position = -1;
9140 /* Entry not editable, or no text */
9141 suggested_action = 0;
9142 priv->dnd_position = -1;
9145 gdk_drag_status (context, suggested_action, time);
9147 if (priv->dnd_position != old_position)
9148 gtk_widget_queue_draw (widget);
9154 gtk_entry_drag_data_received (GtkWidget *widget,
9155 GdkDragContext *context,
9158 GtkSelectionData *selection_data,
9162 GtkEntry *entry = GTK_ENTRY (widget);
9163 GtkEntryPrivate *priv = entry->priv;
9164 GtkEditable *editable = GTK_EDITABLE (widget);
9165 GtkStyleContext *style_context;
9169 str = (gchar *) gtk_selection_data_get_text (selection_data);
9171 style_context = gtk_widget_get_style_context (widget);
9172 gtk_style_context_get_padding (style_context, 0, &padding);
9176 if (str && priv->editable)
9182 if (priv->truncate_multiline)
9183 length = truncate_multiline (str);
9185 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9187 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9188 new_position < sel1 || new_position > sel2)
9190 gtk_editable_insert_text (editable, str, length, &new_position);
9194 /* Replacing selection */
9195 begin_change (entry);
9196 g_object_freeze_notify (G_OBJECT (entry));
9197 gtk_editable_delete_text (editable, sel1, sel2);
9198 gtk_editable_insert_text (editable, str, length, &sel1);
9199 g_object_thaw_notify (G_OBJECT (entry));
9203 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9207 /* Drag and drop didn't happen! */
9208 gtk_drag_finish (context, FALSE, FALSE, time);
9215 gtk_entry_drag_data_get (GtkWidget *widget,
9216 GdkDragContext *context,
9217 GtkSelectionData *selection_data,
9221 GtkEntry *entry = GTK_ENTRY (widget);
9222 GtkEntryPrivate *priv = entry->priv;
9223 GtkEditable *editable = GTK_EDITABLE (widget);
9224 gint sel_start, sel_end;
9227 /* If there is an icon drag going on, exit early. */
9228 for (i = 0; i < MAX_ICONS; i++)
9230 EntryIconInfo *icon_info = priv->icons[i];
9232 if (icon_info != NULL)
9234 if (icon_info->in_drag)
9239 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9241 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9243 gtk_selection_data_set_text (selection_data, str, -1);
9251 gtk_entry_drag_data_delete (GtkWidget *widget,
9252 GdkDragContext *context)
9254 GtkEntry *entry = GTK_ENTRY (widget);
9255 GtkEntryPrivate *priv = entry->priv;
9256 GtkEditable *editable = GTK_EDITABLE (widget);
9257 gint sel_start, sel_end;
9260 /* If there is an icon drag going on, exit early. */
9261 for (i = 0; i < MAX_ICONS; i++)
9263 EntryIconInfo *icon_info = priv->icons[i];
9265 if (icon_info != NULL)
9267 if (icon_info->in_drag)
9272 if (priv->editable &&
9273 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9274 gtk_editable_delete_text (editable, sel_start, sel_end);
9277 /* We display the cursor when
9279 * - the selection is empty, AND
9280 * - the widget has focus
9283 #define CURSOR_ON_MULTIPLIER 2
9284 #define CURSOR_OFF_MULTIPLIER 1
9285 #define CURSOR_PEND_MULTIPLIER 3
9286 #define CURSOR_DIVIDER 3
9289 cursor_blinks (GtkEntry *entry)
9291 GtkEntryPrivate *priv = entry->priv;
9293 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9295 priv->selection_bound == priv->current_pos)
9297 GtkSettings *settings;
9300 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9301 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9310 get_cursor_time (GtkEntry *entry)
9312 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9315 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9321 get_cursor_blink_timeout (GtkEntry *entry)
9323 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9326 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9332 show_cursor (GtkEntry *entry)
9334 GtkEntryPrivate *priv = entry->priv;
9337 if (!priv->cursor_visible)
9339 priv->cursor_visible = TRUE;
9341 widget = GTK_WIDGET (entry);
9342 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9343 gtk_widget_queue_draw (widget);
9348 hide_cursor (GtkEntry *entry)
9350 GtkEntryPrivate *priv = entry->priv;
9353 if (priv->cursor_visible)
9355 priv->cursor_visible = FALSE;
9357 widget = GTK_WIDGET (entry);
9358 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9359 gtk_widget_queue_draw (widget);
9367 blink_cb (gpointer data)
9370 GtkEntryPrivate *priv;
9373 entry = GTK_ENTRY (data);
9376 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9378 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9379 "connect a handler to this signal, it must return\n"
9380 "FALSE so the entry gets the event as well");
9382 gtk_entry_check_cursor_blink (entry);
9387 g_assert (priv->selection_bound == priv->current_pos);
9389 blink_timeout = get_cursor_blink_timeout (entry);
9390 if (priv->blink_time > 1000 * blink_timeout &&
9391 blink_timeout < G_MAXINT/1000)
9393 /* we've blinked enough without the user doing anything, stop blinking */
9394 show_cursor (entry);
9395 priv->blink_timeout = 0;
9397 else if (priv->cursor_visible)
9399 hide_cursor (entry);
9400 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9406 show_cursor (entry);
9407 priv->blink_time += get_cursor_time (entry);
9408 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9413 /* Remove ourselves */
9418 gtk_entry_check_cursor_blink (GtkEntry *entry)
9420 GtkEntryPrivate *priv = entry->priv;
9422 if (cursor_blinks (entry))
9424 if (!priv->blink_timeout)
9426 show_cursor (entry);
9427 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9434 if (priv->blink_timeout)
9436 g_source_remove (priv->blink_timeout);
9437 priv->blink_timeout = 0;
9440 priv->cursor_visible = TRUE;
9445 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9447 GtkEntryPrivate *priv = entry->priv;
9449 if (cursor_blinks (entry))
9451 if (priv->blink_timeout != 0)
9452 g_source_remove (priv->blink_timeout);
9454 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9457 show_cursor (entry);
9462 gtk_entry_reset_blink_time (GtkEntry *entry)
9464 GtkEntryPrivate *priv = entry->priv;
9466 priv->blink_time = 0;
9472 gtk_entry_completion_timeout (gpointer data)
9474 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9475 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9477 completion->priv->completion_timeout = 0;
9479 if (completion->priv->filter_model &&
9480 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9481 >= completion->priv->minimum_key_length)
9485 GtkTreeSelection *s;
9486 gboolean popup_single;
9488 gtk_entry_completion_complete (completion);
9489 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9491 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9493 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9495 gtk_tree_selection_unselect_all (s);
9497 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9499 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9500 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9502 if (gtk_widget_get_visible (completion->priv->popup_window))
9503 _gtk_entry_completion_resize_popup (completion);
9505 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9508 _gtk_entry_completion_popdown (completion);
9510 else if (gtk_widget_get_visible (completion->priv->popup_window))
9511 _gtk_entry_completion_popdown (completion);
9516 static inline gboolean
9517 keyval_is_cursor_move (guint keyval)
9519 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9522 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9525 if (keyval == GDK_KEY_Page_Up)
9528 if (keyval == GDK_KEY_Page_Down)
9535 gtk_entry_completion_key_press (GtkWidget *widget,
9539 gint matches, actions = 0;
9540 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9542 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9545 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9547 if (completion->priv->actions)
9548 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9550 if (keyval_is_cursor_move (event->keyval))
9552 GtkTreePath *path = NULL;
9554 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9556 if (completion->priv->current_selected < 0)
9557 completion->priv->current_selected = matches + actions - 1;
9559 completion->priv->current_selected--;
9561 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9563 if (completion->priv->current_selected < matches + actions - 1)
9564 completion->priv->current_selected++;
9566 completion->priv->current_selected = -1;
9568 else if (event->keyval == GDK_KEY_Page_Up)
9570 if (completion->priv->current_selected < 0)
9571 completion->priv->current_selected = matches + actions - 1;
9572 else if (completion->priv->current_selected == 0)
9573 completion->priv->current_selected = -1;
9574 else if (completion->priv->current_selected < matches)
9576 completion->priv->current_selected -= 14;
9577 if (completion->priv->current_selected < 0)
9578 completion->priv->current_selected = 0;
9582 completion->priv->current_selected -= 14;
9583 if (completion->priv->current_selected < matches - 1)
9584 completion->priv->current_selected = matches - 1;
9587 else if (event->keyval == GDK_KEY_Page_Down)
9589 if (completion->priv->current_selected < 0)
9590 completion->priv->current_selected = 0;
9591 else if (completion->priv->current_selected < matches - 1)
9593 completion->priv->current_selected += 14;
9594 if (completion->priv->current_selected > matches - 1)
9595 completion->priv->current_selected = matches - 1;
9597 else if (completion->priv->current_selected == matches + actions - 1)
9599 completion->priv->current_selected = -1;
9603 completion->priv->current_selected += 14;
9604 if (completion->priv->current_selected > matches + actions - 1)
9605 completion->priv->current_selected = matches + actions - 1;
9609 if (completion->priv->current_selected < 0)
9611 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9612 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9614 if (completion->priv->inline_selection &&
9615 completion->priv->completion_prefix)
9617 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9618 completion->priv->completion_prefix);
9619 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9622 else if (completion->priv->current_selected < matches)
9624 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9626 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9627 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9630 if (completion->priv->inline_selection)
9634 GtkTreeIter child_iter;
9635 GtkTreeModel *model = NULL;
9636 GtkTreeSelection *sel;
9639 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9640 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9643 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9644 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9646 if (completion->priv->completion_prefix == NULL)
9647 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9649 g_signal_emit_by_name (completion, "cursor-on-match", model,
9650 &child_iter, &entry_set);
9653 else if (completion->priv->current_selected - matches >= 0)
9655 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9657 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9658 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9661 if (completion->priv->inline_selection &&
9662 completion->priv->completion_prefix)
9664 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9665 completion->priv->completion_prefix);
9666 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9670 gtk_tree_path_free (path);
9674 else if (event->keyval == GDK_KEY_Escape ||
9675 event->keyval == GDK_KEY_Left ||
9676 event->keyval == GDK_KEY_KP_Left ||
9677 event->keyval == GDK_KEY_Right ||
9678 event->keyval == GDK_KEY_KP_Right)
9680 gboolean retval = TRUE;
9682 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9683 _gtk_entry_completion_popdown (completion);
9685 if (completion->priv->current_selected < 0)
9688 goto keypress_completion_out;
9690 else if (completion->priv->inline_selection)
9692 /* Escape rejects the tentative completion */
9693 if (event->keyval == GDK_KEY_Escape)
9695 if (completion->priv->completion_prefix)
9696 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9697 completion->priv->completion_prefix);
9699 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9702 /* Move the cursor to the end for Right/Esc, to the
9703 beginning for Left */
9704 if (event->keyval == GDK_KEY_Right ||
9705 event->keyval == GDK_KEY_KP_Right ||
9706 event->keyval == GDK_KEY_Escape)
9707 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9709 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9712 keypress_completion_out:
9713 if (completion->priv->inline_selection)
9715 g_free (completion->priv->completion_prefix);
9716 completion->priv->completion_prefix = NULL;
9721 else if (event->keyval == GDK_KEY_Tab ||
9722 event->keyval == GDK_KEY_KP_Tab ||
9723 event->keyval == GDK_KEY_ISO_Left_Tab)
9725 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9726 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9728 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9729 _gtk_entry_completion_popdown (completion);
9731 g_free (completion->priv->completion_prefix);
9732 completion->priv->completion_prefix = NULL;
9734 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9738 else if (event->keyval == GDK_KEY_ISO_Enter ||
9739 event->keyval == GDK_KEY_KP_Enter ||
9740 event->keyval == GDK_KEY_Return)
9743 GtkTreeModel *model = NULL;
9744 GtkTreeModel *child_model;
9745 GtkTreeIter child_iter;
9746 GtkTreeSelection *sel;
9747 gboolean retval = TRUE;
9749 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9750 _gtk_entry_completion_popdown (completion);
9752 if (completion->priv->current_selected < matches)
9756 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9757 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9759 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9760 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9761 g_signal_handler_block (widget, completion->priv->changed_id);
9762 g_signal_emit_by_name (completion, "match-selected",
9763 child_model, &child_iter, &entry_set);
9764 g_signal_handler_unblock (widget, completion->priv->changed_id);
9770 gtk_tree_model_get (model, &iter,
9771 completion->priv->text_column, &str,
9774 gtk_entry_set_text (GTK_ENTRY (widget), str);
9776 /* move the cursor to the end */
9777 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9785 else if (completion->priv->current_selected - matches >= 0)
9787 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9788 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9792 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9793 g_signal_emit_by_name (completion, "action-activated",
9794 gtk_tree_path_get_indices (path)[0]);
9795 gtk_tree_path_free (path);
9801 g_free (completion->priv->completion_prefix);
9802 completion->priv->completion_prefix = NULL;
9811 gtk_entry_completion_changed (GtkWidget *widget,
9814 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9815 GtkEntry *entry = GTK_ENTRY (widget);
9816 GtkEntryPrivate *priv = entry->priv;
9819 /* (re)install completion timeout */
9820 if (completion->priv->completion_timeout)
9821 g_source_remove (completion->priv->completion_timeout);
9823 if (!gtk_entry_get_text (entry))
9826 /* no need to normalize for this test */
9827 if (completion->priv->minimum_key_length > 0 &&
9828 strcmp ("", gtk_entry_get_text (entry)) == 0)
9830 if (gtk_widget_get_visible (completion->priv->popup_window))
9831 _gtk_entry_completion_popdown (completion);
9835 device = gtk_get_current_event_device ();
9837 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9838 device = gdk_device_get_associated_device (device);
9841 priv->completion_device = device;
9843 completion->priv->completion_timeout =
9844 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9845 gtk_entry_completion_timeout,
9850 check_completion_callback (GtkEntryCompletion *completion)
9852 completion->priv->check_completion_idle = NULL;
9854 gtk_entry_completion_complete (completion);
9855 gtk_entry_completion_insert_prefix (completion);
9861 clear_completion_callback (GtkEntry *entry,
9864 if (pspec->name == I_("cursor-position") ||
9865 pspec->name == I_("selection-bound"))
9867 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9869 completion->priv->has_completion = FALSE;
9874 accept_completion_callback (GtkEntry *entry)
9876 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9878 if (completion->priv->has_completion)
9879 gtk_editable_set_position (GTK_EDITABLE (entry),
9880 gtk_entry_buffer_get_length (get_buffer (entry)));
9886 completion_insert_text_callback (GtkEntry *entry,
9890 GtkEntryCompletion *completion)
9892 /* idle to update the selection based on the file list */
9893 if (completion->priv->check_completion_idle == NULL)
9895 completion->priv->check_completion_idle = g_idle_source_new ();
9896 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9897 g_source_set_closure (completion->priv->check_completion_idle,
9898 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9899 G_OBJECT (completion)));
9900 g_source_attach (completion->priv->check_completion_idle, NULL);
9905 completion_changed (GtkEntryCompletion *completion,
9909 GtkEntry *entry = GTK_ENTRY (data);
9911 if (pspec->name == I_("popup-completion") ||
9912 pspec->name == I_("inline-completion"))
9914 disconnect_completion_signals (entry, completion);
9915 connect_completion_signals (entry, completion);
9920 disconnect_completion_signals (GtkEntry *entry,
9921 GtkEntryCompletion *completion)
9923 g_signal_handlers_disconnect_by_func (completion,
9924 G_CALLBACK (completion_changed), entry);
9925 if (completion->priv->changed_id > 0 &&
9926 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9928 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9929 completion->priv->changed_id = 0;
9931 g_signal_handlers_disconnect_by_func (entry,
9932 G_CALLBACK (gtk_entry_completion_key_press), completion);
9933 if (completion->priv->insert_text_id > 0 &&
9934 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9936 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9937 completion->priv->insert_text_id = 0;
9939 g_signal_handlers_disconnect_by_func (entry,
9940 G_CALLBACK (completion_insert_text_callback), completion);
9941 g_signal_handlers_disconnect_by_func (entry,
9942 G_CALLBACK (clear_completion_callback), completion);
9943 g_signal_handlers_disconnect_by_func (entry,
9944 G_CALLBACK (accept_completion_callback), completion);
9948 connect_completion_signals (GtkEntry *entry,
9949 GtkEntryCompletion *completion)
9951 if (completion->priv->popup_completion)
9953 completion->priv->changed_id =
9954 g_signal_connect (entry, "changed",
9955 G_CALLBACK (gtk_entry_completion_changed), completion);
9956 g_signal_connect (entry, "key-press-event",
9957 G_CALLBACK (gtk_entry_completion_key_press), completion);
9960 if (completion->priv->inline_completion)
9962 completion->priv->insert_text_id =
9963 g_signal_connect (entry, "insert-text",
9964 G_CALLBACK (completion_insert_text_callback), completion);
9965 g_signal_connect (entry, "notify",
9966 G_CALLBACK (clear_completion_callback), completion);
9967 g_signal_connect (entry, "activate",
9968 G_CALLBACK (accept_completion_callback), completion);
9969 g_signal_connect (entry, "focus-out-event",
9970 G_CALLBACK (accept_completion_callback), completion);
9973 g_signal_connect (completion, "notify",
9974 G_CALLBACK (completion_changed), entry);
9978 * gtk_entry_set_completion:
9979 * @entry: A #GtkEntry
9980 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9982 * Sets @completion to be the auxiliary completion object to use with @entry.
9983 * All further configuration of the completion mechanism is done on
9984 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9985 * @completion is set to %NULL.
9990 gtk_entry_set_completion (GtkEntry *entry,
9991 GtkEntryCompletion *completion)
9993 GtkEntryCompletion *old;
9995 g_return_if_fail (GTK_IS_ENTRY (entry));
9996 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9998 old = gtk_entry_get_completion (entry);
10000 if (old == completion)
10005 if (old->priv->completion_timeout)
10007 g_source_remove (old->priv->completion_timeout);
10008 old->priv->completion_timeout = 0;
10011 if (old->priv->check_completion_idle)
10013 g_source_destroy (old->priv->check_completion_idle);
10014 old->priv->check_completion_idle = NULL;
10017 if (gtk_widget_get_mapped (old->priv->popup_window))
10018 _gtk_entry_completion_popdown (old);
10020 disconnect_completion_signals (entry, old);
10021 old->priv->entry = NULL;
10023 g_object_unref (old);
10028 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
10032 /* hook into the entry */
10033 g_object_ref (completion);
10035 connect_completion_signals (entry, completion);
10036 completion->priv->entry = GTK_WIDGET (entry);
10037 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10039 g_object_notify (G_OBJECT (entry), "completion");
10043 * gtk_entry_get_completion:
10044 * @entry: A #GtkEntry
10046 * Returns the auxiliary completion object currently in use by @entry.
10048 * Return value: (transfer none): The auxiliary completion object currently
10049 * in use by @entry.
10053 GtkEntryCompletion *
10054 gtk_entry_get_completion (GtkEntry *entry)
10056 GtkEntryCompletion *completion;
10058 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10060 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10061 GTK_ENTRY_COMPLETION_KEY));
10067 * gtk_entry_set_cursor_hadjustment:
10068 * @entry: a #GtkEntry
10069 * @adjustment: an adjustment which should be adjusted when the cursor
10070 * is moved, or %NULL
10072 * Hooks up an adjustment to the cursor position in an entry, so that when
10073 * the cursor is moved, the adjustment is scrolled to show that position.
10074 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10077 * The adjustment has to be in pixel units and in the same coordinate system
10083 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10084 GtkAdjustment *adjustment)
10086 g_return_if_fail (GTK_IS_ENTRY (entry));
10088 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10091 g_object_ref (adjustment);
10093 g_object_set_qdata_full (G_OBJECT (entry),
10094 quark_cursor_hadjustment,
10100 * gtk_entry_get_cursor_hadjustment:
10101 * @entry: a #GtkEntry
10103 * Retrieves the horizontal cursor adjustment for the entry.
10104 * See gtk_entry_set_cursor_hadjustment().
10106 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10107 * if none has been set.
10112 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10114 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10116 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10120 * gtk_entry_set_progress_fraction:
10121 * @entry: a #GtkEntry
10122 * @fraction: fraction of the task that's been completed
10124 * Causes the entry's progress indicator to "fill in" the given
10125 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10131 gtk_entry_set_progress_fraction (GtkEntry *entry,
10135 GtkEntryPrivate *private;
10136 gdouble old_fraction;
10137 gint x, y, width, height;
10138 gint old_x, old_y, old_width, old_height;
10140 g_return_if_fail (GTK_IS_ENTRY (entry));
10142 widget = GTK_WIDGET (entry);
10143 private = entry->priv;
10145 if (private->progress_pulse_mode)
10148 old_fraction = private->progress_fraction;
10150 if (gtk_widget_is_drawable (widget))
10151 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10153 fraction = CLAMP (fraction, 0.0, 1.0);
10155 private->progress_fraction = fraction;
10156 private->progress_pulse_mode = FALSE;
10157 private->progress_pulse_current = 0.0;
10159 if (gtk_widget_is_drawable (widget))
10161 get_progress_area (widget, &x, &y, &width, &height);
10163 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10164 gtk_widget_queue_draw (widget);
10167 if (fraction != old_fraction)
10168 g_object_notify (G_OBJECT (entry), "progress-fraction");
10172 * gtk_entry_get_progress_fraction:
10173 * @entry: a #GtkEntry
10175 * Returns the current fraction of the task that's been completed.
10176 * See gtk_entry_set_progress_fraction().
10178 * Return value: a fraction from 0.0 to 1.0
10183 gtk_entry_get_progress_fraction (GtkEntry *entry)
10185 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10187 return entry->priv->progress_fraction;
10191 * gtk_entry_set_progress_pulse_step:
10192 * @entry: a #GtkEntry
10193 * @fraction: fraction between 0.0 and 1.0
10195 * Sets the fraction of total entry width to move the progress
10196 * bouncing block for each call to gtk_entry_progress_pulse().
10201 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10204 GtkEntryPrivate *private;
10206 g_return_if_fail (GTK_IS_ENTRY (entry));
10208 private = entry->priv;
10210 fraction = CLAMP (fraction, 0.0, 1.0);
10212 if (fraction != private->progress_pulse_fraction)
10214 private->progress_pulse_fraction = fraction;
10216 gtk_widget_queue_draw (GTK_WIDGET (entry));
10218 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10223 * gtk_entry_get_progress_pulse_step:
10224 * @entry: a #GtkEntry
10226 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10228 * Return value: a fraction from 0.0 to 1.0
10233 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10235 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10237 return entry->priv->progress_pulse_fraction;
10241 * gtk_entry_progress_pulse:
10242 * @entry: a #GtkEntry
10244 * Indicates that some progress is made, but you don't know how much.
10245 * Causes the entry's progress indicator to enter "activity mode,"
10246 * where a block bounces back and forth. Each call to
10247 * gtk_entry_progress_pulse() causes the block to move by a little bit
10248 * (the amount of movement per pulse is determined by
10249 * gtk_entry_set_progress_pulse_step()).
10254 gtk_entry_progress_pulse (GtkEntry *entry)
10256 GtkEntryPrivate *private;
10258 g_return_if_fail (GTK_IS_ENTRY (entry));
10260 private = entry->priv;
10262 if (private->progress_pulse_mode)
10264 if (private->progress_pulse_way_back)
10266 private->progress_pulse_current -= private->progress_pulse_fraction;
10268 if (private->progress_pulse_current < 0.0)
10270 private->progress_pulse_current = 0.0;
10271 private->progress_pulse_way_back = FALSE;
10276 private->progress_pulse_current += private->progress_pulse_fraction;
10278 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10280 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10281 private->progress_pulse_way_back = TRUE;
10287 private->progress_fraction = 0.0;
10288 private->progress_pulse_mode = TRUE;
10289 private->progress_pulse_way_back = FALSE;
10290 private->progress_pulse_current = 0.0;
10293 gtk_widget_queue_draw (GTK_WIDGET (entry));
10297 * gtk_entry_set_placeholder_text:
10298 * @entry: a #GtkEntry
10299 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10301 * Sets text to be displayed in @entry when
10302 * it is empty and unfocused. This can be used to give a visual hint
10303 * of the expected contents of the #GtkEntry.
10308 gtk_entry_set_placeholder_text (GtkEntry *entry,
10311 GtkEntryPrivate *priv;
10313 g_return_if_fail (GTK_IS_ENTRY (entry));
10315 priv = entry->priv;
10317 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10320 g_free (priv->placeholder_text);
10321 priv->placeholder_text = g_strdup (text);
10323 gtk_entry_recompute (entry);
10325 g_object_notify (G_OBJECT (entry), "placeholder-text");
10329 * gtk_entry_get_placeholder_text:
10330 * @entry: a #GtkEntry
10332 * Retrieves the text that will be displayed when @entry is empty and unfocused
10334 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10335 * storage in the widget and must not be freed, modified or stored.
10339 G_CONST_RETURN gchar *
10340 gtk_entry_get_placeholder_text (GtkEntry *entry)
10342 GtkEntryPrivate *priv;
10344 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10346 priv = entry->priv;
10348 return priv->placeholder_text;
10351 /* Caps Lock warning for password entries */
10354 show_capslock_feedback (GtkEntry *entry,
10357 GtkEntryPrivate *priv = entry->priv;
10359 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10361 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10362 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10363 priv->caps_lock_warning_shown = TRUE;
10366 if (priv->caps_lock_warning_shown)
10367 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10369 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10373 remove_capslock_feedback (GtkEntry *entry)
10375 GtkEntryPrivate *priv = entry->priv;
10377 if (priv->caps_lock_warning_shown)
10379 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10380 priv->caps_lock_warning_shown = FALSE;
10385 keymap_state_changed (GdkKeymap *keymap,
10388 GtkEntryPrivate *priv = entry->priv;
10391 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10393 if (gdk_keymap_get_num_lock_state (keymap)
10394 && gdk_keymap_get_caps_lock_state (keymap))
10395 text = _("Caps Lock and Num Lock are on");
10396 else if (gdk_keymap_get_num_lock_state (keymap))
10397 text = _("Num Lock is on");
10398 else if (gdk_keymap_get_caps_lock_state (keymap))
10399 text = _("Caps Lock is on");
10403 show_capslock_feedback (entry, text);
10405 remove_capslock_feedback (entry);
10409 * _gtk_entry_set_is_cell_renderer:
10410 * @entry: a #GtkEntry
10411 * @is_cell_renderer: new value
10413 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10414 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10416 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10420 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10421 gboolean is_cell_renderer)
10423 entry->priv->is_cell_renderer = is_cell_renderer;