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 "gtkbubblewindowprivate.h"
70 #include "gtktoolbar.h"
72 #include "a11y/gtkentryaccessible.h"
76 * @Short_description: A single line text entry field
78 * @See_also: #GtkTextView, #GtkEntryCompletion
80 * The #GtkEntry widget is a single line text entry
81 * widget. A fairly large set of key bindings are supported
82 * by default. If the entered text is longer than the allocation
83 * of the widget, the widget will scroll so that the cursor
84 * position is visible.
86 * When using an entry for passwords and other sensitive information,
87 * it can be put into "password mode" using gtk_entry_set_visibility().
88 * In this mode, entered text is displayed using a 'invisible' character.
89 * By default, GTK+ picks the best invisible character that is available
90 * in the current font, but it can be changed with
91 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
92 * when Caps Lock or input methods might interfere with entering text in
93 * a password entry. The warning can be turned off with the
94 * #GtkEntry:caps-lock-warning property.
96 * Since 2.16, GtkEntry has the ability to display progress or activity
97 * information behind the text. To make an entry display such information,
98 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
100 * Additionally, GtkEntry can show icons at either side of the entry. These
101 * icons can be activatable by clicking, can be set up as drag source and
102 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
103 * one of the various other functions that set an icon from a stock id, an
104 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
105 * connect to the #GtkEntry::icon-press signal. To allow DND operations
106 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
107 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
110 * Note that functionality or information that is only available by clicking
111 * on an icon in an entry may not be accessible at all to users which are not
112 * able to use a mouse or other pointing device. It is therefore recommended
113 * that any such functionality should also be available by other means, e.g.
114 * via the context menu of the entry.
118 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
120 #define MIN_ENTRY_WIDTH 150
121 #define DRAW_TIMEOUT 20
122 #define PASSWORD_HINT_MAX 8
126 #define IS_VALID_ICON_POSITION(pos) \
127 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
128 (pos) == GTK_ENTRY_ICON_SECONDARY)
130 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
131 static GQuark quark_inner_border = 0;
132 static GQuark quark_password_hint = 0;
133 static GQuark quark_cursor_hadjustment = 0;
134 static GQuark quark_capslock_feedback = 0;
136 typedef struct _EntryIconInfo EntryIconInfo;
137 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
138 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
140 struct _GtkEntryPrivate
142 EntryIconInfo *icons[MAX_ICONS];
144 GtkEntryBuffer *buffer;
145 GtkIMContext *im_context;
146 GtkWidget *popup_menu;
150 GdkWindow *text_area;
152 PangoLayout *cached_layout;
153 PangoAttrList *attrs;
157 gdouble progress_fraction;
158 gdouble progress_pulse_fraction;
159 gdouble progress_pulse_current;
161 gchar *placeholder_text;
163 GtkBubbleWindow *bubble_window;
164 GtkTextHandle *text_handle;
165 GtkWidget *selection_bubble;
166 guint selection_bubble_timeout_id;
170 gint ascent; /* font ascent in pango units */
172 gint descent; /* font descent in pango units */
173 gint dnd_position; /* In chars, -1 == no DND cursor */
178 gint selection_bound;
184 gunichar invisible_char;
187 guint blink_time; /* time in msec the cursor has blinked since last user event */
189 guint recompute_idle;
191 guint16 x_text_size; /* allocated size, in bytes */
192 guint16 x_n_bytes; /* length in use, in bytes */
194 guint16 preedit_length; /* length of preedit string, in bytes */
195 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
197 guint shadow_type : 4;
200 guint overwrite_mode : 1;
203 guint activates_default : 1;
204 guint cache_includes_preedit : 1;
205 guint caps_lock_warning : 1;
206 guint caps_lock_warning_shown : 1;
207 guint change_count : 8;
208 guint cursor_visible : 1;
209 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
211 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
212 guint is_cell_renderer : 1;
213 guint invisible_char_set : 1;
214 guint interior_focus : 1;
215 guint mouse_cursor_obscured : 1;
216 guint need_im_reset : 1;
217 guint progress_pulse_mode : 1;
218 guint progress_pulse_way_back : 1;
219 guint real_changed : 1;
220 guint resolved_dir : 4; /* PangoDirection */
221 guint select_words : 1;
222 guint select_lines : 1;
223 guint truncate_multiline : 1;
224 guint cursor_handle_dragged : 1;
225 guint selection_handle_dragged : 1;
226 guint populate_all : 1;
229 struct _EntryIconInfo
233 guint insensitive : 1;
234 guint nonactivatable : 1;
239 GtkIconHelper *icon_helper;
241 GtkTargetList *target_list;
242 GdkDragAction actions;
245 struct _GtkEntryPasswordHint
247 gint position; /* Position (in text) of the last password hint */
248 guint source_id; /* Timeout source id */
251 struct _GtkEntryCapslockFeedback
278 PROP_CURSOR_POSITION,
279 PROP_SELECTION_BOUND,
286 PROP_ACTIVATES_DEFAULT,
291 PROP_TRUNCATE_MULTILINE,
295 PROP_INVISIBLE_CHAR_SET,
296 PROP_CAPS_LOCK_WARNING,
297 PROP_PROGRESS_FRACTION,
298 PROP_PROGRESS_PULSE_STEP,
300 PROP_PIXBUF_SECONDARY,
302 PROP_STOCK_SECONDARY,
303 PROP_ICON_NAME_PRIMARY,
304 PROP_ICON_NAME_SECONDARY,
306 PROP_GICON_SECONDARY,
307 PROP_STORAGE_TYPE_PRIMARY,
308 PROP_STORAGE_TYPE_SECONDARY,
309 PROP_ACTIVATABLE_PRIMARY,
310 PROP_ACTIVATABLE_SECONDARY,
311 PROP_SENSITIVE_PRIMARY,
312 PROP_SENSITIVE_SECONDARY,
313 PROP_TOOLTIP_TEXT_PRIMARY,
314 PROP_TOOLTIP_TEXT_SECONDARY,
315 PROP_TOOLTIP_MARKUP_PRIMARY,
316 PROP_TOOLTIP_MARKUP_SECONDARY,
318 PROP_EDITING_CANCELED,
319 PROP_PLACEHOLDER_TEXT,
327 static guint signals[LAST_SIGNAL] = { 0 };
328 static gboolean test_touchscreen = FALSE;
337 DISPLAY_NORMAL, /* The entry text is being shown */
338 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
339 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
344 static void gtk_entry_editable_init (GtkEditableInterface *iface);
345 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
346 static void gtk_entry_set_property (GObject *object,
350 static void gtk_entry_get_property (GObject *object,
354 static void gtk_entry_finalize (GObject *object);
355 static void gtk_entry_dispose (GObject *object);
359 static void gtk_entry_destroy (GtkWidget *widget);
360 static void gtk_entry_realize (GtkWidget *widget);
361 static void gtk_entry_unrealize (GtkWidget *widget);
362 static void gtk_entry_map (GtkWidget *widget);
363 static void gtk_entry_unmap (GtkWidget *widget);
364 static void gtk_entry_get_preferred_width (GtkWidget *widget,
367 static void gtk_entry_get_preferred_height (GtkWidget *widget,
370 static void gtk_entry_size_allocate (GtkWidget *widget,
371 GtkAllocation *allocation);
372 static void gtk_entry_draw_frame (GtkWidget *widget,
373 GtkStyleContext *context,
375 static void gtk_entry_draw_progress (GtkWidget *widget,
376 GtkStyleContext *context,
378 static gint gtk_entry_draw (GtkWidget *widget,
380 static gint gtk_entry_button_press (GtkWidget *widget,
381 GdkEventButton *event);
382 static gint gtk_entry_button_release (GtkWidget *widget,
383 GdkEventButton *event);
384 static gint gtk_entry_enter_notify (GtkWidget *widget,
385 GdkEventCrossing *event);
386 static gint gtk_entry_leave_notify (GtkWidget *widget,
387 GdkEventCrossing *event);
388 static gint gtk_entry_motion_notify (GtkWidget *widget,
389 GdkEventMotion *event);
390 static gint gtk_entry_key_press (GtkWidget *widget,
392 static gint gtk_entry_key_release (GtkWidget *widget,
394 static gint gtk_entry_focus_in (GtkWidget *widget,
395 GdkEventFocus *event);
396 static gint gtk_entry_focus_out (GtkWidget *widget,
397 GdkEventFocus *event);
398 static void gtk_entry_grab_focus (GtkWidget *widget);
399 static void gtk_entry_style_updated (GtkWidget *widget);
400 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
403 gboolean keyboard_tip,
404 GtkTooltip *tooltip);
405 static void gtk_entry_direction_changed (GtkWidget *widget,
406 GtkTextDirection previous_dir);
407 static void gtk_entry_state_flags_changed (GtkWidget *widget,
408 GtkStateFlags previous_state);
409 static void gtk_entry_screen_changed (GtkWidget *widget,
410 GdkScreen *old_screen);
412 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
413 GdkDragContext *context,
417 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
418 GdkDragContext *context,
422 static void gtk_entry_drag_leave (GtkWidget *widget,
423 GdkDragContext *context,
425 static void gtk_entry_drag_data_received (GtkWidget *widget,
426 GdkDragContext *context,
429 GtkSelectionData *selection_data,
432 static void gtk_entry_drag_data_get (GtkWidget *widget,
433 GdkDragContext *context,
434 GtkSelectionData *selection_data,
437 static void gtk_entry_drag_data_delete (GtkWidget *widget,
438 GdkDragContext *context);
439 static void gtk_entry_drag_begin (GtkWidget *widget,
440 GdkDragContext *context);
441 static void gtk_entry_drag_end (GtkWidget *widget,
442 GdkDragContext *context);
445 /* GtkEditable method implementations
447 static void gtk_entry_insert_text (GtkEditable *editable,
448 const gchar *new_text,
449 gint new_text_length,
451 static void gtk_entry_delete_text (GtkEditable *editable,
454 static gchar * gtk_entry_get_chars (GtkEditable *editable,
457 static void gtk_entry_real_set_position (GtkEditable *editable,
459 static gint gtk_entry_get_position (GtkEditable *editable);
460 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
463 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
467 /* GtkCellEditable method implementations
469 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
472 /* Default signal handlers
474 static void gtk_entry_real_insert_text (GtkEditable *editable,
475 const gchar *new_text,
476 gint new_text_length,
478 static void gtk_entry_real_delete_text (GtkEditable *editable,
481 static void gtk_entry_move_cursor (GtkEntry *entry,
482 GtkMovementStep step,
484 gboolean extend_selection);
485 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
487 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
490 static void gtk_entry_backspace (GtkEntry *entry);
491 static void gtk_entry_cut_clipboard (GtkEntry *entry);
492 static void gtk_entry_copy_clipboard (GtkEntry *entry);
493 static void gtk_entry_paste_clipboard (GtkEntry *entry);
494 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
495 static void gtk_entry_select_all (GtkEntry *entry);
496 static void gtk_entry_real_activate (GtkEntry *entry);
497 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
499 static void keymap_direction_changed (GdkKeymap *keymap,
501 static void keymap_state_changed (GdkKeymap *keymap,
503 static void remove_capslock_feedback (GtkEntry *entry);
505 /* IM Context Callbacks
507 static void gtk_entry_commit_cb (GtkIMContext *context,
510 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
512 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
514 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
521 static void gtk_entry_enter_text (GtkEntry *entry,
523 static void gtk_entry_set_positions (GtkEntry *entry,
525 gint selection_bound);
526 static void gtk_entry_draw_text (GtkEntry *entry,
528 static void gtk_entry_draw_cursor (GtkEntry *entry,
531 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
532 gboolean include_preedit);
533 static void gtk_entry_reset_layout (GtkEntry *entry);
534 static void gtk_entry_recompute (GtkEntry *entry);
535 static gint gtk_entry_find_position (GtkEntry *entry,
537 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
541 static void gtk_entry_adjust_scroll (GtkEntry *entry);
542 static gint gtk_entry_move_visually (GtkEntry *editable,
545 static gint gtk_entry_move_logically (GtkEntry *entry,
548 static gint gtk_entry_move_forward_word (GtkEntry *entry,
550 gboolean allow_whitespace);
551 static gint gtk_entry_move_backward_word (GtkEntry *entry,
553 gboolean allow_whitespace);
554 static void gtk_entry_delete_whitespace (GtkEntry *entry);
555 static void gtk_entry_select_word (GtkEntry *entry);
556 static void gtk_entry_select_line (GtkEntry *entry);
557 static void gtk_entry_paste (GtkEntry *entry,
559 static void gtk_entry_update_primary_selection (GtkEntry *entry);
560 static void gtk_entry_do_popup (GtkEntry *entry,
561 GdkEventButton *event);
562 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
563 gboolean group_cycling);
564 static void gtk_entry_grab_notify (GtkWidget *widget,
565 gboolean was_grabbed);
566 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
567 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
568 static void gtk_entry_reset_blink_time (GtkEntry *entry);
569 static void gtk_entry_get_text_area_size (GtkEntry *entry,
574 static void gtk_entry_get_frame_size (GtkEntry *entry,
579 static void get_text_area_size (GtkEntry *entry,
584 static void get_frame_size (GtkEntry *entry,
585 gboolean relative_to_window,
590 static void gtk_entry_move_adjustments (GtkEntry *entry);
591 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
592 GtkEntryIconPosition icon_pos);
593 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
594 static gboolean get_middle_click_paste (GtkEntry *entry);
596 /* GtkTextHandle handlers */
597 static void gtk_entry_handle_dragged (GtkTextHandle *handle,
598 GtkTextHandlePosition pos,
602 static void gtk_entry_handle_drag_finished (GtkTextHandle *handle,
603 GtkTextHandlePosition pos,
606 static void gtk_entry_selection_bubble_popup_set (GtkEntry *entry);
607 static void gtk_entry_selection_bubble_popup_unset (GtkEntry *entry);
609 static void begin_change (GtkEntry *entry);
610 static void end_change (GtkEntry *entry);
611 static void emit_changed (GtkEntry *entry);
613 static void buffer_inserted_text (GtkEntryBuffer *buffer,
618 static void buffer_deleted_text (GtkEntryBuffer *buffer,
622 static void buffer_notify_text (GtkEntryBuffer *buffer,
625 static void buffer_notify_length (GtkEntryBuffer *buffer,
628 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
631 static void buffer_connect_signals (GtkEntry *entry);
632 static void buffer_disconnect_signals (GtkEntry *entry);
633 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
635 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
636 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
637 gtk_entry_editable_init)
638 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
639 gtk_entry_cell_editable_init))
642 add_move_binding (GtkBindingSet *binding_set,
645 GtkMovementStep step,
648 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
650 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
654 G_TYPE_BOOLEAN, FALSE);
656 /* Selection-extending version */
657 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
661 G_TYPE_BOOLEAN, TRUE);
665 gtk_entry_class_init (GtkEntryClass *class)
667 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
668 GtkWidgetClass *widget_class;
669 GtkBindingSet *binding_set;
671 widget_class = (GtkWidgetClass*) class;
673 gobject_class->dispose = gtk_entry_dispose;
674 gobject_class->finalize = gtk_entry_finalize;
675 gobject_class->set_property = gtk_entry_set_property;
676 gobject_class->get_property = gtk_entry_get_property;
678 widget_class->destroy = gtk_entry_destroy;
679 widget_class->map = gtk_entry_map;
680 widget_class->unmap = gtk_entry_unmap;
681 widget_class->realize = gtk_entry_realize;
682 widget_class->unrealize = gtk_entry_unrealize;
683 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
684 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
685 widget_class->size_allocate = gtk_entry_size_allocate;
686 widget_class->draw = gtk_entry_draw;
687 widget_class->enter_notify_event = gtk_entry_enter_notify;
688 widget_class->leave_notify_event = gtk_entry_leave_notify;
689 widget_class->button_press_event = gtk_entry_button_press;
690 widget_class->button_release_event = gtk_entry_button_release;
691 widget_class->motion_notify_event = gtk_entry_motion_notify;
692 widget_class->key_press_event = gtk_entry_key_press;
693 widget_class->key_release_event = gtk_entry_key_release;
694 widget_class->focus_in_event = gtk_entry_focus_in;
695 widget_class->focus_out_event = gtk_entry_focus_out;
696 widget_class->grab_focus = gtk_entry_grab_focus;
697 widget_class->style_updated = gtk_entry_style_updated;
698 widget_class->query_tooltip = gtk_entry_query_tooltip;
699 widget_class->drag_begin = gtk_entry_drag_begin;
700 widget_class->drag_end = gtk_entry_drag_end;
701 widget_class->direction_changed = gtk_entry_direction_changed;
702 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
703 widget_class->screen_changed = gtk_entry_screen_changed;
704 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
705 widget_class->grab_notify = gtk_entry_grab_notify;
707 widget_class->drag_drop = gtk_entry_drag_drop;
708 widget_class->drag_motion = gtk_entry_drag_motion;
709 widget_class->drag_leave = gtk_entry_drag_leave;
710 widget_class->drag_data_received = gtk_entry_drag_data_received;
711 widget_class->drag_data_get = gtk_entry_drag_data_get;
712 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
714 widget_class->popup_menu = gtk_entry_popup_menu;
716 class->move_cursor = gtk_entry_move_cursor;
717 class->insert_at_cursor = gtk_entry_insert_at_cursor;
718 class->delete_from_cursor = gtk_entry_delete_from_cursor;
719 class->backspace = gtk_entry_backspace;
720 class->cut_clipboard = gtk_entry_cut_clipboard;
721 class->copy_clipboard = gtk_entry_copy_clipboard;
722 class->paste_clipboard = gtk_entry_paste_clipboard;
723 class->toggle_overwrite = gtk_entry_toggle_overwrite;
724 class->activate = gtk_entry_real_activate;
725 class->get_text_area_size = gtk_entry_get_text_area_size;
726 class->get_frame_size = gtk_entry_get_frame_size;
728 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
729 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
730 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
731 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
733 g_object_class_override_property (gobject_class,
734 PROP_EDITING_CANCELED,
737 g_object_class_install_property (gobject_class,
739 g_param_spec_object ("buffer",
741 P_("Text buffer object which actually stores entry text"),
742 GTK_TYPE_ENTRY_BUFFER,
743 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
745 g_object_class_install_property (gobject_class,
746 PROP_CURSOR_POSITION,
747 g_param_spec_int ("cursor-position",
748 P_("Cursor Position"),
749 P_("The current position of the insertion cursor in chars"),
751 GTK_ENTRY_BUFFER_MAX_SIZE,
753 GTK_PARAM_READABLE));
755 g_object_class_install_property (gobject_class,
756 PROP_SELECTION_BOUND,
757 g_param_spec_int ("selection-bound",
758 P_("Selection Bound"),
759 P_("The position of the opposite end of the selection from the cursor in chars"),
761 GTK_ENTRY_BUFFER_MAX_SIZE,
763 GTK_PARAM_READABLE));
765 g_object_class_install_property (gobject_class,
767 g_param_spec_boolean ("editable",
769 P_("Whether the entry contents can be edited"),
771 GTK_PARAM_READWRITE));
773 g_object_class_install_property (gobject_class,
775 g_param_spec_int ("max-length",
776 P_("Maximum length"),
777 P_("Maximum number of characters for this entry. Zero if no maximum"),
779 GTK_ENTRY_BUFFER_MAX_SIZE,
781 GTK_PARAM_READWRITE));
782 g_object_class_install_property (gobject_class,
784 g_param_spec_boolean ("visibility",
786 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
788 GTK_PARAM_READWRITE));
790 g_object_class_install_property (gobject_class,
792 g_param_spec_boolean ("has-frame",
794 P_("FALSE removes outside bevel from entry"),
796 GTK_PARAM_READWRITE));
799 * GtkEntry:inner-border:
801 * Sets the text area's border between the text and the frame.
803 * Deprecated: 3.4: Use the standard border and padding CSS properties
804 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
805 * of this style property is ignored.
807 g_object_class_install_property (gobject_class,
809 g_param_spec_boxed ("inner-border",
811 P_("Border between text and frame. Overrides the inner-border style property"),
813 GTK_PARAM_READWRITE |
814 G_PARAM_DEPRECATED));
816 g_object_class_install_property (gobject_class,
818 g_param_spec_unichar ("invisible-char",
819 P_("Invisible character"),
820 P_("The character to use when masking entry contents (in \"password mode\")"),
822 GTK_PARAM_READWRITE));
824 g_object_class_install_property (gobject_class,
825 PROP_ACTIVATES_DEFAULT,
826 g_param_spec_boolean ("activates-default",
827 P_("Activates default"),
828 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
830 GTK_PARAM_READWRITE));
831 g_object_class_install_property (gobject_class,
833 g_param_spec_int ("width-chars",
834 P_("Width in chars"),
835 P_("Number of characters to leave space for in the entry"),
839 GTK_PARAM_READWRITE));
841 g_object_class_install_property (gobject_class,
843 g_param_spec_int ("scroll-offset",
845 P_("Number of pixels of the entry scrolled off the screen to the left"),
849 GTK_PARAM_READABLE));
851 g_object_class_install_property (gobject_class,
853 g_param_spec_string ("text",
855 P_("The contents of the entry"),
857 GTK_PARAM_READWRITE));
862 * The horizontal alignment, from 0 (left) to 1 (right).
863 * Reversed for RTL layouts.
867 g_object_class_install_property (gobject_class,
869 g_param_spec_float ("xalign",
871 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
875 GTK_PARAM_READWRITE));
878 * GtkEntry:truncate-multiline:
880 * When %TRUE, pasted multi-line text is truncated to the first line.
884 g_object_class_install_property (gobject_class,
885 PROP_TRUNCATE_MULTILINE,
886 g_param_spec_boolean ("truncate-multiline",
887 P_("Truncate multiline"),
888 P_("Whether to truncate multiline pastes to one line."),
890 GTK_PARAM_READWRITE));
893 * GtkEntry:shadow-type:
895 * Which kind of shadow to draw around the entry when
896 * #GtkEntry:has-frame is set to %TRUE.
900 g_object_class_install_property (gobject_class,
902 g_param_spec_enum ("shadow-type",
904 P_("Which kind of shadow to draw around the entry when has-frame is set"),
905 GTK_TYPE_SHADOW_TYPE,
907 GTK_PARAM_READWRITE));
910 * GtkEntry:overwrite-mode:
912 * If text is overwritten when typing in the #GtkEntry.
916 g_object_class_install_property (gobject_class,
918 g_param_spec_boolean ("overwrite-mode",
919 P_("Overwrite mode"),
920 P_("Whether new text overwrites existing text"),
922 GTK_PARAM_READWRITE));
925 * GtkEntry:text-length:
927 * The length of the text in the #GtkEntry.
931 g_object_class_install_property (gobject_class,
933 g_param_spec_uint ("text-length",
935 P_("Length of the text currently in the entry"),
939 GTK_PARAM_READABLE));
941 * GtkEntry:invisible-char-set:
943 * Whether the invisible char has been set for the #GtkEntry.
947 g_object_class_install_property (gobject_class,
948 PROP_INVISIBLE_CHAR_SET,
949 g_param_spec_boolean ("invisible-char-set",
950 P_("Invisible character set"),
951 P_("Whether the invisible character has been set"),
953 GTK_PARAM_READWRITE));
956 * GtkEntry:caps-lock-warning:
958 * Whether password entries will show a warning when Caps Lock is on.
960 * Note that the warning is shown using a secondary icon, and thus
961 * does not work if you are using the secondary icon position for some
966 g_object_class_install_property (gobject_class,
967 PROP_CAPS_LOCK_WARNING,
968 g_param_spec_boolean ("caps-lock-warning",
969 P_("Caps Lock warning"),
970 P_("Whether password entries will show a warning when Caps Lock is on"),
972 GTK_PARAM_READWRITE));
975 * GtkEntry:progress-fraction:
977 * The current fraction of the task that's been completed.
981 g_object_class_install_property (gobject_class,
982 PROP_PROGRESS_FRACTION,
983 g_param_spec_double ("progress-fraction",
984 P_("Progress Fraction"),
985 P_("The current fraction of the task that's been completed"),
989 GTK_PARAM_READWRITE));
992 * GtkEntry:progress-pulse-step:
994 * The fraction of total entry width to move the progress
995 * bouncing block for each call to gtk_entry_progress_pulse().
999 g_object_class_install_property (gobject_class,
1000 PROP_PROGRESS_PULSE_STEP,
1001 g_param_spec_double ("progress-pulse-step",
1002 P_("Progress Pulse Step"),
1003 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
1007 GTK_PARAM_READWRITE));
1010 * GtkEntry:placeholder-text:
1012 * The text that will be displayed in the #GtkEntry when it is empty
1017 g_object_class_install_property (gobject_class,
1018 PROP_PLACEHOLDER_TEXT,
1019 g_param_spec_string ("placeholder-text",
1020 P_("Placeholder text"),
1021 P_("Show text in the entry when it's empty and unfocused"),
1023 GTK_PARAM_READWRITE));
1026 * GtkEntry:primary-icon-pixbuf:
1028 * A pixbuf to use as the primary icon for the entry.
1032 g_object_class_install_property (gobject_class,
1033 PROP_PIXBUF_PRIMARY,
1034 g_param_spec_object ("primary-icon-pixbuf",
1035 P_("Primary pixbuf"),
1036 P_("Primary pixbuf for the entry"),
1038 GTK_PARAM_READWRITE));
1041 * GtkEntry:secondary-icon-pixbuf:
1043 * An pixbuf to use as the secondary icon for the entry.
1047 g_object_class_install_property (gobject_class,
1048 PROP_PIXBUF_SECONDARY,
1049 g_param_spec_object ("secondary-icon-pixbuf",
1050 P_("Secondary pixbuf"),
1051 P_("Secondary pixbuf for the entry"),
1053 GTK_PARAM_READWRITE));
1056 * GtkEntry:primary-icon-stock:
1058 * The stock id to use for the primary icon for the entry.
1062 g_object_class_install_property (gobject_class,
1064 g_param_spec_string ("primary-icon-stock",
1065 P_("Primary stock ID"),
1066 P_("Stock ID for primary icon"),
1068 GTK_PARAM_READWRITE));
1071 * GtkEntry:secondary-icon-stock:
1073 * The stock id to use for the secondary icon for the entry.
1077 g_object_class_install_property (gobject_class,
1078 PROP_STOCK_SECONDARY,
1079 g_param_spec_string ("secondary-icon-stock",
1080 P_("Secondary stock ID"),
1081 P_("Stock ID for secondary icon"),
1083 GTK_PARAM_READWRITE));
1086 * GtkEntry:primary-icon-name:
1088 * The icon name to use for the primary icon for the entry.
1092 g_object_class_install_property (gobject_class,
1093 PROP_ICON_NAME_PRIMARY,
1094 g_param_spec_string ("primary-icon-name",
1095 P_("Primary icon name"),
1096 P_("Icon name for primary icon"),
1098 GTK_PARAM_READWRITE));
1101 * GtkEntry:secondary-icon-name:
1103 * The icon name to use for the secondary icon for the entry.
1107 g_object_class_install_property (gobject_class,
1108 PROP_ICON_NAME_SECONDARY,
1109 g_param_spec_string ("secondary-icon-name",
1110 P_("Secondary icon name"),
1111 P_("Icon name for secondary icon"),
1113 GTK_PARAM_READWRITE));
1116 * GtkEntry:primary-icon-gicon:
1118 * The #GIcon to use for the primary icon for the entry.
1122 g_object_class_install_property (gobject_class,
1124 g_param_spec_object ("primary-icon-gicon",
1125 P_("Primary GIcon"),
1126 P_("GIcon for primary icon"),
1128 GTK_PARAM_READWRITE));
1131 * GtkEntry:secondary-icon-gicon:
1133 * The #GIcon to use for the secondary icon for the entry.
1137 g_object_class_install_property (gobject_class,
1138 PROP_GICON_SECONDARY,
1139 g_param_spec_object ("secondary-icon-gicon",
1140 P_("Secondary GIcon"),
1141 P_("GIcon for secondary icon"),
1143 GTK_PARAM_READWRITE));
1146 * GtkEntry:primary-icon-storage-type:
1148 * The representation which is used for the primary icon of the entry.
1152 g_object_class_install_property (gobject_class,
1153 PROP_STORAGE_TYPE_PRIMARY,
1154 g_param_spec_enum ("primary-icon-storage-type",
1155 P_("Primary storage type"),
1156 P_("The representation being used for primary icon"),
1157 GTK_TYPE_IMAGE_TYPE,
1159 GTK_PARAM_READABLE));
1162 * GtkEntry:secondary-icon-storage-type:
1164 * The representation which is used for the secondary icon of the entry.
1168 g_object_class_install_property (gobject_class,
1169 PROP_STORAGE_TYPE_SECONDARY,
1170 g_param_spec_enum ("secondary-icon-storage-type",
1171 P_("Secondary storage type"),
1172 P_("The representation being used for secondary icon"),
1173 GTK_TYPE_IMAGE_TYPE,
1175 GTK_PARAM_READABLE));
1178 * GtkEntry:primary-icon-activatable:
1180 * Whether the primary icon is activatable.
1182 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1183 * signals only on sensitive, activatable icons.
1185 * Sensitive, but non-activatable icons can be used for purely
1186 * informational purposes.
1190 g_object_class_install_property (gobject_class,
1191 PROP_ACTIVATABLE_PRIMARY,
1192 g_param_spec_boolean ("primary-icon-activatable",
1193 P_("Primary icon activatable"),
1194 P_("Whether the primary icon is activatable"),
1196 GTK_PARAM_READWRITE));
1199 * GtkEntry:secondary-icon-activatable:
1201 * Whether the secondary icon is activatable.
1203 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1204 * signals only on sensitive, activatable icons.
1206 * Sensitive, but non-activatable icons can be used for purely
1207 * informational purposes.
1211 g_object_class_install_property (gobject_class,
1212 PROP_ACTIVATABLE_SECONDARY,
1213 g_param_spec_boolean ("secondary-icon-activatable",
1214 P_("Secondary icon activatable"),
1215 P_("Whether the secondary icon is activatable"),
1217 GTK_PARAM_READWRITE));
1221 * GtkEntry:primary-icon-sensitive:
1223 * Whether the primary icon is sensitive.
1225 * An insensitive icon appears grayed out. GTK+ does not emit the
1226 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1227 * does not allow DND from insensitive icons.
1229 * An icon should be set insensitive if the action that would trigger
1230 * when clicked is currently not available.
1234 g_object_class_install_property (gobject_class,
1235 PROP_SENSITIVE_PRIMARY,
1236 g_param_spec_boolean ("primary-icon-sensitive",
1237 P_("Primary icon sensitive"),
1238 P_("Whether the primary icon is sensitive"),
1240 GTK_PARAM_READWRITE));
1243 * GtkEntry:secondary-icon-sensitive:
1245 * Whether the secondary icon is sensitive.
1247 * An insensitive icon appears grayed out. GTK+ does not emit the
1248 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1249 * does not allow DND from insensitive icons.
1251 * An icon should be set insensitive if the action that would trigger
1252 * when clicked is currently not available.
1256 g_object_class_install_property (gobject_class,
1257 PROP_SENSITIVE_SECONDARY,
1258 g_param_spec_boolean ("secondary-icon-sensitive",
1259 P_("Secondary icon sensitive"),
1260 P_("Whether the secondary icon is sensitive"),
1262 GTK_PARAM_READWRITE));
1265 * GtkEntry:primary-icon-tooltip-text:
1267 * The contents of the tooltip on the primary icon.
1269 * Also see gtk_entry_set_icon_tooltip_text().
1273 g_object_class_install_property (gobject_class,
1274 PROP_TOOLTIP_TEXT_PRIMARY,
1275 g_param_spec_string ("primary-icon-tooltip-text",
1276 P_("Primary icon tooltip text"),
1277 P_("The contents of the tooltip on the primary icon"),
1279 GTK_PARAM_READWRITE));
1282 * GtkEntry:secondary-icon-tooltip-text:
1284 * The contents of the tooltip on the secondary icon.
1286 * Also see gtk_entry_set_icon_tooltip_text().
1290 g_object_class_install_property (gobject_class,
1291 PROP_TOOLTIP_TEXT_SECONDARY,
1292 g_param_spec_string ("secondary-icon-tooltip-text",
1293 P_("Secondary icon tooltip text"),
1294 P_("The contents of the tooltip on the secondary icon"),
1296 GTK_PARAM_READWRITE));
1299 * GtkEntry:primary-icon-tooltip-markup:
1301 * The contents of the tooltip on the primary icon, which is marked up
1302 * with the <link linkend="PangoMarkupFormat">Pango text markup
1305 * Also see gtk_entry_set_icon_tooltip_markup().
1309 g_object_class_install_property (gobject_class,
1310 PROP_TOOLTIP_MARKUP_PRIMARY,
1311 g_param_spec_string ("primary-icon-tooltip-markup",
1312 P_("Primary icon tooltip markup"),
1313 P_("The contents of the tooltip on the primary icon"),
1315 GTK_PARAM_READWRITE));
1318 * GtkEntry:secondary-icon-tooltip-markup:
1320 * The contents of the tooltip on the secondary icon, which is marked up
1321 * with the <link linkend="PangoMarkupFormat">Pango text markup
1324 * Also see gtk_entry_set_icon_tooltip_markup().
1328 g_object_class_install_property (gobject_class,
1329 PROP_TOOLTIP_MARKUP_SECONDARY,
1330 g_param_spec_string ("secondary-icon-tooltip-markup",
1331 P_("Secondary icon tooltip markup"),
1332 P_("The contents of the tooltip on the secondary icon"),
1334 GTK_PARAM_READWRITE));
1337 * GtkEntry:im-module:
1339 * Which IM (input method) module should be used for this entry.
1340 * See #GtkIMContext.
1342 * Setting this to a non-%NULL value overrides the
1343 * system-wide IM module setting. See the GtkSettings
1344 * #GtkSettings:gtk-im-module property.
1348 g_object_class_install_property (gobject_class,
1350 g_param_spec_string ("im-module",
1352 P_("Which IM module should be used"),
1354 GTK_PARAM_READWRITE));
1357 * GtkEntry:completion:
1359 * The auxiliary completion object to use with the entry.
1363 g_object_class_install_property (gobject_class,
1365 g_param_spec_object ("completion",
1367 P_("The auxiliary completion object"),
1368 GTK_TYPE_ENTRY_COMPLETION,
1369 GTK_PARAM_READWRITE));
1372 * GtkEntry:input-purpose:
1374 * The purpose of this text field.
1376 * This property can be used by on-screen keyboards and other input
1377 * methods to adjust their behaviour.
1379 * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
1380 * %GTK_INPUT_PURPOSE_PIN is independent from setting
1381 * #GtkEntry:visibility.
1385 g_object_class_install_property (gobject_class,
1387 g_param_spec_enum ("input-purpose",
1389 P_("Purpose of the text field"),
1390 GTK_TYPE_INPUT_PURPOSE,
1391 GTK_INPUT_PURPOSE_FREE_FORM,
1392 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1395 * GtkEntry:input-hints:
1397 * Additional hints (beyond #GtkEntry:input-purpose) that
1398 * allow input methods to fine-tune their behaviour.
1402 g_object_class_install_property (gobject_class,
1404 g_param_spec_flags ("input-hints",
1406 P_("Hints for the text field behaviour"),
1407 GTK_TYPE_INPUT_HINTS,
1408 GTK_INPUT_HINT_NONE,
1409 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1412 * GtkEntry:attributes:
1414 * A list of Pango attributes to apply to the text of the entry.
1416 * This is mainly useful to change the size or weight of the text.
1420 g_object_class_install_property (gobject_class,
1422 g_param_spec_boxed ("attributes",
1424 P_("A list of style attributes to apply to the text of the label"),
1425 PANGO_TYPE_ATTR_LIST,
1426 GTK_PARAM_READWRITE));
1428 /** GtkEntry:populate-all:
1430 * If ::populate-all is %TRUE, the #GtkEntry::populate-popup
1431 * signal is also emitted for touch popups.
1435 g_object_class_install_property (gobject_class,
1437 g_param_spec_boolean ("populate-all",
1439 P_("Whether to emit ::populate-popup for touch popups"),
1441 GTK_PARAM_READWRITE));
1444 * GtkEntry:icon-prelight:
1446 * The prelight style property determines whether activatable
1447 * icons prelight on mouseover.
1451 gtk_widget_class_install_style_property (widget_class,
1452 g_param_spec_boolean ("icon-prelight",
1453 P_("Icon Prelight"),
1454 P_("Whether activatable icons should prelight when hovered"),
1456 GTK_PARAM_READABLE));
1459 * GtkEntry:progress-border:
1461 * The border around the progress bar in the entry.
1465 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1466 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1467 * property is ignored.
1469 gtk_widget_class_install_style_property (widget_class,
1470 g_param_spec_boxed ("progress-border",
1471 P_("Progress Border"),
1472 P_("Border around the progress bar"),
1474 GTK_PARAM_READABLE |
1475 G_PARAM_DEPRECATED));
1478 * GtkEntry:invisible-char:
1480 * The invisible character is used when masking entry contents (in
1481 * \"password mode\")"). When it is not explicitly set with the
1482 * #GtkEntry:invisible-char property, GTK+ determines the character
1483 * to use from a list of possible candidates, depending on availability
1484 * in the current font.
1486 * This style property allows the theme to prepend a character
1487 * to the list of candidates.
1491 gtk_widget_class_install_style_property (widget_class,
1492 g_param_spec_unichar ("invisible-char",
1493 P_("Invisible character"),
1494 P_("The character to use when masking entry contents (in \"password mode\")"),
1496 GTK_PARAM_READABLE));
1499 * GtkEntry::populate-popup:
1500 * @entry: The entry on which the signal is emitted
1501 * @popup: the container that is being populated
1503 * The ::populate-popup signal gets emitted before showing the
1504 * context menu of the entry.
1506 * If you need to add items to the context menu, connect
1507 * to this signal and append your items to the @widget, which
1508 * will be a #GtkMenu in this case.
1510 * If #GtkEntry::populate-all is %TRUE, this signal will
1511 * also be emitted to populate touch popups. In this case,
1512 * @widget will be a different container, e.g. a #GtkToolbar.
1513 * The signal handler should not make assumptions about the
1516 signals[POPULATE_POPUP] =
1517 g_signal_new (I_("populate-popup"),
1518 G_OBJECT_CLASS_TYPE (gobject_class),
1520 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1522 _gtk_marshal_VOID__OBJECT,
1526 /* Action signals */
1529 * GtkEntry::activate:
1530 * @entry: The entry on which the signal is emitted
1532 * The ::activate signal is emitted when the user hits
1535 * While this signal is used as a
1536 * <link linkend="keybinding-signals">keybinding signal</link>,
1537 * it is also commonly used by applications to intercept
1538 * activation of entries.
1540 * The default bindings for this signal are all forms of the Enter key.
1543 g_signal_new (I_("activate"),
1544 G_OBJECT_CLASS_TYPE (gobject_class),
1545 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1546 G_STRUCT_OFFSET (GtkEntryClass, activate),
1548 _gtk_marshal_VOID__VOID,
1550 widget_class->activate_signal = signals[ACTIVATE];
1553 * GtkEntry::move-cursor:
1554 * @entry: the object which received the signal
1555 * @step: the granularity of the move, as a #GtkMovementStep
1556 * @count: the number of @step units to move
1557 * @extend_selection: %TRUE if the move should extend the selection
1559 * The ::move-cursor signal is a
1560 * <link linkend="keybinding-signals">keybinding signal</link>
1561 * which gets emitted when the user initiates a cursor movement.
1562 * If the cursor is not visible in @entry, this signal causes
1563 * the viewport to be moved instead.
1565 * Applications should not connect to it, but may emit it with
1566 * g_signal_emit_by_name() if they need to control the cursor
1569 * The default bindings for this signal come in two variants,
1570 * the variant with the Shift modifier extends the selection,
1571 * the variant without the Shift modifer does not.
1572 * There are too many key combinations to list them all here.
1574 * <listitem>Arrow keys move by individual characters/lines</listitem>
1575 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1576 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1579 signals[MOVE_CURSOR] =
1580 g_signal_new (I_("move-cursor"),
1581 G_OBJECT_CLASS_TYPE (gobject_class),
1582 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1583 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1585 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1587 GTK_TYPE_MOVEMENT_STEP,
1592 * GtkEntry::insert-at-cursor:
1593 * @entry: the object which received the signal
1594 * @string: the string to insert
1596 * The ::insert-at-cursor signal is a
1597 * <link linkend="keybinding-signals">keybinding signal</link>
1598 * which gets emitted when the user initiates the insertion of a
1599 * fixed string at the cursor.
1601 * This signal has no default bindings.
1603 signals[INSERT_AT_CURSOR] =
1604 g_signal_new (I_("insert-at-cursor"),
1605 G_OBJECT_CLASS_TYPE (gobject_class),
1606 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1607 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1609 _gtk_marshal_VOID__STRING,
1614 * GtkEntry::delete-from-cursor:
1615 * @entry: the object which received the signal
1616 * @type: the granularity of the deletion, as a #GtkDeleteType
1617 * @count: the number of @type units to delete
1619 * The ::delete-from-cursor signal is a
1620 * <link linkend="keybinding-signals">keybinding signal</link>
1621 * which gets emitted when the user initiates a text deletion.
1623 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1624 * if there is one, otherwise it deletes the requested number
1627 * The default bindings for this signal are
1628 * Delete for deleting a character and Ctrl-Delete for
1631 signals[DELETE_FROM_CURSOR] =
1632 g_signal_new (I_("delete-from-cursor"),
1633 G_OBJECT_CLASS_TYPE (gobject_class),
1634 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1635 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1637 _gtk_marshal_VOID__ENUM_INT,
1639 GTK_TYPE_DELETE_TYPE,
1643 * GtkEntry::backspace:
1644 * @entry: the object which received the signal
1646 * The ::backspace signal is a
1647 * <link linkend="keybinding-signals">keybinding signal</link>
1648 * which gets emitted when the user asks for it.
1650 * The default bindings for this signal are
1651 * Backspace and Shift-Backspace.
1653 signals[BACKSPACE] =
1654 g_signal_new (I_("backspace"),
1655 G_OBJECT_CLASS_TYPE (gobject_class),
1656 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1657 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1659 _gtk_marshal_VOID__VOID,
1663 * GtkEntry::cut-clipboard:
1664 * @entry: the object which received the signal
1666 * The ::cut-clipboard signal is a
1667 * <link linkend="keybinding-signals">keybinding signal</link>
1668 * which gets emitted to cut the selection to the clipboard.
1670 * The default bindings for this signal are
1671 * Ctrl-x and Shift-Delete.
1673 signals[CUT_CLIPBOARD] =
1674 g_signal_new (I_("cut-clipboard"),
1675 G_OBJECT_CLASS_TYPE (gobject_class),
1676 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1677 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1679 _gtk_marshal_VOID__VOID,
1683 * GtkEntry::copy-clipboard:
1684 * @entry: the object which received the signal
1686 * The ::copy-clipboard signal is a
1687 * <link linkend="keybinding-signals">keybinding signal</link>
1688 * which gets emitted to copy the selection to the clipboard.
1690 * The default bindings for this signal are
1691 * Ctrl-c and Ctrl-Insert.
1693 signals[COPY_CLIPBOARD] =
1694 g_signal_new (I_("copy-clipboard"),
1695 G_OBJECT_CLASS_TYPE (gobject_class),
1696 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1697 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1699 _gtk_marshal_VOID__VOID,
1703 * GtkEntry::paste-clipboard:
1704 * @entry: the object which received the signal
1706 * The ::paste-clipboard signal is a
1707 * <link linkend="keybinding-signals">keybinding signal</link>
1708 * which gets emitted to paste the contents of the clipboard
1709 * into the text view.
1711 * The default bindings for this signal are
1712 * Ctrl-v and Shift-Insert.
1714 signals[PASTE_CLIPBOARD] =
1715 g_signal_new (I_("paste-clipboard"),
1716 G_OBJECT_CLASS_TYPE (gobject_class),
1717 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1718 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1720 _gtk_marshal_VOID__VOID,
1724 * GtkEntry::toggle-overwrite:
1725 * @entry: the object which received the signal
1727 * The ::toggle-overwrite signal is a
1728 * <link linkend="keybinding-signals">keybinding signal</link>
1729 * which gets emitted to toggle the overwrite mode of the entry.
1731 * The default bindings for this signal is Insert.
1733 signals[TOGGLE_OVERWRITE] =
1734 g_signal_new (I_("toggle-overwrite"),
1735 G_OBJECT_CLASS_TYPE (gobject_class),
1736 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1737 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1739 _gtk_marshal_VOID__VOID,
1743 * GtkEntry::icon-press:
1744 * @entry: The entry on which the signal is emitted
1745 * @icon_pos: The position of the clicked icon
1746 * @event: (type Gdk.EventButton): the button press event
1748 * The ::icon-press signal is emitted when an activatable icon
1753 signals[ICON_PRESS] =
1754 g_signal_new (I_("icon-press"),
1755 G_TYPE_FROM_CLASS (gobject_class),
1759 _gtk_marshal_VOID__ENUM_BOXED,
1761 GTK_TYPE_ENTRY_ICON_POSITION,
1762 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1765 * GtkEntry::icon-release:
1766 * @entry: The entry on which the signal is emitted
1767 * @icon_pos: The position of the clicked icon
1768 * @event: (type Gdk.EventButton): the button release event
1770 * The ::icon-release signal is emitted on the button release from a
1771 * mouse click over an activatable icon.
1775 signals[ICON_RELEASE] =
1776 g_signal_new (I_("icon-release"),
1777 G_TYPE_FROM_CLASS (gobject_class),
1781 _gtk_marshal_VOID__ENUM_BOXED,
1783 GTK_TYPE_ENTRY_ICON_POSITION,
1784 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1787 * GtkEntry::preedit-changed:
1788 * @entry: the object which received the signal
1789 * @preedit: the current preedit string
1791 * If an input method is used, the typed text will not immediately
1792 * be committed to the buffer. So if you are interested in the text,
1793 * connect to this signal.
1797 signals[PREEDIT_CHANGED] =
1798 g_signal_new_class_handler (I_("preedit-changed"),
1799 G_OBJECT_CLASS_TYPE (gobject_class),
1800 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1803 _gtk_marshal_VOID__STRING,
1812 binding_set = gtk_binding_set_by_class (class);
1814 /* Moving the insertion point */
1815 add_move_binding (binding_set, GDK_KEY_Right, 0,
1816 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1818 add_move_binding (binding_set, GDK_KEY_Left, 0,
1819 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1821 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1822 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1824 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1825 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1827 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1828 GTK_MOVEMENT_WORDS, 1);
1830 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1831 GTK_MOVEMENT_WORDS, -1);
1833 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1834 GTK_MOVEMENT_WORDS, 1);
1836 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1837 GTK_MOVEMENT_WORDS, -1);
1839 add_move_binding (binding_set, GDK_KEY_Home, 0,
1840 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1842 add_move_binding (binding_set, GDK_KEY_End, 0,
1843 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1845 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1846 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1848 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1849 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1851 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1852 GTK_MOVEMENT_BUFFER_ENDS, -1);
1854 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1855 GTK_MOVEMENT_BUFFER_ENDS, 1);
1857 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1858 GTK_MOVEMENT_BUFFER_ENDS, -1);
1860 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1861 GTK_MOVEMENT_BUFFER_ENDS, 1);
1865 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1867 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1869 G_TYPE_BOOLEAN, FALSE);
1870 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1872 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1874 G_TYPE_BOOLEAN, TRUE);
1876 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1878 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1880 G_TYPE_BOOLEAN, FALSE);
1881 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1883 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1885 G_TYPE_BOOLEAN, TRUE);
1888 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1890 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1892 G_TYPE_BOOLEAN, FALSE);
1893 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1895 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1897 G_TYPE_BOOLEAN, FALSE);
1901 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1903 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1905 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1909 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1910 "delete-from-cursor", 2,
1911 G_TYPE_ENUM, GTK_DELETE_CHARS,
1914 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1915 "delete-from-cursor", 2,
1916 G_TYPE_ENUM, GTK_DELETE_CHARS,
1919 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1922 /* Make this do the same as Backspace, to help with mis-typing */
1923 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1926 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1927 "delete-from-cursor", 2,
1928 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1931 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1932 "delete-from-cursor", 2,
1933 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1936 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1937 "delete-from-cursor", 2,
1938 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1941 /* Cut/copy/paste */
1943 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1944 "cut-clipboard", 0);
1945 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1946 "copy-clipboard", 0);
1947 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1948 "paste-clipboard", 0);
1950 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1951 "cut-clipboard", 0);
1952 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1953 "copy-clipboard", 0);
1954 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1955 "paste-clipboard", 0);
1958 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1959 "toggle-overwrite", 0);
1960 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1961 "toggle-overwrite", 0);
1964 * GtkEntry:inner-border:
1966 * Sets the text area's border between the text and the frame.
1970 * Deprecated: 3.4: Use the standard border and padding CSS properties
1971 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1972 * of this style property is ignored.
1974 gtk_widget_class_install_style_property (widget_class,
1975 g_param_spec_boxed ("inner-border",
1977 P_("Border between text and frame."),
1979 GTK_PARAM_READABLE |
1980 G_PARAM_DEPRECATED));
1982 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1983 test_touchscreen = g_getenv ("GTK_TEST_TOUCHSCREEN") != NULL;
1985 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1989 gtk_entry_editable_init (GtkEditableInterface *iface)
1991 iface->do_insert_text = gtk_entry_insert_text;
1992 iface->do_delete_text = gtk_entry_delete_text;
1993 iface->insert_text = gtk_entry_real_insert_text;
1994 iface->delete_text = gtk_entry_real_delete_text;
1995 iface->get_chars = gtk_entry_get_chars;
1996 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1997 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1998 iface->set_position = gtk_entry_real_set_position;
1999 iface->get_position = gtk_entry_get_position;
2003 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
2005 iface->start_editing = gtk_entry_start_editing;
2008 /* for deprecated properties */
2010 gtk_entry_do_set_inner_border (GtkEntry *entry,
2011 const GtkBorder *border)
2014 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
2015 gtk_border_copy (border),
2016 (GDestroyNotify) gtk_border_free);
2018 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
2020 g_object_notify (G_OBJECT (entry), "inner-border");
2023 static const GtkBorder *
2024 gtk_entry_do_get_inner_border (GtkEntry *entry)
2026 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
2030 gtk_entry_set_property (GObject *object,
2032 const GValue *value,
2035 GtkEntry *entry = GTK_ENTRY (object);
2036 GtkEntryPrivate *priv = entry->priv;
2041 gtk_entry_set_buffer (entry, g_value_get_object (value));
2046 gboolean new_value = g_value_get_boolean (value);
2048 if (new_value != priv->editable)
2050 GtkWidget *widget = GTK_WIDGET (entry);
2054 gtk_entry_reset_im_context (entry);
2055 if (gtk_widget_has_focus (widget))
2056 gtk_im_context_focus_out (priv->im_context);
2058 priv->preedit_length = 0;
2059 priv->preedit_cursor = 0;
2062 priv->editable = new_value;
2064 if (new_value && gtk_widget_has_focus (widget))
2065 gtk_im_context_focus_in (priv->im_context);
2067 gtk_widget_queue_draw (widget);
2072 case PROP_MAX_LENGTH:
2073 gtk_entry_set_max_length (entry, g_value_get_int (value));
2076 case PROP_VISIBILITY:
2077 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
2080 case PROP_HAS_FRAME:
2081 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
2084 case PROP_INNER_BORDER:
2085 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
2088 case PROP_INVISIBLE_CHAR:
2089 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2092 case PROP_ACTIVATES_DEFAULT:
2093 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2096 case PROP_WIDTH_CHARS:
2097 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2101 gtk_entry_set_text (entry, g_value_get_string (value));
2105 gtk_entry_set_alignment (entry, g_value_get_float (value));
2108 case PROP_TRUNCATE_MULTILINE:
2109 priv->truncate_multiline = g_value_get_boolean (value);
2112 case PROP_SHADOW_TYPE:
2113 priv->shadow_type = g_value_get_enum (value);
2116 case PROP_OVERWRITE_MODE:
2117 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2120 case PROP_INVISIBLE_CHAR_SET:
2121 if (g_value_get_boolean (value))
2122 priv->invisible_char_set = TRUE;
2124 gtk_entry_unset_invisible_char (entry);
2127 case PROP_CAPS_LOCK_WARNING:
2128 priv->caps_lock_warning = g_value_get_boolean (value);
2131 case PROP_PROGRESS_FRACTION:
2132 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2135 case PROP_PROGRESS_PULSE_STEP:
2136 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2139 case PROP_PLACEHOLDER_TEXT:
2140 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2143 case PROP_PIXBUF_PRIMARY:
2144 gtk_entry_set_icon_from_pixbuf (entry,
2145 GTK_ENTRY_ICON_PRIMARY,
2146 g_value_get_object (value));
2149 case PROP_PIXBUF_SECONDARY:
2150 gtk_entry_set_icon_from_pixbuf (entry,
2151 GTK_ENTRY_ICON_SECONDARY,
2152 g_value_get_object (value));
2155 case PROP_STOCK_PRIMARY:
2156 gtk_entry_set_icon_from_stock (entry,
2157 GTK_ENTRY_ICON_PRIMARY,
2158 g_value_get_string (value));
2161 case PROP_STOCK_SECONDARY:
2162 gtk_entry_set_icon_from_stock (entry,
2163 GTK_ENTRY_ICON_SECONDARY,
2164 g_value_get_string (value));
2167 case PROP_ICON_NAME_PRIMARY:
2168 gtk_entry_set_icon_from_icon_name (entry,
2169 GTK_ENTRY_ICON_PRIMARY,
2170 g_value_get_string (value));
2173 case PROP_ICON_NAME_SECONDARY:
2174 gtk_entry_set_icon_from_icon_name (entry,
2175 GTK_ENTRY_ICON_SECONDARY,
2176 g_value_get_string (value));
2179 case PROP_GICON_PRIMARY:
2180 gtk_entry_set_icon_from_gicon (entry,
2181 GTK_ENTRY_ICON_PRIMARY,
2182 g_value_get_object (value));
2185 case PROP_GICON_SECONDARY:
2186 gtk_entry_set_icon_from_gicon (entry,
2187 GTK_ENTRY_ICON_SECONDARY,
2188 g_value_get_object (value));
2191 case PROP_ACTIVATABLE_PRIMARY:
2192 gtk_entry_set_icon_activatable (entry,
2193 GTK_ENTRY_ICON_PRIMARY,
2194 g_value_get_boolean (value));
2197 case PROP_ACTIVATABLE_SECONDARY:
2198 gtk_entry_set_icon_activatable (entry,
2199 GTK_ENTRY_ICON_SECONDARY,
2200 g_value_get_boolean (value));
2203 case PROP_SENSITIVE_PRIMARY:
2204 gtk_entry_set_icon_sensitive (entry,
2205 GTK_ENTRY_ICON_PRIMARY,
2206 g_value_get_boolean (value));
2209 case PROP_SENSITIVE_SECONDARY:
2210 gtk_entry_set_icon_sensitive (entry,
2211 GTK_ENTRY_ICON_SECONDARY,
2212 g_value_get_boolean (value));
2215 case PROP_TOOLTIP_TEXT_PRIMARY:
2216 gtk_entry_set_icon_tooltip_text (entry,
2217 GTK_ENTRY_ICON_PRIMARY,
2218 g_value_get_string (value));
2221 case PROP_TOOLTIP_TEXT_SECONDARY:
2222 gtk_entry_set_icon_tooltip_text (entry,
2223 GTK_ENTRY_ICON_SECONDARY,
2224 g_value_get_string (value));
2227 case PROP_TOOLTIP_MARKUP_PRIMARY:
2228 gtk_entry_set_icon_tooltip_markup (entry,
2229 GTK_ENTRY_ICON_PRIMARY,
2230 g_value_get_string (value));
2233 case PROP_TOOLTIP_MARKUP_SECONDARY:
2234 gtk_entry_set_icon_tooltip_markup (entry,
2235 GTK_ENTRY_ICON_SECONDARY,
2236 g_value_get_string (value));
2239 case PROP_IM_MODULE:
2240 g_free (priv->im_module);
2241 priv->im_module = g_value_dup_string (value);
2242 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2243 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2246 case PROP_EDITING_CANCELED:
2247 priv->editing_canceled = g_value_get_boolean (value);
2250 case PROP_COMPLETION:
2251 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2254 case PROP_INPUT_PURPOSE:
2255 gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
2258 case PROP_INPUT_HINTS:
2259 gtk_entry_set_input_hints (entry, g_value_get_flags (value));
2262 case PROP_ATTRIBUTES:
2263 gtk_entry_set_attributes (entry, g_value_get_boxed (value));
2266 case PROP_POPULATE_ALL:
2267 entry->priv->populate_all = g_value_get_boolean (value);
2270 case PROP_SCROLL_OFFSET:
2271 case PROP_CURSOR_POSITION:
2273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2279 gtk_entry_get_property (GObject *object,
2284 GtkEntry *entry = GTK_ENTRY (object);
2285 GtkEntryPrivate *priv = entry->priv;
2290 g_value_set_object (value, gtk_entry_get_buffer (entry));
2293 case PROP_CURSOR_POSITION:
2294 g_value_set_int (value, priv->current_pos);
2297 case PROP_SELECTION_BOUND:
2298 g_value_set_int (value, priv->selection_bound);
2302 g_value_set_boolean (value, priv->editable);
2305 case PROP_MAX_LENGTH:
2306 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2309 case PROP_VISIBILITY:
2310 g_value_set_boolean (value, priv->visible);
2313 case PROP_HAS_FRAME:
2314 g_value_set_boolean (value, priv->has_frame);
2317 case PROP_INNER_BORDER:
2318 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2321 case PROP_INVISIBLE_CHAR:
2322 g_value_set_uint (value, priv->invisible_char);
2325 case PROP_ACTIVATES_DEFAULT:
2326 g_value_set_boolean (value, priv->activates_default);
2329 case PROP_WIDTH_CHARS:
2330 g_value_set_int (value, priv->width_chars);
2333 case PROP_SCROLL_OFFSET:
2334 g_value_set_int (value, priv->scroll_offset);
2338 g_value_set_string (value, gtk_entry_get_text (entry));
2342 g_value_set_float (value, gtk_entry_get_alignment (entry));
2345 case PROP_TRUNCATE_MULTILINE:
2346 g_value_set_boolean (value, priv->truncate_multiline);
2349 case PROP_SHADOW_TYPE:
2350 g_value_set_enum (value, priv->shadow_type);
2353 case PROP_OVERWRITE_MODE:
2354 g_value_set_boolean (value, priv->overwrite_mode);
2357 case PROP_TEXT_LENGTH:
2358 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2361 case PROP_INVISIBLE_CHAR_SET:
2362 g_value_set_boolean (value, priv->invisible_char_set);
2365 case PROP_IM_MODULE:
2366 g_value_set_string (value, priv->im_module);
2369 case PROP_CAPS_LOCK_WARNING:
2370 g_value_set_boolean (value, priv->caps_lock_warning);
2373 case PROP_PROGRESS_FRACTION:
2374 g_value_set_double (value, priv->progress_fraction);
2377 case PROP_PROGRESS_PULSE_STEP:
2378 g_value_set_double (value, priv->progress_pulse_fraction);
2381 case PROP_PLACEHOLDER_TEXT:
2382 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2385 case PROP_PIXBUF_PRIMARY:
2386 g_value_set_object (value,
2387 gtk_entry_get_icon_pixbuf (entry,
2388 GTK_ENTRY_ICON_PRIMARY));
2391 case PROP_PIXBUF_SECONDARY:
2392 g_value_set_object (value,
2393 gtk_entry_get_icon_pixbuf (entry,
2394 GTK_ENTRY_ICON_SECONDARY));
2397 case PROP_STOCK_PRIMARY:
2398 g_value_set_string (value,
2399 gtk_entry_get_icon_stock (entry,
2400 GTK_ENTRY_ICON_PRIMARY));
2403 case PROP_STOCK_SECONDARY:
2404 g_value_set_string (value,
2405 gtk_entry_get_icon_stock (entry,
2406 GTK_ENTRY_ICON_SECONDARY));
2409 case PROP_ICON_NAME_PRIMARY:
2410 g_value_set_string (value,
2411 gtk_entry_get_icon_name (entry,
2412 GTK_ENTRY_ICON_PRIMARY));
2415 case PROP_ICON_NAME_SECONDARY:
2416 g_value_set_string (value,
2417 gtk_entry_get_icon_name (entry,
2418 GTK_ENTRY_ICON_SECONDARY));
2421 case PROP_GICON_PRIMARY:
2422 g_value_set_object (value,
2423 gtk_entry_get_icon_gicon (entry,
2424 GTK_ENTRY_ICON_PRIMARY));
2427 case PROP_GICON_SECONDARY:
2428 g_value_set_object (value,
2429 gtk_entry_get_icon_gicon (entry,
2430 GTK_ENTRY_ICON_SECONDARY));
2433 case PROP_STORAGE_TYPE_PRIMARY:
2434 g_value_set_enum (value,
2435 gtk_entry_get_icon_storage_type (entry,
2436 GTK_ENTRY_ICON_PRIMARY));
2439 case PROP_STORAGE_TYPE_SECONDARY:
2440 g_value_set_enum (value,
2441 gtk_entry_get_icon_storage_type (entry,
2442 GTK_ENTRY_ICON_SECONDARY));
2445 case PROP_ACTIVATABLE_PRIMARY:
2446 g_value_set_boolean (value,
2447 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2450 case PROP_ACTIVATABLE_SECONDARY:
2451 g_value_set_boolean (value,
2452 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2455 case PROP_SENSITIVE_PRIMARY:
2456 g_value_set_boolean (value,
2457 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2460 case PROP_SENSITIVE_SECONDARY:
2461 g_value_set_boolean (value,
2462 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2465 case PROP_TOOLTIP_TEXT_PRIMARY:
2466 g_value_take_string (value,
2467 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2470 case PROP_TOOLTIP_TEXT_SECONDARY:
2471 g_value_take_string (value,
2472 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2475 case PROP_TOOLTIP_MARKUP_PRIMARY:
2476 g_value_take_string (value,
2477 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2480 case PROP_TOOLTIP_MARKUP_SECONDARY:
2481 g_value_take_string (value,
2482 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2485 case PROP_EDITING_CANCELED:
2486 g_value_set_boolean (value,
2487 priv->editing_canceled);
2490 case PROP_COMPLETION:
2491 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2494 case PROP_INPUT_PURPOSE:
2495 g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
2498 case PROP_INPUT_HINTS:
2499 g_value_set_flags (value, gtk_entry_get_input_hints (entry));
2502 case PROP_ATTRIBUTES:
2503 g_value_set_boxed (value, priv->attrs);
2506 case PROP_POPULATE_ALL:
2507 g_value_set_boolean (value, priv->populate_all);
2511 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2517 find_invisible_char (GtkWidget *widget)
2519 PangoLayout *layout;
2520 PangoAttrList *attr_list;
2522 gunichar invisible_chars [] = {
2524 0x25cf, /* BLACK CIRCLE */
2525 0x2022, /* BULLET */
2526 0x2731, /* HEAVY ASTERISK */
2527 0x273a /* SIXTEEN POINTED ASTERISK */
2530 gtk_widget_style_get (widget,
2531 "invisible-char", &invisible_chars[0],
2534 layout = gtk_widget_create_pango_layout (widget, NULL);
2536 attr_list = pango_attr_list_new ();
2537 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2539 pango_layout_set_attributes (layout, attr_list);
2540 pango_attr_list_unref (attr_list);
2542 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2544 gchar text[7] = { 0, };
2547 len = g_unichar_to_utf8 (invisible_chars[i], text);
2548 pango_layout_set_text (layout, text, len);
2550 count = pango_layout_get_unknown_glyphs_count (layout);
2554 g_object_unref (layout);
2555 return invisible_chars[i];
2559 g_object_unref (layout);
2565 gtk_entry_init (GtkEntry *entry)
2567 GtkStyleContext *context;
2568 GtkEntryPrivate *priv;
2570 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2575 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2576 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2578 priv->editable = TRUE;
2579 priv->visible = TRUE;
2580 priv->dnd_position = -1;
2581 priv->width_chars = -1;
2582 priv->is_cell_renderer = FALSE;
2583 priv->editing_canceled = FALSE;
2584 priv->has_frame = TRUE;
2585 priv->truncate_multiline = FALSE;
2586 priv->shadow_type = GTK_SHADOW_IN;
2588 priv->caps_lock_warning = TRUE;
2589 priv->caps_lock_warning_shown = FALSE;
2590 priv->progress_fraction = 0.0;
2591 priv->progress_pulse_fraction = 0.1;
2593 gtk_drag_dest_set (GTK_WIDGET (entry),
2594 GTK_DEST_DEFAULT_HIGHLIGHT,
2596 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2597 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2599 /* This object is completely private. No external entity can gain a reference
2600 * to it; so we create it here and destroy it in finalize().
2602 priv->im_context = gtk_im_multicontext_new ();
2604 g_signal_connect (priv->im_context, "commit",
2605 G_CALLBACK (gtk_entry_commit_cb), entry);
2606 g_signal_connect (priv->im_context, "preedit-changed",
2607 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2608 g_signal_connect (priv->im_context, "retrieve-surrounding",
2609 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2610 g_signal_connect (priv->im_context, "delete-surrounding",
2611 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2613 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2614 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2616 gtk_entry_update_cached_style_values (entry);
2618 priv->text_handle = _gtk_text_handle_new (GTK_WIDGET (entry));
2619 g_signal_connect (priv->text_handle, "handle-dragged",
2620 G_CALLBACK (gtk_entry_handle_dragged), entry);
2621 g_signal_connect (priv->text_handle, "drag-finished",
2622 G_CALLBACK (gtk_entry_handle_drag_finished), entry);
2626 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2627 GtkStyleContext *context,
2628 GtkEntryIconPosition icon_pos)
2630 GtkEntryPrivate *priv = entry->priv;
2631 EntryIconInfo *icon_info = priv->icons[icon_pos];
2633 GtkStateFlags state;
2635 widget = GTK_WIDGET (entry);
2636 state = gtk_widget_get_state_flags (widget);
2638 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2640 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2641 state |= GTK_STATE_FLAG_INSENSITIVE;
2642 else if (icon_info->prelight)
2643 state |= GTK_STATE_FLAG_PRELIGHT;
2645 gtk_style_context_save (context);
2647 gtk_style_context_set_state (context, state);
2648 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2650 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2652 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2653 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2655 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2659 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2660 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2662 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2667 get_icon_width (GtkEntry *entry,
2668 GtkEntryIconPosition icon_pos)
2670 GtkEntryPrivate *priv = entry->priv;
2671 EntryIconInfo *icon_info = priv->icons[icon_pos];
2672 GtkStyleContext *context;
2679 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2680 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2681 gtk_style_context_get_padding (context, 0, &padding);
2683 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2685 gtk_style_context_restore (context);
2688 width += padding.left + padding.right;
2694 get_icon_allocations (GtkEntry *entry,
2695 GtkAllocation *primary,
2696 GtkAllocation *secondary)
2699 GtkEntryPrivate *priv = entry->priv;
2700 gint x, y, width, height;
2702 get_text_area_size (entry, &x, &y, &width, &height);
2704 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2705 y += priv->focus_width;
2708 primary->height = height;
2709 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2712 secondary->height = height;
2713 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2715 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2717 primary->x = x + width - primary->width;
2723 secondary->x = x + width - secondary->width;
2729 begin_change (GtkEntry *entry)
2731 GtkEntryPrivate *priv = entry->priv;
2733 priv->change_count++;
2735 g_object_freeze_notify (G_OBJECT (entry));
2739 end_change (GtkEntry *entry)
2741 GtkEditable *editable = GTK_EDITABLE (entry);
2742 GtkEntryPrivate *priv = entry->priv;
2744 g_return_if_fail (priv->change_count > 0);
2746 g_object_thaw_notify (G_OBJECT (entry));
2748 priv->change_count--;
2750 if (priv->change_count == 0)
2752 if (priv->real_changed)
2754 g_signal_emit_by_name (editable, "changed");
2755 priv->real_changed = FALSE;
2761 emit_changed (GtkEntry *entry)
2763 GtkEditable *editable = GTK_EDITABLE (entry);
2764 GtkEntryPrivate *priv = entry->priv;
2766 if (priv->change_count == 0)
2767 g_signal_emit_by_name (editable, "changed");
2769 priv->real_changed = TRUE;
2773 gtk_entry_destroy (GtkWidget *widget)
2775 GtkEntry *entry = GTK_ENTRY (widget);
2776 GtkEntryPrivate *priv = entry->priv;
2778 priv->current_pos = priv->selection_bound = 0;
2779 gtk_entry_reset_im_context (entry);
2780 gtk_entry_reset_layout (entry);
2782 if (priv->blink_timeout)
2784 g_source_remove (priv->blink_timeout);
2785 priv->blink_timeout = 0;
2788 if (priv->recompute_idle)
2790 g_source_remove (priv->recompute_idle);
2791 priv->recompute_idle = 0;
2794 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2798 gtk_entry_dispose (GObject *object)
2800 GtkEntry *entry = GTK_ENTRY (object);
2801 GtkEntryPrivate *priv = entry->priv;
2804 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2805 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2806 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2807 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2808 gtk_entry_set_completion (entry, NULL);
2812 buffer_disconnect_signals (entry);
2813 g_object_unref (priv->buffer);
2814 priv->buffer = NULL;
2817 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2818 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2819 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2820 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2824 gtk_entry_finalize (GObject *object)
2826 GtkEntry *entry = GTK_ENTRY (object);
2827 GtkEntryPrivate *priv = entry->priv;
2828 EntryIconInfo *icon_info = NULL;
2831 for (i = 0; i < MAX_ICONS; i++)
2833 if ((icon_info = priv->icons[i]) != NULL)
2835 if (icon_info->target_list != NULL)
2837 gtk_target_list_unref (icon_info->target_list);
2838 icon_info->target_list = NULL;
2841 g_clear_object (&icon_info->icon_helper);
2843 g_slice_free (EntryIconInfo, icon_info);
2844 priv->icons[i] = NULL;
2848 if (priv->cached_layout)
2849 g_object_unref (priv->cached_layout);
2851 g_object_unref (priv->im_context);
2853 if (priv->blink_timeout)
2854 g_source_remove (priv->blink_timeout);
2856 if (priv->recompute_idle)
2857 g_source_remove (priv->recompute_idle);
2859 if (priv->selection_bubble)
2860 gtk_widget_destroy (priv->selection_bubble);
2862 g_object_unref (priv->text_handle);
2863 g_free (priv->placeholder_text);
2864 g_free (priv->im_module);
2866 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2870 gtk_entry_get_display_mode (GtkEntry *entry)
2872 GtkEntryPrivate *priv = entry->priv;
2875 return DISPLAY_NORMAL;
2877 if (priv->invisible_char == 0 && priv->invisible_char_set)
2878 return DISPLAY_BLANK;
2880 return DISPLAY_INVISIBLE;
2884 _gtk_entry_get_display_text (GtkEntry *entry,
2888 GtkEntryPasswordHint *password_hint;
2889 GtkEntryPrivate *priv;
2890 gunichar invisible_char;
2901 text = gtk_entry_buffer_get_text (get_buffer (entry));
2902 length = gtk_entry_buffer_get_length (get_buffer (entry));
2906 if (start_pos > length)
2909 if (end_pos <= start_pos)
2910 return g_strdup ("");
2911 else if (priv->visible)
2913 start = g_utf8_offset_to_pointer (text, start_pos);
2914 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2915 return g_strndup (start, end - start);
2919 str = g_string_sized_new (length * 2);
2921 /* Figure out what our invisible char is and encode it */
2922 if (!priv->invisible_char)
2923 invisible_char = priv->invisible_char_set ? ' ' : '*';
2925 invisible_char = priv->invisible_char;
2926 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2929 * Add hidden characters for each character in the text
2930 * buffer. If there is a password hint, then keep that
2931 * character visible.
2934 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2935 for (i = start_pos; i < end_pos; ++i)
2937 if (password_hint && i == password_hint->position)
2939 start = g_utf8_offset_to_pointer (text, i);
2940 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2944 g_string_append_len (str, char_str, char_len);
2948 return g_string_free (str, FALSE);
2953 update_cursors (GtkWidget *widget)
2955 GtkEntry *entry = GTK_ENTRY (widget);
2956 GtkEntryPrivate *priv = entry->priv;
2957 EntryIconInfo *icon_info = NULL;
2958 GdkDisplay *display;
2962 for (i = 0; i < MAX_ICONS; i++)
2964 if ((icon_info = priv->icons[i]) != NULL)
2966 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2967 icon_info->window != NULL)
2968 gdk_window_show_unraised (icon_info->window);
2970 /* The icon windows are not children of the visible entry window,
2971 * thus we can't just inherit the xterm cursor. Slight complication
2972 * here is that for the entry, insensitive => arrow cursor, but for
2973 * an icon in a sensitive entry, insensitive => xterm cursor.
2975 if (gtk_widget_is_sensitive (widget) &&
2976 (icon_info->insensitive ||
2977 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2979 display = gtk_widget_get_display (widget);
2980 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2981 gdk_window_set_cursor (icon_info->window, cursor);
2982 g_object_unref (cursor);
2986 gdk_window_set_cursor (icon_info->window, NULL);
2993 realize_icon_info (GtkWidget *widget,
2994 GtkEntryIconPosition icon_pos)
2996 GtkEntry *entry = GTK_ENTRY (widget);
2997 GtkEntryPrivate *priv = entry->priv;
2998 EntryIconInfo *icon_info = priv->icons[icon_pos];
2999 GdkWindowAttr attributes;
3000 gint attributes_mask;
3002 g_return_if_fail (icon_info != NULL);
3006 attributes.width = 1;
3007 attributes.height = 1;
3008 attributes.window_type = GDK_WINDOW_CHILD;
3009 attributes.wclass = GDK_INPUT_ONLY;
3010 attributes.event_mask = gtk_widget_get_events (widget);
3011 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3012 GDK_BUTTON_RELEASE_MASK |
3013 GDK_BUTTON1_MOTION_MASK |
3014 GDK_BUTTON3_MOTION_MASK |
3015 GDK_POINTER_MOTION_HINT_MASK |
3016 GDK_POINTER_MOTION_MASK |
3017 GDK_ENTER_NOTIFY_MASK |
3018 GDK_LEAVE_NOTIFY_MASK);
3019 attributes_mask = GDK_WA_X | GDK_WA_Y;
3021 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
3024 gtk_widget_register_window (widget, icon_info->window);
3026 gtk_widget_queue_resize (widget);
3029 static EntryIconInfo*
3030 construct_icon_info (GtkWidget *widget,
3031 GtkEntryIconPosition icon_pos)
3033 GtkEntry *entry = GTK_ENTRY (widget);
3034 GtkEntryPrivate *priv = entry->priv;
3035 EntryIconInfo *icon_info;
3037 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
3039 icon_info = g_slice_new0 (EntryIconInfo);
3040 priv->icons[icon_pos] = icon_info;
3042 icon_info->icon_helper = _gtk_icon_helper_new ();
3043 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
3045 if (gtk_widget_get_realized (widget))
3046 realize_icon_info (widget, icon_pos);
3052 gtk_entry_map (GtkWidget *widget)
3054 GtkEntry *entry = GTK_ENTRY (widget);
3055 GtkEntryPrivate *priv = entry->priv;
3056 EntryIconInfo *icon_info = NULL;
3059 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
3061 gdk_window_show (priv->text_area);
3063 for (i = 0; i < MAX_ICONS; i++)
3065 if ((icon_info = priv->icons[i]) != NULL)
3067 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3068 icon_info->window != NULL)
3069 gdk_window_show (icon_info->window);
3073 update_cursors (widget);
3077 gtk_entry_unmap (GtkWidget *widget)
3079 GtkEntry *entry = GTK_ENTRY (widget);
3080 GtkEntryPrivate *priv = entry->priv;
3081 EntryIconInfo *icon_info = NULL;
3084 _gtk_text_handle_set_mode (priv->text_handle,
3085 GTK_TEXT_HANDLE_MODE_NONE);
3087 for (i = 0; i < MAX_ICONS; i++)
3089 if ((icon_info = priv->icons[i]) != NULL)
3091 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3092 icon_info->window != NULL)
3093 gdk_window_hide (icon_info->window);
3097 gdk_window_hide (priv->text_area);
3099 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
3103 gtk_entry_realize (GtkWidget *widget)
3106 GtkEntryPrivate *priv;
3107 EntryIconInfo *icon_info;
3109 GdkWindowAttr attributes;
3110 gint attributes_mask;
3111 gint frame_x, frame_y;
3114 gtk_widget_set_realized (widget, TRUE);
3115 window = gtk_widget_get_parent_window (widget);
3116 gtk_widget_set_window (widget, window);
3117 g_object_ref (window);
3119 entry = GTK_ENTRY (widget);
3122 attributes.window_type = GDK_WINDOW_CHILD;
3123 attributes.wclass = GDK_INPUT_ONLY;
3124 attributes.event_mask = gtk_widget_get_events (widget);
3125 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3126 GDK_BUTTON_RELEASE_MASK |
3127 GDK_BUTTON1_MOTION_MASK |
3128 GDK_BUTTON3_MOTION_MASK |
3129 GDK_POINTER_MOTION_HINT_MASK |
3130 GDK_POINTER_MOTION_MASK |
3131 GDK_ENTER_NOTIFY_MASK |
3132 GDK_LEAVE_NOTIFY_MASK);
3133 attributes_mask = GDK_WA_X | GDK_WA_Y;
3135 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3137 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3138 attributes.x += frame_x;
3139 attributes.y += frame_y;
3141 if (gtk_widget_is_sensitive (widget))
3143 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3144 attributes_mask |= GDK_WA_CURSOR;
3147 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3151 gtk_widget_register_window (widget, priv->text_area);
3153 if (attributes_mask & GDK_WA_CURSOR)
3154 g_object_unref (attributes.cursor);
3156 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3158 gtk_entry_adjust_scroll (entry);
3159 gtk_entry_update_primary_selection (entry);
3160 _gtk_text_handle_set_relative_to (priv->text_handle, priv->text_area);
3162 /* If the icon positions are already setup, create their windows.
3163 * Otherwise if they don't exist yet, then construct_icon_info()
3164 * will create the windows once the widget is already realized.
3166 for (i = 0; i < MAX_ICONS; i++)
3168 if ((icon_info = priv->icons[i]) != NULL)
3170 if (icon_info->window == NULL)
3171 realize_icon_info (widget, i);
3177 gtk_entry_unrealize (GtkWidget *widget)
3179 GtkEntry *entry = GTK_ENTRY (widget);
3180 GtkEntryPrivate *priv = entry->priv;
3181 GtkClipboard *clipboard;
3182 EntryIconInfo *icon_info;
3185 gtk_entry_reset_layout (entry);
3187 gtk_im_context_set_client_window (priv->im_context, NULL);
3188 _gtk_text_handle_set_relative_to (priv->text_handle, NULL);
3190 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3191 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3192 gtk_clipboard_clear (clipboard);
3194 if (priv->text_area)
3196 gtk_widget_unregister_window (widget, priv->text_area);
3197 gdk_window_destroy (priv->text_area);
3198 priv->text_area = NULL;
3201 if (priv->popup_menu)
3203 gtk_widget_destroy (priv->popup_menu);
3204 priv->popup_menu = NULL;
3207 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3209 for (i = 0; i < MAX_ICONS; i++)
3211 if ((icon_info = priv->icons[i]) != NULL)
3213 if (icon_info->window != NULL)
3215 gtk_widget_unregister_window (widget, icon_info->window);
3216 gdk_window_destroy (icon_info->window);
3217 icon_info->window = NULL;
3224 _gtk_entry_get_borders (GtkEntry *entry,
3225 GtkBorder *border_out)
3227 GtkEntryPrivate *priv = entry->priv;
3228 GtkWidget *widget = GTK_WIDGET (entry);
3229 GtkBorder tmp = { 0, 0, 0, 0 };
3230 GtkStyleContext *context;
3232 context = gtk_widget_get_style_context (widget);
3233 gtk_style_context_get_padding (context, 0, &tmp);
3235 if (priv->has_frame)
3239 gtk_style_context_get_border (context, 0, &border);
3240 tmp.top += border.top;
3241 tmp.right += border.right;
3242 tmp.bottom += border.bottom;
3243 tmp.left += border.left;
3246 if (!priv->interior_focus)
3248 tmp.top += priv->focus_width;
3249 tmp.right += priv->focus_width;
3250 tmp.bottom += priv->focus_width;
3251 tmp.left += priv->focus_width;
3254 if (border_out != NULL)
3259 gtk_entry_get_preferred_width (GtkWidget *widget,
3263 GtkEntry *entry = GTK_ENTRY (widget);
3264 GtkEntryPrivate *priv = entry->priv;
3265 PangoFontMetrics *metrics;
3267 PangoContext *context;
3268 gint icon_widths = 0;
3272 context = gtk_widget_get_pango_context (widget);
3274 metrics = pango_context_get_metrics (context,
3275 pango_context_get_font_description (context),
3276 pango_context_get_language (context));
3278 _gtk_entry_get_borders (entry, &borders);
3280 if (priv->width_chars < 0)
3281 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3284 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3285 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3286 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3288 width = char_pixels * priv->width_chars + borders.left + borders.right;
3291 for (i = 0; i < MAX_ICONS; i++)
3293 icon_width = get_icon_width (entry, i);
3295 icon_widths += icon_width;
3298 if (icon_widths > width)
3299 width += icon_widths;
3301 pango_font_metrics_unref (metrics);
3308 gtk_entry_get_preferred_height (GtkWidget *widget,
3312 GtkEntry *entry = GTK_ENTRY (widget);
3313 GtkEntryPrivate *priv = entry->priv;
3314 PangoFontMetrics *metrics;
3316 PangoContext *context;
3318 PangoLayout *layout;
3320 layout = gtk_entry_ensure_layout (entry, TRUE);
3321 context = gtk_widget_get_pango_context (widget);
3323 metrics = pango_context_get_metrics (context,
3324 pango_context_get_font_description (context),
3325 pango_context_get_language (context));
3327 priv->ascent = pango_font_metrics_get_ascent (metrics);
3328 priv->descent = pango_font_metrics_get_descent (metrics);
3329 pango_font_metrics_unref (metrics);
3331 _gtk_entry_get_borders (entry, &borders);
3332 pango_layout_get_pixel_size (layout, NULL, &height);
3334 height += borders.top + borders.bottom;
3341 place_windows (GtkEntry *entry)
3343 GtkWidget *widget = GTK_WIDGET (entry);
3344 GtkEntryPrivate *priv = entry->priv;
3345 gint x, y, width, height;
3346 gint frame_x, frame_y;
3347 GtkAllocation primary;
3348 GtkAllocation secondary;
3349 EntryIconInfo *icon_info = NULL;
3351 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3352 get_text_area_size (entry, &x, &y, &width, &height);
3353 get_icon_allocations (entry, &primary, &secondary);
3355 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3356 y += priv->focus_width;
3358 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3359 x += secondary.width;
3362 width -= primary.width + secondary.width;
3366 primary.x += frame_x;
3367 primary.y += frame_y;
3368 secondary.x += frame_x;
3369 secondary.y += frame_y;
3371 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3372 gdk_window_move_resize (icon_info->window,
3373 primary.x, primary.y,
3374 primary.width, primary.height);
3376 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3377 gdk_window_move_resize (icon_info->window,
3378 secondary.x, secondary.y,
3379 secondary.width, secondary.height);
3381 gdk_window_move_resize (priv->text_area, x, y, width, height);
3385 gtk_entry_get_text_area_size (GtkEntry *entry,
3391 GtkEntryPrivate *priv = entry->priv;
3392 GtkWidget *widget = GTK_WIDGET (entry);
3393 GtkAllocation allocation;
3394 GtkRequisition requisition;
3399 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3400 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3402 gtk_widget_get_allocation (widget, &allocation);
3403 _gtk_entry_get_borders (entry, &borders);
3405 if (gtk_widget_get_realized (widget))
3406 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3408 frame_height = req_height;
3410 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3411 frame_height -= 2 * priv->focus_width;
3417 *y = floor ((frame_height - req_height) / 2) + borders.top;
3420 *width = allocation.width - borders.left - borders.right;
3423 *height = req_height - borders.top - borders.bottom;
3427 get_text_area_size (GtkEntry *entry,
3433 GtkEntryClass *class;
3435 g_return_if_fail (GTK_IS_ENTRY (entry));
3437 class = GTK_ENTRY_GET_CLASS (entry);
3439 if (class->get_text_area_size)
3440 class->get_text_area_size (entry, x, y, width, height);
3445 gtk_entry_get_frame_size (GtkEntry *entry,
3451 GtkEntryPrivate *priv = entry->priv;
3452 GtkAllocation allocation;
3453 GtkRequisition requisition;
3454 GtkWidget *widget = GTK_WIDGET (entry);
3457 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3459 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3461 gtk_widget_get_allocation (widget, &allocation);
3468 if (priv->is_cell_renderer)
3471 *y = (allocation.height - req_height) / 2;
3477 *width = allocation.width;
3481 if (priv->is_cell_renderer)
3482 *height = allocation.height;
3484 *height = req_height;
3489 get_frame_size (GtkEntry *entry,
3490 gboolean relative_to_window,
3496 GtkEntryClass *class;
3497 GtkWidget *widget = GTK_WIDGET (entry);
3499 g_return_if_fail (GTK_IS_ENTRY (entry));
3501 class = GTK_ENTRY_GET_CLASS (entry);
3503 if (class->get_frame_size)
3504 class->get_frame_size (entry, x, y, width, height);
3506 if (!relative_to_window)
3508 GtkAllocation allocation;
3509 gtk_widget_get_allocation (widget, &allocation);
3519 gtk_entry_size_allocate (GtkWidget *widget,
3520 GtkAllocation *allocation)
3522 GtkEntry *entry = GTK_ENTRY (widget);
3524 gtk_widget_set_allocation (widget, allocation);
3526 if (gtk_widget_get_realized (widget))
3528 GtkEntryCompletion* completion;
3530 place_windows (entry);
3531 gtk_entry_recompute (entry);
3533 completion = gtk_entry_get_completion (entry);
3535 _gtk_entry_completion_resize_popup (completion);
3540 should_prelight (GtkEntry *entry,
3541 GtkEntryIconPosition icon_pos)
3543 GtkEntryPrivate *priv = entry->priv;
3544 EntryIconInfo *icon_info = priv->icons[icon_pos];
3550 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3553 if (icon_info->pressed)
3556 gtk_widget_style_get (GTK_WIDGET (entry),
3557 "icon-prelight", &prelight,
3564 draw_icon (GtkWidget *widget,
3566 GtkEntryIconPosition icon_pos)
3568 GtkEntry *entry = GTK_ENTRY (widget);
3569 GtkEntryPrivate *priv = entry->priv;
3570 EntryIconInfo *icon_info = priv->icons[icon_pos];
3571 gint x, y, width, height, pix_width, pix_height;
3572 GtkStyleContext *context;
3578 width = gdk_window_get_width (icon_info->window);
3579 height = gdk_window_get_height (icon_info->window);
3581 /* size_allocate hasn't been called yet. These are the default values.
3583 if (width == 1 || height == 1)
3587 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3589 context = gtk_widget_get_style_context (widget);
3590 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3591 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3592 &pix_width, &pix_height);
3593 gtk_style_context_get_padding (context, 0, &padding);
3595 x = MAX (0, padding.left);
3596 y = MAX (0, (height - pix_height) / 2);
3598 _gtk_icon_helper_draw (icon_info->icon_helper,
3602 gtk_style_context_restore (context);
3608 gtk_entry_draw_frame (GtkWidget *widget,
3609 GtkStyleContext *context,
3612 GtkEntry *entry = GTK_ENTRY (widget);
3613 GtkEntryPrivate *priv = entry->priv;
3614 gint x = 0, y = 0, width, height;
3615 gint frame_x, frame_y;
3619 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3621 cairo_translate (cr, frame_x, frame_y);
3623 /* Fix a problem with some themes which assume that entry->text_area's
3624 * width equals widget->window's width
3625 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3626 if (GTK_IS_SPIN_BUTTON (widget))
3630 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3631 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3634 width += borders.left + borders.right;
3637 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3639 x += priv->focus_width;
3640 y += priv->focus_width;
3641 width -= 2 * priv->focus_width;
3642 height -= 2 * priv->focus_width;
3645 gtk_render_background (context, cr,
3646 x, y, width, height);
3648 if (priv->has_frame)
3649 gtk_render_frame (context, cr,
3650 x, y, width, height);
3652 gtk_entry_draw_progress (widget, context, cr);
3654 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3656 x -= priv->focus_width;
3657 y -= priv->focus_width;
3658 width += 2 * priv->focus_width;
3659 height += 2 * priv->focus_width;
3661 gtk_render_focus (context, cr,
3662 0, 0, width, height);
3669 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3670 GtkStyleContext *context)
3672 GtkEntryPrivate *private = entry->priv;
3674 gtk_style_context_save (context);
3675 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3676 if (private->progress_pulse_mode)
3677 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3681 get_progress_area (GtkWidget *widget,
3687 GtkEntry *entry = GTK_ENTRY (widget);
3688 GtkEntryPrivate *private = entry->priv;
3689 GtkStyleContext *context;
3690 GtkBorder margin, border, entry_borders;
3691 gint frame_width, text_area_width, text_area_height;
3693 context = gtk_widget_get_style_context (widget);
3694 _gtk_entry_get_borders (entry, &entry_borders);
3695 get_text_area_size (entry,
3697 &text_area_width, &text_area_height);
3698 get_frame_size (entry, FALSE,
3700 &frame_width, NULL);
3704 *width = text_area_width + entry_borders.left + entry_borders.right;
3705 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3707 /* if the text area got resized by a subclass, subtract the left/right
3708 * border width, so that the progress bar won't extend over the resized
3711 if (frame_width > *width)
3713 gtk_style_context_get_border (context, 0, &border);
3714 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3716 *x = (frame_width - *width) + border.left;
3717 *width -= border.left;
3721 *width -= border.right;
3725 gtk_entry_prepare_context_for_progress (entry, context);
3726 gtk_style_context_get_margin (context, 0, &margin);
3728 gtk_style_context_restore (context);
3732 *width -= margin.left + margin.right;
3733 *height -= margin.top + margin.bottom;
3735 if (private->progress_pulse_mode)
3737 gdouble value = private->progress_pulse_current;
3739 *x += (gint) floor(value * (*width));
3740 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3742 else if (private->progress_fraction > 0)
3744 gdouble value = private->progress_fraction;
3746 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3750 bar_width = floor(value * (*width) + 0.5);
3751 *x += *width - bar_width;
3756 *width = (gint) floor(value * (*width) + 0.5);
3767 gtk_entry_draw_progress (GtkWidget *widget,
3768 GtkStyleContext *context,
3771 GtkEntry *entry = GTK_ENTRY (widget);
3772 gint x, y, width, height;
3774 get_progress_area (widget, &x, &y, &width, &height);
3776 if ((width <= 0) || (height <= 0))
3779 gtk_entry_prepare_context_for_progress (entry, context);
3780 gtk_render_activity (context, cr,
3781 x, y, width, height);
3783 gtk_style_context_restore (context);
3787 gtk_entry_draw (GtkWidget *widget,
3790 GtkEntry *entry = GTK_ENTRY (widget);
3791 GtkStyleContext *context;
3792 GtkEntryPrivate *priv = entry->priv;
3795 if (gtk_cairo_should_draw_window (cr,
3796 gtk_widget_get_window (widget)))
3798 context = gtk_widget_get_style_context (widget);
3800 /* Draw entry_bg, shadow, progress and focus */
3801 gtk_entry_draw_frame (widget, context, cr);
3803 /* Draw text and cursor */
3806 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3808 if (priv->dnd_position != -1)
3809 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3811 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3813 /* When no text is being displayed at all, don't show the cursor */
3814 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3815 gtk_widget_has_focus (widget) &&
3816 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3817 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3822 for (i = 0; i < MAX_ICONS; i++)
3824 EntryIconInfo *icon_info = priv->icons[i];
3826 if (icon_info != NULL)
3827 draw_icon (widget, cr, i);
3835 gtk_entry_enter_notify (GtkWidget *widget,
3836 GdkEventCrossing *event)
3838 GtkEntry *entry = GTK_ENTRY (widget);
3839 GtkEntryPrivate *priv = entry->priv;
3842 for (i = 0; i < MAX_ICONS; i++)
3844 EntryIconInfo *icon_info = priv->icons[i];
3846 if (icon_info != NULL && event->window == icon_info->window)
3848 if (should_prelight (entry, i))
3850 icon_info->prelight = TRUE;
3851 gtk_widget_queue_draw (widget);
3862 gtk_entry_leave_notify (GtkWidget *widget,
3863 GdkEventCrossing *event)
3865 GtkEntry *entry = GTK_ENTRY (widget);
3866 GtkEntryPrivate *priv = entry->priv;
3869 for (i = 0; i < MAX_ICONS; i++)
3871 EntryIconInfo *icon_info = priv->icons[i];
3873 if (icon_info != NULL && event->window == icon_info->window)
3875 /* a grab means that we may never see the button release */
3876 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3877 icon_info->pressed = FALSE;
3879 if (should_prelight (entry, i))
3881 icon_info->prelight = FALSE;
3882 gtk_widget_queue_draw (widget);
3893 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3897 gint start_char, end_char;
3899 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3901 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3902 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3903 const char *text = pango_layout_get_text (layout);
3904 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3905 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3906 gint real_n_ranges, i;
3908 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3914 for (i = 0; i < real_n_ranges; ++i)
3916 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3917 r[2 * i] = r[2 * i] / PANGO_SCALE;
3922 *n_ranges = real_n_ranges;
3934 in_selection (GtkEntry *entry,
3939 gint retval = FALSE;
3941 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3943 for (i = 0; i < n_ranges; ++i)
3945 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3957 gtk_entry_move_handle (GtkEntry *entry,
3958 GtkTextHandlePosition pos,
3963 GtkEntryPrivate *priv = entry->priv;
3965 if (!_gtk_text_handle_get_is_dragged (priv->text_handle, pos) &&
3966 (x < 0 || x > gdk_window_get_width (priv->text_area)))
3968 /* Hide the handle if it's not being manipulated
3969 * and fell outside of the visible text area.
3971 _gtk_text_handle_set_visible (priv->text_handle, pos, FALSE);
3977 rect.x = CLAMP (x, 0, gdk_window_get_width (priv->text_area));
3980 rect.height = height;
3982 _gtk_text_handle_set_visible (priv->text_handle, pos, TRUE);
3983 _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
3988 gtk_entry_get_selection_bound_location (GtkEntry *entry)
3990 GtkEntryPrivate *priv = entry->priv;
3991 PangoLayout *layout;
3997 layout = gtk_entry_ensure_layout (entry, FALSE);
3998 text = pango_layout_get_text (layout);
3999 index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text;
4000 pango_layout_index_to_pos (layout, index, &pos);
4002 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
4003 x = (pos.x + pos.width) / PANGO_SCALE;
4005 x = pos.x / PANGO_SCALE;
4011 gtk_entry_update_handles (GtkEntry *entry,
4012 GtkTextHandleMode mode)
4014 GtkEntryPrivate *priv = entry->priv;
4015 gint strong_x, height;
4018 _gtk_text_handle_set_mode (priv->text_handle, mode);
4020 /* Wait for recomputation before repositioning */
4021 if (priv->recompute_idle != 0)
4024 height = gdk_window_get_height (priv->text_area);
4026 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
4027 cursor = strong_x - priv->scroll_offset;
4029 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
4033 bound = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
4035 if (priv->selection_bound > priv->current_pos)
4046 /* Update start selection bound */
4047 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_START,
4049 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_END,
4053 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_CURSOR,
4058 gtk_entry_button_press (GtkWidget *widget,
4059 GdkEventButton *event)
4061 GtkEntry *entry = GTK_ENTRY (widget);
4062 GtkEditable *editable = GTK_EDITABLE (widget);
4063 GtkEntryPrivate *priv = entry->priv;
4064 EntryIconInfo *icon_info = NULL;
4066 gint sel_start, sel_end;
4069 gtk_entry_selection_bubble_popup_unset (entry);
4071 for (i = 0; i < MAX_ICONS; i++)
4073 icon_info = priv->icons[i];
4075 if (!icon_info || icon_info->insensitive)
4078 if (event->window == icon_info->window)
4080 if (should_prelight (entry, i))
4082 icon_info->prelight = FALSE;
4083 gtk_widget_queue_draw (widget);
4086 priv->start_x = event->x;
4087 priv->start_y = event->y;
4088 icon_info->pressed = TRUE;
4090 if (!icon_info->nonactivatable)
4091 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
4097 if (event->window != priv->text_area ||
4098 (priv->button && event->button != priv->button))
4101 gtk_entry_reset_blink_time (entry);
4103 priv->button = event->button;
4104 priv->device = gdk_event_get_device ((GdkEvent *) event);
4106 if (!gtk_widget_has_focus (widget))
4108 priv->in_click = TRUE;
4109 gtk_widget_grab_focus (widget);
4110 priv->in_click = FALSE;
4113 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4115 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
4117 gtk_entry_do_popup (entry, event);
4118 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
4119 priv->device = NULL;
4123 else if (event->button == GDK_BUTTON_PRIMARY)
4125 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
4126 gboolean is_touchscreen;
4129 source = gdk_event_get_source_device ((GdkEvent *) event);
4130 is_touchscreen = test_touchscreen ||
4131 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN;
4133 priv->select_words = FALSE;
4134 priv->select_lines = FALSE;
4137 gtk_widget_get_modifier_mask (widget,
4138 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
4140 gtk_entry_reset_im_context (entry);
4142 if (!have_selection) /* select from the current position to the clicked position */
4143 sel_start = sel_end = priv->current_pos;
4145 if (tmp_pos > sel_start && tmp_pos < sel_end)
4147 /* Truncate current selection, but keep it as big as possible */
4148 if (tmp_pos - sel_start > sel_end - tmp_pos)
4149 gtk_entry_set_positions (entry, sel_start, tmp_pos);
4151 gtk_entry_set_positions (entry, tmp_pos, sel_end);
4155 gboolean extend_to_left;
4158 /* Figure out what click selects and extend current selection */
4159 switch (event->type)
4161 case GDK_BUTTON_PRESS:
4162 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
4165 case GDK_2BUTTON_PRESS:
4166 priv->select_words = TRUE;
4167 gtk_entry_select_word (entry);
4170 case GDK_3BUTTON_PRESS:
4171 priv->select_lines = TRUE;
4172 gtk_entry_select_line (entry);
4179 start = MIN (priv->current_pos, priv->selection_bound);
4180 start = MIN (sel_start, start);
4182 end = MAX (priv->current_pos, priv->selection_bound);
4183 end = MAX (sel_end, end);
4185 if (tmp_pos == sel_start || tmp_pos == sel_end)
4186 extend_to_left = (tmp_pos == start);
4188 extend_to_left = (end == sel_end);
4191 gtk_entry_set_positions (entry, start, end);
4193 gtk_entry_set_positions (entry, end, start);
4196 else /* no shift key */
4197 switch (event->type)
4199 case GDK_BUTTON_PRESS:
4200 if (in_selection (entry, event->x + priv->scroll_offset))
4202 /* Click inside the selection - we'll either start a drag, or
4203 * clear the selection
4205 priv->in_drag = TRUE;
4206 priv->drag_start_x = event->x + priv->scroll_offset;
4207 priv->drag_start_y = event->y;
4211 gtk_editable_set_position (editable, tmp_pos);
4214 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4218 case GDK_2BUTTON_PRESS:
4219 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4220 * receiving a GDK_2BUTTON_PRESS so we need to reset
4221 * priv->in_drag which may have been set above
4223 priv->in_drag = FALSE;
4224 priv->select_words = TRUE;
4225 gtk_entry_select_word (entry);
4228 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4231 case GDK_3BUTTON_PRESS:
4232 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4233 * receiving a GDK_3BUTTON_PRESS so we need to reset
4234 * priv->in_drag which may have been set above
4236 priv->in_drag = FALSE;
4237 priv->select_lines = TRUE;
4238 gtk_entry_select_line (entry);
4240 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4249 else if (event->type == GDK_BUTTON_PRESS &&
4250 event->button == GDK_BUTTON_MIDDLE &&
4251 get_middle_click_paste (entry))
4255 priv->insert_pos = tmp_pos;
4256 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
4261 gtk_widget_error_bell (widget);
4269 gtk_entry_button_release (GtkWidget *widget,
4270 GdkEventButton *event)
4272 GtkEntry *entry = GTK_ENTRY (widget);
4273 GtkEntryPrivate *priv = entry->priv;
4274 EntryIconInfo *icon_info = NULL;
4275 gboolean is_touchscreen;
4279 for (i = 0; i < MAX_ICONS; i++)
4281 icon_info = priv->icons[i];
4283 if (!icon_info || icon_info->insensitive)
4286 if (event->window == icon_info->window)
4288 icon_info->pressed = FALSE;
4290 if (should_prelight (entry, i) &&
4291 event->x >= 0 && event->y >= 0 &&
4292 event->x < gdk_window_get_width (icon_info->window) &&
4293 event->y < gdk_window_get_height (icon_info->window))
4295 icon_info->prelight = TRUE;
4296 gtk_widget_queue_draw (widget);
4299 if (!icon_info->nonactivatable)
4300 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4306 if (event->window != priv->text_area || priv->button != event->button)
4309 source = gdk_event_get_source_device ((GdkEvent *) event);
4310 is_touchscreen = (test_touchscreen ||
4311 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN);
4315 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4317 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4320 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4324 else if (is_touchscreen)
4325 gtk_entry_selection_bubble_popup_set (entry);
4328 priv->device = NULL;
4330 gtk_entry_update_primary_selection (entry);
4336 _gtk_entry_get_selected_text (GtkEntry *entry)
4338 GtkEditable *editable = GTK_EDITABLE (entry);
4339 gint start_text, end_text;
4342 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4343 text = gtk_editable_get_chars (editable, start_text, end_text);
4349 gtk_entry_motion_notify (GtkWidget *widget,
4350 GdkEventMotion *event)
4352 GtkEntry *entry = GTK_ENTRY (widget);
4353 GtkEntryPrivate *priv = entry->priv;
4354 EntryIconInfo *icon_info = NULL;
4358 for (i = 0; i < MAX_ICONS; i++)
4360 icon_info = priv->icons[i];
4362 if (!icon_info || icon_info->insensitive)
4365 if (event->window == icon_info->window)
4367 if (icon_info->pressed &&
4368 icon_info->target_list != NULL &&
4369 gtk_drag_check_threshold (widget,
4375 icon_info->in_drag = TRUE;
4376 icon_info->pressed = FALSE;
4377 gtk_drag_begin (widget,
4378 icon_info->target_list,
4388 if (priv->mouse_cursor_obscured)
4392 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4393 gdk_window_set_cursor (priv->text_area, cursor);
4394 g_object_unref (cursor);
4395 priv->mouse_cursor_obscured = FALSE;
4398 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4401 if (priv->select_lines)
4404 gdk_event_request_motions (event);
4408 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4409 gtk_drag_check_threshold (widget,
4410 priv->drag_start_x, priv->drag_start_y,
4411 event->x + priv->scroll_offset, event->y))
4413 GdkDragContext *context;
4414 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4415 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4417 cairo_surface_t *surface;
4419 gtk_target_list_add_text_targets (target_list, 0);
4421 text = _gtk_entry_get_selected_text (entry);
4422 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4424 context = gtk_drag_begin (widget, target_list, actions,
4425 priv->button, (GdkEvent *)event);
4428 gtk_drag_set_icon_surface (context, surface);
4430 gtk_drag_set_icon_default (context);
4433 cairo_surface_destroy (surface);
4436 priv->in_drag = FALSE;
4438 priv->device = NULL;
4440 gtk_target_list_unref (target_list);
4445 GdkInputSource input_source;
4449 length = gtk_entry_buffer_get_length (get_buffer (entry));
4453 else if (event->y >= gdk_window_get_height (priv->text_area))
4456 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4458 source = gdk_event_get_source_device ((GdkEvent *) event);
4459 input_source = gdk_device_get_source (source);
4461 if (priv->select_words)
4464 gint old_min, old_max;
4467 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4468 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4470 pos = priv->current_pos;
4471 bound = priv->selection_bound;
4473 old_min = MIN(priv->current_pos, priv->selection_bound);
4474 old_max = MAX(priv->current_pos, priv->selection_bound);
4481 else if (old_max < max)
4486 else if (pos == old_min)
4488 if (priv->current_pos != min)
4493 if (priv->current_pos != max)
4497 gtk_entry_set_positions (entry, pos, bound);
4500 gtk_entry_set_positions (entry, tmp_pos, -1);
4502 /* Update touch handles' position */
4503 if (test_touchscreen || input_source == GDK_SOURCE_TOUCHSCREEN)
4504 gtk_entry_update_handles (entry,
4505 (priv->current_pos == priv->selection_bound) ?
4506 GTK_TEXT_HANDLE_MODE_CURSOR :
4507 GTK_TEXT_HANDLE_MODE_SELECTION);
4514 set_invisible_cursor (GdkWindow *window)
4516 GdkDisplay *display;
4519 display = gdk_window_get_display (window);
4520 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4522 gdk_window_set_cursor (window, cursor);
4524 g_object_unref (cursor);
4528 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4530 GtkEntryPrivate *priv = entry->priv;
4532 if (priv->mouse_cursor_obscured)
4535 set_invisible_cursor (priv->text_area);
4537 priv->mouse_cursor_obscured = TRUE;
4541 gtk_entry_key_press (GtkWidget *widget,
4544 GtkEntry *entry = GTK_ENTRY (widget);
4545 GtkEntryPrivate *priv = entry->priv;
4547 gtk_entry_reset_blink_time (entry);
4548 gtk_entry_pend_cursor_blink (entry);
4550 gtk_entry_selection_bubble_popup_unset (entry);
4552 if (!event->send_event)
4553 _gtk_text_handle_set_mode (priv->text_handle,
4554 GTK_TEXT_HANDLE_MODE_NONE);
4558 if (gtk_im_context_filter_keypress (priv->im_context, event))
4560 gtk_entry_obscure_mouse_cursor (entry);
4561 priv->need_im_reset = TRUE;
4566 if (event->keyval == GDK_KEY_Return ||
4567 event->keyval == GDK_KEY_KP_Enter ||
4568 event->keyval == GDK_KEY_ISO_Enter ||
4569 event->keyval == GDK_KEY_Escape)
4570 gtk_entry_reset_im_context (entry);
4572 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4573 /* Activate key bindings
4577 if (!priv->editable && event->length)
4578 gtk_widget_error_bell (widget);
4584 gtk_entry_key_release (GtkWidget *widget,
4587 GtkEntry *entry = GTK_ENTRY (widget);
4588 GtkEntryPrivate *priv = entry->priv;
4592 if (gtk_im_context_filter_keypress (priv->im_context, event))
4594 priv->need_im_reset = TRUE;
4599 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4603 gtk_entry_focus_in (GtkWidget *widget,
4604 GdkEventFocus *event)
4606 GtkEntry *entry = GTK_ENTRY (widget);
4607 GtkEntryPrivate *priv = entry->priv;
4610 gtk_widget_queue_draw (widget);
4612 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4616 priv->need_im_reset = TRUE;
4617 gtk_im_context_focus_in (priv->im_context);
4618 keymap_state_changed (keymap, entry);
4619 g_signal_connect (keymap, "state-changed",
4620 G_CALLBACK (keymap_state_changed), entry);
4623 g_signal_connect (keymap, "direction-changed",
4624 G_CALLBACK (keymap_direction_changed), entry);
4626 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4627 priv->placeholder_text != NULL)
4629 gtk_entry_recompute (entry);
4633 gtk_entry_reset_blink_time (entry);
4634 gtk_entry_check_cursor_blink (entry);
4641 gtk_entry_focus_out (GtkWidget *widget,
4642 GdkEventFocus *event)
4644 GtkEntry *entry = GTK_ENTRY (widget);
4645 GtkEntryPrivate *priv = entry->priv;
4646 GtkEntryCompletion *completion;
4649 gtk_entry_selection_bubble_popup_unset (entry);
4650 _gtk_text_handle_set_mode (priv->text_handle,
4651 GTK_TEXT_HANDLE_MODE_NONE);
4653 gtk_widget_queue_draw (widget);
4655 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4659 priv->need_im_reset = TRUE;
4660 gtk_im_context_focus_out (priv->im_context);
4661 remove_capslock_feedback (entry);
4664 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4665 priv->placeholder_text != NULL)
4667 gtk_entry_recompute (entry);
4671 gtk_entry_check_cursor_blink (entry);
4674 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4675 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4677 completion = gtk_entry_get_completion (entry);
4679 _gtk_entry_completion_popdown (completion);
4685 gtk_entry_grab_focus (GtkWidget *widget)
4687 GtkEntry *entry = GTK_ENTRY (widget);
4688 GtkEntryPrivate *priv = entry->priv;
4689 gboolean select_on_focus;
4691 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4693 if (priv->editable && !priv->in_click)
4695 g_object_get (gtk_widget_get_settings (widget),
4696 "gtk-entry-select-on-focus",
4700 if (select_on_focus)
4701 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4706 gtk_entry_direction_changed (GtkWidget *widget,
4707 GtkTextDirection previous_dir)
4709 GtkEntry *entry = GTK_ENTRY (widget);
4711 gtk_entry_recompute (entry);
4713 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4717 gtk_entry_state_flags_changed (GtkWidget *widget,
4718 GtkStateFlags previous_state)
4720 GtkEntry *entry = GTK_ENTRY (widget);
4721 GtkEntryPrivate *priv = entry->priv;
4724 if (gtk_widget_get_realized (widget))
4726 if (gtk_widget_is_sensitive (widget))
4727 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4731 gdk_window_set_cursor (priv->text_area, cursor);
4734 g_object_unref (cursor);
4736 priv->mouse_cursor_obscured = FALSE;
4738 update_cursors (widget);
4741 if (!gtk_widget_is_sensitive (widget))
4743 /* Clear any selection */
4744 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4747 gtk_entry_update_cached_style_values (entry);
4751 gtk_entry_screen_changed (GtkWidget *widget,
4752 GdkScreen *old_screen)
4754 gtk_entry_recompute (GTK_ENTRY (widget));
4757 /* GtkEditable method implementations
4760 gtk_entry_insert_text (GtkEditable *editable,
4761 const gchar *new_text,
4762 gint new_text_length,
4765 g_object_ref (editable);
4768 * The incoming text may a password or other secret. We make sure
4769 * not to copy it into temporary buffers.
4772 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4774 g_object_unref (editable);
4778 gtk_entry_delete_text (GtkEditable *editable,
4782 g_object_ref (editable);
4784 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4786 g_object_unref (editable);
4790 gtk_entry_get_chars (GtkEditable *editable,
4794 GtkEntry *entry = GTK_ENTRY (editable);
4797 gint start_index, end_index;
4799 text = gtk_entry_buffer_get_text (get_buffer (entry));
4800 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4803 end_pos = text_length;
4805 start_pos = MIN (text_length, start_pos);
4806 end_pos = MIN (text_length, end_pos);
4808 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4809 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4811 return g_strndup (text + start_index, end_index - start_index);
4815 gtk_entry_real_set_position (GtkEditable *editable,
4818 GtkEntry *entry = GTK_ENTRY (editable);
4819 GtkEntryPrivate *priv = entry->priv;
4823 length = gtk_entry_buffer_get_length (get_buffer (entry));
4824 if (position < 0 || position > length)
4827 if (position != priv->current_pos ||
4828 position != priv->selection_bound)
4830 gtk_entry_reset_im_context (entry);
4831 gtk_entry_set_positions (entry, position, position);
4836 gtk_entry_get_position (GtkEditable *editable)
4838 GtkEntry *entry = GTK_ENTRY (editable);
4839 GtkEntryPrivate *priv = entry->priv;
4841 return priv->current_pos;
4845 gtk_entry_set_selection_bounds (GtkEditable *editable,
4849 GtkEntry *entry = GTK_ENTRY (editable);
4852 length = gtk_entry_buffer_get_length (get_buffer (entry));
4858 gtk_entry_reset_im_context (entry);
4860 gtk_entry_set_positions (entry,
4862 MIN (start, length));
4864 gtk_entry_update_primary_selection (entry);
4868 gtk_entry_get_selection_bounds (GtkEditable *editable,
4872 GtkEntry *entry = GTK_ENTRY (editable);
4873 GtkEntryPrivate *priv = entry->priv;
4875 *start = priv->selection_bound;
4876 *end = priv->current_pos;
4878 return (priv->selection_bound != priv->current_pos);
4882 icon_theme_changed (GtkEntry *entry)
4884 GtkEntryPrivate *priv = entry->priv;
4887 for (i = 0; i < MAX_ICONS; i++)
4889 EntryIconInfo *icon_info = priv->icons[i];
4890 if (icon_info != NULL)
4891 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4894 gtk_widget_queue_draw (GTK_WIDGET (entry));
4898 gtk_entry_update_cached_style_values (GtkEntry *entry)
4900 GtkEntryPrivate *priv = entry->priv;
4902 gboolean interior_focus;
4904 gtk_widget_style_get (GTK_WIDGET (entry),
4905 "focus-line-width", &focus_width,
4906 "interior-focus", &interior_focus,
4908 priv->focus_width = focus_width;
4909 priv->interior_focus = interior_focus;
4911 if (!priv->invisible_char_set)
4913 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4915 if (priv->invisible_char != ch)
4917 priv->invisible_char = ch;
4918 g_object_notify (G_OBJECT (entry), "invisible-char");
4924 gtk_entry_style_updated (GtkWidget *widget)
4926 GtkEntry *entry = GTK_ENTRY (widget);
4928 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4930 gtk_entry_update_cached_style_values (entry);
4932 icon_theme_changed (entry);
4935 /* GtkCellEditable method implementations
4938 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4940 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4941 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4945 gtk_cell_editable_key_press_event (GtkEntry *entry,
4946 GdkEventKey *key_event,
4949 GtkEntryPrivate *priv = entry->priv;
4951 if (key_event->keyval == GDK_KEY_Escape)
4953 priv->editing_canceled = TRUE;
4954 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4955 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4960 /* override focus */
4961 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4963 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4964 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4973 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4976 GtkEntry *entry = GTK_ENTRY (cell_editable);
4977 GtkEntryPrivate *priv = entry->priv;
4979 priv->is_cell_renderer = TRUE;
4981 g_signal_connect (cell_editable, "activate",
4982 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4983 g_signal_connect (cell_editable, "key-press-event",
4984 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4988 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4990 if (password_hint->source_id)
4991 g_source_remove (password_hint->source_id);
4993 g_slice_free (GtkEntryPasswordHint, password_hint);
4998 gtk_entry_remove_password_hint (gpointer data)
5000 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
5001 password_hint->position = -1;
5003 /* Force the string to be redrawn, but now without a visible character */
5004 gtk_entry_recompute (GTK_ENTRY (data));
5008 /* Default signal handlers
5011 gtk_entry_real_insert_text (GtkEditable *editable,
5012 const gchar *new_text,
5013 gint new_text_length,
5019 n_chars = g_utf8_strlen (new_text, new_text_length);
5022 * The actual insertion into the buffer. This will end up firing the
5023 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
5024 * buffer_notify_text(), buffer_notify_length()
5026 begin_change (GTK_ENTRY (editable));
5028 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
5030 end_change (GTK_ENTRY (editable));
5032 if (n_inserted != n_chars)
5033 gtk_widget_error_bell (GTK_WIDGET (editable));
5035 *position += n_inserted;
5039 gtk_entry_real_delete_text (GtkEditable *editable,
5044 * The actual deletion from the buffer. This will end up firing the
5045 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
5046 * buffer_notify_text(), buffer_notify_length()
5049 begin_change (GTK_ENTRY (editable));
5051 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
5053 end_change (GTK_ENTRY (editable));
5056 /* GtkEntryBuffer signal handlers
5059 buffer_inserted_text (GtkEntryBuffer *buffer,
5065 GtkEntryPrivate *priv = entry->priv;
5066 guint password_hint_timeout;
5068 gint selection_bound;
5070 current_pos = priv->current_pos;
5071 if (current_pos > position)
5072 current_pos += n_chars;
5074 selection_bound = priv->selection_bound;
5075 if (selection_bound > position)
5076 selection_bound += n_chars;
5078 gtk_entry_set_positions (entry, current_pos, selection_bound);
5080 /* Calculate the password hint if it needs to be displayed. */
5081 if (n_chars == 1 && !priv->visible)
5083 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5084 "gtk-entry-password-hint-timeout", &password_hint_timeout,
5087 if (password_hint_timeout > 0)
5089 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5090 quark_password_hint);
5093 password_hint = g_slice_new0 (GtkEntryPasswordHint);
5094 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
5095 (GDestroyNotify)gtk_entry_password_hint_free);
5098 password_hint->position = position;
5099 if (password_hint->source_id)
5100 g_source_remove (password_hint->source_id);
5101 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
5102 (GSourceFunc)gtk_entry_remove_password_hint, entry);
5108 buffer_deleted_text (GtkEntryBuffer *buffer,
5113 GtkEntryPrivate *priv = entry->priv;
5114 guint end_pos = position + n_chars;
5115 gint selection_bound;
5118 current_pos = priv->current_pos;
5119 if (current_pos > position)
5120 current_pos -= MIN (current_pos, end_pos) - position;
5122 selection_bound = priv->selection_bound;
5123 if (selection_bound > position)
5124 selection_bound -= MIN (selection_bound, end_pos) - position;
5126 gtk_entry_set_positions (entry, current_pos, selection_bound);
5128 /* We might have deleted the selection */
5129 gtk_entry_update_primary_selection (entry);
5131 /* Disable the password hint if one exists. */
5134 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5135 quark_password_hint);
5138 if (password_hint->source_id)
5139 g_source_remove (password_hint->source_id);
5140 password_hint->source_id = 0;
5141 password_hint->position = -1;
5147 buffer_notify_text (GtkEntryBuffer *buffer,
5151 gtk_entry_recompute (entry);
5152 emit_changed (entry);
5153 g_object_notify (G_OBJECT (entry), "text");
5157 buffer_notify_length (GtkEntryBuffer *buffer,
5161 g_object_notify (G_OBJECT (entry), "text-length");
5165 buffer_notify_max_length (GtkEntryBuffer *buffer,
5169 g_object_notify (G_OBJECT (entry), "max-length");
5173 buffer_connect_signals (GtkEntry *entry)
5175 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
5176 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
5177 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
5178 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
5179 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
5183 buffer_disconnect_signals (GtkEntry *entry)
5185 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
5186 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
5187 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
5188 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
5189 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
5192 /* Compute the X position for an offset that corresponds to the "more important
5193 * cursor position for that offset. We use this when trying to guess to which
5194 * end of the selection we should go to when the user hits the left or
5198 get_better_cursor_x (GtkEntry *entry,
5201 GtkEntryPrivate *priv = entry->priv;
5202 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5203 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5204 gboolean split_cursor;
5206 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5207 const gchar *text = pango_layout_get_text (layout);
5208 gint index = g_utf8_offset_to_pointer (text, offset) - text;
5210 PangoRectangle strong_pos, weak_pos;
5212 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5213 "gtk-split-cursor", &split_cursor,
5216 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5219 return strong_pos.x / PANGO_SCALE;
5221 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
5225 gtk_entry_move_cursor (GtkEntry *entry,
5226 GtkMovementStep step,
5228 gboolean extend_selection)
5230 GtkEntryPrivate *priv = entry->priv;
5231 gint new_pos = priv->current_pos;
5233 gtk_entry_reset_im_context (entry);
5235 if (priv->current_pos != priv->selection_bound && !extend_selection)
5237 /* If we have a current selection and aren't extending it, move to the
5238 * start/or end of the selection as appropriate
5242 case GTK_MOVEMENT_VISUAL_POSITIONS:
5244 gint current_x = get_better_cursor_x (entry, priv->current_pos);
5245 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
5248 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
5250 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
5253 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5254 case GTK_MOVEMENT_WORDS:
5256 new_pos = MIN (priv->current_pos, priv->selection_bound);
5258 new_pos = MAX (priv->current_pos, priv->selection_bound);
5260 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5261 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5262 case GTK_MOVEMENT_BUFFER_ENDS:
5263 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5265 case GTK_MOVEMENT_DISPLAY_LINES:
5266 case GTK_MOVEMENT_PARAGRAPHS:
5267 case GTK_MOVEMENT_PAGES:
5268 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5276 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5277 new_pos = gtk_entry_move_logically (entry, new_pos, count);
5279 case GTK_MOVEMENT_VISUAL_POSITIONS:
5280 new_pos = gtk_entry_move_visually (entry, new_pos, count);
5281 if (priv->current_pos == new_pos)
5283 if (!extend_selection)
5285 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
5287 GTK_DIR_RIGHT : GTK_DIR_LEFT))
5289 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
5292 gtk_widget_child_focus (toplevel,
5294 GTK_DIR_RIGHT : GTK_DIR_LEFT);
5299 gtk_widget_error_bell (GTK_WIDGET (entry));
5303 case GTK_MOVEMENT_WORDS:
5306 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5311 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5314 if (priv->current_pos == new_pos)
5315 gtk_widget_error_bell (GTK_WIDGET (entry));
5317 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5318 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5319 case GTK_MOVEMENT_BUFFER_ENDS:
5320 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5321 if (priv->current_pos == new_pos)
5322 gtk_widget_error_bell (GTK_WIDGET (entry));
5324 case GTK_MOVEMENT_DISPLAY_LINES:
5325 case GTK_MOVEMENT_PARAGRAPHS:
5326 case GTK_MOVEMENT_PAGES:
5327 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5332 if (extend_selection)
5333 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5335 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5337 gtk_entry_pend_cursor_blink (entry);
5341 gtk_entry_insert_at_cursor (GtkEntry *entry,
5344 GtkEntryPrivate *priv = entry->priv;
5345 GtkEditable *editable = GTK_EDITABLE (entry);
5346 gint pos = priv->current_pos;
5350 gtk_entry_reset_im_context (entry);
5351 gtk_editable_insert_text (editable, str, -1, &pos);
5352 gtk_editable_set_position (editable, pos);
5357 gtk_entry_delete_from_cursor (GtkEntry *entry,
5361 GtkEntryPrivate *priv = entry->priv;
5362 GtkEditable *editable = GTK_EDITABLE (entry);
5363 gint start_pos = priv->current_pos;
5364 gint end_pos = priv->current_pos;
5365 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5367 gtk_entry_reset_im_context (entry);
5369 if (!priv->editable)
5371 gtk_widget_error_bell (GTK_WIDGET (entry));
5375 if (priv->selection_bound != priv->current_pos)
5377 gtk_editable_delete_selection (editable);
5383 case GTK_DELETE_CHARS:
5384 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5385 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5387 case GTK_DELETE_WORDS:
5390 /* Move to end of current word, or if not on a word, end of previous word */
5391 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5392 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5396 /* Move to beginning of current word, or if not on a word, begining of next word */
5397 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5398 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5402 case GTK_DELETE_WORD_ENDS:
5405 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5410 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5413 gtk_editable_delete_text (editable, start_pos, end_pos);
5415 case GTK_DELETE_DISPLAY_LINE_ENDS:
5416 case GTK_DELETE_PARAGRAPH_ENDS:
5418 gtk_editable_delete_text (editable, 0, priv->current_pos);
5420 gtk_editable_delete_text (editable, priv->current_pos, -1);
5422 case GTK_DELETE_DISPLAY_LINES:
5423 case GTK_DELETE_PARAGRAPHS:
5424 gtk_editable_delete_text (editable, 0, -1);
5426 case GTK_DELETE_WHITESPACE:
5427 gtk_entry_delete_whitespace (entry);
5431 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5432 gtk_widget_error_bell (GTK_WIDGET (entry));
5434 gtk_entry_pend_cursor_blink (entry);
5438 gtk_entry_backspace (GtkEntry *entry)
5440 GtkEntryPrivate *priv = entry->priv;
5441 GtkEditable *editable = GTK_EDITABLE (entry);
5444 gtk_entry_reset_im_context (entry);
5446 if (!priv->editable)
5448 gtk_widget_error_bell (GTK_WIDGET (entry));
5452 if (priv->selection_bound != priv->current_pos)
5454 gtk_editable_delete_selection (editable);
5458 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5460 if (prev_pos < priv->current_pos)
5462 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5463 PangoLogAttr *log_attrs;
5466 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5468 /* Deleting parts of characters */
5469 if (log_attrs[priv->current_pos].backspace_deletes_character)
5471 gchar *cluster_text;
5472 gchar *normalized_text;
5475 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5477 normalized_text = g_utf8_normalize (cluster_text,
5478 strlen (cluster_text),
5480 len = g_utf8_strlen (normalized_text, -1);
5482 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5485 gint pos = priv->current_pos;
5487 gtk_editable_insert_text (editable, normalized_text,
5488 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5490 gtk_editable_set_position (editable, pos);
5493 g_free (normalized_text);
5494 g_free (cluster_text);
5498 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5505 gtk_widget_error_bell (GTK_WIDGET (entry));
5508 gtk_entry_pend_cursor_blink (entry);
5512 gtk_entry_copy_clipboard (GtkEntry *entry)
5514 GtkEntryPrivate *priv = entry->priv;
5515 GtkEditable *editable = GTK_EDITABLE (entry);
5519 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5523 gtk_widget_error_bell (GTK_WIDGET (entry));
5527 str = _gtk_entry_get_display_text (entry, start, end);
5528 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5529 GDK_SELECTION_CLIPBOARD),
5536 gtk_entry_cut_clipboard (GtkEntry *entry)
5538 GtkEntryPrivate *priv = entry->priv;
5539 GtkEditable *editable = GTK_EDITABLE (entry);
5544 gtk_widget_error_bell (GTK_WIDGET (entry));
5548 gtk_entry_copy_clipboard (entry);
5552 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5553 gtk_editable_delete_text (editable, start, end);
5557 gtk_widget_error_bell (GTK_WIDGET (entry));
5560 gtk_entry_selection_bubble_popup_unset (entry);
5564 gtk_entry_paste_clipboard (GtkEntry *entry)
5566 GtkEntryPrivate *priv = entry->priv;
5569 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5571 gtk_widget_error_bell (GTK_WIDGET (entry));
5575 gtk_entry_delete_cb (GtkEntry *entry)
5577 GtkEntryPrivate *priv = entry->priv;
5578 GtkEditable *editable = GTK_EDITABLE (entry);
5583 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5584 gtk_editable_delete_text (editable, start, end);
5589 gtk_entry_toggle_overwrite (GtkEntry *entry)
5591 GtkEntryPrivate *priv = entry->priv;
5593 priv->overwrite_mode = !priv->overwrite_mode;
5594 gtk_entry_pend_cursor_blink (entry);
5595 gtk_widget_queue_draw (GTK_WIDGET (entry));
5599 gtk_entry_select_all (GtkEntry *entry)
5601 gtk_entry_select_line (entry);
5605 gtk_entry_real_activate (GtkEntry *entry)
5607 GtkEntryPrivate *priv = entry->priv;
5609 GtkWidget *default_widget, *focus_widget;
5610 GtkWidget *toplevel;
5613 widget = GTK_WIDGET (entry);
5615 if (priv->activates_default)
5617 toplevel = gtk_widget_get_toplevel (widget);
5618 if (GTK_IS_WINDOW (toplevel))
5620 window = GTK_WINDOW (toplevel);
5624 default_widget = gtk_window_get_default_widget (window);
5625 focus_widget = gtk_window_get_focus (window);
5626 if (widget != default_widget &&
5627 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5628 gtk_window_activate_default (window);
5635 keymap_direction_changed (GdkKeymap *keymap,
5638 gtk_entry_recompute (entry);
5641 /* IM Context Callbacks
5645 gtk_entry_commit_cb (GtkIMContext *context,
5649 GtkEntryPrivate *priv = entry->priv;
5652 gtk_entry_enter_text (entry, str);
5656 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5659 GtkEntryPrivate *priv = entry->priv;
5663 gchar *preedit_string;
5666 gtk_im_context_get_preedit_string (priv->im_context,
5667 &preedit_string, NULL,
5669 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5670 priv->preedit_length = strlen (preedit_string);
5671 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5672 priv->preedit_cursor = cursor_pos;
5673 g_free (preedit_string);
5675 gtk_entry_recompute (entry);
5680 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5683 GtkEntryPrivate *priv = entry->priv;
5686 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5687 text = _gtk_entry_get_display_text (entry, 0, -1);
5688 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5689 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5696 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5701 GtkEntryPrivate *priv = entry->priv;
5704 gtk_editable_delete_text (GTK_EDITABLE (entry),
5705 priv->current_pos + offset,
5706 priv->current_pos + offset + n_chars);
5711 /* Internal functions
5714 /* Used for im_commit_cb and inserting Unicode chars */
5716 gtk_entry_enter_text (GtkEntry *entry,
5719 GtkEntryPrivate *priv = entry->priv;
5720 GtkEditable *editable = GTK_EDITABLE (entry);
5722 gboolean old_need_im_reset;
5724 old_need_im_reset = priv->need_im_reset;
5725 priv->need_im_reset = FALSE;
5727 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5728 gtk_editable_delete_selection (editable);
5731 if (priv->overwrite_mode)
5732 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5735 tmp_pos = priv->current_pos;
5736 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5737 gtk_editable_set_position (editable, tmp_pos);
5739 priv->need_im_reset = old_need_im_reset;
5742 /* All changes to priv->current_pos and priv->selection_bound
5743 * should go through this function.
5746 gtk_entry_set_positions (GtkEntry *entry,
5748 gint selection_bound)
5750 GtkEntryPrivate *priv = entry->priv;
5751 gboolean changed = FALSE;
5753 g_object_freeze_notify (G_OBJECT (entry));
5755 if (current_pos != -1 &&
5756 priv->current_pos != current_pos)
5758 priv->current_pos = current_pos;
5761 g_object_notify (G_OBJECT (entry), "cursor-position");
5764 if (selection_bound != -1 &&
5765 priv->selection_bound != selection_bound)
5767 priv->selection_bound = selection_bound;
5770 g_object_notify (G_OBJECT (entry), "selection-bound");
5773 g_object_thaw_notify (G_OBJECT (entry));
5777 gtk_entry_move_adjustments (entry);
5778 gtk_entry_recompute (entry);
5783 gtk_entry_reset_layout (GtkEntry *entry)
5785 GtkEntryPrivate *priv = entry->priv;
5787 if (priv->cached_layout)
5789 g_object_unref (priv->cached_layout);
5790 priv->cached_layout = NULL;
5795 update_im_cursor_location (GtkEntry *entry)
5797 GtkEntryPrivate *priv = entry->priv;
5800 gint strong_xoffset;
5801 gint area_width, area_height;
5803 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5804 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5806 strong_xoffset = strong_x - priv->scroll_offset;
5807 if (strong_xoffset < 0)
5811 else if (strong_xoffset > area_width)
5813 strong_xoffset = area_width;
5815 area.x = strong_xoffset;
5818 area.height = area_height;
5820 gtk_im_context_set_cursor_location (priv->im_context, &area);
5824 recompute_idle_func (gpointer data)
5826 GtkEntry *entry = GTK_ENTRY (data);
5827 GtkEntryPrivate *priv = entry->priv;
5829 priv->recompute_idle = 0;
5831 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5833 GtkTextHandleMode handle_mode;
5835 gtk_entry_adjust_scroll (entry);
5836 gtk_widget_queue_draw (GTK_WIDGET (entry));
5838 update_im_cursor_location (entry);
5840 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
5842 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
5843 gtk_entry_update_handles (entry, handle_mode);
5850 gtk_entry_recompute (GtkEntry *entry)
5852 GtkEntryPrivate *priv = entry->priv;
5854 gtk_entry_reset_layout (entry);
5855 gtk_entry_check_cursor_blink (entry);
5857 if (!priv->recompute_idle)
5859 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5860 recompute_idle_func, entry, NULL);
5865 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5868 GtkWidget *widget = GTK_WIDGET (entry);
5869 GtkStyleContext *context;
5870 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5872 context = gtk_widget_get_style_context (widget);
5873 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5875 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5876 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5877 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5880 static inline gboolean
5881 show_placeholder_text (GtkEntry *entry)
5883 GtkEntryPrivate *priv = entry->priv;
5885 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5886 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5887 priv->placeholder_text != NULL)
5893 static PangoLayout *
5894 gtk_entry_create_layout (GtkEntry *entry,
5895 gboolean include_preedit)
5897 GtkEntryPrivate *priv = entry->priv;
5898 GtkWidget *widget = GTK_WIDGET (entry);
5899 PangoLayout *layout;
5900 PangoAttrList *tmp_attrs;
5901 gboolean placeholder_layout;
5903 gchar *preedit_string = NULL;
5904 gint preedit_length = 0;
5905 PangoAttrList *preedit_attrs = NULL;
5910 layout = gtk_widget_create_pango_layout (widget, NULL);
5911 pango_layout_set_single_paragraph_mode (layout, TRUE);
5913 tmp_attrs = priv->attrs ? pango_attr_list_ref (priv->attrs)
5914 : pango_attr_list_new ();
5916 placeholder_layout = show_placeholder_text (entry);
5917 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5918 n_bytes = strlen (display);
5920 if (!placeholder_layout && include_preedit)
5922 gtk_im_context_get_preedit_string (priv->im_context,
5923 &preedit_string, &preedit_attrs, NULL);
5924 preedit_length = priv->preedit_length;
5926 else if (placeholder_layout)
5929 PangoAttribute *attr;
5931 gtk_entry_get_placeholder_text_color (entry, &color);
5932 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5933 attr->start_index = 0;
5934 attr->end_index = G_MAXINT;
5935 pango_attr_list_insert (tmp_attrs, attr);
5940 GString *tmp_string = g_string_new (display);
5941 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5943 g_string_insert (tmp_string, cursor_index, preedit_string);
5944 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5945 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5946 cursor_index, preedit_length);
5947 g_string_free (tmp_string, TRUE);
5951 PangoDirection pango_dir;
5953 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5954 pango_dir = pango_find_base_dir (display, n_bytes);
5956 pango_dir = PANGO_DIRECTION_NEUTRAL;
5958 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5960 if (gtk_widget_has_focus (widget))
5962 GdkDisplay *display = gtk_widget_get_display (widget);
5963 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5964 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5965 pango_dir = PANGO_DIRECTION_RTL;
5967 pango_dir = PANGO_DIRECTION_LTR;
5971 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5972 pango_dir = PANGO_DIRECTION_RTL;
5974 pango_dir = PANGO_DIRECTION_LTR;
5978 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5981 priv->resolved_dir = pango_dir;
5983 pango_layout_set_text (layout, display, n_bytes);
5986 pango_layout_set_attributes (layout, tmp_attrs);
5988 g_free (preedit_string);
5992 pango_attr_list_unref (preedit_attrs);
5994 pango_attr_list_unref (tmp_attrs);
5999 static PangoLayout *
6000 gtk_entry_ensure_layout (GtkEntry *entry,
6001 gboolean include_preedit)
6003 GtkEntryPrivate *priv = entry->priv;
6005 if (priv->preedit_length > 0 &&
6006 !include_preedit != !priv->cache_includes_preedit)
6007 gtk_entry_reset_layout (entry);
6009 if (!priv->cached_layout)
6011 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
6012 priv->cache_includes_preedit = include_preedit;
6015 return priv->cached_layout;
6019 get_layout_position (GtkEntry *entry,
6023 GtkEntryPrivate *priv = entry->priv;
6024 PangoLayout *layout;
6025 PangoRectangle logical_rect;
6026 gint area_width, area_height;
6028 PangoLayoutLine *line;
6030 layout = gtk_entry_ensure_layout (entry, TRUE);
6032 get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
6033 area_height = PANGO_SCALE * area_height;
6035 line = pango_layout_get_lines_readonly (layout)->data;
6036 pango_layout_line_get_extents (line, NULL, &logical_rect);
6038 /* Align primarily for locale's ascent/descent */
6039 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
6040 priv->ascent + logical_rect.y);
6042 /* Now see if we need to adjust to fit in actual drawn string */
6043 if (logical_rect.height > area_height)
6044 y_pos = (area_height - logical_rect.height) / 2;
6047 else if (y_pos + logical_rect.height > area_height)
6048 y_pos = area_height - logical_rect.height;
6050 y_pos = y_pos / PANGO_SCALE;
6053 *x = - priv->scroll_offset;
6060 draw_text_with_color (GtkEntry *entry,
6062 GdkRGBA *default_color)
6064 GtkEntryPrivate *priv = entry->priv;
6065 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6068 gint start_pos, end_pos;
6070 widget = GTK_WIDGET (entry);
6074 get_layout_position (entry, &x, &y);
6076 cairo_move_to (cr, x, y);
6077 gdk_cairo_set_source_rgba (cr, default_color);
6078 pango_cairo_show_layout (cr, layout);
6080 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
6084 PangoRectangle logical_rect;
6085 GdkRGBA selection_color, text_color;
6086 GtkStyleContext *context;
6087 GtkStateFlags state;
6089 context = gtk_widget_get_style_context (widget);
6090 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
6091 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
6093 state = gtk_widget_get_state_flags (widget);
6094 state |= GTK_STATE_FLAG_SELECTED;
6096 gtk_style_context_get_background_color (context, state, &selection_color);
6097 gtk_style_context_get_color (context, state, &text_color);
6099 for (i = 0; i < n_ranges; ++i)
6100 cairo_rectangle (cr,
6101 - priv->scroll_offset + ranges[2 * i],
6104 logical_rect.height);
6108 gdk_cairo_set_source_rgba (cr, &selection_color);
6111 cairo_move_to (cr, x, y);
6112 gdk_cairo_set_source_rgba (cr, &text_color);
6113 pango_cairo_show_layout (cr, layout);
6121 gtk_entry_draw_text (GtkEntry *entry,
6124 GtkEntryPrivate *priv = entry->priv;
6125 GtkWidget *widget = GTK_WIDGET (entry);
6126 GtkStateFlags state = 0;
6127 GdkRGBA text_color, bar_text_color;
6128 GtkStyleContext *context;
6130 gint progress_x, progress_y, progress_width, progress_height;
6131 gint clip_width, clip_height;
6133 /* Nothing to display at all */
6134 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
6137 state = gtk_widget_get_state_flags (widget);
6138 context = gtk_widget_get_style_context (widget);
6140 gtk_style_context_get_color (context, state, &text_color);
6142 /* Get foreground color for progressbars */
6143 gtk_entry_prepare_context_for_progress (entry, context);
6144 gtk_style_context_get_color (context, state, &bar_text_color);
6145 gtk_style_context_restore (context);
6147 get_progress_area (widget,
6148 &progress_x, &progress_y,
6149 &progress_width, &progress_height);
6153 clip_width = gdk_window_get_width (priv->text_area);
6154 clip_height = gdk_window_get_height (priv->text_area);
6155 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
6158 /* If the color is the same, or the progress area has a zero
6159 * size, then we only need to draw once. */
6160 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
6161 ((progress_width == 0) || (progress_height == 0)))
6163 draw_text_with_color (entry, cr, &text_color);
6167 int frame_x, frame_y, area_x, area_y;
6169 width = gdk_window_get_width (priv->text_area);
6170 height = gdk_window_get_height (priv->text_area);
6174 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
6175 cairo_rectangle (cr, 0, 0, width, height);
6177 /* progres area is frame-relative, we need it text-area window
6179 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
6180 gdk_window_get_position (priv->text_area, &area_x, &area_y);
6181 progress_x += frame_x - area_x;
6182 progress_y += frame_y - area_y;
6184 cairo_rectangle (cr, progress_x, progress_y,
6185 progress_width, progress_height);
6187 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
6189 draw_text_with_color (entry, cr, &text_color);
6194 cairo_rectangle (cr, progress_x, progress_y,
6195 progress_width, progress_height);
6198 draw_text_with_color (entry, cr, &bar_text_color);
6207 gtk_entry_draw_cursor (GtkEntry *entry,
6211 GtkEntryPrivate *priv = entry->priv;
6212 GtkWidget *widget = GTK_WIDGET (entry);
6213 GtkStyleContext *context;
6214 PangoRectangle cursor_rect;
6217 gboolean block_at_line_end;
6218 PangoLayout *layout;
6222 context = gtk_widget_get_style_context (widget);
6224 layout = gtk_entry_ensure_layout (entry, TRUE);
6225 text = pango_layout_get_text (layout);
6226 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6227 get_layout_position (entry, &x, &y);
6229 if (!priv->overwrite_mode)
6232 block = _gtk_text_util_get_block_cursor_location (layout,
6233 cursor_index, &cursor_rect, &block_at_line_end);
6237 gtk_render_insertion_cursor (context, cr,
6239 layout, cursor_index, priv->resolved_dir);
6241 else /* overwrite_mode */
6243 GdkRGBA cursor_color;
6248 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
6249 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
6250 rect.width = PANGO_PIXELS (cursor_rect.width);
6251 rect.height = PANGO_PIXELS (cursor_rect.height);
6253 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
6254 gdk_cairo_set_source_rgba (cr, &cursor_color);
6255 gdk_cairo_rectangle (cr, &rect);
6258 if (!block_at_line_end)
6260 GtkStateFlags state;
6263 state = gtk_widget_get_state_flags (widget);
6264 gtk_style_context_get_background_color (context, state, &color);
6266 gdk_cairo_rectangle (cr, &rect);
6268 cairo_move_to (cr, x, y);
6269 gdk_cairo_set_source_rgba (cr, &color);
6270 pango_cairo_show_layout (cr, layout);
6278 gtk_entry_handle_dragged (GtkTextHandle *handle,
6279 GtkTextHandlePosition pos,
6284 gint cursor_pos, selection_bound_pos, tmp_pos;
6285 GtkEntryPrivate *priv = entry->priv;
6286 GtkTextHandleMode mode;
6289 gtk_entry_selection_bubble_popup_unset (entry);
6291 cursor_pos = priv->current_pos;
6292 selection_bound_pos = priv->selection_bound;
6293 mode = _gtk_text_handle_get_mode (handle);
6294 tmp_pos = gtk_entry_find_position (entry, x + priv->scroll_offset);
6296 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR ||
6297 cursor_pos >= selection_bound_pos)
6300 min = &selection_bound_pos;
6304 max = &selection_bound_pos;
6308 if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
6310 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6314 min_pos = MAX (*min + 1, 0);
6315 tmp_pos = MAX (tmp_pos, min_pos);
6322 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6327 *min = MIN (tmp_pos, max_pos);
6331 if (cursor_pos != priv->current_pos ||
6332 selection_bound_pos != priv->selection_bound)
6334 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
6335 gtk_entry_set_positions (entry, cursor_pos, cursor_pos);
6337 gtk_entry_set_positions (entry, cursor_pos, selection_bound_pos);
6339 gtk_entry_update_handles (entry, mode);
6344 gtk_entry_handle_drag_finished (GtkTextHandle *handle,
6345 GtkTextHandlePosition pos,
6348 gtk_entry_selection_bubble_popup_set (entry);
6353 * gtk_entry_reset_im_context:
6354 * @entry: a #GtkEntry
6356 * Reset the input method context of the entry if needed.
6358 * This can be necessary in the case where modifying the buffer
6359 * would confuse on-going input method behavior.
6364 gtk_entry_reset_im_context (GtkEntry *entry)
6366 GtkEntryPrivate *priv = entry->priv;
6368 g_return_if_fail (GTK_IS_ENTRY (entry));
6370 if (priv->need_im_reset)
6372 priv->need_im_reset = FALSE;
6373 gtk_im_context_reset (priv->im_context);
6378 * gtk_entry_im_context_filter_keypress:
6379 * @entry: a #GtkEntry
6380 * @event: (type Gdk.EventKey): the key event
6382 * Allow the #GtkEntry input method to internally handle key press
6383 * and release events. If this function returns %TRUE, then no further
6384 * processing should be done for this key event. See
6385 * gtk_im_context_filter_keypress().
6387 * Note that you are expected to call this function from your handler
6388 * when overriding key event handling. This is needed in the case when
6389 * you need to insert your own key handling between the input method
6390 * and the default key event handling of the #GtkEntry.
6391 * See gtk_text_view_reset_im_context() for an example of use.
6393 * Return value: %TRUE if the input method handled the key event.
6398 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6401 GtkEntryPrivate *priv;
6403 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6407 return gtk_im_context_filter_keypress (priv->im_context, event);
6411 _gtk_entry_get_im_context (GtkEntry *entry)
6413 return entry->priv->im_context;
6417 gtk_entry_find_position (GtkEntry *entry,
6420 GtkEntryPrivate *priv = entry->priv;
6421 PangoLayout *layout;
6422 PangoLayoutLine *line;
6429 layout = gtk_entry_ensure_layout (entry, TRUE);
6430 text = pango_layout_get_text (layout);
6431 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6433 line = pango_layout_get_lines_readonly (layout)->data;
6434 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6436 if (index >= cursor_index && priv->preedit_length)
6438 if (index >= cursor_index + priv->preedit_length)
6439 index -= priv->preedit_length;
6442 index = cursor_index;
6447 pos = g_utf8_pointer_to_offset (text, text + index);
6454 gtk_entry_get_cursor_locations (GtkEntry *entry,
6459 GtkEntryPrivate *priv = entry->priv;
6460 DisplayMode mode = gtk_entry_get_display_mode (entry);
6462 /* Nothing to display at all, so no cursor is relevant */
6463 if (mode == DISPLAY_BLANK)
6473 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6474 const gchar *text = pango_layout_get_text (layout);
6475 PangoRectangle strong_pos, weak_pos;
6478 if (type == CURSOR_STANDARD)
6480 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6482 else /* type == CURSOR_DND */
6484 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6486 if (priv->dnd_position > priv->current_pos)
6488 if (mode == DISPLAY_NORMAL)
6489 index += priv->preedit_length;
6492 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6493 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6498 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6501 *strong_x = strong_pos.x / PANGO_SCALE;
6504 *weak_x = weak_pos.x / PANGO_SCALE;
6509 gtk_entry_get_is_selection_handle_dragged (GtkEntry *entry)
6511 GtkEntryPrivate *priv = entry->priv;
6512 GtkTextHandlePosition pos;
6514 if (_gtk_text_handle_get_mode (priv->text_handle) != GTK_TEXT_HANDLE_MODE_SELECTION)
6517 if (priv->current_pos >= priv->selection_bound)
6518 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
6520 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
6522 return _gtk_text_handle_get_is_dragged (priv->text_handle, pos);
6526 gtk_entry_adjust_scroll (GtkEntry *entry)
6528 GtkEntryPrivate *priv = entry->priv;
6529 gint min_offset, max_offset;
6530 gint text_area_width, text_width;
6531 gint strong_x, weak_x;
6532 gint strong_xoffset, weak_xoffset;
6534 PangoLayout *layout;
6535 PangoLayoutLine *line;
6536 PangoRectangle logical_rect;
6537 GtkTextHandleMode handle_mode;
6539 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6542 text_area_width = gdk_window_get_width (priv->text_area);
6544 if (text_area_width < 0)
6545 text_area_width = 0;
6547 layout = gtk_entry_ensure_layout (entry, TRUE);
6548 line = pango_layout_get_lines_readonly (layout)->data;
6550 pango_layout_line_get_extents (line, NULL, &logical_rect);
6552 /* Display as much text as we can */
6554 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6555 xalign = priv->xalign;
6557 xalign = 1.0 - priv->xalign;
6559 text_width = PANGO_PIXELS(logical_rect.width);
6561 if (text_width > text_area_width)
6564 max_offset = text_width - text_area_width;
6568 min_offset = (text_width - text_area_width) * xalign;
6569 max_offset = min_offset;
6572 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6574 if (gtk_entry_get_is_selection_handle_dragged (entry))
6576 /* The text handle corresponding to the selection bound is
6577 * being dragged, ensure it stays onscreen even if we scroll
6578 * cursors away, this is so both handles can cause content
6581 strong_x = weak_x = gtk_entry_get_selection_bound_location (entry);
6585 /* And make sure cursors are on screen. Note that the cursor is
6586 * actually drawn one pixel into the INNER_BORDER space on
6587 * the right, when the scroll is at the utmost right. This
6588 * looks better to to me than confining the cursor inside the
6589 * border entirely, though it means that the cursor gets one
6590 * pixel closer to the edge of the widget on the right than
6591 * on the left. This might need changing if one changed
6592 * INNER_BORDER from 2 to 1, as one would do on a
6593 * small-screen-real-estate display.
6595 * We always make sure that the strong cursor is on screen, and
6596 * put the weak cursor on screen if possible.
6598 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6601 strong_xoffset = strong_x - priv->scroll_offset;
6603 if (strong_xoffset < 0)
6605 priv->scroll_offset += strong_xoffset;
6608 else if (strong_xoffset > text_area_width)
6610 priv->scroll_offset += strong_xoffset - text_area_width;
6611 strong_xoffset = text_area_width;
6614 weak_xoffset = weak_x - priv->scroll_offset;
6616 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6618 priv->scroll_offset += weak_xoffset;
6620 else if (weak_xoffset > text_area_width &&
6621 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6623 priv->scroll_offset += weak_xoffset - text_area_width;
6626 g_object_notify (G_OBJECT (entry), "scroll-offset");
6628 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
6630 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
6631 gtk_entry_update_handles (entry, handle_mode);
6635 gtk_entry_move_adjustments (GtkEntry *entry)
6637 GtkWidget *widget = GTK_WIDGET (entry);
6638 GtkAllocation allocation;
6639 GtkAdjustment *adjustment;
6640 PangoContext *context;
6641 PangoFontMetrics *metrics;
6646 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6650 gtk_widget_get_allocation (widget, &allocation);
6652 /* Cursor/char position, layout offset, border width, and widget allocation */
6653 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6654 get_layout_position (entry, &layout_x, NULL);
6655 _gtk_entry_get_borders (entry, &borders);
6656 x += allocation.x + layout_x + borders.left;
6658 /* Approximate width of a char, so user can see what is ahead/behind */
6659 context = gtk_widget_get_pango_context (widget);
6661 metrics = pango_context_get_metrics (context,
6662 pango_context_get_font_description (context),
6663 pango_context_get_language (context));
6664 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6667 gtk_adjustment_clamp_page (adjustment,
6668 x - (char_width + 1), /* one char + one pixel before */
6669 x + (char_width + 2)); /* one char + cursor + one pixel after */
6673 gtk_entry_move_visually (GtkEntry *entry,
6677 GtkEntryPrivate *priv = entry->priv;
6679 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6682 text = pango_layout_get_text (layout);
6684 index = g_utf8_offset_to_pointer (text, start) - text;
6688 int new_index, new_trailing;
6689 gboolean split_cursor;
6692 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6693 "gtk-split-cursor", &split_cursor,
6700 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6701 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6703 strong = keymap_direction == priv->resolved_dir;
6708 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6713 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6719 else if (new_index != G_MAXINT)
6722 while (new_trailing--)
6723 index = g_utf8_next_char (text + index) - text;
6726 return g_utf8_pointer_to_offset (text, text + index);
6730 gtk_entry_move_logically (GtkEntry *entry,
6734 gint new_pos = start;
6737 length = gtk_entry_buffer_get_length (get_buffer (entry));
6739 /* Prevent any leak of information */
6740 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6742 new_pos = CLAMP (start + count, 0, length);
6746 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6747 PangoLogAttr *log_attrs;
6750 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6752 while (count > 0 && new_pos < length)
6756 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6760 while (count < 0 && new_pos > 0)
6764 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6776 gtk_entry_move_forward_word (GtkEntry *entry,
6778 gboolean allow_whitespace)
6780 gint new_pos = start;
6783 length = gtk_entry_buffer_get_length (get_buffer (entry));
6785 /* Prevent any leak of information */
6786 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6790 else if (new_pos < length)
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 /* Find the next word boundary */
6800 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6801 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6812 gtk_entry_move_backward_word (GtkEntry *entry,
6814 gboolean allow_whitespace)
6816 gint new_pos = start;
6818 /* Prevent any leak of information */
6819 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6825 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6826 PangoLogAttr *log_attrs;
6829 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6831 new_pos = start - 1;
6833 /* Find the previous word boundary */
6834 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6835 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6845 gtk_entry_delete_whitespace (GtkEntry *entry)
6847 GtkEntryPrivate *priv = entry->priv;
6848 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6849 PangoLogAttr *log_attrs;
6853 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6855 start = end = priv->current_pos;
6857 while (start > 0 && log_attrs[start-1].is_white)
6860 while (end < n_attrs && log_attrs[end].is_white)
6866 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6871 gtk_entry_select_word (GtkEntry *entry)
6873 GtkEntryPrivate *priv = entry->priv;
6874 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6875 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6877 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6881 gtk_entry_select_line (GtkEntry *entry)
6883 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6887 truncate_multiline (const gchar *text)
6892 text[length] && text[length] != '\n' && text[length] != '\r';
6899 paste_received (GtkClipboard *clipboard,
6903 GtkEntry *entry = GTK_ENTRY (data);
6904 GtkEditable *editable = GTK_EDITABLE (entry);
6905 GtkEntryPrivate *priv = entry->priv;
6907 if (priv->button == GDK_BUTTON_MIDDLE)
6909 gint pos, start, end;
6910 pos = priv->insert_pos;
6911 gtk_editable_get_selection_bounds (editable, &start, &end);
6912 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6913 gtk_editable_select_region (editable, pos, pos);
6918 gint pos, start, end;
6920 gboolean popup_completion;
6921 GtkEntryCompletion *completion;
6923 completion = gtk_entry_get_completion (entry);
6925 if (priv->truncate_multiline)
6926 length = truncate_multiline (text);
6928 /* only complete if the selection is at the end */
6929 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6930 MAX (priv->current_pos, priv->selection_bound));
6934 if (gtk_widget_get_mapped (completion->priv->popup_window))
6935 _gtk_entry_completion_popdown (completion);
6937 if (!popup_completion && completion->priv->changed_id > 0)
6938 g_signal_handler_block (entry, completion->priv->changed_id);
6941 begin_change (entry);
6942 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6943 gtk_editable_delete_text (editable, start, end);
6945 pos = priv->current_pos;
6946 gtk_editable_insert_text (editable, text, length, &pos);
6947 gtk_editable_set_position (editable, pos);
6951 !popup_completion && completion->priv->changed_id > 0)
6952 g_signal_handler_unblock (entry, completion->priv->changed_id);
6955 g_object_unref (entry);
6959 gtk_entry_paste (GtkEntry *entry,
6962 g_object_ref (entry);
6963 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6964 paste_received, entry);
6968 primary_get_cb (GtkClipboard *clipboard,
6969 GtkSelectionData *selection_data,
6973 GtkEntry *entry = GTK_ENTRY (data);
6976 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6978 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6979 gtk_selection_data_set_text (selection_data, str, -1);
6985 primary_clear_cb (GtkClipboard *clipboard,
6988 GtkEntry *entry = GTK_ENTRY (data);
6989 GtkEntryPrivate *priv = entry->priv;
6991 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6995 gtk_entry_update_primary_selection (GtkEntry *entry)
6997 GtkTargetList *list;
6998 GtkTargetEntry *targets;
6999 GtkClipboard *clipboard;
7003 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
7006 list = gtk_target_list_new (NULL, 0);
7007 gtk_target_list_add_text_targets (list, 0);
7009 targets = gtk_target_table_new_from_list (list, &n_targets);
7011 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
7013 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
7015 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
7016 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
7017 primary_clear_cb (clipboard, entry);
7021 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
7022 gtk_clipboard_clear (clipboard);
7025 gtk_target_table_free (targets, n_targets);
7026 gtk_target_list_unref (list);
7030 gtk_entry_clear (GtkEntry *entry,
7031 GtkEntryIconPosition icon_pos)
7033 GtkEntryPrivate *priv = entry->priv;
7034 EntryIconInfo *icon_info = priv->icons[icon_pos];
7035 GtkImageType storage_type;
7037 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
7040 g_object_freeze_notify (G_OBJECT (entry));
7042 /* Explicitly check, as the pointer may become invalidated
7043 * during destruction.
7045 if (GDK_IS_WINDOW (icon_info->window))
7046 gdk_window_hide (icon_info->window);
7048 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
7050 switch (storage_type)
7052 case GTK_IMAGE_PIXBUF:
7053 g_object_notify (G_OBJECT (entry),
7054 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
7057 case GTK_IMAGE_STOCK:
7058 g_object_notify (G_OBJECT (entry),
7059 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
7062 case GTK_IMAGE_ICON_NAME:
7063 g_object_notify (G_OBJECT (entry),
7064 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
7067 case GTK_IMAGE_GICON:
7068 g_object_notify (G_OBJECT (entry),
7069 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
7073 g_assert_not_reached ();
7077 _gtk_icon_helper_clear (icon_info->icon_helper);
7079 g_object_notify (G_OBJECT (entry),
7080 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
7082 g_object_thaw_notify (G_OBJECT (entry));
7086 gtk_entry_ensure_pixbuf (GtkEntry *entry,
7087 GtkEntryIconPosition icon_pos)
7089 GtkEntryPrivate *priv = entry->priv;
7090 EntryIconInfo *icon_info = priv->icons[icon_pos];
7091 GtkStyleContext *context;
7094 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
7095 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
7097 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
7100 gtk_style_context_restore (context);
7111 * Creates a new entry.
7113 * Return value: a new #GtkEntry.
7116 gtk_entry_new (void)
7118 return g_object_new (GTK_TYPE_ENTRY, NULL);
7122 * gtk_entry_new_with_buffer:
7123 * @buffer: The buffer to use for the new #GtkEntry.
7125 * Creates a new entry with the specified text buffer.
7127 * Return value: a new #GtkEntry
7132 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
7134 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
7135 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
7138 static GtkEntryBuffer*
7139 get_buffer (GtkEntry *entry)
7141 GtkEntryPrivate *priv = entry->priv;
7143 if (priv->buffer == NULL)
7145 GtkEntryBuffer *buffer;
7146 buffer = gtk_entry_buffer_new (NULL, 0);
7147 gtk_entry_set_buffer (entry, buffer);
7148 g_object_unref (buffer);
7151 return priv->buffer;
7155 * gtk_entry_get_buffer:
7156 * @entry: a #GtkEntry
7158 * Get the #GtkEntryBuffer object which holds the text for
7163 * Returns: (transfer none): A #GtkEntryBuffer object.
7166 gtk_entry_get_buffer (GtkEntry *entry)
7168 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7170 return get_buffer (entry);
7174 * gtk_entry_set_buffer:
7175 * @entry: a #GtkEntry
7176 * @buffer: a #GtkEntryBuffer
7178 * Set the #GtkEntryBuffer object which holds the text for
7184 gtk_entry_set_buffer (GtkEntry *entry,
7185 GtkEntryBuffer *buffer)
7187 GtkEntryPrivate *priv;
7190 g_return_if_fail (GTK_IS_ENTRY (entry));
7196 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
7197 g_object_ref (buffer);
7202 buffer_disconnect_signals (entry);
7203 g_object_unref (priv->buffer);
7206 priv->buffer = buffer;
7209 buffer_connect_signals (entry);
7211 obj = G_OBJECT (entry);
7212 g_object_freeze_notify (obj);
7213 g_object_notify (obj, "buffer");
7214 g_object_notify (obj, "text");
7215 g_object_notify (obj, "text-length");
7216 g_object_notify (obj, "max-length");
7217 g_object_notify (obj, "visibility");
7218 g_object_notify (obj, "invisible-char");
7219 g_object_notify (obj, "invisible-char-set");
7220 g_object_thaw_notify (obj);
7222 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7223 gtk_entry_recompute (entry);
7227 * gtk_entry_get_text_area:
7228 * @entry: a #GtkEntry
7229 * @text_area: (out): Return location for the text area.
7231 * Gets the area where the entry's text is drawn. This function is
7232 * useful when drawing something to the entry in a draw callback.
7234 * If the entry is not realized, @text_area is filled with zeros.
7236 * See also gtk_entry_get_icon_area().
7241 gtk_entry_get_text_area (GtkEntry *entry,
7242 GdkRectangle *text_area)
7244 GtkEntryPrivate *priv;
7246 g_return_if_fail (GTK_IS_ENTRY (entry));
7247 g_return_if_fail (text_area != NULL);
7251 if (priv->text_area)
7253 GtkAllocation allocation;
7256 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7257 gdk_window_get_position (priv->text_area, &x, &y);
7259 text_area->x = x - allocation.x;
7260 text_area->y = y - allocation.y;
7261 text_area->width = gdk_window_get_width (priv->text_area);
7262 text_area->height = gdk_window_get_height (priv->text_area);
7268 text_area->width = 0;
7269 text_area->height = 0;
7274 * gtk_entry_set_text:
7275 * @entry: a #GtkEntry
7276 * @text: the new text
7278 * Sets the text in the widget to the given
7279 * value, replacing the current contents.
7281 * See gtk_entry_buffer_set_text().
7284 gtk_entry_set_text (GtkEntry *entry,
7288 GtkEntryCompletion *completion;
7290 g_return_if_fail (GTK_IS_ENTRY (entry));
7291 g_return_if_fail (text != NULL);
7293 /* Actually setting the text will affect the cursor and selection;
7294 * if the contents don't actually change, this will look odd to the user.
7296 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7299 completion = gtk_entry_get_completion (entry);
7300 if (completion && completion->priv->changed_id > 0)
7301 g_signal_handler_block (entry, completion->priv->changed_id);
7303 begin_change (entry);
7304 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7306 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7309 if (completion && completion->priv->changed_id > 0)
7310 g_signal_handler_unblock (entry, completion->priv->changed_id);
7314 * gtk_entry_set_visibility:
7315 * @entry: a #GtkEntry
7316 * @visible: %TRUE if the contents of the entry are displayed
7319 * Sets whether the contents of the entry are visible or not.
7320 * When visibility is set to %FALSE, characters are displayed
7321 * as the invisible char, and will also appear that way when
7322 * the text in the entry widget is copied elsewhere.
7324 * By default, GTK+ picks the best invisible character available
7325 * in the current font, but it can be changed with
7326 * gtk_entry_set_invisible_char().
7328 * Note that you probably want to set #GtkEntry:input-purpose
7329 * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
7330 * inform input methods about the purpose of this entry,
7331 * in addition to setting visibility to %FALSE.
7334 gtk_entry_set_visibility (GtkEntry *entry,
7337 GtkEntryPrivate *priv;
7339 g_return_if_fail (GTK_IS_ENTRY (entry));
7343 visible = visible != FALSE;
7345 if (priv->visible != visible)
7347 priv->visible = visible;
7349 g_object_notify (G_OBJECT (entry), "visibility");
7350 gtk_entry_recompute (entry);
7355 * gtk_entry_get_visibility:
7356 * @entry: a #GtkEntry
7358 * Retrieves whether the text in @entry is visible. See
7359 * gtk_entry_set_visibility().
7361 * Return value: %TRUE if the text is currently visible
7364 gtk_entry_get_visibility (GtkEntry *entry)
7366 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7368 return entry->priv->visible;
7372 * gtk_entry_set_invisible_char:
7373 * @entry: a #GtkEntry
7374 * @ch: a Unicode character
7376 * Sets the character to use in place of the actual text when
7377 * gtk_entry_set_visibility() has been called to set text visibility
7378 * to %FALSE. i.e. this is the character used in "password mode" to
7379 * show the user how many characters have been typed. By default, GTK+
7380 * picks the best invisible char available in the current font. If you
7381 * set the invisible char to 0, then the user will get no feedback
7382 * at all; there will be no text on the screen as they type.
7385 gtk_entry_set_invisible_char (GtkEntry *entry,
7388 GtkEntryPrivate *priv;
7390 g_return_if_fail (GTK_IS_ENTRY (entry));
7394 if (!priv->invisible_char_set)
7396 priv->invisible_char_set = TRUE;
7397 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7400 if (ch == priv->invisible_char)
7403 priv->invisible_char = ch;
7404 g_object_notify (G_OBJECT (entry), "invisible-char");
7405 gtk_entry_recompute (entry);
7409 * gtk_entry_get_invisible_char:
7410 * @entry: a #GtkEntry
7412 * Retrieves the character displayed in place of the real characters
7413 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7415 * Return value: the current invisible char, or 0, if the entry does not
7416 * show invisible text at all.
7419 gtk_entry_get_invisible_char (GtkEntry *entry)
7421 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7423 return entry->priv->invisible_char;
7427 * gtk_entry_unset_invisible_char:
7428 * @entry: a #GtkEntry
7430 * Unsets the invisible char previously set with
7431 * gtk_entry_set_invisible_char(). So that the
7432 * default invisible char is used again.
7437 gtk_entry_unset_invisible_char (GtkEntry *entry)
7439 GtkEntryPrivate *priv;
7442 g_return_if_fail (GTK_IS_ENTRY (entry));
7446 if (!priv->invisible_char_set)
7449 priv->invisible_char_set = FALSE;
7450 ch = find_invisible_char (GTK_WIDGET (entry));
7452 if (priv->invisible_char != ch)
7454 priv->invisible_char = ch;
7455 g_object_notify (G_OBJECT (entry), "invisible-char");
7458 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7459 gtk_entry_recompute (entry);
7463 * gtk_entry_set_overwrite_mode:
7464 * @entry: a #GtkEntry
7465 * @overwrite: new value
7467 * Sets whether the text is overwritten when typing in the #GtkEntry.
7472 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7475 GtkEntryPrivate *priv = entry->priv;
7477 g_return_if_fail (GTK_IS_ENTRY (entry));
7479 if (priv->overwrite_mode == overwrite)
7482 gtk_entry_toggle_overwrite (entry);
7484 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7488 * gtk_entry_get_overwrite_mode:
7489 * @entry: a #GtkEntry
7491 * Gets the value set by gtk_entry_set_overwrite_mode().
7493 * Return value: whether the text is overwritten when typing.
7498 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7500 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7502 return entry->priv->overwrite_mode;
7506 * gtk_entry_get_text:
7507 * @entry: a #GtkEntry
7509 * Retrieves the contents of the entry widget.
7510 * See also gtk_editable_get_chars().
7512 * This is equivalent to:
7514 * <informalexample><programlisting>
7515 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7516 * </programlisting></informalexample>
7518 * Return value: a pointer to the contents of the widget as a
7519 * string. This string points to internally allocated
7520 * storage in the widget and must not be freed, modified or
7524 gtk_entry_get_text (GtkEntry *entry)
7526 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7528 return gtk_entry_buffer_get_text (get_buffer (entry));
7532 * gtk_entry_set_max_length:
7533 * @entry: a #GtkEntry
7534 * @max: the maximum length of the entry, or 0 for no maximum.
7535 * (other than the maximum length of entries.) The value passed in will
7536 * be clamped to the range 0-65536.
7538 * Sets the maximum allowed length of the contents of the widget. If
7539 * the current contents are longer than the given length, then they
7540 * will be truncated to fit.
7542 * This is equivalent to:
7544 * <informalexample><programlisting>
7545 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7546 * </programlisting></informalexample>
7549 gtk_entry_set_max_length (GtkEntry *entry,
7552 g_return_if_fail (GTK_IS_ENTRY (entry));
7553 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7557 * gtk_entry_get_max_length:
7558 * @entry: a #GtkEntry
7560 * Retrieves the maximum allowed length of the text in
7561 * @entry. See gtk_entry_set_max_length().
7563 * This is equivalent to:
7565 * <informalexample><programlisting>
7566 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7567 * </programlisting></informalexample>
7569 * Return value: the maximum allowed number of characters
7570 * in #GtkEntry, or 0 if there is no maximum.
7573 gtk_entry_get_max_length (GtkEntry *entry)
7575 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7577 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7581 * gtk_entry_get_text_length:
7582 * @entry: a #GtkEntry
7584 * Retrieves the current length of the text in
7587 * This is equivalent to:
7589 * <informalexample><programlisting>
7590 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7591 * </programlisting></informalexample>
7593 * Return value: the current number of characters
7594 * in #GtkEntry, or 0 if there are none.
7599 gtk_entry_get_text_length (GtkEntry *entry)
7601 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7603 return gtk_entry_buffer_get_length (get_buffer (entry));
7607 * gtk_entry_set_activates_default:
7608 * @entry: a #GtkEntry
7609 * @setting: %TRUE to activate window's default widget on Enter keypress
7611 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7612 * widget for the window containing the entry. This usually means that
7613 * the dialog box containing the entry will be closed, since the default
7614 * widget is usually one of the dialog buttons.
7616 * (For experts: if @setting is %TRUE, the entry calls
7617 * gtk_window_activate_default() on the window containing the entry, in
7618 * the default handler for the #GtkEntry::activate signal.)
7621 gtk_entry_set_activates_default (GtkEntry *entry,
7624 GtkEntryPrivate *priv;
7626 g_return_if_fail (GTK_IS_ENTRY (entry));
7630 setting = setting != FALSE;
7632 if (setting != priv->activates_default)
7634 priv->activates_default = setting;
7635 g_object_notify (G_OBJECT (entry), "activates-default");
7640 * gtk_entry_get_activates_default:
7641 * @entry: a #GtkEntry
7643 * Retrieves the value set by gtk_entry_set_activates_default().
7645 * Return value: %TRUE if the entry will activate the default widget
7648 gtk_entry_get_activates_default (GtkEntry *entry)
7650 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7652 return entry->priv->activates_default;
7656 * gtk_entry_set_width_chars:
7657 * @entry: a #GtkEntry
7658 * @n_chars: width in chars
7660 * Changes the size request of the entry to be about the right size
7661 * for @n_chars characters. Note that it changes the size
7662 * <emphasis>request</emphasis>, the size can still be affected by
7663 * how you pack the widget into containers. If @n_chars is -1, the
7664 * size reverts to the default entry size.
7667 gtk_entry_set_width_chars (GtkEntry *entry,
7670 GtkEntryPrivate *priv;
7672 g_return_if_fail (GTK_IS_ENTRY (entry));
7676 if (priv->width_chars != n_chars)
7678 priv->width_chars = n_chars;
7679 g_object_notify (G_OBJECT (entry), "width-chars");
7680 gtk_widget_queue_resize (GTK_WIDGET (entry));
7685 * gtk_entry_get_width_chars:
7686 * @entry: a #GtkEntry
7688 * Gets the value set by gtk_entry_set_width_chars().
7690 * Return value: number of chars to request space for, or negative if unset
7693 gtk_entry_get_width_chars (GtkEntry *entry)
7695 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7697 return entry->priv->width_chars;
7701 * gtk_entry_set_has_frame:
7702 * @entry: a #GtkEntry
7703 * @setting: new value
7705 * Sets whether the entry has a beveled frame around it.
7708 gtk_entry_set_has_frame (GtkEntry *entry,
7711 GtkEntryPrivate *priv;
7713 g_return_if_fail (GTK_IS_ENTRY (entry));
7717 setting = (setting != FALSE);
7719 if (priv->has_frame == setting)
7722 gtk_widget_queue_resize (GTK_WIDGET (entry));
7723 priv->has_frame = setting;
7724 g_object_notify (G_OBJECT (entry), "has-frame");
7728 * gtk_entry_get_has_frame:
7729 * @entry: a #GtkEntry
7731 * Gets the value set by gtk_entry_set_has_frame().
7733 * Return value: whether the entry has a beveled frame
7736 gtk_entry_get_has_frame (GtkEntry *entry)
7738 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7740 return entry->priv->has_frame;
7744 * gtk_entry_set_inner_border:
7745 * @entry: a #GtkEntry
7746 * @border: (allow-none): a #GtkBorder, or %NULL
7748 * Sets %entry's inner-border property to %border, or clears it if %NULL
7749 * is passed. The inner-border is the area around the entry's text, but
7752 * If set, this property overrides the inner-border style property.
7753 * Overriding the style-provided border is useful when you want to do
7754 * in-place editing of some text in a canvas or list widget, where
7755 * pixel-exact positioning of the entry is important.
7759 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7760 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7761 * this function is ignored by #GtkEntry.
7764 gtk_entry_set_inner_border (GtkEntry *entry,
7765 const GtkBorder *border)
7767 g_return_if_fail (GTK_IS_ENTRY (entry));
7769 gtk_entry_do_set_inner_border (entry, border);
7773 * gtk_entry_get_inner_border:
7774 * @entry: a #GtkEntry
7776 * This function returns the entry's #GtkEntry:inner-border property. See
7777 * gtk_entry_set_inner_border() for more information.
7779 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7783 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7784 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7785 * this function is ignored by #GtkEntry.
7788 gtk_entry_get_inner_border (GtkEntry *entry)
7790 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7792 return gtk_entry_do_get_inner_border (entry);
7796 * gtk_entry_get_layout:
7797 * @entry: a #GtkEntry
7799 * Gets the #PangoLayout used to display the entry.
7800 * The layout is useful to e.g. convert text positions to
7801 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7802 * The returned layout is owned by the entry and must not be
7803 * modified or freed by the caller.
7805 * Keep in mind that the layout text may contain a preedit string, so
7806 * gtk_entry_layout_index_to_text_index() and
7807 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7808 * indices in the layout to byte indices in the entry contents.
7810 * Return value: (transfer none): the #PangoLayout for this entry
7813 gtk_entry_get_layout (GtkEntry *entry)
7815 PangoLayout *layout;
7817 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7819 layout = gtk_entry_ensure_layout (entry, TRUE);
7826 * gtk_entry_layout_index_to_text_index:
7827 * @entry: a #GtkEntry
7828 * @layout_index: byte index into the entry layout text
7830 * Converts from a position in the entry contents (returned
7831 * by gtk_entry_get_text()) to a position in the
7832 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7833 * with text retrieved via pango_layout_get_text()).
7835 * Return value: byte index into the entry contents
7838 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7841 GtkEntryPrivate *priv;
7842 PangoLayout *layout;
7846 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7850 layout = gtk_entry_ensure_layout (entry, TRUE);
7851 text = pango_layout_get_text (layout);
7852 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7854 if (layout_index >= cursor_index && priv->preedit_length)
7856 if (layout_index >= cursor_index + priv->preedit_length)
7857 layout_index -= priv->preedit_length;
7859 layout_index = cursor_index;
7862 return layout_index;
7866 * gtk_entry_text_index_to_layout_index:
7867 * @entry: a #GtkEntry
7868 * @text_index: byte index into the entry contents
7870 * Converts from a position in the entry's #PangoLayout (returned by
7871 * gtk_entry_get_layout()) to a position in the entry contents
7872 * (returned by gtk_entry_get_text()).
7874 * Return value: byte index into the entry layout text
7877 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7880 GtkEntryPrivate *priv;
7881 PangoLayout *layout;
7885 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7889 layout = gtk_entry_ensure_layout (entry, TRUE);
7890 text = pango_layout_get_text (layout);
7891 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7893 if (text_index > cursor_index)
7894 text_index += priv->preedit_length;
7900 * gtk_entry_get_layout_offsets:
7901 * @entry: a #GtkEntry
7902 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7903 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7906 * Obtains the position of the #PangoLayout used to render text
7907 * in the entry, in widget coordinates. Useful if you want to line
7908 * up the text in an entry with some other text, e.g. when using the
7909 * entry to implement editable cells in a sheet widget.
7911 * Also useful to convert mouse events into coordinates inside the
7912 * #PangoLayout, e.g. to take some action if some part of the entry text
7915 * Note that as the user scrolls around in the entry the offsets will
7916 * change; you'll need to connect to the "notify::scroll-offset"
7917 * signal to track this. Remember when using the #PangoLayout
7918 * functions you need to convert to and from pixels using
7919 * PANGO_PIXELS() or #PANGO_SCALE.
7921 * Keep in mind that the layout text may contain a preedit string, so
7922 * gtk_entry_layout_index_to_text_index() and
7923 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7924 * indices in the layout to byte indices in the entry contents.
7927 gtk_entry_get_layout_offsets (GtkEntry *entry,
7931 gint text_area_x, text_area_y;
7933 g_return_if_fail (GTK_IS_ENTRY (entry));
7935 /* this gets coords relative to text area */
7936 get_layout_position (entry, x, y);
7938 /* convert to widget coords */
7939 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7950 * gtk_entry_set_alignment:
7951 * @entry: a #GtkEntry
7952 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7953 * Reversed for RTL layouts
7955 * Sets the alignment for the contents of the entry. This controls
7956 * the horizontal positioning of the contents when the displayed
7957 * text is shorter than the width of the entry.
7962 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7964 GtkEntryPrivate *priv;
7966 g_return_if_fail (GTK_IS_ENTRY (entry));
7972 else if (xalign > 1.0)
7975 if (xalign != priv->xalign)
7977 priv->xalign = xalign;
7979 gtk_entry_recompute (entry);
7981 g_object_notify (G_OBJECT (entry), "xalign");
7986 * gtk_entry_get_alignment:
7987 * @entry: a #GtkEntry
7989 * Gets the value set by gtk_entry_set_alignment().
7991 * Return value: the alignment
7996 gtk_entry_get_alignment (GtkEntry *entry)
7998 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
8000 return entry->priv->xalign;
8004 * gtk_entry_set_icon_from_pixbuf:
8005 * @entry: a #GtkEntry
8006 * @icon_pos: Icon position
8007 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
8009 * Sets the icon shown in the specified position using a pixbuf.
8011 * If @pixbuf is %NULL, no icon will be shown in the specified position.
8016 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
8017 GtkEntryIconPosition icon_pos,
8020 GtkEntryPrivate *priv;
8021 EntryIconInfo *icon_info;
8023 g_return_if_fail (GTK_IS_ENTRY (entry));
8024 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8028 if ((icon_info = priv->icons[icon_pos]) == NULL)
8029 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8031 g_object_freeze_notify (G_OBJECT (entry));
8034 g_object_ref (pixbuf);
8036 gtk_entry_clear (entry, icon_pos);
8040 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
8041 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
8042 GTK_ICON_SIZE_MENU);
8044 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8046 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
8047 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8051 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
8052 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8055 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8056 gdk_window_show_unraised (icon_info->window);
8058 g_object_unref (pixbuf);
8061 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8062 gtk_widget_queue_resize (GTK_WIDGET (entry));
8064 g_object_thaw_notify (G_OBJECT (entry));
8068 * gtk_entry_set_icon_from_stock:
8069 * @entry: A #GtkEntry
8070 * @icon_pos: Icon position
8071 * @stock_id: (allow-none): The name of the stock item, or %NULL
8073 * Sets the icon shown in the entry at the specified position from
8076 * If @stock_id is %NULL, no icon will be shown in the specified position.
8081 gtk_entry_set_icon_from_stock (GtkEntry *entry,
8082 GtkEntryIconPosition icon_pos,
8083 const gchar *stock_id)
8085 GtkEntryPrivate *priv;
8086 EntryIconInfo *icon_info;
8089 g_return_if_fail (GTK_IS_ENTRY (entry));
8090 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8094 if ((icon_info = priv->icons[icon_pos]) == NULL)
8095 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8097 g_object_freeze_notify (G_OBJECT (entry));
8099 /* need to dup before clearing */
8100 new_id = g_strdup (stock_id);
8102 gtk_entry_clear (entry, icon_pos);
8106 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
8108 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8110 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
8111 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8115 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
8116 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8119 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8120 gdk_window_show_unraised (icon_info->window);
8125 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8126 gtk_widget_queue_resize (GTK_WIDGET (entry));
8128 g_object_thaw_notify (G_OBJECT (entry));
8132 * gtk_entry_set_icon_from_icon_name:
8133 * @entry: A #GtkEntry
8134 * @icon_pos: The position at which to set the icon
8135 * @icon_name: (allow-none): An icon name, or %NULL
8137 * Sets the icon shown in the entry at the specified position
8138 * from the current icon theme.
8140 * If the icon name isn't known, a "broken image" icon will be displayed
8143 * If @icon_name is %NULL, no icon will be shown in the specified position.
8148 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
8149 GtkEntryIconPosition icon_pos,
8150 const gchar *icon_name)
8152 GtkEntryPrivate *priv;
8153 EntryIconInfo *icon_info;
8156 g_return_if_fail (GTK_IS_ENTRY (entry));
8157 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8161 if ((icon_info = priv->icons[icon_pos]) == NULL)
8162 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8164 g_object_freeze_notify (G_OBJECT (entry));
8166 /* need to dup before clearing */
8167 new_name = g_strdup (icon_name);
8169 gtk_entry_clear (entry, icon_pos);
8171 if (new_name != NULL)
8173 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
8175 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8177 g_object_notify (G_OBJECT (entry), "primary-icon-name");
8178 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8182 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
8183 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8186 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8187 gdk_window_show_unraised (icon_info->window);
8192 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8193 gtk_widget_queue_resize (GTK_WIDGET (entry));
8195 g_object_thaw_notify (G_OBJECT (entry));
8199 * gtk_entry_set_icon_from_gicon:
8200 * @entry: A #GtkEntry
8201 * @icon_pos: The position at which to set the icon
8202 * @icon: (allow-none): The icon to set, or %NULL
8204 * Sets the icon shown in the entry at the specified position
8205 * from the current icon theme.
8206 * If the icon isn't known, a "broken image" icon will be displayed
8209 * If @icon is %NULL, no icon will be shown in the specified position.
8214 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
8215 GtkEntryIconPosition icon_pos,
8218 GtkEntryPrivate *priv;
8219 EntryIconInfo *icon_info;
8221 g_return_if_fail (GTK_IS_ENTRY (entry));
8222 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8226 if ((icon_info = priv->icons[icon_pos]) == NULL)
8227 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8229 g_object_freeze_notify (G_OBJECT (entry));
8231 /* need to ref before clearing */
8233 g_object_ref (icon);
8235 gtk_entry_clear (entry, icon_pos);
8239 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
8241 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8243 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8244 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8248 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8249 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8252 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8253 gdk_window_show_unraised (icon_info->window);
8255 g_object_unref (icon);
8258 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8259 gtk_widget_queue_resize (GTK_WIDGET (entry));
8261 g_object_thaw_notify (G_OBJECT (entry));
8265 * gtk_entry_set_icon_activatable:
8266 * @entry: A #GtkEntry
8267 * @icon_pos: Icon position
8268 * @activatable: %TRUE if the icon should be activatable
8270 * Sets whether the icon is activatable.
8275 gtk_entry_set_icon_activatable (GtkEntry *entry,
8276 GtkEntryIconPosition icon_pos,
8277 gboolean activatable)
8279 GtkEntryPrivate *priv;
8280 EntryIconInfo *icon_info;
8282 g_return_if_fail (GTK_IS_ENTRY (entry));
8283 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8287 if ((icon_info = priv->icons[icon_pos]) == NULL)
8288 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8290 activatable = activatable != FALSE;
8292 if (icon_info->nonactivatable != !activatable)
8294 icon_info->nonactivatable = !activatable;
8296 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8297 update_cursors (GTK_WIDGET (entry));
8299 g_object_notify (G_OBJECT (entry),
8300 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8305 * gtk_entry_get_icon_activatable:
8306 * @entry: a #GtkEntry
8307 * @icon_pos: Icon position
8309 * Returns whether the icon is activatable.
8311 * Returns: %TRUE if the icon is activatable.
8316 gtk_entry_get_icon_activatable (GtkEntry *entry,
8317 GtkEntryIconPosition icon_pos)
8319 GtkEntryPrivate *priv;
8320 EntryIconInfo *icon_info;
8322 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8323 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8326 icon_info = priv->icons[icon_pos];
8328 return (!icon_info || !icon_info->nonactivatable);
8332 * gtk_entry_get_icon_pixbuf:
8333 * @entry: A #GtkEntry
8334 * @icon_pos: Icon position
8336 * Retrieves the image used for the icon.
8338 * Unlike the other methods of setting and getting icon data, this
8339 * method will work regardless of whether the icon was set using a
8340 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8342 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8343 * set for this position.
8348 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8349 GtkEntryIconPosition icon_pos)
8351 GtkEntryPrivate *priv;
8352 EntryIconInfo *icon_info;
8355 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8356 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8360 icon_info = priv->icons[icon_pos];
8365 /* HACK: unfortunately this is transfer none, so we need to return
8366 * the icon helper's cache ref directly.
8368 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
8370 g_object_unref (pixbuf);
8376 * gtk_entry_get_icon_gicon:
8377 * @entry: A #GtkEntry
8378 * @icon_pos: Icon position
8380 * Retrieves the #GIcon 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 * stock, pixbuf, or icon name).
8384 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8385 * or if the icon is not a #GIcon
8390 gtk_entry_get_icon_gicon (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_peek_gicon (icon_info->icon_helper);
8409 * gtk_entry_get_icon_stock:
8410 * @entry: A #GtkEntry
8411 * @icon_pos: Icon position
8413 * Retrieves the stock id 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, icon name or gicon).
8417 * Returns: A stock id, or %NULL if no icon is set or if the icon
8418 * wasn't set from a stock id
8423 gtk_entry_get_icon_stock (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_stock_id (icon_info->icon_helper);
8442 * gtk_entry_get_icon_name:
8443 * @entry: A #GtkEntry
8444 * @icon_pos: Icon position
8446 * Retrieves the icon name used for the icon, or %NULL if there is
8447 * no icon or if the icon was set by some other method (e.g., by
8448 * pixbuf, stock or gicon).
8450 * Returns: An icon name, or %NULL if no icon is set or if the icon
8451 * wasn't set from an icon name
8456 gtk_entry_get_icon_name (GtkEntry *entry,
8457 GtkEntryIconPosition icon_pos)
8459 GtkEntryPrivate *priv;
8460 EntryIconInfo *icon_info;
8462 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8463 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8466 icon_info = priv->icons[icon_pos];
8471 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8475 * gtk_entry_set_icon_sensitive:
8476 * @entry: A #GtkEntry
8477 * @icon_pos: Icon position
8478 * @sensitive: Specifies whether the icon should appear
8479 * sensitive or insensitive
8481 * Sets the sensitivity for the specified icon.
8486 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8487 GtkEntryIconPosition icon_pos,
8490 GtkEntryPrivate *priv;
8491 EntryIconInfo *icon_info;
8493 g_return_if_fail (GTK_IS_ENTRY (entry));
8494 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8498 if ((icon_info = priv->icons[icon_pos]) == NULL)
8499 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8501 if (icon_info->insensitive != !sensitive)
8503 icon_info->insensitive = !sensitive;
8505 icon_info->pressed = FALSE;
8506 icon_info->prelight = FALSE;
8508 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8509 update_cursors (GTK_WIDGET (entry));
8511 gtk_widget_queue_draw (GTK_WIDGET (entry));
8513 g_object_notify (G_OBJECT (entry),
8514 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8519 * gtk_entry_get_icon_sensitive:
8520 * @entry: a #GtkEntry
8521 * @icon_pos: Icon position
8523 * Returns whether the icon appears sensitive or insensitive.
8525 * Returns: %TRUE if the icon is sensitive.
8530 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8531 GtkEntryIconPosition icon_pos)
8533 GtkEntryPrivate *priv;
8534 EntryIconInfo *icon_info;
8536 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8537 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8541 icon_info = priv->icons[icon_pos];
8543 return (!icon_info || !icon_info->insensitive);
8548 * gtk_entry_get_icon_storage_type:
8549 * @entry: a #GtkEntry
8550 * @icon_pos: Icon position
8552 * Gets the type of representation being used by the icon
8553 * to store image data. If the icon has no image data,
8554 * the return value will be %GTK_IMAGE_EMPTY.
8556 * Return value: image representation being used
8561 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8562 GtkEntryIconPosition icon_pos)
8564 GtkEntryPrivate *priv;
8565 EntryIconInfo *icon_info;
8567 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8568 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8572 icon_info = priv->icons[icon_pos];
8575 return GTK_IMAGE_EMPTY;
8577 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8581 * gtk_entry_get_icon_at_pos:
8582 * @entry: a #GtkEntry
8583 * @x: the x coordinate of the position to find
8584 * @y: the y coordinate of the position to find
8586 * Finds the icon at the given position and return its index. The
8587 * position's coordinates are relative to the @entry's top left corner.
8588 * If @x, @y doesn't lie inside an icon, -1 is returned.
8589 * This function is intended for use in a #GtkWidget::query-tooltip
8592 * Returns: the index of the icon at the given position, or -1
8597 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8601 GtkAllocation primary;
8602 GtkAllocation secondary;
8603 gint frame_x, frame_y;
8605 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8607 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8611 get_icon_allocations (entry, &primary, &secondary);
8613 if (primary.x <= x && x < primary.x + primary.width &&
8614 primary.y <= y && y < primary.y + primary.height)
8615 return GTK_ENTRY_ICON_PRIMARY;
8617 if (secondary.x <= x && x < secondary.x + secondary.width &&
8618 secondary.y <= y && y < secondary.y + secondary.height)
8619 return GTK_ENTRY_ICON_SECONDARY;
8625 * gtk_entry_set_icon_drag_source:
8626 * @entry: a #GtkEntry
8627 * @icon_pos: icon position
8628 * @target_list: the targets (data formats) in which the data can be provided
8629 * @actions: a bitmask of the allowed drag actions
8631 * Sets up the icon at the given position so that GTK+ will start a drag
8632 * operation when the user clicks and drags the icon.
8634 * To handle the drag operation, you need to connect to the usual
8635 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8636 * signal, and use gtk_entry_get_current_icon_drag_source() in
8637 * your signal handler to find out if the drag was started from
8640 * By default, GTK+ uses the icon as the drag icon. You can use the
8641 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8642 * have to use g_signal_connect_after() to ensure that your signal handler
8643 * gets executed after the default handler.
8648 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8649 GtkEntryIconPosition icon_pos,
8650 GtkTargetList *target_list,
8651 GdkDragAction actions)
8653 GtkEntryPrivate *priv;
8654 EntryIconInfo *icon_info;
8656 g_return_if_fail (GTK_IS_ENTRY (entry));
8657 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8661 if ((icon_info = priv->icons[icon_pos]) == NULL)
8662 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8664 if (icon_info->target_list)
8665 gtk_target_list_unref (icon_info->target_list);
8666 icon_info->target_list = target_list;
8667 if (icon_info->target_list)
8668 gtk_target_list_ref (icon_info->target_list);
8670 icon_info->actions = actions;
8674 * gtk_entry_get_current_icon_drag_source:
8675 * @entry: a #GtkIconEntry
8677 * Returns the index of the icon which is the source of the current
8678 * DND operation, or -1.
8680 * This function is meant to be used in a #GtkWidget::drag-data-get
8683 * Returns: index of the icon which is the source of the current
8684 * DND operation, or -1.
8689 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8691 GtkEntryPrivate *priv;
8692 EntryIconInfo *icon_info = NULL;
8695 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8699 for (i = 0; i < MAX_ICONS; i++)
8701 if ((icon_info = priv->icons[i]))
8703 if (icon_info->in_drag)
8712 * gtk_entry_get_icon_area:
8713 * @entry: A #GtkEntry
8714 * @icon_pos: Icon position
8715 * @icon_area: (out): Return location for the icon's area
8717 * Gets the area where entry's icon at @icon_pos is drawn.
8718 * This function is useful when drawing something to the
8719 * entry in a draw callback.
8721 * If the entry is not realized or has no icon at the given position,
8722 * @icon_area is filled with zeros.
8724 * See also gtk_entry_get_text_area()
8729 gtk_entry_get_icon_area (GtkEntry *entry,
8730 GtkEntryIconPosition icon_pos,
8731 GdkRectangle *icon_area)
8733 GtkEntryPrivate *priv;
8734 EntryIconInfo *icon_info;
8736 g_return_if_fail (GTK_IS_ENTRY (entry));
8737 g_return_if_fail (icon_area != NULL);
8741 icon_info = priv->icons[icon_pos];
8745 GtkAllocation primary;
8746 GtkAllocation secondary;
8748 get_icon_allocations (entry, &primary, &secondary);
8750 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8751 *icon_area = primary;
8753 *icon_area = secondary;
8759 icon_area->width = 0;
8760 icon_area->height = 0;
8765 ensure_has_tooltip (GtkEntry *entry)
8767 GtkEntryPrivate *priv;
8768 EntryIconInfo *icon_info;
8770 gboolean has_tooltip = FALSE;
8774 for (i = 0; i < MAX_ICONS; i++)
8776 if ((icon_info = priv->icons[i]) != NULL)
8778 if (icon_info->tooltip != NULL)
8786 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8790 * gtk_entry_get_icon_tooltip_text:
8791 * @entry: a #GtkEntry
8792 * @icon_pos: the icon position
8794 * Gets the contents of the tooltip on the icon at the specified
8795 * position in @entry.
8797 * Returns: the tooltip text, or %NULL. Free the returned string
8798 * with g_free() when done.
8803 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8804 GtkEntryIconPosition icon_pos)
8806 GtkEntryPrivate *priv;
8807 EntryIconInfo *icon_info;
8810 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8811 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8815 icon_info = priv->icons[icon_pos];
8820 if (icon_info->tooltip &&
8821 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8822 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8828 * gtk_entry_set_icon_tooltip_text:
8829 * @entry: a #GtkEntry
8830 * @icon_pos: the icon position
8831 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8833 * Sets @tooltip as the contents of the tooltip for the icon
8834 * at the specified position.
8836 * Use %NULL for @tooltip to remove an existing tooltip.
8838 * See also gtk_widget_set_tooltip_text() and
8839 * gtk_entry_set_icon_tooltip_markup().
8844 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8845 GtkEntryIconPosition icon_pos,
8846 const gchar *tooltip)
8848 GtkEntryPrivate *priv;
8849 EntryIconInfo *icon_info;
8851 g_return_if_fail (GTK_IS_ENTRY (entry));
8852 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8856 if ((icon_info = priv->icons[icon_pos]) == NULL)
8857 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8859 if (icon_info->tooltip)
8860 g_free (icon_info->tooltip);
8862 /* Treat an empty string as a NULL string,
8863 * because an empty string would be useless for a tooltip:
8865 if (tooltip && tooltip[0] == '\0')
8868 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8870 ensure_has_tooltip (entry);
8872 g_object_notify (G_OBJECT (entry),
8873 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-tooltip-text" : "secondary-icon-tooltip-text");
8877 * gtk_entry_get_icon_tooltip_markup:
8878 * @entry: a #GtkEntry
8879 * @icon_pos: the icon position
8881 * Gets the contents of the tooltip on the icon at the specified
8882 * position in @entry.
8884 * Returns: the tooltip text, or %NULL. Free the returned string
8885 * with g_free() when done.
8890 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8891 GtkEntryIconPosition icon_pos)
8893 GtkEntryPrivate *priv;
8894 EntryIconInfo *icon_info;
8896 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8897 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8901 icon_info = priv->icons[icon_pos];
8906 return g_strdup (icon_info->tooltip);
8910 * gtk_entry_set_icon_tooltip_markup:
8911 * @entry: a #GtkEntry
8912 * @icon_pos: the icon position
8913 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8915 * Sets @tooltip as the contents of the tooltip for the icon at
8916 * the specified position. @tooltip is assumed to be marked up with
8917 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8919 * Use %NULL for @tooltip to remove an existing tooltip.
8921 * See also gtk_widget_set_tooltip_markup() and
8922 * gtk_entry_set_icon_tooltip_text().
8927 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8928 GtkEntryIconPosition icon_pos,
8929 const gchar *tooltip)
8931 GtkEntryPrivate *priv;
8932 EntryIconInfo *icon_info;
8934 g_return_if_fail (GTK_IS_ENTRY (entry));
8935 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8939 if ((icon_info = priv->icons[icon_pos]) == NULL)
8940 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8942 if (icon_info->tooltip)
8943 g_free (icon_info->tooltip);
8945 /* Treat an empty string as a NULL string,
8946 * because an empty string would be useless for a tooltip:
8948 if (tooltip && tooltip[0] == '\0')
8951 icon_info->tooltip = g_strdup (tooltip);
8953 ensure_has_tooltip (entry);
8957 gtk_entry_query_tooltip (GtkWidget *widget,
8960 gboolean keyboard_tip,
8961 GtkTooltip *tooltip)
8964 GtkEntryPrivate *priv;
8965 EntryIconInfo *icon_info;
8968 entry = GTK_ENTRY (widget);
8973 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8976 if ((icon_info = priv->icons[icon_pos]) != NULL)
8978 if (icon_info->tooltip)
8980 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8989 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8996 /* Quick hack of a popup menu
8999 activate_cb (GtkWidget *menuitem,
9002 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
9003 g_signal_emit_by_name (entry, signal);
9008 gtk_entry_mnemonic_activate (GtkWidget *widget,
9009 gboolean group_cycling)
9011 gtk_widget_grab_focus (widget);
9016 gtk_entry_grab_notify (GtkWidget *widget,
9017 gboolean was_grabbed)
9019 GtkEntryPrivate *priv;
9021 priv = GTK_ENTRY (widget)->priv;
9024 gtk_widget_device_is_shadowed (widget, priv->device))
9026 /* Unset button so we don't expect
9027 * a button release anymore
9030 priv->device = NULL;
9031 priv->in_drag = FALSE;
9036 append_action_signal (GtkEntry *entry,
9038 const gchar *stock_id,
9039 const gchar *signal,
9042 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
9044 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
9045 g_signal_connect (menuitem, "activate",
9046 G_CALLBACK (activate_cb), entry);
9048 gtk_widget_set_sensitive (menuitem, sensitive);
9050 gtk_widget_show (menuitem);
9051 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
9055 popup_menu_detach (GtkWidget *attach_widget,
9058 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
9059 GtkEntryPrivate *priv_attach = entry_attach->priv;
9061 priv_attach->popup_menu = NULL;
9065 popup_position_func (GtkMenu *menu,
9071 GtkEntry *entry = GTK_ENTRY (user_data);
9072 GtkEntryPrivate *priv = entry->priv;
9073 GtkWidget *widget = GTK_WIDGET (entry);
9075 GtkRequisition menu_req;
9076 GdkRectangle monitor;
9078 gint monitor_num, strong_x, height;
9080 g_return_if_fail (gtk_widget_get_realized (widget));
9082 gdk_window_get_origin (priv->text_area, x, y);
9084 screen = gtk_widget_get_screen (widget);
9085 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
9086 if (monitor_num < 0)
9088 gtk_menu_set_monitor (menu, monitor_num);
9090 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
9091 gtk_widget_get_preferred_size (priv->popup_menu,
9093 height = gdk_window_get_height (priv->text_area);
9094 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
9095 _gtk_entry_get_borders (entry, &borders);
9097 *x += borders.left + strong_x - priv->scroll_offset;
9098 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
9099 *x -= menu_req.width;
9101 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
9103 else if ((*y - menu_req.height) >= monitor.y)
9104 *y -= menu_req.height;
9105 else if (monitor.y + monitor.height - (*y + height) > *y)
9108 *y -= menu_req.height;
9114 unichar_chosen_func (const char *text,
9117 GtkEntry *entry = GTK_ENTRY (data);
9118 GtkEntryPrivate *priv = entry->priv;
9121 gtk_entry_enter_text (entry, text);
9133 popup_targets_received (GtkClipboard *clipboard,
9134 GtkSelectionData *data,
9137 PopupInfo *info = user_data;
9138 GtkEntry *entry = info->entry;
9139 GtkEntryPrivate *info_entry_priv = entry->priv;
9141 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
9144 gboolean clipboard_contains_text;
9145 GtkWidget *menuitem;
9147 gboolean show_input_method_menu;
9148 gboolean show_unicode_menu;
9150 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
9151 if (info_entry_priv->popup_menu)
9152 gtk_widget_destroy (info_entry_priv->popup_menu);
9154 info_entry_priv->popup_menu = gtk_menu_new ();
9156 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
9160 mode = gtk_entry_get_display_mode (entry);
9161 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
9162 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
9163 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9165 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
9166 mode == DISPLAY_NORMAL &&
9167 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9169 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
9170 info_entry_priv->editable && clipboard_contains_text);
9172 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
9173 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
9174 g_signal_connect_swapped (menuitem, "activate",
9175 G_CALLBACK (gtk_entry_delete_cb), entry);
9176 gtk_widget_show (menuitem);
9177 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9179 menuitem = gtk_separator_menu_item_new ();
9180 gtk_widget_show (menuitem);
9181 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9183 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
9184 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
9185 g_signal_connect_swapped (menuitem, "activate",
9186 G_CALLBACK (gtk_entry_select_all), entry);
9187 gtk_widget_show (menuitem);
9188 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9190 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
9191 "gtk-show-input-method-menu", &show_input_method_menu,
9192 "gtk-show-unicode-menu", &show_unicode_menu,
9195 if (show_input_method_menu || show_unicode_menu)
9197 menuitem = gtk_separator_menu_item_new ();
9198 gtk_widget_show (menuitem);
9199 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9202 if (show_input_method_menu)
9204 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
9205 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9206 gtk_widget_show (menuitem);
9207 submenu = gtk_menu_new ();
9208 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9210 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9212 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
9213 GTK_MENU_SHELL (submenu));
9216 if (show_unicode_menu)
9218 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
9219 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9220 gtk_widget_show (menuitem);
9222 submenu = gtk_menu_new ();
9223 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9224 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9226 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
9227 unichar_chosen_func,
9231 g_signal_emit (entry,
9232 signals[POPULATE_POPUP],
9234 info_entry_priv->popup_menu);
9238 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
9239 info->device, NULL, NULL, NULL, NULL, NULL,
9240 info->button, info->time);
9243 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
9244 popup_position_func, entry,
9245 0, gtk_get_current_event_time ());
9246 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9250 g_object_unref (entry);
9251 g_slice_free (PopupInfo, info);
9255 gtk_entry_do_popup (GtkEntry *entry,
9256 GdkEventButton *event)
9258 PopupInfo *info = g_slice_new (PopupInfo);
9260 /* In order to know what entries we should make sensitive, we
9261 * ask for the current targets of the clipboard, and when
9262 * we get them, then we actually pop up the menu.
9264 info->entry = g_object_ref (entry);
9268 info->button = event->button;
9269 info->time = event->time;
9270 info->device = event->device;
9275 info->time = gtk_get_current_event_time ();
9276 info->device = NULL;
9279 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9280 gdk_atom_intern_static_string ("TARGETS"),
9281 popup_targets_received,
9286 gtk_entry_popup_menu (GtkWidget *widget)
9288 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9293 activate_bubble_cb (GtkWidget *item,
9296 const gchar *signal = g_object_get_data (G_OBJECT (item), "gtk-signal");
9297 g_signal_emit_by_name (entry, signal);
9298 _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (entry->priv->selection_bubble));
9302 append_bubble_action (GtkEntry *entry,
9304 const gchar *stock_id,
9305 const gchar *signal,
9308 GtkToolItem *item = gtk_tool_button_new_from_stock (stock_id);
9309 g_object_set_data (G_OBJECT (item), I_("gtk-signal"), (char *)signal);
9310 g_signal_connect (item, "clicked", G_CALLBACK (activate_bubble_cb), entry);
9311 gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive);
9312 gtk_widget_show (GTK_WIDGET (item));
9313 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
9317 bubble_targets_received (GtkClipboard *clipboard,
9318 GtkSelectionData *data,
9321 GtkEntry *entry = user_data;
9322 GtkEntryPrivate *priv = entry->priv;
9323 cairo_rectangle_int_t rect;
9324 GtkAllocation allocation;
9325 gint start_x, end_x;
9326 gboolean has_selection;
9327 gboolean has_clipboard;
9331 has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
9333 if (!has_selection && !priv->editable)
9335 priv->selection_bubble_timeout_id = 0;
9339 if (priv->selection_bubble)
9340 gtk_widget_destroy (priv->selection_bubble);
9342 priv->selection_bubble = _gtk_bubble_window_new ();
9343 toolbar = GTK_WIDGET (gtk_toolbar_new ());
9344 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT);
9345 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
9346 gtk_widget_show (toolbar);
9347 gtk_container_add (GTK_CONTAINER (priv->selection_bubble), toolbar);
9349 has_clipboard = gtk_selection_data_targets_include_text (data);
9350 mode = gtk_entry_get_display_mode (entry);
9352 append_bubble_action (entry, toolbar, GTK_STOCK_CUT, "cut-clipboard",
9353 priv->editable && has_selection && mode == DISPLAY_NORMAL);
9355 append_bubble_action (entry, toolbar, GTK_STOCK_COPY, "copy-clipboard",
9356 has_selection && mode == DISPLAY_NORMAL);
9358 append_bubble_action (entry, toolbar, GTK_STOCK_PASTE, "paste-clipboard",
9359 priv->editable && has_clipboard);
9361 if (priv->populate_all)
9362 g_signal_emit (entry, signals[POPULATE_POPUP], 0, toolbar);
9364 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
9366 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &start_x, NULL);
9368 start_x -= priv->scroll_offset;
9369 start_x = CLAMP (start_x, 0, gdk_window_get_width (priv->text_area));
9372 rect.height = gdk_window_get_height (priv->text_area);
9376 end_x = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
9377 end_x = CLAMP (end_x, 0, gdk_window_get_width (priv->text_area));
9379 rect.x = MIN (start_x, end_x);
9380 rect.width = MAX (start_x, end_x) - rect.x;
9388 _gtk_bubble_window_popup (GTK_BUBBLE_WINDOW (priv->selection_bubble),
9389 priv->text_area, &rect, GTK_POS_TOP);
9391 priv->selection_bubble_timeout_id = 0;
9395 gtk_entry_selection_bubble_popup_cb (gpointer user_data)
9397 GtkEntry *entry = user_data;
9399 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9400 gdk_atom_intern_static_string ("TARGETS"),
9401 bubble_targets_received,
9403 return G_SOURCE_REMOVE;
9407 gtk_entry_selection_bubble_popup_unset (GtkEntry *entry)
9409 GtkEntryPrivate *priv;
9413 if (priv->selection_bubble)
9414 _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
9416 if (priv->selection_bubble_timeout_id)
9418 g_source_remove (priv->selection_bubble_timeout_id);
9419 priv->selection_bubble_timeout_id = 0;
9424 gtk_entry_selection_bubble_popup_set (GtkEntry *entry)
9426 GtkEntryPrivate *priv;
9430 if (priv->selection_bubble_timeout_id)
9431 g_source_remove (priv->selection_bubble_timeout_id);
9433 priv->selection_bubble_timeout_id =
9434 gdk_threads_add_timeout (1000, gtk_entry_selection_bubble_popup_cb, entry);
9438 gtk_entry_drag_begin (GtkWidget *widget,
9439 GdkDragContext *context)
9441 GtkEntry *entry = GTK_ENTRY (widget);
9442 GtkEntryPrivate *priv = entry->priv;
9445 for (i = 0; i < MAX_ICONS; i++)
9447 EntryIconInfo *icon_info = priv->icons[i];
9449 if (icon_info != NULL)
9451 if (icon_info->in_drag)
9455 pix = _gtk_icon_helper_ensure_pixbuf
9456 (icon_info->icon_helper,
9457 gtk_widget_get_style_context (GTK_WIDGET (entry)));
9458 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
9460 g_object_unref (pix);
9467 gtk_entry_drag_end (GtkWidget *widget,
9468 GdkDragContext *context)
9470 GtkEntry *entry = GTK_ENTRY (widget);
9471 GtkEntryPrivate *priv = entry->priv;
9474 for (i = 0; i < MAX_ICONS; i++)
9476 EntryIconInfo *icon_info = priv->icons[i];
9478 if (icon_info != NULL)
9479 icon_info->in_drag = 0;
9484 gtk_entry_drag_leave (GtkWidget *widget,
9485 GdkDragContext *context,
9488 GtkEntry *entry = GTK_ENTRY (widget);
9489 GtkEntryPrivate *priv = entry->priv;
9491 priv->dnd_position = -1;
9492 gtk_widget_queue_draw (widget);
9496 gtk_entry_drag_drop (GtkWidget *widget,
9497 GdkDragContext *context,
9502 GtkEntry *entry = GTK_ENTRY (widget);
9503 GtkEntryPrivate *priv = entry->priv;
9504 GdkAtom target = GDK_NONE;
9507 target = gtk_drag_dest_find_target (widget, context, NULL);
9509 if (target != GDK_NONE)
9510 gtk_drag_get_data (widget, context, target, time);
9512 gtk_drag_finish (context, FALSE, FALSE, time);
9518 gtk_entry_drag_motion (GtkWidget *widget,
9519 GdkDragContext *context,
9524 GtkEntry *entry = GTK_ENTRY (widget);
9525 GtkEntryPrivate *priv = entry->priv;
9526 GtkStyleContext *style_context;
9527 GtkWidget *source_widget;
9528 GdkDragAction suggested_action;
9529 gint new_position, old_position;
9533 style_context = gtk_widget_get_style_context (widget);
9534 gtk_style_context_get_padding (style_context, 0, &padding);
9538 old_position = priv->dnd_position;
9539 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9541 if (priv->editable &&
9542 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9544 source_widget = gtk_drag_get_source_widget (context);
9545 suggested_action = gdk_drag_context_get_suggested_action (context);
9547 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9548 new_position < sel1 || new_position > sel2)
9550 if (source_widget == widget)
9552 /* Default to MOVE, unless the user has
9553 * pressed ctrl or alt to affect available actions
9555 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9556 suggested_action = GDK_ACTION_MOVE;
9559 priv->dnd_position = new_position;
9563 if (source_widget == widget)
9564 suggested_action = 0; /* Can't drop in selection where drag started */
9566 priv->dnd_position = -1;
9571 /* Entry not editable, or no text */
9572 suggested_action = 0;
9573 priv->dnd_position = -1;
9576 gdk_drag_status (context, suggested_action, time);
9578 if (priv->dnd_position != old_position)
9579 gtk_widget_queue_draw (widget);
9585 gtk_entry_drag_data_received (GtkWidget *widget,
9586 GdkDragContext *context,
9589 GtkSelectionData *selection_data,
9593 GtkEntry *entry = GTK_ENTRY (widget);
9594 GtkEntryPrivate *priv = entry->priv;
9595 GtkEditable *editable = GTK_EDITABLE (widget);
9596 GtkStyleContext *style_context;
9600 str = (gchar *) gtk_selection_data_get_text (selection_data);
9602 style_context = gtk_widget_get_style_context (widget);
9603 gtk_style_context_get_padding (style_context, 0, &padding);
9607 if (str && priv->editable)
9613 if (priv->truncate_multiline)
9614 length = truncate_multiline (str);
9616 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9618 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9619 new_position < sel1 || new_position > sel2)
9621 gtk_editable_insert_text (editable, str, length, &new_position);
9625 /* Replacing selection */
9626 begin_change (entry);
9627 gtk_editable_delete_text (editable, sel1, sel2);
9628 gtk_editable_insert_text (editable, str, length, &sel1);
9632 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9636 /* Drag and drop didn't happen! */
9637 gtk_drag_finish (context, FALSE, FALSE, time);
9644 gtk_entry_drag_data_get (GtkWidget *widget,
9645 GdkDragContext *context,
9646 GtkSelectionData *selection_data,
9650 GtkEntry *entry = GTK_ENTRY (widget);
9651 GtkEntryPrivate *priv = entry->priv;
9652 GtkEditable *editable = GTK_EDITABLE (widget);
9653 gint sel_start, sel_end;
9656 /* If there is an icon drag going on, exit early. */
9657 for (i = 0; i < MAX_ICONS; i++)
9659 EntryIconInfo *icon_info = priv->icons[i];
9661 if (icon_info != NULL)
9663 if (icon_info->in_drag)
9668 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9670 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9672 gtk_selection_data_set_text (selection_data, str, -1);
9680 gtk_entry_drag_data_delete (GtkWidget *widget,
9681 GdkDragContext *context)
9683 GtkEntry *entry = GTK_ENTRY (widget);
9684 GtkEntryPrivate *priv = entry->priv;
9685 GtkEditable *editable = GTK_EDITABLE (widget);
9686 gint sel_start, sel_end;
9689 /* If there is an icon drag going on, exit early. */
9690 for (i = 0; i < MAX_ICONS; i++)
9692 EntryIconInfo *icon_info = priv->icons[i];
9694 if (icon_info != NULL)
9696 if (icon_info->in_drag)
9701 if (priv->editable &&
9702 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9703 gtk_editable_delete_text (editable, sel_start, sel_end);
9706 /* We display the cursor when
9708 * - the selection is empty, AND
9709 * - the widget has focus
9712 #define CURSOR_ON_MULTIPLIER 2
9713 #define CURSOR_OFF_MULTIPLIER 1
9714 #define CURSOR_PEND_MULTIPLIER 3
9715 #define CURSOR_DIVIDER 3
9718 cursor_blinks (GtkEntry *entry)
9720 GtkEntryPrivate *priv = entry->priv;
9722 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9724 priv->selection_bound == priv->current_pos)
9726 GtkSettings *settings;
9729 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9730 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9739 get_middle_click_paste (GtkEntry *entry)
9741 GtkSettings *settings;
9744 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9745 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9751 get_cursor_time (GtkEntry *entry)
9753 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9756 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9762 get_cursor_blink_timeout (GtkEntry *entry)
9764 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9767 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9773 show_cursor (GtkEntry *entry)
9775 GtkEntryPrivate *priv = entry->priv;
9778 if (!priv->cursor_visible)
9780 priv->cursor_visible = TRUE;
9782 widget = GTK_WIDGET (entry);
9783 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9784 gtk_widget_queue_draw (widget);
9789 hide_cursor (GtkEntry *entry)
9791 GtkEntryPrivate *priv = entry->priv;
9794 if (priv->cursor_visible)
9796 priv->cursor_visible = FALSE;
9798 widget = GTK_WIDGET (entry);
9799 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9800 gtk_widget_queue_draw (widget);
9808 blink_cb (gpointer data)
9811 GtkEntryPrivate *priv;
9814 entry = GTK_ENTRY (data);
9817 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9819 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9820 "connect a handler to this signal, it must return\n"
9821 "FALSE so the entry gets the event as well");
9823 gtk_entry_check_cursor_blink (entry);
9828 g_assert (priv->selection_bound == priv->current_pos);
9830 blink_timeout = get_cursor_blink_timeout (entry);
9831 if (priv->blink_time > 1000 * blink_timeout &&
9832 blink_timeout < G_MAXINT/1000)
9834 /* we've blinked enough without the user doing anything, stop blinking */
9835 show_cursor (entry);
9836 priv->blink_timeout = 0;
9838 else if (priv->cursor_visible)
9840 hide_cursor (entry);
9841 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9847 show_cursor (entry);
9848 priv->blink_time += get_cursor_time (entry);
9849 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9854 /* Remove ourselves */
9859 gtk_entry_check_cursor_blink (GtkEntry *entry)
9861 GtkEntryPrivate *priv = entry->priv;
9863 if (cursor_blinks (entry))
9865 if (!priv->blink_timeout)
9867 show_cursor (entry);
9868 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9875 if (priv->blink_timeout)
9877 g_source_remove (priv->blink_timeout);
9878 priv->blink_timeout = 0;
9881 priv->cursor_visible = TRUE;
9886 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9888 GtkEntryPrivate *priv = entry->priv;
9890 if (cursor_blinks (entry))
9892 if (priv->blink_timeout != 0)
9893 g_source_remove (priv->blink_timeout);
9895 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9898 show_cursor (entry);
9903 gtk_entry_reset_blink_time (GtkEntry *entry)
9905 GtkEntryPrivate *priv = entry->priv;
9907 priv->blink_time = 0;
9911 * gtk_entry_set_completion:
9912 * @entry: A #GtkEntry
9913 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9915 * Sets @completion to be the auxiliary completion object to use with @entry.
9916 * All further configuration of the completion mechanism is done on
9917 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9918 * @completion is set to %NULL.
9923 gtk_entry_set_completion (GtkEntry *entry,
9924 GtkEntryCompletion *completion)
9926 GtkEntryCompletion *old;
9928 g_return_if_fail (GTK_IS_ENTRY (entry));
9929 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9931 old = gtk_entry_get_completion (entry);
9933 if (old == completion)
9938 _gtk_entry_completion_disconnect (old);
9939 g_object_unref (old);
9944 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9948 /* hook into the entry */
9949 g_object_ref (completion);
9951 _gtk_entry_completion_connect (completion, entry);
9953 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9955 g_object_notify (G_OBJECT (entry), "completion");
9959 * gtk_entry_get_completion:
9960 * @entry: A #GtkEntry
9962 * Returns the auxiliary completion object currently in use by @entry.
9964 * Return value: (transfer none): The auxiliary completion object currently
9969 GtkEntryCompletion *
9970 gtk_entry_get_completion (GtkEntry *entry)
9972 GtkEntryCompletion *completion;
9974 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9976 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9977 GTK_ENTRY_COMPLETION_KEY));
9983 * gtk_entry_set_cursor_hadjustment:
9984 * @entry: a #GtkEntry
9985 * @adjustment: an adjustment which should be adjusted when the cursor
9986 * is moved, or %NULL
9988 * Hooks up an adjustment to the cursor position in an entry, so that when
9989 * the cursor is moved, the adjustment is scrolled to show that position.
9990 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9993 * The adjustment has to be in pixel units and in the same coordinate system
9999 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10000 GtkAdjustment *adjustment)
10002 g_return_if_fail (GTK_IS_ENTRY (entry));
10004 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10007 g_object_ref (adjustment);
10009 g_object_set_qdata_full (G_OBJECT (entry),
10010 quark_cursor_hadjustment,
10016 * gtk_entry_get_cursor_hadjustment:
10017 * @entry: a #GtkEntry
10019 * Retrieves the horizontal cursor adjustment for the entry.
10020 * See gtk_entry_set_cursor_hadjustment().
10022 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10023 * if none has been set.
10028 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10030 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10032 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10036 * gtk_entry_set_progress_fraction:
10037 * @entry: a #GtkEntry
10038 * @fraction: fraction of the task that's been completed
10040 * Causes the entry's progress indicator to "fill in" the given
10041 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10047 gtk_entry_set_progress_fraction (GtkEntry *entry,
10051 GtkEntryPrivate *private;
10052 gdouble old_fraction;
10053 gint x, y, width, height;
10054 gint old_x, old_y, old_width, old_height;
10056 g_return_if_fail (GTK_IS_ENTRY (entry));
10058 widget = GTK_WIDGET (entry);
10059 private = entry->priv;
10061 if (private->progress_pulse_mode)
10064 old_fraction = private->progress_fraction;
10066 if (gtk_widget_is_drawable (widget))
10067 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10069 fraction = CLAMP (fraction, 0.0, 1.0);
10071 private->progress_fraction = fraction;
10072 private->progress_pulse_mode = FALSE;
10073 private->progress_pulse_current = 0.0;
10075 if (gtk_widget_is_drawable (widget))
10077 get_progress_area (widget, &x, &y, &width, &height);
10079 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10080 gtk_widget_queue_draw (widget);
10083 if (fraction != old_fraction)
10084 g_object_notify (G_OBJECT (entry), "progress-fraction");
10088 * gtk_entry_get_progress_fraction:
10089 * @entry: a #GtkEntry
10091 * Returns the current fraction of the task that's been completed.
10092 * See gtk_entry_set_progress_fraction().
10094 * Return value: a fraction from 0.0 to 1.0
10099 gtk_entry_get_progress_fraction (GtkEntry *entry)
10101 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10103 return entry->priv->progress_fraction;
10107 * gtk_entry_set_progress_pulse_step:
10108 * @entry: a #GtkEntry
10109 * @fraction: fraction between 0.0 and 1.0
10111 * Sets the fraction of total entry width to move the progress
10112 * bouncing block for each call to gtk_entry_progress_pulse().
10117 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10120 GtkEntryPrivate *private;
10122 g_return_if_fail (GTK_IS_ENTRY (entry));
10124 private = entry->priv;
10126 fraction = CLAMP (fraction, 0.0, 1.0);
10128 if (fraction != private->progress_pulse_fraction)
10130 private->progress_pulse_fraction = fraction;
10132 gtk_widget_queue_draw (GTK_WIDGET (entry));
10134 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10139 * gtk_entry_get_progress_pulse_step:
10140 * @entry: a #GtkEntry
10142 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10144 * Return value: a fraction from 0.0 to 1.0
10149 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10151 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10153 return entry->priv->progress_pulse_fraction;
10157 * gtk_entry_progress_pulse:
10158 * @entry: a #GtkEntry
10160 * Indicates that some progress is made, but you don't know how much.
10161 * Causes the entry's progress indicator to enter "activity mode,"
10162 * where a block bounces back and forth. Each call to
10163 * gtk_entry_progress_pulse() causes the block to move by a little bit
10164 * (the amount of movement per pulse is determined by
10165 * gtk_entry_set_progress_pulse_step()).
10170 gtk_entry_progress_pulse (GtkEntry *entry)
10172 GtkEntryPrivate *private;
10174 g_return_if_fail (GTK_IS_ENTRY (entry));
10176 private = entry->priv;
10178 if (private->progress_pulse_mode)
10180 if (private->progress_pulse_way_back)
10182 private->progress_pulse_current -= private->progress_pulse_fraction;
10184 if (private->progress_pulse_current < 0.0)
10186 private->progress_pulse_current = 0.0;
10187 private->progress_pulse_way_back = FALSE;
10192 private->progress_pulse_current += private->progress_pulse_fraction;
10194 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10196 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10197 private->progress_pulse_way_back = TRUE;
10203 private->progress_fraction = 0.0;
10204 private->progress_pulse_mode = TRUE;
10205 private->progress_pulse_way_back = FALSE;
10206 private->progress_pulse_current = 0.0;
10209 gtk_widget_queue_draw (GTK_WIDGET (entry));
10213 * gtk_entry_set_placeholder_text:
10214 * @entry: a #GtkEntry
10215 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10217 * Sets text to be displayed in @entry when it is empty and unfocused.
10218 * This can be used to give a visual hint of the expected contents of
10221 * Note that since the placeholder text gets removed when the entry
10222 * received focus, using this feature is a bit problematic if the entry
10223 * is given the initial focus in a window. Sometimes this can be
10224 * worked around by delaying the initial focus setting until the
10225 * first key event arrives.
10230 gtk_entry_set_placeholder_text (GtkEntry *entry,
10233 GtkEntryPrivate *priv;
10235 g_return_if_fail (GTK_IS_ENTRY (entry));
10237 priv = entry->priv;
10239 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10242 g_free (priv->placeholder_text);
10243 priv->placeholder_text = g_strdup (text);
10245 gtk_entry_recompute (entry);
10247 g_object_notify (G_OBJECT (entry), "placeholder-text");
10251 * gtk_entry_get_placeholder_text:
10252 * @entry: a #GtkEntry
10254 * Retrieves the text that will be displayed when @entry is empty and unfocused
10256 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10257 * storage in the widget and must not be freed, modified or stored.
10262 gtk_entry_get_placeholder_text (GtkEntry *entry)
10264 GtkEntryPrivate *priv;
10266 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10268 priv = entry->priv;
10270 return priv->placeholder_text;
10273 /* Caps Lock warning for password entries */
10276 show_capslock_feedback (GtkEntry *entry,
10279 GtkEntryPrivate *priv = entry->priv;
10281 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10283 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10284 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10285 priv->caps_lock_warning_shown = TRUE;
10288 if (priv->caps_lock_warning_shown)
10289 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10291 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10295 remove_capslock_feedback (GtkEntry *entry)
10297 GtkEntryPrivate *priv = entry->priv;
10299 if (priv->caps_lock_warning_shown)
10301 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10302 priv->caps_lock_warning_shown = FALSE;
10307 keymap_state_changed (GdkKeymap *keymap,
10310 GtkEntryPrivate *priv = entry->priv;
10313 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10315 if (gdk_keymap_get_caps_lock_state (keymap))
10316 text = _("Caps Lock is on");
10320 show_capslock_feedback (entry, text);
10322 remove_capslock_feedback (entry);
10326 * _gtk_entry_set_is_cell_renderer:
10327 * @entry: a #GtkEntry
10328 * @is_cell_renderer: new value
10330 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10331 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10333 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10337 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10338 gboolean is_cell_renderer)
10340 entry->priv->is_cell_renderer = is_cell_renderer;
10344 * gtk_entry_set_input_purpose:
10345 * @entry: a #GtkEntry
10346 * @purpose: the purpose
10348 * Sets the #GtkEntry:input-purpose property which
10349 * can be used by on-screen keyboards and other input
10350 * methods to adjust their behaviour.
10355 gtk_entry_set_input_purpose (GtkEntry *entry,
10356 GtkInputPurpose purpose)
10359 g_return_if_fail (GTK_IS_ENTRY (entry));
10361 if (gtk_entry_get_input_purpose (entry) != purpose)
10363 g_object_set (G_OBJECT (entry->priv->im_context),
10364 "input-purpose", purpose,
10367 g_object_notify (G_OBJECT (entry), "input-purpose");
10372 * gtk_entry_get_input_purpose:
10373 * @entry: a #GtkEntry
10375 * Gets the value of the #GtkEntry:input-purpose property.
10380 gtk_entry_get_input_purpose (GtkEntry *entry)
10382 GtkInputPurpose purpose;
10384 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
10386 g_object_get (G_OBJECT (entry->priv->im_context),
10387 "input-purpose", &purpose,
10394 * gtk_entry_set_input_hints:
10395 * @entry: a #GtkEntry
10396 * @hints: the hints
10398 * Sets the #GtkEntry:input-hints property, which
10399 * allows input methods to fine-tune their behaviour.
10404 gtk_entry_set_input_hints (GtkEntry *entry,
10405 GtkInputHints hints)
10408 g_return_if_fail (GTK_IS_ENTRY (entry));
10410 if (gtk_entry_get_input_hints (entry) != hints)
10412 g_object_set (G_OBJECT (entry->priv->im_context),
10413 "input-hints", hints,
10416 g_object_notify (G_OBJECT (entry), "input-hints");
10421 * gtk_entry_get_input_hints:
10422 * @entry: a #GtkEntry
10424 * Gets the value of the #GtkEntry:input-hints property.
10429 gtk_entry_get_input_hints (GtkEntry *entry)
10431 GtkInputHints hints;
10433 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
10435 g_object_get (G_OBJECT (entry->priv->im_context),
10436 "input-hints", &hints,
10443 * gtk_entry_set_attributes:
10444 * @entry: a #GtkEntry
10445 * @attrs: a #PangoAttrList
10447 * Sets a #PangoAttrList; the attributes in the list are applied to the
10453 gtk_entry_set_attributes (GtkEntry *entry,
10454 PangoAttrList *attrs)
10456 GtkEntryPrivate *priv = entry->priv;
10457 g_return_if_fail (GTK_IS_ENTRY (entry));
10460 pango_attr_list_ref (attrs);
10463 pango_attr_list_unref (priv->attrs);
10464 priv->attrs = attrs;
10466 g_object_notify (G_OBJECT (entry), "attributes");
10468 gtk_entry_recompute (entry);
10469 gtk_widget_queue_resize (GTK_WIDGET (entry));
10473 * gtk_entry_get_attributes:
10474 * @entry: a #GtkEntry
10476 * Gets the attribute list that was set on the entry using
10477 * gtk_entry_set_attributes(), if any.
10479 * Return value: (transfer none): the attribute list, or %NULL
10485 gtk_entry_get_attributes (GtkEntry *entry)
10487 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10489 return entry->priv->attrs;