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_queue_draw (GtkEntry *entry);
519 static void gtk_entry_recompute (GtkEntry *entry);
520 static gint gtk_entry_find_position (GtkEntry *entry,
522 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
526 static void gtk_entry_adjust_scroll (GtkEntry *entry);
527 static gint gtk_entry_move_visually (GtkEntry *editable,
530 static gint gtk_entry_move_logically (GtkEntry *entry,
533 static gint gtk_entry_move_forward_word (GtkEntry *entry,
535 gboolean allow_whitespace);
536 static gint gtk_entry_move_backward_word (GtkEntry *entry,
538 gboolean allow_whitespace);
539 static void gtk_entry_delete_whitespace (GtkEntry *entry);
540 static void gtk_entry_select_word (GtkEntry *entry);
541 static void gtk_entry_select_line (GtkEntry *entry);
542 static void gtk_entry_paste (GtkEntry *entry,
544 static void gtk_entry_update_primary_selection (GtkEntry *entry);
545 static void gtk_entry_do_popup (GtkEntry *entry,
546 GdkEventButton *event);
547 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
548 gboolean group_cycling);
549 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
550 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
551 static void gtk_entry_reset_blink_time (GtkEntry *entry);
552 static void gtk_entry_get_text_area_size (GtkEntry *entry,
557 static void get_text_area_size (GtkEntry *entry,
562 static void get_frame_size (GtkEntry *entry,
567 static void gtk_entry_move_adjustments (GtkEntry *entry);
568 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
569 GtkEntryIconPosition icon_pos);
573 static gint gtk_entry_completion_timeout (gpointer data);
574 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
577 static void gtk_entry_completion_changed (GtkWidget *entry,
579 static gboolean check_completion_callback (GtkEntryCompletion *completion);
580 static void clear_completion_callback (GtkEntry *entry,
582 static gboolean accept_completion_callback (GtkEntry *entry);
583 static void completion_insert_text_callback (GtkEntry *entry,
587 GtkEntryCompletion *completion);
588 static void completion_changed (GtkEntryCompletion *completion,
591 static void disconnect_completion_signals (GtkEntry *entry,
592 GtkEntryCompletion *completion);
593 static void connect_completion_signals (GtkEntry *entry,
594 GtkEntryCompletion *completion);
596 static void begin_change (GtkEntry *entry);
597 static void end_change (GtkEntry *entry);
598 static void emit_changed (GtkEntry *entry);
601 static void buffer_inserted_text (GtkEntryBuffer *buffer,
606 static void buffer_deleted_text (GtkEntryBuffer *buffer,
610 static void buffer_notify_text (GtkEntryBuffer *buffer,
613 static void buffer_notify_length (GtkEntryBuffer *buffer,
616 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
619 static void buffer_connect_signals (GtkEntry *entry);
620 static void buffer_disconnect_signals (GtkEntry *entry);
621 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
624 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
625 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
626 gtk_entry_editable_init)
627 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
628 gtk_entry_cell_editable_init))
631 add_move_binding (GtkBindingSet *binding_set,
634 GtkMovementStep step,
637 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
639 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
643 G_TYPE_BOOLEAN, FALSE);
645 /* Selection-extending version */
646 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
650 G_TYPE_BOOLEAN, TRUE);
654 gtk_entry_class_init (GtkEntryClass *class)
656 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
657 GtkWidgetClass *widget_class;
658 GtkBindingSet *binding_set;
660 widget_class = (GtkWidgetClass*) class;
662 gobject_class->dispose = gtk_entry_dispose;
663 gobject_class->finalize = gtk_entry_finalize;
664 gobject_class->set_property = gtk_entry_set_property;
665 gobject_class->get_property = gtk_entry_get_property;
667 widget_class->destroy = gtk_entry_destroy;
668 widget_class->map = gtk_entry_map;
669 widget_class->unmap = gtk_entry_unmap;
670 widget_class->realize = gtk_entry_realize;
671 widget_class->unrealize = gtk_entry_unrealize;
672 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
673 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
674 widget_class->size_allocate = gtk_entry_size_allocate;
675 widget_class->draw = gtk_entry_draw;
676 widget_class->enter_notify_event = gtk_entry_enter_notify;
677 widget_class->leave_notify_event = gtk_entry_leave_notify;
678 widget_class->button_press_event = gtk_entry_button_press;
679 widget_class->button_release_event = gtk_entry_button_release;
680 widget_class->motion_notify_event = gtk_entry_motion_notify;
681 widget_class->key_press_event = gtk_entry_key_press;
682 widget_class->key_release_event = gtk_entry_key_release;
683 widget_class->focus_in_event = gtk_entry_focus_in;
684 widget_class->focus_out_event = gtk_entry_focus_out;
685 widget_class->grab_focus = gtk_entry_grab_focus;
686 widget_class->style_updated = gtk_entry_style_updated;
687 widget_class->query_tooltip = gtk_entry_query_tooltip;
688 widget_class->drag_begin = gtk_entry_drag_begin;
689 widget_class->drag_end = gtk_entry_drag_end;
690 widget_class->direction_changed = gtk_entry_direction_changed;
691 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
692 widget_class->screen_changed = gtk_entry_screen_changed;
693 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
695 widget_class->drag_drop = gtk_entry_drag_drop;
696 widget_class->drag_motion = gtk_entry_drag_motion;
697 widget_class->drag_leave = gtk_entry_drag_leave;
698 widget_class->drag_data_received = gtk_entry_drag_data_received;
699 widget_class->drag_data_get = gtk_entry_drag_data_get;
700 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
702 widget_class->popup_menu = gtk_entry_popup_menu;
704 class->move_cursor = gtk_entry_move_cursor;
705 class->insert_at_cursor = gtk_entry_insert_at_cursor;
706 class->delete_from_cursor = gtk_entry_delete_from_cursor;
707 class->backspace = gtk_entry_backspace;
708 class->cut_clipboard = gtk_entry_cut_clipboard;
709 class->copy_clipboard = gtk_entry_copy_clipboard;
710 class->paste_clipboard = gtk_entry_paste_clipboard;
711 class->toggle_overwrite = gtk_entry_toggle_overwrite;
712 class->activate = gtk_entry_real_activate;
713 class->get_text_area_size = gtk_entry_get_text_area_size;
715 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
716 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
717 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
718 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
720 g_object_class_override_property (gobject_class,
721 PROP_EDITING_CANCELED,
724 g_object_class_install_property (gobject_class,
726 g_param_spec_object ("buffer",
728 P_("Text buffer object which actually stores entry text"),
729 GTK_TYPE_ENTRY_BUFFER,
730 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
732 g_object_class_install_property (gobject_class,
733 PROP_CURSOR_POSITION,
734 g_param_spec_int ("cursor-position",
735 P_("Cursor Position"),
736 P_("The current position of the insertion cursor in chars"),
738 GTK_ENTRY_BUFFER_MAX_SIZE,
740 GTK_PARAM_READABLE));
742 g_object_class_install_property (gobject_class,
743 PROP_SELECTION_BOUND,
744 g_param_spec_int ("selection-bound",
745 P_("Selection Bound"),
746 P_("The position of the opposite end of the selection from the cursor in chars"),
748 GTK_ENTRY_BUFFER_MAX_SIZE,
750 GTK_PARAM_READABLE));
752 g_object_class_install_property (gobject_class,
754 g_param_spec_boolean ("editable",
756 P_("Whether the entry contents can be edited"),
758 GTK_PARAM_READWRITE));
760 g_object_class_install_property (gobject_class,
762 g_param_spec_int ("max-length",
763 P_("Maximum length"),
764 P_("Maximum number of characters for this entry. Zero if no maximum"),
766 GTK_ENTRY_BUFFER_MAX_SIZE,
768 GTK_PARAM_READWRITE));
769 g_object_class_install_property (gobject_class,
771 g_param_spec_boolean ("visibility",
773 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
775 GTK_PARAM_READWRITE));
777 g_object_class_install_property (gobject_class,
779 g_param_spec_boolean ("has-frame",
781 P_("FALSE removes outside bevel from entry"),
783 GTK_PARAM_READWRITE));
785 g_object_class_install_property (gobject_class,
787 g_param_spec_boxed ("inner-border",
789 P_("Border between text and frame. Overrides the inner-border style property"),
791 GTK_PARAM_READWRITE));
793 g_object_class_install_property (gobject_class,
795 g_param_spec_unichar ("invisible-char",
796 P_("Invisible character"),
797 P_("The character to use when masking entry contents (in \"password mode\")"),
799 GTK_PARAM_READWRITE));
801 g_object_class_install_property (gobject_class,
802 PROP_ACTIVATES_DEFAULT,
803 g_param_spec_boolean ("activates-default",
804 P_("Activates default"),
805 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
807 GTK_PARAM_READWRITE));
808 g_object_class_install_property (gobject_class,
810 g_param_spec_int ("width-chars",
811 P_("Width in chars"),
812 P_("Number of characters to leave space for in the entry"),
816 GTK_PARAM_READWRITE));
818 g_object_class_install_property (gobject_class,
820 g_param_spec_int ("scroll-offset",
822 P_("Number of pixels of the entry scrolled off the screen to the left"),
826 GTK_PARAM_READABLE));
828 g_object_class_install_property (gobject_class,
830 g_param_spec_string ("text",
832 P_("The contents of the entry"),
834 GTK_PARAM_READWRITE));
839 * The horizontal alignment, from 0 (left) to 1 (right).
840 * Reversed for RTL layouts.
844 g_object_class_install_property (gobject_class,
846 g_param_spec_float ("xalign",
848 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
852 GTK_PARAM_READWRITE));
855 * GtkEntry:truncate-multiline:
857 * When %TRUE, pasted multi-line text is truncated to the first line.
861 g_object_class_install_property (gobject_class,
862 PROP_TRUNCATE_MULTILINE,
863 g_param_spec_boolean ("truncate-multiline",
864 P_("Truncate multiline"),
865 P_("Whether to truncate multiline pastes to one line."),
867 GTK_PARAM_READWRITE));
870 * GtkEntry:shadow-type:
872 * Which kind of shadow to draw around the entry when
873 * #GtkEntry:has-frame is set to %TRUE.
877 g_object_class_install_property (gobject_class,
879 g_param_spec_enum ("shadow-type",
881 P_("Which kind of shadow to draw around the entry when has-frame is set"),
882 GTK_TYPE_SHADOW_TYPE,
884 GTK_PARAM_READWRITE));
887 * GtkEntry:overwrite-mode:
889 * If text is overwritten when typing in the #GtkEntry.
893 g_object_class_install_property (gobject_class,
895 g_param_spec_boolean ("overwrite-mode",
896 P_("Overwrite mode"),
897 P_("Whether new text overwrites existing text"),
899 GTK_PARAM_READWRITE));
902 * GtkEntry:text-length:
904 * The length of the text in the #GtkEntry.
908 g_object_class_install_property (gobject_class,
910 g_param_spec_uint ("text-length",
912 P_("Length of the text currently in the entry"),
916 GTK_PARAM_READABLE));
918 * GtkEntry:invisible-char-set:
920 * Whether the invisible char has been set for the #GtkEntry.
924 g_object_class_install_property (gobject_class,
925 PROP_INVISIBLE_CHAR_SET,
926 g_param_spec_boolean ("invisible-char-set",
927 P_("Invisible character set"),
928 P_("Whether the invisible character has been set"),
930 GTK_PARAM_READWRITE));
933 * GtkEntry:caps-lock-warning
935 * Whether password entries will show a warning when Caps Lock is on.
937 * Note that the warning is shown using a secondary icon, and thus
938 * does not work if you are using the secondary icon position for some
943 g_object_class_install_property (gobject_class,
944 PROP_CAPS_LOCK_WARNING,
945 g_param_spec_boolean ("caps-lock-warning",
946 P_("Caps Lock warning"),
947 P_("Whether password entries will show a warning when Caps Lock is on"),
949 GTK_PARAM_READWRITE));
952 * GtkEntry:progress-fraction:
954 * The current fraction of the task that's been completed.
958 g_object_class_install_property (gobject_class,
959 PROP_PROGRESS_FRACTION,
960 g_param_spec_double ("progress-fraction",
961 P_("Progress Fraction"),
962 P_("The current fraction of the task that's been completed"),
966 GTK_PARAM_READWRITE));
969 * GtkEntry:progress-pulse-step:
971 * The fraction of total entry width to move the progress
972 * bouncing block for each call to gtk_entry_progress_pulse().
976 g_object_class_install_property (gobject_class,
977 PROP_PROGRESS_PULSE_STEP,
978 g_param_spec_double ("progress-pulse-step",
979 P_("Progress Pulse Step"),
980 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
984 GTK_PARAM_READWRITE));
987 * GtkEntry:primary-icon-pixbuf:
989 * A pixbuf to use as the primary icon for the entry.
993 g_object_class_install_property (gobject_class,
995 g_param_spec_object ("primary-icon-pixbuf",
996 P_("Primary pixbuf"),
997 P_("Primary pixbuf for the entry"),
999 GTK_PARAM_READWRITE));
1002 * GtkEntry:secondary-icon-pixbuf:
1004 * An pixbuf to use as the secondary icon for the entry.
1008 g_object_class_install_property (gobject_class,
1009 PROP_PIXBUF_SECONDARY,
1010 g_param_spec_object ("secondary-icon-pixbuf",
1011 P_("Secondary pixbuf"),
1012 P_("Secondary pixbuf for the entry"),
1014 GTK_PARAM_READWRITE));
1017 * GtkEntry:primary-icon-stock:
1019 * The stock id to use for the primary icon for the entry.
1023 g_object_class_install_property (gobject_class,
1025 g_param_spec_string ("primary-icon-stock",
1026 P_("Primary stock ID"),
1027 P_("Stock ID for primary icon"),
1029 GTK_PARAM_READWRITE));
1032 * GtkEntry:secondary-icon-stock:
1034 * The stock id to use for the secondary icon for the entry.
1038 g_object_class_install_property (gobject_class,
1039 PROP_STOCK_SECONDARY,
1040 g_param_spec_string ("secondary-icon-stock",
1041 P_("Secondary stock ID"),
1042 P_("Stock ID for secondary icon"),
1044 GTK_PARAM_READWRITE));
1047 * GtkEntry:primary-icon-name:
1049 * The icon name to use for the primary icon for the entry.
1053 g_object_class_install_property (gobject_class,
1054 PROP_ICON_NAME_PRIMARY,
1055 g_param_spec_string ("primary-icon-name",
1056 P_("Primary icon name"),
1057 P_("Icon name for primary icon"),
1059 GTK_PARAM_READWRITE));
1062 * GtkEntry:secondary-icon-name:
1064 * The icon name to use for the secondary icon for the entry.
1068 g_object_class_install_property (gobject_class,
1069 PROP_ICON_NAME_SECONDARY,
1070 g_param_spec_string ("secondary-icon-name",
1071 P_("Secondary icon name"),
1072 P_("Icon name for secondary icon"),
1074 GTK_PARAM_READWRITE));
1077 * GtkEntry:primary-icon-gicon:
1079 * The #GIcon to use for the primary icon for the entry.
1083 g_object_class_install_property (gobject_class,
1085 g_param_spec_object ("primary-icon-gicon",
1086 P_("Primary GIcon"),
1087 P_("GIcon for primary icon"),
1089 GTK_PARAM_READWRITE));
1092 * GtkEntry:secondary-icon-gicon:
1094 * The #GIcon to use for the secondary icon for the entry.
1098 g_object_class_install_property (gobject_class,
1099 PROP_GICON_SECONDARY,
1100 g_param_spec_object ("secondary-icon-gicon",
1101 P_("Secondary GIcon"),
1102 P_("GIcon for secondary icon"),
1104 GTK_PARAM_READWRITE));
1107 * GtkEntry:primary-icon-storage-type:
1109 * The representation which is used for the primary icon of the entry.
1113 g_object_class_install_property (gobject_class,
1114 PROP_STORAGE_TYPE_PRIMARY,
1115 g_param_spec_enum ("primary-icon-storage-type",
1116 P_("Primary storage type"),
1117 P_("The representation being used for primary icon"),
1118 GTK_TYPE_IMAGE_TYPE,
1120 GTK_PARAM_READABLE));
1123 * GtkEntry:secondary-icon-storage-type:
1125 * The representation which is used for the secondary icon of the entry.
1129 g_object_class_install_property (gobject_class,
1130 PROP_STORAGE_TYPE_SECONDARY,
1131 g_param_spec_enum ("secondary-icon-storage-type",
1132 P_("Secondary storage type"),
1133 P_("The representation being used for secondary icon"),
1134 GTK_TYPE_IMAGE_TYPE,
1136 GTK_PARAM_READABLE));
1139 * GtkEntry:primary-icon-activatable:
1141 * Whether the primary icon is activatable.
1143 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1144 * signals only on sensitive, activatable icons.
1146 * Sensitive, but non-activatable icons can be used for purely
1147 * informational purposes.
1151 g_object_class_install_property (gobject_class,
1152 PROP_ACTIVATABLE_PRIMARY,
1153 g_param_spec_boolean ("primary-icon-activatable",
1154 P_("Primary icon activatable"),
1155 P_("Whether the primary icon is activatable"),
1157 GTK_PARAM_READWRITE));
1160 * GtkEntry:secondary-icon-activatable:
1162 * Whether the secondary icon is activatable.
1164 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1165 * signals only on sensitive, activatable icons.
1167 * Sensitive, but non-activatable icons can be used for purely
1168 * informational purposes.
1172 g_object_class_install_property (gobject_class,
1173 PROP_ACTIVATABLE_SECONDARY,
1174 g_param_spec_boolean ("secondary-icon-activatable",
1175 P_("Secondary icon activatable"),
1176 P_("Whether the secondary icon is activatable"),
1178 GTK_PARAM_READWRITE));
1182 * GtkEntry:primary-icon-sensitive:
1184 * Whether the primary icon is sensitive.
1186 * An insensitive icon appears grayed out. GTK+ does not emit the
1187 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1188 * does not allow DND from insensitive icons.
1190 * An icon should be set insensitive if the action that would trigger
1191 * when clicked is currently not available.
1195 g_object_class_install_property (gobject_class,
1196 PROP_SENSITIVE_PRIMARY,
1197 g_param_spec_boolean ("primary-icon-sensitive",
1198 P_("Primary icon sensitive"),
1199 P_("Whether the primary icon is sensitive"),
1201 GTK_PARAM_READWRITE));
1204 * GtkEntry:secondary-icon-sensitive:
1206 * Whether the secondary icon is sensitive.
1208 * An insensitive icon appears grayed out. GTK+ does not emit the
1209 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1210 * does not allow DND from insensitive icons.
1212 * An icon should be set insensitive if the action that would trigger
1213 * when clicked is currently not available.
1217 g_object_class_install_property (gobject_class,
1218 PROP_SENSITIVE_SECONDARY,
1219 g_param_spec_boolean ("secondary-icon-sensitive",
1220 P_("Secondary icon sensitive"),
1221 P_("Whether the secondary icon is sensitive"),
1223 GTK_PARAM_READWRITE));
1226 * GtkEntry:primary-icon-tooltip-text:
1228 * The contents of the tooltip on the primary icon.
1230 * Also see gtk_entry_set_icon_tooltip_text().
1234 g_object_class_install_property (gobject_class,
1235 PROP_TOOLTIP_TEXT_PRIMARY,
1236 g_param_spec_string ("primary-icon-tooltip-text",
1237 P_("Primary icon tooltip text"),
1238 P_("The contents of the tooltip on the primary icon"),
1240 GTK_PARAM_READWRITE));
1243 * GtkEntry:secondary-icon-tooltip-text:
1245 * The contents of the tooltip on the secondary icon.
1247 * Also see gtk_entry_set_icon_tooltip_text().
1251 g_object_class_install_property (gobject_class,
1252 PROP_TOOLTIP_TEXT_SECONDARY,
1253 g_param_spec_string ("secondary-icon-tooltip-text",
1254 P_("Secondary icon tooltip text"),
1255 P_("The contents of the tooltip on the secondary icon"),
1257 GTK_PARAM_READWRITE));
1260 * GtkEntry:primary-icon-tooltip-markup:
1262 * The contents of the tooltip on the primary icon, which is marked up
1263 * with the <link linkend="PangoMarkupFormat">Pango text markup
1266 * Also see gtk_entry_set_icon_tooltip_markup().
1270 g_object_class_install_property (gobject_class,
1271 PROP_TOOLTIP_MARKUP_PRIMARY,
1272 g_param_spec_string ("primary-icon-tooltip-markup",
1273 P_("Primary icon tooltip markup"),
1274 P_("The contents of the tooltip on the primary icon"),
1276 GTK_PARAM_READWRITE));
1279 * GtkEntry:secondary-icon-tooltip-markup:
1281 * The contents of the tooltip on the secondary icon, which is marked up
1282 * with the <link linkend="PangoMarkupFormat">Pango text markup
1285 * Also see gtk_entry_set_icon_tooltip_markup().
1289 g_object_class_install_property (gobject_class,
1290 PROP_TOOLTIP_MARKUP_SECONDARY,
1291 g_param_spec_string ("secondary-icon-tooltip-markup",
1292 P_("Secondary icon tooltip markup"),
1293 P_("The contents of the tooltip on the secondary icon"),
1295 GTK_PARAM_READWRITE));
1298 * GtkEntry:im-module:
1300 * Which IM (input method) module should be used for this entry.
1301 * See #GtkIMContext.
1303 * Setting this to a non-%NULL value overrides the
1304 * system-wide IM module setting. See the GtkSettings
1305 * #GtkSettings:gtk-im-module property.
1309 g_object_class_install_property (gobject_class,
1311 g_param_spec_string ("im-module",
1313 P_("Which IM module should be used"),
1315 GTK_PARAM_READWRITE));
1318 * GtkEntry:icon-prelight:
1320 * The prelight style property determines whether activatable
1321 * icons prelight on mouseover.
1325 gtk_widget_class_install_style_property (widget_class,
1326 g_param_spec_boolean ("icon-prelight",
1327 P_("Icon Prelight"),
1328 P_("Whether activatable icons should prelight when hovered"),
1330 GTK_PARAM_READABLE));
1333 * GtkEntry:progress-border:
1335 * The border around the progress bar in the entry.
1339 gtk_widget_class_install_style_property (widget_class,
1340 g_param_spec_boxed ("progress-border",
1341 P_("Progress Border"),
1342 P_("Border around the progress bar"),
1344 GTK_PARAM_READABLE));
1347 * GtkEntry:invisible-char:
1349 * The invisible character is used when masking entry contents (in
1350 * \"password mode\")"). When it is not explicitly set with the
1351 * #GtkEntry::invisible-char property, GTK+ determines the character
1352 * to use from a list of possible candidates, depending on availability
1353 * in the current font.
1355 * This style property allows the theme to prepend a character
1356 * to the list of candidates.
1360 gtk_widget_class_install_style_property (widget_class,
1361 g_param_spec_unichar ("invisible-char",
1362 P_("Invisible character"),
1363 P_("The character to use when masking entry contents (in \"password mode\")"),
1365 GTK_PARAM_READABLE));
1368 * GtkEntry::populate-popup:
1369 * @entry: The entry on which the signal is emitted
1370 * @menu: the menu that is being populated
1372 * The ::populate-popup signal gets emitted before showing the
1373 * context menu of the entry.
1375 * If you need to add items to the context menu, connect
1376 * to this signal and append your menuitems to the @menu.
1378 signals[POPULATE_POPUP] =
1379 g_signal_new (I_("populate-popup"),
1380 G_OBJECT_CLASS_TYPE (gobject_class),
1382 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1384 _gtk_marshal_VOID__OBJECT,
1388 /* Action signals */
1391 * GtkEntry::activate:
1392 * @entry: The entry on which the signal is emitted
1394 * A <link linkend="keybinding-signals">keybinding signal</link>
1395 * which gets emitted when the user activates the entry.
1397 * Applications should not connect to it, but may emit it with
1398 * g_signal_emit_by_name() if they need to control activation
1401 * The default bindings for this signal are all forms of the Enter key.
1404 g_signal_new (I_("activate"),
1405 G_OBJECT_CLASS_TYPE (gobject_class),
1406 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1407 G_STRUCT_OFFSET (GtkEntryClass, activate),
1409 _gtk_marshal_VOID__VOID,
1411 widget_class->activate_signal = signals[ACTIVATE];
1414 * GtkEntry::move-cursor:
1415 * @entry: the object which received the signal
1416 * @step: the granularity of the move, as a #GtkMovementStep
1417 * @count: the number of @step units to move
1418 * @extend_selection: %TRUE if the move should extend the selection
1420 * The ::move-cursor signal is a
1421 * <link linkend="keybinding-signals">keybinding signal</link>
1422 * which gets emitted when the user initiates a cursor movement.
1423 * If the cursor is not visible in @entry, this signal causes
1424 * the viewport to be moved instead.
1426 * Applications should not connect to it, but may emit it with
1427 * g_signal_emit_by_name() if they need to control the cursor
1430 * The default bindings for this signal come in two variants,
1431 * the variant with the Shift modifier extends the selection,
1432 * the variant without the Shift modifer does not.
1433 * There are too many key combinations to list them all here.
1435 * <listitem>Arrow keys move by individual characters/lines</listitem>
1436 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1437 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1440 signals[MOVE_CURSOR] =
1441 g_signal_new (I_("move-cursor"),
1442 G_OBJECT_CLASS_TYPE (gobject_class),
1443 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1444 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1446 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1448 GTK_TYPE_MOVEMENT_STEP,
1453 * GtkEntry::insert-at-cursor:
1454 * @entry: the object which received the signal
1455 * @string: the string to insert
1457 * The ::insert-at-cursor signal is a
1458 * <link linkend="keybinding-signals">keybinding signal</link>
1459 * which gets emitted when the user initiates the insertion of a
1460 * fixed string at the cursor.
1462 * This signal has no default bindings.
1464 signals[INSERT_AT_CURSOR] =
1465 g_signal_new (I_("insert-at-cursor"),
1466 G_OBJECT_CLASS_TYPE (gobject_class),
1467 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1468 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1470 _gtk_marshal_VOID__STRING,
1475 * GtkEntry::delete-from-cursor:
1476 * @entry: the object which received the signal
1477 * @type: the granularity of the deletion, as a #GtkDeleteType
1478 * @count: the number of @type units to delete
1480 * The ::delete-from-cursor signal is a
1481 * <link linkend="keybinding-signals">keybinding signal</link>
1482 * which gets emitted when the user initiates a text deletion.
1484 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1485 * if there is one, otherwise it deletes the requested number
1488 * The default bindings for this signal are
1489 * Delete for deleting a character and Ctrl-Delete for
1492 signals[DELETE_FROM_CURSOR] =
1493 g_signal_new (I_("delete-from-cursor"),
1494 G_OBJECT_CLASS_TYPE (gobject_class),
1495 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1496 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1498 _gtk_marshal_VOID__ENUM_INT,
1500 GTK_TYPE_DELETE_TYPE,
1504 * GtkEntry::backspace:
1505 * @entry: the object which received the signal
1507 * The ::backspace signal is a
1508 * <link linkend="keybinding-signals">keybinding signal</link>
1509 * which gets emitted when the user asks for it.
1511 * The default bindings for this signal are
1512 * Backspace and Shift-Backspace.
1514 signals[BACKSPACE] =
1515 g_signal_new (I_("backspace"),
1516 G_OBJECT_CLASS_TYPE (gobject_class),
1517 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1518 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1520 _gtk_marshal_VOID__VOID,
1524 * GtkEntry::cut-clipboard:
1525 * @entry: the object which received the signal
1527 * The ::cut-clipboard signal is a
1528 * <link linkend="keybinding-signals">keybinding signal</link>
1529 * which gets emitted to cut the selection to the clipboard.
1531 * The default bindings for this signal are
1532 * Ctrl-x and Shift-Delete.
1534 signals[CUT_CLIPBOARD] =
1535 g_signal_new (I_("cut-clipboard"),
1536 G_OBJECT_CLASS_TYPE (gobject_class),
1537 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1538 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1540 _gtk_marshal_VOID__VOID,
1544 * GtkEntry::copy-clipboard:
1545 * @entry: the object which received the signal
1547 * The ::copy-clipboard signal is a
1548 * <link linkend="keybinding-signals">keybinding signal</link>
1549 * which gets emitted to copy the selection to the clipboard.
1551 * The default bindings for this signal are
1552 * Ctrl-c and Ctrl-Insert.
1554 signals[COPY_CLIPBOARD] =
1555 g_signal_new (I_("copy-clipboard"),
1556 G_OBJECT_CLASS_TYPE (gobject_class),
1557 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1558 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1560 _gtk_marshal_VOID__VOID,
1564 * GtkEntry::paste-clipboard:
1565 * @entry: the object which received the signal
1567 * The ::paste-clipboard signal is a
1568 * <link linkend="keybinding-signals">keybinding signal</link>
1569 * which gets emitted to paste the contents of the clipboard
1570 * into the text view.
1572 * The default bindings for this signal are
1573 * Ctrl-v and Shift-Insert.
1575 signals[PASTE_CLIPBOARD] =
1576 g_signal_new (I_("paste-clipboard"),
1577 G_OBJECT_CLASS_TYPE (gobject_class),
1578 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1579 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1581 _gtk_marshal_VOID__VOID,
1585 * GtkEntry::toggle-overwrite:
1586 * @entry: the object which received the signal
1588 * The ::toggle-overwrite signal is a
1589 * <link linkend="keybinding-signals">keybinding signal</link>
1590 * which gets emitted to toggle the overwrite mode of the entry.
1592 * The default bindings for this signal is Insert.
1594 signals[TOGGLE_OVERWRITE] =
1595 g_signal_new (I_("toggle-overwrite"),
1596 G_OBJECT_CLASS_TYPE (gobject_class),
1597 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1598 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1600 _gtk_marshal_VOID__VOID,
1604 * GtkEntry::icon-press:
1605 * @entry: The entry on which the signal is emitted
1606 * @icon_pos: The position of the clicked icon
1607 * @event: the button press event
1609 * The ::icon-press signal is emitted when an activatable icon
1614 signals[ICON_PRESS] =
1615 g_signal_new (I_("icon-press"),
1616 G_TYPE_FROM_CLASS (gobject_class),
1620 _gtk_marshal_VOID__ENUM_BOXED,
1622 GTK_TYPE_ENTRY_ICON_POSITION,
1623 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1626 * GtkEntry::icon-release:
1627 * @entry: The entry on which the signal is emitted
1628 * @icon_pos: The position of the clicked icon
1629 * @event: the button release event
1631 * The ::icon-release signal is emitted on the button release from a
1632 * mouse click over an activatable icon.
1636 signals[ICON_RELEASE] =
1637 g_signal_new (I_("icon-release"),
1638 G_TYPE_FROM_CLASS (gobject_class),
1642 _gtk_marshal_VOID__ENUM_BOXED,
1644 GTK_TYPE_ENTRY_ICON_POSITION,
1645 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1648 * GtkEntry::preedit-changed:
1649 * @entry: the object which received the signal
1650 * @preedit: the current preedit string
1652 * If an input method is used, the typed text will not immediately
1653 * be committed to the buffer. So if you are interested in the text,
1654 * connect to this signal.
1658 signals[PREEDIT_CHANGED] =
1659 g_signal_new_class_handler (I_("preedit-changed"),
1660 G_OBJECT_CLASS_TYPE (gobject_class),
1661 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1664 _gtk_marshal_VOID__STRING,
1673 binding_set = gtk_binding_set_by_class (class);
1675 /* Moving the insertion point */
1676 add_move_binding (binding_set, GDK_KEY_Right, 0,
1677 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1679 add_move_binding (binding_set, GDK_KEY_Left, 0,
1680 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1682 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1683 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1685 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1686 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1688 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1689 GTK_MOVEMENT_WORDS, 1);
1691 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1692 GTK_MOVEMENT_WORDS, -1);
1694 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1695 GTK_MOVEMENT_WORDS, 1);
1697 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1698 GTK_MOVEMENT_WORDS, -1);
1700 add_move_binding (binding_set, GDK_KEY_Home, 0,
1701 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1703 add_move_binding (binding_set, GDK_KEY_End, 0,
1704 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1706 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1707 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1709 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1710 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1712 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1713 GTK_MOVEMENT_BUFFER_ENDS, -1);
1715 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1716 GTK_MOVEMENT_BUFFER_ENDS, 1);
1718 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1719 GTK_MOVEMENT_BUFFER_ENDS, -1);
1721 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1722 GTK_MOVEMENT_BUFFER_ENDS, 1);
1726 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1728 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1730 G_TYPE_BOOLEAN, FALSE);
1731 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1733 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1735 G_TYPE_BOOLEAN, TRUE);
1737 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1739 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1741 G_TYPE_BOOLEAN, FALSE);
1742 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1744 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1746 G_TYPE_BOOLEAN, TRUE);
1749 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1751 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1753 G_TYPE_BOOLEAN, FALSE);
1754 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1756 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1758 G_TYPE_BOOLEAN, FALSE);
1762 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1764 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1766 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1770 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1771 "delete-from-cursor", 2,
1772 G_TYPE_ENUM, GTK_DELETE_CHARS,
1775 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1776 "delete-from-cursor", 2,
1777 G_TYPE_ENUM, GTK_DELETE_CHARS,
1780 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1783 /* Make this do the same as Backspace, to help with mis-typing */
1784 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1787 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1788 "delete-from-cursor", 2,
1789 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1792 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1793 "delete-from-cursor", 2,
1794 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1797 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1798 "delete-from-cursor", 2,
1799 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1802 /* Cut/copy/paste */
1804 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1805 "cut-clipboard", 0);
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1807 "copy-clipboard", 0);
1808 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1809 "paste-clipboard", 0);
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1812 "cut-clipboard", 0);
1813 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1814 "copy-clipboard", 0);
1815 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1816 "paste-clipboard", 0);
1819 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1820 "toggle-overwrite", 0);
1821 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1822 "toggle-overwrite", 0);
1825 * GtkEntry:inner-border:
1827 * Sets the text area's border between the text and the frame.
1831 gtk_widget_class_install_style_property (widget_class,
1832 g_param_spec_boxed ("inner-border",
1834 P_("Border between text and frame."),
1836 GTK_PARAM_READABLE));
1838 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1842 gtk_entry_editable_init (GtkEditableInterface *iface)
1844 iface->do_insert_text = gtk_entry_insert_text;
1845 iface->do_delete_text = gtk_entry_delete_text;
1846 iface->insert_text = gtk_entry_real_insert_text;
1847 iface->delete_text = gtk_entry_real_delete_text;
1848 iface->get_chars = gtk_entry_get_chars;
1849 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1850 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1851 iface->set_position = gtk_entry_real_set_position;
1852 iface->get_position = gtk_entry_get_position;
1856 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1858 iface->start_editing = gtk_entry_start_editing;
1862 gtk_entry_set_property (GObject *object,
1864 const GValue *value,
1867 GtkEntry *entry = GTK_ENTRY (object);
1868 GtkEntryPrivate *priv = entry->priv;
1874 gtk_entry_set_buffer (entry, g_value_get_object (value));
1879 gboolean new_value = g_value_get_boolean (value);
1881 if (new_value != priv->editable)
1883 widget = GTK_WIDGET (entry);
1886 _gtk_entry_reset_im_context (entry);
1887 if (gtk_widget_has_focus (widget))
1888 gtk_im_context_focus_out (priv->im_context);
1890 priv->preedit_length = 0;
1891 priv->preedit_cursor = 0;
1894 priv->editable = new_value;
1896 if (new_value && gtk_widget_has_focus (widget))
1897 gtk_im_context_focus_in (priv->im_context);
1899 gtk_entry_queue_draw (entry);
1904 case PROP_MAX_LENGTH:
1905 gtk_entry_set_max_length (entry, g_value_get_int (value));
1908 case PROP_VISIBILITY:
1909 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1912 case PROP_HAS_FRAME:
1913 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1916 case PROP_INNER_BORDER:
1917 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1920 case PROP_INVISIBLE_CHAR:
1921 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1924 case PROP_ACTIVATES_DEFAULT:
1925 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1928 case PROP_WIDTH_CHARS:
1929 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1933 gtk_entry_set_text (entry, g_value_get_string (value));
1937 gtk_entry_set_alignment (entry, g_value_get_float (value));
1940 case PROP_TRUNCATE_MULTILINE:
1941 priv->truncate_multiline = g_value_get_boolean (value);
1944 case PROP_SHADOW_TYPE:
1945 priv->shadow_type = g_value_get_enum (value);
1948 case PROP_OVERWRITE_MODE:
1949 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1952 case PROP_INVISIBLE_CHAR_SET:
1953 if (g_value_get_boolean (value))
1954 priv->invisible_char_set = TRUE;
1956 gtk_entry_unset_invisible_char (entry);
1959 case PROP_CAPS_LOCK_WARNING:
1960 priv->caps_lock_warning = g_value_get_boolean (value);
1963 case PROP_PROGRESS_FRACTION:
1964 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1967 case PROP_PROGRESS_PULSE_STEP:
1968 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1971 case PROP_PIXBUF_PRIMARY:
1972 gtk_entry_set_icon_from_pixbuf (entry,
1973 GTK_ENTRY_ICON_PRIMARY,
1974 g_value_get_object (value));
1977 case PROP_PIXBUF_SECONDARY:
1978 gtk_entry_set_icon_from_pixbuf (entry,
1979 GTK_ENTRY_ICON_SECONDARY,
1980 g_value_get_object (value));
1983 case PROP_STOCK_PRIMARY:
1984 gtk_entry_set_icon_from_stock (entry,
1985 GTK_ENTRY_ICON_PRIMARY,
1986 g_value_get_string (value));
1989 case PROP_STOCK_SECONDARY:
1990 gtk_entry_set_icon_from_stock (entry,
1991 GTK_ENTRY_ICON_SECONDARY,
1992 g_value_get_string (value));
1995 case PROP_ICON_NAME_PRIMARY:
1996 gtk_entry_set_icon_from_icon_name (entry,
1997 GTK_ENTRY_ICON_PRIMARY,
1998 g_value_get_string (value));
2001 case PROP_ICON_NAME_SECONDARY:
2002 gtk_entry_set_icon_from_icon_name (entry,
2003 GTK_ENTRY_ICON_SECONDARY,
2004 g_value_get_string (value));
2007 case PROP_GICON_PRIMARY:
2008 gtk_entry_set_icon_from_gicon (entry,
2009 GTK_ENTRY_ICON_PRIMARY,
2010 g_value_get_object (value));
2013 case PROP_GICON_SECONDARY:
2014 gtk_entry_set_icon_from_gicon (entry,
2015 GTK_ENTRY_ICON_SECONDARY,
2016 g_value_get_object (value));
2019 case PROP_ACTIVATABLE_PRIMARY:
2020 gtk_entry_set_icon_activatable (entry,
2021 GTK_ENTRY_ICON_PRIMARY,
2022 g_value_get_boolean (value));
2025 case PROP_ACTIVATABLE_SECONDARY:
2026 gtk_entry_set_icon_activatable (entry,
2027 GTK_ENTRY_ICON_SECONDARY,
2028 g_value_get_boolean (value));
2031 case PROP_SENSITIVE_PRIMARY:
2032 gtk_entry_set_icon_sensitive (entry,
2033 GTK_ENTRY_ICON_PRIMARY,
2034 g_value_get_boolean (value));
2037 case PROP_SENSITIVE_SECONDARY:
2038 gtk_entry_set_icon_sensitive (entry,
2039 GTK_ENTRY_ICON_SECONDARY,
2040 g_value_get_boolean (value));
2043 case PROP_TOOLTIP_TEXT_PRIMARY:
2044 gtk_entry_set_icon_tooltip_text (entry,
2045 GTK_ENTRY_ICON_PRIMARY,
2046 g_value_get_string (value));
2049 case PROP_TOOLTIP_TEXT_SECONDARY:
2050 gtk_entry_set_icon_tooltip_text (entry,
2051 GTK_ENTRY_ICON_SECONDARY,
2052 g_value_get_string (value));
2055 case PROP_TOOLTIP_MARKUP_PRIMARY:
2056 gtk_entry_set_icon_tooltip_markup (entry,
2057 GTK_ENTRY_ICON_PRIMARY,
2058 g_value_get_string (value));
2061 case PROP_TOOLTIP_MARKUP_SECONDARY:
2062 gtk_entry_set_icon_tooltip_markup (entry,
2063 GTK_ENTRY_ICON_SECONDARY,
2064 g_value_get_string (value));
2067 case PROP_IM_MODULE:
2068 g_free (priv->im_module);
2069 priv->im_module = g_value_dup_string (value);
2070 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2071 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2074 case PROP_EDITING_CANCELED:
2075 priv->editing_canceled = g_value_get_boolean (value);
2078 case PROP_SCROLL_OFFSET:
2079 case PROP_CURSOR_POSITION:
2081 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2087 gtk_entry_get_property (GObject *object,
2092 GtkEntry *entry = GTK_ENTRY (object);
2093 GtkEntryPrivate *priv = entry->priv;
2098 g_value_set_object (value, gtk_entry_get_buffer (entry));
2101 case PROP_CURSOR_POSITION:
2102 g_value_set_int (value, priv->current_pos);
2105 case PROP_SELECTION_BOUND:
2106 g_value_set_int (value, priv->selection_bound);
2110 g_value_set_boolean (value, priv->editable);
2113 case PROP_MAX_LENGTH:
2114 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2117 case PROP_VISIBILITY:
2118 g_value_set_boolean (value, priv->visible);
2121 case PROP_HAS_FRAME:
2122 g_value_set_boolean (value, priv->has_frame);
2125 case PROP_INNER_BORDER:
2126 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2129 case PROP_INVISIBLE_CHAR:
2130 g_value_set_uint (value, priv->invisible_char);
2133 case PROP_ACTIVATES_DEFAULT:
2134 g_value_set_boolean (value, priv->activates_default);
2137 case PROP_WIDTH_CHARS:
2138 g_value_set_int (value, priv->width_chars);
2141 case PROP_SCROLL_OFFSET:
2142 g_value_set_int (value, priv->scroll_offset);
2146 g_value_set_string (value, gtk_entry_get_text (entry));
2150 g_value_set_float (value, gtk_entry_get_alignment (entry));
2153 case PROP_TRUNCATE_MULTILINE:
2154 g_value_set_boolean (value, priv->truncate_multiline);
2157 case PROP_SHADOW_TYPE:
2158 g_value_set_enum (value, priv->shadow_type);
2161 case PROP_OVERWRITE_MODE:
2162 g_value_set_boolean (value, priv->overwrite_mode);
2165 case PROP_TEXT_LENGTH:
2166 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2169 case PROP_INVISIBLE_CHAR_SET:
2170 g_value_set_boolean (value, priv->invisible_char_set);
2173 case PROP_IM_MODULE:
2174 g_value_set_string (value, priv->im_module);
2177 case PROP_CAPS_LOCK_WARNING:
2178 g_value_set_boolean (value, priv->caps_lock_warning);
2181 case PROP_PROGRESS_FRACTION:
2182 g_value_set_double (value, priv->progress_fraction);
2185 case PROP_PROGRESS_PULSE_STEP:
2186 g_value_set_double (value, priv->progress_pulse_fraction);
2189 case PROP_PIXBUF_PRIMARY:
2190 g_value_set_object (value,
2191 gtk_entry_get_icon_pixbuf (entry,
2192 GTK_ENTRY_ICON_PRIMARY));
2195 case PROP_PIXBUF_SECONDARY:
2196 g_value_set_object (value,
2197 gtk_entry_get_icon_pixbuf (entry,
2198 GTK_ENTRY_ICON_SECONDARY));
2201 case PROP_STOCK_PRIMARY:
2202 g_value_set_string (value,
2203 gtk_entry_get_icon_stock (entry,
2204 GTK_ENTRY_ICON_PRIMARY));
2207 case PROP_STOCK_SECONDARY:
2208 g_value_set_string (value,
2209 gtk_entry_get_icon_stock (entry,
2210 GTK_ENTRY_ICON_SECONDARY));
2213 case PROP_ICON_NAME_PRIMARY:
2214 g_value_set_string (value,
2215 gtk_entry_get_icon_name (entry,
2216 GTK_ENTRY_ICON_PRIMARY));
2219 case PROP_ICON_NAME_SECONDARY:
2220 g_value_set_string (value,
2221 gtk_entry_get_icon_name (entry,
2222 GTK_ENTRY_ICON_SECONDARY));
2225 case PROP_GICON_PRIMARY:
2226 g_value_set_object (value,
2227 gtk_entry_get_icon_gicon (entry,
2228 GTK_ENTRY_ICON_PRIMARY));
2231 case PROP_GICON_SECONDARY:
2232 g_value_set_object (value,
2233 gtk_entry_get_icon_gicon (entry,
2234 GTK_ENTRY_ICON_SECONDARY));
2237 case PROP_STORAGE_TYPE_PRIMARY:
2238 g_value_set_enum (value,
2239 gtk_entry_get_icon_storage_type (entry,
2240 GTK_ENTRY_ICON_PRIMARY));
2243 case PROP_STORAGE_TYPE_SECONDARY:
2244 g_value_set_enum (value,
2245 gtk_entry_get_icon_storage_type (entry,
2246 GTK_ENTRY_ICON_SECONDARY));
2249 case PROP_ACTIVATABLE_PRIMARY:
2250 g_value_set_boolean (value,
2251 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2254 case PROP_ACTIVATABLE_SECONDARY:
2255 g_value_set_boolean (value,
2256 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2259 case PROP_SENSITIVE_PRIMARY:
2260 g_value_set_boolean (value,
2261 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2264 case PROP_SENSITIVE_SECONDARY:
2265 g_value_set_boolean (value,
2266 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2269 case PROP_TOOLTIP_TEXT_PRIMARY:
2270 g_value_take_string (value,
2271 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2274 case PROP_TOOLTIP_TEXT_SECONDARY:
2275 g_value_take_string (value,
2276 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2279 case PROP_TOOLTIP_MARKUP_PRIMARY:
2280 g_value_take_string (value,
2281 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2284 case PROP_TOOLTIP_MARKUP_SECONDARY:
2285 g_value_take_string (value,
2286 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2289 case PROP_EDITING_CANCELED:
2290 g_value_set_boolean (value,
2291 priv->editing_canceled);
2295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2301 find_invisible_char (GtkWidget *widget)
2303 PangoLayout *layout;
2304 PangoAttrList *attr_list;
2306 gunichar invisible_chars [] = {
2308 0x25cf, /* BLACK CIRCLE */
2309 0x2022, /* BULLET */
2310 0x2731, /* HEAVY ASTERISK */
2311 0x273a /* SIXTEEN POINTED ASTERISK */
2314 gtk_widget_style_get (widget,
2315 "invisible-char", &invisible_chars[0],
2318 layout = gtk_widget_create_pango_layout (widget, NULL);
2320 attr_list = pango_attr_list_new ();
2321 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2323 pango_layout_set_attributes (layout, attr_list);
2324 pango_attr_list_unref (attr_list);
2326 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2328 gchar text[7] = { 0, };
2331 len = g_unichar_to_utf8 (invisible_chars[i], text);
2332 pango_layout_set_text (layout, text, len);
2334 count = pango_layout_get_unknown_glyphs_count (layout);
2338 g_object_unref (layout);
2339 return invisible_chars[i];
2343 g_object_unref (layout);
2349 gtk_entry_init (GtkEntry *entry)
2351 GtkStyleContext *context;
2352 GtkEntryPrivate *priv;
2354 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2359 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2360 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2362 priv->editable = TRUE;
2363 priv->visible = TRUE;
2364 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2365 priv->dnd_position = -1;
2366 priv->width_chars = -1;
2367 priv->is_cell_renderer = FALSE;
2368 priv->editing_canceled = FALSE;
2369 priv->has_frame = TRUE;
2370 priv->truncate_multiline = FALSE;
2371 priv->shadow_type = GTK_SHADOW_IN;
2373 priv->caps_lock_warning = TRUE;
2374 priv->caps_lock_warning_shown = FALSE;
2375 priv->progress_fraction = 0.0;
2376 priv->progress_pulse_fraction = 0.1;
2378 gtk_drag_dest_set (GTK_WIDGET (entry),
2379 GTK_DEST_DEFAULT_HIGHLIGHT,
2381 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2382 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2384 /* This object is completely private. No external entity can gain a reference
2385 * to it; so we create it here and destroy it in finalize().
2387 priv->im_context = gtk_im_multicontext_new ();
2389 g_signal_connect (priv->im_context, "commit",
2390 G_CALLBACK (gtk_entry_commit_cb), entry);
2391 g_signal_connect (priv->im_context, "preedit-changed",
2392 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2393 g_signal_connect (priv->im_context, "retrieve-surrounding",
2394 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2395 g_signal_connect (priv->im_context, "delete-surrounding",
2396 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2398 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2399 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2403 get_icon_width (GtkEntry *entry,
2404 GtkEntryIconPosition icon_pos)
2406 GtkEntryPrivate *priv = entry->priv;
2407 EntryIconInfo *icon_info = priv->icons[icon_pos];
2409 GtkSettings *settings;
2410 gint menu_icon_width;
2412 if (!icon_info || icon_info->pixbuf == NULL)
2415 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2416 settings = gtk_settings_get_for_screen (screen);
2418 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2419 &menu_icon_width, NULL);
2421 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2425 get_icon_allocations (GtkEntry *entry,
2426 GtkAllocation *primary,
2427 GtkAllocation *secondary)
2430 GtkEntryPrivate *priv = entry->priv;
2431 gint x, y, width, height;
2433 get_text_area_size (entry, &x, &y, &width, &height);
2435 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2436 y += priv->focus_width;
2439 primary->height = height;
2440 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2441 if (primary->width > 0)
2442 primary->width += 2 * priv->icon_margin;
2445 secondary->height = height;
2446 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2447 if (secondary->width > 0)
2448 secondary->width += 2 * priv->icon_margin;
2450 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2452 primary->x = x + width - primary->width;
2458 secondary->x = x + width - secondary->width;
2464 begin_change (GtkEntry *entry)
2466 GtkEntryPrivate *priv = entry->priv;
2468 priv->change_count++;
2472 end_change (GtkEntry *entry)
2474 GtkEditable *editable = GTK_EDITABLE (entry);
2475 GtkEntryPrivate *priv = entry->priv;
2477 g_return_if_fail (priv->change_count > 0);
2479 priv->change_count--;
2481 if (priv->change_count == 0)
2483 if (priv->real_changed)
2485 g_signal_emit_by_name (editable, "changed");
2486 priv->real_changed = FALSE;
2492 emit_changed (GtkEntry *entry)
2494 GtkEditable *editable = GTK_EDITABLE (entry);
2495 GtkEntryPrivate *priv = entry->priv;
2497 if (priv->change_count == 0)
2498 g_signal_emit_by_name (editable, "changed");
2500 priv->real_changed = TRUE;
2504 gtk_entry_destroy (GtkWidget *widget)
2506 GtkEntry *entry = GTK_ENTRY (widget);
2507 GtkEntryPrivate *priv = entry->priv;
2509 priv->current_pos = priv->selection_bound = 0;
2510 _gtk_entry_reset_im_context (entry);
2511 gtk_entry_reset_layout (entry);
2513 if (priv->blink_timeout)
2515 g_source_remove (priv->blink_timeout);
2516 priv->blink_timeout = 0;
2519 if (priv->recompute_idle)
2521 g_source_remove (priv->recompute_idle);
2522 priv->recompute_idle = 0;
2525 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2529 gtk_entry_dispose (GObject *object)
2531 GtkEntry *entry = GTK_ENTRY (object);
2532 GtkEntryPrivate *priv = entry->priv;
2534 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2535 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2536 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2537 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2541 buffer_disconnect_signals (entry);
2542 g_object_unref (priv->buffer);
2543 priv->buffer = NULL;
2546 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2550 gtk_entry_finalize (GObject *object)
2552 GtkEntry *entry = GTK_ENTRY (object);
2553 GtkEntryPrivate *priv = entry->priv;
2554 EntryIconInfo *icon_info = NULL;
2557 for (i = 0; i < MAX_ICONS; i++)
2559 if ((icon_info = priv->icons[i]) != NULL)
2561 if (icon_info->target_list != NULL)
2563 gtk_target_list_unref (icon_info->target_list);
2564 icon_info->target_list = NULL;
2567 g_slice_free (EntryIconInfo, icon_info);
2568 priv->icons[i] = NULL;
2572 gtk_entry_set_completion (entry, NULL);
2574 if (priv->cached_layout)
2575 g_object_unref (priv->cached_layout);
2577 g_object_unref (priv->im_context);
2579 if (priv->blink_timeout)
2580 g_source_remove (priv->blink_timeout);
2582 if (priv->recompute_idle)
2583 g_source_remove (priv->recompute_idle);
2585 g_free (priv->im_module);
2587 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2591 gtk_entry_get_display_mode (GtkEntry *entry)
2593 GtkEntryPrivate *priv = entry->priv;
2596 return DISPLAY_NORMAL;
2598 if (priv->invisible_char == 0 && priv->invisible_char_set)
2599 return DISPLAY_BLANK;
2601 return DISPLAY_INVISIBLE;
2605 gtk_entry_get_display_text (GtkEntry *entry,
2609 GtkEntryPasswordHint *password_hint;
2610 GtkEntryPrivate *priv;
2611 gunichar invisible_char;
2622 text = gtk_entry_buffer_get_text (get_buffer (entry));
2623 length = gtk_entry_buffer_get_length (get_buffer (entry));
2627 if (start_pos > length)
2630 if (end_pos <= start_pos)
2631 return g_strdup ("");
2632 else if (priv->visible)
2634 start = g_utf8_offset_to_pointer (text, start_pos);
2635 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2636 return g_strndup (start, end - start);
2640 str = g_string_sized_new (length * 2);
2642 /* Figure out what our invisible char is and encode it */
2643 if (!priv->invisible_char)
2644 invisible_char = priv->invisible_char_set ? ' ' : '*';
2646 invisible_char = priv->invisible_char;
2647 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2650 * Add hidden characters for each character in the text
2651 * buffer. If there is a password hint, then keep that
2652 * character visible.
2655 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2656 for (i = start_pos; i < end_pos; ++i)
2658 if (password_hint && i == password_hint->position)
2660 start = g_utf8_offset_to_pointer (text, i);
2661 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2665 g_string_append_len (str, char_str, char_len);
2669 return g_string_free (str, FALSE);
2675 update_cursors (GtkWidget *widget)
2677 GtkEntry *entry = GTK_ENTRY (widget);
2678 GtkEntryPrivate *priv = entry->priv;
2679 EntryIconInfo *icon_info = NULL;
2680 GdkDisplay *display;
2684 for (i = 0; i < MAX_ICONS; i++)
2686 if ((icon_info = priv->icons[i]) != NULL)
2688 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2689 gdk_window_show_unraised (icon_info->window);
2691 /* The icon windows are not children of the visible entry window,
2692 * thus we can't just inherit the xterm cursor. Slight complication
2693 * here is that for the entry, insensitive => arrow cursor, but for
2694 * an icon in a sensitive entry, insensitive => xterm cursor.
2696 if (gtk_widget_is_sensitive (widget) &&
2697 (icon_info->insensitive ||
2698 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2700 display = gtk_widget_get_display (widget);
2701 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2702 gdk_window_set_cursor (icon_info->window, cursor);
2703 g_object_unref (cursor);
2707 gdk_window_set_cursor (icon_info->window, NULL);
2714 realize_icon_info (GtkWidget *widget,
2715 GtkEntryIconPosition icon_pos)
2717 GtkEntry *entry = GTK_ENTRY (widget);
2718 GtkEntryPrivate *priv = entry->priv;
2719 EntryIconInfo *icon_info = priv->icons[icon_pos];
2720 GdkWindowAttr attributes;
2721 gint attributes_mask;
2723 g_return_if_fail (icon_info != NULL);
2727 attributes.width = 1;
2728 attributes.height = 1;
2729 attributes.window_type = GDK_WINDOW_CHILD;
2730 attributes.wclass = GDK_INPUT_ONLY;
2731 attributes.event_mask = gtk_widget_get_events (widget);
2732 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2733 GDK_BUTTON_RELEASE_MASK |
2734 GDK_BUTTON1_MOTION_MASK |
2735 GDK_BUTTON3_MOTION_MASK |
2736 GDK_POINTER_MOTION_HINT_MASK |
2737 GDK_POINTER_MOTION_MASK |
2738 GDK_ENTER_NOTIFY_MASK |
2739 GDK_LEAVE_NOTIFY_MASK);
2740 attributes_mask = GDK_WA_X | GDK_WA_Y;
2742 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2745 gdk_window_set_user_data (icon_info->window, widget);
2747 gtk_widget_queue_resize (widget);
2750 static EntryIconInfo*
2751 construct_icon_info (GtkWidget *widget,
2752 GtkEntryIconPosition icon_pos)
2754 GtkEntry *entry = GTK_ENTRY (widget);
2755 GtkEntryPrivate *priv = entry->priv;
2756 EntryIconInfo *icon_info;
2758 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2760 icon_info = g_slice_new0 (EntryIconInfo);
2761 priv->icons[icon_pos] = icon_info;
2763 if (gtk_widget_get_realized (widget))
2764 realize_icon_info (widget, icon_pos);
2770 gtk_entry_map (GtkWidget *widget)
2772 GtkEntry *entry = GTK_ENTRY (widget);
2773 GtkEntryPrivate *priv = entry->priv;
2774 EntryIconInfo *icon_info = NULL;
2777 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2779 gdk_window_show (priv->text_area);
2781 for (i = 0; i < MAX_ICONS; i++)
2783 if ((icon_info = priv->icons[i]) != NULL)
2785 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2786 gdk_window_show (icon_info->window);
2790 update_cursors (widget);
2794 gtk_entry_unmap (GtkWidget *widget)
2796 GtkEntry *entry = GTK_ENTRY (widget);
2797 GtkEntryPrivate *priv = entry->priv;
2798 EntryIconInfo *icon_info = NULL;
2801 for (i = 0; i < MAX_ICONS; i++)
2803 if ((icon_info = priv->icons[i]) != NULL)
2805 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2806 gdk_window_hide (icon_info->window);
2810 gdk_window_hide (priv->text_area);
2812 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2816 gtk_entry_realize (GtkWidget *widget)
2819 GtkEntryPrivate *priv;
2820 EntryIconInfo *icon_info;
2822 GdkWindowAttr attributes;
2823 gint attributes_mask;
2824 gint frame_x, frame_y;
2827 gtk_widget_set_realized (widget, TRUE);
2828 window = gtk_widget_get_parent_window (widget);
2829 gtk_widget_set_window (widget, window);
2830 g_object_ref (window);
2832 entry = GTK_ENTRY (widget);
2835 attributes.window_type = GDK_WINDOW_CHILD;
2836 attributes.wclass = GDK_INPUT_ONLY;
2837 attributes.event_mask = gtk_widget_get_events (widget);
2838 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2839 GDK_BUTTON_RELEASE_MASK |
2840 GDK_BUTTON1_MOTION_MASK |
2841 GDK_BUTTON3_MOTION_MASK |
2842 GDK_POINTER_MOTION_HINT_MASK |
2843 GDK_POINTER_MOTION_MASK |
2844 GDK_ENTER_NOTIFY_MASK |
2845 GDK_LEAVE_NOTIFY_MASK);
2846 attributes_mask = GDK_WA_X | GDK_WA_Y;
2848 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2850 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2851 attributes.x += frame_x;
2852 attributes.y += frame_y;
2854 if (gtk_widget_is_sensitive (widget))
2856 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2857 attributes_mask |= GDK_WA_CURSOR;
2860 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2864 gdk_window_set_user_data (priv->text_area, entry);
2866 if (attributes_mask & GDK_WA_CURSOR)
2867 g_object_unref (attributes.cursor);
2869 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2871 gtk_entry_adjust_scroll (entry);
2872 gtk_entry_update_primary_selection (entry);
2875 /* If the icon positions are already setup, create their windows.
2876 * Otherwise if they don't exist yet, then construct_icon_info()
2877 * will create the windows once the widget is already realized.
2879 for (i = 0; i < MAX_ICONS; i++)
2881 if ((icon_info = priv->icons[i]) != NULL)
2883 if (icon_info->window == NULL)
2884 realize_icon_info (widget, i);
2890 gtk_entry_unrealize (GtkWidget *widget)
2892 GtkEntry *entry = GTK_ENTRY (widget);
2893 GtkEntryPrivate *priv = entry->priv;
2894 GtkClipboard *clipboard;
2895 EntryIconInfo *icon_info;
2898 gtk_entry_reset_layout (entry);
2900 gtk_im_context_set_client_window (priv->im_context, NULL);
2902 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2903 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2904 gtk_clipboard_clear (clipboard);
2906 if (priv->text_area)
2908 gdk_window_set_user_data (priv->text_area, NULL);
2909 gdk_window_destroy (priv->text_area);
2910 priv->text_area = NULL;
2913 if (priv->popup_menu)
2915 gtk_widget_destroy (priv->popup_menu);
2916 priv->popup_menu = NULL;
2919 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2921 for (i = 0; i < MAX_ICONS; i++)
2923 if ((icon_info = priv->icons[i]) != NULL)
2925 if (icon_info->window != NULL)
2927 gdk_window_destroy (icon_info->window);
2928 icon_info->window = NULL;
2935 _gtk_entry_get_borders (GtkEntry *entry,
2939 GtkEntryPrivate *priv = entry->priv;
2940 GtkWidget *widget = GTK_WIDGET (entry);
2942 if (priv->has_frame)
2944 GtkStyleContext *context;
2947 context = gtk_widget_get_style_context (widget);
2948 gtk_style_context_get_padding (context, 0, &padding);
2950 *xborder = padding.left;
2951 *yborder = padding.top;
2959 if (!priv->interior_focus)
2961 *xborder += priv->focus_width;
2962 *yborder += priv->focus_width;
2967 gtk_entry_get_preferred_width (GtkWidget *widget,
2971 GtkEntry *entry = GTK_ENTRY (widget);
2972 GtkEntryPrivate *priv = entry->priv;
2973 PangoFontMetrics *metrics;
2974 gint xborder, yborder;
2975 GtkBorder inner_border;
2976 PangoContext *context;
2977 GtkStyleContext *style_context;
2978 GtkStateFlags state;
2979 gint icon_widths = 0;
2983 context = gtk_widget_get_pango_context (widget);
2985 style_context = gtk_widget_get_style_context (widget);
2986 state = gtk_widget_get_state_flags (widget);
2988 metrics = pango_context_get_metrics (context,
2989 gtk_style_context_get_font (style_context, state),
2990 pango_context_get_language (context));
2992 _gtk_entry_get_borders (entry, &xborder, &yborder);
2993 _gtk_entry_effective_inner_border (entry, &inner_border);
2995 if (priv->width_chars < 0)
2996 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2999 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3000 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3001 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3003 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3006 for (i = 0; i < MAX_ICONS; i++)
3008 icon_width = get_icon_width (entry, i);
3010 icon_widths += icon_width + 2 * priv->icon_margin;
3013 if (icon_widths > width)
3014 width += icon_widths;
3016 pango_font_metrics_unref (metrics);
3023 gtk_entry_get_preferred_height (GtkWidget *widget,
3027 GtkEntry *entry = GTK_ENTRY (widget);
3028 GtkEntryPrivate *priv = entry->priv;
3029 PangoFontMetrics *metrics;
3030 gint xborder, yborder;
3031 GtkBorder inner_border;
3032 GtkStyleContext *style_context;
3033 GtkStateFlags state;
3034 PangoContext *context;
3037 context = gtk_widget_get_pango_context (widget);
3039 style_context = gtk_widget_get_style_context (widget);
3040 state = gtk_widget_get_state_flags (widget);
3042 metrics = pango_context_get_metrics (context,
3043 gtk_style_context_get_font (style_context, state),
3044 pango_context_get_language (context));
3046 priv->ascent = pango_font_metrics_get_ascent (metrics);
3047 priv->descent = pango_font_metrics_get_descent (metrics);
3049 _gtk_entry_get_borders (entry, &xborder, &yborder);
3050 _gtk_entry_effective_inner_border (entry, &inner_border);
3052 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3054 pango_font_metrics_unref (metrics);
3061 place_windows (GtkEntry *entry)
3063 GtkWidget *widget = GTK_WIDGET (entry);
3064 GtkEntryPrivate *priv = entry->priv;
3065 gint x, y, width, height;
3066 gint frame_x, frame_y;
3067 GtkAllocation primary;
3068 GtkAllocation secondary;
3069 EntryIconInfo *icon_info = NULL;
3071 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
3072 get_text_area_size (entry, &x, &y, &width, &height);
3073 get_icon_allocations (entry, &primary, &secondary);
3075 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3076 y += priv->focus_width;
3078 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3079 x += secondary.width;
3082 width -= primary.width + secondary.width;
3086 primary.x += frame_x;
3087 primary.y += frame_y;
3088 secondary.x += frame_x;
3089 secondary.y += frame_y;
3091 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3092 gdk_window_move_resize (icon_info->window,
3093 primary.x, primary.y,
3094 primary.width, primary.height);
3096 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3097 gdk_window_move_resize (icon_info->window,
3098 secondary.x, secondary.y,
3099 secondary.width, secondary.height);
3101 gdk_window_move_resize (priv->text_area, x, y, width, height);
3105 gtk_entry_get_text_area_size (GtkEntry *entry,
3111 GtkEntryPrivate *priv = entry->priv;
3112 GtkWidget *widget = GTK_WIDGET (entry);
3113 GtkAllocation allocation;
3114 GtkRequisition requisition;
3116 gint xborder, yborder;
3118 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3119 gtk_widget_get_allocation (widget, &allocation);
3120 _gtk_entry_get_borders (entry, &xborder, &yborder);
3122 if (gtk_widget_get_realized (widget))
3123 get_frame_size (entry, NULL, NULL, NULL, &frame_height);
3125 frame_height = requisition.height;
3127 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3128 frame_height -= 2 * priv->focus_width;
3134 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3137 *width = allocation.width - xborder * 2;
3140 *height = requisition.height - yborder * 2;
3144 get_text_area_size (GtkEntry *entry,
3150 GtkEntryClass *class;
3152 g_return_if_fail (GTK_IS_ENTRY (entry));
3154 class = GTK_ENTRY_GET_CLASS (entry);
3156 if (class->get_text_area_size)
3157 class->get_text_area_size (entry, x, y, width, height);
3162 get_frame_size (GtkEntry *entry,
3168 GtkEntryPrivate *priv = entry->priv;
3169 GtkAllocation allocation;
3170 GtkRequisition requisition;
3171 GtkWidget *widget = GTK_WIDGET (entry);
3173 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3174 gtk_widget_get_allocation (widget, &allocation);
3181 if (priv->is_cell_renderer)
3184 *y = allocation.y + (allocation.height - requisition.height) / 2;
3188 *width = allocation.width;
3192 if (priv->is_cell_renderer)
3193 *height = allocation.height;
3195 *height = requisition.height;
3200 _gtk_entry_effective_inner_border (GtkEntry *entry,
3203 GtkBorder *tmp_border;
3205 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3209 *border = *tmp_border;
3213 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3217 *border = *tmp_border;
3218 gtk_border_free (tmp_border);
3222 *border = default_inner_border;
3226 gtk_entry_size_allocate (GtkWidget *widget,
3227 GtkAllocation *allocation)
3229 GtkEntry *entry = GTK_ENTRY (widget);
3231 gtk_widget_set_allocation (widget, allocation);
3233 if (gtk_widget_get_realized (widget))
3235 GtkEntryCompletion* completion;
3237 place_windows (entry);
3238 gtk_entry_recompute (entry);
3240 completion = gtk_entry_get_completion (entry);
3241 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3242 _gtk_entry_completion_resize_popup (completion);
3247 should_prelight (GtkEntry *entry,
3248 GtkEntryIconPosition icon_pos)
3250 GtkEntryPrivate *priv = entry->priv;
3251 EntryIconInfo *icon_info = priv->icons[icon_pos];
3257 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3260 if (icon_info->pressed)
3263 gtk_widget_style_get (GTK_WIDGET (entry),
3264 "icon-prelight", &prelight,
3271 draw_icon (GtkWidget *widget,
3273 GtkEntryIconPosition icon_pos)
3275 GtkEntry *entry = GTK_ENTRY (widget);
3276 GtkEntryPrivate *priv = entry->priv;
3277 EntryIconInfo *icon_info = priv->icons[icon_pos];
3279 gint x, y, width, height;
3280 GtkStyleContext *context;
3281 GtkIconSource *icon_source;
3282 GtkStateFlags state;
3287 gtk_entry_ensure_pixbuf (entry, icon_pos);
3289 if (icon_info->pixbuf == NULL)
3292 width = gdk_window_get_width (icon_info->window);
3293 height = gdk_window_get_height (icon_info->window);
3295 /* size_allocate hasn't been called yet. These are the default values.
3297 if (width == 1 || height == 1)
3300 pixbuf = icon_info->pixbuf;
3301 g_object_ref (pixbuf);
3303 if (gdk_pixbuf_get_height (pixbuf) > height)
3305 GdkPixbuf *temp_pixbuf;
3308 scale = height - 2 * priv->icon_margin;
3309 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3310 GDK_INTERP_BILINEAR);
3311 g_object_unref (pixbuf);
3312 pixbuf = temp_pixbuf;
3315 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3316 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3318 icon_source = gtk_icon_source_new ();
3319 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
3320 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
3323 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
3324 state |= GTK_STATE_FLAG_INSENSITIVE;
3325 else if (icon_info->prelight)
3326 state |= GTK_STATE_FLAG_PRELIGHT;
3328 context = gtk_widget_get_style_context (widget);
3329 gtk_style_context_save (context);
3330 gtk_style_context_set_state (context, state);
3331 pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
3332 gtk_style_context_restore (context);
3334 gtk_icon_source_free (icon_source);
3336 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3339 g_object_unref (pixbuf);
3344 gtk_entry_draw_frame (GtkWidget *widget,
3345 GtkStyleContext *context,
3348 GtkEntry *entry = GTK_ENTRY (widget);
3349 GtkEntryPrivate *priv = entry->priv;
3350 gint x = 0, y = 0, width, height;
3351 GtkAllocation allocation;
3352 gint frame_x, frame_y;
3356 get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
3357 gtk_widget_get_allocation (widget, &allocation);
3359 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3361 /* Fix a problem with some themes which assume that entry->text_area's
3362 * width equals widget->window's width
3363 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3364 if (GTK_IS_SPIN_BUTTON (widget))
3366 gint xborder, yborder;
3368 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3369 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3372 width += xborder * 2;
3375 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3377 x += priv->focus_width;
3378 y += priv->focus_width;
3379 width -= 2 * priv->focus_width;
3380 height -= 2 * priv->focus_width;
3383 gtk_render_background (context, cr,
3384 x, y, width, height);
3386 if (priv->has_frame)
3387 gtk_render_frame (context, cr,
3388 x, y, width, height);
3390 gtk_entry_draw_progress (widget, context, cr);
3392 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3394 x -= priv->focus_width;
3395 y -= priv->focus_width;
3396 width += 2 * priv->focus_width;
3397 height += 2 * priv->focus_width;
3399 gtk_render_focus (context, cr,
3400 0, 0, width, height);
3407 get_progress_area (GtkWidget *widget,
3413 GtkEntry *entry = GTK_ENTRY (widget);
3414 GtkEntryPrivate *private = entry->priv;
3415 GtkBorder *progress_border;
3417 get_text_area_size (entry, x, y, width, height);
3419 if (!private->interior_focus)
3421 *x -= private->focus_width;
3422 *y -= private->focus_width;
3423 *width += 2 * private->focus_width;
3424 *height += 2 * private->focus_width;
3427 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3429 if (progress_border)
3431 *x += progress_border->left;
3432 *y += progress_border->top;
3433 *width -= progress_border->left + progress_border->right;
3434 *height -= progress_border->top + progress_border->bottom;
3436 gtk_border_free (progress_border);
3439 if (private->progress_pulse_mode)
3441 gdouble value = private->progress_pulse_current;
3443 *x += (gint) floor(value * (*width));
3444 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3446 else if (private->progress_fraction > 0)
3448 gdouble value = private->progress_fraction;
3450 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3454 bar_width = floor(value * (*width) + 0.5);
3455 *x += *width - bar_width;
3460 *width = (gint) floor(value * (*width) + 0.5);
3471 gtk_entry_draw_progress (GtkWidget *widget,
3472 GtkStyleContext *context,
3475 gint x, y, width, height;
3477 get_progress_area (widget, &x, &y, &width, &height);
3479 if ((width <= 0) || (height <= 0))
3482 gtk_style_context_save (context);
3483 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3485 gtk_render_activity (context, cr,
3486 x, y, width, height);
3488 gtk_style_context_restore (context);
3492 gtk_entry_draw (GtkWidget *widget,
3495 GtkEntry *entry = GTK_ENTRY (widget);
3496 GtkStyleContext *context;
3497 GtkStateFlags state;
3498 GtkEntryPrivate *priv = entry->priv;
3501 context = gtk_widget_get_style_context (widget);
3502 state = gtk_widget_get_state_flags (widget);
3504 gtk_style_context_save (context);
3505 gtk_style_context_set_state (context, state);
3507 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3509 /* Draw entry_bg, shadow, progress and focus */
3510 gtk_entry_draw_frame (widget, context, cr);
3512 /* Draw text and cursor */
3515 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3517 if (priv->dnd_position != -1)
3518 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3520 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3522 /* When no text is being displayed at all, don't show the cursor */
3523 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3524 gtk_widget_has_focus (widget) &&
3525 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3526 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3531 for (i = 0; i < MAX_ICONS; i++)
3533 EntryIconInfo *icon_info = priv->icons[i];
3535 if (icon_info != NULL)
3539 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3541 draw_icon (widget, cr, i);
3548 gtk_style_context_restore (context);
3554 gtk_entry_enter_notify (GtkWidget *widget,
3555 GdkEventCrossing *event)
3557 GtkEntry *entry = GTK_ENTRY (widget);
3558 GtkEntryPrivate *priv = entry->priv;
3561 for (i = 0; i < MAX_ICONS; i++)
3563 EntryIconInfo *icon_info = priv->icons[i];
3565 if (icon_info != NULL && event->window == icon_info->window)
3567 if (should_prelight (entry, i))
3569 icon_info->prelight = TRUE;
3570 gtk_widget_queue_draw (widget);
3581 gtk_entry_leave_notify (GtkWidget *widget,
3582 GdkEventCrossing *event)
3584 GtkEntry *entry = GTK_ENTRY (widget);
3585 GtkEntryPrivate *priv = entry->priv;
3588 for (i = 0; i < MAX_ICONS; i++)
3590 EntryIconInfo *icon_info = priv->icons[i];
3592 if (icon_info != NULL && event->window == icon_info->window)
3594 /* a grab means that we may never see the button release */
3595 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3596 icon_info->pressed = FALSE;
3598 if (should_prelight (entry, i))
3600 icon_info->prelight = FALSE;
3601 gtk_widget_queue_draw (widget);
3612 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3616 gint start_char, end_char;
3618 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3620 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3621 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3622 const char *text = pango_layout_get_text (layout);
3623 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3624 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3625 gint real_n_ranges, i;
3627 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3633 for (i = 0; i < real_n_ranges; ++i)
3635 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3636 r[2 * i] = r[2 * i] / PANGO_SCALE;
3641 *n_ranges = real_n_ranges;
3653 in_selection (GtkEntry *entry,
3658 gint retval = FALSE;
3660 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3662 for (i = 0; i < n_ranges; ++i)
3664 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3676 gtk_entry_button_press (GtkWidget *widget,
3677 GdkEventButton *event)
3679 GtkEntry *entry = GTK_ENTRY (widget);
3680 GtkEditable *editable = GTK_EDITABLE (widget);
3681 GtkEntryPrivate *priv = entry->priv;
3682 EntryIconInfo *icon_info = NULL;
3684 gint sel_start, sel_end;
3687 for (i = 0; i < MAX_ICONS; i++)
3689 icon_info = priv->icons[i];
3691 if (!icon_info || icon_info->insensitive)
3694 if (event->window == icon_info->window)
3696 if (should_prelight (entry, i))
3698 icon_info->prelight = FALSE;
3699 gtk_widget_queue_draw (widget);
3702 priv->start_x = event->x;
3703 priv->start_y = event->y;
3704 icon_info->pressed = TRUE;
3706 if (!icon_info->nonactivatable)
3707 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3713 if (event->window != priv->text_area ||
3714 (priv->button && event->button != priv->button))
3717 gtk_entry_reset_blink_time (entry);
3719 priv->button = event->button;
3721 if (!gtk_widget_has_focus (widget))
3723 priv->in_click = TRUE;
3724 gtk_widget_grab_focus (widget);
3725 priv->in_click = FALSE;
3728 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3730 if (event->button == 1)
3732 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3734 priv->select_words = FALSE;
3735 priv->select_lines = FALSE;
3737 if (event->state & GDK_SHIFT_MASK)
3739 _gtk_entry_reset_im_context (entry);
3741 if (!have_selection) /* select from the current position to the clicked position */
3742 sel_start = sel_end = priv->current_pos;
3744 if (tmp_pos > sel_start && tmp_pos < sel_end)
3746 /* Truncate current selection, but keep it as big as possible */
3747 if (tmp_pos - sel_start > sel_end - tmp_pos)
3748 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3750 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3754 gboolean extend_to_left;
3757 /* Figure out what click selects and extend current selection */
3758 switch (event->type)
3760 case GDK_BUTTON_PRESS:
3761 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3764 case GDK_2BUTTON_PRESS:
3765 priv->select_words = TRUE;
3766 gtk_entry_select_word (entry);
3769 case GDK_3BUTTON_PRESS:
3770 priv->select_lines = TRUE;
3771 gtk_entry_select_line (entry);
3778 start = MIN (priv->current_pos, priv->selection_bound);
3779 start = MIN (sel_start, start);
3781 end = MAX (priv->current_pos, priv->selection_bound);
3782 end = MAX (sel_end, end);
3784 if (tmp_pos == sel_start || tmp_pos == sel_end)
3785 extend_to_left = (tmp_pos == start);
3787 extend_to_left = (end == sel_end);
3790 gtk_entry_set_positions (entry, start, end);
3792 gtk_entry_set_positions (entry, end, start);
3795 else /* no shift key */
3796 switch (event->type)
3798 case GDK_BUTTON_PRESS:
3799 if (in_selection (entry, event->x + priv->scroll_offset))
3801 /* Click inside the selection - we'll either start a drag, or
3802 * clear the selection
3804 priv->in_drag = TRUE;
3805 priv->drag_start_x = event->x + priv->scroll_offset;
3806 priv->drag_start_y = event->y;
3809 gtk_editable_set_position (editable, tmp_pos);
3812 case GDK_2BUTTON_PRESS:
3813 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3814 * receiving a GDK_2BUTTON_PRESS so we need to reset
3815 * priv->in_drag which may have been set above
3817 priv->in_drag = FALSE;
3818 priv->select_words = TRUE;
3819 gtk_entry_select_word (entry);
3822 case GDK_3BUTTON_PRESS:
3823 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3824 * receiving a GDK_3BUTTON_PRESS so we need to reset
3825 * priv->in_drag which may have been set above
3827 priv->in_drag = FALSE;
3828 priv->select_lines = TRUE;
3829 gtk_entry_select_line (entry);
3838 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3842 priv->insert_pos = tmp_pos;
3843 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3848 gtk_widget_error_bell (widget);
3851 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3853 gtk_entry_do_popup (entry, event);
3854 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3863 gtk_entry_button_release (GtkWidget *widget,
3864 GdkEventButton *event)
3866 GtkEntry *entry = GTK_ENTRY (widget);
3867 GtkEntryPrivate *priv = entry->priv;
3868 EntryIconInfo *icon_info = NULL;
3871 for (i = 0; i < MAX_ICONS; i++)
3873 icon_info = priv->icons[i];
3875 if (!icon_info || icon_info->insensitive)
3878 if (event->window == icon_info->window)
3880 icon_info->pressed = FALSE;
3882 if (should_prelight (entry, i) &&
3883 event->x >= 0 && event->y >= 0 &&
3884 event->x < gdk_window_get_width (icon_info->window) &&
3885 event->y < gdk_window_get_height (icon_info->window))
3887 icon_info->prelight = TRUE;
3888 gtk_widget_queue_draw (widget);
3891 if (!icon_info->nonactivatable)
3892 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3898 if (event->window != priv->text_area || priv->button != event->button)
3903 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3905 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3912 gtk_entry_update_primary_selection (entry);
3918 _gtk_entry_get_selected_text (GtkEntry *entry)
3920 GtkEditable *editable = GTK_EDITABLE (entry);
3921 gint start_text, end_text;
3924 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3925 text = gtk_editable_get_chars (editable, start_text, end_text);
3931 gtk_entry_motion_notify (GtkWidget *widget,
3932 GdkEventMotion *event)
3934 GtkEntry *entry = GTK_ENTRY (widget);
3935 GtkEntryPrivate *priv = entry->priv;
3936 EntryIconInfo *icon_info = NULL;
3940 for (i = 0; i < MAX_ICONS; i++)
3942 icon_info = priv->icons[i];
3944 if (!icon_info || icon_info->insensitive)
3947 if (event->window == icon_info->window)
3949 if (icon_info->pressed &&
3950 icon_info->target_list != NULL &&
3951 gtk_drag_check_threshold (widget,
3957 icon_info->in_drag = TRUE;
3958 icon_info->pressed = FALSE;
3959 gtk_drag_begin (widget,
3960 icon_info->target_list,
3970 if (priv->mouse_cursor_obscured)
3974 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3975 gdk_window_set_cursor (priv->text_area, cursor);
3976 g_object_unref (cursor);
3977 priv->mouse_cursor_obscured = FALSE;
3980 if (event->window != priv->text_area || priv->button != 1)
3983 if (priv->select_lines)
3986 gdk_event_request_motions (event);
3990 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3991 gtk_drag_check_threshold (widget,
3992 priv->drag_start_x, priv->drag_start_y,
3993 event->x + priv->scroll_offset, event->y))
3995 GdkDragContext *context;
3996 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3997 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3999 cairo_surface_t *surface;
4001 gtk_target_list_add_text_targets (target_list, 0);
4003 text = _gtk_entry_get_selected_text (entry);
4004 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4006 context = gtk_drag_begin (widget, target_list, actions,
4007 priv->button, (GdkEvent *)event);
4010 gtk_drag_set_icon_surface (context, surface);
4012 gtk_drag_set_icon_default (context);
4015 cairo_surface_destroy (surface);
4018 priv->in_drag = FALSE;
4021 gtk_target_list_unref (target_list);
4028 else if (event->y >= gdk_window_get_height (priv->text_area))
4029 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4031 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4033 if (priv->select_words)
4036 gint old_min, old_max;
4039 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4040 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4042 pos = priv->current_pos;
4043 bound = priv->selection_bound;
4045 old_min = MIN(priv->current_pos, priv->selection_bound);
4046 old_max = MAX(priv->current_pos, priv->selection_bound);
4053 else if (old_max < max)
4058 else if (pos == old_min)
4060 if (priv->current_pos != min)
4065 if (priv->current_pos != max)
4069 gtk_entry_set_positions (entry, pos, bound);
4072 gtk_entry_set_positions (entry, tmp_pos, -1);
4079 set_invisible_cursor (GdkWindow *window)
4081 GdkDisplay *display;
4084 display = gdk_window_get_display (window);
4085 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4087 gdk_window_set_cursor (window, cursor);
4089 g_object_unref (cursor);
4093 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4095 GtkEntryPrivate *priv = entry->priv;
4097 if (priv->mouse_cursor_obscured)
4100 set_invisible_cursor (priv->text_area);
4102 priv->mouse_cursor_obscured = TRUE;
4106 gtk_entry_key_press (GtkWidget *widget,
4109 GtkEntry *entry = GTK_ENTRY (widget);
4110 GtkEntryPrivate *priv = entry->priv;
4112 gtk_entry_reset_blink_time (entry);
4113 gtk_entry_pend_cursor_blink (entry);
4117 if (gtk_im_context_filter_keypress (priv->im_context, event))
4119 gtk_entry_obscure_mouse_cursor (entry);
4120 priv->need_im_reset = TRUE;
4125 if (event->keyval == GDK_KEY_Return ||
4126 event->keyval == GDK_KEY_KP_Enter ||
4127 event->keyval == GDK_KEY_ISO_Enter ||
4128 event->keyval == GDK_KEY_Escape)
4130 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4132 if (completion && completion->priv->completion_timeout)
4134 g_source_remove (completion->priv->completion_timeout);
4135 completion->priv->completion_timeout = 0;
4138 _gtk_entry_reset_im_context (entry);
4141 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4142 /* Activate key bindings
4146 if (!priv->editable && event->length)
4147 gtk_widget_error_bell (widget);
4153 gtk_entry_key_release (GtkWidget *widget,
4156 GtkEntry *entry = GTK_ENTRY (widget);
4157 GtkEntryPrivate *priv = entry->priv;
4161 if (gtk_im_context_filter_keypress (priv->im_context, event))
4163 priv->need_im_reset = TRUE;
4168 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4172 gtk_entry_focus_in (GtkWidget *widget,
4173 GdkEventFocus *event)
4175 GtkEntry *entry = GTK_ENTRY (widget);
4176 GtkEntryPrivate *priv = entry->priv;
4179 gtk_widget_queue_draw (widget);
4181 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4185 priv->need_im_reset = TRUE;
4186 gtk_im_context_focus_in (priv->im_context);
4187 keymap_state_changed (keymap, entry);
4188 g_signal_connect (keymap, "state-changed",
4189 G_CALLBACK (keymap_state_changed), entry);
4192 g_signal_connect (keymap, "direction-changed",
4193 G_CALLBACK (keymap_direction_changed), entry);
4195 gtk_entry_reset_blink_time (entry);
4196 gtk_entry_check_cursor_blink (entry);
4202 gtk_entry_focus_out (GtkWidget *widget,
4203 GdkEventFocus *event)
4205 GtkEntry *entry = GTK_ENTRY (widget);
4206 GtkEntryPrivate *priv = entry->priv;
4207 GtkEntryCompletion *completion;
4210 gtk_widget_queue_draw (widget);
4212 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4216 priv->need_im_reset = TRUE;
4217 gtk_im_context_focus_out (priv->im_context);
4218 remove_capslock_feedback (entry);
4221 gtk_entry_check_cursor_blink (entry);
4223 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4224 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4226 completion = gtk_entry_get_completion (entry);
4228 _gtk_entry_completion_popdown (completion);
4234 gtk_entry_grab_focus (GtkWidget *widget)
4236 GtkEntry *entry = GTK_ENTRY (widget);
4237 GtkEntryPrivate *priv = entry->priv;
4238 gboolean select_on_focus;
4240 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4242 if (priv->editable && !priv->in_click)
4244 g_object_get (gtk_widget_get_settings (widget),
4245 "gtk-entry-select-on-focus",
4249 if (select_on_focus)
4250 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4255 gtk_entry_direction_changed (GtkWidget *widget,
4256 GtkTextDirection previous_dir)
4258 GtkEntry *entry = GTK_ENTRY (widget);
4260 gtk_entry_recompute (entry);
4262 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4266 gtk_entry_state_flags_changed (GtkWidget *widget,
4267 GtkStateFlags previous_state)
4269 GtkEntry *entry = GTK_ENTRY (widget);
4270 GtkEntryPrivate *priv = entry->priv;
4273 if (gtk_widget_get_realized (widget))
4275 if (gtk_widget_is_sensitive (widget))
4276 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4280 gdk_window_set_cursor (priv->text_area, cursor);
4283 g_object_unref (cursor);
4285 priv->mouse_cursor_obscured = FALSE;
4287 update_cursors (widget);
4290 if (!gtk_widget_is_sensitive (widget))
4292 /* Clear any selection */
4293 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4296 gtk_widget_queue_draw (widget);
4300 gtk_entry_screen_changed (GtkWidget *widget,
4301 GdkScreen *old_screen)
4303 gtk_entry_recompute (GTK_ENTRY (widget));
4306 /* GtkEditable method implementations
4309 gtk_entry_insert_text (GtkEditable *editable,
4310 const gchar *new_text,
4311 gint new_text_length,
4314 g_object_ref (editable);
4317 * The incoming text may a password or other secret. We make sure
4318 * not to copy it into temporary buffers.
4321 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4323 g_object_unref (editable);
4327 gtk_entry_delete_text (GtkEditable *editable,
4331 g_object_ref (editable);
4333 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4335 g_object_unref (editable);
4339 gtk_entry_get_chars (GtkEditable *editable,
4343 GtkEntry *entry = GTK_ENTRY (editable);
4346 gint start_index, end_index;
4348 text = gtk_entry_buffer_get_text (get_buffer (entry));
4349 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4352 end_pos = text_length;
4354 start_pos = MIN (text_length, start_pos);
4355 end_pos = MIN (text_length, end_pos);
4357 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4358 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4360 return g_strndup (text + start_index, end_index - start_index);
4364 gtk_entry_real_set_position (GtkEditable *editable,
4367 GtkEntry *entry = GTK_ENTRY (editable);
4368 GtkEntryPrivate *priv = entry->priv;
4372 length = gtk_entry_buffer_get_length (get_buffer (entry));
4373 if (position < 0 || position > length)
4376 if (position != priv->current_pos ||
4377 position != priv->selection_bound)
4379 _gtk_entry_reset_im_context (entry);
4380 gtk_entry_set_positions (entry, position, position);
4385 gtk_entry_get_position (GtkEditable *editable)
4387 GtkEntry *entry = GTK_ENTRY (editable);
4388 GtkEntryPrivate *priv = entry->priv;
4390 return priv->current_pos;
4394 gtk_entry_set_selection_bounds (GtkEditable *editable,
4398 GtkEntry *entry = GTK_ENTRY (editable);
4401 length = gtk_entry_buffer_get_length (get_buffer (entry));
4407 _gtk_entry_reset_im_context (entry);
4409 gtk_entry_set_positions (entry,
4411 MIN (start, length));
4413 gtk_entry_update_primary_selection (entry);
4417 gtk_entry_get_selection_bounds (GtkEditable *editable,
4421 GtkEntry *entry = GTK_ENTRY (editable);
4422 GtkEntryPrivate *priv = entry->priv;
4424 *start = priv->selection_bound;
4425 *end = priv->current_pos;
4427 return (priv->selection_bound != priv->current_pos);
4431 icon_theme_changed (GtkEntry *entry)
4433 GtkEntryPrivate *priv = entry->priv;
4436 for (i = 0; i < MAX_ICONS; i++)
4438 EntryIconInfo *icon_info = priv->icons[i];
4439 if (icon_info != NULL)
4441 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4442 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4443 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4444 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4445 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4446 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4450 gtk_widget_queue_draw (GTK_WIDGET (entry));
4454 icon_margin_changed (GtkEntry *entry)
4456 GtkEntryPrivate *priv = entry->priv;
4459 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4461 priv->icon_margin = border.left;
4465 gtk_entry_style_updated (GtkWidget *widget)
4467 GtkEntry *entry = GTK_ENTRY (widget);
4468 GtkEntryPrivate *priv = entry->priv;
4470 gboolean interior_focus;
4472 gtk_widget_style_get (widget,
4473 "focus-line-width", &focus_width,
4474 "interior-focus", &interior_focus,
4477 priv->focus_width = focus_width;
4478 priv->interior_focus = interior_focus;
4480 if (!priv->invisible_char_set)
4481 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4483 gtk_entry_recompute (entry);
4485 icon_theme_changed (entry);
4486 icon_margin_changed (entry);
4489 /* GtkCellEditable method implementations
4492 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4494 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4495 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4499 gtk_cell_editable_key_press_event (GtkEntry *entry,
4500 GdkEventKey *key_event,
4503 GtkEntryPrivate *priv = entry->priv;
4505 if (key_event->keyval == GDK_KEY_Escape)
4507 priv->editing_canceled = TRUE;
4508 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4509 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4514 /* override focus */
4515 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4517 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4518 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4527 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4530 GtkEntry *entry = GTK_ENTRY (cell_editable);
4531 GtkEntryPrivate *priv = entry->priv;
4533 priv->is_cell_renderer = TRUE;
4535 g_signal_connect (cell_editable, "activate",
4536 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4537 g_signal_connect (cell_editable, "key-press-event",
4538 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4542 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4544 if (password_hint->source_id)
4545 g_source_remove (password_hint->source_id);
4547 g_slice_free (GtkEntryPasswordHint, password_hint);
4552 gtk_entry_remove_password_hint (gpointer data)
4554 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4555 password_hint->position = -1;
4557 /* Force the string to be redrawn, but now without a visible character */
4558 gtk_entry_recompute (GTK_ENTRY (data));
4562 /* Default signal handlers
4565 gtk_entry_real_insert_text (GtkEditable *editable,
4566 const gchar *new_text,
4567 gint new_text_length,
4573 n_chars = g_utf8_strlen (new_text, new_text_length);
4576 * The actual insertion into the buffer. This will end up firing the
4577 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4578 * buffer_notify_text(), buffer_notify_length()
4580 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4582 if (n_inserted != n_chars)
4583 gtk_widget_error_bell (GTK_WIDGET (editable));
4585 *position += n_inserted;
4589 gtk_entry_real_delete_text (GtkEditable *editable,
4594 * The actual deletion from the buffer. This will end up firing the
4595 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4596 * buffer_notify_text(), buffer_notify_length()
4599 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4602 /* GtkEntryBuffer signal handlers
4605 buffer_inserted_text (GtkEntryBuffer *buffer,
4611 GtkEntryPrivate *priv = entry->priv;
4612 guint password_hint_timeout;
4614 if (priv->current_pos > position)
4615 priv->current_pos += n_chars;
4617 if (priv->selection_bound > position)
4618 priv->selection_bound += n_chars;
4620 /* Calculate the password hint if it needs to be displayed. */
4621 if (n_chars == 1 && !priv->visible)
4623 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4624 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4627 if (password_hint_timeout > 0)
4629 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4630 quark_password_hint);
4633 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4634 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4635 (GDestroyNotify)gtk_entry_password_hint_free);
4638 password_hint->position = position;
4639 if (password_hint->source_id)
4640 g_source_remove (password_hint->source_id);
4641 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4642 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4648 buffer_deleted_text (GtkEntryBuffer *buffer,
4653 GtkEntryPrivate *priv = entry->priv;
4654 guint end_pos = position + n_chars;
4655 gint selection_bound;
4658 current_pos = priv->current_pos;
4659 if (current_pos > position)
4660 current_pos -= MIN (current_pos, end_pos) - position;
4662 selection_bound = priv->selection_bound;
4663 if (selection_bound > position)
4664 selection_bound -= MIN (selection_bound, end_pos) - position;
4666 gtk_entry_set_positions (entry, current_pos, selection_bound);
4668 /* We might have deleted the selection */
4669 gtk_entry_update_primary_selection (entry);
4671 /* Disable the password hint if one exists. */
4674 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4675 quark_password_hint);
4678 if (password_hint->source_id)
4679 g_source_remove (password_hint->source_id);
4680 password_hint->source_id = 0;
4681 password_hint->position = -1;
4687 buffer_notify_text (GtkEntryBuffer *buffer,
4691 gtk_entry_recompute (entry);
4692 emit_changed (entry);
4693 g_object_notify (G_OBJECT (entry), "text");
4697 buffer_notify_length (GtkEntryBuffer *buffer,
4701 g_object_notify (G_OBJECT (entry), "text-length");
4705 buffer_notify_max_length (GtkEntryBuffer *buffer,
4709 g_object_notify (G_OBJECT (entry), "max-length");
4713 buffer_connect_signals (GtkEntry *entry)
4715 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4716 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4717 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4718 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4719 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4723 buffer_disconnect_signals (GtkEntry *entry)
4725 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4726 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4727 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4728 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4729 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4732 /* Compute the X position for an offset that corresponds to the "more important
4733 * cursor position for that offset. We use this when trying to guess to which
4734 * end of the selection we should go to when the user hits the left or
4738 get_better_cursor_x (GtkEntry *entry,
4741 GtkEntryPrivate *priv = entry->priv;
4742 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4743 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4744 gboolean split_cursor;
4746 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4747 const gchar *text = pango_layout_get_text (layout);
4748 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4750 PangoRectangle strong_pos, weak_pos;
4752 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4753 "gtk-split-cursor", &split_cursor,
4756 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4759 return strong_pos.x / PANGO_SCALE;
4761 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4765 gtk_entry_move_cursor (GtkEntry *entry,
4766 GtkMovementStep step,
4768 gboolean extend_selection)
4770 GtkEntryPrivate *priv = entry->priv;
4771 gint new_pos = priv->current_pos;
4773 _gtk_entry_reset_im_context (entry);
4775 if (priv->current_pos != priv->selection_bound && !extend_selection)
4777 /* If we have a current selection and aren't extending it, move to the
4778 * start/or end of the selection as appropriate
4782 case GTK_MOVEMENT_VISUAL_POSITIONS:
4784 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4785 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4788 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4790 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4793 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4794 case GTK_MOVEMENT_WORDS:
4796 new_pos = MIN (priv->current_pos, priv->selection_bound);
4798 new_pos = MAX (priv->current_pos, priv->selection_bound);
4800 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4801 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4802 case GTK_MOVEMENT_BUFFER_ENDS:
4803 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4805 case GTK_MOVEMENT_DISPLAY_LINES:
4806 case GTK_MOVEMENT_PARAGRAPHS:
4807 case GTK_MOVEMENT_PAGES:
4808 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4816 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4817 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4819 case GTK_MOVEMENT_VISUAL_POSITIONS:
4820 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4821 if (priv->current_pos == new_pos)
4823 if (!extend_selection)
4825 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4827 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4829 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4832 gtk_widget_child_focus (toplevel,
4834 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4839 gtk_widget_error_bell (GTK_WIDGET (entry));
4843 case GTK_MOVEMENT_WORDS:
4846 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4851 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4854 if (priv->current_pos == new_pos)
4855 gtk_widget_error_bell (GTK_WIDGET (entry));
4857 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4858 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4859 case GTK_MOVEMENT_BUFFER_ENDS:
4860 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4861 if (priv->current_pos == new_pos)
4862 gtk_widget_error_bell (GTK_WIDGET (entry));
4864 case GTK_MOVEMENT_DISPLAY_LINES:
4865 case GTK_MOVEMENT_PARAGRAPHS:
4866 case GTK_MOVEMENT_PAGES:
4867 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4872 if (extend_selection)
4873 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4875 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4877 gtk_entry_pend_cursor_blink (entry);
4881 gtk_entry_insert_at_cursor (GtkEntry *entry,
4884 GtkEntryPrivate *priv = entry->priv;
4885 GtkEditable *editable = GTK_EDITABLE (entry);
4886 gint pos = priv->current_pos;
4890 _gtk_entry_reset_im_context (entry);
4892 gtk_editable_insert_text (editable, str, -1, &pos);
4893 gtk_editable_set_position (editable, pos);
4898 gtk_entry_delete_from_cursor (GtkEntry *entry,
4902 GtkEntryPrivate *priv = entry->priv;
4903 GtkEditable *editable = GTK_EDITABLE (entry);
4904 gint start_pos = priv->current_pos;
4905 gint end_pos = priv->current_pos;
4906 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4908 _gtk_entry_reset_im_context (entry);
4910 if (!priv->editable)
4912 gtk_widget_error_bell (GTK_WIDGET (entry));
4916 if (priv->selection_bound != priv->current_pos)
4918 gtk_editable_delete_selection (editable);
4924 case GTK_DELETE_CHARS:
4925 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
4926 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4928 case GTK_DELETE_WORDS:
4931 /* Move to end of current word, or if not on a word, end of previous word */
4932 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4933 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4937 /* Move to beginning of current word, or if not on a word, begining of next word */
4938 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4939 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4943 case GTK_DELETE_WORD_ENDS:
4946 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4951 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4954 gtk_editable_delete_text (editable, start_pos, end_pos);
4956 case GTK_DELETE_DISPLAY_LINE_ENDS:
4957 case GTK_DELETE_PARAGRAPH_ENDS:
4959 gtk_editable_delete_text (editable, 0, priv->current_pos);
4961 gtk_editable_delete_text (editable, priv->current_pos, -1);
4963 case GTK_DELETE_DISPLAY_LINES:
4964 case GTK_DELETE_PARAGRAPHS:
4965 gtk_editable_delete_text (editable, 0, -1);
4967 case GTK_DELETE_WHITESPACE:
4968 gtk_entry_delete_whitespace (entry);
4972 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4973 gtk_widget_error_bell (GTK_WIDGET (entry));
4975 gtk_entry_pend_cursor_blink (entry);
4979 gtk_entry_backspace (GtkEntry *entry)
4981 GtkEntryPrivate *priv = entry->priv;
4982 GtkEditable *editable = GTK_EDITABLE (entry);
4985 _gtk_entry_reset_im_context (entry);
4987 if (!priv->editable)
4989 gtk_widget_error_bell (GTK_WIDGET (entry));
4993 if (priv->selection_bound != priv->current_pos)
4995 gtk_editable_delete_selection (editable);
4999 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5001 if (prev_pos < priv->current_pos)
5003 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5004 PangoLogAttr *log_attrs;
5007 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5009 /* Deleting parts of characters */
5010 if (log_attrs[priv->current_pos].backspace_deletes_character)
5012 gchar *cluster_text;
5013 gchar *normalized_text;
5016 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5018 normalized_text = g_utf8_normalize (cluster_text,
5019 strlen (cluster_text),
5021 len = g_utf8_strlen (normalized_text, -1);
5023 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5026 gint pos = priv->current_pos;
5028 gtk_editable_insert_text (editable, normalized_text,
5029 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5031 gtk_editable_set_position (editable, pos);
5034 g_free (normalized_text);
5035 g_free (cluster_text);
5039 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5046 gtk_widget_error_bell (GTK_WIDGET (entry));
5049 gtk_entry_pend_cursor_blink (entry);
5053 gtk_entry_copy_clipboard (GtkEntry *entry)
5055 GtkEntryPrivate *priv = entry->priv;
5056 GtkEditable *editable = GTK_EDITABLE (entry);
5060 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5064 gtk_widget_error_bell (GTK_WIDGET (entry));
5068 str = gtk_entry_get_display_text (entry, start, end);
5069 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5070 GDK_SELECTION_CLIPBOARD),
5077 gtk_entry_cut_clipboard (GtkEntry *entry)
5079 GtkEntryPrivate *priv = entry->priv;
5080 GtkEditable *editable = GTK_EDITABLE (entry);
5085 gtk_widget_error_bell (GTK_WIDGET (entry));
5089 gtk_entry_copy_clipboard (entry);
5093 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5094 gtk_editable_delete_text (editable, start, end);
5098 gtk_widget_error_bell (GTK_WIDGET (entry));
5103 gtk_entry_paste_clipboard (GtkEntry *entry)
5105 GtkEntryPrivate *priv = entry->priv;
5108 gtk_entry_paste (entry, GDK_NONE);
5110 gtk_widget_error_bell (GTK_WIDGET (entry));
5114 gtk_entry_delete_cb (GtkEntry *entry)
5116 GtkEntryPrivate *priv = entry->priv;
5117 GtkEditable *editable = GTK_EDITABLE (entry);
5122 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5123 gtk_editable_delete_text (editable, start, end);
5128 gtk_entry_toggle_overwrite (GtkEntry *entry)
5130 GtkEntryPrivate *priv = entry->priv;
5132 priv->overwrite_mode = !priv->overwrite_mode;
5133 gtk_entry_pend_cursor_blink (entry);
5134 gtk_widget_queue_draw (GTK_WIDGET (entry));
5138 gtk_entry_select_all (GtkEntry *entry)
5140 gtk_entry_select_line (entry);
5144 gtk_entry_real_activate (GtkEntry *entry)
5146 GtkEntryPrivate *priv = entry->priv;
5148 GtkWidget *default_widget, *focus_widget;
5149 GtkWidget *toplevel;
5152 widget = GTK_WIDGET (entry);
5154 if (priv->activates_default)
5156 toplevel = gtk_widget_get_toplevel (widget);
5157 if (GTK_IS_WINDOW (toplevel))
5159 window = GTK_WINDOW (toplevel);
5163 default_widget = gtk_window_get_default_widget (window);
5164 focus_widget = gtk_window_get_focus (window);
5165 if (widget != default_widget &&
5166 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5167 gtk_window_activate_default (window);
5174 keymap_direction_changed (GdkKeymap *keymap,
5177 gtk_entry_recompute (entry);
5180 /* IM Context Callbacks
5184 gtk_entry_commit_cb (GtkIMContext *context,
5188 GtkEntryPrivate *priv = entry->priv;
5191 gtk_entry_enter_text (entry, str);
5195 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5198 GtkEntryPrivate *priv = entry->priv;
5202 gchar *preedit_string;
5205 gtk_im_context_get_preedit_string (priv->im_context,
5206 &preedit_string, NULL,
5208 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5209 priv->preedit_length = strlen (preedit_string);
5210 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5211 priv->preedit_cursor = cursor_pos;
5212 g_free (preedit_string);
5214 gtk_entry_recompute (entry);
5219 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5222 GtkEntryPrivate *priv = entry->priv;
5225 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5226 text = gtk_entry_get_display_text (entry, 0, -1);
5227 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5228 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5235 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5240 GtkEntryPrivate *priv = entry->priv;
5243 gtk_editable_delete_text (GTK_EDITABLE (entry),
5244 priv->current_pos + offset,
5245 priv->current_pos + offset + n_chars);
5250 /* Internal functions
5253 /* Used for im_commit_cb and inserting Unicode chars */
5255 gtk_entry_enter_text (GtkEntry *entry,
5258 GtkEntryPrivate *priv = entry->priv;
5259 GtkEditable *editable = GTK_EDITABLE (entry);
5261 gboolean old_need_im_reset;
5263 old_need_im_reset = priv->need_im_reset;
5264 priv->need_im_reset = FALSE;
5266 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5267 gtk_editable_delete_selection (editable);
5270 if (priv->overwrite_mode)
5271 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5274 tmp_pos = priv->current_pos;
5275 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5276 gtk_editable_set_position (editable, tmp_pos);
5278 priv->need_im_reset = old_need_im_reset;
5281 /* All changes to priv->current_pos and priv->selection_bound
5282 * should go through this function.
5285 gtk_entry_set_positions (GtkEntry *entry,
5287 gint selection_bound)
5289 GtkEntryPrivate *priv = entry->priv;
5290 gboolean changed = FALSE;
5292 g_object_freeze_notify (G_OBJECT (entry));
5294 if (current_pos != -1 &&
5295 priv->current_pos != current_pos)
5297 priv->current_pos = current_pos;
5300 g_object_notify (G_OBJECT (entry), "cursor-position");
5303 if (selection_bound != -1 &&
5304 priv->selection_bound != selection_bound)
5306 priv->selection_bound = selection_bound;
5309 g_object_notify (G_OBJECT (entry), "selection-bound");
5312 g_object_thaw_notify (G_OBJECT (entry));
5316 gtk_entry_move_adjustments (entry);
5317 gtk_entry_recompute (entry);
5322 gtk_entry_reset_layout (GtkEntry *entry)
5324 GtkEntryPrivate *priv = entry->priv;
5326 if (priv->cached_layout)
5328 g_object_unref (priv->cached_layout);
5329 priv->cached_layout = NULL;
5334 update_im_cursor_location (GtkEntry *entry)
5336 GtkEntryPrivate *priv = entry->priv;
5339 gint strong_xoffset;
5340 gint area_width, area_height;
5342 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5343 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5345 strong_xoffset = strong_x - priv->scroll_offset;
5346 if (strong_xoffset < 0)
5350 else if (strong_xoffset > area_width)
5352 strong_xoffset = area_width;
5354 area.x = strong_xoffset;
5357 area.height = area_height;
5359 gtk_im_context_set_cursor_location (priv->im_context, &area);
5363 recompute_idle_func (gpointer data)
5365 GtkEntry *entry = GTK_ENTRY (data);
5366 GtkEntryPrivate *priv = entry->priv;
5368 priv->recompute_idle = 0;
5370 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5372 gtk_entry_adjust_scroll (entry);
5373 gtk_entry_queue_draw (entry);
5375 update_im_cursor_location (entry);
5382 gtk_entry_recompute (GtkEntry *entry)
5384 GtkEntryPrivate *priv = entry->priv;
5386 gtk_entry_reset_layout (entry);
5387 gtk_entry_check_cursor_blink (entry);
5389 if (!priv->recompute_idle)
5391 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5392 recompute_idle_func, entry, NULL);
5396 static PangoLayout *
5397 gtk_entry_create_layout (GtkEntry *entry,
5398 gboolean include_preedit)
5400 GtkEntryPrivate *priv = entry->priv;
5401 GtkWidget *widget = GTK_WIDGET (entry);
5402 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5403 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5405 gchar *preedit_string = NULL;
5406 gint preedit_length = 0;
5407 PangoAttrList *preedit_attrs = NULL;
5412 pango_layout_set_single_paragraph_mode (layout, TRUE);
5414 display = gtk_entry_get_display_text (entry, 0, -1);
5415 n_bytes = strlen (display);
5417 if (include_preedit)
5419 gtk_im_context_get_preedit_string (priv->im_context,
5420 &preedit_string, &preedit_attrs, NULL);
5421 preedit_length = priv->preedit_length;
5426 GString *tmp_string = g_string_new (display);
5427 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5429 g_string_insert (tmp_string, cursor_index, preedit_string);
5431 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5433 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5434 cursor_index, preedit_length);
5436 g_string_free (tmp_string, TRUE);
5440 PangoDirection pango_dir;
5442 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5443 pango_dir = pango_find_base_dir (display, n_bytes);
5445 pango_dir = PANGO_DIRECTION_NEUTRAL;
5447 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5449 if (gtk_widget_has_focus (widget))
5451 GdkDisplay *display = gtk_widget_get_display (widget);
5452 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5453 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5454 pango_dir = PANGO_DIRECTION_RTL;
5456 pango_dir = PANGO_DIRECTION_LTR;
5460 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5461 pango_dir = PANGO_DIRECTION_RTL;
5463 pango_dir = PANGO_DIRECTION_LTR;
5467 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5470 priv->resolved_dir = pango_dir;
5472 pango_layout_set_text (layout, display, n_bytes);
5475 pango_layout_set_attributes (layout, tmp_attrs);
5477 g_free (preedit_string);
5481 pango_attr_list_unref (preedit_attrs);
5483 pango_attr_list_unref (tmp_attrs);
5488 static PangoLayout *
5489 gtk_entry_ensure_layout (GtkEntry *entry,
5490 gboolean include_preedit)
5492 GtkEntryPrivate *priv = entry->priv;
5494 if (priv->preedit_length > 0 &&
5495 !include_preedit != !priv->cache_includes_preedit)
5496 gtk_entry_reset_layout (entry);
5498 if (!priv->cached_layout)
5500 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5501 priv->cache_includes_preedit = include_preedit;
5504 return priv->cached_layout;
5508 get_layout_position (GtkEntry *entry,
5512 GtkEntryPrivate *priv = entry->priv;
5513 PangoLayout *layout;
5514 PangoRectangle logical_rect;
5515 gint area_width, area_height;
5516 GtkBorder inner_border;
5518 PangoLayoutLine *line;
5520 layout = gtk_entry_ensure_layout (entry, TRUE);
5522 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5523 _gtk_entry_effective_inner_border (entry, &inner_border);
5525 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5527 line = pango_layout_get_lines_readonly (layout)->data;
5528 pango_layout_line_get_extents (line, NULL, &logical_rect);
5530 /* Align primarily for locale's ascent/descent */
5531 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5532 priv->ascent + logical_rect.y);
5534 /* Now see if we need to adjust to fit in actual drawn string */
5535 if (logical_rect.height > area_height)
5536 y_pos = (area_height - logical_rect.height) / 2;
5539 else if (y_pos + logical_rect.height > area_height)
5540 y_pos = area_height - logical_rect.height;
5542 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5545 *x = inner_border.left - priv->scroll_offset;
5552 draw_text_with_color (GtkEntry *entry,
5554 GdkRGBA *default_color)
5556 GtkEntryPrivate *priv = entry->priv;
5557 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5560 gint start_pos, end_pos;
5562 widget = GTK_WIDGET (entry);
5566 get_layout_position (entry, &x, &y);
5568 cairo_move_to (cr, x, y);
5569 gdk_cairo_set_source_rgba (cr, default_color);
5570 pango_cairo_show_layout (cr, layout);
5572 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5576 PangoRectangle logical_rect;
5577 GdkRGBA selection_color, text_color;
5578 GtkBorder inner_border;
5579 GtkStyleContext *context;
5580 GtkStateFlags state;
5582 context = gtk_widget_get_style_context (widget);
5583 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5584 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5586 state = GTK_STATE_FLAG_SELECTED;
5588 if (gtk_widget_has_focus (widget))
5589 state |= GTK_STATE_FLAG_FOCUSED;
5591 gtk_style_context_get_background_color (context, state, &selection_color);
5592 gtk_style_context_get_color (context, state, &text_color);
5594 _gtk_entry_effective_inner_border (entry, &inner_border);
5596 for (i = 0; i < n_ranges; ++i)
5597 cairo_rectangle (cr,
5598 inner_border.left - priv->scroll_offset + ranges[2 * i],
5601 logical_rect.height);
5605 gdk_cairo_set_source_rgba (cr, &selection_color);
5608 cairo_move_to (cr, x, y);
5609 gdk_cairo_set_source_rgba (cr, &text_color);
5610 pango_cairo_show_layout (cr, layout);
5618 gtk_entry_draw_text (GtkEntry *entry,
5621 GtkEntryPrivate *priv = entry->priv;
5622 GtkWidget *widget = GTK_WIDGET (entry);
5623 GtkStateFlags state = 0;
5624 GdkRGBA text_color, bar_text_color;
5625 GtkStyleContext *context;
5628 gint progress_x, progress_y, progress_width, progress_height;
5629 gint clip_width, clip_height;
5631 /* Nothing to display at all */
5632 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5635 state = gtk_widget_get_state_flags (widget);
5636 context = gtk_widget_get_style_context (widget);
5638 gtk_style_context_get_color (context, state, &text_color);
5640 /* Get foreground color for progressbars */
5641 gtk_style_context_save (context);
5642 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5643 gtk_style_context_get_color (context, state, &bar_text_color);
5644 gtk_style_context_restore (context);
5646 get_progress_area (widget,
5647 &progress_x, &progress_y,
5648 &progress_width, &progress_height);
5650 clip_width = gdk_window_get_width (priv->text_area);
5651 clip_height = gdk_window_get_height (priv->text_area);
5652 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5655 /* If the color is the same, or the progress area has a zero
5656 * size, then we only need to draw once. */
5657 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5658 ((progress_width == 0) || (progress_height == 0)))
5660 draw_text_with_color (entry, cr, &text_color);
5664 width = gdk_window_get_width (priv->text_area);
5665 height = gdk_window_get_height (priv->text_area);
5669 cairo_rectangle (cr, 0, 0, width, height);
5673 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5674 cairo_rectangle (cr, 0, 0, width, height);
5676 gdk_window_get_position (priv->text_area, &pos_x, &pos_y);
5677 progress_x -= pos_x;
5678 progress_y -= pos_y;
5680 cairo_rectangle (cr, progress_x, progress_y,
5681 progress_width, progress_height);
5683 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5685 draw_text_with_color (entry, cr, &text_color);
5688 cairo_rectangle (cr, progress_x, progress_y,
5689 progress_width, progress_height);
5692 draw_text_with_color (entry, cr, &bar_text_color);
5699 draw_insertion_cursor (GtkEntry *entry,
5701 GdkRectangle *cursor_location,
5702 gboolean is_primary,
5703 PangoDirection direction,
5704 gboolean draw_arrow)
5706 GtkWidget *widget = GTK_WIDGET (entry);
5707 GtkTextDirection text_dir;
5709 if (direction == PANGO_DIRECTION_LTR)
5710 text_dir = GTK_TEXT_DIR_LTR;
5712 text_dir = GTK_TEXT_DIR_RTL;
5714 gtk_draw_insertion_cursor (widget, cr,
5716 is_primary, text_dir, draw_arrow);
5720 gtk_entry_draw_cursor (GtkEntry *entry,
5724 GtkEntryPrivate *priv = entry->priv;
5725 GtkWidget *widget = GTK_WIDGET (entry);
5726 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5727 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5728 GdkRectangle cursor_location;
5729 gboolean split_cursor;
5730 PangoRectangle cursor_rect;
5731 GtkBorder inner_border;
5733 gint text_area_height;
5736 gboolean block_at_line_end;
5737 PangoLayout *layout;
5740 _gtk_entry_effective_inner_border (entry, &inner_border);
5742 xoffset = inner_border.left - priv->scroll_offset;
5744 text_area_height = gdk_window_get_height (priv->text_area);
5746 layout = gtk_entry_ensure_layout (entry, TRUE);
5747 text = pango_layout_get_text (layout);
5748 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5749 if (!priv->overwrite_mode)
5752 block = _gtk_text_util_get_block_cursor_location (layout,
5753 cursor_index, &cursor_rect, &block_at_line_end);
5757 gint strong_x, weak_x;
5758 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5759 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5763 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5765 g_object_get (gtk_widget_get_settings (widget),
5766 "gtk-split-cursor", &split_cursor,
5769 dir1 = priv->resolved_dir;
5775 if (weak_x != strong_x)
5777 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5783 if (keymap_direction == priv->resolved_dir)
5789 cursor_location.x = xoffset + x1;
5790 cursor_location.y = inner_border.top;
5791 cursor_location.width = 0;
5792 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5794 draw_insertion_cursor (entry, cr,
5795 &cursor_location, TRUE, dir1,
5796 dir2 != PANGO_DIRECTION_NEUTRAL);
5798 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5800 cursor_location.x = xoffset + x2;
5801 draw_insertion_cursor (entry, cr,
5802 &cursor_location, FALSE, dir2,
5806 else /* overwrite_mode */
5808 GtkStyleContext *context;
5809 GdkRGBA cursor_color;
5815 get_layout_position (entry, &x, &y);
5817 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5818 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5819 rect.width = PANGO_PIXELS (cursor_rect.width);
5820 rect.height = PANGO_PIXELS (cursor_rect.height);
5822 context = gtk_widget_get_style_context (widget);
5824 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5825 gdk_cairo_set_source_rgba (cr, &cursor_color);
5826 gdk_cairo_rectangle (cr, &rect);
5829 if (!block_at_line_end)
5831 GtkStateFlags state;
5834 state = gtk_widget_get_state_flags (widget);
5835 gtk_style_context_get_background_color (context, state, &color);
5837 gdk_cairo_rectangle (cr, &rect);
5839 cairo_move_to (cr, x, y);
5840 gdk_cairo_set_source_rgba (cr, &color);
5841 pango_cairo_show_layout (cr, layout);
5849 gtk_entry_queue_draw (GtkEntry *entry)
5851 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5852 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
5857 _gtk_entry_reset_im_context (GtkEntry *entry)
5859 GtkEntryPrivate *priv = entry->priv;
5861 if (priv->need_im_reset)
5863 priv->need_im_reset = FALSE;
5864 gtk_im_context_reset (priv->im_context);
5869 * gtk_entry_reset_im_context:
5870 * @entry: a #GtkEntry
5872 * Reset the input method context of the entry if needed.
5874 * This can be necessary in the case where modifying the buffer
5875 * would confuse on-going input method behavior.
5880 gtk_entry_reset_im_context (GtkEntry *entry)
5882 g_return_if_fail (GTK_IS_ENTRY (entry));
5884 _gtk_entry_reset_im_context (entry);
5888 * gtk_entry_im_context_filter_keypress:
5889 * @entry: a #GtkEntry
5890 * @event: the key event
5892 * Allow the #GtkEntry input method to internally handle key press
5893 * and release events. If this function returns %TRUE, then no further
5894 * processing should be done for this key event. See
5895 * gtk_im_context_filter_keypress().
5897 * Note that you are expected to call this function from your handler
5898 * when overriding key event handling. This is needed in the case when
5899 * you need to insert your own key handling between the input method
5900 * and the default key event handling of the #GtkEntry.
5901 * See gtk_text_view_reset_im_context() for an example of use.
5903 * Return value: %TRUE if the input method handled the key event.
5908 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5911 GtkEntryPrivate *priv;
5913 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5917 return gtk_im_context_filter_keypress (priv->im_context, event);
5921 _gtk_entry_get_im_context (GtkEntry *entry)
5923 return entry->priv->im_context;
5927 gtk_entry_find_position (GtkEntry *entry,
5930 GtkEntryPrivate *priv = entry->priv;
5931 PangoLayout *layout;
5932 PangoLayoutLine *line;
5939 layout = gtk_entry_ensure_layout (entry, TRUE);
5940 text = pango_layout_get_text (layout);
5941 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
5943 line = pango_layout_get_lines_readonly (layout)->data;
5944 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5946 if (index >= cursor_index && priv->preedit_length)
5948 if (index >= cursor_index + priv->preedit_length)
5949 index -= priv->preedit_length;
5952 index = cursor_index;
5957 pos = g_utf8_pointer_to_offset (text, text + index);
5964 gtk_entry_get_cursor_locations (GtkEntry *entry,
5969 GtkEntryPrivate *priv = entry->priv;
5970 DisplayMode mode = gtk_entry_get_display_mode (entry);
5972 /* Nothing to display at all, so no cursor is relevant */
5973 if (mode == DISPLAY_BLANK)
5983 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5984 const gchar *text = pango_layout_get_text (layout);
5985 PangoRectangle strong_pos, weak_pos;
5988 if (type == CURSOR_STANDARD)
5990 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5992 else /* type == CURSOR_DND */
5994 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
5996 if (priv->dnd_position > priv->current_pos)
5998 if (mode == DISPLAY_NORMAL)
5999 index += priv->preedit_length;
6002 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6003 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6008 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6011 *strong_x = strong_pos.x / PANGO_SCALE;
6014 *weak_x = weak_pos.x / PANGO_SCALE;
6019 gtk_entry_adjust_scroll (GtkEntry *entry)
6021 GtkEntryPrivate *priv = entry->priv;
6022 gint min_offset, max_offset;
6023 gint text_area_width, text_width;
6024 GtkBorder inner_border;
6025 gint strong_x, weak_x;
6026 gint strong_xoffset, weak_xoffset;
6028 PangoLayout *layout;
6029 PangoLayoutLine *line;
6030 PangoRectangle logical_rect;
6032 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6035 _gtk_entry_effective_inner_border (entry, &inner_border);
6037 text_area_width = gdk_window_get_width (priv->text_area);
6038 text_area_width -= inner_border.left + inner_border.right;
6039 if (text_area_width < 0)
6040 text_area_width = 0;
6042 layout = gtk_entry_ensure_layout (entry, TRUE);
6043 line = pango_layout_get_lines_readonly (layout)->data;
6045 pango_layout_line_get_extents (line, NULL, &logical_rect);
6047 /* Display as much text as we can */
6049 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6050 xalign = priv->xalign;
6052 xalign = 1.0 - priv->xalign;
6054 text_width = PANGO_PIXELS(logical_rect.width);
6056 if (text_width > text_area_width)
6059 max_offset = text_width - text_area_width;
6063 min_offset = (text_width - text_area_width) * xalign;
6064 max_offset = min_offset;
6067 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6069 /* And make sure cursors are on screen. Note that the cursor is
6070 * actually drawn one pixel into the INNER_BORDER space on
6071 * the right, when the scroll is at the utmost right. This
6072 * looks better to to me than confining the cursor inside the
6073 * border entirely, though it means that the cursor gets one
6074 * pixel closer to the edge of the widget on the right than
6075 * on the left. This might need changing if one changed
6076 * INNER_BORDER from 2 to 1, as one would do on a
6077 * small-screen-real-estate display.
6079 * We always make sure that the strong cursor is on screen, and
6080 * put the weak cursor on screen if possible.
6083 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6085 strong_xoffset = strong_x - priv->scroll_offset;
6087 if (strong_xoffset < 0)
6089 priv->scroll_offset += strong_xoffset;
6092 else if (strong_xoffset > text_area_width)
6094 priv->scroll_offset += strong_xoffset - text_area_width;
6095 strong_xoffset = text_area_width;
6098 weak_xoffset = weak_x - priv->scroll_offset;
6100 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6102 priv->scroll_offset += weak_xoffset;
6104 else if (weak_xoffset > text_area_width &&
6105 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6107 priv->scroll_offset += weak_xoffset - text_area_width;
6110 g_object_notify (G_OBJECT (entry), "scroll-offset");
6114 gtk_entry_move_adjustments (GtkEntry *entry)
6116 GtkWidget *widget = GTK_WIDGET (entry);
6117 GtkAllocation allocation;
6118 GtkAdjustment *adjustment;
6119 PangoContext *context;
6120 PangoFontMetrics *metrics;
6121 GtkStyleContext *style_context;
6122 GtkStateFlags state;
6123 gint x, layout_x, border_x, border_y;
6126 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6130 gtk_widget_get_allocation (widget, &allocation);
6132 /* Cursor position, layout offset, border width, and widget allocation */
6133 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6134 get_layout_position (entry, &layout_x, NULL);
6135 _gtk_entry_get_borders (entry, &border_x, &border_y);
6136 x += allocation.x + layout_x + border_x;
6138 /* Approximate width of a char, so user can see what is ahead/behind */
6139 context = gtk_widget_get_pango_context (widget);
6140 style_context = gtk_widget_get_style_context (widget);
6141 state = gtk_widget_get_state_flags (widget);
6143 metrics = pango_context_get_metrics (context,
6144 gtk_style_context_get_font (style_context, state),
6145 pango_context_get_language (context));
6146 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6149 gtk_adjustment_clamp_page (adjustment,
6150 x - (char_width + 1), /* one char + one pixel before */
6151 x + (char_width + 2)); /* one char + cursor + one pixel after */
6155 gtk_entry_move_visually (GtkEntry *entry,
6159 GtkEntryPrivate *priv = entry->priv;
6161 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6164 text = pango_layout_get_text (layout);
6166 index = g_utf8_offset_to_pointer (text, start) - text;
6170 int new_index, new_trailing;
6171 gboolean split_cursor;
6174 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6175 "gtk-split-cursor", &split_cursor,
6182 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6183 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6185 strong = keymap_direction == priv->resolved_dir;
6190 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6195 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6201 else if (new_index != G_MAXINT)
6204 while (new_trailing--)
6205 index = g_utf8_next_char (text + index) - text;
6208 return g_utf8_pointer_to_offset (text, text + index);
6212 gtk_entry_move_logically (GtkEntry *entry,
6216 gint new_pos = start;
6219 length = gtk_entry_buffer_get_length (get_buffer (entry));
6221 /* Prevent any leak of information */
6222 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6224 new_pos = CLAMP (start + count, 0, length);
6228 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6229 PangoLogAttr *log_attrs;
6232 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6234 while (count > 0 && new_pos < length)
6238 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6242 while (count < 0 && new_pos > 0)
6246 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6258 gtk_entry_move_forward_word (GtkEntry *entry,
6260 gboolean allow_whitespace)
6262 gint new_pos = start;
6265 length = gtk_entry_buffer_get_length (get_buffer (entry));
6267 /* Prevent any leak of information */
6268 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6272 else if (new_pos < length)
6274 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6275 PangoLogAttr *log_attrs;
6278 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6280 /* Find the next word boundary */
6282 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6283 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6294 gtk_entry_move_backward_word (GtkEntry *entry,
6296 gboolean allow_whitespace)
6298 gint new_pos = start;
6300 /* Prevent any leak of information */
6301 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6307 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6308 PangoLogAttr *log_attrs;
6311 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6313 new_pos = start - 1;
6315 /* Find the previous word boundary */
6316 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6317 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6327 gtk_entry_delete_whitespace (GtkEntry *entry)
6329 GtkEntryPrivate *priv = entry->priv;
6330 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6331 PangoLogAttr *log_attrs;
6335 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6337 start = end = priv->current_pos;
6339 while (start > 0 && log_attrs[start-1].is_white)
6342 while (end < n_attrs && log_attrs[end].is_white)
6348 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6353 gtk_entry_select_word (GtkEntry *entry)
6355 GtkEntryPrivate *priv = entry->priv;
6356 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6357 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6359 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6363 gtk_entry_select_line (GtkEntry *entry)
6365 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6369 truncate_multiline (const gchar *text)
6374 text[length] && text[length] != '\n' && text[length] != '\r';
6381 paste_received (GtkClipboard *clipboard,
6385 GtkEntry *entry = GTK_ENTRY (data);
6386 GtkEditable *editable = GTK_EDITABLE (entry);
6387 GtkEntryPrivate *priv = entry->priv;
6389 if (priv->button == 2)
6391 gint pos, start, end;
6392 pos = priv->insert_pos;
6393 gtk_editable_get_selection_bounds (editable, &start, &end);
6394 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6395 gtk_editable_select_region (editable, pos, pos);
6400 gint pos, start, end;
6402 gboolean popup_completion;
6403 GtkEntryCompletion *completion;
6405 completion = gtk_entry_get_completion (entry);
6407 if (priv->truncate_multiline)
6408 length = truncate_multiline (text);
6410 /* only complete if the selection is at the end */
6411 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6412 MAX (priv->current_pos, priv->selection_bound));
6416 if (gtk_widget_get_mapped (completion->priv->popup_window))
6417 _gtk_entry_completion_popdown (completion);
6419 if (!popup_completion && completion->priv->changed_id > 0)
6420 g_signal_handler_block (entry, completion->priv->changed_id);
6423 begin_change (entry);
6424 g_object_freeze_notify (G_OBJECT (entry));
6425 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6426 gtk_editable_delete_text (editable, start, end);
6428 pos = priv->current_pos;
6429 gtk_editable_insert_text (editable, text, length, &pos);
6430 gtk_editable_set_position (editable, pos);
6431 g_object_thaw_notify (G_OBJECT (entry));
6435 !popup_completion && completion->priv->changed_id > 0)
6436 g_signal_handler_unblock (entry, completion->priv->changed_id);
6439 g_object_unref (entry);
6443 gtk_entry_paste (GtkEntry *entry,
6446 g_object_ref (entry);
6447 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6448 paste_received, entry);
6452 primary_get_cb (GtkClipboard *clipboard,
6453 GtkSelectionData *selection_data,
6457 GtkEntry *entry = GTK_ENTRY (data);
6460 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6462 gchar *str = gtk_entry_get_display_text (entry, start, end);
6463 gtk_selection_data_set_text (selection_data, str, -1);
6469 primary_clear_cb (GtkClipboard *clipboard,
6472 GtkEntry *entry = GTK_ENTRY (data);
6473 GtkEntryPrivate *priv = entry->priv;
6475 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6479 gtk_entry_update_primary_selection (GtkEntry *entry)
6481 GtkTargetList *list;
6482 GtkTargetEntry *targets;
6483 GtkClipboard *clipboard;
6487 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6490 list = gtk_target_list_new (NULL, 0);
6491 gtk_target_list_add_text_targets (list, 0);
6493 targets = gtk_target_table_new_from_list (list, &n_targets);
6495 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6497 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6499 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6500 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6501 primary_clear_cb (clipboard, entry);
6505 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6506 gtk_clipboard_clear (clipboard);
6509 gtk_target_table_free (targets, n_targets);
6510 gtk_target_list_unref (list);
6514 gtk_entry_clear (GtkEntry *entry,
6515 GtkEntryIconPosition icon_pos)
6517 GtkEntryPrivate *priv = entry->priv;
6518 EntryIconInfo *icon_info = priv->icons[icon_pos];
6520 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6523 g_object_freeze_notify (G_OBJECT (entry));
6525 /* Explicitly check, as the pointer may become invalidated
6526 * during destruction.
6528 if (GDK_IS_WINDOW (icon_info->window))
6529 gdk_window_hide (icon_info->window);
6531 if (icon_info->pixbuf)
6533 g_object_unref (icon_info->pixbuf);
6534 icon_info->pixbuf = NULL;
6537 switch (icon_info->storage_type)
6539 case GTK_IMAGE_PIXBUF:
6540 g_object_notify (G_OBJECT (entry),
6541 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6544 case GTK_IMAGE_STOCK:
6545 g_free (icon_info->stock_id);
6546 icon_info->stock_id = NULL;
6547 g_object_notify (G_OBJECT (entry),
6548 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6551 case GTK_IMAGE_ICON_NAME:
6552 g_free (icon_info->icon_name);
6553 icon_info->icon_name = NULL;
6554 g_object_notify (G_OBJECT (entry),
6555 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6558 case GTK_IMAGE_GICON:
6559 if (icon_info->gicon)
6561 g_object_unref (icon_info->gicon);
6562 icon_info->gicon = NULL;
6564 g_object_notify (G_OBJECT (entry),
6565 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6569 g_assert_not_reached ();
6573 icon_info->storage_type = GTK_IMAGE_EMPTY;
6574 g_object_notify (G_OBJECT (entry),
6575 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6577 g_object_thaw_notify (G_OBJECT (entry));
6581 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6582 GtkEntryIconPosition icon_pos)
6584 GtkEntryPrivate *priv = entry->priv;
6585 EntryIconInfo *icon_info = priv->icons[icon_pos];
6587 GtkIconTheme *icon_theme;
6588 GtkSettings *settings;
6589 GtkStateFlags state;
6594 if (!icon_info || icon_info->pixbuf)
6597 widget = GTK_WIDGET (entry);
6599 switch (icon_info->storage_type)
6601 case GTK_IMAGE_EMPTY:
6602 case GTK_IMAGE_PIXBUF:
6604 case GTK_IMAGE_STOCK:
6605 state = gtk_widget_get_state_flags (widget);
6606 gtk_widget_set_state_flags (widget, 0, TRUE);
6607 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6608 icon_info->stock_id,
6609 GTK_ICON_SIZE_MENU);
6610 if (!icon_info->pixbuf)
6611 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6612 GTK_STOCK_MISSING_IMAGE,
6613 GTK_ICON_SIZE_MENU);
6614 gtk_widget_set_state_flags (widget, state, TRUE);
6617 case GTK_IMAGE_ICON_NAME:
6618 screen = gtk_widget_get_screen (widget);
6621 icon_theme = gtk_icon_theme_get_for_screen (screen);
6622 settings = gtk_settings_get_for_screen (screen);
6624 gtk_icon_size_lookup_for_settings (settings,
6628 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6629 icon_info->icon_name,
6630 MIN (width, height),
6633 if (icon_info->pixbuf == NULL)
6635 state = gtk_widget_get_state_flags (widget);
6636 gtk_widget_set_state_flags (widget, 0, TRUE);
6637 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6638 GTK_STOCK_MISSING_IMAGE,
6639 GTK_ICON_SIZE_MENU);
6640 gtk_widget_set_state_flags (widget, state, TRUE);
6645 case GTK_IMAGE_GICON:
6646 screen = gtk_widget_get_screen (widget);
6649 icon_theme = gtk_icon_theme_get_for_screen (screen);
6650 settings = gtk_settings_get_for_screen (screen);
6652 gtk_icon_size_lookup_for_settings (settings,
6656 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6658 MIN (width, height),
6659 GTK_ICON_LOOKUP_USE_BUILTIN);
6662 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6663 gtk_icon_info_free (info);
6666 if (icon_info->pixbuf == NULL)
6668 state = gtk_widget_get_state_flags (widget);
6669 gtk_widget_set_state_flags (widget, 0, TRUE);
6670 icon_info->pixbuf = gtk_widget_render_icon_pixbuf (widget,
6671 GTK_STOCK_MISSING_IMAGE,
6672 GTK_ICON_SIZE_MENU);
6673 gtk_widget_set_state_flags (widget, state, TRUE);
6679 g_assert_not_reached ();
6683 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6684 gdk_window_show_unraised (icon_info->window);
6694 * Creates a new entry.
6696 * Return value: a new #GtkEntry.
6699 gtk_entry_new (void)
6701 return g_object_new (GTK_TYPE_ENTRY, NULL);
6705 * gtk_entry_new_with_buffer:
6706 * @buffer: The buffer to use for the new #GtkEntry.
6708 * Creates a new entry with the specified text buffer.
6710 * Return value: a new #GtkEntry
6715 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6717 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6718 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6721 static GtkEntryBuffer*
6722 get_buffer (GtkEntry *entry)
6724 GtkEntryPrivate *priv = entry->priv;
6726 if (priv->buffer == NULL)
6728 GtkEntryBuffer *buffer;
6729 buffer = gtk_entry_buffer_new (NULL, 0);
6730 gtk_entry_set_buffer (entry, buffer);
6731 g_object_unref (buffer);
6734 return priv->buffer;
6738 * gtk_entry_get_buffer:
6739 * @entry: a #GtkEntry
6741 * Get the #GtkEntryBuffer object which holds the text for
6746 * Returns: (transfer none): A #GtkEntryBuffer object.
6749 gtk_entry_get_buffer (GtkEntry *entry)
6751 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6753 return get_buffer (entry);
6757 * gtk_entry_set_buffer:
6758 * @entry: a #GtkEntry
6759 * @buffer: a #GtkEntryBuffer
6761 * Set the #GtkEntryBuffer object which holds the text for
6767 gtk_entry_set_buffer (GtkEntry *entry,
6768 GtkEntryBuffer *buffer)
6770 GtkEntryPrivate *priv;
6773 g_return_if_fail (GTK_IS_ENTRY (entry));
6779 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6780 g_object_ref (buffer);
6785 buffer_disconnect_signals (entry);
6786 g_object_unref (priv->buffer);
6789 priv->buffer = buffer;
6792 buffer_connect_signals (entry);
6794 obj = G_OBJECT (entry);
6795 g_object_freeze_notify (obj);
6796 g_object_notify (obj, "buffer");
6797 g_object_notify (obj, "text");
6798 g_object_notify (obj, "text-length");
6799 g_object_notify (obj, "max-length");
6800 g_object_notify (obj, "visibility");
6801 g_object_notify (obj, "invisible-char");
6802 g_object_notify (obj, "invisible-char-set");
6803 g_object_thaw_notify (obj);
6805 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6806 gtk_entry_recompute (entry);
6810 * gtk_entry_get_text_area:
6811 * @entry: a #GtkEntry
6812 * @text_area: (out): Return location for the text area.
6814 * Gets the area where the entry's text is drawn. This function is
6815 * useful when drawing something to the entry in a draw callback.
6817 * If the entry is not realized, @text_area is filled with zeros.
6819 * See also gtk_entry_get_icon_area().
6824 gtk_entry_get_text_area (GtkEntry *entry,
6825 GdkRectangle *text_area)
6827 GtkEntryPrivate *priv;
6829 g_return_if_fail (GTK_IS_ENTRY (entry));
6830 g_return_if_fail (text_area != NULL);
6834 if (priv->text_area)
6836 GtkAllocation allocation;
6839 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6840 gdk_window_get_position (priv->text_area, &x, &y);
6842 text_area->x = x - allocation.x;
6843 text_area->y = y - allocation.y;
6844 text_area->width = gdk_window_get_width (priv->text_area);
6845 text_area->height = gdk_window_get_height (priv->text_area);
6851 text_area->width = 0;
6852 text_area->height = 0;
6857 * gtk_entry_set_text:
6858 * @entry: a #GtkEntry
6859 * @text: the new text
6861 * Sets the text in the widget to the given
6862 * value, replacing the current contents.
6864 * See gtk_entry_buffer_set_text().
6867 gtk_entry_set_text (GtkEntry *entry,
6871 GtkEntryCompletion *completion;
6873 g_return_if_fail (GTK_IS_ENTRY (entry));
6874 g_return_if_fail (text != NULL);
6876 /* Actually setting the text will affect the cursor and selection;
6877 * if the contents don't actually change, this will look odd to the user.
6879 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6882 completion = gtk_entry_get_completion (entry);
6883 if (completion && completion->priv->changed_id > 0)
6884 g_signal_handler_block (entry, completion->priv->changed_id);
6886 begin_change (entry);
6887 g_object_freeze_notify (G_OBJECT (entry));
6888 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6890 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6891 g_object_thaw_notify (G_OBJECT (entry));
6894 if (completion && completion->priv->changed_id > 0)
6895 g_signal_handler_unblock (entry, completion->priv->changed_id);
6899 * gtk_entry_set_visibility:
6900 * @entry: a #GtkEntry
6901 * @visible: %TRUE if the contents of the entry are displayed
6904 * Sets whether the contents of the entry are visible or not.
6905 * When visibility is set to %FALSE, characters are displayed
6906 * as the invisible char, and will also appear that way when
6907 * the text in the entry widget is copied elsewhere.
6909 * By default, GTK+ picks the best invisible character available
6910 * in the current font, but it can be changed with
6911 * gtk_entry_set_invisible_char().
6914 gtk_entry_set_visibility (GtkEntry *entry,
6917 GtkEntryPrivate *priv;
6919 g_return_if_fail (GTK_IS_ENTRY (entry));
6923 visible = visible != FALSE;
6925 if (priv->visible != visible)
6927 priv->visible = visible;
6929 g_object_notify (G_OBJECT (entry), "visibility");
6930 gtk_entry_recompute (entry);
6935 * gtk_entry_get_visibility:
6936 * @entry: a #GtkEntry
6938 * Retrieves whether the text in @entry is visible. See
6939 * gtk_entry_set_visibility().
6941 * Return value: %TRUE if the text is currently visible
6944 gtk_entry_get_visibility (GtkEntry *entry)
6946 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6948 return entry->priv->visible;
6952 * gtk_entry_set_invisible_char:
6953 * @entry: a #GtkEntry
6954 * @ch: a Unicode character
6956 * Sets the character to use in place of the actual text when
6957 * gtk_entry_set_visibility() has been called to set text visibility
6958 * to %FALSE. i.e. this is the character used in "password mode" to
6959 * show the user how many characters have been typed. By default, GTK+
6960 * picks the best invisible char available in the current font. If you
6961 * set the invisible char to 0, then the user will get no feedback
6962 * at all; there will be no text on the screen as they type.
6965 gtk_entry_set_invisible_char (GtkEntry *entry,
6968 GtkEntryPrivate *priv;
6970 g_return_if_fail (GTK_IS_ENTRY (entry));
6974 if (!priv->invisible_char_set)
6976 priv->invisible_char_set = TRUE;
6977 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6980 if (ch == priv->invisible_char)
6983 priv->invisible_char = ch;
6984 g_object_notify (G_OBJECT (entry), "invisible-char");
6985 gtk_entry_recompute (entry);
6989 * gtk_entry_get_invisible_char:
6990 * @entry: a #GtkEntry
6992 * Retrieves the character displayed in place of the real characters
6993 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6995 * Return value: the current invisible char, or 0, if the entry does not
6996 * show invisible text at all.
6999 gtk_entry_get_invisible_char (GtkEntry *entry)
7001 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7003 return entry->priv->invisible_char;
7007 * gtk_entry_unset_invisible_char:
7008 * @entry: a #GtkEntry
7010 * Unsets the invisible char previously set with
7011 * gtk_entry_set_invisible_char(). So that the
7012 * default invisible char is used again.
7017 gtk_entry_unset_invisible_char (GtkEntry *entry)
7019 GtkEntryPrivate *priv;
7022 g_return_if_fail (GTK_IS_ENTRY (entry));
7026 if (!priv->invisible_char_set)
7029 priv->invisible_char_set = FALSE;
7030 ch = find_invisible_char (GTK_WIDGET (entry));
7032 if (priv->invisible_char != ch)
7034 priv->invisible_char = ch;
7035 g_object_notify (G_OBJECT (entry), "invisible-char");
7038 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7039 gtk_entry_recompute (entry);
7043 * gtk_entry_set_overwrite_mode:
7044 * @entry: a #GtkEntry
7045 * @overwrite: new value
7047 * Sets whether the text is overwritten when typing in the #GtkEntry.
7052 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7055 GtkEntryPrivate *priv = entry->priv;
7057 g_return_if_fail (GTK_IS_ENTRY (entry));
7059 if (priv->overwrite_mode == overwrite)
7062 gtk_entry_toggle_overwrite (entry);
7064 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7068 * gtk_entry_get_overwrite_mode:
7069 * @entry: a #GtkEntry
7071 * Gets the value set by gtk_entry_set_overwrite_mode().
7073 * Return value: whether the text is overwritten when typing.
7078 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7080 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7082 return entry->priv->overwrite_mode;
7086 * gtk_entry_get_text:
7087 * @entry: a #GtkEntry
7089 * Retrieves the contents of the entry widget.
7090 * See also gtk_editable_get_chars().
7092 * This is equivalent to:
7094 * <informalexample><programlisting>
7095 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7096 * </programlisting></informalexample>
7098 * Return value: a pointer to the contents of the widget as a
7099 * string. This string points to internally allocated
7100 * storage in the widget and must not be freed, modified or
7103 G_CONST_RETURN gchar*
7104 gtk_entry_get_text (GtkEntry *entry)
7106 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7108 return gtk_entry_buffer_get_text (get_buffer (entry));
7112 * gtk_entry_set_max_length:
7113 * @entry: a #GtkEntry
7114 * @max: the maximum length of the entry, or 0 for no maximum.
7115 * (other than the maximum length of entries.) The value passed in will
7116 * be clamped to the range 0-65536.
7118 * Sets the maximum allowed length of the contents of the widget. If
7119 * the current contents are longer than the given length, then they
7120 * will be truncated to fit.
7122 * This is equivalent to:
7124 * <informalexample><programlisting>
7125 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7126 * </programlisting></informalexample>
7129 gtk_entry_set_max_length (GtkEntry *entry,
7132 g_return_if_fail (GTK_IS_ENTRY (entry));
7133 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7137 * gtk_entry_get_max_length:
7138 * @entry: a #GtkEntry
7140 * Retrieves the maximum allowed length of the text in
7141 * @entry. See gtk_entry_set_max_length().
7143 * This is equivalent to:
7145 * <informalexample><programlisting>
7146 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7147 * </programlisting></informalexample>
7149 * Return value: the maximum allowed number of characters
7150 * in #GtkEntry, or 0 if there is no maximum.
7153 gtk_entry_get_max_length (GtkEntry *entry)
7155 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7157 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7161 * gtk_entry_get_text_length:
7162 * @entry: a #GtkEntry
7164 * Retrieves the current length of the text in
7167 * This is equivalent to:
7169 * <informalexample><programlisting>
7170 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7171 * </programlisting></informalexample>
7173 * Return value: the current number of characters
7174 * in #GtkEntry, or 0 if there are none.
7179 gtk_entry_get_text_length (GtkEntry *entry)
7181 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7183 return gtk_entry_buffer_get_length (get_buffer (entry));
7187 * gtk_entry_set_activates_default:
7188 * @entry: a #GtkEntry
7189 * @setting: %TRUE to activate window's default widget on Enter keypress
7191 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7192 * widget for the window containing the entry. This usually means that
7193 * the dialog box containing the entry will be closed, since the default
7194 * widget is usually one of the dialog buttons.
7196 * (For experts: if @setting is %TRUE, the entry calls
7197 * gtk_window_activate_default() on the window containing the entry, in
7198 * the default handler for the #GtkWidget::activate signal.)
7201 gtk_entry_set_activates_default (GtkEntry *entry,
7204 GtkEntryPrivate *priv;
7206 g_return_if_fail (GTK_IS_ENTRY (entry));
7210 setting = setting != FALSE;
7212 if (setting != priv->activates_default)
7214 priv->activates_default = setting;
7215 g_object_notify (G_OBJECT (entry), "activates-default");
7220 * gtk_entry_get_activates_default:
7221 * @entry: a #GtkEntry
7223 * Retrieves the value set by gtk_entry_set_activates_default().
7225 * Return value: %TRUE if the entry will activate the default widget
7228 gtk_entry_get_activates_default (GtkEntry *entry)
7230 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7232 return entry->priv->activates_default;
7236 * gtk_entry_set_width_chars:
7237 * @entry: a #GtkEntry
7238 * @n_chars: width in chars
7240 * Changes the size request of the entry to be about the right size
7241 * for @n_chars characters. Note that it changes the size
7242 * <emphasis>request</emphasis>, the size can still be affected by
7243 * how you pack the widget into containers. If @n_chars is -1, the
7244 * size reverts to the default entry size.
7247 gtk_entry_set_width_chars (GtkEntry *entry,
7250 GtkEntryPrivate *priv;
7252 g_return_if_fail (GTK_IS_ENTRY (entry));
7256 if (priv->width_chars != n_chars)
7258 priv->width_chars = n_chars;
7259 g_object_notify (G_OBJECT (entry), "width-chars");
7260 gtk_widget_queue_resize (GTK_WIDGET (entry));
7265 * gtk_entry_get_width_chars:
7266 * @entry: a #GtkEntry
7268 * Gets the value set by gtk_entry_set_width_chars().
7270 * Return value: number of chars to request space for, or negative if unset
7273 gtk_entry_get_width_chars (GtkEntry *entry)
7275 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7277 return entry->priv->width_chars;
7281 * gtk_entry_set_has_frame:
7282 * @entry: a #GtkEntry
7283 * @setting: new value
7285 * Sets whether the entry has a beveled frame around it.
7288 gtk_entry_set_has_frame (GtkEntry *entry,
7291 GtkEntryPrivate *priv;
7293 g_return_if_fail (GTK_IS_ENTRY (entry));
7297 setting = (setting != FALSE);
7299 if (priv->has_frame == setting)
7302 gtk_widget_queue_resize (GTK_WIDGET (entry));
7303 priv->has_frame = setting;
7304 g_object_notify (G_OBJECT (entry), "has-frame");
7308 * gtk_entry_get_has_frame:
7309 * @entry: a #GtkEntry
7311 * Gets the value set by gtk_entry_set_has_frame().
7313 * Return value: whether the entry has a beveled frame
7316 gtk_entry_get_has_frame (GtkEntry *entry)
7318 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7320 return entry->priv->has_frame;
7324 * gtk_entry_set_inner_border:
7325 * @entry: a #GtkEntry
7326 * @border: (allow-none): a #GtkBorder, or %NULL
7328 * Sets %entry's inner-border property to %border, or clears it if %NULL
7329 * is passed. The inner-border is the area around the entry's text, but
7332 * If set, this property overrides the inner-border style property.
7333 * Overriding the style-provided border is useful when you want to do
7334 * in-place editing of some text in a canvas or list widget, where
7335 * pixel-exact positioning of the entry is important.
7340 gtk_entry_set_inner_border (GtkEntry *entry,
7341 const GtkBorder *border)
7343 g_return_if_fail (GTK_IS_ENTRY (entry));
7345 gtk_widget_queue_resize (GTK_WIDGET (entry));
7348 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7349 gtk_border_copy (border),
7350 (GDestroyNotify) gtk_border_free);
7352 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7354 g_object_notify (G_OBJECT (entry), "inner-border");
7358 * gtk_entry_get_inner_border:
7359 * @entry: a #GtkEntry
7361 * This function returns the entry's #GtkEntry:inner-border property. See
7362 * gtk_entry_set_inner_border() for more information.
7364 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7368 G_CONST_RETURN GtkBorder *
7369 gtk_entry_get_inner_border (GtkEntry *entry)
7371 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7373 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7377 * gtk_entry_get_layout:
7378 * @entry: a #GtkEntry
7380 * Gets the #PangoLayout used to display the entry.
7381 * The layout is useful to e.g. convert text positions to
7382 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7383 * The returned layout is owned by the entry and must not be
7384 * modified or freed by the caller.
7386 * Keep in mind that the layout text may contain a preedit string, so
7387 * gtk_entry_layout_index_to_text_index() and
7388 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7389 * indices in the layout to byte indices in the entry contents.
7391 * Return value: (transfer none): the #PangoLayout for this entry
7394 gtk_entry_get_layout (GtkEntry *entry)
7396 PangoLayout *layout;
7398 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7400 layout = gtk_entry_ensure_layout (entry, TRUE);
7407 * gtk_entry_layout_index_to_text_index:
7408 * @entry: a #GtkEntry
7409 * @layout_index: byte index into the entry layout text
7411 * Converts from a position in the entry contents (returned
7412 * by gtk_entry_get_text()) to a position in the
7413 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7414 * with text retrieved via pango_layout_get_text()).
7416 * Return value: byte index into the entry contents
7419 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7422 GtkEntryPrivate *priv;
7423 PangoLayout *layout;
7427 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7431 layout = gtk_entry_ensure_layout (entry, TRUE);
7432 text = pango_layout_get_text (layout);
7433 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7435 if (layout_index >= cursor_index && priv->preedit_length)
7437 if (layout_index >= cursor_index + priv->preedit_length)
7438 layout_index -= priv->preedit_length;
7440 layout_index = cursor_index;
7443 return layout_index;
7447 * gtk_entry_text_index_to_layout_index:
7448 * @entry: a #GtkEntry
7449 * @text_index: byte index into the entry contents
7451 * Converts from a position in the entry's #PangoLayout (returned by
7452 * gtk_entry_get_layout()) to a position in the entry contents
7453 * (returned by gtk_entry_get_text()).
7455 * Return value: byte index into the entry layout text
7458 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7461 GtkEntryPrivate *priv;
7462 PangoLayout *layout;
7466 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7470 layout = gtk_entry_ensure_layout (entry, TRUE);
7471 text = pango_layout_get_text (layout);
7472 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7474 if (text_index > cursor_index)
7475 text_index += priv->preedit_length;
7481 * gtk_entry_get_layout_offsets:
7482 * @entry: a #GtkEntry
7483 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7484 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7487 * Obtains the position of the #PangoLayout used to render text
7488 * in the entry, in widget coordinates. Useful if you want to line
7489 * up the text in an entry with some other text, e.g. when using the
7490 * entry to implement editable cells in a sheet widget.
7492 * Also useful to convert mouse events into coordinates inside the
7493 * #PangoLayout, e.g. to take some action if some part of the entry text
7496 * Note that as the user scrolls around in the entry the offsets will
7497 * change; you'll need to connect to the "notify::scroll-offset"
7498 * signal to track this. Remember when using the #PangoLayout
7499 * functions you need to convert to and from pixels using
7500 * PANGO_PIXELS() or #PANGO_SCALE.
7502 * Keep in mind that the layout text may contain a preedit string, so
7503 * gtk_entry_layout_index_to_text_index() and
7504 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7505 * indices in the layout to byte indices in the entry contents.
7508 gtk_entry_get_layout_offsets (GtkEntry *entry,
7512 gint text_area_x, text_area_y;
7514 g_return_if_fail (GTK_IS_ENTRY (entry));
7516 /* this gets coords relative to text area */
7517 get_layout_position (entry, x, y);
7519 /* convert to widget coords */
7520 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7531 * gtk_entry_set_alignment:
7532 * @entry: a #GtkEntry
7533 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7534 * Reversed for RTL layouts
7536 * Sets the alignment for the contents of the entry. This controls
7537 * the horizontal positioning of the contents when the displayed
7538 * text is shorter than the width of the entry.
7543 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7545 GtkEntryPrivate *priv;
7547 g_return_if_fail (GTK_IS_ENTRY (entry));
7553 else if (xalign > 1.0)
7556 if (xalign != priv->xalign)
7558 priv->xalign = xalign;
7560 gtk_entry_recompute (entry);
7562 g_object_notify (G_OBJECT (entry), "xalign");
7567 * gtk_entry_get_alignment:
7568 * @entry: a #GtkEntry
7570 * Gets the value set by gtk_entry_set_alignment().
7572 * Return value: the alignment
7577 gtk_entry_get_alignment (GtkEntry *entry)
7579 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7581 return entry->priv->xalign;
7585 * gtk_entry_set_icon_from_pixbuf:
7586 * @entry: a #GtkEntry
7587 * @icon_pos: Icon position
7588 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7590 * Sets the icon shown in the specified position using a pixbuf.
7592 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7597 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7598 GtkEntryIconPosition icon_pos,
7601 GtkEntryPrivate *priv;
7602 EntryIconInfo *icon_info;
7604 g_return_if_fail (GTK_IS_ENTRY (entry));
7605 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7609 if ((icon_info = priv->icons[icon_pos]) == NULL)
7610 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7612 g_object_freeze_notify (G_OBJECT (entry));
7615 g_object_ref (pixbuf);
7617 gtk_entry_clear (entry, icon_pos);
7621 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7622 icon_info->pixbuf = pixbuf;
7624 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7626 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7627 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7631 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7632 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7635 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7636 gdk_window_show_unraised (icon_info->window);
7639 gtk_entry_ensure_pixbuf (entry, icon_pos);
7641 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7642 gtk_widget_queue_resize (GTK_WIDGET (entry));
7644 g_object_thaw_notify (G_OBJECT (entry));
7648 * gtk_entry_set_icon_from_stock:
7649 * @entry: A #GtkEntry
7650 * @icon_pos: Icon position
7651 * @stock_id: (allow-none): The name of the stock item, or %NULL
7653 * Sets the icon shown in the entry at the specified position from
7656 * If @stock_id is %NULL, no icon will be shown in the specified position.
7661 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7662 GtkEntryIconPosition icon_pos,
7663 const gchar *stock_id)
7665 GtkEntryPrivate *priv;
7666 EntryIconInfo *icon_info;
7669 g_return_if_fail (GTK_IS_ENTRY (entry));
7670 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7674 if ((icon_info = priv->icons[icon_pos]) == NULL)
7675 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7677 g_object_freeze_notify (G_OBJECT (entry));
7679 /* need to dup before clearing */
7680 new_id = g_strdup (stock_id);
7682 gtk_entry_clear (entry, icon_pos);
7686 icon_info->storage_type = GTK_IMAGE_STOCK;
7687 icon_info->stock_id = new_id;
7689 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7691 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7692 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7696 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7697 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7700 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7701 gdk_window_show_unraised (icon_info->window);
7704 gtk_entry_ensure_pixbuf (entry, icon_pos);
7706 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7707 gtk_widget_queue_resize (GTK_WIDGET (entry));
7709 g_object_thaw_notify (G_OBJECT (entry));
7713 * gtk_entry_set_icon_from_icon_name:
7714 * @entry: A #GtkEntry
7715 * @icon_pos: The position at which to set the icon
7716 * @icon_name: (allow-none): An icon name, or %NULL
7718 * Sets the icon shown in the entry at the specified position
7719 * from the current icon theme.
7721 * If the icon name isn't known, a "broken image" icon will be displayed
7724 * If @icon_name is %NULL, no icon will be shown in the specified position.
7729 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7730 GtkEntryIconPosition icon_pos,
7731 const gchar *icon_name)
7733 GtkEntryPrivate *priv;
7734 EntryIconInfo *icon_info;
7737 g_return_if_fail (GTK_IS_ENTRY (entry));
7738 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7742 if ((icon_info = priv->icons[icon_pos]) == NULL)
7743 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7745 g_object_freeze_notify (G_OBJECT (entry));
7747 /* need to dup before clearing */
7748 new_name = g_strdup (icon_name);
7750 gtk_entry_clear (entry, icon_pos);
7752 if (new_name != NULL)
7754 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7755 icon_info->icon_name = new_name;
7757 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7759 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7760 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7764 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7765 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7768 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7769 gdk_window_show_unraised (icon_info->window);
7772 gtk_entry_ensure_pixbuf (entry, icon_pos);
7774 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7775 gtk_widget_queue_resize (GTK_WIDGET (entry));
7777 g_object_thaw_notify (G_OBJECT (entry));
7781 * gtk_entry_set_icon_from_gicon:
7782 * @entry: A #GtkEntry
7783 * @icon_pos: The position at which to set the icon
7784 * @icon: (allow-none): The icon to set, or %NULL
7786 * Sets the icon shown in the entry at the specified position
7787 * from the current icon theme.
7788 * If the icon isn't known, a "broken image" icon will be displayed
7791 * If @icon is %NULL, no icon will be shown in the specified position.
7796 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7797 GtkEntryIconPosition icon_pos,
7800 GtkEntryPrivate *priv;
7801 EntryIconInfo *icon_info;
7803 g_return_if_fail (GTK_IS_ENTRY (entry));
7804 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7808 if ((icon_info = priv->icons[icon_pos]) == NULL)
7809 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7811 g_object_freeze_notify (G_OBJECT (entry));
7813 /* need to ref before clearing */
7815 g_object_ref (icon);
7817 gtk_entry_clear (entry, icon_pos);
7821 icon_info->storage_type = GTK_IMAGE_GICON;
7822 icon_info->gicon = icon;
7824 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7826 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7827 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7831 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7832 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7835 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7836 gdk_window_show_unraised (icon_info->window);
7839 gtk_entry_ensure_pixbuf (entry, icon_pos);
7841 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7842 gtk_widget_queue_resize (GTK_WIDGET (entry));
7844 g_object_thaw_notify (G_OBJECT (entry));
7848 * gtk_entry_set_icon_activatable:
7849 * @entry: A #GtkEntry
7850 * @icon_pos: Icon position
7851 * @activatable: %TRUE if the icon should be activatable
7853 * Sets whether the icon is activatable.
7858 gtk_entry_set_icon_activatable (GtkEntry *entry,
7859 GtkEntryIconPosition icon_pos,
7860 gboolean activatable)
7862 GtkEntryPrivate *priv;
7863 EntryIconInfo *icon_info;
7865 g_return_if_fail (GTK_IS_ENTRY (entry));
7866 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7870 if ((icon_info = priv->icons[icon_pos]) == NULL)
7871 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7873 activatable = activatable != FALSE;
7875 if (icon_info->nonactivatable != !activatable)
7877 icon_info->nonactivatable = !activatable;
7879 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7880 update_cursors (GTK_WIDGET (entry));
7882 g_object_notify (G_OBJECT (entry),
7883 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7888 * gtk_entry_get_icon_activatable:
7889 * @entry: a #GtkEntry
7890 * @icon_pos: Icon position
7892 * Returns whether the icon is activatable.
7894 * Returns: %TRUE if the icon is activatable.
7899 gtk_entry_get_icon_activatable (GtkEntry *entry,
7900 GtkEntryIconPosition icon_pos)
7902 GtkEntryPrivate *priv;
7903 EntryIconInfo *icon_info;
7905 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7906 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7909 icon_info = priv->icons[icon_pos];
7911 return (!icon_info || !icon_info->nonactivatable);
7915 * gtk_entry_get_icon_pixbuf:
7916 * @entry: A #GtkEntry
7917 * @icon_pos: Icon position
7919 * Retrieves the image used for the icon.
7921 * Unlike the other methods of setting and getting icon data, this
7922 * method will work regardless of whether the icon was set using a
7923 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7925 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7926 * set for this position.
7931 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7932 GtkEntryIconPosition icon_pos)
7934 GtkEntryPrivate *priv;
7935 EntryIconInfo *icon_info;
7937 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7938 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7942 icon_info = priv->icons[icon_pos];
7947 gtk_entry_ensure_pixbuf (entry, icon_pos);
7949 return icon_info->pixbuf;
7953 * gtk_entry_get_icon_gicon:
7954 * @entry: A #GtkEntry
7955 * @icon_pos: Icon position
7957 * Retrieves the #GIcon used for the icon, or %NULL if there is
7958 * no icon or if the icon was set by some other method (e.g., by
7959 * stock, pixbuf, or icon name).
7961 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7962 * or if the icon is not a #GIcon
7967 gtk_entry_get_icon_gicon (GtkEntry *entry,
7968 GtkEntryIconPosition icon_pos)
7970 GtkEntryPrivate *priv;
7971 EntryIconInfo *icon_info;
7973 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7974 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7977 icon_info = priv->icons[icon_pos];
7982 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7986 * gtk_entry_get_icon_stock:
7987 * @entry: A #GtkEntry
7988 * @icon_pos: Icon position
7990 * Retrieves the stock id used for the icon, or %NULL if there is
7991 * no icon or if the icon was set by some other method (e.g., by
7992 * pixbuf, icon name or gicon).
7994 * Returns: A stock id, or %NULL if no icon is set or if the icon
7995 * wasn't set from a stock id
8000 gtk_entry_get_icon_stock (GtkEntry *entry,
8001 GtkEntryIconPosition icon_pos)
8003 GtkEntryPrivate *priv;
8004 EntryIconInfo *icon_info;
8006 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8007 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8010 icon_info = priv->icons[icon_pos];
8015 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8019 * gtk_entry_get_icon_name:
8020 * @entry: A #GtkEntry
8021 * @icon_pos: Icon position
8023 * Retrieves the icon name used for the icon, or %NULL if there is
8024 * no icon or if the icon was set by some other method (e.g., by
8025 * pixbuf, stock or gicon).
8027 * Returns: An icon name, or %NULL if no icon is set or if the icon
8028 * wasn't set from an icon name
8033 gtk_entry_get_icon_name (GtkEntry *entry,
8034 GtkEntryIconPosition icon_pos)
8036 GtkEntryPrivate *priv;
8037 EntryIconInfo *icon_info;
8039 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8040 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8043 icon_info = priv->icons[icon_pos];
8048 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8052 * gtk_entry_set_icon_sensitive:
8053 * @entry: A #GtkEntry
8054 * @icon_pos: Icon position
8055 * @sensitive: Specifies whether the icon should appear
8056 * sensitive or insensitive
8058 * Sets the sensitivity for the specified icon.
8063 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8064 GtkEntryIconPosition icon_pos,
8067 GtkEntryPrivate *priv;
8068 EntryIconInfo *icon_info;
8070 g_return_if_fail (GTK_IS_ENTRY (entry));
8071 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8075 if ((icon_info = priv->icons[icon_pos]) == NULL)
8076 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8078 if (icon_info->insensitive != !sensitive)
8080 icon_info->insensitive = !sensitive;
8082 icon_info->pressed = FALSE;
8083 icon_info->prelight = FALSE;
8085 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8086 update_cursors (GTK_WIDGET (entry));
8088 gtk_widget_queue_draw (GTK_WIDGET (entry));
8090 g_object_notify (G_OBJECT (entry),
8091 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8096 * gtk_entry_get_icon_sensitive:
8097 * @entry: a #GtkEntry
8098 * @icon_pos: Icon position
8100 * Returns whether the icon appears sensitive or insensitive.
8102 * Returns: %TRUE if the icon is sensitive.
8107 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8108 GtkEntryIconPosition icon_pos)
8110 GtkEntryPrivate *priv;
8111 EntryIconInfo *icon_info;
8113 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8114 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8118 icon_info = priv->icons[icon_pos];
8120 return (!icon_info || !icon_info->insensitive);
8125 * gtk_entry_get_icon_storage_type:
8126 * @entry: a #GtkEntry
8127 * @icon_pos: Icon position
8129 * Gets the type of representation being used by the icon
8130 * to store image data. If the icon has no image data,
8131 * the return value will be %GTK_IMAGE_EMPTY.
8133 * Return value: image representation being used
8138 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8139 GtkEntryIconPosition icon_pos)
8141 GtkEntryPrivate *priv;
8142 EntryIconInfo *icon_info;
8144 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8145 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8149 icon_info = priv->icons[icon_pos];
8152 return GTK_IMAGE_EMPTY;
8154 return icon_info->storage_type;
8158 * gtk_entry_get_icon_at_pos:
8159 * @entry: a #GtkEntry
8160 * @x: the x coordinate of the position to find
8161 * @y: the y coordinate of the position to find
8163 * Finds the icon at the given position and return its index.
8164 * If @x, @y doesn't lie inside an icon, -1 is returned.
8165 * This function is intended for use in a #GtkWidget::query-tooltip
8168 * Returns: the index of the icon at the given position, or -1
8173 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8177 GtkAllocation primary;
8178 GtkAllocation secondary;
8179 gint frame_x, frame_y;
8181 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8183 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8187 get_icon_allocations (entry, &primary, &secondary);
8189 if (primary.x <= x && x < primary.x + primary.width &&
8190 primary.y <= y && y < primary.y + primary.height)
8191 return GTK_ENTRY_ICON_PRIMARY;
8193 if (secondary.x <= x && x < secondary.x + secondary.width &&
8194 secondary.y <= y && y < secondary.y + secondary.height)
8195 return GTK_ENTRY_ICON_SECONDARY;
8201 * gtk_entry_set_icon_drag_source:
8202 * @entry: a #GtkIconEntry
8203 * @icon_pos: icon position
8204 * @target_list: the targets (data formats) in which the data can be provided
8205 * @actions: a bitmask of the allowed drag actions
8207 * Sets up the icon at the given position so that GTK+ will start a drag
8208 * operation when the user clicks and drags the icon.
8210 * To handle the drag operation, you need to connect to the usual
8211 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8212 * signal, and use gtk_entry_get_current_icon_drag_source() in
8213 * your signal handler to find out if the drag was started from
8216 * By default, GTK+ uses the icon as the drag icon. You can use the
8217 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8218 * have to use g_signal_connect_after() to ensure that your signal handler
8219 * gets executed after the default handler.
8224 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8225 GtkEntryIconPosition icon_pos,
8226 GtkTargetList *target_list,
8227 GdkDragAction actions)
8229 GtkEntryPrivate *priv;
8230 EntryIconInfo *icon_info;
8232 g_return_if_fail (GTK_IS_ENTRY (entry));
8233 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8237 if ((icon_info = priv->icons[icon_pos]) == NULL)
8238 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8240 if (icon_info->target_list)
8241 gtk_target_list_unref (icon_info->target_list);
8242 icon_info->target_list = target_list;
8243 if (icon_info->target_list)
8244 gtk_target_list_ref (icon_info->target_list);
8246 icon_info->actions = actions;
8250 * gtk_entry_get_current_icon_drag_source:
8251 * @entry: a #GtkIconEntry
8253 * Returns the index of the icon which is the source of the current
8254 * DND operation, or -1.
8256 * This function is meant to be used in a #GtkWidget::drag-data-get
8259 * Returns: index of the icon which is the source of the current
8260 * DND operation, or -1.
8265 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8267 GtkEntryPrivate *priv;
8268 EntryIconInfo *icon_info = NULL;
8271 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8275 for (i = 0; i < MAX_ICONS; i++)
8277 if ((icon_info = priv->icons[i]))
8279 if (icon_info->in_drag)
8288 * gtk_entry_get_icon_area:
8289 * @entry: A #GtkEntry
8290 * @icon_pos: Icon position
8291 * @icon_area: (out): Return location for the icon's area
8293 * Gets the area where entry's icon at @icon_pos is drawn.
8294 * This function is useful when drawing something to the
8295 * entry in a draw callback.
8297 * If the entry is not realized or has no icon at the given position,
8298 * @icon_area is filled with zeros.
8300 * See also gtk_entry_get_text_area()
8305 gtk_entry_get_icon_area (GtkEntry *entry,
8306 GtkEntryIconPosition icon_pos,
8307 GdkRectangle *icon_area)
8309 GtkEntryPrivate *priv;
8310 EntryIconInfo *icon_info;
8312 g_return_if_fail (GTK_IS_ENTRY (entry));
8313 g_return_if_fail (icon_area != NULL);
8317 icon_info = priv->icons[icon_pos];
8321 GtkAllocation primary;
8322 GtkAllocation secondary;
8324 get_icon_allocations (entry, &primary, &secondary);
8326 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8327 *icon_area = primary;
8329 *icon_area = secondary;
8335 icon_area->width = 0;
8336 icon_area->height = 0;
8341 ensure_has_tooltip (GtkEntry *entry)
8343 GtkEntryPrivate *priv;
8344 EntryIconInfo *icon_info;
8346 gboolean has_tooltip = FALSE;
8350 for (i = 0; i < MAX_ICONS; i++)
8352 if ((icon_info = priv->icons[i]) != NULL)
8354 if (icon_info->tooltip != NULL)
8362 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8366 * gtk_entry_get_icon_tooltip_text:
8367 * @entry: a #GtkEntry
8368 * @icon_pos: the icon position
8370 * Gets the contents of the tooltip on the icon at the specified
8371 * position in @entry.
8373 * Returns: the tooltip text, or %NULL. Free the returned string
8374 * with g_free() when done.
8379 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8380 GtkEntryIconPosition icon_pos)
8382 GtkEntryPrivate *priv;
8383 EntryIconInfo *icon_info;
8386 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8387 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8391 icon_info = priv->icons[icon_pos];
8396 if (icon_info->tooltip &&
8397 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8398 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8404 * gtk_entry_set_icon_tooltip_text:
8405 * @entry: a #GtkEntry
8406 * @icon_pos: the icon position
8407 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8409 * Sets @tooltip as the contents of the tooltip for the icon
8410 * at the specified position.
8412 * Use %NULL for @tooltip to remove an existing tooltip.
8414 * See also gtk_widget_set_tooltip_text() and
8415 * gtk_entry_set_icon_tooltip_markup().
8420 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8421 GtkEntryIconPosition icon_pos,
8422 const gchar *tooltip)
8424 GtkEntryPrivate *priv;
8425 EntryIconInfo *icon_info;
8427 g_return_if_fail (GTK_IS_ENTRY (entry));
8428 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8432 if ((icon_info = priv->icons[icon_pos]) == NULL)
8433 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8435 if (icon_info->tooltip)
8436 g_free (icon_info->tooltip);
8438 /* Treat an empty string as a NULL string,
8439 * because an empty string would be useless for a tooltip:
8441 if (tooltip && tooltip[0] == '\0')
8444 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8446 ensure_has_tooltip (entry);
8450 * gtk_entry_get_icon_tooltip_markup:
8451 * @entry: a #GtkEntry
8452 * @icon_pos: the icon position
8454 * Gets the contents of the tooltip on the icon at the specified
8455 * position in @entry.
8457 * Returns: the tooltip text, or %NULL. Free the returned string
8458 * with g_free() when done.
8463 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8464 GtkEntryIconPosition icon_pos)
8466 GtkEntryPrivate *priv;
8467 EntryIconInfo *icon_info;
8469 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8470 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8474 icon_info = priv->icons[icon_pos];
8479 return g_strdup (icon_info->tooltip);
8483 * gtk_entry_set_icon_tooltip_markup:
8484 * @entry: a #GtkEntry
8485 * @icon_pos: the icon position
8486 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8488 * Sets @tooltip as the contents of the tooltip for the icon at
8489 * the specified position. @tooltip is assumed to be marked up with
8490 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8492 * Use %NULL for @tooltip to remove an existing tooltip.
8494 * See also gtk_widget_set_tooltip_markup() and
8495 * gtk_enty_set_icon_tooltip_text().
8500 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8501 GtkEntryIconPosition icon_pos,
8502 const gchar *tooltip)
8504 GtkEntryPrivate *priv;
8505 EntryIconInfo *icon_info;
8507 g_return_if_fail (GTK_IS_ENTRY (entry));
8508 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8512 if ((icon_info = priv->icons[icon_pos]) == NULL)
8513 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8515 if (icon_info->tooltip)
8516 g_free (icon_info->tooltip);
8518 /* Treat an empty string as a NULL string,
8519 * because an empty string would be useless for a tooltip:
8521 if (tooltip && tooltip[0] == '\0')
8524 icon_info->tooltip = g_strdup (tooltip);
8526 ensure_has_tooltip (entry);
8530 gtk_entry_query_tooltip (GtkWidget *widget,
8533 gboolean keyboard_tip,
8534 GtkTooltip *tooltip)
8537 GtkEntryPrivate *priv;
8538 EntryIconInfo *icon_info;
8541 entry = GTK_ENTRY (widget);
8546 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8549 if ((icon_info = priv->icons[icon_pos]) != NULL)
8551 if (icon_info->tooltip)
8553 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8562 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8569 /* Quick hack of a popup menu
8572 activate_cb (GtkWidget *menuitem,
8575 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8576 g_signal_emit_by_name (entry, signal);
8581 gtk_entry_mnemonic_activate (GtkWidget *widget,
8582 gboolean group_cycling)
8584 gtk_widget_grab_focus (widget);
8589 append_action_signal (GtkEntry *entry,
8591 const gchar *stock_id,
8592 const gchar *signal,
8595 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8597 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8598 g_signal_connect (menuitem, "activate",
8599 G_CALLBACK (activate_cb), entry);
8601 gtk_widget_set_sensitive (menuitem, sensitive);
8603 gtk_widget_show (menuitem);
8604 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8608 popup_menu_detach (GtkWidget *attach_widget,
8611 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8612 GtkEntryPrivate *priv_attach = entry_attach->priv;
8614 priv_attach->popup_menu = NULL;
8618 popup_position_func (GtkMenu *menu,
8624 GtkEntry *entry = GTK_ENTRY (user_data);
8625 GtkEntryPrivate *priv = entry->priv;
8626 GtkWidget *widget = GTK_WIDGET (entry);
8628 GtkRequisition menu_req;
8629 GdkRectangle monitor;
8630 GtkBorder inner_border;
8631 gint monitor_num, strong_x, height;
8633 g_return_if_fail (gtk_widget_get_realized (widget));
8635 gdk_window_get_origin (priv->text_area, x, y);
8637 screen = gtk_widget_get_screen (widget);
8638 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8639 if (monitor_num < 0)
8641 gtk_menu_set_monitor (menu, monitor_num);
8643 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8644 gtk_widget_get_preferred_size (priv->popup_menu,
8646 height = gdk_window_get_height (priv->text_area);
8647 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8648 _gtk_entry_effective_inner_border (entry, &inner_border);
8650 *x += inner_border.left + strong_x - priv->scroll_offset;
8651 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8652 *x -= menu_req.width;
8654 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8656 else if ((*y - menu_req.height) >= monitor.y)
8657 *y -= menu_req.height;
8658 else if (monitor.y + monitor.height - (*y + height) > *y)
8661 *y -= menu_req.height;
8667 unichar_chosen_func (const char *text,
8670 GtkEntry *entry = GTK_ENTRY (data);
8671 GtkEntryPrivate *priv = entry->priv;
8674 gtk_entry_enter_text (entry, text);
8685 popup_targets_received (GtkClipboard *clipboard,
8686 GtkSelectionData *data,
8689 PopupInfo *info = user_data;
8690 GtkEntry *entry = info->entry;
8691 GtkEntryPrivate *info_entry_priv = entry->priv;
8693 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8696 gboolean clipboard_contains_text;
8697 GtkWidget *menuitem;
8699 gboolean show_input_method_menu;
8700 gboolean show_unicode_menu;
8702 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8703 if (info_entry_priv->popup_menu)
8704 gtk_widget_destroy (info_entry_priv->popup_menu);
8706 info_entry_priv->popup_menu = gtk_menu_new ();
8708 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8712 mode = gtk_entry_get_display_mode (entry);
8713 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8714 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8715 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8717 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8718 mode == DISPLAY_NORMAL &&
8719 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8721 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8722 info_entry_priv->editable && clipboard_contains_text);
8724 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8725 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8726 g_signal_connect_swapped (menuitem, "activate",
8727 G_CALLBACK (gtk_entry_delete_cb), entry);
8728 gtk_widget_show (menuitem);
8729 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8731 menuitem = gtk_separator_menu_item_new ();
8732 gtk_widget_show (menuitem);
8733 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8735 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8736 g_signal_connect_swapped (menuitem, "activate",
8737 G_CALLBACK (gtk_entry_select_all), entry);
8738 gtk_widget_show (menuitem);
8739 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8741 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8742 "gtk-show-input-method-menu", &show_input_method_menu,
8743 "gtk-show-unicode-menu", &show_unicode_menu,
8746 if (show_input_method_menu || show_unicode_menu)
8748 menuitem = gtk_separator_menu_item_new ();
8749 gtk_widget_show (menuitem);
8750 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8753 if (show_input_method_menu)
8755 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8756 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8757 gtk_widget_show (menuitem);
8758 submenu = gtk_menu_new ();
8759 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8761 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8763 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8764 GTK_MENU_SHELL (submenu));
8767 if (show_unicode_menu)
8769 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8770 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8771 gtk_widget_show (menuitem);
8773 submenu = gtk_menu_new ();
8774 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8775 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8777 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8778 unichar_chosen_func,
8782 g_signal_emit (entry,
8783 signals[POPULATE_POPUP],
8785 info_entry_priv->popup_menu);
8789 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8791 info->button, info->time);
8794 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8795 popup_position_func, entry,
8796 info->button, info->time);
8797 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8801 g_object_unref (entry);
8802 g_slice_free (PopupInfo, info);
8806 gtk_entry_do_popup (GtkEntry *entry,
8807 GdkEventButton *event)
8809 PopupInfo *info = g_slice_new (PopupInfo);
8811 /* In order to know what entries we should make sensitive, we
8812 * ask for the current targets of the clipboard, and when
8813 * we get them, then we actually pop up the menu.
8815 info->entry = g_object_ref (entry);
8819 info->button = event->button;
8820 info->time = event->time;
8825 info->time = gtk_get_current_event_time ();
8828 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8829 gdk_atom_intern_static_string ("TARGETS"),
8830 popup_targets_received,
8835 gtk_entry_popup_menu (GtkWidget *widget)
8837 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8842 gtk_entry_drag_begin (GtkWidget *widget,
8843 GdkDragContext *context)
8845 GtkEntry *entry = GTK_ENTRY (widget);
8846 GtkEntryPrivate *priv = entry->priv;
8849 for (i = 0; i < MAX_ICONS; i++)
8851 EntryIconInfo *icon_info = priv->icons[i];
8853 if (icon_info != NULL)
8855 if (icon_info->in_drag)
8857 switch (icon_info->storage_type)
8859 case GTK_IMAGE_STOCK:
8860 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8863 case GTK_IMAGE_ICON_NAME:
8864 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8867 /* FIXME: No GIcon support for dnd icons */
8868 case GTK_IMAGE_GICON:
8869 case GTK_IMAGE_PIXBUF:
8870 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8873 g_assert_not_reached ();
8881 gtk_entry_drag_end (GtkWidget *widget,
8882 GdkDragContext *context)
8884 GtkEntry *entry = GTK_ENTRY (widget);
8885 GtkEntryPrivate *priv = entry->priv;
8888 for (i = 0; i < MAX_ICONS; i++)
8890 EntryIconInfo *icon_info = priv->icons[i];
8892 if (icon_info != NULL)
8893 icon_info->in_drag = 0;
8898 gtk_entry_drag_leave (GtkWidget *widget,
8899 GdkDragContext *context,
8902 GtkEntry *entry = GTK_ENTRY (widget);
8903 GtkEntryPrivate *priv = entry->priv;
8905 priv->dnd_position = -1;
8906 gtk_widget_queue_draw (widget);
8910 gtk_entry_drag_drop (GtkWidget *widget,
8911 GdkDragContext *context,
8916 GtkEntry *entry = GTK_ENTRY (widget);
8917 GtkEntryPrivate *priv = entry->priv;
8918 GdkAtom target = GDK_NONE;
8921 target = gtk_drag_dest_find_target (widget, context, NULL);
8923 if (target != GDK_NONE)
8924 gtk_drag_get_data (widget, context, target, time);
8926 gtk_drag_finish (context, FALSE, FALSE, time);
8932 gtk_entry_drag_motion (GtkWidget *widget,
8933 GdkDragContext *context,
8938 GtkEntry *entry = GTK_ENTRY (widget);
8939 GtkEntryPrivate *priv = entry->priv;
8940 GtkStyleContext *style_context;
8941 GtkWidget *source_widget;
8942 GdkDragAction suggested_action;
8943 gint new_position, old_position;
8947 style_context = gtk_widget_get_style_context (widget);
8948 gtk_style_context_get_padding (style_context, 0, &padding);
8952 old_position = priv->dnd_position;
8953 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8955 if (priv->editable &&
8956 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8958 source_widget = gtk_drag_get_source_widget (context);
8959 suggested_action = gdk_drag_context_get_suggested_action (context);
8961 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8962 new_position < sel1 || new_position > sel2)
8964 if (source_widget == widget)
8966 /* Default to MOVE, unless the user has
8967 * pressed ctrl or alt to affect available actions
8969 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8970 suggested_action = GDK_ACTION_MOVE;
8973 priv->dnd_position = new_position;
8977 if (source_widget == widget)
8978 suggested_action = 0; /* Can't drop in selection where drag started */
8980 priv->dnd_position = -1;
8985 /* Entry not editable, or no text */
8986 suggested_action = 0;
8987 priv->dnd_position = -1;
8990 gdk_drag_status (context, suggested_action, time);
8992 if (priv->dnd_position != old_position)
8993 gtk_widget_queue_draw (widget);
8999 gtk_entry_drag_data_received (GtkWidget *widget,
9000 GdkDragContext *context,
9003 GtkSelectionData *selection_data,
9007 GtkEntry *entry = GTK_ENTRY (widget);
9008 GtkEntryPrivate *priv = entry->priv;
9009 GtkEditable *editable = GTK_EDITABLE (widget);
9010 GtkStyleContext *style_context;
9014 str = (gchar *) gtk_selection_data_get_text (selection_data);
9016 style_context = gtk_widget_get_style_context (widget);
9017 gtk_style_context_get_padding (style_context, 0, &padding);
9021 if (str && priv->editable)
9027 if (priv->truncate_multiline)
9028 length = truncate_multiline (str);
9030 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9032 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9033 new_position < sel1 || new_position > sel2)
9035 gtk_editable_insert_text (editable, str, length, &new_position);
9039 /* Replacing selection */
9040 begin_change (entry);
9041 g_object_freeze_notify (G_OBJECT (entry));
9042 gtk_editable_delete_text (editable, sel1, sel2);
9043 gtk_editable_insert_text (editable, str, length, &sel1);
9044 g_object_thaw_notify (G_OBJECT (entry));
9048 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9052 /* Drag and drop didn't happen! */
9053 gtk_drag_finish (context, FALSE, FALSE, time);
9060 gtk_entry_drag_data_get (GtkWidget *widget,
9061 GdkDragContext *context,
9062 GtkSelectionData *selection_data,
9066 GtkEntry *entry = GTK_ENTRY (widget);
9067 GtkEntryPrivate *priv = entry->priv;
9068 GtkEditable *editable = GTK_EDITABLE (widget);
9069 gint sel_start, sel_end;
9072 /* If there is an icon drag going on, exit early. */
9073 for (i = 0; i < MAX_ICONS; i++)
9075 EntryIconInfo *icon_info = priv->icons[i];
9077 if (icon_info != NULL)
9079 if (icon_info->in_drag)
9084 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9086 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9088 gtk_selection_data_set_text (selection_data, str, -1);
9096 gtk_entry_drag_data_delete (GtkWidget *widget,
9097 GdkDragContext *context)
9099 GtkEntry *entry = GTK_ENTRY (widget);
9100 GtkEntryPrivate *priv = entry->priv;
9101 GtkEditable *editable = GTK_EDITABLE (widget);
9102 gint sel_start, sel_end;
9105 /* If there is an icon drag going on, exit early. */
9106 for (i = 0; i < MAX_ICONS; i++)
9108 EntryIconInfo *icon_info = priv->icons[i];
9110 if (icon_info != NULL)
9112 if (icon_info->in_drag)
9117 if (priv->editable &&
9118 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9119 gtk_editable_delete_text (editable, sel_start, sel_end);
9122 /* We display the cursor when
9124 * - the selection is empty, AND
9125 * - the widget has focus
9128 #define CURSOR_ON_MULTIPLIER 2
9129 #define CURSOR_OFF_MULTIPLIER 1
9130 #define CURSOR_PEND_MULTIPLIER 3
9131 #define CURSOR_DIVIDER 3
9134 cursor_blinks (GtkEntry *entry)
9136 GtkEntryPrivate *priv = entry->priv;
9138 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9140 priv->selection_bound == priv->current_pos)
9142 GtkSettings *settings;
9145 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9146 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9155 get_cursor_time (GtkEntry *entry)
9157 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9160 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9166 get_cursor_blink_timeout (GtkEntry *entry)
9168 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9171 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9177 show_cursor (GtkEntry *entry)
9179 GtkEntryPrivate *priv = entry->priv;
9182 if (!priv->cursor_visible)
9184 priv->cursor_visible = TRUE;
9186 widget = GTK_WIDGET (entry);
9187 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9188 gtk_widget_queue_draw (widget);
9193 hide_cursor (GtkEntry *entry)
9195 GtkEntryPrivate *priv = entry->priv;
9198 if (priv->cursor_visible)
9200 priv->cursor_visible = FALSE;
9202 widget = GTK_WIDGET (entry);
9203 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9204 gtk_widget_queue_draw (widget);
9212 blink_cb (gpointer data)
9215 GtkEntryPrivate *priv;
9218 entry = GTK_ENTRY (data);
9221 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9223 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9224 "connect a handler to this signal, it must return\n"
9225 "FALSE so the entry gets the event as well");
9227 gtk_entry_check_cursor_blink (entry);
9232 g_assert (priv->selection_bound == priv->current_pos);
9234 blink_timeout = get_cursor_blink_timeout (entry);
9235 if (priv->blink_time > 1000 * blink_timeout &&
9236 blink_timeout < G_MAXINT/1000)
9238 /* we've blinked enough without the user doing anything, stop blinking */
9239 show_cursor (entry);
9240 priv->blink_timeout = 0;
9242 else if (priv->cursor_visible)
9244 hide_cursor (entry);
9245 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9251 show_cursor (entry);
9252 priv->blink_time += get_cursor_time (entry);
9253 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9258 /* Remove ourselves */
9263 gtk_entry_check_cursor_blink (GtkEntry *entry)
9265 GtkEntryPrivate *priv = entry->priv;
9267 if (cursor_blinks (entry))
9269 if (!priv->blink_timeout)
9271 show_cursor (entry);
9272 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9279 if (priv->blink_timeout)
9281 g_source_remove (priv->blink_timeout);
9282 priv->blink_timeout = 0;
9285 priv->cursor_visible = TRUE;
9290 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9292 GtkEntryPrivate *priv = entry->priv;
9294 if (cursor_blinks (entry))
9296 if (priv->blink_timeout != 0)
9297 g_source_remove (priv->blink_timeout);
9299 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9302 show_cursor (entry);
9307 gtk_entry_reset_blink_time (GtkEntry *entry)
9309 GtkEntryPrivate *priv = entry->priv;
9311 priv->blink_time = 0;
9317 gtk_entry_completion_timeout (gpointer data)
9319 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9320 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9322 completion->priv->completion_timeout = 0;
9324 if (completion->priv->filter_model &&
9325 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9326 >= completion->priv->minimum_key_length)
9330 GtkTreeSelection *s;
9331 gboolean popup_single;
9333 gtk_entry_completion_complete (completion);
9334 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9336 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9338 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9340 gtk_tree_selection_unselect_all (s);
9342 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9344 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9345 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9347 if (gtk_widget_get_visible (completion->priv->popup_window))
9348 _gtk_entry_completion_resize_popup (completion);
9350 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9353 _gtk_entry_completion_popdown (completion);
9355 else if (gtk_widget_get_visible (completion->priv->popup_window))
9356 _gtk_entry_completion_popdown (completion);
9361 static inline gboolean
9362 keyval_is_cursor_move (guint keyval)
9364 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9367 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9370 if (keyval == GDK_KEY_Page_Up)
9373 if (keyval == GDK_KEY_Page_Down)
9380 gtk_entry_completion_key_press (GtkWidget *widget,
9384 gint matches, actions = 0;
9385 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9387 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9390 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9392 if (completion->priv->actions)
9393 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9395 if (keyval_is_cursor_move (event->keyval))
9397 GtkTreePath *path = NULL;
9399 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9401 if (completion->priv->current_selected < 0)
9402 completion->priv->current_selected = matches + actions - 1;
9404 completion->priv->current_selected--;
9406 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9408 if (completion->priv->current_selected < matches + actions - 1)
9409 completion->priv->current_selected++;
9411 completion->priv->current_selected = -1;
9413 else if (event->keyval == GDK_KEY_Page_Up)
9415 if (completion->priv->current_selected < 0)
9416 completion->priv->current_selected = matches + actions - 1;
9417 else if (completion->priv->current_selected == 0)
9418 completion->priv->current_selected = -1;
9419 else if (completion->priv->current_selected < matches)
9421 completion->priv->current_selected -= 14;
9422 if (completion->priv->current_selected < 0)
9423 completion->priv->current_selected = 0;
9427 completion->priv->current_selected -= 14;
9428 if (completion->priv->current_selected < matches - 1)
9429 completion->priv->current_selected = matches - 1;
9432 else if (event->keyval == GDK_KEY_Page_Down)
9434 if (completion->priv->current_selected < 0)
9435 completion->priv->current_selected = 0;
9436 else if (completion->priv->current_selected < matches - 1)
9438 completion->priv->current_selected += 14;
9439 if (completion->priv->current_selected > matches - 1)
9440 completion->priv->current_selected = matches - 1;
9442 else if (completion->priv->current_selected == matches + actions - 1)
9444 completion->priv->current_selected = -1;
9448 completion->priv->current_selected += 14;
9449 if (completion->priv->current_selected > matches + actions - 1)
9450 completion->priv->current_selected = matches + actions - 1;
9454 if (completion->priv->current_selected < 0)
9456 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9457 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9459 if (completion->priv->inline_selection &&
9460 completion->priv->completion_prefix)
9462 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9463 completion->priv->completion_prefix);
9464 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9467 else if (completion->priv->current_selected < matches)
9469 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9471 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9472 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9475 if (completion->priv->inline_selection)
9479 GtkTreeIter child_iter;
9480 GtkTreeModel *model = NULL;
9481 GtkTreeSelection *sel;
9484 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9485 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9488 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9489 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9491 if (completion->priv->completion_prefix == NULL)
9492 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9494 g_signal_emit_by_name (completion, "cursor-on-match", model,
9495 &child_iter, &entry_set);
9498 else if (completion->priv->current_selected - matches >= 0)
9500 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9502 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9503 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9506 if (completion->priv->inline_selection &&
9507 completion->priv->completion_prefix)
9509 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9510 completion->priv->completion_prefix);
9511 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9515 gtk_tree_path_free (path);
9519 else if (event->keyval == GDK_KEY_Escape ||
9520 event->keyval == GDK_KEY_Left ||
9521 event->keyval == GDK_KEY_KP_Left ||
9522 event->keyval == GDK_KEY_Right ||
9523 event->keyval == GDK_KEY_KP_Right)
9525 gboolean retval = TRUE;
9527 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9528 _gtk_entry_completion_popdown (completion);
9530 if (completion->priv->current_selected < 0)
9533 goto keypress_completion_out;
9535 else if (completion->priv->inline_selection)
9537 /* Escape rejects the tentative completion */
9538 if (event->keyval == GDK_KEY_Escape)
9540 if (completion->priv->completion_prefix)
9541 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9542 completion->priv->completion_prefix);
9544 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9547 /* Move the cursor to the end for Right/Esc, to the
9548 beginning for Left */
9549 if (event->keyval == GDK_KEY_Right ||
9550 event->keyval == GDK_KEY_KP_Right ||
9551 event->keyval == GDK_KEY_Escape)
9552 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9554 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9557 keypress_completion_out:
9558 if (completion->priv->inline_selection)
9560 g_free (completion->priv->completion_prefix);
9561 completion->priv->completion_prefix = NULL;
9566 else if (event->keyval == GDK_KEY_Tab ||
9567 event->keyval == GDK_KEY_KP_Tab ||
9568 event->keyval == GDK_KEY_ISO_Left_Tab)
9570 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9571 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9573 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9574 _gtk_entry_completion_popdown (completion);
9576 g_free (completion->priv->completion_prefix);
9577 completion->priv->completion_prefix = NULL;
9579 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9583 else if (event->keyval == GDK_KEY_ISO_Enter ||
9584 event->keyval == GDK_KEY_KP_Enter ||
9585 event->keyval == GDK_KEY_Return)
9588 GtkTreeModel *model = NULL;
9589 GtkTreeModel *child_model;
9590 GtkTreeIter child_iter;
9591 GtkTreeSelection *sel;
9592 gboolean retval = TRUE;
9594 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9595 _gtk_entry_completion_popdown (completion);
9597 if (completion->priv->current_selected < matches)
9601 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9602 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9604 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9605 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9606 g_signal_handler_block (widget, completion->priv->changed_id);
9607 g_signal_emit_by_name (completion, "match-selected",
9608 child_model, &child_iter, &entry_set);
9609 g_signal_handler_unblock (widget, completion->priv->changed_id);
9615 gtk_tree_model_get (model, &iter,
9616 completion->priv->text_column, &str,
9619 gtk_entry_set_text (GTK_ENTRY (widget), str);
9621 /* move the cursor to the end */
9622 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9630 else if (completion->priv->current_selected - matches >= 0)
9632 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9633 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9637 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9638 g_signal_emit_by_name (completion, "action-activated",
9639 gtk_tree_path_get_indices (path)[0]);
9640 gtk_tree_path_free (path);
9646 g_free (completion->priv->completion_prefix);
9647 completion->priv->completion_prefix = NULL;
9656 gtk_entry_completion_changed (GtkWidget *widget,
9659 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9660 GtkEntry *entry = GTK_ENTRY (widget);
9661 GtkEntryPrivate *priv = entry->priv;
9664 /* (re)install completion timeout */
9665 if (completion->priv->completion_timeout)
9666 g_source_remove (completion->priv->completion_timeout);
9668 if (!gtk_entry_get_text (entry))
9671 /* no need to normalize for this test */
9672 if (completion->priv->minimum_key_length > 0 &&
9673 strcmp ("", gtk_entry_get_text (entry)) == 0)
9675 if (gtk_widget_get_visible (completion->priv->popup_window))
9676 _gtk_entry_completion_popdown (completion);
9680 device = gtk_get_current_event_device ();
9682 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9683 device = gdk_device_get_associated_device (device);
9686 priv->completion_device = device;
9688 completion->priv->completion_timeout =
9689 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9690 gtk_entry_completion_timeout,
9695 check_completion_callback (GtkEntryCompletion *completion)
9697 completion->priv->check_completion_idle = NULL;
9699 gtk_entry_completion_complete (completion);
9700 gtk_entry_completion_insert_prefix (completion);
9706 clear_completion_callback (GtkEntry *entry,
9709 if (pspec->name == I_("cursor-position") ||
9710 pspec->name == I_("selection-bound"))
9712 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9714 completion->priv->has_completion = FALSE;
9719 accept_completion_callback (GtkEntry *entry)
9721 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9723 if (completion->priv->has_completion)
9724 gtk_editable_set_position (GTK_EDITABLE (entry),
9725 gtk_entry_buffer_get_length (get_buffer (entry)));
9731 completion_insert_text_callback (GtkEntry *entry,
9735 GtkEntryCompletion *completion)
9737 /* idle to update the selection based on the file list */
9738 if (completion->priv->check_completion_idle == NULL)
9740 completion->priv->check_completion_idle = g_idle_source_new ();
9741 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9742 g_source_set_closure (completion->priv->check_completion_idle,
9743 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9744 G_OBJECT (completion)));
9745 g_source_attach (completion->priv->check_completion_idle, NULL);
9750 completion_changed (GtkEntryCompletion *completion,
9754 GtkEntry *entry = GTK_ENTRY (data);
9756 if (pspec->name == I_("popup-completion") ||
9757 pspec->name == I_("inline-completion"))
9759 disconnect_completion_signals (entry, completion);
9760 connect_completion_signals (entry, completion);
9765 disconnect_completion_signals (GtkEntry *entry,
9766 GtkEntryCompletion *completion)
9768 g_signal_handlers_disconnect_by_func (completion,
9769 G_CALLBACK (completion_changed), entry);
9770 if (completion->priv->changed_id > 0 &&
9771 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9773 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9774 completion->priv->changed_id = 0;
9776 g_signal_handlers_disconnect_by_func (entry,
9777 G_CALLBACK (gtk_entry_completion_key_press), completion);
9778 if (completion->priv->insert_text_id > 0 &&
9779 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9781 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9782 completion->priv->insert_text_id = 0;
9784 g_signal_handlers_disconnect_by_func (entry,
9785 G_CALLBACK (completion_insert_text_callback), completion);
9786 g_signal_handlers_disconnect_by_func (entry,
9787 G_CALLBACK (clear_completion_callback), completion);
9788 g_signal_handlers_disconnect_by_func (entry,
9789 G_CALLBACK (accept_completion_callback), completion);
9793 connect_completion_signals (GtkEntry *entry,
9794 GtkEntryCompletion *completion)
9796 if (completion->priv->popup_completion)
9798 completion->priv->changed_id =
9799 g_signal_connect (entry, "changed",
9800 G_CALLBACK (gtk_entry_completion_changed), completion);
9801 g_signal_connect (entry, "key-press-event",
9802 G_CALLBACK (gtk_entry_completion_key_press), completion);
9805 if (completion->priv->inline_completion)
9807 completion->priv->insert_text_id =
9808 g_signal_connect (entry, "insert-text",
9809 G_CALLBACK (completion_insert_text_callback), completion);
9810 g_signal_connect (entry, "notify",
9811 G_CALLBACK (clear_completion_callback), completion);
9812 g_signal_connect (entry, "activate",
9813 G_CALLBACK (accept_completion_callback), completion);
9814 g_signal_connect (entry, "focus-out-event",
9815 G_CALLBACK (accept_completion_callback), completion);
9818 g_signal_connect (completion, "notify",
9819 G_CALLBACK (completion_changed), entry);
9823 * gtk_entry_set_completion:
9824 * @entry: A #GtkEntry
9825 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9827 * Sets @completion to be the auxiliary completion object to use with @entry.
9828 * All further configuration of the completion mechanism is done on
9829 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9830 * @completion is set to %NULL.
9835 gtk_entry_set_completion (GtkEntry *entry,
9836 GtkEntryCompletion *completion)
9838 GtkEntryCompletion *old;
9840 g_return_if_fail (GTK_IS_ENTRY (entry));
9841 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9843 old = gtk_entry_get_completion (entry);
9845 if (old == completion)
9850 if (old->priv->completion_timeout)
9852 g_source_remove (old->priv->completion_timeout);
9853 old->priv->completion_timeout = 0;
9856 if (gtk_widget_get_mapped (old->priv->popup_window))
9857 _gtk_entry_completion_popdown (old);
9859 disconnect_completion_signals (entry, old);
9860 old->priv->entry = NULL;
9862 g_object_unref (old);
9867 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9871 /* hook into the entry */
9872 g_object_ref (completion);
9874 connect_completion_signals (entry, completion);
9875 completion->priv->entry = GTK_WIDGET (entry);
9876 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9880 * gtk_entry_get_completion:
9881 * @entry: A #GtkEntry
9883 * Returns the auxiliary completion object currently in use by @entry.
9885 * Return value: (transfer none): The auxiliary completion object currently
9890 GtkEntryCompletion *
9891 gtk_entry_get_completion (GtkEntry *entry)
9893 GtkEntryCompletion *completion;
9895 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9897 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9898 GTK_ENTRY_COMPLETION_KEY));
9904 * gtk_entry_set_cursor_hadjustment:
9905 * @entry: a #GtkEntry
9906 * @adjustment: an adjustment which should be adjusted when the cursor
9907 * is moved, or %NULL
9909 * Hooks up an adjustment to the cursor position in an entry, so that when
9910 * the cursor is moved, the adjustment is scrolled to show that position.
9911 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9914 * The adjustment has to be in pixel units and in the same coordinate system
9920 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9921 GtkAdjustment *adjustment)
9923 g_return_if_fail (GTK_IS_ENTRY (entry));
9925 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9928 g_object_ref (adjustment);
9930 g_object_set_qdata_full (G_OBJECT (entry),
9931 quark_cursor_hadjustment,
9937 * gtk_entry_get_cursor_hadjustment:
9938 * @entry: a #GtkEntry
9940 * Retrieves the horizontal cursor adjustment for the entry.
9941 * See gtk_entry_set_cursor_hadjustment().
9943 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9944 * if none has been set.
9949 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9951 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9953 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9957 * gtk_entry_set_progress_fraction:
9958 * @entry: a #GtkEntry
9959 * @fraction: fraction of the task that's been completed
9961 * Causes the entry's progress indicator to "fill in" the given
9962 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9968 gtk_entry_set_progress_fraction (GtkEntry *entry,
9972 GtkEntryPrivate *private;
9973 gdouble old_fraction;
9974 gint x, y, width, height;
9975 gint old_x, old_y, old_width, old_height;
9977 g_return_if_fail (GTK_IS_ENTRY (entry));
9979 widget = GTK_WIDGET (entry);
9980 private = entry->priv;
9982 if (private->progress_pulse_mode)
9985 old_fraction = private->progress_fraction;
9987 if (gtk_widget_is_drawable (widget))
9988 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9990 fraction = CLAMP (fraction, 0.0, 1.0);
9992 private->progress_fraction = fraction;
9993 private->progress_pulse_mode = FALSE;
9994 private->progress_pulse_current = 0.0;
9996 if (gtk_widget_is_drawable (widget))
9998 get_progress_area (widget, &x, &y, &width, &height);
10000 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10001 gtk_widget_queue_draw (widget);
10004 if (fraction != old_fraction)
10005 g_object_notify (G_OBJECT (entry), "progress-fraction");
10009 * gtk_entry_get_progress_fraction:
10010 * @entry: a #GtkEntry
10012 * Returns the current fraction of the task that's been completed.
10013 * See gtk_entry_set_progress_fraction().
10015 * Return value: a fraction from 0.0 to 1.0
10020 gtk_entry_get_progress_fraction (GtkEntry *entry)
10022 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10024 return entry->priv->progress_fraction;
10028 * gtk_entry_set_progress_pulse_step:
10029 * @entry: a #GtkEntry
10030 * @fraction: fraction between 0.0 and 1.0
10032 * Sets the fraction of total entry width to move the progress
10033 * bouncing block for each call to gtk_entry_progress_pulse().
10038 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10041 GtkEntryPrivate *private;
10043 g_return_if_fail (GTK_IS_ENTRY (entry));
10045 private = entry->priv;
10047 fraction = CLAMP (fraction, 0.0, 1.0);
10049 if (fraction != private->progress_pulse_fraction)
10051 private->progress_pulse_fraction = fraction;
10053 gtk_widget_queue_draw (GTK_WIDGET (entry));
10055 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10060 * gtk_entry_get_progress_pulse_step:
10061 * @entry: a #GtkEntry
10063 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10065 * Return value: a fraction from 0.0 to 1.0
10070 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10072 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10074 return entry->priv->progress_pulse_fraction;
10078 * gtk_entry_progress_pulse:
10079 * @entry: a #GtkEntry
10081 * Indicates that some progress is made, but you don't know how much.
10082 * Causes the entry's progress indicator to enter "activity mode,"
10083 * where a block bounces back and forth. Each call to
10084 * gtk_entry_progress_pulse() causes the block to move by a little bit
10085 * (the amount of movement per pulse is determined by
10086 * gtk_entry_set_progress_pulse_step()).
10091 gtk_entry_progress_pulse (GtkEntry *entry)
10093 GtkEntryPrivate *private;
10095 g_return_if_fail (GTK_IS_ENTRY (entry));
10097 private = entry->priv;
10099 if (private->progress_pulse_mode)
10101 if (private->progress_pulse_way_back)
10103 private->progress_pulse_current -= private->progress_pulse_fraction;
10105 if (private->progress_pulse_current < 0.0)
10107 private->progress_pulse_current = 0.0;
10108 private->progress_pulse_way_back = FALSE;
10113 private->progress_pulse_current += private->progress_pulse_fraction;
10115 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10117 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10118 private->progress_pulse_way_back = TRUE;
10124 private->progress_fraction = 0.0;
10125 private->progress_pulse_mode = TRUE;
10126 private->progress_pulse_way_back = FALSE;
10127 private->progress_pulse_current = 0.0;
10130 gtk_widget_queue_draw (GTK_WIDGET (entry));
10133 /* Caps Lock warning for password entries */
10136 show_capslock_feedback (GtkEntry *entry,
10139 GtkEntryPrivate *priv = entry->priv;
10141 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10143 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10144 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10145 priv->caps_lock_warning_shown = TRUE;
10148 if (priv->caps_lock_warning_shown)
10149 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10151 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10155 remove_capslock_feedback (GtkEntry *entry)
10157 GtkEntryPrivate *priv = entry->priv;
10159 if (priv->caps_lock_warning_shown)
10161 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10162 priv->caps_lock_warning_shown = FALSE;
10167 keymap_state_changed (GdkKeymap *keymap,
10170 GtkEntryPrivate *priv = entry->priv;
10173 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10175 if (gdk_keymap_get_num_lock_state (keymap)
10176 && gdk_keymap_get_caps_lock_state (keymap))
10177 text = _("Caps Lock and Num Lock are on");
10178 else if (gdk_keymap_get_num_lock_state (keymap))
10179 text = _("Num Lock is on");
10180 else if (gdk_keymap_get_caps_lock_state (keymap))
10181 text = _("Caps Lock is on");
10185 show_capslock_feedback (entry, text);
10187 remove_capslock_feedback (entry);
10191 * _gtk_entry_set_is_cell_renderer:
10192 * @entry: a #GtkEntry
10193 * @is_cell_renderer: new value
10195 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10196 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10198 * I.e take up it's allocation and get GtkEntry->is_cell_renderer = TRUE.
10202 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10203 gboolean is_cell_renderer)
10205 entry->priv->is_cell_renderer = is_cell_renderer;