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 "gtkiconhelperprivate.h"
43 #include "gtkimagemenuitem.h"
44 #include "gtkimcontextsimple.h"
45 #include "gtkimmulticontext.h"
49 #include "gtkmarshalers.h"
51 #include "gtkmenuitem.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkselection.h"
54 #include "gtksettings.h"
55 #include "gtkspinbutton.h"
57 #include "gtktextutil.h"
58 #include "gtkwindow.h"
59 #include "gtktreeview.h"
60 #include "gtktreeselection.h"
61 #include "gtktypebuiltins.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
68 #include "gtkwidgetprivate.h"
69 #include "gtkstylecontextprivate.h"
71 #include "a11y/gtkentryaccessible.h"
75 * @Short_description: A single line text entry field
77 * @See_also: #GtkTextView, #GtkEntryCompletion
79 * The #GtkEntry widget is a single line text entry
80 * widget. A fairly large set of key bindings are supported
81 * by default. If the entered text is longer than the allocation
82 * of the widget, the widget will scroll so that the cursor
83 * position is visible.
85 * When using an entry for passwords and other sensitive information,
86 * it can be put into "password mode" using gtk_entry_set_visibility().
87 * In this mode, entered text is displayed using a 'invisible' character.
88 * By default, GTK+ picks the best invisible character that is available
89 * in the current font, but it can be changed with
90 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
91 * when Caps Lock or input methods might interfere with entering text in
92 * a password entry. The warning can be turned off with the
93 * #GtkEntry:caps-lock-warning property.
95 * Since 2.16, GtkEntry has the ability to display progress or activity
96 * information behind the text. To make an entry display such information,
97 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
99 * Additionally, GtkEntry can show icons at either side of the entry. These
100 * icons can be activatable by clicking, can be set up as drag source and
101 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
102 * one of the various other functions that set an icon from a stock id, an
103 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
104 * connect to the #GtkEntry::icon-press signal. To allow DND operations
105 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
106 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
109 * Note that functionality or information that is only available by clicking
110 * on an icon in an entry may not be accessible at all to users which are not
111 * able to use a mouse or other pointing device. It is therefore recommended
112 * that any such functionality should also be available by other means, e.g.
113 * via the context menu of the entry.
117 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
119 #define MIN_ENTRY_WIDTH 150
120 #define DRAW_TIMEOUT 20
121 #define COMPLETION_TIMEOUT 300
122 #define PASSWORD_HINT_MAX 8
127 #define IS_VALID_ICON_POSITION(pos) \
128 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
129 (pos) == GTK_ENTRY_ICON_SECONDARY)
131 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
132 static GQuark quark_inner_border = 0;
133 static GQuark quark_password_hint = 0;
134 static GQuark quark_cursor_hadjustment = 0;
135 static GQuark quark_capslock_feedback = 0;
137 typedef struct _EntryIconInfo EntryIconInfo;
138 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
139 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
141 struct _GtkEntryPrivate
143 EntryIconInfo *icons[MAX_ICONS];
145 GtkEntryBuffer *buffer;
146 GtkIMContext *im_context;
147 GtkShadowType shadow_type;
148 GtkWidget *popup_menu;
150 GdkDevice *completion_device;
151 GdkWindow *text_area;
153 PangoLayout *cached_layout;
157 gdouble progress_fraction;
158 gdouble progress_pulse_fraction;
159 gdouble progress_pulse_current;
161 gchar *placeholder_text;
165 gint ascent; /* font ascent in pango units */
167 gint descent; /* font descent in pango units */
168 gint dnd_position; /* In chars, -1 == no DND cursor */
174 gint selection_bound;
180 gunichar invisible_char;
183 guint blink_time; /* time in msec the cursor has blinked since last user event */
185 guint recompute_idle;
187 guint16 x_text_size; /* allocated size, in bytes */
188 guint16 x_n_bytes; /* length in use, in bytes */
190 guint16 preedit_length; /* length of preedit string, in bytes */
191 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
195 guint overwrite_mode : 1;
198 guint activates_default : 1;
199 guint cache_includes_preedit : 1;
200 guint caps_lock_warning : 1;
201 guint caps_lock_warning_shown : 1;
202 guint change_count : 8;
203 guint cursor_visible : 1;
204 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
206 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
207 guint is_cell_renderer : 1;
208 guint invisible_char_set : 1;
209 guint interior_focus : 1;
210 guint mouse_cursor_obscured : 1;
211 guint need_im_reset : 1;
212 guint progress_pulse_mode : 1;
213 guint progress_pulse_way_back : 1;
214 guint real_changed : 1;
215 guint resolved_dir : 4; /* PangoDirection */
216 guint select_words : 1;
217 guint select_lines : 1;
218 guint truncate_multiline : 1;
221 struct _EntryIconInfo
225 guint insensitive : 1;
226 guint nonactivatable : 1;
231 GtkIconHelper *icon_helper;
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 GdkPixbuf * 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
995 g_object_class_install_property (gobject_class,
996 PROP_PLACEHOLDER_TEXT,
997 g_param_spec_string ("placeholder-text",
998 P_("Placeholder text"),
999 P_("Show text in the entry when it's empty and unfocused"),
1001 GTK_PARAM_READWRITE));
1004 * GtkEntry:primary-icon-pixbuf:
1006 * A pixbuf to use as the primary icon for the entry.
1010 g_object_class_install_property (gobject_class,
1011 PROP_PIXBUF_PRIMARY,
1012 g_param_spec_object ("primary-icon-pixbuf",
1013 P_("Primary pixbuf"),
1014 P_("Primary pixbuf for the entry"),
1016 GTK_PARAM_READWRITE));
1019 * GtkEntry:secondary-icon-pixbuf:
1021 * An pixbuf to use as the secondary icon for the entry.
1025 g_object_class_install_property (gobject_class,
1026 PROP_PIXBUF_SECONDARY,
1027 g_param_spec_object ("secondary-icon-pixbuf",
1028 P_("Secondary pixbuf"),
1029 P_("Secondary pixbuf for the entry"),
1031 GTK_PARAM_READWRITE));
1034 * GtkEntry:primary-icon-stock:
1036 * The stock id to use for the primary icon for the entry.
1040 g_object_class_install_property (gobject_class,
1042 g_param_spec_string ("primary-icon-stock",
1043 P_("Primary stock ID"),
1044 P_("Stock ID for primary icon"),
1046 GTK_PARAM_READWRITE));
1049 * GtkEntry:secondary-icon-stock:
1051 * The stock id to use for the secondary icon for the entry.
1055 g_object_class_install_property (gobject_class,
1056 PROP_STOCK_SECONDARY,
1057 g_param_spec_string ("secondary-icon-stock",
1058 P_("Secondary stock ID"),
1059 P_("Stock ID for secondary icon"),
1061 GTK_PARAM_READWRITE));
1064 * GtkEntry:primary-icon-name:
1066 * The icon name to use for the primary icon for the entry.
1070 g_object_class_install_property (gobject_class,
1071 PROP_ICON_NAME_PRIMARY,
1072 g_param_spec_string ("primary-icon-name",
1073 P_("Primary icon name"),
1074 P_("Icon name for primary icon"),
1076 GTK_PARAM_READWRITE));
1079 * GtkEntry:secondary-icon-name:
1081 * The icon name to use for the secondary icon for the entry.
1085 g_object_class_install_property (gobject_class,
1086 PROP_ICON_NAME_SECONDARY,
1087 g_param_spec_string ("secondary-icon-name",
1088 P_("Secondary icon name"),
1089 P_("Icon name for secondary icon"),
1091 GTK_PARAM_READWRITE));
1094 * GtkEntry:primary-icon-gicon:
1096 * The #GIcon to use for the primary icon for the entry.
1100 g_object_class_install_property (gobject_class,
1102 g_param_spec_object ("primary-icon-gicon",
1103 P_("Primary GIcon"),
1104 P_("GIcon for primary icon"),
1106 GTK_PARAM_READWRITE));
1109 * GtkEntry:secondary-icon-gicon:
1111 * The #GIcon to use for the secondary icon for the entry.
1115 g_object_class_install_property (gobject_class,
1116 PROP_GICON_SECONDARY,
1117 g_param_spec_object ("secondary-icon-gicon",
1118 P_("Secondary GIcon"),
1119 P_("GIcon for secondary icon"),
1121 GTK_PARAM_READWRITE));
1124 * GtkEntry:primary-icon-storage-type:
1126 * The representation which is used for the primary icon of the entry.
1130 g_object_class_install_property (gobject_class,
1131 PROP_STORAGE_TYPE_PRIMARY,
1132 g_param_spec_enum ("primary-icon-storage-type",
1133 P_("Primary storage type"),
1134 P_("The representation being used for primary icon"),
1135 GTK_TYPE_IMAGE_TYPE,
1137 GTK_PARAM_READABLE));
1140 * GtkEntry:secondary-icon-storage-type:
1142 * The representation which is used for the secondary icon of the entry.
1146 g_object_class_install_property (gobject_class,
1147 PROP_STORAGE_TYPE_SECONDARY,
1148 g_param_spec_enum ("secondary-icon-storage-type",
1149 P_("Secondary storage type"),
1150 P_("The representation being used for secondary icon"),
1151 GTK_TYPE_IMAGE_TYPE,
1153 GTK_PARAM_READABLE));
1156 * GtkEntry:primary-icon-activatable:
1158 * Whether the primary icon is activatable.
1160 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1161 * signals only on sensitive, activatable icons.
1163 * Sensitive, but non-activatable icons can be used for purely
1164 * informational purposes.
1168 g_object_class_install_property (gobject_class,
1169 PROP_ACTIVATABLE_PRIMARY,
1170 g_param_spec_boolean ("primary-icon-activatable",
1171 P_("Primary icon activatable"),
1172 P_("Whether the primary icon is activatable"),
1174 GTK_PARAM_READWRITE));
1177 * GtkEntry:secondary-icon-activatable:
1179 * Whether the secondary icon is activatable.
1181 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1182 * signals only on sensitive, activatable icons.
1184 * Sensitive, but non-activatable icons can be used for purely
1185 * informational purposes.
1189 g_object_class_install_property (gobject_class,
1190 PROP_ACTIVATABLE_SECONDARY,
1191 g_param_spec_boolean ("secondary-icon-activatable",
1192 P_("Secondary icon activatable"),
1193 P_("Whether the secondary icon is activatable"),
1195 GTK_PARAM_READWRITE));
1199 * GtkEntry:primary-icon-sensitive:
1201 * Whether the primary icon is sensitive.
1203 * An insensitive icon appears grayed out. GTK+ does not emit the
1204 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1205 * does not allow DND from insensitive icons.
1207 * An icon should be set insensitive if the action that would trigger
1208 * when clicked is currently not available.
1212 g_object_class_install_property (gobject_class,
1213 PROP_SENSITIVE_PRIMARY,
1214 g_param_spec_boolean ("primary-icon-sensitive",
1215 P_("Primary icon sensitive"),
1216 P_("Whether the primary icon is sensitive"),
1218 GTK_PARAM_READWRITE));
1221 * GtkEntry:secondary-icon-sensitive:
1223 * Whether the secondary icon is sensitive.
1225 * An insensitive icon appears grayed out. GTK+ does not emit the
1226 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1227 * does not allow DND from insensitive icons.
1229 * An icon should be set insensitive if the action that would trigger
1230 * when clicked is currently not available.
1234 g_object_class_install_property (gobject_class,
1235 PROP_SENSITIVE_SECONDARY,
1236 g_param_spec_boolean ("secondary-icon-sensitive",
1237 P_("Secondary icon sensitive"),
1238 P_("Whether the secondary icon is sensitive"),
1240 GTK_PARAM_READWRITE));
1243 * GtkEntry:primary-icon-tooltip-text:
1245 * The contents of the tooltip on the primary icon.
1247 * Also see gtk_entry_set_icon_tooltip_text().
1251 g_object_class_install_property (gobject_class,
1252 PROP_TOOLTIP_TEXT_PRIMARY,
1253 g_param_spec_string ("primary-icon-tooltip-text",
1254 P_("Primary icon tooltip text"),
1255 P_("The contents of the tooltip on the primary icon"),
1257 GTK_PARAM_READWRITE));
1260 * GtkEntry:secondary-icon-tooltip-text:
1262 * The contents of the tooltip on the secondary icon.
1264 * Also see gtk_entry_set_icon_tooltip_text().
1268 g_object_class_install_property (gobject_class,
1269 PROP_TOOLTIP_TEXT_SECONDARY,
1270 g_param_spec_string ("secondary-icon-tooltip-text",
1271 P_("Secondary icon tooltip text"),
1272 P_("The contents of the tooltip on the secondary icon"),
1274 GTK_PARAM_READWRITE));
1277 * GtkEntry:primary-icon-tooltip-markup:
1279 * The contents of the tooltip on the primary icon, which is marked up
1280 * with the <link linkend="PangoMarkupFormat">Pango text markup
1283 * Also see gtk_entry_set_icon_tooltip_markup().
1287 g_object_class_install_property (gobject_class,
1288 PROP_TOOLTIP_MARKUP_PRIMARY,
1289 g_param_spec_string ("primary-icon-tooltip-markup",
1290 P_("Primary icon tooltip markup"),
1291 P_("The contents of the tooltip on the primary icon"),
1293 GTK_PARAM_READWRITE));
1296 * GtkEntry:secondary-icon-tooltip-markup:
1298 * The contents of the tooltip on the secondary icon, which is marked up
1299 * with the <link linkend="PangoMarkupFormat">Pango text markup
1302 * Also see gtk_entry_set_icon_tooltip_markup().
1306 g_object_class_install_property (gobject_class,
1307 PROP_TOOLTIP_MARKUP_SECONDARY,
1308 g_param_spec_string ("secondary-icon-tooltip-markup",
1309 P_("Secondary icon tooltip markup"),
1310 P_("The contents of the tooltip on the secondary icon"),
1312 GTK_PARAM_READWRITE));
1315 * GtkEntry:im-module:
1317 * Which IM (input method) module should be used for this entry.
1318 * See #GtkIMContext.
1320 * Setting this to a non-%NULL value overrides the
1321 * system-wide IM module setting. See the GtkSettings
1322 * #GtkSettings:gtk-im-module property.
1326 g_object_class_install_property (gobject_class,
1328 g_param_spec_string ("im-module",
1330 P_("Which IM module should be used"),
1332 GTK_PARAM_READWRITE));
1335 * GtkEntry:completion:
1337 * The auxiliary completion object to use with the entry.
1341 g_object_class_install_property (gobject_class,
1343 g_param_spec_object ("completion",
1345 P_("The auxiliary completion object"),
1346 GTK_TYPE_ENTRY_COMPLETION,
1347 GTK_PARAM_READWRITE));
1350 * GtkEntry:icon-prelight:
1352 * The prelight style property determines whether activatable
1353 * icons prelight on mouseover.
1357 gtk_widget_class_install_style_property (widget_class,
1358 g_param_spec_boolean ("icon-prelight",
1359 P_("Icon Prelight"),
1360 P_("Whether activatable icons should prelight when hovered"),
1362 GTK_PARAM_READABLE));
1365 * GtkEntry:progress-border:
1367 * The border around the progress bar in the entry.
1371 gtk_widget_class_install_style_property (widget_class,
1372 g_param_spec_boxed ("progress-border",
1373 P_("Progress Border"),
1374 P_("Border around the progress bar"),
1376 GTK_PARAM_READABLE));
1379 * GtkEntry:invisible-char:
1381 * The invisible character is used when masking entry contents (in
1382 * \"password mode\")"). When it is not explicitly set with the
1383 * #GtkEntry::invisible-char property, GTK+ determines the character
1384 * to use from a list of possible candidates, depending on availability
1385 * in the current font.
1387 * This style property allows the theme to prepend a character
1388 * to the list of candidates.
1392 gtk_widget_class_install_style_property (widget_class,
1393 g_param_spec_unichar ("invisible-char",
1394 P_("Invisible character"),
1395 P_("The character to use when masking entry contents (in \"password mode\")"),
1397 GTK_PARAM_READABLE));
1400 * GtkEntry::populate-popup:
1401 * @entry: The entry on which the signal is emitted
1402 * @menu: the menu that is being populated
1404 * The ::populate-popup signal gets emitted before showing the
1405 * context menu of the entry.
1407 * If you need to add items to the context menu, connect
1408 * to this signal and append your menuitems to the @menu.
1410 signals[POPULATE_POPUP] =
1411 g_signal_new (I_("populate-popup"),
1412 G_OBJECT_CLASS_TYPE (gobject_class),
1414 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1416 _gtk_marshal_VOID__OBJECT,
1420 /* Action signals */
1423 * GtkEntry::activate:
1424 * @entry: The entry on which the signal is emitted
1426 * A <link linkend="keybinding-signals">keybinding signal</link>
1427 * which gets emitted when the user activates the entry.
1429 * Applications should not connect to it, but may emit it with
1430 * g_signal_emit_by_name() if they need to control activation
1433 * The default bindings for this signal are all forms of the Enter key.
1436 g_signal_new (I_("activate"),
1437 G_OBJECT_CLASS_TYPE (gobject_class),
1438 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1439 G_STRUCT_OFFSET (GtkEntryClass, activate),
1441 _gtk_marshal_VOID__VOID,
1443 widget_class->activate_signal = signals[ACTIVATE];
1446 * GtkEntry::move-cursor:
1447 * @entry: the object which received the signal
1448 * @step: the granularity of the move, as a #GtkMovementStep
1449 * @count: the number of @step units to move
1450 * @extend_selection: %TRUE if the move should extend the selection
1452 * The ::move-cursor signal is a
1453 * <link linkend="keybinding-signals">keybinding signal</link>
1454 * which gets emitted when the user initiates a cursor movement.
1455 * If the cursor is not visible in @entry, this signal causes
1456 * the viewport to be moved instead.
1458 * Applications should not connect to it, but may emit it with
1459 * g_signal_emit_by_name() if they need to control the cursor
1462 * The default bindings for this signal come in two variants,
1463 * the variant with the Shift modifier extends the selection,
1464 * the variant without the Shift modifer does not.
1465 * There are too many key combinations to list them all here.
1467 * <listitem>Arrow keys move by individual characters/lines</listitem>
1468 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1469 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1472 signals[MOVE_CURSOR] =
1473 g_signal_new (I_("move-cursor"),
1474 G_OBJECT_CLASS_TYPE (gobject_class),
1475 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1476 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1478 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1480 GTK_TYPE_MOVEMENT_STEP,
1485 * GtkEntry::insert-at-cursor:
1486 * @entry: the object which received the signal
1487 * @string: the string to insert
1489 * The ::insert-at-cursor signal is a
1490 * <link linkend="keybinding-signals">keybinding signal</link>
1491 * which gets emitted when the user initiates the insertion of a
1492 * fixed string at the cursor.
1494 * This signal has no default bindings.
1496 signals[INSERT_AT_CURSOR] =
1497 g_signal_new (I_("insert-at-cursor"),
1498 G_OBJECT_CLASS_TYPE (gobject_class),
1499 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1500 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1502 _gtk_marshal_VOID__STRING,
1507 * GtkEntry::delete-from-cursor:
1508 * @entry: the object which received the signal
1509 * @type: the granularity of the deletion, as a #GtkDeleteType
1510 * @count: the number of @type units to delete
1512 * The ::delete-from-cursor signal is a
1513 * <link linkend="keybinding-signals">keybinding signal</link>
1514 * which gets emitted when the user initiates a text deletion.
1516 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1517 * if there is one, otherwise it deletes the requested number
1520 * The default bindings for this signal are
1521 * Delete for deleting a character and Ctrl-Delete for
1524 signals[DELETE_FROM_CURSOR] =
1525 g_signal_new (I_("delete-from-cursor"),
1526 G_OBJECT_CLASS_TYPE (gobject_class),
1527 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1528 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1530 _gtk_marshal_VOID__ENUM_INT,
1532 GTK_TYPE_DELETE_TYPE,
1536 * GtkEntry::backspace:
1537 * @entry: the object which received the signal
1539 * The ::backspace signal is a
1540 * <link linkend="keybinding-signals">keybinding signal</link>
1541 * which gets emitted when the user asks for it.
1543 * The default bindings for this signal are
1544 * Backspace and Shift-Backspace.
1546 signals[BACKSPACE] =
1547 g_signal_new (I_("backspace"),
1548 G_OBJECT_CLASS_TYPE (gobject_class),
1549 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1550 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1552 _gtk_marshal_VOID__VOID,
1556 * GtkEntry::cut-clipboard:
1557 * @entry: the object which received the signal
1559 * The ::cut-clipboard signal is a
1560 * <link linkend="keybinding-signals">keybinding signal</link>
1561 * which gets emitted to cut the selection to the clipboard.
1563 * The default bindings for this signal are
1564 * Ctrl-x and Shift-Delete.
1566 signals[CUT_CLIPBOARD] =
1567 g_signal_new (I_("cut-clipboard"),
1568 G_OBJECT_CLASS_TYPE (gobject_class),
1569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1570 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1572 _gtk_marshal_VOID__VOID,
1576 * GtkEntry::copy-clipboard:
1577 * @entry: the object which received the signal
1579 * The ::copy-clipboard signal is a
1580 * <link linkend="keybinding-signals">keybinding signal</link>
1581 * which gets emitted to copy the selection to the clipboard.
1583 * The default bindings for this signal are
1584 * Ctrl-c and Ctrl-Insert.
1586 signals[COPY_CLIPBOARD] =
1587 g_signal_new (I_("copy-clipboard"),
1588 G_OBJECT_CLASS_TYPE (gobject_class),
1589 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1590 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1592 _gtk_marshal_VOID__VOID,
1596 * GtkEntry::paste-clipboard:
1597 * @entry: the object which received the signal
1599 * The ::paste-clipboard signal is a
1600 * <link linkend="keybinding-signals">keybinding signal</link>
1601 * which gets emitted to paste the contents of the clipboard
1602 * into the text view.
1604 * The default bindings for this signal are
1605 * Ctrl-v and Shift-Insert.
1607 signals[PASTE_CLIPBOARD] =
1608 g_signal_new (I_("paste-clipboard"),
1609 G_OBJECT_CLASS_TYPE (gobject_class),
1610 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1611 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1613 _gtk_marshal_VOID__VOID,
1617 * GtkEntry::toggle-overwrite:
1618 * @entry: the object which received the signal
1620 * The ::toggle-overwrite signal is a
1621 * <link linkend="keybinding-signals">keybinding signal</link>
1622 * which gets emitted to toggle the overwrite mode of the entry.
1624 * The default bindings for this signal is Insert.
1626 signals[TOGGLE_OVERWRITE] =
1627 g_signal_new (I_("toggle-overwrite"),
1628 G_OBJECT_CLASS_TYPE (gobject_class),
1629 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1630 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1632 _gtk_marshal_VOID__VOID,
1636 * GtkEntry::icon-press:
1637 * @entry: The entry on which the signal is emitted
1638 * @icon_pos: The position of the clicked icon
1639 * @event: (type Gdk.EventButton): the button press event
1641 * The ::icon-press signal is emitted when an activatable icon
1646 signals[ICON_PRESS] =
1647 g_signal_new (I_("icon-press"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1652 _gtk_marshal_VOID__ENUM_BOXED,
1654 GTK_TYPE_ENTRY_ICON_POSITION,
1655 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1658 * GtkEntry::icon-release:
1659 * @entry: The entry on which the signal is emitted
1660 * @icon_pos: The position of the clicked icon
1661 * @event: (type Gdk.EventButton): the button release event
1663 * The ::icon-release signal is emitted on the button release from a
1664 * mouse click over an activatable icon.
1668 signals[ICON_RELEASE] =
1669 g_signal_new (I_("icon-release"),
1670 G_TYPE_FROM_CLASS (gobject_class),
1674 _gtk_marshal_VOID__ENUM_BOXED,
1676 GTK_TYPE_ENTRY_ICON_POSITION,
1677 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1680 * GtkEntry::preedit-changed:
1681 * @entry: the object which received the signal
1682 * @preedit: the current preedit string
1684 * If an input method is used, the typed text will not immediately
1685 * be committed to the buffer. So if you are interested in the text,
1686 * connect to this signal.
1690 signals[PREEDIT_CHANGED] =
1691 g_signal_new_class_handler (I_("preedit-changed"),
1692 G_OBJECT_CLASS_TYPE (gobject_class),
1693 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1696 _gtk_marshal_VOID__STRING,
1705 binding_set = gtk_binding_set_by_class (class);
1707 /* Moving the insertion point */
1708 add_move_binding (binding_set, GDK_KEY_Right, 0,
1709 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1711 add_move_binding (binding_set, GDK_KEY_Left, 0,
1712 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1714 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1715 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1717 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1718 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1720 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1721 GTK_MOVEMENT_WORDS, 1);
1723 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1724 GTK_MOVEMENT_WORDS, -1);
1726 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1727 GTK_MOVEMENT_WORDS, 1);
1729 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1730 GTK_MOVEMENT_WORDS, -1);
1732 add_move_binding (binding_set, GDK_KEY_Home, 0,
1733 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1735 add_move_binding (binding_set, GDK_KEY_End, 0,
1736 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1738 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1739 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1741 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1742 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1744 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1745 GTK_MOVEMENT_BUFFER_ENDS, -1);
1747 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1748 GTK_MOVEMENT_BUFFER_ENDS, 1);
1750 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1751 GTK_MOVEMENT_BUFFER_ENDS, -1);
1753 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1754 GTK_MOVEMENT_BUFFER_ENDS, 1);
1758 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1760 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1762 G_TYPE_BOOLEAN, FALSE);
1763 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1765 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1767 G_TYPE_BOOLEAN, TRUE);
1769 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1771 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1773 G_TYPE_BOOLEAN, FALSE);
1774 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1776 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1778 G_TYPE_BOOLEAN, TRUE);
1781 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1783 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1785 G_TYPE_BOOLEAN, FALSE);
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1788 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1790 G_TYPE_BOOLEAN, FALSE);
1794 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1796 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1798 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1803 "delete-from-cursor", 2,
1804 G_TYPE_ENUM, GTK_DELETE_CHARS,
1807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1808 "delete-from-cursor", 2,
1809 G_TYPE_ENUM, GTK_DELETE_CHARS,
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1815 /* Make this do the same as Backspace, to help with mis-typing */
1816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1819 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1820 "delete-from-cursor", 2,
1821 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1825 "delete-from-cursor", 2,
1826 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1829 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1830 "delete-from-cursor", 2,
1831 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1834 /* Cut/copy/paste */
1836 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1837 "cut-clipboard", 0);
1838 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1839 "copy-clipboard", 0);
1840 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1841 "paste-clipboard", 0);
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1844 "cut-clipboard", 0);
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1846 "copy-clipboard", 0);
1847 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1848 "paste-clipboard", 0);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1852 "toggle-overwrite", 0);
1853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1854 "toggle-overwrite", 0);
1857 * GtkEntry:inner-border:
1859 * Sets the text area's border between the text and the frame.
1863 gtk_widget_class_install_style_property (widget_class,
1864 g_param_spec_boxed ("inner-border",
1866 P_("Border between text and frame."),
1868 GTK_PARAM_READABLE));
1870 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1872 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1876 gtk_entry_editable_init (GtkEditableInterface *iface)
1878 iface->do_insert_text = gtk_entry_insert_text;
1879 iface->do_delete_text = gtk_entry_delete_text;
1880 iface->insert_text = gtk_entry_real_insert_text;
1881 iface->delete_text = gtk_entry_real_delete_text;
1882 iface->get_chars = gtk_entry_get_chars;
1883 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1884 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1885 iface->set_position = gtk_entry_real_set_position;
1886 iface->get_position = gtk_entry_get_position;
1890 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1892 iface->start_editing = gtk_entry_start_editing;
1896 gtk_entry_set_property (GObject *object,
1898 const GValue *value,
1901 GtkEntry *entry = GTK_ENTRY (object);
1902 GtkEntryPrivate *priv = entry->priv;
1907 gtk_entry_set_buffer (entry, g_value_get_object (value));
1912 gboolean new_value = g_value_get_boolean (value);
1914 if (new_value != priv->editable)
1916 GtkWidget *widget = GTK_WIDGET (entry);
1920 _gtk_entry_reset_im_context (entry);
1921 if (gtk_widget_has_focus (widget))
1922 gtk_im_context_focus_out (priv->im_context);
1924 priv->preedit_length = 0;
1925 priv->preedit_cursor = 0;
1928 priv->editable = new_value;
1930 if (new_value && gtk_widget_has_focus (widget))
1931 gtk_im_context_focus_in (priv->im_context);
1933 gtk_widget_queue_draw (widget);
1938 case PROP_MAX_LENGTH:
1939 gtk_entry_set_max_length (entry, g_value_get_int (value));
1942 case PROP_VISIBILITY:
1943 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1946 case PROP_HAS_FRAME:
1947 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1950 case PROP_INNER_BORDER:
1951 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1954 case PROP_INVISIBLE_CHAR:
1955 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1958 case PROP_ACTIVATES_DEFAULT:
1959 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1962 case PROP_WIDTH_CHARS:
1963 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1967 gtk_entry_set_text (entry, g_value_get_string (value));
1971 gtk_entry_set_alignment (entry, g_value_get_float (value));
1974 case PROP_TRUNCATE_MULTILINE:
1975 priv->truncate_multiline = g_value_get_boolean (value);
1978 case PROP_SHADOW_TYPE:
1979 priv->shadow_type = g_value_get_enum (value);
1982 case PROP_OVERWRITE_MODE:
1983 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1986 case PROP_INVISIBLE_CHAR_SET:
1987 if (g_value_get_boolean (value))
1988 priv->invisible_char_set = TRUE;
1990 gtk_entry_unset_invisible_char (entry);
1993 case PROP_CAPS_LOCK_WARNING:
1994 priv->caps_lock_warning = g_value_get_boolean (value);
1997 case PROP_PROGRESS_FRACTION:
1998 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2001 case PROP_PROGRESS_PULSE_STEP:
2002 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2005 case PROP_PLACEHOLDER_TEXT:
2006 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2009 case PROP_PIXBUF_PRIMARY:
2010 gtk_entry_set_icon_from_pixbuf (entry,
2011 GTK_ENTRY_ICON_PRIMARY,
2012 g_value_get_object (value));
2015 case PROP_PIXBUF_SECONDARY:
2016 gtk_entry_set_icon_from_pixbuf (entry,
2017 GTK_ENTRY_ICON_SECONDARY,
2018 g_value_get_object (value));
2021 case PROP_STOCK_PRIMARY:
2022 gtk_entry_set_icon_from_stock (entry,
2023 GTK_ENTRY_ICON_PRIMARY,
2024 g_value_get_string (value));
2027 case PROP_STOCK_SECONDARY:
2028 gtk_entry_set_icon_from_stock (entry,
2029 GTK_ENTRY_ICON_SECONDARY,
2030 g_value_get_string (value));
2033 case PROP_ICON_NAME_PRIMARY:
2034 gtk_entry_set_icon_from_icon_name (entry,
2035 GTK_ENTRY_ICON_PRIMARY,
2036 g_value_get_string (value));
2039 case PROP_ICON_NAME_SECONDARY:
2040 gtk_entry_set_icon_from_icon_name (entry,
2041 GTK_ENTRY_ICON_SECONDARY,
2042 g_value_get_string (value));
2045 case PROP_GICON_PRIMARY:
2046 gtk_entry_set_icon_from_gicon (entry,
2047 GTK_ENTRY_ICON_PRIMARY,
2048 g_value_get_object (value));
2051 case PROP_GICON_SECONDARY:
2052 gtk_entry_set_icon_from_gicon (entry,
2053 GTK_ENTRY_ICON_SECONDARY,
2054 g_value_get_object (value));
2057 case PROP_ACTIVATABLE_PRIMARY:
2058 gtk_entry_set_icon_activatable (entry,
2059 GTK_ENTRY_ICON_PRIMARY,
2060 g_value_get_boolean (value));
2063 case PROP_ACTIVATABLE_SECONDARY:
2064 gtk_entry_set_icon_activatable (entry,
2065 GTK_ENTRY_ICON_SECONDARY,
2066 g_value_get_boolean (value));
2069 case PROP_SENSITIVE_PRIMARY:
2070 gtk_entry_set_icon_sensitive (entry,
2071 GTK_ENTRY_ICON_PRIMARY,
2072 g_value_get_boolean (value));
2075 case PROP_SENSITIVE_SECONDARY:
2076 gtk_entry_set_icon_sensitive (entry,
2077 GTK_ENTRY_ICON_SECONDARY,
2078 g_value_get_boolean (value));
2081 case PROP_TOOLTIP_TEXT_PRIMARY:
2082 gtk_entry_set_icon_tooltip_text (entry,
2083 GTK_ENTRY_ICON_PRIMARY,
2084 g_value_get_string (value));
2087 case PROP_TOOLTIP_TEXT_SECONDARY:
2088 gtk_entry_set_icon_tooltip_text (entry,
2089 GTK_ENTRY_ICON_SECONDARY,
2090 g_value_get_string (value));
2093 case PROP_TOOLTIP_MARKUP_PRIMARY:
2094 gtk_entry_set_icon_tooltip_markup (entry,
2095 GTK_ENTRY_ICON_PRIMARY,
2096 g_value_get_string (value));
2099 case PROP_TOOLTIP_MARKUP_SECONDARY:
2100 gtk_entry_set_icon_tooltip_markup (entry,
2101 GTK_ENTRY_ICON_SECONDARY,
2102 g_value_get_string (value));
2105 case PROP_IM_MODULE:
2106 g_free (priv->im_module);
2107 priv->im_module = g_value_dup_string (value);
2108 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2109 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2112 case PROP_EDITING_CANCELED:
2113 priv->editing_canceled = g_value_get_boolean (value);
2116 case PROP_COMPLETION:
2117 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2120 case PROP_SCROLL_OFFSET:
2121 case PROP_CURSOR_POSITION:
2123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2129 gtk_entry_get_property (GObject *object,
2134 GtkEntry *entry = GTK_ENTRY (object);
2135 GtkEntryPrivate *priv = entry->priv;
2140 g_value_set_object (value, gtk_entry_get_buffer (entry));
2143 case PROP_CURSOR_POSITION:
2144 g_value_set_int (value, priv->current_pos);
2147 case PROP_SELECTION_BOUND:
2148 g_value_set_int (value, priv->selection_bound);
2152 g_value_set_boolean (value, priv->editable);
2155 case PROP_MAX_LENGTH:
2156 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2159 case PROP_VISIBILITY:
2160 g_value_set_boolean (value, priv->visible);
2163 case PROP_HAS_FRAME:
2164 g_value_set_boolean (value, priv->has_frame);
2167 case PROP_INNER_BORDER:
2168 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2171 case PROP_INVISIBLE_CHAR:
2172 g_value_set_uint (value, priv->invisible_char);
2175 case PROP_ACTIVATES_DEFAULT:
2176 g_value_set_boolean (value, priv->activates_default);
2179 case PROP_WIDTH_CHARS:
2180 g_value_set_int (value, priv->width_chars);
2183 case PROP_SCROLL_OFFSET:
2184 g_value_set_int (value, priv->scroll_offset);
2188 g_value_set_string (value, gtk_entry_get_text (entry));
2192 g_value_set_float (value, gtk_entry_get_alignment (entry));
2195 case PROP_TRUNCATE_MULTILINE:
2196 g_value_set_boolean (value, priv->truncate_multiline);
2199 case PROP_SHADOW_TYPE:
2200 g_value_set_enum (value, priv->shadow_type);
2203 case PROP_OVERWRITE_MODE:
2204 g_value_set_boolean (value, priv->overwrite_mode);
2207 case PROP_TEXT_LENGTH:
2208 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2211 case PROP_INVISIBLE_CHAR_SET:
2212 g_value_set_boolean (value, priv->invisible_char_set);
2215 case PROP_IM_MODULE:
2216 g_value_set_string (value, priv->im_module);
2219 case PROP_CAPS_LOCK_WARNING:
2220 g_value_set_boolean (value, priv->caps_lock_warning);
2223 case PROP_PROGRESS_FRACTION:
2224 g_value_set_double (value, priv->progress_fraction);
2227 case PROP_PROGRESS_PULSE_STEP:
2228 g_value_set_double (value, priv->progress_pulse_fraction);
2231 case PROP_PLACEHOLDER_TEXT:
2232 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2235 case PROP_PIXBUF_PRIMARY:
2236 g_value_set_object (value,
2237 gtk_entry_get_icon_pixbuf (entry,
2238 GTK_ENTRY_ICON_PRIMARY));
2241 case PROP_PIXBUF_SECONDARY:
2242 g_value_set_object (value,
2243 gtk_entry_get_icon_pixbuf (entry,
2244 GTK_ENTRY_ICON_SECONDARY));
2247 case PROP_STOCK_PRIMARY:
2248 g_value_set_string (value,
2249 gtk_entry_get_icon_stock (entry,
2250 GTK_ENTRY_ICON_PRIMARY));
2253 case PROP_STOCK_SECONDARY:
2254 g_value_set_string (value,
2255 gtk_entry_get_icon_stock (entry,
2256 GTK_ENTRY_ICON_SECONDARY));
2259 case PROP_ICON_NAME_PRIMARY:
2260 g_value_set_string (value,
2261 gtk_entry_get_icon_name (entry,
2262 GTK_ENTRY_ICON_PRIMARY));
2265 case PROP_ICON_NAME_SECONDARY:
2266 g_value_set_string (value,
2267 gtk_entry_get_icon_name (entry,
2268 GTK_ENTRY_ICON_SECONDARY));
2271 case PROP_GICON_PRIMARY:
2272 g_value_set_object (value,
2273 gtk_entry_get_icon_gicon (entry,
2274 GTK_ENTRY_ICON_PRIMARY));
2277 case PROP_GICON_SECONDARY:
2278 g_value_set_object (value,
2279 gtk_entry_get_icon_gicon (entry,
2280 GTK_ENTRY_ICON_SECONDARY));
2283 case PROP_STORAGE_TYPE_PRIMARY:
2284 g_value_set_enum (value,
2285 gtk_entry_get_icon_storage_type (entry,
2286 GTK_ENTRY_ICON_PRIMARY));
2289 case PROP_STORAGE_TYPE_SECONDARY:
2290 g_value_set_enum (value,
2291 gtk_entry_get_icon_storage_type (entry,
2292 GTK_ENTRY_ICON_SECONDARY));
2295 case PROP_ACTIVATABLE_PRIMARY:
2296 g_value_set_boolean (value,
2297 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2300 case PROP_ACTIVATABLE_SECONDARY:
2301 g_value_set_boolean (value,
2302 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2305 case PROP_SENSITIVE_PRIMARY:
2306 g_value_set_boolean (value,
2307 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2310 case PROP_SENSITIVE_SECONDARY:
2311 g_value_set_boolean (value,
2312 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2315 case PROP_TOOLTIP_TEXT_PRIMARY:
2316 g_value_take_string (value,
2317 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2320 case PROP_TOOLTIP_TEXT_SECONDARY:
2321 g_value_take_string (value,
2322 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2325 case PROP_TOOLTIP_MARKUP_PRIMARY:
2326 g_value_take_string (value,
2327 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2330 case PROP_TOOLTIP_MARKUP_SECONDARY:
2331 g_value_take_string (value,
2332 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2335 case PROP_EDITING_CANCELED:
2336 g_value_set_boolean (value,
2337 priv->editing_canceled);
2340 case PROP_COMPLETION:
2341 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2345 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2351 find_invisible_char (GtkWidget *widget)
2353 PangoLayout *layout;
2354 PangoAttrList *attr_list;
2356 gunichar invisible_chars [] = {
2358 0x25cf, /* BLACK CIRCLE */
2359 0x2022, /* BULLET */
2360 0x2731, /* HEAVY ASTERISK */
2361 0x273a /* SIXTEEN POINTED ASTERISK */
2364 gtk_widget_style_get (widget,
2365 "invisible-char", &invisible_chars[0],
2368 layout = gtk_widget_create_pango_layout (widget, NULL);
2370 attr_list = pango_attr_list_new ();
2371 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2373 pango_layout_set_attributes (layout, attr_list);
2374 pango_attr_list_unref (attr_list);
2376 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2378 gchar text[7] = { 0, };
2381 len = g_unichar_to_utf8 (invisible_chars[i], text);
2382 pango_layout_set_text (layout, text, len);
2384 count = pango_layout_get_unknown_glyphs_count (layout);
2388 g_object_unref (layout);
2389 return invisible_chars[i];
2393 g_object_unref (layout);
2399 gtk_entry_init (GtkEntry *entry)
2401 GtkStyleContext *context;
2402 GtkEntryPrivate *priv;
2404 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2409 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2410 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2412 priv->editable = TRUE;
2413 priv->visible = TRUE;
2414 priv->dnd_position = -1;
2415 priv->width_chars = -1;
2416 priv->is_cell_renderer = FALSE;
2417 priv->editing_canceled = FALSE;
2418 priv->has_frame = TRUE;
2419 priv->truncate_multiline = FALSE;
2420 priv->shadow_type = GTK_SHADOW_IN;
2422 priv->caps_lock_warning = TRUE;
2423 priv->caps_lock_warning_shown = FALSE;
2424 priv->progress_fraction = 0.0;
2425 priv->progress_pulse_fraction = 0.1;
2427 gtk_drag_dest_set (GTK_WIDGET (entry),
2428 GTK_DEST_DEFAULT_HIGHLIGHT,
2430 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2431 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2433 /* This object is completely private. No external entity can gain a reference
2434 * to it; so we create it here and destroy it in finalize().
2436 priv->im_context = gtk_im_multicontext_new ();
2438 g_signal_connect (priv->im_context, "commit",
2439 G_CALLBACK (gtk_entry_commit_cb), entry);
2440 g_signal_connect (priv->im_context, "preedit-changed",
2441 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2442 g_signal_connect (priv->im_context, "retrieve-surrounding",
2443 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2444 g_signal_connect (priv->im_context, "delete-surrounding",
2445 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2447 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2448 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2450 gtk_entry_update_cached_style_values (entry);
2454 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2455 GtkStyleContext *context,
2456 GtkEntryIconPosition icon_pos)
2458 GtkEntryPrivate *priv = entry->priv;
2459 EntryIconInfo *icon_info = priv->icons[icon_pos];
2461 GtkStateFlags state;
2463 widget = GTK_WIDGET (entry);
2464 state = GTK_STATE_FLAG_NORMAL;
2466 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
2467 state |= GTK_STATE_FLAG_INSENSITIVE;
2468 else if (icon_info->prelight)
2469 state |= GTK_STATE_FLAG_PRELIGHT;
2471 gtk_style_context_save (context);
2473 gtk_style_context_set_state (context, state);
2474 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2478 get_icon_width (GtkEntry *entry,
2479 GtkEntryIconPosition icon_pos)
2481 GtkEntryPrivate *priv = entry->priv;
2482 EntryIconInfo *icon_info = priv->icons[icon_pos];
2483 GtkStyleContext *context;
2489 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2490 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2491 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2493 gtk_style_context_restore (context);
2499 get_icon_allocations (GtkEntry *entry,
2500 GtkAllocation *primary,
2501 GtkAllocation *secondary)
2504 GtkEntryPrivate *priv = entry->priv;
2505 gint x, y, width, height;
2507 get_text_area_size (entry, &x, &y, &width, &height);
2509 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2510 y += priv->focus_width;
2513 primary->height = height;
2514 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2515 if (primary->width > 0)
2516 primary->width += 2 * priv->icon_margin;
2519 secondary->height = height;
2520 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2521 if (secondary->width > 0)
2522 secondary->width += 2 * priv->icon_margin;
2524 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2526 primary->x = x + width - primary->width;
2532 secondary->x = x + width - secondary->width;
2538 begin_change (GtkEntry *entry)
2540 GtkEntryPrivate *priv = entry->priv;
2542 priv->change_count++;
2546 end_change (GtkEntry *entry)
2548 GtkEditable *editable = GTK_EDITABLE (entry);
2549 GtkEntryPrivate *priv = entry->priv;
2551 g_return_if_fail (priv->change_count > 0);
2553 priv->change_count--;
2555 if (priv->change_count == 0)
2557 if (priv->real_changed)
2559 g_signal_emit_by_name (editable, "changed");
2560 priv->real_changed = FALSE;
2566 emit_changed (GtkEntry *entry)
2568 GtkEditable *editable = GTK_EDITABLE (entry);
2569 GtkEntryPrivate *priv = entry->priv;
2571 if (priv->change_count == 0)
2572 g_signal_emit_by_name (editable, "changed");
2574 priv->real_changed = TRUE;
2578 gtk_entry_destroy (GtkWidget *widget)
2580 GtkEntry *entry = GTK_ENTRY (widget);
2581 GtkEntryPrivate *priv = entry->priv;
2583 priv->current_pos = priv->selection_bound = 0;
2584 _gtk_entry_reset_im_context (entry);
2585 gtk_entry_reset_layout (entry);
2587 if (priv->blink_timeout)
2589 g_source_remove (priv->blink_timeout);
2590 priv->blink_timeout = 0;
2593 if (priv->recompute_idle)
2595 g_source_remove (priv->recompute_idle);
2596 priv->recompute_idle = 0;
2599 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2603 gtk_entry_dispose (GObject *object)
2605 GtkEntry *entry = GTK_ENTRY (object);
2606 GtkEntryPrivate *priv = entry->priv;
2609 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2610 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2611 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2612 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2616 buffer_disconnect_signals (entry);
2617 g_object_unref (priv->buffer);
2618 priv->buffer = NULL;
2621 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2622 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2623 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2624 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2628 gtk_entry_finalize (GObject *object)
2630 GtkEntry *entry = GTK_ENTRY (object);
2631 GtkEntryPrivate *priv = entry->priv;
2632 EntryIconInfo *icon_info = NULL;
2635 for (i = 0; i < MAX_ICONS; i++)
2637 if ((icon_info = priv->icons[i]) != NULL)
2639 if (icon_info->target_list != NULL)
2641 gtk_target_list_unref (icon_info->target_list);
2642 icon_info->target_list = NULL;
2645 g_clear_object (&icon_info->icon_helper);
2647 g_slice_free (EntryIconInfo, icon_info);
2648 priv->icons[i] = NULL;
2652 gtk_entry_set_completion (entry, NULL);
2654 if (priv->cached_layout)
2655 g_object_unref (priv->cached_layout);
2657 g_object_unref (priv->im_context);
2659 if (priv->blink_timeout)
2660 g_source_remove (priv->blink_timeout);
2662 if (priv->recompute_idle)
2663 g_source_remove (priv->recompute_idle);
2665 g_free (priv->placeholder_text);
2666 g_free (priv->im_module);
2668 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2672 gtk_entry_get_display_mode (GtkEntry *entry)
2674 GtkEntryPrivate *priv = entry->priv;
2677 return DISPLAY_NORMAL;
2679 if (priv->invisible_char == 0 && priv->invisible_char_set)
2680 return DISPLAY_BLANK;
2682 return DISPLAY_INVISIBLE;
2686 gtk_entry_get_display_text (GtkEntry *entry,
2690 GtkEntryPasswordHint *password_hint;
2691 GtkEntryPrivate *priv;
2692 gunichar invisible_char;
2703 text = gtk_entry_buffer_get_text (get_buffer (entry));
2704 length = gtk_entry_buffer_get_length (get_buffer (entry));
2708 if (start_pos > length)
2711 if (end_pos <= start_pos)
2712 return g_strdup ("");
2713 else if (priv->visible)
2715 start = g_utf8_offset_to_pointer (text, start_pos);
2716 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2717 return g_strndup (start, end - start);
2721 str = g_string_sized_new (length * 2);
2723 /* Figure out what our invisible char is and encode it */
2724 if (!priv->invisible_char)
2725 invisible_char = priv->invisible_char_set ? ' ' : '*';
2727 invisible_char = priv->invisible_char;
2728 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2731 * Add hidden characters for each character in the text
2732 * buffer. If there is a password hint, then keep that
2733 * character visible.
2736 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2737 for (i = start_pos; i < end_pos; ++i)
2739 if (password_hint && i == password_hint->position)
2741 start = g_utf8_offset_to_pointer (text, i);
2742 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2746 g_string_append_len (str, char_str, char_len);
2750 return g_string_free (str, FALSE);
2755 update_cursors (GtkWidget *widget)
2757 GtkEntry *entry = GTK_ENTRY (widget);
2758 GtkEntryPrivate *priv = entry->priv;
2759 EntryIconInfo *icon_info = NULL;
2760 GdkDisplay *display;
2764 for (i = 0; i < MAX_ICONS; i++)
2766 if ((icon_info = priv->icons[i]) != NULL)
2768 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2769 icon_info->window != NULL)
2770 gdk_window_show_unraised (icon_info->window);
2772 /* The icon windows are not children of the visible entry window,
2773 * thus we can't just inherit the xterm cursor. Slight complication
2774 * here is that for the entry, insensitive => arrow cursor, but for
2775 * an icon in a sensitive entry, insensitive => xterm cursor.
2777 if (gtk_widget_is_sensitive (widget) &&
2778 (icon_info->insensitive ||
2779 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2781 display = gtk_widget_get_display (widget);
2782 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2783 gdk_window_set_cursor (icon_info->window, cursor);
2784 g_object_unref (cursor);
2788 gdk_window_set_cursor (icon_info->window, NULL);
2795 realize_icon_info (GtkWidget *widget,
2796 GtkEntryIconPosition icon_pos)
2798 GtkEntry *entry = GTK_ENTRY (widget);
2799 GtkEntryPrivate *priv = entry->priv;
2800 EntryIconInfo *icon_info = priv->icons[icon_pos];
2801 GdkWindowAttr attributes;
2802 gint attributes_mask;
2804 g_return_if_fail (icon_info != NULL);
2808 attributes.width = 1;
2809 attributes.height = 1;
2810 attributes.window_type = GDK_WINDOW_CHILD;
2811 attributes.wclass = GDK_INPUT_ONLY;
2812 attributes.event_mask = gtk_widget_get_events (widget);
2813 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2814 GDK_BUTTON_RELEASE_MASK |
2815 GDK_BUTTON1_MOTION_MASK |
2816 GDK_BUTTON3_MOTION_MASK |
2817 GDK_POINTER_MOTION_HINT_MASK |
2818 GDK_POINTER_MOTION_MASK |
2819 GDK_ENTER_NOTIFY_MASK |
2820 GDK_LEAVE_NOTIFY_MASK);
2821 attributes_mask = GDK_WA_X | GDK_WA_Y;
2823 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2826 gdk_window_set_user_data (icon_info->window, widget);
2828 gtk_widget_queue_resize (widget);
2831 static EntryIconInfo*
2832 construct_icon_info (GtkWidget *widget,
2833 GtkEntryIconPosition icon_pos)
2835 GtkEntry *entry = GTK_ENTRY (widget);
2836 GtkEntryPrivate *priv = entry->priv;
2837 EntryIconInfo *icon_info;
2839 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2841 icon_info = g_slice_new0 (EntryIconInfo);
2842 priv->icons[icon_pos] = icon_info;
2844 icon_info->icon_helper = _gtk_icon_helper_new ();
2846 if (gtk_widget_get_realized (widget))
2847 realize_icon_info (widget, icon_pos);
2853 gtk_entry_map (GtkWidget *widget)
2855 GtkEntry *entry = GTK_ENTRY (widget);
2856 GtkEntryPrivate *priv = entry->priv;
2857 EntryIconInfo *icon_info = NULL;
2860 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2862 gdk_window_show (priv->text_area);
2864 for (i = 0; i < MAX_ICONS; i++)
2866 if ((icon_info = priv->icons[i]) != NULL)
2868 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2869 icon_info->window != NULL)
2870 gdk_window_show (icon_info->window);
2874 update_cursors (widget);
2878 gtk_entry_unmap (GtkWidget *widget)
2880 GtkEntry *entry = GTK_ENTRY (widget);
2881 GtkEntryPrivate *priv = entry->priv;
2882 EntryIconInfo *icon_info = NULL;
2885 for (i = 0; i < MAX_ICONS; i++)
2887 if ((icon_info = priv->icons[i]) != NULL)
2889 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2890 icon_info->window != NULL)
2891 gdk_window_hide (icon_info->window);
2895 gdk_window_hide (priv->text_area);
2897 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2901 gtk_entry_realize (GtkWidget *widget)
2904 GtkEntryPrivate *priv;
2905 EntryIconInfo *icon_info;
2907 GdkWindowAttr attributes;
2908 gint attributes_mask;
2909 gint frame_x, frame_y;
2912 gtk_widget_set_realized (widget, TRUE);
2913 window = gtk_widget_get_parent_window (widget);
2914 gtk_widget_set_window (widget, window);
2915 g_object_ref (window);
2917 entry = GTK_ENTRY (widget);
2920 attributes.window_type = GDK_WINDOW_CHILD;
2921 attributes.wclass = GDK_INPUT_ONLY;
2922 attributes.event_mask = gtk_widget_get_events (widget);
2923 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2924 GDK_BUTTON_RELEASE_MASK |
2925 GDK_BUTTON1_MOTION_MASK |
2926 GDK_BUTTON3_MOTION_MASK |
2927 GDK_POINTER_MOTION_HINT_MASK |
2928 GDK_POINTER_MOTION_MASK |
2929 GDK_ENTER_NOTIFY_MASK |
2930 GDK_LEAVE_NOTIFY_MASK);
2931 attributes_mask = GDK_WA_X | GDK_WA_Y;
2933 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2935 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2936 attributes.x += frame_x;
2937 attributes.y += frame_y;
2939 if (gtk_widget_is_sensitive (widget))
2941 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2942 attributes_mask |= GDK_WA_CURSOR;
2945 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2949 gdk_window_set_user_data (priv->text_area, entry);
2951 if (attributes_mask & GDK_WA_CURSOR)
2952 g_object_unref (attributes.cursor);
2954 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2956 gtk_entry_adjust_scroll (entry);
2957 gtk_entry_update_primary_selection (entry);
2960 /* If the icon positions are already setup, create their windows.
2961 * Otherwise if they don't exist yet, then construct_icon_info()
2962 * will create the windows once the widget is already realized.
2964 for (i = 0; i < MAX_ICONS; i++)
2966 if ((icon_info = priv->icons[i]) != NULL)
2968 if (icon_info->window == NULL)
2969 realize_icon_info (widget, i);
2975 gtk_entry_unrealize (GtkWidget *widget)
2977 GtkEntry *entry = GTK_ENTRY (widget);
2978 GtkEntryPrivate *priv = entry->priv;
2979 GtkClipboard *clipboard;
2980 EntryIconInfo *icon_info;
2983 gtk_entry_reset_layout (entry);
2985 gtk_im_context_set_client_window (priv->im_context, NULL);
2987 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2988 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2989 gtk_clipboard_clear (clipboard);
2991 if (priv->text_area)
2993 gdk_window_set_user_data (priv->text_area, NULL);
2994 gdk_window_destroy (priv->text_area);
2995 priv->text_area = NULL;
2998 if (priv->popup_menu)
3000 gtk_widget_destroy (priv->popup_menu);
3001 priv->popup_menu = NULL;
3004 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3006 for (i = 0; i < MAX_ICONS; i++)
3008 if ((icon_info = priv->icons[i]) != NULL)
3010 if (icon_info->window != NULL)
3012 gdk_window_destroy (icon_info->window);
3013 icon_info->window = NULL;
3020 _gtk_entry_get_borders (GtkEntry *entry,
3024 GtkEntryPrivate *priv = entry->priv;
3025 GtkWidget *widget = GTK_WIDGET (entry);
3027 if (priv->has_frame)
3029 GtkStyleContext *context;
3032 context = gtk_widget_get_style_context (widget);
3033 gtk_style_context_get_padding (context, 0, &padding);
3035 *xborder = padding.left;
3036 *yborder = padding.top;
3044 if (!priv->interior_focus)
3046 *xborder += priv->focus_width;
3047 *yborder += priv->focus_width;
3052 gtk_entry_get_preferred_width (GtkWidget *widget,
3056 GtkEntry *entry = GTK_ENTRY (widget);
3057 GtkEntryPrivate *priv = entry->priv;
3058 PangoFontMetrics *metrics;
3059 gint xborder, yborder;
3060 GtkBorder inner_border;
3061 PangoContext *context;
3062 GtkStyleContext *style_context;
3063 GtkStateFlags state;
3064 gint icon_widths = 0;
3068 context = gtk_widget_get_pango_context (widget);
3070 style_context = gtk_widget_get_style_context (widget);
3071 state = gtk_widget_get_state_flags (widget);
3073 metrics = pango_context_get_metrics (context,
3074 gtk_style_context_get_font (style_context, state),
3075 pango_context_get_language (context));
3077 _gtk_entry_get_borders (entry, &xborder, &yborder);
3078 _gtk_entry_effective_inner_border (entry, &inner_border);
3080 if (priv->width_chars < 0)
3081 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3084 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3085 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3086 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3088 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3091 for (i = 0; i < MAX_ICONS; i++)
3093 icon_width = get_icon_width (entry, i);
3095 icon_widths += icon_width + 2 * priv->icon_margin;
3098 if (icon_widths > width)
3099 width += icon_widths;
3101 pango_font_metrics_unref (metrics);
3108 gtk_entry_get_preferred_height (GtkWidget *widget,
3112 GtkEntry *entry = GTK_ENTRY (widget);
3113 GtkEntryPrivate *priv = entry->priv;
3114 PangoFontMetrics *metrics;
3115 gint xborder, yborder;
3116 GtkBorder inner_border;
3117 GtkStyleContext *style_context;
3118 GtkStateFlags state;
3119 PangoContext *context;
3122 context = gtk_widget_get_pango_context (widget);
3124 style_context = gtk_widget_get_style_context (widget);
3125 state = gtk_widget_get_state_flags (widget);
3127 metrics = pango_context_get_metrics (context,
3128 gtk_style_context_get_font (style_context, state),
3129 pango_context_get_language (context));
3131 priv->ascent = pango_font_metrics_get_ascent (metrics);
3132 priv->descent = pango_font_metrics_get_descent (metrics);
3134 _gtk_entry_get_borders (entry, &xborder, &yborder);
3135 _gtk_entry_effective_inner_border (entry, &inner_border);
3137 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3139 pango_font_metrics_unref (metrics);
3146 place_windows (GtkEntry *entry)
3148 GtkWidget *widget = GTK_WIDGET (entry);
3149 GtkEntryPrivate *priv = entry->priv;
3150 gint x, y, width, height;
3151 gint frame_x, frame_y;
3152 GtkAllocation primary;
3153 GtkAllocation secondary;
3154 EntryIconInfo *icon_info = NULL;
3156 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3157 get_text_area_size (entry, &x, &y, &width, &height);
3158 get_icon_allocations (entry, &primary, &secondary);
3160 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3161 y += priv->focus_width;
3163 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3164 x += secondary.width;
3167 width -= primary.width + secondary.width;
3171 primary.x += frame_x;
3172 primary.y += frame_y;
3173 secondary.x += frame_x;
3174 secondary.y += frame_y;
3176 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3177 gdk_window_move_resize (icon_info->window,
3178 primary.x, primary.y,
3179 primary.width, primary.height);
3181 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3182 gdk_window_move_resize (icon_info->window,
3183 secondary.x, secondary.y,
3184 secondary.width, secondary.height);
3186 gdk_window_move_resize (priv->text_area, x, y, width, height);
3190 gtk_entry_get_text_area_size (GtkEntry *entry,
3196 GtkEntryPrivate *priv = entry->priv;
3197 GtkWidget *widget = GTK_WIDGET (entry);
3198 GtkAllocation allocation;
3199 GtkRequisition requisition;
3202 gint xborder, yborder;
3204 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3205 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3207 gtk_widget_get_allocation (widget, &allocation);
3208 _gtk_entry_get_borders (entry, &xborder, &yborder);
3210 if (gtk_widget_get_realized (widget))
3211 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3213 frame_height = req_height;
3215 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3216 frame_height -= 2 * priv->focus_width;
3222 *y = frame_height / 2 - (req_height - yborder * 2) / 2;
3225 *width = allocation.width - xborder * 2;
3228 *height = req_height - yborder * 2;
3232 get_text_area_size (GtkEntry *entry,
3238 GtkEntryClass *class;
3240 g_return_if_fail (GTK_IS_ENTRY (entry));
3242 class = GTK_ENTRY_GET_CLASS (entry);
3244 if (class->get_text_area_size)
3245 class->get_text_area_size (entry, x, y, width, height);
3250 get_frame_size (GtkEntry *entry,
3251 gboolean relative_to_window,
3257 GtkEntryPrivate *priv = entry->priv;
3258 GtkAllocation allocation;
3259 GtkRequisition requisition;
3260 GtkWidget *widget = GTK_WIDGET (entry);
3263 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3265 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3267 gtk_widget_get_allocation (widget, &allocation);
3270 *x = relative_to_window ? allocation.x : 0;
3274 if (priv->is_cell_renderer)
3277 *y = (allocation.height - req_height) / 2;
3279 if (relative_to_window)
3284 *width = allocation.width;
3288 if (priv->is_cell_renderer)
3289 *height = allocation.height;
3291 *height = req_height;
3296 _gtk_entry_effective_inner_border (GtkEntry *entry,
3299 GtkBorder *tmp_border;
3301 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3305 *border = *tmp_border;
3309 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3313 *border = *tmp_border;
3314 gtk_border_free (tmp_border);
3318 *border = default_inner_border;
3322 gtk_entry_size_allocate (GtkWidget *widget,
3323 GtkAllocation *allocation)
3325 GtkEntry *entry = GTK_ENTRY (widget);
3327 gtk_widget_set_allocation (widget, allocation);
3329 if (gtk_widget_get_realized (widget))
3331 GtkEntryCompletion* completion;
3333 place_windows (entry);
3334 gtk_entry_recompute (entry);
3336 completion = gtk_entry_get_completion (entry);
3337 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3338 _gtk_entry_completion_resize_popup (completion);
3343 should_prelight (GtkEntry *entry,
3344 GtkEntryIconPosition icon_pos)
3346 GtkEntryPrivate *priv = entry->priv;
3347 EntryIconInfo *icon_info = priv->icons[icon_pos];
3353 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3356 if (icon_info->pressed)
3359 gtk_widget_style_get (GTK_WIDGET (entry),
3360 "icon-prelight", &prelight,
3367 draw_icon (GtkWidget *widget,
3369 GtkEntryIconPosition icon_pos)
3371 GtkEntry *entry = GTK_ENTRY (widget);
3372 GtkEntryPrivate *priv = entry->priv;
3373 EntryIconInfo *icon_info = priv->icons[icon_pos];
3374 gint x, y, width, height, pix_width, pix_height;
3375 GtkStyleContext *context;
3380 width = gdk_window_get_width (icon_info->window);
3381 height = gdk_window_get_height (icon_info->window);
3383 /* size_allocate hasn't been called yet. These are the default values.
3385 if (width == 1 || height == 1)
3389 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3391 context = gtk_widget_get_style_context (widget);
3392 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3393 _gtk_icon_helper_get_size (icon_info->icon_helper, context, &pix_width, &pix_height);
3395 x = MAX (0, (width - pix_width) / 2);
3396 y = MAX (0, (height - pix_height) / 2);
3398 _gtk_icon_helper_draw (icon_info->icon_helper,
3402 gtk_style_context_restore (context);
3408 gtk_entry_draw_frame (GtkWidget *widget,
3409 GtkStyleContext *context,
3412 GtkEntry *entry = GTK_ENTRY (widget);
3413 GtkEntryPrivate *priv = entry->priv;
3414 gint x = 0, y = 0, width, height;
3415 gint frame_x, frame_y;
3419 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3421 cairo_translate (cr, frame_x, frame_y);
3423 /* Fix a problem with some themes which assume that entry->text_area's
3424 * width equals widget->window's width
3425 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3426 if (GTK_IS_SPIN_BUTTON (widget))
3428 gint xborder, yborder;
3430 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3431 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3434 width += xborder * 2;
3437 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3439 x += priv->focus_width;
3440 y += priv->focus_width;
3441 width -= 2 * priv->focus_width;
3442 height -= 2 * priv->focus_width;
3445 gtk_render_background (context, cr,
3446 x, y, width, height);
3448 if (priv->has_frame)
3449 gtk_render_frame (context, cr,
3450 x, y, width, height);
3452 gtk_entry_draw_progress (widget, context, cr);
3454 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3456 x -= priv->focus_width;
3457 y -= priv->focus_width;
3458 width += 2 * priv->focus_width;
3459 height += 2 * priv->focus_width;
3461 gtk_render_focus (context, cr,
3462 0, 0, width, height);
3469 get_progress_area (GtkWidget *widget,
3475 GtkEntry *entry = GTK_ENTRY (widget);
3476 GtkEntryPrivate *private = entry->priv;
3477 GtkBorder *progress_border;
3479 get_text_area_size (entry, x, y, width, height);
3481 if (!private->interior_focus)
3483 *x -= private->focus_width;
3484 *y -= private->focus_width;
3485 *width += 2 * private->focus_width;
3486 *height += 2 * private->focus_width;
3489 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3491 if (progress_border)
3493 *x += progress_border->left;
3494 *y += progress_border->top;
3495 *width -= progress_border->left + progress_border->right;
3496 *height -= progress_border->top + progress_border->bottom;
3498 gtk_border_free (progress_border);
3501 if (private->progress_pulse_mode)
3503 gdouble value = private->progress_pulse_current;
3505 *x += (gint) floor(value * (*width));
3506 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3508 else if (private->progress_fraction > 0)
3510 gdouble value = private->progress_fraction;
3512 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3516 bar_width = floor(value * (*width) + 0.5);
3517 *x += *width - bar_width;
3522 *width = (gint) floor(value * (*width) + 0.5);
3533 gtk_entry_draw_progress (GtkWidget *widget,
3534 GtkStyleContext *context,
3537 GtkEntry *entry = GTK_ENTRY (widget);
3538 GtkEntryPrivate *private = entry->priv;
3539 gint x, y, width, height;
3541 get_progress_area (widget, &x, &y, &width, &height);
3543 if ((width <= 0) || (height <= 0))
3546 gtk_style_context_save (context);
3547 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3548 if (private->progress_pulse_mode)
3549 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3551 gtk_render_activity (context, cr,
3552 x, y, width, height);
3554 gtk_style_context_restore (context);
3558 gtk_entry_draw (GtkWidget *widget,
3561 GtkEntry *entry = GTK_ENTRY (widget);
3562 GtkStyleContext *context;
3563 GtkStateFlags state;
3564 GtkEntryPrivate *priv = entry->priv;
3567 context = gtk_widget_get_style_context (widget);
3568 state = gtk_widget_get_state_flags (widget);
3570 gtk_style_context_save (context);
3571 gtk_style_context_set_state (context, state);
3573 /* Draw entry_bg, shadow, progress and focus */
3574 gtk_entry_draw_frame (widget, context, cr);
3576 /* Draw text and cursor */
3579 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3581 if (priv->dnd_position != -1)
3582 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3584 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3586 /* When no text is being displayed at all, don't show the cursor */
3587 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3588 gtk_widget_has_focus (widget) &&
3589 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3590 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3595 for (i = 0; i < MAX_ICONS; i++)
3597 EntryIconInfo *icon_info = priv->icons[i];
3599 if (icon_info != NULL)
3600 draw_icon (widget, cr, i);
3603 gtk_style_context_restore (context);
3609 gtk_entry_enter_notify (GtkWidget *widget,
3610 GdkEventCrossing *event)
3612 GtkEntry *entry = GTK_ENTRY (widget);
3613 GtkEntryPrivate *priv = entry->priv;
3616 for (i = 0; i < MAX_ICONS; i++)
3618 EntryIconInfo *icon_info = priv->icons[i];
3620 if (icon_info != NULL && event->window == icon_info->window)
3622 if (should_prelight (entry, i))
3624 icon_info->prelight = TRUE;
3625 gtk_widget_queue_draw (widget);
3636 gtk_entry_leave_notify (GtkWidget *widget,
3637 GdkEventCrossing *event)
3639 GtkEntry *entry = GTK_ENTRY (widget);
3640 GtkEntryPrivate *priv = entry->priv;
3643 for (i = 0; i < MAX_ICONS; i++)
3645 EntryIconInfo *icon_info = priv->icons[i];
3647 if (icon_info != NULL && event->window == icon_info->window)
3649 /* a grab means that we may never see the button release */
3650 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3651 icon_info->pressed = FALSE;
3653 if (should_prelight (entry, i))
3655 icon_info->prelight = FALSE;
3656 gtk_widget_queue_draw (widget);
3667 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3671 gint start_char, end_char;
3673 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3675 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3676 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3677 const char *text = pango_layout_get_text (layout);
3678 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3679 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3680 gint real_n_ranges, i;
3682 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3688 for (i = 0; i < real_n_ranges; ++i)
3690 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3691 r[2 * i] = r[2 * i] / PANGO_SCALE;
3696 *n_ranges = real_n_ranges;
3708 in_selection (GtkEntry *entry,
3713 gint retval = FALSE;
3715 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3717 for (i = 0; i < n_ranges; ++i)
3719 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3731 gtk_entry_button_press (GtkWidget *widget,
3732 GdkEventButton *event)
3734 GtkEntry *entry = GTK_ENTRY (widget);
3735 GtkEditable *editable = GTK_EDITABLE (widget);
3736 GtkEntryPrivate *priv = entry->priv;
3737 EntryIconInfo *icon_info = NULL;
3739 gint sel_start, sel_end;
3742 for (i = 0; i < MAX_ICONS; i++)
3744 icon_info = priv->icons[i];
3746 if (!icon_info || icon_info->insensitive)
3749 if (event->window == icon_info->window)
3751 if (should_prelight (entry, i))
3753 icon_info->prelight = FALSE;
3754 gtk_widget_queue_draw (widget);
3757 priv->start_x = event->x;
3758 priv->start_y = event->y;
3759 icon_info->pressed = TRUE;
3761 if (!icon_info->nonactivatable)
3762 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3768 if (event->window != priv->text_area ||
3769 (priv->button && event->button != priv->button))
3772 gtk_entry_reset_blink_time (entry);
3774 priv->button = event->button;
3776 if (!gtk_widget_has_focus (widget))
3778 priv->in_click = TRUE;
3779 gtk_widget_grab_focus (widget);
3780 priv->in_click = FALSE;
3783 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3785 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3787 gtk_entry_do_popup (entry, event);
3788 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3792 else if (event->button == 1)
3794 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3796 priv->select_words = FALSE;
3797 priv->select_lines = FALSE;
3800 gtk_widget_get_modifier_mask (widget,
3801 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3803 _gtk_entry_reset_im_context (entry);
3805 if (!have_selection) /* select from the current position to the clicked position */
3806 sel_start = sel_end = priv->current_pos;
3808 if (tmp_pos > sel_start && tmp_pos < sel_end)
3810 /* Truncate current selection, but keep it as big as possible */
3811 if (tmp_pos - sel_start > sel_end - tmp_pos)
3812 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3814 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3818 gboolean extend_to_left;
3821 /* Figure out what click selects and extend current selection */
3822 switch (event->type)
3824 case GDK_BUTTON_PRESS:
3825 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3828 case GDK_2BUTTON_PRESS:
3829 priv->select_words = TRUE;
3830 gtk_entry_select_word (entry);
3833 case GDK_3BUTTON_PRESS:
3834 priv->select_lines = TRUE;
3835 gtk_entry_select_line (entry);
3842 start = MIN (priv->current_pos, priv->selection_bound);
3843 start = MIN (sel_start, start);
3845 end = MAX (priv->current_pos, priv->selection_bound);
3846 end = MAX (sel_end, end);
3848 if (tmp_pos == sel_start || tmp_pos == sel_end)
3849 extend_to_left = (tmp_pos == start);
3851 extend_to_left = (end == sel_end);
3854 gtk_entry_set_positions (entry, start, end);
3856 gtk_entry_set_positions (entry, end, start);
3859 else /* no shift key */
3860 switch (event->type)
3862 case GDK_BUTTON_PRESS:
3863 if (in_selection (entry, event->x + priv->scroll_offset))
3865 /* Click inside the selection - we'll either start a drag, or
3866 * clear the selection
3868 priv->in_drag = TRUE;
3869 priv->drag_start_x = event->x + priv->scroll_offset;
3870 priv->drag_start_y = event->y;
3873 gtk_editable_set_position (editable, tmp_pos);
3876 case GDK_2BUTTON_PRESS:
3877 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3878 * receiving a GDK_2BUTTON_PRESS so we need to reset
3879 * priv->in_drag which may have been set above
3881 priv->in_drag = FALSE;
3882 priv->select_words = TRUE;
3883 gtk_entry_select_word (entry);
3886 case GDK_3BUTTON_PRESS:
3887 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3888 * receiving a GDK_3BUTTON_PRESS so we need to reset
3889 * priv->in_drag which may have been set above
3891 priv->in_drag = FALSE;
3892 priv->select_lines = TRUE;
3893 gtk_entry_select_line (entry);
3902 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3906 priv->insert_pos = tmp_pos;
3907 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3912 gtk_widget_error_bell (widget);
3920 gtk_entry_button_release (GtkWidget *widget,
3921 GdkEventButton *event)
3923 GtkEntry *entry = GTK_ENTRY (widget);
3924 GtkEntryPrivate *priv = entry->priv;
3925 EntryIconInfo *icon_info = NULL;
3928 for (i = 0; i < MAX_ICONS; i++)
3930 icon_info = priv->icons[i];
3932 if (!icon_info || icon_info->insensitive)
3935 if (event->window == icon_info->window)
3937 icon_info->pressed = FALSE;
3939 if (should_prelight (entry, i) &&
3940 event->x >= 0 && event->y >= 0 &&
3941 event->x < gdk_window_get_width (icon_info->window) &&
3942 event->y < gdk_window_get_height (icon_info->window))
3944 icon_info->prelight = TRUE;
3945 gtk_widget_queue_draw (widget);
3948 if (!icon_info->nonactivatable)
3949 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3955 if (event->window != priv->text_area || priv->button != event->button)
3960 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3962 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3969 gtk_entry_update_primary_selection (entry);
3975 _gtk_entry_get_selected_text (GtkEntry *entry)
3977 GtkEditable *editable = GTK_EDITABLE (entry);
3978 gint start_text, end_text;
3981 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3982 text = gtk_editable_get_chars (editable, start_text, end_text);
3988 gtk_entry_motion_notify (GtkWidget *widget,
3989 GdkEventMotion *event)
3991 GtkEntry *entry = GTK_ENTRY (widget);
3992 GtkEntryPrivate *priv = entry->priv;
3993 EntryIconInfo *icon_info = NULL;
3997 for (i = 0; i < MAX_ICONS; i++)
3999 icon_info = priv->icons[i];
4001 if (!icon_info || icon_info->insensitive)
4004 if (event->window == icon_info->window)
4006 if (icon_info->pressed &&
4007 icon_info->target_list != NULL &&
4008 gtk_drag_check_threshold (widget,
4014 icon_info->in_drag = TRUE;
4015 icon_info->pressed = FALSE;
4016 gtk_drag_begin (widget,
4017 icon_info->target_list,
4027 if (priv->mouse_cursor_obscured)
4031 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4032 gdk_window_set_cursor (priv->text_area, cursor);
4033 g_object_unref (cursor);
4034 priv->mouse_cursor_obscured = FALSE;
4037 if (event->window != priv->text_area || priv->button != 1)
4040 if (priv->select_lines)
4043 gdk_event_request_motions (event);
4047 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4048 gtk_drag_check_threshold (widget,
4049 priv->drag_start_x, priv->drag_start_y,
4050 event->x + priv->scroll_offset, event->y))
4052 GdkDragContext *context;
4053 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4054 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4056 cairo_surface_t *surface;
4058 gtk_target_list_add_text_targets (target_list, 0);
4060 text = _gtk_entry_get_selected_text (entry);
4061 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4063 context = gtk_drag_begin (widget, target_list, actions,
4064 priv->button, (GdkEvent *)event);
4067 gtk_drag_set_icon_surface (context, surface);
4069 gtk_drag_set_icon_default (context);
4072 cairo_surface_destroy (surface);
4075 priv->in_drag = FALSE;
4078 gtk_target_list_unref (target_list);
4085 else if (event->y >= gdk_window_get_height (priv->text_area))
4086 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4088 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4090 if (priv->select_words)
4093 gint old_min, old_max;
4096 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4097 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4099 pos = priv->current_pos;
4100 bound = priv->selection_bound;
4102 old_min = MIN(priv->current_pos, priv->selection_bound);
4103 old_max = MAX(priv->current_pos, priv->selection_bound);
4110 else if (old_max < max)
4115 else if (pos == old_min)
4117 if (priv->current_pos != min)
4122 if (priv->current_pos != max)
4126 gtk_entry_set_positions (entry, pos, bound);
4129 gtk_entry_set_positions (entry, tmp_pos, -1);
4136 set_invisible_cursor (GdkWindow *window)
4138 GdkDisplay *display;
4141 display = gdk_window_get_display (window);
4142 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4144 gdk_window_set_cursor (window, cursor);
4146 g_object_unref (cursor);
4150 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4152 GtkEntryPrivate *priv = entry->priv;
4154 if (priv->mouse_cursor_obscured)
4157 set_invisible_cursor (priv->text_area);
4159 priv->mouse_cursor_obscured = TRUE;
4163 gtk_entry_key_press (GtkWidget *widget,
4166 GtkEntry *entry = GTK_ENTRY (widget);
4167 GtkEntryPrivate *priv = entry->priv;
4169 gtk_entry_reset_blink_time (entry);
4170 gtk_entry_pend_cursor_blink (entry);
4174 if (gtk_im_context_filter_keypress (priv->im_context, event))
4176 gtk_entry_obscure_mouse_cursor (entry);
4177 priv->need_im_reset = TRUE;
4182 if (event->keyval == GDK_KEY_Return ||
4183 event->keyval == GDK_KEY_KP_Enter ||
4184 event->keyval == GDK_KEY_ISO_Enter ||
4185 event->keyval == GDK_KEY_Escape)
4187 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4189 if (completion && completion->priv->completion_timeout)
4191 g_source_remove (completion->priv->completion_timeout);
4192 completion->priv->completion_timeout = 0;
4195 _gtk_entry_reset_im_context (entry);
4198 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4199 /* Activate key bindings
4203 if (!priv->editable && event->length)
4204 gtk_widget_error_bell (widget);
4210 gtk_entry_key_release (GtkWidget *widget,
4213 GtkEntry *entry = GTK_ENTRY (widget);
4214 GtkEntryPrivate *priv = entry->priv;
4218 if (gtk_im_context_filter_keypress (priv->im_context, event))
4220 priv->need_im_reset = TRUE;
4225 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4229 gtk_entry_focus_in (GtkWidget *widget,
4230 GdkEventFocus *event)
4232 GtkEntry *entry = GTK_ENTRY (widget);
4233 GtkEntryPrivate *priv = entry->priv;
4236 gtk_widget_queue_draw (widget);
4238 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4242 priv->need_im_reset = TRUE;
4243 gtk_im_context_focus_in (priv->im_context);
4244 keymap_state_changed (keymap, entry);
4245 g_signal_connect (keymap, "state-changed",
4246 G_CALLBACK (keymap_state_changed), entry);
4249 g_signal_connect (keymap, "direction-changed",
4250 G_CALLBACK (keymap_direction_changed), entry);
4252 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4253 priv->placeholder_text != NULL)
4255 gtk_entry_recompute (entry);
4259 gtk_entry_reset_blink_time (entry);
4260 gtk_entry_check_cursor_blink (entry);
4267 gtk_entry_focus_out (GtkWidget *widget,
4268 GdkEventFocus *event)
4270 GtkEntry *entry = GTK_ENTRY (widget);
4271 GtkEntryPrivate *priv = entry->priv;
4272 GtkEntryCompletion *completion;
4275 gtk_widget_queue_draw (widget);
4277 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4281 priv->need_im_reset = TRUE;
4282 gtk_im_context_focus_out (priv->im_context);
4283 remove_capslock_feedback (entry);
4286 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4287 priv->placeholder_text != NULL)
4289 gtk_entry_recompute (entry);
4293 gtk_entry_check_cursor_blink (entry);
4296 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4297 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4299 completion = gtk_entry_get_completion (entry);
4301 _gtk_entry_completion_popdown (completion);
4307 gtk_entry_grab_focus (GtkWidget *widget)
4309 GtkEntry *entry = GTK_ENTRY (widget);
4310 GtkEntryPrivate *priv = entry->priv;
4311 gboolean select_on_focus;
4313 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4315 if (priv->editable && !priv->in_click)
4317 g_object_get (gtk_widget_get_settings (widget),
4318 "gtk-entry-select-on-focus",
4322 if (select_on_focus)
4323 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4328 gtk_entry_direction_changed (GtkWidget *widget,
4329 GtkTextDirection previous_dir)
4331 GtkEntry *entry = GTK_ENTRY (widget);
4333 gtk_entry_recompute (entry);
4335 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4339 gtk_entry_state_flags_changed (GtkWidget *widget,
4340 GtkStateFlags previous_state)
4342 GtkEntry *entry = GTK_ENTRY (widget);
4343 GtkEntryPrivate *priv = entry->priv;
4346 if (gtk_widget_get_realized (widget))
4348 if (gtk_widget_is_sensitive (widget))
4349 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4353 gdk_window_set_cursor (priv->text_area, cursor);
4356 g_object_unref (cursor);
4358 priv->mouse_cursor_obscured = FALSE;
4360 update_cursors (widget);
4363 if (!gtk_widget_is_sensitive (widget))
4365 /* Clear any selection */
4366 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4369 gtk_entry_update_cached_style_values (entry);
4373 gtk_entry_screen_changed (GtkWidget *widget,
4374 GdkScreen *old_screen)
4376 gtk_entry_recompute (GTK_ENTRY (widget));
4379 /* GtkEditable method implementations
4382 gtk_entry_insert_text (GtkEditable *editable,
4383 const gchar *new_text,
4384 gint new_text_length,
4387 g_object_ref (editable);
4390 * The incoming text may a password or other secret. We make sure
4391 * not to copy it into temporary buffers.
4394 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4396 g_object_unref (editable);
4400 gtk_entry_delete_text (GtkEditable *editable,
4404 g_object_ref (editable);
4406 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4408 g_object_unref (editable);
4412 gtk_entry_get_chars (GtkEditable *editable,
4416 GtkEntry *entry = GTK_ENTRY (editable);
4419 gint start_index, end_index;
4421 text = gtk_entry_buffer_get_text (get_buffer (entry));
4422 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4425 end_pos = text_length;
4427 start_pos = MIN (text_length, start_pos);
4428 end_pos = MIN (text_length, end_pos);
4430 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4431 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4433 return g_strndup (text + start_index, end_index - start_index);
4437 gtk_entry_real_set_position (GtkEditable *editable,
4440 GtkEntry *entry = GTK_ENTRY (editable);
4441 GtkEntryPrivate *priv = entry->priv;
4445 length = gtk_entry_buffer_get_length (get_buffer (entry));
4446 if (position < 0 || position > length)
4449 if (position != priv->current_pos ||
4450 position != priv->selection_bound)
4452 _gtk_entry_reset_im_context (entry);
4453 gtk_entry_set_positions (entry, position, position);
4458 gtk_entry_get_position (GtkEditable *editable)
4460 GtkEntry *entry = GTK_ENTRY (editable);
4461 GtkEntryPrivate *priv = entry->priv;
4463 return priv->current_pos;
4467 gtk_entry_set_selection_bounds (GtkEditable *editable,
4471 GtkEntry *entry = GTK_ENTRY (editable);
4474 length = gtk_entry_buffer_get_length (get_buffer (entry));
4480 _gtk_entry_reset_im_context (entry);
4482 gtk_entry_set_positions (entry,
4484 MIN (start, length));
4486 gtk_entry_update_primary_selection (entry);
4490 gtk_entry_get_selection_bounds (GtkEditable *editable,
4494 GtkEntry *entry = GTK_ENTRY (editable);
4495 GtkEntryPrivate *priv = entry->priv;
4497 *start = priv->selection_bound;
4498 *end = priv->current_pos;
4500 return (priv->selection_bound != priv->current_pos);
4504 icon_theme_changed (GtkEntry *entry)
4506 GtkEntryPrivate *priv = entry->priv;
4509 for (i = 0; i < MAX_ICONS; i++)
4511 EntryIconInfo *icon_info = priv->icons[i];
4512 if (icon_info != NULL)
4513 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4516 gtk_widget_queue_draw (GTK_WIDGET (entry));
4520 icon_margin_changed (GtkEntry *entry)
4522 GtkEntryPrivate *priv = entry->priv;
4525 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4527 priv->icon_margin = border.left;
4531 gtk_entry_update_cached_style_values (GtkEntry *entry)
4533 GtkEntryPrivate *priv = entry->priv;
4535 gboolean interior_focus;
4537 gtk_widget_style_get (GTK_WIDGET (entry),
4538 "focus-line-width", &focus_width,
4539 "interior-focus", &interior_focus,
4541 priv->focus_width = focus_width;
4542 priv->interior_focus = interior_focus;
4544 if (!priv->invisible_char_set)
4546 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4548 if (priv->invisible_char != ch)
4550 priv->invisible_char = ch;
4551 g_object_notify (G_OBJECT (entry), "invisible-char");
4557 gtk_entry_style_updated (GtkWidget *widget)
4559 GtkEntry *entry = GTK_ENTRY (widget);
4561 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4563 gtk_entry_update_cached_style_values (entry);
4565 gtk_entry_recompute (entry);
4567 icon_theme_changed (entry);
4568 icon_margin_changed (entry);
4571 /* GtkCellEditable method implementations
4574 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4576 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4577 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4581 gtk_cell_editable_key_press_event (GtkEntry *entry,
4582 GdkEventKey *key_event,
4585 GtkEntryPrivate *priv = entry->priv;
4587 if (key_event->keyval == GDK_KEY_Escape)
4589 priv->editing_canceled = TRUE;
4590 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4591 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4596 /* override focus */
4597 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4599 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4600 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4609 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4612 GtkEntry *entry = GTK_ENTRY (cell_editable);
4613 GtkEntryPrivate *priv = entry->priv;
4615 priv->is_cell_renderer = TRUE;
4617 g_signal_connect (cell_editable, "activate",
4618 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4619 g_signal_connect (cell_editable, "key-press-event",
4620 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4624 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4626 if (password_hint->source_id)
4627 g_source_remove (password_hint->source_id);
4629 g_slice_free (GtkEntryPasswordHint, password_hint);
4634 gtk_entry_remove_password_hint (gpointer data)
4636 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4637 password_hint->position = -1;
4639 /* Force the string to be redrawn, but now without a visible character */
4640 gtk_entry_recompute (GTK_ENTRY (data));
4644 /* Default signal handlers
4647 gtk_entry_real_insert_text (GtkEditable *editable,
4648 const gchar *new_text,
4649 gint new_text_length,
4655 n_chars = g_utf8_strlen (new_text, new_text_length);
4658 * The actual insertion into the buffer. This will end up firing the
4659 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4660 * buffer_notify_text(), buffer_notify_length()
4662 begin_change (GTK_ENTRY (editable));
4663 g_object_freeze_notify (G_OBJECT (editable));
4665 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4667 g_object_thaw_notify (G_OBJECT (editable));
4668 end_change (GTK_ENTRY (editable));
4670 if (n_inserted != n_chars)
4671 gtk_widget_error_bell (GTK_WIDGET (editable));
4673 *position += n_inserted;
4677 gtk_entry_real_delete_text (GtkEditable *editable,
4682 * The actual deletion from the buffer. This will end up firing the
4683 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4684 * buffer_notify_text(), buffer_notify_length()
4687 begin_change (GTK_ENTRY (editable));
4688 g_object_freeze_notify (G_OBJECT (editable));
4689 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4690 g_object_thaw_notify (G_OBJECT (editable));
4691 end_change (GTK_ENTRY (editable));
4694 /* GtkEntryBuffer signal handlers
4697 buffer_inserted_text (GtkEntryBuffer *buffer,
4703 GtkEntryPrivate *priv = entry->priv;
4704 guint password_hint_timeout;
4706 gint selection_bound;
4708 current_pos = priv->current_pos;
4709 if (current_pos > position)
4710 current_pos += n_chars;
4712 selection_bound = priv->selection_bound;
4713 if (selection_bound > position)
4714 selection_bound += n_chars;
4716 gtk_entry_set_positions (entry, current_pos, selection_bound);
4718 /* Calculate the password hint if it needs to be displayed. */
4719 if (n_chars == 1 && !priv->visible)
4721 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4722 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4725 if (password_hint_timeout > 0)
4727 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4728 quark_password_hint);
4731 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4732 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4733 (GDestroyNotify)gtk_entry_password_hint_free);
4736 password_hint->position = position;
4737 if (password_hint->source_id)
4738 g_source_remove (password_hint->source_id);
4739 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4740 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4746 buffer_deleted_text (GtkEntryBuffer *buffer,
4751 GtkEntryPrivate *priv = entry->priv;
4752 guint end_pos = position + n_chars;
4753 gint selection_bound;
4756 current_pos = priv->current_pos;
4757 if (current_pos > position)
4758 current_pos -= MIN (current_pos, end_pos) - position;
4760 selection_bound = priv->selection_bound;
4761 if (selection_bound > position)
4762 selection_bound -= MIN (selection_bound, end_pos) - position;
4764 gtk_entry_set_positions (entry, current_pos, selection_bound);
4766 /* We might have deleted the selection */
4767 gtk_entry_update_primary_selection (entry);
4769 /* Disable the password hint if one exists. */
4772 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4773 quark_password_hint);
4776 if (password_hint->source_id)
4777 g_source_remove (password_hint->source_id);
4778 password_hint->source_id = 0;
4779 password_hint->position = -1;
4785 buffer_notify_text (GtkEntryBuffer *buffer,
4789 gtk_entry_recompute (entry);
4790 emit_changed (entry);
4791 g_object_notify (G_OBJECT (entry), "text");
4795 buffer_notify_length (GtkEntryBuffer *buffer,
4799 g_object_notify (G_OBJECT (entry), "text-length");
4803 buffer_notify_max_length (GtkEntryBuffer *buffer,
4807 g_object_notify (G_OBJECT (entry), "max-length");
4811 buffer_connect_signals (GtkEntry *entry)
4813 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4814 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4815 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4816 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4817 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4821 buffer_disconnect_signals (GtkEntry *entry)
4823 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4824 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4825 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4826 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4827 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4830 /* Compute the X position for an offset that corresponds to the "more important
4831 * cursor position for that offset. We use this when trying to guess to which
4832 * end of the selection we should go to when the user hits the left or
4836 get_better_cursor_x (GtkEntry *entry,
4839 GtkEntryPrivate *priv = entry->priv;
4840 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4841 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4842 gboolean split_cursor;
4844 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4845 const gchar *text = pango_layout_get_text (layout);
4846 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4848 PangoRectangle strong_pos, weak_pos;
4850 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4851 "gtk-split-cursor", &split_cursor,
4854 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4857 return strong_pos.x / PANGO_SCALE;
4859 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4863 gtk_entry_move_cursor (GtkEntry *entry,
4864 GtkMovementStep step,
4866 gboolean extend_selection)
4868 GtkEntryPrivate *priv = entry->priv;
4869 gint new_pos = priv->current_pos;
4871 _gtk_entry_reset_im_context (entry);
4873 if (priv->current_pos != priv->selection_bound && !extend_selection)
4875 /* If we have a current selection and aren't extending it, move to the
4876 * start/or end of the selection as appropriate
4880 case GTK_MOVEMENT_VISUAL_POSITIONS:
4882 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4883 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4886 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4888 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4891 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4892 case GTK_MOVEMENT_WORDS:
4894 new_pos = MIN (priv->current_pos, priv->selection_bound);
4896 new_pos = MAX (priv->current_pos, priv->selection_bound);
4898 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4899 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4900 case GTK_MOVEMENT_BUFFER_ENDS:
4901 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4903 case GTK_MOVEMENT_DISPLAY_LINES:
4904 case GTK_MOVEMENT_PARAGRAPHS:
4905 case GTK_MOVEMENT_PAGES:
4906 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4914 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4915 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4917 case GTK_MOVEMENT_VISUAL_POSITIONS:
4918 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4919 if (priv->current_pos == new_pos)
4921 if (!extend_selection)
4923 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4925 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4927 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4930 gtk_widget_child_focus (toplevel,
4932 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4937 gtk_widget_error_bell (GTK_WIDGET (entry));
4941 case GTK_MOVEMENT_WORDS:
4944 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4949 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4952 if (priv->current_pos == new_pos)
4953 gtk_widget_error_bell (GTK_WIDGET (entry));
4955 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4956 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4957 case GTK_MOVEMENT_BUFFER_ENDS:
4958 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4959 if (priv->current_pos == new_pos)
4960 gtk_widget_error_bell (GTK_WIDGET (entry));
4962 case GTK_MOVEMENT_DISPLAY_LINES:
4963 case GTK_MOVEMENT_PARAGRAPHS:
4964 case GTK_MOVEMENT_PAGES:
4965 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4970 if (extend_selection)
4971 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4973 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4975 gtk_entry_pend_cursor_blink (entry);
4979 gtk_entry_insert_at_cursor (GtkEntry *entry,
4982 GtkEntryPrivate *priv = entry->priv;
4983 GtkEditable *editable = GTK_EDITABLE (entry);
4984 gint pos = priv->current_pos;
4988 _gtk_entry_reset_im_context (entry);
4990 gtk_editable_insert_text (editable, str, -1, &pos);
4991 gtk_editable_set_position (editable, pos);
4996 gtk_entry_delete_from_cursor (GtkEntry *entry,
5000 GtkEntryPrivate *priv = entry->priv;
5001 GtkEditable *editable = GTK_EDITABLE (entry);
5002 gint start_pos = priv->current_pos;
5003 gint end_pos = priv->current_pos;
5004 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5006 _gtk_entry_reset_im_context (entry);
5008 if (!priv->editable)
5010 gtk_widget_error_bell (GTK_WIDGET (entry));
5014 if (priv->selection_bound != priv->current_pos)
5016 gtk_editable_delete_selection (editable);
5022 case GTK_DELETE_CHARS:
5023 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5024 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5026 case GTK_DELETE_WORDS:
5029 /* Move to end of current word, or if not on a word, end of previous word */
5030 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5031 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5035 /* Move to beginning of current word, or if not on a word, begining of next word */
5036 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5037 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5041 case GTK_DELETE_WORD_ENDS:
5044 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5049 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5052 gtk_editable_delete_text (editable, start_pos, end_pos);
5054 case GTK_DELETE_DISPLAY_LINE_ENDS:
5055 case GTK_DELETE_PARAGRAPH_ENDS:
5057 gtk_editable_delete_text (editable, 0, priv->current_pos);
5059 gtk_editable_delete_text (editable, priv->current_pos, -1);
5061 case GTK_DELETE_DISPLAY_LINES:
5062 case GTK_DELETE_PARAGRAPHS:
5063 gtk_editable_delete_text (editable, 0, -1);
5065 case GTK_DELETE_WHITESPACE:
5066 gtk_entry_delete_whitespace (entry);
5070 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5071 gtk_widget_error_bell (GTK_WIDGET (entry));
5073 gtk_entry_pend_cursor_blink (entry);
5077 gtk_entry_backspace (GtkEntry *entry)
5079 GtkEntryPrivate *priv = entry->priv;
5080 GtkEditable *editable = GTK_EDITABLE (entry);
5083 _gtk_entry_reset_im_context (entry);
5085 if (!priv->editable)
5087 gtk_widget_error_bell (GTK_WIDGET (entry));
5091 if (priv->selection_bound != priv->current_pos)
5093 gtk_editable_delete_selection (editable);
5097 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5099 if (prev_pos < priv->current_pos)
5101 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5102 PangoLogAttr *log_attrs;
5105 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5107 /* Deleting parts of characters */
5108 if (log_attrs[priv->current_pos].backspace_deletes_character)
5110 gchar *cluster_text;
5111 gchar *normalized_text;
5114 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5116 normalized_text = g_utf8_normalize (cluster_text,
5117 strlen (cluster_text),
5119 len = g_utf8_strlen (normalized_text, -1);
5121 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5124 gint pos = priv->current_pos;
5126 gtk_editable_insert_text (editable, normalized_text,
5127 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5129 gtk_editable_set_position (editable, pos);
5132 g_free (normalized_text);
5133 g_free (cluster_text);
5137 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5144 gtk_widget_error_bell (GTK_WIDGET (entry));
5147 gtk_entry_pend_cursor_blink (entry);
5151 gtk_entry_copy_clipboard (GtkEntry *entry)
5153 GtkEntryPrivate *priv = entry->priv;
5154 GtkEditable *editable = GTK_EDITABLE (entry);
5158 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5162 gtk_widget_error_bell (GTK_WIDGET (entry));
5166 str = gtk_entry_get_display_text (entry, start, end);
5167 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5168 GDK_SELECTION_CLIPBOARD),
5175 gtk_entry_cut_clipboard (GtkEntry *entry)
5177 GtkEntryPrivate *priv = entry->priv;
5178 GtkEditable *editable = GTK_EDITABLE (entry);
5183 gtk_widget_error_bell (GTK_WIDGET (entry));
5187 gtk_entry_copy_clipboard (entry);
5191 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5192 gtk_editable_delete_text (editable, start, end);
5196 gtk_widget_error_bell (GTK_WIDGET (entry));
5201 gtk_entry_paste_clipboard (GtkEntry *entry)
5203 GtkEntryPrivate *priv = entry->priv;
5206 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5208 gtk_widget_error_bell (GTK_WIDGET (entry));
5212 gtk_entry_delete_cb (GtkEntry *entry)
5214 GtkEntryPrivate *priv = entry->priv;
5215 GtkEditable *editable = GTK_EDITABLE (entry);
5220 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5221 gtk_editable_delete_text (editable, start, end);
5226 gtk_entry_toggle_overwrite (GtkEntry *entry)
5228 GtkEntryPrivate *priv = entry->priv;
5230 priv->overwrite_mode = !priv->overwrite_mode;
5231 gtk_entry_pend_cursor_blink (entry);
5232 gtk_widget_queue_draw (GTK_WIDGET (entry));
5236 gtk_entry_select_all (GtkEntry *entry)
5238 gtk_entry_select_line (entry);
5242 gtk_entry_real_activate (GtkEntry *entry)
5244 GtkEntryPrivate *priv = entry->priv;
5246 GtkWidget *default_widget, *focus_widget;
5247 GtkWidget *toplevel;
5250 widget = GTK_WIDGET (entry);
5252 if (priv->activates_default)
5254 toplevel = gtk_widget_get_toplevel (widget);
5255 if (GTK_IS_WINDOW (toplevel))
5257 window = GTK_WINDOW (toplevel);
5261 default_widget = gtk_window_get_default_widget (window);
5262 focus_widget = gtk_window_get_focus (window);
5263 if (widget != default_widget &&
5264 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5265 gtk_window_activate_default (window);
5272 keymap_direction_changed (GdkKeymap *keymap,
5275 gtk_entry_recompute (entry);
5278 /* IM Context Callbacks
5282 gtk_entry_commit_cb (GtkIMContext *context,
5286 GtkEntryPrivate *priv = entry->priv;
5289 gtk_entry_enter_text (entry, str);
5293 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5296 GtkEntryPrivate *priv = entry->priv;
5300 gchar *preedit_string;
5303 gtk_im_context_get_preedit_string (priv->im_context,
5304 &preedit_string, NULL,
5306 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5307 priv->preedit_length = strlen (preedit_string);
5308 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5309 priv->preedit_cursor = cursor_pos;
5310 g_free (preedit_string);
5312 gtk_entry_recompute (entry);
5317 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5320 GtkEntryPrivate *priv = entry->priv;
5323 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5324 text = gtk_entry_get_display_text (entry, 0, -1);
5325 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5326 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5333 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5338 GtkEntryPrivate *priv = entry->priv;
5341 gtk_editable_delete_text (GTK_EDITABLE (entry),
5342 priv->current_pos + offset,
5343 priv->current_pos + offset + n_chars);
5348 /* Internal functions
5351 /* Used for im_commit_cb and inserting Unicode chars */
5353 gtk_entry_enter_text (GtkEntry *entry,
5356 GtkEntryPrivate *priv = entry->priv;
5357 GtkEditable *editable = GTK_EDITABLE (entry);
5359 gboolean old_need_im_reset;
5361 old_need_im_reset = priv->need_im_reset;
5362 priv->need_im_reset = FALSE;
5364 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5365 gtk_editable_delete_selection (editable);
5368 if (priv->overwrite_mode)
5369 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5372 tmp_pos = priv->current_pos;
5373 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5374 gtk_editable_set_position (editable, tmp_pos);
5376 priv->need_im_reset = old_need_im_reset;
5379 /* All changes to priv->current_pos and priv->selection_bound
5380 * should go through this function.
5383 gtk_entry_set_positions (GtkEntry *entry,
5385 gint selection_bound)
5387 GtkEntryPrivate *priv = entry->priv;
5388 gboolean changed = FALSE;
5390 g_object_freeze_notify (G_OBJECT (entry));
5392 if (current_pos != -1 &&
5393 priv->current_pos != current_pos)
5395 priv->current_pos = current_pos;
5398 g_object_notify (G_OBJECT (entry), "cursor-position");
5401 if (selection_bound != -1 &&
5402 priv->selection_bound != selection_bound)
5404 priv->selection_bound = selection_bound;
5407 g_object_notify (G_OBJECT (entry), "selection-bound");
5410 g_object_thaw_notify (G_OBJECT (entry));
5414 gtk_entry_move_adjustments (entry);
5415 gtk_entry_recompute (entry);
5420 gtk_entry_reset_layout (GtkEntry *entry)
5422 GtkEntryPrivate *priv = entry->priv;
5424 if (priv->cached_layout)
5426 g_object_unref (priv->cached_layout);
5427 priv->cached_layout = NULL;
5432 update_im_cursor_location (GtkEntry *entry)
5434 GtkEntryPrivate *priv = entry->priv;
5437 gint strong_xoffset;
5438 gint area_width, area_height;
5440 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5441 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5443 strong_xoffset = strong_x - priv->scroll_offset;
5444 if (strong_xoffset < 0)
5448 else if (strong_xoffset > area_width)
5450 strong_xoffset = area_width;
5452 area.x = strong_xoffset;
5455 area.height = area_height;
5457 gtk_im_context_set_cursor_location (priv->im_context, &area);
5461 recompute_idle_func (gpointer data)
5463 GtkEntry *entry = GTK_ENTRY (data);
5464 GtkEntryPrivate *priv = entry->priv;
5466 priv->recompute_idle = 0;
5468 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5470 gtk_entry_adjust_scroll (entry);
5471 gtk_widget_queue_draw (GTK_WIDGET (entry));
5473 update_im_cursor_location (entry);
5480 gtk_entry_recompute (GtkEntry *entry)
5482 GtkEntryPrivate *priv = entry->priv;
5484 gtk_entry_reset_layout (entry);
5485 gtk_entry_check_cursor_blink (entry);
5487 if (!priv->recompute_idle)
5489 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5490 recompute_idle_func, entry, NULL);
5495 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5498 GtkWidget *widget = GTK_WIDGET (entry);
5499 GtkStyleContext *context;
5500 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5502 context = gtk_widget_get_style_context (widget);
5503 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5505 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5506 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5507 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5510 static inline gboolean
5511 show_placeholder_text (GtkEntry *entry)
5513 GtkEntryPrivate *priv = entry->priv;
5515 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5516 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5517 priv->placeholder_text != NULL)
5523 static PangoLayout *
5524 gtk_entry_create_layout (GtkEntry *entry,
5525 gboolean include_preedit)
5527 GtkEntryPrivate *priv = entry->priv;
5528 GtkWidget *widget = GTK_WIDGET (entry);
5529 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5530 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5531 gboolean placeholder_layout = show_placeholder_text (entry);
5533 gchar *preedit_string = NULL;
5534 gint preedit_length = 0;
5535 PangoAttrList *preedit_attrs = NULL;
5540 pango_layout_set_single_paragraph_mode (layout, TRUE);
5542 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5543 n_bytes = strlen (display);
5545 if (!placeholder_layout && include_preedit)
5547 gtk_im_context_get_preedit_string (priv->im_context,
5548 &preedit_string, &preedit_attrs, NULL);
5549 preedit_length = priv->preedit_length;
5551 else if (placeholder_layout)
5554 PangoAttribute *attr;
5556 gtk_entry_get_placeholder_text_color (entry, &color);
5557 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5558 attr->start_index = 0;
5559 attr->end_index = G_MAXINT;
5560 pango_attr_list_insert (tmp_attrs, attr);
5565 GString *tmp_string = g_string_new (display);
5566 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5568 g_string_insert (tmp_string, cursor_index, preedit_string);
5570 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5572 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5573 cursor_index, preedit_length);
5575 g_string_free (tmp_string, TRUE);
5579 PangoDirection pango_dir;
5581 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5582 pango_dir = pango_find_base_dir (display, n_bytes);
5584 pango_dir = PANGO_DIRECTION_NEUTRAL;
5586 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5588 if (gtk_widget_has_focus (widget))
5590 GdkDisplay *display = gtk_widget_get_display (widget);
5591 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5592 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5593 pango_dir = PANGO_DIRECTION_RTL;
5595 pango_dir = PANGO_DIRECTION_LTR;
5599 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5600 pango_dir = PANGO_DIRECTION_RTL;
5602 pango_dir = PANGO_DIRECTION_LTR;
5606 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5609 priv->resolved_dir = pango_dir;
5611 pango_layout_set_text (layout, display, n_bytes);
5614 pango_layout_set_attributes (layout, tmp_attrs);
5616 g_free (preedit_string);
5620 pango_attr_list_unref (preedit_attrs);
5622 pango_attr_list_unref (tmp_attrs);
5627 static PangoLayout *
5628 gtk_entry_ensure_layout (GtkEntry *entry,
5629 gboolean include_preedit)
5631 GtkEntryPrivate *priv = entry->priv;
5633 if (priv->preedit_length > 0 &&
5634 !include_preedit != !priv->cache_includes_preedit)
5635 gtk_entry_reset_layout (entry);
5637 if (!priv->cached_layout)
5639 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5640 priv->cache_includes_preedit = include_preedit;
5643 return priv->cached_layout;
5647 get_layout_position (GtkEntry *entry,
5651 GtkEntryPrivate *priv = entry->priv;
5652 PangoLayout *layout;
5653 PangoRectangle logical_rect;
5654 gint area_width, area_height;
5655 GtkBorder inner_border;
5657 PangoLayoutLine *line;
5659 layout = gtk_entry_ensure_layout (entry, TRUE);
5661 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5662 _gtk_entry_effective_inner_border (entry, &inner_border);
5664 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5666 line = pango_layout_get_lines_readonly (layout)->data;
5667 pango_layout_line_get_extents (line, NULL, &logical_rect);
5669 /* Align primarily for locale's ascent/descent */
5670 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5671 priv->ascent + logical_rect.y);
5673 /* Now see if we need to adjust to fit in actual drawn string */
5674 if (logical_rect.height > area_height)
5675 y_pos = (area_height - logical_rect.height) / 2;
5678 else if (y_pos + logical_rect.height > area_height)
5679 y_pos = area_height - logical_rect.height;
5681 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5684 *x = inner_border.left - priv->scroll_offset;
5691 draw_text_with_color (GtkEntry *entry,
5693 GdkRGBA *default_color)
5695 GtkEntryPrivate *priv = entry->priv;
5696 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5699 gint start_pos, end_pos;
5701 widget = GTK_WIDGET (entry);
5705 get_layout_position (entry, &x, &y);
5707 cairo_move_to (cr, x, y);
5708 gdk_cairo_set_source_rgba (cr, default_color);
5709 pango_cairo_show_layout (cr, layout);
5711 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5715 PangoRectangle logical_rect;
5716 GdkRGBA selection_color, text_color;
5717 GtkBorder inner_border;
5718 GtkStyleContext *context;
5719 GtkStateFlags state;
5721 context = gtk_widget_get_style_context (widget);
5722 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5723 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5725 state = GTK_STATE_FLAG_SELECTED;
5727 if (gtk_widget_has_focus (widget))
5728 state |= GTK_STATE_FLAG_FOCUSED;
5730 gtk_style_context_get_background_color (context, state, &selection_color);
5731 gtk_style_context_get_color (context, state, &text_color);
5733 _gtk_entry_effective_inner_border (entry, &inner_border);
5735 for (i = 0; i < n_ranges; ++i)
5736 cairo_rectangle (cr,
5737 inner_border.left - priv->scroll_offset + ranges[2 * i],
5740 logical_rect.height);
5744 gdk_cairo_set_source_rgba (cr, &selection_color);
5747 cairo_move_to (cr, x, y);
5748 gdk_cairo_set_source_rgba (cr, &text_color);
5749 pango_cairo_show_layout (cr, layout);
5757 gtk_entry_draw_text (GtkEntry *entry,
5760 GtkEntryPrivate *priv = entry->priv;
5761 GtkWidget *widget = GTK_WIDGET (entry);
5762 GtkStateFlags state = 0;
5763 GdkRGBA text_color, bar_text_color;
5764 GtkStyleContext *context;
5766 gint progress_x, progress_y, progress_width, progress_height;
5767 gint clip_width, clip_height;
5769 /* Nothing to display at all */
5770 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5773 state = gtk_widget_get_state_flags (widget);
5774 context = gtk_widget_get_style_context (widget);
5776 gtk_style_context_get_color (context, state, &text_color);
5778 /* Get foreground color for progressbars */
5779 gtk_style_context_save (context);
5780 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5781 gtk_style_context_get_color (context, state, &bar_text_color);
5782 gtk_style_context_restore (context);
5784 get_progress_area (widget,
5785 &progress_x, &progress_y,
5786 &progress_width, &progress_height);
5790 clip_width = gdk_window_get_width (priv->text_area);
5791 clip_height = gdk_window_get_height (priv->text_area);
5792 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5795 /* If the color is the same, or the progress area has a zero
5796 * size, then we only need to draw once. */
5797 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5798 ((progress_width == 0) || (progress_height == 0)))
5800 draw_text_with_color (entry, cr, &text_color);
5804 int frame_x, frame_y, area_x, area_y;
5806 width = gdk_window_get_width (priv->text_area);
5807 height = gdk_window_get_height (priv->text_area);
5811 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5812 cairo_rectangle (cr, 0, 0, width, height);
5814 /* progres area is frame-relative, we need it text-area window
5816 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5817 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5818 progress_x += frame_x - area_x;
5819 progress_y += frame_y - area_y;
5821 cairo_rectangle (cr, progress_x, progress_y,
5822 progress_width, progress_height);
5824 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5826 draw_text_with_color (entry, cr, &text_color);
5831 cairo_rectangle (cr, progress_x, progress_y,
5832 progress_width, progress_height);
5835 draw_text_with_color (entry, cr, &bar_text_color);
5844 gtk_entry_draw_cursor (GtkEntry *entry,
5848 GtkEntryPrivate *priv = entry->priv;
5849 GtkWidget *widget = GTK_WIDGET (entry);
5850 GtkStyleContext *context;
5851 PangoRectangle cursor_rect;
5854 gboolean block_at_line_end;
5855 PangoLayout *layout;
5858 context = gtk_widget_get_style_context (widget);
5860 layout = gtk_entry_ensure_layout (entry, TRUE);
5861 text = pango_layout_get_text (layout);
5862 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5864 if (!priv->overwrite_mode)
5867 block = _gtk_text_util_get_block_cursor_location (layout,
5868 cursor_index, &cursor_rect, &block_at_line_end);
5872 GtkBorder inner_border;
5874 _gtk_entry_effective_inner_border (entry, &inner_border);
5876 gtk_render_insertion_cursor (context, cr,
5877 inner_border.left - priv->scroll_offset, inner_border.top,
5878 layout, cursor_index, priv->resolved_dir);
5880 else /* overwrite_mode */
5882 GdkRGBA cursor_color;
5888 get_layout_position (entry, &x, &y);
5890 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5891 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5892 rect.width = PANGO_PIXELS (cursor_rect.width);
5893 rect.height = PANGO_PIXELS (cursor_rect.height);
5895 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5896 gdk_cairo_set_source_rgba (cr, &cursor_color);
5897 gdk_cairo_rectangle (cr, &rect);
5900 if (!block_at_line_end)
5902 GtkStateFlags state;
5905 state = gtk_widget_get_state_flags (widget);
5906 gtk_style_context_get_background_color (context, state, &color);
5908 gdk_cairo_rectangle (cr, &rect);
5910 cairo_move_to (cr, x, y);
5911 gdk_cairo_set_source_rgba (cr, &color);
5912 pango_cairo_show_layout (cr, layout);
5920 _gtk_entry_reset_im_context (GtkEntry *entry)
5922 GtkEntryPrivate *priv = entry->priv;
5924 if (priv->need_im_reset)
5926 priv->need_im_reset = FALSE;
5927 gtk_im_context_reset (priv->im_context);
5932 * gtk_entry_reset_im_context:
5933 * @entry: a #GtkEntry
5935 * Reset the input method context of the entry if needed.
5937 * This can be necessary in the case where modifying the buffer
5938 * would confuse on-going input method behavior.
5943 gtk_entry_reset_im_context (GtkEntry *entry)
5945 g_return_if_fail (GTK_IS_ENTRY (entry));
5947 _gtk_entry_reset_im_context (entry);
5951 * gtk_entry_im_context_filter_keypress:
5952 * @entry: a #GtkEntry
5953 * @event: (type Gdk.EventKey): the key event
5955 * Allow the #GtkEntry input method to internally handle key press
5956 * and release events. If this function returns %TRUE, then no further
5957 * processing should be done for this key event. See
5958 * gtk_im_context_filter_keypress().
5960 * Note that you are expected to call this function from your handler
5961 * when overriding key event handling. This is needed in the case when
5962 * you need to insert your own key handling between the input method
5963 * and the default key event handling of the #GtkEntry.
5964 * See gtk_text_view_reset_im_context() for an example of use.
5966 * Return value: %TRUE if the input method handled the key event.
5971 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5974 GtkEntryPrivate *priv;
5976 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5980 return gtk_im_context_filter_keypress (priv->im_context, event);
5984 _gtk_entry_get_im_context (GtkEntry *entry)
5986 return entry->priv->im_context;
5990 gtk_entry_find_position (GtkEntry *entry,
5993 GtkEntryPrivate *priv = entry->priv;
5994 PangoLayout *layout;
5995 PangoLayoutLine *line;
6002 layout = gtk_entry_ensure_layout (entry, TRUE);
6003 text = pango_layout_get_text (layout);
6004 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6006 line = pango_layout_get_lines_readonly (layout)->data;
6007 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6009 if (index >= cursor_index && priv->preedit_length)
6011 if (index >= cursor_index + priv->preedit_length)
6012 index -= priv->preedit_length;
6015 index = cursor_index;
6020 pos = g_utf8_pointer_to_offset (text, text + index);
6027 gtk_entry_get_cursor_locations (GtkEntry *entry,
6032 GtkEntryPrivate *priv = entry->priv;
6033 DisplayMode mode = gtk_entry_get_display_mode (entry);
6035 /* Nothing to display at all, so no cursor is relevant */
6036 if (mode == DISPLAY_BLANK)
6046 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6047 const gchar *text = pango_layout_get_text (layout);
6048 PangoRectangle strong_pos, weak_pos;
6051 if (type == CURSOR_STANDARD)
6053 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6055 else /* type == CURSOR_DND */
6057 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6059 if (priv->dnd_position > priv->current_pos)
6061 if (mode == DISPLAY_NORMAL)
6062 index += priv->preedit_length;
6065 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6066 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6071 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6074 *strong_x = strong_pos.x / PANGO_SCALE;
6077 *weak_x = weak_pos.x / PANGO_SCALE;
6082 gtk_entry_adjust_scroll (GtkEntry *entry)
6084 GtkEntryPrivate *priv = entry->priv;
6085 gint min_offset, max_offset;
6086 gint text_area_width, text_width;
6087 GtkBorder inner_border;
6088 gint strong_x, weak_x;
6089 gint strong_xoffset, weak_xoffset;
6091 PangoLayout *layout;
6092 PangoLayoutLine *line;
6093 PangoRectangle logical_rect;
6095 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6098 _gtk_entry_effective_inner_border (entry, &inner_border);
6100 text_area_width = gdk_window_get_width (priv->text_area);
6101 text_area_width -= inner_border.left + inner_border.right;
6102 if (text_area_width < 0)
6103 text_area_width = 0;
6105 layout = gtk_entry_ensure_layout (entry, TRUE);
6106 line = pango_layout_get_lines_readonly (layout)->data;
6108 pango_layout_line_get_extents (line, NULL, &logical_rect);
6110 /* Display as much text as we can */
6112 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6113 xalign = priv->xalign;
6115 xalign = 1.0 - priv->xalign;
6117 text_width = PANGO_PIXELS(logical_rect.width);
6119 if (text_width > text_area_width)
6122 max_offset = text_width - text_area_width;
6126 min_offset = (text_width - text_area_width) * xalign;
6127 max_offset = min_offset;
6130 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6132 /* And make sure cursors are on screen. Note that the cursor is
6133 * actually drawn one pixel into the INNER_BORDER space on
6134 * the right, when the scroll is at the utmost right. This
6135 * looks better to to me than confining the cursor inside the
6136 * border entirely, though it means that the cursor gets one
6137 * pixel closer to the edge of the widget on the right than
6138 * on the left. This might need changing if one changed
6139 * INNER_BORDER from 2 to 1, as one would do on a
6140 * small-screen-real-estate display.
6142 * We always make sure that the strong cursor is on screen, and
6143 * put the weak cursor on screen if possible.
6146 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6148 strong_xoffset = strong_x - priv->scroll_offset;
6150 if (strong_xoffset < 0)
6152 priv->scroll_offset += strong_xoffset;
6155 else if (strong_xoffset > text_area_width)
6157 priv->scroll_offset += strong_xoffset - text_area_width;
6158 strong_xoffset = text_area_width;
6161 weak_xoffset = weak_x - priv->scroll_offset;
6163 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6165 priv->scroll_offset += weak_xoffset;
6167 else if (weak_xoffset > text_area_width &&
6168 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6170 priv->scroll_offset += weak_xoffset - text_area_width;
6173 g_object_notify (G_OBJECT (entry), "scroll-offset");
6177 gtk_entry_move_adjustments (GtkEntry *entry)
6179 GtkWidget *widget = GTK_WIDGET (entry);
6180 GtkAllocation allocation;
6181 GtkAdjustment *adjustment;
6182 PangoContext *context;
6183 PangoFontMetrics *metrics;
6184 GtkStyleContext *style_context;
6185 GtkStateFlags state;
6186 gint x, layout_x, border_x, border_y;
6189 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6193 gtk_widget_get_allocation (widget, &allocation);
6195 /* Cursor position, layout offset, border width, and widget allocation */
6196 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6197 get_layout_position (entry, &layout_x, NULL);
6198 _gtk_entry_get_borders (entry, &border_x, &border_y);
6199 x += allocation.x + layout_x + border_x;
6201 /* Approximate width of a char, so user can see what is ahead/behind */
6202 context = gtk_widget_get_pango_context (widget);
6203 style_context = gtk_widget_get_style_context (widget);
6204 state = gtk_widget_get_state_flags (widget);
6206 metrics = pango_context_get_metrics (context,
6207 gtk_style_context_get_font (style_context, state),
6208 pango_context_get_language (context));
6209 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6212 gtk_adjustment_clamp_page (adjustment,
6213 x - (char_width + 1), /* one char + one pixel before */
6214 x + (char_width + 2)); /* one char + cursor + one pixel after */
6218 gtk_entry_move_visually (GtkEntry *entry,
6222 GtkEntryPrivate *priv = entry->priv;
6224 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6227 text = pango_layout_get_text (layout);
6229 index = g_utf8_offset_to_pointer (text, start) - text;
6233 int new_index, new_trailing;
6234 gboolean split_cursor;
6237 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6238 "gtk-split-cursor", &split_cursor,
6245 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6246 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6248 strong = keymap_direction == priv->resolved_dir;
6253 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6258 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6264 else if (new_index != G_MAXINT)
6267 while (new_trailing--)
6268 index = g_utf8_next_char (text + index) - text;
6271 return g_utf8_pointer_to_offset (text, text + index);
6275 gtk_entry_move_logically (GtkEntry *entry,
6279 gint new_pos = start;
6282 length = gtk_entry_buffer_get_length (get_buffer (entry));
6284 /* Prevent any leak of information */
6285 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6287 new_pos = CLAMP (start + count, 0, length);
6291 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6292 PangoLogAttr *log_attrs;
6295 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6297 while (count > 0 && new_pos < length)
6301 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6305 while (count < 0 && new_pos > 0)
6309 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6321 gtk_entry_move_forward_word (GtkEntry *entry,
6323 gboolean allow_whitespace)
6325 gint new_pos = start;
6328 length = gtk_entry_buffer_get_length (get_buffer (entry));
6330 /* Prevent any leak of information */
6331 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6335 else if (new_pos < length)
6337 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6338 PangoLogAttr *log_attrs;
6341 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6343 /* Find the next word boundary */
6345 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6346 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6357 gtk_entry_move_backward_word (GtkEntry *entry,
6359 gboolean allow_whitespace)
6361 gint new_pos = start;
6363 /* Prevent any leak of information */
6364 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6370 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6371 PangoLogAttr *log_attrs;
6374 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6376 new_pos = start - 1;
6378 /* Find the previous word boundary */
6379 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6380 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6390 gtk_entry_delete_whitespace (GtkEntry *entry)
6392 GtkEntryPrivate *priv = entry->priv;
6393 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6394 PangoLogAttr *log_attrs;
6398 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6400 start = end = priv->current_pos;
6402 while (start > 0 && log_attrs[start-1].is_white)
6405 while (end < n_attrs && log_attrs[end].is_white)
6411 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6416 gtk_entry_select_word (GtkEntry *entry)
6418 GtkEntryPrivate *priv = entry->priv;
6419 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6420 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6422 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6426 gtk_entry_select_line (GtkEntry *entry)
6428 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6432 truncate_multiline (const gchar *text)
6437 text[length] && text[length] != '\n' && text[length] != '\r';
6444 paste_received (GtkClipboard *clipboard,
6448 GtkEntry *entry = GTK_ENTRY (data);
6449 GtkEditable *editable = GTK_EDITABLE (entry);
6450 GtkEntryPrivate *priv = entry->priv;
6452 if (priv->button == 2)
6454 gint pos, start, end;
6455 pos = priv->insert_pos;
6456 gtk_editable_get_selection_bounds (editable, &start, &end);
6457 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6458 gtk_editable_select_region (editable, pos, pos);
6463 gint pos, start, end;
6465 gboolean popup_completion;
6466 GtkEntryCompletion *completion;
6468 completion = gtk_entry_get_completion (entry);
6470 if (priv->truncate_multiline)
6471 length = truncate_multiline (text);
6473 /* only complete if the selection is at the end */
6474 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6475 MAX (priv->current_pos, priv->selection_bound));
6479 if (gtk_widget_get_mapped (completion->priv->popup_window))
6480 _gtk_entry_completion_popdown (completion);
6482 if (!popup_completion && completion->priv->changed_id > 0)
6483 g_signal_handler_block (entry, completion->priv->changed_id);
6486 begin_change (entry);
6487 g_object_freeze_notify (G_OBJECT (entry));
6488 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6489 gtk_editable_delete_text (editable, start, end);
6491 pos = priv->current_pos;
6492 gtk_editable_insert_text (editable, text, length, &pos);
6493 gtk_editable_set_position (editable, pos);
6494 g_object_thaw_notify (G_OBJECT (entry));
6498 !popup_completion && completion->priv->changed_id > 0)
6499 g_signal_handler_unblock (entry, completion->priv->changed_id);
6502 g_object_unref (entry);
6506 gtk_entry_paste (GtkEntry *entry,
6509 g_object_ref (entry);
6510 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6511 paste_received, entry);
6515 primary_get_cb (GtkClipboard *clipboard,
6516 GtkSelectionData *selection_data,
6520 GtkEntry *entry = GTK_ENTRY (data);
6523 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6525 gchar *str = gtk_entry_get_display_text (entry, start, end);
6526 gtk_selection_data_set_text (selection_data, str, -1);
6532 primary_clear_cb (GtkClipboard *clipboard,
6535 GtkEntry *entry = GTK_ENTRY (data);
6536 GtkEntryPrivate *priv = entry->priv;
6538 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6542 gtk_entry_update_primary_selection (GtkEntry *entry)
6544 GtkTargetList *list;
6545 GtkTargetEntry *targets;
6546 GtkClipboard *clipboard;
6550 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6553 list = gtk_target_list_new (NULL, 0);
6554 gtk_target_list_add_text_targets (list, 0);
6556 targets = gtk_target_table_new_from_list (list, &n_targets);
6558 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6560 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6562 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6563 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6564 primary_clear_cb (clipboard, entry);
6568 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6569 gtk_clipboard_clear (clipboard);
6572 gtk_target_table_free (targets, n_targets);
6573 gtk_target_list_unref (list);
6577 gtk_entry_clear (GtkEntry *entry,
6578 GtkEntryIconPosition icon_pos)
6580 GtkEntryPrivate *priv = entry->priv;
6581 EntryIconInfo *icon_info = priv->icons[icon_pos];
6582 GtkImageType storage_type;
6584 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6587 g_object_freeze_notify (G_OBJECT (entry));
6589 /* Explicitly check, as the pointer may become invalidated
6590 * during destruction.
6592 if (GDK_IS_WINDOW (icon_info->window))
6593 gdk_window_hide (icon_info->window);
6595 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6597 switch (storage_type)
6599 case GTK_IMAGE_PIXBUF:
6600 g_object_notify (G_OBJECT (entry),
6601 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6604 case GTK_IMAGE_STOCK:
6605 g_object_notify (G_OBJECT (entry),
6606 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6609 case GTK_IMAGE_ICON_NAME:
6610 g_object_notify (G_OBJECT (entry),
6611 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6614 case GTK_IMAGE_GICON:
6615 g_object_notify (G_OBJECT (entry),
6616 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6620 g_assert_not_reached ();
6624 _gtk_icon_helper_clear (icon_info->icon_helper);
6626 g_object_notify (G_OBJECT (entry),
6627 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6629 g_object_thaw_notify (G_OBJECT (entry));
6633 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6634 GtkEntryIconPosition icon_pos)
6636 GtkEntryPrivate *priv = entry->priv;
6637 EntryIconInfo *icon_info = priv->icons[icon_pos];
6638 GtkStyleContext *context;
6641 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6642 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6644 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6647 gtk_style_context_restore (context);
6658 * Creates a new entry.
6660 * Return value: a new #GtkEntry.
6663 gtk_entry_new (void)
6665 return g_object_new (GTK_TYPE_ENTRY, NULL);
6669 * gtk_entry_new_with_buffer:
6670 * @buffer: The buffer to use for the new #GtkEntry.
6672 * Creates a new entry with the specified text buffer.
6674 * Return value: a new #GtkEntry
6679 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6681 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6682 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6685 static GtkEntryBuffer*
6686 get_buffer (GtkEntry *entry)
6688 GtkEntryPrivate *priv = entry->priv;
6690 if (priv->buffer == NULL)
6692 GtkEntryBuffer *buffer;
6693 buffer = gtk_entry_buffer_new (NULL, 0);
6694 gtk_entry_set_buffer (entry, buffer);
6695 g_object_unref (buffer);
6698 return priv->buffer;
6702 * gtk_entry_get_buffer:
6703 * @entry: a #GtkEntry
6705 * Get the #GtkEntryBuffer object which holds the text for
6710 * Returns: (transfer none): A #GtkEntryBuffer object.
6713 gtk_entry_get_buffer (GtkEntry *entry)
6715 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6717 return get_buffer (entry);
6721 * gtk_entry_set_buffer:
6722 * @entry: a #GtkEntry
6723 * @buffer: a #GtkEntryBuffer
6725 * Set the #GtkEntryBuffer object which holds the text for
6731 gtk_entry_set_buffer (GtkEntry *entry,
6732 GtkEntryBuffer *buffer)
6734 GtkEntryPrivate *priv;
6737 g_return_if_fail (GTK_IS_ENTRY (entry));
6743 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6744 g_object_ref (buffer);
6749 buffer_disconnect_signals (entry);
6750 g_object_unref (priv->buffer);
6753 priv->buffer = buffer;
6756 buffer_connect_signals (entry);
6758 obj = G_OBJECT (entry);
6759 g_object_freeze_notify (obj);
6760 g_object_notify (obj, "buffer");
6761 g_object_notify (obj, "text");
6762 g_object_notify (obj, "text-length");
6763 g_object_notify (obj, "max-length");
6764 g_object_notify (obj, "visibility");
6765 g_object_notify (obj, "invisible-char");
6766 g_object_notify (obj, "invisible-char-set");
6767 g_object_thaw_notify (obj);
6769 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6770 gtk_entry_recompute (entry);
6774 * gtk_entry_get_text_area:
6775 * @entry: a #GtkEntry
6776 * @text_area: (out): Return location for the text area.
6778 * Gets the area where the entry's text is drawn. This function is
6779 * useful when drawing something to the entry in a draw callback.
6781 * If the entry is not realized, @text_area is filled with zeros.
6783 * See also gtk_entry_get_icon_area().
6788 gtk_entry_get_text_area (GtkEntry *entry,
6789 GdkRectangle *text_area)
6791 GtkEntryPrivate *priv;
6793 g_return_if_fail (GTK_IS_ENTRY (entry));
6794 g_return_if_fail (text_area != NULL);
6798 if (priv->text_area)
6800 GtkAllocation allocation;
6803 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6804 gdk_window_get_position (priv->text_area, &x, &y);
6806 text_area->x = x - allocation.x;
6807 text_area->y = y - allocation.y;
6808 text_area->width = gdk_window_get_width (priv->text_area);
6809 text_area->height = gdk_window_get_height (priv->text_area);
6815 text_area->width = 0;
6816 text_area->height = 0;
6821 * gtk_entry_set_text:
6822 * @entry: a #GtkEntry
6823 * @text: the new text
6825 * Sets the text in the widget to the given
6826 * value, replacing the current contents.
6828 * See gtk_entry_buffer_set_text().
6831 gtk_entry_set_text (GtkEntry *entry,
6835 GtkEntryCompletion *completion;
6837 g_return_if_fail (GTK_IS_ENTRY (entry));
6838 g_return_if_fail (text != NULL);
6840 /* Actually setting the text will affect the cursor and selection;
6841 * if the contents don't actually change, this will look odd to the user.
6843 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6846 completion = gtk_entry_get_completion (entry);
6847 if (completion && completion->priv->changed_id > 0)
6848 g_signal_handler_block (entry, completion->priv->changed_id);
6850 begin_change (entry);
6851 g_object_freeze_notify (G_OBJECT (entry));
6852 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6854 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6855 g_object_thaw_notify (G_OBJECT (entry));
6858 if (completion && completion->priv->changed_id > 0)
6859 g_signal_handler_unblock (entry, completion->priv->changed_id);
6863 * gtk_entry_set_visibility:
6864 * @entry: a #GtkEntry
6865 * @visible: %TRUE if the contents of the entry are displayed
6868 * Sets whether the contents of the entry are visible or not.
6869 * When visibility is set to %FALSE, characters are displayed
6870 * as the invisible char, and will also appear that way when
6871 * the text in the entry widget is copied elsewhere.
6873 * By default, GTK+ picks the best invisible character available
6874 * in the current font, but it can be changed with
6875 * gtk_entry_set_invisible_char().
6878 gtk_entry_set_visibility (GtkEntry *entry,
6881 GtkEntryPrivate *priv;
6883 g_return_if_fail (GTK_IS_ENTRY (entry));
6887 visible = visible != FALSE;
6889 if (priv->visible != visible)
6891 priv->visible = visible;
6893 g_object_notify (G_OBJECT (entry), "visibility");
6894 gtk_entry_recompute (entry);
6899 * gtk_entry_get_visibility:
6900 * @entry: a #GtkEntry
6902 * Retrieves whether the text in @entry is visible. See
6903 * gtk_entry_set_visibility().
6905 * Return value: %TRUE if the text is currently visible
6908 gtk_entry_get_visibility (GtkEntry *entry)
6910 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6912 return entry->priv->visible;
6916 * gtk_entry_set_invisible_char:
6917 * @entry: a #GtkEntry
6918 * @ch: a Unicode character
6920 * Sets the character to use in place of the actual text when
6921 * gtk_entry_set_visibility() has been called to set text visibility
6922 * to %FALSE. i.e. this is the character used in "password mode" to
6923 * show the user how many characters have been typed. By default, GTK+
6924 * picks the best invisible char available in the current font. If you
6925 * set the invisible char to 0, then the user will get no feedback
6926 * at all; there will be no text on the screen as they type.
6929 gtk_entry_set_invisible_char (GtkEntry *entry,
6932 GtkEntryPrivate *priv;
6934 g_return_if_fail (GTK_IS_ENTRY (entry));
6938 if (!priv->invisible_char_set)
6940 priv->invisible_char_set = TRUE;
6941 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6944 if (ch == priv->invisible_char)
6947 priv->invisible_char = ch;
6948 g_object_notify (G_OBJECT (entry), "invisible-char");
6949 gtk_entry_recompute (entry);
6953 * gtk_entry_get_invisible_char:
6954 * @entry: a #GtkEntry
6956 * Retrieves the character displayed in place of the real characters
6957 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6959 * Return value: the current invisible char, or 0, if the entry does not
6960 * show invisible text at all.
6963 gtk_entry_get_invisible_char (GtkEntry *entry)
6965 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6967 return entry->priv->invisible_char;
6971 * gtk_entry_unset_invisible_char:
6972 * @entry: a #GtkEntry
6974 * Unsets the invisible char previously set with
6975 * gtk_entry_set_invisible_char(). So that the
6976 * default invisible char is used again.
6981 gtk_entry_unset_invisible_char (GtkEntry *entry)
6983 GtkEntryPrivate *priv;
6986 g_return_if_fail (GTK_IS_ENTRY (entry));
6990 if (!priv->invisible_char_set)
6993 priv->invisible_char_set = FALSE;
6994 ch = find_invisible_char (GTK_WIDGET (entry));
6996 if (priv->invisible_char != ch)
6998 priv->invisible_char = ch;
6999 g_object_notify (G_OBJECT (entry), "invisible-char");
7002 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7003 gtk_entry_recompute (entry);
7007 * gtk_entry_set_overwrite_mode:
7008 * @entry: a #GtkEntry
7009 * @overwrite: new value
7011 * Sets whether the text is overwritten when typing in the #GtkEntry.
7016 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7019 GtkEntryPrivate *priv = entry->priv;
7021 g_return_if_fail (GTK_IS_ENTRY (entry));
7023 if (priv->overwrite_mode == overwrite)
7026 gtk_entry_toggle_overwrite (entry);
7028 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7032 * gtk_entry_get_overwrite_mode:
7033 * @entry: a #GtkEntry
7035 * Gets the value set by gtk_entry_set_overwrite_mode().
7037 * Return value: whether the text is overwritten when typing.
7042 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7044 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7046 return entry->priv->overwrite_mode;
7050 * gtk_entry_get_text:
7051 * @entry: a #GtkEntry
7053 * Retrieves the contents of the entry widget.
7054 * See also gtk_editable_get_chars().
7056 * This is equivalent to:
7058 * <informalexample><programlisting>
7059 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7060 * </programlisting></informalexample>
7062 * Return value: a pointer to the contents of the widget as a
7063 * string. This string points to internally allocated
7064 * storage in the widget and must not be freed, modified or
7068 gtk_entry_get_text (GtkEntry *entry)
7070 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7072 return gtk_entry_buffer_get_text (get_buffer (entry));
7076 * gtk_entry_set_max_length:
7077 * @entry: a #GtkEntry
7078 * @max: the maximum length of the entry, or 0 for no maximum.
7079 * (other than the maximum length of entries.) The value passed in will
7080 * be clamped to the range 0-65536.
7082 * Sets the maximum allowed length of the contents of the widget. If
7083 * the current contents are longer than the given length, then they
7084 * will be truncated to fit.
7086 * This is equivalent to:
7088 * <informalexample><programlisting>
7089 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7090 * </programlisting></informalexample>
7093 gtk_entry_set_max_length (GtkEntry *entry,
7096 g_return_if_fail (GTK_IS_ENTRY (entry));
7097 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7101 * gtk_entry_get_max_length:
7102 * @entry: a #GtkEntry
7104 * Retrieves the maximum allowed length of the text in
7105 * @entry. See gtk_entry_set_max_length().
7107 * This is equivalent to:
7109 * <informalexample><programlisting>
7110 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7111 * </programlisting></informalexample>
7113 * Return value: the maximum allowed number of characters
7114 * in #GtkEntry, or 0 if there is no maximum.
7117 gtk_entry_get_max_length (GtkEntry *entry)
7119 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7121 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7125 * gtk_entry_get_text_length:
7126 * @entry: a #GtkEntry
7128 * Retrieves the current length of the text in
7131 * This is equivalent to:
7133 * <informalexample><programlisting>
7134 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7135 * </programlisting></informalexample>
7137 * Return value: the current number of characters
7138 * in #GtkEntry, or 0 if there are none.
7143 gtk_entry_get_text_length (GtkEntry *entry)
7145 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7147 return gtk_entry_buffer_get_length (get_buffer (entry));
7151 * gtk_entry_set_activates_default:
7152 * @entry: a #GtkEntry
7153 * @setting: %TRUE to activate window's default widget on Enter keypress
7155 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7156 * widget for the window containing the entry. This usually means that
7157 * the dialog box containing the entry will be closed, since the default
7158 * widget is usually one of the dialog buttons.
7160 * (For experts: if @setting is %TRUE, the entry calls
7161 * gtk_window_activate_default() on the window containing the entry, in
7162 * the default handler for the #GtkWidget::activate signal.)
7165 gtk_entry_set_activates_default (GtkEntry *entry,
7168 GtkEntryPrivate *priv;
7170 g_return_if_fail (GTK_IS_ENTRY (entry));
7174 setting = setting != FALSE;
7176 if (setting != priv->activates_default)
7178 priv->activates_default = setting;
7179 g_object_notify (G_OBJECT (entry), "activates-default");
7184 * gtk_entry_get_activates_default:
7185 * @entry: a #GtkEntry
7187 * Retrieves the value set by gtk_entry_set_activates_default().
7189 * Return value: %TRUE if the entry will activate the default widget
7192 gtk_entry_get_activates_default (GtkEntry *entry)
7194 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7196 return entry->priv->activates_default;
7200 * gtk_entry_set_width_chars:
7201 * @entry: a #GtkEntry
7202 * @n_chars: width in chars
7204 * Changes the size request of the entry to be about the right size
7205 * for @n_chars characters. Note that it changes the size
7206 * <emphasis>request</emphasis>, the size can still be affected by
7207 * how you pack the widget into containers. If @n_chars is -1, the
7208 * size reverts to the default entry size.
7211 gtk_entry_set_width_chars (GtkEntry *entry,
7214 GtkEntryPrivate *priv;
7216 g_return_if_fail (GTK_IS_ENTRY (entry));
7220 if (priv->width_chars != n_chars)
7222 priv->width_chars = n_chars;
7223 g_object_notify (G_OBJECT (entry), "width-chars");
7224 gtk_widget_queue_resize (GTK_WIDGET (entry));
7229 * gtk_entry_get_width_chars:
7230 * @entry: a #GtkEntry
7232 * Gets the value set by gtk_entry_set_width_chars().
7234 * Return value: number of chars to request space for, or negative if unset
7237 gtk_entry_get_width_chars (GtkEntry *entry)
7239 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7241 return entry->priv->width_chars;
7245 * gtk_entry_set_has_frame:
7246 * @entry: a #GtkEntry
7247 * @setting: new value
7249 * Sets whether the entry has a beveled frame around it.
7252 gtk_entry_set_has_frame (GtkEntry *entry,
7255 GtkEntryPrivate *priv;
7257 g_return_if_fail (GTK_IS_ENTRY (entry));
7261 setting = (setting != FALSE);
7263 if (priv->has_frame == setting)
7266 gtk_widget_queue_resize (GTK_WIDGET (entry));
7267 priv->has_frame = setting;
7268 g_object_notify (G_OBJECT (entry), "has-frame");
7272 * gtk_entry_get_has_frame:
7273 * @entry: a #GtkEntry
7275 * Gets the value set by gtk_entry_set_has_frame().
7277 * Return value: whether the entry has a beveled frame
7280 gtk_entry_get_has_frame (GtkEntry *entry)
7282 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7284 return entry->priv->has_frame;
7288 * gtk_entry_set_inner_border:
7289 * @entry: a #GtkEntry
7290 * @border: (allow-none): a #GtkBorder, or %NULL
7292 * Sets %entry's inner-border property to %border, or clears it if %NULL
7293 * is passed. The inner-border is the area around the entry's text, but
7296 * If set, this property overrides the inner-border style property.
7297 * Overriding the style-provided border is useful when you want to do
7298 * in-place editing of some text in a canvas or list widget, where
7299 * pixel-exact positioning of the entry is important.
7304 gtk_entry_set_inner_border (GtkEntry *entry,
7305 const GtkBorder *border)
7307 g_return_if_fail (GTK_IS_ENTRY (entry));
7309 gtk_widget_queue_resize (GTK_WIDGET (entry));
7312 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7313 gtk_border_copy (border),
7314 (GDestroyNotify) gtk_border_free);
7316 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7318 g_object_notify (G_OBJECT (entry), "inner-border");
7322 * gtk_entry_get_inner_border:
7323 * @entry: a #GtkEntry
7325 * This function returns the entry's #GtkEntry:inner-border property. See
7326 * gtk_entry_set_inner_border() for more information.
7328 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7333 gtk_entry_get_inner_border (GtkEntry *entry)
7335 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7337 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7341 * gtk_entry_get_layout:
7342 * @entry: a #GtkEntry
7344 * Gets the #PangoLayout used to display the entry.
7345 * The layout is useful to e.g. convert text positions to
7346 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7347 * The returned layout is owned by the entry and must not be
7348 * modified or freed by the caller.
7350 * Keep in mind that the layout text may contain a preedit string, so
7351 * gtk_entry_layout_index_to_text_index() and
7352 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7353 * indices in the layout to byte indices in the entry contents.
7355 * Return value: (transfer none): the #PangoLayout for this entry
7358 gtk_entry_get_layout (GtkEntry *entry)
7360 PangoLayout *layout;
7362 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7364 layout = gtk_entry_ensure_layout (entry, TRUE);
7371 * gtk_entry_layout_index_to_text_index:
7372 * @entry: a #GtkEntry
7373 * @layout_index: byte index into the entry layout text
7375 * Converts from a position in the entry contents (returned
7376 * by gtk_entry_get_text()) to a position in the
7377 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7378 * with text retrieved via pango_layout_get_text()).
7380 * Return value: byte index into the entry contents
7383 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7386 GtkEntryPrivate *priv;
7387 PangoLayout *layout;
7391 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7395 layout = gtk_entry_ensure_layout (entry, TRUE);
7396 text = pango_layout_get_text (layout);
7397 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7399 if (layout_index >= cursor_index && priv->preedit_length)
7401 if (layout_index >= cursor_index + priv->preedit_length)
7402 layout_index -= priv->preedit_length;
7404 layout_index = cursor_index;
7407 return layout_index;
7411 * gtk_entry_text_index_to_layout_index:
7412 * @entry: a #GtkEntry
7413 * @text_index: byte index into the entry contents
7415 * Converts from a position in the entry's #PangoLayout (returned by
7416 * gtk_entry_get_layout()) to a position in the entry contents
7417 * (returned by gtk_entry_get_text()).
7419 * Return value: byte index into the entry layout text
7422 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7425 GtkEntryPrivate *priv;
7426 PangoLayout *layout;
7430 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7434 layout = gtk_entry_ensure_layout (entry, TRUE);
7435 text = pango_layout_get_text (layout);
7436 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7438 if (text_index > cursor_index)
7439 text_index += priv->preedit_length;
7445 * gtk_entry_get_layout_offsets:
7446 * @entry: a #GtkEntry
7447 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7448 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7451 * Obtains the position of the #PangoLayout used to render text
7452 * in the entry, in widget coordinates. Useful if you want to line
7453 * up the text in an entry with some other text, e.g. when using the
7454 * entry to implement editable cells in a sheet widget.
7456 * Also useful to convert mouse events into coordinates inside the
7457 * #PangoLayout, e.g. to take some action if some part of the entry text
7460 * Note that as the user scrolls around in the entry the offsets will
7461 * change; you'll need to connect to the "notify::scroll-offset"
7462 * signal to track this. Remember when using the #PangoLayout
7463 * functions you need to convert to and from pixels using
7464 * PANGO_PIXELS() or #PANGO_SCALE.
7466 * Keep in mind that the layout text may contain a preedit string, so
7467 * gtk_entry_layout_index_to_text_index() and
7468 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7469 * indices in the layout to byte indices in the entry contents.
7472 gtk_entry_get_layout_offsets (GtkEntry *entry,
7476 gint text_area_x, text_area_y;
7478 g_return_if_fail (GTK_IS_ENTRY (entry));
7480 /* this gets coords relative to text area */
7481 get_layout_position (entry, x, y);
7483 /* convert to widget coords */
7484 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7495 * gtk_entry_set_alignment:
7496 * @entry: a #GtkEntry
7497 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7498 * Reversed for RTL layouts
7500 * Sets the alignment for the contents of the entry. This controls
7501 * the horizontal positioning of the contents when the displayed
7502 * text is shorter than the width of the entry.
7507 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7509 GtkEntryPrivate *priv;
7511 g_return_if_fail (GTK_IS_ENTRY (entry));
7517 else if (xalign > 1.0)
7520 if (xalign != priv->xalign)
7522 priv->xalign = xalign;
7524 gtk_entry_recompute (entry);
7526 g_object_notify (G_OBJECT (entry), "xalign");
7531 * gtk_entry_get_alignment:
7532 * @entry: a #GtkEntry
7534 * Gets the value set by gtk_entry_set_alignment().
7536 * Return value: the alignment
7541 gtk_entry_get_alignment (GtkEntry *entry)
7543 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7545 return entry->priv->xalign;
7549 * gtk_entry_set_icon_from_pixbuf:
7550 * @entry: a #GtkEntry
7551 * @icon_pos: Icon position
7552 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7554 * Sets the icon shown in the specified position using a pixbuf.
7556 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7561 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7562 GtkEntryIconPosition icon_pos,
7565 GtkEntryPrivate *priv;
7566 EntryIconInfo *icon_info;
7568 g_return_if_fail (GTK_IS_ENTRY (entry));
7569 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7573 if ((icon_info = priv->icons[icon_pos]) == NULL)
7574 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7576 g_object_freeze_notify (G_OBJECT (entry));
7579 g_object_ref (pixbuf);
7581 gtk_entry_clear (entry, icon_pos);
7585 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7587 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7589 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7590 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7594 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7595 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7598 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7599 gdk_window_show_unraised (icon_info->window);
7601 g_object_unref (pixbuf);
7604 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7605 gtk_widget_queue_resize (GTK_WIDGET (entry));
7607 g_object_thaw_notify (G_OBJECT (entry));
7611 * gtk_entry_set_icon_from_stock:
7612 * @entry: A #GtkEntry
7613 * @icon_pos: Icon position
7614 * @stock_id: (allow-none): The name of the stock item, or %NULL
7616 * Sets the icon shown in the entry at the specified position from
7619 * If @stock_id is %NULL, no icon will be shown in the specified position.
7624 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7625 GtkEntryIconPosition icon_pos,
7626 const gchar *stock_id)
7628 GtkEntryPrivate *priv;
7629 EntryIconInfo *icon_info;
7632 g_return_if_fail (GTK_IS_ENTRY (entry));
7633 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7637 if ((icon_info = priv->icons[icon_pos]) == NULL)
7638 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7640 g_object_freeze_notify (G_OBJECT (entry));
7642 /* need to dup before clearing */
7643 new_id = g_strdup (stock_id);
7645 gtk_entry_clear (entry, icon_pos);
7649 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7651 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7653 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7654 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7658 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7659 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7662 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7663 gdk_window_show_unraised (icon_info->window);
7668 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7669 gtk_widget_queue_resize (GTK_WIDGET (entry));
7671 g_object_thaw_notify (G_OBJECT (entry));
7675 * gtk_entry_set_icon_from_icon_name:
7676 * @entry: A #GtkEntry
7677 * @icon_pos: The position at which to set the icon
7678 * @icon_name: (allow-none): An icon name, or %NULL
7680 * Sets the icon shown in the entry at the specified position
7681 * from the current icon theme.
7683 * If the icon name isn't known, a "broken image" icon will be displayed
7686 * If @icon_name is %NULL, no icon will be shown in the specified position.
7691 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7692 GtkEntryIconPosition icon_pos,
7693 const gchar *icon_name)
7695 GtkEntryPrivate *priv;
7696 EntryIconInfo *icon_info;
7699 g_return_if_fail (GTK_IS_ENTRY (entry));
7700 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7704 if ((icon_info = priv->icons[icon_pos]) == NULL)
7705 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7707 g_object_freeze_notify (G_OBJECT (entry));
7709 /* need to dup before clearing */
7710 new_name = g_strdup (icon_name);
7712 gtk_entry_clear (entry, icon_pos);
7714 if (new_name != NULL)
7716 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7718 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7720 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7721 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7725 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7726 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7729 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7730 gdk_window_show_unraised (icon_info->window);
7735 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7736 gtk_widget_queue_resize (GTK_WIDGET (entry));
7738 g_object_thaw_notify (G_OBJECT (entry));
7742 * gtk_entry_set_icon_from_gicon:
7743 * @entry: A #GtkEntry
7744 * @icon_pos: The position at which to set the icon
7745 * @icon: (allow-none): The icon to set, or %NULL
7747 * Sets the icon shown in the entry at the specified position
7748 * from the current icon theme.
7749 * If the icon isn't known, a "broken image" icon will be displayed
7752 * If @icon is %NULL, no icon will be shown in the specified position.
7757 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7758 GtkEntryIconPosition icon_pos,
7761 GtkEntryPrivate *priv;
7762 EntryIconInfo *icon_info;
7764 g_return_if_fail (GTK_IS_ENTRY (entry));
7765 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7769 if ((icon_info = priv->icons[icon_pos]) == NULL)
7770 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7772 g_object_freeze_notify (G_OBJECT (entry));
7774 /* need to ref before clearing */
7776 g_object_ref (icon);
7778 gtk_entry_clear (entry, icon_pos);
7782 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7784 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7786 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7787 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7791 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7792 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7795 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7796 gdk_window_show_unraised (icon_info->window);
7798 g_object_unref (icon);
7801 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7802 gtk_widget_queue_resize (GTK_WIDGET (entry));
7804 g_object_thaw_notify (G_OBJECT (entry));
7808 * gtk_entry_set_icon_activatable:
7809 * @entry: A #GtkEntry
7810 * @icon_pos: Icon position
7811 * @activatable: %TRUE if the icon should be activatable
7813 * Sets whether the icon is activatable.
7818 gtk_entry_set_icon_activatable (GtkEntry *entry,
7819 GtkEntryIconPosition icon_pos,
7820 gboolean activatable)
7822 GtkEntryPrivate *priv;
7823 EntryIconInfo *icon_info;
7825 g_return_if_fail (GTK_IS_ENTRY (entry));
7826 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7830 if ((icon_info = priv->icons[icon_pos]) == NULL)
7831 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7833 activatable = activatable != FALSE;
7835 if (icon_info->nonactivatable != !activatable)
7837 icon_info->nonactivatable = !activatable;
7839 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7840 update_cursors (GTK_WIDGET (entry));
7842 g_object_notify (G_OBJECT (entry),
7843 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7848 * gtk_entry_get_icon_activatable:
7849 * @entry: a #GtkEntry
7850 * @icon_pos: Icon position
7852 * Returns whether the icon is activatable.
7854 * Returns: %TRUE if the icon is activatable.
7859 gtk_entry_get_icon_activatable (GtkEntry *entry,
7860 GtkEntryIconPosition icon_pos)
7862 GtkEntryPrivate *priv;
7863 EntryIconInfo *icon_info;
7865 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7866 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7869 icon_info = priv->icons[icon_pos];
7871 return (!icon_info || !icon_info->nonactivatable);
7875 * gtk_entry_get_icon_pixbuf:
7876 * @entry: A #GtkEntry
7877 * @icon_pos: Icon position
7879 * Retrieves the image used for the icon.
7881 * Unlike the other methods of setting and getting icon data, this
7882 * method will work regardless of whether the icon was set using a
7883 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7885 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7886 * set for this position.
7891 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7892 GtkEntryIconPosition icon_pos)
7894 GtkEntryPrivate *priv;
7895 EntryIconInfo *icon_info;
7898 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7899 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7903 icon_info = priv->icons[icon_pos];
7908 /* HACK: unfortunately this is transfer none, so we need to return
7909 * the icon helper's cache ref directly.
7911 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7912 g_object_unref (pixbuf);
7918 * gtk_entry_get_icon_gicon:
7919 * @entry: A #GtkEntry
7920 * @icon_pos: Icon position
7922 * Retrieves the #GIcon used for the icon, or %NULL if there is
7923 * no icon or if the icon was set by some other method (e.g., by
7924 * stock, pixbuf, or icon name).
7926 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7927 * or if the icon is not a #GIcon
7932 gtk_entry_get_icon_gicon (GtkEntry *entry,
7933 GtkEntryIconPosition icon_pos)
7935 GtkEntryPrivate *priv;
7936 EntryIconInfo *icon_info;
7938 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7939 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7942 icon_info = priv->icons[icon_pos];
7947 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7951 * gtk_entry_get_icon_stock:
7952 * @entry: A #GtkEntry
7953 * @icon_pos: Icon position
7955 * Retrieves the stock id used for the icon, or %NULL if there is
7956 * no icon or if the icon was set by some other method (e.g., by
7957 * pixbuf, icon name or gicon).
7959 * Returns: A stock id, or %NULL if no icon is set or if the icon
7960 * wasn't set from a stock id
7965 gtk_entry_get_icon_stock (GtkEntry *entry,
7966 GtkEntryIconPosition icon_pos)
7968 GtkEntryPrivate *priv;
7969 EntryIconInfo *icon_info;
7971 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7972 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7975 icon_info = priv->icons[icon_pos];
7980 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
7984 * gtk_entry_get_icon_name:
7985 * @entry: A #GtkEntry
7986 * @icon_pos: Icon position
7988 * Retrieves the icon name used for the icon, or %NULL if there is
7989 * no icon or if the icon was set by some other method (e.g., by
7990 * pixbuf, stock or gicon).
7992 * Returns: An icon name, or %NULL if no icon is set or if the icon
7993 * wasn't set from an icon name
7998 gtk_entry_get_icon_name (GtkEntry *entry,
7999 GtkEntryIconPosition icon_pos)
8001 GtkEntryPrivate *priv;
8002 EntryIconInfo *icon_info;
8004 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8005 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8008 icon_info = priv->icons[icon_pos];
8013 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8017 * gtk_entry_set_icon_sensitive:
8018 * @entry: A #GtkEntry
8019 * @icon_pos: Icon position
8020 * @sensitive: Specifies whether the icon should appear
8021 * sensitive or insensitive
8023 * Sets the sensitivity for the specified icon.
8028 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8029 GtkEntryIconPosition icon_pos,
8032 GtkEntryPrivate *priv;
8033 EntryIconInfo *icon_info;
8035 g_return_if_fail (GTK_IS_ENTRY (entry));
8036 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8040 if ((icon_info = priv->icons[icon_pos]) == NULL)
8041 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8043 if (icon_info->insensitive != !sensitive)
8045 icon_info->insensitive = !sensitive;
8047 icon_info->pressed = FALSE;
8048 icon_info->prelight = FALSE;
8050 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8051 update_cursors (GTK_WIDGET (entry));
8053 gtk_widget_queue_draw (GTK_WIDGET (entry));
8055 g_object_notify (G_OBJECT (entry),
8056 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8061 * gtk_entry_get_icon_sensitive:
8062 * @entry: a #GtkEntry
8063 * @icon_pos: Icon position
8065 * Returns whether the icon appears sensitive or insensitive.
8067 * Returns: %TRUE if the icon is sensitive.
8072 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8073 GtkEntryIconPosition icon_pos)
8075 GtkEntryPrivate *priv;
8076 EntryIconInfo *icon_info;
8078 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8079 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8083 icon_info = priv->icons[icon_pos];
8085 return (!icon_info || !icon_info->insensitive);
8090 * gtk_entry_get_icon_storage_type:
8091 * @entry: a #GtkEntry
8092 * @icon_pos: Icon position
8094 * Gets the type of representation being used by the icon
8095 * to store image data. If the icon has no image data,
8096 * the return value will be %GTK_IMAGE_EMPTY.
8098 * Return value: image representation being used
8103 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8104 GtkEntryIconPosition icon_pos)
8106 GtkEntryPrivate *priv;
8107 EntryIconInfo *icon_info;
8109 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8110 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8114 icon_info = priv->icons[icon_pos];
8117 return GTK_IMAGE_EMPTY;
8119 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8123 * gtk_entry_get_icon_at_pos:
8124 * @entry: a #GtkEntry
8125 * @x: the x coordinate of the position to find
8126 * @y: the y coordinate of the position to find
8128 * Finds the icon at the given position and return its index. The
8129 * position's coordinates are relative to the @entry's top left corner.
8130 * If @x, @y doesn't lie inside an icon, -1 is returned.
8131 * This function is intended for use in a #GtkWidget::query-tooltip
8134 * Returns: the index of the icon at the given position, or -1
8139 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8143 GtkAllocation primary;
8144 GtkAllocation secondary;
8145 gint frame_x, frame_y;
8147 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8149 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8153 get_icon_allocations (entry, &primary, &secondary);
8155 if (primary.x <= x && x < primary.x + primary.width &&
8156 primary.y <= y && y < primary.y + primary.height)
8157 return GTK_ENTRY_ICON_PRIMARY;
8159 if (secondary.x <= x && x < secondary.x + secondary.width &&
8160 secondary.y <= y && y < secondary.y + secondary.height)
8161 return GTK_ENTRY_ICON_SECONDARY;
8167 * gtk_entry_set_icon_drag_source:
8168 * @entry: a #GtkIconEntry
8169 * @icon_pos: icon position
8170 * @target_list: the targets (data formats) in which the data can be provided
8171 * @actions: a bitmask of the allowed drag actions
8173 * Sets up the icon at the given position so that GTK+ will start a drag
8174 * operation when the user clicks and drags the icon.
8176 * To handle the drag operation, you need to connect to the usual
8177 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8178 * signal, and use gtk_entry_get_current_icon_drag_source() in
8179 * your signal handler to find out if the drag was started from
8182 * By default, GTK+ uses the icon as the drag icon. You can use the
8183 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8184 * have to use g_signal_connect_after() to ensure that your signal handler
8185 * gets executed after the default handler.
8190 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8191 GtkEntryIconPosition icon_pos,
8192 GtkTargetList *target_list,
8193 GdkDragAction actions)
8195 GtkEntryPrivate *priv;
8196 EntryIconInfo *icon_info;
8198 g_return_if_fail (GTK_IS_ENTRY (entry));
8199 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8203 if ((icon_info = priv->icons[icon_pos]) == NULL)
8204 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8206 if (icon_info->target_list)
8207 gtk_target_list_unref (icon_info->target_list);
8208 icon_info->target_list = target_list;
8209 if (icon_info->target_list)
8210 gtk_target_list_ref (icon_info->target_list);
8212 icon_info->actions = actions;
8216 * gtk_entry_get_current_icon_drag_source:
8217 * @entry: a #GtkIconEntry
8219 * Returns the index of the icon which is the source of the current
8220 * DND operation, or -1.
8222 * This function is meant to be used in a #GtkWidget::drag-data-get
8225 * Returns: index of the icon which is the source of the current
8226 * DND operation, or -1.
8231 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8233 GtkEntryPrivate *priv;
8234 EntryIconInfo *icon_info = NULL;
8237 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8241 for (i = 0; i < MAX_ICONS; i++)
8243 if ((icon_info = priv->icons[i]))
8245 if (icon_info->in_drag)
8254 * gtk_entry_get_icon_area:
8255 * @entry: A #GtkEntry
8256 * @icon_pos: Icon position
8257 * @icon_area: (out): Return location for the icon's area
8259 * Gets the area where entry's icon at @icon_pos is drawn.
8260 * This function is useful when drawing something to the
8261 * entry in a draw callback.
8263 * If the entry is not realized or has no icon at the given position,
8264 * @icon_area is filled with zeros.
8266 * See also gtk_entry_get_text_area()
8271 gtk_entry_get_icon_area (GtkEntry *entry,
8272 GtkEntryIconPosition icon_pos,
8273 GdkRectangle *icon_area)
8275 GtkEntryPrivate *priv;
8276 EntryIconInfo *icon_info;
8278 g_return_if_fail (GTK_IS_ENTRY (entry));
8279 g_return_if_fail (icon_area != NULL);
8283 icon_info = priv->icons[icon_pos];
8287 GtkAllocation primary;
8288 GtkAllocation secondary;
8290 get_icon_allocations (entry, &primary, &secondary);
8292 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8293 *icon_area = primary;
8295 *icon_area = secondary;
8301 icon_area->width = 0;
8302 icon_area->height = 0;
8307 ensure_has_tooltip (GtkEntry *entry)
8309 GtkEntryPrivate *priv;
8310 EntryIconInfo *icon_info;
8312 gboolean has_tooltip = FALSE;
8316 for (i = 0; i < MAX_ICONS; i++)
8318 if ((icon_info = priv->icons[i]) != NULL)
8320 if (icon_info->tooltip != NULL)
8328 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8332 * gtk_entry_get_icon_tooltip_text:
8333 * @entry: a #GtkEntry
8334 * @icon_pos: the icon position
8336 * Gets the contents of the tooltip on the icon at the specified
8337 * position in @entry.
8339 * Returns: the tooltip text, or %NULL. Free the returned string
8340 * with g_free() when done.
8345 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8346 GtkEntryIconPosition icon_pos)
8348 GtkEntryPrivate *priv;
8349 EntryIconInfo *icon_info;
8352 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8353 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8357 icon_info = priv->icons[icon_pos];
8362 if (icon_info->tooltip &&
8363 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8364 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8370 * gtk_entry_set_icon_tooltip_text:
8371 * @entry: a #GtkEntry
8372 * @icon_pos: the icon position
8373 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8375 * Sets @tooltip as the contents of the tooltip for the icon
8376 * at the specified position.
8378 * Use %NULL for @tooltip to remove an existing tooltip.
8380 * See also gtk_widget_set_tooltip_text() and
8381 * gtk_entry_set_icon_tooltip_markup().
8386 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8387 GtkEntryIconPosition icon_pos,
8388 const gchar *tooltip)
8390 GtkEntryPrivate *priv;
8391 EntryIconInfo *icon_info;
8393 g_return_if_fail (GTK_IS_ENTRY (entry));
8394 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8398 if ((icon_info = priv->icons[icon_pos]) == NULL)
8399 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8401 if (icon_info->tooltip)
8402 g_free (icon_info->tooltip);
8404 /* Treat an empty string as a NULL string,
8405 * because an empty string would be useless for a tooltip:
8407 if (tooltip && tooltip[0] == '\0')
8410 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8412 ensure_has_tooltip (entry);
8416 * gtk_entry_get_icon_tooltip_markup:
8417 * @entry: a #GtkEntry
8418 * @icon_pos: the icon position
8420 * Gets the contents of the tooltip on the icon at the specified
8421 * position in @entry.
8423 * Returns: the tooltip text, or %NULL. Free the returned string
8424 * with g_free() when done.
8429 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8430 GtkEntryIconPosition icon_pos)
8432 GtkEntryPrivate *priv;
8433 EntryIconInfo *icon_info;
8435 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8436 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8440 icon_info = priv->icons[icon_pos];
8445 return g_strdup (icon_info->tooltip);
8449 * gtk_entry_set_icon_tooltip_markup:
8450 * @entry: a #GtkEntry
8451 * @icon_pos: the icon position
8452 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8454 * Sets @tooltip as the contents of the tooltip for the icon at
8455 * the specified position. @tooltip is assumed to be marked up with
8456 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8458 * Use %NULL for @tooltip to remove an existing tooltip.
8460 * See also gtk_widget_set_tooltip_markup() and
8461 * gtk_enty_set_icon_tooltip_text().
8466 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8467 GtkEntryIconPosition icon_pos,
8468 const gchar *tooltip)
8470 GtkEntryPrivate *priv;
8471 EntryIconInfo *icon_info;
8473 g_return_if_fail (GTK_IS_ENTRY (entry));
8474 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8478 if ((icon_info = priv->icons[icon_pos]) == NULL)
8479 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8481 if (icon_info->tooltip)
8482 g_free (icon_info->tooltip);
8484 /* Treat an empty string as a NULL string,
8485 * because an empty string would be useless for a tooltip:
8487 if (tooltip && tooltip[0] == '\0')
8490 icon_info->tooltip = g_strdup (tooltip);
8492 ensure_has_tooltip (entry);
8496 gtk_entry_query_tooltip (GtkWidget *widget,
8499 gboolean keyboard_tip,
8500 GtkTooltip *tooltip)
8503 GtkEntryPrivate *priv;
8504 EntryIconInfo *icon_info;
8507 entry = GTK_ENTRY (widget);
8512 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8515 if ((icon_info = priv->icons[icon_pos]) != NULL)
8517 if (icon_info->tooltip)
8519 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8528 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8535 /* Quick hack of a popup menu
8538 activate_cb (GtkWidget *menuitem,
8541 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8542 g_signal_emit_by_name (entry, signal);
8547 gtk_entry_mnemonic_activate (GtkWidget *widget,
8548 gboolean group_cycling)
8550 gtk_widget_grab_focus (widget);
8555 append_action_signal (GtkEntry *entry,
8557 const gchar *stock_id,
8558 const gchar *signal,
8561 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8563 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8564 g_signal_connect (menuitem, "activate",
8565 G_CALLBACK (activate_cb), entry);
8567 gtk_widget_set_sensitive (menuitem, sensitive);
8569 gtk_widget_show (menuitem);
8570 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8574 popup_menu_detach (GtkWidget *attach_widget,
8577 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8578 GtkEntryPrivate *priv_attach = entry_attach->priv;
8580 priv_attach->popup_menu = NULL;
8584 popup_position_func (GtkMenu *menu,
8590 GtkEntry *entry = GTK_ENTRY (user_data);
8591 GtkEntryPrivate *priv = entry->priv;
8592 GtkWidget *widget = GTK_WIDGET (entry);
8594 GtkRequisition menu_req;
8595 GdkRectangle monitor;
8596 GtkBorder inner_border;
8597 gint monitor_num, strong_x, height;
8599 g_return_if_fail (gtk_widget_get_realized (widget));
8601 gdk_window_get_origin (priv->text_area, x, y);
8603 screen = gtk_widget_get_screen (widget);
8604 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8605 if (monitor_num < 0)
8607 gtk_menu_set_monitor (menu, monitor_num);
8609 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8610 gtk_widget_get_preferred_size (priv->popup_menu,
8612 height = gdk_window_get_height (priv->text_area);
8613 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8614 _gtk_entry_effective_inner_border (entry, &inner_border);
8616 *x += inner_border.left + strong_x - priv->scroll_offset;
8617 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8618 *x -= menu_req.width;
8620 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8622 else if ((*y - menu_req.height) >= monitor.y)
8623 *y -= menu_req.height;
8624 else if (monitor.y + monitor.height - (*y + height) > *y)
8627 *y -= menu_req.height;
8633 unichar_chosen_func (const char *text,
8636 GtkEntry *entry = GTK_ENTRY (data);
8637 GtkEntryPrivate *priv = entry->priv;
8640 gtk_entry_enter_text (entry, text);
8652 popup_targets_received (GtkClipboard *clipboard,
8653 GtkSelectionData *data,
8656 PopupInfo *info = user_data;
8657 GtkEntry *entry = info->entry;
8658 GtkEntryPrivate *info_entry_priv = entry->priv;
8660 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8663 gboolean clipboard_contains_text;
8664 GtkWidget *menuitem;
8666 gboolean show_input_method_menu;
8667 gboolean show_unicode_menu;
8669 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8670 if (info_entry_priv->popup_menu)
8671 gtk_widget_destroy (info_entry_priv->popup_menu);
8673 info_entry_priv->popup_menu = gtk_menu_new ();
8675 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8679 mode = gtk_entry_get_display_mode (entry);
8680 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8681 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8682 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8684 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8685 mode == DISPLAY_NORMAL &&
8686 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8688 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8689 info_entry_priv->editable && clipboard_contains_text);
8691 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8692 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8693 g_signal_connect_swapped (menuitem, "activate",
8694 G_CALLBACK (gtk_entry_delete_cb), entry);
8695 gtk_widget_show (menuitem);
8696 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8698 menuitem = gtk_separator_menu_item_new ();
8699 gtk_widget_show (menuitem);
8700 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8702 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8703 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8704 g_signal_connect_swapped (menuitem, "activate",
8705 G_CALLBACK (gtk_entry_select_all), entry);
8706 gtk_widget_show (menuitem);
8707 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8709 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8710 "gtk-show-input-method-menu", &show_input_method_menu,
8711 "gtk-show-unicode-menu", &show_unicode_menu,
8714 if (show_input_method_menu || show_unicode_menu)
8716 menuitem = gtk_separator_menu_item_new ();
8717 gtk_widget_show (menuitem);
8718 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8721 if (show_input_method_menu)
8723 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8724 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8725 gtk_widget_show (menuitem);
8726 submenu = gtk_menu_new ();
8727 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8729 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8731 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8732 GTK_MENU_SHELL (submenu));
8735 if (show_unicode_menu)
8737 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8738 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8739 gtk_widget_show (menuitem);
8741 submenu = gtk_menu_new ();
8742 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8743 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8745 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8746 unichar_chosen_func,
8750 g_signal_emit (entry,
8751 signals[POPULATE_POPUP],
8753 info_entry_priv->popup_menu);
8757 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8758 info->device, NULL, NULL, NULL, NULL, NULL,
8759 info->button, info->time);
8762 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8763 popup_position_func, entry,
8764 0, gtk_get_current_event_time ());
8765 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8769 g_object_unref (entry);
8770 g_slice_free (PopupInfo, info);
8774 gtk_entry_do_popup (GtkEntry *entry,
8775 GdkEventButton *event)
8777 PopupInfo *info = g_slice_new (PopupInfo);
8779 /* In order to know what entries we should make sensitive, we
8780 * ask for the current targets of the clipboard, and when
8781 * we get them, then we actually pop up the menu.
8783 info->entry = g_object_ref (entry);
8787 info->button = event->button;
8788 info->time = event->time;
8789 info->device = event->device;
8794 info->time = gtk_get_current_event_time ();
8795 info->device = NULL;
8798 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8799 gdk_atom_intern_static_string ("TARGETS"),
8800 popup_targets_received,
8805 gtk_entry_popup_menu (GtkWidget *widget)
8807 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8812 gtk_entry_drag_begin (GtkWidget *widget,
8813 GdkDragContext *context)
8815 GtkEntry *entry = GTK_ENTRY (widget);
8816 GtkEntryPrivate *priv = entry->priv;
8819 for (i = 0; i < MAX_ICONS; i++)
8821 EntryIconInfo *icon_info = priv->icons[i];
8823 if (icon_info != NULL)
8825 if (icon_info->in_drag)
8829 pix = _gtk_icon_helper_ensure_pixbuf
8830 (icon_info->icon_helper,
8831 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8832 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8834 g_object_unref (pix);
8841 gtk_entry_drag_end (GtkWidget *widget,
8842 GdkDragContext *context)
8844 GtkEntry *entry = GTK_ENTRY (widget);
8845 GtkEntryPrivate *priv = entry->priv;
8848 for (i = 0; i < MAX_ICONS; i++)
8850 EntryIconInfo *icon_info = priv->icons[i];
8852 if (icon_info != NULL)
8853 icon_info->in_drag = 0;
8858 gtk_entry_drag_leave (GtkWidget *widget,
8859 GdkDragContext *context,
8862 GtkEntry *entry = GTK_ENTRY (widget);
8863 GtkEntryPrivate *priv = entry->priv;
8865 priv->dnd_position = -1;
8866 gtk_widget_queue_draw (widget);
8870 gtk_entry_drag_drop (GtkWidget *widget,
8871 GdkDragContext *context,
8876 GtkEntry *entry = GTK_ENTRY (widget);
8877 GtkEntryPrivate *priv = entry->priv;
8878 GdkAtom target = GDK_NONE;
8881 target = gtk_drag_dest_find_target (widget, context, NULL);
8883 if (target != GDK_NONE)
8884 gtk_drag_get_data (widget, context, target, time);
8886 gtk_drag_finish (context, FALSE, FALSE, time);
8892 gtk_entry_drag_motion (GtkWidget *widget,
8893 GdkDragContext *context,
8898 GtkEntry *entry = GTK_ENTRY (widget);
8899 GtkEntryPrivate *priv = entry->priv;
8900 GtkStyleContext *style_context;
8901 GtkWidget *source_widget;
8902 GdkDragAction suggested_action;
8903 gint new_position, old_position;
8907 style_context = gtk_widget_get_style_context (widget);
8908 gtk_style_context_get_padding (style_context, 0, &padding);
8912 old_position = priv->dnd_position;
8913 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8915 if (priv->editable &&
8916 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8918 source_widget = gtk_drag_get_source_widget (context);
8919 suggested_action = gdk_drag_context_get_suggested_action (context);
8921 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8922 new_position < sel1 || new_position > sel2)
8924 if (source_widget == widget)
8926 /* Default to MOVE, unless the user has
8927 * pressed ctrl or alt to affect available actions
8929 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8930 suggested_action = GDK_ACTION_MOVE;
8933 priv->dnd_position = new_position;
8937 if (source_widget == widget)
8938 suggested_action = 0; /* Can't drop in selection where drag started */
8940 priv->dnd_position = -1;
8945 /* Entry not editable, or no text */
8946 suggested_action = 0;
8947 priv->dnd_position = -1;
8950 gdk_drag_status (context, suggested_action, time);
8952 if (priv->dnd_position != old_position)
8953 gtk_widget_queue_draw (widget);
8959 gtk_entry_drag_data_received (GtkWidget *widget,
8960 GdkDragContext *context,
8963 GtkSelectionData *selection_data,
8967 GtkEntry *entry = GTK_ENTRY (widget);
8968 GtkEntryPrivate *priv = entry->priv;
8969 GtkEditable *editable = GTK_EDITABLE (widget);
8970 GtkStyleContext *style_context;
8974 str = (gchar *) gtk_selection_data_get_text (selection_data);
8976 style_context = gtk_widget_get_style_context (widget);
8977 gtk_style_context_get_padding (style_context, 0, &padding);
8981 if (str && priv->editable)
8987 if (priv->truncate_multiline)
8988 length = truncate_multiline (str);
8990 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8992 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8993 new_position < sel1 || new_position > sel2)
8995 gtk_editable_insert_text (editable, str, length, &new_position);
8999 /* Replacing selection */
9000 begin_change (entry);
9001 g_object_freeze_notify (G_OBJECT (entry));
9002 gtk_editable_delete_text (editable, sel1, sel2);
9003 gtk_editable_insert_text (editable, str, length, &sel1);
9004 g_object_thaw_notify (G_OBJECT (entry));
9008 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9012 /* Drag and drop didn't happen! */
9013 gtk_drag_finish (context, FALSE, FALSE, time);
9020 gtk_entry_drag_data_get (GtkWidget *widget,
9021 GdkDragContext *context,
9022 GtkSelectionData *selection_data,
9026 GtkEntry *entry = GTK_ENTRY (widget);
9027 GtkEntryPrivate *priv = entry->priv;
9028 GtkEditable *editable = GTK_EDITABLE (widget);
9029 gint sel_start, sel_end;
9032 /* If there is an icon drag going on, exit early. */
9033 for (i = 0; i < MAX_ICONS; i++)
9035 EntryIconInfo *icon_info = priv->icons[i];
9037 if (icon_info != NULL)
9039 if (icon_info->in_drag)
9044 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9046 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9048 gtk_selection_data_set_text (selection_data, str, -1);
9056 gtk_entry_drag_data_delete (GtkWidget *widget,
9057 GdkDragContext *context)
9059 GtkEntry *entry = GTK_ENTRY (widget);
9060 GtkEntryPrivate *priv = entry->priv;
9061 GtkEditable *editable = GTK_EDITABLE (widget);
9062 gint sel_start, sel_end;
9065 /* If there is an icon drag going on, exit early. */
9066 for (i = 0; i < MAX_ICONS; i++)
9068 EntryIconInfo *icon_info = priv->icons[i];
9070 if (icon_info != NULL)
9072 if (icon_info->in_drag)
9077 if (priv->editable &&
9078 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9079 gtk_editable_delete_text (editable, sel_start, sel_end);
9082 /* We display the cursor when
9084 * - the selection is empty, AND
9085 * - the widget has focus
9088 #define CURSOR_ON_MULTIPLIER 2
9089 #define CURSOR_OFF_MULTIPLIER 1
9090 #define CURSOR_PEND_MULTIPLIER 3
9091 #define CURSOR_DIVIDER 3
9094 cursor_blinks (GtkEntry *entry)
9096 GtkEntryPrivate *priv = entry->priv;
9098 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9100 priv->selection_bound == priv->current_pos)
9102 GtkSettings *settings;
9105 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9106 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9115 get_cursor_time (GtkEntry *entry)
9117 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9120 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9126 get_cursor_blink_timeout (GtkEntry *entry)
9128 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9131 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9137 show_cursor (GtkEntry *entry)
9139 GtkEntryPrivate *priv = entry->priv;
9142 if (!priv->cursor_visible)
9144 priv->cursor_visible = TRUE;
9146 widget = GTK_WIDGET (entry);
9147 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9148 gtk_widget_queue_draw (widget);
9153 hide_cursor (GtkEntry *entry)
9155 GtkEntryPrivate *priv = entry->priv;
9158 if (priv->cursor_visible)
9160 priv->cursor_visible = FALSE;
9162 widget = GTK_WIDGET (entry);
9163 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9164 gtk_widget_queue_draw (widget);
9172 blink_cb (gpointer data)
9175 GtkEntryPrivate *priv;
9178 entry = GTK_ENTRY (data);
9181 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9183 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9184 "connect a handler to this signal, it must return\n"
9185 "FALSE so the entry gets the event as well");
9187 gtk_entry_check_cursor_blink (entry);
9192 g_assert (priv->selection_bound == priv->current_pos);
9194 blink_timeout = get_cursor_blink_timeout (entry);
9195 if (priv->blink_time > 1000 * blink_timeout &&
9196 blink_timeout < G_MAXINT/1000)
9198 /* we've blinked enough without the user doing anything, stop blinking */
9199 show_cursor (entry);
9200 priv->blink_timeout = 0;
9202 else if (priv->cursor_visible)
9204 hide_cursor (entry);
9205 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9211 show_cursor (entry);
9212 priv->blink_time += get_cursor_time (entry);
9213 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9218 /* Remove ourselves */
9223 gtk_entry_check_cursor_blink (GtkEntry *entry)
9225 GtkEntryPrivate *priv = entry->priv;
9227 if (cursor_blinks (entry))
9229 if (!priv->blink_timeout)
9231 show_cursor (entry);
9232 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9239 if (priv->blink_timeout)
9241 g_source_remove (priv->blink_timeout);
9242 priv->blink_timeout = 0;
9245 priv->cursor_visible = TRUE;
9250 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9252 GtkEntryPrivate *priv = entry->priv;
9254 if (cursor_blinks (entry))
9256 if (priv->blink_timeout != 0)
9257 g_source_remove (priv->blink_timeout);
9259 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9262 show_cursor (entry);
9267 gtk_entry_reset_blink_time (GtkEntry *entry)
9269 GtkEntryPrivate *priv = entry->priv;
9271 priv->blink_time = 0;
9277 gtk_entry_completion_timeout (gpointer data)
9279 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9280 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9282 completion->priv->completion_timeout = 0;
9284 if (completion->priv->filter_model &&
9285 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9286 >= completion->priv->minimum_key_length)
9290 GtkTreeSelection *s;
9291 gboolean popup_single;
9293 gtk_entry_completion_complete (completion);
9294 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9296 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9298 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9300 gtk_tree_selection_unselect_all (s);
9302 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9304 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9305 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9307 if (gtk_widget_get_visible (completion->priv->popup_window))
9308 _gtk_entry_completion_resize_popup (completion);
9310 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9313 _gtk_entry_completion_popdown (completion);
9315 else if (gtk_widget_get_visible (completion->priv->popup_window))
9316 _gtk_entry_completion_popdown (completion);
9321 static inline gboolean
9322 keyval_is_cursor_move (guint keyval)
9324 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9327 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9330 if (keyval == GDK_KEY_Page_Up)
9333 if (keyval == GDK_KEY_Page_Down)
9340 gtk_entry_completion_key_press (GtkWidget *widget,
9344 gint matches, actions = 0;
9345 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9347 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9350 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9352 if (completion->priv->actions)
9353 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9355 if (keyval_is_cursor_move (event->keyval))
9357 GtkTreePath *path = NULL;
9359 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9361 if (completion->priv->current_selected < 0)
9362 completion->priv->current_selected = matches + actions - 1;
9364 completion->priv->current_selected--;
9366 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9368 if (completion->priv->current_selected < matches + actions - 1)
9369 completion->priv->current_selected++;
9371 completion->priv->current_selected = -1;
9373 else if (event->keyval == GDK_KEY_Page_Up)
9375 if (completion->priv->current_selected < 0)
9376 completion->priv->current_selected = matches + actions - 1;
9377 else if (completion->priv->current_selected == 0)
9378 completion->priv->current_selected = -1;
9379 else if (completion->priv->current_selected < matches)
9381 completion->priv->current_selected -= PAGE_STEP;
9382 if (completion->priv->current_selected < 0)
9383 completion->priv->current_selected = 0;
9387 completion->priv->current_selected -= PAGE_STEP;
9388 if (completion->priv->current_selected < matches - 1)
9389 completion->priv->current_selected = matches - 1;
9392 else if (event->keyval == GDK_KEY_Page_Down)
9394 if (completion->priv->current_selected < 0)
9395 completion->priv->current_selected = 0;
9396 else if (completion->priv->current_selected < matches - 1)
9398 completion->priv->current_selected += PAGE_STEP;
9399 if (completion->priv->current_selected > matches - 1)
9400 completion->priv->current_selected = matches - 1;
9402 else if (completion->priv->current_selected == matches + actions - 1)
9404 completion->priv->current_selected = -1;
9408 completion->priv->current_selected += PAGE_STEP;
9409 if (completion->priv->current_selected > matches + actions - 1)
9410 completion->priv->current_selected = matches + actions - 1;
9414 if (completion->priv->current_selected < 0)
9416 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9417 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9419 if (completion->priv->inline_selection &&
9420 completion->priv->completion_prefix)
9422 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9423 completion->priv->completion_prefix);
9424 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9427 else if (completion->priv->current_selected < matches)
9429 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9431 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9432 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9435 if (completion->priv->inline_selection)
9439 GtkTreeIter child_iter;
9440 GtkTreeModel *model = NULL;
9441 GtkTreeSelection *sel;
9444 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9445 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9448 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9449 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9451 if (completion->priv->completion_prefix == NULL)
9452 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9454 g_signal_emit_by_name (completion, "cursor-on-match", model,
9455 &child_iter, &entry_set);
9458 else if (completion->priv->current_selected - matches >= 0)
9460 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9462 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9463 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9466 if (completion->priv->inline_selection &&
9467 completion->priv->completion_prefix)
9469 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9470 completion->priv->completion_prefix);
9471 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9475 gtk_tree_path_free (path);
9479 else if (event->keyval == GDK_KEY_Escape ||
9480 event->keyval == GDK_KEY_Left ||
9481 event->keyval == GDK_KEY_KP_Left ||
9482 event->keyval == GDK_KEY_Right ||
9483 event->keyval == GDK_KEY_KP_Right)
9485 gboolean retval = TRUE;
9487 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9488 _gtk_entry_completion_popdown (completion);
9490 if (completion->priv->current_selected < 0)
9493 goto keypress_completion_out;
9495 else if (completion->priv->inline_selection)
9497 /* Escape rejects the tentative completion */
9498 if (event->keyval == GDK_KEY_Escape)
9500 if (completion->priv->completion_prefix)
9501 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9502 completion->priv->completion_prefix);
9504 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9507 /* Move the cursor to the end for Right/Esc, to the
9508 beginning for Left */
9509 if (event->keyval == GDK_KEY_Right ||
9510 event->keyval == GDK_KEY_KP_Right ||
9511 event->keyval == GDK_KEY_Escape)
9512 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9514 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9517 keypress_completion_out:
9518 if (completion->priv->inline_selection)
9520 g_free (completion->priv->completion_prefix);
9521 completion->priv->completion_prefix = NULL;
9526 else if (event->keyval == GDK_KEY_Tab ||
9527 event->keyval == GDK_KEY_KP_Tab ||
9528 event->keyval == GDK_KEY_ISO_Left_Tab)
9530 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9531 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9533 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9534 _gtk_entry_completion_popdown (completion);
9536 g_free (completion->priv->completion_prefix);
9537 completion->priv->completion_prefix = NULL;
9539 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9543 else if (event->keyval == GDK_KEY_ISO_Enter ||
9544 event->keyval == GDK_KEY_KP_Enter ||
9545 event->keyval == GDK_KEY_Return)
9548 GtkTreeModel *model = NULL;
9549 GtkTreeModel *child_model;
9550 GtkTreeIter child_iter;
9551 GtkTreeSelection *sel;
9552 gboolean retval = TRUE;
9554 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9555 _gtk_entry_completion_popdown (completion);
9557 if (completion->priv->current_selected < matches)
9561 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9562 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9564 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9565 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9566 g_signal_handler_block (widget, completion->priv->changed_id);
9567 g_signal_emit_by_name (completion, "match-selected",
9568 child_model, &child_iter, &entry_set);
9569 g_signal_handler_unblock (widget, completion->priv->changed_id);
9575 gtk_tree_model_get (model, &iter,
9576 completion->priv->text_column, &str,
9579 gtk_entry_set_text (GTK_ENTRY (widget), str);
9581 /* move the cursor to the end */
9582 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9590 else if (completion->priv->current_selected - matches >= 0)
9592 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9593 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9597 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9598 g_signal_emit_by_name (completion, "action-activated",
9599 gtk_tree_path_get_indices (path)[0]);
9600 gtk_tree_path_free (path);
9606 g_free (completion->priv->completion_prefix);
9607 completion->priv->completion_prefix = NULL;
9616 gtk_entry_completion_changed (GtkWidget *widget,
9619 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9620 GtkEntry *entry = GTK_ENTRY (widget);
9621 GtkEntryPrivate *priv = entry->priv;
9624 /* (re)install completion timeout */
9625 if (completion->priv->completion_timeout)
9626 g_source_remove (completion->priv->completion_timeout);
9628 if (!gtk_entry_get_text (entry))
9631 /* no need to normalize for this test */
9632 if (completion->priv->minimum_key_length > 0 &&
9633 strcmp ("", gtk_entry_get_text (entry)) == 0)
9635 if (gtk_widget_get_visible (completion->priv->popup_window))
9636 _gtk_entry_completion_popdown (completion);
9640 device = gtk_get_current_event_device ();
9642 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9643 device = gdk_device_get_associated_device (device);
9646 priv->completion_device = device;
9648 completion->priv->completion_timeout =
9649 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9650 gtk_entry_completion_timeout,
9655 check_completion_callback (GtkEntryCompletion *completion)
9657 completion->priv->check_completion_idle = NULL;
9659 gtk_entry_completion_complete (completion);
9660 gtk_entry_completion_insert_prefix (completion);
9666 clear_completion_callback (GtkEntry *entry,
9669 if (pspec->name == I_("cursor-position") ||
9670 pspec->name == I_("selection-bound"))
9672 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9674 completion->priv->has_completion = FALSE;
9679 accept_completion_callback (GtkEntry *entry)
9681 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9683 if (completion->priv->has_completion)
9684 gtk_editable_set_position (GTK_EDITABLE (entry),
9685 gtk_entry_buffer_get_length (get_buffer (entry)));
9691 completion_insert_text_callback (GtkEntry *entry,
9695 GtkEntryCompletion *completion)
9697 /* idle to update the selection based on the file list */
9698 if (completion->priv->check_completion_idle == NULL)
9700 completion->priv->check_completion_idle = g_idle_source_new ();
9701 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9702 g_source_set_closure (completion->priv->check_completion_idle,
9703 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9704 G_OBJECT (completion)));
9705 g_source_attach (completion->priv->check_completion_idle, NULL);
9710 completion_changed (GtkEntryCompletion *completion,
9714 GtkEntry *entry = GTK_ENTRY (data);
9716 if (pspec->name == I_("popup-completion") ||
9717 pspec->name == I_("inline-completion"))
9719 disconnect_completion_signals (entry, completion);
9720 connect_completion_signals (entry, completion);
9725 disconnect_completion_signals (GtkEntry *entry,
9726 GtkEntryCompletion *completion)
9728 g_signal_handlers_disconnect_by_func (completion,
9729 G_CALLBACK (completion_changed), entry);
9730 if (completion->priv->changed_id > 0 &&
9731 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9733 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9734 completion->priv->changed_id = 0;
9736 g_signal_handlers_disconnect_by_func (entry,
9737 G_CALLBACK (gtk_entry_completion_key_press), completion);
9738 if (completion->priv->insert_text_id > 0 &&
9739 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9741 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9742 completion->priv->insert_text_id = 0;
9744 g_signal_handlers_disconnect_by_func (entry,
9745 G_CALLBACK (completion_insert_text_callback), completion);
9746 g_signal_handlers_disconnect_by_func (entry,
9747 G_CALLBACK (clear_completion_callback), completion);
9748 g_signal_handlers_disconnect_by_func (entry,
9749 G_CALLBACK (accept_completion_callback), completion);
9753 connect_completion_signals (GtkEntry *entry,
9754 GtkEntryCompletion *completion)
9756 if (completion->priv->popup_completion)
9758 completion->priv->changed_id =
9759 g_signal_connect (entry, "changed",
9760 G_CALLBACK (gtk_entry_completion_changed), completion);
9761 g_signal_connect (entry, "key-press-event",
9762 G_CALLBACK (gtk_entry_completion_key_press), completion);
9765 if (completion->priv->inline_completion)
9767 completion->priv->insert_text_id =
9768 g_signal_connect (entry, "insert-text",
9769 G_CALLBACK (completion_insert_text_callback), completion);
9770 g_signal_connect (entry, "notify",
9771 G_CALLBACK (clear_completion_callback), completion);
9772 g_signal_connect (entry, "activate",
9773 G_CALLBACK (accept_completion_callback), completion);
9774 g_signal_connect (entry, "focus-out-event",
9775 G_CALLBACK (accept_completion_callback), completion);
9778 g_signal_connect (completion, "notify",
9779 G_CALLBACK (completion_changed), entry);
9783 * gtk_entry_set_completion:
9784 * @entry: A #GtkEntry
9785 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9787 * Sets @completion to be the auxiliary completion object to use with @entry.
9788 * All further configuration of the completion mechanism is done on
9789 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9790 * @completion is set to %NULL.
9795 gtk_entry_set_completion (GtkEntry *entry,
9796 GtkEntryCompletion *completion)
9798 GtkEntryCompletion *old;
9800 g_return_if_fail (GTK_IS_ENTRY (entry));
9801 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9803 old = gtk_entry_get_completion (entry);
9805 if (old == completion)
9810 if (old->priv->completion_timeout)
9812 g_source_remove (old->priv->completion_timeout);
9813 old->priv->completion_timeout = 0;
9816 if (old->priv->check_completion_idle)
9818 g_source_destroy (old->priv->check_completion_idle);
9819 old->priv->check_completion_idle = NULL;
9822 if (gtk_widget_get_mapped (old->priv->popup_window))
9823 _gtk_entry_completion_popdown (old);
9825 disconnect_completion_signals (entry, old);
9826 old->priv->entry = NULL;
9828 g_object_unref (old);
9833 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9837 /* hook into the entry */
9838 g_object_ref (completion);
9840 connect_completion_signals (entry, completion);
9841 completion->priv->entry = GTK_WIDGET (entry);
9842 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9844 g_object_notify (G_OBJECT (entry), "completion");
9848 * gtk_entry_get_completion:
9849 * @entry: A #GtkEntry
9851 * Returns the auxiliary completion object currently in use by @entry.
9853 * Return value: (transfer none): The auxiliary completion object currently
9858 GtkEntryCompletion *
9859 gtk_entry_get_completion (GtkEntry *entry)
9861 GtkEntryCompletion *completion;
9863 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9865 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9866 GTK_ENTRY_COMPLETION_KEY));
9872 * gtk_entry_set_cursor_hadjustment:
9873 * @entry: a #GtkEntry
9874 * @adjustment: an adjustment which should be adjusted when the cursor
9875 * is moved, or %NULL
9877 * Hooks up an adjustment to the cursor position in an entry, so that when
9878 * the cursor is moved, the adjustment is scrolled to show that position.
9879 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9882 * The adjustment has to be in pixel units and in the same coordinate system
9888 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9889 GtkAdjustment *adjustment)
9891 g_return_if_fail (GTK_IS_ENTRY (entry));
9893 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9896 g_object_ref (adjustment);
9898 g_object_set_qdata_full (G_OBJECT (entry),
9899 quark_cursor_hadjustment,
9905 * gtk_entry_get_cursor_hadjustment:
9906 * @entry: a #GtkEntry
9908 * Retrieves the horizontal cursor adjustment for the entry.
9909 * See gtk_entry_set_cursor_hadjustment().
9911 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9912 * if none has been set.
9917 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9919 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9921 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9925 * gtk_entry_set_progress_fraction:
9926 * @entry: a #GtkEntry
9927 * @fraction: fraction of the task that's been completed
9929 * Causes the entry's progress indicator to "fill in" the given
9930 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9936 gtk_entry_set_progress_fraction (GtkEntry *entry,
9940 GtkEntryPrivate *private;
9941 gdouble old_fraction;
9942 gint x, y, width, height;
9943 gint old_x, old_y, old_width, old_height;
9945 g_return_if_fail (GTK_IS_ENTRY (entry));
9947 widget = GTK_WIDGET (entry);
9948 private = entry->priv;
9950 if (private->progress_pulse_mode)
9953 old_fraction = private->progress_fraction;
9955 if (gtk_widget_is_drawable (widget))
9956 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9958 fraction = CLAMP (fraction, 0.0, 1.0);
9960 private->progress_fraction = fraction;
9961 private->progress_pulse_mode = FALSE;
9962 private->progress_pulse_current = 0.0;
9964 if (gtk_widget_is_drawable (widget))
9966 get_progress_area (widget, &x, &y, &width, &height);
9968 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9969 gtk_widget_queue_draw (widget);
9972 if (fraction != old_fraction)
9973 g_object_notify (G_OBJECT (entry), "progress-fraction");
9977 * gtk_entry_get_progress_fraction:
9978 * @entry: a #GtkEntry
9980 * Returns the current fraction of the task that's been completed.
9981 * See gtk_entry_set_progress_fraction().
9983 * Return value: a fraction from 0.0 to 1.0
9988 gtk_entry_get_progress_fraction (GtkEntry *entry)
9990 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9992 return entry->priv->progress_fraction;
9996 * gtk_entry_set_progress_pulse_step:
9997 * @entry: a #GtkEntry
9998 * @fraction: fraction between 0.0 and 1.0
10000 * Sets the fraction of total entry width to move the progress
10001 * bouncing block for each call to gtk_entry_progress_pulse().
10006 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10009 GtkEntryPrivate *private;
10011 g_return_if_fail (GTK_IS_ENTRY (entry));
10013 private = entry->priv;
10015 fraction = CLAMP (fraction, 0.0, 1.0);
10017 if (fraction != private->progress_pulse_fraction)
10019 private->progress_pulse_fraction = fraction;
10021 gtk_widget_queue_draw (GTK_WIDGET (entry));
10023 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10028 * gtk_entry_get_progress_pulse_step:
10029 * @entry: a #GtkEntry
10031 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10033 * Return value: a fraction from 0.0 to 1.0
10038 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10040 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10042 return entry->priv->progress_pulse_fraction;
10046 * gtk_entry_progress_pulse:
10047 * @entry: a #GtkEntry
10049 * Indicates that some progress is made, but you don't know how much.
10050 * Causes the entry's progress indicator to enter "activity mode,"
10051 * where a block bounces back and forth. Each call to
10052 * gtk_entry_progress_pulse() causes the block to move by a little bit
10053 * (the amount of movement per pulse is determined by
10054 * gtk_entry_set_progress_pulse_step()).
10059 gtk_entry_progress_pulse (GtkEntry *entry)
10061 GtkEntryPrivate *private;
10063 g_return_if_fail (GTK_IS_ENTRY (entry));
10065 private = entry->priv;
10067 if (private->progress_pulse_mode)
10069 if (private->progress_pulse_way_back)
10071 private->progress_pulse_current -= private->progress_pulse_fraction;
10073 if (private->progress_pulse_current < 0.0)
10075 private->progress_pulse_current = 0.0;
10076 private->progress_pulse_way_back = FALSE;
10081 private->progress_pulse_current += private->progress_pulse_fraction;
10083 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10085 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10086 private->progress_pulse_way_back = TRUE;
10092 private->progress_fraction = 0.0;
10093 private->progress_pulse_mode = TRUE;
10094 private->progress_pulse_way_back = FALSE;
10095 private->progress_pulse_current = 0.0;
10098 gtk_widget_queue_draw (GTK_WIDGET (entry));
10102 * gtk_entry_set_placeholder_text:
10103 * @entry: a #GtkEntry
10104 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10106 * Sets text to be displayed in @entry when it is empty and unfocused.
10107 * This can be used to give a visual hint of the expected contents of
10110 * Note that since the placeholder text gets removed when the entry
10111 * received focus, using this feature is a bit problematic if the entry
10112 * is given the initial focus in a window. Sometimes this can be
10113 * worked around by delaying the initial focus setting until the
10114 * first key event arrives.
10119 gtk_entry_set_placeholder_text (GtkEntry *entry,
10122 GtkEntryPrivate *priv;
10124 g_return_if_fail (GTK_IS_ENTRY (entry));
10126 priv = entry->priv;
10128 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10131 g_free (priv->placeholder_text);
10132 priv->placeholder_text = g_strdup (text);
10134 gtk_entry_recompute (entry);
10136 g_object_notify (G_OBJECT (entry), "placeholder-text");
10140 * gtk_entry_get_placeholder_text:
10141 * @entry: a #GtkEntry
10143 * Retrieves the text that will be displayed when @entry is empty and unfocused
10145 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10146 * storage in the widget and must not be freed, modified or stored.
10151 gtk_entry_get_placeholder_text (GtkEntry *entry)
10153 GtkEntryPrivate *priv;
10155 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10157 priv = entry->priv;
10159 return priv->placeholder_text;
10162 /* Caps Lock warning for password entries */
10165 show_capslock_feedback (GtkEntry *entry,
10168 GtkEntryPrivate *priv = entry->priv;
10170 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10172 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10173 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10174 priv->caps_lock_warning_shown = TRUE;
10177 if (priv->caps_lock_warning_shown)
10178 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10180 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10184 remove_capslock_feedback (GtkEntry *entry)
10186 GtkEntryPrivate *priv = entry->priv;
10188 if (priv->caps_lock_warning_shown)
10190 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10191 priv->caps_lock_warning_shown = FALSE;
10196 keymap_state_changed (GdkKeymap *keymap,
10199 GtkEntryPrivate *priv = entry->priv;
10202 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10204 if (gdk_keymap_get_num_lock_state (keymap)
10205 && gdk_keymap_get_caps_lock_state (keymap))
10206 text = _("Caps Lock and Num Lock are on");
10207 else if (gdk_keymap_get_num_lock_state (keymap))
10208 text = _("Num Lock is on");
10209 else if (gdk_keymap_get_caps_lock_state (keymap))
10210 text = _("Caps Lock is on");
10214 show_capslock_feedback (entry, text);
10216 remove_capslock_feedback (entry);
10220 * _gtk_entry_set_is_cell_renderer:
10221 * @entry: a #GtkEntry
10222 * @is_cell_renderer: new value
10224 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10225 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10227 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10231 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10232 gboolean is_cell_renderer)
10234 entry->priv->is_cell_renderer = is_cell_renderer;