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;
233 GtkTargetList *target_list;
234 GdkDragAction actions;
237 struct _GtkEntryPasswordHint
239 gint position; /* Position (in text) of the last password hint */
240 guint source_id; /* Timeout source id */
243 struct _GtkEntryCapslockFeedback
270 PROP_CURSOR_POSITION,
271 PROP_SELECTION_BOUND,
278 PROP_ACTIVATES_DEFAULT,
283 PROP_TRUNCATE_MULTILINE,
287 PROP_INVISIBLE_CHAR_SET,
288 PROP_CAPS_LOCK_WARNING,
289 PROP_PROGRESS_FRACTION,
290 PROP_PROGRESS_PULSE_STEP,
292 PROP_PIXBUF_SECONDARY,
294 PROP_STOCK_SECONDARY,
295 PROP_ICON_NAME_PRIMARY,
296 PROP_ICON_NAME_SECONDARY,
298 PROP_GICON_SECONDARY,
299 PROP_STORAGE_TYPE_PRIMARY,
300 PROP_STORAGE_TYPE_SECONDARY,
301 PROP_ACTIVATABLE_PRIMARY,
302 PROP_ACTIVATABLE_SECONDARY,
303 PROP_SENSITIVE_PRIMARY,
304 PROP_SENSITIVE_SECONDARY,
305 PROP_TOOLTIP_TEXT_PRIMARY,
306 PROP_TOOLTIP_TEXT_SECONDARY,
307 PROP_TOOLTIP_MARKUP_PRIMARY,
308 PROP_TOOLTIP_MARKUP_SECONDARY,
310 PROP_EDITING_CANCELED,
311 PROP_PLACEHOLDER_TEXT,
315 static guint signals[LAST_SIGNAL] = { 0 };
324 DISPLAY_NORMAL, /* The entry text is being shown */
325 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
326 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
331 static void gtk_entry_editable_init (GtkEditableInterface *iface);
332 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
333 static void gtk_entry_set_property (GObject *object,
337 static void gtk_entry_get_property (GObject *object,
341 static void gtk_entry_finalize (GObject *object);
342 static void gtk_entry_dispose (GObject *object);
346 static void gtk_entry_destroy (GtkWidget *widget);
347 static void gtk_entry_realize (GtkWidget *widget);
348 static void gtk_entry_unrealize (GtkWidget *widget);
349 static void gtk_entry_map (GtkWidget *widget);
350 static void gtk_entry_unmap (GtkWidget *widget);
351 static void gtk_entry_get_preferred_width (GtkWidget *widget,
354 static void gtk_entry_get_preferred_height (GtkWidget *widget,
357 static void gtk_entry_size_allocate (GtkWidget *widget,
358 GtkAllocation *allocation);
359 static void gtk_entry_draw_frame (GtkWidget *widget,
360 GtkStyleContext *context,
362 static void gtk_entry_draw_progress (GtkWidget *widget,
363 GtkStyleContext *context,
365 static gint gtk_entry_draw (GtkWidget *widget,
367 static gint gtk_entry_button_press (GtkWidget *widget,
368 GdkEventButton *event);
369 static gint gtk_entry_button_release (GtkWidget *widget,
370 GdkEventButton *event);
371 static gint gtk_entry_enter_notify (GtkWidget *widget,
372 GdkEventCrossing *event);
373 static gint gtk_entry_leave_notify (GtkWidget *widget,
374 GdkEventCrossing *event);
375 static gint gtk_entry_motion_notify (GtkWidget *widget,
376 GdkEventMotion *event);
377 static gint gtk_entry_key_press (GtkWidget *widget,
379 static gint gtk_entry_key_release (GtkWidget *widget,
381 static gint gtk_entry_focus_in (GtkWidget *widget,
382 GdkEventFocus *event);
383 static gint gtk_entry_focus_out (GtkWidget *widget,
384 GdkEventFocus *event);
385 static void gtk_entry_grab_focus (GtkWidget *widget);
386 static void gtk_entry_style_updated (GtkWidget *widget);
387 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
390 gboolean keyboard_tip,
391 GtkTooltip *tooltip);
392 static void gtk_entry_direction_changed (GtkWidget *widget,
393 GtkTextDirection previous_dir);
394 static void gtk_entry_state_flags_changed (GtkWidget *widget,
395 GtkStateFlags previous_state);
396 static void gtk_entry_screen_changed (GtkWidget *widget,
397 GdkScreen *old_screen);
399 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
400 GdkDragContext *context,
404 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
405 GdkDragContext *context,
409 static void gtk_entry_drag_leave (GtkWidget *widget,
410 GdkDragContext *context,
412 static void gtk_entry_drag_data_received (GtkWidget *widget,
413 GdkDragContext *context,
416 GtkSelectionData *selection_data,
419 static void gtk_entry_drag_data_get (GtkWidget *widget,
420 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_entry_drag_data_delete (GtkWidget *widget,
425 GdkDragContext *context);
426 static void gtk_entry_drag_begin (GtkWidget *widget,
427 GdkDragContext *context);
428 static void gtk_entry_drag_end (GtkWidget *widget,
429 GdkDragContext *context);
432 /* GtkEditable method implementations
434 static void gtk_entry_insert_text (GtkEditable *editable,
435 const gchar *new_text,
436 gint new_text_length,
438 static void gtk_entry_delete_text (GtkEditable *editable,
441 static gchar * gtk_entry_get_chars (GtkEditable *editable,
444 static void gtk_entry_real_set_position (GtkEditable *editable,
446 static gint gtk_entry_get_position (GtkEditable *editable);
447 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
450 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
454 /* GtkCellEditable method implementations
456 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
459 /* Default signal handlers
461 static void gtk_entry_real_insert_text (GtkEditable *editable,
462 const gchar *new_text,
463 gint new_text_length,
465 static void gtk_entry_real_delete_text (GtkEditable *editable,
468 static void gtk_entry_move_cursor (GtkEntry *entry,
469 GtkMovementStep step,
471 gboolean extend_selection);
472 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
474 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
477 static void gtk_entry_backspace (GtkEntry *entry);
478 static void gtk_entry_cut_clipboard (GtkEntry *entry);
479 static void gtk_entry_copy_clipboard (GtkEntry *entry);
480 static void gtk_entry_paste_clipboard (GtkEntry *entry);
481 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
482 static void gtk_entry_select_all (GtkEntry *entry);
483 static void gtk_entry_real_activate (GtkEntry *entry);
484 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
486 static void keymap_direction_changed (GdkKeymap *keymap,
488 static void keymap_state_changed (GdkKeymap *keymap,
490 static void remove_capslock_feedback (GtkEntry *entry);
492 /* IM Context Callbacks
494 static void gtk_entry_commit_cb (GtkIMContext *context,
497 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
499 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
501 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
508 static void gtk_entry_enter_text (GtkEntry *entry,
510 static void gtk_entry_set_positions (GtkEntry *entry,
512 gint selection_bound);
513 static void gtk_entry_draw_text (GtkEntry *entry,
515 static void gtk_entry_draw_cursor (GtkEntry *entry,
518 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
519 gboolean include_preedit);
520 static void gtk_entry_reset_layout (GtkEntry *entry);
521 static void gtk_entry_recompute (GtkEntry *entry);
522 static gint gtk_entry_find_position (GtkEntry *entry,
524 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
528 static void gtk_entry_adjust_scroll (GtkEntry *entry);
529 static gint gtk_entry_move_visually (GtkEntry *editable,
532 static gint gtk_entry_move_logically (GtkEntry *entry,
535 static gint gtk_entry_move_forward_word (GtkEntry *entry,
537 gboolean allow_whitespace);
538 static gint gtk_entry_move_backward_word (GtkEntry *entry,
540 gboolean allow_whitespace);
541 static void gtk_entry_delete_whitespace (GtkEntry *entry);
542 static void gtk_entry_select_word (GtkEntry *entry);
543 static void gtk_entry_select_line (GtkEntry *entry);
544 static void gtk_entry_paste (GtkEntry *entry,
546 static void gtk_entry_update_primary_selection (GtkEntry *entry);
547 static void gtk_entry_do_popup (GtkEntry *entry,
548 GdkEventButton *event);
549 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
550 gboolean group_cycling);
551 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
552 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
553 static void gtk_entry_reset_blink_time (GtkEntry *entry);
554 static void gtk_entry_get_text_area_size (GtkEntry *entry,
559 static void get_text_area_size (GtkEntry *entry,
564 static void get_frame_size (GtkEntry *entry,
565 gboolean relative_to_window,
570 static void gtk_entry_move_adjustments (GtkEntry *entry);
571 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
572 GtkEntryIconPosition icon_pos);
573 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
576 static gint gtk_entry_completion_timeout (gpointer data);
577 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
580 static void gtk_entry_completion_changed (GtkWidget *entry,
582 static gboolean check_completion_callback (GtkEntryCompletion *completion);
583 static void clear_completion_callback (GtkEntry *entry,
585 static gboolean accept_completion_callback (GtkEntry *entry);
586 static void completion_insert_text_callback (GtkEntry *entry,
590 GtkEntryCompletion *completion);
591 static void completion_changed (GtkEntryCompletion *completion,
594 static void disconnect_completion_signals (GtkEntry *entry,
595 GtkEntryCompletion *completion);
596 static void connect_completion_signals (GtkEntry *entry,
597 GtkEntryCompletion *completion);
599 static void begin_change (GtkEntry *entry);
600 static void end_change (GtkEntry *entry);
601 static void emit_changed (GtkEntry *entry);
603 static void buffer_inserted_text (GtkEntryBuffer *buffer,
608 static void buffer_deleted_text (GtkEntryBuffer *buffer,
612 static void buffer_notify_text (GtkEntryBuffer *buffer,
615 static void buffer_notify_length (GtkEntryBuffer *buffer,
618 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
621 static void buffer_connect_signals (GtkEntry *entry);
622 static void buffer_disconnect_signals (GtkEntry *entry);
623 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
625 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
626 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
627 gtk_entry_editable_init)
628 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
629 gtk_entry_cell_editable_init))
632 add_move_binding (GtkBindingSet *binding_set,
635 GtkMovementStep step,
638 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
640 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
644 G_TYPE_BOOLEAN, FALSE);
646 /* Selection-extending version */
647 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
651 G_TYPE_BOOLEAN, TRUE);
655 gtk_entry_class_init (GtkEntryClass *class)
657 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
658 GtkWidgetClass *widget_class;
659 GtkBindingSet *binding_set;
661 widget_class = (GtkWidgetClass*) class;
663 gobject_class->dispose = gtk_entry_dispose;
664 gobject_class->finalize = gtk_entry_finalize;
665 gobject_class->set_property = gtk_entry_set_property;
666 gobject_class->get_property = gtk_entry_get_property;
668 widget_class->destroy = gtk_entry_destroy;
669 widget_class->map = gtk_entry_map;
670 widget_class->unmap = gtk_entry_unmap;
671 widget_class->realize = gtk_entry_realize;
672 widget_class->unrealize = gtk_entry_unrealize;
673 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
674 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
675 widget_class->size_allocate = gtk_entry_size_allocate;
676 widget_class->draw = gtk_entry_draw;
677 widget_class->enter_notify_event = gtk_entry_enter_notify;
678 widget_class->leave_notify_event = gtk_entry_leave_notify;
679 widget_class->button_press_event = gtk_entry_button_press;
680 widget_class->button_release_event = gtk_entry_button_release;
681 widget_class->motion_notify_event = gtk_entry_motion_notify;
682 widget_class->key_press_event = gtk_entry_key_press;
683 widget_class->key_release_event = gtk_entry_key_release;
684 widget_class->focus_in_event = gtk_entry_focus_in;
685 widget_class->focus_out_event = gtk_entry_focus_out;
686 widget_class->grab_focus = gtk_entry_grab_focus;
687 widget_class->style_updated = gtk_entry_style_updated;
688 widget_class->query_tooltip = gtk_entry_query_tooltip;
689 widget_class->drag_begin = gtk_entry_drag_begin;
690 widget_class->drag_end = gtk_entry_drag_end;
691 widget_class->direction_changed = gtk_entry_direction_changed;
692 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
693 widget_class->screen_changed = gtk_entry_screen_changed;
694 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
696 widget_class->drag_drop = gtk_entry_drag_drop;
697 widget_class->drag_motion = gtk_entry_drag_motion;
698 widget_class->drag_leave = gtk_entry_drag_leave;
699 widget_class->drag_data_received = gtk_entry_drag_data_received;
700 widget_class->drag_data_get = gtk_entry_drag_data_get;
701 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
703 widget_class->popup_menu = gtk_entry_popup_menu;
705 class->move_cursor = gtk_entry_move_cursor;
706 class->insert_at_cursor = gtk_entry_insert_at_cursor;
707 class->delete_from_cursor = gtk_entry_delete_from_cursor;
708 class->backspace = gtk_entry_backspace;
709 class->cut_clipboard = gtk_entry_cut_clipboard;
710 class->copy_clipboard = gtk_entry_copy_clipboard;
711 class->paste_clipboard = gtk_entry_paste_clipboard;
712 class->toggle_overwrite = gtk_entry_toggle_overwrite;
713 class->activate = gtk_entry_real_activate;
714 class->get_text_area_size = gtk_entry_get_text_area_size;
716 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
717 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
718 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
719 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
721 g_object_class_override_property (gobject_class,
722 PROP_EDITING_CANCELED,
725 g_object_class_install_property (gobject_class,
727 g_param_spec_object ("buffer",
729 P_("Text buffer object which actually stores entry text"),
730 GTK_TYPE_ENTRY_BUFFER,
731 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
733 g_object_class_install_property (gobject_class,
734 PROP_CURSOR_POSITION,
735 g_param_spec_int ("cursor-position",
736 P_("Cursor Position"),
737 P_("The current position of the insertion cursor in chars"),
739 GTK_ENTRY_BUFFER_MAX_SIZE,
741 GTK_PARAM_READABLE));
743 g_object_class_install_property (gobject_class,
744 PROP_SELECTION_BOUND,
745 g_param_spec_int ("selection-bound",
746 P_("Selection Bound"),
747 P_("The position of the opposite end of the selection from the cursor in chars"),
749 GTK_ENTRY_BUFFER_MAX_SIZE,
751 GTK_PARAM_READABLE));
753 g_object_class_install_property (gobject_class,
755 g_param_spec_boolean ("editable",
757 P_("Whether the entry contents can be edited"),
759 GTK_PARAM_READWRITE));
761 g_object_class_install_property (gobject_class,
763 g_param_spec_int ("max-length",
764 P_("Maximum length"),
765 P_("Maximum number of characters for this entry. Zero if no maximum"),
767 GTK_ENTRY_BUFFER_MAX_SIZE,
769 GTK_PARAM_READWRITE));
770 g_object_class_install_property (gobject_class,
772 g_param_spec_boolean ("visibility",
774 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
776 GTK_PARAM_READWRITE));
778 g_object_class_install_property (gobject_class,
780 g_param_spec_boolean ("has-frame",
782 P_("FALSE removes outside bevel from entry"),
784 GTK_PARAM_READWRITE));
786 g_object_class_install_property (gobject_class,
788 g_param_spec_boxed ("inner-border",
790 P_("Border between text and frame. Overrides the inner-border style property"),
792 GTK_PARAM_READWRITE));
794 g_object_class_install_property (gobject_class,
796 g_param_spec_unichar ("invisible-char",
797 P_("Invisible character"),
798 P_("The character to use when masking entry contents (in \"password mode\")"),
800 GTK_PARAM_READWRITE));
802 g_object_class_install_property (gobject_class,
803 PROP_ACTIVATES_DEFAULT,
804 g_param_spec_boolean ("activates-default",
805 P_("Activates default"),
806 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
808 GTK_PARAM_READWRITE));
809 g_object_class_install_property (gobject_class,
811 g_param_spec_int ("width-chars",
812 P_("Width in chars"),
813 P_("Number of characters to leave space for in the entry"),
817 GTK_PARAM_READWRITE));
819 g_object_class_install_property (gobject_class,
821 g_param_spec_int ("scroll-offset",
823 P_("Number of pixels of the entry scrolled off the screen to the left"),
827 GTK_PARAM_READABLE));
829 g_object_class_install_property (gobject_class,
831 g_param_spec_string ("text",
833 P_("The contents of the entry"),
835 GTK_PARAM_READWRITE));
840 * The horizontal alignment, from 0 (left) to 1 (right).
841 * Reversed for RTL layouts.
845 g_object_class_install_property (gobject_class,
847 g_param_spec_float ("xalign",
849 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
853 GTK_PARAM_READWRITE));
856 * GtkEntry:truncate-multiline:
858 * When %TRUE, pasted multi-line text is truncated to the first line.
862 g_object_class_install_property (gobject_class,
863 PROP_TRUNCATE_MULTILINE,
864 g_param_spec_boolean ("truncate-multiline",
865 P_("Truncate multiline"),
866 P_("Whether to truncate multiline pastes to one line."),
868 GTK_PARAM_READWRITE));
871 * GtkEntry:shadow-type:
873 * Which kind of shadow to draw around the entry when
874 * #GtkEntry:has-frame is set to %TRUE.
878 g_object_class_install_property (gobject_class,
880 g_param_spec_enum ("shadow-type",
882 P_("Which kind of shadow to draw around the entry when has-frame is set"),
883 GTK_TYPE_SHADOW_TYPE,
885 GTK_PARAM_READWRITE));
888 * GtkEntry:overwrite-mode:
890 * If text is overwritten when typing in the #GtkEntry.
894 g_object_class_install_property (gobject_class,
896 g_param_spec_boolean ("overwrite-mode",
897 P_("Overwrite mode"),
898 P_("Whether new text overwrites existing text"),
900 GTK_PARAM_READWRITE));
903 * GtkEntry:text-length:
905 * The length of the text in the #GtkEntry.
909 g_object_class_install_property (gobject_class,
911 g_param_spec_uint ("text-length",
913 P_("Length of the text currently in the entry"),
917 GTK_PARAM_READABLE));
919 * GtkEntry:invisible-char-set:
921 * Whether the invisible char has been set for the #GtkEntry.
925 g_object_class_install_property (gobject_class,
926 PROP_INVISIBLE_CHAR_SET,
927 g_param_spec_boolean ("invisible-char-set",
928 P_("Invisible character set"),
929 P_("Whether the invisible character has been set"),
931 GTK_PARAM_READWRITE));
934 * GtkEntry:caps-lock-warning
936 * Whether password entries will show a warning when Caps Lock is on.
938 * Note that the warning is shown using a secondary icon, and thus
939 * does not work if you are using the secondary icon position for some
944 g_object_class_install_property (gobject_class,
945 PROP_CAPS_LOCK_WARNING,
946 g_param_spec_boolean ("caps-lock-warning",
947 P_("Caps Lock warning"),
948 P_("Whether password entries will show a warning when Caps Lock is on"),
950 GTK_PARAM_READWRITE));
953 * GtkEntry:progress-fraction:
955 * The current fraction of the task that's been completed.
959 g_object_class_install_property (gobject_class,
960 PROP_PROGRESS_FRACTION,
961 g_param_spec_double ("progress-fraction",
962 P_("Progress Fraction"),
963 P_("The current fraction of the task that's been completed"),
967 GTK_PARAM_READWRITE));
970 * GtkEntry:progress-pulse-step:
972 * The fraction of total entry width to move the progress
973 * bouncing block for each call to gtk_entry_progress_pulse().
977 g_object_class_install_property (gobject_class,
978 PROP_PROGRESS_PULSE_STEP,
979 g_param_spec_double ("progress-pulse-step",
980 P_("Progress Pulse Step"),
981 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
985 GTK_PARAM_READWRITE));
988 * GtkEntry:placeholder-text:
990 * The text that will be displayed in the #GtkEntry when it is empty and unfocused.
994 g_object_class_install_property (gobject_class,
995 PROP_PLACEHOLDER_TEXT,
996 g_param_spec_string ("placeholder-text",
997 P_("Placeholder text"),
998 P_("Show text in the entry when it's empty and unfocused"),
1000 GTK_PARAM_READWRITE));
1003 * GtkEntry:primary-icon-pixbuf:
1005 * A pixbuf to use as the primary icon for the entry.
1009 g_object_class_install_property (gobject_class,
1010 PROP_PIXBUF_PRIMARY,
1011 g_param_spec_object ("primary-icon-pixbuf",
1012 P_("Primary pixbuf"),
1013 P_("Primary pixbuf for the entry"),
1015 GTK_PARAM_READWRITE));
1018 * GtkEntry:secondary-icon-pixbuf:
1020 * An pixbuf to use as the secondary icon for the entry.
1024 g_object_class_install_property (gobject_class,
1025 PROP_PIXBUF_SECONDARY,
1026 g_param_spec_object ("secondary-icon-pixbuf",
1027 P_("Secondary pixbuf"),
1028 P_("Secondary pixbuf for the entry"),
1030 GTK_PARAM_READWRITE));
1033 * GtkEntry:primary-icon-stock:
1035 * The stock id to use for the primary icon for the entry.
1039 g_object_class_install_property (gobject_class,
1041 g_param_spec_string ("primary-icon-stock",
1042 P_("Primary stock ID"),
1043 P_("Stock ID for primary icon"),
1045 GTK_PARAM_READWRITE));
1048 * GtkEntry:secondary-icon-stock:
1050 * The stock id to use for the secondary icon for the entry.
1054 g_object_class_install_property (gobject_class,
1055 PROP_STOCK_SECONDARY,
1056 g_param_spec_string ("secondary-icon-stock",
1057 P_("Secondary stock ID"),
1058 P_("Stock ID for secondary icon"),
1060 GTK_PARAM_READWRITE));
1063 * GtkEntry:primary-icon-name:
1065 * The icon name to use for the primary icon for the entry.
1069 g_object_class_install_property (gobject_class,
1070 PROP_ICON_NAME_PRIMARY,
1071 g_param_spec_string ("primary-icon-name",
1072 P_("Primary icon name"),
1073 P_("Icon name for primary icon"),
1075 GTK_PARAM_READWRITE));
1078 * GtkEntry:secondary-icon-name:
1080 * The icon name to use for the secondary icon for the entry.
1084 g_object_class_install_property (gobject_class,
1085 PROP_ICON_NAME_SECONDARY,
1086 g_param_spec_string ("secondary-icon-name",
1087 P_("Secondary icon name"),
1088 P_("Icon name for secondary icon"),
1090 GTK_PARAM_READWRITE));
1093 * GtkEntry:primary-icon-gicon:
1095 * The #GIcon to use for the primary icon for the entry.
1099 g_object_class_install_property (gobject_class,
1101 g_param_spec_object ("primary-icon-gicon",
1102 P_("Primary GIcon"),
1103 P_("GIcon for primary icon"),
1105 GTK_PARAM_READWRITE));
1108 * GtkEntry:secondary-icon-gicon:
1110 * The #GIcon to use for the secondary icon for the entry.
1114 g_object_class_install_property (gobject_class,
1115 PROP_GICON_SECONDARY,
1116 g_param_spec_object ("secondary-icon-gicon",
1117 P_("Secondary GIcon"),
1118 P_("GIcon for secondary icon"),
1120 GTK_PARAM_READWRITE));
1123 * GtkEntry:primary-icon-storage-type:
1125 * The representation which is used for the primary icon of the entry.
1129 g_object_class_install_property (gobject_class,
1130 PROP_STORAGE_TYPE_PRIMARY,
1131 g_param_spec_enum ("primary-icon-storage-type",
1132 P_("Primary storage type"),
1133 P_("The representation being used for primary icon"),
1134 GTK_TYPE_IMAGE_TYPE,
1136 GTK_PARAM_READABLE));
1139 * GtkEntry:secondary-icon-storage-type:
1141 * The representation which is used for the secondary icon of the entry.
1145 g_object_class_install_property (gobject_class,
1146 PROP_STORAGE_TYPE_SECONDARY,
1147 g_param_spec_enum ("secondary-icon-storage-type",
1148 P_("Secondary storage type"),
1149 P_("The representation being used for secondary icon"),
1150 GTK_TYPE_IMAGE_TYPE,
1152 GTK_PARAM_READABLE));
1155 * GtkEntry:primary-icon-activatable:
1157 * Whether the primary icon is activatable.
1159 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1160 * signals only on sensitive, activatable icons.
1162 * Sensitive, but non-activatable icons can be used for purely
1163 * informational purposes.
1167 g_object_class_install_property (gobject_class,
1168 PROP_ACTIVATABLE_PRIMARY,
1169 g_param_spec_boolean ("primary-icon-activatable",
1170 P_("Primary icon activatable"),
1171 P_("Whether the primary icon is activatable"),
1173 GTK_PARAM_READWRITE));
1176 * GtkEntry:secondary-icon-activatable:
1178 * Whether the secondary icon is activatable.
1180 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1181 * signals only on sensitive, activatable icons.
1183 * Sensitive, but non-activatable icons can be used for purely
1184 * informational purposes.
1188 g_object_class_install_property (gobject_class,
1189 PROP_ACTIVATABLE_SECONDARY,
1190 g_param_spec_boolean ("secondary-icon-activatable",
1191 P_("Secondary icon activatable"),
1192 P_("Whether the secondary icon is activatable"),
1194 GTK_PARAM_READWRITE));
1198 * GtkEntry:primary-icon-sensitive:
1200 * Whether the primary icon is sensitive.
1202 * An insensitive icon appears grayed out. GTK+ does not emit the
1203 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1204 * does not allow DND from insensitive icons.
1206 * An icon should be set insensitive if the action that would trigger
1207 * when clicked is currently not available.
1211 g_object_class_install_property (gobject_class,
1212 PROP_SENSITIVE_PRIMARY,
1213 g_param_spec_boolean ("primary-icon-sensitive",
1214 P_("Primary icon sensitive"),
1215 P_("Whether the primary icon is sensitive"),
1217 GTK_PARAM_READWRITE));
1220 * GtkEntry:secondary-icon-sensitive:
1222 * Whether the secondary icon is sensitive.
1224 * An insensitive icon appears grayed out. GTK+ does not emit the
1225 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1226 * does not allow DND from insensitive icons.
1228 * An icon should be set insensitive if the action that would trigger
1229 * when clicked is currently not available.
1233 g_object_class_install_property (gobject_class,
1234 PROP_SENSITIVE_SECONDARY,
1235 g_param_spec_boolean ("secondary-icon-sensitive",
1236 P_("Secondary icon sensitive"),
1237 P_("Whether the secondary icon is sensitive"),
1239 GTK_PARAM_READWRITE));
1242 * GtkEntry:primary-icon-tooltip-text:
1244 * The contents of the tooltip on the primary icon.
1246 * Also see gtk_entry_set_icon_tooltip_text().
1250 g_object_class_install_property (gobject_class,
1251 PROP_TOOLTIP_TEXT_PRIMARY,
1252 g_param_spec_string ("primary-icon-tooltip-text",
1253 P_("Primary icon tooltip text"),
1254 P_("The contents of the tooltip on the primary icon"),
1256 GTK_PARAM_READWRITE));
1259 * GtkEntry:secondary-icon-tooltip-text:
1261 * The contents of the tooltip on the secondary icon.
1263 * Also see gtk_entry_set_icon_tooltip_text().
1267 g_object_class_install_property (gobject_class,
1268 PROP_TOOLTIP_TEXT_SECONDARY,
1269 g_param_spec_string ("secondary-icon-tooltip-text",
1270 P_("Secondary icon tooltip text"),
1271 P_("The contents of the tooltip on the secondary icon"),
1273 GTK_PARAM_READWRITE));
1276 * GtkEntry:primary-icon-tooltip-markup:
1278 * The contents of the tooltip on the primary icon, which is marked up
1279 * with the <link linkend="PangoMarkupFormat">Pango text markup
1282 * Also see gtk_entry_set_icon_tooltip_markup().
1286 g_object_class_install_property (gobject_class,
1287 PROP_TOOLTIP_MARKUP_PRIMARY,
1288 g_param_spec_string ("primary-icon-tooltip-markup",
1289 P_("Primary icon tooltip markup"),
1290 P_("The contents of the tooltip on the primary icon"),
1292 GTK_PARAM_READWRITE));
1295 * GtkEntry:secondary-icon-tooltip-markup:
1297 * The contents of the tooltip on the secondary icon, which is marked up
1298 * with the <link linkend="PangoMarkupFormat">Pango text markup
1301 * Also see gtk_entry_set_icon_tooltip_markup().
1305 g_object_class_install_property (gobject_class,
1306 PROP_TOOLTIP_MARKUP_SECONDARY,
1307 g_param_spec_string ("secondary-icon-tooltip-markup",
1308 P_("Secondary icon tooltip markup"),
1309 P_("The contents of the tooltip on the secondary icon"),
1311 GTK_PARAM_READWRITE));
1314 * GtkEntry:im-module:
1316 * Which IM (input method) module should be used for this entry.
1317 * See #GtkIMContext.
1319 * Setting this to a non-%NULL value overrides the
1320 * system-wide IM module setting. See the GtkSettings
1321 * #GtkSettings:gtk-im-module property.
1325 g_object_class_install_property (gobject_class,
1327 g_param_spec_string ("im-module",
1329 P_("Which IM module should be used"),
1331 GTK_PARAM_READWRITE));
1334 * GtkEntry:completion:
1336 * The auxiliary completion object to use with the entry.
1340 g_object_class_install_property (gobject_class,
1342 g_param_spec_object ("completion",
1344 P_("The auxiliary completion object"),
1345 GTK_TYPE_ENTRY_COMPLETION,
1346 GTK_PARAM_READWRITE));
1349 * GtkEntry:icon-prelight:
1351 * The prelight style property determines whether activatable
1352 * icons prelight on mouseover.
1356 gtk_widget_class_install_style_property (widget_class,
1357 g_param_spec_boolean ("icon-prelight",
1358 P_("Icon Prelight"),
1359 P_("Whether activatable icons should prelight when hovered"),
1361 GTK_PARAM_READABLE));
1364 * GtkEntry:progress-border:
1366 * The border around the progress bar in the entry.
1370 gtk_widget_class_install_style_property (widget_class,
1371 g_param_spec_boxed ("progress-border",
1372 P_("Progress Border"),
1373 P_("Border around the progress bar"),
1375 GTK_PARAM_READABLE));
1378 * GtkEntry:invisible-char:
1380 * The invisible character is used when masking entry contents (in
1381 * \"password mode\")"). When it is not explicitly set with the
1382 * #GtkEntry::invisible-char property, GTK+ determines the character
1383 * to use from a list of possible candidates, depending on availability
1384 * in the current font.
1386 * This style property allows the theme to prepend a character
1387 * to the list of candidates.
1391 gtk_widget_class_install_style_property (widget_class,
1392 g_param_spec_unichar ("invisible-char",
1393 P_("Invisible character"),
1394 P_("The character to use when masking entry contents (in \"password mode\")"),
1396 GTK_PARAM_READABLE));
1399 * GtkEntry::populate-popup:
1400 * @entry: The entry on which the signal is emitted
1401 * @menu: the menu that is being populated
1403 * The ::populate-popup signal gets emitted before showing the
1404 * context menu of the entry.
1406 * If you need to add items to the context menu, connect
1407 * to this signal and append your menuitems to the @menu.
1409 signals[POPULATE_POPUP] =
1410 g_signal_new (I_("populate-popup"),
1411 G_OBJECT_CLASS_TYPE (gobject_class),
1413 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1415 _gtk_marshal_VOID__OBJECT,
1419 /* Action signals */
1422 * GtkEntry::activate:
1423 * @entry: The entry on which the signal is emitted
1425 * A <link linkend="keybinding-signals">keybinding signal</link>
1426 * which gets emitted when the user activates the entry.
1428 * Applications should not connect to it, but may emit it with
1429 * g_signal_emit_by_name() if they need to control activation
1432 * The default bindings for this signal are all forms of the Enter key.
1435 g_signal_new (I_("activate"),
1436 G_OBJECT_CLASS_TYPE (gobject_class),
1437 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1438 G_STRUCT_OFFSET (GtkEntryClass, activate),
1440 _gtk_marshal_VOID__VOID,
1442 widget_class->activate_signal = signals[ACTIVATE];
1445 * GtkEntry::move-cursor:
1446 * @entry: the object which received the signal
1447 * @step: the granularity of the move, as a #GtkMovementStep
1448 * @count: the number of @step units to move
1449 * @extend_selection: %TRUE if the move should extend the selection
1451 * The ::move-cursor signal is a
1452 * <link linkend="keybinding-signals">keybinding signal</link>
1453 * which gets emitted when the user initiates a cursor movement.
1454 * If the cursor is not visible in @entry, this signal causes
1455 * the viewport to be moved instead.
1457 * Applications should not connect to it, but may emit it with
1458 * g_signal_emit_by_name() if they need to control the cursor
1461 * The default bindings for this signal come in two variants,
1462 * the variant with the Shift modifier extends the selection,
1463 * the variant without the Shift modifer does not.
1464 * There are too many key combinations to list them all here.
1466 * <listitem>Arrow keys move by individual characters/lines</listitem>
1467 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1468 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1471 signals[MOVE_CURSOR] =
1472 g_signal_new (I_("move-cursor"),
1473 G_OBJECT_CLASS_TYPE (gobject_class),
1474 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1475 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1477 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1479 GTK_TYPE_MOVEMENT_STEP,
1484 * GtkEntry::insert-at-cursor:
1485 * @entry: the object which received the signal
1486 * @string: the string to insert
1488 * The ::insert-at-cursor signal is a
1489 * <link linkend="keybinding-signals">keybinding signal</link>
1490 * which gets emitted when the user initiates the insertion of a
1491 * fixed string at the cursor.
1493 * This signal has no default bindings.
1495 signals[INSERT_AT_CURSOR] =
1496 g_signal_new (I_("insert-at-cursor"),
1497 G_OBJECT_CLASS_TYPE (gobject_class),
1498 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1499 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1501 _gtk_marshal_VOID__STRING,
1506 * GtkEntry::delete-from-cursor:
1507 * @entry: the object which received the signal
1508 * @type: the granularity of the deletion, as a #GtkDeleteType
1509 * @count: the number of @type units to delete
1511 * The ::delete-from-cursor signal is a
1512 * <link linkend="keybinding-signals">keybinding signal</link>
1513 * which gets emitted when the user initiates a text deletion.
1515 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1516 * if there is one, otherwise it deletes the requested number
1519 * The default bindings for this signal are
1520 * Delete for deleting a character and Ctrl-Delete for
1523 signals[DELETE_FROM_CURSOR] =
1524 g_signal_new (I_("delete-from-cursor"),
1525 G_OBJECT_CLASS_TYPE (gobject_class),
1526 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1527 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1529 _gtk_marshal_VOID__ENUM_INT,
1531 GTK_TYPE_DELETE_TYPE,
1535 * GtkEntry::backspace:
1536 * @entry: the object which received the signal
1538 * The ::backspace signal is a
1539 * <link linkend="keybinding-signals">keybinding signal</link>
1540 * which gets emitted when the user asks for it.
1542 * The default bindings for this signal are
1543 * Backspace and Shift-Backspace.
1545 signals[BACKSPACE] =
1546 g_signal_new (I_("backspace"),
1547 G_OBJECT_CLASS_TYPE (gobject_class),
1548 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1549 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1551 _gtk_marshal_VOID__VOID,
1555 * GtkEntry::cut-clipboard:
1556 * @entry: the object which received the signal
1558 * The ::cut-clipboard signal is a
1559 * <link linkend="keybinding-signals">keybinding signal</link>
1560 * which gets emitted to cut the selection to the clipboard.
1562 * The default bindings for this signal are
1563 * Ctrl-x and Shift-Delete.
1565 signals[CUT_CLIPBOARD] =
1566 g_signal_new (I_("cut-clipboard"),
1567 G_OBJECT_CLASS_TYPE (gobject_class),
1568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1569 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1571 _gtk_marshal_VOID__VOID,
1575 * GtkEntry::copy-clipboard:
1576 * @entry: the object which received the signal
1578 * The ::copy-clipboard signal is a
1579 * <link linkend="keybinding-signals">keybinding signal</link>
1580 * which gets emitted to copy the selection to the clipboard.
1582 * The default bindings for this signal are
1583 * Ctrl-c and Ctrl-Insert.
1585 signals[COPY_CLIPBOARD] =
1586 g_signal_new (I_("copy-clipboard"),
1587 G_OBJECT_CLASS_TYPE (gobject_class),
1588 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1589 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1591 _gtk_marshal_VOID__VOID,
1595 * GtkEntry::paste-clipboard:
1596 * @entry: the object which received the signal
1598 * The ::paste-clipboard signal is a
1599 * <link linkend="keybinding-signals">keybinding signal</link>
1600 * which gets emitted to paste the contents of the clipboard
1601 * into the text view.
1603 * The default bindings for this signal are
1604 * Ctrl-v and Shift-Insert.
1606 signals[PASTE_CLIPBOARD] =
1607 g_signal_new (I_("paste-clipboard"),
1608 G_OBJECT_CLASS_TYPE (gobject_class),
1609 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1610 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1612 _gtk_marshal_VOID__VOID,
1616 * GtkEntry::toggle-overwrite:
1617 * @entry: the object which received the signal
1619 * The ::toggle-overwrite signal is a
1620 * <link linkend="keybinding-signals">keybinding signal</link>
1621 * which gets emitted to toggle the overwrite mode of the entry.
1623 * The default bindings for this signal is Insert.
1625 signals[TOGGLE_OVERWRITE] =
1626 g_signal_new (I_("toggle-overwrite"),
1627 G_OBJECT_CLASS_TYPE (gobject_class),
1628 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1629 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1631 _gtk_marshal_VOID__VOID,
1635 * GtkEntry::icon-press:
1636 * @entry: The entry on which the signal is emitted
1637 * @icon_pos: The position of the clicked icon
1638 * @event: (type Gdk.EventButton): the button press event
1640 * The ::icon-press signal is emitted when an activatable icon
1645 signals[ICON_PRESS] =
1646 g_signal_new (I_("icon-press"),
1647 G_TYPE_FROM_CLASS (gobject_class),
1651 _gtk_marshal_VOID__ENUM_BOXED,
1653 GTK_TYPE_ENTRY_ICON_POSITION,
1654 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1657 * GtkEntry::icon-release:
1658 * @entry: The entry on which the signal is emitted
1659 * @icon_pos: The position of the clicked icon
1660 * @event: (type Gdk.EventButton): the button release event
1662 * The ::icon-release signal is emitted on the button release from a
1663 * mouse click over an activatable icon.
1667 signals[ICON_RELEASE] =
1668 g_signal_new (I_("icon-release"),
1669 G_TYPE_FROM_CLASS (gobject_class),
1673 _gtk_marshal_VOID__ENUM_BOXED,
1675 GTK_TYPE_ENTRY_ICON_POSITION,
1676 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1679 * GtkEntry::preedit-changed:
1680 * @entry: the object which received the signal
1681 * @preedit: the current preedit string
1683 * If an input method is used, the typed text will not immediately
1684 * be committed to the buffer. So if you are interested in the text,
1685 * connect to this signal.
1689 signals[PREEDIT_CHANGED] =
1690 g_signal_new_class_handler (I_("preedit-changed"),
1691 G_OBJECT_CLASS_TYPE (gobject_class),
1692 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1695 _gtk_marshal_VOID__STRING,
1704 binding_set = gtk_binding_set_by_class (class);
1706 /* Moving the insertion point */
1707 add_move_binding (binding_set, GDK_KEY_Right, 0,
1708 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1710 add_move_binding (binding_set, GDK_KEY_Left, 0,
1711 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1713 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1714 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1716 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1717 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1719 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1720 GTK_MOVEMENT_WORDS, 1);
1722 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1723 GTK_MOVEMENT_WORDS, -1);
1725 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1726 GTK_MOVEMENT_WORDS, 1);
1728 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1729 GTK_MOVEMENT_WORDS, -1);
1731 add_move_binding (binding_set, GDK_KEY_Home, 0,
1732 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1734 add_move_binding (binding_set, GDK_KEY_End, 0,
1735 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1737 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1738 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1740 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1741 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1743 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1744 GTK_MOVEMENT_BUFFER_ENDS, -1);
1746 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1747 GTK_MOVEMENT_BUFFER_ENDS, 1);
1749 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1750 GTK_MOVEMENT_BUFFER_ENDS, -1);
1752 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1753 GTK_MOVEMENT_BUFFER_ENDS, 1);
1757 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1759 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1761 G_TYPE_BOOLEAN, FALSE);
1762 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1764 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1766 G_TYPE_BOOLEAN, TRUE);
1768 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1770 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1772 G_TYPE_BOOLEAN, FALSE);
1773 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1775 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1777 G_TYPE_BOOLEAN, TRUE);
1780 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1782 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1784 G_TYPE_BOOLEAN, FALSE);
1785 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1787 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1789 G_TYPE_BOOLEAN, FALSE);
1793 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1795 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1797 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1801 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1802 "delete-from-cursor", 2,
1803 G_TYPE_ENUM, GTK_DELETE_CHARS,
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1807 "delete-from-cursor", 2,
1808 G_TYPE_ENUM, GTK_DELETE_CHARS,
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1814 /* Make this do the same as Backspace, to help with mis-typing */
1815 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1818 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1819 "delete-from-cursor", 2,
1820 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1823 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1824 "delete-from-cursor", 2,
1825 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1828 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1829 "delete-from-cursor", 2,
1830 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1833 /* Cut/copy/paste */
1835 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1836 "cut-clipboard", 0);
1837 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1838 "copy-clipboard", 0);
1839 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1840 "paste-clipboard", 0);
1842 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1843 "cut-clipboard", 0);
1844 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1845 "copy-clipboard", 0);
1846 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1847 "paste-clipboard", 0);
1850 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1851 "toggle-overwrite", 0);
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1853 "toggle-overwrite", 0);
1856 * GtkEntry:inner-border:
1858 * Sets the text area's border between the text and the frame.
1862 gtk_widget_class_install_style_property (widget_class,
1863 g_param_spec_boxed ("inner-border",
1865 P_("Border between text and frame."),
1867 GTK_PARAM_READABLE));
1869 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1873 gtk_entry_editable_init (GtkEditableInterface *iface)
1875 iface->do_insert_text = gtk_entry_insert_text;
1876 iface->do_delete_text = gtk_entry_delete_text;
1877 iface->insert_text = gtk_entry_real_insert_text;
1878 iface->delete_text = gtk_entry_real_delete_text;
1879 iface->get_chars = gtk_entry_get_chars;
1880 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1881 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1882 iface->set_position = gtk_entry_real_set_position;
1883 iface->get_position = gtk_entry_get_position;
1887 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1889 iface->start_editing = gtk_entry_start_editing;
1893 gtk_entry_set_property (GObject *object,
1895 const GValue *value,
1898 GtkEntry *entry = GTK_ENTRY (object);
1899 GtkEntryPrivate *priv = entry->priv;
1904 gtk_entry_set_buffer (entry, g_value_get_object (value));
1909 gboolean new_value = g_value_get_boolean (value);
1911 if (new_value != priv->editable)
1913 GtkWidget *widget = GTK_WIDGET (entry);
1917 _gtk_entry_reset_im_context (entry);
1918 if (gtk_widget_has_focus (widget))
1919 gtk_im_context_focus_out (priv->im_context);
1921 priv->preedit_length = 0;
1922 priv->preedit_cursor = 0;
1925 priv->editable = new_value;
1927 if (new_value && gtk_widget_has_focus (widget))
1928 gtk_im_context_focus_in (priv->im_context);
1930 gtk_widget_queue_draw (widget);
1935 case PROP_MAX_LENGTH:
1936 gtk_entry_set_max_length (entry, g_value_get_int (value));
1939 case PROP_VISIBILITY:
1940 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1943 case PROP_HAS_FRAME:
1944 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1947 case PROP_INNER_BORDER:
1948 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1951 case PROP_INVISIBLE_CHAR:
1952 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1955 case PROP_ACTIVATES_DEFAULT:
1956 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1959 case PROP_WIDTH_CHARS:
1960 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1964 gtk_entry_set_text (entry, g_value_get_string (value));
1968 gtk_entry_set_alignment (entry, g_value_get_float (value));
1971 case PROP_TRUNCATE_MULTILINE:
1972 priv->truncate_multiline = g_value_get_boolean (value);
1975 case PROP_SHADOW_TYPE:
1976 priv->shadow_type = g_value_get_enum (value);
1979 case PROP_OVERWRITE_MODE:
1980 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1983 case PROP_INVISIBLE_CHAR_SET:
1984 if (g_value_get_boolean (value))
1985 priv->invisible_char_set = TRUE;
1987 gtk_entry_unset_invisible_char (entry);
1990 case PROP_CAPS_LOCK_WARNING:
1991 priv->caps_lock_warning = g_value_get_boolean (value);
1994 case PROP_PROGRESS_FRACTION:
1995 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1998 case PROP_PROGRESS_PULSE_STEP:
1999 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2002 case PROP_PLACEHOLDER_TEXT:
2003 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2006 case PROP_PIXBUF_PRIMARY:
2007 gtk_entry_set_icon_from_pixbuf (entry,
2008 GTK_ENTRY_ICON_PRIMARY,
2009 g_value_get_object (value));
2012 case PROP_PIXBUF_SECONDARY:
2013 gtk_entry_set_icon_from_pixbuf (entry,
2014 GTK_ENTRY_ICON_SECONDARY,
2015 g_value_get_object (value));
2018 case PROP_STOCK_PRIMARY:
2019 gtk_entry_set_icon_from_stock (entry,
2020 GTK_ENTRY_ICON_PRIMARY,
2021 g_value_get_string (value));
2024 case PROP_STOCK_SECONDARY:
2025 gtk_entry_set_icon_from_stock (entry,
2026 GTK_ENTRY_ICON_SECONDARY,
2027 g_value_get_string (value));
2030 case PROP_ICON_NAME_PRIMARY:
2031 gtk_entry_set_icon_from_icon_name (entry,
2032 GTK_ENTRY_ICON_PRIMARY,
2033 g_value_get_string (value));
2036 case PROP_ICON_NAME_SECONDARY:
2037 gtk_entry_set_icon_from_icon_name (entry,
2038 GTK_ENTRY_ICON_SECONDARY,
2039 g_value_get_string (value));
2042 case PROP_GICON_PRIMARY:
2043 gtk_entry_set_icon_from_gicon (entry,
2044 GTK_ENTRY_ICON_PRIMARY,
2045 g_value_get_object (value));
2048 case PROP_GICON_SECONDARY:
2049 gtk_entry_set_icon_from_gicon (entry,
2050 GTK_ENTRY_ICON_SECONDARY,
2051 g_value_get_object (value));
2054 case PROP_ACTIVATABLE_PRIMARY:
2055 gtk_entry_set_icon_activatable (entry,
2056 GTK_ENTRY_ICON_PRIMARY,
2057 g_value_get_boolean (value));
2060 case PROP_ACTIVATABLE_SECONDARY:
2061 gtk_entry_set_icon_activatable (entry,
2062 GTK_ENTRY_ICON_SECONDARY,
2063 g_value_get_boolean (value));
2066 case PROP_SENSITIVE_PRIMARY:
2067 gtk_entry_set_icon_sensitive (entry,
2068 GTK_ENTRY_ICON_PRIMARY,
2069 g_value_get_boolean (value));
2072 case PROP_SENSITIVE_SECONDARY:
2073 gtk_entry_set_icon_sensitive (entry,
2074 GTK_ENTRY_ICON_SECONDARY,
2075 g_value_get_boolean (value));
2078 case PROP_TOOLTIP_TEXT_PRIMARY:
2079 gtk_entry_set_icon_tooltip_text (entry,
2080 GTK_ENTRY_ICON_PRIMARY,
2081 g_value_get_string (value));
2084 case PROP_TOOLTIP_TEXT_SECONDARY:
2085 gtk_entry_set_icon_tooltip_text (entry,
2086 GTK_ENTRY_ICON_SECONDARY,
2087 g_value_get_string (value));
2090 case PROP_TOOLTIP_MARKUP_PRIMARY:
2091 gtk_entry_set_icon_tooltip_markup (entry,
2092 GTK_ENTRY_ICON_PRIMARY,
2093 g_value_get_string (value));
2096 case PROP_TOOLTIP_MARKUP_SECONDARY:
2097 gtk_entry_set_icon_tooltip_markup (entry,
2098 GTK_ENTRY_ICON_SECONDARY,
2099 g_value_get_string (value));
2102 case PROP_IM_MODULE:
2103 g_free (priv->im_module);
2104 priv->im_module = g_value_dup_string (value);
2105 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2106 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2109 case PROP_EDITING_CANCELED:
2110 priv->editing_canceled = g_value_get_boolean (value);
2113 case PROP_COMPLETION:
2114 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2117 case PROP_SCROLL_OFFSET:
2118 case PROP_CURSOR_POSITION:
2120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2126 gtk_entry_get_property (GObject *object,
2131 GtkEntry *entry = GTK_ENTRY (object);
2132 GtkEntryPrivate *priv = entry->priv;
2137 g_value_set_object (value, gtk_entry_get_buffer (entry));
2140 case PROP_CURSOR_POSITION:
2141 g_value_set_int (value, priv->current_pos);
2144 case PROP_SELECTION_BOUND:
2145 g_value_set_int (value, priv->selection_bound);
2149 g_value_set_boolean (value, priv->editable);
2152 case PROP_MAX_LENGTH:
2153 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2156 case PROP_VISIBILITY:
2157 g_value_set_boolean (value, priv->visible);
2160 case PROP_HAS_FRAME:
2161 g_value_set_boolean (value, priv->has_frame);
2164 case PROP_INNER_BORDER:
2165 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2168 case PROP_INVISIBLE_CHAR:
2169 g_value_set_uint (value, priv->invisible_char);
2172 case PROP_ACTIVATES_DEFAULT:
2173 g_value_set_boolean (value, priv->activates_default);
2176 case PROP_WIDTH_CHARS:
2177 g_value_set_int (value, priv->width_chars);
2180 case PROP_SCROLL_OFFSET:
2181 g_value_set_int (value, priv->scroll_offset);
2185 g_value_set_string (value, gtk_entry_get_text (entry));
2189 g_value_set_float (value, gtk_entry_get_alignment (entry));
2192 case PROP_TRUNCATE_MULTILINE:
2193 g_value_set_boolean (value, priv->truncate_multiline);
2196 case PROP_SHADOW_TYPE:
2197 g_value_set_enum (value, priv->shadow_type);
2200 case PROP_OVERWRITE_MODE:
2201 g_value_set_boolean (value, priv->overwrite_mode);
2204 case PROP_TEXT_LENGTH:
2205 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2208 case PROP_INVISIBLE_CHAR_SET:
2209 g_value_set_boolean (value, priv->invisible_char_set);
2212 case PROP_IM_MODULE:
2213 g_value_set_string (value, priv->im_module);
2216 case PROP_CAPS_LOCK_WARNING:
2217 g_value_set_boolean (value, priv->caps_lock_warning);
2220 case PROP_PROGRESS_FRACTION:
2221 g_value_set_double (value, priv->progress_fraction);
2224 case PROP_PROGRESS_PULSE_STEP:
2225 g_value_set_double (value, priv->progress_pulse_fraction);
2228 case PROP_PLACEHOLDER_TEXT:
2229 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2232 case PROP_PIXBUF_PRIMARY:
2233 g_value_set_object (value,
2234 gtk_entry_get_icon_pixbuf (entry,
2235 GTK_ENTRY_ICON_PRIMARY));
2238 case PROP_PIXBUF_SECONDARY:
2239 g_value_set_object (value,
2240 gtk_entry_get_icon_pixbuf (entry,
2241 GTK_ENTRY_ICON_SECONDARY));
2244 case PROP_STOCK_PRIMARY:
2245 g_value_set_string (value,
2246 gtk_entry_get_icon_stock (entry,
2247 GTK_ENTRY_ICON_PRIMARY));
2250 case PROP_STOCK_SECONDARY:
2251 g_value_set_string (value,
2252 gtk_entry_get_icon_stock (entry,
2253 GTK_ENTRY_ICON_SECONDARY));
2256 case PROP_ICON_NAME_PRIMARY:
2257 g_value_set_string (value,
2258 gtk_entry_get_icon_name (entry,
2259 GTK_ENTRY_ICON_PRIMARY));
2262 case PROP_ICON_NAME_SECONDARY:
2263 g_value_set_string (value,
2264 gtk_entry_get_icon_name (entry,
2265 GTK_ENTRY_ICON_SECONDARY));
2268 case PROP_GICON_PRIMARY:
2269 g_value_set_object (value,
2270 gtk_entry_get_icon_gicon (entry,
2271 GTK_ENTRY_ICON_PRIMARY));
2274 case PROP_GICON_SECONDARY:
2275 g_value_set_object (value,
2276 gtk_entry_get_icon_gicon (entry,
2277 GTK_ENTRY_ICON_SECONDARY));
2280 case PROP_STORAGE_TYPE_PRIMARY:
2281 g_value_set_enum (value,
2282 gtk_entry_get_icon_storage_type (entry,
2283 GTK_ENTRY_ICON_PRIMARY));
2286 case PROP_STORAGE_TYPE_SECONDARY:
2287 g_value_set_enum (value,
2288 gtk_entry_get_icon_storage_type (entry,
2289 GTK_ENTRY_ICON_SECONDARY));
2292 case PROP_ACTIVATABLE_PRIMARY:
2293 g_value_set_boolean (value,
2294 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2297 case PROP_ACTIVATABLE_SECONDARY:
2298 g_value_set_boolean (value,
2299 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2302 case PROP_SENSITIVE_PRIMARY:
2303 g_value_set_boolean (value,
2304 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2307 case PROP_SENSITIVE_SECONDARY:
2308 g_value_set_boolean (value,
2309 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2312 case PROP_TOOLTIP_TEXT_PRIMARY:
2313 g_value_take_string (value,
2314 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2317 case PROP_TOOLTIP_TEXT_SECONDARY:
2318 g_value_take_string (value,
2319 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2322 case PROP_TOOLTIP_MARKUP_PRIMARY:
2323 g_value_take_string (value,
2324 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2327 case PROP_TOOLTIP_MARKUP_SECONDARY:
2328 g_value_take_string (value,
2329 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2332 case PROP_EDITING_CANCELED:
2333 g_value_set_boolean (value,
2334 priv->editing_canceled);
2337 case PROP_COMPLETION:
2338 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2342 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2348 find_invisible_char (GtkWidget *widget)
2350 PangoLayout *layout;
2351 PangoAttrList *attr_list;
2353 gunichar invisible_chars [] = {
2355 0x25cf, /* BLACK CIRCLE */
2356 0x2022, /* BULLET */
2357 0x2731, /* HEAVY ASTERISK */
2358 0x273a /* SIXTEEN POINTED ASTERISK */
2361 gtk_widget_style_get (widget,
2362 "invisible-char", &invisible_chars[0],
2365 layout = gtk_widget_create_pango_layout (widget, NULL);
2367 attr_list = pango_attr_list_new ();
2368 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2370 pango_layout_set_attributes (layout, attr_list);
2371 pango_attr_list_unref (attr_list);
2373 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2375 gchar text[7] = { 0, };
2378 len = g_unichar_to_utf8 (invisible_chars[i], text);
2379 pango_layout_set_text (layout, text, len);
2381 count = pango_layout_get_unknown_glyphs_count (layout);
2385 g_object_unref (layout);
2386 return invisible_chars[i];
2390 g_object_unref (layout);
2396 gtk_entry_init (GtkEntry *entry)
2398 GtkStyleContext *context;
2399 GtkEntryPrivate *priv;
2401 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2406 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2407 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2409 priv->editable = TRUE;
2410 priv->visible = TRUE;
2411 priv->dnd_position = -1;
2412 priv->width_chars = -1;
2413 priv->is_cell_renderer = FALSE;
2414 priv->editing_canceled = FALSE;
2415 priv->has_frame = TRUE;
2416 priv->truncate_multiline = FALSE;
2417 priv->shadow_type = GTK_SHADOW_IN;
2419 priv->caps_lock_warning = TRUE;
2420 priv->caps_lock_warning_shown = FALSE;
2421 priv->progress_fraction = 0.0;
2422 priv->progress_pulse_fraction = 0.1;
2424 gtk_drag_dest_set (GTK_WIDGET (entry),
2425 GTK_DEST_DEFAULT_HIGHLIGHT,
2427 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2428 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2430 /* This object is completely private. No external entity can gain a reference
2431 * to it; so we create it here and destroy it in finalize().
2433 priv->im_context = gtk_im_multicontext_new ();
2435 g_signal_connect (priv->im_context, "commit",
2436 G_CALLBACK (gtk_entry_commit_cb), entry);
2437 g_signal_connect (priv->im_context, "preedit-changed",
2438 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2439 g_signal_connect (priv->im_context, "retrieve-surrounding",
2440 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2441 g_signal_connect (priv->im_context, "delete-surrounding",
2442 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2444 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2445 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2447 gtk_entry_update_cached_style_values (entry);
2451 get_icon_width (GtkEntry *entry,
2452 GtkEntryIconPosition icon_pos)
2454 GtkEntryPrivate *priv = entry->priv;
2455 EntryIconInfo *icon_info = priv->icons[icon_pos];
2457 GtkSettings *settings;
2458 gint menu_icon_width;
2460 if (!icon_info || icon_info->pixbuf == NULL)
2463 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2464 settings = gtk_settings_get_for_screen (screen);
2466 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2467 &menu_icon_width, NULL);
2469 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2473 get_icon_allocations (GtkEntry *entry,
2474 GtkAllocation *primary,
2475 GtkAllocation *secondary)
2478 GtkEntryPrivate *priv = entry->priv;
2479 gint x, y, width, height;
2481 get_text_area_size (entry, &x, &y, &width, &height);
2483 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2484 y += priv->focus_width;
2487 primary->height = height;
2488 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2489 if (primary->width > 0)
2490 primary->width += 2 * priv->icon_margin;
2493 secondary->height = height;
2494 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2495 if (secondary->width > 0)
2496 secondary->width += 2 * priv->icon_margin;
2498 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2500 primary->x = x + width - primary->width;
2506 secondary->x = x + width - secondary->width;
2512 begin_change (GtkEntry *entry)
2514 GtkEntryPrivate *priv = entry->priv;
2516 priv->change_count++;
2520 end_change (GtkEntry *entry)
2522 GtkEditable *editable = GTK_EDITABLE (entry);
2523 GtkEntryPrivate *priv = entry->priv;
2525 g_return_if_fail (priv->change_count > 0);
2527 priv->change_count--;
2529 if (priv->change_count == 0)
2531 if (priv->real_changed)
2533 g_signal_emit_by_name (editable, "changed");
2534 priv->real_changed = FALSE;
2540 emit_changed (GtkEntry *entry)
2542 GtkEditable *editable = GTK_EDITABLE (entry);
2543 GtkEntryPrivate *priv = entry->priv;
2545 if (priv->change_count == 0)
2546 g_signal_emit_by_name (editable, "changed");
2548 priv->real_changed = TRUE;
2552 gtk_entry_destroy (GtkWidget *widget)
2554 GtkEntry *entry = GTK_ENTRY (widget);
2555 GtkEntryPrivate *priv = entry->priv;
2557 priv->current_pos = priv->selection_bound = 0;
2558 _gtk_entry_reset_im_context (entry);
2559 gtk_entry_reset_layout (entry);
2561 if (priv->blink_timeout)
2563 g_source_remove (priv->blink_timeout);
2564 priv->blink_timeout = 0;
2567 if (priv->recompute_idle)
2569 g_source_remove (priv->recompute_idle);
2570 priv->recompute_idle = 0;
2573 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2577 gtk_entry_dispose (GObject *object)
2579 GtkEntry *entry = GTK_ENTRY (object);
2580 GtkEntryPrivate *priv = entry->priv;
2583 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2584 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2585 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2586 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2590 buffer_disconnect_signals (entry);
2591 g_object_unref (priv->buffer);
2592 priv->buffer = NULL;
2595 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2596 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2597 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2598 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2602 gtk_entry_finalize (GObject *object)
2604 GtkEntry *entry = GTK_ENTRY (object);
2605 GtkEntryPrivate *priv = entry->priv;
2606 EntryIconInfo *icon_info = NULL;
2609 for (i = 0; i < MAX_ICONS; i++)
2611 if ((icon_info = priv->icons[i]) != NULL)
2613 if (icon_info->target_list != NULL)
2615 gtk_target_list_unref (icon_info->target_list);
2616 icon_info->target_list = NULL;
2619 g_slice_free (EntryIconInfo, icon_info);
2620 priv->icons[i] = NULL;
2624 gtk_entry_set_completion (entry, NULL);
2626 if (priv->cached_layout)
2627 g_object_unref (priv->cached_layout);
2629 g_object_unref (priv->im_context);
2631 if (priv->blink_timeout)
2632 g_source_remove (priv->blink_timeout);
2634 if (priv->recompute_idle)
2635 g_source_remove (priv->recompute_idle);
2637 g_free (priv->placeholder_text);
2638 g_free (priv->im_module);
2640 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2644 gtk_entry_get_display_mode (GtkEntry *entry)
2646 GtkEntryPrivate *priv = entry->priv;
2649 return DISPLAY_NORMAL;
2651 if (priv->invisible_char == 0 && priv->invisible_char_set)
2652 return DISPLAY_BLANK;
2654 return DISPLAY_INVISIBLE;
2658 gtk_entry_get_display_text (GtkEntry *entry,
2662 GtkEntryPasswordHint *password_hint;
2663 GtkEntryPrivate *priv;
2664 gunichar invisible_char;
2675 text = gtk_entry_buffer_get_text (get_buffer (entry));
2676 length = gtk_entry_buffer_get_length (get_buffer (entry));
2680 if (start_pos > length)
2683 if (end_pos <= start_pos)
2684 return g_strdup ("");
2685 else if (priv->visible)
2687 start = g_utf8_offset_to_pointer (text, start_pos);
2688 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2689 return g_strndup (start, end - start);
2693 str = g_string_sized_new (length * 2);
2695 /* Figure out what our invisible char is and encode it */
2696 if (!priv->invisible_char)
2697 invisible_char = priv->invisible_char_set ? ' ' : '*';
2699 invisible_char = priv->invisible_char;
2700 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2703 * Add hidden characters for each character in the text
2704 * buffer. If there is a password hint, then keep that
2705 * character visible.
2708 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2709 for (i = start_pos; i < end_pos; ++i)
2711 if (password_hint && i == password_hint->position)
2713 start = g_utf8_offset_to_pointer (text, i);
2714 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2718 g_string_append_len (str, char_str, char_len);
2722 return g_string_free (str, FALSE);
2727 update_cursors (GtkWidget *widget)
2729 GtkEntry *entry = GTK_ENTRY (widget);
2730 GtkEntryPrivate *priv = entry->priv;
2731 EntryIconInfo *icon_info = NULL;
2732 GdkDisplay *display;
2736 for (i = 0; i < MAX_ICONS; i++)
2738 if ((icon_info = priv->icons[i]) != NULL)
2740 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2741 gdk_window_show_unraised (icon_info->window);
2743 /* The icon windows are not children of the visible entry window,
2744 * thus we can't just inherit the xterm cursor. Slight complication
2745 * here is that for the entry, insensitive => arrow cursor, but for
2746 * an icon in a sensitive entry, insensitive => xterm cursor.
2748 if (gtk_widget_is_sensitive (widget) &&
2749 (icon_info->insensitive ||
2750 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2752 display = gtk_widget_get_display (widget);
2753 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2754 gdk_window_set_cursor (icon_info->window, cursor);
2755 g_object_unref (cursor);
2759 gdk_window_set_cursor (icon_info->window, NULL);
2766 realize_icon_info (GtkWidget *widget,
2767 GtkEntryIconPosition icon_pos)
2769 GtkEntry *entry = GTK_ENTRY (widget);
2770 GtkEntryPrivate *priv = entry->priv;
2771 EntryIconInfo *icon_info = priv->icons[icon_pos];
2772 GdkWindowAttr attributes;
2773 gint attributes_mask;
2775 g_return_if_fail (icon_info != NULL);
2779 attributes.width = 1;
2780 attributes.height = 1;
2781 attributes.window_type = GDK_WINDOW_CHILD;
2782 attributes.wclass = GDK_INPUT_ONLY;
2783 attributes.event_mask = gtk_widget_get_events (widget);
2784 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2785 GDK_BUTTON_RELEASE_MASK |
2786 GDK_BUTTON1_MOTION_MASK |
2787 GDK_BUTTON3_MOTION_MASK |
2788 GDK_POINTER_MOTION_HINT_MASK |
2789 GDK_POINTER_MOTION_MASK |
2790 GDK_ENTER_NOTIFY_MASK |
2791 GDK_LEAVE_NOTIFY_MASK);
2792 attributes_mask = GDK_WA_X | GDK_WA_Y;
2794 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2797 gdk_window_set_user_data (icon_info->window, widget);
2799 gtk_widget_queue_resize (widget);
2802 static EntryIconInfo*
2803 construct_icon_info (GtkWidget *widget,
2804 GtkEntryIconPosition icon_pos)
2806 GtkEntry *entry = GTK_ENTRY (widget);
2807 GtkEntryPrivate *priv = entry->priv;
2808 EntryIconInfo *icon_info;
2810 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2812 icon_info = g_slice_new0 (EntryIconInfo);
2813 priv->icons[icon_pos] = icon_info;
2815 if (gtk_widget_get_realized (widget))
2816 realize_icon_info (widget, icon_pos);
2822 gtk_entry_map (GtkWidget *widget)
2824 GtkEntry *entry = GTK_ENTRY (widget);
2825 GtkEntryPrivate *priv = entry->priv;
2826 EntryIconInfo *icon_info = NULL;
2829 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2831 gdk_window_show (priv->text_area);
2833 for (i = 0; i < MAX_ICONS; i++)
2835 if ((icon_info = priv->icons[i]) != NULL)
2837 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2838 gdk_window_show (icon_info->window);
2842 update_cursors (widget);
2846 gtk_entry_unmap (GtkWidget *widget)
2848 GtkEntry *entry = GTK_ENTRY (widget);
2849 GtkEntryPrivate *priv = entry->priv;
2850 EntryIconInfo *icon_info = NULL;
2853 for (i = 0; i < MAX_ICONS; i++)
2855 if ((icon_info = priv->icons[i]) != NULL)
2857 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2858 gdk_window_hide (icon_info->window);
2862 gdk_window_hide (priv->text_area);
2864 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2868 gtk_entry_realize (GtkWidget *widget)
2871 GtkEntryPrivate *priv;
2872 EntryIconInfo *icon_info;
2874 GdkWindowAttr attributes;
2875 gint attributes_mask;
2876 gint frame_x, frame_y;
2879 gtk_widget_set_realized (widget, TRUE);
2880 window = gtk_widget_get_parent_window (widget);
2881 gtk_widget_set_window (widget, window);
2882 g_object_ref (window);
2884 entry = GTK_ENTRY (widget);
2887 attributes.window_type = GDK_WINDOW_CHILD;
2888 attributes.wclass = GDK_INPUT_ONLY;
2889 attributes.event_mask = gtk_widget_get_events (widget);
2890 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2891 GDK_BUTTON_RELEASE_MASK |
2892 GDK_BUTTON1_MOTION_MASK |
2893 GDK_BUTTON3_MOTION_MASK |
2894 GDK_POINTER_MOTION_HINT_MASK |
2895 GDK_POINTER_MOTION_MASK |
2896 GDK_ENTER_NOTIFY_MASK |
2897 GDK_LEAVE_NOTIFY_MASK);
2898 attributes_mask = GDK_WA_X | GDK_WA_Y;
2900 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2902 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2903 attributes.x += frame_x;
2904 attributes.y += frame_y;
2906 if (gtk_widget_is_sensitive (widget))
2908 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2909 attributes_mask |= GDK_WA_CURSOR;
2912 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2916 gdk_window_set_user_data (priv->text_area, entry);
2918 if (attributes_mask & GDK_WA_CURSOR)
2919 g_object_unref (attributes.cursor);
2921 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2923 gtk_entry_adjust_scroll (entry);
2924 gtk_entry_update_primary_selection (entry);
2927 /* If the icon positions are already setup, create their windows.
2928 * Otherwise if they don't exist yet, then construct_icon_info()
2929 * will create the windows once the widget is already realized.
2931 for (i = 0; i < MAX_ICONS; i++)
2933 if ((icon_info = priv->icons[i]) != NULL)
2935 if (icon_info->window == NULL)
2936 realize_icon_info (widget, i);
2942 gtk_entry_unrealize (GtkWidget *widget)
2944 GtkEntry *entry = GTK_ENTRY (widget);
2945 GtkEntryPrivate *priv = entry->priv;
2946 GtkClipboard *clipboard;
2947 EntryIconInfo *icon_info;
2950 gtk_entry_reset_layout (entry);
2952 gtk_im_context_set_client_window (priv->im_context, NULL);
2954 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2955 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2956 gtk_clipboard_clear (clipboard);
2958 if (priv->text_area)
2960 gdk_window_set_user_data (priv->text_area, NULL);
2961 gdk_window_destroy (priv->text_area);
2962 priv->text_area = NULL;
2965 if (priv->popup_menu)
2967 gtk_widget_destroy (priv->popup_menu);
2968 priv->popup_menu = NULL;
2971 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2973 for (i = 0; i < MAX_ICONS; i++)
2975 if ((icon_info = priv->icons[i]) != NULL)
2977 if (icon_info->window != NULL)
2979 gdk_window_destroy (icon_info->window);
2980 icon_info->window = NULL;
2987 _gtk_entry_get_borders (GtkEntry *entry,
2991 GtkEntryPrivate *priv = entry->priv;
2992 GtkWidget *widget = GTK_WIDGET (entry);
2994 if (priv->has_frame)
2996 GtkStyleContext *context;
2999 context = gtk_widget_get_style_context (widget);
3000 gtk_style_context_get_padding (context, 0, &padding);
3002 *xborder = padding.left;
3003 *yborder = padding.top;
3011 if (!priv->interior_focus)
3013 *xborder += priv->focus_width;
3014 *yborder += priv->focus_width;
3019 gtk_entry_get_preferred_width (GtkWidget *widget,
3023 GtkEntry *entry = GTK_ENTRY (widget);
3024 GtkEntryPrivate *priv = entry->priv;
3025 PangoFontMetrics *metrics;
3026 gint xborder, yborder;
3027 GtkBorder inner_border;
3028 PangoContext *context;
3029 GtkStyleContext *style_context;
3030 GtkStateFlags state;
3031 gint icon_widths = 0;
3035 context = gtk_widget_get_pango_context (widget);
3037 style_context = gtk_widget_get_style_context (widget);
3038 state = gtk_widget_get_state_flags (widget);
3040 metrics = pango_context_get_metrics (context,
3041 gtk_style_context_get_font (style_context, state),
3042 pango_context_get_language (context));
3044 _gtk_entry_get_borders (entry, &xborder, &yborder);
3045 _gtk_entry_effective_inner_border (entry, &inner_border);
3047 if (priv->width_chars < 0)
3048 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3051 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3052 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3053 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3055 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3058 for (i = 0; i < MAX_ICONS; i++)
3060 icon_width = get_icon_width (entry, i);
3062 icon_widths += icon_width + 2 * priv->icon_margin;
3065 if (icon_widths > width)
3066 width += icon_widths;
3068 pango_font_metrics_unref (metrics);
3075 gtk_entry_get_preferred_height (GtkWidget *widget,
3079 GtkEntry *entry = GTK_ENTRY (widget);
3080 GtkEntryPrivate *priv = entry->priv;
3081 PangoFontMetrics *metrics;
3082 gint xborder, yborder;
3083 GtkBorder inner_border;
3084 GtkStyleContext *style_context;
3085 GtkStateFlags state;
3086 PangoContext *context;
3089 context = gtk_widget_get_pango_context (widget);
3091 style_context = gtk_widget_get_style_context (widget);
3092 state = gtk_widget_get_state_flags (widget);
3094 metrics = pango_context_get_metrics (context,
3095 gtk_style_context_get_font (style_context, state),
3096 pango_context_get_language (context));
3098 priv->ascent = pango_font_metrics_get_ascent (metrics);
3099 priv->descent = pango_font_metrics_get_descent (metrics);
3101 _gtk_entry_get_borders (entry, &xborder, &yborder);
3102 _gtk_entry_effective_inner_border (entry, &inner_border);
3104 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3106 pango_font_metrics_unref (metrics);
3113 place_windows (GtkEntry *entry)
3115 GtkWidget *widget = GTK_WIDGET (entry);
3116 GtkEntryPrivate *priv = entry->priv;
3117 gint x, y, width, height;
3118 gint frame_x, frame_y;
3119 GtkAllocation primary;
3120 GtkAllocation secondary;
3121 EntryIconInfo *icon_info = NULL;
3123 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3124 get_text_area_size (entry, &x, &y, &width, &height);
3125 get_icon_allocations (entry, &primary, &secondary);
3127 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3128 y += priv->focus_width;
3130 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3131 x += secondary.width;
3134 width -= primary.width + secondary.width;
3138 primary.x += frame_x;
3139 primary.y += frame_y;
3140 secondary.x += frame_x;
3141 secondary.y += frame_y;
3143 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3144 gdk_window_move_resize (icon_info->window,
3145 primary.x, primary.y,
3146 primary.width, primary.height);
3148 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3149 gdk_window_move_resize (icon_info->window,
3150 secondary.x, secondary.y,
3151 secondary.width, secondary.height);
3153 gdk_window_move_resize (priv->text_area, x, y, width, height);
3157 gtk_entry_get_text_area_size (GtkEntry *entry,
3163 GtkEntryPrivate *priv = entry->priv;
3164 GtkWidget *widget = GTK_WIDGET (entry);
3165 GtkAllocation allocation;
3166 GtkRequisition requisition;
3168 gint xborder, yborder;
3170 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3171 gtk_widget_get_allocation (widget, &allocation);
3172 _gtk_entry_get_borders (entry, &xborder, &yborder);
3174 if (gtk_widget_get_realized (widget))
3175 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3177 frame_height = requisition.height;
3179 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3180 frame_height -= 2 * priv->focus_width;
3186 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3189 *width = allocation.width - xborder * 2;
3192 *height = requisition.height - yborder * 2;
3196 get_text_area_size (GtkEntry *entry,
3202 GtkEntryClass *class;
3204 g_return_if_fail (GTK_IS_ENTRY (entry));
3206 class = GTK_ENTRY_GET_CLASS (entry);
3208 if (class->get_text_area_size)
3209 class->get_text_area_size (entry, x, y, width, height);
3214 get_frame_size (GtkEntry *entry,
3215 gboolean relative_to_window,
3221 GtkEntryPrivate *priv = entry->priv;
3222 GtkAllocation allocation;
3223 GtkRequisition requisition;
3224 GtkWidget *widget = GTK_WIDGET (entry);
3226 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3227 gtk_widget_get_allocation (widget, &allocation);
3230 *x = relative_to_window ? allocation.x : 0;
3234 if (priv->is_cell_renderer)
3237 *y = (allocation.height - requisition.height) / 2;
3239 if (relative_to_window)
3244 *width = allocation.width;
3248 if (priv->is_cell_renderer)
3249 *height = allocation.height;
3251 *height = requisition.height;
3256 _gtk_entry_effective_inner_border (GtkEntry *entry,
3259 GtkBorder *tmp_border;
3261 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3265 *border = *tmp_border;
3269 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3273 *border = *tmp_border;
3274 gtk_border_free (tmp_border);
3278 *border = default_inner_border;
3282 gtk_entry_size_allocate (GtkWidget *widget,
3283 GtkAllocation *allocation)
3285 GtkEntry *entry = GTK_ENTRY (widget);
3287 gtk_widget_set_allocation (widget, allocation);
3289 if (gtk_widget_get_realized (widget))
3291 GtkEntryCompletion* completion;
3293 place_windows (entry);
3294 gtk_entry_recompute (entry);
3296 completion = gtk_entry_get_completion (entry);
3297 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3298 _gtk_entry_completion_resize_popup (completion);
3303 should_prelight (GtkEntry *entry,
3304 GtkEntryIconPosition icon_pos)
3306 GtkEntryPrivate *priv = entry->priv;
3307 EntryIconInfo *icon_info = priv->icons[icon_pos];
3313 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3316 if (icon_info->pressed)
3319 gtk_widget_style_get (GTK_WIDGET (entry),
3320 "icon-prelight", &prelight,
3327 draw_icon (GtkWidget *widget,
3329 GtkEntryIconPosition icon_pos)
3331 GtkEntry *entry = GTK_ENTRY (widget);
3332 GtkEntryPrivate *priv = entry->priv;
3333 EntryIconInfo *icon_info = priv->icons[icon_pos];
3335 gint x, y, width, height;
3336 GtkStyleContext *context;
3337 GtkIconSource *icon_source;
3338 GtkStateFlags state;
3343 gtk_entry_ensure_pixbuf (entry, icon_pos);
3345 if (icon_info->pixbuf == NULL)
3348 width = gdk_window_get_width (icon_info->window);
3349 height = gdk_window_get_height (icon_info->window);
3351 /* size_allocate hasn't been called yet. These are the default values.
3353 if (width == 1 || height == 1)
3356 pixbuf = icon_info->pixbuf;
3357 g_object_ref (pixbuf);
3359 if (gdk_pixbuf_get_height (pixbuf) > height)
3361 GdkPixbuf *temp_pixbuf;
3364 scale = height - 2 * priv->icon_margin;
3365 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3366 GDK_INTERP_BILINEAR);
3367 g_object_unref (pixbuf);
3368 pixbuf = temp_pixbuf;
3371 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3372 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3374 icon_source = gtk_icon_source_new ();
3375 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
3376 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
3379 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
3380 state |= GTK_STATE_FLAG_INSENSITIVE;
3381 else if (icon_info->prelight)
3382 state |= GTK_STATE_FLAG_PRELIGHT;
3384 context = gtk_widget_get_style_context (widget);
3385 gtk_style_context_save (context);
3386 gtk_style_context_set_state (context, state);
3387 pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
3388 gtk_style_context_restore (context);
3390 gtk_icon_source_free (icon_source);
3392 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3395 g_object_unref (pixbuf);
3400 gtk_entry_draw_frame (GtkWidget *widget,
3401 GtkStyleContext *context,
3404 GtkEntry *entry = GTK_ENTRY (widget);
3405 GtkEntryPrivate *priv = entry->priv;
3406 gint x = 0, y = 0, width, height;
3407 gint frame_x, frame_y;
3411 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3413 cairo_translate (cr, frame_x, frame_y);
3415 /* Fix a problem with some themes which assume that entry->text_area's
3416 * width equals widget->window's width
3417 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3418 if (GTK_IS_SPIN_BUTTON (widget))
3420 gint xborder, yborder;
3422 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3423 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3426 width += xborder * 2;
3429 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3431 x += priv->focus_width;
3432 y += priv->focus_width;
3433 width -= 2 * priv->focus_width;
3434 height -= 2 * priv->focus_width;
3437 gtk_render_background (context, cr,
3438 x, y, width, height);
3440 if (priv->has_frame)
3441 gtk_render_frame (context, cr,
3442 x, y, width, height);
3444 gtk_entry_draw_progress (widget, context, cr);
3446 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3448 x -= priv->focus_width;
3449 y -= priv->focus_width;
3450 width += 2 * priv->focus_width;
3451 height += 2 * priv->focus_width;
3453 gtk_render_focus (context, cr,
3454 0, 0, width, height);
3461 get_progress_area (GtkWidget *widget,
3467 GtkEntry *entry = GTK_ENTRY (widget);
3468 GtkEntryPrivate *private = entry->priv;
3469 GtkBorder *progress_border;
3471 get_text_area_size (entry, x, y, width, height);
3473 if (!private->interior_focus)
3475 *x -= private->focus_width;
3476 *y -= private->focus_width;
3477 *width += 2 * private->focus_width;
3478 *height += 2 * private->focus_width;
3481 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3483 if (progress_border)
3485 *x += progress_border->left;
3486 *y += progress_border->top;
3487 *width -= progress_border->left + progress_border->right;
3488 *height -= progress_border->top + progress_border->bottom;
3490 gtk_border_free (progress_border);
3493 if (private->progress_pulse_mode)
3495 gdouble value = private->progress_pulse_current;
3497 *x += (gint) floor(value * (*width));
3498 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3500 else if (private->progress_fraction > 0)
3502 gdouble value = private->progress_fraction;
3504 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3508 bar_width = floor(value * (*width) + 0.5);
3509 *x += *width - bar_width;
3514 *width = (gint) floor(value * (*width) + 0.5);
3525 gtk_entry_draw_progress (GtkWidget *widget,
3526 GtkStyleContext *context,
3529 gint x, y, width, height;
3531 get_progress_area (widget, &x, &y, &width, &height);
3533 if ((width <= 0) || (height <= 0))
3536 gtk_style_context_save (context);
3537 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3539 gtk_render_activity (context, cr,
3540 x, y, width, height);
3542 gtk_style_context_restore (context);
3546 gtk_entry_draw (GtkWidget *widget,
3549 GtkEntry *entry = GTK_ENTRY (widget);
3550 GtkStyleContext *context;
3551 GtkStateFlags state;
3552 GtkEntryPrivate *priv = entry->priv;
3555 context = gtk_widget_get_style_context (widget);
3556 state = gtk_widget_get_state_flags (widget);
3558 gtk_style_context_save (context);
3559 gtk_style_context_set_state (context, state);
3561 /* Draw entry_bg, shadow, progress and focus */
3562 gtk_entry_draw_frame (widget, context, cr);
3564 /* Draw text and cursor */
3567 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3569 if (priv->dnd_position != -1)
3570 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3572 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3574 /* When no text is being displayed at all, don't show the cursor */
3575 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3576 gtk_widget_has_focus (widget) &&
3577 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3578 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3583 for (i = 0; i < MAX_ICONS; i++)
3585 EntryIconInfo *icon_info = priv->icons[i];
3587 if (icon_info != NULL)
3591 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3593 draw_icon (widget, cr, i);
3599 gtk_style_context_restore (context);
3605 gtk_entry_enter_notify (GtkWidget *widget,
3606 GdkEventCrossing *event)
3608 GtkEntry *entry = GTK_ENTRY (widget);
3609 GtkEntryPrivate *priv = entry->priv;
3612 for (i = 0; i < MAX_ICONS; i++)
3614 EntryIconInfo *icon_info = priv->icons[i];
3616 if (icon_info != NULL && event->window == icon_info->window)
3618 if (should_prelight (entry, i))
3620 icon_info->prelight = TRUE;
3621 gtk_widget_queue_draw (widget);
3632 gtk_entry_leave_notify (GtkWidget *widget,
3633 GdkEventCrossing *event)
3635 GtkEntry *entry = GTK_ENTRY (widget);
3636 GtkEntryPrivate *priv = entry->priv;
3639 for (i = 0; i < MAX_ICONS; i++)
3641 EntryIconInfo *icon_info = priv->icons[i];
3643 if (icon_info != NULL && event->window == icon_info->window)
3645 /* a grab means that we may never see the button release */
3646 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3647 icon_info->pressed = FALSE;
3649 if (should_prelight (entry, i))
3651 icon_info->prelight = FALSE;
3652 gtk_widget_queue_draw (widget);
3663 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3667 gint start_char, end_char;
3669 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3671 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3672 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3673 const char *text = pango_layout_get_text (layout);
3674 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3675 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3676 gint real_n_ranges, i;
3678 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3684 for (i = 0; i < real_n_ranges; ++i)
3686 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3687 r[2 * i] = r[2 * i] / PANGO_SCALE;
3692 *n_ranges = real_n_ranges;
3704 in_selection (GtkEntry *entry,
3709 gint retval = FALSE;
3711 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3713 for (i = 0; i < n_ranges; ++i)
3715 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3727 gtk_entry_button_press (GtkWidget *widget,
3728 GdkEventButton *event)
3730 GtkEntry *entry = GTK_ENTRY (widget);
3731 GtkEditable *editable = GTK_EDITABLE (widget);
3732 GtkEntryPrivate *priv = entry->priv;
3733 EntryIconInfo *icon_info = NULL;
3735 gint sel_start, sel_end;
3738 for (i = 0; i < MAX_ICONS; i++)
3740 icon_info = priv->icons[i];
3742 if (!icon_info || icon_info->insensitive)
3745 if (event->window == icon_info->window)
3747 if (should_prelight (entry, i))
3749 icon_info->prelight = FALSE;
3750 gtk_widget_queue_draw (widget);
3753 priv->start_x = event->x;
3754 priv->start_y = event->y;
3755 icon_info->pressed = TRUE;
3757 if (!icon_info->nonactivatable)
3758 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3764 if (event->window != priv->text_area ||
3765 (priv->button && event->button != priv->button))
3768 gtk_entry_reset_blink_time (entry);
3770 priv->button = event->button;
3772 if (!gtk_widget_has_focus (widget))
3774 priv->in_click = TRUE;
3775 gtk_widget_grab_focus (widget);
3776 priv->in_click = FALSE;
3779 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3781 if (event->button == 1)
3783 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3785 priv->select_words = FALSE;
3786 priv->select_lines = FALSE;
3788 if (event->state & GDK_SHIFT_MASK)
3790 _gtk_entry_reset_im_context (entry);
3792 if (!have_selection) /* select from the current position to the clicked position */
3793 sel_start = sel_end = priv->current_pos;
3795 if (tmp_pos > sel_start && tmp_pos < sel_end)
3797 /* Truncate current selection, but keep it as big as possible */
3798 if (tmp_pos - sel_start > sel_end - tmp_pos)
3799 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3801 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3805 gboolean extend_to_left;
3808 /* Figure out what click selects and extend current selection */
3809 switch (event->type)
3811 case GDK_BUTTON_PRESS:
3812 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3815 case GDK_2BUTTON_PRESS:
3816 priv->select_words = TRUE;
3817 gtk_entry_select_word (entry);
3820 case GDK_3BUTTON_PRESS:
3821 priv->select_lines = TRUE;
3822 gtk_entry_select_line (entry);
3829 start = MIN (priv->current_pos, priv->selection_bound);
3830 start = MIN (sel_start, start);
3832 end = MAX (priv->current_pos, priv->selection_bound);
3833 end = MAX (sel_end, end);
3835 if (tmp_pos == sel_start || tmp_pos == sel_end)
3836 extend_to_left = (tmp_pos == start);
3838 extend_to_left = (end == sel_end);
3841 gtk_entry_set_positions (entry, start, end);
3843 gtk_entry_set_positions (entry, end, start);
3846 else /* no shift key */
3847 switch (event->type)
3849 case GDK_BUTTON_PRESS:
3850 if (in_selection (entry, event->x + priv->scroll_offset))
3852 /* Click inside the selection - we'll either start a drag, or
3853 * clear the selection
3855 priv->in_drag = TRUE;
3856 priv->drag_start_x = event->x + priv->scroll_offset;
3857 priv->drag_start_y = event->y;
3860 gtk_editable_set_position (editable, tmp_pos);
3863 case GDK_2BUTTON_PRESS:
3864 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3865 * receiving a GDK_2BUTTON_PRESS so we need to reset
3866 * priv->in_drag which may have been set above
3868 priv->in_drag = FALSE;
3869 priv->select_words = TRUE;
3870 gtk_entry_select_word (entry);
3873 case GDK_3BUTTON_PRESS:
3874 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3875 * receiving a GDK_3BUTTON_PRESS so we need to reset
3876 * priv->in_drag which may have been set above
3878 priv->in_drag = FALSE;
3879 priv->select_lines = TRUE;
3880 gtk_entry_select_line (entry);
3889 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3893 priv->insert_pos = tmp_pos;
3894 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3899 gtk_widget_error_bell (widget);
3902 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3904 gtk_entry_do_popup (entry, event);
3905 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3914 gtk_entry_button_release (GtkWidget *widget,
3915 GdkEventButton *event)
3917 GtkEntry *entry = GTK_ENTRY (widget);
3918 GtkEntryPrivate *priv = entry->priv;
3919 EntryIconInfo *icon_info = NULL;
3922 for (i = 0; i < MAX_ICONS; i++)
3924 icon_info = priv->icons[i];
3926 if (!icon_info || icon_info->insensitive)
3929 if (event->window == icon_info->window)
3931 icon_info->pressed = FALSE;
3933 if (should_prelight (entry, i) &&
3934 event->x >= 0 && event->y >= 0 &&
3935 event->x < gdk_window_get_width (icon_info->window) &&
3936 event->y < gdk_window_get_height (icon_info->window))
3938 icon_info->prelight = TRUE;
3939 gtk_widget_queue_draw (widget);
3942 if (!icon_info->nonactivatable)
3943 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3949 if (event->window != priv->text_area || priv->button != event->button)
3954 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3956 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3963 gtk_entry_update_primary_selection (entry);
3969 _gtk_entry_get_selected_text (GtkEntry *entry)
3971 GtkEditable *editable = GTK_EDITABLE (entry);
3972 gint start_text, end_text;
3975 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3976 text = gtk_editable_get_chars (editable, start_text, end_text);
3982 gtk_entry_motion_notify (GtkWidget *widget,
3983 GdkEventMotion *event)
3985 GtkEntry *entry = GTK_ENTRY (widget);
3986 GtkEntryPrivate *priv = entry->priv;
3987 EntryIconInfo *icon_info = NULL;
3991 for (i = 0; i < MAX_ICONS; i++)
3993 icon_info = priv->icons[i];
3995 if (!icon_info || icon_info->insensitive)
3998 if (event->window == icon_info->window)
4000 if (icon_info->pressed &&
4001 icon_info->target_list != NULL &&
4002 gtk_drag_check_threshold (widget,
4008 icon_info->in_drag = TRUE;
4009 icon_info->pressed = FALSE;
4010 gtk_drag_begin (widget,
4011 icon_info->target_list,
4021 if (priv->mouse_cursor_obscured)
4025 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4026 gdk_window_set_cursor (priv->text_area, cursor);
4027 g_object_unref (cursor);
4028 priv->mouse_cursor_obscured = FALSE;
4031 if (event->window != priv->text_area || priv->button != 1)
4034 if (priv->select_lines)
4037 gdk_event_request_motions (event);
4041 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4042 gtk_drag_check_threshold (widget,
4043 priv->drag_start_x, priv->drag_start_y,
4044 event->x + priv->scroll_offset, event->y))
4046 GdkDragContext *context;
4047 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4048 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4050 cairo_surface_t *surface;
4052 gtk_target_list_add_text_targets (target_list, 0);
4054 text = _gtk_entry_get_selected_text (entry);
4055 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4057 context = gtk_drag_begin (widget, target_list, actions,
4058 priv->button, (GdkEvent *)event);
4061 gtk_drag_set_icon_surface (context, surface);
4063 gtk_drag_set_icon_default (context);
4066 cairo_surface_destroy (surface);
4069 priv->in_drag = FALSE;
4072 gtk_target_list_unref (target_list);
4079 else if (event->y >= gdk_window_get_height (priv->text_area))
4080 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4082 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4084 if (priv->select_words)
4087 gint old_min, old_max;
4090 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4091 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4093 pos = priv->current_pos;
4094 bound = priv->selection_bound;
4096 old_min = MIN(priv->current_pos, priv->selection_bound);
4097 old_max = MAX(priv->current_pos, priv->selection_bound);
4104 else if (old_max < max)
4109 else if (pos == old_min)
4111 if (priv->current_pos != min)
4116 if (priv->current_pos != max)
4120 gtk_entry_set_positions (entry, pos, bound);
4123 gtk_entry_set_positions (entry, tmp_pos, -1);
4130 set_invisible_cursor (GdkWindow *window)
4132 GdkDisplay *display;
4135 display = gdk_window_get_display (window);
4136 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4138 gdk_window_set_cursor (window, cursor);
4140 g_object_unref (cursor);
4144 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4146 GtkEntryPrivate *priv = entry->priv;
4148 if (priv->mouse_cursor_obscured)
4151 set_invisible_cursor (priv->text_area);
4153 priv->mouse_cursor_obscured = TRUE;
4157 gtk_entry_key_press (GtkWidget *widget,
4160 GtkEntry *entry = GTK_ENTRY (widget);
4161 GtkEntryPrivate *priv = entry->priv;
4163 gtk_entry_reset_blink_time (entry);
4164 gtk_entry_pend_cursor_blink (entry);
4168 if (gtk_im_context_filter_keypress (priv->im_context, event))
4170 gtk_entry_obscure_mouse_cursor (entry);
4171 priv->need_im_reset = TRUE;
4176 if (event->keyval == GDK_KEY_Return ||
4177 event->keyval == GDK_KEY_KP_Enter ||
4178 event->keyval == GDK_KEY_ISO_Enter ||
4179 event->keyval == GDK_KEY_Escape)
4181 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4183 if (completion && completion->priv->completion_timeout)
4185 g_source_remove (completion->priv->completion_timeout);
4186 completion->priv->completion_timeout = 0;
4189 _gtk_entry_reset_im_context (entry);
4192 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4193 /* Activate key bindings
4197 if (!priv->editable && event->length)
4198 gtk_widget_error_bell (widget);
4204 gtk_entry_key_release (GtkWidget *widget,
4207 GtkEntry *entry = GTK_ENTRY (widget);
4208 GtkEntryPrivate *priv = entry->priv;
4212 if (gtk_im_context_filter_keypress (priv->im_context, event))
4214 priv->need_im_reset = TRUE;
4219 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4223 gtk_entry_focus_in (GtkWidget *widget,
4224 GdkEventFocus *event)
4226 GtkEntry *entry = GTK_ENTRY (widget);
4227 GtkEntryPrivate *priv = entry->priv;
4230 gtk_widget_queue_draw (widget);
4232 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4236 priv->need_im_reset = TRUE;
4237 gtk_im_context_focus_in (priv->im_context);
4238 keymap_state_changed (keymap, entry);
4239 g_signal_connect (keymap, "state-changed",
4240 G_CALLBACK (keymap_state_changed), entry);
4243 g_signal_connect (keymap, "direction-changed",
4244 G_CALLBACK (keymap_direction_changed), entry);
4246 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4247 priv->placeholder_text != NULL)
4249 gtk_entry_recompute (entry);
4253 gtk_entry_reset_blink_time (entry);
4254 gtk_entry_check_cursor_blink (entry);
4261 gtk_entry_focus_out (GtkWidget *widget,
4262 GdkEventFocus *event)
4264 GtkEntry *entry = GTK_ENTRY (widget);
4265 GtkEntryPrivate *priv = entry->priv;
4266 GtkEntryCompletion *completion;
4269 gtk_widget_queue_draw (widget);
4271 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4275 priv->need_im_reset = TRUE;
4276 gtk_im_context_focus_out (priv->im_context);
4277 remove_capslock_feedback (entry);
4280 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4281 priv->placeholder_text != NULL)
4283 gtk_entry_recompute (entry);
4287 gtk_entry_check_cursor_blink (entry);
4290 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4291 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4293 completion = gtk_entry_get_completion (entry);
4295 _gtk_entry_completion_popdown (completion);
4301 gtk_entry_grab_focus (GtkWidget *widget)
4303 GtkEntry *entry = GTK_ENTRY (widget);
4304 GtkEntryPrivate *priv = entry->priv;
4305 gboolean select_on_focus;
4307 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4309 if (priv->editable && !priv->in_click)
4311 g_object_get (gtk_widget_get_settings (widget),
4312 "gtk-entry-select-on-focus",
4316 if (select_on_focus)
4317 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4322 gtk_entry_direction_changed (GtkWidget *widget,
4323 GtkTextDirection previous_dir)
4325 GtkEntry *entry = GTK_ENTRY (widget);
4327 gtk_entry_recompute (entry);
4329 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4333 gtk_entry_state_flags_changed (GtkWidget *widget,
4334 GtkStateFlags previous_state)
4336 GtkEntry *entry = GTK_ENTRY (widget);
4337 GtkEntryPrivate *priv = entry->priv;
4340 if (gtk_widget_get_realized (widget))
4342 if (gtk_widget_is_sensitive (widget))
4343 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4347 gdk_window_set_cursor (priv->text_area, cursor);
4350 g_object_unref (cursor);
4352 priv->mouse_cursor_obscured = FALSE;
4354 update_cursors (widget);
4357 if (!gtk_widget_is_sensitive (widget))
4359 /* Clear any selection */
4360 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4363 gtk_entry_update_cached_style_values (entry);
4367 gtk_entry_screen_changed (GtkWidget *widget,
4368 GdkScreen *old_screen)
4370 gtk_entry_recompute (GTK_ENTRY (widget));
4373 /* GtkEditable method implementations
4376 gtk_entry_insert_text (GtkEditable *editable,
4377 const gchar *new_text,
4378 gint new_text_length,
4381 g_object_ref (editable);
4384 * The incoming text may a password or other secret. We make sure
4385 * not to copy it into temporary buffers.
4388 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4390 g_object_unref (editable);
4394 gtk_entry_delete_text (GtkEditable *editable,
4398 g_object_ref (editable);
4400 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4402 g_object_unref (editable);
4406 gtk_entry_get_chars (GtkEditable *editable,
4410 GtkEntry *entry = GTK_ENTRY (editable);
4413 gint start_index, end_index;
4415 text = gtk_entry_buffer_get_text (get_buffer (entry));
4416 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4419 end_pos = text_length;
4421 start_pos = MIN (text_length, start_pos);
4422 end_pos = MIN (text_length, end_pos);
4424 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4425 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4427 return g_strndup (text + start_index, end_index - start_index);
4431 gtk_entry_real_set_position (GtkEditable *editable,
4434 GtkEntry *entry = GTK_ENTRY (editable);
4435 GtkEntryPrivate *priv = entry->priv;
4439 length = gtk_entry_buffer_get_length (get_buffer (entry));
4440 if (position < 0 || position > length)
4443 if (position != priv->current_pos ||
4444 position != priv->selection_bound)
4446 _gtk_entry_reset_im_context (entry);
4447 gtk_entry_set_positions (entry, position, position);
4452 gtk_entry_get_position (GtkEditable *editable)
4454 GtkEntry *entry = GTK_ENTRY (editable);
4455 GtkEntryPrivate *priv = entry->priv;
4457 return priv->current_pos;
4461 gtk_entry_set_selection_bounds (GtkEditable *editable,
4465 GtkEntry *entry = GTK_ENTRY (editable);
4468 length = gtk_entry_buffer_get_length (get_buffer (entry));
4474 _gtk_entry_reset_im_context (entry);
4476 gtk_entry_set_positions (entry,
4478 MIN (start, length));
4480 gtk_entry_update_primary_selection (entry);
4484 gtk_entry_get_selection_bounds (GtkEditable *editable,
4488 GtkEntry *entry = GTK_ENTRY (editable);
4489 GtkEntryPrivate *priv = entry->priv;
4491 *start = priv->selection_bound;
4492 *end = priv->current_pos;
4494 return (priv->selection_bound != priv->current_pos);
4498 icon_theme_changed (GtkEntry *entry)
4500 GtkEntryPrivate *priv = entry->priv;
4503 for (i = 0; i < MAX_ICONS; i++)
4505 EntryIconInfo *icon_info = priv->icons[i];
4506 if (icon_info != NULL)
4508 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4509 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4510 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4511 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4512 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4513 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4517 gtk_widget_queue_draw (GTK_WIDGET (entry));
4521 icon_margin_changed (GtkEntry *entry)
4523 GtkEntryPrivate *priv = entry->priv;
4526 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4528 priv->icon_margin = border.left;
4532 gtk_entry_update_cached_style_values (GtkEntry *entry)
4534 GtkEntryPrivate *priv = entry->priv;
4536 gboolean interior_focus;
4538 gtk_widget_style_get (GTK_WIDGET (entry),
4539 "focus-line-width", &focus_width,
4540 "interior-focus", &interior_focus,
4542 priv->focus_width = focus_width;
4543 priv->interior_focus = interior_focus;
4545 if (!priv->invisible_char_set)
4547 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4549 if (priv->invisible_char != ch)
4551 priv->invisible_char = ch;
4552 g_object_notify (G_OBJECT (entry), "invisible-char");
4558 gtk_entry_style_updated (GtkWidget *widget)
4560 GtkEntry *entry = GTK_ENTRY (widget);
4562 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4564 gtk_entry_update_cached_style_values (entry);
4566 gtk_entry_recompute (entry);
4568 icon_theme_changed (entry);
4569 icon_margin_changed (entry);
4572 /* GtkCellEditable method implementations
4575 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4577 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4578 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4582 gtk_cell_editable_key_press_event (GtkEntry *entry,
4583 GdkEventKey *key_event,
4586 GtkEntryPrivate *priv = entry->priv;
4588 if (key_event->keyval == GDK_KEY_Escape)
4590 priv->editing_canceled = TRUE;
4591 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4592 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4597 /* override focus */
4598 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4600 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4601 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4610 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4613 GtkEntry *entry = GTK_ENTRY (cell_editable);
4614 GtkEntryPrivate *priv = entry->priv;
4616 priv->is_cell_renderer = TRUE;
4618 g_signal_connect (cell_editable, "activate",
4619 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4620 g_signal_connect (cell_editable, "key-press-event",
4621 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4625 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4627 if (password_hint->source_id)
4628 g_source_remove (password_hint->source_id);
4630 g_slice_free (GtkEntryPasswordHint, password_hint);
4635 gtk_entry_remove_password_hint (gpointer data)
4637 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4638 password_hint->position = -1;
4640 /* Force the string to be redrawn, but now without a visible character */
4641 gtk_entry_recompute (GTK_ENTRY (data));
4645 /* Default signal handlers
4648 gtk_entry_real_insert_text (GtkEditable *editable,
4649 const gchar *new_text,
4650 gint new_text_length,
4656 n_chars = g_utf8_strlen (new_text, new_text_length);
4659 * The actual insertion into the buffer. This will end up firing the
4660 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4661 * buffer_notify_text(), buffer_notify_length()
4663 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4665 if (n_inserted != n_chars)
4666 gtk_widget_error_bell (GTK_WIDGET (editable));
4668 *position += n_inserted;
4672 gtk_entry_real_delete_text (GtkEditable *editable,
4677 * The actual deletion from the buffer. This will end up firing the
4678 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4679 * buffer_notify_text(), buffer_notify_length()
4682 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4685 /* GtkEntryBuffer signal handlers
4688 buffer_inserted_text (GtkEntryBuffer *buffer,
4694 GtkEntryPrivate *priv = entry->priv;
4695 guint password_hint_timeout;
4697 if (priv->current_pos > position)
4698 priv->current_pos += n_chars;
4700 if (priv->selection_bound > position)
4701 priv->selection_bound += n_chars;
4703 /* Calculate the password hint if it needs to be displayed. */
4704 if (n_chars == 1 && !priv->visible)
4706 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4707 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4710 if (password_hint_timeout > 0)
4712 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4713 quark_password_hint);
4716 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4717 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4718 (GDestroyNotify)gtk_entry_password_hint_free);
4721 password_hint->position = position;
4722 if (password_hint->source_id)
4723 g_source_remove (password_hint->source_id);
4724 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4725 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4731 buffer_deleted_text (GtkEntryBuffer *buffer,
4736 GtkEntryPrivate *priv = entry->priv;
4737 guint end_pos = position + n_chars;
4738 gint selection_bound;
4741 current_pos = priv->current_pos;
4742 if (current_pos > position)
4743 current_pos -= MIN (current_pos, end_pos) - position;
4745 selection_bound = priv->selection_bound;
4746 if (selection_bound > position)
4747 selection_bound -= MIN (selection_bound, end_pos) - position;
4749 gtk_entry_set_positions (entry, current_pos, selection_bound);
4751 /* We might have deleted the selection */
4752 gtk_entry_update_primary_selection (entry);
4754 /* Disable the password hint if one exists. */
4757 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4758 quark_password_hint);
4761 if (password_hint->source_id)
4762 g_source_remove (password_hint->source_id);
4763 password_hint->source_id = 0;
4764 password_hint->position = -1;
4770 buffer_notify_text (GtkEntryBuffer *buffer,
4774 gtk_entry_recompute (entry);
4775 emit_changed (entry);
4776 g_object_notify (G_OBJECT (entry), "text");
4780 buffer_notify_length (GtkEntryBuffer *buffer,
4784 g_object_notify (G_OBJECT (entry), "text-length");
4788 buffer_notify_max_length (GtkEntryBuffer *buffer,
4792 g_object_notify (G_OBJECT (entry), "max-length");
4796 buffer_connect_signals (GtkEntry *entry)
4798 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4799 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4800 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4801 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4802 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4806 buffer_disconnect_signals (GtkEntry *entry)
4808 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4809 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4810 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4811 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4812 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4815 /* Compute the X position for an offset that corresponds to the "more important
4816 * cursor position for that offset. We use this when trying to guess to which
4817 * end of the selection we should go to when the user hits the left or
4821 get_better_cursor_x (GtkEntry *entry,
4824 GtkEntryPrivate *priv = entry->priv;
4825 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4826 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4827 gboolean split_cursor;
4829 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4830 const gchar *text = pango_layout_get_text (layout);
4831 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4833 PangoRectangle strong_pos, weak_pos;
4835 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4836 "gtk-split-cursor", &split_cursor,
4839 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4842 return strong_pos.x / PANGO_SCALE;
4844 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4848 gtk_entry_move_cursor (GtkEntry *entry,
4849 GtkMovementStep step,
4851 gboolean extend_selection)
4853 GtkEntryPrivate *priv = entry->priv;
4854 gint new_pos = priv->current_pos;
4856 _gtk_entry_reset_im_context (entry);
4858 if (priv->current_pos != priv->selection_bound && !extend_selection)
4860 /* If we have a current selection and aren't extending it, move to the
4861 * start/or end of the selection as appropriate
4865 case GTK_MOVEMENT_VISUAL_POSITIONS:
4867 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4868 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4871 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4873 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4876 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4877 case GTK_MOVEMENT_WORDS:
4879 new_pos = MIN (priv->current_pos, priv->selection_bound);
4881 new_pos = MAX (priv->current_pos, priv->selection_bound);
4883 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4884 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4885 case GTK_MOVEMENT_BUFFER_ENDS:
4886 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4888 case GTK_MOVEMENT_DISPLAY_LINES:
4889 case GTK_MOVEMENT_PARAGRAPHS:
4890 case GTK_MOVEMENT_PAGES:
4891 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4899 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4900 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4902 case GTK_MOVEMENT_VISUAL_POSITIONS:
4903 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4904 if (priv->current_pos == new_pos)
4906 if (!extend_selection)
4908 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4910 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4912 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4915 gtk_widget_child_focus (toplevel,
4917 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4922 gtk_widget_error_bell (GTK_WIDGET (entry));
4926 case GTK_MOVEMENT_WORDS:
4929 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4934 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4937 if (priv->current_pos == new_pos)
4938 gtk_widget_error_bell (GTK_WIDGET (entry));
4940 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4941 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4942 case GTK_MOVEMENT_BUFFER_ENDS:
4943 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4944 if (priv->current_pos == new_pos)
4945 gtk_widget_error_bell (GTK_WIDGET (entry));
4947 case GTK_MOVEMENT_DISPLAY_LINES:
4948 case GTK_MOVEMENT_PARAGRAPHS:
4949 case GTK_MOVEMENT_PAGES:
4950 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4955 if (extend_selection)
4956 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4958 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4960 gtk_entry_pend_cursor_blink (entry);
4964 gtk_entry_insert_at_cursor (GtkEntry *entry,
4967 GtkEntryPrivate *priv = entry->priv;
4968 GtkEditable *editable = GTK_EDITABLE (entry);
4969 gint pos = priv->current_pos;
4973 _gtk_entry_reset_im_context (entry);
4975 gtk_editable_insert_text (editable, str, -1, &pos);
4976 gtk_editable_set_position (editable, pos);
4981 gtk_entry_delete_from_cursor (GtkEntry *entry,
4985 GtkEntryPrivate *priv = entry->priv;
4986 GtkEditable *editable = GTK_EDITABLE (entry);
4987 gint start_pos = priv->current_pos;
4988 gint end_pos = priv->current_pos;
4989 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4991 _gtk_entry_reset_im_context (entry);
4993 if (!priv->editable)
4995 gtk_widget_error_bell (GTK_WIDGET (entry));
4999 if (priv->selection_bound != priv->current_pos)
5001 gtk_editable_delete_selection (editable);
5007 case GTK_DELETE_CHARS:
5008 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5009 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5011 case GTK_DELETE_WORDS:
5014 /* Move to end of current word, or if not on a word, end of previous word */
5015 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5016 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5020 /* Move to beginning of current word, or if not on a word, begining of next word */
5021 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5022 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5026 case GTK_DELETE_WORD_ENDS:
5029 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5034 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5037 gtk_editable_delete_text (editable, start_pos, end_pos);
5039 case GTK_DELETE_DISPLAY_LINE_ENDS:
5040 case GTK_DELETE_PARAGRAPH_ENDS:
5042 gtk_editable_delete_text (editable, 0, priv->current_pos);
5044 gtk_editable_delete_text (editable, priv->current_pos, -1);
5046 case GTK_DELETE_DISPLAY_LINES:
5047 case GTK_DELETE_PARAGRAPHS:
5048 gtk_editable_delete_text (editable, 0, -1);
5050 case GTK_DELETE_WHITESPACE:
5051 gtk_entry_delete_whitespace (entry);
5055 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5056 gtk_widget_error_bell (GTK_WIDGET (entry));
5058 gtk_entry_pend_cursor_blink (entry);
5062 gtk_entry_backspace (GtkEntry *entry)
5064 GtkEntryPrivate *priv = entry->priv;
5065 GtkEditable *editable = GTK_EDITABLE (entry);
5068 _gtk_entry_reset_im_context (entry);
5070 if (!priv->editable)
5072 gtk_widget_error_bell (GTK_WIDGET (entry));
5076 if (priv->selection_bound != priv->current_pos)
5078 gtk_editable_delete_selection (editable);
5082 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5084 if (prev_pos < priv->current_pos)
5086 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5087 PangoLogAttr *log_attrs;
5090 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5092 /* Deleting parts of characters */
5093 if (log_attrs[priv->current_pos].backspace_deletes_character)
5095 gchar *cluster_text;
5096 gchar *normalized_text;
5099 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5101 normalized_text = g_utf8_normalize (cluster_text,
5102 strlen (cluster_text),
5104 len = g_utf8_strlen (normalized_text, -1);
5106 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5109 gint pos = priv->current_pos;
5111 gtk_editable_insert_text (editable, normalized_text,
5112 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5114 gtk_editable_set_position (editable, pos);
5117 g_free (normalized_text);
5118 g_free (cluster_text);
5122 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5129 gtk_widget_error_bell (GTK_WIDGET (entry));
5132 gtk_entry_pend_cursor_blink (entry);
5136 gtk_entry_copy_clipboard (GtkEntry *entry)
5138 GtkEntryPrivate *priv = entry->priv;
5139 GtkEditable *editable = GTK_EDITABLE (entry);
5143 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5147 gtk_widget_error_bell (GTK_WIDGET (entry));
5151 str = gtk_entry_get_display_text (entry, start, end);
5152 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5153 GDK_SELECTION_CLIPBOARD),
5160 gtk_entry_cut_clipboard (GtkEntry *entry)
5162 GtkEntryPrivate *priv = entry->priv;
5163 GtkEditable *editable = GTK_EDITABLE (entry);
5168 gtk_widget_error_bell (GTK_WIDGET (entry));
5172 gtk_entry_copy_clipboard (entry);
5176 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5177 gtk_editable_delete_text (editable, start, end);
5181 gtk_widget_error_bell (GTK_WIDGET (entry));
5186 gtk_entry_paste_clipboard (GtkEntry *entry)
5188 GtkEntryPrivate *priv = entry->priv;
5191 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5193 gtk_widget_error_bell (GTK_WIDGET (entry));
5197 gtk_entry_delete_cb (GtkEntry *entry)
5199 GtkEntryPrivate *priv = entry->priv;
5200 GtkEditable *editable = GTK_EDITABLE (entry);
5205 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5206 gtk_editable_delete_text (editable, start, end);
5211 gtk_entry_toggle_overwrite (GtkEntry *entry)
5213 GtkEntryPrivate *priv = entry->priv;
5215 priv->overwrite_mode = !priv->overwrite_mode;
5216 gtk_entry_pend_cursor_blink (entry);
5217 gtk_widget_queue_draw (GTK_WIDGET (entry));
5221 gtk_entry_select_all (GtkEntry *entry)
5223 gtk_entry_select_line (entry);
5227 gtk_entry_real_activate (GtkEntry *entry)
5229 GtkEntryPrivate *priv = entry->priv;
5231 GtkWidget *default_widget, *focus_widget;
5232 GtkWidget *toplevel;
5235 widget = GTK_WIDGET (entry);
5237 if (priv->activates_default)
5239 toplevel = gtk_widget_get_toplevel (widget);
5240 if (GTK_IS_WINDOW (toplevel))
5242 window = GTK_WINDOW (toplevel);
5246 default_widget = gtk_window_get_default_widget (window);
5247 focus_widget = gtk_window_get_focus (window);
5248 if (widget != default_widget &&
5249 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5250 gtk_window_activate_default (window);
5257 keymap_direction_changed (GdkKeymap *keymap,
5260 gtk_entry_recompute (entry);
5263 /* IM Context Callbacks
5267 gtk_entry_commit_cb (GtkIMContext *context,
5271 GtkEntryPrivate *priv = entry->priv;
5274 gtk_entry_enter_text (entry, str);
5278 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5281 GtkEntryPrivate *priv = entry->priv;
5285 gchar *preedit_string;
5288 gtk_im_context_get_preedit_string (priv->im_context,
5289 &preedit_string, NULL,
5291 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5292 priv->preedit_length = strlen (preedit_string);
5293 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5294 priv->preedit_cursor = cursor_pos;
5295 g_free (preedit_string);
5297 gtk_entry_recompute (entry);
5302 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5305 GtkEntryPrivate *priv = entry->priv;
5308 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5309 text = gtk_entry_get_display_text (entry, 0, -1);
5310 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5311 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5318 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5323 GtkEntryPrivate *priv = entry->priv;
5326 gtk_editable_delete_text (GTK_EDITABLE (entry),
5327 priv->current_pos + offset,
5328 priv->current_pos + offset + n_chars);
5333 /* Internal functions
5336 /* Used for im_commit_cb and inserting Unicode chars */
5338 gtk_entry_enter_text (GtkEntry *entry,
5341 GtkEntryPrivate *priv = entry->priv;
5342 GtkEditable *editable = GTK_EDITABLE (entry);
5344 gboolean old_need_im_reset;
5346 old_need_im_reset = priv->need_im_reset;
5347 priv->need_im_reset = FALSE;
5349 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5350 gtk_editable_delete_selection (editable);
5353 if (priv->overwrite_mode)
5354 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5357 tmp_pos = priv->current_pos;
5358 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5359 gtk_editable_set_position (editable, tmp_pos);
5361 priv->need_im_reset = old_need_im_reset;
5364 /* All changes to priv->current_pos and priv->selection_bound
5365 * should go through this function.
5368 gtk_entry_set_positions (GtkEntry *entry,
5370 gint selection_bound)
5372 GtkEntryPrivate *priv = entry->priv;
5373 gboolean changed = FALSE;
5375 g_object_freeze_notify (G_OBJECT (entry));
5377 if (current_pos != -1 &&
5378 priv->current_pos != current_pos)
5380 priv->current_pos = current_pos;
5383 g_object_notify (G_OBJECT (entry), "cursor-position");
5386 if (selection_bound != -1 &&
5387 priv->selection_bound != selection_bound)
5389 priv->selection_bound = selection_bound;
5392 g_object_notify (G_OBJECT (entry), "selection-bound");
5395 g_object_thaw_notify (G_OBJECT (entry));
5399 gtk_entry_move_adjustments (entry);
5400 gtk_entry_recompute (entry);
5405 gtk_entry_reset_layout (GtkEntry *entry)
5407 GtkEntryPrivate *priv = entry->priv;
5409 if (priv->cached_layout)
5411 g_object_unref (priv->cached_layout);
5412 priv->cached_layout = NULL;
5417 update_im_cursor_location (GtkEntry *entry)
5419 GtkEntryPrivate *priv = entry->priv;
5422 gint strong_xoffset;
5423 gint area_width, area_height;
5425 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5426 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5428 strong_xoffset = strong_x - priv->scroll_offset;
5429 if (strong_xoffset < 0)
5433 else if (strong_xoffset > area_width)
5435 strong_xoffset = area_width;
5437 area.x = strong_xoffset;
5440 area.height = area_height;
5442 gtk_im_context_set_cursor_location (priv->im_context, &area);
5446 recompute_idle_func (gpointer data)
5448 GtkEntry *entry = GTK_ENTRY (data);
5449 GtkEntryPrivate *priv = entry->priv;
5451 priv->recompute_idle = 0;
5453 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5455 gtk_entry_adjust_scroll (entry);
5456 gtk_widget_queue_draw (GTK_WIDGET (entry));
5458 update_im_cursor_location (entry);
5465 gtk_entry_recompute (GtkEntry *entry)
5467 GtkEntryPrivate *priv = entry->priv;
5469 gtk_entry_reset_layout (entry);
5470 gtk_entry_check_cursor_blink (entry);
5472 if (!priv->recompute_idle)
5474 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5475 recompute_idle_func, entry, NULL);
5480 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5483 GtkWidget *widget = GTK_WIDGET (entry);
5484 GtkStyleContext *context;
5485 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5487 context = gtk_widget_get_style_context (widget);
5488 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5490 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5491 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5492 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5495 static inline gboolean
5496 show_placeholder_text (GtkEntry *entry)
5498 GtkEntryPrivate *priv = entry->priv;
5500 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5501 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5502 priv->placeholder_text != NULL)
5508 static PangoLayout *
5509 gtk_entry_create_layout (GtkEntry *entry,
5510 gboolean include_preedit)
5512 GtkEntryPrivate *priv = entry->priv;
5513 GtkWidget *widget = GTK_WIDGET (entry);
5514 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5515 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5516 gboolean placeholder_layout = show_placeholder_text (entry);
5518 gchar *preedit_string = NULL;
5519 gint preedit_length = 0;
5520 PangoAttrList *preedit_attrs = NULL;
5525 pango_layout_set_single_paragraph_mode (layout, TRUE);
5527 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5528 n_bytes = strlen (display);
5530 if (!placeholder_layout && include_preedit)
5532 gtk_im_context_get_preedit_string (priv->im_context,
5533 &preedit_string, &preedit_attrs, NULL);
5534 preedit_length = priv->preedit_length;
5536 else if (placeholder_layout)
5539 PangoAttribute *attr;
5541 gtk_entry_get_placeholder_text_color (entry, &color);
5542 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5543 attr->start_index = 0;
5544 attr->end_index = G_MAXINT;
5545 pango_attr_list_insert (tmp_attrs, attr);
5550 GString *tmp_string = g_string_new (display);
5551 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5553 g_string_insert (tmp_string, cursor_index, preedit_string);
5555 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5557 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5558 cursor_index, preedit_length);
5560 g_string_free (tmp_string, TRUE);
5564 PangoDirection pango_dir;
5566 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5567 pango_dir = pango_find_base_dir (display, n_bytes);
5569 pango_dir = PANGO_DIRECTION_NEUTRAL;
5571 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5573 if (gtk_widget_has_focus (widget))
5575 GdkDisplay *display = gtk_widget_get_display (widget);
5576 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5577 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5578 pango_dir = PANGO_DIRECTION_RTL;
5580 pango_dir = PANGO_DIRECTION_LTR;
5584 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5585 pango_dir = PANGO_DIRECTION_RTL;
5587 pango_dir = PANGO_DIRECTION_LTR;
5591 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5594 priv->resolved_dir = pango_dir;
5596 pango_layout_set_text (layout, display, n_bytes);
5599 pango_layout_set_attributes (layout, tmp_attrs);
5601 g_free (preedit_string);
5605 pango_attr_list_unref (preedit_attrs);
5607 pango_attr_list_unref (tmp_attrs);
5612 static PangoLayout *
5613 gtk_entry_ensure_layout (GtkEntry *entry,
5614 gboolean include_preedit)
5616 GtkEntryPrivate *priv = entry->priv;
5618 if (priv->preedit_length > 0 &&
5619 !include_preedit != !priv->cache_includes_preedit)
5620 gtk_entry_reset_layout (entry);
5622 if (!priv->cached_layout)
5624 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5625 priv->cache_includes_preedit = include_preedit;
5628 return priv->cached_layout;
5632 get_layout_position (GtkEntry *entry,
5636 GtkEntryPrivate *priv = entry->priv;
5637 PangoLayout *layout;
5638 PangoRectangle logical_rect;
5639 gint area_width, area_height;
5640 GtkBorder inner_border;
5642 PangoLayoutLine *line;
5644 layout = gtk_entry_ensure_layout (entry, TRUE);
5646 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5647 _gtk_entry_effective_inner_border (entry, &inner_border);
5649 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5651 line = pango_layout_get_lines_readonly (layout)->data;
5652 pango_layout_line_get_extents (line, NULL, &logical_rect);
5654 /* Align primarily for locale's ascent/descent */
5655 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5656 priv->ascent + logical_rect.y);
5658 /* Now see if we need to adjust to fit in actual drawn string */
5659 if (logical_rect.height > area_height)
5660 y_pos = (area_height - logical_rect.height) / 2;
5663 else if (y_pos + logical_rect.height > area_height)
5664 y_pos = area_height - logical_rect.height;
5666 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5669 *x = inner_border.left - priv->scroll_offset;
5676 draw_text_with_color (GtkEntry *entry,
5678 GdkRGBA *default_color)
5680 GtkEntryPrivate *priv = entry->priv;
5681 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5684 gint start_pos, end_pos;
5686 widget = GTK_WIDGET (entry);
5690 get_layout_position (entry, &x, &y);
5692 cairo_move_to (cr, x, y);
5693 gdk_cairo_set_source_rgba (cr, default_color);
5694 pango_cairo_show_layout (cr, layout);
5696 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5700 PangoRectangle logical_rect;
5701 GdkRGBA selection_color, text_color;
5702 GtkBorder inner_border;
5703 GtkStyleContext *context;
5704 GtkStateFlags state;
5706 context = gtk_widget_get_style_context (widget);
5707 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5708 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5710 state = GTK_STATE_FLAG_SELECTED;
5712 if (gtk_widget_has_focus (widget))
5713 state |= GTK_STATE_FLAG_FOCUSED;
5715 gtk_style_context_get_background_color (context, state, &selection_color);
5716 gtk_style_context_get_color (context, state, &text_color);
5718 _gtk_entry_effective_inner_border (entry, &inner_border);
5720 for (i = 0; i < n_ranges; ++i)
5721 cairo_rectangle (cr,
5722 inner_border.left - priv->scroll_offset + ranges[2 * i],
5725 logical_rect.height);
5729 gdk_cairo_set_source_rgba (cr, &selection_color);
5732 cairo_move_to (cr, x, y);
5733 gdk_cairo_set_source_rgba (cr, &text_color);
5734 pango_cairo_show_layout (cr, layout);
5742 gtk_entry_draw_text (GtkEntry *entry,
5745 GtkEntryPrivate *priv = entry->priv;
5746 GtkWidget *widget = GTK_WIDGET (entry);
5747 GtkStateFlags state = 0;
5748 GdkRGBA text_color, bar_text_color;
5749 GtkStyleContext *context;
5751 gint progress_x, progress_y, progress_width, progress_height;
5752 gint clip_width, clip_height;
5754 /* Nothing to display at all */
5755 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5758 state = gtk_widget_get_state_flags (widget);
5759 context = gtk_widget_get_style_context (widget);
5761 gtk_style_context_get_color (context, state, &text_color);
5763 /* Get foreground color for progressbars */
5764 gtk_style_context_save (context);
5765 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5766 gtk_style_context_get_color (context, state, &bar_text_color);
5767 gtk_style_context_restore (context);
5769 get_progress_area (widget,
5770 &progress_x, &progress_y,
5771 &progress_width, &progress_height);
5775 clip_width = gdk_window_get_width (priv->text_area);
5776 clip_height = gdk_window_get_height (priv->text_area);
5777 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5780 /* If the color is the same, or the progress area has a zero
5781 * size, then we only need to draw once. */
5782 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5783 ((progress_width == 0) || (progress_height == 0)))
5785 draw_text_with_color (entry, cr, &text_color);
5789 int frame_x, frame_y, area_x, area_y;
5791 width = gdk_window_get_width (priv->text_area);
5792 height = gdk_window_get_height (priv->text_area);
5796 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5797 cairo_rectangle (cr, 0, 0, width, height);
5799 /* progres area is frame-relative, we need it text-area window
5801 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5802 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5803 progress_x += frame_x - area_x;
5804 progress_y += frame_y - area_y;
5806 cairo_rectangle (cr, progress_x, progress_y,
5807 progress_width, progress_height);
5809 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5811 draw_text_with_color (entry, cr, &text_color);
5816 cairo_rectangle (cr, progress_x, progress_y,
5817 progress_width, progress_height);
5820 draw_text_with_color (entry, cr, &bar_text_color);
5829 draw_insertion_cursor (GtkEntry *entry,
5831 GdkRectangle *cursor_location,
5832 gboolean is_primary,
5833 PangoDirection direction,
5834 gboolean draw_arrow)
5836 GtkWidget *widget = GTK_WIDGET (entry);
5837 GtkTextDirection text_dir;
5839 if (direction == PANGO_DIRECTION_LTR)
5840 text_dir = GTK_TEXT_DIR_LTR;
5842 text_dir = GTK_TEXT_DIR_RTL;
5844 gtk_draw_insertion_cursor (widget, cr,
5846 is_primary, text_dir, draw_arrow);
5850 gtk_entry_draw_cursor (GtkEntry *entry,
5854 GtkEntryPrivate *priv = entry->priv;
5855 GtkWidget *widget = GTK_WIDGET (entry);
5856 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5857 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5858 GdkRectangle cursor_location;
5859 gboolean split_cursor;
5860 PangoRectangle cursor_rect;
5861 GtkBorder inner_border;
5863 gint text_area_height;
5866 gboolean block_at_line_end;
5867 PangoLayout *layout;
5870 _gtk_entry_effective_inner_border (entry, &inner_border);
5872 xoffset = inner_border.left - priv->scroll_offset;
5874 text_area_height = gdk_window_get_height (priv->text_area);
5876 layout = gtk_entry_ensure_layout (entry, TRUE);
5877 text = pango_layout_get_text (layout);
5878 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5879 if (!priv->overwrite_mode)
5882 block = _gtk_text_util_get_block_cursor_location (layout,
5883 cursor_index, &cursor_rect, &block_at_line_end);
5887 gint strong_x, weak_x;
5888 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5889 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5893 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5895 g_object_get (gtk_widget_get_settings (widget),
5896 "gtk-split-cursor", &split_cursor,
5899 dir1 = priv->resolved_dir;
5905 if (weak_x != strong_x)
5907 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5913 if (keymap_direction == priv->resolved_dir)
5919 cursor_location.x = xoffset + x1;
5920 cursor_location.y = inner_border.top;
5921 cursor_location.width = 0;
5922 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5924 draw_insertion_cursor (entry, cr,
5925 &cursor_location, TRUE, dir1,
5926 dir2 != PANGO_DIRECTION_NEUTRAL);
5928 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5930 cursor_location.x = xoffset + x2;
5931 draw_insertion_cursor (entry, cr,
5932 &cursor_location, FALSE, dir2,
5936 else /* overwrite_mode */
5938 GtkStyleContext *context;
5939 GdkRGBA cursor_color;
5945 get_layout_position (entry, &x, &y);
5947 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5948 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5949 rect.width = PANGO_PIXELS (cursor_rect.width);
5950 rect.height = PANGO_PIXELS (cursor_rect.height);
5952 context = gtk_widget_get_style_context (widget);
5954 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5955 gdk_cairo_set_source_rgba (cr, &cursor_color);
5956 gdk_cairo_rectangle (cr, &rect);
5959 if (!block_at_line_end)
5961 GtkStateFlags state;
5964 state = gtk_widget_get_state_flags (widget);
5965 gtk_style_context_get_background_color (context, state, &color);
5967 gdk_cairo_rectangle (cr, &rect);
5969 cairo_move_to (cr, x, y);
5970 gdk_cairo_set_source_rgba (cr, &color);
5971 pango_cairo_show_layout (cr, layout);
5979 _gtk_entry_reset_im_context (GtkEntry *entry)
5981 GtkEntryPrivate *priv = entry->priv;
5983 if (priv->need_im_reset)
5985 priv->need_im_reset = FALSE;
5986 gtk_im_context_reset (priv->im_context);
5991 * gtk_entry_reset_im_context:
5992 * @entry: a #GtkEntry
5994 * Reset the input method context of the entry if needed.
5996 * This can be necessary in the case where modifying the buffer
5997 * would confuse on-going input method behavior.
6002 gtk_entry_reset_im_context (GtkEntry *entry)
6004 g_return_if_fail (GTK_IS_ENTRY (entry));
6006 _gtk_entry_reset_im_context (entry);
6010 * gtk_entry_im_context_filter_keypress:
6011 * @entry: a #GtkEntry
6012 * @event: (type Gdk.EventKey): the key event
6014 * Allow the #GtkEntry input method to internally handle key press
6015 * and release events. If this function returns %TRUE, then no further
6016 * processing should be done for this key event. See
6017 * gtk_im_context_filter_keypress().
6019 * Note that you are expected to call this function from your handler
6020 * when overriding key event handling. This is needed in the case when
6021 * you need to insert your own key handling between the input method
6022 * and the default key event handling of the #GtkEntry.
6023 * See gtk_text_view_reset_im_context() for an example of use.
6025 * Return value: %TRUE if the input method handled the key event.
6030 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6033 GtkEntryPrivate *priv;
6035 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6039 return gtk_im_context_filter_keypress (priv->im_context, event);
6043 _gtk_entry_get_im_context (GtkEntry *entry)
6045 return entry->priv->im_context;
6049 gtk_entry_find_position (GtkEntry *entry,
6052 GtkEntryPrivate *priv = entry->priv;
6053 PangoLayout *layout;
6054 PangoLayoutLine *line;
6061 layout = gtk_entry_ensure_layout (entry, TRUE);
6062 text = pango_layout_get_text (layout);
6063 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6065 line = pango_layout_get_lines_readonly (layout)->data;
6066 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6068 if (index >= cursor_index && priv->preedit_length)
6070 if (index >= cursor_index + priv->preedit_length)
6071 index -= priv->preedit_length;
6074 index = cursor_index;
6079 pos = g_utf8_pointer_to_offset (text, text + index);
6086 gtk_entry_get_cursor_locations (GtkEntry *entry,
6091 GtkEntryPrivate *priv = entry->priv;
6092 DisplayMode mode = gtk_entry_get_display_mode (entry);
6094 /* Nothing to display at all, so no cursor is relevant */
6095 if (mode == DISPLAY_BLANK)
6105 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6106 const gchar *text = pango_layout_get_text (layout);
6107 PangoRectangle strong_pos, weak_pos;
6110 if (type == CURSOR_STANDARD)
6112 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6114 else /* type == CURSOR_DND */
6116 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6118 if (priv->dnd_position > priv->current_pos)
6120 if (mode == DISPLAY_NORMAL)
6121 index += priv->preedit_length;
6124 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6125 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6130 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6133 *strong_x = strong_pos.x / PANGO_SCALE;
6136 *weak_x = weak_pos.x / PANGO_SCALE;
6141 gtk_entry_adjust_scroll (GtkEntry *entry)
6143 GtkEntryPrivate *priv = entry->priv;
6144 gint min_offset, max_offset;
6145 gint text_area_width, text_width;
6146 GtkBorder inner_border;
6147 gint strong_x, weak_x;
6148 gint strong_xoffset, weak_xoffset;
6150 PangoLayout *layout;
6151 PangoLayoutLine *line;
6152 PangoRectangle logical_rect;
6154 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6157 _gtk_entry_effective_inner_border (entry, &inner_border);
6159 text_area_width = gdk_window_get_width (priv->text_area);
6160 text_area_width -= inner_border.left + inner_border.right;
6161 if (text_area_width < 0)
6162 text_area_width = 0;
6164 layout = gtk_entry_ensure_layout (entry, TRUE);
6165 line = pango_layout_get_lines_readonly (layout)->data;
6167 pango_layout_line_get_extents (line, NULL, &logical_rect);
6169 /* Display as much text as we can */
6171 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6172 xalign = priv->xalign;
6174 xalign = 1.0 - priv->xalign;
6176 text_width = PANGO_PIXELS(logical_rect.width);
6178 if (text_width > text_area_width)
6181 max_offset = text_width - text_area_width;
6185 min_offset = (text_width - text_area_width) * xalign;
6186 max_offset = min_offset;
6189 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6191 /* And make sure cursors are on screen. Note that the cursor is
6192 * actually drawn one pixel into the INNER_BORDER space on
6193 * the right, when the scroll is at the utmost right. This
6194 * looks better to to me than confining the cursor inside the
6195 * border entirely, though it means that the cursor gets one
6196 * pixel closer to the edge of the widget on the right than
6197 * on the left. This might need changing if one changed
6198 * INNER_BORDER from 2 to 1, as one would do on a
6199 * small-screen-real-estate display.
6201 * We always make sure that the strong cursor is on screen, and
6202 * put the weak cursor on screen if possible.
6205 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6207 strong_xoffset = strong_x - priv->scroll_offset;
6209 if (strong_xoffset < 0)
6211 priv->scroll_offset += strong_xoffset;
6214 else if (strong_xoffset > text_area_width)
6216 priv->scroll_offset += strong_xoffset - text_area_width;
6217 strong_xoffset = text_area_width;
6220 weak_xoffset = weak_x - priv->scroll_offset;
6222 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6224 priv->scroll_offset += weak_xoffset;
6226 else if (weak_xoffset > text_area_width &&
6227 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6229 priv->scroll_offset += weak_xoffset - text_area_width;
6232 g_object_notify (G_OBJECT (entry), "scroll-offset");
6236 gtk_entry_move_adjustments (GtkEntry *entry)
6238 GtkWidget *widget = GTK_WIDGET (entry);
6239 GtkAllocation allocation;
6240 GtkAdjustment *adjustment;
6241 PangoContext *context;
6242 PangoFontMetrics *metrics;
6243 GtkStyleContext *style_context;
6244 GtkStateFlags state;
6245 gint x, layout_x, border_x, border_y;
6248 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6252 gtk_widget_get_allocation (widget, &allocation);
6254 /* Cursor position, layout offset, border width, and widget allocation */
6255 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6256 get_layout_position (entry, &layout_x, NULL);
6257 _gtk_entry_get_borders (entry, &border_x, &border_y);
6258 x += allocation.x + layout_x + border_x;
6260 /* Approximate width of a char, so user can see what is ahead/behind */
6261 context = gtk_widget_get_pango_context (widget);
6262 style_context = gtk_widget_get_style_context (widget);
6263 state = gtk_widget_get_state_flags (widget);
6265 metrics = pango_context_get_metrics (context,
6266 gtk_style_context_get_font (style_context, state),
6267 pango_context_get_language (context));
6268 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6271 gtk_adjustment_clamp_page (adjustment,
6272 x - (char_width + 1), /* one char + one pixel before */
6273 x + (char_width + 2)); /* one char + cursor + one pixel after */
6277 gtk_entry_move_visually (GtkEntry *entry,
6281 GtkEntryPrivate *priv = entry->priv;
6283 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6286 text = pango_layout_get_text (layout);
6288 index = g_utf8_offset_to_pointer (text, start) - text;
6292 int new_index, new_trailing;
6293 gboolean split_cursor;
6296 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6297 "gtk-split-cursor", &split_cursor,
6304 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6305 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6307 strong = keymap_direction == priv->resolved_dir;
6312 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6317 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6323 else if (new_index != G_MAXINT)
6326 while (new_trailing--)
6327 index = g_utf8_next_char (text + index) - text;
6330 return g_utf8_pointer_to_offset (text, text + index);
6334 gtk_entry_move_logically (GtkEntry *entry,
6338 gint new_pos = start;
6341 length = gtk_entry_buffer_get_length (get_buffer (entry));
6343 /* Prevent any leak of information */
6344 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6346 new_pos = CLAMP (start + count, 0, length);
6350 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6351 PangoLogAttr *log_attrs;
6354 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6356 while (count > 0 && new_pos < length)
6360 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6364 while (count < 0 && new_pos > 0)
6368 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6380 gtk_entry_move_forward_word (GtkEntry *entry,
6382 gboolean allow_whitespace)
6384 gint new_pos = start;
6387 length = gtk_entry_buffer_get_length (get_buffer (entry));
6389 /* Prevent any leak of information */
6390 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6394 else if (new_pos < length)
6396 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6397 PangoLogAttr *log_attrs;
6400 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6402 /* Find the next word boundary */
6404 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6405 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6416 gtk_entry_move_backward_word (GtkEntry *entry,
6418 gboolean allow_whitespace)
6420 gint new_pos = start;
6422 /* Prevent any leak of information */
6423 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6429 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6430 PangoLogAttr *log_attrs;
6433 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6435 new_pos = start - 1;
6437 /* Find the previous word boundary */
6438 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6439 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6449 gtk_entry_delete_whitespace (GtkEntry *entry)
6451 GtkEntryPrivate *priv = entry->priv;
6452 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6453 PangoLogAttr *log_attrs;
6457 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6459 start = end = priv->current_pos;
6461 while (start > 0 && log_attrs[start-1].is_white)
6464 while (end < n_attrs && log_attrs[end].is_white)
6470 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6475 gtk_entry_select_word (GtkEntry *entry)
6477 GtkEntryPrivate *priv = entry->priv;
6478 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6479 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6481 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6485 gtk_entry_select_line (GtkEntry *entry)
6487 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6491 truncate_multiline (const gchar *text)
6496 text[length] && text[length] != '\n' && text[length] != '\r';
6503 paste_received (GtkClipboard *clipboard,
6507 GtkEntry *entry = GTK_ENTRY (data);
6508 GtkEditable *editable = GTK_EDITABLE (entry);
6509 GtkEntryPrivate *priv = entry->priv;
6511 if (priv->button == 2)
6513 gint pos, start, end;
6514 pos = priv->insert_pos;
6515 gtk_editable_get_selection_bounds (editable, &start, &end);
6516 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6517 gtk_editable_select_region (editable, pos, pos);
6522 gint pos, start, end;
6524 gboolean popup_completion;
6525 GtkEntryCompletion *completion;
6527 completion = gtk_entry_get_completion (entry);
6529 if (priv->truncate_multiline)
6530 length = truncate_multiline (text);
6532 /* only complete if the selection is at the end */
6533 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6534 MAX (priv->current_pos, priv->selection_bound));
6538 if (gtk_widget_get_mapped (completion->priv->popup_window))
6539 _gtk_entry_completion_popdown (completion);
6541 if (!popup_completion && completion->priv->changed_id > 0)
6542 g_signal_handler_block (entry, completion->priv->changed_id);
6545 begin_change (entry);
6546 g_object_freeze_notify (G_OBJECT (entry));
6547 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6548 gtk_editable_delete_text (editable, start, end);
6550 pos = priv->current_pos;
6551 gtk_editable_insert_text (editable, text, length, &pos);
6552 gtk_editable_set_position (editable, pos);
6553 g_object_thaw_notify (G_OBJECT (entry));
6557 !popup_completion && completion->priv->changed_id > 0)
6558 g_signal_handler_unblock (entry, completion->priv->changed_id);
6561 g_object_unref (entry);
6565 gtk_entry_paste (GtkEntry *entry,
6568 g_object_ref (entry);
6569 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6570 paste_received, entry);
6574 primary_get_cb (GtkClipboard *clipboard,
6575 GtkSelectionData *selection_data,
6579 GtkEntry *entry = GTK_ENTRY (data);
6582 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6584 gchar *str = gtk_entry_get_display_text (entry, start, end);
6585 gtk_selection_data_set_text (selection_data, str, -1);
6591 primary_clear_cb (GtkClipboard *clipboard,
6594 GtkEntry *entry = GTK_ENTRY (data);
6595 GtkEntryPrivate *priv = entry->priv;
6597 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6601 gtk_entry_update_primary_selection (GtkEntry *entry)
6603 GtkTargetList *list;
6604 GtkTargetEntry *targets;
6605 GtkClipboard *clipboard;
6609 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6612 list = gtk_target_list_new (NULL, 0);
6613 gtk_target_list_add_text_targets (list, 0);
6615 targets = gtk_target_table_new_from_list (list, &n_targets);
6617 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6619 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6621 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6622 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6623 primary_clear_cb (clipboard, entry);
6627 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6628 gtk_clipboard_clear (clipboard);
6631 gtk_target_table_free (targets, n_targets);
6632 gtk_target_list_unref (list);
6636 gtk_entry_clear (GtkEntry *entry,
6637 GtkEntryIconPosition icon_pos)
6639 GtkEntryPrivate *priv = entry->priv;
6640 EntryIconInfo *icon_info = priv->icons[icon_pos];
6642 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6645 g_object_freeze_notify (G_OBJECT (entry));
6647 /* Explicitly check, as the pointer may become invalidated
6648 * during destruction.
6650 if (GDK_IS_WINDOW (icon_info->window))
6651 gdk_window_hide (icon_info->window);
6653 if (icon_info->pixbuf)
6655 g_object_unref (icon_info->pixbuf);
6656 icon_info->pixbuf = NULL;
6659 switch (icon_info->storage_type)
6661 case GTK_IMAGE_PIXBUF:
6662 g_object_notify (G_OBJECT (entry),
6663 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6666 case GTK_IMAGE_STOCK:
6667 g_free (icon_info->stock_id);
6668 icon_info->stock_id = NULL;
6669 g_object_notify (G_OBJECT (entry),
6670 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6673 case GTK_IMAGE_ICON_NAME:
6674 g_free (icon_info->icon_name);
6675 icon_info->icon_name = NULL;
6676 g_object_notify (G_OBJECT (entry),
6677 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6680 case GTK_IMAGE_GICON:
6681 if (icon_info->gicon)
6683 g_object_unref (icon_info->gicon);
6684 icon_info->gicon = NULL;
6686 g_object_notify (G_OBJECT (entry),
6687 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6691 g_assert_not_reached ();
6695 icon_info->storage_type = GTK_IMAGE_EMPTY;
6696 g_object_notify (G_OBJECT (entry),
6697 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6699 g_object_thaw_notify (G_OBJECT (entry));
6703 create_normal_pixbuf (GtkStyleContext *context,
6704 const gchar *stock_id,
6705 GtkIconSize icon_size)
6707 GtkIconSet *icon_set;
6710 gtk_style_context_save (context);
6712 /* Unset any state */
6713 gtk_style_context_set_state (context, 0);
6715 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6716 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6718 gtk_style_context_restore (context);
6724 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6725 GtkEntryIconPosition icon_pos)
6727 GtkEntryPrivate *priv = entry->priv;
6728 EntryIconInfo *icon_info = priv->icons[icon_pos];
6729 GtkStyleContext *context;
6731 GtkIconTheme *icon_theme;
6732 GtkSettings *settings;
6737 if (!icon_info || icon_info->pixbuf)
6740 widget = GTK_WIDGET (entry);
6741 context = gtk_widget_get_style_context (widget);
6743 switch (icon_info->storage_type)
6745 case GTK_IMAGE_EMPTY:
6746 case GTK_IMAGE_PIXBUF:
6748 case GTK_IMAGE_STOCK:
6749 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6750 GTK_ICON_SIZE_MENU);
6752 if (!icon_info->pixbuf)
6753 icon_info->pixbuf = create_normal_pixbuf (context,
6754 GTK_STOCK_MISSING_IMAGE,
6755 GTK_ICON_SIZE_MENU);
6758 case GTK_IMAGE_ICON_NAME:
6759 screen = gtk_widget_get_screen (widget);
6762 icon_theme = gtk_icon_theme_get_for_screen (screen);
6763 settings = gtk_settings_get_for_screen (screen);
6765 gtk_icon_size_lookup_for_settings (settings,
6769 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6770 icon_info->icon_name,
6771 MIN (width, height),
6774 if (icon_info->pixbuf == NULL)
6775 icon_info->pixbuf = create_normal_pixbuf (context,
6776 GTK_STOCK_MISSING_IMAGE,
6777 GTK_ICON_SIZE_MENU);
6781 case GTK_IMAGE_GICON:
6782 screen = gtk_widget_get_screen (widget);
6785 icon_theme = gtk_icon_theme_get_for_screen (screen);
6786 settings = gtk_settings_get_for_screen (screen);
6788 gtk_icon_size_lookup_for_settings (settings,
6792 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6794 MIN (width, height),
6795 GTK_ICON_LOOKUP_USE_BUILTIN);
6798 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6799 gtk_icon_info_free (info);
6802 if (icon_info->pixbuf == NULL)
6803 icon_info->pixbuf = create_normal_pixbuf (context,
6804 GTK_STOCK_MISSING_IMAGE,
6805 GTK_ICON_SIZE_MENU);
6810 g_assert_not_reached ();
6814 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6815 gdk_window_show_unraised (icon_info->window);
6825 * Creates a new entry.
6827 * Return value: a new #GtkEntry.
6830 gtk_entry_new (void)
6832 return g_object_new (GTK_TYPE_ENTRY, NULL);
6836 * gtk_entry_new_with_buffer:
6837 * @buffer: The buffer to use for the new #GtkEntry.
6839 * Creates a new entry with the specified text buffer.
6841 * Return value: a new #GtkEntry
6846 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6848 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6849 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6852 static GtkEntryBuffer*
6853 get_buffer (GtkEntry *entry)
6855 GtkEntryPrivate *priv = entry->priv;
6857 if (priv->buffer == NULL)
6859 GtkEntryBuffer *buffer;
6860 buffer = gtk_entry_buffer_new (NULL, 0);
6861 gtk_entry_set_buffer (entry, buffer);
6862 g_object_unref (buffer);
6865 return priv->buffer;
6869 * gtk_entry_get_buffer:
6870 * @entry: a #GtkEntry
6872 * Get the #GtkEntryBuffer object which holds the text for
6877 * Returns: (transfer none): A #GtkEntryBuffer object.
6880 gtk_entry_get_buffer (GtkEntry *entry)
6882 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6884 return get_buffer (entry);
6888 * gtk_entry_set_buffer:
6889 * @entry: a #GtkEntry
6890 * @buffer: a #GtkEntryBuffer
6892 * Set the #GtkEntryBuffer object which holds the text for
6898 gtk_entry_set_buffer (GtkEntry *entry,
6899 GtkEntryBuffer *buffer)
6901 GtkEntryPrivate *priv;
6904 g_return_if_fail (GTK_IS_ENTRY (entry));
6910 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6911 g_object_ref (buffer);
6916 buffer_disconnect_signals (entry);
6917 g_object_unref (priv->buffer);
6920 priv->buffer = buffer;
6923 buffer_connect_signals (entry);
6925 obj = G_OBJECT (entry);
6926 g_object_freeze_notify (obj);
6927 g_object_notify (obj, "buffer");
6928 g_object_notify (obj, "text");
6929 g_object_notify (obj, "text-length");
6930 g_object_notify (obj, "max-length");
6931 g_object_notify (obj, "visibility");
6932 g_object_notify (obj, "invisible-char");
6933 g_object_notify (obj, "invisible-char-set");
6934 g_object_thaw_notify (obj);
6936 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6937 gtk_entry_recompute (entry);
6941 * gtk_entry_get_text_area:
6942 * @entry: a #GtkEntry
6943 * @text_area: (out): Return location for the text area.
6945 * Gets the area where the entry's text is drawn. This function is
6946 * useful when drawing something to the entry in a draw callback.
6948 * If the entry is not realized, @text_area is filled with zeros.
6950 * See also gtk_entry_get_icon_area().
6955 gtk_entry_get_text_area (GtkEntry *entry,
6956 GdkRectangle *text_area)
6958 GtkEntryPrivate *priv;
6960 g_return_if_fail (GTK_IS_ENTRY (entry));
6961 g_return_if_fail (text_area != NULL);
6965 if (priv->text_area)
6967 GtkAllocation allocation;
6970 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6971 gdk_window_get_position (priv->text_area, &x, &y);
6973 text_area->x = x - allocation.x;
6974 text_area->y = y - allocation.y;
6975 text_area->width = gdk_window_get_width (priv->text_area);
6976 text_area->height = gdk_window_get_height (priv->text_area);
6982 text_area->width = 0;
6983 text_area->height = 0;
6988 * gtk_entry_set_text:
6989 * @entry: a #GtkEntry
6990 * @text: the new text
6992 * Sets the text in the widget to the given
6993 * value, replacing the current contents.
6995 * See gtk_entry_buffer_set_text().
6998 gtk_entry_set_text (GtkEntry *entry,
7002 GtkEntryCompletion *completion;
7004 g_return_if_fail (GTK_IS_ENTRY (entry));
7005 g_return_if_fail (text != NULL);
7007 /* Actually setting the text will affect the cursor and selection;
7008 * if the contents don't actually change, this will look odd to the user.
7010 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7013 completion = gtk_entry_get_completion (entry);
7014 if (completion && completion->priv->changed_id > 0)
7015 g_signal_handler_block (entry, completion->priv->changed_id);
7017 begin_change (entry);
7018 g_object_freeze_notify (G_OBJECT (entry));
7019 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7021 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7022 g_object_thaw_notify (G_OBJECT (entry));
7025 if (completion && completion->priv->changed_id > 0)
7026 g_signal_handler_unblock (entry, completion->priv->changed_id);
7030 * gtk_entry_set_visibility:
7031 * @entry: a #GtkEntry
7032 * @visible: %TRUE if the contents of the entry are displayed
7035 * Sets whether the contents of the entry are visible or not.
7036 * When visibility is set to %FALSE, characters are displayed
7037 * as the invisible char, and will also appear that way when
7038 * the text in the entry widget is copied elsewhere.
7040 * By default, GTK+ picks the best invisible character available
7041 * in the current font, but it can be changed with
7042 * gtk_entry_set_invisible_char().
7045 gtk_entry_set_visibility (GtkEntry *entry,
7048 GtkEntryPrivate *priv;
7050 g_return_if_fail (GTK_IS_ENTRY (entry));
7054 visible = visible != FALSE;
7056 if (priv->visible != visible)
7058 priv->visible = visible;
7060 g_object_notify (G_OBJECT (entry), "visibility");
7061 gtk_entry_recompute (entry);
7066 * gtk_entry_get_visibility:
7067 * @entry: a #GtkEntry
7069 * Retrieves whether the text in @entry is visible. See
7070 * gtk_entry_set_visibility().
7072 * Return value: %TRUE if the text is currently visible
7075 gtk_entry_get_visibility (GtkEntry *entry)
7077 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7079 return entry->priv->visible;
7083 * gtk_entry_set_invisible_char:
7084 * @entry: a #GtkEntry
7085 * @ch: a Unicode character
7087 * Sets the character to use in place of the actual text when
7088 * gtk_entry_set_visibility() has been called to set text visibility
7089 * to %FALSE. i.e. this is the character used in "password mode" to
7090 * show the user how many characters have been typed. By default, GTK+
7091 * picks the best invisible char available in the current font. If you
7092 * set the invisible char to 0, then the user will get no feedback
7093 * at all; there will be no text on the screen as they type.
7096 gtk_entry_set_invisible_char (GtkEntry *entry,
7099 GtkEntryPrivate *priv;
7101 g_return_if_fail (GTK_IS_ENTRY (entry));
7105 if (!priv->invisible_char_set)
7107 priv->invisible_char_set = TRUE;
7108 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7111 if (ch == priv->invisible_char)
7114 priv->invisible_char = ch;
7115 g_object_notify (G_OBJECT (entry), "invisible-char");
7116 gtk_entry_recompute (entry);
7120 * gtk_entry_get_invisible_char:
7121 * @entry: a #GtkEntry
7123 * Retrieves the character displayed in place of the real characters
7124 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7126 * Return value: the current invisible char, or 0, if the entry does not
7127 * show invisible text at all.
7130 gtk_entry_get_invisible_char (GtkEntry *entry)
7132 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7134 return entry->priv->invisible_char;
7138 * gtk_entry_unset_invisible_char:
7139 * @entry: a #GtkEntry
7141 * Unsets the invisible char previously set with
7142 * gtk_entry_set_invisible_char(). So that the
7143 * default invisible char is used again.
7148 gtk_entry_unset_invisible_char (GtkEntry *entry)
7150 GtkEntryPrivate *priv;
7153 g_return_if_fail (GTK_IS_ENTRY (entry));
7157 if (!priv->invisible_char_set)
7160 priv->invisible_char_set = FALSE;
7161 ch = find_invisible_char (GTK_WIDGET (entry));
7163 if (priv->invisible_char != ch)
7165 priv->invisible_char = ch;
7166 g_object_notify (G_OBJECT (entry), "invisible-char");
7169 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7170 gtk_entry_recompute (entry);
7174 * gtk_entry_set_overwrite_mode:
7175 * @entry: a #GtkEntry
7176 * @overwrite: new value
7178 * Sets whether the text is overwritten when typing in the #GtkEntry.
7183 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7186 GtkEntryPrivate *priv = entry->priv;
7188 g_return_if_fail (GTK_IS_ENTRY (entry));
7190 if (priv->overwrite_mode == overwrite)
7193 gtk_entry_toggle_overwrite (entry);
7195 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7199 * gtk_entry_get_overwrite_mode:
7200 * @entry: a #GtkEntry
7202 * Gets the value set by gtk_entry_set_overwrite_mode().
7204 * Return value: whether the text is overwritten when typing.
7209 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7211 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7213 return entry->priv->overwrite_mode;
7217 * gtk_entry_get_text:
7218 * @entry: a #GtkEntry
7220 * Retrieves the contents of the entry widget.
7221 * See also gtk_editable_get_chars().
7223 * This is equivalent to:
7225 * <informalexample><programlisting>
7226 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7227 * </programlisting></informalexample>
7229 * Return value: a pointer to the contents of the widget as a
7230 * string. This string points to internally allocated
7231 * storage in the widget and must not be freed, modified or
7234 G_CONST_RETURN gchar*
7235 gtk_entry_get_text (GtkEntry *entry)
7237 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7239 return gtk_entry_buffer_get_text (get_buffer (entry));
7243 * gtk_entry_set_max_length:
7244 * @entry: a #GtkEntry
7245 * @max: the maximum length of the entry, or 0 for no maximum.
7246 * (other than the maximum length of entries.) The value passed in will
7247 * be clamped to the range 0-65536.
7249 * Sets the maximum allowed length of the contents of the widget. If
7250 * the current contents are longer than the given length, then they
7251 * will be truncated to fit.
7253 * This is equivalent to:
7255 * <informalexample><programlisting>
7256 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7257 * </programlisting></informalexample>
7260 gtk_entry_set_max_length (GtkEntry *entry,
7263 g_return_if_fail (GTK_IS_ENTRY (entry));
7264 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7268 * gtk_entry_get_max_length:
7269 * @entry: a #GtkEntry
7271 * Retrieves the maximum allowed length of the text in
7272 * @entry. See gtk_entry_set_max_length().
7274 * This is equivalent to:
7276 * <informalexample><programlisting>
7277 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7278 * </programlisting></informalexample>
7280 * Return value: the maximum allowed number of characters
7281 * in #GtkEntry, or 0 if there is no maximum.
7284 gtk_entry_get_max_length (GtkEntry *entry)
7286 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7288 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7292 * gtk_entry_get_text_length:
7293 * @entry: a #GtkEntry
7295 * Retrieves the current length of the text in
7298 * This is equivalent to:
7300 * <informalexample><programlisting>
7301 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7302 * </programlisting></informalexample>
7304 * Return value: the current number of characters
7305 * in #GtkEntry, or 0 if there are none.
7310 gtk_entry_get_text_length (GtkEntry *entry)
7312 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7314 return gtk_entry_buffer_get_length (get_buffer (entry));
7318 * gtk_entry_set_activates_default:
7319 * @entry: a #GtkEntry
7320 * @setting: %TRUE to activate window's default widget on Enter keypress
7322 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7323 * widget for the window containing the entry. This usually means that
7324 * the dialog box containing the entry will be closed, since the default
7325 * widget is usually one of the dialog buttons.
7327 * (For experts: if @setting is %TRUE, the entry calls
7328 * gtk_window_activate_default() on the window containing the entry, in
7329 * the default handler for the #GtkWidget::activate signal.)
7332 gtk_entry_set_activates_default (GtkEntry *entry,
7335 GtkEntryPrivate *priv;
7337 g_return_if_fail (GTK_IS_ENTRY (entry));
7341 setting = setting != FALSE;
7343 if (setting != priv->activates_default)
7345 priv->activates_default = setting;
7346 g_object_notify (G_OBJECT (entry), "activates-default");
7351 * gtk_entry_get_activates_default:
7352 * @entry: a #GtkEntry
7354 * Retrieves the value set by gtk_entry_set_activates_default().
7356 * Return value: %TRUE if the entry will activate the default widget
7359 gtk_entry_get_activates_default (GtkEntry *entry)
7361 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7363 return entry->priv->activates_default;
7367 * gtk_entry_set_width_chars:
7368 * @entry: a #GtkEntry
7369 * @n_chars: width in chars
7371 * Changes the size request of the entry to be about the right size
7372 * for @n_chars characters. Note that it changes the size
7373 * <emphasis>request</emphasis>, the size can still be affected by
7374 * how you pack the widget into containers. If @n_chars is -1, the
7375 * size reverts to the default entry size.
7378 gtk_entry_set_width_chars (GtkEntry *entry,
7381 GtkEntryPrivate *priv;
7383 g_return_if_fail (GTK_IS_ENTRY (entry));
7387 if (priv->width_chars != n_chars)
7389 priv->width_chars = n_chars;
7390 g_object_notify (G_OBJECT (entry), "width-chars");
7391 gtk_widget_queue_resize (GTK_WIDGET (entry));
7396 * gtk_entry_get_width_chars:
7397 * @entry: a #GtkEntry
7399 * Gets the value set by gtk_entry_set_width_chars().
7401 * Return value: number of chars to request space for, or negative if unset
7404 gtk_entry_get_width_chars (GtkEntry *entry)
7406 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7408 return entry->priv->width_chars;
7412 * gtk_entry_set_has_frame:
7413 * @entry: a #GtkEntry
7414 * @setting: new value
7416 * Sets whether the entry has a beveled frame around it.
7419 gtk_entry_set_has_frame (GtkEntry *entry,
7422 GtkEntryPrivate *priv;
7424 g_return_if_fail (GTK_IS_ENTRY (entry));
7428 setting = (setting != FALSE);
7430 if (priv->has_frame == setting)
7433 gtk_widget_queue_resize (GTK_WIDGET (entry));
7434 priv->has_frame = setting;
7435 g_object_notify (G_OBJECT (entry), "has-frame");
7439 * gtk_entry_get_has_frame:
7440 * @entry: a #GtkEntry
7442 * Gets the value set by gtk_entry_set_has_frame().
7444 * Return value: whether the entry has a beveled frame
7447 gtk_entry_get_has_frame (GtkEntry *entry)
7449 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7451 return entry->priv->has_frame;
7455 * gtk_entry_set_inner_border:
7456 * @entry: a #GtkEntry
7457 * @border: (allow-none): a #GtkBorder, or %NULL
7459 * Sets %entry's inner-border property to %border, or clears it if %NULL
7460 * is passed. The inner-border is the area around the entry's text, but
7463 * If set, this property overrides the inner-border style property.
7464 * Overriding the style-provided border is useful when you want to do
7465 * in-place editing of some text in a canvas or list widget, where
7466 * pixel-exact positioning of the entry is important.
7471 gtk_entry_set_inner_border (GtkEntry *entry,
7472 const GtkBorder *border)
7474 g_return_if_fail (GTK_IS_ENTRY (entry));
7476 gtk_widget_queue_resize (GTK_WIDGET (entry));
7479 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7480 gtk_border_copy (border),
7481 (GDestroyNotify) gtk_border_free);
7483 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7485 g_object_notify (G_OBJECT (entry), "inner-border");
7489 * gtk_entry_get_inner_border:
7490 * @entry: a #GtkEntry
7492 * This function returns the entry's #GtkEntry:inner-border property. See
7493 * gtk_entry_set_inner_border() for more information.
7495 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7499 G_CONST_RETURN GtkBorder *
7500 gtk_entry_get_inner_border (GtkEntry *entry)
7502 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7504 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7508 * gtk_entry_get_layout:
7509 * @entry: a #GtkEntry
7511 * Gets the #PangoLayout used to display the entry.
7512 * The layout is useful to e.g. convert text positions to
7513 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7514 * The returned layout is owned by the entry and must not be
7515 * modified or freed by the caller.
7517 * Keep in mind that the layout text may contain a preedit string, so
7518 * gtk_entry_layout_index_to_text_index() and
7519 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7520 * indices in the layout to byte indices in the entry contents.
7522 * Return value: (transfer none): the #PangoLayout for this entry
7525 gtk_entry_get_layout (GtkEntry *entry)
7527 PangoLayout *layout;
7529 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7531 layout = gtk_entry_ensure_layout (entry, TRUE);
7538 * gtk_entry_layout_index_to_text_index:
7539 * @entry: a #GtkEntry
7540 * @layout_index: byte index into the entry layout text
7542 * Converts from a position in the entry contents (returned
7543 * by gtk_entry_get_text()) to a position in the
7544 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7545 * with text retrieved via pango_layout_get_text()).
7547 * Return value: byte index into the entry contents
7550 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7553 GtkEntryPrivate *priv;
7554 PangoLayout *layout;
7558 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7562 layout = gtk_entry_ensure_layout (entry, TRUE);
7563 text = pango_layout_get_text (layout);
7564 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7566 if (layout_index >= cursor_index && priv->preedit_length)
7568 if (layout_index >= cursor_index + priv->preedit_length)
7569 layout_index -= priv->preedit_length;
7571 layout_index = cursor_index;
7574 return layout_index;
7578 * gtk_entry_text_index_to_layout_index:
7579 * @entry: a #GtkEntry
7580 * @text_index: byte index into the entry contents
7582 * Converts from a position in the entry's #PangoLayout (returned by
7583 * gtk_entry_get_layout()) to a position in the entry contents
7584 * (returned by gtk_entry_get_text()).
7586 * Return value: byte index into the entry layout text
7589 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7592 GtkEntryPrivate *priv;
7593 PangoLayout *layout;
7597 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7601 layout = gtk_entry_ensure_layout (entry, TRUE);
7602 text = pango_layout_get_text (layout);
7603 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7605 if (text_index > cursor_index)
7606 text_index += priv->preedit_length;
7612 * gtk_entry_get_layout_offsets:
7613 * @entry: a #GtkEntry
7614 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7615 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7618 * Obtains the position of the #PangoLayout used to render text
7619 * in the entry, in widget coordinates. Useful if you want to line
7620 * up the text in an entry with some other text, e.g. when using the
7621 * entry to implement editable cells in a sheet widget.
7623 * Also useful to convert mouse events into coordinates inside the
7624 * #PangoLayout, e.g. to take some action if some part of the entry text
7627 * Note that as the user scrolls around in the entry the offsets will
7628 * change; you'll need to connect to the "notify::scroll-offset"
7629 * signal to track this. Remember when using the #PangoLayout
7630 * functions you need to convert to and from pixels using
7631 * PANGO_PIXELS() or #PANGO_SCALE.
7633 * Keep in mind that the layout text may contain a preedit string, so
7634 * gtk_entry_layout_index_to_text_index() and
7635 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7636 * indices in the layout to byte indices in the entry contents.
7639 gtk_entry_get_layout_offsets (GtkEntry *entry,
7643 gint text_area_x, text_area_y;
7645 g_return_if_fail (GTK_IS_ENTRY (entry));
7647 /* this gets coords relative to text area */
7648 get_layout_position (entry, x, y);
7650 /* convert to widget coords */
7651 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7662 * gtk_entry_set_alignment:
7663 * @entry: a #GtkEntry
7664 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7665 * Reversed for RTL layouts
7667 * Sets the alignment for the contents of the entry. This controls
7668 * the horizontal positioning of the contents when the displayed
7669 * text is shorter than the width of the entry.
7674 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7676 GtkEntryPrivate *priv;
7678 g_return_if_fail (GTK_IS_ENTRY (entry));
7684 else if (xalign > 1.0)
7687 if (xalign != priv->xalign)
7689 priv->xalign = xalign;
7691 gtk_entry_recompute (entry);
7693 g_object_notify (G_OBJECT (entry), "xalign");
7698 * gtk_entry_get_alignment:
7699 * @entry: a #GtkEntry
7701 * Gets the value set by gtk_entry_set_alignment().
7703 * Return value: the alignment
7708 gtk_entry_get_alignment (GtkEntry *entry)
7710 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7712 return entry->priv->xalign;
7716 * gtk_entry_set_icon_from_pixbuf:
7717 * @entry: a #GtkEntry
7718 * @icon_pos: Icon position
7719 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7721 * Sets the icon shown in the specified position using a pixbuf.
7723 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7728 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7729 GtkEntryIconPosition icon_pos,
7732 GtkEntryPrivate *priv;
7733 EntryIconInfo *icon_info;
7735 g_return_if_fail (GTK_IS_ENTRY (entry));
7736 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7740 if ((icon_info = priv->icons[icon_pos]) == NULL)
7741 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7743 g_object_freeze_notify (G_OBJECT (entry));
7746 g_object_ref (pixbuf);
7748 gtk_entry_clear (entry, icon_pos);
7752 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7753 icon_info->pixbuf = pixbuf;
7755 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7757 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7758 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7762 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7763 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7766 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7767 gdk_window_show_unraised (icon_info->window);
7770 gtk_entry_ensure_pixbuf (entry, icon_pos);
7772 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7773 gtk_widget_queue_resize (GTK_WIDGET (entry));
7775 g_object_thaw_notify (G_OBJECT (entry));
7779 * gtk_entry_set_icon_from_stock:
7780 * @entry: A #GtkEntry
7781 * @icon_pos: Icon position
7782 * @stock_id: (allow-none): The name of the stock item, or %NULL
7784 * Sets the icon shown in the entry at the specified position from
7787 * If @stock_id is %NULL, no icon will be shown in the specified position.
7792 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7793 GtkEntryIconPosition icon_pos,
7794 const gchar *stock_id)
7796 GtkEntryPrivate *priv;
7797 EntryIconInfo *icon_info;
7800 g_return_if_fail (GTK_IS_ENTRY (entry));
7801 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7805 if ((icon_info = priv->icons[icon_pos]) == NULL)
7806 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7808 g_object_freeze_notify (G_OBJECT (entry));
7810 /* need to dup before clearing */
7811 new_id = g_strdup (stock_id);
7813 gtk_entry_clear (entry, icon_pos);
7817 icon_info->storage_type = GTK_IMAGE_STOCK;
7818 icon_info->stock_id = new_id;
7820 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7822 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7823 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7827 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7828 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7831 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7832 gdk_window_show_unraised (icon_info->window);
7835 gtk_entry_ensure_pixbuf (entry, icon_pos);
7837 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7838 gtk_widget_queue_resize (GTK_WIDGET (entry));
7840 g_object_thaw_notify (G_OBJECT (entry));
7844 * gtk_entry_set_icon_from_icon_name:
7845 * @entry: A #GtkEntry
7846 * @icon_pos: The position at which to set the icon
7847 * @icon_name: (allow-none): An icon name, or %NULL
7849 * Sets the icon shown in the entry at the specified position
7850 * from the current icon theme.
7852 * If the icon name isn't known, a "broken image" icon will be displayed
7855 * If @icon_name is %NULL, no icon will be shown in the specified position.
7860 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7861 GtkEntryIconPosition icon_pos,
7862 const gchar *icon_name)
7864 GtkEntryPrivate *priv;
7865 EntryIconInfo *icon_info;
7868 g_return_if_fail (GTK_IS_ENTRY (entry));
7869 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7873 if ((icon_info = priv->icons[icon_pos]) == NULL)
7874 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7876 g_object_freeze_notify (G_OBJECT (entry));
7878 /* need to dup before clearing */
7879 new_name = g_strdup (icon_name);
7881 gtk_entry_clear (entry, icon_pos);
7883 if (new_name != NULL)
7885 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7886 icon_info->icon_name = new_name;
7888 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7890 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7891 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7895 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7896 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7899 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7900 gdk_window_show_unraised (icon_info->window);
7903 gtk_entry_ensure_pixbuf (entry, icon_pos);
7905 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7906 gtk_widget_queue_resize (GTK_WIDGET (entry));
7908 g_object_thaw_notify (G_OBJECT (entry));
7912 * gtk_entry_set_icon_from_gicon:
7913 * @entry: A #GtkEntry
7914 * @icon_pos: The position at which to set the icon
7915 * @icon: (allow-none): The icon to set, or %NULL
7917 * Sets the icon shown in the entry at the specified position
7918 * from the current icon theme.
7919 * If the icon isn't known, a "broken image" icon will be displayed
7922 * If @icon is %NULL, no icon will be shown in the specified position.
7927 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7928 GtkEntryIconPosition icon_pos,
7931 GtkEntryPrivate *priv;
7932 EntryIconInfo *icon_info;
7934 g_return_if_fail (GTK_IS_ENTRY (entry));
7935 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7939 if ((icon_info = priv->icons[icon_pos]) == NULL)
7940 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7942 g_object_freeze_notify (G_OBJECT (entry));
7944 /* need to ref before clearing */
7946 g_object_ref (icon);
7948 gtk_entry_clear (entry, icon_pos);
7952 icon_info->storage_type = GTK_IMAGE_GICON;
7953 icon_info->gicon = icon;
7955 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7957 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7958 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7962 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7963 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7966 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7967 gdk_window_show_unraised (icon_info->window);
7970 gtk_entry_ensure_pixbuf (entry, icon_pos);
7972 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7973 gtk_widget_queue_resize (GTK_WIDGET (entry));
7975 g_object_thaw_notify (G_OBJECT (entry));
7979 * gtk_entry_set_icon_activatable:
7980 * @entry: A #GtkEntry
7981 * @icon_pos: Icon position
7982 * @activatable: %TRUE if the icon should be activatable
7984 * Sets whether the icon is activatable.
7989 gtk_entry_set_icon_activatable (GtkEntry *entry,
7990 GtkEntryIconPosition icon_pos,
7991 gboolean activatable)
7993 GtkEntryPrivate *priv;
7994 EntryIconInfo *icon_info;
7996 g_return_if_fail (GTK_IS_ENTRY (entry));
7997 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8001 if ((icon_info = priv->icons[icon_pos]) == NULL)
8002 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8004 activatable = activatable != FALSE;
8006 if (icon_info->nonactivatable != !activatable)
8008 icon_info->nonactivatable = !activatable;
8010 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8011 update_cursors (GTK_WIDGET (entry));
8013 g_object_notify (G_OBJECT (entry),
8014 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8019 * gtk_entry_get_icon_activatable:
8020 * @entry: a #GtkEntry
8021 * @icon_pos: Icon position
8023 * Returns whether the icon is activatable.
8025 * Returns: %TRUE if the icon is activatable.
8030 gtk_entry_get_icon_activatable (GtkEntry *entry,
8031 GtkEntryIconPosition icon_pos)
8033 GtkEntryPrivate *priv;
8034 EntryIconInfo *icon_info;
8036 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8037 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8040 icon_info = priv->icons[icon_pos];
8042 return (!icon_info || !icon_info->nonactivatable);
8046 * gtk_entry_get_icon_pixbuf:
8047 * @entry: A #GtkEntry
8048 * @icon_pos: Icon position
8050 * Retrieves the image used for the icon.
8052 * Unlike the other methods of setting and getting icon data, this
8053 * method will work regardless of whether the icon was set using a
8054 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8056 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8057 * set for this position.
8062 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8063 GtkEntryIconPosition icon_pos)
8065 GtkEntryPrivate *priv;
8066 EntryIconInfo *icon_info;
8068 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8069 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8073 icon_info = priv->icons[icon_pos];
8078 gtk_entry_ensure_pixbuf (entry, icon_pos);
8080 return icon_info->pixbuf;
8084 * gtk_entry_get_icon_gicon:
8085 * @entry: A #GtkEntry
8086 * @icon_pos: Icon position
8088 * Retrieves the #GIcon used for the icon, or %NULL if there is
8089 * no icon or if the icon was set by some other method (e.g., by
8090 * stock, pixbuf, or icon name).
8092 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8093 * or if the icon is not a #GIcon
8098 gtk_entry_get_icon_gicon (GtkEntry *entry,
8099 GtkEntryIconPosition icon_pos)
8101 GtkEntryPrivate *priv;
8102 EntryIconInfo *icon_info;
8104 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8105 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8108 icon_info = priv->icons[icon_pos];
8113 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8117 * gtk_entry_get_icon_stock:
8118 * @entry: A #GtkEntry
8119 * @icon_pos: Icon position
8121 * Retrieves the stock id used for the icon, or %NULL if there is
8122 * no icon or if the icon was set by some other method (e.g., by
8123 * pixbuf, icon name or gicon).
8125 * Returns: A stock id, or %NULL if no icon is set or if the icon
8126 * wasn't set from a stock id
8131 gtk_entry_get_icon_stock (GtkEntry *entry,
8132 GtkEntryIconPosition icon_pos)
8134 GtkEntryPrivate *priv;
8135 EntryIconInfo *icon_info;
8137 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8138 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8141 icon_info = priv->icons[icon_pos];
8146 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8150 * gtk_entry_get_icon_name:
8151 * @entry: A #GtkEntry
8152 * @icon_pos: Icon position
8154 * Retrieves the icon name used for the icon, or %NULL if there is
8155 * no icon or if the icon was set by some other method (e.g., by
8156 * pixbuf, stock or gicon).
8158 * Returns: An icon name, or %NULL if no icon is set or if the icon
8159 * wasn't set from an icon name
8164 gtk_entry_get_icon_name (GtkEntry *entry,
8165 GtkEntryIconPosition icon_pos)
8167 GtkEntryPrivate *priv;
8168 EntryIconInfo *icon_info;
8170 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8171 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8174 icon_info = priv->icons[icon_pos];
8179 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8183 * gtk_entry_set_icon_sensitive:
8184 * @entry: A #GtkEntry
8185 * @icon_pos: Icon position
8186 * @sensitive: Specifies whether the icon should appear
8187 * sensitive or insensitive
8189 * Sets the sensitivity for the specified icon.
8194 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8195 GtkEntryIconPosition icon_pos,
8198 GtkEntryPrivate *priv;
8199 EntryIconInfo *icon_info;
8201 g_return_if_fail (GTK_IS_ENTRY (entry));
8202 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8206 if ((icon_info = priv->icons[icon_pos]) == NULL)
8207 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8209 if (icon_info->insensitive != !sensitive)
8211 icon_info->insensitive = !sensitive;
8213 icon_info->pressed = FALSE;
8214 icon_info->prelight = FALSE;
8216 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8217 update_cursors (GTK_WIDGET (entry));
8219 gtk_widget_queue_draw (GTK_WIDGET (entry));
8221 g_object_notify (G_OBJECT (entry),
8222 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8227 * gtk_entry_get_icon_sensitive:
8228 * @entry: a #GtkEntry
8229 * @icon_pos: Icon position
8231 * Returns whether the icon appears sensitive or insensitive.
8233 * Returns: %TRUE if the icon is sensitive.
8238 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8239 GtkEntryIconPosition icon_pos)
8241 GtkEntryPrivate *priv;
8242 EntryIconInfo *icon_info;
8244 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8245 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8249 icon_info = priv->icons[icon_pos];
8251 return (!icon_info || !icon_info->insensitive);
8256 * gtk_entry_get_icon_storage_type:
8257 * @entry: a #GtkEntry
8258 * @icon_pos: Icon position
8260 * Gets the type of representation being used by the icon
8261 * to store image data. If the icon has no image data,
8262 * the return value will be %GTK_IMAGE_EMPTY.
8264 * Return value: image representation being used
8269 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8270 GtkEntryIconPosition icon_pos)
8272 GtkEntryPrivate *priv;
8273 EntryIconInfo *icon_info;
8275 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8276 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8280 icon_info = priv->icons[icon_pos];
8283 return GTK_IMAGE_EMPTY;
8285 return icon_info->storage_type;
8289 * gtk_entry_get_icon_at_pos:
8290 * @entry: a #GtkEntry
8291 * @x: the x coordinate of the position to find
8292 * @y: the y coordinate of the position to find
8294 * Finds the icon at the given position and return its index. The
8295 * position's coordinates are relative to the @entry's top left corner.
8296 * If @x, @y doesn't lie inside an icon, -1 is returned.
8297 * This function is intended for use in a #GtkWidget::query-tooltip
8300 * Returns: the index of the icon at the given position, or -1
8305 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8309 GtkAllocation primary;
8310 GtkAllocation secondary;
8311 gint frame_x, frame_y;
8313 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8315 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8319 get_icon_allocations (entry, &primary, &secondary);
8321 if (primary.x <= x && x < primary.x + primary.width &&
8322 primary.y <= y && y < primary.y + primary.height)
8323 return GTK_ENTRY_ICON_PRIMARY;
8325 if (secondary.x <= x && x < secondary.x + secondary.width &&
8326 secondary.y <= y && y < secondary.y + secondary.height)
8327 return GTK_ENTRY_ICON_SECONDARY;
8333 * gtk_entry_set_icon_drag_source:
8334 * @entry: a #GtkIconEntry
8335 * @icon_pos: icon position
8336 * @target_list: the targets (data formats) in which the data can be provided
8337 * @actions: a bitmask of the allowed drag actions
8339 * Sets up the icon at the given position so that GTK+ will start a drag
8340 * operation when the user clicks and drags the icon.
8342 * To handle the drag operation, you need to connect to the usual
8343 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8344 * signal, and use gtk_entry_get_current_icon_drag_source() in
8345 * your signal handler to find out if the drag was started from
8348 * By default, GTK+ uses the icon as the drag icon. You can use the
8349 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8350 * have to use g_signal_connect_after() to ensure that your signal handler
8351 * gets executed after the default handler.
8356 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8357 GtkEntryIconPosition icon_pos,
8358 GtkTargetList *target_list,
8359 GdkDragAction actions)
8361 GtkEntryPrivate *priv;
8362 EntryIconInfo *icon_info;
8364 g_return_if_fail (GTK_IS_ENTRY (entry));
8365 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8369 if ((icon_info = priv->icons[icon_pos]) == NULL)
8370 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8372 if (icon_info->target_list)
8373 gtk_target_list_unref (icon_info->target_list);
8374 icon_info->target_list = target_list;
8375 if (icon_info->target_list)
8376 gtk_target_list_ref (icon_info->target_list);
8378 icon_info->actions = actions;
8382 * gtk_entry_get_current_icon_drag_source:
8383 * @entry: a #GtkIconEntry
8385 * Returns the index of the icon which is the source of the current
8386 * DND operation, or -1.
8388 * This function is meant to be used in a #GtkWidget::drag-data-get
8391 * Returns: index of the icon which is the source of the current
8392 * DND operation, or -1.
8397 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8399 GtkEntryPrivate *priv;
8400 EntryIconInfo *icon_info = NULL;
8403 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8407 for (i = 0; i < MAX_ICONS; i++)
8409 if ((icon_info = priv->icons[i]))
8411 if (icon_info->in_drag)
8420 * gtk_entry_get_icon_area:
8421 * @entry: A #GtkEntry
8422 * @icon_pos: Icon position
8423 * @icon_area: (out): Return location for the icon's area
8425 * Gets the area where entry's icon at @icon_pos is drawn.
8426 * This function is useful when drawing something to the
8427 * entry in a draw callback.
8429 * If the entry is not realized or has no icon at the given position,
8430 * @icon_area is filled with zeros.
8432 * See also gtk_entry_get_text_area()
8437 gtk_entry_get_icon_area (GtkEntry *entry,
8438 GtkEntryIconPosition icon_pos,
8439 GdkRectangle *icon_area)
8441 GtkEntryPrivate *priv;
8442 EntryIconInfo *icon_info;
8444 g_return_if_fail (GTK_IS_ENTRY (entry));
8445 g_return_if_fail (icon_area != NULL);
8449 icon_info = priv->icons[icon_pos];
8453 GtkAllocation primary;
8454 GtkAllocation secondary;
8456 get_icon_allocations (entry, &primary, &secondary);
8458 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8459 *icon_area = primary;
8461 *icon_area = secondary;
8467 icon_area->width = 0;
8468 icon_area->height = 0;
8473 ensure_has_tooltip (GtkEntry *entry)
8475 GtkEntryPrivate *priv;
8476 EntryIconInfo *icon_info;
8478 gboolean has_tooltip = FALSE;
8482 for (i = 0; i < MAX_ICONS; i++)
8484 if ((icon_info = priv->icons[i]) != NULL)
8486 if (icon_info->tooltip != NULL)
8494 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8498 * gtk_entry_get_icon_tooltip_text:
8499 * @entry: a #GtkEntry
8500 * @icon_pos: the icon position
8502 * Gets the contents of the tooltip on the icon at the specified
8503 * position in @entry.
8505 * Returns: the tooltip text, or %NULL. Free the returned string
8506 * with g_free() when done.
8511 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8512 GtkEntryIconPosition icon_pos)
8514 GtkEntryPrivate *priv;
8515 EntryIconInfo *icon_info;
8518 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8519 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8523 icon_info = priv->icons[icon_pos];
8528 if (icon_info->tooltip &&
8529 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8530 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8536 * gtk_entry_set_icon_tooltip_text:
8537 * @entry: a #GtkEntry
8538 * @icon_pos: the icon position
8539 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8541 * Sets @tooltip as the contents of the tooltip for the icon
8542 * at the specified position.
8544 * Use %NULL for @tooltip to remove an existing tooltip.
8546 * See also gtk_widget_set_tooltip_text() and
8547 * gtk_entry_set_icon_tooltip_markup().
8552 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8553 GtkEntryIconPosition icon_pos,
8554 const gchar *tooltip)
8556 GtkEntryPrivate *priv;
8557 EntryIconInfo *icon_info;
8559 g_return_if_fail (GTK_IS_ENTRY (entry));
8560 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8564 if ((icon_info = priv->icons[icon_pos]) == NULL)
8565 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8567 if (icon_info->tooltip)
8568 g_free (icon_info->tooltip);
8570 /* Treat an empty string as a NULL string,
8571 * because an empty string would be useless for a tooltip:
8573 if (tooltip && tooltip[0] == '\0')
8576 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8578 ensure_has_tooltip (entry);
8582 * gtk_entry_get_icon_tooltip_markup:
8583 * @entry: a #GtkEntry
8584 * @icon_pos: the icon position
8586 * Gets the contents of the tooltip on the icon at the specified
8587 * position in @entry.
8589 * Returns: the tooltip text, or %NULL. Free the returned string
8590 * with g_free() when done.
8595 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8596 GtkEntryIconPosition icon_pos)
8598 GtkEntryPrivate *priv;
8599 EntryIconInfo *icon_info;
8601 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8602 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8606 icon_info = priv->icons[icon_pos];
8611 return g_strdup (icon_info->tooltip);
8615 * gtk_entry_set_icon_tooltip_markup:
8616 * @entry: a #GtkEntry
8617 * @icon_pos: the icon position
8618 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8620 * Sets @tooltip as the contents of the tooltip for the icon at
8621 * the specified position. @tooltip is assumed to be marked up with
8622 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8624 * Use %NULL for @tooltip to remove an existing tooltip.
8626 * See also gtk_widget_set_tooltip_markup() and
8627 * gtk_enty_set_icon_tooltip_text().
8632 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8633 GtkEntryIconPosition icon_pos,
8634 const gchar *tooltip)
8636 GtkEntryPrivate *priv;
8637 EntryIconInfo *icon_info;
8639 g_return_if_fail (GTK_IS_ENTRY (entry));
8640 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8644 if ((icon_info = priv->icons[icon_pos]) == NULL)
8645 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8647 if (icon_info->tooltip)
8648 g_free (icon_info->tooltip);
8650 /* Treat an empty string as a NULL string,
8651 * because an empty string would be useless for a tooltip:
8653 if (tooltip && tooltip[0] == '\0')
8656 icon_info->tooltip = g_strdup (tooltip);
8658 ensure_has_tooltip (entry);
8662 gtk_entry_query_tooltip (GtkWidget *widget,
8665 gboolean keyboard_tip,
8666 GtkTooltip *tooltip)
8669 GtkEntryPrivate *priv;
8670 EntryIconInfo *icon_info;
8673 entry = GTK_ENTRY (widget);
8678 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8681 if ((icon_info = priv->icons[icon_pos]) != NULL)
8683 if (icon_info->tooltip)
8685 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8694 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8701 /* Quick hack of a popup menu
8704 activate_cb (GtkWidget *menuitem,
8707 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8708 g_signal_emit_by_name (entry, signal);
8713 gtk_entry_mnemonic_activate (GtkWidget *widget,
8714 gboolean group_cycling)
8716 gtk_widget_grab_focus (widget);
8721 append_action_signal (GtkEntry *entry,
8723 const gchar *stock_id,
8724 const gchar *signal,
8727 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8729 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8730 g_signal_connect (menuitem, "activate",
8731 G_CALLBACK (activate_cb), entry);
8733 gtk_widget_set_sensitive (menuitem, sensitive);
8735 gtk_widget_show (menuitem);
8736 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8740 popup_menu_detach (GtkWidget *attach_widget,
8743 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8744 GtkEntryPrivate *priv_attach = entry_attach->priv;
8746 priv_attach->popup_menu = NULL;
8750 popup_position_func (GtkMenu *menu,
8756 GtkEntry *entry = GTK_ENTRY (user_data);
8757 GtkEntryPrivate *priv = entry->priv;
8758 GtkWidget *widget = GTK_WIDGET (entry);
8760 GtkRequisition menu_req;
8761 GdkRectangle monitor;
8762 GtkBorder inner_border;
8763 gint monitor_num, strong_x, height;
8765 g_return_if_fail (gtk_widget_get_realized (widget));
8767 gdk_window_get_origin (priv->text_area, x, y);
8769 screen = gtk_widget_get_screen (widget);
8770 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8771 if (monitor_num < 0)
8773 gtk_menu_set_monitor (menu, monitor_num);
8775 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8776 gtk_widget_get_preferred_size (priv->popup_menu,
8778 height = gdk_window_get_height (priv->text_area);
8779 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8780 _gtk_entry_effective_inner_border (entry, &inner_border);
8782 *x += inner_border.left + strong_x - priv->scroll_offset;
8783 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8784 *x -= menu_req.width;
8786 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8788 else if ((*y - menu_req.height) >= monitor.y)
8789 *y -= menu_req.height;
8790 else if (monitor.y + monitor.height - (*y + height) > *y)
8793 *y -= menu_req.height;
8799 unichar_chosen_func (const char *text,
8802 GtkEntry *entry = GTK_ENTRY (data);
8803 GtkEntryPrivate *priv = entry->priv;
8806 gtk_entry_enter_text (entry, text);
8817 popup_targets_received (GtkClipboard *clipboard,
8818 GtkSelectionData *data,
8821 PopupInfo *info = user_data;
8822 GtkEntry *entry = info->entry;
8823 GtkEntryPrivate *info_entry_priv = entry->priv;
8825 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8828 gboolean clipboard_contains_text;
8829 GtkWidget *menuitem;
8831 gboolean show_input_method_menu;
8832 gboolean show_unicode_menu;
8834 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8835 if (info_entry_priv->popup_menu)
8836 gtk_widget_destroy (info_entry_priv->popup_menu);
8838 info_entry_priv->popup_menu = gtk_menu_new ();
8840 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8844 mode = gtk_entry_get_display_mode (entry);
8845 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8846 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8847 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8849 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8850 mode == DISPLAY_NORMAL &&
8851 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8853 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8854 info_entry_priv->editable && clipboard_contains_text);
8856 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8857 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8858 g_signal_connect_swapped (menuitem, "activate",
8859 G_CALLBACK (gtk_entry_delete_cb), entry);
8860 gtk_widget_show (menuitem);
8861 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8863 menuitem = gtk_separator_menu_item_new ();
8864 gtk_widget_show (menuitem);
8865 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8867 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8868 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8869 g_signal_connect_swapped (menuitem, "activate",
8870 G_CALLBACK (gtk_entry_select_all), entry);
8871 gtk_widget_show (menuitem);
8872 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8874 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8875 "gtk-show-input-method-menu", &show_input_method_menu,
8876 "gtk-show-unicode-menu", &show_unicode_menu,
8879 if (show_input_method_menu || show_unicode_menu)
8881 menuitem = gtk_separator_menu_item_new ();
8882 gtk_widget_show (menuitem);
8883 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8886 if (show_input_method_menu)
8888 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8889 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8890 gtk_widget_show (menuitem);
8891 submenu = gtk_menu_new ();
8892 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8894 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8896 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8897 GTK_MENU_SHELL (submenu));
8900 if (show_unicode_menu)
8902 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8903 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8904 gtk_widget_show (menuitem);
8906 submenu = gtk_menu_new ();
8907 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8908 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8910 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8911 unichar_chosen_func,
8915 g_signal_emit (entry,
8916 signals[POPULATE_POPUP],
8918 info_entry_priv->popup_menu);
8922 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8924 info->button, info->time);
8927 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8928 popup_position_func, entry,
8929 info->button, info->time);
8930 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8934 g_object_unref (entry);
8935 g_slice_free (PopupInfo, info);
8939 gtk_entry_do_popup (GtkEntry *entry,
8940 GdkEventButton *event)
8942 PopupInfo *info = g_slice_new (PopupInfo);
8944 /* In order to know what entries we should make sensitive, we
8945 * ask for the current targets of the clipboard, and when
8946 * we get them, then we actually pop up the menu.
8948 info->entry = g_object_ref (entry);
8952 info->button = event->button;
8953 info->time = event->time;
8958 info->time = gtk_get_current_event_time ();
8961 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8962 gdk_atom_intern_static_string ("TARGETS"),
8963 popup_targets_received,
8968 gtk_entry_popup_menu (GtkWidget *widget)
8970 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8975 gtk_entry_drag_begin (GtkWidget *widget,
8976 GdkDragContext *context)
8978 GtkEntry *entry = GTK_ENTRY (widget);
8979 GtkEntryPrivate *priv = entry->priv;
8982 for (i = 0; i < MAX_ICONS; i++)
8984 EntryIconInfo *icon_info = priv->icons[i];
8986 if (icon_info != NULL)
8988 if (icon_info->in_drag)
8990 switch (icon_info->storage_type)
8992 case GTK_IMAGE_STOCK:
8993 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8996 case GTK_IMAGE_ICON_NAME:
8997 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
9000 /* FIXME: No GIcon support for dnd icons */
9001 case GTK_IMAGE_GICON:
9002 case GTK_IMAGE_PIXBUF:
9003 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
9006 g_assert_not_reached ();
9014 gtk_entry_drag_end (GtkWidget *widget,
9015 GdkDragContext *context)
9017 GtkEntry *entry = GTK_ENTRY (widget);
9018 GtkEntryPrivate *priv = entry->priv;
9021 for (i = 0; i < MAX_ICONS; i++)
9023 EntryIconInfo *icon_info = priv->icons[i];
9025 if (icon_info != NULL)
9026 icon_info->in_drag = 0;
9031 gtk_entry_drag_leave (GtkWidget *widget,
9032 GdkDragContext *context,
9035 GtkEntry *entry = GTK_ENTRY (widget);
9036 GtkEntryPrivate *priv = entry->priv;
9038 priv->dnd_position = -1;
9039 gtk_widget_queue_draw (widget);
9043 gtk_entry_drag_drop (GtkWidget *widget,
9044 GdkDragContext *context,
9049 GtkEntry *entry = GTK_ENTRY (widget);
9050 GtkEntryPrivate *priv = entry->priv;
9051 GdkAtom target = GDK_NONE;
9054 target = gtk_drag_dest_find_target (widget, context, NULL);
9056 if (target != GDK_NONE)
9057 gtk_drag_get_data (widget, context, target, time);
9059 gtk_drag_finish (context, FALSE, FALSE, time);
9065 gtk_entry_drag_motion (GtkWidget *widget,
9066 GdkDragContext *context,
9071 GtkEntry *entry = GTK_ENTRY (widget);
9072 GtkEntryPrivate *priv = entry->priv;
9073 GtkStyleContext *style_context;
9074 GtkWidget *source_widget;
9075 GdkDragAction suggested_action;
9076 gint new_position, old_position;
9080 style_context = gtk_widget_get_style_context (widget);
9081 gtk_style_context_get_padding (style_context, 0, &padding);
9085 old_position = priv->dnd_position;
9086 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9088 if (priv->editable &&
9089 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9091 source_widget = gtk_drag_get_source_widget (context);
9092 suggested_action = gdk_drag_context_get_suggested_action (context);
9094 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9095 new_position < sel1 || new_position > sel2)
9097 if (source_widget == widget)
9099 /* Default to MOVE, unless the user has
9100 * pressed ctrl or alt to affect available actions
9102 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9103 suggested_action = GDK_ACTION_MOVE;
9106 priv->dnd_position = new_position;
9110 if (source_widget == widget)
9111 suggested_action = 0; /* Can't drop in selection where drag started */
9113 priv->dnd_position = -1;
9118 /* Entry not editable, or no text */
9119 suggested_action = 0;
9120 priv->dnd_position = -1;
9123 gdk_drag_status (context, suggested_action, time);
9125 if (priv->dnd_position != old_position)
9126 gtk_widget_queue_draw (widget);
9132 gtk_entry_drag_data_received (GtkWidget *widget,
9133 GdkDragContext *context,
9136 GtkSelectionData *selection_data,
9140 GtkEntry *entry = GTK_ENTRY (widget);
9141 GtkEntryPrivate *priv = entry->priv;
9142 GtkEditable *editable = GTK_EDITABLE (widget);
9143 GtkStyleContext *style_context;
9147 str = (gchar *) gtk_selection_data_get_text (selection_data);
9149 style_context = gtk_widget_get_style_context (widget);
9150 gtk_style_context_get_padding (style_context, 0, &padding);
9154 if (str && priv->editable)
9160 if (priv->truncate_multiline)
9161 length = truncate_multiline (str);
9163 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9165 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9166 new_position < sel1 || new_position > sel2)
9168 gtk_editable_insert_text (editable, str, length, &new_position);
9172 /* Replacing selection */
9173 begin_change (entry);
9174 g_object_freeze_notify (G_OBJECT (entry));
9175 gtk_editable_delete_text (editable, sel1, sel2);
9176 gtk_editable_insert_text (editable, str, length, &sel1);
9177 g_object_thaw_notify (G_OBJECT (entry));
9181 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9185 /* Drag and drop didn't happen! */
9186 gtk_drag_finish (context, FALSE, FALSE, time);
9193 gtk_entry_drag_data_get (GtkWidget *widget,
9194 GdkDragContext *context,
9195 GtkSelectionData *selection_data,
9199 GtkEntry *entry = GTK_ENTRY (widget);
9200 GtkEntryPrivate *priv = entry->priv;
9201 GtkEditable *editable = GTK_EDITABLE (widget);
9202 gint sel_start, sel_end;
9205 /* If there is an icon drag going on, exit early. */
9206 for (i = 0; i < MAX_ICONS; i++)
9208 EntryIconInfo *icon_info = priv->icons[i];
9210 if (icon_info != NULL)
9212 if (icon_info->in_drag)
9217 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9219 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9221 gtk_selection_data_set_text (selection_data, str, -1);
9229 gtk_entry_drag_data_delete (GtkWidget *widget,
9230 GdkDragContext *context)
9232 GtkEntry *entry = GTK_ENTRY (widget);
9233 GtkEntryPrivate *priv = entry->priv;
9234 GtkEditable *editable = GTK_EDITABLE (widget);
9235 gint sel_start, sel_end;
9238 /* If there is an icon drag going on, exit early. */
9239 for (i = 0; i < MAX_ICONS; i++)
9241 EntryIconInfo *icon_info = priv->icons[i];
9243 if (icon_info != NULL)
9245 if (icon_info->in_drag)
9250 if (priv->editable &&
9251 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9252 gtk_editable_delete_text (editable, sel_start, sel_end);
9255 /* We display the cursor when
9257 * - the selection is empty, AND
9258 * - the widget has focus
9261 #define CURSOR_ON_MULTIPLIER 2
9262 #define CURSOR_OFF_MULTIPLIER 1
9263 #define CURSOR_PEND_MULTIPLIER 3
9264 #define CURSOR_DIVIDER 3
9267 cursor_blinks (GtkEntry *entry)
9269 GtkEntryPrivate *priv = entry->priv;
9271 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9273 priv->selection_bound == priv->current_pos)
9275 GtkSettings *settings;
9278 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9279 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9288 get_cursor_time (GtkEntry *entry)
9290 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9293 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9299 get_cursor_blink_timeout (GtkEntry *entry)
9301 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9304 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9310 show_cursor (GtkEntry *entry)
9312 GtkEntryPrivate *priv = entry->priv;
9315 if (!priv->cursor_visible)
9317 priv->cursor_visible = TRUE;
9319 widget = GTK_WIDGET (entry);
9320 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9321 gtk_widget_queue_draw (widget);
9326 hide_cursor (GtkEntry *entry)
9328 GtkEntryPrivate *priv = entry->priv;
9331 if (priv->cursor_visible)
9333 priv->cursor_visible = FALSE;
9335 widget = GTK_WIDGET (entry);
9336 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9337 gtk_widget_queue_draw (widget);
9345 blink_cb (gpointer data)
9348 GtkEntryPrivate *priv;
9351 entry = GTK_ENTRY (data);
9354 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9356 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9357 "connect a handler to this signal, it must return\n"
9358 "FALSE so the entry gets the event as well");
9360 gtk_entry_check_cursor_blink (entry);
9365 g_assert (priv->selection_bound == priv->current_pos);
9367 blink_timeout = get_cursor_blink_timeout (entry);
9368 if (priv->blink_time > 1000 * blink_timeout &&
9369 blink_timeout < G_MAXINT/1000)
9371 /* we've blinked enough without the user doing anything, stop blinking */
9372 show_cursor (entry);
9373 priv->blink_timeout = 0;
9375 else if (priv->cursor_visible)
9377 hide_cursor (entry);
9378 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9384 show_cursor (entry);
9385 priv->blink_time += get_cursor_time (entry);
9386 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9391 /* Remove ourselves */
9396 gtk_entry_check_cursor_blink (GtkEntry *entry)
9398 GtkEntryPrivate *priv = entry->priv;
9400 if (cursor_blinks (entry))
9402 if (!priv->blink_timeout)
9404 show_cursor (entry);
9405 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9412 if (priv->blink_timeout)
9414 g_source_remove (priv->blink_timeout);
9415 priv->blink_timeout = 0;
9418 priv->cursor_visible = TRUE;
9423 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9425 GtkEntryPrivate *priv = entry->priv;
9427 if (cursor_blinks (entry))
9429 if (priv->blink_timeout != 0)
9430 g_source_remove (priv->blink_timeout);
9432 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9435 show_cursor (entry);
9440 gtk_entry_reset_blink_time (GtkEntry *entry)
9442 GtkEntryPrivate *priv = entry->priv;
9444 priv->blink_time = 0;
9450 gtk_entry_completion_timeout (gpointer data)
9452 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9453 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9455 completion->priv->completion_timeout = 0;
9457 if (completion->priv->filter_model &&
9458 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9459 >= completion->priv->minimum_key_length)
9463 GtkTreeSelection *s;
9464 gboolean popup_single;
9466 gtk_entry_completion_complete (completion);
9467 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9469 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9471 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9473 gtk_tree_selection_unselect_all (s);
9475 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9477 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9478 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9480 if (gtk_widget_get_visible (completion->priv->popup_window))
9481 _gtk_entry_completion_resize_popup (completion);
9483 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9486 _gtk_entry_completion_popdown (completion);
9488 else if (gtk_widget_get_visible (completion->priv->popup_window))
9489 _gtk_entry_completion_popdown (completion);
9494 static inline gboolean
9495 keyval_is_cursor_move (guint keyval)
9497 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9500 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9503 if (keyval == GDK_KEY_Page_Up)
9506 if (keyval == GDK_KEY_Page_Down)
9513 gtk_entry_completion_key_press (GtkWidget *widget,
9517 gint matches, actions = 0;
9518 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9520 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9523 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9525 if (completion->priv->actions)
9526 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9528 if (keyval_is_cursor_move (event->keyval))
9530 GtkTreePath *path = NULL;
9532 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9534 if (completion->priv->current_selected < 0)
9535 completion->priv->current_selected = matches + actions - 1;
9537 completion->priv->current_selected--;
9539 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9541 if (completion->priv->current_selected < matches + actions - 1)
9542 completion->priv->current_selected++;
9544 completion->priv->current_selected = -1;
9546 else if (event->keyval == GDK_KEY_Page_Up)
9548 if (completion->priv->current_selected < 0)
9549 completion->priv->current_selected = matches + actions - 1;
9550 else if (completion->priv->current_selected == 0)
9551 completion->priv->current_selected = -1;
9552 else if (completion->priv->current_selected < matches)
9554 completion->priv->current_selected -= 14;
9555 if (completion->priv->current_selected < 0)
9556 completion->priv->current_selected = 0;
9560 completion->priv->current_selected -= 14;
9561 if (completion->priv->current_selected < matches - 1)
9562 completion->priv->current_selected = matches - 1;
9565 else if (event->keyval == GDK_KEY_Page_Down)
9567 if (completion->priv->current_selected < 0)
9568 completion->priv->current_selected = 0;
9569 else if (completion->priv->current_selected < matches - 1)
9571 completion->priv->current_selected += 14;
9572 if (completion->priv->current_selected > matches - 1)
9573 completion->priv->current_selected = matches - 1;
9575 else if (completion->priv->current_selected == matches + actions - 1)
9577 completion->priv->current_selected = -1;
9581 completion->priv->current_selected += 14;
9582 if (completion->priv->current_selected > matches + actions - 1)
9583 completion->priv->current_selected = matches + actions - 1;
9587 if (completion->priv->current_selected < 0)
9589 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9590 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9592 if (completion->priv->inline_selection &&
9593 completion->priv->completion_prefix)
9595 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9596 completion->priv->completion_prefix);
9597 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9600 else if (completion->priv->current_selected < matches)
9602 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9604 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9605 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9608 if (completion->priv->inline_selection)
9612 GtkTreeIter child_iter;
9613 GtkTreeModel *model = NULL;
9614 GtkTreeSelection *sel;
9617 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9618 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9621 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9622 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9624 if (completion->priv->completion_prefix == NULL)
9625 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9627 g_signal_emit_by_name (completion, "cursor-on-match", model,
9628 &child_iter, &entry_set);
9631 else if (completion->priv->current_selected - matches >= 0)
9633 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9635 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9636 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9639 if (completion->priv->inline_selection &&
9640 completion->priv->completion_prefix)
9642 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9643 completion->priv->completion_prefix);
9644 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9648 gtk_tree_path_free (path);
9652 else if (event->keyval == GDK_KEY_Escape ||
9653 event->keyval == GDK_KEY_Left ||
9654 event->keyval == GDK_KEY_KP_Left ||
9655 event->keyval == GDK_KEY_Right ||
9656 event->keyval == GDK_KEY_KP_Right)
9658 gboolean retval = TRUE;
9660 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9661 _gtk_entry_completion_popdown (completion);
9663 if (completion->priv->current_selected < 0)
9666 goto keypress_completion_out;
9668 else if (completion->priv->inline_selection)
9670 /* Escape rejects the tentative completion */
9671 if (event->keyval == GDK_KEY_Escape)
9673 if (completion->priv->completion_prefix)
9674 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9675 completion->priv->completion_prefix);
9677 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9680 /* Move the cursor to the end for Right/Esc, to the
9681 beginning for Left */
9682 if (event->keyval == GDK_KEY_Right ||
9683 event->keyval == GDK_KEY_KP_Right ||
9684 event->keyval == GDK_KEY_Escape)
9685 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9687 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9690 keypress_completion_out:
9691 if (completion->priv->inline_selection)
9693 g_free (completion->priv->completion_prefix);
9694 completion->priv->completion_prefix = NULL;
9699 else if (event->keyval == GDK_KEY_Tab ||
9700 event->keyval == GDK_KEY_KP_Tab ||
9701 event->keyval == GDK_KEY_ISO_Left_Tab)
9703 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9704 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9706 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9707 _gtk_entry_completion_popdown (completion);
9709 g_free (completion->priv->completion_prefix);
9710 completion->priv->completion_prefix = NULL;
9712 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9716 else if (event->keyval == GDK_KEY_ISO_Enter ||
9717 event->keyval == GDK_KEY_KP_Enter ||
9718 event->keyval == GDK_KEY_Return)
9721 GtkTreeModel *model = NULL;
9722 GtkTreeModel *child_model;
9723 GtkTreeIter child_iter;
9724 GtkTreeSelection *sel;
9725 gboolean retval = TRUE;
9727 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9728 _gtk_entry_completion_popdown (completion);
9730 if (completion->priv->current_selected < matches)
9734 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9735 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9737 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9738 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9739 g_signal_handler_block (widget, completion->priv->changed_id);
9740 g_signal_emit_by_name (completion, "match-selected",
9741 child_model, &child_iter, &entry_set);
9742 g_signal_handler_unblock (widget, completion->priv->changed_id);
9748 gtk_tree_model_get (model, &iter,
9749 completion->priv->text_column, &str,
9752 gtk_entry_set_text (GTK_ENTRY (widget), str);
9754 /* move the cursor to the end */
9755 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9763 else if (completion->priv->current_selected - matches >= 0)
9765 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9766 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9770 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9771 g_signal_emit_by_name (completion, "action-activated",
9772 gtk_tree_path_get_indices (path)[0]);
9773 gtk_tree_path_free (path);
9779 g_free (completion->priv->completion_prefix);
9780 completion->priv->completion_prefix = NULL;
9789 gtk_entry_completion_changed (GtkWidget *widget,
9792 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9793 GtkEntry *entry = GTK_ENTRY (widget);
9794 GtkEntryPrivate *priv = entry->priv;
9797 /* (re)install completion timeout */
9798 if (completion->priv->completion_timeout)
9799 g_source_remove (completion->priv->completion_timeout);
9801 if (!gtk_entry_get_text (entry))
9804 /* no need to normalize for this test */
9805 if (completion->priv->minimum_key_length > 0 &&
9806 strcmp ("", gtk_entry_get_text (entry)) == 0)
9808 if (gtk_widget_get_visible (completion->priv->popup_window))
9809 _gtk_entry_completion_popdown (completion);
9813 device = gtk_get_current_event_device ();
9815 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9816 device = gdk_device_get_associated_device (device);
9819 priv->completion_device = device;
9821 completion->priv->completion_timeout =
9822 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9823 gtk_entry_completion_timeout,
9828 check_completion_callback (GtkEntryCompletion *completion)
9830 completion->priv->check_completion_idle = NULL;
9832 gtk_entry_completion_complete (completion);
9833 gtk_entry_completion_insert_prefix (completion);
9839 clear_completion_callback (GtkEntry *entry,
9842 if (pspec->name == I_("cursor-position") ||
9843 pspec->name == I_("selection-bound"))
9845 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9847 completion->priv->has_completion = FALSE;
9852 accept_completion_callback (GtkEntry *entry)
9854 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9856 if (completion->priv->has_completion)
9857 gtk_editable_set_position (GTK_EDITABLE (entry),
9858 gtk_entry_buffer_get_length (get_buffer (entry)));
9864 completion_insert_text_callback (GtkEntry *entry,
9868 GtkEntryCompletion *completion)
9870 /* idle to update the selection based on the file list */
9871 if (completion->priv->check_completion_idle == NULL)
9873 completion->priv->check_completion_idle = g_idle_source_new ();
9874 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9875 g_source_set_closure (completion->priv->check_completion_idle,
9876 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9877 G_OBJECT (completion)));
9878 g_source_attach (completion->priv->check_completion_idle, NULL);
9883 completion_changed (GtkEntryCompletion *completion,
9887 GtkEntry *entry = GTK_ENTRY (data);
9889 if (pspec->name == I_("popup-completion") ||
9890 pspec->name == I_("inline-completion"))
9892 disconnect_completion_signals (entry, completion);
9893 connect_completion_signals (entry, completion);
9898 disconnect_completion_signals (GtkEntry *entry,
9899 GtkEntryCompletion *completion)
9901 g_signal_handlers_disconnect_by_func (completion,
9902 G_CALLBACK (completion_changed), entry);
9903 if (completion->priv->changed_id > 0 &&
9904 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9906 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9907 completion->priv->changed_id = 0;
9909 g_signal_handlers_disconnect_by_func (entry,
9910 G_CALLBACK (gtk_entry_completion_key_press), completion);
9911 if (completion->priv->insert_text_id > 0 &&
9912 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9914 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9915 completion->priv->insert_text_id = 0;
9917 g_signal_handlers_disconnect_by_func (entry,
9918 G_CALLBACK (completion_insert_text_callback), completion);
9919 g_signal_handlers_disconnect_by_func (entry,
9920 G_CALLBACK (clear_completion_callback), completion);
9921 g_signal_handlers_disconnect_by_func (entry,
9922 G_CALLBACK (accept_completion_callback), completion);
9926 connect_completion_signals (GtkEntry *entry,
9927 GtkEntryCompletion *completion)
9929 if (completion->priv->popup_completion)
9931 completion->priv->changed_id =
9932 g_signal_connect (entry, "changed",
9933 G_CALLBACK (gtk_entry_completion_changed), completion);
9934 g_signal_connect (entry, "key-press-event",
9935 G_CALLBACK (gtk_entry_completion_key_press), completion);
9938 if (completion->priv->inline_completion)
9940 completion->priv->insert_text_id =
9941 g_signal_connect (entry, "insert-text",
9942 G_CALLBACK (completion_insert_text_callback), completion);
9943 g_signal_connect (entry, "notify",
9944 G_CALLBACK (clear_completion_callback), completion);
9945 g_signal_connect (entry, "activate",
9946 G_CALLBACK (accept_completion_callback), completion);
9947 g_signal_connect (entry, "focus-out-event",
9948 G_CALLBACK (accept_completion_callback), completion);
9951 g_signal_connect (completion, "notify",
9952 G_CALLBACK (completion_changed), entry);
9956 * gtk_entry_set_completion:
9957 * @entry: A #GtkEntry
9958 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9960 * Sets @completion to be the auxiliary completion object to use with @entry.
9961 * All further configuration of the completion mechanism is done on
9962 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9963 * @completion is set to %NULL.
9968 gtk_entry_set_completion (GtkEntry *entry,
9969 GtkEntryCompletion *completion)
9971 GtkEntryCompletion *old;
9973 g_return_if_fail (GTK_IS_ENTRY (entry));
9974 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9976 old = gtk_entry_get_completion (entry);
9978 if (old == completion)
9983 if (old->priv->completion_timeout)
9985 g_source_remove (old->priv->completion_timeout);
9986 old->priv->completion_timeout = 0;
9989 if (old->priv->check_completion_idle)
9991 g_source_destroy (old->priv->check_completion_idle);
9992 old->priv->check_completion_idle = NULL;
9995 if (gtk_widget_get_mapped (old->priv->popup_window))
9996 _gtk_entry_completion_popdown (old);
9998 disconnect_completion_signals (entry, old);
9999 old->priv->entry = NULL;
10001 g_object_unref (old);
10006 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
10010 /* hook into the entry */
10011 g_object_ref (completion);
10013 connect_completion_signals (entry, completion);
10014 completion->priv->entry = GTK_WIDGET (entry);
10015 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10017 g_object_notify (G_OBJECT (entry), "completion");
10021 * gtk_entry_get_completion:
10022 * @entry: A #GtkEntry
10024 * Returns the auxiliary completion object currently in use by @entry.
10026 * Return value: (transfer none): The auxiliary completion object currently
10027 * in use by @entry.
10031 GtkEntryCompletion *
10032 gtk_entry_get_completion (GtkEntry *entry)
10034 GtkEntryCompletion *completion;
10036 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10038 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10039 GTK_ENTRY_COMPLETION_KEY));
10045 * gtk_entry_set_cursor_hadjustment:
10046 * @entry: a #GtkEntry
10047 * @adjustment: an adjustment which should be adjusted when the cursor
10048 * is moved, or %NULL
10050 * Hooks up an adjustment to the cursor position in an entry, so that when
10051 * the cursor is moved, the adjustment is scrolled to show that position.
10052 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10055 * The adjustment has to be in pixel units and in the same coordinate system
10061 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10062 GtkAdjustment *adjustment)
10064 g_return_if_fail (GTK_IS_ENTRY (entry));
10066 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10069 g_object_ref (adjustment);
10071 g_object_set_qdata_full (G_OBJECT (entry),
10072 quark_cursor_hadjustment,
10078 * gtk_entry_get_cursor_hadjustment:
10079 * @entry: a #GtkEntry
10081 * Retrieves the horizontal cursor adjustment for the entry.
10082 * See gtk_entry_set_cursor_hadjustment().
10084 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10085 * if none has been set.
10090 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10092 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10094 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10098 * gtk_entry_set_progress_fraction:
10099 * @entry: a #GtkEntry
10100 * @fraction: fraction of the task that's been completed
10102 * Causes the entry's progress indicator to "fill in" the given
10103 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10109 gtk_entry_set_progress_fraction (GtkEntry *entry,
10113 GtkEntryPrivate *private;
10114 gdouble old_fraction;
10115 gint x, y, width, height;
10116 gint old_x, old_y, old_width, old_height;
10118 g_return_if_fail (GTK_IS_ENTRY (entry));
10120 widget = GTK_WIDGET (entry);
10121 private = entry->priv;
10123 if (private->progress_pulse_mode)
10126 old_fraction = private->progress_fraction;
10128 if (gtk_widget_is_drawable (widget))
10129 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10131 fraction = CLAMP (fraction, 0.0, 1.0);
10133 private->progress_fraction = fraction;
10134 private->progress_pulse_mode = FALSE;
10135 private->progress_pulse_current = 0.0;
10137 if (gtk_widget_is_drawable (widget))
10139 get_progress_area (widget, &x, &y, &width, &height);
10141 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10142 gtk_widget_queue_draw (widget);
10145 if (fraction != old_fraction)
10146 g_object_notify (G_OBJECT (entry), "progress-fraction");
10150 * gtk_entry_get_progress_fraction:
10151 * @entry: a #GtkEntry
10153 * Returns the current fraction of the task that's been completed.
10154 * See gtk_entry_set_progress_fraction().
10156 * Return value: a fraction from 0.0 to 1.0
10161 gtk_entry_get_progress_fraction (GtkEntry *entry)
10163 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10165 return entry->priv->progress_fraction;
10169 * gtk_entry_set_progress_pulse_step:
10170 * @entry: a #GtkEntry
10171 * @fraction: fraction between 0.0 and 1.0
10173 * Sets the fraction of total entry width to move the progress
10174 * bouncing block for each call to gtk_entry_progress_pulse().
10179 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10182 GtkEntryPrivate *private;
10184 g_return_if_fail (GTK_IS_ENTRY (entry));
10186 private = entry->priv;
10188 fraction = CLAMP (fraction, 0.0, 1.0);
10190 if (fraction != private->progress_pulse_fraction)
10192 private->progress_pulse_fraction = fraction;
10194 gtk_widget_queue_draw (GTK_WIDGET (entry));
10196 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10201 * gtk_entry_get_progress_pulse_step:
10202 * @entry: a #GtkEntry
10204 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10206 * Return value: a fraction from 0.0 to 1.0
10211 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10213 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10215 return entry->priv->progress_pulse_fraction;
10219 * gtk_entry_progress_pulse:
10220 * @entry: a #GtkEntry
10222 * Indicates that some progress is made, but you don't know how much.
10223 * Causes the entry's progress indicator to enter "activity mode,"
10224 * where a block bounces back and forth. Each call to
10225 * gtk_entry_progress_pulse() causes the block to move by a little bit
10226 * (the amount of movement per pulse is determined by
10227 * gtk_entry_set_progress_pulse_step()).
10232 gtk_entry_progress_pulse (GtkEntry *entry)
10234 GtkEntryPrivate *private;
10236 g_return_if_fail (GTK_IS_ENTRY (entry));
10238 private = entry->priv;
10240 if (private->progress_pulse_mode)
10242 if (private->progress_pulse_way_back)
10244 private->progress_pulse_current -= private->progress_pulse_fraction;
10246 if (private->progress_pulse_current < 0.0)
10248 private->progress_pulse_current = 0.0;
10249 private->progress_pulse_way_back = FALSE;
10254 private->progress_pulse_current += private->progress_pulse_fraction;
10256 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10258 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10259 private->progress_pulse_way_back = TRUE;
10265 private->progress_fraction = 0.0;
10266 private->progress_pulse_mode = TRUE;
10267 private->progress_pulse_way_back = FALSE;
10268 private->progress_pulse_current = 0.0;
10271 gtk_widget_queue_draw (GTK_WIDGET (entry));
10275 * gtk_entry_set_placeholder_text:
10276 * @entry: a #GtkEntry
10277 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10279 * Sets text to be displayed in @entry when
10280 * it is empty and unfocused. This can be used to give a visual hint
10281 * of the expected contents of the #GtkEntry.
10286 gtk_entry_set_placeholder_text (GtkEntry *entry,
10289 GtkEntryPrivate *priv;
10291 g_return_if_fail (GTK_IS_ENTRY (entry));
10293 priv = entry->priv;
10295 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10298 g_free (priv->placeholder_text);
10299 priv->placeholder_text = g_strdup (text);
10301 gtk_entry_recompute (entry);
10303 g_object_notify (G_OBJECT (entry), "placeholder-text");
10307 * gtk_entry_get_placeholder_text:
10308 * @entry: a #GtkEntry
10310 * Retrieves the text that will be displayed when @entry is empty and unfocused
10312 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10313 * storage in the widget and must not be freed, modified or stored.
10317 G_CONST_RETURN gchar *
10318 gtk_entry_get_placeholder_text (GtkEntry *entry)
10320 GtkEntryPrivate *priv;
10322 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10324 priv = entry->priv;
10326 return priv->placeholder_text;
10329 /* Caps Lock warning for password entries */
10332 show_capslock_feedback (GtkEntry *entry,
10335 GtkEntryPrivate *priv = entry->priv;
10337 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10339 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10340 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10341 priv->caps_lock_warning_shown = TRUE;
10344 if (priv->caps_lock_warning_shown)
10345 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10347 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10351 remove_capslock_feedback (GtkEntry *entry)
10353 GtkEntryPrivate *priv = entry->priv;
10355 if (priv->caps_lock_warning_shown)
10357 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10358 priv->caps_lock_warning_shown = FALSE;
10363 keymap_state_changed (GdkKeymap *keymap,
10366 GtkEntryPrivate *priv = entry->priv;
10369 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10371 if (gdk_keymap_get_num_lock_state (keymap)
10372 && gdk_keymap_get_caps_lock_state (keymap))
10373 text = _("Caps Lock and Num Lock are on");
10374 else if (gdk_keymap_get_num_lock_state (keymap))
10375 text = _("Num Lock is on");
10376 else if (gdk_keymap_get_caps_lock_state (keymap))
10377 text = _("Caps Lock is on");
10381 show_capslock_feedback (entry, text);
10383 remove_capslock_feedback (entry);
10387 * _gtk_entry_set_is_cell_renderer:
10388 * @entry: a #GtkEntry
10389 * @is_cell_renderer: new value
10391 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10392 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10394 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10398 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10399 gboolean is_cell_renderer)
10401 entry->priv->is_cell_renderer = is_cell_renderer;