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, see <http://www.gnu.org/licenses/>.
23 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
24 * file for a list of people on the GTK+ Team. See the ChangeLog
25 * files for a list of changes. These files are distributed with
26 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #include "gtkbindings.h"
35 #include "gtkcelleditable.h"
36 #include "gtkclipboard.h"
39 #include "gtkentrybuffer.h"
40 #include "gtkiconhelperprivate.h"
41 #include "gtkimagemenuitem.h"
42 #include "gtkimcontextsimple.h"
43 #include "gtkimmulticontext.h"
47 #include "gtkmarshalers.h"
49 #include "gtkmenuitem.h"
50 #include "gtkseparatormenuitem.h"
51 #include "gtkselection.h"
52 #include "gtksettings.h"
53 #include "gtkspinbutton.h"
55 #include "gtktextutil.h"
56 #include "gtkwindow.h"
57 #include "gtktreeview.h"
58 #include "gtktreeselection.h"
59 #include "gtktypebuiltins.h"
60 #include "gtkprivate.h"
61 #include "gtkentryprivate.h"
62 #include "gtkcelllayout.h"
63 #include "gtktooltip.h"
64 #include "gtkiconfactory.h"
65 #include "gtkicontheme.h"
66 #include "gtkwidgetprivate.h"
67 #include "gtkstylecontextprivate.h"
68 #include "gtktexthandleprivate.h"
69 #include "gtkselectionwindow.h"
71 #include "a11y/gtkentryaccessible.h"
75 * @Short_description: A single line text entry field
77 * @See_also: #GtkTextView, #GtkEntryCompletion
79 * The #GtkEntry widget is a single line text entry
80 * widget. A fairly large set of key bindings are supported
81 * by default. If the entered text is longer than the allocation
82 * of the widget, the widget will scroll so that the cursor
83 * position is visible.
85 * When using an entry for passwords and other sensitive information,
86 * it can be put into "password mode" using gtk_entry_set_visibility().
87 * In this mode, entered text is displayed using a 'invisible' character.
88 * By default, GTK+ picks the best invisible character that is available
89 * in the current font, but it can be changed with
90 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
91 * when Caps Lock or input methods might interfere with entering text in
92 * a password entry. The warning can be turned off with the
93 * #GtkEntry:caps-lock-warning property.
95 * Since 2.16, GtkEntry has the ability to display progress or activity
96 * information behind the text. To make an entry display such information,
97 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
99 * Additionally, GtkEntry can show icons at either side of the entry. These
100 * icons can be activatable by clicking, can be set up as drag source and
101 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
102 * one of the various other functions that set an icon from a stock id, an
103 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
104 * connect to the #GtkEntry::icon-press signal. To allow DND operations
105 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
106 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
109 * Note that functionality or information that is only available by clicking
110 * on an icon in an entry may not be accessible at all to users which are not
111 * able to use a mouse or other pointing device. It is therefore recommended
112 * that any such functionality should also be available by other means, e.g.
113 * via the context menu of the entry.
117 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
119 #define MIN_ENTRY_WIDTH 150
120 #define DRAW_TIMEOUT 20
121 #define PASSWORD_HINT_MAX 8
125 #define IS_VALID_ICON_POSITION(pos) \
126 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
127 (pos) == GTK_ENTRY_ICON_SECONDARY)
129 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
130 static GQuark quark_inner_border = 0;
131 static GQuark quark_password_hint = 0;
132 static GQuark quark_cursor_hadjustment = 0;
133 static GQuark quark_capslock_feedback = 0;
135 typedef struct _EntryIconInfo EntryIconInfo;
136 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
137 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
139 struct _GtkEntryPrivate
141 EntryIconInfo *icons[MAX_ICONS];
143 GtkEntryBuffer *buffer;
144 GtkIMContext *im_context;
145 GtkWidget *popup_menu;
149 GdkWindow *text_area;
151 PangoLayout *cached_layout;
152 PangoAttrList *attrs;
156 gdouble progress_fraction;
157 gdouble progress_pulse_fraction;
158 gdouble progress_pulse_current;
160 gchar *placeholder_text;
162 GtkBubbleWindow *bubble_window;
163 GtkTextHandle *text_handle;
164 GtkWidget *selection_bubble;
165 guint selection_bubble_timeout_id;
169 gint ascent; /* font ascent in pango units */
171 gint descent; /* font descent in pango units */
172 gint dnd_position; /* In chars, -1 == no DND cursor */
177 gint selection_bound;
183 gunichar invisible_char;
186 guint blink_time; /* time in msec the cursor has blinked since last user event */
188 guint recompute_idle;
190 guint16 x_text_size; /* allocated size, in bytes */
191 guint16 x_n_bytes; /* length in use, in bytes */
193 guint16 preedit_length; /* length of preedit string, in bytes */
194 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
196 guint shadow_type : 4;
199 guint overwrite_mode : 1;
202 guint activates_default : 1;
203 guint cache_includes_preedit : 1;
204 guint caps_lock_warning : 1;
205 guint caps_lock_warning_shown : 1;
206 guint change_count : 8;
207 guint cursor_visible : 1;
208 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
210 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
211 guint is_cell_renderer : 1;
212 guint invisible_char_set : 1;
213 guint interior_focus : 1;
214 guint mouse_cursor_obscured : 1;
215 guint need_im_reset : 1;
216 guint progress_pulse_mode : 1;
217 guint progress_pulse_way_back : 1;
218 guint real_changed : 1;
219 guint resolved_dir : 4; /* PangoDirection */
220 guint select_words : 1;
221 guint select_lines : 1;
222 guint truncate_multiline : 1;
223 guint cursor_handle_dragged : 1;
224 guint selection_handle_dragged : 1;
227 struct _EntryIconInfo
231 guint insensitive : 1;
232 guint nonactivatable : 1;
237 GtkIconHelper *icon_helper;
239 GtkTargetList *target_list;
240 GdkDragAction actions;
243 struct _GtkEntryPasswordHint
245 gint position; /* Position (in text) of the last password hint */
246 guint source_id; /* Timeout source id */
249 struct _GtkEntryCapslockFeedback
276 PROP_CURSOR_POSITION,
277 PROP_SELECTION_BOUND,
284 PROP_ACTIVATES_DEFAULT,
289 PROP_TRUNCATE_MULTILINE,
293 PROP_INVISIBLE_CHAR_SET,
294 PROP_CAPS_LOCK_WARNING,
295 PROP_PROGRESS_FRACTION,
296 PROP_PROGRESS_PULSE_STEP,
298 PROP_PIXBUF_SECONDARY,
300 PROP_STOCK_SECONDARY,
301 PROP_ICON_NAME_PRIMARY,
302 PROP_ICON_NAME_SECONDARY,
304 PROP_GICON_SECONDARY,
305 PROP_STORAGE_TYPE_PRIMARY,
306 PROP_STORAGE_TYPE_SECONDARY,
307 PROP_ACTIVATABLE_PRIMARY,
308 PROP_ACTIVATABLE_SECONDARY,
309 PROP_SENSITIVE_PRIMARY,
310 PROP_SENSITIVE_SECONDARY,
311 PROP_TOOLTIP_TEXT_PRIMARY,
312 PROP_TOOLTIP_TEXT_SECONDARY,
313 PROP_TOOLTIP_MARKUP_PRIMARY,
314 PROP_TOOLTIP_MARKUP_SECONDARY,
316 PROP_EDITING_CANCELED,
317 PROP_PLACEHOLDER_TEXT,
324 static guint signals[LAST_SIGNAL] = { 0 };
325 static gboolean test_touchscreen = FALSE;
334 DISPLAY_NORMAL, /* The entry text is being shown */
335 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
336 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
341 static void gtk_entry_editable_init (GtkEditableInterface *iface);
342 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
343 static void gtk_entry_set_property (GObject *object,
347 static void gtk_entry_get_property (GObject *object,
351 static void gtk_entry_finalize (GObject *object);
352 static void gtk_entry_dispose (GObject *object);
356 static void gtk_entry_destroy (GtkWidget *widget);
357 static void gtk_entry_realize (GtkWidget *widget);
358 static void gtk_entry_unrealize (GtkWidget *widget);
359 static void gtk_entry_map (GtkWidget *widget);
360 static void gtk_entry_unmap (GtkWidget *widget);
361 static void gtk_entry_get_preferred_width (GtkWidget *widget,
364 static void gtk_entry_get_preferred_height (GtkWidget *widget,
367 static void gtk_entry_size_allocate (GtkWidget *widget,
368 GtkAllocation *allocation);
369 static void gtk_entry_draw_frame (GtkWidget *widget,
370 GtkStyleContext *context,
372 static void gtk_entry_draw_progress (GtkWidget *widget,
373 GtkStyleContext *context,
375 static gint gtk_entry_draw (GtkWidget *widget,
377 static gint gtk_entry_button_press (GtkWidget *widget,
378 GdkEventButton *event);
379 static gint gtk_entry_button_release (GtkWidget *widget,
380 GdkEventButton *event);
381 static gint gtk_entry_enter_notify (GtkWidget *widget,
382 GdkEventCrossing *event);
383 static gint gtk_entry_leave_notify (GtkWidget *widget,
384 GdkEventCrossing *event);
385 static gint gtk_entry_motion_notify (GtkWidget *widget,
386 GdkEventMotion *event);
387 static gint gtk_entry_key_press (GtkWidget *widget,
389 static gint gtk_entry_key_release (GtkWidget *widget,
391 static gint gtk_entry_focus_in (GtkWidget *widget,
392 GdkEventFocus *event);
393 static gint gtk_entry_focus_out (GtkWidget *widget,
394 GdkEventFocus *event);
395 static void gtk_entry_grab_focus (GtkWidget *widget);
396 static void gtk_entry_style_updated (GtkWidget *widget);
397 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
400 gboolean keyboard_tip,
401 GtkTooltip *tooltip);
402 static void gtk_entry_direction_changed (GtkWidget *widget,
403 GtkTextDirection previous_dir);
404 static void gtk_entry_state_flags_changed (GtkWidget *widget,
405 GtkStateFlags previous_state);
406 static void gtk_entry_screen_changed (GtkWidget *widget,
407 GdkScreen *old_screen);
409 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
410 GdkDragContext *context,
414 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
415 GdkDragContext *context,
419 static void gtk_entry_drag_leave (GtkWidget *widget,
420 GdkDragContext *context,
422 static void gtk_entry_drag_data_received (GtkWidget *widget,
423 GdkDragContext *context,
426 GtkSelectionData *selection_data,
429 static void gtk_entry_drag_data_get (GtkWidget *widget,
430 GdkDragContext *context,
431 GtkSelectionData *selection_data,
434 static void gtk_entry_drag_data_delete (GtkWidget *widget,
435 GdkDragContext *context);
436 static void gtk_entry_drag_begin (GtkWidget *widget,
437 GdkDragContext *context);
438 static void gtk_entry_drag_end (GtkWidget *widget,
439 GdkDragContext *context);
442 /* GtkEditable method implementations
444 static void gtk_entry_insert_text (GtkEditable *editable,
445 const gchar *new_text,
446 gint new_text_length,
448 static void gtk_entry_delete_text (GtkEditable *editable,
451 static gchar * gtk_entry_get_chars (GtkEditable *editable,
454 static void gtk_entry_real_set_position (GtkEditable *editable,
456 static gint gtk_entry_get_position (GtkEditable *editable);
457 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
460 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
464 /* GtkCellEditable method implementations
466 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
469 /* Default signal handlers
471 static void gtk_entry_real_insert_text (GtkEditable *editable,
472 const gchar *new_text,
473 gint new_text_length,
475 static void gtk_entry_real_delete_text (GtkEditable *editable,
478 static void gtk_entry_move_cursor (GtkEntry *entry,
479 GtkMovementStep step,
481 gboolean extend_selection);
482 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
484 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
487 static void gtk_entry_backspace (GtkEntry *entry);
488 static void gtk_entry_cut_clipboard (GtkEntry *entry);
489 static void gtk_entry_copy_clipboard (GtkEntry *entry);
490 static void gtk_entry_paste_clipboard (GtkEntry *entry);
491 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
492 static void gtk_entry_select_all (GtkEntry *entry);
493 static void gtk_entry_real_activate (GtkEntry *entry);
494 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
496 static void keymap_direction_changed (GdkKeymap *keymap,
498 static void keymap_state_changed (GdkKeymap *keymap,
500 static void remove_capslock_feedback (GtkEntry *entry);
502 /* IM Context Callbacks
504 static void gtk_entry_commit_cb (GtkIMContext *context,
507 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
509 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
511 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
518 static void gtk_entry_enter_text (GtkEntry *entry,
520 static void gtk_entry_set_positions (GtkEntry *entry,
522 gint selection_bound);
523 static void gtk_entry_draw_text (GtkEntry *entry,
525 static void gtk_entry_draw_cursor (GtkEntry *entry,
528 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
529 gboolean include_preedit);
530 static void gtk_entry_reset_layout (GtkEntry *entry);
531 static void gtk_entry_recompute (GtkEntry *entry);
532 static gint gtk_entry_find_position (GtkEntry *entry,
534 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
538 static void gtk_entry_adjust_scroll (GtkEntry *entry);
539 static gint gtk_entry_move_visually (GtkEntry *editable,
542 static gint gtk_entry_move_logically (GtkEntry *entry,
545 static gint gtk_entry_move_forward_word (GtkEntry *entry,
547 gboolean allow_whitespace);
548 static gint gtk_entry_move_backward_word (GtkEntry *entry,
550 gboolean allow_whitespace);
551 static void gtk_entry_delete_whitespace (GtkEntry *entry);
552 static void gtk_entry_select_word (GtkEntry *entry);
553 static void gtk_entry_select_line (GtkEntry *entry);
554 static void gtk_entry_paste (GtkEntry *entry,
556 static void gtk_entry_update_primary_selection (GtkEntry *entry);
557 static void gtk_entry_do_popup (GtkEntry *entry,
558 GdkEventButton *event);
559 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
560 gboolean group_cycling);
561 static void gtk_entry_grab_notify (GtkWidget *widget,
562 gboolean was_grabbed);
563 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
564 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
565 static void gtk_entry_reset_blink_time (GtkEntry *entry);
566 static void gtk_entry_get_text_area_size (GtkEntry *entry,
571 static void gtk_entry_get_frame_size (GtkEntry *entry,
576 static void get_text_area_size (GtkEntry *entry,
581 static void get_frame_size (GtkEntry *entry,
582 gboolean relative_to_window,
587 static void gtk_entry_move_adjustments (GtkEntry *entry);
588 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
589 GtkEntryIconPosition icon_pos);
590 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
591 static gboolean get_middle_click_paste (GtkEntry *entry);
593 /* GtkTextHandle handlers */
594 static void gtk_entry_handle_dragged (GtkTextHandle *handle,
595 GtkTextHandlePosition pos,
599 static void gtk_entry_handle_drag_finished (GtkTextHandle *handle,
600 GtkTextHandlePosition pos,
603 static void gtk_entry_selection_bubble_popup_set (GtkEntry *entry);
604 static void gtk_entry_selection_bubble_popup_unset (GtkEntry *entry);
606 static void begin_change (GtkEntry *entry);
607 static void end_change (GtkEntry *entry);
608 static void emit_changed (GtkEntry *entry);
610 static void buffer_inserted_text (GtkEntryBuffer *buffer,
615 static void buffer_deleted_text (GtkEntryBuffer *buffer,
619 static void buffer_notify_text (GtkEntryBuffer *buffer,
622 static void buffer_notify_length (GtkEntryBuffer *buffer,
625 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
628 static void buffer_connect_signals (GtkEntry *entry);
629 static void buffer_disconnect_signals (GtkEntry *entry);
630 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
632 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
633 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
634 gtk_entry_editable_init)
635 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
636 gtk_entry_cell_editable_init))
639 add_move_binding (GtkBindingSet *binding_set,
642 GtkMovementStep step,
645 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
647 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
651 G_TYPE_BOOLEAN, FALSE);
653 /* Selection-extending version */
654 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
658 G_TYPE_BOOLEAN, TRUE);
662 gtk_entry_class_init (GtkEntryClass *class)
664 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
665 GtkWidgetClass *widget_class;
666 GtkBindingSet *binding_set;
668 widget_class = (GtkWidgetClass*) class;
670 gobject_class->dispose = gtk_entry_dispose;
671 gobject_class->finalize = gtk_entry_finalize;
672 gobject_class->set_property = gtk_entry_set_property;
673 gobject_class->get_property = gtk_entry_get_property;
675 widget_class->destroy = gtk_entry_destroy;
676 widget_class->map = gtk_entry_map;
677 widget_class->unmap = gtk_entry_unmap;
678 widget_class->realize = gtk_entry_realize;
679 widget_class->unrealize = gtk_entry_unrealize;
680 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
681 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
682 widget_class->size_allocate = gtk_entry_size_allocate;
683 widget_class->draw = gtk_entry_draw;
684 widget_class->enter_notify_event = gtk_entry_enter_notify;
685 widget_class->leave_notify_event = gtk_entry_leave_notify;
686 widget_class->button_press_event = gtk_entry_button_press;
687 widget_class->button_release_event = gtk_entry_button_release;
688 widget_class->motion_notify_event = gtk_entry_motion_notify;
689 widget_class->key_press_event = gtk_entry_key_press;
690 widget_class->key_release_event = gtk_entry_key_release;
691 widget_class->focus_in_event = gtk_entry_focus_in;
692 widget_class->focus_out_event = gtk_entry_focus_out;
693 widget_class->grab_focus = gtk_entry_grab_focus;
694 widget_class->style_updated = gtk_entry_style_updated;
695 widget_class->query_tooltip = gtk_entry_query_tooltip;
696 widget_class->drag_begin = gtk_entry_drag_begin;
697 widget_class->drag_end = gtk_entry_drag_end;
698 widget_class->direction_changed = gtk_entry_direction_changed;
699 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
700 widget_class->screen_changed = gtk_entry_screen_changed;
701 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
702 widget_class->grab_notify = gtk_entry_grab_notify;
704 widget_class->drag_drop = gtk_entry_drag_drop;
705 widget_class->drag_motion = gtk_entry_drag_motion;
706 widget_class->drag_leave = gtk_entry_drag_leave;
707 widget_class->drag_data_received = gtk_entry_drag_data_received;
708 widget_class->drag_data_get = gtk_entry_drag_data_get;
709 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
711 widget_class->popup_menu = gtk_entry_popup_menu;
713 class->move_cursor = gtk_entry_move_cursor;
714 class->insert_at_cursor = gtk_entry_insert_at_cursor;
715 class->delete_from_cursor = gtk_entry_delete_from_cursor;
716 class->backspace = gtk_entry_backspace;
717 class->cut_clipboard = gtk_entry_cut_clipboard;
718 class->copy_clipboard = gtk_entry_copy_clipboard;
719 class->paste_clipboard = gtk_entry_paste_clipboard;
720 class->toggle_overwrite = gtk_entry_toggle_overwrite;
721 class->activate = gtk_entry_real_activate;
722 class->get_text_area_size = gtk_entry_get_text_area_size;
723 class->get_frame_size = gtk_entry_get_frame_size;
725 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
726 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
727 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
728 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
730 g_object_class_override_property (gobject_class,
731 PROP_EDITING_CANCELED,
734 g_object_class_install_property (gobject_class,
736 g_param_spec_object ("buffer",
738 P_("Text buffer object which actually stores entry text"),
739 GTK_TYPE_ENTRY_BUFFER,
740 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
742 g_object_class_install_property (gobject_class,
743 PROP_CURSOR_POSITION,
744 g_param_spec_int ("cursor-position",
745 P_("Cursor Position"),
746 P_("The current position of the insertion cursor in chars"),
748 GTK_ENTRY_BUFFER_MAX_SIZE,
750 GTK_PARAM_READABLE));
752 g_object_class_install_property (gobject_class,
753 PROP_SELECTION_BOUND,
754 g_param_spec_int ("selection-bound",
755 P_("Selection Bound"),
756 P_("The position of the opposite end of the selection from the cursor in chars"),
758 GTK_ENTRY_BUFFER_MAX_SIZE,
760 GTK_PARAM_READABLE));
762 g_object_class_install_property (gobject_class,
764 g_param_spec_boolean ("editable",
766 P_("Whether the entry contents can be edited"),
768 GTK_PARAM_READWRITE));
770 g_object_class_install_property (gobject_class,
772 g_param_spec_int ("max-length",
773 P_("Maximum length"),
774 P_("Maximum number of characters for this entry. Zero if no maximum"),
776 GTK_ENTRY_BUFFER_MAX_SIZE,
778 GTK_PARAM_READWRITE));
779 g_object_class_install_property (gobject_class,
781 g_param_spec_boolean ("visibility",
783 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
785 GTK_PARAM_READWRITE));
787 g_object_class_install_property (gobject_class,
789 g_param_spec_boolean ("has-frame",
791 P_("FALSE removes outside bevel from entry"),
793 GTK_PARAM_READWRITE));
796 * GtkEntry:inner-border:
798 * Sets the text area's border between the text and the frame.
800 * Deprecated: 3.4: Use the standard border and padding CSS properties
801 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
802 * of this style property is ignored.
804 g_object_class_install_property (gobject_class,
806 g_param_spec_boxed ("inner-border",
808 P_("Border between text and frame. Overrides the inner-border style property"),
810 GTK_PARAM_READWRITE |
811 G_PARAM_DEPRECATED));
813 g_object_class_install_property (gobject_class,
815 g_param_spec_unichar ("invisible-char",
816 P_("Invisible character"),
817 P_("The character to use when masking entry contents (in \"password mode\")"),
819 GTK_PARAM_READWRITE));
821 g_object_class_install_property (gobject_class,
822 PROP_ACTIVATES_DEFAULT,
823 g_param_spec_boolean ("activates-default",
824 P_("Activates default"),
825 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
827 GTK_PARAM_READWRITE));
828 g_object_class_install_property (gobject_class,
830 g_param_spec_int ("width-chars",
831 P_("Width in chars"),
832 P_("Number of characters to leave space for in the entry"),
836 GTK_PARAM_READWRITE));
838 g_object_class_install_property (gobject_class,
840 g_param_spec_int ("scroll-offset",
842 P_("Number of pixels of the entry scrolled off the screen to the left"),
846 GTK_PARAM_READABLE));
848 g_object_class_install_property (gobject_class,
850 g_param_spec_string ("text",
852 P_("The contents of the entry"),
854 GTK_PARAM_READWRITE));
859 * The horizontal alignment, from 0 (left) to 1 (right).
860 * Reversed for RTL layouts.
864 g_object_class_install_property (gobject_class,
866 g_param_spec_float ("xalign",
868 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
872 GTK_PARAM_READWRITE));
875 * GtkEntry:truncate-multiline:
877 * When %TRUE, pasted multi-line text is truncated to the first line.
881 g_object_class_install_property (gobject_class,
882 PROP_TRUNCATE_MULTILINE,
883 g_param_spec_boolean ("truncate-multiline",
884 P_("Truncate multiline"),
885 P_("Whether to truncate multiline pastes to one line."),
887 GTK_PARAM_READWRITE));
890 * GtkEntry:shadow-type:
892 * Which kind of shadow to draw around the entry when
893 * #GtkEntry:has-frame is set to %TRUE.
897 g_object_class_install_property (gobject_class,
899 g_param_spec_enum ("shadow-type",
901 P_("Which kind of shadow to draw around the entry when has-frame is set"),
902 GTK_TYPE_SHADOW_TYPE,
904 GTK_PARAM_READWRITE));
907 * GtkEntry:overwrite-mode:
909 * If text is overwritten when typing in the #GtkEntry.
913 g_object_class_install_property (gobject_class,
915 g_param_spec_boolean ("overwrite-mode",
916 P_("Overwrite mode"),
917 P_("Whether new text overwrites existing text"),
919 GTK_PARAM_READWRITE));
922 * GtkEntry:text-length:
924 * The length of the text in the #GtkEntry.
928 g_object_class_install_property (gobject_class,
930 g_param_spec_uint ("text-length",
932 P_("Length of the text currently in the entry"),
936 GTK_PARAM_READABLE));
938 * GtkEntry:invisible-char-set:
940 * Whether the invisible char has been set for the #GtkEntry.
944 g_object_class_install_property (gobject_class,
945 PROP_INVISIBLE_CHAR_SET,
946 g_param_spec_boolean ("invisible-char-set",
947 P_("Invisible character set"),
948 P_("Whether the invisible character has been set"),
950 GTK_PARAM_READWRITE));
953 * GtkEntry:caps-lock-warning:
955 * Whether password entries will show a warning when Caps Lock is on.
957 * Note that the warning is shown using a secondary icon, and thus
958 * does not work if you are using the secondary icon position for some
963 g_object_class_install_property (gobject_class,
964 PROP_CAPS_LOCK_WARNING,
965 g_param_spec_boolean ("caps-lock-warning",
966 P_("Caps Lock warning"),
967 P_("Whether password entries will show a warning when Caps Lock is on"),
969 GTK_PARAM_READWRITE));
972 * GtkEntry:progress-fraction:
974 * The current fraction of the task that's been completed.
978 g_object_class_install_property (gobject_class,
979 PROP_PROGRESS_FRACTION,
980 g_param_spec_double ("progress-fraction",
981 P_("Progress Fraction"),
982 P_("The current fraction of the task that's been completed"),
986 GTK_PARAM_READWRITE));
989 * GtkEntry:progress-pulse-step:
991 * The fraction of total entry width to move the progress
992 * bouncing block for each call to gtk_entry_progress_pulse().
996 g_object_class_install_property (gobject_class,
997 PROP_PROGRESS_PULSE_STEP,
998 g_param_spec_double ("progress-pulse-step",
999 P_("Progress Pulse Step"),
1000 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
1004 GTK_PARAM_READWRITE));
1007 * GtkEntry:placeholder-text:
1009 * The text that will be displayed in the #GtkEntry when it is empty
1014 g_object_class_install_property (gobject_class,
1015 PROP_PLACEHOLDER_TEXT,
1016 g_param_spec_string ("placeholder-text",
1017 P_("Placeholder text"),
1018 P_("Show text in the entry when it's empty and unfocused"),
1020 GTK_PARAM_READWRITE));
1023 * GtkEntry:primary-icon-pixbuf:
1025 * A pixbuf to use as the primary icon for the entry.
1029 g_object_class_install_property (gobject_class,
1030 PROP_PIXBUF_PRIMARY,
1031 g_param_spec_object ("primary-icon-pixbuf",
1032 P_("Primary pixbuf"),
1033 P_("Primary pixbuf for the entry"),
1035 GTK_PARAM_READWRITE));
1038 * GtkEntry:secondary-icon-pixbuf:
1040 * An pixbuf to use as the secondary icon for the entry.
1044 g_object_class_install_property (gobject_class,
1045 PROP_PIXBUF_SECONDARY,
1046 g_param_spec_object ("secondary-icon-pixbuf",
1047 P_("Secondary pixbuf"),
1048 P_("Secondary pixbuf for the entry"),
1050 GTK_PARAM_READWRITE));
1053 * GtkEntry:primary-icon-stock:
1055 * The stock id to use for the primary icon for the entry.
1059 g_object_class_install_property (gobject_class,
1061 g_param_spec_string ("primary-icon-stock",
1062 P_("Primary stock ID"),
1063 P_("Stock ID for primary icon"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:secondary-icon-stock:
1070 * The stock id to use for the secondary icon for the entry.
1074 g_object_class_install_property (gobject_class,
1075 PROP_STOCK_SECONDARY,
1076 g_param_spec_string ("secondary-icon-stock",
1077 P_("Secondary stock ID"),
1078 P_("Stock ID for secondary icon"),
1080 GTK_PARAM_READWRITE));
1083 * GtkEntry:primary-icon-name:
1085 * The icon name to use for the primary icon for the entry.
1089 g_object_class_install_property (gobject_class,
1090 PROP_ICON_NAME_PRIMARY,
1091 g_param_spec_string ("primary-icon-name",
1092 P_("Primary icon name"),
1093 P_("Icon name for primary icon"),
1095 GTK_PARAM_READWRITE));
1098 * GtkEntry:secondary-icon-name:
1100 * The icon name to use for the secondary icon for the entry.
1104 g_object_class_install_property (gobject_class,
1105 PROP_ICON_NAME_SECONDARY,
1106 g_param_spec_string ("secondary-icon-name",
1107 P_("Secondary icon name"),
1108 P_("Icon name for secondary icon"),
1110 GTK_PARAM_READWRITE));
1113 * GtkEntry:primary-icon-gicon:
1115 * The #GIcon to use for the primary icon for the entry.
1119 g_object_class_install_property (gobject_class,
1121 g_param_spec_object ("primary-icon-gicon",
1122 P_("Primary GIcon"),
1123 P_("GIcon for primary icon"),
1125 GTK_PARAM_READWRITE));
1128 * GtkEntry:secondary-icon-gicon:
1130 * The #GIcon to use for the secondary icon for the entry.
1134 g_object_class_install_property (gobject_class,
1135 PROP_GICON_SECONDARY,
1136 g_param_spec_object ("secondary-icon-gicon",
1137 P_("Secondary GIcon"),
1138 P_("GIcon for secondary icon"),
1140 GTK_PARAM_READWRITE));
1143 * GtkEntry:primary-icon-storage-type:
1145 * The representation which is used for the primary icon of the entry.
1149 g_object_class_install_property (gobject_class,
1150 PROP_STORAGE_TYPE_PRIMARY,
1151 g_param_spec_enum ("primary-icon-storage-type",
1152 P_("Primary storage type"),
1153 P_("The representation being used for primary icon"),
1154 GTK_TYPE_IMAGE_TYPE,
1156 GTK_PARAM_READABLE));
1159 * GtkEntry:secondary-icon-storage-type:
1161 * The representation which is used for the secondary icon of the entry.
1165 g_object_class_install_property (gobject_class,
1166 PROP_STORAGE_TYPE_SECONDARY,
1167 g_param_spec_enum ("secondary-icon-storage-type",
1168 P_("Secondary storage type"),
1169 P_("The representation being used for secondary icon"),
1170 GTK_TYPE_IMAGE_TYPE,
1172 GTK_PARAM_READABLE));
1175 * GtkEntry:primary-icon-activatable:
1177 * Whether the primary icon is activatable.
1179 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1180 * signals only on sensitive, activatable icons.
1182 * Sensitive, but non-activatable icons can be used for purely
1183 * informational purposes.
1187 g_object_class_install_property (gobject_class,
1188 PROP_ACTIVATABLE_PRIMARY,
1189 g_param_spec_boolean ("primary-icon-activatable",
1190 P_("Primary icon activatable"),
1191 P_("Whether the primary icon is activatable"),
1193 GTK_PARAM_READWRITE));
1196 * GtkEntry:secondary-icon-activatable:
1198 * Whether the secondary icon is activatable.
1200 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1201 * signals only on sensitive, activatable icons.
1203 * Sensitive, but non-activatable icons can be used for purely
1204 * informational purposes.
1208 g_object_class_install_property (gobject_class,
1209 PROP_ACTIVATABLE_SECONDARY,
1210 g_param_spec_boolean ("secondary-icon-activatable",
1211 P_("Secondary icon activatable"),
1212 P_("Whether the secondary icon is activatable"),
1214 GTK_PARAM_READWRITE));
1218 * GtkEntry:primary-icon-sensitive:
1220 * Whether the primary icon is sensitive.
1222 * An insensitive icon appears grayed out. GTK+ does not emit the
1223 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1224 * does not allow DND from insensitive icons.
1226 * An icon should be set insensitive if the action that would trigger
1227 * when clicked is currently not available.
1231 g_object_class_install_property (gobject_class,
1232 PROP_SENSITIVE_PRIMARY,
1233 g_param_spec_boolean ("primary-icon-sensitive",
1234 P_("Primary icon sensitive"),
1235 P_("Whether the primary icon is sensitive"),
1237 GTK_PARAM_READWRITE));
1240 * GtkEntry:secondary-icon-sensitive:
1242 * Whether the secondary icon is sensitive.
1244 * An insensitive icon appears grayed out. GTK+ does not emit the
1245 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1246 * does not allow DND from insensitive icons.
1248 * An icon should be set insensitive if the action that would trigger
1249 * when clicked is currently not available.
1253 g_object_class_install_property (gobject_class,
1254 PROP_SENSITIVE_SECONDARY,
1255 g_param_spec_boolean ("secondary-icon-sensitive",
1256 P_("Secondary icon sensitive"),
1257 P_("Whether the secondary icon is sensitive"),
1259 GTK_PARAM_READWRITE));
1262 * GtkEntry:primary-icon-tooltip-text:
1264 * The contents of the tooltip on the primary icon.
1266 * Also see gtk_entry_set_icon_tooltip_text().
1270 g_object_class_install_property (gobject_class,
1271 PROP_TOOLTIP_TEXT_PRIMARY,
1272 g_param_spec_string ("primary-icon-tooltip-text",
1273 P_("Primary icon tooltip text"),
1274 P_("The contents of the tooltip on the primary icon"),
1276 GTK_PARAM_READWRITE));
1279 * GtkEntry:secondary-icon-tooltip-text:
1281 * The contents of the tooltip on the secondary icon.
1283 * Also see gtk_entry_set_icon_tooltip_text().
1287 g_object_class_install_property (gobject_class,
1288 PROP_TOOLTIP_TEXT_SECONDARY,
1289 g_param_spec_string ("secondary-icon-tooltip-text",
1290 P_("Secondary icon tooltip text"),
1291 P_("The contents of the tooltip on the secondary icon"),
1293 GTK_PARAM_READWRITE));
1296 * GtkEntry:primary-icon-tooltip-markup:
1298 * The contents of the tooltip on the primary icon, which is marked up
1299 * with the <link linkend="PangoMarkupFormat">Pango text markup
1302 * Also see gtk_entry_set_icon_tooltip_markup().
1306 g_object_class_install_property (gobject_class,
1307 PROP_TOOLTIP_MARKUP_PRIMARY,
1308 g_param_spec_string ("primary-icon-tooltip-markup",
1309 P_("Primary icon tooltip markup"),
1310 P_("The contents of the tooltip on the primary icon"),
1312 GTK_PARAM_READWRITE));
1315 * GtkEntry:secondary-icon-tooltip-markup:
1317 * The contents of the tooltip on the secondary icon, which is marked up
1318 * with the <link linkend="PangoMarkupFormat">Pango text markup
1321 * Also see gtk_entry_set_icon_tooltip_markup().
1325 g_object_class_install_property (gobject_class,
1326 PROP_TOOLTIP_MARKUP_SECONDARY,
1327 g_param_spec_string ("secondary-icon-tooltip-markup",
1328 P_("Secondary icon tooltip markup"),
1329 P_("The contents of the tooltip on the secondary icon"),
1331 GTK_PARAM_READWRITE));
1334 * GtkEntry:im-module:
1336 * Which IM (input method) module should be used for this entry.
1337 * See #GtkIMContext.
1339 * Setting this to a non-%NULL value overrides the
1340 * system-wide IM module setting. See the GtkSettings
1341 * #GtkSettings:gtk-im-module property.
1345 g_object_class_install_property (gobject_class,
1347 g_param_spec_string ("im-module",
1349 P_("Which IM module should be used"),
1351 GTK_PARAM_READWRITE));
1354 * GtkEntry:completion:
1356 * The auxiliary completion object to use with the entry.
1360 g_object_class_install_property (gobject_class,
1362 g_param_spec_object ("completion",
1364 P_("The auxiliary completion object"),
1365 GTK_TYPE_ENTRY_COMPLETION,
1366 GTK_PARAM_READWRITE));
1369 * GtkEntry:input-purpose:
1371 * The purpose of this text field.
1373 * This property can be used by on-screen keyboards and other input
1374 * methods to adjust their behaviour.
1376 * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
1377 * %GTK_INPUT_PURPOSE_PIN is independent from setting
1378 * #GtkEntry:visibility.
1382 g_object_class_install_property (gobject_class,
1384 g_param_spec_enum ("input-purpose",
1386 P_("Purpose of the text field"),
1387 GTK_TYPE_INPUT_PURPOSE,
1388 GTK_INPUT_PURPOSE_FREE_FORM,
1389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1392 * GtkEntry:input-hints:
1394 * Additional hints (beyond #GtkEntry:input-purpose) that
1395 * allow input methods to fine-tune their behaviour.
1399 g_object_class_install_property (gobject_class,
1401 g_param_spec_flags ("input-hints",
1403 P_("Hints for the text field behaviour"),
1404 GTK_TYPE_INPUT_HINTS,
1405 GTK_INPUT_HINT_NONE,
1406 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1409 * GtkEntry:attributes:
1411 * A list of Pango attributes to apply to the text of the entry.
1413 * This is mainly useful to change the size or weight of the text.
1417 g_object_class_install_property (gobject_class,
1419 g_param_spec_boxed ("attributes",
1421 P_("A list of style attributes to apply to the text of the label"),
1422 PANGO_TYPE_ATTR_LIST,
1423 GTK_PARAM_READWRITE));
1426 * GtkEntry:icon-prelight:
1428 * The prelight style property determines whether activatable
1429 * icons prelight on mouseover.
1433 gtk_widget_class_install_style_property (widget_class,
1434 g_param_spec_boolean ("icon-prelight",
1435 P_("Icon Prelight"),
1436 P_("Whether activatable icons should prelight when hovered"),
1438 GTK_PARAM_READABLE));
1441 * GtkEntry:progress-border:
1443 * The border around the progress bar in the entry.
1447 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1448 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1449 * property is ignored.
1451 gtk_widget_class_install_style_property (widget_class,
1452 g_param_spec_boxed ("progress-border",
1453 P_("Progress Border"),
1454 P_("Border around the progress bar"),
1456 GTK_PARAM_READABLE |
1457 G_PARAM_DEPRECATED));
1460 * GtkEntry:invisible-char:
1462 * The invisible character is used when masking entry contents (in
1463 * \"password mode\")"). When it is not explicitly set with the
1464 * #GtkEntry:invisible-char property, GTK+ determines the character
1465 * to use from a list of possible candidates, depending on availability
1466 * in the current font.
1468 * This style property allows the theme to prepend a character
1469 * to the list of candidates.
1473 gtk_widget_class_install_style_property (widget_class,
1474 g_param_spec_unichar ("invisible-char",
1475 P_("Invisible character"),
1476 P_("The character to use when masking entry contents (in \"password mode\")"),
1478 GTK_PARAM_READABLE));
1481 * GtkEntry::populate-popup:
1482 * @entry: The entry on which the signal is emitted
1483 * @menu: the menu that is being populated
1485 * The ::populate-popup signal gets emitted before showing the
1486 * context menu of the entry.
1488 * If you need to add items to the context menu, connect
1489 * to this signal and append your menuitems to the @menu.
1491 signals[POPULATE_POPUP] =
1492 g_signal_new (I_("populate-popup"),
1493 G_OBJECT_CLASS_TYPE (gobject_class),
1495 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1497 _gtk_marshal_VOID__OBJECT,
1501 /* Action signals */
1504 * GtkEntry::activate:
1505 * @entry: The entry on which the signal is emitted
1507 * The ::activate signal is emitted when the user hits
1510 * While this signal is used as a
1511 * <link linkend="keybinding-signals">keybinding signal</link>,
1512 * it is also commonly used by applications to intercept
1513 * activation of entries.
1515 * The default bindings for this signal are all forms of the Enter key.
1518 g_signal_new (I_("activate"),
1519 G_OBJECT_CLASS_TYPE (gobject_class),
1520 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1521 G_STRUCT_OFFSET (GtkEntryClass, activate),
1523 _gtk_marshal_VOID__VOID,
1525 widget_class->activate_signal = signals[ACTIVATE];
1528 * GtkEntry::move-cursor:
1529 * @entry: the object which received the signal
1530 * @step: the granularity of the move, as a #GtkMovementStep
1531 * @count: the number of @step units to move
1532 * @extend_selection: %TRUE if the move should extend the selection
1534 * The ::move-cursor signal is a
1535 * <link linkend="keybinding-signals">keybinding signal</link>
1536 * which gets emitted when the user initiates a cursor movement.
1537 * If the cursor is not visible in @entry, this signal causes
1538 * the viewport to be moved instead.
1540 * Applications should not connect to it, but may emit it with
1541 * g_signal_emit_by_name() if they need to control the cursor
1544 * The default bindings for this signal come in two variants,
1545 * the variant with the Shift modifier extends the selection,
1546 * the variant without the Shift modifer does not.
1547 * There are too many key combinations to list them all here.
1549 * <listitem>Arrow keys move by individual characters/lines</listitem>
1550 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1551 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1554 signals[MOVE_CURSOR] =
1555 g_signal_new (I_("move-cursor"),
1556 G_OBJECT_CLASS_TYPE (gobject_class),
1557 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1558 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1560 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1562 GTK_TYPE_MOVEMENT_STEP,
1567 * GtkEntry::insert-at-cursor:
1568 * @entry: the object which received the signal
1569 * @string: the string to insert
1571 * The ::insert-at-cursor signal is a
1572 * <link linkend="keybinding-signals">keybinding signal</link>
1573 * which gets emitted when the user initiates the insertion of a
1574 * fixed string at the cursor.
1576 * This signal has no default bindings.
1578 signals[INSERT_AT_CURSOR] =
1579 g_signal_new (I_("insert-at-cursor"),
1580 G_OBJECT_CLASS_TYPE (gobject_class),
1581 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1582 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1584 _gtk_marshal_VOID__STRING,
1589 * GtkEntry::delete-from-cursor:
1590 * @entry: the object which received the signal
1591 * @type: the granularity of the deletion, as a #GtkDeleteType
1592 * @count: the number of @type units to delete
1594 * The ::delete-from-cursor signal is a
1595 * <link linkend="keybinding-signals">keybinding signal</link>
1596 * which gets emitted when the user initiates a text deletion.
1598 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1599 * if there is one, otherwise it deletes the requested number
1602 * The default bindings for this signal are
1603 * Delete for deleting a character and Ctrl-Delete for
1606 signals[DELETE_FROM_CURSOR] =
1607 g_signal_new (I_("delete-from-cursor"),
1608 G_OBJECT_CLASS_TYPE (gobject_class),
1609 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1610 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1612 _gtk_marshal_VOID__ENUM_INT,
1614 GTK_TYPE_DELETE_TYPE,
1618 * GtkEntry::backspace:
1619 * @entry: the object which received the signal
1621 * The ::backspace signal is a
1622 * <link linkend="keybinding-signals">keybinding signal</link>
1623 * which gets emitted when the user asks for it.
1625 * The default bindings for this signal are
1626 * Backspace and Shift-Backspace.
1628 signals[BACKSPACE] =
1629 g_signal_new (I_("backspace"),
1630 G_OBJECT_CLASS_TYPE (gobject_class),
1631 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1632 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1634 _gtk_marshal_VOID__VOID,
1638 * GtkEntry::cut-clipboard:
1639 * @entry: the object which received the signal
1641 * The ::cut-clipboard signal is a
1642 * <link linkend="keybinding-signals">keybinding signal</link>
1643 * which gets emitted to cut the selection to the clipboard.
1645 * The default bindings for this signal are
1646 * Ctrl-x and Shift-Delete.
1648 signals[CUT_CLIPBOARD] =
1649 g_signal_new (I_("cut-clipboard"),
1650 G_OBJECT_CLASS_TYPE (gobject_class),
1651 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1652 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1654 _gtk_marshal_VOID__VOID,
1658 * GtkEntry::copy-clipboard:
1659 * @entry: the object which received the signal
1661 * The ::copy-clipboard signal is a
1662 * <link linkend="keybinding-signals">keybinding signal</link>
1663 * which gets emitted to copy the selection to the clipboard.
1665 * The default bindings for this signal are
1666 * Ctrl-c and Ctrl-Insert.
1668 signals[COPY_CLIPBOARD] =
1669 g_signal_new (I_("copy-clipboard"),
1670 G_OBJECT_CLASS_TYPE (gobject_class),
1671 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1672 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1674 _gtk_marshal_VOID__VOID,
1678 * GtkEntry::paste-clipboard:
1679 * @entry: the object which received the signal
1681 * The ::paste-clipboard signal is a
1682 * <link linkend="keybinding-signals">keybinding signal</link>
1683 * which gets emitted to paste the contents of the clipboard
1684 * into the text view.
1686 * The default bindings for this signal are
1687 * Ctrl-v and Shift-Insert.
1689 signals[PASTE_CLIPBOARD] =
1690 g_signal_new (I_("paste-clipboard"),
1691 G_OBJECT_CLASS_TYPE (gobject_class),
1692 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1693 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1695 _gtk_marshal_VOID__VOID,
1699 * GtkEntry::toggle-overwrite:
1700 * @entry: the object which received the signal
1702 * The ::toggle-overwrite signal is a
1703 * <link linkend="keybinding-signals">keybinding signal</link>
1704 * which gets emitted to toggle the overwrite mode of the entry.
1706 * The default bindings for this signal is Insert.
1708 signals[TOGGLE_OVERWRITE] =
1709 g_signal_new (I_("toggle-overwrite"),
1710 G_OBJECT_CLASS_TYPE (gobject_class),
1711 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1712 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1714 _gtk_marshal_VOID__VOID,
1718 * GtkEntry::icon-press:
1719 * @entry: The entry on which the signal is emitted
1720 * @icon_pos: The position of the clicked icon
1721 * @event: (type Gdk.EventButton): the button press event
1723 * The ::icon-press signal is emitted when an activatable icon
1728 signals[ICON_PRESS] =
1729 g_signal_new (I_("icon-press"),
1730 G_TYPE_FROM_CLASS (gobject_class),
1734 _gtk_marshal_VOID__ENUM_BOXED,
1736 GTK_TYPE_ENTRY_ICON_POSITION,
1737 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1740 * GtkEntry::icon-release:
1741 * @entry: The entry on which the signal is emitted
1742 * @icon_pos: The position of the clicked icon
1743 * @event: (type Gdk.EventButton): the button release event
1745 * The ::icon-release signal is emitted on the button release from a
1746 * mouse click over an activatable icon.
1750 signals[ICON_RELEASE] =
1751 g_signal_new (I_("icon-release"),
1752 G_TYPE_FROM_CLASS (gobject_class),
1756 _gtk_marshal_VOID__ENUM_BOXED,
1758 GTK_TYPE_ENTRY_ICON_POSITION,
1759 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1762 * GtkEntry::preedit-changed:
1763 * @entry: the object which received the signal
1764 * @preedit: the current preedit string
1766 * If an input method is used, the typed text will not immediately
1767 * be committed to the buffer. So if you are interested in the text,
1768 * connect to this signal.
1772 signals[PREEDIT_CHANGED] =
1773 g_signal_new_class_handler (I_("preedit-changed"),
1774 G_OBJECT_CLASS_TYPE (gobject_class),
1775 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1778 _gtk_marshal_VOID__STRING,
1787 binding_set = gtk_binding_set_by_class (class);
1789 /* Moving the insertion point */
1790 add_move_binding (binding_set, GDK_KEY_Right, 0,
1791 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1793 add_move_binding (binding_set, GDK_KEY_Left, 0,
1794 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1796 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1797 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1799 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1800 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1802 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1803 GTK_MOVEMENT_WORDS, 1);
1805 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1806 GTK_MOVEMENT_WORDS, -1);
1808 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1809 GTK_MOVEMENT_WORDS, 1);
1811 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1812 GTK_MOVEMENT_WORDS, -1);
1814 add_move_binding (binding_set, GDK_KEY_Home, 0,
1815 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1817 add_move_binding (binding_set, GDK_KEY_End, 0,
1818 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1820 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1821 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1823 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1824 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1826 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1827 GTK_MOVEMENT_BUFFER_ENDS, -1);
1829 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1830 GTK_MOVEMENT_BUFFER_ENDS, 1);
1832 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1833 GTK_MOVEMENT_BUFFER_ENDS, -1);
1835 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1836 GTK_MOVEMENT_BUFFER_ENDS, 1);
1840 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1842 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1844 G_TYPE_BOOLEAN, FALSE);
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1847 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1849 G_TYPE_BOOLEAN, TRUE);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1853 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1855 G_TYPE_BOOLEAN, FALSE);
1856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1858 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1860 G_TYPE_BOOLEAN, TRUE);
1863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1865 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1867 G_TYPE_BOOLEAN, FALSE);
1868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1870 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1872 G_TYPE_BOOLEAN, FALSE);
1876 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1878 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1880 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1884 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1885 "delete-from-cursor", 2,
1886 G_TYPE_ENUM, GTK_DELETE_CHARS,
1889 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1890 "delete-from-cursor", 2,
1891 G_TYPE_ENUM, GTK_DELETE_CHARS,
1894 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1897 /* Make this do the same as Backspace, to help with mis-typing */
1898 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1901 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1902 "delete-from-cursor", 2,
1903 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1906 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1907 "delete-from-cursor", 2,
1908 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1911 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1912 "delete-from-cursor", 2,
1913 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1916 /* Cut/copy/paste */
1918 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1919 "cut-clipboard", 0);
1920 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1921 "copy-clipboard", 0);
1922 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1923 "paste-clipboard", 0);
1925 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1926 "cut-clipboard", 0);
1927 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1928 "copy-clipboard", 0);
1929 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1930 "paste-clipboard", 0);
1933 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1934 "toggle-overwrite", 0);
1935 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1936 "toggle-overwrite", 0);
1939 * GtkEntry:inner-border:
1941 * Sets the text area's border between the text and the frame.
1945 * Deprecated: 3.4: Use the standard border and padding CSS properties
1946 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1947 * of this style property is ignored.
1949 gtk_widget_class_install_style_property (widget_class,
1950 g_param_spec_boxed ("inner-border",
1952 P_("Border between text and frame."),
1954 GTK_PARAM_READABLE |
1955 G_PARAM_DEPRECATED));
1957 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1958 test_touchscreen = g_getenv ("GTK_TEST_TOUCHSCREEN") != NULL;
1960 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1964 gtk_entry_editable_init (GtkEditableInterface *iface)
1966 iface->do_insert_text = gtk_entry_insert_text;
1967 iface->do_delete_text = gtk_entry_delete_text;
1968 iface->insert_text = gtk_entry_real_insert_text;
1969 iface->delete_text = gtk_entry_real_delete_text;
1970 iface->get_chars = gtk_entry_get_chars;
1971 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1972 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1973 iface->set_position = gtk_entry_real_set_position;
1974 iface->get_position = gtk_entry_get_position;
1978 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1980 iface->start_editing = gtk_entry_start_editing;
1983 /* for deprecated properties */
1985 gtk_entry_do_set_inner_border (GtkEntry *entry,
1986 const GtkBorder *border)
1989 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1990 gtk_border_copy (border),
1991 (GDestroyNotify) gtk_border_free);
1993 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1995 g_object_notify (G_OBJECT (entry), "inner-border");
1998 static const GtkBorder *
1999 gtk_entry_do_get_inner_border (GtkEntry *entry)
2001 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
2005 gtk_entry_set_property (GObject *object,
2007 const GValue *value,
2010 GtkEntry *entry = GTK_ENTRY (object);
2011 GtkEntryPrivate *priv = entry->priv;
2016 gtk_entry_set_buffer (entry, g_value_get_object (value));
2021 gboolean new_value = g_value_get_boolean (value);
2023 if (new_value != priv->editable)
2025 GtkWidget *widget = GTK_WIDGET (entry);
2029 gtk_entry_reset_im_context (entry);
2030 if (gtk_widget_has_focus (widget))
2031 gtk_im_context_focus_out (priv->im_context);
2033 priv->preedit_length = 0;
2034 priv->preedit_cursor = 0;
2037 priv->editable = new_value;
2039 if (new_value && gtk_widget_has_focus (widget))
2040 gtk_im_context_focus_in (priv->im_context);
2042 gtk_widget_queue_draw (widget);
2047 case PROP_MAX_LENGTH:
2048 gtk_entry_set_max_length (entry, g_value_get_int (value));
2051 case PROP_VISIBILITY:
2052 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
2055 case PROP_HAS_FRAME:
2056 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
2059 case PROP_INNER_BORDER:
2060 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
2063 case PROP_INVISIBLE_CHAR:
2064 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2067 case PROP_ACTIVATES_DEFAULT:
2068 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2071 case PROP_WIDTH_CHARS:
2072 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2076 gtk_entry_set_text (entry, g_value_get_string (value));
2080 gtk_entry_set_alignment (entry, g_value_get_float (value));
2083 case PROP_TRUNCATE_MULTILINE:
2084 priv->truncate_multiline = g_value_get_boolean (value);
2087 case PROP_SHADOW_TYPE:
2088 priv->shadow_type = g_value_get_enum (value);
2091 case PROP_OVERWRITE_MODE:
2092 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2095 case PROP_INVISIBLE_CHAR_SET:
2096 if (g_value_get_boolean (value))
2097 priv->invisible_char_set = TRUE;
2099 gtk_entry_unset_invisible_char (entry);
2102 case PROP_CAPS_LOCK_WARNING:
2103 priv->caps_lock_warning = g_value_get_boolean (value);
2106 case PROP_PROGRESS_FRACTION:
2107 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2110 case PROP_PROGRESS_PULSE_STEP:
2111 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2114 case PROP_PLACEHOLDER_TEXT:
2115 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2118 case PROP_PIXBUF_PRIMARY:
2119 gtk_entry_set_icon_from_pixbuf (entry,
2120 GTK_ENTRY_ICON_PRIMARY,
2121 g_value_get_object (value));
2124 case PROP_PIXBUF_SECONDARY:
2125 gtk_entry_set_icon_from_pixbuf (entry,
2126 GTK_ENTRY_ICON_SECONDARY,
2127 g_value_get_object (value));
2130 case PROP_STOCK_PRIMARY:
2131 gtk_entry_set_icon_from_stock (entry,
2132 GTK_ENTRY_ICON_PRIMARY,
2133 g_value_get_string (value));
2136 case PROP_STOCK_SECONDARY:
2137 gtk_entry_set_icon_from_stock (entry,
2138 GTK_ENTRY_ICON_SECONDARY,
2139 g_value_get_string (value));
2142 case PROP_ICON_NAME_PRIMARY:
2143 gtk_entry_set_icon_from_icon_name (entry,
2144 GTK_ENTRY_ICON_PRIMARY,
2145 g_value_get_string (value));
2148 case PROP_ICON_NAME_SECONDARY:
2149 gtk_entry_set_icon_from_icon_name (entry,
2150 GTK_ENTRY_ICON_SECONDARY,
2151 g_value_get_string (value));
2154 case PROP_GICON_PRIMARY:
2155 gtk_entry_set_icon_from_gicon (entry,
2156 GTK_ENTRY_ICON_PRIMARY,
2157 g_value_get_object (value));
2160 case PROP_GICON_SECONDARY:
2161 gtk_entry_set_icon_from_gicon (entry,
2162 GTK_ENTRY_ICON_SECONDARY,
2163 g_value_get_object (value));
2166 case PROP_ACTIVATABLE_PRIMARY:
2167 gtk_entry_set_icon_activatable (entry,
2168 GTK_ENTRY_ICON_PRIMARY,
2169 g_value_get_boolean (value));
2172 case PROP_ACTIVATABLE_SECONDARY:
2173 gtk_entry_set_icon_activatable (entry,
2174 GTK_ENTRY_ICON_SECONDARY,
2175 g_value_get_boolean (value));
2178 case PROP_SENSITIVE_PRIMARY:
2179 gtk_entry_set_icon_sensitive (entry,
2180 GTK_ENTRY_ICON_PRIMARY,
2181 g_value_get_boolean (value));
2184 case PROP_SENSITIVE_SECONDARY:
2185 gtk_entry_set_icon_sensitive (entry,
2186 GTK_ENTRY_ICON_SECONDARY,
2187 g_value_get_boolean (value));
2190 case PROP_TOOLTIP_TEXT_PRIMARY:
2191 gtk_entry_set_icon_tooltip_text (entry,
2192 GTK_ENTRY_ICON_PRIMARY,
2193 g_value_get_string (value));
2196 case PROP_TOOLTIP_TEXT_SECONDARY:
2197 gtk_entry_set_icon_tooltip_text (entry,
2198 GTK_ENTRY_ICON_SECONDARY,
2199 g_value_get_string (value));
2202 case PROP_TOOLTIP_MARKUP_PRIMARY:
2203 gtk_entry_set_icon_tooltip_markup (entry,
2204 GTK_ENTRY_ICON_PRIMARY,
2205 g_value_get_string (value));
2208 case PROP_TOOLTIP_MARKUP_SECONDARY:
2209 gtk_entry_set_icon_tooltip_markup (entry,
2210 GTK_ENTRY_ICON_SECONDARY,
2211 g_value_get_string (value));
2214 case PROP_IM_MODULE:
2215 g_free (priv->im_module);
2216 priv->im_module = g_value_dup_string (value);
2217 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2218 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2221 case PROP_EDITING_CANCELED:
2222 priv->editing_canceled = g_value_get_boolean (value);
2225 case PROP_COMPLETION:
2226 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2229 case PROP_INPUT_PURPOSE:
2230 gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
2233 case PROP_INPUT_HINTS:
2234 gtk_entry_set_input_hints (entry, g_value_get_flags (value));
2237 case PROP_ATTRIBUTES:
2238 gtk_entry_set_attributes (entry, g_value_get_boxed (value));
2241 case PROP_SCROLL_OFFSET:
2242 case PROP_CURSOR_POSITION:
2244 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2250 gtk_entry_get_property (GObject *object,
2255 GtkEntry *entry = GTK_ENTRY (object);
2256 GtkEntryPrivate *priv = entry->priv;
2261 g_value_set_object (value, gtk_entry_get_buffer (entry));
2264 case PROP_CURSOR_POSITION:
2265 g_value_set_int (value, priv->current_pos);
2268 case PROP_SELECTION_BOUND:
2269 g_value_set_int (value, priv->selection_bound);
2273 g_value_set_boolean (value, priv->editable);
2276 case PROP_MAX_LENGTH:
2277 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2280 case PROP_VISIBILITY:
2281 g_value_set_boolean (value, priv->visible);
2284 case PROP_HAS_FRAME:
2285 g_value_set_boolean (value, priv->has_frame);
2288 case PROP_INNER_BORDER:
2289 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2292 case PROP_INVISIBLE_CHAR:
2293 g_value_set_uint (value, priv->invisible_char);
2296 case PROP_ACTIVATES_DEFAULT:
2297 g_value_set_boolean (value, priv->activates_default);
2300 case PROP_WIDTH_CHARS:
2301 g_value_set_int (value, priv->width_chars);
2304 case PROP_SCROLL_OFFSET:
2305 g_value_set_int (value, priv->scroll_offset);
2309 g_value_set_string (value, gtk_entry_get_text (entry));
2313 g_value_set_float (value, gtk_entry_get_alignment (entry));
2316 case PROP_TRUNCATE_MULTILINE:
2317 g_value_set_boolean (value, priv->truncate_multiline);
2320 case PROP_SHADOW_TYPE:
2321 g_value_set_enum (value, priv->shadow_type);
2324 case PROP_OVERWRITE_MODE:
2325 g_value_set_boolean (value, priv->overwrite_mode);
2328 case PROP_TEXT_LENGTH:
2329 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2332 case PROP_INVISIBLE_CHAR_SET:
2333 g_value_set_boolean (value, priv->invisible_char_set);
2336 case PROP_IM_MODULE:
2337 g_value_set_string (value, priv->im_module);
2340 case PROP_CAPS_LOCK_WARNING:
2341 g_value_set_boolean (value, priv->caps_lock_warning);
2344 case PROP_PROGRESS_FRACTION:
2345 g_value_set_double (value, priv->progress_fraction);
2348 case PROP_PROGRESS_PULSE_STEP:
2349 g_value_set_double (value, priv->progress_pulse_fraction);
2352 case PROP_PLACEHOLDER_TEXT:
2353 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2356 case PROP_PIXBUF_PRIMARY:
2357 g_value_set_object (value,
2358 gtk_entry_get_icon_pixbuf (entry,
2359 GTK_ENTRY_ICON_PRIMARY));
2362 case PROP_PIXBUF_SECONDARY:
2363 g_value_set_object (value,
2364 gtk_entry_get_icon_pixbuf (entry,
2365 GTK_ENTRY_ICON_SECONDARY));
2368 case PROP_STOCK_PRIMARY:
2369 g_value_set_string (value,
2370 gtk_entry_get_icon_stock (entry,
2371 GTK_ENTRY_ICON_PRIMARY));
2374 case PROP_STOCK_SECONDARY:
2375 g_value_set_string (value,
2376 gtk_entry_get_icon_stock (entry,
2377 GTK_ENTRY_ICON_SECONDARY));
2380 case PROP_ICON_NAME_PRIMARY:
2381 g_value_set_string (value,
2382 gtk_entry_get_icon_name (entry,
2383 GTK_ENTRY_ICON_PRIMARY));
2386 case PROP_ICON_NAME_SECONDARY:
2387 g_value_set_string (value,
2388 gtk_entry_get_icon_name (entry,
2389 GTK_ENTRY_ICON_SECONDARY));
2392 case PROP_GICON_PRIMARY:
2393 g_value_set_object (value,
2394 gtk_entry_get_icon_gicon (entry,
2395 GTK_ENTRY_ICON_PRIMARY));
2398 case PROP_GICON_SECONDARY:
2399 g_value_set_object (value,
2400 gtk_entry_get_icon_gicon (entry,
2401 GTK_ENTRY_ICON_SECONDARY));
2404 case PROP_STORAGE_TYPE_PRIMARY:
2405 g_value_set_enum (value,
2406 gtk_entry_get_icon_storage_type (entry,
2407 GTK_ENTRY_ICON_PRIMARY));
2410 case PROP_STORAGE_TYPE_SECONDARY:
2411 g_value_set_enum (value,
2412 gtk_entry_get_icon_storage_type (entry,
2413 GTK_ENTRY_ICON_SECONDARY));
2416 case PROP_ACTIVATABLE_PRIMARY:
2417 g_value_set_boolean (value,
2418 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2421 case PROP_ACTIVATABLE_SECONDARY:
2422 g_value_set_boolean (value,
2423 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2426 case PROP_SENSITIVE_PRIMARY:
2427 g_value_set_boolean (value,
2428 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2431 case PROP_SENSITIVE_SECONDARY:
2432 g_value_set_boolean (value,
2433 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2436 case PROP_TOOLTIP_TEXT_PRIMARY:
2437 g_value_take_string (value,
2438 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2441 case PROP_TOOLTIP_TEXT_SECONDARY:
2442 g_value_take_string (value,
2443 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2446 case PROP_TOOLTIP_MARKUP_PRIMARY:
2447 g_value_take_string (value,
2448 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2451 case PROP_TOOLTIP_MARKUP_SECONDARY:
2452 g_value_take_string (value,
2453 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2456 case PROP_EDITING_CANCELED:
2457 g_value_set_boolean (value,
2458 priv->editing_canceled);
2461 case PROP_COMPLETION:
2462 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2465 case PROP_INPUT_PURPOSE:
2466 g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
2469 case PROP_INPUT_HINTS:
2470 g_value_set_flags (value, gtk_entry_get_input_hints (entry));
2473 case PROP_ATTRIBUTES:
2474 g_value_set_boxed (value, priv->attrs);
2478 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2484 find_invisible_char (GtkWidget *widget)
2486 PangoLayout *layout;
2487 PangoAttrList *attr_list;
2489 gunichar invisible_chars [] = {
2491 0x25cf, /* BLACK CIRCLE */
2492 0x2022, /* BULLET */
2493 0x2731, /* HEAVY ASTERISK */
2494 0x273a /* SIXTEEN POINTED ASTERISK */
2497 gtk_widget_style_get (widget,
2498 "invisible-char", &invisible_chars[0],
2501 layout = gtk_widget_create_pango_layout (widget, NULL);
2503 attr_list = pango_attr_list_new ();
2504 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2506 pango_layout_set_attributes (layout, attr_list);
2507 pango_attr_list_unref (attr_list);
2509 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2511 gchar text[7] = { 0, };
2514 len = g_unichar_to_utf8 (invisible_chars[i], text);
2515 pango_layout_set_text (layout, text, len);
2517 count = pango_layout_get_unknown_glyphs_count (layout);
2521 g_object_unref (layout);
2522 return invisible_chars[i];
2526 g_object_unref (layout);
2532 gtk_entry_init (GtkEntry *entry)
2534 GtkStyleContext *context;
2535 GtkEntryPrivate *priv;
2537 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2542 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2543 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2545 priv->editable = TRUE;
2546 priv->visible = TRUE;
2547 priv->dnd_position = -1;
2548 priv->width_chars = -1;
2549 priv->is_cell_renderer = FALSE;
2550 priv->editing_canceled = FALSE;
2551 priv->has_frame = TRUE;
2552 priv->truncate_multiline = FALSE;
2553 priv->shadow_type = GTK_SHADOW_IN;
2555 priv->caps_lock_warning = TRUE;
2556 priv->caps_lock_warning_shown = FALSE;
2557 priv->progress_fraction = 0.0;
2558 priv->progress_pulse_fraction = 0.1;
2560 gtk_drag_dest_set (GTK_WIDGET (entry),
2561 GTK_DEST_DEFAULT_HIGHLIGHT,
2563 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2564 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2566 /* This object is completely private. No external entity can gain a reference
2567 * to it; so we create it here and destroy it in finalize().
2569 priv->im_context = gtk_im_multicontext_new ();
2571 g_signal_connect (priv->im_context, "commit",
2572 G_CALLBACK (gtk_entry_commit_cb), entry);
2573 g_signal_connect (priv->im_context, "preedit-changed",
2574 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2575 g_signal_connect (priv->im_context, "retrieve-surrounding",
2576 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2577 g_signal_connect (priv->im_context, "delete-surrounding",
2578 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2580 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2581 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2583 gtk_entry_update_cached_style_values (entry);
2585 priv->text_handle = _gtk_text_handle_new (GTK_WIDGET (entry));
2586 g_signal_connect (priv->text_handle, "handle-dragged",
2587 G_CALLBACK (gtk_entry_handle_dragged), entry);
2588 g_signal_connect (priv->text_handle, "drag-finished",
2589 G_CALLBACK (gtk_entry_handle_drag_finished), entry);
2593 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2594 GtkStyleContext *context,
2595 GtkEntryIconPosition icon_pos)
2597 GtkEntryPrivate *priv = entry->priv;
2598 EntryIconInfo *icon_info = priv->icons[icon_pos];
2600 GtkStateFlags state;
2602 widget = GTK_WIDGET (entry);
2603 state = gtk_widget_get_state_flags (widget);
2605 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2607 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2608 state |= GTK_STATE_FLAG_INSENSITIVE;
2609 else if (icon_info->prelight)
2610 state |= GTK_STATE_FLAG_PRELIGHT;
2612 gtk_style_context_save (context);
2614 gtk_style_context_set_state (context, state);
2615 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2617 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2619 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2620 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2622 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2626 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2627 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2629 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2634 get_icon_width (GtkEntry *entry,
2635 GtkEntryIconPosition icon_pos)
2637 GtkEntryPrivate *priv = entry->priv;
2638 EntryIconInfo *icon_info = priv->icons[icon_pos];
2639 GtkStyleContext *context;
2646 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2647 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2648 gtk_style_context_get_padding (context, 0, &padding);
2650 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2652 gtk_style_context_restore (context);
2655 width += padding.left + padding.right;
2661 get_icon_allocations (GtkEntry *entry,
2662 GtkAllocation *primary,
2663 GtkAllocation *secondary)
2666 GtkEntryPrivate *priv = entry->priv;
2667 gint x, y, width, height;
2669 get_text_area_size (entry, &x, &y, &width, &height);
2671 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2672 y += priv->focus_width;
2675 primary->height = height;
2676 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2679 secondary->height = height;
2680 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2682 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2684 primary->x = x + width - primary->width;
2690 secondary->x = x + width - secondary->width;
2696 begin_change (GtkEntry *entry)
2698 GtkEntryPrivate *priv = entry->priv;
2700 priv->change_count++;
2702 g_object_freeze_notify (G_OBJECT (entry));
2706 end_change (GtkEntry *entry)
2708 GtkEditable *editable = GTK_EDITABLE (entry);
2709 GtkEntryPrivate *priv = entry->priv;
2711 g_return_if_fail (priv->change_count > 0);
2713 g_object_thaw_notify (G_OBJECT (entry));
2715 priv->change_count--;
2717 if (priv->change_count == 0)
2719 if (priv->real_changed)
2721 g_signal_emit_by_name (editable, "changed");
2722 priv->real_changed = FALSE;
2728 emit_changed (GtkEntry *entry)
2730 GtkEditable *editable = GTK_EDITABLE (entry);
2731 GtkEntryPrivate *priv = entry->priv;
2733 if (priv->change_count == 0)
2734 g_signal_emit_by_name (editable, "changed");
2736 priv->real_changed = TRUE;
2740 gtk_entry_destroy (GtkWidget *widget)
2742 GtkEntry *entry = GTK_ENTRY (widget);
2743 GtkEntryPrivate *priv = entry->priv;
2745 priv->current_pos = priv->selection_bound = 0;
2746 gtk_entry_reset_im_context (entry);
2747 gtk_entry_reset_layout (entry);
2749 if (priv->blink_timeout)
2751 g_source_remove (priv->blink_timeout);
2752 priv->blink_timeout = 0;
2755 if (priv->recompute_idle)
2757 g_source_remove (priv->recompute_idle);
2758 priv->recompute_idle = 0;
2761 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2765 gtk_entry_dispose (GObject *object)
2767 GtkEntry *entry = GTK_ENTRY (object);
2768 GtkEntryPrivate *priv = entry->priv;
2771 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2772 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2773 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2774 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2775 gtk_entry_set_completion (entry, NULL);
2779 buffer_disconnect_signals (entry);
2780 g_object_unref (priv->buffer);
2781 priv->buffer = NULL;
2784 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2785 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2786 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2787 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2791 gtk_entry_finalize (GObject *object)
2793 GtkEntry *entry = GTK_ENTRY (object);
2794 GtkEntryPrivate *priv = entry->priv;
2795 EntryIconInfo *icon_info = NULL;
2798 for (i = 0; i < MAX_ICONS; i++)
2800 if ((icon_info = priv->icons[i]) != NULL)
2802 if (icon_info->target_list != NULL)
2804 gtk_target_list_unref (icon_info->target_list);
2805 icon_info->target_list = NULL;
2808 g_clear_object (&icon_info->icon_helper);
2810 g_slice_free (EntryIconInfo, icon_info);
2811 priv->icons[i] = NULL;
2815 if (priv->cached_layout)
2816 g_object_unref (priv->cached_layout);
2818 g_object_unref (priv->im_context);
2820 if (priv->blink_timeout)
2821 g_source_remove (priv->blink_timeout);
2823 if (priv->recompute_idle)
2824 g_source_remove (priv->recompute_idle);
2826 if (priv->selection_bubble)
2827 gtk_widget_destroy (priv->selection_bubble);
2829 g_object_unref (priv->text_handle);
2830 g_free (priv->placeholder_text);
2831 g_free (priv->im_module);
2833 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2837 gtk_entry_get_display_mode (GtkEntry *entry)
2839 GtkEntryPrivate *priv = entry->priv;
2842 return DISPLAY_NORMAL;
2844 if (priv->invisible_char == 0 && priv->invisible_char_set)
2845 return DISPLAY_BLANK;
2847 return DISPLAY_INVISIBLE;
2851 _gtk_entry_get_display_text (GtkEntry *entry,
2855 GtkEntryPasswordHint *password_hint;
2856 GtkEntryPrivate *priv;
2857 gunichar invisible_char;
2868 text = gtk_entry_buffer_get_text (get_buffer (entry));
2869 length = gtk_entry_buffer_get_length (get_buffer (entry));
2873 if (start_pos > length)
2876 if (end_pos <= start_pos)
2877 return g_strdup ("");
2878 else if (priv->visible)
2880 start = g_utf8_offset_to_pointer (text, start_pos);
2881 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2882 return g_strndup (start, end - start);
2886 str = g_string_sized_new (length * 2);
2888 /* Figure out what our invisible char is and encode it */
2889 if (!priv->invisible_char)
2890 invisible_char = priv->invisible_char_set ? ' ' : '*';
2892 invisible_char = priv->invisible_char;
2893 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2896 * Add hidden characters for each character in the text
2897 * buffer. If there is a password hint, then keep that
2898 * character visible.
2901 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2902 for (i = start_pos; i < end_pos; ++i)
2904 if (password_hint && i == password_hint->position)
2906 start = g_utf8_offset_to_pointer (text, i);
2907 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2911 g_string_append_len (str, char_str, char_len);
2915 return g_string_free (str, FALSE);
2920 update_cursors (GtkWidget *widget)
2922 GtkEntry *entry = GTK_ENTRY (widget);
2923 GtkEntryPrivate *priv = entry->priv;
2924 EntryIconInfo *icon_info = NULL;
2925 GdkDisplay *display;
2929 for (i = 0; i < MAX_ICONS; i++)
2931 if ((icon_info = priv->icons[i]) != NULL)
2933 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2934 icon_info->window != NULL)
2935 gdk_window_show_unraised (icon_info->window);
2937 /* The icon windows are not children of the visible entry window,
2938 * thus we can't just inherit the xterm cursor. Slight complication
2939 * here is that for the entry, insensitive => arrow cursor, but for
2940 * an icon in a sensitive entry, insensitive => xterm cursor.
2942 if (gtk_widget_is_sensitive (widget) &&
2943 (icon_info->insensitive ||
2944 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2946 display = gtk_widget_get_display (widget);
2947 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2948 gdk_window_set_cursor (icon_info->window, cursor);
2949 g_object_unref (cursor);
2953 gdk_window_set_cursor (icon_info->window, NULL);
2960 realize_icon_info (GtkWidget *widget,
2961 GtkEntryIconPosition icon_pos)
2963 GtkEntry *entry = GTK_ENTRY (widget);
2964 GtkEntryPrivate *priv = entry->priv;
2965 EntryIconInfo *icon_info = priv->icons[icon_pos];
2966 GdkWindowAttr attributes;
2967 gint attributes_mask;
2969 g_return_if_fail (icon_info != NULL);
2973 attributes.width = 1;
2974 attributes.height = 1;
2975 attributes.window_type = GDK_WINDOW_CHILD;
2976 attributes.wclass = GDK_INPUT_ONLY;
2977 attributes.event_mask = gtk_widget_get_events (widget);
2978 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2979 GDK_BUTTON_RELEASE_MASK |
2980 GDK_BUTTON1_MOTION_MASK |
2981 GDK_BUTTON3_MOTION_MASK |
2982 GDK_POINTER_MOTION_HINT_MASK |
2983 GDK_POINTER_MOTION_MASK |
2984 GDK_ENTER_NOTIFY_MASK |
2985 GDK_LEAVE_NOTIFY_MASK);
2986 attributes_mask = GDK_WA_X | GDK_WA_Y;
2988 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2991 gtk_widget_register_window (widget, icon_info->window);
2993 gtk_widget_queue_resize (widget);
2996 static EntryIconInfo*
2997 construct_icon_info (GtkWidget *widget,
2998 GtkEntryIconPosition icon_pos)
3000 GtkEntry *entry = GTK_ENTRY (widget);
3001 GtkEntryPrivate *priv = entry->priv;
3002 EntryIconInfo *icon_info;
3004 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
3006 icon_info = g_slice_new0 (EntryIconInfo);
3007 priv->icons[icon_pos] = icon_info;
3009 icon_info->icon_helper = _gtk_icon_helper_new ();
3010 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
3012 if (gtk_widget_get_realized (widget))
3013 realize_icon_info (widget, icon_pos);
3019 gtk_entry_map (GtkWidget *widget)
3021 GtkEntry *entry = GTK_ENTRY (widget);
3022 GtkEntryPrivate *priv = entry->priv;
3023 EntryIconInfo *icon_info = NULL;
3026 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
3028 gdk_window_show (priv->text_area);
3030 for (i = 0; i < MAX_ICONS; i++)
3032 if ((icon_info = priv->icons[i]) != NULL)
3034 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3035 icon_info->window != NULL)
3036 gdk_window_show (icon_info->window);
3040 update_cursors (widget);
3044 gtk_entry_unmap (GtkWidget *widget)
3046 GtkEntry *entry = GTK_ENTRY (widget);
3047 GtkEntryPrivate *priv = entry->priv;
3048 EntryIconInfo *icon_info = NULL;
3051 _gtk_text_handle_set_mode (priv->text_handle,
3052 GTK_TEXT_HANDLE_MODE_NONE);
3054 for (i = 0; i < MAX_ICONS; i++)
3056 if ((icon_info = priv->icons[i]) != NULL)
3058 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3059 icon_info->window != NULL)
3060 gdk_window_hide (icon_info->window);
3064 gdk_window_hide (priv->text_area);
3066 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
3070 gtk_entry_realize (GtkWidget *widget)
3073 GtkEntryPrivate *priv;
3074 EntryIconInfo *icon_info;
3076 GdkWindowAttr attributes;
3077 gint attributes_mask;
3078 gint frame_x, frame_y;
3081 gtk_widget_set_realized (widget, TRUE);
3082 window = gtk_widget_get_parent_window (widget);
3083 gtk_widget_set_window (widget, window);
3084 g_object_ref (window);
3086 entry = GTK_ENTRY (widget);
3089 attributes.window_type = GDK_WINDOW_CHILD;
3090 attributes.wclass = GDK_INPUT_ONLY;
3091 attributes.event_mask = gtk_widget_get_events (widget);
3092 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3093 GDK_BUTTON_RELEASE_MASK |
3094 GDK_BUTTON1_MOTION_MASK |
3095 GDK_BUTTON3_MOTION_MASK |
3096 GDK_POINTER_MOTION_HINT_MASK |
3097 GDK_POINTER_MOTION_MASK |
3098 GDK_ENTER_NOTIFY_MASK |
3099 GDK_LEAVE_NOTIFY_MASK);
3100 attributes_mask = GDK_WA_X | GDK_WA_Y;
3102 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3104 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3105 attributes.x += frame_x;
3106 attributes.y += frame_y;
3108 if (gtk_widget_is_sensitive (widget))
3110 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3111 attributes_mask |= GDK_WA_CURSOR;
3114 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3118 gtk_widget_register_window (widget, priv->text_area);
3120 if (attributes_mask & GDK_WA_CURSOR)
3121 g_object_unref (attributes.cursor);
3123 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3125 gtk_entry_adjust_scroll (entry);
3126 gtk_entry_update_primary_selection (entry);
3127 _gtk_text_handle_set_relative_to (priv->text_handle, priv->text_area);
3129 /* If the icon positions are already setup, create their windows.
3130 * Otherwise if they don't exist yet, then construct_icon_info()
3131 * will create the windows once the widget is already realized.
3133 for (i = 0; i < MAX_ICONS; i++)
3135 if ((icon_info = priv->icons[i]) != NULL)
3137 if (icon_info->window == NULL)
3138 realize_icon_info (widget, i);
3144 gtk_entry_unrealize (GtkWidget *widget)
3146 GtkEntry *entry = GTK_ENTRY (widget);
3147 GtkEntryPrivate *priv = entry->priv;
3148 GtkClipboard *clipboard;
3149 EntryIconInfo *icon_info;
3152 gtk_entry_reset_layout (entry);
3154 gtk_im_context_set_client_window (priv->im_context, NULL);
3155 _gtk_text_handle_set_relative_to (priv->text_handle, NULL);
3157 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3158 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3159 gtk_clipboard_clear (clipboard);
3161 if (priv->text_area)
3163 gtk_widget_unregister_window (widget, priv->text_area);
3164 gdk_window_destroy (priv->text_area);
3165 priv->text_area = NULL;
3168 if (priv->popup_menu)
3170 gtk_widget_destroy (priv->popup_menu);
3171 priv->popup_menu = NULL;
3174 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3176 for (i = 0; i < MAX_ICONS; i++)
3178 if ((icon_info = priv->icons[i]) != NULL)
3180 if (icon_info->window != NULL)
3182 gtk_widget_unregister_window (widget, icon_info->window);
3183 gdk_window_destroy (icon_info->window);
3184 icon_info->window = NULL;
3191 _gtk_entry_get_borders (GtkEntry *entry,
3192 GtkBorder *border_out)
3194 GtkEntryPrivate *priv = entry->priv;
3195 GtkWidget *widget = GTK_WIDGET (entry);
3196 GtkBorder tmp = { 0, 0, 0, 0 };
3197 GtkStyleContext *context;
3199 context = gtk_widget_get_style_context (widget);
3200 gtk_style_context_get_padding (context, 0, &tmp);
3202 if (priv->has_frame)
3206 gtk_style_context_get_border (context, 0, &border);
3207 tmp.top += border.top;
3208 tmp.right += border.right;
3209 tmp.bottom += border.bottom;
3210 tmp.left += border.left;
3213 if (!priv->interior_focus)
3215 tmp.top += priv->focus_width;
3216 tmp.right += priv->focus_width;
3217 tmp.bottom += priv->focus_width;
3218 tmp.left += priv->focus_width;
3221 if (border_out != NULL)
3226 gtk_entry_get_preferred_width (GtkWidget *widget,
3230 GtkEntry *entry = GTK_ENTRY (widget);
3231 GtkEntryPrivate *priv = entry->priv;
3232 PangoFontMetrics *metrics;
3234 PangoContext *context;
3235 gint icon_widths = 0;
3239 context = gtk_widget_get_pango_context (widget);
3241 metrics = pango_context_get_metrics (context,
3242 pango_context_get_font_description (context),
3243 pango_context_get_language (context));
3245 _gtk_entry_get_borders (entry, &borders);
3247 if (priv->width_chars < 0)
3248 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3251 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3252 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3253 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3255 width = char_pixels * priv->width_chars + borders.left + borders.right;
3258 for (i = 0; i < MAX_ICONS; i++)
3260 icon_width = get_icon_width (entry, i);
3262 icon_widths += icon_width;
3265 if (icon_widths > width)
3266 width += icon_widths;
3268 pango_font_metrics_unref (metrics);
3275 gtk_entry_get_preferred_height (GtkWidget *widget,
3279 GtkEntry *entry = GTK_ENTRY (widget);
3280 GtkEntryPrivate *priv = entry->priv;
3281 PangoFontMetrics *metrics;
3283 PangoContext *context;
3285 PangoLayout *layout;
3287 layout = gtk_entry_ensure_layout (entry, TRUE);
3288 context = gtk_widget_get_pango_context (widget);
3290 metrics = pango_context_get_metrics (context,
3291 pango_context_get_font_description (context),
3292 pango_context_get_language (context));
3294 priv->ascent = pango_font_metrics_get_ascent (metrics);
3295 priv->descent = pango_font_metrics_get_descent (metrics);
3296 pango_font_metrics_unref (metrics);
3298 _gtk_entry_get_borders (entry, &borders);
3299 pango_layout_get_pixel_size (layout, NULL, &height);
3301 height += borders.top + borders.bottom;
3308 place_windows (GtkEntry *entry)
3310 GtkWidget *widget = GTK_WIDGET (entry);
3311 GtkEntryPrivate *priv = entry->priv;
3312 gint x, y, width, height;
3313 gint frame_x, frame_y;
3314 GtkAllocation primary;
3315 GtkAllocation secondary;
3316 EntryIconInfo *icon_info = NULL;
3318 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3319 get_text_area_size (entry, &x, &y, &width, &height);
3320 get_icon_allocations (entry, &primary, &secondary);
3322 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3323 y += priv->focus_width;
3325 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3326 x += secondary.width;
3329 width -= primary.width + secondary.width;
3333 primary.x += frame_x;
3334 primary.y += frame_y;
3335 secondary.x += frame_x;
3336 secondary.y += frame_y;
3338 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3339 gdk_window_move_resize (icon_info->window,
3340 primary.x, primary.y,
3341 primary.width, primary.height);
3343 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3344 gdk_window_move_resize (icon_info->window,
3345 secondary.x, secondary.y,
3346 secondary.width, secondary.height);
3348 gdk_window_move_resize (priv->text_area, x, y, width, height);
3352 gtk_entry_get_text_area_size (GtkEntry *entry,
3358 GtkEntryPrivate *priv = entry->priv;
3359 GtkWidget *widget = GTK_WIDGET (entry);
3360 GtkAllocation allocation;
3361 GtkRequisition requisition;
3366 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3367 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3369 gtk_widget_get_allocation (widget, &allocation);
3370 _gtk_entry_get_borders (entry, &borders);
3372 if (gtk_widget_get_realized (widget))
3373 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3375 frame_height = req_height;
3377 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3378 frame_height -= 2 * priv->focus_width;
3384 *y = floor ((frame_height - req_height) / 2) + borders.top;
3387 *width = allocation.width - borders.left - borders.right;
3390 *height = req_height - borders.top - borders.bottom;
3394 get_text_area_size (GtkEntry *entry,
3400 GtkEntryClass *class;
3402 g_return_if_fail (GTK_IS_ENTRY (entry));
3404 class = GTK_ENTRY_GET_CLASS (entry);
3406 if (class->get_text_area_size)
3407 class->get_text_area_size (entry, x, y, width, height);
3412 gtk_entry_get_frame_size (GtkEntry *entry,
3418 GtkEntryPrivate *priv = entry->priv;
3419 GtkAllocation allocation;
3420 GtkRequisition requisition;
3421 GtkWidget *widget = GTK_WIDGET (entry);
3424 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3426 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3428 gtk_widget_get_allocation (widget, &allocation);
3435 if (priv->is_cell_renderer)
3438 *y = (allocation.height - req_height) / 2;
3444 *width = allocation.width;
3448 if (priv->is_cell_renderer)
3449 *height = allocation.height;
3451 *height = req_height;
3456 get_frame_size (GtkEntry *entry,
3457 gboolean relative_to_window,
3463 GtkEntryClass *class;
3464 GtkWidget *widget = GTK_WIDGET (entry);
3466 g_return_if_fail (GTK_IS_ENTRY (entry));
3468 class = GTK_ENTRY_GET_CLASS (entry);
3470 if (class->get_frame_size)
3471 class->get_frame_size (entry, x, y, width, height);
3473 if (!relative_to_window)
3475 GtkAllocation allocation;
3476 gtk_widget_get_allocation (widget, &allocation);
3486 gtk_entry_size_allocate (GtkWidget *widget,
3487 GtkAllocation *allocation)
3489 GtkEntry *entry = GTK_ENTRY (widget);
3491 gtk_widget_set_allocation (widget, allocation);
3493 if (gtk_widget_get_realized (widget))
3495 GtkEntryCompletion* completion;
3497 place_windows (entry);
3498 gtk_entry_recompute (entry);
3500 completion = gtk_entry_get_completion (entry);
3502 _gtk_entry_completion_resize_popup (completion);
3507 should_prelight (GtkEntry *entry,
3508 GtkEntryIconPosition icon_pos)
3510 GtkEntryPrivate *priv = entry->priv;
3511 EntryIconInfo *icon_info = priv->icons[icon_pos];
3517 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3520 if (icon_info->pressed)
3523 gtk_widget_style_get (GTK_WIDGET (entry),
3524 "icon-prelight", &prelight,
3531 draw_icon (GtkWidget *widget,
3533 GtkEntryIconPosition icon_pos)
3535 GtkEntry *entry = GTK_ENTRY (widget);
3536 GtkEntryPrivate *priv = entry->priv;
3537 EntryIconInfo *icon_info = priv->icons[icon_pos];
3538 gint x, y, width, height, pix_width, pix_height;
3539 GtkStyleContext *context;
3545 width = gdk_window_get_width (icon_info->window);
3546 height = gdk_window_get_height (icon_info->window);
3548 /* size_allocate hasn't been called yet. These are the default values.
3550 if (width == 1 || height == 1)
3554 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3556 context = gtk_widget_get_style_context (widget);
3557 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3558 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3559 &pix_width, &pix_height);
3560 gtk_style_context_get_padding (context, 0, &padding);
3562 x = MAX (0, padding.left);
3563 y = MAX (0, (height - pix_height) / 2);
3565 _gtk_icon_helper_draw (icon_info->icon_helper,
3569 gtk_style_context_restore (context);
3575 gtk_entry_draw_frame (GtkWidget *widget,
3576 GtkStyleContext *context,
3579 GtkEntry *entry = GTK_ENTRY (widget);
3580 GtkEntryPrivate *priv = entry->priv;
3581 gint x = 0, y = 0, width, height;
3582 gint frame_x, frame_y;
3586 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3588 cairo_translate (cr, frame_x, frame_y);
3590 /* Fix a problem with some themes which assume that entry->text_area's
3591 * width equals widget->window's width
3592 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3593 if (GTK_IS_SPIN_BUTTON (widget))
3597 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3598 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3601 width += borders.left + borders.right;
3604 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3606 x += priv->focus_width;
3607 y += priv->focus_width;
3608 width -= 2 * priv->focus_width;
3609 height -= 2 * priv->focus_width;
3612 gtk_render_background (context, cr,
3613 x, y, width, height);
3615 if (priv->has_frame)
3616 gtk_render_frame (context, cr,
3617 x, y, width, height);
3619 gtk_entry_draw_progress (widget, context, cr);
3621 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3623 x -= priv->focus_width;
3624 y -= priv->focus_width;
3625 width += 2 * priv->focus_width;
3626 height += 2 * priv->focus_width;
3628 gtk_render_focus (context, cr,
3629 0, 0, width, height);
3636 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3637 GtkStyleContext *context)
3639 GtkEntryPrivate *private = entry->priv;
3641 gtk_style_context_save (context);
3642 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3643 if (private->progress_pulse_mode)
3644 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3648 get_progress_area (GtkWidget *widget,
3654 GtkEntry *entry = GTK_ENTRY (widget);
3655 GtkEntryPrivate *private = entry->priv;
3656 GtkStyleContext *context;
3657 GtkBorder margin, border, entry_borders;
3658 gint frame_width, text_area_width, text_area_height;
3660 context = gtk_widget_get_style_context (widget);
3661 _gtk_entry_get_borders (entry, &entry_borders);
3662 get_text_area_size (entry,
3664 &text_area_width, &text_area_height);
3665 get_frame_size (entry, FALSE,
3667 &frame_width, NULL);
3671 *width = text_area_width + entry_borders.left + entry_borders.right;
3672 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3674 /* if the text area got resized by a subclass, subtract the left/right
3675 * border width, so that the progress bar won't extend over the resized
3678 if (frame_width > *width)
3680 gtk_style_context_get_border (context, 0, &border);
3681 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3683 *x = (frame_width - *width) + border.left;
3684 *width -= border.left;
3688 *width -= border.right;
3692 gtk_entry_prepare_context_for_progress (entry, context);
3693 gtk_style_context_get_margin (context, 0, &margin);
3695 gtk_style_context_restore (context);
3699 *width -= margin.left + margin.right;
3700 *height -= margin.top + margin.bottom;
3702 if (private->progress_pulse_mode)
3704 gdouble value = private->progress_pulse_current;
3706 *x += (gint) floor(value * (*width));
3707 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3709 else if (private->progress_fraction > 0)
3711 gdouble value = private->progress_fraction;
3713 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3717 bar_width = floor(value * (*width) + 0.5);
3718 *x += *width - bar_width;
3723 *width = (gint) floor(value * (*width) + 0.5);
3734 gtk_entry_draw_progress (GtkWidget *widget,
3735 GtkStyleContext *context,
3738 GtkEntry *entry = GTK_ENTRY (widget);
3739 gint x, y, width, height;
3741 get_progress_area (widget, &x, &y, &width, &height);
3743 if ((width <= 0) || (height <= 0))
3746 gtk_entry_prepare_context_for_progress (entry, context);
3747 gtk_render_activity (context, cr,
3748 x, y, width, height);
3750 gtk_style_context_restore (context);
3754 gtk_entry_draw (GtkWidget *widget,
3757 GtkEntry *entry = GTK_ENTRY (widget);
3758 GtkStyleContext *context;
3759 GtkEntryPrivate *priv = entry->priv;
3762 if (gtk_cairo_should_draw_window (cr,
3763 gtk_widget_get_window (widget)))
3765 context = gtk_widget_get_style_context (widget);
3767 /* Draw entry_bg, shadow, progress and focus */
3768 gtk_entry_draw_frame (widget, context, cr);
3770 /* Draw text and cursor */
3773 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3775 if (priv->dnd_position != -1)
3776 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3778 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3780 /* When no text is being displayed at all, don't show the cursor */
3781 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3782 gtk_widget_has_focus (widget) &&
3783 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3784 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3789 for (i = 0; i < MAX_ICONS; i++)
3791 EntryIconInfo *icon_info = priv->icons[i];
3793 if (icon_info != NULL)
3794 draw_icon (widget, cr, i);
3802 gtk_entry_enter_notify (GtkWidget *widget,
3803 GdkEventCrossing *event)
3805 GtkEntry *entry = GTK_ENTRY (widget);
3806 GtkEntryPrivate *priv = entry->priv;
3809 for (i = 0; i < MAX_ICONS; i++)
3811 EntryIconInfo *icon_info = priv->icons[i];
3813 if (icon_info != NULL && event->window == icon_info->window)
3815 if (should_prelight (entry, i))
3817 icon_info->prelight = TRUE;
3818 gtk_widget_queue_draw (widget);
3829 gtk_entry_leave_notify (GtkWidget *widget,
3830 GdkEventCrossing *event)
3832 GtkEntry *entry = GTK_ENTRY (widget);
3833 GtkEntryPrivate *priv = entry->priv;
3836 for (i = 0; i < MAX_ICONS; i++)
3838 EntryIconInfo *icon_info = priv->icons[i];
3840 if (icon_info != NULL && event->window == icon_info->window)
3842 /* a grab means that we may never see the button release */
3843 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3844 icon_info->pressed = FALSE;
3846 if (should_prelight (entry, i))
3848 icon_info->prelight = FALSE;
3849 gtk_widget_queue_draw (widget);
3860 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3864 gint start_char, end_char;
3866 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3868 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3869 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3870 const char *text = pango_layout_get_text (layout);
3871 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3872 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3873 gint real_n_ranges, i;
3875 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3881 for (i = 0; i < real_n_ranges; ++i)
3883 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3884 r[2 * i] = r[2 * i] / PANGO_SCALE;
3889 *n_ranges = real_n_ranges;
3901 in_selection (GtkEntry *entry,
3906 gint retval = FALSE;
3908 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3910 for (i = 0; i < n_ranges; ++i)
3912 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3924 gtk_entry_move_handle (GtkEntry *entry,
3925 GtkTextHandlePosition pos,
3930 GtkEntryPrivate *priv = entry->priv;
3932 if (!_gtk_text_handle_get_is_dragged (priv->text_handle, pos) &&
3933 (x < 0 || x > gdk_window_get_width (priv->text_area)))
3935 /* Hide the handle if it's not being manipulated
3936 * and fell outside of the visible text area.
3938 _gtk_text_handle_set_visible (priv->text_handle, pos, FALSE);
3944 rect.x = CLAMP (x, 0, gdk_window_get_width (priv->text_area));
3947 rect.height = height;
3949 _gtk_text_handle_set_visible (priv->text_handle, pos, TRUE);
3950 _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
3955 gtk_entry_get_selection_bound_location (GtkEntry *entry)
3957 GtkEntryPrivate *priv = entry->priv;
3958 PangoLayout *layout;
3964 layout = gtk_entry_ensure_layout (entry, FALSE);
3965 text = pango_layout_get_text (layout);
3966 index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text;
3967 pango_layout_index_to_pos (layout, index, &pos);
3969 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3970 x = (pos.x + pos.width) / PANGO_SCALE;
3972 x = pos.x / PANGO_SCALE;
3978 gtk_entry_update_handles (GtkEntry *entry,
3979 GtkTextHandleMode mode)
3981 GtkEntryPrivate *priv = entry->priv;
3982 gint strong_x, height;
3985 _gtk_text_handle_set_mode (priv->text_handle, mode);
3987 /* Wait for recomputation before repositioning */
3988 if (priv->recompute_idle != 0)
3991 height = gdk_window_get_height (priv->text_area);
3993 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
3994 cursor = strong_x - priv->scroll_offset;
3996 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
4000 bound = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
4002 if (priv->selection_bound > priv->current_pos)
4013 /* Update start selection bound */
4014 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_START,
4016 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_END,
4020 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_CURSOR,
4025 gtk_entry_button_press (GtkWidget *widget,
4026 GdkEventButton *event)
4028 GtkEntry *entry = GTK_ENTRY (widget);
4029 GtkEditable *editable = GTK_EDITABLE (widget);
4030 GtkEntryPrivate *priv = entry->priv;
4031 EntryIconInfo *icon_info = NULL;
4033 gint sel_start, sel_end;
4036 gtk_entry_selection_bubble_popup_unset (entry);
4038 for (i = 0; i < MAX_ICONS; i++)
4040 icon_info = priv->icons[i];
4042 if (!icon_info || icon_info->insensitive)
4045 if (event->window == icon_info->window)
4047 if (should_prelight (entry, i))
4049 icon_info->prelight = FALSE;
4050 gtk_widget_queue_draw (widget);
4053 priv->start_x = event->x;
4054 priv->start_y = event->y;
4055 icon_info->pressed = TRUE;
4057 if (!icon_info->nonactivatable)
4058 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
4064 if (event->window != priv->text_area ||
4065 (priv->button && event->button != priv->button))
4068 gtk_entry_reset_blink_time (entry);
4070 priv->button = event->button;
4071 priv->device = gdk_event_get_device ((GdkEvent *) event);
4073 if (!gtk_widget_has_focus (widget))
4075 priv->in_click = TRUE;
4076 gtk_widget_grab_focus (widget);
4077 priv->in_click = FALSE;
4080 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4082 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
4084 gtk_entry_do_popup (entry, event);
4085 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
4086 priv->device = NULL;
4090 else if (event->button == GDK_BUTTON_PRIMARY)
4092 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
4093 gboolean is_touchscreen;
4096 source = gdk_event_get_source_device ((GdkEvent *) event);
4097 is_touchscreen = test_touchscreen ||
4098 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN;
4100 priv->select_words = FALSE;
4101 priv->select_lines = FALSE;
4104 gtk_widget_get_modifier_mask (widget,
4105 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
4107 gtk_entry_reset_im_context (entry);
4109 if (!have_selection) /* select from the current position to the clicked position */
4110 sel_start = sel_end = priv->current_pos;
4112 if (tmp_pos > sel_start && tmp_pos < sel_end)
4114 /* Truncate current selection, but keep it as big as possible */
4115 if (tmp_pos - sel_start > sel_end - tmp_pos)
4116 gtk_entry_set_positions (entry, sel_start, tmp_pos);
4118 gtk_entry_set_positions (entry, tmp_pos, sel_end);
4122 gboolean extend_to_left;
4125 /* Figure out what click selects and extend current selection */
4126 switch (event->type)
4128 case GDK_BUTTON_PRESS:
4129 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
4132 case GDK_2BUTTON_PRESS:
4133 priv->select_words = TRUE;
4134 gtk_entry_select_word (entry);
4137 case GDK_3BUTTON_PRESS:
4138 priv->select_lines = TRUE;
4139 gtk_entry_select_line (entry);
4146 start = MIN (priv->current_pos, priv->selection_bound);
4147 start = MIN (sel_start, start);
4149 end = MAX (priv->current_pos, priv->selection_bound);
4150 end = MAX (sel_end, end);
4152 if (tmp_pos == sel_start || tmp_pos == sel_end)
4153 extend_to_left = (tmp_pos == start);
4155 extend_to_left = (end == sel_end);
4158 gtk_entry_set_positions (entry, start, end);
4160 gtk_entry_set_positions (entry, end, start);
4163 else /* no shift key */
4164 switch (event->type)
4166 case GDK_BUTTON_PRESS:
4167 if (in_selection (entry, event->x + priv->scroll_offset))
4169 /* Click inside the selection - we'll either start a drag, or
4170 * clear the selection
4172 priv->in_drag = TRUE;
4173 priv->drag_start_x = event->x + priv->scroll_offset;
4174 priv->drag_start_y = event->y;
4178 gtk_editable_set_position (editable, tmp_pos);
4181 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4185 case GDK_2BUTTON_PRESS:
4186 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4187 * receiving a GDK_2BUTTON_PRESS so we need to reset
4188 * priv->in_drag which may have been set above
4190 priv->in_drag = FALSE;
4191 priv->select_words = TRUE;
4192 gtk_entry_select_word (entry);
4195 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4198 case GDK_3BUTTON_PRESS:
4199 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4200 * receiving a GDK_3BUTTON_PRESS so we need to reset
4201 * priv->in_drag which may have been set above
4203 priv->in_drag = FALSE;
4204 priv->select_lines = TRUE;
4205 gtk_entry_select_line (entry);
4207 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4216 else if (event->type == GDK_BUTTON_PRESS &&
4217 event->button == GDK_BUTTON_MIDDLE &&
4218 get_middle_click_paste (entry))
4222 priv->insert_pos = tmp_pos;
4223 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
4228 gtk_widget_error_bell (widget);
4236 gtk_entry_button_release (GtkWidget *widget,
4237 GdkEventButton *event)
4239 GtkEntry *entry = GTK_ENTRY (widget);
4240 GtkEntryPrivate *priv = entry->priv;
4241 EntryIconInfo *icon_info = NULL;
4242 gboolean is_touchscreen;
4246 for (i = 0; i < MAX_ICONS; i++)
4248 icon_info = priv->icons[i];
4250 if (!icon_info || icon_info->insensitive)
4253 if (event->window == icon_info->window)
4255 icon_info->pressed = FALSE;
4257 if (should_prelight (entry, i) &&
4258 event->x >= 0 && event->y >= 0 &&
4259 event->x < gdk_window_get_width (icon_info->window) &&
4260 event->y < gdk_window_get_height (icon_info->window))
4262 icon_info->prelight = TRUE;
4263 gtk_widget_queue_draw (widget);
4266 if (!icon_info->nonactivatable)
4267 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4273 if (event->window != priv->text_area || priv->button != event->button)
4276 source = gdk_event_get_source_device ((GdkEvent *) event);
4277 is_touchscreen = (test_touchscreen ||
4278 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN);
4282 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4284 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4287 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4291 else if (is_touchscreen)
4292 gtk_entry_selection_bubble_popup_set (entry);
4295 priv->device = NULL;
4297 gtk_entry_update_primary_selection (entry);
4303 _gtk_entry_get_selected_text (GtkEntry *entry)
4305 GtkEditable *editable = GTK_EDITABLE (entry);
4306 gint start_text, end_text;
4309 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4310 text = gtk_editable_get_chars (editable, start_text, end_text);
4316 gtk_entry_motion_notify (GtkWidget *widget,
4317 GdkEventMotion *event)
4319 GtkEntry *entry = GTK_ENTRY (widget);
4320 GtkEntryPrivate *priv = entry->priv;
4321 EntryIconInfo *icon_info = NULL;
4325 for (i = 0; i < MAX_ICONS; i++)
4327 icon_info = priv->icons[i];
4329 if (!icon_info || icon_info->insensitive)
4332 if (event->window == icon_info->window)
4334 if (icon_info->pressed &&
4335 icon_info->target_list != NULL &&
4336 gtk_drag_check_threshold (widget,
4342 icon_info->in_drag = TRUE;
4343 icon_info->pressed = FALSE;
4344 gtk_drag_begin (widget,
4345 icon_info->target_list,
4355 if (priv->mouse_cursor_obscured)
4359 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4360 gdk_window_set_cursor (priv->text_area, cursor);
4361 g_object_unref (cursor);
4362 priv->mouse_cursor_obscured = FALSE;
4365 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4368 if (priv->select_lines)
4371 gdk_event_request_motions (event);
4375 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4376 gtk_drag_check_threshold (widget,
4377 priv->drag_start_x, priv->drag_start_y,
4378 event->x + priv->scroll_offset, event->y))
4380 GdkDragContext *context;
4381 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4382 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4384 cairo_surface_t *surface;
4386 gtk_target_list_add_text_targets (target_list, 0);
4388 text = _gtk_entry_get_selected_text (entry);
4389 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4391 context = gtk_drag_begin (widget, target_list, actions,
4392 priv->button, (GdkEvent *)event);
4395 gtk_drag_set_icon_surface (context, surface);
4397 gtk_drag_set_icon_default (context);
4400 cairo_surface_destroy (surface);
4403 priv->in_drag = FALSE;
4405 priv->device = NULL;
4407 gtk_target_list_unref (target_list);
4412 GdkInputSource input_source;
4416 length = gtk_entry_buffer_get_length (get_buffer (entry));
4420 else if (event->y >= gdk_window_get_height (priv->text_area))
4423 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4425 source = gdk_event_get_source_device ((GdkEvent *) event);
4426 input_source = gdk_device_get_source (source);
4428 if (priv->select_words)
4431 gint old_min, old_max;
4434 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4435 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4437 pos = priv->current_pos;
4438 bound = priv->selection_bound;
4440 old_min = MIN(priv->current_pos, priv->selection_bound);
4441 old_max = MAX(priv->current_pos, priv->selection_bound);
4448 else if (old_max < max)
4453 else if (pos == old_min)
4455 if (priv->current_pos != min)
4460 if (priv->current_pos != max)
4464 gtk_entry_set_positions (entry, pos, bound);
4467 gtk_entry_set_positions (entry, tmp_pos, -1);
4469 /* Update touch handles' position */
4470 if (test_touchscreen || input_source == GDK_SOURCE_TOUCHSCREEN)
4471 gtk_entry_update_handles (entry,
4472 (priv->current_pos == priv->selection_bound) ?
4473 GTK_TEXT_HANDLE_MODE_CURSOR :
4474 GTK_TEXT_HANDLE_MODE_SELECTION);
4481 set_invisible_cursor (GdkWindow *window)
4483 GdkDisplay *display;
4486 display = gdk_window_get_display (window);
4487 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4489 gdk_window_set_cursor (window, cursor);
4491 g_object_unref (cursor);
4495 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4497 GtkEntryPrivate *priv = entry->priv;
4499 if (priv->mouse_cursor_obscured)
4502 set_invisible_cursor (priv->text_area);
4504 priv->mouse_cursor_obscured = TRUE;
4508 gtk_entry_key_press (GtkWidget *widget,
4511 GtkEntry *entry = GTK_ENTRY (widget);
4512 GtkEntryPrivate *priv = entry->priv;
4514 gtk_entry_reset_blink_time (entry);
4515 gtk_entry_pend_cursor_blink (entry);
4517 gtk_entry_selection_bubble_popup_unset (entry);
4519 if (!event->send_event)
4520 _gtk_text_handle_set_mode (priv->text_handle,
4521 GTK_TEXT_HANDLE_MODE_NONE);
4525 if (gtk_im_context_filter_keypress (priv->im_context, event))
4527 gtk_entry_obscure_mouse_cursor (entry);
4528 priv->need_im_reset = TRUE;
4533 if (event->keyval == GDK_KEY_Return ||
4534 event->keyval == GDK_KEY_KP_Enter ||
4535 event->keyval == GDK_KEY_ISO_Enter ||
4536 event->keyval == GDK_KEY_Escape)
4537 gtk_entry_reset_im_context (entry);
4539 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4540 /* Activate key bindings
4544 if (!priv->editable && event->length)
4545 gtk_widget_error_bell (widget);
4551 gtk_entry_key_release (GtkWidget *widget,
4554 GtkEntry *entry = GTK_ENTRY (widget);
4555 GtkEntryPrivate *priv = entry->priv;
4559 if (gtk_im_context_filter_keypress (priv->im_context, event))
4561 priv->need_im_reset = TRUE;
4566 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4570 gtk_entry_focus_in (GtkWidget *widget,
4571 GdkEventFocus *event)
4573 GtkEntry *entry = GTK_ENTRY (widget);
4574 GtkEntryPrivate *priv = entry->priv;
4577 gtk_widget_queue_draw (widget);
4579 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4583 priv->need_im_reset = TRUE;
4584 gtk_im_context_focus_in (priv->im_context);
4585 keymap_state_changed (keymap, entry);
4586 g_signal_connect (keymap, "state-changed",
4587 G_CALLBACK (keymap_state_changed), entry);
4590 g_signal_connect (keymap, "direction-changed",
4591 G_CALLBACK (keymap_direction_changed), entry);
4593 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4594 priv->placeholder_text != NULL)
4596 gtk_entry_recompute (entry);
4600 gtk_entry_reset_blink_time (entry);
4601 gtk_entry_check_cursor_blink (entry);
4608 gtk_entry_focus_out (GtkWidget *widget,
4609 GdkEventFocus *event)
4611 GtkEntry *entry = GTK_ENTRY (widget);
4612 GtkEntryPrivate *priv = entry->priv;
4613 GtkEntryCompletion *completion;
4616 gtk_entry_selection_bubble_popup_unset (entry);
4617 _gtk_text_handle_set_mode (priv->text_handle,
4618 GTK_TEXT_HANDLE_MODE_NONE);
4620 gtk_widget_queue_draw (widget);
4622 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4626 priv->need_im_reset = TRUE;
4627 gtk_im_context_focus_out (priv->im_context);
4628 remove_capslock_feedback (entry);
4631 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4632 priv->placeholder_text != NULL)
4634 gtk_entry_recompute (entry);
4638 gtk_entry_check_cursor_blink (entry);
4641 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4642 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4644 completion = gtk_entry_get_completion (entry);
4646 _gtk_entry_completion_popdown (completion);
4652 gtk_entry_grab_focus (GtkWidget *widget)
4654 GtkEntry *entry = GTK_ENTRY (widget);
4655 GtkEntryPrivate *priv = entry->priv;
4656 gboolean select_on_focus;
4658 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4660 if (priv->editable && !priv->in_click)
4662 g_object_get (gtk_widget_get_settings (widget),
4663 "gtk-entry-select-on-focus",
4667 if (select_on_focus)
4668 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4673 gtk_entry_direction_changed (GtkWidget *widget,
4674 GtkTextDirection previous_dir)
4676 GtkEntry *entry = GTK_ENTRY (widget);
4678 gtk_entry_recompute (entry);
4680 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4684 gtk_entry_state_flags_changed (GtkWidget *widget,
4685 GtkStateFlags previous_state)
4687 GtkEntry *entry = GTK_ENTRY (widget);
4688 GtkEntryPrivate *priv = entry->priv;
4691 if (gtk_widget_get_realized (widget))
4693 if (gtk_widget_is_sensitive (widget))
4694 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4698 gdk_window_set_cursor (priv->text_area, cursor);
4701 g_object_unref (cursor);
4703 priv->mouse_cursor_obscured = FALSE;
4705 update_cursors (widget);
4708 if (!gtk_widget_is_sensitive (widget))
4710 /* Clear any selection */
4711 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4714 gtk_entry_update_cached_style_values (entry);
4718 gtk_entry_screen_changed (GtkWidget *widget,
4719 GdkScreen *old_screen)
4721 gtk_entry_recompute (GTK_ENTRY (widget));
4724 /* GtkEditable method implementations
4727 gtk_entry_insert_text (GtkEditable *editable,
4728 const gchar *new_text,
4729 gint new_text_length,
4732 g_object_ref (editable);
4735 * The incoming text may a password or other secret. We make sure
4736 * not to copy it into temporary buffers.
4739 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4741 g_object_unref (editable);
4745 gtk_entry_delete_text (GtkEditable *editable,
4749 g_object_ref (editable);
4751 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4753 g_object_unref (editable);
4757 gtk_entry_get_chars (GtkEditable *editable,
4761 GtkEntry *entry = GTK_ENTRY (editable);
4764 gint start_index, end_index;
4766 text = gtk_entry_buffer_get_text (get_buffer (entry));
4767 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4770 end_pos = text_length;
4772 start_pos = MIN (text_length, start_pos);
4773 end_pos = MIN (text_length, end_pos);
4775 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4776 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4778 return g_strndup (text + start_index, end_index - start_index);
4782 gtk_entry_real_set_position (GtkEditable *editable,
4785 GtkEntry *entry = GTK_ENTRY (editable);
4786 GtkEntryPrivate *priv = entry->priv;
4790 length = gtk_entry_buffer_get_length (get_buffer (entry));
4791 if (position < 0 || position > length)
4794 if (position != priv->current_pos ||
4795 position != priv->selection_bound)
4797 gtk_entry_reset_im_context (entry);
4798 gtk_entry_set_positions (entry, position, position);
4803 gtk_entry_get_position (GtkEditable *editable)
4805 GtkEntry *entry = GTK_ENTRY (editable);
4806 GtkEntryPrivate *priv = entry->priv;
4808 return priv->current_pos;
4812 gtk_entry_set_selection_bounds (GtkEditable *editable,
4816 GtkEntry *entry = GTK_ENTRY (editable);
4819 length = gtk_entry_buffer_get_length (get_buffer (entry));
4825 gtk_entry_reset_im_context (entry);
4827 gtk_entry_set_positions (entry,
4829 MIN (start, length));
4831 gtk_entry_update_primary_selection (entry);
4835 gtk_entry_get_selection_bounds (GtkEditable *editable,
4839 GtkEntry *entry = GTK_ENTRY (editable);
4840 GtkEntryPrivate *priv = entry->priv;
4842 *start = priv->selection_bound;
4843 *end = priv->current_pos;
4845 return (priv->selection_bound != priv->current_pos);
4849 icon_theme_changed (GtkEntry *entry)
4851 GtkEntryPrivate *priv = entry->priv;
4854 for (i = 0; i < MAX_ICONS; i++)
4856 EntryIconInfo *icon_info = priv->icons[i];
4857 if (icon_info != NULL)
4858 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4861 gtk_widget_queue_draw (GTK_WIDGET (entry));
4865 gtk_entry_update_cached_style_values (GtkEntry *entry)
4867 GtkEntryPrivate *priv = entry->priv;
4869 gboolean interior_focus;
4871 gtk_widget_style_get (GTK_WIDGET (entry),
4872 "focus-line-width", &focus_width,
4873 "interior-focus", &interior_focus,
4875 priv->focus_width = focus_width;
4876 priv->interior_focus = interior_focus;
4878 if (!priv->invisible_char_set)
4880 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4882 if (priv->invisible_char != ch)
4884 priv->invisible_char = ch;
4885 g_object_notify (G_OBJECT (entry), "invisible-char");
4891 gtk_entry_style_updated (GtkWidget *widget)
4893 GtkEntry *entry = GTK_ENTRY (widget);
4895 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4897 gtk_entry_update_cached_style_values (entry);
4899 icon_theme_changed (entry);
4902 /* GtkCellEditable method implementations
4905 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4907 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4908 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4912 gtk_cell_editable_key_press_event (GtkEntry *entry,
4913 GdkEventKey *key_event,
4916 GtkEntryPrivate *priv = entry->priv;
4918 if (key_event->keyval == GDK_KEY_Escape)
4920 priv->editing_canceled = TRUE;
4921 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4922 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4927 /* override focus */
4928 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4930 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4931 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4940 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4943 GtkEntry *entry = GTK_ENTRY (cell_editable);
4944 GtkEntryPrivate *priv = entry->priv;
4946 priv->is_cell_renderer = TRUE;
4948 g_signal_connect (cell_editable, "activate",
4949 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4950 g_signal_connect (cell_editable, "key-press-event",
4951 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4955 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4957 if (password_hint->source_id)
4958 g_source_remove (password_hint->source_id);
4960 g_slice_free (GtkEntryPasswordHint, password_hint);
4965 gtk_entry_remove_password_hint (gpointer data)
4967 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4968 password_hint->position = -1;
4970 /* Force the string to be redrawn, but now without a visible character */
4971 gtk_entry_recompute (GTK_ENTRY (data));
4975 /* Default signal handlers
4978 gtk_entry_real_insert_text (GtkEditable *editable,
4979 const gchar *new_text,
4980 gint new_text_length,
4986 n_chars = g_utf8_strlen (new_text, new_text_length);
4989 * The actual insertion into the buffer. This will end up firing the
4990 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4991 * buffer_notify_text(), buffer_notify_length()
4993 begin_change (GTK_ENTRY (editable));
4995 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4997 end_change (GTK_ENTRY (editable));
4999 if (n_inserted != n_chars)
5000 gtk_widget_error_bell (GTK_WIDGET (editable));
5002 *position += n_inserted;
5006 gtk_entry_real_delete_text (GtkEditable *editable,
5011 * The actual deletion from the buffer. This will end up firing the
5012 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
5013 * buffer_notify_text(), buffer_notify_length()
5016 begin_change (GTK_ENTRY (editable));
5018 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
5020 end_change (GTK_ENTRY (editable));
5023 /* GtkEntryBuffer signal handlers
5026 buffer_inserted_text (GtkEntryBuffer *buffer,
5032 GtkEntryPrivate *priv = entry->priv;
5033 guint password_hint_timeout;
5035 gint selection_bound;
5037 current_pos = priv->current_pos;
5038 if (current_pos > position)
5039 current_pos += n_chars;
5041 selection_bound = priv->selection_bound;
5042 if (selection_bound > position)
5043 selection_bound += n_chars;
5045 gtk_entry_set_positions (entry, current_pos, selection_bound);
5047 /* Calculate the password hint if it needs to be displayed. */
5048 if (n_chars == 1 && !priv->visible)
5050 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5051 "gtk-entry-password-hint-timeout", &password_hint_timeout,
5054 if (password_hint_timeout > 0)
5056 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5057 quark_password_hint);
5060 password_hint = g_slice_new0 (GtkEntryPasswordHint);
5061 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
5062 (GDestroyNotify)gtk_entry_password_hint_free);
5065 password_hint->position = position;
5066 if (password_hint->source_id)
5067 g_source_remove (password_hint->source_id);
5068 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
5069 (GSourceFunc)gtk_entry_remove_password_hint, entry);
5075 buffer_deleted_text (GtkEntryBuffer *buffer,
5080 GtkEntryPrivate *priv = entry->priv;
5081 guint end_pos = position + n_chars;
5082 gint selection_bound;
5085 current_pos = priv->current_pos;
5086 if (current_pos > position)
5087 current_pos -= MIN (current_pos, end_pos) - position;
5089 selection_bound = priv->selection_bound;
5090 if (selection_bound > position)
5091 selection_bound -= MIN (selection_bound, end_pos) - position;
5093 gtk_entry_set_positions (entry, current_pos, selection_bound);
5095 /* We might have deleted the selection */
5096 gtk_entry_update_primary_selection (entry);
5098 /* Disable the password hint if one exists. */
5101 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5102 quark_password_hint);
5105 if (password_hint->source_id)
5106 g_source_remove (password_hint->source_id);
5107 password_hint->source_id = 0;
5108 password_hint->position = -1;
5114 buffer_notify_text (GtkEntryBuffer *buffer,
5118 gtk_entry_recompute (entry);
5119 emit_changed (entry);
5120 g_object_notify (G_OBJECT (entry), "text");
5124 buffer_notify_length (GtkEntryBuffer *buffer,
5128 g_object_notify (G_OBJECT (entry), "text-length");
5132 buffer_notify_max_length (GtkEntryBuffer *buffer,
5136 g_object_notify (G_OBJECT (entry), "max-length");
5140 buffer_connect_signals (GtkEntry *entry)
5142 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
5143 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
5144 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
5145 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
5146 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
5150 buffer_disconnect_signals (GtkEntry *entry)
5152 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
5153 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
5154 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
5155 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
5156 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
5159 /* Compute the X position for an offset that corresponds to the "more important
5160 * cursor position for that offset. We use this when trying to guess to which
5161 * end of the selection we should go to when the user hits the left or
5165 get_better_cursor_x (GtkEntry *entry,
5168 GtkEntryPrivate *priv = entry->priv;
5169 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5170 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5171 gboolean split_cursor;
5173 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5174 const gchar *text = pango_layout_get_text (layout);
5175 gint index = g_utf8_offset_to_pointer (text, offset) - text;
5177 PangoRectangle strong_pos, weak_pos;
5179 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5180 "gtk-split-cursor", &split_cursor,
5183 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5186 return strong_pos.x / PANGO_SCALE;
5188 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
5192 gtk_entry_move_cursor (GtkEntry *entry,
5193 GtkMovementStep step,
5195 gboolean extend_selection)
5197 GtkEntryPrivate *priv = entry->priv;
5198 gint new_pos = priv->current_pos;
5200 gtk_entry_reset_im_context (entry);
5202 if (priv->current_pos != priv->selection_bound && !extend_selection)
5204 /* If we have a current selection and aren't extending it, move to the
5205 * start/or end of the selection as appropriate
5209 case GTK_MOVEMENT_VISUAL_POSITIONS:
5211 gint current_x = get_better_cursor_x (entry, priv->current_pos);
5212 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
5215 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
5217 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
5220 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5221 case GTK_MOVEMENT_WORDS:
5223 new_pos = MIN (priv->current_pos, priv->selection_bound);
5225 new_pos = MAX (priv->current_pos, priv->selection_bound);
5227 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5228 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5229 case GTK_MOVEMENT_BUFFER_ENDS:
5230 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5232 case GTK_MOVEMENT_DISPLAY_LINES:
5233 case GTK_MOVEMENT_PARAGRAPHS:
5234 case GTK_MOVEMENT_PAGES:
5235 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5243 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5244 new_pos = gtk_entry_move_logically (entry, new_pos, count);
5246 case GTK_MOVEMENT_VISUAL_POSITIONS:
5247 new_pos = gtk_entry_move_visually (entry, new_pos, count);
5248 if (priv->current_pos == new_pos)
5250 if (!extend_selection)
5252 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
5254 GTK_DIR_RIGHT : GTK_DIR_LEFT))
5256 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
5259 gtk_widget_child_focus (toplevel,
5261 GTK_DIR_RIGHT : GTK_DIR_LEFT);
5266 gtk_widget_error_bell (GTK_WIDGET (entry));
5270 case GTK_MOVEMENT_WORDS:
5273 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5278 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5281 if (priv->current_pos == new_pos)
5282 gtk_widget_error_bell (GTK_WIDGET (entry));
5284 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5285 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5286 case GTK_MOVEMENT_BUFFER_ENDS:
5287 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5288 if (priv->current_pos == new_pos)
5289 gtk_widget_error_bell (GTK_WIDGET (entry));
5291 case GTK_MOVEMENT_DISPLAY_LINES:
5292 case GTK_MOVEMENT_PARAGRAPHS:
5293 case GTK_MOVEMENT_PAGES:
5294 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5299 if (extend_selection)
5300 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5302 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5304 gtk_entry_pend_cursor_blink (entry);
5308 gtk_entry_insert_at_cursor (GtkEntry *entry,
5311 GtkEntryPrivate *priv = entry->priv;
5312 GtkEditable *editable = GTK_EDITABLE (entry);
5313 gint pos = priv->current_pos;
5317 gtk_entry_reset_im_context (entry);
5318 gtk_editable_insert_text (editable, str, -1, &pos);
5319 gtk_editable_set_position (editable, pos);
5324 gtk_entry_delete_from_cursor (GtkEntry *entry,
5328 GtkEntryPrivate *priv = entry->priv;
5329 GtkEditable *editable = GTK_EDITABLE (entry);
5330 gint start_pos = priv->current_pos;
5331 gint end_pos = priv->current_pos;
5332 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5334 gtk_entry_reset_im_context (entry);
5336 if (!priv->editable)
5338 gtk_widget_error_bell (GTK_WIDGET (entry));
5342 if (priv->selection_bound != priv->current_pos)
5344 gtk_editable_delete_selection (editable);
5350 case GTK_DELETE_CHARS:
5351 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5352 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5354 case GTK_DELETE_WORDS:
5357 /* Move to end of current word, or if not on a word, end of previous word */
5358 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5359 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5363 /* Move to beginning of current word, or if not on a word, begining of next word */
5364 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5365 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5369 case GTK_DELETE_WORD_ENDS:
5372 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5377 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5380 gtk_editable_delete_text (editable, start_pos, end_pos);
5382 case GTK_DELETE_DISPLAY_LINE_ENDS:
5383 case GTK_DELETE_PARAGRAPH_ENDS:
5385 gtk_editable_delete_text (editable, 0, priv->current_pos);
5387 gtk_editable_delete_text (editable, priv->current_pos, -1);
5389 case GTK_DELETE_DISPLAY_LINES:
5390 case GTK_DELETE_PARAGRAPHS:
5391 gtk_editable_delete_text (editable, 0, -1);
5393 case GTK_DELETE_WHITESPACE:
5394 gtk_entry_delete_whitespace (entry);
5398 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5399 gtk_widget_error_bell (GTK_WIDGET (entry));
5401 gtk_entry_pend_cursor_blink (entry);
5405 gtk_entry_backspace (GtkEntry *entry)
5407 GtkEntryPrivate *priv = entry->priv;
5408 GtkEditable *editable = GTK_EDITABLE (entry);
5411 gtk_entry_reset_im_context (entry);
5413 if (!priv->editable)
5415 gtk_widget_error_bell (GTK_WIDGET (entry));
5419 if (priv->selection_bound != priv->current_pos)
5421 gtk_editable_delete_selection (editable);
5425 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5427 if (prev_pos < priv->current_pos)
5429 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5430 PangoLogAttr *log_attrs;
5433 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5435 /* Deleting parts of characters */
5436 if (log_attrs[priv->current_pos].backspace_deletes_character)
5438 gchar *cluster_text;
5439 gchar *normalized_text;
5442 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5444 normalized_text = g_utf8_normalize (cluster_text,
5445 strlen (cluster_text),
5447 len = g_utf8_strlen (normalized_text, -1);
5449 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5452 gint pos = priv->current_pos;
5454 gtk_editable_insert_text (editable, normalized_text,
5455 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5457 gtk_editable_set_position (editable, pos);
5460 g_free (normalized_text);
5461 g_free (cluster_text);
5465 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5472 gtk_widget_error_bell (GTK_WIDGET (entry));
5475 gtk_entry_pend_cursor_blink (entry);
5479 gtk_entry_copy_clipboard (GtkEntry *entry)
5481 GtkEntryPrivate *priv = entry->priv;
5482 GtkEditable *editable = GTK_EDITABLE (entry);
5486 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5490 gtk_widget_error_bell (GTK_WIDGET (entry));
5494 str = _gtk_entry_get_display_text (entry, start, end);
5495 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5496 GDK_SELECTION_CLIPBOARD),
5503 gtk_entry_cut_clipboard (GtkEntry *entry)
5505 GtkEntryPrivate *priv = entry->priv;
5506 GtkEditable *editable = GTK_EDITABLE (entry);
5511 gtk_widget_error_bell (GTK_WIDGET (entry));
5515 gtk_entry_copy_clipboard (entry);
5519 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5520 gtk_editable_delete_text (editable, start, end);
5524 gtk_widget_error_bell (GTK_WIDGET (entry));
5527 gtk_entry_selection_bubble_popup_unset (entry);
5531 gtk_entry_paste_clipboard (GtkEntry *entry)
5533 GtkEntryPrivate *priv = entry->priv;
5536 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5538 gtk_widget_error_bell (GTK_WIDGET (entry));
5542 gtk_entry_delete_cb (GtkEntry *entry)
5544 GtkEntryPrivate *priv = entry->priv;
5545 GtkEditable *editable = GTK_EDITABLE (entry);
5550 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5551 gtk_editable_delete_text (editable, start, end);
5556 gtk_entry_toggle_overwrite (GtkEntry *entry)
5558 GtkEntryPrivate *priv = entry->priv;
5560 priv->overwrite_mode = !priv->overwrite_mode;
5561 gtk_entry_pend_cursor_blink (entry);
5562 gtk_widget_queue_draw (GTK_WIDGET (entry));
5566 gtk_entry_select_all (GtkEntry *entry)
5568 gtk_entry_select_line (entry);
5572 gtk_entry_real_activate (GtkEntry *entry)
5574 GtkEntryPrivate *priv = entry->priv;
5576 GtkWidget *default_widget, *focus_widget;
5577 GtkWidget *toplevel;
5580 widget = GTK_WIDGET (entry);
5582 if (priv->activates_default)
5584 toplevel = gtk_widget_get_toplevel (widget);
5585 if (GTK_IS_WINDOW (toplevel))
5587 window = GTK_WINDOW (toplevel);
5591 default_widget = gtk_window_get_default_widget (window);
5592 focus_widget = gtk_window_get_focus (window);
5593 if (widget != default_widget &&
5594 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5595 gtk_window_activate_default (window);
5602 keymap_direction_changed (GdkKeymap *keymap,
5605 gtk_entry_recompute (entry);
5608 /* IM Context Callbacks
5612 gtk_entry_commit_cb (GtkIMContext *context,
5616 GtkEntryPrivate *priv = entry->priv;
5619 gtk_entry_enter_text (entry, str);
5623 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5626 GtkEntryPrivate *priv = entry->priv;
5630 gchar *preedit_string;
5633 gtk_im_context_get_preedit_string (priv->im_context,
5634 &preedit_string, NULL,
5636 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5637 priv->preedit_length = strlen (preedit_string);
5638 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5639 priv->preedit_cursor = cursor_pos;
5640 g_free (preedit_string);
5642 gtk_entry_recompute (entry);
5647 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5650 GtkEntryPrivate *priv = entry->priv;
5653 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5654 text = _gtk_entry_get_display_text (entry, 0, -1);
5655 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5656 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5663 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5668 GtkEntryPrivate *priv = entry->priv;
5671 gtk_editable_delete_text (GTK_EDITABLE (entry),
5672 priv->current_pos + offset,
5673 priv->current_pos + offset + n_chars);
5678 /* Internal functions
5681 /* Used for im_commit_cb and inserting Unicode chars */
5683 gtk_entry_enter_text (GtkEntry *entry,
5686 GtkEntryPrivate *priv = entry->priv;
5687 GtkEditable *editable = GTK_EDITABLE (entry);
5689 gboolean old_need_im_reset;
5691 old_need_im_reset = priv->need_im_reset;
5692 priv->need_im_reset = FALSE;
5694 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5695 gtk_editable_delete_selection (editable);
5698 if (priv->overwrite_mode)
5699 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5702 tmp_pos = priv->current_pos;
5703 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5704 gtk_editable_set_position (editable, tmp_pos);
5706 priv->need_im_reset = old_need_im_reset;
5709 /* All changes to priv->current_pos and priv->selection_bound
5710 * should go through this function.
5713 gtk_entry_set_positions (GtkEntry *entry,
5715 gint selection_bound)
5717 GtkEntryPrivate *priv = entry->priv;
5718 gboolean changed = FALSE;
5720 g_object_freeze_notify (G_OBJECT (entry));
5722 if (current_pos != -1 &&
5723 priv->current_pos != current_pos)
5725 priv->current_pos = current_pos;
5728 g_object_notify (G_OBJECT (entry), "cursor-position");
5731 if (selection_bound != -1 &&
5732 priv->selection_bound != selection_bound)
5734 priv->selection_bound = selection_bound;
5737 g_object_notify (G_OBJECT (entry), "selection-bound");
5740 g_object_thaw_notify (G_OBJECT (entry));
5744 gtk_entry_move_adjustments (entry);
5745 gtk_entry_recompute (entry);
5750 gtk_entry_reset_layout (GtkEntry *entry)
5752 GtkEntryPrivate *priv = entry->priv;
5754 if (priv->cached_layout)
5756 g_object_unref (priv->cached_layout);
5757 priv->cached_layout = NULL;
5762 update_im_cursor_location (GtkEntry *entry)
5764 GtkEntryPrivate *priv = entry->priv;
5767 gint strong_xoffset;
5768 gint area_width, area_height;
5770 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5771 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5773 strong_xoffset = strong_x - priv->scroll_offset;
5774 if (strong_xoffset < 0)
5778 else if (strong_xoffset > area_width)
5780 strong_xoffset = area_width;
5782 area.x = strong_xoffset;
5785 area.height = area_height;
5787 gtk_im_context_set_cursor_location (priv->im_context, &area);
5791 recompute_idle_func (gpointer data)
5793 GtkEntry *entry = GTK_ENTRY (data);
5794 GtkEntryPrivate *priv = entry->priv;
5796 priv->recompute_idle = 0;
5798 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5800 GtkTextHandleMode handle_mode;
5802 gtk_entry_adjust_scroll (entry);
5803 gtk_widget_queue_draw (GTK_WIDGET (entry));
5805 update_im_cursor_location (entry);
5807 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
5809 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
5810 gtk_entry_update_handles (entry, handle_mode);
5817 gtk_entry_recompute (GtkEntry *entry)
5819 GtkEntryPrivate *priv = entry->priv;
5821 gtk_entry_reset_layout (entry);
5822 gtk_entry_check_cursor_blink (entry);
5824 if (!priv->recompute_idle)
5826 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5827 recompute_idle_func, entry, NULL);
5832 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5835 GtkWidget *widget = GTK_WIDGET (entry);
5836 GtkStyleContext *context;
5837 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5839 context = gtk_widget_get_style_context (widget);
5840 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5842 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5843 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5844 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5847 static inline gboolean
5848 show_placeholder_text (GtkEntry *entry)
5850 GtkEntryPrivate *priv = entry->priv;
5852 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5853 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5854 priv->placeholder_text != NULL)
5860 static PangoLayout *
5861 gtk_entry_create_layout (GtkEntry *entry,
5862 gboolean include_preedit)
5864 GtkEntryPrivate *priv = entry->priv;
5865 GtkWidget *widget = GTK_WIDGET (entry);
5866 PangoLayout *layout;
5867 PangoAttrList *tmp_attrs;
5868 gboolean placeholder_layout;
5870 gchar *preedit_string = NULL;
5871 gint preedit_length = 0;
5872 PangoAttrList *preedit_attrs = NULL;
5877 layout = gtk_widget_create_pango_layout (widget, NULL);
5878 pango_layout_set_single_paragraph_mode (layout, TRUE);
5880 tmp_attrs = priv->attrs ? pango_attr_list_ref (priv->attrs)
5881 : pango_attr_list_new ();
5883 placeholder_layout = show_placeholder_text (entry);
5884 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5885 n_bytes = strlen (display);
5887 if (!placeholder_layout && include_preedit)
5889 gtk_im_context_get_preedit_string (priv->im_context,
5890 &preedit_string, &preedit_attrs, NULL);
5891 preedit_length = priv->preedit_length;
5893 else if (placeholder_layout)
5896 PangoAttribute *attr;
5898 gtk_entry_get_placeholder_text_color (entry, &color);
5899 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5900 attr->start_index = 0;
5901 attr->end_index = G_MAXINT;
5902 pango_attr_list_insert (tmp_attrs, attr);
5907 GString *tmp_string = g_string_new (display);
5908 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5910 g_string_insert (tmp_string, cursor_index, preedit_string);
5911 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5912 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5913 cursor_index, preedit_length);
5914 g_string_free (tmp_string, TRUE);
5918 PangoDirection pango_dir;
5920 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5921 pango_dir = pango_find_base_dir (display, n_bytes);
5923 pango_dir = PANGO_DIRECTION_NEUTRAL;
5925 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5927 if (gtk_widget_has_focus (widget))
5929 GdkDisplay *display = gtk_widget_get_display (widget);
5930 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5931 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5932 pango_dir = PANGO_DIRECTION_RTL;
5934 pango_dir = PANGO_DIRECTION_LTR;
5938 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5939 pango_dir = PANGO_DIRECTION_RTL;
5941 pango_dir = PANGO_DIRECTION_LTR;
5945 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5948 priv->resolved_dir = pango_dir;
5950 pango_layout_set_text (layout, display, n_bytes);
5953 pango_layout_set_attributes (layout, tmp_attrs);
5955 g_free (preedit_string);
5959 pango_attr_list_unref (preedit_attrs);
5961 pango_attr_list_unref (tmp_attrs);
5966 static PangoLayout *
5967 gtk_entry_ensure_layout (GtkEntry *entry,
5968 gboolean include_preedit)
5970 GtkEntryPrivate *priv = entry->priv;
5972 if (priv->preedit_length > 0 &&
5973 !include_preedit != !priv->cache_includes_preedit)
5974 gtk_entry_reset_layout (entry);
5976 if (!priv->cached_layout)
5978 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5979 priv->cache_includes_preedit = include_preedit;
5982 return priv->cached_layout;
5986 get_layout_position (GtkEntry *entry,
5990 GtkEntryPrivate *priv = entry->priv;
5991 PangoLayout *layout;
5992 PangoRectangle logical_rect;
5993 gint area_width, area_height;
5995 PangoLayoutLine *line;
5997 layout = gtk_entry_ensure_layout (entry, TRUE);
5999 get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
6000 area_height = PANGO_SCALE * area_height;
6002 line = pango_layout_get_lines_readonly (layout)->data;
6003 pango_layout_line_get_extents (line, NULL, &logical_rect);
6005 /* Align primarily for locale's ascent/descent */
6006 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
6007 priv->ascent + logical_rect.y);
6009 /* Now see if we need to adjust to fit in actual drawn string */
6010 if (logical_rect.height > area_height)
6011 y_pos = (area_height - logical_rect.height) / 2;
6014 else if (y_pos + logical_rect.height > area_height)
6015 y_pos = area_height - logical_rect.height;
6017 y_pos = y_pos / PANGO_SCALE;
6020 *x = - priv->scroll_offset;
6027 draw_text_with_color (GtkEntry *entry,
6029 GdkRGBA *default_color)
6031 GtkEntryPrivate *priv = entry->priv;
6032 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6035 gint start_pos, end_pos;
6037 widget = GTK_WIDGET (entry);
6041 get_layout_position (entry, &x, &y);
6043 cairo_move_to (cr, x, y);
6044 gdk_cairo_set_source_rgba (cr, default_color);
6045 pango_cairo_show_layout (cr, layout);
6047 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
6051 PangoRectangle logical_rect;
6052 GdkRGBA selection_color, text_color;
6053 GtkStyleContext *context;
6054 GtkStateFlags state;
6056 context = gtk_widget_get_style_context (widget);
6057 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
6058 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
6060 state = gtk_widget_get_state_flags (widget);
6061 state |= GTK_STATE_FLAG_SELECTED;
6063 gtk_style_context_get_background_color (context, state, &selection_color);
6064 gtk_style_context_get_color (context, state, &text_color);
6066 for (i = 0; i < n_ranges; ++i)
6067 cairo_rectangle (cr,
6068 - priv->scroll_offset + ranges[2 * i],
6071 logical_rect.height);
6075 gdk_cairo_set_source_rgba (cr, &selection_color);
6078 cairo_move_to (cr, x, y);
6079 gdk_cairo_set_source_rgba (cr, &text_color);
6080 pango_cairo_show_layout (cr, layout);
6088 gtk_entry_draw_text (GtkEntry *entry,
6091 GtkEntryPrivate *priv = entry->priv;
6092 GtkWidget *widget = GTK_WIDGET (entry);
6093 GtkStateFlags state = 0;
6094 GdkRGBA text_color, bar_text_color;
6095 GtkStyleContext *context;
6097 gint progress_x, progress_y, progress_width, progress_height;
6098 gint clip_width, clip_height;
6100 /* Nothing to display at all */
6101 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
6104 state = gtk_widget_get_state_flags (widget);
6105 context = gtk_widget_get_style_context (widget);
6107 gtk_style_context_get_color (context, state, &text_color);
6109 /* Get foreground color for progressbars */
6110 gtk_entry_prepare_context_for_progress (entry, context);
6111 gtk_style_context_get_color (context, state, &bar_text_color);
6112 gtk_style_context_restore (context);
6114 get_progress_area (widget,
6115 &progress_x, &progress_y,
6116 &progress_width, &progress_height);
6120 clip_width = gdk_window_get_width (priv->text_area);
6121 clip_height = gdk_window_get_height (priv->text_area);
6122 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
6125 /* If the color is the same, or the progress area has a zero
6126 * size, then we only need to draw once. */
6127 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
6128 ((progress_width == 0) || (progress_height == 0)))
6130 draw_text_with_color (entry, cr, &text_color);
6134 int frame_x, frame_y, area_x, area_y;
6136 width = gdk_window_get_width (priv->text_area);
6137 height = gdk_window_get_height (priv->text_area);
6141 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
6142 cairo_rectangle (cr, 0, 0, width, height);
6144 /* progres area is frame-relative, we need it text-area window
6146 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
6147 gdk_window_get_position (priv->text_area, &area_x, &area_y);
6148 progress_x += frame_x - area_x;
6149 progress_y += frame_y - area_y;
6151 cairo_rectangle (cr, progress_x, progress_y,
6152 progress_width, progress_height);
6154 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
6156 draw_text_with_color (entry, cr, &text_color);
6161 cairo_rectangle (cr, progress_x, progress_y,
6162 progress_width, progress_height);
6165 draw_text_with_color (entry, cr, &bar_text_color);
6174 gtk_entry_draw_cursor (GtkEntry *entry,
6178 GtkEntryPrivate *priv = entry->priv;
6179 GtkWidget *widget = GTK_WIDGET (entry);
6180 GtkStyleContext *context;
6181 PangoRectangle cursor_rect;
6184 gboolean block_at_line_end;
6185 PangoLayout *layout;
6189 context = gtk_widget_get_style_context (widget);
6191 layout = gtk_entry_ensure_layout (entry, TRUE);
6192 text = pango_layout_get_text (layout);
6193 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6194 get_layout_position (entry, &x, &y);
6196 if (!priv->overwrite_mode)
6199 block = _gtk_text_util_get_block_cursor_location (layout,
6200 cursor_index, &cursor_rect, &block_at_line_end);
6204 gtk_render_insertion_cursor (context, cr,
6206 layout, cursor_index, priv->resolved_dir);
6208 else /* overwrite_mode */
6210 GdkRGBA cursor_color;
6215 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
6216 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
6217 rect.width = PANGO_PIXELS (cursor_rect.width);
6218 rect.height = PANGO_PIXELS (cursor_rect.height);
6220 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
6221 gdk_cairo_set_source_rgba (cr, &cursor_color);
6222 gdk_cairo_rectangle (cr, &rect);
6225 if (!block_at_line_end)
6227 GtkStateFlags state;
6230 state = gtk_widget_get_state_flags (widget);
6231 gtk_style_context_get_background_color (context, state, &color);
6233 gdk_cairo_rectangle (cr, &rect);
6235 cairo_move_to (cr, x, y);
6236 gdk_cairo_set_source_rgba (cr, &color);
6237 pango_cairo_show_layout (cr, layout);
6245 gtk_entry_handle_dragged (GtkTextHandle *handle,
6246 GtkTextHandlePosition pos,
6251 gint cursor_pos, selection_bound_pos, tmp_pos;
6252 GtkEntryPrivate *priv = entry->priv;
6253 GtkTextHandleMode mode;
6256 gtk_entry_selection_bubble_popup_unset (entry);
6258 cursor_pos = priv->current_pos;
6259 selection_bound_pos = priv->selection_bound;
6260 mode = _gtk_text_handle_get_mode (handle);
6261 tmp_pos = gtk_entry_find_position (entry, x + priv->scroll_offset);
6263 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR ||
6264 cursor_pos >= selection_bound_pos)
6267 min = &selection_bound_pos;
6271 max = &selection_bound_pos;
6275 if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
6277 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6281 min_pos = MAX (*min + 1, 0);
6282 tmp_pos = MAX (tmp_pos, min_pos);
6289 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6294 *min = MIN (tmp_pos, max_pos);
6298 if (cursor_pos != priv->current_pos ||
6299 selection_bound_pos != priv->selection_bound)
6301 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
6302 gtk_entry_set_positions (entry, cursor_pos, cursor_pos);
6304 gtk_entry_set_positions (entry, cursor_pos, selection_bound_pos);
6306 gtk_entry_update_handles (entry, mode);
6311 gtk_entry_handle_drag_finished (GtkTextHandle *handle,
6312 GtkTextHandlePosition pos,
6315 gtk_entry_selection_bubble_popup_set (entry);
6320 * gtk_entry_reset_im_context:
6321 * @entry: a #GtkEntry
6323 * Reset the input method context of the entry if needed.
6325 * This can be necessary in the case where modifying the buffer
6326 * would confuse on-going input method behavior.
6331 gtk_entry_reset_im_context (GtkEntry *entry)
6333 GtkEntryPrivate *priv = entry->priv;
6335 g_return_if_fail (GTK_IS_ENTRY (entry));
6337 if (priv->need_im_reset)
6339 priv->need_im_reset = FALSE;
6340 gtk_im_context_reset (priv->im_context);
6345 * gtk_entry_im_context_filter_keypress:
6346 * @entry: a #GtkEntry
6347 * @event: (type Gdk.EventKey): the key event
6349 * Allow the #GtkEntry input method to internally handle key press
6350 * and release events. If this function returns %TRUE, then no further
6351 * processing should be done for this key event. See
6352 * gtk_im_context_filter_keypress().
6354 * Note that you are expected to call this function from your handler
6355 * when overriding key event handling. This is needed in the case when
6356 * you need to insert your own key handling between the input method
6357 * and the default key event handling of the #GtkEntry.
6358 * See gtk_text_view_reset_im_context() for an example of use.
6360 * Return value: %TRUE if the input method handled the key event.
6365 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6368 GtkEntryPrivate *priv;
6370 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6374 return gtk_im_context_filter_keypress (priv->im_context, event);
6378 _gtk_entry_get_im_context (GtkEntry *entry)
6380 return entry->priv->im_context;
6384 gtk_entry_find_position (GtkEntry *entry,
6387 GtkEntryPrivate *priv = entry->priv;
6388 PangoLayout *layout;
6389 PangoLayoutLine *line;
6396 layout = gtk_entry_ensure_layout (entry, TRUE);
6397 text = pango_layout_get_text (layout);
6398 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6400 line = pango_layout_get_lines_readonly (layout)->data;
6401 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6403 if (index >= cursor_index && priv->preedit_length)
6405 if (index >= cursor_index + priv->preedit_length)
6406 index -= priv->preedit_length;
6409 index = cursor_index;
6414 pos = g_utf8_pointer_to_offset (text, text + index);
6421 gtk_entry_get_cursor_locations (GtkEntry *entry,
6426 GtkEntryPrivate *priv = entry->priv;
6427 DisplayMode mode = gtk_entry_get_display_mode (entry);
6429 /* Nothing to display at all, so no cursor is relevant */
6430 if (mode == DISPLAY_BLANK)
6440 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6441 const gchar *text = pango_layout_get_text (layout);
6442 PangoRectangle strong_pos, weak_pos;
6445 if (type == CURSOR_STANDARD)
6447 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6449 else /* type == CURSOR_DND */
6451 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6453 if (priv->dnd_position > priv->current_pos)
6455 if (mode == DISPLAY_NORMAL)
6456 index += priv->preedit_length;
6459 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6460 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6465 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6468 *strong_x = strong_pos.x / PANGO_SCALE;
6471 *weak_x = weak_pos.x / PANGO_SCALE;
6476 gtk_entry_get_is_selection_handle_dragged (GtkEntry *entry)
6478 GtkEntryPrivate *priv = entry->priv;
6479 GtkTextHandlePosition pos;
6481 if (_gtk_text_handle_get_mode (priv->text_handle) != GTK_TEXT_HANDLE_MODE_SELECTION)
6484 if (priv->current_pos >= priv->selection_bound)
6485 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
6487 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
6489 return _gtk_text_handle_get_is_dragged (priv->text_handle, pos);
6493 gtk_entry_adjust_scroll (GtkEntry *entry)
6495 GtkEntryPrivate *priv = entry->priv;
6496 gint min_offset, max_offset;
6497 gint text_area_width, text_width;
6498 gint strong_x, weak_x;
6499 gint strong_xoffset, weak_xoffset;
6501 PangoLayout *layout;
6502 PangoLayoutLine *line;
6503 PangoRectangle logical_rect;
6504 GtkTextHandleMode handle_mode;
6506 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6509 text_area_width = gdk_window_get_width (priv->text_area);
6511 if (text_area_width < 0)
6512 text_area_width = 0;
6514 layout = gtk_entry_ensure_layout (entry, TRUE);
6515 line = pango_layout_get_lines_readonly (layout)->data;
6517 pango_layout_line_get_extents (line, NULL, &logical_rect);
6519 /* Display as much text as we can */
6521 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6522 xalign = priv->xalign;
6524 xalign = 1.0 - priv->xalign;
6526 text_width = PANGO_PIXELS(logical_rect.width);
6528 if (text_width > text_area_width)
6531 max_offset = text_width - text_area_width;
6535 min_offset = (text_width - text_area_width) * xalign;
6536 max_offset = min_offset;
6539 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6541 if (gtk_entry_get_is_selection_handle_dragged (entry))
6543 /* The text handle corresponding to the selection bound is
6544 * being dragged, ensure it stays onscreen even if we scroll
6545 * cursors away, this is so both handles can cause content
6548 strong_x = weak_x = gtk_entry_get_selection_bound_location (entry);
6552 /* And make sure cursors are on screen. Note that the cursor is
6553 * actually drawn one pixel into the INNER_BORDER space on
6554 * the right, when the scroll is at the utmost right. This
6555 * looks better to to me than confining the cursor inside the
6556 * border entirely, though it means that the cursor gets one
6557 * pixel closer to the edge of the widget on the right than
6558 * on the left. This might need changing if one changed
6559 * INNER_BORDER from 2 to 1, as one would do on a
6560 * small-screen-real-estate display.
6562 * We always make sure that the strong cursor is on screen, and
6563 * put the weak cursor on screen if possible.
6565 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6568 strong_xoffset = strong_x - priv->scroll_offset;
6570 if (strong_xoffset < 0)
6572 priv->scroll_offset += strong_xoffset;
6575 else if (strong_xoffset > text_area_width)
6577 priv->scroll_offset += strong_xoffset - text_area_width;
6578 strong_xoffset = text_area_width;
6581 weak_xoffset = weak_x - priv->scroll_offset;
6583 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6585 priv->scroll_offset += weak_xoffset;
6587 else if (weak_xoffset > text_area_width &&
6588 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6590 priv->scroll_offset += weak_xoffset - text_area_width;
6593 g_object_notify (G_OBJECT (entry), "scroll-offset");
6595 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
6597 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
6598 gtk_entry_update_handles (entry, handle_mode);
6602 gtk_entry_move_adjustments (GtkEntry *entry)
6604 GtkWidget *widget = GTK_WIDGET (entry);
6605 GtkAllocation allocation;
6606 GtkAdjustment *adjustment;
6607 PangoContext *context;
6608 PangoFontMetrics *metrics;
6613 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6617 gtk_widget_get_allocation (widget, &allocation);
6619 /* Cursor/char position, layout offset, border width, and widget allocation */
6620 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6621 get_layout_position (entry, &layout_x, NULL);
6622 _gtk_entry_get_borders (entry, &borders);
6623 x += allocation.x + layout_x + borders.left;
6625 /* Approximate width of a char, so user can see what is ahead/behind */
6626 context = gtk_widget_get_pango_context (widget);
6628 metrics = pango_context_get_metrics (context,
6629 pango_context_get_font_description (context),
6630 pango_context_get_language (context));
6631 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6634 gtk_adjustment_clamp_page (adjustment,
6635 x - (char_width + 1), /* one char + one pixel before */
6636 x + (char_width + 2)); /* one char + cursor + one pixel after */
6640 gtk_entry_move_visually (GtkEntry *entry,
6644 GtkEntryPrivate *priv = entry->priv;
6646 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6649 text = pango_layout_get_text (layout);
6651 index = g_utf8_offset_to_pointer (text, start) - text;
6655 int new_index, new_trailing;
6656 gboolean split_cursor;
6659 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6660 "gtk-split-cursor", &split_cursor,
6667 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6668 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6670 strong = keymap_direction == priv->resolved_dir;
6675 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6680 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6686 else if (new_index != G_MAXINT)
6689 while (new_trailing--)
6690 index = g_utf8_next_char (text + index) - text;
6693 return g_utf8_pointer_to_offset (text, text + index);
6697 gtk_entry_move_logically (GtkEntry *entry,
6701 gint new_pos = start;
6704 length = gtk_entry_buffer_get_length (get_buffer (entry));
6706 /* Prevent any leak of information */
6707 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6709 new_pos = CLAMP (start + count, 0, length);
6713 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6714 PangoLogAttr *log_attrs;
6717 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6719 while (count > 0 && new_pos < length)
6723 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6727 while (count < 0 && new_pos > 0)
6731 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6743 gtk_entry_move_forward_word (GtkEntry *entry,
6745 gboolean allow_whitespace)
6747 gint new_pos = start;
6750 length = gtk_entry_buffer_get_length (get_buffer (entry));
6752 /* Prevent any leak of information */
6753 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6757 else if (new_pos < length)
6759 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6760 PangoLogAttr *log_attrs;
6763 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6765 /* Find the next word boundary */
6767 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6768 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6779 gtk_entry_move_backward_word (GtkEntry *entry,
6781 gboolean allow_whitespace)
6783 gint new_pos = start;
6785 /* Prevent any leak of information */
6786 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6792 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6793 PangoLogAttr *log_attrs;
6796 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6798 new_pos = start - 1;
6800 /* Find the previous word boundary */
6801 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6802 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6812 gtk_entry_delete_whitespace (GtkEntry *entry)
6814 GtkEntryPrivate *priv = entry->priv;
6815 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6816 PangoLogAttr *log_attrs;
6820 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6822 start = end = priv->current_pos;
6824 while (start > 0 && log_attrs[start-1].is_white)
6827 while (end < n_attrs && log_attrs[end].is_white)
6833 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6838 gtk_entry_select_word (GtkEntry *entry)
6840 GtkEntryPrivate *priv = entry->priv;
6841 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6842 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6844 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6848 gtk_entry_select_line (GtkEntry *entry)
6850 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6854 truncate_multiline (const gchar *text)
6859 text[length] && text[length] != '\n' && text[length] != '\r';
6866 paste_received (GtkClipboard *clipboard,
6870 GtkEntry *entry = GTK_ENTRY (data);
6871 GtkEditable *editable = GTK_EDITABLE (entry);
6872 GtkEntryPrivate *priv = entry->priv;
6874 if (priv->button == GDK_BUTTON_MIDDLE)
6876 gint pos, start, end;
6877 pos = priv->insert_pos;
6878 gtk_editable_get_selection_bounds (editable, &start, &end);
6879 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6880 gtk_editable_select_region (editable, pos, pos);
6885 gint pos, start, end;
6887 gboolean popup_completion;
6888 GtkEntryCompletion *completion;
6890 completion = gtk_entry_get_completion (entry);
6892 if (priv->truncate_multiline)
6893 length = truncate_multiline (text);
6895 /* only complete if the selection is at the end */
6896 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6897 MAX (priv->current_pos, priv->selection_bound));
6901 if (gtk_widget_get_mapped (completion->priv->popup_window))
6902 _gtk_entry_completion_popdown (completion);
6904 if (!popup_completion && completion->priv->changed_id > 0)
6905 g_signal_handler_block (entry, completion->priv->changed_id);
6908 begin_change (entry);
6909 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6910 gtk_editable_delete_text (editable, start, end);
6912 pos = priv->current_pos;
6913 gtk_editable_insert_text (editable, text, length, &pos);
6914 gtk_editable_set_position (editable, pos);
6918 !popup_completion && completion->priv->changed_id > 0)
6919 g_signal_handler_unblock (entry, completion->priv->changed_id);
6922 g_object_unref (entry);
6926 gtk_entry_paste (GtkEntry *entry,
6929 g_object_ref (entry);
6930 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6931 paste_received, entry);
6935 primary_get_cb (GtkClipboard *clipboard,
6936 GtkSelectionData *selection_data,
6940 GtkEntry *entry = GTK_ENTRY (data);
6943 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6945 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6946 gtk_selection_data_set_text (selection_data, str, -1);
6952 primary_clear_cb (GtkClipboard *clipboard,
6955 GtkEntry *entry = GTK_ENTRY (data);
6956 GtkEntryPrivate *priv = entry->priv;
6958 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6962 gtk_entry_update_primary_selection (GtkEntry *entry)
6964 GtkTargetList *list;
6965 GtkTargetEntry *targets;
6966 GtkClipboard *clipboard;
6970 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6973 list = gtk_target_list_new (NULL, 0);
6974 gtk_target_list_add_text_targets (list, 0);
6976 targets = gtk_target_table_new_from_list (list, &n_targets);
6978 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6980 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6982 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6983 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6984 primary_clear_cb (clipboard, entry);
6988 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6989 gtk_clipboard_clear (clipboard);
6992 gtk_target_table_free (targets, n_targets);
6993 gtk_target_list_unref (list);
6997 gtk_entry_clear (GtkEntry *entry,
6998 GtkEntryIconPosition icon_pos)
7000 GtkEntryPrivate *priv = entry->priv;
7001 EntryIconInfo *icon_info = priv->icons[icon_pos];
7002 GtkImageType storage_type;
7004 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
7007 g_object_freeze_notify (G_OBJECT (entry));
7009 /* Explicitly check, as the pointer may become invalidated
7010 * during destruction.
7012 if (GDK_IS_WINDOW (icon_info->window))
7013 gdk_window_hide (icon_info->window);
7015 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
7017 switch (storage_type)
7019 case GTK_IMAGE_PIXBUF:
7020 g_object_notify (G_OBJECT (entry),
7021 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
7024 case GTK_IMAGE_STOCK:
7025 g_object_notify (G_OBJECT (entry),
7026 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
7029 case GTK_IMAGE_ICON_NAME:
7030 g_object_notify (G_OBJECT (entry),
7031 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
7034 case GTK_IMAGE_GICON:
7035 g_object_notify (G_OBJECT (entry),
7036 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
7040 g_assert_not_reached ();
7044 _gtk_icon_helper_clear (icon_info->icon_helper);
7046 g_object_notify (G_OBJECT (entry),
7047 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
7049 g_object_thaw_notify (G_OBJECT (entry));
7053 gtk_entry_ensure_pixbuf (GtkEntry *entry,
7054 GtkEntryIconPosition icon_pos)
7056 GtkEntryPrivate *priv = entry->priv;
7057 EntryIconInfo *icon_info = priv->icons[icon_pos];
7058 GtkStyleContext *context;
7061 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
7062 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
7064 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
7067 gtk_style_context_restore (context);
7078 * Creates a new entry.
7080 * Return value: a new #GtkEntry.
7083 gtk_entry_new (void)
7085 return g_object_new (GTK_TYPE_ENTRY, NULL);
7089 * gtk_entry_new_with_buffer:
7090 * @buffer: The buffer to use for the new #GtkEntry.
7092 * Creates a new entry with the specified text buffer.
7094 * Return value: a new #GtkEntry
7099 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
7101 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
7102 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
7105 static GtkEntryBuffer*
7106 get_buffer (GtkEntry *entry)
7108 GtkEntryPrivate *priv = entry->priv;
7110 if (priv->buffer == NULL)
7112 GtkEntryBuffer *buffer;
7113 buffer = gtk_entry_buffer_new (NULL, 0);
7114 gtk_entry_set_buffer (entry, buffer);
7115 g_object_unref (buffer);
7118 return priv->buffer;
7122 * gtk_entry_get_buffer:
7123 * @entry: a #GtkEntry
7125 * Get the #GtkEntryBuffer object which holds the text for
7130 * Returns: (transfer none): A #GtkEntryBuffer object.
7133 gtk_entry_get_buffer (GtkEntry *entry)
7135 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7137 return get_buffer (entry);
7141 * gtk_entry_set_buffer:
7142 * @entry: a #GtkEntry
7143 * @buffer: a #GtkEntryBuffer
7145 * Set the #GtkEntryBuffer object which holds the text for
7151 gtk_entry_set_buffer (GtkEntry *entry,
7152 GtkEntryBuffer *buffer)
7154 GtkEntryPrivate *priv;
7157 g_return_if_fail (GTK_IS_ENTRY (entry));
7163 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
7164 g_object_ref (buffer);
7169 buffer_disconnect_signals (entry);
7170 g_object_unref (priv->buffer);
7173 priv->buffer = buffer;
7176 buffer_connect_signals (entry);
7178 obj = G_OBJECT (entry);
7179 g_object_freeze_notify (obj);
7180 g_object_notify (obj, "buffer");
7181 g_object_notify (obj, "text");
7182 g_object_notify (obj, "text-length");
7183 g_object_notify (obj, "max-length");
7184 g_object_notify (obj, "visibility");
7185 g_object_notify (obj, "invisible-char");
7186 g_object_notify (obj, "invisible-char-set");
7187 g_object_thaw_notify (obj);
7189 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7190 gtk_entry_recompute (entry);
7194 * gtk_entry_get_text_area:
7195 * @entry: a #GtkEntry
7196 * @text_area: (out): Return location for the text area.
7198 * Gets the area where the entry's text is drawn. This function is
7199 * useful when drawing something to the entry in a draw callback.
7201 * If the entry is not realized, @text_area is filled with zeros.
7203 * See also gtk_entry_get_icon_area().
7208 gtk_entry_get_text_area (GtkEntry *entry,
7209 GdkRectangle *text_area)
7211 GtkEntryPrivate *priv;
7213 g_return_if_fail (GTK_IS_ENTRY (entry));
7214 g_return_if_fail (text_area != NULL);
7218 if (priv->text_area)
7220 GtkAllocation allocation;
7223 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7224 gdk_window_get_position (priv->text_area, &x, &y);
7226 text_area->x = x - allocation.x;
7227 text_area->y = y - allocation.y;
7228 text_area->width = gdk_window_get_width (priv->text_area);
7229 text_area->height = gdk_window_get_height (priv->text_area);
7235 text_area->width = 0;
7236 text_area->height = 0;
7241 * gtk_entry_set_text:
7242 * @entry: a #GtkEntry
7243 * @text: the new text
7245 * Sets the text in the widget to the given
7246 * value, replacing the current contents.
7248 * See gtk_entry_buffer_set_text().
7251 gtk_entry_set_text (GtkEntry *entry,
7255 GtkEntryCompletion *completion;
7257 g_return_if_fail (GTK_IS_ENTRY (entry));
7258 g_return_if_fail (text != NULL);
7260 /* Actually setting the text will affect the cursor and selection;
7261 * if the contents don't actually change, this will look odd to the user.
7263 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7266 completion = gtk_entry_get_completion (entry);
7267 if (completion && completion->priv->changed_id > 0)
7268 g_signal_handler_block (entry, completion->priv->changed_id);
7270 begin_change (entry);
7271 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7273 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7276 if (completion && completion->priv->changed_id > 0)
7277 g_signal_handler_unblock (entry, completion->priv->changed_id);
7281 * gtk_entry_set_visibility:
7282 * @entry: a #GtkEntry
7283 * @visible: %TRUE if the contents of the entry are displayed
7286 * Sets whether the contents of the entry are visible or not.
7287 * When visibility is set to %FALSE, characters are displayed
7288 * as the invisible char, and will also appear that way when
7289 * the text in the entry widget is copied elsewhere.
7291 * By default, GTK+ picks the best invisible character available
7292 * in the current font, but it can be changed with
7293 * gtk_entry_set_invisible_char().
7295 * Note that you probably want to set #GtkEntry:input-purpose
7296 * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
7297 * inform input methods about the purpose of this entry,
7298 * in addition to setting visibility to %FALSE.
7301 gtk_entry_set_visibility (GtkEntry *entry,
7304 GtkEntryPrivate *priv;
7306 g_return_if_fail (GTK_IS_ENTRY (entry));
7310 visible = visible != FALSE;
7312 if (priv->visible != visible)
7314 priv->visible = visible;
7316 g_object_notify (G_OBJECT (entry), "visibility");
7317 gtk_entry_recompute (entry);
7322 * gtk_entry_get_visibility:
7323 * @entry: a #GtkEntry
7325 * Retrieves whether the text in @entry is visible. See
7326 * gtk_entry_set_visibility().
7328 * Return value: %TRUE if the text is currently visible
7331 gtk_entry_get_visibility (GtkEntry *entry)
7333 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7335 return entry->priv->visible;
7339 * gtk_entry_set_invisible_char:
7340 * @entry: a #GtkEntry
7341 * @ch: a Unicode character
7343 * Sets the character to use in place of the actual text when
7344 * gtk_entry_set_visibility() has been called to set text visibility
7345 * to %FALSE. i.e. this is the character used in "password mode" to
7346 * show the user how many characters have been typed. By default, GTK+
7347 * picks the best invisible char available in the current font. If you
7348 * set the invisible char to 0, then the user will get no feedback
7349 * at all; there will be no text on the screen as they type.
7352 gtk_entry_set_invisible_char (GtkEntry *entry,
7355 GtkEntryPrivate *priv;
7357 g_return_if_fail (GTK_IS_ENTRY (entry));
7361 if (!priv->invisible_char_set)
7363 priv->invisible_char_set = TRUE;
7364 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7367 if (ch == priv->invisible_char)
7370 priv->invisible_char = ch;
7371 g_object_notify (G_OBJECT (entry), "invisible-char");
7372 gtk_entry_recompute (entry);
7376 * gtk_entry_get_invisible_char:
7377 * @entry: a #GtkEntry
7379 * Retrieves the character displayed in place of the real characters
7380 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7382 * Return value: the current invisible char, or 0, if the entry does not
7383 * show invisible text at all.
7386 gtk_entry_get_invisible_char (GtkEntry *entry)
7388 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7390 return entry->priv->invisible_char;
7394 * gtk_entry_unset_invisible_char:
7395 * @entry: a #GtkEntry
7397 * Unsets the invisible char previously set with
7398 * gtk_entry_set_invisible_char(). So that the
7399 * default invisible char is used again.
7404 gtk_entry_unset_invisible_char (GtkEntry *entry)
7406 GtkEntryPrivate *priv;
7409 g_return_if_fail (GTK_IS_ENTRY (entry));
7413 if (!priv->invisible_char_set)
7416 priv->invisible_char_set = FALSE;
7417 ch = find_invisible_char (GTK_WIDGET (entry));
7419 if (priv->invisible_char != ch)
7421 priv->invisible_char = ch;
7422 g_object_notify (G_OBJECT (entry), "invisible-char");
7425 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7426 gtk_entry_recompute (entry);
7430 * gtk_entry_set_overwrite_mode:
7431 * @entry: a #GtkEntry
7432 * @overwrite: new value
7434 * Sets whether the text is overwritten when typing in the #GtkEntry.
7439 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7442 GtkEntryPrivate *priv = entry->priv;
7444 g_return_if_fail (GTK_IS_ENTRY (entry));
7446 if (priv->overwrite_mode == overwrite)
7449 gtk_entry_toggle_overwrite (entry);
7451 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7455 * gtk_entry_get_overwrite_mode:
7456 * @entry: a #GtkEntry
7458 * Gets the value set by gtk_entry_set_overwrite_mode().
7460 * Return value: whether the text is overwritten when typing.
7465 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7467 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7469 return entry->priv->overwrite_mode;
7473 * gtk_entry_get_text:
7474 * @entry: a #GtkEntry
7476 * Retrieves the contents of the entry widget.
7477 * See also gtk_editable_get_chars().
7479 * This is equivalent to:
7481 * <informalexample><programlisting>
7482 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7483 * </programlisting></informalexample>
7485 * Return value: a pointer to the contents of the widget as a
7486 * string. This string points to internally allocated
7487 * storage in the widget and must not be freed, modified or
7491 gtk_entry_get_text (GtkEntry *entry)
7493 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7495 return gtk_entry_buffer_get_text (get_buffer (entry));
7499 * gtk_entry_set_max_length:
7500 * @entry: a #GtkEntry
7501 * @max: the maximum length of the entry, or 0 for no maximum.
7502 * (other than the maximum length of entries.) The value passed in will
7503 * be clamped to the range 0-65536.
7505 * Sets the maximum allowed length of the contents of the widget. If
7506 * the current contents are longer than the given length, then they
7507 * will be truncated to fit.
7509 * This is equivalent to:
7511 * <informalexample><programlisting>
7512 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7513 * </programlisting></informalexample>
7516 gtk_entry_set_max_length (GtkEntry *entry,
7519 g_return_if_fail (GTK_IS_ENTRY (entry));
7520 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7524 * gtk_entry_get_max_length:
7525 * @entry: a #GtkEntry
7527 * Retrieves the maximum allowed length of the text in
7528 * @entry. See gtk_entry_set_max_length().
7530 * This is equivalent to:
7532 * <informalexample><programlisting>
7533 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7534 * </programlisting></informalexample>
7536 * Return value: the maximum allowed number of characters
7537 * in #GtkEntry, or 0 if there is no maximum.
7540 gtk_entry_get_max_length (GtkEntry *entry)
7542 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7544 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7548 * gtk_entry_get_text_length:
7549 * @entry: a #GtkEntry
7551 * Retrieves the current length of the text in
7554 * This is equivalent to:
7556 * <informalexample><programlisting>
7557 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7558 * </programlisting></informalexample>
7560 * Return value: the current number of characters
7561 * in #GtkEntry, or 0 if there are none.
7566 gtk_entry_get_text_length (GtkEntry *entry)
7568 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7570 return gtk_entry_buffer_get_length (get_buffer (entry));
7574 * gtk_entry_set_activates_default:
7575 * @entry: a #GtkEntry
7576 * @setting: %TRUE to activate window's default widget on Enter keypress
7578 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7579 * widget for the window containing the entry. This usually means that
7580 * the dialog box containing the entry will be closed, since the default
7581 * widget is usually one of the dialog buttons.
7583 * (For experts: if @setting is %TRUE, the entry calls
7584 * gtk_window_activate_default() on the window containing the entry, in
7585 * the default handler for the #GtkEntry::activate signal.)
7588 gtk_entry_set_activates_default (GtkEntry *entry,
7591 GtkEntryPrivate *priv;
7593 g_return_if_fail (GTK_IS_ENTRY (entry));
7597 setting = setting != FALSE;
7599 if (setting != priv->activates_default)
7601 priv->activates_default = setting;
7602 g_object_notify (G_OBJECT (entry), "activates-default");
7607 * gtk_entry_get_activates_default:
7608 * @entry: a #GtkEntry
7610 * Retrieves the value set by gtk_entry_set_activates_default().
7612 * Return value: %TRUE if the entry will activate the default widget
7615 gtk_entry_get_activates_default (GtkEntry *entry)
7617 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7619 return entry->priv->activates_default;
7623 * gtk_entry_set_width_chars:
7624 * @entry: a #GtkEntry
7625 * @n_chars: width in chars
7627 * Changes the size request of the entry to be about the right size
7628 * for @n_chars characters. Note that it changes the size
7629 * <emphasis>request</emphasis>, the size can still be affected by
7630 * how you pack the widget into containers. If @n_chars is -1, the
7631 * size reverts to the default entry size.
7634 gtk_entry_set_width_chars (GtkEntry *entry,
7637 GtkEntryPrivate *priv;
7639 g_return_if_fail (GTK_IS_ENTRY (entry));
7643 if (priv->width_chars != n_chars)
7645 priv->width_chars = n_chars;
7646 g_object_notify (G_OBJECT (entry), "width-chars");
7647 gtk_widget_queue_resize (GTK_WIDGET (entry));
7652 * gtk_entry_get_width_chars:
7653 * @entry: a #GtkEntry
7655 * Gets the value set by gtk_entry_set_width_chars().
7657 * Return value: number of chars to request space for, or negative if unset
7660 gtk_entry_get_width_chars (GtkEntry *entry)
7662 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7664 return entry->priv->width_chars;
7668 * gtk_entry_set_has_frame:
7669 * @entry: a #GtkEntry
7670 * @setting: new value
7672 * Sets whether the entry has a beveled frame around it.
7675 gtk_entry_set_has_frame (GtkEntry *entry,
7678 GtkEntryPrivate *priv;
7680 g_return_if_fail (GTK_IS_ENTRY (entry));
7684 setting = (setting != FALSE);
7686 if (priv->has_frame == setting)
7689 gtk_widget_queue_resize (GTK_WIDGET (entry));
7690 priv->has_frame = setting;
7691 g_object_notify (G_OBJECT (entry), "has-frame");
7695 * gtk_entry_get_has_frame:
7696 * @entry: a #GtkEntry
7698 * Gets the value set by gtk_entry_set_has_frame().
7700 * Return value: whether the entry has a beveled frame
7703 gtk_entry_get_has_frame (GtkEntry *entry)
7705 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7707 return entry->priv->has_frame;
7711 * gtk_entry_set_inner_border:
7712 * @entry: a #GtkEntry
7713 * @border: (allow-none): a #GtkBorder, or %NULL
7715 * Sets %entry's inner-border property to %border, or clears it if %NULL
7716 * is passed. The inner-border is the area around the entry's text, but
7719 * If set, this property overrides the inner-border style property.
7720 * Overriding the style-provided border is useful when you want to do
7721 * in-place editing of some text in a canvas or list widget, where
7722 * pixel-exact positioning of the entry is important.
7726 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7727 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7728 * this function is ignored by #GtkEntry.
7731 gtk_entry_set_inner_border (GtkEntry *entry,
7732 const GtkBorder *border)
7734 g_return_if_fail (GTK_IS_ENTRY (entry));
7736 gtk_entry_do_set_inner_border (entry, border);
7740 * gtk_entry_get_inner_border:
7741 * @entry: a #GtkEntry
7743 * This function returns the entry's #GtkEntry:inner-border property. See
7744 * gtk_entry_set_inner_border() for more information.
7746 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7750 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7751 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7752 * this function is ignored by #GtkEntry.
7755 gtk_entry_get_inner_border (GtkEntry *entry)
7757 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7759 return gtk_entry_do_get_inner_border (entry);
7763 * gtk_entry_get_layout:
7764 * @entry: a #GtkEntry
7766 * Gets the #PangoLayout used to display the entry.
7767 * The layout is useful to e.g. convert text positions to
7768 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7769 * The returned layout is owned by the entry and must not be
7770 * modified or freed by the caller.
7772 * Keep in mind that the layout text may contain a preedit string, so
7773 * gtk_entry_layout_index_to_text_index() and
7774 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7775 * indices in the layout to byte indices in the entry contents.
7777 * Return value: (transfer none): the #PangoLayout for this entry
7780 gtk_entry_get_layout (GtkEntry *entry)
7782 PangoLayout *layout;
7784 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7786 layout = gtk_entry_ensure_layout (entry, TRUE);
7793 * gtk_entry_layout_index_to_text_index:
7794 * @entry: a #GtkEntry
7795 * @layout_index: byte index into the entry layout text
7797 * Converts from a position in the entry contents (returned
7798 * by gtk_entry_get_text()) to a position in the
7799 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7800 * with text retrieved via pango_layout_get_text()).
7802 * Return value: byte index into the entry contents
7805 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7808 GtkEntryPrivate *priv;
7809 PangoLayout *layout;
7813 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7817 layout = gtk_entry_ensure_layout (entry, TRUE);
7818 text = pango_layout_get_text (layout);
7819 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7821 if (layout_index >= cursor_index && priv->preedit_length)
7823 if (layout_index >= cursor_index + priv->preedit_length)
7824 layout_index -= priv->preedit_length;
7826 layout_index = cursor_index;
7829 return layout_index;
7833 * gtk_entry_text_index_to_layout_index:
7834 * @entry: a #GtkEntry
7835 * @text_index: byte index into the entry contents
7837 * Converts from a position in the entry's #PangoLayout (returned by
7838 * gtk_entry_get_layout()) to a position in the entry contents
7839 * (returned by gtk_entry_get_text()).
7841 * Return value: byte index into the entry layout text
7844 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7847 GtkEntryPrivate *priv;
7848 PangoLayout *layout;
7852 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7856 layout = gtk_entry_ensure_layout (entry, TRUE);
7857 text = pango_layout_get_text (layout);
7858 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7860 if (text_index > cursor_index)
7861 text_index += priv->preedit_length;
7867 * gtk_entry_get_layout_offsets:
7868 * @entry: a #GtkEntry
7869 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7870 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7873 * Obtains the position of the #PangoLayout used to render text
7874 * in the entry, in widget coordinates. Useful if you want to line
7875 * up the text in an entry with some other text, e.g. when using the
7876 * entry to implement editable cells in a sheet widget.
7878 * Also useful to convert mouse events into coordinates inside the
7879 * #PangoLayout, e.g. to take some action if some part of the entry text
7882 * Note that as the user scrolls around in the entry the offsets will
7883 * change; you'll need to connect to the "notify::scroll-offset"
7884 * signal to track this. Remember when using the #PangoLayout
7885 * functions you need to convert to and from pixels using
7886 * PANGO_PIXELS() or #PANGO_SCALE.
7888 * Keep in mind that the layout text may contain a preedit string, so
7889 * gtk_entry_layout_index_to_text_index() and
7890 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7891 * indices in the layout to byte indices in the entry contents.
7894 gtk_entry_get_layout_offsets (GtkEntry *entry,
7898 gint text_area_x, text_area_y;
7900 g_return_if_fail (GTK_IS_ENTRY (entry));
7902 /* this gets coords relative to text area */
7903 get_layout_position (entry, x, y);
7905 /* convert to widget coords */
7906 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7917 * gtk_entry_set_alignment:
7918 * @entry: a #GtkEntry
7919 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7920 * Reversed for RTL layouts
7922 * Sets the alignment for the contents of the entry. This controls
7923 * the horizontal positioning of the contents when the displayed
7924 * text is shorter than the width of the entry.
7929 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7931 GtkEntryPrivate *priv;
7933 g_return_if_fail (GTK_IS_ENTRY (entry));
7939 else if (xalign > 1.0)
7942 if (xalign != priv->xalign)
7944 priv->xalign = xalign;
7946 gtk_entry_recompute (entry);
7948 g_object_notify (G_OBJECT (entry), "xalign");
7953 * gtk_entry_get_alignment:
7954 * @entry: a #GtkEntry
7956 * Gets the value set by gtk_entry_set_alignment().
7958 * Return value: the alignment
7963 gtk_entry_get_alignment (GtkEntry *entry)
7965 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7967 return entry->priv->xalign;
7971 * gtk_entry_set_icon_from_pixbuf:
7972 * @entry: a #GtkEntry
7973 * @icon_pos: Icon position
7974 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7976 * Sets the icon shown in the specified position using a pixbuf.
7978 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7983 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7984 GtkEntryIconPosition icon_pos,
7987 GtkEntryPrivate *priv;
7988 EntryIconInfo *icon_info;
7990 g_return_if_fail (GTK_IS_ENTRY (entry));
7991 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7995 if ((icon_info = priv->icons[icon_pos]) == NULL)
7996 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7998 g_object_freeze_notify (G_OBJECT (entry));
8001 g_object_ref (pixbuf);
8003 gtk_entry_clear (entry, icon_pos);
8007 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
8008 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
8009 GTK_ICON_SIZE_MENU);
8011 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8013 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
8014 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8018 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
8019 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8022 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8023 gdk_window_show_unraised (icon_info->window);
8025 g_object_unref (pixbuf);
8028 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8029 gtk_widget_queue_resize (GTK_WIDGET (entry));
8031 g_object_thaw_notify (G_OBJECT (entry));
8035 * gtk_entry_set_icon_from_stock:
8036 * @entry: A #GtkEntry
8037 * @icon_pos: Icon position
8038 * @stock_id: (allow-none): The name of the stock item, or %NULL
8040 * Sets the icon shown in the entry at the specified position from
8043 * If @stock_id is %NULL, no icon will be shown in the specified position.
8048 gtk_entry_set_icon_from_stock (GtkEntry *entry,
8049 GtkEntryIconPosition icon_pos,
8050 const gchar *stock_id)
8052 GtkEntryPrivate *priv;
8053 EntryIconInfo *icon_info;
8056 g_return_if_fail (GTK_IS_ENTRY (entry));
8057 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8061 if ((icon_info = priv->icons[icon_pos]) == NULL)
8062 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8064 g_object_freeze_notify (G_OBJECT (entry));
8066 /* need to dup before clearing */
8067 new_id = g_strdup (stock_id);
8069 gtk_entry_clear (entry, icon_pos);
8073 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
8075 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8077 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
8078 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8082 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
8083 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8086 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8087 gdk_window_show_unraised (icon_info->window);
8092 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8093 gtk_widget_queue_resize (GTK_WIDGET (entry));
8095 g_object_thaw_notify (G_OBJECT (entry));
8099 * gtk_entry_set_icon_from_icon_name:
8100 * @entry: A #GtkEntry
8101 * @icon_pos: The position at which to set the icon
8102 * @icon_name: (allow-none): An icon name, or %NULL
8104 * Sets the icon shown in the entry at the specified position
8105 * from the current icon theme.
8107 * If the icon name isn't known, a "broken image" icon will be displayed
8110 * If @icon_name is %NULL, no icon will be shown in the specified position.
8115 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
8116 GtkEntryIconPosition icon_pos,
8117 const gchar *icon_name)
8119 GtkEntryPrivate *priv;
8120 EntryIconInfo *icon_info;
8123 g_return_if_fail (GTK_IS_ENTRY (entry));
8124 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8128 if ((icon_info = priv->icons[icon_pos]) == NULL)
8129 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8131 g_object_freeze_notify (G_OBJECT (entry));
8133 /* need to dup before clearing */
8134 new_name = g_strdup (icon_name);
8136 gtk_entry_clear (entry, icon_pos);
8138 if (new_name != NULL)
8140 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
8142 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8144 g_object_notify (G_OBJECT (entry), "primary-icon-name");
8145 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8149 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
8150 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8153 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8154 gdk_window_show_unraised (icon_info->window);
8159 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8160 gtk_widget_queue_resize (GTK_WIDGET (entry));
8162 g_object_thaw_notify (G_OBJECT (entry));
8166 * gtk_entry_set_icon_from_gicon:
8167 * @entry: A #GtkEntry
8168 * @icon_pos: The position at which to set the icon
8169 * @icon: (allow-none): The icon to set, or %NULL
8171 * Sets the icon shown in the entry at the specified position
8172 * from the current icon theme.
8173 * If the icon isn't known, a "broken image" icon will be displayed
8176 * If @icon is %NULL, no icon will be shown in the specified position.
8181 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
8182 GtkEntryIconPosition icon_pos,
8185 GtkEntryPrivate *priv;
8186 EntryIconInfo *icon_info;
8188 g_return_if_fail (GTK_IS_ENTRY (entry));
8189 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8193 if ((icon_info = priv->icons[icon_pos]) == NULL)
8194 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8196 g_object_freeze_notify (G_OBJECT (entry));
8198 /* need to ref before clearing */
8200 g_object_ref (icon);
8202 gtk_entry_clear (entry, icon_pos);
8206 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
8208 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8210 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8211 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8215 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8216 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8219 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8220 gdk_window_show_unraised (icon_info->window);
8222 g_object_unref (icon);
8225 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8226 gtk_widget_queue_resize (GTK_WIDGET (entry));
8228 g_object_thaw_notify (G_OBJECT (entry));
8232 * gtk_entry_set_icon_activatable:
8233 * @entry: A #GtkEntry
8234 * @icon_pos: Icon position
8235 * @activatable: %TRUE if the icon should be activatable
8237 * Sets whether the icon is activatable.
8242 gtk_entry_set_icon_activatable (GtkEntry *entry,
8243 GtkEntryIconPosition icon_pos,
8244 gboolean activatable)
8246 GtkEntryPrivate *priv;
8247 EntryIconInfo *icon_info;
8249 g_return_if_fail (GTK_IS_ENTRY (entry));
8250 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8254 if ((icon_info = priv->icons[icon_pos]) == NULL)
8255 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8257 activatable = activatable != FALSE;
8259 if (icon_info->nonactivatable != !activatable)
8261 icon_info->nonactivatable = !activatable;
8263 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8264 update_cursors (GTK_WIDGET (entry));
8266 g_object_notify (G_OBJECT (entry),
8267 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8272 * gtk_entry_get_icon_activatable:
8273 * @entry: a #GtkEntry
8274 * @icon_pos: Icon position
8276 * Returns whether the icon is activatable.
8278 * Returns: %TRUE if the icon is activatable.
8283 gtk_entry_get_icon_activatable (GtkEntry *entry,
8284 GtkEntryIconPosition icon_pos)
8286 GtkEntryPrivate *priv;
8287 EntryIconInfo *icon_info;
8289 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8290 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8293 icon_info = priv->icons[icon_pos];
8295 return (!icon_info || !icon_info->nonactivatable);
8299 * gtk_entry_get_icon_pixbuf:
8300 * @entry: A #GtkEntry
8301 * @icon_pos: Icon position
8303 * Retrieves the image used for the icon.
8305 * Unlike the other methods of setting and getting icon data, this
8306 * method will work regardless of whether the icon was set using a
8307 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8309 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8310 * set for this position.
8315 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8316 GtkEntryIconPosition icon_pos)
8318 GtkEntryPrivate *priv;
8319 EntryIconInfo *icon_info;
8322 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8323 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8327 icon_info = priv->icons[icon_pos];
8332 /* HACK: unfortunately this is transfer none, so we need to return
8333 * the icon helper's cache ref directly.
8335 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
8337 g_object_unref (pixbuf);
8343 * gtk_entry_get_icon_gicon:
8344 * @entry: A #GtkEntry
8345 * @icon_pos: Icon position
8347 * Retrieves the #GIcon used for the icon, or %NULL if there is
8348 * no icon or if the icon was set by some other method (e.g., by
8349 * stock, pixbuf, or icon name).
8351 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8352 * or if the icon is not a #GIcon
8357 gtk_entry_get_icon_gicon (GtkEntry *entry,
8358 GtkEntryIconPosition icon_pos)
8360 GtkEntryPrivate *priv;
8361 EntryIconInfo *icon_info;
8363 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8364 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8367 icon_info = priv->icons[icon_pos];
8372 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
8376 * gtk_entry_get_icon_stock:
8377 * @entry: A #GtkEntry
8378 * @icon_pos: Icon position
8380 * Retrieves the stock id used for the icon, or %NULL if there is
8381 * no icon or if the icon was set by some other method (e.g., by
8382 * pixbuf, icon name or gicon).
8384 * Returns: A stock id, or %NULL if no icon is set or if the icon
8385 * wasn't set from a stock id
8390 gtk_entry_get_icon_stock (GtkEntry *entry,
8391 GtkEntryIconPosition icon_pos)
8393 GtkEntryPrivate *priv;
8394 EntryIconInfo *icon_info;
8396 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8397 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8400 icon_info = priv->icons[icon_pos];
8405 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8409 * gtk_entry_get_icon_name:
8410 * @entry: A #GtkEntry
8411 * @icon_pos: Icon position
8413 * Retrieves the icon name used for the icon, or %NULL if there is
8414 * no icon or if the icon was set by some other method (e.g., by
8415 * pixbuf, stock or gicon).
8417 * Returns: An icon name, or %NULL if no icon is set or if the icon
8418 * wasn't set from an icon name
8423 gtk_entry_get_icon_name (GtkEntry *entry,
8424 GtkEntryIconPosition icon_pos)
8426 GtkEntryPrivate *priv;
8427 EntryIconInfo *icon_info;
8429 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8430 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8433 icon_info = priv->icons[icon_pos];
8438 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8442 * gtk_entry_set_icon_sensitive:
8443 * @entry: A #GtkEntry
8444 * @icon_pos: Icon position
8445 * @sensitive: Specifies whether the icon should appear
8446 * sensitive or insensitive
8448 * Sets the sensitivity for the specified icon.
8453 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8454 GtkEntryIconPosition icon_pos,
8457 GtkEntryPrivate *priv;
8458 EntryIconInfo *icon_info;
8460 g_return_if_fail (GTK_IS_ENTRY (entry));
8461 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8465 if ((icon_info = priv->icons[icon_pos]) == NULL)
8466 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8468 if (icon_info->insensitive != !sensitive)
8470 icon_info->insensitive = !sensitive;
8472 icon_info->pressed = FALSE;
8473 icon_info->prelight = FALSE;
8475 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8476 update_cursors (GTK_WIDGET (entry));
8478 gtk_widget_queue_draw (GTK_WIDGET (entry));
8480 g_object_notify (G_OBJECT (entry),
8481 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8486 * gtk_entry_get_icon_sensitive:
8487 * @entry: a #GtkEntry
8488 * @icon_pos: Icon position
8490 * Returns whether the icon appears sensitive or insensitive.
8492 * Returns: %TRUE if the icon is sensitive.
8497 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8498 GtkEntryIconPosition icon_pos)
8500 GtkEntryPrivate *priv;
8501 EntryIconInfo *icon_info;
8503 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8504 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8508 icon_info = priv->icons[icon_pos];
8510 return (!icon_info || !icon_info->insensitive);
8515 * gtk_entry_get_icon_storage_type:
8516 * @entry: a #GtkEntry
8517 * @icon_pos: Icon position
8519 * Gets the type of representation being used by the icon
8520 * to store image data. If the icon has no image data,
8521 * the return value will be %GTK_IMAGE_EMPTY.
8523 * Return value: image representation being used
8528 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8529 GtkEntryIconPosition icon_pos)
8531 GtkEntryPrivate *priv;
8532 EntryIconInfo *icon_info;
8534 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8535 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8539 icon_info = priv->icons[icon_pos];
8542 return GTK_IMAGE_EMPTY;
8544 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8548 * gtk_entry_get_icon_at_pos:
8549 * @entry: a #GtkEntry
8550 * @x: the x coordinate of the position to find
8551 * @y: the y coordinate of the position to find
8553 * Finds the icon at the given position and return its index. The
8554 * position's coordinates are relative to the @entry's top left corner.
8555 * If @x, @y doesn't lie inside an icon, -1 is returned.
8556 * This function is intended for use in a #GtkWidget::query-tooltip
8559 * Returns: the index of the icon at the given position, or -1
8564 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8568 GtkAllocation primary;
8569 GtkAllocation secondary;
8570 gint frame_x, frame_y;
8572 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8574 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8578 get_icon_allocations (entry, &primary, &secondary);
8580 if (primary.x <= x && x < primary.x + primary.width &&
8581 primary.y <= y && y < primary.y + primary.height)
8582 return GTK_ENTRY_ICON_PRIMARY;
8584 if (secondary.x <= x && x < secondary.x + secondary.width &&
8585 secondary.y <= y && y < secondary.y + secondary.height)
8586 return GTK_ENTRY_ICON_SECONDARY;
8592 * gtk_entry_set_icon_drag_source:
8593 * @entry: a #GtkEntry
8594 * @icon_pos: icon position
8595 * @target_list: the targets (data formats) in which the data can be provided
8596 * @actions: a bitmask of the allowed drag actions
8598 * Sets up the icon at the given position so that GTK+ will start a drag
8599 * operation when the user clicks and drags the icon.
8601 * To handle the drag operation, you need to connect to the usual
8602 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8603 * signal, and use gtk_entry_get_current_icon_drag_source() in
8604 * your signal handler to find out if the drag was started from
8607 * By default, GTK+ uses the icon as the drag icon. You can use the
8608 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8609 * have to use g_signal_connect_after() to ensure that your signal handler
8610 * gets executed after the default handler.
8615 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8616 GtkEntryIconPosition icon_pos,
8617 GtkTargetList *target_list,
8618 GdkDragAction actions)
8620 GtkEntryPrivate *priv;
8621 EntryIconInfo *icon_info;
8623 g_return_if_fail (GTK_IS_ENTRY (entry));
8624 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8628 if ((icon_info = priv->icons[icon_pos]) == NULL)
8629 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8631 if (icon_info->target_list)
8632 gtk_target_list_unref (icon_info->target_list);
8633 icon_info->target_list = target_list;
8634 if (icon_info->target_list)
8635 gtk_target_list_ref (icon_info->target_list);
8637 icon_info->actions = actions;
8641 * gtk_entry_get_current_icon_drag_source:
8642 * @entry: a #GtkIconEntry
8644 * Returns the index of the icon which is the source of the current
8645 * DND operation, or -1.
8647 * This function is meant to be used in a #GtkWidget::drag-data-get
8650 * Returns: index of the icon which is the source of the current
8651 * DND operation, or -1.
8656 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8658 GtkEntryPrivate *priv;
8659 EntryIconInfo *icon_info = NULL;
8662 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8666 for (i = 0; i < MAX_ICONS; i++)
8668 if ((icon_info = priv->icons[i]))
8670 if (icon_info->in_drag)
8679 * gtk_entry_get_icon_area:
8680 * @entry: A #GtkEntry
8681 * @icon_pos: Icon position
8682 * @icon_area: (out): Return location for the icon's area
8684 * Gets the area where entry's icon at @icon_pos is drawn.
8685 * This function is useful when drawing something to the
8686 * entry in a draw callback.
8688 * If the entry is not realized or has no icon at the given position,
8689 * @icon_area is filled with zeros.
8691 * See also gtk_entry_get_text_area()
8696 gtk_entry_get_icon_area (GtkEntry *entry,
8697 GtkEntryIconPosition icon_pos,
8698 GdkRectangle *icon_area)
8700 GtkEntryPrivate *priv;
8701 EntryIconInfo *icon_info;
8703 g_return_if_fail (GTK_IS_ENTRY (entry));
8704 g_return_if_fail (icon_area != NULL);
8708 icon_info = priv->icons[icon_pos];
8712 GtkAllocation primary;
8713 GtkAllocation secondary;
8715 get_icon_allocations (entry, &primary, &secondary);
8717 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8718 *icon_area = primary;
8720 *icon_area = secondary;
8726 icon_area->width = 0;
8727 icon_area->height = 0;
8732 ensure_has_tooltip (GtkEntry *entry)
8734 GtkEntryPrivate *priv;
8735 EntryIconInfo *icon_info;
8737 gboolean has_tooltip = FALSE;
8741 for (i = 0; i < MAX_ICONS; i++)
8743 if ((icon_info = priv->icons[i]) != NULL)
8745 if (icon_info->tooltip != NULL)
8753 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8757 * gtk_entry_get_icon_tooltip_text:
8758 * @entry: a #GtkEntry
8759 * @icon_pos: the icon position
8761 * Gets the contents of the tooltip on the icon at the specified
8762 * position in @entry.
8764 * Returns: the tooltip text, or %NULL. Free the returned string
8765 * with g_free() when done.
8770 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8771 GtkEntryIconPosition icon_pos)
8773 GtkEntryPrivate *priv;
8774 EntryIconInfo *icon_info;
8777 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8778 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8782 icon_info = priv->icons[icon_pos];
8787 if (icon_info->tooltip &&
8788 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8789 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8795 * gtk_entry_set_icon_tooltip_text:
8796 * @entry: a #GtkEntry
8797 * @icon_pos: the icon position
8798 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8800 * Sets @tooltip as the contents of the tooltip for the icon
8801 * at the specified position.
8803 * Use %NULL for @tooltip to remove an existing tooltip.
8805 * See also gtk_widget_set_tooltip_text() and
8806 * gtk_entry_set_icon_tooltip_markup().
8811 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8812 GtkEntryIconPosition icon_pos,
8813 const gchar *tooltip)
8815 GtkEntryPrivate *priv;
8816 EntryIconInfo *icon_info;
8818 g_return_if_fail (GTK_IS_ENTRY (entry));
8819 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8823 if ((icon_info = priv->icons[icon_pos]) == NULL)
8824 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8826 if (icon_info->tooltip)
8827 g_free (icon_info->tooltip);
8829 /* Treat an empty string as a NULL string,
8830 * because an empty string would be useless for a tooltip:
8832 if (tooltip && tooltip[0] == '\0')
8835 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8837 ensure_has_tooltip (entry);
8839 g_object_notify (G_OBJECT (entry),
8840 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-tooltip-text" : "secondary-icon-tooltip-text");
8844 * gtk_entry_get_icon_tooltip_markup:
8845 * @entry: a #GtkEntry
8846 * @icon_pos: the icon position
8848 * Gets the contents of the tooltip on the icon at the specified
8849 * position in @entry.
8851 * Returns: the tooltip text, or %NULL. Free the returned string
8852 * with g_free() when done.
8857 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8858 GtkEntryIconPosition icon_pos)
8860 GtkEntryPrivate *priv;
8861 EntryIconInfo *icon_info;
8863 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8864 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8868 icon_info = priv->icons[icon_pos];
8873 return g_strdup (icon_info->tooltip);
8877 * gtk_entry_set_icon_tooltip_markup:
8878 * @entry: a #GtkEntry
8879 * @icon_pos: the icon position
8880 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8882 * Sets @tooltip as the contents of the tooltip for the icon at
8883 * the specified position. @tooltip is assumed to be marked up with
8884 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8886 * Use %NULL for @tooltip to remove an existing tooltip.
8888 * See also gtk_widget_set_tooltip_markup() and
8889 * gtk_entry_set_icon_tooltip_text().
8894 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8895 GtkEntryIconPosition icon_pos,
8896 const gchar *tooltip)
8898 GtkEntryPrivate *priv;
8899 EntryIconInfo *icon_info;
8901 g_return_if_fail (GTK_IS_ENTRY (entry));
8902 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8906 if ((icon_info = priv->icons[icon_pos]) == NULL)
8907 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8909 if (icon_info->tooltip)
8910 g_free (icon_info->tooltip);
8912 /* Treat an empty string as a NULL string,
8913 * because an empty string would be useless for a tooltip:
8915 if (tooltip && tooltip[0] == '\0')
8918 icon_info->tooltip = g_strdup (tooltip);
8920 ensure_has_tooltip (entry);
8924 gtk_entry_query_tooltip (GtkWidget *widget,
8927 gboolean keyboard_tip,
8928 GtkTooltip *tooltip)
8931 GtkEntryPrivate *priv;
8932 EntryIconInfo *icon_info;
8935 entry = GTK_ENTRY (widget);
8940 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8943 if ((icon_info = priv->icons[icon_pos]) != NULL)
8945 if (icon_info->tooltip)
8947 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8956 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8963 /* Quick hack of a popup menu
8966 activate_cb (GtkWidget *menuitem,
8969 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8970 g_signal_emit_by_name (entry, signal);
8975 gtk_entry_mnemonic_activate (GtkWidget *widget,
8976 gboolean group_cycling)
8978 gtk_widget_grab_focus (widget);
8983 gtk_entry_grab_notify (GtkWidget *widget,
8984 gboolean was_grabbed)
8986 GtkEntryPrivate *priv;
8988 priv = GTK_ENTRY (widget)->priv;
8991 gtk_widget_device_is_shadowed (widget, priv->device))
8993 /* Unset button so we don't expect
8994 * a button release anymore
8997 priv->device = NULL;
8998 priv->in_drag = FALSE;
9003 append_action_signal (GtkEntry *entry,
9005 const gchar *stock_id,
9006 const gchar *signal,
9009 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
9011 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
9012 g_signal_connect (menuitem, "activate",
9013 G_CALLBACK (activate_cb), entry);
9015 gtk_widget_set_sensitive (menuitem, sensitive);
9017 gtk_widget_show (menuitem);
9018 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
9022 popup_menu_detach (GtkWidget *attach_widget,
9025 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
9026 GtkEntryPrivate *priv_attach = entry_attach->priv;
9028 priv_attach->popup_menu = NULL;
9032 popup_position_func (GtkMenu *menu,
9038 GtkEntry *entry = GTK_ENTRY (user_data);
9039 GtkEntryPrivate *priv = entry->priv;
9040 GtkWidget *widget = GTK_WIDGET (entry);
9042 GtkRequisition menu_req;
9043 GdkRectangle monitor;
9045 gint monitor_num, strong_x, height;
9047 g_return_if_fail (gtk_widget_get_realized (widget));
9049 gdk_window_get_origin (priv->text_area, x, y);
9051 screen = gtk_widget_get_screen (widget);
9052 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
9053 if (monitor_num < 0)
9055 gtk_menu_set_monitor (menu, monitor_num);
9057 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
9058 gtk_widget_get_preferred_size (priv->popup_menu,
9060 height = gdk_window_get_height (priv->text_area);
9061 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
9062 _gtk_entry_get_borders (entry, &borders);
9064 *x += borders.left + strong_x - priv->scroll_offset;
9065 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
9066 *x -= menu_req.width;
9068 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
9070 else if ((*y - menu_req.height) >= monitor.y)
9071 *y -= menu_req.height;
9072 else if (monitor.y + monitor.height - (*y + height) > *y)
9075 *y -= menu_req.height;
9081 unichar_chosen_func (const char *text,
9084 GtkEntry *entry = GTK_ENTRY (data);
9085 GtkEntryPrivate *priv = entry->priv;
9088 gtk_entry_enter_text (entry, text);
9100 popup_targets_received (GtkClipboard *clipboard,
9101 GtkSelectionData *data,
9104 PopupInfo *info = user_data;
9105 GtkEntry *entry = info->entry;
9106 GtkEntryPrivate *info_entry_priv = entry->priv;
9108 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
9111 gboolean clipboard_contains_text;
9112 GtkWidget *menuitem;
9114 gboolean show_input_method_menu;
9115 gboolean show_unicode_menu;
9117 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
9118 if (info_entry_priv->popup_menu)
9119 gtk_widget_destroy (info_entry_priv->popup_menu);
9121 info_entry_priv->popup_menu = gtk_menu_new ();
9123 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
9127 mode = gtk_entry_get_display_mode (entry);
9128 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
9129 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
9130 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9132 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
9133 mode == DISPLAY_NORMAL &&
9134 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9136 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
9137 info_entry_priv->editable && clipboard_contains_text);
9139 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
9140 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
9141 g_signal_connect_swapped (menuitem, "activate",
9142 G_CALLBACK (gtk_entry_delete_cb), entry);
9143 gtk_widget_show (menuitem);
9144 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9146 menuitem = gtk_separator_menu_item_new ();
9147 gtk_widget_show (menuitem);
9148 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9150 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
9151 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
9152 g_signal_connect_swapped (menuitem, "activate",
9153 G_CALLBACK (gtk_entry_select_all), entry);
9154 gtk_widget_show (menuitem);
9155 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9157 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
9158 "gtk-show-input-method-menu", &show_input_method_menu,
9159 "gtk-show-unicode-menu", &show_unicode_menu,
9162 if (show_input_method_menu || show_unicode_menu)
9164 menuitem = gtk_separator_menu_item_new ();
9165 gtk_widget_show (menuitem);
9166 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9169 if (show_input_method_menu)
9171 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
9172 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9173 gtk_widget_show (menuitem);
9174 submenu = gtk_menu_new ();
9175 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9177 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9179 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
9180 GTK_MENU_SHELL (submenu));
9183 if (show_unicode_menu)
9185 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
9186 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9187 gtk_widget_show (menuitem);
9189 submenu = gtk_menu_new ();
9190 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9191 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9193 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
9194 unichar_chosen_func,
9198 g_signal_emit (entry,
9199 signals[POPULATE_POPUP],
9201 info_entry_priv->popup_menu);
9205 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
9206 info->device, NULL, NULL, NULL, NULL, NULL,
9207 info->button, info->time);
9210 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
9211 popup_position_func, entry,
9212 0, gtk_get_current_event_time ());
9213 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9217 g_object_unref (entry);
9218 g_slice_free (PopupInfo, info);
9222 gtk_entry_do_popup (GtkEntry *entry,
9223 GdkEventButton *event)
9225 PopupInfo *info = g_slice_new (PopupInfo);
9227 /* In order to know what entries we should make sensitive, we
9228 * ask for the current targets of the clipboard, and when
9229 * we get them, then we actually pop up the menu.
9231 info->entry = g_object_ref (entry);
9235 info->button = event->button;
9236 info->time = event->time;
9237 info->device = event->device;
9242 info->time = gtk_get_current_event_time ();
9243 info->device = NULL;
9246 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9247 gdk_atom_intern_static_string ("TARGETS"),
9248 popup_targets_received,
9253 gtk_entry_popup_menu (GtkWidget *widget)
9255 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9260 gtk_entry_selection_bubble_popup_cb (gpointer user_data)
9262 GtkEntry *entry = user_data;
9263 GtkEntryPrivate *priv = entry->priv;
9264 cairo_rectangle_int_t rect;
9265 GtkAllocation allocation;
9266 gint start_x, end_x;
9267 gboolean has_selection;
9269 has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
9271 if (!has_selection && !priv->editable)
9273 priv->selection_bubble_timeout_id = 0;
9277 if (priv->selection_bubble)
9278 gtk_widget_destroy (priv->selection_bubble);
9280 priv->selection_bubble = gtk_selection_window_new ();
9281 g_signal_connect_swapped (priv->selection_bubble, "cut",
9282 G_CALLBACK (gtk_entry_cut_clipboard),
9284 g_signal_connect_swapped (priv->selection_bubble, "copy",
9285 G_CALLBACK (gtk_entry_copy_clipboard),
9287 g_signal_connect_swapped (priv->selection_bubble, "paste",
9288 G_CALLBACK (gtk_entry_paste_clipboard),
9291 gtk_selection_window_set_editable (GTK_SELECTION_WINDOW (priv->selection_bubble),
9293 gtk_selection_window_set_has_selection (GTK_SELECTION_WINDOW (priv->selection_bubble),
9296 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
9298 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &start_x, NULL);
9300 start_x -= priv->scroll_offset;
9301 start_x = CLAMP (start_x, 0, gdk_window_get_width (priv->text_area));
9304 rect.height = gdk_window_get_height (priv->text_area);
9308 end_x = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
9309 end_x = CLAMP (end_x, 0, gdk_window_get_width (priv->text_area));
9311 rect.x = MIN (start_x, end_x);
9312 rect.width = MAX (start_x, end_x) - rect.x;
9320 gtk_bubble_window_popup (GTK_BUBBLE_WINDOW (priv->selection_bubble),
9321 priv->text_area, &rect, GTK_POS_TOP);
9323 priv->selection_bubble_timeout_id = 0;
9328 gtk_entry_selection_bubble_popup_unset (GtkEntry *entry)
9330 GtkEntryPrivate *priv;
9334 if (priv->selection_bubble)
9335 gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
9337 if (priv->selection_bubble_timeout_id)
9339 g_source_remove (priv->selection_bubble_timeout_id);
9340 priv->selection_bubble_timeout_id = 0;
9345 gtk_entry_selection_bubble_popup_set (GtkEntry *entry)
9347 GtkEntryPrivate *priv;
9351 if (priv->selection_bubble_timeout_id)
9352 g_source_remove (priv->selection_bubble_timeout_id);
9354 priv->selection_bubble_timeout_id =
9355 gdk_threads_add_timeout (1000, gtk_entry_selection_bubble_popup_cb, entry);
9359 gtk_entry_drag_begin (GtkWidget *widget,
9360 GdkDragContext *context)
9362 GtkEntry *entry = GTK_ENTRY (widget);
9363 GtkEntryPrivate *priv = entry->priv;
9366 for (i = 0; i < MAX_ICONS; i++)
9368 EntryIconInfo *icon_info = priv->icons[i];
9370 if (icon_info != NULL)
9372 if (icon_info->in_drag)
9376 pix = _gtk_icon_helper_ensure_pixbuf
9377 (icon_info->icon_helper,
9378 gtk_widget_get_style_context (GTK_WIDGET (entry)));
9379 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
9381 g_object_unref (pix);
9388 gtk_entry_drag_end (GtkWidget *widget,
9389 GdkDragContext *context)
9391 GtkEntry *entry = GTK_ENTRY (widget);
9392 GtkEntryPrivate *priv = entry->priv;
9395 for (i = 0; i < MAX_ICONS; i++)
9397 EntryIconInfo *icon_info = priv->icons[i];
9399 if (icon_info != NULL)
9400 icon_info->in_drag = 0;
9405 gtk_entry_drag_leave (GtkWidget *widget,
9406 GdkDragContext *context,
9409 GtkEntry *entry = GTK_ENTRY (widget);
9410 GtkEntryPrivate *priv = entry->priv;
9412 priv->dnd_position = -1;
9413 gtk_widget_queue_draw (widget);
9417 gtk_entry_drag_drop (GtkWidget *widget,
9418 GdkDragContext *context,
9423 GtkEntry *entry = GTK_ENTRY (widget);
9424 GtkEntryPrivate *priv = entry->priv;
9425 GdkAtom target = GDK_NONE;
9428 target = gtk_drag_dest_find_target (widget, context, NULL);
9430 if (target != GDK_NONE)
9431 gtk_drag_get_data (widget, context, target, time);
9433 gtk_drag_finish (context, FALSE, FALSE, time);
9439 gtk_entry_drag_motion (GtkWidget *widget,
9440 GdkDragContext *context,
9445 GtkEntry *entry = GTK_ENTRY (widget);
9446 GtkEntryPrivate *priv = entry->priv;
9447 GtkStyleContext *style_context;
9448 GtkWidget *source_widget;
9449 GdkDragAction suggested_action;
9450 gint new_position, old_position;
9454 style_context = gtk_widget_get_style_context (widget);
9455 gtk_style_context_get_padding (style_context, 0, &padding);
9459 old_position = priv->dnd_position;
9460 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9462 if (priv->editable &&
9463 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9465 source_widget = gtk_drag_get_source_widget (context);
9466 suggested_action = gdk_drag_context_get_suggested_action (context);
9468 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9469 new_position < sel1 || new_position > sel2)
9471 if (source_widget == widget)
9473 /* Default to MOVE, unless the user has
9474 * pressed ctrl or alt to affect available actions
9476 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9477 suggested_action = GDK_ACTION_MOVE;
9480 priv->dnd_position = new_position;
9484 if (source_widget == widget)
9485 suggested_action = 0; /* Can't drop in selection where drag started */
9487 priv->dnd_position = -1;
9492 /* Entry not editable, or no text */
9493 suggested_action = 0;
9494 priv->dnd_position = -1;
9497 gdk_drag_status (context, suggested_action, time);
9499 if (priv->dnd_position != old_position)
9500 gtk_widget_queue_draw (widget);
9506 gtk_entry_drag_data_received (GtkWidget *widget,
9507 GdkDragContext *context,
9510 GtkSelectionData *selection_data,
9514 GtkEntry *entry = GTK_ENTRY (widget);
9515 GtkEntryPrivate *priv = entry->priv;
9516 GtkEditable *editable = GTK_EDITABLE (widget);
9517 GtkStyleContext *style_context;
9521 str = (gchar *) gtk_selection_data_get_text (selection_data);
9523 style_context = gtk_widget_get_style_context (widget);
9524 gtk_style_context_get_padding (style_context, 0, &padding);
9528 if (str && priv->editable)
9534 if (priv->truncate_multiline)
9535 length = truncate_multiline (str);
9537 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9539 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9540 new_position < sel1 || new_position > sel2)
9542 gtk_editable_insert_text (editable, str, length, &new_position);
9546 /* Replacing selection */
9547 begin_change (entry);
9548 gtk_editable_delete_text (editable, sel1, sel2);
9549 gtk_editable_insert_text (editable, str, length, &sel1);
9553 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9557 /* Drag and drop didn't happen! */
9558 gtk_drag_finish (context, FALSE, FALSE, time);
9565 gtk_entry_drag_data_get (GtkWidget *widget,
9566 GdkDragContext *context,
9567 GtkSelectionData *selection_data,
9571 GtkEntry *entry = GTK_ENTRY (widget);
9572 GtkEntryPrivate *priv = entry->priv;
9573 GtkEditable *editable = GTK_EDITABLE (widget);
9574 gint sel_start, sel_end;
9577 /* If there is an icon drag going on, exit early. */
9578 for (i = 0; i < MAX_ICONS; i++)
9580 EntryIconInfo *icon_info = priv->icons[i];
9582 if (icon_info != NULL)
9584 if (icon_info->in_drag)
9589 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9591 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9593 gtk_selection_data_set_text (selection_data, str, -1);
9601 gtk_entry_drag_data_delete (GtkWidget *widget,
9602 GdkDragContext *context)
9604 GtkEntry *entry = GTK_ENTRY (widget);
9605 GtkEntryPrivate *priv = entry->priv;
9606 GtkEditable *editable = GTK_EDITABLE (widget);
9607 gint sel_start, sel_end;
9610 /* If there is an icon drag going on, exit early. */
9611 for (i = 0; i < MAX_ICONS; i++)
9613 EntryIconInfo *icon_info = priv->icons[i];
9615 if (icon_info != NULL)
9617 if (icon_info->in_drag)
9622 if (priv->editable &&
9623 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9624 gtk_editable_delete_text (editable, sel_start, sel_end);
9627 /* We display the cursor when
9629 * - the selection is empty, AND
9630 * - the widget has focus
9633 #define CURSOR_ON_MULTIPLIER 2
9634 #define CURSOR_OFF_MULTIPLIER 1
9635 #define CURSOR_PEND_MULTIPLIER 3
9636 #define CURSOR_DIVIDER 3
9639 cursor_blinks (GtkEntry *entry)
9641 GtkEntryPrivate *priv = entry->priv;
9643 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9645 priv->selection_bound == priv->current_pos)
9647 GtkSettings *settings;
9650 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9651 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9660 get_middle_click_paste (GtkEntry *entry)
9662 GtkSettings *settings;
9665 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9666 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9672 get_cursor_time (GtkEntry *entry)
9674 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9677 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9683 get_cursor_blink_timeout (GtkEntry *entry)
9685 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9688 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9694 show_cursor (GtkEntry *entry)
9696 GtkEntryPrivate *priv = entry->priv;
9699 if (!priv->cursor_visible)
9701 priv->cursor_visible = TRUE;
9703 widget = GTK_WIDGET (entry);
9704 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9705 gtk_widget_queue_draw (widget);
9710 hide_cursor (GtkEntry *entry)
9712 GtkEntryPrivate *priv = entry->priv;
9715 if (priv->cursor_visible)
9717 priv->cursor_visible = FALSE;
9719 widget = GTK_WIDGET (entry);
9720 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9721 gtk_widget_queue_draw (widget);
9729 blink_cb (gpointer data)
9732 GtkEntryPrivate *priv;
9735 entry = GTK_ENTRY (data);
9738 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9740 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9741 "connect a handler to this signal, it must return\n"
9742 "FALSE so the entry gets the event as well");
9744 gtk_entry_check_cursor_blink (entry);
9749 g_assert (priv->selection_bound == priv->current_pos);
9751 blink_timeout = get_cursor_blink_timeout (entry);
9752 if (priv->blink_time > 1000 * blink_timeout &&
9753 blink_timeout < G_MAXINT/1000)
9755 /* we've blinked enough without the user doing anything, stop blinking */
9756 show_cursor (entry);
9757 priv->blink_timeout = 0;
9759 else if (priv->cursor_visible)
9761 hide_cursor (entry);
9762 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9768 show_cursor (entry);
9769 priv->blink_time += get_cursor_time (entry);
9770 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9775 /* Remove ourselves */
9780 gtk_entry_check_cursor_blink (GtkEntry *entry)
9782 GtkEntryPrivate *priv = entry->priv;
9784 if (cursor_blinks (entry))
9786 if (!priv->blink_timeout)
9788 show_cursor (entry);
9789 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9796 if (priv->blink_timeout)
9798 g_source_remove (priv->blink_timeout);
9799 priv->blink_timeout = 0;
9802 priv->cursor_visible = TRUE;
9807 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9809 GtkEntryPrivate *priv = entry->priv;
9811 if (cursor_blinks (entry))
9813 if (priv->blink_timeout != 0)
9814 g_source_remove (priv->blink_timeout);
9816 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9819 show_cursor (entry);
9824 gtk_entry_reset_blink_time (GtkEntry *entry)
9826 GtkEntryPrivate *priv = entry->priv;
9828 priv->blink_time = 0;
9832 * gtk_entry_set_completion:
9833 * @entry: A #GtkEntry
9834 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9836 * Sets @completion to be the auxiliary completion object to use with @entry.
9837 * All further configuration of the completion mechanism is done on
9838 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9839 * @completion is set to %NULL.
9844 gtk_entry_set_completion (GtkEntry *entry,
9845 GtkEntryCompletion *completion)
9847 GtkEntryCompletion *old;
9849 g_return_if_fail (GTK_IS_ENTRY (entry));
9850 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9852 old = gtk_entry_get_completion (entry);
9854 if (old == completion)
9859 _gtk_entry_completion_disconnect (old);
9860 g_object_unref (old);
9865 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9869 /* hook into the entry */
9870 g_object_ref (completion);
9872 _gtk_entry_completion_connect (completion, entry);
9874 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9876 g_object_notify (G_OBJECT (entry), "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));
10134 * gtk_entry_set_placeholder_text:
10135 * @entry: a #GtkEntry
10136 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10138 * Sets text to be displayed in @entry when it is empty and unfocused.
10139 * This can be used to give a visual hint of the expected contents of
10142 * Note that since the placeholder text gets removed when the entry
10143 * received focus, using this feature is a bit problematic if the entry
10144 * is given the initial focus in a window. Sometimes this can be
10145 * worked around by delaying the initial focus setting until the
10146 * first key event arrives.
10151 gtk_entry_set_placeholder_text (GtkEntry *entry,
10154 GtkEntryPrivate *priv;
10156 g_return_if_fail (GTK_IS_ENTRY (entry));
10158 priv = entry->priv;
10160 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10163 g_free (priv->placeholder_text);
10164 priv->placeholder_text = g_strdup (text);
10166 gtk_entry_recompute (entry);
10168 g_object_notify (G_OBJECT (entry), "placeholder-text");
10172 * gtk_entry_get_placeholder_text:
10173 * @entry: a #GtkEntry
10175 * Retrieves the text that will be displayed when @entry is empty and unfocused
10177 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10178 * storage in the widget and must not be freed, modified or stored.
10183 gtk_entry_get_placeholder_text (GtkEntry *entry)
10185 GtkEntryPrivate *priv;
10187 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10189 priv = entry->priv;
10191 return priv->placeholder_text;
10194 /* Caps Lock warning for password entries */
10197 show_capslock_feedback (GtkEntry *entry,
10200 GtkEntryPrivate *priv = entry->priv;
10202 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10204 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10205 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10206 priv->caps_lock_warning_shown = TRUE;
10209 if (priv->caps_lock_warning_shown)
10210 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10212 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10216 remove_capslock_feedback (GtkEntry *entry)
10218 GtkEntryPrivate *priv = entry->priv;
10220 if (priv->caps_lock_warning_shown)
10222 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10223 priv->caps_lock_warning_shown = FALSE;
10228 keymap_state_changed (GdkKeymap *keymap,
10231 GtkEntryPrivate *priv = entry->priv;
10234 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10236 if (gdk_keymap_get_caps_lock_state (keymap))
10237 text = _("Caps Lock is on");
10241 show_capslock_feedback (entry, text);
10243 remove_capslock_feedback (entry);
10247 * _gtk_entry_set_is_cell_renderer:
10248 * @entry: a #GtkEntry
10249 * @is_cell_renderer: new value
10251 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10252 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10254 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10258 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10259 gboolean is_cell_renderer)
10261 entry->priv->is_cell_renderer = is_cell_renderer;
10265 * gtk_entry_set_input_purpose:
10266 * @entry: a #GtkEntry
10267 * @purpose: the purpose
10269 * Sets the #GtkEntry:input-purpose property which
10270 * can be used by on-screen keyboards and other input
10271 * methods to adjust their behaviour.
10276 gtk_entry_set_input_purpose (GtkEntry *entry,
10277 GtkInputPurpose purpose)
10280 g_return_if_fail (GTK_IS_ENTRY (entry));
10282 if (gtk_entry_get_input_purpose (entry) != purpose)
10284 g_object_set (G_OBJECT (entry->priv->im_context),
10285 "input-purpose", purpose,
10288 g_object_notify (G_OBJECT (entry), "input-purpose");
10293 * gtk_entry_get_input_purpose:
10294 * @entry: a #GtkEntry
10296 * Gets the value of the #GtkEntry:input-purpose property.
10301 gtk_entry_get_input_purpose (GtkEntry *entry)
10303 GtkInputPurpose purpose;
10305 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
10307 g_object_get (G_OBJECT (entry->priv->im_context),
10308 "input-purpose", &purpose,
10315 * gtk_entry_set_input_hints:
10316 * @entry: a #GtkEntry
10317 * @hints: the hints
10319 * Sets the #GtkEntry:input-hints property, which
10320 * allows input methods to fine-tune their behaviour.
10325 gtk_entry_set_input_hints (GtkEntry *entry,
10326 GtkInputHints hints)
10329 g_return_if_fail (GTK_IS_ENTRY (entry));
10331 if (gtk_entry_get_input_hints (entry) != hints)
10333 g_object_set (G_OBJECT (entry->priv->im_context),
10334 "input-hints", hints,
10337 g_object_notify (G_OBJECT (entry), "input-hints");
10342 * gtk_entry_get_input_hints:
10343 * @entry: a #GtkEntry
10345 * Gets the value of the #GtkEntry:input-hints property.
10350 gtk_entry_get_input_hints (GtkEntry *entry)
10352 GtkInputHints hints;
10354 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
10356 g_object_get (G_OBJECT (entry->priv->im_context),
10357 "input-hints", &hints,
10364 * gtk_entry_set_attributes:
10365 * @entry: a #GtkEntry
10366 * @attrs: a #PangoAttrList
10368 * Sets a #PangoAttrList; the attributes in the list are applied to the
10374 gtk_entry_set_attributes (GtkEntry *entry,
10375 PangoAttrList *attrs)
10377 GtkEntryPrivate *priv = entry->priv;
10378 g_return_if_fail (GTK_IS_ENTRY (entry));
10381 pango_attr_list_ref (attrs);
10384 pango_attr_list_unref (priv->attrs);
10385 priv->attrs = attrs;
10387 g_object_notify (G_OBJECT (entry), "attributes");
10389 gtk_entry_recompute (entry);
10390 gtk_widget_queue_resize (GTK_WIDGET (entry));
10394 * gtk_entry_get_attributes:
10395 * @entry: a #GtkEntry
10397 * Gets the attribute list that was set on the entry using
10398 * gtk_entry_set_attributes(), if any.
10400 * Return value: (transfer none): the attribute list, or %NULL
10406 gtk_entry_get_attributes (GtkEntry *entry)
10408 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10410 return entry->priv->attrs;