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 "gtkalignment.h"
37 #include "gtkbindings.h"
38 #include "gtkcelleditable.h"
39 #include "gtkclipboard.h"
42 #include "gtkentrybuffer.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"
73 * @Short_description: A single line text entry field
75 * @See_also: #GtkTextView, #GtkEntryCompletion
77 * The #GtkEntry widget is a single line text entry
78 * widget. A fairly large set of key bindings are supported
79 * by default. If the entered text is longer than the allocation
80 * of the widget, the widget will scroll so that the cursor
81 * position is visible.
83 * When using an entry for passwords and other sensitive information,
84 * it can be put into "password mode" using gtk_entry_set_visibility().
85 * In this mode, entered text is displayed using a 'invisible' character.
86 * By default, GTK+ picks the best invisible character that is available
87 * in the current font, but it can be changed with
88 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
89 * when Caps Lock or input methods might interfere with entering text in
90 * a password entry. The warning can be turned off with the
91 * #GtkEntry:caps-lock-warning property.
93 * Since 2.16, GtkEntry has the ability to display progress or activity
94 * information behind the text. To make an entry display such information,
95 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
97 * Additionally, GtkEntry can show icons at either side of the entry. These
98 * icons can be activatable by clicking, can be set up as drag source and
99 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
100 * one of the various other functions that set an icon from a stock id, an
101 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
102 * connect to the #GtkEntry::icon-press signal. To allow DND operations
103 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
104 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
107 * Note that functionality or information that is only available by clicking
108 * on an icon in an entry may not be accessible at all to users which are not
109 * able to use a mouse or other pointing device. It is therefore recommended
110 * that any such functionality should also be available by other means, e.g.
111 * via the context menu of the entry.
115 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
117 #define MIN_ENTRY_WIDTH 150
118 #define DRAW_TIMEOUT 20
119 #define COMPLETION_TIMEOUT 300
120 #define PASSWORD_HINT_MAX 8
124 #define IS_VALID_ICON_POSITION(pos) \
125 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
126 (pos) == GTK_ENTRY_ICON_SECONDARY)
128 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
129 static GQuark quark_inner_border = 0;
130 static GQuark quark_password_hint = 0;
131 static GQuark quark_cursor_hadjustment = 0;
132 static GQuark quark_capslock_feedback = 0;
134 typedef struct _EntryIconInfo EntryIconInfo;
135 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
136 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
138 struct _GtkEntryPrivate
140 EntryIconInfo *icons[MAX_ICONS];
142 GtkEntryBuffer *buffer;
143 GtkIMContext *im_context;
144 GtkShadowType shadow_type;
145 GtkWidget *popup_menu;
147 GdkDevice *completion_device;
148 GdkWindow *text_area;
150 PangoLayout *cached_layout;
154 gdouble progress_fraction;
155 gdouble progress_pulse_fraction;
156 gdouble progress_pulse_current;
160 gint ascent; /* font ascent in pango units */
162 gint descent; /* font descent in pango units */
163 gint dnd_position; /* In chars, -1 == no DND cursor */
169 gint selection_bound;
175 gunichar invisible_char;
178 guint blink_time; /* time in msec the cursor has blinked since last user event */
180 guint recompute_idle;
182 guint16 x_text_size; /* allocated size, in bytes */
183 guint16 x_n_bytes; /* length in use, in bytes */
185 guint16 preedit_length; /* length of preedit string, in bytes */
186 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
190 guint overwrite_mode : 1;
193 guint activates_default : 1;
194 guint cache_includes_preedit : 1;
195 guint caps_lock_warning : 1;
196 guint caps_lock_warning_shown : 1;
197 guint change_count : 8;
198 guint cursor_visible : 1;
199 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
201 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
202 guint is_cell_renderer : 1;
203 guint invisible_char_set : 1;
204 guint interior_focus : 1;
205 guint mouse_cursor_obscured : 1;
206 guint need_im_reset : 1;
207 guint progress_pulse_mode : 1;
208 guint progress_pulse_way_back : 1;
209 guint real_changed : 1;
210 guint resolved_dir : 4; /* PangoDirection */
211 guint select_words : 1;
212 guint select_lines : 1;
213 guint truncate_multiline : 1;
216 struct _EntryIconInfo
220 guint insensitive : 1;
221 guint nonactivatable : 1;
226 GtkImageType storage_type;
232 GtkTargetList *target_list;
233 GdkDragAction actions;
236 struct _GtkEntryPasswordHint
238 gint position; /* Position (in text) of the last password hint */
239 guint source_id; /* Timeout source id */
242 struct _GtkEntryCapslockFeedback
269 PROP_CURSOR_POSITION,
270 PROP_SELECTION_BOUND,
277 PROP_ACTIVATES_DEFAULT,
282 PROP_TRUNCATE_MULTILINE,
286 PROP_INVISIBLE_CHAR_SET,
287 PROP_CAPS_LOCK_WARNING,
288 PROP_PROGRESS_FRACTION,
289 PROP_PROGRESS_PULSE_STEP,
291 PROP_PIXBUF_SECONDARY,
293 PROP_STOCK_SECONDARY,
294 PROP_ICON_NAME_PRIMARY,
295 PROP_ICON_NAME_SECONDARY,
297 PROP_GICON_SECONDARY,
298 PROP_STORAGE_TYPE_PRIMARY,
299 PROP_STORAGE_TYPE_SECONDARY,
300 PROP_ACTIVATABLE_PRIMARY,
301 PROP_ACTIVATABLE_SECONDARY,
302 PROP_SENSITIVE_PRIMARY,
303 PROP_SENSITIVE_SECONDARY,
304 PROP_TOOLTIP_TEXT_PRIMARY,
305 PROP_TOOLTIP_TEXT_SECONDARY,
306 PROP_TOOLTIP_MARKUP_PRIMARY,
307 PROP_TOOLTIP_MARKUP_SECONDARY,
309 PROP_EDITING_CANCELED
312 static guint signals[LAST_SIGNAL] = { 0 };
321 DISPLAY_NORMAL, /* The entry text is being shown */
322 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
323 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
328 static void gtk_entry_editable_init (GtkEditableInterface *iface);
329 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
330 static void gtk_entry_set_property (GObject *object,
334 static void gtk_entry_get_property (GObject *object,
338 static void gtk_entry_finalize (GObject *object);
339 static void gtk_entry_dispose (GObject *object);
343 static void gtk_entry_destroy (GtkWidget *widget);
344 static void gtk_entry_realize (GtkWidget *widget);
345 static void gtk_entry_unrealize (GtkWidget *widget);
346 static void gtk_entry_map (GtkWidget *widget);
347 static void gtk_entry_unmap (GtkWidget *widget);
348 static void gtk_entry_get_preferred_width (GtkWidget *widget,
351 static void gtk_entry_get_preferred_height (GtkWidget *widget,
354 static void gtk_entry_size_allocate (GtkWidget *widget,
355 GtkAllocation *allocation);
356 static void gtk_entry_draw_frame (GtkWidget *widget,
357 GtkStyleContext *context,
359 static void gtk_entry_draw_progress (GtkWidget *widget,
360 GtkStyleContext *context,
362 static gint gtk_entry_draw (GtkWidget *widget,
364 static gint gtk_entry_button_press (GtkWidget *widget,
365 GdkEventButton *event);
366 static gint gtk_entry_button_release (GtkWidget *widget,
367 GdkEventButton *event);
368 static gint gtk_entry_enter_notify (GtkWidget *widget,
369 GdkEventCrossing *event);
370 static gint gtk_entry_leave_notify (GtkWidget *widget,
371 GdkEventCrossing *event);
372 static gint gtk_entry_motion_notify (GtkWidget *widget,
373 GdkEventMotion *event);
374 static gint gtk_entry_key_press (GtkWidget *widget,
376 static gint gtk_entry_key_release (GtkWidget *widget,
378 static gint gtk_entry_focus_in (GtkWidget *widget,
379 GdkEventFocus *event);
380 static gint gtk_entry_focus_out (GtkWidget *widget,
381 GdkEventFocus *event);
382 static void gtk_entry_grab_focus (GtkWidget *widget);
383 static void gtk_entry_style_updated (GtkWidget *widget);
384 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
387 gboolean keyboard_tip,
388 GtkTooltip *tooltip);
389 static void gtk_entry_direction_changed (GtkWidget *widget,
390 GtkTextDirection previous_dir);
391 static void gtk_entry_state_flags_changed (GtkWidget *widget,
392 GtkStateFlags previous_state);
393 static void gtk_entry_screen_changed (GtkWidget *widget,
394 GdkScreen *old_screen);
396 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
397 GdkDragContext *context,
401 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
402 GdkDragContext *context,
406 static void gtk_entry_drag_leave (GtkWidget *widget,
407 GdkDragContext *context,
409 static void gtk_entry_drag_data_received (GtkWidget *widget,
410 GdkDragContext *context,
413 GtkSelectionData *selection_data,
416 static void gtk_entry_drag_data_get (GtkWidget *widget,
417 GdkDragContext *context,
418 GtkSelectionData *selection_data,
421 static void gtk_entry_drag_data_delete (GtkWidget *widget,
422 GdkDragContext *context);
423 static void gtk_entry_drag_begin (GtkWidget *widget,
424 GdkDragContext *context);
425 static void gtk_entry_drag_end (GtkWidget *widget,
426 GdkDragContext *context);
429 /* GtkEditable method implementations
431 static void gtk_entry_insert_text (GtkEditable *editable,
432 const gchar *new_text,
433 gint new_text_length,
435 static void gtk_entry_delete_text (GtkEditable *editable,
438 static gchar * gtk_entry_get_chars (GtkEditable *editable,
441 static void gtk_entry_real_set_position (GtkEditable *editable,
443 static gint gtk_entry_get_position (GtkEditable *editable);
444 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
447 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
451 /* GtkCellEditable method implementations
453 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
456 /* Default signal handlers
458 static void gtk_entry_real_insert_text (GtkEditable *editable,
459 const gchar *new_text,
460 gint new_text_length,
462 static void gtk_entry_real_delete_text (GtkEditable *editable,
465 static void gtk_entry_move_cursor (GtkEntry *entry,
466 GtkMovementStep step,
468 gboolean extend_selection);
469 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
471 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
474 static void gtk_entry_backspace (GtkEntry *entry);
475 static void gtk_entry_cut_clipboard (GtkEntry *entry);
476 static void gtk_entry_copy_clipboard (GtkEntry *entry);
477 static void gtk_entry_paste_clipboard (GtkEntry *entry);
478 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
479 static void gtk_entry_select_all (GtkEntry *entry);
480 static void gtk_entry_real_activate (GtkEntry *entry);
481 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
483 static void keymap_direction_changed (GdkKeymap *keymap,
485 static void keymap_state_changed (GdkKeymap *keymap,
487 static void remove_capslock_feedback (GtkEntry *entry);
489 /* IM Context Callbacks
491 static void gtk_entry_commit_cb (GtkIMContext *context,
494 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
496 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
498 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
505 static void gtk_entry_enter_text (GtkEntry *entry,
507 static void gtk_entry_set_positions (GtkEntry *entry,
509 gint selection_bound);
510 static void gtk_entry_draw_text (GtkEntry *entry,
512 static void gtk_entry_draw_cursor (GtkEntry *entry,
515 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
516 gboolean include_preedit);
517 static void gtk_entry_reset_layout (GtkEntry *entry);
518 static void gtk_entry_recompute (GtkEntry *entry);
519 static gint gtk_entry_find_position (GtkEntry *entry,
521 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
525 static void gtk_entry_adjust_scroll (GtkEntry *entry);
526 static gint gtk_entry_move_visually (GtkEntry *editable,
529 static gint gtk_entry_move_logically (GtkEntry *entry,
532 static gint gtk_entry_move_forward_word (GtkEntry *entry,
534 gboolean allow_whitespace);
535 static gint gtk_entry_move_backward_word (GtkEntry *entry,
537 gboolean allow_whitespace);
538 static void gtk_entry_delete_whitespace (GtkEntry *entry);
539 static void gtk_entry_select_word (GtkEntry *entry);
540 static void gtk_entry_select_line (GtkEntry *entry);
541 static void gtk_entry_paste (GtkEntry *entry,
543 static void gtk_entry_update_primary_selection (GtkEntry *entry);
544 static void gtk_entry_do_popup (GtkEntry *entry,
545 GdkEventButton *event);
546 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
547 gboolean group_cycling);
548 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
549 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
550 static void gtk_entry_reset_blink_time (GtkEntry *entry);
551 static void gtk_entry_get_text_area_size (GtkEntry *entry,
556 static void get_text_area_size (GtkEntry *entry,
561 static void get_frame_size (GtkEntry *entry,
566 static void gtk_entry_move_adjustments (GtkEntry *entry);
567 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
568 GtkEntryIconPosition icon_pos);
572 static gint gtk_entry_completion_timeout (gpointer data);
573 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
576 static void gtk_entry_completion_changed (GtkWidget *entry,
578 static gboolean check_completion_callback (GtkEntryCompletion *completion);
579 static void clear_completion_callback (GtkEntry *entry,
581 static gboolean accept_completion_callback (GtkEntry *entry);
582 static void completion_insert_text_callback (GtkEntry *entry,
586 GtkEntryCompletion *completion);
587 static void completion_changed (GtkEntryCompletion *completion,
590 static void disconnect_completion_signals (GtkEntry *entry,
591 GtkEntryCompletion *completion);
592 static void connect_completion_signals (GtkEntry *entry,
593 GtkEntryCompletion *completion);
595 static void begin_change (GtkEntry *entry);
596 static void end_change (GtkEntry *entry);
597 static void emit_changed (GtkEntry *entry);
600 static void buffer_inserted_text (GtkEntryBuffer *buffer,
605 static void buffer_deleted_text (GtkEntryBuffer *buffer,
609 static void buffer_notify_text (GtkEntryBuffer *buffer,
612 static void buffer_notify_length (GtkEntryBuffer *buffer,
615 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
618 static void buffer_connect_signals (GtkEntry *entry);
619 static void buffer_disconnect_signals (GtkEntry *entry);
620 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
623 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
624 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
625 gtk_entry_editable_init)
626 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
627 gtk_entry_cell_editable_init))
630 add_move_binding (GtkBindingSet *binding_set,
633 GtkMovementStep step,
636 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
638 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
642 G_TYPE_BOOLEAN, FALSE);
644 /* Selection-extending version */
645 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
649 G_TYPE_BOOLEAN, TRUE);
653 gtk_entry_class_init (GtkEntryClass *class)
655 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
656 GtkWidgetClass *widget_class;
657 GtkBindingSet *binding_set;
659 widget_class = (GtkWidgetClass*) class;
661 gobject_class->dispose = gtk_entry_dispose;
662 gobject_class->finalize = gtk_entry_finalize;
663 gobject_class->set_property = gtk_entry_set_property;
664 gobject_class->get_property = gtk_entry_get_property;
666 widget_class->destroy = gtk_entry_destroy;
667 widget_class->map = gtk_entry_map;
668 widget_class->unmap = gtk_entry_unmap;
669 widget_class->realize = gtk_entry_realize;
670 widget_class->unrealize = gtk_entry_unrealize;
671 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
672 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
673 widget_class->size_allocate = gtk_entry_size_allocate;
674 widget_class->draw = gtk_entry_draw;
675 widget_class->enter_notify_event = gtk_entry_enter_notify;
676 widget_class->leave_notify_event = gtk_entry_leave_notify;
677 widget_class->button_press_event = gtk_entry_button_press;
678 widget_class->button_release_event = gtk_entry_button_release;
679 widget_class->motion_notify_event = gtk_entry_motion_notify;
680 widget_class->key_press_event = gtk_entry_key_press;
681 widget_class->key_release_event = gtk_entry_key_release;
682 widget_class->focus_in_event = gtk_entry_focus_in;
683 widget_class->focus_out_event = gtk_entry_focus_out;
684 widget_class->grab_focus = gtk_entry_grab_focus;
685 widget_class->style_updated = gtk_entry_style_updated;
686 widget_class->query_tooltip = gtk_entry_query_tooltip;
687 widget_class->drag_begin = gtk_entry_drag_begin;
688 widget_class->drag_end = gtk_entry_drag_end;
689 widget_class->direction_changed = gtk_entry_direction_changed;
690 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
691 widget_class->screen_changed = gtk_entry_screen_changed;
692 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
694 widget_class->drag_drop = gtk_entry_drag_drop;
695 widget_class->drag_motion = gtk_entry_drag_motion;
696 widget_class->drag_leave = gtk_entry_drag_leave;
697 widget_class->drag_data_received = gtk_entry_drag_data_received;
698 widget_class->drag_data_get = gtk_entry_drag_data_get;
699 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
701 widget_class->popup_menu = gtk_entry_popup_menu;
703 class->move_cursor = gtk_entry_move_cursor;
704 class->insert_at_cursor = gtk_entry_insert_at_cursor;
705 class->delete_from_cursor = gtk_entry_delete_from_cursor;
706 class->backspace = gtk_entry_backspace;
707 class->cut_clipboard = gtk_entry_cut_clipboard;
708 class->copy_clipboard = gtk_entry_copy_clipboard;
709 class->paste_clipboard = gtk_entry_paste_clipboard;
710 class->toggle_overwrite = gtk_entry_toggle_overwrite;
711 class->activate = gtk_entry_real_activate;
712 class->get_text_area_size = gtk_entry_get_text_area_size;
714 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
715 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
716 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
717 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
719 g_object_class_override_property (gobject_class,
720 PROP_EDITING_CANCELED,
723 g_object_class_install_property (gobject_class,
725 g_param_spec_object ("buffer",
727 P_("Text buffer object which actually stores entry text"),
728 GTK_TYPE_ENTRY_BUFFER,
729 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
731 g_object_class_install_property (gobject_class,
732 PROP_CURSOR_POSITION,
733 g_param_spec_int ("cursor-position",
734 P_("Cursor Position"),
735 P_("The current position of the insertion cursor in chars"),
737 GTK_ENTRY_BUFFER_MAX_SIZE,
739 GTK_PARAM_READABLE));
741 g_object_class_install_property (gobject_class,
742 PROP_SELECTION_BOUND,
743 g_param_spec_int ("selection-bound",
744 P_("Selection Bound"),
745 P_("The position of the opposite end of the selection from the cursor in chars"),
747 GTK_ENTRY_BUFFER_MAX_SIZE,
749 GTK_PARAM_READABLE));
751 g_object_class_install_property (gobject_class,
753 g_param_spec_boolean ("editable",
755 P_("Whether the entry contents can be edited"),
757 GTK_PARAM_READWRITE));
759 g_object_class_install_property (gobject_class,
761 g_param_spec_int ("max-length",
762 P_("Maximum length"),
763 P_("Maximum number of characters for this entry. Zero if no maximum"),
765 GTK_ENTRY_BUFFER_MAX_SIZE,
767 GTK_PARAM_READWRITE));
768 g_object_class_install_property (gobject_class,
770 g_param_spec_boolean ("visibility",
772 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
774 GTK_PARAM_READWRITE));
776 g_object_class_install_property (gobject_class,
778 g_param_spec_boolean ("has-frame",
780 P_("FALSE removes outside bevel from entry"),
782 GTK_PARAM_READWRITE));
784 g_object_class_install_property (gobject_class,
786 g_param_spec_boxed ("inner-border",
788 P_("Border between text and frame. Overrides the inner-border style property"),
790 GTK_PARAM_READWRITE));
792 g_object_class_install_property (gobject_class,
794 g_param_spec_unichar ("invisible-char",
795 P_("Invisible character"),
796 P_("The character to use when masking entry contents (in \"password mode\")"),
798 GTK_PARAM_READWRITE));
800 g_object_class_install_property (gobject_class,
801 PROP_ACTIVATES_DEFAULT,
802 g_param_spec_boolean ("activates-default",
803 P_("Activates default"),
804 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
806 GTK_PARAM_READWRITE));
807 g_object_class_install_property (gobject_class,
809 g_param_spec_int ("width-chars",
810 P_("Width in chars"),
811 P_("Number of characters to leave space for in the entry"),
815 GTK_PARAM_READWRITE));
817 g_object_class_install_property (gobject_class,
819 g_param_spec_int ("scroll-offset",
821 P_("Number of pixels of the entry scrolled off the screen to the left"),
825 GTK_PARAM_READABLE));
827 g_object_class_install_property (gobject_class,
829 g_param_spec_string ("text",
831 P_("The contents of the entry"),
833 GTK_PARAM_READWRITE));
838 * The horizontal alignment, from 0 (left) to 1 (right).
839 * Reversed for RTL layouts.
843 g_object_class_install_property (gobject_class,
845 g_param_spec_float ("xalign",
847 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
851 GTK_PARAM_READWRITE));
854 * GtkEntry:truncate-multiline:
856 * When %TRUE, pasted multi-line text is truncated to the first line.
860 g_object_class_install_property (gobject_class,
861 PROP_TRUNCATE_MULTILINE,
862 g_param_spec_boolean ("truncate-multiline",
863 P_("Truncate multiline"),
864 P_("Whether to truncate multiline pastes to one line."),
866 GTK_PARAM_READWRITE));
869 * GtkEntry:shadow-type:
871 * Which kind of shadow to draw around the entry when
872 * #GtkEntry:has-frame is set to %TRUE.
876 g_object_class_install_property (gobject_class,
878 g_param_spec_enum ("shadow-type",
880 P_("Which kind of shadow to draw around the entry when has-frame is set"),
881 GTK_TYPE_SHADOW_TYPE,
883 GTK_PARAM_READWRITE));
886 * GtkEntry:overwrite-mode:
888 * If text is overwritten when typing in the #GtkEntry.
892 g_object_class_install_property (gobject_class,
894 g_param_spec_boolean ("overwrite-mode",
895 P_("Overwrite mode"),
896 P_("Whether new text overwrites existing text"),
898 GTK_PARAM_READWRITE));
901 * GtkEntry:text-length:
903 * The length of the text in the #GtkEntry.
907 g_object_class_install_property (gobject_class,
909 g_param_spec_uint ("text-length",
911 P_("Length of the text currently in the entry"),
915 GTK_PARAM_READABLE));
917 * GtkEntry:invisible-char-set:
919 * Whether the invisible char has been set for the #GtkEntry.
923 g_object_class_install_property (gobject_class,
924 PROP_INVISIBLE_CHAR_SET,
925 g_param_spec_boolean ("invisible-char-set",
926 P_("Invisible character set"),
927 P_("Whether the invisible character has been set"),
929 GTK_PARAM_READWRITE));
932 * GtkEntry:caps-lock-warning
934 * Whether password entries will show a warning when Caps Lock is on.
936 * Note that the warning is shown using a secondary icon, and thus
937 * does not work if you are using the secondary icon position for some
942 g_object_class_install_property (gobject_class,
943 PROP_CAPS_LOCK_WARNING,
944 g_param_spec_boolean ("caps-lock-warning",
945 P_("Caps Lock warning"),
946 P_("Whether password entries will show a warning when Caps Lock is on"),
948 GTK_PARAM_READWRITE));
951 * GtkEntry:progress-fraction:
953 * The current fraction of the task that's been completed.
957 g_object_class_install_property (gobject_class,
958 PROP_PROGRESS_FRACTION,
959 g_param_spec_double ("progress-fraction",
960 P_("Progress Fraction"),
961 P_("The current fraction of the task that's been completed"),
965 GTK_PARAM_READWRITE));
968 * GtkEntry:progress-pulse-step:
970 * The fraction of total entry width to move the progress
971 * bouncing block for each call to gtk_entry_progress_pulse().
975 g_object_class_install_property (gobject_class,
976 PROP_PROGRESS_PULSE_STEP,
977 g_param_spec_double ("progress-pulse-step",
978 P_("Progress Pulse Step"),
979 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
983 GTK_PARAM_READWRITE));
986 * GtkEntry:primary-icon-pixbuf:
988 * A pixbuf to use as the primary icon for the entry.
992 g_object_class_install_property (gobject_class,
994 g_param_spec_object ("primary-icon-pixbuf",
995 P_("Primary pixbuf"),
996 P_("Primary pixbuf for the entry"),
998 GTK_PARAM_READWRITE));
1001 * GtkEntry:secondary-icon-pixbuf:
1003 * An pixbuf to use as the secondary icon for the entry.
1007 g_object_class_install_property (gobject_class,
1008 PROP_PIXBUF_SECONDARY,
1009 g_param_spec_object ("secondary-icon-pixbuf",
1010 P_("Secondary pixbuf"),
1011 P_("Secondary pixbuf for the entry"),
1013 GTK_PARAM_READWRITE));
1016 * GtkEntry:primary-icon-stock:
1018 * The stock id to use for the primary icon for the entry.
1022 g_object_class_install_property (gobject_class,
1024 g_param_spec_string ("primary-icon-stock",
1025 P_("Primary stock ID"),
1026 P_("Stock ID for primary icon"),
1028 GTK_PARAM_READWRITE));
1031 * GtkEntry:secondary-icon-stock:
1033 * The stock id to use for the secondary icon for the entry.
1037 g_object_class_install_property (gobject_class,
1038 PROP_STOCK_SECONDARY,
1039 g_param_spec_string ("secondary-icon-stock",
1040 P_("Secondary stock ID"),
1041 P_("Stock ID for secondary icon"),
1043 GTK_PARAM_READWRITE));
1046 * GtkEntry:primary-icon-name:
1048 * The icon name to use for the primary icon for the entry.
1052 g_object_class_install_property (gobject_class,
1053 PROP_ICON_NAME_PRIMARY,
1054 g_param_spec_string ("primary-icon-name",
1055 P_("Primary icon name"),
1056 P_("Icon name for primary icon"),
1058 GTK_PARAM_READWRITE));
1061 * GtkEntry:secondary-icon-name:
1063 * The icon name to use for the secondary icon for the entry.
1067 g_object_class_install_property (gobject_class,
1068 PROP_ICON_NAME_SECONDARY,
1069 g_param_spec_string ("secondary-icon-name",
1070 P_("Secondary icon name"),
1071 P_("Icon name for secondary icon"),
1073 GTK_PARAM_READWRITE));
1076 * GtkEntry:primary-icon-gicon:
1078 * The #GIcon to use for the primary icon for the entry.
1082 g_object_class_install_property (gobject_class,
1084 g_param_spec_object ("primary-icon-gicon",
1085 P_("Primary GIcon"),
1086 P_("GIcon for primary icon"),
1088 GTK_PARAM_READWRITE));
1091 * GtkEntry:secondary-icon-gicon:
1093 * The #GIcon to use for the secondary icon for the entry.
1097 g_object_class_install_property (gobject_class,
1098 PROP_GICON_SECONDARY,
1099 g_param_spec_object ("secondary-icon-gicon",
1100 P_("Secondary GIcon"),
1101 P_("GIcon for secondary icon"),
1103 GTK_PARAM_READWRITE));
1106 * GtkEntry:primary-icon-storage-type:
1108 * The representation which is used for the primary icon of the entry.
1112 g_object_class_install_property (gobject_class,
1113 PROP_STORAGE_TYPE_PRIMARY,
1114 g_param_spec_enum ("primary-icon-storage-type",
1115 P_("Primary storage type"),
1116 P_("The representation being used for primary icon"),
1117 GTK_TYPE_IMAGE_TYPE,
1119 GTK_PARAM_READABLE));
1122 * GtkEntry:secondary-icon-storage-type:
1124 * The representation which is used for the secondary icon of the entry.
1128 g_object_class_install_property (gobject_class,
1129 PROP_STORAGE_TYPE_SECONDARY,
1130 g_param_spec_enum ("secondary-icon-storage-type",
1131 P_("Secondary storage type"),
1132 P_("The representation being used for secondary icon"),
1133 GTK_TYPE_IMAGE_TYPE,
1135 GTK_PARAM_READABLE));
1138 * GtkEntry:primary-icon-activatable:
1140 * Whether the primary icon is activatable.
1142 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1143 * signals only on sensitive, activatable icons.
1145 * Sensitive, but non-activatable icons can be used for purely
1146 * informational purposes.
1150 g_object_class_install_property (gobject_class,
1151 PROP_ACTIVATABLE_PRIMARY,
1152 g_param_spec_boolean ("primary-icon-activatable",
1153 P_("Primary icon activatable"),
1154 P_("Whether the primary icon is activatable"),
1156 GTK_PARAM_READWRITE));
1159 * GtkEntry:secondary-icon-activatable:
1161 * Whether the secondary icon is activatable.
1163 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1164 * signals only on sensitive, activatable icons.
1166 * Sensitive, but non-activatable icons can be used for purely
1167 * informational purposes.
1171 g_object_class_install_property (gobject_class,
1172 PROP_ACTIVATABLE_SECONDARY,
1173 g_param_spec_boolean ("secondary-icon-activatable",
1174 P_("Secondary icon activatable"),
1175 P_("Whether the secondary icon is activatable"),
1177 GTK_PARAM_READWRITE));
1181 * GtkEntry:primary-icon-sensitive:
1183 * Whether the primary icon is sensitive.
1185 * An insensitive icon appears grayed out. GTK+ does not emit the
1186 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1187 * does not allow DND from insensitive icons.
1189 * An icon should be set insensitive if the action that would trigger
1190 * when clicked is currently not available.
1194 g_object_class_install_property (gobject_class,
1195 PROP_SENSITIVE_PRIMARY,
1196 g_param_spec_boolean ("primary-icon-sensitive",
1197 P_("Primary icon sensitive"),
1198 P_("Whether the primary icon is sensitive"),
1200 GTK_PARAM_READWRITE));
1203 * GtkEntry:secondary-icon-sensitive:
1205 * Whether the secondary icon is sensitive.
1207 * An insensitive icon appears grayed out. GTK+ does not emit the
1208 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1209 * does not allow DND from insensitive icons.
1211 * An icon should be set insensitive if the action that would trigger
1212 * when clicked is currently not available.
1216 g_object_class_install_property (gobject_class,
1217 PROP_SENSITIVE_SECONDARY,
1218 g_param_spec_boolean ("secondary-icon-sensitive",
1219 P_("Secondary icon sensitive"),
1220 P_("Whether the secondary icon is sensitive"),
1222 GTK_PARAM_READWRITE));
1225 * GtkEntry:primary-icon-tooltip-text:
1227 * The contents of the tooltip on the primary icon.
1229 * Also see gtk_entry_set_icon_tooltip_text().
1233 g_object_class_install_property (gobject_class,
1234 PROP_TOOLTIP_TEXT_PRIMARY,
1235 g_param_spec_string ("primary-icon-tooltip-text",
1236 P_("Primary icon tooltip text"),
1237 P_("The contents of the tooltip on the primary icon"),
1239 GTK_PARAM_READWRITE));
1242 * GtkEntry:secondary-icon-tooltip-text:
1244 * The contents of the tooltip on the secondary icon.
1246 * Also see gtk_entry_set_icon_tooltip_text().
1250 g_object_class_install_property (gobject_class,
1251 PROP_TOOLTIP_TEXT_SECONDARY,
1252 g_param_spec_string ("secondary-icon-tooltip-text",
1253 P_("Secondary icon tooltip text"),
1254 P_("The contents of the tooltip on the secondary icon"),
1256 GTK_PARAM_READWRITE));
1259 * GtkEntry:primary-icon-tooltip-markup:
1261 * The contents of the tooltip on the primary icon, which is marked up
1262 * with the <link linkend="PangoMarkupFormat">Pango text markup
1265 * Also see gtk_entry_set_icon_tooltip_markup().
1269 g_object_class_install_property (gobject_class,
1270 PROP_TOOLTIP_MARKUP_PRIMARY,
1271 g_param_spec_string ("primary-icon-tooltip-markup",
1272 P_("Primary icon tooltip markup"),
1273 P_("The contents of the tooltip on the primary icon"),
1275 GTK_PARAM_READWRITE));
1278 * GtkEntry:secondary-icon-tooltip-markup:
1280 * The contents of the tooltip on the secondary icon, which is marked up
1281 * with the <link linkend="PangoMarkupFormat">Pango text markup
1284 * Also see gtk_entry_set_icon_tooltip_markup().
1288 g_object_class_install_property (gobject_class,
1289 PROP_TOOLTIP_MARKUP_SECONDARY,
1290 g_param_spec_string ("secondary-icon-tooltip-markup",
1291 P_("Secondary icon tooltip markup"),
1292 P_("The contents of the tooltip on the secondary icon"),
1294 GTK_PARAM_READWRITE));
1297 * GtkEntry:im-module:
1299 * Which IM (input method) module should be used for this entry.
1300 * See #GtkIMContext.
1302 * Setting this to a non-%NULL value overrides the
1303 * system-wide IM module setting. See the GtkSettings
1304 * #GtkSettings:gtk-im-module property.
1308 g_object_class_install_property (gobject_class,
1310 g_param_spec_string ("im-module",
1312 P_("Which IM module should be used"),
1314 GTK_PARAM_READWRITE));
1317 * GtkEntry:icon-prelight:
1319 * The prelight style property determines whether activatable
1320 * icons prelight on mouseover.
1324 gtk_widget_class_install_style_property (widget_class,
1325 g_param_spec_boolean ("icon-prelight",
1326 P_("Icon Prelight"),
1327 P_("Whether activatable icons should prelight when hovered"),
1329 GTK_PARAM_READABLE));
1332 * GtkEntry:progress-border:
1334 * The border around the progress bar in the entry.
1338 gtk_widget_class_install_style_property (widget_class,
1339 g_param_spec_boxed ("progress-border",
1340 P_("Progress Border"),
1341 P_("Border around the progress bar"),
1343 GTK_PARAM_READABLE));
1346 * GtkEntry:invisible-char:
1348 * The invisible character is used when masking entry contents (in
1349 * \"password mode\")"). When it is not explicitly set with the
1350 * #GtkEntry::invisible-char property, GTK+ determines the character
1351 * to use from a list of possible candidates, depending on availability
1352 * in the current font.
1354 * This style property allows the theme to prepend a character
1355 * to the list of candidates.
1359 gtk_widget_class_install_style_property (widget_class,
1360 g_param_spec_unichar ("invisible-char",
1361 P_("Invisible character"),
1362 P_("The character to use when masking entry contents (in \"password mode\")"),
1364 GTK_PARAM_READABLE));
1367 * GtkEntry::populate-popup:
1368 * @entry: The entry on which the signal is emitted
1369 * @menu: the menu that is being populated
1371 * The ::populate-popup signal gets emitted before showing the
1372 * context menu of the entry.
1374 * If you need to add items to the context menu, connect
1375 * to this signal and append your menuitems to the @menu.
1377 signals[POPULATE_POPUP] =
1378 g_signal_new (I_("populate-popup"),
1379 G_OBJECT_CLASS_TYPE (gobject_class),
1381 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1383 _gtk_marshal_VOID__OBJECT,
1387 /* Action signals */
1390 * GtkEntry::activate:
1391 * @entry: The entry on which the signal is emitted
1393 * A <link linkend="keybinding-signals">keybinding signal</link>
1394 * which gets emitted when the user activates the entry.
1396 * Applications should not connect to it, but may emit it with
1397 * g_signal_emit_by_name() if they need to control activation
1400 * The default bindings for this signal are all forms of the Enter key.
1403 g_signal_new (I_("activate"),
1404 G_OBJECT_CLASS_TYPE (gobject_class),
1405 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1406 G_STRUCT_OFFSET (GtkEntryClass, activate),
1408 _gtk_marshal_VOID__VOID,
1410 widget_class->activate_signal = signals[ACTIVATE];
1413 * GtkEntry::move-cursor:
1414 * @entry: the object which received the signal
1415 * @step: the granularity of the move, as a #GtkMovementStep
1416 * @count: the number of @step units to move
1417 * @extend_selection: %TRUE if the move should extend the selection
1419 * The ::move-cursor signal is a
1420 * <link linkend="keybinding-signals">keybinding signal</link>
1421 * which gets emitted when the user initiates a cursor movement.
1422 * If the cursor is not visible in @entry, this signal causes
1423 * the viewport to be moved instead.
1425 * Applications should not connect to it, but may emit it with
1426 * g_signal_emit_by_name() if they need to control the cursor
1429 * The default bindings for this signal come in two variants,
1430 * the variant with the Shift modifier extends the selection,
1431 * the variant without the Shift modifer does not.
1432 * There are too many key combinations to list them all here.
1434 * <listitem>Arrow keys move by individual characters/lines</listitem>
1435 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1436 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1439 signals[MOVE_CURSOR] =
1440 g_signal_new (I_("move-cursor"),
1441 G_OBJECT_CLASS_TYPE (gobject_class),
1442 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1443 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1445 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1447 GTK_TYPE_MOVEMENT_STEP,
1452 * GtkEntry::insert-at-cursor:
1453 * @entry: the object which received the signal
1454 * @string: the string to insert
1456 * The ::insert-at-cursor signal is a
1457 * <link linkend="keybinding-signals">keybinding signal</link>
1458 * which gets emitted when the user initiates the insertion of a
1459 * fixed string at the cursor.
1461 * This signal has no default bindings.
1463 signals[INSERT_AT_CURSOR] =
1464 g_signal_new (I_("insert-at-cursor"),
1465 G_OBJECT_CLASS_TYPE (gobject_class),
1466 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1467 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1469 _gtk_marshal_VOID__STRING,
1474 * GtkEntry::delete-from-cursor:
1475 * @entry: the object which received the signal
1476 * @type: the granularity of the deletion, as a #GtkDeleteType
1477 * @count: the number of @type units to delete
1479 * The ::delete-from-cursor signal is a
1480 * <link linkend="keybinding-signals">keybinding signal</link>
1481 * which gets emitted when the user initiates a text deletion.
1483 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1484 * if there is one, otherwise it deletes the requested number
1487 * The default bindings for this signal are
1488 * Delete for deleting a character and Ctrl-Delete for
1491 signals[DELETE_FROM_CURSOR] =
1492 g_signal_new (I_("delete-from-cursor"),
1493 G_OBJECT_CLASS_TYPE (gobject_class),
1494 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1495 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1497 _gtk_marshal_VOID__ENUM_INT,
1499 GTK_TYPE_DELETE_TYPE,
1503 * GtkEntry::backspace:
1504 * @entry: the object which received the signal
1506 * The ::backspace signal is a
1507 * <link linkend="keybinding-signals">keybinding signal</link>
1508 * which gets emitted when the user asks for it.
1510 * The default bindings for this signal are
1511 * Backspace and Shift-Backspace.
1513 signals[BACKSPACE] =
1514 g_signal_new (I_("backspace"),
1515 G_OBJECT_CLASS_TYPE (gobject_class),
1516 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1517 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1519 _gtk_marshal_VOID__VOID,
1523 * GtkEntry::cut-clipboard:
1524 * @entry: the object which received the signal
1526 * The ::cut-clipboard signal is a
1527 * <link linkend="keybinding-signals">keybinding signal</link>
1528 * which gets emitted to cut the selection to the clipboard.
1530 * The default bindings for this signal are
1531 * Ctrl-x and Shift-Delete.
1533 signals[CUT_CLIPBOARD] =
1534 g_signal_new (I_("cut-clipboard"),
1535 G_OBJECT_CLASS_TYPE (gobject_class),
1536 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1537 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1539 _gtk_marshal_VOID__VOID,
1543 * GtkEntry::copy-clipboard:
1544 * @entry: the object which received the signal
1546 * The ::copy-clipboard signal is a
1547 * <link linkend="keybinding-signals">keybinding signal</link>
1548 * which gets emitted to copy the selection to the clipboard.
1550 * The default bindings for this signal are
1551 * Ctrl-c and Ctrl-Insert.
1553 signals[COPY_CLIPBOARD] =
1554 g_signal_new (I_("copy-clipboard"),
1555 G_OBJECT_CLASS_TYPE (gobject_class),
1556 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1557 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1559 _gtk_marshal_VOID__VOID,
1563 * GtkEntry::paste-clipboard:
1564 * @entry: the object which received the signal
1566 * The ::paste-clipboard signal is a
1567 * <link linkend="keybinding-signals">keybinding signal</link>
1568 * which gets emitted to paste the contents of the clipboard
1569 * into the text view.
1571 * The default bindings for this signal are
1572 * Ctrl-v and Shift-Insert.
1574 signals[PASTE_CLIPBOARD] =
1575 g_signal_new (I_("paste-clipboard"),
1576 G_OBJECT_CLASS_TYPE (gobject_class),
1577 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1578 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1580 _gtk_marshal_VOID__VOID,
1584 * GtkEntry::toggle-overwrite:
1585 * @entry: the object which received the signal
1587 * The ::toggle-overwrite signal is a
1588 * <link linkend="keybinding-signals">keybinding signal</link>
1589 * which gets emitted to toggle the overwrite mode of the entry.
1591 * The default bindings for this signal is Insert.
1593 signals[TOGGLE_OVERWRITE] =
1594 g_signal_new (I_("toggle-overwrite"),
1595 G_OBJECT_CLASS_TYPE (gobject_class),
1596 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1597 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1599 _gtk_marshal_VOID__VOID,
1603 * GtkEntry::icon-press:
1604 * @entry: The entry on which the signal is emitted
1605 * @icon_pos: The position of the clicked icon
1606 * @event: the button press event
1608 * The ::icon-press signal is emitted when an activatable icon
1613 signals[ICON_PRESS] =
1614 g_signal_new (I_("icon-press"),
1615 G_TYPE_FROM_CLASS (gobject_class),
1619 _gtk_marshal_VOID__ENUM_BOXED,
1621 GTK_TYPE_ENTRY_ICON_POSITION,
1622 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1625 * GtkEntry::icon-release:
1626 * @entry: The entry on which the signal is emitted
1627 * @icon_pos: The position of the clicked icon
1628 * @event: the button release event
1630 * The ::icon-release signal is emitted on the button release from a
1631 * mouse click over an activatable icon.
1635 signals[ICON_RELEASE] =
1636 g_signal_new (I_("icon-release"),
1637 G_TYPE_FROM_CLASS (gobject_class),
1641 _gtk_marshal_VOID__ENUM_BOXED,
1643 GTK_TYPE_ENTRY_ICON_POSITION,
1644 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1647 * GtkEntry::preedit-changed:
1648 * @entry: the object which received the signal
1649 * @preedit: the current preedit string
1651 * If an input method is used, the typed text will not immediately
1652 * be committed to the buffer. So if you are interested in the text,
1653 * connect to this signal.
1657 signals[PREEDIT_CHANGED] =
1658 g_signal_new_class_handler (I_("preedit-changed"),
1659 G_OBJECT_CLASS_TYPE (gobject_class),
1660 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1663 _gtk_marshal_VOID__STRING,
1672 binding_set = gtk_binding_set_by_class (class);
1674 /* Moving the insertion point */
1675 add_move_binding (binding_set, GDK_KEY_Right, 0,
1676 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1678 add_move_binding (binding_set, GDK_KEY_Left, 0,
1679 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1681 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1682 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1684 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1685 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1687 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1688 GTK_MOVEMENT_WORDS, 1);
1690 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1691 GTK_MOVEMENT_WORDS, -1);
1693 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1694 GTK_MOVEMENT_WORDS, 1);
1696 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1697 GTK_MOVEMENT_WORDS, -1);
1699 add_move_binding (binding_set, GDK_KEY_Home, 0,
1700 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1702 add_move_binding (binding_set, GDK_KEY_End, 0,
1703 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1705 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1706 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1708 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1709 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1711 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1712 GTK_MOVEMENT_BUFFER_ENDS, -1);
1714 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1715 GTK_MOVEMENT_BUFFER_ENDS, 1);
1717 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1718 GTK_MOVEMENT_BUFFER_ENDS, -1);
1720 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1721 GTK_MOVEMENT_BUFFER_ENDS, 1);
1725 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1727 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1729 G_TYPE_BOOLEAN, FALSE);
1730 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1732 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1734 G_TYPE_BOOLEAN, TRUE);
1736 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1738 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1740 G_TYPE_BOOLEAN, FALSE);
1741 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1743 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1745 G_TYPE_BOOLEAN, TRUE);
1748 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1750 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1752 G_TYPE_BOOLEAN, FALSE);
1753 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1755 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1757 G_TYPE_BOOLEAN, FALSE);
1761 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1763 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1765 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1769 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1770 "delete-from-cursor", 2,
1771 G_TYPE_ENUM, GTK_DELETE_CHARS,
1774 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1775 "delete-from-cursor", 2,
1776 G_TYPE_ENUM, GTK_DELETE_CHARS,
1779 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1782 /* Make this do the same as Backspace, to help with mis-typing */
1783 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1787 "delete-from-cursor", 2,
1788 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1791 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1792 "delete-from-cursor", 2,
1793 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1796 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1797 "delete-from-cursor", 2,
1798 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1801 /* Cut/copy/paste */
1803 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1804 "cut-clipboard", 0);
1805 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1806 "copy-clipboard", 0);
1807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1808 "paste-clipboard", 0);
1810 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1811 "cut-clipboard", 0);
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1813 "copy-clipboard", 0);
1814 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1815 "paste-clipboard", 0);
1818 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1819 "toggle-overwrite", 0);
1820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1821 "toggle-overwrite", 0);
1824 * GtkEntry:inner-border:
1826 * Sets the text area's border between the text and the frame.
1830 gtk_widget_class_install_style_property (widget_class,
1831 g_param_spec_boxed ("inner-border",
1833 P_("Border between text and frame."),
1835 GTK_PARAM_READABLE));
1837 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1841 gtk_entry_editable_init (GtkEditableInterface *iface)
1843 iface->do_insert_text = gtk_entry_insert_text;
1844 iface->do_delete_text = gtk_entry_delete_text;
1845 iface->insert_text = gtk_entry_real_insert_text;
1846 iface->delete_text = gtk_entry_real_delete_text;
1847 iface->get_chars = gtk_entry_get_chars;
1848 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1849 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1850 iface->set_position = gtk_entry_real_set_position;
1851 iface->get_position = gtk_entry_get_position;
1855 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1857 iface->start_editing = gtk_entry_start_editing;
1861 gtk_entry_set_property (GObject *object,
1863 const GValue *value,
1866 GtkEntry *entry = GTK_ENTRY (object);
1867 GtkEntryPrivate *priv = entry->priv;
1872 gtk_entry_set_buffer (entry, g_value_get_object (value));
1877 gboolean new_value = g_value_get_boolean (value);
1879 if (new_value != priv->editable)
1881 GtkWidget *widget = GTK_WIDGET (entry);
1885 _gtk_entry_reset_im_context (entry);
1886 if (gtk_widget_has_focus (widget))
1887 gtk_im_context_focus_out (priv->im_context);
1889 priv->preedit_length = 0;
1890 priv->preedit_cursor = 0;
1893 priv->editable = new_value;
1895 if (new_value && gtk_widget_has_focus (widget))
1896 gtk_im_context_focus_in (priv->im_context);
1898 gtk_widget_queue_draw (widget);
1903 case PROP_MAX_LENGTH:
1904 gtk_entry_set_max_length (entry, g_value_get_int (value));
1907 case PROP_VISIBILITY:
1908 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1911 case PROP_HAS_FRAME:
1912 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1915 case PROP_INNER_BORDER:
1916 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1919 case PROP_INVISIBLE_CHAR:
1920 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1923 case PROP_ACTIVATES_DEFAULT:
1924 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1927 case PROP_WIDTH_CHARS:
1928 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1932 gtk_entry_set_text (entry, g_value_get_string (value));
1936 gtk_entry_set_alignment (entry, g_value_get_float (value));
1939 case PROP_TRUNCATE_MULTILINE:
1940 priv->truncate_multiline = g_value_get_boolean (value);
1943 case PROP_SHADOW_TYPE:
1944 priv->shadow_type = g_value_get_enum (value);
1947 case PROP_OVERWRITE_MODE:
1948 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1951 case PROP_INVISIBLE_CHAR_SET:
1952 if (g_value_get_boolean (value))
1953 priv->invisible_char_set = TRUE;
1955 gtk_entry_unset_invisible_char (entry);
1958 case PROP_CAPS_LOCK_WARNING:
1959 priv->caps_lock_warning = g_value_get_boolean (value);
1962 case PROP_PROGRESS_FRACTION:
1963 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1966 case PROP_PROGRESS_PULSE_STEP:
1967 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1970 case PROP_PIXBUF_PRIMARY:
1971 gtk_entry_set_icon_from_pixbuf (entry,
1972 GTK_ENTRY_ICON_PRIMARY,
1973 g_value_get_object (value));
1976 case PROP_PIXBUF_SECONDARY:
1977 gtk_entry_set_icon_from_pixbuf (entry,
1978 GTK_ENTRY_ICON_SECONDARY,
1979 g_value_get_object (value));
1982 case PROP_STOCK_PRIMARY:
1983 gtk_entry_set_icon_from_stock (entry,
1984 GTK_ENTRY_ICON_PRIMARY,
1985 g_value_get_string (value));
1988 case PROP_STOCK_SECONDARY:
1989 gtk_entry_set_icon_from_stock (entry,
1990 GTK_ENTRY_ICON_SECONDARY,
1991 g_value_get_string (value));
1994 case PROP_ICON_NAME_PRIMARY:
1995 gtk_entry_set_icon_from_icon_name (entry,
1996 GTK_ENTRY_ICON_PRIMARY,
1997 g_value_get_string (value));
2000 case PROP_ICON_NAME_SECONDARY:
2001 gtk_entry_set_icon_from_icon_name (entry,
2002 GTK_ENTRY_ICON_SECONDARY,
2003 g_value_get_string (value));
2006 case PROP_GICON_PRIMARY:
2007 gtk_entry_set_icon_from_gicon (entry,
2008 GTK_ENTRY_ICON_PRIMARY,
2009 g_value_get_object (value));
2012 case PROP_GICON_SECONDARY:
2013 gtk_entry_set_icon_from_gicon (entry,
2014 GTK_ENTRY_ICON_SECONDARY,
2015 g_value_get_object (value));
2018 case PROP_ACTIVATABLE_PRIMARY:
2019 gtk_entry_set_icon_activatable (entry,
2020 GTK_ENTRY_ICON_PRIMARY,
2021 g_value_get_boolean (value));
2024 case PROP_ACTIVATABLE_SECONDARY:
2025 gtk_entry_set_icon_activatable (entry,
2026 GTK_ENTRY_ICON_SECONDARY,
2027 g_value_get_boolean (value));
2030 case PROP_SENSITIVE_PRIMARY:
2031 gtk_entry_set_icon_sensitive (entry,
2032 GTK_ENTRY_ICON_PRIMARY,
2033 g_value_get_boolean (value));
2036 case PROP_SENSITIVE_SECONDARY:
2037 gtk_entry_set_icon_sensitive (entry,
2038 GTK_ENTRY_ICON_SECONDARY,
2039 g_value_get_boolean (value));
2042 case PROP_TOOLTIP_TEXT_PRIMARY:
2043 gtk_entry_set_icon_tooltip_text (entry,
2044 GTK_ENTRY_ICON_PRIMARY,
2045 g_value_get_string (value));
2048 case PROP_TOOLTIP_TEXT_SECONDARY:
2049 gtk_entry_set_icon_tooltip_text (entry,
2050 GTK_ENTRY_ICON_SECONDARY,
2051 g_value_get_string (value));
2054 case PROP_TOOLTIP_MARKUP_PRIMARY:
2055 gtk_entry_set_icon_tooltip_markup (entry,
2056 GTK_ENTRY_ICON_PRIMARY,
2057 g_value_get_string (value));
2060 case PROP_TOOLTIP_MARKUP_SECONDARY:
2061 gtk_entry_set_icon_tooltip_markup (entry,
2062 GTK_ENTRY_ICON_SECONDARY,
2063 g_value_get_string (value));
2066 case PROP_IM_MODULE:
2067 g_free (priv->im_module);
2068 priv->im_module = g_value_dup_string (value);
2069 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2070 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2073 case PROP_EDITING_CANCELED:
2074 priv->editing_canceled = g_value_get_boolean (value);
2077 case PROP_SCROLL_OFFSET:
2078 case PROP_CURSOR_POSITION:
2080 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2086 gtk_entry_get_property (GObject *object,
2091 GtkEntry *entry = GTK_ENTRY (object);
2092 GtkEntryPrivate *priv = entry->priv;
2097 g_value_set_object (value, gtk_entry_get_buffer (entry));
2100 case PROP_CURSOR_POSITION:
2101 g_value_set_int (value, priv->current_pos);
2104 case PROP_SELECTION_BOUND:
2105 g_value_set_int (value, priv->selection_bound);
2109 g_value_set_boolean (value, priv->editable);
2112 case PROP_MAX_LENGTH:
2113 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2116 case PROP_VISIBILITY:
2117 g_value_set_boolean (value, priv->visible);
2120 case PROP_HAS_FRAME:
2121 g_value_set_boolean (value, priv->has_frame);
2124 case PROP_INNER_BORDER:
2125 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2128 case PROP_INVISIBLE_CHAR:
2129 g_value_set_uint (value, priv->invisible_char);
2132 case PROP_ACTIVATES_DEFAULT:
2133 g_value_set_boolean (value, priv->activates_default);
2136 case PROP_WIDTH_CHARS:
2137 g_value_set_int (value, priv->width_chars);
2140 case PROP_SCROLL_OFFSET:
2141 g_value_set_int (value, priv->scroll_offset);
2145 g_value_set_string (value, gtk_entry_get_text (entry));
2149 g_value_set_float (value, gtk_entry_get_alignment (entry));
2152 case PROP_TRUNCATE_MULTILINE:
2153 g_value_set_boolean (value, priv->truncate_multiline);
2156 case PROP_SHADOW_TYPE:
2157 g_value_set_enum (value, priv->shadow_type);
2160 case PROP_OVERWRITE_MODE:
2161 g_value_set_boolean (value, priv->overwrite_mode);
2164 case PROP_TEXT_LENGTH:
2165 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2168 case PROP_INVISIBLE_CHAR_SET:
2169 g_value_set_boolean (value, priv->invisible_char_set);
2172 case PROP_IM_MODULE:
2173 g_value_set_string (value, priv->im_module);
2176 case PROP_CAPS_LOCK_WARNING:
2177 g_value_set_boolean (value, priv->caps_lock_warning);
2180 case PROP_PROGRESS_FRACTION:
2181 g_value_set_double (value, priv->progress_fraction);
2184 case PROP_PROGRESS_PULSE_STEP:
2185 g_value_set_double (value, priv->progress_pulse_fraction);
2188 case PROP_PIXBUF_PRIMARY:
2189 g_value_set_object (value,
2190 gtk_entry_get_icon_pixbuf (entry,
2191 GTK_ENTRY_ICON_PRIMARY));
2194 case PROP_PIXBUF_SECONDARY:
2195 g_value_set_object (value,
2196 gtk_entry_get_icon_pixbuf (entry,
2197 GTK_ENTRY_ICON_SECONDARY));
2200 case PROP_STOCK_PRIMARY:
2201 g_value_set_string (value,
2202 gtk_entry_get_icon_stock (entry,
2203 GTK_ENTRY_ICON_PRIMARY));
2206 case PROP_STOCK_SECONDARY:
2207 g_value_set_string (value,
2208 gtk_entry_get_icon_stock (entry,
2209 GTK_ENTRY_ICON_SECONDARY));
2212 case PROP_ICON_NAME_PRIMARY:
2213 g_value_set_string (value,
2214 gtk_entry_get_icon_name (entry,
2215 GTK_ENTRY_ICON_PRIMARY));
2218 case PROP_ICON_NAME_SECONDARY:
2219 g_value_set_string (value,
2220 gtk_entry_get_icon_name (entry,
2221 GTK_ENTRY_ICON_SECONDARY));
2224 case PROP_GICON_PRIMARY:
2225 g_value_set_object (value,
2226 gtk_entry_get_icon_gicon (entry,
2227 GTK_ENTRY_ICON_PRIMARY));
2230 case PROP_GICON_SECONDARY:
2231 g_value_set_object (value,
2232 gtk_entry_get_icon_gicon (entry,
2233 GTK_ENTRY_ICON_SECONDARY));
2236 case PROP_STORAGE_TYPE_PRIMARY:
2237 g_value_set_enum (value,
2238 gtk_entry_get_icon_storage_type (entry,
2239 GTK_ENTRY_ICON_PRIMARY));
2242 case PROP_STORAGE_TYPE_SECONDARY:
2243 g_value_set_enum (value,
2244 gtk_entry_get_icon_storage_type (entry,
2245 GTK_ENTRY_ICON_SECONDARY));
2248 case PROP_ACTIVATABLE_PRIMARY:
2249 g_value_set_boolean (value,
2250 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2253 case PROP_ACTIVATABLE_SECONDARY:
2254 g_value_set_boolean (value,
2255 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2258 case PROP_SENSITIVE_PRIMARY:
2259 g_value_set_boolean (value,
2260 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2263 case PROP_SENSITIVE_SECONDARY:
2264 g_value_set_boolean (value,
2265 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2268 case PROP_TOOLTIP_TEXT_PRIMARY:
2269 g_value_take_string (value,
2270 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2273 case PROP_TOOLTIP_TEXT_SECONDARY:
2274 g_value_take_string (value,
2275 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2278 case PROP_TOOLTIP_MARKUP_PRIMARY:
2279 g_value_take_string (value,
2280 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2283 case PROP_TOOLTIP_MARKUP_SECONDARY:
2284 g_value_take_string (value,
2285 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2288 case PROP_EDITING_CANCELED:
2289 g_value_set_boolean (value,
2290 priv->editing_canceled);
2294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2300 find_invisible_char (GtkWidget *widget)
2302 PangoLayout *layout;
2303 PangoAttrList *attr_list;
2305 gunichar invisible_chars [] = {
2307 0x25cf, /* BLACK CIRCLE */
2308 0x2022, /* BULLET */
2309 0x2731, /* HEAVY ASTERISK */
2310 0x273a /* SIXTEEN POINTED ASTERISK */
2313 gtk_widget_style_get (widget,
2314 "invisible-char", &invisible_chars[0],
2317 layout = gtk_widget_create_pango_layout (widget, NULL);
2319 attr_list = pango_attr_list_new ();
2320 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2322 pango_layout_set_attributes (layout, attr_list);
2323 pango_attr_list_unref (attr_list);
2325 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2327 gchar text[7] = { 0, };
2330 len = g_unichar_to_utf8 (invisible_chars[i], text);
2331 pango_layout_set_text (layout, text, len);
2333 count = pango_layout_get_unknown_glyphs_count (layout);
2337 g_object_unref (layout);
2338 return invisible_chars[i];
2342 g_object_unref (layout);
2348 gtk_entry_init (GtkEntry *entry)
2350 GtkStyleContext *context;
2351 GtkEntryPrivate *priv;
2353 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2358 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2359 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2361 priv->editable = TRUE;
2362 priv->visible = TRUE;
2363 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2364 priv->dnd_position = -1;
2365 priv->width_chars = -1;
2366 priv->is_cell_renderer = FALSE;
2367 priv->editing_canceled = FALSE;
2368 priv->has_frame = TRUE;
2369 priv->truncate_multiline = FALSE;
2370 priv->shadow_type = GTK_SHADOW_IN;
2372 priv->caps_lock_warning = TRUE;
2373 priv->caps_lock_warning_shown = FALSE;
2374 priv->progress_fraction = 0.0;
2375 priv->progress_pulse_fraction = 0.1;
2377 gtk_drag_dest_set (GTK_WIDGET (entry),
2378 GTK_DEST_DEFAULT_HIGHLIGHT,
2380 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2381 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2383 /* This object is completely private. No external entity can gain a reference
2384 * to it; so we create it here and destroy it in finalize().
2386 priv->im_context = gtk_im_multicontext_new ();
2388 g_signal_connect (priv->im_context, "commit",
2389 G_CALLBACK (gtk_entry_commit_cb), entry);
2390 g_signal_connect (priv->im_context, "preedit-changed",
2391 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2392 g_signal_connect (priv->im_context, "retrieve-surrounding",
2393 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2394 g_signal_connect (priv->im_context, "delete-surrounding",
2395 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2397 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2398 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2402 get_icon_width (GtkEntry *entry,
2403 GtkEntryIconPosition icon_pos)
2405 GtkEntryPrivate *priv = entry->priv;
2406 EntryIconInfo *icon_info = priv->icons[icon_pos];
2408 GtkSettings *settings;
2409 gint menu_icon_width;
2411 if (!icon_info || icon_info->pixbuf == NULL)
2414 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2415 settings = gtk_settings_get_for_screen (screen);
2417 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2418 &menu_icon_width, NULL);
2420 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2424 get_icon_allocations (GtkEntry *entry,
2425 GtkAllocation *primary,
2426 GtkAllocation *secondary)
2429 GtkEntryPrivate *priv = entry->priv;
2430 gint x, y, width, height;
2432 get_text_area_size (entry, &x, &y, &width, &height);
2434 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2435 y += priv->focus_width;
2438 primary->height = height;
2439 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2440 if (primary->width > 0)
2441 primary->width += 2 * priv->icon_margin;
2444 secondary->height = height;
2445 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2446 if (secondary->width > 0)
2447 secondary->width += 2 * priv->icon_margin;
2449 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2451 primary->x = x + width - primary->width;
2457 secondary->x = x + width - secondary->width;
2463 begin_change (GtkEntry *entry)
2465 GtkEntryPrivate *priv = entry->priv;
2467 priv->change_count++;
2471 end_change (GtkEntry *entry)
2473 GtkEditable *editable = GTK_EDITABLE (entry);
2474 GtkEntryPrivate *priv = entry->priv;
2476 g_return_if_fail (priv->change_count > 0);
2478 priv->change_count--;
2480 if (priv->change_count == 0)
2482 if (priv->real_changed)
2484 g_signal_emit_by_name (editable, "changed");
2485 priv->real_changed = FALSE;
2491 emit_changed (GtkEntry *entry)
2493 GtkEditable *editable = GTK_EDITABLE (entry);
2494 GtkEntryPrivate *priv = entry->priv;
2496 if (priv->change_count == 0)
2497 g_signal_emit_by_name (editable, "changed");
2499 priv->real_changed = TRUE;
2503 gtk_entry_destroy (GtkWidget *widget)
2505 GtkEntry *entry = GTK_ENTRY (widget);
2506 GtkEntryPrivate *priv = entry->priv;
2508 priv->current_pos = priv->selection_bound = 0;
2509 _gtk_entry_reset_im_context (entry);
2510 gtk_entry_reset_layout (entry);
2512 if (priv->blink_timeout)
2514 g_source_remove (priv->blink_timeout);
2515 priv->blink_timeout = 0;
2518 if (priv->recompute_idle)
2520 g_source_remove (priv->recompute_idle);
2521 priv->recompute_idle = 0;
2524 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2528 gtk_entry_dispose (GObject *object)
2530 GtkEntry *entry = GTK_ENTRY (object);
2531 GtkEntryPrivate *priv = entry->priv;
2533 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2534 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2535 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2536 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2540 buffer_disconnect_signals (entry);
2541 g_object_unref (priv->buffer);
2542 priv->buffer = NULL;
2545 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2549 gtk_entry_finalize (GObject *object)
2551 GtkEntry *entry = GTK_ENTRY (object);
2552 GtkEntryPrivate *priv = entry->priv;
2553 EntryIconInfo *icon_info = NULL;
2556 for (i = 0; i < MAX_ICONS; i++)
2558 if ((icon_info = priv->icons[i]) != NULL)
2560 if (icon_info->target_list != NULL)
2562 gtk_target_list_unref (icon_info->target_list);
2563 icon_info->target_list = NULL;
2566 g_slice_free (EntryIconInfo, icon_info);
2567 priv->icons[i] = NULL;
2571 gtk_entry_set_completion (entry, NULL);
2573 if (priv->cached_layout)
2574 g_object_unref (priv->cached_layout);
2576 g_object_unref (priv->im_context);
2578 if (priv->blink_timeout)
2579 g_source_remove (priv->blink_timeout);
2581 if (priv->recompute_idle)
2582 g_source_remove (priv->recompute_idle);
2584 g_free (priv->im_module);
2586 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2590 gtk_entry_get_display_mode (GtkEntry *entry)
2592 GtkEntryPrivate *priv = entry->priv;
2595 return DISPLAY_NORMAL;
2597 if (priv->invisible_char == 0 && priv->invisible_char_set)
2598 return DISPLAY_BLANK;
2600 return DISPLAY_INVISIBLE;
2604 gtk_entry_get_display_text (GtkEntry *entry,
2608 GtkEntryPasswordHint *password_hint;
2609 GtkEntryPrivate *priv;
2610 gunichar invisible_char;
2621 text = gtk_entry_buffer_get_text (get_buffer (entry));
2622 length = gtk_entry_buffer_get_length (get_buffer (entry));
2626 if (start_pos > length)
2629 if (end_pos <= start_pos)
2630 return g_strdup ("");
2631 else if (priv->visible)
2633 start = g_utf8_offset_to_pointer (text, start_pos);
2634 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2635 return g_strndup (start, end - start);
2639 str = g_string_sized_new (length * 2);
2641 /* Figure out what our invisible char is and encode it */
2642 if (!priv->invisible_char)
2643 invisible_char = priv->invisible_char_set ? ' ' : '*';
2645 invisible_char = priv->invisible_char;
2646 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2649 * Add hidden characters for each character in the text
2650 * buffer. If there is a password hint, then keep that
2651 * character visible.
2654 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2655 for (i = start_pos; i < end_pos; ++i)
2657 if (password_hint && i == password_hint->position)
2659 start = g_utf8_offset_to_pointer (text, i);
2660 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2664 g_string_append_len (str, char_str, char_len);
2668 return g_string_free (str, FALSE);
2674 update_cursors (GtkWidget *widget)
2676 GtkEntry *entry = GTK_ENTRY (widget);
2677 GtkEntryPrivate *priv = entry->priv;
2678 EntryIconInfo *icon_info = NULL;
2679 GdkDisplay *display;
2683 for (i = 0; i < MAX_ICONS; i++)
2685 if ((icon_info = priv->icons[i]) != NULL)
2687 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2688 gdk_window_show_unraised (icon_info->window);
2690 /* The icon windows are not children of the visible entry window,
2691 * thus we can't just inherit the xterm cursor. Slight complication
2692 * here is that for the entry, insensitive => arrow cursor, but for
2693 * an icon in a sensitive entry, insensitive => xterm cursor.
2695 if (gtk_widget_is_sensitive (widget) &&
2696 (icon_info->insensitive ||
2697 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2699 display = gtk_widget_get_display (widget);
2700 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2701 gdk_window_set_cursor (icon_info->window, cursor);
2702 g_object_unref (cursor);
2706 gdk_window_set_cursor (icon_info->window, NULL);
2713 realize_icon_info (GtkWidget *widget,
2714 GtkEntryIconPosition icon_pos)
2716 GtkEntry *entry = GTK_ENTRY (widget);
2717 GtkEntryPrivate *priv = entry->priv;
2718 EntryIconInfo *icon_info = priv->icons[icon_pos];
2719 GdkWindowAttr attributes;
2720 gint attributes_mask;
2722 g_return_if_fail (icon_info != NULL);
2726 attributes.width = 1;
2727 attributes.height = 1;
2728 attributes.window_type = GDK_WINDOW_CHILD;
2729 attributes.wclass = GDK_INPUT_ONLY;
2730 attributes.event_mask = gtk_widget_get_events (widget);
2731 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2732 GDK_BUTTON_RELEASE_MASK |
2733 GDK_BUTTON1_MOTION_MASK |
2734 GDK_BUTTON3_MOTION_MASK |
2735 GDK_POINTER_MOTION_HINT_MASK |
2736 GDK_POINTER_MOTION_MASK |
2737 GDK_ENTER_NOTIFY_MASK |
2738 GDK_LEAVE_NOTIFY_MASK);
2739 attributes_mask = GDK_WA_X | GDK_WA_Y;
2741 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2744 gdk_window_set_user_data (icon_info->window, widget);
2746 gtk_widget_queue_resize (widget);
2749 static EntryIconInfo*
2750 construct_icon_info (GtkWidget *widget,
2751 GtkEntryIconPosition icon_pos)
2753 GtkEntry *entry = GTK_ENTRY (widget);
2754 GtkEntryPrivate *priv = entry->priv;
2755 EntryIconInfo *icon_info;
2757 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2759 icon_info = g_slice_new0 (EntryIconInfo);
2760 priv->icons[icon_pos] = icon_info;
2762 if (gtk_widget_get_realized (widget))
2763 realize_icon_info (widget, icon_pos);
2769 gtk_entry_map (GtkWidget *widget)
2771 GtkEntry *entry = GTK_ENTRY (widget);
2772 GtkEntryPrivate *priv = entry->priv;
2773 EntryIconInfo *icon_info = NULL;
2776 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2778 gdk_window_show (priv->text_area);
2780 for (i = 0; i < MAX_ICONS; i++)
2782 if ((icon_info = priv->icons[i]) != NULL)
2784 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2785 gdk_window_show (icon_info->window);
2789 update_cursors (widget);
2793 gtk_entry_unmap (GtkWidget *widget)
2795 GtkEntry *entry = GTK_ENTRY (widget);
2796 GtkEntryPrivate *priv = entry->priv;
2797 EntryIconInfo *icon_info = NULL;
2800 for (i = 0; i < MAX_ICONS; i++)
2802 if ((icon_info = priv->icons[i]) != NULL)
2804 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2805 gdk_window_hide (icon_info->window);
2809 gdk_window_hide (priv->text_area);
2811 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2815 gtk_entry_realize (GtkWidget *widget)
2818 GtkEntryPrivate *priv;
2819 EntryIconInfo *icon_info;
2821 GdkWindowAttr attributes;
2822 gint attributes_mask;
2823 gint frame_x, frame_y;
2826 gtk_widget_set_realized (widget, TRUE);
2827 window = gtk_widget_get_parent_window (widget);
2828 gtk_widget_set_window (widget, window);
2829 g_object_ref (window);
2831 entry = GTK_ENTRY (widget);
2834 attributes.window_type = GDK_WINDOW_CHILD;
2835 attributes.wclass = GDK_INPUT_ONLY;
2836 attributes.event_mask = gtk_widget_get_events (widget);
2837 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2838 GDK_BUTTON_RELEASE_MASK |
2839 GDK_BUTTON1_MOTION_MASK |
2840 GDK_BUTTON3_MOTION_MASK |
2841 GDK_POINTER_MOTION_HINT_MASK |
2842 GDK_POINTER_MOTION_MASK |
2843 GDK_ENTER_NOTIFY_MASK |
2844 GDK_LEAVE_NOTIFY_MASK);
2845 attributes_mask = GDK_WA_X | GDK_WA_Y;
2847 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2849 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2850 attributes.x += frame_x;
2851 attributes.y += frame_y;
2853 if (gtk_widget_is_sensitive (widget))
2855 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2856 attributes_mask |= GDK_WA_CURSOR;
2859 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2863 gdk_window_set_user_data (priv->text_area, entry);
2865 if (attributes_mask & GDK_WA_CURSOR)
2866 g_object_unref (attributes.cursor);
2868 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2870 gtk_entry_adjust_scroll (entry);
2871 gtk_entry_update_primary_selection (entry);
2874 /* If the icon positions are already setup, create their windows.
2875 * Otherwise if they don't exist yet, then construct_icon_info()
2876 * will create the windows once the widget is already realized.
2878 for (i = 0; i < MAX_ICONS; i++)
2880 if ((icon_info = priv->icons[i]) != NULL)
2882 if (icon_info->window == NULL)
2883 realize_icon_info (widget, i);
2889 gtk_entry_unrealize (GtkWidget *widget)
2891 GtkEntry *entry = GTK_ENTRY (widget);
2892 GtkEntryPrivate *priv = entry->priv;
2893 GtkClipboard *clipboard;
2894 EntryIconInfo *icon_info;
2897 gtk_entry_reset_layout (entry);
2899 gtk_im_context_set_client_window (priv->im_context, NULL);
2901 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2902 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2903 gtk_clipboard_clear (clipboard);
2905 if (priv->text_area)
2907 gdk_window_set_user_data (priv->text_area, NULL);
2908 gdk_window_destroy (priv->text_area);
2909 priv->text_area = NULL;
2912 if (priv->popup_menu)
2914 gtk_widget_destroy (priv->popup_menu);
2915 priv->popup_menu = NULL;
2918 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2920 for (i = 0; i < MAX_ICONS; i++)
2922 if ((icon_info = priv->icons[i]) != NULL)
2924 if (icon_info->window != NULL)
2926 gdk_window_destroy (icon_info->window);
2927 icon_info->window = NULL;
2934 _gtk_entry_get_borders (GtkEntry *entry,
2938 GtkEntryPrivate *priv = entry->priv;
2939 GtkWidget *widget = GTK_WIDGET (entry);
2941 if (priv->has_frame)
2943 GtkStyleContext *context;
2946 context = gtk_widget_get_style_context (widget);
2947 gtk_style_context_get_padding (context, 0, &padding);
2949 *xborder = padding.left;
2950 *yborder = padding.top;
2958 if (!priv->interior_focus)
2960 *xborder += priv->focus_width;
2961 *yborder += priv->focus_width;
2966 gtk_entry_get_preferred_width (GtkWidget *widget,
2970 GtkEntry *entry = GTK_ENTRY (widget);
2971 GtkEntryPrivate *priv = entry->priv;
2972 PangoFontMetrics *metrics;
2973 gint xborder, yborder;
2974 GtkBorder inner_border;
2975 PangoContext *context;
2976 GtkStyleContext *style_context;
2977 GtkStateFlags state;
2978 gint icon_widths = 0;
2982 context = gtk_widget_get_pango_context (widget);
2984 style_context = gtk_widget_get_style_context (widget);
2985 state = gtk_widget_get_state_flags (widget);
2987 metrics = pango_context_get_metrics (context,
2988 gtk_style_context_get_font (style_context, state),
2989 pango_context_get_language (context));
2991 _gtk_entry_get_borders (entry, &xborder, &yborder);
2992 _gtk_entry_effective_inner_border (entry, &inner_border);
2994 if (priv->width_chars < 0)
2995 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2998 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2999 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3000 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3002 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3005 for (i = 0; i < MAX_ICONS; i++)
3007 icon_width = get_icon_width (entry, i);
3009 icon_widths += icon_width + 2 * priv->icon_margin;
3012 if (icon_widths > width)
3013 width += icon_widths;
3015 pango_font_metrics_unref (metrics);
3022 gtk_entry_get_preferred_height (GtkWidget *widget,
3026 GtkEntry *entry = GTK_ENTRY (widget);
3027 GtkEntryPrivate *priv = entry->priv;
3028 PangoFontMetrics *metrics;
3029 gint xborder, yborder;
3030 GtkBorder inner_border;
3031 GtkStyleContext *style_context;
3032 GtkStateFlags state;
3033 PangoContext *context;
3036 context = gtk_widget_get_pango_context (widget);
3038 style_context = gtk_widget_get_style_context (widget);
3039 state = gtk_widget_get_state_flags (widget);
3041 metrics = pango_context_get_metrics (context,
3042 gtk_style_context_get_font (style_context, state),
3043 pango_context_get_language (context));
3045 priv->ascent = pango_font_metrics_get_ascent (metrics);
3046 priv->descent = pango_font_metrics_get_descent (metrics);
3048 _gtk_entry_get_borders (entry, &xborder, &yborder);
3049 _gtk_entry_effective_inner_border (entry, &inner_border);
3051 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3053 pango_font_metrics_unref (metrics);
3060 place_windows (GtkEntry *entry)
3062 GtkWidget *widget = GTK_WIDGET (entry);
3063 GtkEntryPrivate *priv = entry->priv;
3064 gint x, y, width, height;
3065 gint frame_x, frame_y;
3066 GtkAllocation primary;
3067 GtkAllocation secondary;
3068 EntryIconInfo *icon_info = NULL;
3070 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
3071 get_text_area_size (entry, &x, &y, &width, &height);
3072 get_icon_allocations (entry, &primary, &secondary);
3074 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3075 y += priv->focus_width;
3077 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3078 x += secondary.width;
3081 width -= primary.width + secondary.width;
3085 primary.x += frame_x;
3086 primary.y += frame_y;
3087 secondary.x += frame_x;
3088 secondary.y += frame_y;
3090 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3091 gdk_window_move_resize (icon_info->window,
3092 primary.x, primary.y,
3093 primary.width, primary.height);
3095 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3096 gdk_window_move_resize (icon_info->window,
3097 secondary.x, secondary.y,
3098 secondary.width, secondary.height);
3100 gdk_window_move_resize (priv->text_area, x, y, width, height);
3104 gtk_entry_get_text_area_size (GtkEntry *entry,
3110 GtkEntryPrivate *priv = entry->priv;
3111 GtkWidget *widget = GTK_WIDGET (entry);
3112 GtkAllocation allocation;
3113 GtkRequisition requisition;
3115 gint xborder, yborder;
3117 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3118 gtk_widget_get_allocation (widget, &allocation);
3119 _gtk_entry_get_borders (entry, &xborder, &yborder);
3121 if (gtk_widget_get_realized (widget))
3122 get_frame_size (entry, NULL, NULL, NULL, &frame_height);
3124 frame_height = requisition.height;
3126 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3127 frame_height -= 2 * priv->focus_width;
3133 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3136 *width = allocation.width - xborder * 2;
3139 *height = requisition.height - yborder * 2;
3143 get_text_area_size (GtkEntry *entry,
3149 GtkEntryClass *class;
3151 g_return_if_fail (GTK_IS_ENTRY (entry));
3153 class = GTK_ENTRY_GET_CLASS (entry);
3155 if (class->get_text_area_size)
3156 class->get_text_area_size (entry, x, y, width, height);
3161 get_frame_size (GtkEntry *entry,
3167 GtkEntryPrivate *priv = entry->priv;
3168 GtkAllocation allocation;
3169 GtkRequisition requisition;
3170 GtkWidget *widget = GTK_WIDGET (entry);
3172 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3173 gtk_widget_get_allocation (widget, &allocation);
3180 if (priv->is_cell_renderer)
3183 *y = allocation.y + (allocation.height - requisition.height) / 2;
3187 *width = allocation.width;
3191 if (priv->is_cell_renderer)
3192 *height = allocation.height;
3194 *height = requisition.height;
3199 _gtk_entry_effective_inner_border (GtkEntry *entry,
3202 GtkBorder *tmp_border;
3204 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3208 *border = *tmp_border;
3212 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3216 *border = *tmp_border;
3217 gtk_border_free (tmp_border);
3221 *border = default_inner_border;
3225 gtk_entry_size_allocate (GtkWidget *widget,
3226 GtkAllocation *allocation)
3228 GtkEntry *entry = GTK_ENTRY (widget);
3230 gtk_widget_set_allocation (widget, allocation);
3232 if (gtk_widget_get_realized (widget))
3234 GtkEntryCompletion* completion;
3236 place_windows (entry);
3237 gtk_entry_recompute (entry);
3239 completion = gtk_entry_get_completion (entry);
3240 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3241 _gtk_entry_completion_resize_popup (completion);
3246 should_prelight (GtkEntry *entry,
3247 GtkEntryIconPosition icon_pos)
3249 GtkEntryPrivate *priv = entry->priv;
3250 EntryIconInfo *icon_info = priv->icons[icon_pos];
3256 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3259 if (icon_info->pressed)
3262 gtk_widget_style_get (GTK_WIDGET (entry),
3263 "icon-prelight", &prelight,
3270 draw_icon (GtkWidget *widget,
3272 GtkEntryIconPosition icon_pos)
3274 GtkEntry *entry = GTK_ENTRY (widget);
3275 GtkEntryPrivate *priv = entry->priv;
3276 EntryIconInfo *icon_info = priv->icons[icon_pos];
3278 gint x, y, width, height;
3279 GtkStyleContext *context;
3280 GtkIconSource *icon_source;
3281 GtkStateFlags state;
3286 gtk_entry_ensure_pixbuf (entry, icon_pos);
3288 if (icon_info->pixbuf == NULL)
3291 width = gdk_window_get_width (icon_info->window);
3292 height = gdk_window_get_height (icon_info->window);
3294 /* size_allocate hasn't been called yet. These are the default values.
3296 if (width == 1 || height == 1)
3299 pixbuf = icon_info->pixbuf;
3300 g_object_ref (pixbuf);
3302 if (gdk_pixbuf_get_height (pixbuf) > height)
3304 GdkPixbuf *temp_pixbuf;
3307 scale = height - 2 * priv->icon_margin;
3308 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3309 GDK_INTERP_BILINEAR);
3310 g_object_unref (pixbuf);
3311 pixbuf = temp_pixbuf;
3314 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3315 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3317 icon_source = gtk_icon_source_new ();
3318 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
3319 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
3322 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
3323 state |= GTK_STATE_FLAG_INSENSITIVE;
3324 else if (icon_info->prelight)
3325 state |= GTK_STATE_FLAG_PRELIGHT;
3327 context = gtk_widget_get_style_context (widget);
3328 gtk_style_context_save (context);
3329 gtk_style_context_set_state (context, state);
3330 pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
3331 gtk_style_context_restore (context);
3333 gtk_icon_source_free (icon_source);
3335 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3338 g_object_unref (pixbuf);
3343 gtk_entry_draw_frame (GtkWidget *widget,
3344 GtkStyleContext *context,
3347 GtkEntry *entry = GTK_ENTRY (widget);
3348 GtkEntryPrivate *priv = entry->priv;
3349 gint x = 0, y = 0, width, height;
3350 GtkAllocation allocation;
3351 gint frame_x, frame_y;
3355 get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
3356 gtk_widget_get_allocation (widget, &allocation);
3358 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3360 /* Fix a problem with some themes which assume that entry->text_area's
3361 * width equals widget->window's width
3362 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3363 if (GTK_IS_SPIN_BUTTON (widget))
3365 gint xborder, yborder;
3367 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3368 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3371 width += xborder * 2;
3374 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3376 x += priv->focus_width;
3377 y += priv->focus_width;
3378 width -= 2 * priv->focus_width;
3379 height -= 2 * priv->focus_width;
3382 gtk_render_background (context, cr,
3383 x, y, width, height);
3385 if (priv->has_frame)
3386 gtk_render_frame (context, cr,
3387 x, y, width, height);
3389 gtk_entry_draw_progress (widget, context, cr);
3391 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3393 x -= priv->focus_width;
3394 y -= priv->focus_width;
3395 width += 2 * priv->focus_width;
3396 height += 2 * priv->focus_width;
3398 gtk_render_focus (context, cr,
3399 0, 0, width, height);
3406 get_progress_area (GtkWidget *widget,
3412 GtkEntry *entry = GTK_ENTRY (widget);
3413 GtkEntryPrivate *private = entry->priv;
3414 GtkBorder *progress_border;
3416 get_text_area_size (entry, x, y, width, height);
3418 if (!private->interior_focus)
3420 *x -= private->focus_width;
3421 *y -= private->focus_width;
3422 *width += 2 * private->focus_width;
3423 *height += 2 * private->focus_width;
3426 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3428 if (progress_border)
3430 *x += progress_border->left;
3431 *y += progress_border->top;
3432 *width -= progress_border->left + progress_border->right;
3433 *height -= progress_border->top + progress_border->bottom;
3435 gtk_border_free (progress_border);
3438 if (private->progress_pulse_mode)
3440 gdouble value = private->progress_pulse_current;
3442 *x += (gint) floor(value * (*width));
3443 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3445 else if (private->progress_fraction > 0)
3447 gdouble value = private->progress_fraction;
3449 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3453 bar_width = floor(value * (*width) + 0.5);
3454 *x += *width - bar_width;
3459 *width = (gint) floor(value * (*width) + 0.5);
3470 gtk_entry_draw_progress (GtkWidget *widget,
3471 GtkStyleContext *context,
3474 gint x, y, width, height;
3476 get_progress_area (widget, &x, &y, &width, &height);
3478 if ((width <= 0) || (height <= 0))
3481 gtk_style_context_save (context);
3482 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3484 gtk_render_activity (context, cr,
3485 x, y, width, height);
3487 gtk_style_context_restore (context);
3491 gtk_entry_draw (GtkWidget *widget,
3494 GtkEntry *entry = GTK_ENTRY (widget);
3495 GtkStyleContext *context;
3496 GtkStateFlags state;
3497 GtkEntryPrivate *priv = entry->priv;
3500 context = gtk_widget_get_style_context (widget);
3501 state = gtk_widget_get_state_flags (widget);
3503 gtk_style_context_save (context);
3504 gtk_style_context_set_state (context, state);
3506 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3508 /* Draw entry_bg, shadow, progress and focus */
3509 gtk_entry_draw_frame (widget, context, cr);
3511 /* Draw text and cursor */
3514 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3516 if (priv->dnd_position != -1)
3517 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3519 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3521 /* When no text is being displayed at all, don't show the cursor */
3522 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3523 gtk_widget_has_focus (widget) &&
3524 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3525 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3530 for (i = 0; i < MAX_ICONS; i++)
3532 EntryIconInfo *icon_info = priv->icons[i];
3534 if (icon_info != NULL)
3538 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3540 draw_icon (widget, cr, i);
3547 gtk_style_context_restore (context);
3553 gtk_entry_enter_notify (GtkWidget *widget,
3554 GdkEventCrossing *event)
3556 GtkEntry *entry = GTK_ENTRY (widget);
3557 GtkEntryPrivate *priv = entry->priv;
3560 for (i = 0; i < MAX_ICONS; i++)
3562 EntryIconInfo *icon_info = priv->icons[i];
3564 if (icon_info != NULL && event->window == icon_info->window)
3566 if (should_prelight (entry, i))
3568 icon_info->prelight = TRUE;
3569 gtk_widget_queue_draw (widget);
3580 gtk_entry_leave_notify (GtkWidget *widget,
3581 GdkEventCrossing *event)
3583 GtkEntry *entry = GTK_ENTRY (widget);
3584 GtkEntryPrivate *priv = entry->priv;
3587 for (i = 0; i < MAX_ICONS; i++)
3589 EntryIconInfo *icon_info = priv->icons[i];
3591 if (icon_info != NULL && event->window == icon_info->window)
3593 /* a grab means that we may never see the button release */
3594 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3595 icon_info->pressed = FALSE;
3597 if (should_prelight (entry, i))
3599 icon_info->prelight = FALSE;
3600 gtk_widget_queue_draw (widget);
3611 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3615 gint start_char, end_char;
3617 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3619 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3620 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3621 const char *text = pango_layout_get_text (layout);
3622 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3623 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3624 gint real_n_ranges, i;
3626 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3632 for (i = 0; i < real_n_ranges; ++i)
3634 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3635 r[2 * i] = r[2 * i] / PANGO_SCALE;
3640 *n_ranges = real_n_ranges;
3652 in_selection (GtkEntry *entry,
3657 gint retval = FALSE;
3659 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3661 for (i = 0; i < n_ranges; ++i)
3663 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3675 gtk_entry_button_press (GtkWidget *widget,
3676 GdkEventButton *event)
3678 GtkEntry *entry = GTK_ENTRY (widget);
3679 GtkEditable *editable = GTK_EDITABLE (widget);
3680 GtkEntryPrivate *priv = entry->priv;
3681 EntryIconInfo *icon_info = NULL;
3683 gint sel_start, sel_end;
3686 for (i = 0; i < MAX_ICONS; i++)
3688 icon_info = priv->icons[i];
3690 if (!icon_info || icon_info->insensitive)
3693 if (event->window == icon_info->window)
3695 if (should_prelight (entry, i))
3697 icon_info->prelight = FALSE;
3698 gtk_widget_queue_draw (widget);
3701 priv->start_x = event->x;
3702 priv->start_y = event->y;
3703 icon_info->pressed = TRUE;
3705 if (!icon_info->nonactivatable)
3706 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3712 if (event->window != priv->text_area ||
3713 (priv->button && event->button != priv->button))
3716 gtk_entry_reset_blink_time (entry);
3718 priv->button = event->button;
3720 if (!gtk_widget_has_focus (widget))
3722 priv->in_click = TRUE;
3723 gtk_widget_grab_focus (widget);
3724 priv->in_click = FALSE;
3727 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3729 if (event->button == 1)
3731 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3733 priv->select_words = FALSE;
3734 priv->select_lines = FALSE;
3736 if (event->state & GDK_SHIFT_MASK)
3738 _gtk_entry_reset_im_context (entry);
3740 if (!have_selection) /* select from the current position to the clicked position */
3741 sel_start = sel_end = priv->current_pos;
3743 if (tmp_pos > sel_start && tmp_pos < sel_end)
3745 /* Truncate current selection, but keep it as big as possible */
3746 if (tmp_pos - sel_start > sel_end - tmp_pos)
3747 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3749 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3753 gboolean extend_to_left;
3756 /* Figure out what click selects and extend current selection */
3757 switch (event->type)
3759 case GDK_BUTTON_PRESS:
3760 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3763 case GDK_2BUTTON_PRESS:
3764 priv->select_words = TRUE;
3765 gtk_entry_select_word (entry);
3768 case GDK_3BUTTON_PRESS:
3769 priv->select_lines = TRUE;
3770 gtk_entry_select_line (entry);
3777 start = MIN (priv->current_pos, priv->selection_bound);
3778 start = MIN (sel_start, start);
3780 end = MAX (priv->current_pos, priv->selection_bound);
3781 end = MAX (sel_end, end);
3783 if (tmp_pos == sel_start || tmp_pos == sel_end)
3784 extend_to_left = (tmp_pos == start);
3786 extend_to_left = (end == sel_end);
3789 gtk_entry_set_positions (entry, start, end);
3791 gtk_entry_set_positions (entry, end, start);
3794 else /* no shift key */
3795 switch (event->type)
3797 case GDK_BUTTON_PRESS:
3798 if (in_selection (entry, event->x + priv->scroll_offset))
3800 /* Click inside the selection - we'll either start a drag, or
3801 * clear the selection
3803 priv->in_drag = TRUE;
3804 priv->drag_start_x = event->x + priv->scroll_offset;
3805 priv->drag_start_y = event->y;
3808 gtk_editable_set_position (editable, tmp_pos);
3811 case GDK_2BUTTON_PRESS:
3812 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3813 * receiving a GDK_2BUTTON_PRESS so we need to reset
3814 * priv->in_drag which may have been set above
3816 priv->in_drag = FALSE;
3817 priv->select_words = TRUE;
3818 gtk_entry_select_word (entry);
3821 case GDK_3BUTTON_PRESS:
3822 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3823 * receiving a GDK_3BUTTON_PRESS so we need to reset
3824 * priv->in_drag which may have been set above
3826 priv->in_drag = FALSE;
3827 priv->select_lines = TRUE;
3828 gtk_entry_select_line (entry);
3837 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3841 priv->insert_pos = tmp_pos;
3842 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3847 gtk_widget_error_bell (widget);
3850 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3852 gtk_entry_do_popup (entry, event);
3853 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3862 gtk_entry_button_release (GtkWidget *widget,
3863 GdkEventButton *event)
3865 GtkEntry *entry = GTK_ENTRY (widget);
3866 GtkEntryPrivate *priv = entry->priv;
3867 EntryIconInfo *icon_info = NULL;
3870 for (i = 0; i < MAX_ICONS; i++)
3872 icon_info = priv->icons[i];
3874 if (!icon_info || icon_info->insensitive)
3877 if (event->window == icon_info->window)
3879 icon_info->pressed = FALSE;
3881 if (should_prelight (entry, i) &&
3882 event->x >= 0 && event->y >= 0 &&
3883 event->x < gdk_window_get_width (icon_info->window) &&
3884 event->y < gdk_window_get_height (icon_info->window))
3886 icon_info->prelight = TRUE;
3887 gtk_widget_queue_draw (widget);
3890 if (!icon_info->nonactivatable)
3891 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3897 if (event->window != priv->text_area || priv->button != event->button)
3902 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3904 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3911 gtk_entry_update_primary_selection (entry);
3917 _gtk_entry_get_selected_text (GtkEntry *entry)
3919 GtkEditable *editable = GTK_EDITABLE (entry);
3920 gint start_text, end_text;
3923 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3924 text = gtk_editable_get_chars (editable, start_text, end_text);
3930 gtk_entry_motion_notify (GtkWidget *widget,
3931 GdkEventMotion *event)
3933 GtkEntry *entry = GTK_ENTRY (widget);
3934 GtkEntryPrivate *priv = entry->priv;
3935 EntryIconInfo *icon_info = NULL;
3939 for (i = 0; i < MAX_ICONS; i++)
3941 icon_info = priv->icons[i];
3943 if (!icon_info || icon_info->insensitive)
3946 if (event->window == icon_info->window)
3948 if (icon_info->pressed &&
3949 icon_info->target_list != NULL &&
3950 gtk_drag_check_threshold (widget,
3956 icon_info->in_drag = TRUE;
3957 icon_info->pressed = FALSE;
3958 gtk_drag_begin (widget,
3959 icon_info->target_list,
3969 if (priv->mouse_cursor_obscured)
3973 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3974 gdk_window_set_cursor (priv->text_area, cursor);
3975 g_object_unref (cursor);
3976 priv->mouse_cursor_obscured = FALSE;
3979 if (event->window != priv->text_area || priv->button != 1)
3982 if (priv->select_lines)
3985 gdk_event_request_motions (event);
3989 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3990 gtk_drag_check_threshold (widget,
3991 priv->drag_start_x, priv->drag_start_y,
3992 event->x + priv->scroll_offset, event->y))
3994 GdkDragContext *context;
3995 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3996 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3998 cairo_surface_t *surface;
4000 gtk_target_list_add_text_targets (target_list, 0);
4002 text = _gtk_entry_get_selected_text (entry);
4003 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4005 context = gtk_drag_begin (widget, target_list, actions,
4006 priv->button, (GdkEvent *)event);
4009 gtk_drag_set_icon_surface (context, surface);
4011 gtk_drag_set_icon_default (context);
4014 cairo_surface_destroy (surface);
4017 priv->in_drag = FALSE;
4020 gtk_target_list_unref (target_list);
4027 else if (event->y >= gdk_window_get_height (priv->text_area))
4028 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4030 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4032 if (priv->select_words)
4035 gint old_min, old_max;
4038 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4039 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4041 pos = priv->current_pos;
4042 bound = priv->selection_bound;
4044 old_min = MIN(priv->current_pos, priv->selection_bound);
4045 old_max = MAX(priv->current_pos, priv->selection_bound);
4052 else if (old_max < max)
4057 else if (pos == old_min)
4059 if (priv->current_pos != min)
4064 if (priv->current_pos != max)
4068 gtk_entry_set_positions (entry, pos, bound);
4071 gtk_entry_set_positions (entry, tmp_pos, -1);
4078 set_invisible_cursor (GdkWindow *window)
4080 GdkDisplay *display;
4083 display = gdk_window_get_display (window);
4084 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4086 gdk_window_set_cursor (window, cursor);
4088 g_object_unref (cursor);
4092 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4094 GtkEntryPrivate *priv = entry->priv;
4096 if (priv->mouse_cursor_obscured)
4099 set_invisible_cursor (priv->text_area);
4101 priv->mouse_cursor_obscured = TRUE;
4105 gtk_entry_key_press (GtkWidget *widget,
4108 GtkEntry *entry = GTK_ENTRY (widget);
4109 GtkEntryPrivate *priv = entry->priv;
4111 gtk_entry_reset_blink_time (entry);
4112 gtk_entry_pend_cursor_blink (entry);
4116 if (gtk_im_context_filter_keypress (priv->im_context, event))
4118 gtk_entry_obscure_mouse_cursor (entry);
4119 priv->need_im_reset = TRUE;
4124 if (event->keyval == GDK_KEY_Return ||
4125 event->keyval == GDK_KEY_KP_Enter ||
4126 event->keyval == GDK_KEY_ISO_Enter ||
4127 event->keyval == GDK_KEY_Escape)
4129 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4131 if (completion && completion->priv->completion_timeout)
4133 g_source_remove (completion->priv->completion_timeout);
4134 completion->priv->completion_timeout = 0;
4137 _gtk_entry_reset_im_context (entry);
4140 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4141 /* Activate key bindings
4145 if (!priv->editable && event->length)
4146 gtk_widget_error_bell (widget);
4152 gtk_entry_key_release (GtkWidget *widget,
4155 GtkEntry *entry = GTK_ENTRY (widget);
4156 GtkEntryPrivate *priv = entry->priv;
4160 if (gtk_im_context_filter_keypress (priv->im_context, event))
4162 priv->need_im_reset = TRUE;
4167 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4171 gtk_entry_focus_in (GtkWidget *widget,
4172 GdkEventFocus *event)
4174 GtkEntry *entry = GTK_ENTRY (widget);
4175 GtkEntryPrivate *priv = entry->priv;
4178 gtk_widget_queue_draw (widget);
4180 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4184 priv->need_im_reset = TRUE;
4185 gtk_im_context_focus_in (priv->im_context);
4186 keymap_state_changed (keymap, entry);
4187 g_signal_connect (keymap, "state-changed",
4188 G_CALLBACK (keymap_state_changed), entry);
4191 g_signal_connect (keymap, "direction-changed",
4192 G_CALLBACK (keymap_direction_changed), entry);
4194 gtk_entry_reset_blink_time (entry);
4195 gtk_entry_check_cursor_blink (entry);
4201 gtk_entry_focus_out (GtkWidget *widget,
4202 GdkEventFocus *event)
4204 GtkEntry *entry = GTK_ENTRY (widget);
4205 GtkEntryPrivate *priv = entry->priv;
4206 GtkEntryCompletion *completion;
4209 gtk_widget_queue_draw (widget);
4211 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4215 priv->need_im_reset = TRUE;
4216 gtk_im_context_focus_out (priv->im_context);
4217 remove_capslock_feedback (entry);
4220 gtk_entry_check_cursor_blink (entry);
4222 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4223 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4225 completion = gtk_entry_get_completion (entry);
4227 _gtk_entry_completion_popdown (completion);
4233 gtk_entry_grab_focus (GtkWidget *widget)
4235 GtkEntry *entry = GTK_ENTRY (widget);
4236 GtkEntryPrivate *priv = entry->priv;
4237 gboolean select_on_focus;
4239 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4241 if (priv->editable && !priv->in_click)
4243 g_object_get (gtk_widget_get_settings (widget),
4244 "gtk-entry-select-on-focus",
4248 if (select_on_focus)
4249 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4254 gtk_entry_direction_changed (GtkWidget *widget,
4255 GtkTextDirection previous_dir)
4257 GtkEntry *entry = GTK_ENTRY (widget);
4259 gtk_entry_recompute (entry);
4261 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4265 gtk_entry_state_flags_changed (GtkWidget *widget,
4266 GtkStateFlags previous_state)
4268 GtkEntry *entry = GTK_ENTRY (widget);
4269 GtkEntryPrivate *priv = entry->priv;
4272 if (gtk_widget_get_realized (widget))
4274 if (gtk_widget_is_sensitive (widget))
4275 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4279 gdk_window_set_cursor (priv->text_area, cursor);
4282 g_object_unref (cursor);
4284 priv->mouse_cursor_obscured = FALSE;
4286 update_cursors (widget);
4289 if (!gtk_widget_is_sensitive (widget))
4291 /* Clear any selection */
4292 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4295 gtk_widget_queue_draw (widget);
4299 gtk_entry_screen_changed (GtkWidget *widget,
4300 GdkScreen *old_screen)
4302 gtk_entry_recompute (GTK_ENTRY (widget));
4305 /* GtkEditable method implementations
4308 gtk_entry_insert_text (GtkEditable *editable,
4309 const gchar *new_text,
4310 gint new_text_length,
4313 g_object_ref (editable);
4316 * The incoming text may a password or other secret. We make sure
4317 * not to copy it into temporary buffers.
4320 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4322 g_object_unref (editable);
4326 gtk_entry_delete_text (GtkEditable *editable,
4330 g_object_ref (editable);
4332 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4334 g_object_unref (editable);
4338 gtk_entry_get_chars (GtkEditable *editable,
4342 GtkEntry *entry = GTK_ENTRY (editable);
4345 gint start_index, end_index;
4347 text = gtk_entry_buffer_get_text (get_buffer (entry));
4348 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4351 end_pos = text_length;
4353 start_pos = MIN (text_length, start_pos);
4354 end_pos = MIN (text_length, end_pos);
4356 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4357 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4359 return g_strndup (text + start_index, end_index - start_index);
4363 gtk_entry_real_set_position (GtkEditable *editable,
4366 GtkEntry *entry = GTK_ENTRY (editable);
4367 GtkEntryPrivate *priv = entry->priv;
4371 length = gtk_entry_buffer_get_length (get_buffer (entry));
4372 if (position < 0 || position > length)
4375 if (position != priv->current_pos ||
4376 position != priv->selection_bound)
4378 _gtk_entry_reset_im_context (entry);
4379 gtk_entry_set_positions (entry, position, position);
4384 gtk_entry_get_position (GtkEditable *editable)
4386 GtkEntry *entry = GTK_ENTRY (editable);
4387 GtkEntryPrivate *priv = entry->priv;
4389 return priv->current_pos;
4393 gtk_entry_set_selection_bounds (GtkEditable *editable,
4397 GtkEntry *entry = GTK_ENTRY (editable);
4400 length = gtk_entry_buffer_get_length (get_buffer (entry));
4406 _gtk_entry_reset_im_context (entry);
4408 gtk_entry_set_positions (entry,
4410 MIN (start, length));
4412 gtk_entry_update_primary_selection (entry);
4416 gtk_entry_get_selection_bounds (GtkEditable *editable,
4420 GtkEntry *entry = GTK_ENTRY (editable);
4421 GtkEntryPrivate *priv = entry->priv;
4423 *start = priv->selection_bound;
4424 *end = priv->current_pos;
4426 return (priv->selection_bound != priv->current_pos);
4430 icon_theme_changed (GtkEntry *entry)
4432 GtkEntryPrivate *priv = entry->priv;
4435 for (i = 0; i < MAX_ICONS; i++)
4437 EntryIconInfo *icon_info = priv->icons[i];
4438 if (icon_info != NULL)
4440 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4441 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4442 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4443 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4444 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4445 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4449 gtk_widget_queue_draw (GTK_WIDGET (entry));
4453 icon_margin_changed (GtkEntry *entry)
4455 GtkEntryPrivate *priv = entry->priv;
4458 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4460 priv->icon_margin = border.left;
4464 gtk_entry_style_updated (GtkWidget *widget)
4466 GtkEntry *entry = GTK_ENTRY (widget);
4467 GtkEntryPrivate *priv = entry->priv;
4469 gboolean interior_focus;
4471 gtk_widget_style_get (widget,
4472 "focus-line-width", &focus_width,
4473 "interior-focus", &interior_focus,
4476 priv->focus_width = focus_width;
4477 priv->interior_focus = interior_focus;
4479 if (!priv->invisible_char_set)
4480 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4482 gtk_entry_recompute (entry);
4484 icon_theme_changed (entry);
4485 icon_margin_changed (entry);
4488 /* GtkCellEditable method implementations
4491 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4493 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4494 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4498 gtk_cell_editable_key_press_event (GtkEntry *entry,
4499 GdkEventKey *key_event,
4502 GtkEntryPrivate *priv = entry->priv;
4504 if (key_event->keyval == GDK_KEY_Escape)
4506 priv->editing_canceled = TRUE;
4507 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4508 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4513 /* override focus */
4514 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4516 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4517 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4526 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4529 GtkEntry *entry = GTK_ENTRY (cell_editable);
4530 GtkEntryPrivate *priv = entry->priv;
4532 priv->is_cell_renderer = TRUE;
4534 g_signal_connect (cell_editable, "activate",
4535 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4536 g_signal_connect (cell_editable, "key-press-event",
4537 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4541 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4543 if (password_hint->source_id)
4544 g_source_remove (password_hint->source_id);
4546 g_slice_free (GtkEntryPasswordHint, password_hint);
4551 gtk_entry_remove_password_hint (gpointer data)
4553 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4554 password_hint->position = -1;
4556 /* Force the string to be redrawn, but now without a visible character */
4557 gtk_entry_recompute (GTK_ENTRY (data));
4561 /* Default signal handlers
4564 gtk_entry_real_insert_text (GtkEditable *editable,
4565 const gchar *new_text,
4566 gint new_text_length,
4572 n_chars = g_utf8_strlen (new_text, new_text_length);
4575 * The actual insertion into the buffer. This will end up firing the
4576 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4577 * buffer_notify_text(), buffer_notify_length()
4579 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4581 if (n_inserted != n_chars)
4582 gtk_widget_error_bell (GTK_WIDGET (editable));
4584 *position += n_inserted;
4588 gtk_entry_real_delete_text (GtkEditable *editable,
4593 * The actual deletion from the buffer. This will end up firing the
4594 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4595 * buffer_notify_text(), buffer_notify_length()
4598 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4601 /* GtkEntryBuffer signal handlers
4604 buffer_inserted_text (GtkEntryBuffer *buffer,
4610 GtkEntryPrivate *priv = entry->priv;
4611 guint password_hint_timeout;
4613 if (priv->current_pos > position)
4614 priv->current_pos += n_chars;
4616 if (priv->selection_bound > position)
4617 priv->selection_bound += n_chars;
4619 /* Calculate the password hint if it needs to be displayed. */
4620 if (n_chars == 1 && !priv->visible)
4622 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4623 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4626 if (password_hint_timeout > 0)
4628 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4629 quark_password_hint);
4632 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4633 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4634 (GDestroyNotify)gtk_entry_password_hint_free);
4637 password_hint->position = position;
4638 if (password_hint->source_id)
4639 g_source_remove (password_hint->source_id);
4640 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4641 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4647 buffer_deleted_text (GtkEntryBuffer *buffer,
4652 GtkEntryPrivate *priv = entry->priv;
4653 guint end_pos = position + n_chars;
4654 gint selection_bound;
4657 current_pos = priv->current_pos;
4658 if (current_pos > position)
4659 current_pos -= MIN (current_pos, end_pos) - position;
4661 selection_bound = priv->selection_bound;
4662 if (selection_bound > position)
4663 selection_bound -= MIN (selection_bound, end_pos) - position;
4665 gtk_entry_set_positions (entry, current_pos, selection_bound);
4667 /* We might have deleted the selection */
4668 gtk_entry_update_primary_selection (entry);
4670 /* Disable the password hint if one exists. */
4673 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4674 quark_password_hint);
4677 if (password_hint->source_id)
4678 g_source_remove (password_hint->source_id);
4679 password_hint->source_id = 0;
4680 password_hint->position = -1;
4686 buffer_notify_text (GtkEntryBuffer *buffer,
4690 gtk_entry_recompute (entry);
4691 emit_changed (entry);
4692 g_object_notify (G_OBJECT (entry), "text");
4696 buffer_notify_length (GtkEntryBuffer *buffer,
4700 g_object_notify (G_OBJECT (entry), "text-length");
4704 buffer_notify_max_length (GtkEntryBuffer *buffer,
4708 g_object_notify (G_OBJECT (entry), "max-length");
4712 buffer_connect_signals (GtkEntry *entry)
4714 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4715 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4716 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4717 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4718 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4722 buffer_disconnect_signals (GtkEntry *entry)
4724 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4725 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4726 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4727 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4728 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4731 /* Compute the X position for an offset that corresponds to the "more important
4732 * cursor position for that offset. We use this when trying to guess to which
4733 * end of the selection we should go to when the user hits the left or
4737 get_better_cursor_x (GtkEntry *entry,
4740 GtkEntryPrivate *priv = entry->priv;
4741 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4742 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4743 gboolean split_cursor;
4745 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4746 const gchar *text = pango_layout_get_text (layout);
4747 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4749 PangoRectangle strong_pos, weak_pos;
4751 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4752 "gtk-split-cursor", &split_cursor,
4755 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4758 return strong_pos.x / PANGO_SCALE;
4760 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4764 gtk_entry_move_cursor (GtkEntry *entry,
4765 GtkMovementStep step,
4767 gboolean extend_selection)
4769 GtkEntryPrivate *priv = entry->priv;
4770 gint new_pos = priv->current_pos;
4772 _gtk_entry_reset_im_context (entry);
4774 if (priv->current_pos != priv->selection_bound && !extend_selection)
4776 /* If we have a current selection and aren't extending it, move to the
4777 * start/or end of the selection as appropriate
4781 case GTK_MOVEMENT_VISUAL_POSITIONS:
4783 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4784 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4787 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4789 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4792 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4793 case GTK_MOVEMENT_WORDS:
4795 new_pos = MIN (priv->current_pos, priv->selection_bound);
4797 new_pos = MAX (priv->current_pos, priv->selection_bound);
4799 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4800 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4801 case GTK_MOVEMENT_BUFFER_ENDS:
4802 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4804 case GTK_MOVEMENT_DISPLAY_LINES:
4805 case GTK_MOVEMENT_PARAGRAPHS:
4806 case GTK_MOVEMENT_PAGES:
4807 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4815 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4816 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4818 case GTK_MOVEMENT_VISUAL_POSITIONS:
4819 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4820 if (priv->current_pos == new_pos)
4822 if (!extend_selection)
4824 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4826 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4828 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4831 gtk_widget_child_focus (toplevel,
4833 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4838 gtk_widget_error_bell (GTK_WIDGET (entry));
4842 case GTK_MOVEMENT_WORDS:
4845 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4850 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4853 if (priv->current_pos == new_pos)
4854 gtk_widget_error_bell (GTK_WIDGET (entry));
4856 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4857 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4858 case GTK_MOVEMENT_BUFFER_ENDS:
4859 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4860 if (priv->current_pos == new_pos)
4861 gtk_widget_error_bell (GTK_WIDGET (entry));
4863 case GTK_MOVEMENT_DISPLAY_LINES:
4864 case GTK_MOVEMENT_PARAGRAPHS:
4865 case GTK_MOVEMENT_PAGES:
4866 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4871 if (extend_selection)
4872 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4874 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4876 gtk_entry_pend_cursor_blink (entry);
4880 gtk_entry_insert_at_cursor (GtkEntry *entry,
4883 GtkEntryPrivate *priv = entry->priv;
4884 GtkEditable *editable = GTK_EDITABLE (entry);
4885 gint pos = priv->current_pos;
4889 _gtk_entry_reset_im_context (entry);
4891 gtk_editable_insert_text (editable, str, -1, &pos);
4892 gtk_editable_set_position (editable, pos);
4897 gtk_entry_delete_from_cursor (GtkEntry *entry,
4901 GtkEntryPrivate *priv = entry->priv;
4902 GtkEditable *editable = GTK_EDITABLE (entry);
4903 gint start_pos = priv->current_pos;
4904 gint end_pos = priv->current_pos;
4905 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4907 _gtk_entry_reset_im_context (entry);
4909 if (!priv->editable)
4911 gtk_widget_error_bell (GTK_WIDGET (entry));
4915 if (priv->selection_bound != priv->current_pos)
4917 gtk_editable_delete_selection (editable);
4923 case GTK_DELETE_CHARS:
4924 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
4925 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4927 case GTK_DELETE_WORDS:
4930 /* Move to end of current word, or if not on a word, end of previous word */
4931 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4932 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4936 /* Move to beginning of current word, or if not on a word, begining of next word */
4937 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4938 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4942 case GTK_DELETE_WORD_ENDS:
4945 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4950 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4953 gtk_editable_delete_text (editable, start_pos, end_pos);
4955 case GTK_DELETE_DISPLAY_LINE_ENDS:
4956 case GTK_DELETE_PARAGRAPH_ENDS:
4958 gtk_editable_delete_text (editable, 0, priv->current_pos);
4960 gtk_editable_delete_text (editable, priv->current_pos, -1);
4962 case GTK_DELETE_DISPLAY_LINES:
4963 case GTK_DELETE_PARAGRAPHS:
4964 gtk_editable_delete_text (editable, 0, -1);
4966 case GTK_DELETE_WHITESPACE:
4967 gtk_entry_delete_whitespace (entry);
4971 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4972 gtk_widget_error_bell (GTK_WIDGET (entry));
4974 gtk_entry_pend_cursor_blink (entry);
4978 gtk_entry_backspace (GtkEntry *entry)
4980 GtkEntryPrivate *priv = entry->priv;
4981 GtkEditable *editable = GTK_EDITABLE (entry);
4984 _gtk_entry_reset_im_context (entry);
4986 if (!priv->editable)
4988 gtk_widget_error_bell (GTK_WIDGET (entry));
4992 if (priv->selection_bound != priv->current_pos)
4994 gtk_editable_delete_selection (editable);
4998 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5000 if (prev_pos < priv->current_pos)
5002 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5003 PangoLogAttr *log_attrs;
5006 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5008 /* Deleting parts of characters */
5009 if (log_attrs[priv->current_pos].backspace_deletes_character)
5011 gchar *cluster_text;
5012 gchar *normalized_text;
5015 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5017 normalized_text = g_utf8_normalize (cluster_text,
5018 strlen (cluster_text),
5020 len = g_utf8_strlen (normalized_text, -1);
5022 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5025 gint pos = priv->current_pos;
5027 gtk_editable_insert_text (editable, normalized_text,
5028 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5030 gtk_editable_set_position (editable, pos);
5033 g_free (normalized_text);
5034 g_free (cluster_text);
5038 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5045 gtk_widget_error_bell (GTK_WIDGET (entry));
5048 gtk_entry_pend_cursor_blink (entry);
5052 gtk_entry_copy_clipboard (GtkEntry *entry)
5054 GtkEntryPrivate *priv = entry->priv;
5055 GtkEditable *editable = GTK_EDITABLE (entry);
5059 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5063 gtk_widget_error_bell (GTK_WIDGET (entry));
5067 str = gtk_entry_get_display_text (entry, start, end);
5068 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5069 GDK_SELECTION_CLIPBOARD),
5076 gtk_entry_cut_clipboard (GtkEntry *entry)
5078 GtkEntryPrivate *priv = entry->priv;
5079 GtkEditable *editable = GTK_EDITABLE (entry);
5084 gtk_widget_error_bell (GTK_WIDGET (entry));
5088 gtk_entry_copy_clipboard (entry);
5092 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5093 gtk_editable_delete_text (editable, start, end);
5097 gtk_widget_error_bell (GTK_WIDGET (entry));
5102 gtk_entry_paste_clipboard (GtkEntry *entry)
5104 GtkEntryPrivate *priv = entry->priv;
5107 gtk_entry_paste (entry, GDK_NONE);
5109 gtk_widget_error_bell (GTK_WIDGET (entry));
5113 gtk_entry_delete_cb (GtkEntry *entry)
5115 GtkEntryPrivate *priv = entry->priv;
5116 GtkEditable *editable = GTK_EDITABLE (entry);
5121 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5122 gtk_editable_delete_text (editable, start, end);
5127 gtk_entry_toggle_overwrite (GtkEntry *entry)
5129 GtkEntryPrivate *priv = entry->priv;
5131 priv->overwrite_mode = !priv->overwrite_mode;
5132 gtk_entry_pend_cursor_blink (entry);
5133 gtk_widget_queue_draw (GTK_WIDGET (entry));
5137 gtk_entry_select_all (GtkEntry *entry)
5139 gtk_entry_select_line (entry);
5143 gtk_entry_real_activate (GtkEntry *entry)
5145 GtkEntryPrivate *priv = entry->priv;
5147 GtkWidget *default_widget, *focus_widget;
5148 GtkWidget *toplevel;
5151 widget = GTK_WIDGET (entry);
5153 if (priv->activates_default)
5155 toplevel = gtk_widget_get_toplevel (widget);
5156 if (GTK_IS_WINDOW (toplevel))
5158 window = GTK_WINDOW (toplevel);
5162 default_widget = gtk_window_get_default_widget (window);
5163 focus_widget = gtk_window_get_focus (window);
5164 if (widget != default_widget &&
5165 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5166 gtk_window_activate_default (window);
5173 keymap_direction_changed (GdkKeymap *keymap,
5176 gtk_entry_recompute (entry);
5179 /* IM Context Callbacks
5183 gtk_entry_commit_cb (GtkIMContext *context,
5187 GtkEntryPrivate *priv = entry->priv;
5190 gtk_entry_enter_text (entry, str);
5194 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5197 GtkEntryPrivate *priv = entry->priv;
5201 gchar *preedit_string;
5204 gtk_im_context_get_preedit_string (priv->im_context,
5205 &preedit_string, NULL,
5207 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5208 priv->preedit_length = strlen (preedit_string);
5209 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5210 priv->preedit_cursor = cursor_pos;
5211 g_free (preedit_string);
5213 gtk_entry_recompute (entry);
5218 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5221 GtkEntryPrivate *priv = entry->priv;
5224 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5225 text = gtk_entry_get_display_text (entry, 0, -1);
5226 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5227 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5234 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5239 GtkEntryPrivate *priv = entry->priv;
5242 gtk_editable_delete_text (GTK_EDITABLE (entry),
5243 priv->current_pos + offset,
5244 priv->current_pos + offset + n_chars);
5249 /* Internal functions
5252 /* Used for im_commit_cb and inserting Unicode chars */
5254 gtk_entry_enter_text (GtkEntry *entry,
5257 GtkEntryPrivate *priv = entry->priv;
5258 GtkEditable *editable = GTK_EDITABLE (entry);
5260 gboolean old_need_im_reset;
5262 old_need_im_reset = priv->need_im_reset;
5263 priv->need_im_reset = FALSE;
5265 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5266 gtk_editable_delete_selection (editable);
5269 if (priv->overwrite_mode)
5270 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5273 tmp_pos = priv->current_pos;
5274 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5275 gtk_editable_set_position (editable, tmp_pos);
5277 priv->need_im_reset = old_need_im_reset;
5280 /* All changes to priv->current_pos and priv->selection_bound
5281 * should go through this function.
5284 gtk_entry_set_positions (GtkEntry *entry,
5286 gint selection_bound)
5288 GtkEntryPrivate *priv = entry->priv;
5289 gboolean changed = FALSE;
5291 g_object_freeze_notify (G_OBJECT (entry));
5293 if (current_pos != -1 &&
5294 priv->current_pos != current_pos)
5296 priv->current_pos = current_pos;
5299 g_object_notify (G_OBJECT (entry), "cursor-position");
5302 if (selection_bound != -1 &&
5303 priv->selection_bound != selection_bound)
5305 priv->selection_bound = selection_bound;
5308 g_object_notify (G_OBJECT (entry), "selection-bound");
5311 g_object_thaw_notify (G_OBJECT (entry));
5315 gtk_entry_move_adjustments (entry);
5316 gtk_entry_recompute (entry);
5321 gtk_entry_reset_layout (GtkEntry *entry)
5323 GtkEntryPrivate *priv = entry->priv;
5325 if (priv->cached_layout)
5327 g_object_unref (priv->cached_layout);
5328 priv->cached_layout = NULL;
5333 update_im_cursor_location (GtkEntry *entry)
5335 GtkEntryPrivate *priv = entry->priv;
5338 gint strong_xoffset;
5339 gint area_width, area_height;
5341 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5342 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5344 strong_xoffset = strong_x - priv->scroll_offset;
5345 if (strong_xoffset < 0)
5349 else if (strong_xoffset > area_width)
5351 strong_xoffset = area_width;
5353 area.x = strong_xoffset;
5356 area.height = area_height;
5358 gtk_im_context_set_cursor_location (priv->im_context, &area);
5362 recompute_idle_func (gpointer data)
5364 GtkEntry *entry = GTK_ENTRY (data);
5365 GtkEntryPrivate *priv = entry->priv;
5367 priv->recompute_idle = 0;
5369 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5371 gtk_entry_adjust_scroll (entry);
5372 gtk_widget_queue_draw (GTK_WIDGET (entry));
5374 update_im_cursor_location (entry);
5381 gtk_entry_recompute (GtkEntry *entry)
5383 GtkEntryPrivate *priv = entry->priv;
5385 gtk_entry_reset_layout (entry);
5386 gtk_entry_check_cursor_blink (entry);
5388 if (!priv->recompute_idle)
5390 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5391 recompute_idle_func, entry, NULL);
5395 static PangoLayout *
5396 gtk_entry_create_layout (GtkEntry *entry,
5397 gboolean include_preedit)
5399 GtkEntryPrivate *priv = entry->priv;
5400 GtkWidget *widget = GTK_WIDGET (entry);
5401 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5402 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5404 gchar *preedit_string = NULL;
5405 gint preedit_length = 0;
5406 PangoAttrList *preedit_attrs = NULL;
5411 pango_layout_set_single_paragraph_mode (layout, TRUE);
5413 display = gtk_entry_get_display_text (entry, 0, -1);
5414 n_bytes = strlen (display);
5416 if (include_preedit)
5418 gtk_im_context_get_preedit_string (priv->im_context,
5419 &preedit_string, &preedit_attrs, NULL);
5420 preedit_length = priv->preedit_length;
5425 GString *tmp_string = g_string_new (display);
5426 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5428 g_string_insert (tmp_string, cursor_index, preedit_string);
5430 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5432 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5433 cursor_index, preedit_length);
5435 g_string_free (tmp_string, TRUE);
5439 PangoDirection pango_dir;
5441 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5442 pango_dir = pango_find_base_dir (display, n_bytes);
5444 pango_dir = PANGO_DIRECTION_NEUTRAL;
5446 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5448 if (gtk_widget_has_focus (widget))
5450 GdkDisplay *display = gtk_widget_get_display (widget);
5451 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5452 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5453 pango_dir = PANGO_DIRECTION_RTL;
5455 pango_dir = PANGO_DIRECTION_LTR;
5459 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5460 pango_dir = PANGO_DIRECTION_RTL;
5462 pango_dir = PANGO_DIRECTION_LTR;
5466 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5469 priv->resolved_dir = pango_dir;
5471 pango_layout_set_text (layout, display, n_bytes);
5474 pango_layout_set_attributes (layout, tmp_attrs);
5476 g_free (preedit_string);
5480 pango_attr_list_unref (preedit_attrs);
5482 pango_attr_list_unref (tmp_attrs);
5487 static PangoLayout *
5488 gtk_entry_ensure_layout (GtkEntry *entry,
5489 gboolean include_preedit)
5491 GtkEntryPrivate *priv = entry->priv;
5493 if (priv->preedit_length > 0 &&
5494 !include_preedit != !priv->cache_includes_preedit)
5495 gtk_entry_reset_layout (entry);
5497 if (!priv->cached_layout)
5499 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5500 priv->cache_includes_preedit = include_preedit;
5503 return priv->cached_layout;
5507 get_layout_position (GtkEntry *entry,
5511 GtkEntryPrivate *priv = entry->priv;
5512 PangoLayout *layout;
5513 PangoRectangle logical_rect;
5514 gint area_width, area_height;
5515 GtkBorder inner_border;
5517 PangoLayoutLine *line;
5519 layout = gtk_entry_ensure_layout (entry, TRUE);
5521 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5522 _gtk_entry_effective_inner_border (entry, &inner_border);
5524 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5526 line = pango_layout_get_lines_readonly (layout)->data;
5527 pango_layout_line_get_extents (line, NULL, &logical_rect);
5529 /* Align primarily for locale's ascent/descent */
5530 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5531 priv->ascent + logical_rect.y);
5533 /* Now see if we need to adjust to fit in actual drawn string */
5534 if (logical_rect.height > area_height)
5535 y_pos = (area_height - logical_rect.height) / 2;
5538 else if (y_pos + logical_rect.height > area_height)
5539 y_pos = area_height - logical_rect.height;
5541 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5544 *x = inner_border.left - priv->scroll_offset;
5551 draw_text_with_color (GtkEntry *entry,
5553 GdkRGBA *default_color)
5555 GtkEntryPrivate *priv = entry->priv;
5556 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5559 gint start_pos, end_pos;
5561 widget = GTK_WIDGET (entry);
5565 get_layout_position (entry, &x, &y);
5567 cairo_move_to (cr, x, y);
5568 gdk_cairo_set_source_rgba (cr, default_color);
5569 pango_cairo_show_layout (cr, layout);
5571 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5575 PangoRectangle logical_rect;
5576 GdkRGBA selection_color, text_color;
5577 GtkBorder inner_border;
5578 GtkStyleContext *context;
5579 GtkStateFlags state;
5581 context = gtk_widget_get_style_context (widget);
5582 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5583 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5585 state = GTK_STATE_FLAG_SELECTED;
5587 if (gtk_widget_has_focus (widget))
5588 state |= GTK_STATE_FLAG_FOCUSED;
5590 gtk_style_context_get_background_color (context, state, &selection_color);
5591 gtk_style_context_get_color (context, state, &text_color);
5593 _gtk_entry_effective_inner_border (entry, &inner_border);
5595 for (i = 0; i < n_ranges; ++i)
5596 cairo_rectangle (cr,
5597 inner_border.left - priv->scroll_offset + ranges[2 * i],
5600 logical_rect.height);
5604 gdk_cairo_set_source_rgba (cr, &selection_color);
5607 cairo_move_to (cr, x, y);
5608 gdk_cairo_set_source_rgba (cr, &text_color);
5609 pango_cairo_show_layout (cr, layout);
5617 gtk_entry_draw_text (GtkEntry *entry,
5620 GtkEntryPrivate *priv = entry->priv;
5621 GtkWidget *widget = GTK_WIDGET (entry);
5622 GtkStateFlags state = 0;
5623 GdkRGBA text_color, bar_text_color;
5624 GtkStyleContext *context;
5627 gint progress_x, progress_y, progress_width, progress_height;
5628 gint clip_width, clip_height;
5630 /* Nothing to display at all */
5631 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5634 state = gtk_widget_get_state_flags (widget);
5635 context = gtk_widget_get_style_context (widget);
5637 gtk_style_context_get_color (context, state, &text_color);
5639 /* Get foreground color for progressbars */
5640 gtk_style_context_save (context);
5641 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5642 gtk_style_context_get_color (context, state, &bar_text_color);
5643 gtk_style_context_restore (context);
5645 get_progress_area (widget,
5646 &progress_x, &progress_y,
5647 &progress_width, &progress_height);
5649 clip_width = gdk_window_get_width (priv->text_area);
5650 clip_height = gdk_window_get_height (priv->text_area);
5651 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5654 /* If the color is the same, or the progress area has a zero
5655 * size, then we only need to draw once. */
5656 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5657 ((progress_width == 0) || (progress_height == 0)))
5659 draw_text_with_color (entry, cr, &text_color);
5663 width = gdk_window_get_width (priv->text_area);
5664 height = gdk_window_get_height (priv->text_area);
5668 cairo_rectangle (cr, 0, 0, width, height);
5672 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5673 cairo_rectangle (cr, 0, 0, width, height);
5675 gdk_window_get_position (priv->text_area, &pos_x, &pos_y);
5676 progress_x -= pos_x;
5677 progress_y -= pos_y;
5679 cairo_rectangle (cr, progress_x, progress_y,
5680 progress_width, progress_height);
5682 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5684 draw_text_with_color (entry, cr, &text_color);
5687 cairo_rectangle (cr, progress_x, progress_y,
5688 progress_width, progress_height);
5691 draw_text_with_color (entry, cr, &bar_text_color);
5698 draw_insertion_cursor (GtkEntry *entry,
5700 GdkRectangle *cursor_location,
5701 gboolean is_primary,
5702 PangoDirection direction,
5703 gboolean draw_arrow)
5705 GtkWidget *widget = GTK_WIDGET (entry);
5706 GtkTextDirection text_dir;
5708 if (direction == PANGO_DIRECTION_LTR)
5709 text_dir = GTK_TEXT_DIR_LTR;
5711 text_dir = GTK_TEXT_DIR_RTL;
5713 gtk_draw_insertion_cursor (widget, cr,
5715 is_primary, text_dir, draw_arrow);
5719 gtk_entry_draw_cursor (GtkEntry *entry,
5723 GtkEntryPrivate *priv = entry->priv;
5724 GtkWidget *widget = GTK_WIDGET (entry);
5725 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5726 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5727 GdkRectangle cursor_location;
5728 gboolean split_cursor;
5729 PangoRectangle cursor_rect;
5730 GtkBorder inner_border;
5732 gint text_area_height;
5735 gboolean block_at_line_end;
5736 PangoLayout *layout;
5739 _gtk_entry_effective_inner_border (entry, &inner_border);
5741 xoffset = inner_border.left - priv->scroll_offset;
5743 text_area_height = gdk_window_get_height (priv->text_area);
5745 layout = gtk_entry_ensure_layout (entry, TRUE);
5746 text = pango_layout_get_text (layout);
5747 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5748 if (!priv->overwrite_mode)
5751 block = _gtk_text_util_get_block_cursor_location (layout,
5752 cursor_index, &cursor_rect, &block_at_line_end);
5756 gint strong_x, weak_x;
5757 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5758 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5762 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5764 g_object_get (gtk_widget_get_settings (widget),
5765 "gtk-split-cursor", &split_cursor,
5768 dir1 = priv->resolved_dir;
5774 if (weak_x != strong_x)
5776 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5782 if (keymap_direction == priv->resolved_dir)
5788 cursor_location.x = xoffset + x1;
5789 cursor_location.y = inner_border.top;
5790 cursor_location.width = 0;
5791 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5793 draw_insertion_cursor (entry, cr,
5794 &cursor_location, TRUE, dir1,
5795 dir2 != PANGO_DIRECTION_NEUTRAL);
5797 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5799 cursor_location.x = xoffset + x2;
5800 draw_insertion_cursor (entry, cr,
5801 &cursor_location, FALSE, dir2,
5805 else /* overwrite_mode */
5807 GtkStyleContext *context;
5808 GdkRGBA cursor_color;
5814 get_layout_position (entry, &x, &y);
5816 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5817 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5818 rect.width = PANGO_PIXELS (cursor_rect.width);
5819 rect.height = PANGO_PIXELS (cursor_rect.height);
5821 context = gtk_widget_get_style_context (widget);
5823 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5824 gdk_cairo_set_source_rgba (cr, &cursor_color);
5825 gdk_cairo_rectangle (cr, &rect);
5828 if (!block_at_line_end)
5830 GtkStateFlags state;
5833 state = gtk_widget_get_state_flags (widget);
5834 gtk_style_context_get_background_color (context, state, &color);
5836 gdk_cairo_rectangle (cr, &rect);
5838 cairo_move_to (cr, x, y);
5839 gdk_cairo_set_source_rgba (cr, &color);
5840 pango_cairo_show_layout (cr, layout);
5848 _gtk_entry_reset_im_context (GtkEntry *entry)
5850 GtkEntryPrivate *priv = entry->priv;
5852 if (priv->need_im_reset)
5854 priv->need_im_reset = FALSE;
5855 gtk_im_context_reset (priv->im_context);
5860 * gtk_entry_reset_im_context:
5861 * @entry: a #GtkEntry
5863 * Reset the input method context of the entry if needed.
5865 * This can be necessary in the case where modifying the buffer
5866 * would confuse on-going input method behavior.
5871 gtk_entry_reset_im_context (GtkEntry *entry)
5873 g_return_if_fail (GTK_IS_ENTRY (entry));
5875 _gtk_entry_reset_im_context (entry);
5879 * gtk_entry_im_context_filter_keypress:
5880 * @entry: a #GtkEntry
5881 * @event: the key event
5883 * Allow the #GtkEntry input method to internally handle key press
5884 * and release events. If this function returns %TRUE, then no further
5885 * processing should be done for this key event. See
5886 * gtk_im_context_filter_keypress().
5888 * Note that you are expected to call this function from your handler
5889 * when overriding key event handling. This is needed in the case when
5890 * you need to insert your own key handling between the input method
5891 * and the default key event handling of the #GtkEntry.
5892 * See gtk_text_view_reset_im_context() for an example of use.
5894 * Return value: %TRUE if the input method handled the key event.
5899 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5902 GtkEntryPrivate *priv;
5904 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5908 return gtk_im_context_filter_keypress (priv->im_context, event);
5912 _gtk_entry_get_im_context (GtkEntry *entry)
5914 return entry->priv->im_context;
5918 gtk_entry_find_position (GtkEntry *entry,
5921 GtkEntryPrivate *priv = entry->priv;
5922 PangoLayout *layout;
5923 PangoLayoutLine *line;
5930 layout = gtk_entry_ensure_layout (entry, TRUE);
5931 text = pango_layout_get_text (layout);
5932 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
5934 line = pango_layout_get_lines_readonly (layout)->data;
5935 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5937 if (index >= cursor_index && priv->preedit_length)
5939 if (index >= cursor_index + priv->preedit_length)
5940 index -= priv->preedit_length;
5943 index = cursor_index;
5948 pos = g_utf8_pointer_to_offset (text, text + index);
5955 gtk_entry_get_cursor_locations (GtkEntry *entry,
5960 GtkEntryPrivate *priv = entry->priv;
5961 DisplayMode mode = gtk_entry_get_display_mode (entry);
5963 /* Nothing to display at all, so no cursor is relevant */
5964 if (mode == DISPLAY_BLANK)
5974 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5975 const gchar *text = pango_layout_get_text (layout);
5976 PangoRectangle strong_pos, weak_pos;
5979 if (type == CURSOR_STANDARD)
5981 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5983 else /* type == CURSOR_DND */
5985 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
5987 if (priv->dnd_position > priv->current_pos)
5989 if (mode == DISPLAY_NORMAL)
5990 index += priv->preedit_length;
5993 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5994 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
5999 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6002 *strong_x = strong_pos.x / PANGO_SCALE;
6005 *weak_x = weak_pos.x / PANGO_SCALE;
6010 gtk_entry_adjust_scroll (GtkEntry *entry)
6012 GtkEntryPrivate *priv = entry->priv;
6013 gint min_offset, max_offset;
6014 gint text_area_width, text_width;
6015 GtkBorder inner_border;
6016 gint strong_x, weak_x;
6017 gint strong_xoffset, weak_xoffset;
6019 PangoLayout *layout;
6020 PangoLayoutLine *line;
6021 PangoRectangle logical_rect;
6023 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6026 _gtk_entry_effective_inner_border (entry, &inner_border);
6028 text_area_width = gdk_window_get_width (priv->text_area);
6029 text_area_width -= inner_border.left + inner_border.right;
6030 if (text_area_width < 0)
6031 text_area_width = 0;
6033 layout = gtk_entry_ensure_layout (entry, TRUE);
6034 line = pango_layout_get_lines_readonly (layout)->data;
6036 pango_layout_line_get_extents (line, NULL, &logical_rect);
6038 /* Display as much text as we can */
6040 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6041 xalign = priv->xalign;
6043 xalign = 1.0 - priv->xalign;
6045 text_width = PANGO_PIXELS(logical_rect.width);
6047 if (text_width > text_area_width)
6050 max_offset = text_width - text_area_width;
6054 min_offset = (text_width - text_area_width) * xalign;
6055 max_offset = min_offset;
6058 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6060 /* And make sure cursors are on screen. Note that the cursor is
6061 * actually drawn one pixel into the INNER_BORDER space on
6062 * the right, when the scroll is at the utmost right. This
6063 * looks better to to me than confining the cursor inside the
6064 * border entirely, though it means that the cursor gets one
6065 * pixel closer to the edge of the widget on the right than
6066 * on the left. This might need changing if one changed
6067 * INNER_BORDER from 2 to 1, as one would do on a
6068 * small-screen-real-estate display.
6070 * We always make sure that the strong cursor is on screen, and
6071 * put the weak cursor on screen if possible.
6074 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6076 strong_xoffset = strong_x - priv->scroll_offset;
6078 if (strong_xoffset < 0)
6080 priv->scroll_offset += strong_xoffset;
6083 else if (strong_xoffset > text_area_width)
6085 priv->scroll_offset += strong_xoffset - text_area_width;
6086 strong_xoffset = text_area_width;
6089 weak_xoffset = weak_x - priv->scroll_offset;
6091 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6093 priv->scroll_offset += weak_xoffset;
6095 else if (weak_xoffset > text_area_width &&
6096 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6098 priv->scroll_offset += weak_xoffset - text_area_width;
6101 g_object_notify (G_OBJECT (entry), "scroll-offset");
6105 gtk_entry_move_adjustments (GtkEntry *entry)
6107 GtkWidget *widget = GTK_WIDGET (entry);
6108 GtkAllocation allocation;
6109 GtkAdjustment *adjustment;
6110 PangoContext *context;
6111 PangoFontMetrics *metrics;
6112 GtkStyleContext *style_context;
6113 GtkStateFlags state;
6114 gint x, layout_x, border_x, border_y;
6117 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6121 gtk_widget_get_allocation (widget, &allocation);
6123 /* Cursor position, layout offset, border width, and widget allocation */
6124 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6125 get_layout_position (entry, &layout_x, NULL);
6126 _gtk_entry_get_borders (entry, &border_x, &border_y);
6127 x += allocation.x + layout_x + border_x;
6129 /* Approximate width of a char, so user can see what is ahead/behind */
6130 context = gtk_widget_get_pango_context (widget);
6131 style_context = gtk_widget_get_style_context (widget);
6132 state = gtk_widget_get_state_flags (widget);
6134 metrics = pango_context_get_metrics (context,
6135 gtk_style_context_get_font (style_context, state),
6136 pango_context_get_language (context));
6137 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6140 gtk_adjustment_clamp_page (adjustment,
6141 x - (char_width + 1), /* one char + one pixel before */
6142 x + (char_width + 2)); /* one char + cursor + one pixel after */
6146 gtk_entry_move_visually (GtkEntry *entry,
6150 GtkEntryPrivate *priv = entry->priv;
6152 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6155 text = pango_layout_get_text (layout);
6157 index = g_utf8_offset_to_pointer (text, start) - text;
6161 int new_index, new_trailing;
6162 gboolean split_cursor;
6165 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6166 "gtk-split-cursor", &split_cursor,
6173 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6174 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6176 strong = keymap_direction == priv->resolved_dir;
6181 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6186 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6192 else if (new_index != G_MAXINT)
6195 while (new_trailing--)
6196 index = g_utf8_next_char (text + index) - text;
6199 return g_utf8_pointer_to_offset (text, text + index);
6203 gtk_entry_move_logically (GtkEntry *entry,
6207 gint new_pos = start;
6210 length = gtk_entry_buffer_get_length (get_buffer (entry));
6212 /* Prevent any leak of information */
6213 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6215 new_pos = CLAMP (start + count, 0, length);
6219 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6220 PangoLogAttr *log_attrs;
6223 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6225 while (count > 0 && new_pos < length)
6229 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6233 while (count < 0 && new_pos > 0)
6237 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6249 gtk_entry_move_forward_word (GtkEntry *entry,
6251 gboolean allow_whitespace)
6253 gint new_pos = start;
6256 length = gtk_entry_buffer_get_length (get_buffer (entry));
6258 /* Prevent any leak of information */
6259 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6263 else if (new_pos < length)
6265 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6266 PangoLogAttr *log_attrs;
6269 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6271 /* Find the next word boundary */
6273 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6274 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6285 gtk_entry_move_backward_word (GtkEntry *entry,
6287 gboolean allow_whitespace)
6289 gint new_pos = start;
6291 /* Prevent any leak of information */
6292 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6298 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6299 PangoLogAttr *log_attrs;
6302 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6304 new_pos = start - 1;
6306 /* Find the previous word boundary */
6307 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6308 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6318 gtk_entry_delete_whitespace (GtkEntry *entry)
6320 GtkEntryPrivate *priv = entry->priv;
6321 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6322 PangoLogAttr *log_attrs;
6326 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6328 start = end = priv->current_pos;
6330 while (start > 0 && log_attrs[start-1].is_white)
6333 while (end < n_attrs && log_attrs[end].is_white)
6339 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6344 gtk_entry_select_word (GtkEntry *entry)
6346 GtkEntryPrivate *priv = entry->priv;
6347 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6348 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6350 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6354 gtk_entry_select_line (GtkEntry *entry)
6356 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6360 truncate_multiline (const gchar *text)
6365 text[length] && text[length] != '\n' && text[length] != '\r';
6372 paste_received (GtkClipboard *clipboard,
6376 GtkEntry *entry = GTK_ENTRY (data);
6377 GtkEditable *editable = GTK_EDITABLE (entry);
6378 GtkEntryPrivate *priv = entry->priv;
6380 if (priv->button == 2)
6382 gint pos, start, end;
6383 pos = priv->insert_pos;
6384 gtk_editable_get_selection_bounds (editable, &start, &end);
6385 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6386 gtk_editable_select_region (editable, pos, pos);
6391 gint pos, start, end;
6393 gboolean popup_completion;
6394 GtkEntryCompletion *completion;
6396 completion = gtk_entry_get_completion (entry);
6398 if (priv->truncate_multiline)
6399 length = truncate_multiline (text);
6401 /* only complete if the selection is at the end */
6402 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6403 MAX (priv->current_pos, priv->selection_bound));
6407 if (gtk_widget_get_mapped (completion->priv->popup_window))
6408 _gtk_entry_completion_popdown (completion);
6410 if (!popup_completion && completion->priv->changed_id > 0)
6411 g_signal_handler_block (entry, completion->priv->changed_id);
6414 begin_change (entry);
6415 g_object_freeze_notify (G_OBJECT (entry));
6416 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6417 gtk_editable_delete_text (editable, start, end);
6419 pos = priv->current_pos;
6420 gtk_editable_insert_text (editable, text, length, &pos);
6421 gtk_editable_set_position (editable, pos);
6422 g_object_thaw_notify (G_OBJECT (entry));
6426 !popup_completion && completion->priv->changed_id > 0)
6427 g_signal_handler_unblock (entry, completion->priv->changed_id);
6430 g_object_unref (entry);
6434 gtk_entry_paste (GtkEntry *entry,
6437 g_object_ref (entry);
6438 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6439 paste_received, entry);
6443 primary_get_cb (GtkClipboard *clipboard,
6444 GtkSelectionData *selection_data,
6448 GtkEntry *entry = GTK_ENTRY (data);
6451 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6453 gchar *str = gtk_entry_get_display_text (entry, start, end);
6454 gtk_selection_data_set_text (selection_data, str, -1);
6460 primary_clear_cb (GtkClipboard *clipboard,
6463 GtkEntry *entry = GTK_ENTRY (data);
6464 GtkEntryPrivate *priv = entry->priv;
6466 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6470 gtk_entry_update_primary_selection (GtkEntry *entry)
6472 GtkTargetList *list;
6473 GtkTargetEntry *targets;
6474 GtkClipboard *clipboard;
6478 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6481 list = gtk_target_list_new (NULL, 0);
6482 gtk_target_list_add_text_targets (list, 0);
6484 targets = gtk_target_table_new_from_list (list, &n_targets);
6486 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6488 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6490 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6491 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6492 primary_clear_cb (clipboard, entry);
6496 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6497 gtk_clipboard_clear (clipboard);
6500 gtk_target_table_free (targets, n_targets);
6501 gtk_target_list_unref (list);
6505 gtk_entry_clear (GtkEntry *entry,
6506 GtkEntryIconPosition icon_pos)
6508 GtkEntryPrivate *priv = entry->priv;
6509 EntryIconInfo *icon_info = priv->icons[icon_pos];
6511 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6514 g_object_freeze_notify (G_OBJECT (entry));
6516 /* Explicitly check, as the pointer may become invalidated
6517 * during destruction.
6519 if (GDK_IS_WINDOW (icon_info->window))
6520 gdk_window_hide (icon_info->window);
6522 if (icon_info->pixbuf)
6524 g_object_unref (icon_info->pixbuf);
6525 icon_info->pixbuf = NULL;
6528 switch (icon_info->storage_type)
6530 case GTK_IMAGE_PIXBUF:
6531 g_object_notify (G_OBJECT (entry),
6532 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6535 case GTK_IMAGE_STOCK:
6536 g_free (icon_info->stock_id);
6537 icon_info->stock_id = NULL;
6538 g_object_notify (G_OBJECT (entry),
6539 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6542 case GTK_IMAGE_ICON_NAME:
6543 g_free (icon_info->icon_name);
6544 icon_info->icon_name = NULL;
6545 g_object_notify (G_OBJECT (entry),
6546 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6549 case GTK_IMAGE_GICON:
6550 if (icon_info->gicon)
6552 g_object_unref (icon_info->gicon);
6553 icon_info->gicon = NULL;
6555 g_object_notify (G_OBJECT (entry),
6556 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6560 g_assert_not_reached ();
6564 icon_info->storage_type = GTK_IMAGE_EMPTY;
6565 g_object_notify (G_OBJECT (entry),
6566 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6568 g_object_thaw_notify (G_OBJECT (entry));
6572 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6573 GtkEntryIconPosition icon_pos)
6575 GtkEntryPrivate *priv = entry->priv;
6576 EntryIconInfo *icon_info = priv->icons[icon_pos];
6578 GtkIconTheme *icon_theme;
6579 GtkSettings *settings;
6580 GtkStateFlags state;
6585 if (!icon_info || icon_info->pixbuf)
6588 widget = GTK_WIDGET (entry);
6590 switch (icon_info->storage_type)
6592 case GTK_IMAGE_EMPTY:
6593 case GTK_IMAGE_PIXBUF:
6595 case GTK_IMAGE_STOCK:
6596 state = gtk_widget_get_state_flags (widget);
6597 gtk_widget_set_state_flags (widget, 0, TRUE);
6598 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6599 icon_info->stock_id,
6600 GTK_ICON_SIZE_MENU);
6601 if (!icon_info->pixbuf)
6602 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6603 GTK_STOCK_MISSING_IMAGE,
6604 GTK_ICON_SIZE_MENU);
6605 gtk_widget_set_state_flags (widget, state, TRUE);
6608 case GTK_IMAGE_ICON_NAME:
6609 screen = gtk_widget_get_screen (widget);
6612 icon_theme = gtk_icon_theme_get_for_screen (screen);
6613 settings = gtk_settings_get_for_screen (screen);
6615 gtk_icon_size_lookup_for_settings (settings,
6619 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6620 icon_info->icon_name,
6621 MIN (width, height),
6624 if (icon_info->pixbuf == NULL)
6626 state = gtk_widget_get_state_flags (widget);
6627 gtk_widget_set_state_flags (widget, 0, TRUE);
6628 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6629 GTK_STOCK_MISSING_IMAGE,
6630 GTK_ICON_SIZE_MENU);
6631 gtk_widget_set_state_flags (widget, state, TRUE);
6636 case GTK_IMAGE_GICON:
6637 screen = gtk_widget_get_screen (widget);
6640 icon_theme = gtk_icon_theme_get_for_screen (screen);
6641 settings = gtk_settings_get_for_screen (screen);
6643 gtk_icon_size_lookup_for_settings (settings,
6647 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6649 MIN (width, height),
6650 GTK_ICON_LOOKUP_USE_BUILTIN);
6653 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6654 gtk_icon_info_free (info);
6657 if (icon_info->pixbuf == NULL)
6659 state = gtk_widget_get_state_flags (widget);
6660 gtk_widget_set_state_flags (widget, 0, TRUE);
6661 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6662 GTK_STOCK_MISSING_IMAGE,
6663 GTK_ICON_SIZE_MENU);
6664 gtk_widget_set_state_flags (widget, state, TRUE);
6670 g_assert_not_reached ();
6674 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6675 gdk_window_show_unraised (icon_info->window);
6685 * Creates a new entry.
6687 * Return value: a new #GtkEntry.
6690 gtk_entry_new (void)
6692 return g_object_new (GTK_TYPE_ENTRY, NULL);
6696 * gtk_entry_new_with_buffer:
6697 * @buffer: The buffer to use for the new #GtkEntry.
6699 * Creates a new entry with the specified text buffer.
6701 * Return value: a new #GtkEntry
6706 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6708 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6709 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6712 static GtkEntryBuffer*
6713 get_buffer (GtkEntry *entry)
6715 GtkEntryPrivate *priv = entry->priv;
6717 if (priv->buffer == NULL)
6719 GtkEntryBuffer *buffer;
6720 buffer = gtk_entry_buffer_new (NULL, 0);
6721 gtk_entry_set_buffer (entry, buffer);
6722 g_object_unref (buffer);
6725 return priv->buffer;
6729 * gtk_entry_get_buffer:
6730 * @entry: a #GtkEntry
6732 * Get the #GtkEntryBuffer object which holds the text for
6737 * Returns: (transfer none): A #GtkEntryBuffer object.
6740 gtk_entry_get_buffer (GtkEntry *entry)
6742 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6744 return get_buffer (entry);
6748 * gtk_entry_set_buffer:
6749 * @entry: a #GtkEntry
6750 * @buffer: a #GtkEntryBuffer
6752 * Set the #GtkEntryBuffer object which holds the text for
6758 gtk_entry_set_buffer (GtkEntry *entry,
6759 GtkEntryBuffer *buffer)
6761 GtkEntryPrivate *priv;
6764 g_return_if_fail (GTK_IS_ENTRY (entry));
6770 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6771 g_object_ref (buffer);
6776 buffer_disconnect_signals (entry);
6777 g_object_unref (priv->buffer);
6780 priv->buffer = buffer;
6783 buffer_connect_signals (entry);
6785 obj = G_OBJECT (entry);
6786 g_object_freeze_notify (obj);
6787 g_object_notify (obj, "buffer");
6788 g_object_notify (obj, "text");
6789 g_object_notify (obj, "text-length");
6790 g_object_notify (obj, "max-length");
6791 g_object_notify (obj, "visibility");
6792 g_object_notify (obj, "invisible-char");
6793 g_object_notify (obj, "invisible-char-set");
6794 g_object_thaw_notify (obj);
6796 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6797 gtk_entry_recompute (entry);
6801 * gtk_entry_get_text_area:
6802 * @entry: a #GtkEntry
6803 * @text_area: (out): Return location for the text area.
6805 * Gets the area where the entry's text is drawn. This function is
6806 * useful when drawing something to the entry in a draw callback.
6808 * If the entry is not realized, @text_area is filled with zeros.
6810 * See also gtk_entry_get_icon_area().
6815 gtk_entry_get_text_area (GtkEntry *entry,
6816 GdkRectangle *text_area)
6818 GtkEntryPrivate *priv;
6820 g_return_if_fail (GTK_IS_ENTRY (entry));
6821 g_return_if_fail (text_area != NULL);
6825 if (priv->text_area)
6827 GtkAllocation allocation;
6830 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6831 gdk_window_get_position (priv->text_area, &x, &y);
6833 text_area->x = x - allocation.x;
6834 text_area->y = y - allocation.y;
6835 text_area->width = gdk_window_get_width (priv->text_area);
6836 text_area->height = gdk_window_get_height (priv->text_area);
6842 text_area->width = 0;
6843 text_area->height = 0;
6848 * gtk_entry_set_text:
6849 * @entry: a #GtkEntry
6850 * @text: the new text
6852 * Sets the text in the widget to the given
6853 * value, replacing the current contents.
6855 * See gtk_entry_buffer_set_text().
6858 gtk_entry_set_text (GtkEntry *entry,
6862 GtkEntryCompletion *completion;
6864 g_return_if_fail (GTK_IS_ENTRY (entry));
6865 g_return_if_fail (text != NULL);
6867 /* Actually setting the text will affect the cursor and selection;
6868 * if the contents don't actually change, this will look odd to the user.
6870 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6873 completion = gtk_entry_get_completion (entry);
6874 if (completion && completion->priv->changed_id > 0)
6875 g_signal_handler_block (entry, completion->priv->changed_id);
6877 begin_change (entry);
6878 g_object_freeze_notify (G_OBJECT (entry));
6879 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6881 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6882 g_object_thaw_notify (G_OBJECT (entry));
6885 if (completion && completion->priv->changed_id > 0)
6886 g_signal_handler_unblock (entry, completion->priv->changed_id);
6890 * gtk_entry_set_visibility:
6891 * @entry: a #GtkEntry
6892 * @visible: %TRUE if the contents of the entry are displayed
6895 * Sets whether the contents of the entry are visible or not.
6896 * When visibility is set to %FALSE, characters are displayed
6897 * as the invisible char, and will also appear that way when
6898 * the text in the entry widget is copied elsewhere.
6900 * By default, GTK+ picks the best invisible character available
6901 * in the current font, but it can be changed with
6902 * gtk_entry_set_invisible_char().
6905 gtk_entry_set_visibility (GtkEntry *entry,
6908 GtkEntryPrivate *priv;
6910 g_return_if_fail (GTK_IS_ENTRY (entry));
6914 visible = visible != FALSE;
6916 if (priv->visible != visible)
6918 priv->visible = visible;
6920 g_object_notify (G_OBJECT (entry), "visibility");
6921 gtk_entry_recompute (entry);
6926 * gtk_entry_get_visibility:
6927 * @entry: a #GtkEntry
6929 * Retrieves whether the text in @entry is visible. See
6930 * gtk_entry_set_visibility().
6932 * Return value: %TRUE if the text is currently visible
6935 gtk_entry_get_visibility (GtkEntry *entry)
6937 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6939 return entry->priv->visible;
6943 * gtk_entry_set_invisible_char:
6944 * @entry: a #GtkEntry
6945 * @ch: a Unicode character
6947 * Sets the character to use in place of the actual text when
6948 * gtk_entry_set_visibility() has been called to set text visibility
6949 * to %FALSE. i.e. this is the character used in "password mode" to
6950 * show the user how many characters have been typed. By default, GTK+
6951 * picks the best invisible char available in the current font. If you
6952 * set the invisible char to 0, then the user will get no feedback
6953 * at all; there will be no text on the screen as they type.
6956 gtk_entry_set_invisible_char (GtkEntry *entry,
6959 GtkEntryPrivate *priv;
6961 g_return_if_fail (GTK_IS_ENTRY (entry));
6965 if (!priv->invisible_char_set)
6967 priv->invisible_char_set = TRUE;
6968 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6971 if (ch == priv->invisible_char)
6974 priv->invisible_char = ch;
6975 g_object_notify (G_OBJECT (entry), "invisible-char");
6976 gtk_entry_recompute (entry);
6980 * gtk_entry_get_invisible_char:
6981 * @entry: a #GtkEntry
6983 * Retrieves the character displayed in place of the real characters
6984 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6986 * Return value: the current invisible char, or 0, if the entry does not
6987 * show invisible text at all.
6990 gtk_entry_get_invisible_char (GtkEntry *entry)
6992 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6994 return entry->priv->invisible_char;
6998 * gtk_entry_unset_invisible_char:
6999 * @entry: a #GtkEntry
7001 * Unsets the invisible char previously set with
7002 * gtk_entry_set_invisible_char(). So that the
7003 * default invisible char is used again.
7008 gtk_entry_unset_invisible_char (GtkEntry *entry)
7010 GtkEntryPrivate *priv;
7013 g_return_if_fail (GTK_IS_ENTRY (entry));
7017 if (!priv->invisible_char_set)
7020 priv->invisible_char_set = FALSE;
7021 ch = find_invisible_char (GTK_WIDGET (entry));
7023 if (priv->invisible_char != ch)
7025 priv->invisible_char = ch;
7026 g_object_notify (G_OBJECT (entry), "invisible-char");
7029 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7030 gtk_entry_recompute (entry);
7034 * gtk_entry_set_overwrite_mode:
7035 * @entry: a #GtkEntry
7036 * @overwrite: new value
7038 * Sets whether the text is overwritten when typing in the #GtkEntry.
7043 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7046 GtkEntryPrivate *priv = entry->priv;
7048 g_return_if_fail (GTK_IS_ENTRY (entry));
7050 if (priv->overwrite_mode == overwrite)
7053 gtk_entry_toggle_overwrite (entry);
7055 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7059 * gtk_entry_get_overwrite_mode:
7060 * @entry: a #GtkEntry
7062 * Gets the value set by gtk_entry_set_overwrite_mode().
7064 * Return value: whether the text is overwritten when typing.
7069 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7071 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7073 return entry->priv->overwrite_mode;
7077 * gtk_entry_get_text:
7078 * @entry: a #GtkEntry
7080 * Retrieves the contents of the entry widget.
7081 * See also gtk_editable_get_chars().
7083 * This is equivalent to:
7085 * <informalexample><programlisting>
7086 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7087 * </programlisting></informalexample>
7089 * Return value: a pointer to the contents of the widget as a
7090 * string. This string points to internally allocated
7091 * storage in the widget and must not be freed, modified or
7094 G_CONST_RETURN gchar*
7095 gtk_entry_get_text (GtkEntry *entry)
7097 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7099 return gtk_entry_buffer_get_text (get_buffer (entry));
7103 * gtk_entry_set_max_length:
7104 * @entry: a #GtkEntry
7105 * @max: the maximum length of the entry, or 0 for no maximum.
7106 * (other than the maximum length of entries.) The value passed in will
7107 * be clamped to the range 0-65536.
7109 * Sets the maximum allowed length of the contents of the widget. If
7110 * the current contents are longer than the given length, then they
7111 * will be truncated to fit.
7113 * This is equivalent to:
7115 * <informalexample><programlisting>
7116 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7117 * </programlisting></informalexample>
7120 gtk_entry_set_max_length (GtkEntry *entry,
7123 g_return_if_fail (GTK_IS_ENTRY (entry));
7124 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7128 * gtk_entry_get_max_length:
7129 * @entry: a #GtkEntry
7131 * Retrieves the maximum allowed length of the text in
7132 * @entry. See gtk_entry_set_max_length().
7134 * This is equivalent to:
7136 * <informalexample><programlisting>
7137 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7138 * </programlisting></informalexample>
7140 * Return value: the maximum allowed number of characters
7141 * in #GtkEntry, or 0 if there is no maximum.
7144 gtk_entry_get_max_length (GtkEntry *entry)
7146 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7148 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7152 * gtk_entry_get_text_length:
7153 * @entry: a #GtkEntry
7155 * Retrieves the current length of the text in
7158 * This is equivalent to:
7160 * <informalexample><programlisting>
7161 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7162 * </programlisting></informalexample>
7164 * Return value: the current number of characters
7165 * in #GtkEntry, or 0 if there are none.
7170 gtk_entry_get_text_length (GtkEntry *entry)
7172 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7174 return gtk_entry_buffer_get_length (get_buffer (entry));
7178 * gtk_entry_set_activates_default:
7179 * @entry: a #GtkEntry
7180 * @setting: %TRUE to activate window's default widget on Enter keypress
7182 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7183 * widget for the window containing the entry. This usually means that
7184 * the dialog box containing the entry will be closed, since the default
7185 * widget is usually one of the dialog buttons.
7187 * (For experts: if @setting is %TRUE, the entry calls
7188 * gtk_window_activate_default() on the window containing the entry, in
7189 * the default handler for the #GtkWidget::activate signal.)
7192 gtk_entry_set_activates_default (GtkEntry *entry,
7195 GtkEntryPrivate *priv;
7197 g_return_if_fail (GTK_IS_ENTRY (entry));
7201 setting = setting != FALSE;
7203 if (setting != priv->activates_default)
7205 priv->activates_default = setting;
7206 g_object_notify (G_OBJECT (entry), "activates-default");
7211 * gtk_entry_get_activates_default:
7212 * @entry: a #GtkEntry
7214 * Retrieves the value set by gtk_entry_set_activates_default().
7216 * Return value: %TRUE if the entry will activate the default widget
7219 gtk_entry_get_activates_default (GtkEntry *entry)
7221 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7223 return entry->priv->activates_default;
7227 * gtk_entry_set_width_chars:
7228 * @entry: a #GtkEntry
7229 * @n_chars: width in chars
7231 * Changes the size request of the entry to be about the right size
7232 * for @n_chars characters. Note that it changes the size
7233 * <emphasis>request</emphasis>, the size can still be affected by
7234 * how you pack the widget into containers. If @n_chars is -1, the
7235 * size reverts to the default entry size.
7238 gtk_entry_set_width_chars (GtkEntry *entry,
7241 GtkEntryPrivate *priv;
7243 g_return_if_fail (GTK_IS_ENTRY (entry));
7247 if (priv->width_chars != n_chars)
7249 priv->width_chars = n_chars;
7250 g_object_notify (G_OBJECT (entry), "width-chars");
7251 gtk_widget_queue_resize (GTK_WIDGET (entry));
7256 * gtk_entry_get_width_chars:
7257 * @entry: a #GtkEntry
7259 * Gets the value set by gtk_entry_set_width_chars().
7261 * Return value: number of chars to request space for, or negative if unset
7264 gtk_entry_get_width_chars (GtkEntry *entry)
7266 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7268 return entry->priv->width_chars;
7272 * gtk_entry_set_has_frame:
7273 * @entry: a #GtkEntry
7274 * @setting: new value
7276 * Sets whether the entry has a beveled frame around it.
7279 gtk_entry_set_has_frame (GtkEntry *entry,
7282 GtkEntryPrivate *priv;
7284 g_return_if_fail (GTK_IS_ENTRY (entry));
7288 setting = (setting != FALSE);
7290 if (priv->has_frame == setting)
7293 gtk_widget_queue_resize (GTK_WIDGET (entry));
7294 priv->has_frame = setting;
7295 g_object_notify (G_OBJECT (entry), "has-frame");
7299 * gtk_entry_get_has_frame:
7300 * @entry: a #GtkEntry
7302 * Gets the value set by gtk_entry_set_has_frame().
7304 * Return value: whether the entry has a beveled frame
7307 gtk_entry_get_has_frame (GtkEntry *entry)
7309 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7311 return entry->priv->has_frame;
7315 * gtk_entry_set_inner_border:
7316 * @entry: a #GtkEntry
7317 * @border: (allow-none): a #GtkBorder, or %NULL
7319 * Sets %entry's inner-border property to %border, or clears it if %NULL
7320 * is passed. The inner-border is the area around the entry's text, but
7323 * If set, this property overrides the inner-border style property.
7324 * Overriding the style-provided border is useful when you want to do
7325 * in-place editing of some text in a canvas or list widget, where
7326 * pixel-exact positioning of the entry is important.
7331 gtk_entry_set_inner_border (GtkEntry *entry,
7332 const GtkBorder *border)
7334 g_return_if_fail (GTK_IS_ENTRY (entry));
7336 gtk_widget_queue_resize (GTK_WIDGET (entry));
7339 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7340 gtk_border_copy (border),
7341 (GDestroyNotify) gtk_border_free);
7343 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7345 g_object_notify (G_OBJECT (entry), "inner-border");
7349 * gtk_entry_get_inner_border:
7350 * @entry: a #GtkEntry
7352 * This function returns the entry's #GtkEntry:inner-border property. See
7353 * gtk_entry_set_inner_border() for more information.
7355 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7359 G_CONST_RETURN GtkBorder *
7360 gtk_entry_get_inner_border (GtkEntry *entry)
7362 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7364 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7368 * gtk_entry_get_layout:
7369 * @entry: a #GtkEntry
7371 * Gets the #PangoLayout used to display the entry.
7372 * The layout is useful to e.g. convert text positions to
7373 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7374 * The returned layout is owned by the entry and must not be
7375 * modified or freed by the caller.
7377 * Keep in mind that the layout text may contain a preedit string, so
7378 * gtk_entry_layout_index_to_text_index() and
7379 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7380 * indices in the layout to byte indices in the entry contents.
7382 * Return value: (transfer none): the #PangoLayout for this entry
7385 gtk_entry_get_layout (GtkEntry *entry)
7387 PangoLayout *layout;
7389 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7391 layout = gtk_entry_ensure_layout (entry, TRUE);
7398 * gtk_entry_layout_index_to_text_index:
7399 * @entry: a #GtkEntry
7400 * @layout_index: byte index into the entry layout text
7402 * Converts from a position in the entry contents (returned
7403 * by gtk_entry_get_text()) to a position in the
7404 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7405 * with text retrieved via pango_layout_get_text()).
7407 * Return value: byte index into the entry contents
7410 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7413 GtkEntryPrivate *priv;
7414 PangoLayout *layout;
7418 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7422 layout = gtk_entry_ensure_layout (entry, TRUE);
7423 text = pango_layout_get_text (layout);
7424 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7426 if (layout_index >= cursor_index && priv->preedit_length)
7428 if (layout_index >= cursor_index + priv->preedit_length)
7429 layout_index -= priv->preedit_length;
7431 layout_index = cursor_index;
7434 return layout_index;
7438 * gtk_entry_text_index_to_layout_index:
7439 * @entry: a #GtkEntry
7440 * @text_index: byte index into the entry contents
7442 * Converts from a position in the entry's #PangoLayout (returned by
7443 * gtk_entry_get_layout()) to a position in the entry contents
7444 * (returned by gtk_entry_get_text()).
7446 * Return value: byte index into the entry layout text
7449 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7452 GtkEntryPrivate *priv;
7453 PangoLayout *layout;
7457 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7461 layout = gtk_entry_ensure_layout (entry, TRUE);
7462 text = pango_layout_get_text (layout);
7463 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7465 if (text_index > cursor_index)
7466 text_index += priv->preedit_length;
7472 * gtk_entry_get_layout_offsets:
7473 * @entry: a #GtkEntry
7474 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7475 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7478 * Obtains the position of the #PangoLayout used to render text
7479 * in the entry, in widget coordinates. Useful if you want to line
7480 * up the text in an entry with some other text, e.g. when using the
7481 * entry to implement editable cells in a sheet widget.
7483 * Also useful to convert mouse events into coordinates inside the
7484 * #PangoLayout, e.g. to take some action if some part of the entry text
7487 * Note that as the user scrolls around in the entry the offsets will
7488 * change; you'll need to connect to the "notify::scroll-offset"
7489 * signal to track this. Remember when using the #PangoLayout
7490 * functions you need to convert to and from pixels using
7491 * PANGO_PIXELS() or #PANGO_SCALE.
7493 * Keep in mind that the layout text may contain a preedit string, so
7494 * gtk_entry_layout_index_to_text_index() and
7495 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7496 * indices in the layout to byte indices in the entry contents.
7499 gtk_entry_get_layout_offsets (GtkEntry *entry,
7503 gint text_area_x, text_area_y;
7505 g_return_if_fail (GTK_IS_ENTRY (entry));
7507 /* this gets coords relative to text area */
7508 get_layout_position (entry, x, y);
7510 /* convert to widget coords */
7511 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7522 * gtk_entry_set_alignment:
7523 * @entry: a #GtkEntry
7524 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7525 * Reversed for RTL layouts
7527 * Sets the alignment for the contents of the entry. This controls
7528 * the horizontal positioning of the contents when the displayed
7529 * text is shorter than the width of the entry.
7534 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7536 GtkEntryPrivate *priv;
7538 g_return_if_fail (GTK_IS_ENTRY (entry));
7544 else if (xalign > 1.0)
7547 if (xalign != priv->xalign)
7549 priv->xalign = xalign;
7551 gtk_entry_recompute (entry);
7553 g_object_notify (G_OBJECT (entry), "xalign");
7558 * gtk_entry_get_alignment:
7559 * @entry: a #GtkEntry
7561 * Gets the value set by gtk_entry_set_alignment().
7563 * Return value: the alignment
7568 gtk_entry_get_alignment (GtkEntry *entry)
7570 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7572 return entry->priv->xalign;
7576 * gtk_entry_set_icon_from_pixbuf:
7577 * @entry: a #GtkEntry
7578 * @icon_pos: Icon position
7579 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7581 * Sets the icon shown in the specified position using a pixbuf.
7583 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7588 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7589 GtkEntryIconPosition icon_pos,
7592 GtkEntryPrivate *priv;
7593 EntryIconInfo *icon_info;
7595 g_return_if_fail (GTK_IS_ENTRY (entry));
7596 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7600 if ((icon_info = priv->icons[icon_pos]) == NULL)
7601 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7603 g_object_freeze_notify (G_OBJECT (entry));
7606 g_object_ref (pixbuf);
7608 gtk_entry_clear (entry, icon_pos);
7612 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7613 icon_info->pixbuf = pixbuf;
7615 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7617 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7618 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7622 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7623 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7626 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7627 gdk_window_show_unraised (icon_info->window);
7630 gtk_entry_ensure_pixbuf (entry, icon_pos);
7632 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7633 gtk_widget_queue_resize (GTK_WIDGET (entry));
7635 g_object_thaw_notify (G_OBJECT (entry));
7639 * gtk_entry_set_icon_from_stock:
7640 * @entry: A #GtkEntry
7641 * @icon_pos: Icon position
7642 * @stock_id: (allow-none): The name of the stock item, or %NULL
7644 * Sets the icon shown in the entry at the specified position from
7647 * If @stock_id is %NULL, no icon will be shown in the specified position.
7652 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7653 GtkEntryIconPosition icon_pos,
7654 const gchar *stock_id)
7656 GtkEntryPrivate *priv;
7657 EntryIconInfo *icon_info;
7660 g_return_if_fail (GTK_IS_ENTRY (entry));
7661 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7665 if ((icon_info = priv->icons[icon_pos]) == NULL)
7666 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7668 g_object_freeze_notify (G_OBJECT (entry));
7670 /* need to dup before clearing */
7671 new_id = g_strdup (stock_id);
7673 gtk_entry_clear (entry, icon_pos);
7677 icon_info->storage_type = GTK_IMAGE_STOCK;
7678 icon_info->stock_id = new_id;
7680 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7682 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7683 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7687 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7688 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7691 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7692 gdk_window_show_unraised (icon_info->window);
7695 gtk_entry_ensure_pixbuf (entry, icon_pos);
7697 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7698 gtk_widget_queue_resize (GTK_WIDGET (entry));
7700 g_object_thaw_notify (G_OBJECT (entry));
7704 * gtk_entry_set_icon_from_icon_name:
7705 * @entry: A #GtkEntry
7706 * @icon_pos: The position at which to set the icon
7707 * @icon_name: (allow-none): An icon name, or %NULL
7709 * Sets the icon shown in the entry at the specified position
7710 * from the current icon theme.
7712 * If the icon name isn't known, a "broken image" icon will be displayed
7715 * If @icon_name is %NULL, no icon will be shown in the specified position.
7720 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7721 GtkEntryIconPosition icon_pos,
7722 const gchar *icon_name)
7724 GtkEntryPrivate *priv;
7725 EntryIconInfo *icon_info;
7728 g_return_if_fail (GTK_IS_ENTRY (entry));
7729 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7733 if ((icon_info = priv->icons[icon_pos]) == NULL)
7734 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7736 g_object_freeze_notify (G_OBJECT (entry));
7738 /* need to dup before clearing */
7739 new_name = g_strdup (icon_name);
7741 gtk_entry_clear (entry, icon_pos);
7743 if (new_name != NULL)
7745 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7746 icon_info->icon_name = new_name;
7748 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7750 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7751 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7755 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7756 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7759 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7760 gdk_window_show_unraised (icon_info->window);
7763 gtk_entry_ensure_pixbuf (entry, icon_pos);
7765 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7766 gtk_widget_queue_resize (GTK_WIDGET (entry));
7768 g_object_thaw_notify (G_OBJECT (entry));
7772 * gtk_entry_set_icon_from_gicon:
7773 * @entry: A #GtkEntry
7774 * @icon_pos: The position at which to set the icon
7775 * @icon: (allow-none): The icon to set, or %NULL
7777 * Sets the icon shown in the entry at the specified position
7778 * from the current icon theme.
7779 * If the icon isn't known, a "broken image" icon will be displayed
7782 * If @icon is %NULL, no icon will be shown in the specified position.
7787 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7788 GtkEntryIconPosition icon_pos,
7791 GtkEntryPrivate *priv;
7792 EntryIconInfo *icon_info;
7794 g_return_if_fail (GTK_IS_ENTRY (entry));
7795 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7799 if ((icon_info = priv->icons[icon_pos]) == NULL)
7800 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7802 g_object_freeze_notify (G_OBJECT (entry));
7804 /* need to ref before clearing */
7806 g_object_ref (icon);
7808 gtk_entry_clear (entry, icon_pos);
7812 icon_info->storage_type = GTK_IMAGE_GICON;
7813 icon_info->gicon = icon;
7815 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7817 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7818 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7822 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7823 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7826 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7827 gdk_window_show_unraised (icon_info->window);
7830 gtk_entry_ensure_pixbuf (entry, icon_pos);
7832 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7833 gtk_widget_queue_resize (GTK_WIDGET (entry));
7835 g_object_thaw_notify (G_OBJECT (entry));
7839 * gtk_entry_set_icon_activatable:
7840 * @entry: A #GtkEntry
7841 * @icon_pos: Icon position
7842 * @activatable: %TRUE if the icon should be activatable
7844 * Sets whether the icon is activatable.
7849 gtk_entry_set_icon_activatable (GtkEntry *entry,
7850 GtkEntryIconPosition icon_pos,
7851 gboolean activatable)
7853 GtkEntryPrivate *priv;
7854 EntryIconInfo *icon_info;
7856 g_return_if_fail (GTK_IS_ENTRY (entry));
7857 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7861 if ((icon_info = priv->icons[icon_pos]) == NULL)
7862 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7864 activatable = activatable != FALSE;
7866 if (icon_info->nonactivatable != !activatable)
7868 icon_info->nonactivatable = !activatable;
7870 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7871 update_cursors (GTK_WIDGET (entry));
7873 g_object_notify (G_OBJECT (entry),
7874 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7879 * gtk_entry_get_icon_activatable:
7880 * @entry: a #GtkEntry
7881 * @icon_pos: Icon position
7883 * Returns whether the icon is activatable.
7885 * Returns: %TRUE if the icon is activatable.
7890 gtk_entry_get_icon_activatable (GtkEntry *entry,
7891 GtkEntryIconPosition icon_pos)
7893 GtkEntryPrivate *priv;
7894 EntryIconInfo *icon_info;
7896 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7897 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7900 icon_info = priv->icons[icon_pos];
7902 return (!icon_info || !icon_info->nonactivatable);
7906 * gtk_entry_get_icon_pixbuf:
7907 * @entry: A #GtkEntry
7908 * @icon_pos: Icon position
7910 * Retrieves the image used for the icon.
7912 * Unlike the other methods of setting and getting icon data, this
7913 * method will work regardless of whether the icon was set using a
7914 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7916 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7917 * set for this position.
7922 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7923 GtkEntryIconPosition icon_pos)
7925 GtkEntryPrivate *priv;
7926 EntryIconInfo *icon_info;
7928 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7929 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7933 icon_info = priv->icons[icon_pos];
7938 gtk_entry_ensure_pixbuf (entry, icon_pos);
7940 return icon_info->pixbuf;
7944 * gtk_entry_get_icon_gicon:
7945 * @entry: A #GtkEntry
7946 * @icon_pos: Icon position
7948 * Retrieves the #GIcon used for the icon, or %NULL if there is
7949 * no icon or if the icon was set by some other method (e.g., by
7950 * stock, pixbuf, or icon name).
7952 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7953 * or if the icon is not a #GIcon
7958 gtk_entry_get_icon_gicon (GtkEntry *entry,
7959 GtkEntryIconPosition icon_pos)
7961 GtkEntryPrivate *priv;
7962 EntryIconInfo *icon_info;
7964 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7965 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7968 icon_info = priv->icons[icon_pos];
7973 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7977 * gtk_entry_get_icon_stock:
7978 * @entry: A #GtkEntry
7979 * @icon_pos: Icon position
7981 * Retrieves the stock id used for the icon, or %NULL if there is
7982 * no icon or if the icon was set by some other method (e.g., by
7983 * pixbuf, icon name or gicon).
7985 * Returns: A stock id, or %NULL if no icon is set or if the icon
7986 * wasn't set from a stock id
7991 gtk_entry_get_icon_stock (GtkEntry *entry,
7992 GtkEntryIconPosition icon_pos)
7994 GtkEntryPrivate *priv;
7995 EntryIconInfo *icon_info;
7997 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7998 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8001 icon_info = priv->icons[icon_pos];
8006 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8010 * gtk_entry_get_icon_name:
8011 * @entry: A #GtkEntry
8012 * @icon_pos: Icon position
8014 * Retrieves the icon name used for the icon, or %NULL if there is
8015 * no icon or if the icon was set by some other method (e.g., by
8016 * pixbuf, stock or gicon).
8018 * Returns: An icon name, or %NULL if no icon is set or if the icon
8019 * wasn't set from an icon name
8024 gtk_entry_get_icon_name (GtkEntry *entry,
8025 GtkEntryIconPosition icon_pos)
8027 GtkEntryPrivate *priv;
8028 EntryIconInfo *icon_info;
8030 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8031 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8034 icon_info = priv->icons[icon_pos];
8039 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8043 * gtk_entry_set_icon_sensitive:
8044 * @entry: A #GtkEntry
8045 * @icon_pos: Icon position
8046 * @sensitive: Specifies whether the icon should appear
8047 * sensitive or insensitive
8049 * Sets the sensitivity for the specified icon.
8054 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8055 GtkEntryIconPosition icon_pos,
8058 GtkEntryPrivate *priv;
8059 EntryIconInfo *icon_info;
8061 g_return_if_fail (GTK_IS_ENTRY (entry));
8062 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8066 if ((icon_info = priv->icons[icon_pos]) == NULL)
8067 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8069 if (icon_info->insensitive != !sensitive)
8071 icon_info->insensitive = !sensitive;
8073 icon_info->pressed = FALSE;
8074 icon_info->prelight = FALSE;
8076 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8077 update_cursors (GTK_WIDGET (entry));
8079 gtk_widget_queue_draw (GTK_WIDGET (entry));
8081 g_object_notify (G_OBJECT (entry),
8082 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8087 * gtk_entry_get_icon_sensitive:
8088 * @entry: a #GtkEntry
8089 * @icon_pos: Icon position
8091 * Returns whether the icon appears sensitive or insensitive.
8093 * Returns: %TRUE if the icon is sensitive.
8098 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8099 GtkEntryIconPosition icon_pos)
8101 GtkEntryPrivate *priv;
8102 EntryIconInfo *icon_info;
8104 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8105 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8109 icon_info = priv->icons[icon_pos];
8111 return (!icon_info || !icon_info->insensitive);
8116 * gtk_entry_get_icon_storage_type:
8117 * @entry: a #GtkEntry
8118 * @icon_pos: Icon position
8120 * Gets the type of representation being used by the icon
8121 * to store image data. If the icon has no image data,
8122 * the return value will be %GTK_IMAGE_EMPTY.
8124 * Return value: image representation being used
8129 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8130 GtkEntryIconPosition icon_pos)
8132 GtkEntryPrivate *priv;
8133 EntryIconInfo *icon_info;
8135 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8136 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8140 icon_info = priv->icons[icon_pos];
8143 return GTK_IMAGE_EMPTY;
8145 return icon_info->storage_type;
8149 * gtk_entry_get_icon_at_pos:
8150 * @entry: a #GtkEntry
8151 * @x: the x coordinate of the position to find
8152 * @y: the y coordinate of the position to find
8154 * Finds the icon at the given position and return its index.
8155 * If @x, @y doesn't lie inside an icon, -1 is returned.
8156 * This function is intended for use in a #GtkWidget::query-tooltip
8159 * Returns: the index of the icon at the given position, or -1
8164 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8168 GtkAllocation primary;
8169 GtkAllocation secondary;
8170 gint frame_x, frame_y;
8172 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8174 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8178 get_icon_allocations (entry, &primary, &secondary);
8180 if (primary.x <= x && x < primary.x + primary.width &&
8181 primary.y <= y && y < primary.y + primary.height)
8182 return GTK_ENTRY_ICON_PRIMARY;
8184 if (secondary.x <= x && x < secondary.x + secondary.width &&
8185 secondary.y <= y && y < secondary.y + secondary.height)
8186 return GTK_ENTRY_ICON_SECONDARY;
8192 * gtk_entry_set_icon_drag_source:
8193 * @entry: a #GtkIconEntry
8194 * @icon_pos: icon position
8195 * @target_list: the targets (data formats) in which the data can be provided
8196 * @actions: a bitmask of the allowed drag actions
8198 * Sets up the icon at the given position so that GTK+ will start a drag
8199 * operation when the user clicks and drags the icon.
8201 * To handle the drag operation, you need to connect to the usual
8202 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8203 * signal, and use gtk_entry_get_current_icon_drag_source() in
8204 * your signal handler to find out if the drag was started from
8207 * By default, GTK+ uses the icon as the drag icon. You can use the
8208 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8209 * have to use g_signal_connect_after() to ensure that your signal handler
8210 * gets executed after the default handler.
8215 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8216 GtkEntryIconPosition icon_pos,
8217 GtkTargetList *target_list,
8218 GdkDragAction actions)
8220 GtkEntryPrivate *priv;
8221 EntryIconInfo *icon_info;
8223 g_return_if_fail (GTK_IS_ENTRY (entry));
8224 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8228 if ((icon_info = priv->icons[icon_pos]) == NULL)
8229 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8231 if (icon_info->target_list)
8232 gtk_target_list_unref (icon_info->target_list);
8233 icon_info->target_list = target_list;
8234 if (icon_info->target_list)
8235 gtk_target_list_ref (icon_info->target_list);
8237 icon_info->actions = actions;
8241 * gtk_entry_get_current_icon_drag_source:
8242 * @entry: a #GtkIconEntry
8244 * Returns the index of the icon which is the source of the current
8245 * DND operation, or -1.
8247 * This function is meant to be used in a #GtkWidget::drag-data-get
8250 * Returns: index of the icon which is the source of the current
8251 * DND operation, or -1.
8256 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8258 GtkEntryPrivate *priv;
8259 EntryIconInfo *icon_info = NULL;
8262 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8266 for (i = 0; i < MAX_ICONS; i++)
8268 if ((icon_info = priv->icons[i]))
8270 if (icon_info->in_drag)
8279 * gtk_entry_get_icon_area:
8280 * @entry: A #GtkEntry
8281 * @icon_pos: Icon position
8282 * @icon_area: (out): Return location for the icon's area
8284 * Gets the area where entry's icon at @icon_pos is drawn.
8285 * This function is useful when drawing something to the
8286 * entry in a draw callback.
8288 * If the entry is not realized or has no icon at the given position,
8289 * @icon_area is filled with zeros.
8291 * See also gtk_entry_get_text_area()
8296 gtk_entry_get_icon_area (GtkEntry *entry,
8297 GtkEntryIconPosition icon_pos,
8298 GdkRectangle *icon_area)
8300 GtkEntryPrivate *priv;
8301 EntryIconInfo *icon_info;
8303 g_return_if_fail (GTK_IS_ENTRY (entry));
8304 g_return_if_fail (icon_area != NULL);
8308 icon_info = priv->icons[icon_pos];
8312 GtkAllocation primary;
8313 GtkAllocation secondary;
8315 get_icon_allocations (entry, &primary, &secondary);
8317 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8318 *icon_area = primary;
8320 *icon_area = secondary;
8326 icon_area->width = 0;
8327 icon_area->height = 0;
8332 ensure_has_tooltip (GtkEntry *entry)
8334 GtkEntryPrivate *priv;
8335 EntryIconInfo *icon_info;
8337 gboolean has_tooltip = FALSE;
8341 for (i = 0; i < MAX_ICONS; i++)
8343 if ((icon_info = priv->icons[i]) != NULL)
8345 if (icon_info->tooltip != NULL)
8353 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8357 * gtk_entry_get_icon_tooltip_text:
8358 * @entry: a #GtkEntry
8359 * @icon_pos: the icon position
8361 * Gets the contents of the tooltip on the icon at the specified
8362 * position in @entry.
8364 * Returns: the tooltip text, or %NULL. Free the returned string
8365 * with g_free() when done.
8370 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8371 GtkEntryIconPosition icon_pos)
8373 GtkEntryPrivate *priv;
8374 EntryIconInfo *icon_info;
8377 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8378 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8382 icon_info = priv->icons[icon_pos];
8387 if (icon_info->tooltip &&
8388 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8389 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8395 * gtk_entry_set_icon_tooltip_text:
8396 * @entry: a #GtkEntry
8397 * @icon_pos: the icon position
8398 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8400 * Sets @tooltip as the contents of the tooltip for the icon
8401 * at the specified position.
8403 * Use %NULL for @tooltip to remove an existing tooltip.
8405 * See also gtk_widget_set_tooltip_text() and
8406 * gtk_entry_set_icon_tooltip_markup().
8411 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8412 GtkEntryIconPosition icon_pos,
8413 const gchar *tooltip)
8415 GtkEntryPrivate *priv;
8416 EntryIconInfo *icon_info;
8418 g_return_if_fail (GTK_IS_ENTRY (entry));
8419 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8423 if ((icon_info = priv->icons[icon_pos]) == NULL)
8424 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8426 if (icon_info->tooltip)
8427 g_free (icon_info->tooltip);
8429 /* Treat an empty string as a NULL string,
8430 * because an empty string would be useless for a tooltip:
8432 if (tooltip && tooltip[0] == '\0')
8435 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8437 ensure_has_tooltip (entry);
8441 * gtk_entry_get_icon_tooltip_markup:
8442 * @entry: a #GtkEntry
8443 * @icon_pos: the icon position
8445 * Gets the contents of the tooltip on the icon at the specified
8446 * position in @entry.
8448 * Returns: the tooltip text, or %NULL. Free the returned string
8449 * with g_free() when done.
8454 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8455 GtkEntryIconPosition icon_pos)
8457 GtkEntryPrivate *priv;
8458 EntryIconInfo *icon_info;
8460 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8461 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8465 icon_info = priv->icons[icon_pos];
8470 return g_strdup (icon_info->tooltip);
8474 * gtk_entry_set_icon_tooltip_markup:
8475 * @entry: a #GtkEntry
8476 * @icon_pos: the icon position
8477 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8479 * Sets @tooltip as the contents of the tooltip for the icon at
8480 * the specified position. @tooltip is assumed to be marked up with
8481 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8483 * Use %NULL for @tooltip to remove an existing tooltip.
8485 * See also gtk_widget_set_tooltip_markup() and
8486 * gtk_enty_set_icon_tooltip_text().
8491 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8492 GtkEntryIconPosition icon_pos,
8493 const gchar *tooltip)
8495 GtkEntryPrivate *priv;
8496 EntryIconInfo *icon_info;
8498 g_return_if_fail (GTK_IS_ENTRY (entry));
8499 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8503 if ((icon_info = priv->icons[icon_pos]) == NULL)
8504 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8506 if (icon_info->tooltip)
8507 g_free (icon_info->tooltip);
8509 /* Treat an empty string as a NULL string,
8510 * because an empty string would be useless for a tooltip:
8512 if (tooltip && tooltip[0] == '\0')
8515 icon_info->tooltip = g_strdup (tooltip);
8517 ensure_has_tooltip (entry);
8521 gtk_entry_query_tooltip (GtkWidget *widget,
8524 gboolean keyboard_tip,
8525 GtkTooltip *tooltip)
8528 GtkEntryPrivate *priv;
8529 EntryIconInfo *icon_info;
8532 entry = GTK_ENTRY (widget);
8537 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8540 if ((icon_info = priv->icons[icon_pos]) != NULL)
8542 if (icon_info->tooltip)
8544 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8553 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8560 /* Quick hack of a popup menu
8563 activate_cb (GtkWidget *menuitem,
8566 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8567 g_signal_emit_by_name (entry, signal);
8572 gtk_entry_mnemonic_activate (GtkWidget *widget,
8573 gboolean group_cycling)
8575 gtk_widget_grab_focus (widget);
8580 append_action_signal (GtkEntry *entry,
8582 const gchar *stock_id,
8583 const gchar *signal,
8586 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8588 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8589 g_signal_connect (menuitem, "activate",
8590 G_CALLBACK (activate_cb), entry);
8592 gtk_widget_set_sensitive (menuitem, sensitive);
8594 gtk_widget_show (menuitem);
8595 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8599 popup_menu_detach (GtkWidget *attach_widget,
8602 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8603 GtkEntryPrivate *priv_attach = entry_attach->priv;
8605 priv_attach->popup_menu = NULL;
8609 popup_position_func (GtkMenu *menu,
8615 GtkEntry *entry = GTK_ENTRY (user_data);
8616 GtkEntryPrivate *priv = entry->priv;
8617 GtkWidget *widget = GTK_WIDGET (entry);
8619 GtkRequisition menu_req;
8620 GdkRectangle monitor;
8621 GtkBorder inner_border;
8622 gint monitor_num, strong_x, height;
8624 g_return_if_fail (gtk_widget_get_realized (widget));
8626 gdk_window_get_origin (priv->text_area, x, y);
8628 screen = gtk_widget_get_screen (widget);
8629 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8630 if (monitor_num < 0)
8632 gtk_menu_set_monitor (menu, monitor_num);
8634 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8635 gtk_widget_get_preferred_size (priv->popup_menu,
8637 height = gdk_window_get_height (priv->text_area);
8638 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8639 _gtk_entry_effective_inner_border (entry, &inner_border);
8641 *x += inner_border.left + strong_x - priv->scroll_offset;
8642 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8643 *x -= menu_req.width;
8645 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8647 else if ((*y - menu_req.height) >= monitor.y)
8648 *y -= menu_req.height;
8649 else if (monitor.y + monitor.height - (*y + height) > *y)
8652 *y -= menu_req.height;
8658 unichar_chosen_func (const char *text,
8661 GtkEntry *entry = GTK_ENTRY (data);
8662 GtkEntryPrivate *priv = entry->priv;
8665 gtk_entry_enter_text (entry, text);
8676 popup_targets_received (GtkClipboard *clipboard,
8677 GtkSelectionData *data,
8680 PopupInfo *info = user_data;
8681 GtkEntry *entry = info->entry;
8682 GtkEntryPrivate *info_entry_priv = entry->priv;
8684 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8687 gboolean clipboard_contains_text;
8688 GtkWidget *menuitem;
8690 gboolean show_input_method_menu;
8691 gboolean show_unicode_menu;
8693 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8694 if (info_entry_priv->popup_menu)
8695 gtk_widget_destroy (info_entry_priv->popup_menu);
8697 info_entry_priv->popup_menu = gtk_menu_new ();
8699 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8703 mode = gtk_entry_get_display_mode (entry);
8704 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8705 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8706 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8708 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8709 mode == DISPLAY_NORMAL &&
8710 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8712 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8713 info_entry_priv->editable && clipboard_contains_text);
8715 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8716 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8717 g_signal_connect_swapped (menuitem, "activate",
8718 G_CALLBACK (gtk_entry_delete_cb), entry);
8719 gtk_widget_show (menuitem);
8720 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8722 menuitem = gtk_separator_menu_item_new ();
8723 gtk_widget_show (menuitem);
8724 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8726 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8727 g_signal_connect_swapped (menuitem, "activate",
8728 G_CALLBACK (gtk_entry_select_all), entry);
8729 gtk_widget_show (menuitem);
8730 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8732 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8733 "gtk-show-input-method-menu", &show_input_method_menu,
8734 "gtk-show-unicode-menu", &show_unicode_menu,
8737 if (show_input_method_menu || show_unicode_menu)
8739 menuitem = gtk_separator_menu_item_new ();
8740 gtk_widget_show (menuitem);
8741 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8744 if (show_input_method_menu)
8746 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8747 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8748 gtk_widget_show (menuitem);
8749 submenu = gtk_menu_new ();
8750 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8752 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8754 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8755 GTK_MENU_SHELL (submenu));
8758 if (show_unicode_menu)
8760 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8761 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8762 gtk_widget_show (menuitem);
8764 submenu = gtk_menu_new ();
8765 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8766 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8768 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8769 unichar_chosen_func,
8773 g_signal_emit (entry,
8774 signals[POPULATE_POPUP],
8776 info_entry_priv->popup_menu);
8780 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8782 info->button, info->time);
8785 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8786 popup_position_func, entry,
8787 info->button, info->time);
8788 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8792 g_object_unref (entry);
8793 g_slice_free (PopupInfo, info);
8797 gtk_entry_do_popup (GtkEntry *entry,
8798 GdkEventButton *event)
8800 PopupInfo *info = g_slice_new (PopupInfo);
8802 /* In order to know what entries we should make sensitive, we
8803 * ask for the current targets of the clipboard, and when
8804 * we get them, then we actually pop up the menu.
8806 info->entry = g_object_ref (entry);
8810 info->button = event->button;
8811 info->time = event->time;
8816 info->time = gtk_get_current_event_time ();
8819 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8820 gdk_atom_intern_static_string ("TARGETS"),
8821 popup_targets_received,
8826 gtk_entry_popup_menu (GtkWidget *widget)
8828 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8833 gtk_entry_drag_begin (GtkWidget *widget,
8834 GdkDragContext *context)
8836 GtkEntry *entry = GTK_ENTRY (widget);
8837 GtkEntryPrivate *priv = entry->priv;
8840 for (i = 0; i < MAX_ICONS; i++)
8842 EntryIconInfo *icon_info = priv->icons[i];
8844 if (icon_info != NULL)
8846 if (icon_info->in_drag)
8848 switch (icon_info->storage_type)
8850 case GTK_IMAGE_STOCK:
8851 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8854 case GTK_IMAGE_ICON_NAME:
8855 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8858 /* FIXME: No GIcon support for dnd icons */
8859 case GTK_IMAGE_GICON:
8860 case GTK_IMAGE_PIXBUF:
8861 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8864 g_assert_not_reached ();
8872 gtk_entry_drag_end (GtkWidget *widget,
8873 GdkDragContext *context)
8875 GtkEntry *entry = GTK_ENTRY (widget);
8876 GtkEntryPrivate *priv = entry->priv;
8879 for (i = 0; i < MAX_ICONS; i++)
8881 EntryIconInfo *icon_info = priv->icons[i];
8883 if (icon_info != NULL)
8884 icon_info->in_drag = 0;
8889 gtk_entry_drag_leave (GtkWidget *widget,
8890 GdkDragContext *context,
8893 GtkEntry *entry = GTK_ENTRY (widget);
8894 GtkEntryPrivate *priv = entry->priv;
8896 priv->dnd_position = -1;
8897 gtk_widget_queue_draw (widget);
8901 gtk_entry_drag_drop (GtkWidget *widget,
8902 GdkDragContext *context,
8907 GtkEntry *entry = GTK_ENTRY (widget);
8908 GtkEntryPrivate *priv = entry->priv;
8909 GdkAtom target = GDK_NONE;
8912 target = gtk_drag_dest_find_target (widget, context, NULL);
8914 if (target != GDK_NONE)
8915 gtk_drag_get_data (widget, context, target, time);
8917 gtk_drag_finish (context, FALSE, FALSE, time);
8923 gtk_entry_drag_motion (GtkWidget *widget,
8924 GdkDragContext *context,
8929 GtkEntry *entry = GTK_ENTRY (widget);
8930 GtkEntryPrivate *priv = entry->priv;
8931 GtkStyleContext *style_context;
8932 GtkWidget *source_widget;
8933 GdkDragAction suggested_action;
8934 gint new_position, old_position;
8938 style_context = gtk_widget_get_style_context (widget);
8939 gtk_style_context_get_padding (style_context, 0, &padding);
8943 old_position = priv->dnd_position;
8944 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8946 if (priv->editable &&
8947 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8949 source_widget = gtk_drag_get_source_widget (context);
8950 suggested_action = gdk_drag_context_get_suggested_action (context);
8952 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8953 new_position < sel1 || new_position > sel2)
8955 if (source_widget == widget)
8957 /* Default to MOVE, unless the user has
8958 * pressed ctrl or alt to affect available actions
8960 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8961 suggested_action = GDK_ACTION_MOVE;
8964 priv->dnd_position = new_position;
8968 if (source_widget == widget)
8969 suggested_action = 0; /* Can't drop in selection where drag started */
8971 priv->dnd_position = -1;
8976 /* Entry not editable, or no text */
8977 suggested_action = 0;
8978 priv->dnd_position = -1;
8981 gdk_drag_status (context, suggested_action, time);
8983 if (priv->dnd_position != old_position)
8984 gtk_widget_queue_draw (widget);
8990 gtk_entry_drag_data_received (GtkWidget *widget,
8991 GdkDragContext *context,
8994 GtkSelectionData *selection_data,
8998 GtkEntry *entry = GTK_ENTRY (widget);
8999 GtkEntryPrivate *priv = entry->priv;
9000 GtkEditable *editable = GTK_EDITABLE (widget);
9001 GtkStyleContext *style_context;
9005 str = (gchar *) gtk_selection_data_get_text (selection_data);
9007 style_context = gtk_widget_get_style_context (widget);
9008 gtk_style_context_get_padding (style_context, 0, &padding);
9012 if (str && priv->editable)
9018 if (priv->truncate_multiline)
9019 length = truncate_multiline (str);
9021 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9023 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9024 new_position < sel1 || new_position > sel2)
9026 gtk_editable_insert_text (editable, str, length, &new_position);
9030 /* Replacing selection */
9031 begin_change (entry);
9032 g_object_freeze_notify (G_OBJECT (entry));
9033 gtk_editable_delete_text (editable, sel1, sel2);
9034 gtk_editable_insert_text (editable, str, length, &sel1);
9035 g_object_thaw_notify (G_OBJECT (entry));
9039 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9043 /* Drag and drop didn't happen! */
9044 gtk_drag_finish (context, FALSE, FALSE, time);
9051 gtk_entry_drag_data_get (GtkWidget *widget,
9052 GdkDragContext *context,
9053 GtkSelectionData *selection_data,
9057 GtkEntry *entry = GTK_ENTRY (widget);
9058 GtkEntryPrivate *priv = entry->priv;
9059 GtkEditable *editable = GTK_EDITABLE (widget);
9060 gint sel_start, sel_end;
9063 /* If there is an icon drag going on, exit early. */
9064 for (i = 0; i < MAX_ICONS; i++)
9066 EntryIconInfo *icon_info = priv->icons[i];
9068 if (icon_info != NULL)
9070 if (icon_info->in_drag)
9075 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9077 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9079 gtk_selection_data_set_text (selection_data, str, -1);
9087 gtk_entry_drag_data_delete (GtkWidget *widget,
9088 GdkDragContext *context)
9090 GtkEntry *entry = GTK_ENTRY (widget);
9091 GtkEntryPrivate *priv = entry->priv;
9092 GtkEditable *editable = GTK_EDITABLE (widget);
9093 gint sel_start, sel_end;
9096 /* If there is an icon drag going on, exit early. */
9097 for (i = 0; i < MAX_ICONS; i++)
9099 EntryIconInfo *icon_info = priv->icons[i];
9101 if (icon_info != NULL)
9103 if (icon_info->in_drag)
9108 if (priv->editable &&
9109 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9110 gtk_editable_delete_text (editable, sel_start, sel_end);
9113 /* We display the cursor when
9115 * - the selection is empty, AND
9116 * - the widget has focus
9119 #define CURSOR_ON_MULTIPLIER 2
9120 #define CURSOR_OFF_MULTIPLIER 1
9121 #define CURSOR_PEND_MULTIPLIER 3
9122 #define CURSOR_DIVIDER 3
9125 cursor_blinks (GtkEntry *entry)
9127 GtkEntryPrivate *priv = entry->priv;
9129 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9131 priv->selection_bound == priv->current_pos)
9133 GtkSettings *settings;
9136 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9137 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9146 get_cursor_time (GtkEntry *entry)
9148 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9151 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9157 get_cursor_blink_timeout (GtkEntry *entry)
9159 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9162 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9168 show_cursor (GtkEntry *entry)
9170 GtkEntryPrivate *priv = entry->priv;
9173 if (!priv->cursor_visible)
9175 priv->cursor_visible = TRUE;
9177 widget = GTK_WIDGET (entry);
9178 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9179 gtk_widget_queue_draw (widget);
9184 hide_cursor (GtkEntry *entry)
9186 GtkEntryPrivate *priv = entry->priv;
9189 if (priv->cursor_visible)
9191 priv->cursor_visible = FALSE;
9193 widget = GTK_WIDGET (entry);
9194 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9195 gtk_widget_queue_draw (widget);
9203 blink_cb (gpointer data)
9206 GtkEntryPrivate *priv;
9209 entry = GTK_ENTRY (data);
9212 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9214 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9215 "connect a handler to this signal, it must return\n"
9216 "FALSE so the entry gets the event as well");
9218 gtk_entry_check_cursor_blink (entry);
9223 g_assert (priv->selection_bound == priv->current_pos);
9225 blink_timeout = get_cursor_blink_timeout (entry);
9226 if (priv->blink_time > 1000 * blink_timeout &&
9227 blink_timeout < G_MAXINT/1000)
9229 /* we've blinked enough without the user doing anything, stop blinking */
9230 show_cursor (entry);
9231 priv->blink_timeout = 0;
9233 else if (priv->cursor_visible)
9235 hide_cursor (entry);
9236 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9242 show_cursor (entry);
9243 priv->blink_time += get_cursor_time (entry);
9244 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9249 /* Remove ourselves */
9254 gtk_entry_check_cursor_blink (GtkEntry *entry)
9256 GtkEntryPrivate *priv = entry->priv;
9258 if (cursor_blinks (entry))
9260 if (!priv->blink_timeout)
9262 show_cursor (entry);
9263 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9270 if (priv->blink_timeout)
9272 g_source_remove (priv->blink_timeout);
9273 priv->blink_timeout = 0;
9276 priv->cursor_visible = TRUE;
9281 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9283 GtkEntryPrivate *priv = entry->priv;
9285 if (cursor_blinks (entry))
9287 if (priv->blink_timeout != 0)
9288 g_source_remove (priv->blink_timeout);
9290 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9293 show_cursor (entry);
9298 gtk_entry_reset_blink_time (GtkEntry *entry)
9300 GtkEntryPrivate *priv = entry->priv;
9302 priv->blink_time = 0;
9308 gtk_entry_completion_timeout (gpointer data)
9310 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9311 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9313 completion->priv->completion_timeout = 0;
9315 if (completion->priv->filter_model &&
9316 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9317 >= completion->priv->minimum_key_length)
9321 GtkTreeSelection *s;
9322 gboolean popup_single;
9324 gtk_entry_completion_complete (completion);
9325 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9327 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9329 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9331 gtk_tree_selection_unselect_all (s);
9333 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9335 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9336 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9338 if (gtk_widget_get_visible (completion->priv->popup_window))
9339 _gtk_entry_completion_resize_popup (completion);
9341 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9344 _gtk_entry_completion_popdown (completion);
9346 else if (gtk_widget_get_visible (completion->priv->popup_window))
9347 _gtk_entry_completion_popdown (completion);
9352 static inline gboolean
9353 keyval_is_cursor_move (guint keyval)
9355 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9358 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9361 if (keyval == GDK_KEY_Page_Up)
9364 if (keyval == GDK_KEY_Page_Down)
9371 gtk_entry_completion_key_press (GtkWidget *widget,
9375 gint matches, actions = 0;
9376 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9378 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9381 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9383 if (completion->priv->actions)
9384 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9386 if (keyval_is_cursor_move (event->keyval))
9388 GtkTreePath *path = NULL;
9390 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9392 if (completion->priv->current_selected < 0)
9393 completion->priv->current_selected = matches + actions - 1;
9395 completion->priv->current_selected--;
9397 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9399 if (completion->priv->current_selected < matches + actions - 1)
9400 completion->priv->current_selected++;
9402 completion->priv->current_selected = -1;
9404 else if (event->keyval == GDK_KEY_Page_Up)
9406 if (completion->priv->current_selected < 0)
9407 completion->priv->current_selected = matches + actions - 1;
9408 else if (completion->priv->current_selected == 0)
9409 completion->priv->current_selected = -1;
9410 else if (completion->priv->current_selected < matches)
9412 completion->priv->current_selected -= 14;
9413 if (completion->priv->current_selected < 0)
9414 completion->priv->current_selected = 0;
9418 completion->priv->current_selected -= 14;
9419 if (completion->priv->current_selected < matches - 1)
9420 completion->priv->current_selected = matches - 1;
9423 else if (event->keyval == GDK_KEY_Page_Down)
9425 if (completion->priv->current_selected < 0)
9426 completion->priv->current_selected = 0;
9427 else if (completion->priv->current_selected < matches - 1)
9429 completion->priv->current_selected += 14;
9430 if (completion->priv->current_selected > matches - 1)
9431 completion->priv->current_selected = matches - 1;
9433 else if (completion->priv->current_selected == matches + actions - 1)
9435 completion->priv->current_selected = -1;
9439 completion->priv->current_selected += 14;
9440 if (completion->priv->current_selected > matches + actions - 1)
9441 completion->priv->current_selected = matches + actions - 1;
9445 if (completion->priv->current_selected < 0)
9447 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9448 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9450 if (completion->priv->inline_selection &&
9451 completion->priv->completion_prefix)
9453 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9454 completion->priv->completion_prefix);
9455 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9458 else if (completion->priv->current_selected < matches)
9460 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9462 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9463 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9466 if (completion->priv->inline_selection)
9470 GtkTreeIter child_iter;
9471 GtkTreeModel *model = NULL;
9472 GtkTreeSelection *sel;
9475 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9476 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9479 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9480 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9482 if (completion->priv->completion_prefix == NULL)
9483 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9485 g_signal_emit_by_name (completion, "cursor-on-match", model,
9486 &child_iter, &entry_set);
9489 else if (completion->priv->current_selected - matches >= 0)
9491 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9493 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9494 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9497 if (completion->priv->inline_selection &&
9498 completion->priv->completion_prefix)
9500 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9501 completion->priv->completion_prefix);
9502 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9506 gtk_tree_path_free (path);
9510 else if (event->keyval == GDK_KEY_Escape ||
9511 event->keyval == GDK_KEY_Left ||
9512 event->keyval == GDK_KEY_KP_Left ||
9513 event->keyval == GDK_KEY_Right ||
9514 event->keyval == GDK_KEY_KP_Right)
9516 gboolean retval = TRUE;
9518 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9519 _gtk_entry_completion_popdown (completion);
9521 if (completion->priv->current_selected < 0)
9524 goto keypress_completion_out;
9526 else if (completion->priv->inline_selection)
9528 /* Escape rejects the tentative completion */
9529 if (event->keyval == GDK_KEY_Escape)
9531 if (completion->priv->completion_prefix)
9532 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9533 completion->priv->completion_prefix);
9535 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9538 /* Move the cursor to the end for Right/Esc, to the
9539 beginning for Left */
9540 if (event->keyval == GDK_KEY_Right ||
9541 event->keyval == GDK_KEY_KP_Right ||
9542 event->keyval == GDK_KEY_Escape)
9543 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9545 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9548 keypress_completion_out:
9549 if (completion->priv->inline_selection)
9551 g_free (completion->priv->completion_prefix);
9552 completion->priv->completion_prefix = NULL;
9557 else if (event->keyval == GDK_KEY_Tab ||
9558 event->keyval == GDK_KEY_KP_Tab ||
9559 event->keyval == GDK_KEY_ISO_Left_Tab)
9561 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9562 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9564 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9565 _gtk_entry_completion_popdown (completion);
9567 g_free (completion->priv->completion_prefix);
9568 completion->priv->completion_prefix = NULL;
9570 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9574 else if (event->keyval == GDK_KEY_ISO_Enter ||
9575 event->keyval == GDK_KEY_KP_Enter ||
9576 event->keyval == GDK_KEY_Return)
9579 GtkTreeModel *model = NULL;
9580 GtkTreeModel *child_model;
9581 GtkTreeIter child_iter;
9582 GtkTreeSelection *sel;
9583 gboolean retval = TRUE;
9585 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9586 _gtk_entry_completion_popdown (completion);
9588 if (completion->priv->current_selected < matches)
9592 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9593 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9595 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9596 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9597 g_signal_handler_block (widget, completion->priv->changed_id);
9598 g_signal_emit_by_name (completion, "match-selected",
9599 child_model, &child_iter, &entry_set);
9600 g_signal_handler_unblock (widget, completion->priv->changed_id);
9606 gtk_tree_model_get (model, &iter,
9607 completion->priv->text_column, &str,
9610 gtk_entry_set_text (GTK_ENTRY (widget), str);
9612 /* move the cursor to the end */
9613 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9621 else if (completion->priv->current_selected - matches >= 0)
9623 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9624 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9628 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9629 g_signal_emit_by_name (completion, "action-activated",
9630 gtk_tree_path_get_indices (path)[0]);
9631 gtk_tree_path_free (path);
9637 g_free (completion->priv->completion_prefix);
9638 completion->priv->completion_prefix = NULL;
9647 gtk_entry_completion_changed (GtkWidget *widget,
9650 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9651 GtkEntry *entry = GTK_ENTRY (widget);
9652 GtkEntryPrivate *priv = entry->priv;
9655 /* (re)install completion timeout */
9656 if (completion->priv->completion_timeout)
9657 g_source_remove (completion->priv->completion_timeout);
9659 if (!gtk_entry_get_text (entry))
9662 /* no need to normalize for this test */
9663 if (completion->priv->minimum_key_length > 0 &&
9664 strcmp ("", gtk_entry_get_text (entry)) == 0)
9666 if (gtk_widget_get_visible (completion->priv->popup_window))
9667 _gtk_entry_completion_popdown (completion);
9671 device = gtk_get_current_event_device ();
9673 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9674 device = gdk_device_get_associated_device (device);
9677 priv->completion_device = device;
9679 completion->priv->completion_timeout =
9680 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9681 gtk_entry_completion_timeout,
9686 check_completion_callback (GtkEntryCompletion *completion)
9688 completion->priv->check_completion_idle = NULL;
9690 gtk_entry_completion_complete (completion);
9691 gtk_entry_completion_insert_prefix (completion);
9697 clear_completion_callback (GtkEntry *entry,
9700 if (pspec->name == I_("cursor-position") ||
9701 pspec->name == I_("selection-bound"))
9703 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9705 completion->priv->has_completion = FALSE;
9710 accept_completion_callback (GtkEntry *entry)
9712 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9714 if (completion->priv->has_completion)
9715 gtk_editable_set_position (GTK_EDITABLE (entry),
9716 gtk_entry_buffer_get_length (get_buffer (entry)));
9722 completion_insert_text_callback (GtkEntry *entry,
9726 GtkEntryCompletion *completion)
9728 /* idle to update the selection based on the file list */
9729 if (completion->priv->check_completion_idle == NULL)
9731 completion->priv->check_completion_idle = g_idle_source_new ();
9732 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9733 g_source_set_closure (completion->priv->check_completion_idle,
9734 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9735 G_OBJECT (completion)));
9736 g_source_attach (completion->priv->check_completion_idle, NULL);
9741 completion_changed (GtkEntryCompletion *completion,
9745 GtkEntry *entry = GTK_ENTRY (data);
9747 if (pspec->name == I_("popup-completion") ||
9748 pspec->name == I_("inline-completion"))
9750 disconnect_completion_signals (entry, completion);
9751 connect_completion_signals (entry, completion);
9756 disconnect_completion_signals (GtkEntry *entry,
9757 GtkEntryCompletion *completion)
9759 g_signal_handlers_disconnect_by_func (completion,
9760 G_CALLBACK (completion_changed), entry);
9761 if (completion->priv->changed_id > 0 &&
9762 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9764 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9765 completion->priv->changed_id = 0;
9767 g_signal_handlers_disconnect_by_func (entry,
9768 G_CALLBACK (gtk_entry_completion_key_press), completion);
9769 if (completion->priv->insert_text_id > 0 &&
9770 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9772 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9773 completion->priv->insert_text_id = 0;
9775 g_signal_handlers_disconnect_by_func (entry,
9776 G_CALLBACK (completion_insert_text_callback), completion);
9777 g_signal_handlers_disconnect_by_func (entry,
9778 G_CALLBACK (clear_completion_callback), completion);
9779 g_signal_handlers_disconnect_by_func (entry,
9780 G_CALLBACK (accept_completion_callback), completion);
9784 connect_completion_signals (GtkEntry *entry,
9785 GtkEntryCompletion *completion)
9787 if (completion->priv->popup_completion)
9789 completion->priv->changed_id =
9790 g_signal_connect (entry, "changed",
9791 G_CALLBACK (gtk_entry_completion_changed), completion);
9792 g_signal_connect (entry, "key-press-event",
9793 G_CALLBACK (gtk_entry_completion_key_press), completion);
9796 if (completion->priv->inline_completion)
9798 completion->priv->insert_text_id =
9799 g_signal_connect (entry, "insert-text",
9800 G_CALLBACK (completion_insert_text_callback), completion);
9801 g_signal_connect (entry, "notify",
9802 G_CALLBACK (clear_completion_callback), completion);
9803 g_signal_connect (entry, "activate",
9804 G_CALLBACK (accept_completion_callback), completion);
9805 g_signal_connect (entry, "focus-out-event",
9806 G_CALLBACK (accept_completion_callback), completion);
9809 g_signal_connect (completion, "notify",
9810 G_CALLBACK (completion_changed), entry);
9814 * gtk_entry_set_completion:
9815 * @entry: A #GtkEntry
9816 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9818 * Sets @completion to be the auxiliary completion object to use with @entry.
9819 * All further configuration of the completion mechanism is done on
9820 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9821 * @completion is set to %NULL.
9826 gtk_entry_set_completion (GtkEntry *entry,
9827 GtkEntryCompletion *completion)
9829 GtkEntryCompletion *old;
9831 g_return_if_fail (GTK_IS_ENTRY (entry));
9832 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9834 old = gtk_entry_get_completion (entry);
9836 if (old == completion)
9841 if (old->priv->completion_timeout)
9843 g_source_remove (old->priv->completion_timeout);
9844 old->priv->completion_timeout = 0;
9847 if (gtk_widget_get_mapped (old->priv->popup_window))
9848 _gtk_entry_completion_popdown (old);
9850 disconnect_completion_signals (entry, old);
9851 old->priv->entry = NULL;
9853 g_object_unref (old);
9858 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9862 /* hook into the entry */
9863 g_object_ref (completion);
9865 connect_completion_signals (entry, completion);
9866 completion->priv->entry = GTK_WIDGET (entry);
9867 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9871 * gtk_entry_get_completion:
9872 * @entry: A #GtkEntry
9874 * Returns the auxiliary completion object currently in use by @entry.
9876 * Return value: (transfer none): The auxiliary completion object currently
9881 GtkEntryCompletion *
9882 gtk_entry_get_completion (GtkEntry *entry)
9884 GtkEntryCompletion *completion;
9886 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9888 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9889 GTK_ENTRY_COMPLETION_KEY));
9895 * gtk_entry_set_cursor_hadjustment:
9896 * @entry: a #GtkEntry
9897 * @adjustment: an adjustment which should be adjusted when the cursor
9898 * is moved, or %NULL
9900 * Hooks up an adjustment to the cursor position in an entry, so that when
9901 * the cursor is moved, the adjustment is scrolled to show that position.
9902 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9905 * The adjustment has to be in pixel units and in the same coordinate system
9911 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9912 GtkAdjustment *adjustment)
9914 g_return_if_fail (GTK_IS_ENTRY (entry));
9916 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9919 g_object_ref (adjustment);
9921 g_object_set_qdata_full (G_OBJECT (entry),
9922 quark_cursor_hadjustment,
9928 * gtk_entry_get_cursor_hadjustment:
9929 * @entry: a #GtkEntry
9931 * Retrieves the horizontal cursor adjustment for the entry.
9932 * See gtk_entry_set_cursor_hadjustment().
9934 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9935 * if none has been set.
9940 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9942 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9944 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9948 * gtk_entry_set_progress_fraction:
9949 * @entry: a #GtkEntry
9950 * @fraction: fraction of the task that's been completed
9952 * Causes the entry's progress indicator to "fill in" the given
9953 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9959 gtk_entry_set_progress_fraction (GtkEntry *entry,
9963 GtkEntryPrivate *private;
9964 gdouble old_fraction;
9965 gint x, y, width, height;
9966 gint old_x, old_y, old_width, old_height;
9968 g_return_if_fail (GTK_IS_ENTRY (entry));
9970 widget = GTK_WIDGET (entry);
9971 private = entry->priv;
9973 if (private->progress_pulse_mode)
9976 old_fraction = private->progress_fraction;
9978 if (gtk_widget_is_drawable (widget))
9979 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9981 fraction = CLAMP (fraction, 0.0, 1.0);
9983 private->progress_fraction = fraction;
9984 private->progress_pulse_mode = FALSE;
9985 private->progress_pulse_current = 0.0;
9987 if (gtk_widget_is_drawable (widget))
9989 get_progress_area (widget, &x, &y, &width, &height);
9991 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9992 gtk_widget_queue_draw (widget);
9995 if (fraction != old_fraction)
9996 g_object_notify (G_OBJECT (entry), "progress-fraction");
10000 * gtk_entry_get_progress_fraction:
10001 * @entry: a #GtkEntry
10003 * Returns the current fraction of the task that's been completed.
10004 * See gtk_entry_set_progress_fraction().
10006 * Return value: a fraction from 0.0 to 1.0
10011 gtk_entry_get_progress_fraction (GtkEntry *entry)
10013 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10015 return entry->priv->progress_fraction;
10019 * gtk_entry_set_progress_pulse_step:
10020 * @entry: a #GtkEntry
10021 * @fraction: fraction between 0.0 and 1.0
10023 * Sets the fraction of total entry width to move the progress
10024 * bouncing block for each call to gtk_entry_progress_pulse().
10029 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10032 GtkEntryPrivate *private;
10034 g_return_if_fail (GTK_IS_ENTRY (entry));
10036 private = entry->priv;
10038 fraction = CLAMP (fraction, 0.0, 1.0);
10040 if (fraction != private->progress_pulse_fraction)
10042 private->progress_pulse_fraction = fraction;
10044 gtk_widget_queue_draw (GTK_WIDGET (entry));
10046 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10051 * gtk_entry_get_progress_pulse_step:
10052 * @entry: a #GtkEntry
10054 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10056 * Return value: a fraction from 0.0 to 1.0
10061 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10063 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10065 return entry->priv->progress_pulse_fraction;
10069 * gtk_entry_progress_pulse:
10070 * @entry: a #GtkEntry
10072 * Indicates that some progress is made, but you don't know how much.
10073 * Causes the entry's progress indicator to enter "activity mode,"
10074 * where a block bounces back and forth. Each call to
10075 * gtk_entry_progress_pulse() causes the block to move by a little bit
10076 * (the amount of movement per pulse is determined by
10077 * gtk_entry_set_progress_pulse_step()).
10082 gtk_entry_progress_pulse (GtkEntry *entry)
10084 GtkEntryPrivate *private;
10086 g_return_if_fail (GTK_IS_ENTRY (entry));
10088 private = entry->priv;
10090 if (private->progress_pulse_mode)
10092 if (private->progress_pulse_way_back)
10094 private->progress_pulse_current -= private->progress_pulse_fraction;
10096 if (private->progress_pulse_current < 0.0)
10098 private->progress_pulse_current = 0.0;
10099 private->progress_pulse_way_back = FALSE;
10104 private->progress_pulse_current += private->progress_pulse_fraction;
10106 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10108 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10109 private->progress_pulse_way_back = TRUE;
10115 private->progress_fraction = 0.0;
10116 private->progress_pulse_mode = TRUE;
10117 private->progress_pulse_way_back = FALSE;
10118 private->progress_pulse_current = 0.0;
10121 gtk_widget_queue_draw (GTK_WIDGET (entry));
10124 /* Caps Lock warning for password entries */
10127 show_capslock_feedback (GtkEntry *entry,
10130 GtkEntryPrivate *priv = entry->priv;
10132 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10134 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10135 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10136 priv->caps_lock_warning_shown = TRUE;
10139 if (priv->caps_lock_warning_shown)
10140 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10142 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10146 remove_capslock_feedback (GtkEntry *entry)
10148 GtkEntryPrivate *priv = entry->priv;
10150 if (priv->caps_lock_warning_shown)
10152 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10153 priv->caps_lock_warning_shown = FALSE;
10158 keymap_state_changed (GdkKeymap *keymap,
10161 GtkEntryPrivate *priv = entry->priv;
10164 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10166 if (gdk_keymap_get_num_lock_state (keymap)
10167 && gdk_keymap_get_caps_lock_state (keymap))
10168 text = _("Caps Lock and Num Lock are on");
10169 else if (gdk_keymap_get_num_lock_state (keymap))
10170 text = _("Num Lock is on");
10171 else if (gdk_keymap_get_caps_lock_state (keymap))
10172 text = _("Caps Lock is on");
10176 show_capslock_feedback (entry, text);
10178 remove_capslock_feedback (entry);
10182 * _gtk_entry_set_is_cell_renderer:
10183 * @entry: a #GtkEntry
10184 * @is_cell_renderer: new value
10186 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10187 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10189 * I.e take up it's allocation and get GtkEntry->is_cell_renderer = TRUE.
10193 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10194 gboolean is_cell_renderer)
10196 entry->priv->is_cell_renderer = is_cell_renderer;