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_toolbar : 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,
324 PROP_POPULATE_TOOLBAR
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-toolbar:
1430 * If ::populate-toolbar is %TRUE, the #GtkEntry::populate-popup
1431 * signal is also emitted for touch popups. In this case, the container
1436 g_object_class_install_property (gobject_class,
1437 PROP_POPULATE_TOOLBAR,
1438 g_param_spec_boolean ("populate-toolbar",
1439 P_("Populate toolbar"),
1440 P_("Whether to emit ::populate-popup for touch popups"),
1442 GTK_PARAM_READWRITE));
1445 * GtkEntry:icon-prelight:
1447 * The prelight style property determines whether activatable
1448 * icons prelight on mouseover.
1452 gtk_widget_class_install_style_property (widget_class,
1453 g_param_spec_boolean ("icon-prelight",
1454 P_("Icon Prelight"),
1455 P_("Whether activatable icons should prelight when hovered"),
1457 GTK_PARAM_READABLE));
1460 * GtkEntry:progress-border:
1462 * The border around the progress bar in the entry.
1466 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1467 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1468 * property is ignored.
1470 gtk_widget_class_install_style_property (widget_class,
1471 g_param_spec_boxed ("progress-border",
1472 P_("Progress Border"),
1473 P_("Border around the progress bar"),
1475 GTK_PARAM_READABLE |
1476 G_PARAM_DEPRECATED));
1479 * GtkEntry:invisible-char:
1481 * The invisible character is used when masking entry contents (in
1482 * \"password mode\")"). When it is not explicitly set with the
1483 * #GtkEntry:invisible-char property, GTK+ determines the character
1484 * to use from a list of possible candidates, depending on availability
1485 * in the current font.
1487 * This style property allows the theme to prepend a character
1488 * to the list of candidates.
1492 gtk_widget_class_install_style_property (widget_class,
1493 g_param_spec_unichar ("invisible-char",
1494 P_("Invisible character"),
1495 P_("The character to use when masking entry contents (in \"password mode\")"),
1497 GTK_PARAM_READABLE));
1500 * GtkEntry::populate-popup:
1501 * @entry: The entry on which the signal is emitted
1502 * @popup: the menu or toolbar that is being populated
1504 * The ::populate-popup signal gets emitted before showing the
1505 * context menu of the entry.
1507 * If you need to add items to the context menu, connect
1508 * to this signal and append your items to the @widget.
1510 * If #GtkEntry::populate-toolbar is %TRUE, this signal will
1511 * also be emitted to populate touch popups. In this case,
1512 * @widget will be a toolbar instead of a menu.
1514 signals[POPULATE_POPUP] =
1515 g_signal_new (I_("populate-popup"),
1516 G_OBJECT_CLASS_TYPE (gobject_class),
1518 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1520 _gtk_marshal_VOID__OBJECT,
1524 /* Action signals */
1527 * GtkEntry::activate:
1528 * @entry: The entry on which the signal is emitted
1530 * The ::activate signal is emitted when the user hits
1533 * While this signal is used as a
1534 * <link linkend="keybinding-signals">keybinding signal</link>,
1535 * it is also commonly used by applications to intercept
1536 * activation of entries.
1538 * The default bindings for this signal are all forms of the Enter key.
1541 g_signal_new (I_("activate"),
1542 G_OBJECT_CLASS_TYPE (gobject_class),
1543 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1544 G_STRUCT_OFFSET (GtkEntryClass, activate),
1546 _gtk_marshal_VOID__VOID,
1548 widget_class->activate_signal = signals[ACTIVATE];
1551 * GtkEntry::move-cursor:
1552 * @entry: the object which received the signal
1553 * @step: the granularity of the move, as a #GtkMovementStep
1554 * @count: the number of @step units to move
1555 * @extend_selection: %TRUE if the move should extend the selection
1557 * The ::move-cursor signal is a
1558 * <link linkend="keybinding-signals">keybinding signal</link>
1559 * which gets emitted when the user initiates a cursor movement.
1560 * If the cursor is not visible in @entry, this signal causes
1561 * the viewport to be moved instead.
1563 * Applications should not connect to it, but may emit it with
1564 * g_signal_emit_by_name() if they need to control the cursor
1567 * The default bindings for this signal come in two variants,
1568 * the variant with the Shift modifier extends the selection,
1569 * the variant without the Shift modifer does not.
1570 * There are too many key combinations to list them all here.
1572 * <listitem>Arrow keys move by individual characters/lines</listitem>
1573 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1574 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1577 signals[MOVE_CURSOR] =
1578 g_signal_new (I_("move-cursor"),
1579 G_OBJECT_CLASS_TYPE (gobject_class),
1580 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1581 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1583 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1585 GTK_TYPE_MOVEMENT_STEP,
1590 * GtkEntry::insert-at-cursor:
1591 * @entry: the object which received the signal
1592 * @string: the string to insert
1594 * The ::insert-at-cursor signal is a
1595 * <link linkend="keybinding-signals">keybinding signal</link>
1596 * which gets emitted when the user initiates the insertion of a
1597 * fixed string at the cursor.
1599 * This signal has no default bindings.
1601 signals[INSERT_AT_CURSOR] =
1602 g_signal_new (I_("insert-at-cursor"),
1603 G_OBJECT_CLASS_TYPE (gobject_class),
1604 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1605 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1607 _gtk_marshal_VOID__STRING,
1612 * GtkEntry::delete-from-cursor:
1613 * @entry: the object which received the signal
1614 * @type: the granularity of the deletion, as a #GtkDeleteType
1615 * @count: the number of @type units to delete
1617 * The ::delete-from-cursor signal is a
1618 * <link linkend="keybinding-signals">keybinding signal</link>
1619 * which gets emitted when the user initiates a text deletion.
1621 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1622 * if there is one, otherwise it deletes the requested number
1625 * The default bindings for this signal are
1626 * Delete for deleting a character and Ctrl-Delete for
1629 signals[DELETE_FROM_CURSOR] =
1630 g_signal_new (I_("delete-from-cursor"),
1631 G_OBJECT_CLASS_TYPE (gobject_class),
1632 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1633 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1635 _gtk_marshal_VOID__ENUM_INT,
1637 GTK_TYPE_DELETE_TYPE,
1641 * GtkEntry::backspace:
1642 * @entry: the object which received the signal
1644 * The ::backspace signal is a
1645 * <link linkend="keybinding-signals">keybinding signal</link>
1646 * which gets emitted when the user asks for it.
1648 * The default bindings for this signal are
1649 * Backspace and Shift-Backspace.
1651 signals[BACKSPACE] =
1652 g_signal_new (I_("backspace"),
1653 G_OBJECT_CLASS_TYPE (gobject_class),
1654 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1655 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1657 _gtk_marshal_VOID__VOID,
1661 * GtkEntry::cut-clipboard:
1662 * @entry: the object which received the signal
1664 * The ::cut-clipboard signal is a
1665 * <link linkend="keybinding-signals">keybinding signal</link>
1666 * which gets emitted to cut the selection to the clipboard.
1668 * The default bindings for this signal are
1669 * Ctrl-x and Shift-Delete.
1671 signals[CUT_CLIPBOARD] =
1672 g_signal_new (I_("cut-clipboard"),
1673 G_OBJECT_CLASS_TYPE (gobject_class),
1674 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1675 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1677 _gtk_marshal_VOID__VOID,
1681 * GtkEntry::copy-clipboard:
1682 * @entry: the object which received the signal
1684 * The ::copy-clipboard signal is a
1685 * <link linkend="keybinding-signals">keybinding signal</link>
1686 * which gets emitted to copy the selection to the clipboard.
1688 * The default bindings for this signal are
1689 * Ctrl-c and Ctrl-Insert.
1691 signals[COPY_CLIPBOARD] =
1692 g_signal_new (I_("copy-clipboard"),
1693 G_OBJECT_CLASS_TYPE (gobject_class),
1694 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1695 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1697 _gtk_marshal_VOID__VOID,
1701 * GtkEntry::paste-clipboard:
1702 * @entry: the object which received the signal
1704 * The ::paste-clipboard signal is a
1705 * <link linkend="keybinding-signals">keybinding signal</link>
1706 * which gets emitted to paste the contents of the clipboard
1707 * into the text view.
1709 * The default bindings for this signal are
1710 * Ctrl-v and Shift-Insert.
1712 signals[PASTE_CLIPBOARD] =
1713 g_signal_new (I_("paste-clipboard"),
1714 G_OBJECT_CLASS_TYPE (gobject_class),
1715 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1716 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1718 _gtk_marshal_VOID__VOID,
1722 * GtkEntry::toggle-overwrite:
1723 * @entry: the object which received the signal
1725 * The ::toggle-overwrite signal is a
1726 * <link linkend="keybinding-signals">keybinding signal</link>
1727 * which gets emitted to toggle the overwrite mode of the entry.
1729 * The default bindings for this signal is Insert.
1731 signals[TOGGLE_OVERWRITE] =
1732 g_signal_new (I_("toggle-overwrite"),
1733 G_OBJECT_CLASS_TYPE (gobject_class),
1734 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1735 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1737 _gtk_marshal_VOID__VOID,
1741 * GtkEntry::icon-press:
1742 * @entry: The entry on which the signal is emitted
1743 * @icon_pos: The position of the clicked icon
1744 * @event: (type Gdk.EventButton): the button press event
1746 * The ::icon-press signal is emitted when an activatable icon
1751 signals[ICON_PRESS] =
1752 g_signal_new (I_("icon-press"),
1753 G_TYPE_FROM_CLASS (gobject_class),
1757 _gtk_marshal_VOID__ENUM_BOXED,
1759 GTK_TYPE_ENTRY_ICON_POSITION,
1760 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1763 * GtkEntry::icon-release:
1764 * @entry: The entry on which the signal is emitted
1765 * @icon_pos: The position of the clicked icon
1766 * @event: (type Gdk.EventButton): the button release event
1768 * The ::icon-release signal is emitted on the button release from a
1769 * mouse click over an activatable icon.
1773 signals[ICON_RELEASE] =
1774 g_signal_new (I_("icon-release"),
1775 G_TYPE_FROM_CLASS (gobject_class),
1779 _gtk_marshal_VOID__ENUM_BOXED,
1781 GTK_TYPE_ENTRY_ICON_POSITION,
1782 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1785 * GtkEntry::preedit-changed:
1786 * @entry: the object which received the signal
1787 * @preedit: the current preedit string
1789 * If an input method is used, the typed text will not immediately
1790 * be committed to the buffer. So if you are interested in the text,
1791 * connect to this signal.
1795 signals[PREEDIT_CHANGED] =
1796 g_signal_new_class_handler (I_("preedit-changed"),
1797 G_OBJECT_CLASS_TYPE (gobject_class),
1798 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1801 _gtk_marshal_VOID__STRING,
1810 binding_set = gtk_binding_set_by_class (class);
1812 /* Moving the insertion point */
1813 add_move_binding (binding_set, GDK_KEY_Right, 0,
1814 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1816 add_move_binding (binding_set, GDK_KEY_Left, 0,
1817 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1819 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1820 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1822 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1823 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1825 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1826 GTK_MOVEMENT_WORDS, 1);
1828 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1829 GTK_MOVEMENT_WORDS, -1);
1831 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1832 GTK_MOVEMENT_WORDS, 1);
1834 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1835 GTK_MOVEMENT_WORDS, -1);
1837 add_move_binding (binding_set, GDK_KEY_Home, 0,
1838 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1840 add_move_binding (binding_set, GDK_KEY_End, 0,
1841 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1843 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1844 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1846 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1847 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1849 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1850 GTK_MOVEMENT_BUFFER_ENDS, -1);
1852 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1853 GTK_MOVEMENT_BUFFER_ENDS, 1);
1855 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1856 GTK_MOVEMENT_BUFFER_ENDS, -1);
1858 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1859 GTK_MOVEMENT_BUFFER_ENDS, 1);
1863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1865 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1867 G_TYPE_BOOLEAN, FALSE);
1868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1870 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1872 G_TYPE_BOOLEAN, TRUE);
1874 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1876 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1878 G_TYPE_BOOLEAN, FALSE);
1879 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1881 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1883 G_TYPE_BOOLEAN, TRUE);
1886 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1888 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1890 G_TYPE_BOOLEAN, FALSE);
1891 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1893 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1895 G_TYPE_BOOLEAN, FALSE);
1899 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1901 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1903 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1907 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1908 "delete-from-cursor", 2,
1909 G_TYPE_ENUM, GTK_DELETE_CHARS,
1912 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1913 "delete-from-cursor", 2,
1914 G_TYPE_ENUM, GTK_DELETE_CHARS,
1917 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1920 /* Make this do the same as Backspace, to help with mis-typing */
1921 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1924 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1925 "delete-from-cursor", 2,
1926 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1929 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1930 "delete-from-cursor", 2,
1931 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1934 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1935 "delete-from-cursor", 2,
1936 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1939 /* Cut/copy/paste */
1941 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1942 "cut-clipboard", 0);
1943 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1944 "copy-clipboard", 0);
1945 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1946 "paste-clipboard", 0);
1948 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1949 "cut-clipboard", 0);
1950 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1951 "copy-clipboard", 0);
1952 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1953 "paste-clipboard", 0);
1956 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1957 "toggle-overwrite", 0);
1958 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1959 "toggle-overwrite", 0);
1962 * GtkEntry:inner-border:
1964 * Sets the text area's border between the text and the frame.
1968 * Deprecated: 3.4: Use the standard border and padding CSS properties
1969 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1970 * of this style property is ignored.
1972 gtk_widget_class_install_style_property (widget_class,
1973 g_param_spec_boxed ("inner-border",
1975 P_("Border between text and frame."),
1977 GTK_PARAM_READABLE |
1978 G_PARAM_DEPRECATED));
1980 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1981 test_touchscreen = g_getenv ("GTK_TEST_TOUCHSCREEN") != NULL;
1983 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1987 gtk_entry_editable_init (GtkEditableInterface *iface)
1989 iface->do_insert_text = gtk_entry_insert_text;
1990 iface->do_delete_text = gtk_entry_delete_text;
1991 iface->insert_text = gtk_entry_real_insert_text;
1992 iface->delete_text = gtk_entry_real_delete_text;
1993 iface->get_chars = gtk_entry_get_chars;
1994 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1995 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1996 iface->set_position = gtk_entry_real_set_position;
1997 iface->get_position = gtk_entry_get_position;
2001 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
2003 iface->start_editing = gtk_entry_start_editing;
2006 /* for deprecated properties */
2008 gtk_entry_do_set_inner_border (GtkEntry *entry,
2009 const GtkBorder *border)
2012 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
2013 gtk_border_copy (border),
2014 (GDestroyNotify) gtk_border_free);
2016 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
2018 g_object_notify (G_OBJECT (entry), "inner-border");
2021 static const GtkBorder *
2022 gtk_entry_do_get_inner_border (GtkEntry *entry)
2024 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
2028 gtk_entry_set_property (GObject *object,
2030 const GValue *value,
2033 GtkEntry *entry = GTK_ENTRY (object);
2034 GtkEntryPrivate *priv = entry->priv;
2039 gtk_entry_set_buffer (entry, g_value_get_object (value));
2044 gboolean new_value = g_value_get_boolean (value);
2046 if (new_value != priv->editable)
2048 GtkWidget *widget = GTK_WIDGET (entry);
2052 gtk_entry_reset_im_context (entry);
2053 if (gtk_widget_has_focus (widget))
2054 gtk_im_context_focus_out (priv->im_context);
2056 priv->preedit_length = 0;
2057 priv->preedit_cursor = 0;
2060 priv->editable = new_value;
2062 if (new_value && gtk_widget_has_focus (widget))
2063 gtk_im_context_focus_in (priv->im_context);
2065 gtk_widget_queue_draw (widget);
2070 case PROP_MAX_LENGTH:
2071 gtk_entry_set_max_length (entry, g_value_get_int (value));
2074 case PROP_VISIBILITY:
2075 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
2078 case PROP_HAS_FRAME:
2079 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
2082 case PROP_INNER_BORDER:
2083 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
2086 case PROP_INVISIBLE_CHAR:
2087 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2090 case PROP_ACTIVATES_DEFAULT:
2091 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2094 case PROP_WIDTH_CHARS:
2095 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2099 gtk_entry_set_text (entry, g_value_get_string (value));
2103 gtk_entry_set_alignment (entry, g_value_get_float (value));
2106 case PROP_TRUNCATE_MULTILINE:
2107 priv->truncate_multiline = g_value_get_boolean (value);
2110 case PROP_SHADOW_TYPE:
2111 priv->shadow_type = g_value_get_enum (value);
2114 case PROP_OVERWRITE_MODE:
2115 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2118 case PROP_INVISIBLE_CHAR_SET:
2119 if (g_value_get_boolean (value))
2120 priv->invisible_char_set = TRUE;
2122 gtk_entry_unset_invisible_char (entry);
2125 case PROP_CAPS_LOCK_WARNING:
2126 priv->caps_lock_warning = g_value_get_boolean (value);
2129 case PROP_PROGRESS_FRACTION:
2130 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2133 case PROP_PROGRESS_PULSE_STEP:
2134 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2137 case PROP_PLACEHOLDER_TEXT:
2138 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2141 case PROP_PIXBUF_PRIMARY:
2142 gtk_entry_set_icon_from_pixbuf (entry,
2143 GTK_ENTRY_ICON_PRIMARY,
2144 g_value_get_object (value));
2147 case PROP_PIXBUF_SECONDARY:
2148 gtk_entry_set_icon_from_pixbuf (entry,
2149 GTK_ENTRY_ICON_SECONDARY,
2150 g_value_get_object (value));
2153 case PROP_STOCK_PRIMARY:
2154 gtk_entry_set_icon_from_stock (entry,
2155 GTK_ENTRY_ICON_PRIMARY,
2156 g_value_get_string (value));
2159 case PROP_STOCK_SECONDARY:
2160 gtk_entry_set_icon_from_stock (entry,
2161 GTK_ENTRY_ICON_SECONDARY,
2162 g_value_get_string (value));
2165 case PROP_ICON_NAME_PRIMARY:
2166 gtk_entry_set_icon_from_icon_name (entry,
2167 GTK_ENTRY_ICON_PRIMARY,
2168 g_value_get_string (value));
2171 case PROP_ICON_NAME_SECONDARY:
2172 gtk_entry_set_icon_from_icon_name (entry,
2173 GTK_ENTRY_ICON_SECONDARY,
2174 g_value_get_string (value));
2177 case PROP_GICON_PRIMARY:
2178 gtk_entry_set_icon_from_gicon (entry,
2179 GTK_ENTRY_ICON_PRIMARY,
2180 g_value_get_object (value));
2183 case PROP_GICON_SECONDARY:
2184 gtk_entry_set_icon_from_gicon (entry,
2185 GTK_ENTRY_ICON_SECONDARY,
2186 g_value_get_object (value));
2189 case PROP_ACTIVATABLE_PRIMARY:
2190 gtk_entry_set_icon_activatable (entry,
2191 GTK_ENTRY_ICON_PRIMARY,
2192 g_value_get_boolean (value));
2195 case PROP_ACTIVATABLE_SECONDARY:
2196 gtk_entry_set_icon_activatable (entry,
2197 GTK_ENTRY_ICON_SECONDARY,
2198 g_value_get_boolean (value));
2201 case PROP_SENSITIVE_PRIMARY:
2202 gtk_entry_set_icon_sensitive (entry,
2203 GTK_ENTRY_ICON_PRIMARY,
2204 g_value_get_boolean (value));
2207 case PROP_SENSITIVE_SECONDARY:
2208 gtk_entry_set_icon_sensitive (entry,
2209 GTK_ENTRY_ICON_SECONDARY,
2210 g_value_get_boolean (value));
2213 case PROP_TOOLTIP_TEXT_PRIMARY:
2214 gtk_entry_set_icon_tooltip_text (entry,
2215 GTK_ENTRY_ICON_PRIMARY,
2216 g_value_get_string (value));
2219 case PROP_TOOLTIP_TEXT_SECONDARY:
2220 gtk_entry_set_icon_tooltip_text (entry,
2221 GTK_ENTRY_ICON_SECONDARY,
2222 g_value_get_string (value));
2225 case PROP_TOOLTIP_MARKUP_PRIMARY:
2226 gtk_entry_set_icon_tooltip_markup (entry,
2227 GTK_ENTRY_ICON_PRIMARY,
2228 g_value_get_string (value));
2231 case PROP_TOOLTIP_MARKUP_SECONDARY:
2232 gtk_entry_set_icon_tooltip_markup (entry,
2233 GTK_ENTRY_ICON_SECONDARY,
2234 g_value_get_string (value));
2237 case PROP_IM_MODULE:
2238 g_free (priv->im_module);
2239 priv->im_module = g_value_dup_string (value);
2240 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2241 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2244 case PROP_EDITING_CANCELED:
2245 priv->editing_canceled = g_value_get_boolean (value);
2248 case PROP_COMPLETION:
2249 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2252 case PROP_INPUT_PURPOSE:
2253 gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
2256 case PROP_INPUT_HINTS:
2257 gtk_entry_set_input_hints (entry, g_value_get_flags (value));
2260 case PROP_ATTRIBUTES:
2261 gtk_entry_set_attributes (entry, g_value_get_boxed (value));
2264 case PROP_POPULATE_TOOLBAR:
2265 entry->priv->populate_toolbar = g_value_get_boolean (value);
2268 case PROP_SCROLL_OFFSET:
2269 case PROP_CURSOR_POSITION:
2271 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2277 gtk_entry_get_property (GObject *object,
2282 GtkEntry *entry = GTK_ENTRY (object);
2283 GtkEntryPrivate *priv = entry->priv;
2288 g_value_set_object (value, gtk_entry_get_buffer (entry));
2291 case PROP_CURSOR_POSITION:
2292 g_value_set_int (value, priv->current_pos);
2295 case PROP_SELECTION_BOUND:
2296 g_value_set_int (value, priv->selection_bound);
2300 g_value_set_boolean (value, priv->editable);
2303 case PROP_MAX_LENGTH:
2304 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2307 case PROP_VISIBILITY:
2308 g_value_set_boolean (value, priv->visible);
2311 case PROP_HAS_FRAME:
2312 g_value_set_boolean (value, priv->has_frame);
2315 case PROP_INNER_BORDER:
2316 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2319 case PROP_INVISIBLE_CHAR:
2320 g_value_set_uint (value, priv->invisible_char);
2323 case PROP_ACTIVATES_DEFAULT:
2324 g_value_set_boolean (value, priv->activates_default);
2327 case PROP_WIDTH_CHARS:
2328 g_value_set_int (value, priv->width_chars);
2331 case PROP_SCROLL_OFFSET:
2332 g_value_set_int (value, priv->scroll_offset);
2336 g_value_set_string (value, gtk_entry_get_text (entry));
2340 g_value_set_float (value, gtk_entry_get_alignment (entry));
2343 case PROP_TRUNCATE_MULTILINE:
2344 g_value_set_boolean (value, priv->truncate_multiline);
2347 case PROP_SHADOW_TYPE:
2348 g_value_set_enum (value, priv->shadow_type);
2351 case PROP_OVERWRITE_MODE:
2352 g_value_set_boolean (value, priv->overwrite_mode);
2355 case PROP_TEXT_LENGTH:
2356 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2359 case PROP_INVISIBLE_CHAR_SET:
2360 g_value_set_boolean (value, priv->invisible_char_set);
2363 case PROP_IM_MODULE:
2364 g_value_set_string (value, priv->im_module);
2367 case PROP_CAPS_LOCK_WARNING:
2368 g_value_set_boolean (value, priv->caps_lock_warning);
2371 case PROP_PROGRESS_FRACTION:
2372 g_value_set_double (value, priv->progress_fraction);
2375 case PROP_PROGRESS_PULSE_STEP:
2376 g_value_set_double (value, priv->progress_pulse_fraction);
2379 case PROP_PLACEHOLDER_TEXT:
2380 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2383 case PROP_PIXBUF_PRIMARY:
2384 g_value_set_object (value,
2385 gtk_entry_get_icon_pixbuf (entry,
2386 GTK_ENTRY_ICON_PRIMARY));
2389 case PROP_PIXBUF_SECONDARY:
2390 g_value_set_object (value,
2391 gtk_entry_get_icon_pixbuf (entry,
2392 GTK_ENTRY_ICON_SECONDARY));
2395 case PROP_STOCK_PRIMARY:
2396 g_value_set_string (value,
2397 gtk_entry_get_icon_stock (entry,
2398 GTK_ENTRY_ICON_PRIMARY));
2401 case PROP_STOCK_SECONDARY:
2402 g_value_set_string (value,
2403 gtk_entry_get_icon_stock (entry,
2404 GTK_ENTRY_ICON_SECONDARY));
2407 case PROP_ICON_NAME_PRIMARY:
2408 g_value_set_string (value,
2409 gtk_entry_get_icon_name (entry,
2410 GTK_ENTRY_ICON_PRIMARY));
2413 case PROP_ICON_NAME_SECONDARY:
2414 g_value_set_string (value,
2415 gtk_entry_get_icon_name (entry,
2416 GTK_ENTRY_ICON_SECONDARY));
2419 case PROP_GICON_PRIMARY:
2420 g_value_set_object (value,
2421 gtk_entry_get_icon_gicon (entry,
2422 GTK_ENTRY_ICON_PRIMARY));
2425 case PROP_GICON_SECONDARY:
2426 g_value_set_object (value,
2427 gtk_entry_get_icon_gicon (entry,
2428 GTK_ENTRY_ICON_SECONDARY));
2431 case PROP_STORAGE_TYPE_PRIMARY:
2432 g_value_set_enum (value,
2433 gtk_entry_get_icon_storage_type (entry,
2434 GTK_ENTRY_ICON_PRIMARY));
2437 case PROP_STORAGE_TYPE_SECONDARY:
2438 g_value_set_enum (value,
2439 gtk_entry_get_icon_storage_type (entry,
2440 GTK_ENTRY_ICON_SECONDARY));
2443 case PROP_ACTIVATABLE_PRIMARY:
2444 g_value_set_boolean (value,
2445 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2448 case PROP_ACTIVATABLE_SECONDARY:
2449 g_value_set_boolean (value,
2450 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2453 case PROP_SENSITIVE_PRIMARY:
2454 g_value_set_boolean (value,
2455 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2458 case PROP_SENSITIVE_SECONDARY:
2459 g_value_set_boolean (value,
2460 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2463 case PROP_TOOLTIP_TEXT_PRIMARY:
2464 g_value_take_string (value,
2465 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2468 case PROP_TOOLTIP_TEXT_SECONDARY:
2469 g_value_take_string (value,
2470 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2473 case PROP_TOOLTIP_MARKUP_PRIMARY:
2474 g_value_take_string (value,
2475 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2478 case PROP_TOOLTIP_MARKUP_SECONDARY:
2479 g_value_take_string (value,
2480 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2483 case PROP_EDITING_CANCELED:
2484 g_value_set_boolean (value,
2485 priv->editing_canceled);
2488 case PROP_COMPLETION:
2489 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2492 case PROP_INPUT_PURPOSE:
2493 g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
2496 case PROP_INPUT_HINTS:
2497 g_value_set_flags (value, gtk_entry_get_input_hints (entry));
2500 case PROP_ATTRIBUTES:
2501 g_value_set_boxed (value, priv->attrs);
2504 case PROP_POPULATE_TOOLBAR:
2505 g_value_set_boolean (value, priv->populate_toolbar);
2509 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2515 find_invisible_char (GtkWidget *widget)
2517 PangoLayout *layout;
2518 PangoAttrList *attr_list;
2520 gunichar invisible_chars [] = {
2522 0x25cf, /* BLACK CIRCLE */
2523 0x2022, /* BULLET */
2524 0x2731, /* HEAVY ASTERISK */
2525 0x273a /* SIXTEEN POINTED ASTERISK */
2528 gtk_widget_style_get (widget,
2529 "invisible-char", &invisible_chars[0],
2532 layout = gtk_widget_create_pango_layout (widget, NULL);
2534 attr_list = pango_attr_list_new ();
2535 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2537 pango_layout_set_attributes (layout, attr_list);
2538 pango_attr_list_unref (attr_list);
2540 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2542 gchar text[7] = { 0, };
2545 len = g_unichar_to_utf8 (invisible_chars[i], text);
2546 pango_layout_set_text (layout, text, len);
2548 count = pango_layout_get_unknown_glyphs_count (layout);
2552 g_object_unref (layout);
2553 return invisible_chars[i];
2557 g_object_unref (layout);
2563 gtk_entry_init (GtkEntry *entry)
2565 GtkStyleContext *context;
2566 GtkEntryPrivate *priv;
2568 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2573 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2574 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2576 priv->editable = TRUE;
2577 priv->visible = TRUE;
2578 priv->dnd_position = -1;
2579 priv->width_chars = -1;
2580 priv->is_cell_renderer = FALSE;
2581 priv->editing_canceled = FALSE;
2582 priv->has_frame = TRUE;
2583 priv->truncate_multiline = FALSE;
2584 priv->shadow_type = GTK_SHADOW_IN;
2586 priv->caps_lock_warning = TRUE;
2587 priv->caps_lock_warning_shown = FALSE;
2588 priv->progress_fraction = 0.0;
2589 priv->progress_pulse_fraction = 0.1;
2591 gtk_drag_dest_set (GTK_WIDGET (entry),
2592 GTK_DEST_DEFAULT_HIGHLIGHT,
2594 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2595 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2597 /* This object is completely private. No external entity can gain a reference
2598 * to it; so we create it here and destroy it in finalize().
2600 priv->im_context = gtk_im_multicontext_new ();
2602 g_signal_connect (priv->im_context, "commit",
2603 G_CALLBACK (gtk_entry_commit_cb), entry);
2604 g_signal_connect (priv->im_context, "preedit-changed",
2605 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2606 g_signal_connect (priv->im_context, "retrieve-surrounding",
2607 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2608 g_signal_connect (priv->im_context, "delete-surrounding",
2609 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2611 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2612 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2614 gtk_entry_update_cached_style_values (entry);
2616 priv->text_handle = _gtk_text_handle_new (GTK_WIDGET (entry));
2617 g_signal_connect (priv->text_handle, "handle-dragged",
2618 G_CALLBACK (gtk_entry_handle_dragged), entry);
2619 g_signal_connect (priv->text_handle, "drag-finished",
2620 G_CALLBACK (gtk_entry_handle_drag_finished), entry);
2624 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2625 GtkStyleContext *context,
2626 GtkEntryIconPosition icon_pos)
2628 GtkEntryPrivate *priv = entry->priv;
2629 EntryIconInfo *icon_info = priv->icons[icon_pos];
2631 GtkStateFlags state;
2633 widget = GTK_WIDGET (entry);
2634 state = gtk_widget_get_state_flags (widget);
2636 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2638 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2639 state |= GTK_STATE_FLAG_INSENSITIVE;
2640 else if (icon_info->prelight)
2641 state |= GTK_STATE_FLAG_PRELIGHT;
2643 gtk_style_context_save (context);
2645 gtk_style_context_set_state (context, state);
2646 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2648 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2650 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2651 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2653 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2657 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2658 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2660 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2665 get_icon_width (GtkEntry *entry,
2666 GtkEntryIconPosition icon_pos)
2668 GtkEntryPrivate *priv = entry->priv;
2669 EntryIconInfo *icon_info = priv->icons[icon_pos];
2670 GtkStyleContext *context;
2677 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2678 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2679 gtk_style_context_get_padding (context, 0, &padding);
2681 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2683 gtk_style_context_restore (context);
2686 width += padding.left + padding.right;
2692 get_icon_allocations (GtkEntry *entry,
2693 GtkAllocation *primary,
2694 GtkAllocation *secondary)
2697 GtkEntryPrivate *priv = entry->priv;
2698 gint x, y, width, height;
2700 get_text_area_size (entry, &x, &y, &width, &height);
2702 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2703 y += priv->focus_width;
2706 primary->height = height;
2707 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2710 secondary->height = height;
2711 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2713 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2715 primary->x = x + width - primary->width;
2721 secondary->x = x + width - secondary->width;
2727 begin_change (GtkEntry *entry)
2729 GtkEntryPrivate *priv = entry->priv;
2731 priv->change_count++;
2733 g_object_freeze_notify (G_OBJECT (entry));
2737 end_change (GtkEntry *entry)
2739 GtkEditable *editable = GTK_EDITABLE (entry);
2740 GtkEntryPrivate *priv = entry->priv;
2742 g_return_if_fail (priv->change_count > 0);
2744 g_object_thaw_notify (G_OBJECT (entry));
2746 priv->change_count--;
2748 if (priv->change_count == 0)
2750 if (priv->real_changed)
2752 g_signal_emit_by_name (editable, "changed");
2753 priv->real_changed = FALSE;
2759 emit_changed (GtkEntry *entry)
2761 GtkEditable *editable = GTK_EDITABLE (entry);
2762 GtkEntryPrivate *priv = entry->priv;
2764 if (priv->change_count == 0)
2765 g_signal_emit_by_name (editable, "changed");
2767 priv->real_changed = TRUE;
2771 gtk_entry_destroy (GtkWidget *widget)
2773 GtkEntry *entry = GTK_ENTRY (widget);
2774 GtkEntryPrivate *priv = entry->priv;
2776 priv->current_pos = priv->selection_bound = 0;
2777 gtk_entry_reset_im_context (entry);
2778 gtk_entry_reset_layout (entry);
2780 if (priv->blink_timeout)
2782 g_source_remove (priv->blink_timeout);
2783 priv->blink_timeout = 0;
2786 if (priv->recompute_idle)
2788 g_source_remove (priv->recompute_idle);
2789 priv->recompute_idle = 0;
2792 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2796 gtk_entry_dispose (GObject *object)
2798 GtkEntry *entry = GTK_ENTRY (object);
2799 GtkEntryPrivate *priv = entry->priv;
2802 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2803 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2804 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2805 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2806 gtk_entry_set_completion (entry, NULL);
2810 buffer_disconnect_signals (entry);
2811 g_object_unref (priv->buffer);
2812 priv->buffer = NULL;
2815 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2816 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2817 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2818 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2822 gtk_entry_finalize (GObject *object)
2824 GtkEntry *entry = GTK_ENTRY (object);
2825 GtkEntryPrivate *priv = entry->priv;
2826 EntryIconInfo *icon_info = NULL;
2829 for (i = 0; i < MAX_ICONS; i++)
2831 if ((icon_info = priv->icons[i]) != NULL)
2833 if (icon_info->target_list != NULL)
2835 gtk_target_list_unref (icon_info->target_list);
2836 icon_info->target_list = NULL;
2839 g_clear_object (&icon_info->icon_helper);
2841 g_slice_free (EntryIconInfo, icon_info);
2842 priv->icons[i] = NULL;
2846 if (priv->cached_layout)
2847 g_object_unref (priv->cached_layout);
2849 g_object_unref (priv->im_context);
2851 if (priv->blink_timeout)
2852 g_source_remove (priv->blink_timeout);
2854 if (priv->recompute_idle)
2855 g_source_remove (priv->recompute_idle);
2857 if (priv->selection_bubble)
2858 gtk_widget_destroy (priv->selection_bubble);
2860 g_object_unref (priv->text_handle);
2861 g_free (priv->placeholder_text);
2862 g_free (priv->im_module);
2864 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2868 gtk_entry_get_display_mode (GtkEntry *entry)
2870 GtkEntryPrivate *priv = entry->priv;
2873 return DISPLAY_NORMAL;
2875 if (priv->invisible_char == 0 && priv->invisible_char_set)
2876 return DISPLAY_BLANK;
2878 return DISPLAY_INVISIBLE;
2882 _gtk_entry_get_display_text (GtkEntry *entry,
2886 GtkEntryPasswordHint *password_hint;
2887 GtkEntryPrivate *priv;
2888 gunichar invisible_char;
2899 text = gtk_entry_buffer_get_text (get_buffer (entry));
2900 length = gtk_entry_buffer_get_length (get_buffer (entry));
2904 if (start_pos > length)
2907 if (end_pos <= start_pos)
2908 return g_strdup ("");
2909 else if (priv->visible)
2911 start = g_utf8_offset_to_pointer (text, start_pos);
2912 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2913 return g_strndup (start, end - start);
2917 str = g_string_sized_new (length * 2);
2919 /* Figure out what our invisible char is and encode it */
2920 if (!priv->invisible_char)
2921 invisible_char = priv->invisible_char_set ? ' ' : '*';
2923 invisible_char = priv->invisible_char;
2924 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2927 * Add hidden characters for each character in the text
2928 * buffer. If there is a password hint, then keep that
2929 * character visible.
2932 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2933 for (i = start_pos; i < end_pos; ++i)
2935 if (password_hint && i == password_hint->position)
2937 start = g_utf8_offset_to_pointer (text, i);
2938 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2942 g_string_append_len (str, char_str, char_len);
2946 return g_string_free (str, FALSE);
2951 update_cursors (GtkWidget *widget)
2953 GtkEntry *entry = GTK_ENTRY (widget);
2954 GtkEntryPrivate *priv = entry->priv;
2955 EntryIconInfo *icon_info = NULL;
2956 GdkDisplay *display;
2960 for (i = 0; i < MAX_ICONS; i++)
2962 if ((icon_info = priv->icons[i]) != NULL)
2964 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2965 icon_info->window != NULL)
2966 gdk_window_show_unraised (icon_info->window);
2968 /* The icon windows are not children of the visible entry window,
2969 * thus we can't just inherit the xterm cursor. Slight complication
2970 * here is that for the entry, insensitive => arrow cursor, but for
2971 * an icon in a sensitive entry, insensitive => xterm cursor.
2973 if (gtk_widget_is_sensitive (widget) &&
2974 (icon_info->insensitive ||
2975 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2977 display = gtk_widget_get_display (widget);
2978 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2979 gdk_window_set_cursor (icon_info->window, cursor);
2980 g_object_unref (cursor);
2984 gdk_window_set_cursor (icon_info->window, NULL);
2991 realize_icon_info (GtkWidget *widget,
2992 GtkEntryIconPosition icon_pos)
2994 GtkEntry *entry = GTK_ENTRY (widget);
2995 GtkEntryPrivate *priv = entry->priv;
2996 EntryIconInfo *icon_info = priv->icons[icon_pos];
2997 GdkWindowAttr attributes;
2998 gint attributes_mask;
3000 g_return_if_fail (icon_info != NULL);
3004 attributes.width = 1;
3005 attributes.height = 1;
3006 attributes.window_type = GDK_WINDOW_CHILD;
3007 attributes.wclass = GDK_INPUT_ONLY;
3008 attributes.event_mask = gtk_widget_get_events (widget);
3009 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3010 GDK_BUTTON_RELEASE_MASK |
3011 GDK_BUTTON1_MOTION_MASK |
3012 GDK_BUTTON3_MOTION_MASK |
3013 GDK_POINTER_MOTION_HINT_MASK |
3014 GDK_POINTER_MOTION_MASK |
3015 GDK_ENTER_NOTIFY_MASK |
3016 GDK_LEAVE_NOTIFY_MASK);
3017 attributes_mask = GDK_WA_X | GDK_WA_Y;
3019 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
3022 gtk_widget_register_window (widget, icon_info->window);
3024 gtk_widget_queue_resize (widget);
3027 static EntryIconInfo*
3028 construct_icon_info (GtkWidget *widget,
3029 GtkEntryIconPosition icon_pos)
3031 GtkEntry *entry = GTK_ENTRY (widget);
3032 GtkEntryPrivate *priv = entry->priv;
3033 EntryIconInfo *icon_info;
3035 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
3037 icon_info = g_slice_new0 (EntryIconInfo);
3038 priv->icons[icon_pos] = icon_info;
3040 icon_info->icon_helper = _gtk_icon_helper_new ();
3041 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
3043 if (gtk_widget_get_realized (widget))
3044 realize_icon_info (widget, icon_pos);
3050 gtk_entry_map (GtkWidget *widget)
3052 GtkEntry *entry = GTK_ENTRY (widget);
3053 GtkEntryPrivate *priv = entry->priv;
3054 EntryIconInfo *icon_info = NULL;
3057 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
3059 gdk_window_show (priv->text_area);
3061 for (i = 0; i < MAX_ICONS; i++)
3063 if ((icon_info = priv->icons[i]) != NULL)
3065 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3066 icon_info->window != NULL)
3067 gdk_window_show (icon_info->window);
3071 update_cursors (widget);
3075 gtk_entry_unmap (GtkWidget *widget)
3077 GtkEntry *entry = GTK_ENTRY (widget);
3078 GtkEntryPrivate *priv = entry->priv;
3079 EntryIconInfo *icon_info = NULL;
3082 _gtk_text_handle_set_mode (priv->text_handle,
3083 GTK_TEXT_HANDLE_MODE_NONE);
3085 for (i = 0; i < MAX_ICONS; i++)
3087 if ((icon_info = priv->icons[i]) != NULL)
3089 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3090 icon_info->window != NULL)
3091 gdk_window_hide (icon_info->window);
3095 gdk_window_hide (priv->text_area);
3097 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
3101 gtk_entry_realize (GtkWidget *widget)
3104 GtkEntryPrivate *priv;
3105 EntryIconInfo *icon_info;
3107 GdkWindowAttr attributes;
3108 gint attributes_mask;
3109 gint frame_x, frame_y;
3112 gtk_widget_set_realized (widget, TRUE);
3113 window = gtk_widget_get_parent_window (widget);
3114 gtk_widget_set_window (widget, window);
3115 g_object_ref (window);
3117 entry = GTK_ENTRY (widget);
3120 attributes.window_type = GDK_WINDOW_CHILD;
3121 attributes.wclass = GDK_INPUT_ONLY;
3122 attributes.event_mask = gtk_widget_get_events (widget);
3123 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3124 GDK_BUTTON_RELEASE_MASK |
3125 GDK_BUTTON1_MOTION_MASK |
3126 GDK_BUTTON3_MOTION_MASK |
3127 GDK_POINTER_MOTION_HINT_MASK |
3128 GDK_POINTER_MOTION_MASK |
3129 GDK_ENTER_NOTIFY_MASK |
3130 GDK_LEAVE_NOTIFY_MASK);
3131 attributes_mask = GDK_WA_X | GDK_WA_Y;
3133 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3135 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3136 attributes.x += frame_x;
3137 attributes.y += frame_y;
3139 if (gtk_widget_is_sensitive (widget))
3141 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3142 attributes_mask |= GDK_WA_CURSOR;
3145 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3149 gtk_widget_register_window (widget, priv->text_area);
3151 if (attributes_mask & GDK_WA_CURSOR)
3152 g_object_unref (attributes.cursor);
3154 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3156 gtk_entry_adjust_scroll (entry);
3157 gtk_entry_update_primary_selection (entry);
3158 _gtk_text_handle_set_relative_to (priv->text_handle, priv->text_area);
3160 /* If the icon positions are already setup, create their windows.
3161 * Otherwise if they don't exist yet, then construct_icon_info()
3162 * will create the windows once the widget is already realized.
3164 for (i = 0; i < MAX_ICONS; i++)
3166 if ((icon_info = priv->icons[i]) != NULL)
3168 if (icon_info->window == NULL)
3169 realize_icon_info (widget, i);
3175 gtk_entry_unrealize (GtkWidget *widget)
3177 GtkEntry *entry = GTK_ENTRY (widget);
3178 GtkEntryPrivate *priv = entry->priv;
3179 GtkClipboard *clipboard;
3180 EntryIconInfo *icon_info;
3183 gtk_entry_reset_layout (entry);
3185 gtk_im_context_set_client_window (priv->im_context, NULL);
3186 _gtk_text_handle_set_relative_to (priv->text_handle, NULL);
3188 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3189 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3190 gtk_clipboard_clear (clipboard);
3192 if (priv->text_area)
3194 gtk_widget_unregister_window (widget, priv->text_area);
3195 gdk_window_destroy (priv->text_area);
3196 priv->text_area = NULL;
3199 if (priv->popup_menu)
3201 gtk_widget_destroy (priv->popup_menu);
3202 priv->popup_menu = NULL;
3205 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3207 for (i = 0; i < MAX_ICONS; i++)
3209 if ((icon_info = priv->icons[i]) != NULL)
3211 if (icon_info->window != NULL)
3213 gtk_widget_unregister_window (widget, icon_info->window);
3214 gdk_window_destroy (icon_info->window);
3215 icon_info->window = NULL;
3222 _gtk_entry_get_borders (GtkEntry *entry,
3223 GtkBorder *border_out)
3225 GtkEntryPrivate *priv = entry->priv;
3226 GtkWidget *widget = GTK_WIDGET (entry);
3227 GtkBorder tmp = { 0, 0, 0, 0 };
3228 GtkStyleContext *context;
3230 context = gtk_widget_get_style_context (widget);
3231 gtk_style_context_get_padding (context, 0, &tmp);
3233 if (priv->has_frame)
3237 gtk_style_context_get_border (context, 0, &border);
3238 tmp.top += border.top;
3239 tmp.right += border.right;
3240 tmp.bottom += border.bottom;
3241 tmp.left += border.left;
3244 if (!priv->interior_focus)
3246 tmp.top += priv->focus_width;
3247 tmp.right += priv->focus_width;
3248 tmp.bottom += priv->focus_width;
3249 tmp.left += priv->focus_width;
3252 if (border_out != NULL)
3257 gtk_entry_get_preferred_width (GtkWidget *widget,
3261 GtkEntry *entry = GTK_ENTRY (widget);
3262 GtkEntryPrivate *priv = entry->priv;
3263 PangoFontMetrics *metrics;
3265 PangoContext *context;
3266 gint icon_widths = 0;
3270 context = gtk_widget_get_pango_context (widget);
3272 metrics = pango_context_get_metrics (context,
3273 pango_context_get_font_description (context),
3274 pango_context_get_language (context));
3276 _gtk_entry_get_borders (entry, &borders);
3278 if (priv->width_chars < 0)
3279 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3282 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3283 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3284 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3286 width = char_pixels * priv->width_chars + borders.left + borders.right;
3289 for (i = 0; i < MAX_ICONS; i++)
3291 icon_width = get_icon_width (entry, i);
3293 icon_widths += icon_width;
3296 if (icon_widths > width)
3297 width += icon_widths;
3299 pango_font_metrics_unref (metrics);
3306 gtk_entry_get_preferred_height (GtkWidget *widget,
3310 GtkEntry *entry = GTK_ENTRY (widget);
3311 GtkEntryPrivate *priv = entry->priv;
3312 PangoFontMetrics *metrics;
3314 PangoContext *context;
3316 PangoLayout *layout;
3318 layout = gtk_entry_ensure_layout (entry, TRUE);
3319 context = gtk_widget_get_pango_context (widget);
3321 metrics = pango_context_get_metrics (context,
3322 pango_context_get_font_description (context),
3323 pango_context_get_language (context));
3325 priv->ascent = pango_font_metrics_get_ascent (metrics);
3326 priv->descent = pango_font_metrics_get_descent (metrics);
3327 pango_font_metrics_unref (metrics);
3329 _gtk_entry_get_borders (entry, &borders);
3330 pango_layout_get_pixel_size (layout, NULL, &height);
3332 height += borders.top + borders.bottom;
3339 place_windows (GtkEntry *entry)
3341 GtkWidget *widget = GTK_WIDGET (entry);
3342 GtkEntryPrivate *priv = entry->priv;
3343 gint x, y, width, height;
3344 gint frame_x, frame_y;
3345 GtkAllocation primary;
3346 GtkAllocation secondary;
3347 EntryIconInfo *icon_info = NULL;
3349 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3350 get_text_area_size (entry, &x, &y, &width, &height);
3351 get_icon_allocations (entry, &primary, &secondary);
3353 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3354 y += priv->focus_width;
3356 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3357 x += secondary.width;
3360 width -= primary.width + secondary.width;
3364 primary.x += frame_x;
3365 primary.y += frame_y;
3366 secondary.x += frame_x;
3367 secondary.y += frame_y;
3369 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3370 gdk_window_move_resize (icon_info->window,
3371 primary.x, primary.y,
3372 primary.width, primary.height);
3374 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3375 gdk_window_move_resize (icon_info->window,
3376 secondary.x, secondary.y,
3377 secondary.width, secondary.height);
3379 gdk_window_move_resize (priv->text_area, x, y, width, height);
3383 gtk_entry_get_text_area_size (GtkEntry *entry,
3389 GtkEntryPrivate *priv = entry->priv;
3390 GtkWidget *widget = GTK_WIDGET (entry);
3391 GtkAllocation allocation;
3392 GtkRequisition requisition;
3397 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3398 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3400 gtk_widget_get_allocation (widget, &allocation);
3401 _gtk_entry_get_borders (entry, &borders);
3403 if (gtk_widget_get_realized (widget))
3404 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3406 frame_height = req_height;
3408 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3409 frame_height -= 2 * priv->focus_width;
3415 *y = floor ((frame_height - req_height) / 2) + borders.top;
3418 *width = allocation.width - borders.left - borders.right;
3421 *height = req_height - borders.top - borders.bottom;
3425 get_text_area_size (GtkEntry *entry,
3431 GtkEntryClass *class;
3433 g_return_if_fail (GTK_IS_ENTRY (entry));
3435 class = GTK_ENTRY_GET_CLASS (entry);
3437 if (class->get_text_area_size)
3438 class->get_text_area_size (entry, x, y, width, height);
3443 gtk_entry_get_frame_size (GtkEntry *entry,
3449 GtkEntryPrivate *priv = entry->priv;
3450 GtkAllocation allocation;
3451 GtkRequisition requisition;
3452 GtkWidget *widget = GTK_WIDGET (entry);
3455 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3457 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3459 gtk_widget_get_allocation (widget, &allocation);
3466 if (priv->is_cell_renderer)
3469 *y = (allocation.height - req_height) / 2;
3475 *width = allocation.width;
3479 if (priv->is_cell_renderer)
3480 *height = allocation.height;
3482 *height = req_height;
3487 get_frame_size (GtkEntry *entry,
3488 gboolean relative_to_window,
3494 GtkEntryClass *class;
3495 GtkWidget *widget = GTK_WIDGET (entry);
3497 g_return_if_fail (GTK_IS_ENTRY (entry));
3499 class = GTK_ENTRY_GET_CLASS (entry);
3501 if (class->get_frame_size)
3502 class->get_frame_size (entry, x, y, width, height);
3504 if (!relative_to_window)
3506 GtkAllocation allocation;
3507 gtk_widget_get_allocation (widget, &allocation);
3517 gtk_entry_size_allocate (GtkWidget *widget,
3518 GtkAllocation *allocation)
3520 GtkEntry *entry = GTK_ENTRY (widget);
3522 gtk_widget_set_allocation (widget, allocation);
3524 if (gtk_widget_get_realized (widget))
3526 GtkEntryCompletion* completion;
3528 place_windows (entry);
3529 gtk_entry_recompute (entry);
3531 completion = gtk_entry_get_completion (entry);
3533 _gtk_entry_completion_resize_popup (completion);
3538 should_prelight (GtkEntry *entry,
3539 GtkEntryIconPosition icon_pos)
3541 GtkEntryPrivate *priv = entry->priv;
3542 EntryIconInfo *icon_info = priv->icons[icon_pos];
3548 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3551 if (icon_info->pressed)
3554 gtk_widget_style_get (GTK_WIDGET (entry),
3555 "icon-prelight", &prelight,
3562 draw_icon (GtkWidget *widget,
3564 GtkEntryIconPosition icon_pos)
3566 GtkEntry *entry = GTK_ENTRY (widget);
3567 GtkEntryPrivate *priv = entry->priv;
3568 EntryIconInfo *icon_info = priv->icons[icon_pos];
3569 gint x, y, width, height, pix_width, pix_height;
3570 GtkStyleContext *context;
3576 width = gdk_window_get_width (icon_info->window);
3577 height = gdk_window_get_height (icon_info->window);
3579 /* size_allocate hasn't been called yet. These are the default values.
3581 if (width == 1 || height == 1)
3585 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3587 context = gtk_widget_get_style_context (widget);
3588 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3589 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3590 &pix_width, &pix_height);
3591 gtk_style_context_get_padding (context, 0, &padding);
3593 x = MAX (0, padding.left);
3594 y = MAX (0, (height - pix_height) / 2);
3596 _gtk_icon_helper_draw (icon_info->icon_helper,
3600 gtk_style_context_restore (context);
3606 gtk_entry_draw_frame (GtkWidget *widget,
3607 GtkStyleContext *context,
3610 GtkEntry *entry = GTK_ENTRY (widget);
3611 GtkEntryPrivate *priv = entry->priv;
3612 gint x = 0, y = 0, width, height;
3613 gint frame_x, frame_y;
3617 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3619 cairo_translate (cr, frame_x, frame_y);
3621 /* Fix a problem with some themes which assume that entry->text_area's
3622 * width equals widget->window's width
3623 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3624 if (GTK_IS_SPIN_BUTTON (widget))
3628 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3629 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3632 width += borders.left + borders.right;
3635 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3637 x += priv->focus_width;
3638 y += priv->focus_width;
3639 width -= 2 * priv->focus_width;
3640 height -= 2 * priv->focus_width;
3643 gtk_render_background (context, cr,
3644 x, y, width, height);
3646 if (priv->has_frame)
3647 gtk_render_frame (context, cr,
3648 x, y, width, height);
3650 gtk_entry_draw_progress (widget, context, cr);
3652 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3654 x -= priv->focus_width;
3655 y -= priv->focus_width;
3656 width += 2 * priv->focus_width;
3657 height += 2 * priv->focus_width;
3659 gtk_render_focus (context, cr,
3660 0, 0, width, height);
3667 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3668 GtkStyleContext *context)
3670 GtkEntryPrivate *private = entry->priv;
3672 gtk_style_context_save (context);
3673 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3674 if (private->progress_pulse_mode)
3675 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3679 get_progress_area (GtkWidget *widget,
3685 GtkEntry *entry = GTK_ENTRY (widget);
3686 GtkEntryPrivate *private = entry->priv;
3687 GtkStyleContext *context;
3688 GtkBorder margin, border, entry_borders;
3689 gint frame_width, text_area_width, text_area_height;
3691 context = gtk_widget_get_style_context (widget);
3692 _gtk_entry_get_borders (entry, &entry_borders);
3693 get_text_area_size (entry,
3695 &text_area_width, &text_area_height);
3696 get_frame_size (entry, FALSE,
3698 &frame_width, NULL);
3702 *width = text_area_width + entry_borders.left + entry_borders.right;
3703 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3705 /* if the text area got resized by a subclass, subtract the left/right
3706 * border width, so that the progress bar won't extend over the resized
3709 if (frame_width > *width)
3711 gtk_style_context_get_border (context, 0, &border);
3712 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3714 *x = (frame_width - *width) + border.left;
3715 *width -= border.left;
3719 *width -= border.right;
3723 gtk_entry_prepare_context_for_progress (entry, context);
3724 gtk_style_context_get_margin (context, 0, &margin);
3726 gtk_style_context_restore (context);
3730 *width -= margin.left + margin.right;
3731 *height -= margin.top + margin.bottom;
3733 if (private->progress_pulse_mode)
3735 gdouble value = private->progress_pulse_current;
3737 *x += (gint) floor(value * (*width));
3738 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3740 else if (private->progress_fraction > 0)
3742 gdouble value = private->progress_fraction;
3744 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3748 bar_width = floor(value * (*width) + 0.5);
3749 *x += *width - bar_width;
3754 *width = (gint) floor(value * (*width) + 0.5);
3765 gtk_entry_draw_progress (GtkWidget *widget,
3766 GtkStyleContext *context,
3769 GtkEntry *entry = GTK_ENTRY (widget);
3770 gint x, y, width, height;
3772 get_progress_area (widget, &x, &y, &width, &height);
3774 if ((width <= 0) || (height <= 0))
3777 gtk_entry_prepare_context_for_progress (entry, context);
3778 gtk_render_activity (context, cr,
3779 x, y, width, height);
3781 gtk_style_context_restore (context);
3785 gtk_entry_draw (GtkWidget *widget,
3788 GtkEntry *entry = GTK_ENTRY (widget);
3789 GtkStyleContext *context;
3790 GtkEntryPrivate *priv = entry->priv;
3793 if (gtk_cairo_should_draw_window (cr,
3794 gtk_widget_get_window (widget)))
3796 context = gtk_widget_get_style_context (widget);
3798 /* Draw entry_bg, shadow, progress and focus */
3799 gtk_entry_draw_frame (widget, context, cr);
3801 /* Draw text and cursor */
3804 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3806 if (priv->dnd_position != -1)
3807 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3809 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3811 /* When no text is being displayed at all, don't show the cursor */
3812 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3813 gtk_widget_has_focus (widget) &&
3814 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3815 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3820 for (i = 0; i < MAX_ICONS; i++)
3822 EntryIconInfo *icon_info = priv->icons[i];
3824 if (icon_info != NULL)
3825 draw_icon (widget, cr, i);
3833 gtk_entry_enter_notify (GtkWidget *widget,
3834 GdkEventCrossing *event)
3836 GtkEntry *entry = GTK_ENTRY (widget);
3837 GtkEntryPrivate *priv = entry->priv;
3840 for (i = 0; i < MAX_ICONS; i++)
3842 EntryIconInfo *icon_info = priv->icons[i];
3844 if (icon_info != NULL && event->window == icon_info->window)
3846 if (should_prelight (entry, i))
3848 icon_info->prelight = TRUE;
3849 gtk_widget_queue_draw (widget);
3860 gtk_entry_leave_notify (GtkWidget *widget,
3861 GdkEventCrossing *event)
3863 GtkEntry *entry = GTK_ENTRY (widget);
3864 GtkEntryPrivate *priv = entry->priv;
3867 for (i = 0; i < MAX_ICONS; i++)
3869 EntryIconInfo *icon_info = priv->icons[i];
3871 if (icon_info != NULL && event->window == icon_info->window)
3873 /* a grab means that we may never see the button release */
3874 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3875 icon_info->pressed = FALSE;
3877 if (should_prelight (entry, i))
3879 icon_info->prelight = FALSE;
3880 gtk_widget_queue_draw (widget);
3891 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3895 gint start_char, end_char;
3897 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3899 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3900 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3901 const char *text = pango_layout_get_text (layout);
3902 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3903 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3904 gint real_n_ranges, i;
3906 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3912 for (i = 0; i < real_n_ranges; ++i)
3914 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3915 r[2 * i] = r[2 * i] / PANGO_SCALE;
3920 *n_ranges = real_n_ranges;
3932 in_selection (GtkEntry *entry,
3937 gint retval = FALSE;
3939 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3941 for (i = 0; i < n_ranges; ++i)
3943 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3955 gtk_entry_move_handle (GtkEntry *entry,
3956 GtkTextHandlePosition pos,
3961 GtkEntryPrivate *priv = entry->priv;
3963 if (!_gtk_text_handle_get_is_dragged (priv->text_handle, pos) &&
3964 (x < 0 || x > gdk_window_get_width (priv->text_area)))
3966 /* Hide the handle if it's not being manipulated
3967 * and fell outside of the visible text area.
3969 _gtk_text_handle_set_visible (priv->text_handle, pos, FALSE);
3975 rect.x = CLAMP (x, 0, gdk_window_get_width (priv->text_area));
3978 rect.height = height;
3980 _gtk_text_handle_set_visible (priv->text_handle, pos, TRUE);
3981 _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
3986 gtk_entry_get_selection_bound_location (GtkEntry *entry)
3988 GtkEntryPrivate *priv = entry->priv;
3989 PangoLayout *layout;
3995 layout = gtk_entry_ensure_layout (entry, FALSE);
3996 text = pango_layout_get_text (layout);
3997 index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text;
3998 pango_layout_index_to_pos (layout, index, &pos);
4000 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
4001 x = (pos.x + pos.width) / PANGO_SCALE;
4003 x = pos.x / PANGO_SCALE;
4009 gtk_entry_update_handles (GtkEntry *entry,
4010 GtkTextHandleMode mode)
4012 GtkEntryPrivate *priv = entry->priv;
4013 gint strong_x, height;
4016 _gtk_text_handle_set_mode (priv->text_handle, mode);
4018 /* Wait for recomputation before repositioning */
4019 if (priv->recompute_idle != 0)
4022 height = gdk_window_get_height (priv->text_area);
4024 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
4025 cursor = strong_x - priv->scroll_offset;
4027 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
4031 bound = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
4033 if (priv->selection_bound > priv->current_pos)
4044 /* Update start selection bound */
4045 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_START,
4047 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_END,
4051 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_CURSOR,
4056 gtk_entry_button_press (GtkWidget *widget,
4057 GdkEventButton *event)
4059 GtkEntry *entry = GTK_ENTRY (widget);
4060 GtkEditable *editable = GTK_EDITABLE (widget);
4061 GtkEntryPrivate *priv = entry->priv;
4062 EntryIconInfo *icon_info = NULL;
4064 gint sel_start, sel_end;
4067 gtk_entry_selection_bubble_popup_unset (entry);
4069 for (i = 0; i < MAX_ICONS; i++)
4071 icon_info = priv->icons[i];
4073 if (!icon_info || icon_info->insensitive)
4076 if (event->window == icon_info->window)
4078 if (should_prelight (entry, i))
4080 icon_info->prelight = FALSE;
4081 gtk_widget_queue_draw (widget);
4084 priv->start_x = event->x;
4085 priv->start_y = event->y;
4086 icon_info->pressed = TRUE;
4088 if (!icon_info->nonactivatable)
4089 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
4095 if (event->window != priv->text_area ||
4096 (priv->button && event->button != priv->button))
4099 gtk_entry_reset_blink_time (entry);
4101 priv->button = event->button;
4102 priv->device = gdk_event_get_device ((GdkEvent *) event);
4104 if (!gtk_widget_has_focus (widget))
4106 priv->in_click = TRUE;
4107 gtk_widget_grab_focus (widget);
4108 priv->in_click = FALSE;
4111 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4113 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
4115 gtk_entry_do_popup (entry, event);
4116 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
4117 priv->device = NULL;
4121 else if (event->button == GDK_BUTTON_PRIMARY)
4123 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
4124 gboolean is_touchscreen;
4127 source = gdk_event_get_source_device ((GdkEvent *) event);
4128 is_touchscreen = test_touchscreen ||
4129 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN;
4131 priv->select_words = FALSE;
4132 priv->select_lines = FALSE;
4135 gtk_widget_get_modifier_mask (widget,
4136 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
4138 gtk_entry_reset_im_context (entry);
4140 if (!have_selection) /* select from the current position to the clicked position */
4141 sel_start = sel_end = priv->current_pos;
4143 if (tmp_pos > sel_start && tmp_pos < sel_end)
4145 /* Truncate current selection, but keep it as big as possible */
4146 if (tmp_pos - sel_start > sel_end - tmp_pos)
4147 gtk_entry_set_positions (entry, sel_start, tmp_pos);
4149 gtk_entry_set_positions (entry, tmp_pos, sel_end);
4153 gboolean extend_to_left;
4156 /* Figure out what click selects and extend current selection */
4157 switch (event->type)
4159 case GDK_BUTTON_PRESS:
4160 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
4163 case GDK_2BUTTON_PRESS:
4164 priv->select_words = TRUE;
4165 gtk_entry_select_word (entry);
4168 case GDK_3BUTTON_PRESS:
4169 priv->select_lines = TRUE;
4170 gtk_entry_select_line (entry);
4177 start = MIN (priv->current_pos, priv->selection_bound);
4178 start = MIN (sel_start, start);
4180 end = MAX (priv->current_pos, priv->selection_bound);
4181 end = MAX (sel_end, end);
4183 if (tmp_pos == sel_start || tmp_pos == sel_end)
4184 extend_to_left = (tmp_pos == start);
4186 extend_to_left = (end == sel_end);
4189 gtk_entry_set_positions (entry, start, end);
4191 gtk_entry_set_positions (entry, end, start);
4194 else /* no shift key */
4195 switch (event->type)
4197 case GDK_BUTTON_PRESS:
4198 if (in_selection (entry, event->x + priv->scroll_offset))
4200 /* Click inside the selection - we'll either start a drag, or
4201 * clear the selection
4203 priv->in_drag = TRUE;
4204 priv->drag_start_x = event->x + priv->scroll_offset;
4205 priv->drag_start_y = event->y;
4209 gtk_editable_set_position (editable, tmp_pos);
4212 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4216 case GDK_2BUTTON_PRESS:
4217 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4218 * receiving a GDK_2BUTTON_PRESS so we need to reset
4219 * priv->in_drag which may have been set above
4221 priv->in_drag = FALSE;
4222 priv->select_words = TRUE;
4223 gtk_entry_select_word (entry);
4226 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4229 case GDK_3BUTTON_PRESS:
4230 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4231 * receiving a GDK_3BUTTON_PRESS so we need to reset
4232 * priv->in_drag which may have been set above
4234 priv->in_drag = FALSE;
4235 priv->select_lines = TRUE;
4236 gtk_entry_select_line (entry);
4238 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4247 else if (event->type == GDK_BUTTON_PRESS &&
4248 event->button == GDK_BUTTON_MIDDLE &&
4249 get_middle_click_paste (entry))
4253 priv->insert_pos = tmp_pos;
4254 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
4259 gtk_widget_error_bell (widget);
4267 gtk_entry_button_release (GtkWidget *widget,
4268 GdkEventButton *event)
4270 GtkEntry *entry = GTK_ENTRY (widget);
4271 GtkEntryPrivate *priv = entry->priv;
4272 EntryIconInfo *icon_info = NULL;
4273 gboolean is_touchscreen;
4277 for (i = 0; i < MAX_ICONS; i++)
4279 icon_info = priv->icons[i];
4281 if (!icon_info || icon_info->insensitive)
4284 if (event->window == icon_info->window)
4286 icon_info->pressed = FALSE;
4288 if (should_prelight (entry, i) &&
4289 event->x >= 0 && event->y >= 0 &&
4290 event->x < gdk_window_get_width (icon_info->window) &&
4291 event->y < gdk_window_get_height (icon_info->window))
4293 icon_info->prelight = TRUE;
4294 gtk_widget_queue_draw (widget);
4297 if (!icon_info->nonactivatable)
4298 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4304 if (event->window != priv->text_area || priv->button != event->button)
4307 source = gdk_event_get_source_device ((GdkEvent *) event);
4308 is_touchscreen = (test_touchscreen ||
4309 gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN);
4313 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4315 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4318 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4322 else if (is_touchscreen)
4323 gtk_entry_selection_bubble_popup_set (entry);
4326 priv->device = NULL;
4328 gtk_entry_update_primary_selection (entry);
4334 _gtk_entry_get_selected_text (GtkEntry *entry)
4336 GtkEditable *editable = GTK_EDITABLE (entry);
4337 gint start_text, end_text;
4340 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4341 text = gtk_editable_get_chars (editable, start_text, end_text);
4347 gtk_entry_motion_notify (GtkWidget *widget,
4348 GdkEventMotion *event)
4350 GtkEntry *entry = GTK_ENTRY (widget);
4351 GtkEntryPrivate *priv = entry->priv;
4352 EntryIconInfo *icon_info = NULL;
4356 for (i = 0; i < MAX_ICONS; i++)
4358 icon_info = priv->icons[i];
4360 if (!icon_info || icon_info->insensitive)
4363 if (event->window == icon_info->window)
4365 if (icon_info->pressed &&
4366 icon_info->target_list != NULL &&
4367 gtk_drag_check_threshold (widget,
4373 icon_info->in_drag = TRUE;
4374 icon_info->pressed = FALSE;
4375 gtk_drag_begin (widget,
4376 icon_info->target_list,
4386 if (priv->mouse_cursor_obscured)
4390 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4391 gdk_window_set_cursor (priv->text_area, cursor);
4392 g_object_unref (cursor);
4393 priv->mouse_cursor_obscured = FALSE;
4396 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4399 if (priv->select_lines)
4402 gdk_event_request_motions (event);
4406 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4407 gtk_drag_check_threshold (widget,
4408 priv->drag_start_x, priv->drag_start_y,
4409 event->x + priv->scroll_offset, event->y))
4411 GdkDragContext *context;
4412 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4413 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4415 cairo_surface_t *surface;
4417 gtk_target_list_add_text_targets (target_list, 0);
4419 text = _gtk_entry_get_selected_text (entry);
4420 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4422 context = gtk_drag_begin (widget, target_list, actions,
4423 priv->button, (GdkEvent *)event);
4426 gtk_drag_set_icon_surface (context, surface);
4428 gtk_drag_set_icon_default (context);
4431 cairo_surface_destroy (surface);
4434 priv->in_drag = FALSE;
4436 priv->device = NULL;
4438 gtk_target_list_unref (target_list);
4443 GdkInputSource input_source;
4447 length = gtk_entry_buffer_get_length (get_buffer (entry));
4451 else if (event->y >= gdk_window_get_height (priv->text_area))
4454 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4456 source = gdk_event_get_source_device ((GdkEvent *) event);
4457 input_source = gdk_device_get_source (source);
4459 if (priv->select_words)
4462 gint old_min, old_max;
4465 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4466 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4468 pos = priv->current_pos;
4469 bound = priv->selection_bound;
4471 old_min = MIN(priv->current_pos, priv->selection_bound);
4472 old_max = MAX(priv->current_pos, priv->selection_bound);
4479 else if (old_max < max)
4484 else if (pos == old_min)
4486 if (priv->current_pos != min)
4491 if (priv->current_pos != max)
4495 gtk_entry_set_positions (entry, pos, bound);
4498 gtk_entry_set_positions (entry, tmp_pos, -1);
4500 /* Update touch handles' position */
4501 if (test_touchscreen || input_source == GDK_SOURCE_TOUCHSCREEN)
4502 gtk_entry_update_handles (entry,
4503 (priv->current_pos == priv->selection_bound) ?
4504 GTK_TEXT_HANDLE_MODE_CURSOR :
4505 GTK_TEXT_HANDLE_MODE_SELECTION);
4512 set_invisible_cursor (GdkWindow *window)
4514 GdkDisplay *display;
4517 display = gdk_window_get_display (window);
4518 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4520 gdk_window_set_cursor (window, cursor);
4522 g_object_unref (cursor);
4526 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4528 GtkEntryPrivate *priv = entry->priv;
4530 if (priv->mouse_cursor_obscured)
4533 set_invisible_cursor (priv->text_area);
4535 priv->mouse_cursor_obscured = TRUE;
4539 gtk_entry_key_press (GtkWidget *widget,
4542 GtkEntry *entry = GTK_ENTRY (widget);
4543 GtkEntryPrivate *priv = entry->priv;
4545 gtk_entry_reset_blink_time (entry);
4546 gtk_entry_pend_cursor_blink (entry);
4548 gtk_entry_selection_bubble_popup_unset (entry);
4550 if (!event->send_event)
4551 _gtk_text_handle_set_mode (priv->text_handle,
4552 GTK_TEXT_HANDLE_MODE_NONE);
4556 if (gtk_im_context_filter_keypress (priv->im_context, event))
4558 gtk_entry_obscure_mouse_cursor (entry);
4559 priv->need_im_reset = TRUE;
4564 if (event->keyval == GDK_KEY_Return ||
4565 event->keyval == GDK_KEY_KP_Enter ||
4566 event->keyval == GDK_KEY_ISO_Enter ||
4567 event->keyval == GDK_KEY_Escape)
4568 gtk_entry_reset_im_context (entry);
4570 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4571 /* Activate key bindings
4575 if (!priv->editable && event->length)
4576 gtk_widget_error_bell (widget);
4582 gtk_entry_key_release (GtkWidget *widget,
4585 GtkEntry *entry = GTK_ENTRY (widget);
4586 GtkEntryPrivate *priv = entry->priv;
4590 if (gtk_im_context_filter_keypress (priv->im_context, event))
4592 priv->need_im_reset = TRUE;
4597 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4601 gtk_entry_focus_in (GtkWidget *widget,
4602 GdkEventFocus *event)
4604 GtkEntry *entry = GTK_ENTRY (widget);
4605 GtkEntryPrivate *priv = entry->priv;
4608 gtk_widget_queue_draw (widget);
4610 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4614 priv->need_im_reset = TRUE;
4615 gtk_im_context_focus_in (priv->im_context);
4616 keymap_state_changed (keymap, entry);
4617 g_signal_connect (keymap, "state-changed",
4618 G_CALLBACK (keymap_state_changed), entry);
4621 g_signal_connect (keymap, "direction-changed",
4622 G_CALLBACK (keymap_direction_changed), entry);
4624 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4625 priv->placeholder_text != NULL)
4627 gtk_entry_recompute (entry);
4631 gtk_entry_reset_blink_time (entry);
4632 gtk_entry_check_cursor_blink (entry);
4639 gtk_entry_focus_out (GtkWidget *widget,
4640 GdkEventFocus *event)
4642 GtkEntry *entry = GTK_ENTRY (widget);
4643 GtkEntryPrivate *priv = entry->priv;
4644 GtkEntryCompletion *completion;
4647 gtk_entry_selection_bubble_popup_unset (entry);
4648 _gtk_text_handle_set_mode (priv->text_handle,
4649 GTK_TEXT_HANDLE_MODE_NONE);
4651 gtk_widget_queue_draw (widget);
4653 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4657 priv->need_im_reset = TRUE;
4658 gtk_im_context_focus_out (priv->im_context);
4659 remove_capslock_feedback (entry);
4662 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4663 priv->placeholder_text != NULL)
4665 gtk_entry_recompute (entry);
4669 gtk_entry_check_cursor_blink (entry);
4672 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4673 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4675 completion = gtk_entry_get_completion (entry);
4677 _gtk_entry_completion_popdown (completion);
4683 gtk_entry_grab_focus (GtkWidget *widget)
4685 GtkEntry *entry = GTK_ENTRY (widget);
4686 GtkEntryPrivate *priv = entry->priv;
4687 gboolean select_on_focus;
4689 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4691 if (priv->editable && !priv->in_click)
4693 g_object_get (gtk_widget_get_settings (widget),
4694 "gtk-entry-select-on-focus",
4698 if (select_on_focus)
4699 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4704 gtk_entry_direction_changed (GtkWidget *widget,
4705 GtkTextDirection previous_dir)
4707 GtkEntry *entry = GTK_ENTRY (widget);
4709 gtk_entry_recompute (entry);
4711 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4715 gtk_entry_state_flags_changed (GtkWidget *widget,
4716 GtkStateFlags previous_state)
4718 GtkEntry *entry = GTK_ENTRY (widget);
4719 GtkEntryPrivate *priv = entry->priv;
4722 if (gtk_widget_get_realized (widget))
4724 if (gtk_widget_is_sensitive (widget))
4725 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4729 gdk_window_set_cursor (priv->text_area, cursor);
4732 g_object_unref (cursor);
4734 priv->mouse_cursor_obscured = FALSE;
4736 update_cursors (widget);
4739 if (!gtk_widget_is_sensitive (widget))
4741 /* Clear any selection */
4742 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4745 gtk_entry_update_cached_style_values (entry);
4749 gtk_entry_screen_changed (GtkWidget *widget,
4750 GdkScreen *old_screen)
4752 gtk_entry_recompute (GTK_ENTRY (widget));
4755 /* GtkEditable method implementations
4758 gtk_entry_insert_text (GtkEditable *editable,
4759 const gchar *new_text,
4760 gint new_text_length,
4763 g_object_ref (editable);
4766 * The incoming text may a password or other secret. We make sure
4767 * not to copy it into temporary buffers.
4770 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4772 g_object_unref (editable);
4776 gtk_entry_delete_text (GtkEditable *editable,
4780 g_object_ref (editable);
4782 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4784 g_object_unref (editable);
4788 gtk_entry_get_chars (GtkEditable *editable,
4792 GtkEntry *entry = GTK_ENTRY (editable);
4795 gint start_index, end_index;
4797 text = gtk_entry_buffer_get_text (get_buffer (entry));
4798 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4801 end_pos = text_length;
4803 start_pos = MIN (text_length, start_pos);
4804 end_pos = MIN (text_length, end_pos);
4806 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4807 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4809 return g_strndup (text + start_index, end_index - start_index);
4813 gtk_entry_real_set_position (GtkEditable *editable,
4816 GtkEntry *entry = GTK_ENTRY (editable);
4817 GtkEntryPrivate *priv = entry->priv;
4821 length = gtk_entry_buffer_get_length (get_buffer (entry));
4822 if (position < 0 || position > length)
4825 if (position != priv->current_pos ||
4826 position != priv->selection_bound)
4828 gtk_entry_reset_im_context (entry);
4829 gtk_entry_set_positions (entry, position, position);
4834 gtk_entry_get_position (GtkEditable *editable)
4836 GtkEntry *entry = GTK_ENTRY (editable);
4837 GtkEntryPrivate *priv = entry->priv;
4839 return priv->current_pos;
4843 gtk_entry_set_selection_bounds (GtkEditable *editable,
4847 GtkEntry *entry = GTK_ENTRY (editable);
4850 length = gtk_entry_buffer_get_length (get_buffer (entry));
4856 gtk_entry_reset_im_context (entry);
4858 gtk_entry_set_positions (entry,
4860 MIN (start, length));
4862 gtk_entry_update_primary_selection (entry);
4866 gtk_entry_get_selection_bounds (GtkEditable *editable,
4870 GtkEntry *entry = GTK_ENTRY (editable);
4871 GtkEntryPrivate *priv = entry->priv;
4873 *start = priv->selection_bound;
4874 *end = priv->current_pos;
4876 return (priv->selection_bound != priv->current_pos);
4880 icon_theme_changed (GtkEntry *entry)
4882 GtkEntryPrivate *priv = entry->priv;
4885 for (i = 0; i < MAX_ICONS; i++)
4887 EntryIconInfo *icon_info = priv->icons[i];
4888 if (icon_info != NULL)
4889 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4892 gtk_widget_queue_draw (GTK_WIDGET (entry));
4896 gtk_entry_update_cached_style_values (GtkEntry *entry)
4898 GtkEntryPrivate *priv = entry->priv;
4900 gboolean interior_focus;
4902 gtk_widget_style_get (GTK_WIDGET (entry),
4903 "focus-line-width", &focus_width,
4904 "interior-focus", &interior_focus,
4906 priv->focus_width = focus_width;
4907 priv->interior_focus = interior_focus;
4909 if (!priv->invisible_char_set)
4911 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4913 if (priv->invisible_char != ch)
4915 priv->invisible_char = ch;
4916 g_object_notify (G_OBJECT (entry), "invisible-char");
4922 gtk_entry_style_updated (GtkWidget *widget)
4924 GtkEntry *entry = GTK_ENTRY (widget);
4926 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4928 gtk_entry_update_cached_style_values (entry);
4930 icon_theme_changed (entry);
4933 /* GtkCellEditable method implementations
4936 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4938 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4939 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4943 gtk_cell_editable_key_press_event (GtkEntry *entry,
4944 GdkEventKey *key_event,
4947 GtkEntryPrivate *priv = entry->priv;
4949 if (key_event->keyval == GDK_KEY_Escape)
4951 priv->editing_canceled = TRUE;
4952 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4953 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4958 /* override focus */
4959 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4961 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4962 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4971 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4974 GtkEntry *entry = GTK_ENTRY (cell_editable);
4975 GtkEntryPrivate *priv = entry->priv;
4977 priv->is_cell_renderer = TRUE;
4979 g_signal_connect (cell_editable, "activate",
4980 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4981 g_signal_connect (cell_editable, "key-press-event",
4982 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4986 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4988 if (password_hint->source_id)
4989 g_source_remove (password_hint->source_id);
4991 g_slice_free (GtkEntryPasswordHint, password_hint);
4996 gtk_entry_remove_password_hint (gpointer data)
4998 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4999 password_hint->position = -1;
5001 /* Force the string to be redrawn, but now without a visible character */
5002 gtk_entry_recompute (GTK_ENTRY (data));
5006 /* Default signal handlers
5009 gtk_entry_real_insert_text (GtkEditable *editable,
5010 const gchar *new_text,
5011 gint new_text_length,
5017 n_chars = g_utf8_strlen (new_text, new_text_length);
5020 * The actual insertion into the buffer. This will end up firing the
5021 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
5022 * buffer_notify_text(), buffer_notify_length()
5024 begin_change (GTK_ENTRY (editable));
5026 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
5028 end_change (GTK_ENTRY (editable));
5030 if (n_inserted != n_chars)
5031 gtk_widget_error_bell (GTK_WIDGET (editable));
5033 *position += n_inserted;
5037 gtk_entry_real_delete_text (GtkEditable *editable,
5042 * The actual deletion from the buffer. This will end up firing the
5043 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
5044 * buffer_notify_text(), buffer_notify_length()
5047 begin_change (GTK_ENTRY (editable));
5049 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
5051 end_change (GTK_ENTRY (editable));
5054 /* GtkEntryBuffer signal handlers
5057 buffer_inserted_text (GtkEntryBuffer *buffer,
5063 GtkEntryPrivate *priv = entry->priv;
5064 guint password_hint_timeout;
5066 gint selection_bound;
5068 current_pos = priv->current_pos;
5069 if (current_pos > position)
5070 current_pos += n_chars;
5072 selection_bound = priv->selection_bound;
5073 if (selection_bound > position)
5074 selection_bound += n_chars;
5076 gtk_entry_set_positions (entry, current_pos, selection_bound);
5078 /* Calculate the password hint if it needs to be displayed. */
5079 if (n_chars == 1 && !priv->visible)
5081 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5082 "gtk-entry-password-hint-timeout", &password_hint_timeout,
5085 if (password_hint_timeout > 0)
5087 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5088 quark_password_hint);
5091 password_hint = g_slice_new0 (GtkEntryPasswordHint);
5092 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
5093 (GDestroyNotify)gtk_entry_password_hint_free);
5096 password_hint->position = position;
5097 if (password_hint->source_id)
5098 g_source_remove (password_hint->source_id);
5099 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
5100 (GSourceFunc)gtk_entry_remove_password_hint, entry);
5106 buffer_deleted_text (GtkEntryBuffer *buffer,
5111 GtkEntryPrivate *priv = entry->priv;
5112 guint end_pos = position + n_chars;
5113 gint selection_bound;
5116 current_pos = priv->current_pos;
5117 if (current_pos > position)
5118 current_pos -= MIN (current_pos, end_pos) - position;
5120 selection_bound = priv->selection_bound;
5121 if (selection_bound > position)
5122 selection_bound -= MIN (selection_bound, end_pos) - position;
5124 gtk_entry_set_positions (entry, current_pos, selection_bound);
5126 /* We might have deleted the selection */
5127 gtk_entry_update_primary_selection (entry);
5129 /* Disable the password hint if one exists. */
5132 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5133 quark_password_hint);
5136 if (password_hint->source_id)
5137 g_source_remove (password_hint->source_id);
5138 password_hint->source_id = 0;
5139 password_hint->position = -1;
5145 buffer_notify_text (GtkEntryBuffer *buffer,
5149 gtk_entry_recompute (entry);
5150 emit_changed (entry);
5151 g_object_notify (G_OBJECT (entry), "text");
5155 buffer_notify_length (GtkEntryBuffer *buffer,
5159 g_object_notify (G_OBJECT (entry), "text-length");
5163 buffer_notify_max_length (GtkEntryBuffer *buffer,
5167 g_object_notify (G_OBJECT (entry), "max-length");
5171 buffer_connect_signals (GtkEntry *entry)
5173 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
5174 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
5175 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
5176 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
5177 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
5181 buffer_disconnect_signals (GtkEntry *entry)
5183 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
5184 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
5185 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
5186 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
5187 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
5190 /* Compute the X position for an offset that corresponds to the "more important
5191 * cursor position for that offset. We use this when trying to guess to which
5192 * end of the selection we should go to when the user hits the left or
5196 get_better_cursor_x (GtkEntry *entry,
5199 GtkEntryPrivate *priv = entry->priv;
5200 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5201 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5202 gboolean split_cursor;
5204 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5205 const gchar *text = pango_layout_get_text (layout);
5206 gint index = g_utf8_offset_to_pointer (text, offset) - text;
5208 PangoRectangle strong_pos, weak_pos;
5210 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5211 "gtk-split-cursor", &split_cursor,
5214 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5217 return strong_pos.x / PANGO_SCALE;
5219 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
5223 gtk_entry_move_cursor (GtkEntry *entry,
5224 GtkMovementStep step,
5226 gboolean extend_selection)
5228 GtkEntryPrivate *priv = entry->priv;
5229 gint new_pos = priv->current_pos;
5231 gtk_entry_reset_im_context (entry);
5233 if (priv->current_pos != priv->selection_bound && !extend_selection)
5235 /* If we have a current selection and aren't extending it, move to the
5236 * start/or end of the selection as appropriate
5240 case GTK_MOVEMENT_VISUAL_POSITIONS:
5242 gint current_x = get_better_cursor_x (entry, priv->current_pos);
5243 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
5246 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
5248 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
5251 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5252 case GTK_MOVEMENT_WORDS:
5254 new_pos = MIN (priv->current_pos, priv->selection_bound);
5256 new_pos = MAX (priv->current_pos, priv->selection_bound);
5258 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5259 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5260 case GTK_MOVEMENT_BUFFER_ENDS:
5261 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5263 case GTK_MOVEMENT_DISPLAY_LINES:
5264 case GTK_MOVEMENT_PARAGRAPHS:
5265 case GTK_MOVEMENT_PAGES:
5266 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5274 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5275 new_pos = gtk_entry_move_logically (entry, new_pos, count);
5277 case GTK_MOVEMENT_VISUAL_POSITIONS:
5278 new_pos = gtk_entry_move_visually (entry, new_pos, count);
5279 if (priv->current_pos == new_pos)
5281 if (!extend_selection)
5283 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
5285 GTK_DIR_RIGHT : GTK_DIR_LEFT))
5287 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
5290 gtk_widget_child_focus (toplevel,
5292 GTK_DIR_RIGHT : GTK_DIR_LEFT);
5297 gtk_widget_error_bell (GTK_WIDGET (entry));
5301 case GTK_MOVEMENT_WORDS:
5304 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5309 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5312 if (priv->current_pos == new_pos)
5313 gtk_widget_error_bell (GTK_WIDGET (entry));
5315 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5316 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5317 case GTK_MOVEMENT_BUFFER_ENDS:
5318 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5319 if (priv->current_pos == new_pos)
5320 gtk_widget_error_bell (GTK_WIDGET (entry));
5322 case GTK_MOVEMENT_DISPLAY_LINES:
5323 case GTK_MOVEMENT_PARAGRAPHS:
5324 case GTK_MOVEMENT_PAGES:
5325 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5330 if (extend_selection)
5331 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5333 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5335 gtk_entry_pend_cursor_blink (entry);
5339 gtk_entry_insert_at_cursor (GtkEntry *entry,
5342 GtkEntryPrivate *priv = entry->priv;
5343 GtkEditable *editable = GTK_EDITABLE (entry);
5344 gint pos = priv->current_pos;
5348 gtk_entry_reset_im_context (entry);
5349 gtk_editable_insert_text (editable, str, -1, &pos);
5350 gtk_editable_set_position (editable, pos);
5355 gtk_entry_delete_from_cursor (GtkEntry *entry,
5359 GtkEntryPrivate *priv = entry->priv;
5360 GtkEditable *editable = GTK_EDITABLE (entry);
5361 gint start_pos = priv->current_pos;
5362 gint end_pos = priv->current_pos;
5363 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5365 gtk_entry_reset_im_context (entry);
5367 if (!priv->editable)
5369 gtk_widget_error_bell (GTK_WIDGET (entry));
5373 if (priv->selection_bound != priv->current_pos)
5375 gtk_editable_delete_selection (editable);
5381 case GTK_DELETE_CHARS:
5382 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5383 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5385 case GTK_DELETE_WORDS:
5388 /* Move to end of current word, or if not on a word, end of previous word */
5389 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5390 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5394 /* Move to beginning of current word, or if not on a word, begining of next word */
5395 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5396 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5400 case GTK_DELETE_WORD_ENDS:
5403 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5408 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5411 gtk_editable_delete_text (editable, start_pos, end_pos);
5413 case GTK_DELETE_DISPLAY_LINE_ENDS:
5414 case GTK_DELETE_PARAGRAPH_ENDS:
5416 gtk_editable_delete_text (editable, 0, priv->current_pos);
5418 gtk_editable_delete_text (editable, priv->current_pos, -1);
5420 case GTK_DELETE_DISPLAY_LINES:
5421 case GTK_DELETE_PARAGRAPHS:
5422 gtk_editable_delete_text (editable, 0, -1);
5424 case GTK_DELETE_WHITESPACE:
5425 gtk_entry_delete_whitespace (entry);
5429 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5430 gtk_widget_error_bell (GTK_WIDGET (entry));
5432 gtk_entry_pend_cursor_blink (entry);
5436 gtk_entry_backspace (GtkEntry *entry)
5438 GtkEntryPrivate *priv = entry->priv;
5439 GtkEditable *editable = GTK_EDITABLE (entry);
5442 gtk_entry_reset_im_context (entry);
5444 if (!priv->editable)
5446 gtk_widget_error_bell (GTK_WIDGET (entry));
5450 if (priv->selection_bound != priv->current_pos)
5452 gtk_editable_delete_selection (editable);
5456 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5458 if (prev_pos < priv->current_pos)
5460 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5461 PangoLogAttr *log_attrs;
5464 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5466 /* Deleting parts of characters */
5467 if (log_attrs[priv->current_pos].backspace_deletes_character)
5469 gchar *cluster_text;
5470 gchar *normalized_text;
5473 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5475 normalized_text = g_utf8_normalize (cluster_text,
5476 strlen (cluster_text),
5478 len = g_utf8_strlen (normalized_text, -1);
5480 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5483 gint pos = priv->current_pos;
5485 gtk_editable_insert_text (editable, normalized_text,
5486 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5488 gtk_editable_set_position (editable, pos);
5491 g_free (normalized_text);
5492 g_free (cluster_text);
5496 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5503 gtk_widget_error_bell (GTK_WIDGET (entry));
5506 gtk_entry_pend_cursor_blink (entry);
5510 gtk_entry_copy_clipboard (GtkEntry *entry)
5512 GtkEntryPrivate *priv = entry->priv;
5513 GtkEditable *editable = GTK_EDITABLE (entry);
5517 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5521 gtk_widget_error_bell (GTK_WIDGET (entry));
5525 str = _gtk_entry_get_display_text (entry, start, end);
5526 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5527 GDK_SELECTION_CLIPBOARD),
5534 gtk_entry_cut_clipboard (GtkEntry *entry)
5536 GtkEntryPrivate *priv = entry->priv;
5537 GtkEditable *editable = GTK_EDITABLE (entry);
5542 gtk_widget_error_bell (GTK_WIDGET (entry));
5546 gtk_entry_copy_clipboard (entry);
5550 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5551 gtk_editable_delete_text (editable, start, end);
5555 gtk_widget_error_bell (GTK_WIDGET (entry));
5558 gtk_entry_selection_bubble_popup_unset (entry);
5562 gtk_entry_paste_clipboard (GtkEntry *entry)
5564 GtkEntryPrivate *priv = entry->priv;
5567 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5569 gtk_widget_error_bell (GTK_WIDGET (entry));
5573 gtk_entry_delete_cb (GtkEntry *entry)
5575 GtkEntryPrivate *priv = entry->priv;
5576 GtkEditable *editable = GTK_EDITABLE (entry);
5581 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5582 gtk_editable_delete_text (editable, start, end);
5587 gtk_entry_toggle_overwrite (GtkEntry *entry)
5589 GtkEntryPrivate *priv = entry->priv;
5591 priv->overwrite_mode = !priv->overwrite_mode;
5592 gtk_entry_pend_cursor_blink (entry);
5593 gtk_widget_queue_draw (GTK_WIDGET (entry));
5597 gtk_entry_select_all (GtkEntry *entry)
5599 gtk_entry_select_line (entry);
5603 gtk_entry_real_activate (GtkEntry *entry)
5605 GtkEntryPrivate *priv = entry->priv;
5607 GtkWidget *default_widget, *focus_widget;
5608 GtkWidget *toplevel;
5611 widget = GTK_WIDGET (entry);
5613 if (priv->activates_default)
5615 toplevel = gtk_widget_get_toplevel (widget);
5616 if (GTK_IS_WINDOW (toplevel))
5618 window = GTK_WINDOW (toplevel);
5622 default_widget = gtk_window_get_default_widget (window);
5623 focus_widget = gtk_window_get_focus (window);
5624 if (widget != default_widget &&
5625 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5626 gtk_window_activate_default (window);
5633 keymap_direction_changed (GdkKeymap *keymap,
5636 gtk_entry_recompute (entry);
5639 /* IM Context Callbacks
5643 gtk_entry_commit_cb (GtkIMContext *context,
5647 GtkEntryPrivate *priv = entry->priv;
5650 gtk_entry_enter_text (entry, str);
5654 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5657 GtkEntryPrivate *priv = entry->priv;
5661 gchar *preedit_string;
5664 gtk_im_context_get_preedit_string (priv->im_context,
5665 &preedit_string, NULL,
5667 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5668 priv->preedit_length = strlen (preedit_string);
5669 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5670 priv->preedit_cursor = cursor_pos;
5671 g_free (preedit_string);
5673 gtk_entry_recompute (entry);
5678 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5681 GtkEntryPrivate *priv = entry->priv;
5684 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5685 text = _gtk_entry_get_display_text (entry, 0, -1);
5686 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5687 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5694 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5699 GtkEntryPrivate *priv = entry->priv;
5702 gtk_editable_delete_text (GTK_EDITABLE (entry),
5703 priv->current_pos + offset,
5704 priv->current_pos + offset + n_chars);
5709 /* Internal functions
5712 /* Used for im_commit_cb and inserting Unicode chars */
5714 gtk_entry_enter_text (GtkEntry *entry,
5717 GtkEntryPrivate *priv = entry->priv;
5718 GtkEditable *editable = GTK_EDITABLE (entry);
5720 gboolean old_need_im_reset;
5722 old_need_im_reset = priv->need_im_reset;
5723 priv->need_im_reset = FALSE;
5725 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5726 gtk_editable_delete_selection (editable);
5729 if (priv->overwrite_mode)
5730 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5733 tmp_pos = priv->current_pos;
5734 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5735 gtk_editable_set_position (editable, tmp_pos);
5737 priv->need_im_reset = old_need_im_reset;
5740 /* All changes to priv->current_pos and priv->selection_bound
5741 * should go through this function.
5744 gtk_entry_set_positions (GtkEntry *entry,
5746 gint selection_bound)
5748 GtkEntryPrivate *priv = entry->priv;
5749 gboolean changed = FALSE;
5751 g_object_freeze_notify (G_OBJECT (entry));
5753 if (current_pos != -1 &&
5754 priv->current_pos != current_pos)
5756 priv->current_pos = current_pos;
5759 g_object_notify (G_OBJECT (entry), "cursor-position");
5762 if (selection_bound != -1 &&
5763 priv->selection_bound != selection_bound)
5765 priv->selection_bound = selection_bound;
5768 g_object_notify (G_OBJECT (entry), "selection-bound");
5771 g_object_thaw_notify (G_OBJECT (entry));
5775 gtk_entry_move_adjustments (entry);
5776 gtk_entry_recompute (entry);
5781 gtk_entry_reset_layout (GtkEntry *entry)
5783 GtkEntryPrivate *priv = entry->priv;
5785 if (priv->cached_layout)
5787 g_object_unref (priv->cached_layout);
5788 priv->cached_layout = NULL;
5793 update_im_cursor_location (GtkEntry *entry)
5795 GtkEntryPrivate *priv = entry->priv;
5798 gint strong_xoffset;
5799 gint area_width, area_height;
5801 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5802 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5804 strong_xoffset = strong_x - priv->scroll_offset;
5805 if (strong_xoffset < 0)
5809 else if (strong_xoffset > area_width)
5811 strong_xoffset = area_width;
5813 area.x = strong_xoffset;
5816 area.height = area_height;
5818 gtk_im_context_set_cursor_location (priv->im_context, &area);
5822 recompute_idle_func (gpointer data)
5824 GtkEntry *entry = GTK_ENTRY (data);
5825 GtkEntryPrivate *priv = entry->priv;
5827 priv->recompute_idle = 0;
5829 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5831 GtkTextHandleMode handle_mode;
5833 gtk_entry_adjust_scroll (entry);
5834 gtk_widget_queue_draw (GTK_WIDGET (entry));
5836 update_im_cursor_location (entry);
5838 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
5840 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
5841 gtk_entry_update_handles (entry, handle_mode);
5848 gtk_entry_recompute (GtkEntry *entry)
5850 GtkEntryPrivate *priv = entry->priv;
5852 gtk_entry_reset_layout (entry);
5853 gtk_entry_check_cursor_blink (entry);
5855 if (!priv->recompute_idle)
5857 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5858 recompute_idle_func, entry, NULL);
5863 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5866 GtkWidget *widget = GTK_WIDGET (entry);
5867 GtkStyleContext *context;
5868 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5870 context = gtk_widget_get_style_context (widget);
5871 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5873 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5874 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5875 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5878 static inline gboolean
5879 show_placeholder_text (GtkEntry *entry)
5881 GtkEntryPrivate *priv = entry->priv;
5883 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5884 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5885 priv->placeholder_text != NULL)
5891 static PangoLayout *
5892 gtk_entry_create_layout (GtkEntry *entry,
5893 gboolean include_preedit)
5895 GtkEntryPrivate *priv = entry->priv;
5896 GtkWidget *widget = GTK_WIDGET (entry);
5897 PangoLayout *layout;
5898 PangoAttrList *tmp_attrs;
5899 gboolean placeholder_layout;
5901 gchar *preedit_string = NULL;
5902 gint preedit_length = 0;
5903 PangoAttrList *preedit_attrs = NULL;
5908 layout = gtk_widget_create_pango_layout (widget, NULL);
5909 pango_layout_set_single_paragraph_mode (layout, TRUE);
5911 tmp_attrs = priv->attrs ? pango_attr_list_ref (priv->attrs)
5912 : pango_attr_list_new ();
5914 placeholder_layout = show_placeholder_text (entry);
5915 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5916 n_bytes = strlen (display);
5918 if (!placeholder_layout && include_preedit)
5920 gtk_im_context_get_preedit_string (priv->im_context,
5921 &preedit_string, &preedit_attrs, NULL);
5922 preedit_length = priv->preedit_length;
5924 else if (placeholder_layout)
5927 PangoAttribute *attr;
5929 gtk_entry_get_placeholder_text_color (entry, &color);
5930 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5931 attr->start_index = 0;
5932 attr->end_index = G_MAXINT;
5933 pango_attr_list_insert (tmp_attrs, attr);
5938 GString *tmp_string = g_string_new (display);
5939 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5941 g_string_insert (tmp_string, cursor_index, preedit_string);
5942 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5943 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5944 cursor_index, preedit_length);
5945 g_string_free (tmp_string, TRUE);
5949 PangoDirection pango_dir;
5951 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5952 pango_dir = pango_find_base_dir (display, n_bytes);
5954 pango_dir = PANGO_DIRECTION_NEUTRAL;
5956 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5958 if (gtk_widget_has_focus (widget))
5960 GdkDisplay *display = gtk_widget_get_display (widget);
5961 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5962 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5963 pango_dir = PANGO_DIRECTION_RTL;
5965 pango_dir = PANGO_DIRECTION_LTR;
5969 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5970 pango_dir = PANGO_DIRECTION_RTL;
5972 pango_dir = PANGO_DIRECTION_LTR;
5976 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5979 priv->resolved_dir = pango_dir;
5981 pango_layout_set_text (layout, display, n_bytes);
5984 pango_layout_set_attributes (layout, tmp_attrs);
5986 g_free (preedit_string);
5990 pango_attr_list_unref (preedit_attrs);
5992 pango_attr_list_unref (tmp_attrs);
5997 static PangoLayout *
5998 gtk_entry_ensure_layout (GtkEntry *entry,
5999 gboolean include_preedit)
6001 GtkEntryPrivate *priv = entry->priv;
6003 if (priv->preedit_length > 0 &&
6004 !include_preedit != !priv->cache_includes_preedit)
6005 gtk_entry_reset_layout (entry);
6007 if (!priv->cached_layout)
6009 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
6010 priv->cache_includes_preedit = include_preedit;
6013 return priv->cached_layout;
6017 get_layout_position (GtkEntry *entry,
6021 GtkEntryPrivate *priv = entry->priv;
6022 PangoLayout *layout;
6023 PangoRectangle logical_rect;
6024 gint area_width, area_height;
6026 PangoLayoutLine *line;
6028 layout = gtk_entry_ensure_layout (entry, TRUE);
6030 get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
6031 area_height = PANGO_SCALE * area_height;
6033 line = pango_layout_get_lines_readonly (layout)->data;
6034 pango_layout_line_get_extents (line, NULL, &logical_rect);
6036 /* Align primarily for locale's ascent/descent */
6037 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
6038 priv->ascent + logical_rect.y);
6040 /* Now see if we need to adjust to fit in actual drawn string */
6041 if (logical_rect.height > area_height)
6042 y_pos = (area_height - logical_rect.height) / 2;
6045 else if (y_pos + logical_rect.height > area_height)
6046 y_pos = area_height - logical_rect.height;
6048 y_pos = y_pos / PANGO_SCALE;
6051 *x = - priv->scroll_offset;
6058 draw_text_with_color (GtkEntry *entry,
6060 GdkRGBA *default_color)
6062 GtkEntryPrivate *priv = entry->priv;
6063 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6066 gint start_pos, end_pos;
6068 widget = GTK_WIDGET (entry);
6072 get_layout_position (entry, &x, &y);
6074 cairo_move_to (cr, x, y);
6075 gdk_cairo_set_source_rgba (cr, default_color);
6076 pango_cairo_show_layout (cr, layout);
6078 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
6082 PangoRectangle logical_rect;
6083 GdkRGBA selection_color, text_color;
6084 GtkStyleContext *context;
6085 GtkStateFlags state;
6087 context = gtk_widget_get_style_context (widget);
6088 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
6089 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
6091 state = gtk_widget_get_state_flags (widget);
6092 state |= GTK_STATE_FLAG_SELECTED;
6094 gtk_style_context_get_background_color (context, state, &selection_color);
6095 gtk_style_context_get_color (context, state, &text_color);
6097 for (i = 0; i < n_ranges; ++i)
6098 cairo_rectangle (cr,
6099 - priv->scroll_offset + ranges[2 * i],
6102 logical_rect.height);
6106 gdk_cairo_set_source_rgba (cr, &selection_color);
6109 cairo_move_to (cr, x, y);
6110 gdk_cairo_set_source_rgba (cr, &text_color);
6111 pango_cairo_show_layout (cr, layout);
6119 gtk_entry_draw_text (GtkEntry *entry,
6122 GtkEntryPrivate *priv = entry->priv;
6123 GtkWidget *widget = GTK_WIDGET (entry);
6124 GtkStateFlags state = 0;
6125 GdkRGBA text_color, bar_text_color;
6126 GtkStyleContext *context;
6128 gint progress_x, progress_y, progress_width, progress_height;
6129 gint clip_width, clip_height;
6131 /* Nothing to display at all */
6132 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
6135 state = gtk_widget_get_state_flags (widget);
6136 context = gtk_widget_get_style_context (widget);
6138 gtk_style_context_get_color (context, state, &text_color);
6140 /* Get foreground color for progressbars */
6141 gtk_entry_prepare_context_for_progress (entry, context);
6142 gtk_style_context_get_color (context, state, &bar_text_color);
6143 gtk_style_context_restore (context);
6145 get_progress_area (widget,
6146 &progress_x, &progress_y,
6147 &progress_width, &progress_height);
6151 clip_width = gdk_window_get_width (priv->text_area);
6152 clip_height = gdk_window_get_height (priv->text_area);
6153 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
6156 /* If the color is the same, or the progress area has a zero
6157 * size, then we only need to draw once. */
6158 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
6159 ((progress_width == 0) || (progress_height == 0)))
6161 draw_text_with_color (entry, cr, &text_color);
6165 int frame_x, frame_y, area_x, area_y;
6167 width = gdk_window_get_width (priv->text_area);
6168 height = gdk_window_get_height (priv->text_area);
6172 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
6173 cairo_rectangle (cr, 0, 0, width, height);
6175 /* progres area is frame-relative, we need it text-area window
6177 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
6178 gdk_window_get_position (priv->text_area, &area_x, &area_y);
6179 progress_x += frame_x - area_x;
6180 progress_y += frame_y - area_y;
6182 cairo_rectangle (cr, progress_x, progress_y,
6183 progress_width, progress_height);
6185 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
6187 draw_text_with_color (entry, cr, &text_color);
6192 cairo_rectangle (cr, progress_x, progress_y,
6193 progress_width, progress_height);
6196 draw_text_with_color (entry, cr, &bar_text_color);
6205 gtk_entry_draw_cursor (GtkEntry *entry,
6209 GtkEntryPrivate *priv = entry->priv;
6210 GtkWidget *widget = GTK_WIDGET (entry);
6211 GtkStyleContext *context;
6212 PangoRectangle cursor_rect;
6215 gboolean block_at_line_end;
6216 PangoLayout *layout;
6220 context = gtk_widget_get_style_context (widget);
6222 layout = gtk_entry_ensure_layout (entry, TRUE);
6223 text = pango_layout_get_text (layout);
6224 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6225 get_layout_position (entry, &x, &y);
6227 if (!priv->overwrite_mode)
6230 block = _gtk_text_util_get_block_cursor_location (layout,
6231 cursor_index, &cursor_rect, &block_at_line_end);
6235 gtk_render_insertion_cursor (context, cr,
6237 layout, cursor_index, priv->resolved_dir);
6239 else /* overwrite_mode */
6241 GdkRGBA cursor_color;
6246 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
6247 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
6248 rect.width = PANGO_PIXELS (cursor_rect.width);
6249 rect.height = PANGO_PIXELS (cursor_rect.height);
6251 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
6252 gdk_cairo_set_source_rgba (cr, &cursor_color);
6253 gdk_cairo_rectangle (cr, &rect);
6256 if (!block_at_line_end)
6258 GtkStateFlags state;
6261 state = gtk_widget_get_state_flags (widget);
6262 gtk_style_context_get_background_color (context, state, &color);
6264 gdk_cairo_rectangle (cr, &rect);
6266 cairo_move_to (cr, x, y);
6267 gdk_cairo_set_source_rgba (cr, &color);
6268 pango_cairo_show_layout (cr, layout);
6276 gtk_entry_handle_dragged (GtkTextHandle *handle,
6277 GtkTextHandlePosition pos,
6282 gint cursor_pos, selection_bound_pos, tmp_pos;
6283 GtkEntryPrivate *priv = entry->priv;
6284 GtkTextHandleMode mode;
6287 gtk_entry_selection_bubble_popup_unset (entry);
6289 cursor_pos = priv->current_pos;
6290 selection_bound_pos = priv->selection_bound;
6291 mode = _gtk_text_handle_get_mode (handle);
6292 tmp_pos = gtk_entry_find_position (entry, x + priv->scroll_offset);
6294 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR ||
6295 cursor_pos >= selection_bound_pos)
6298 min = &selection_bound_pos;
6302 max = &selection_bound_pos;
6306 if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
6308 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6312 min_pos = MAX (*min + 1, 0);
6313 tmp_pos = MAX (tmp_pos, min_pos);
6320 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6325 *min = MIN (tmp_pos, max_pos);
6329 if (cursor_pos != priv->current_pos ||
6330 selection_bound_pos != priv->selection_bound)
6332 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
6333 gtk_entry_set_positions (entry, cursor_pos, cursor_pos);
6335 gtk_entry_set_positions (entry, cursor_pos, selection_bound_pos);
6337 gtk_entry_update_handles (entry, mode);
6342 gtk_entry_handle_drag_finished (GtkTextHandle *handle,
6343 GtkTextHandlePosition pos,
6346 gtk_entry_selection_bubble_popup_set (entry);
6351 * gtk_entry_reset_im_context:
6352 * @entry: a #GtkEntry
6354 * Reset the input method context of the entry if needed.
6356 * This can be necessary in the case where modifying the buffer
6357 * would confuse on-going input method behavior.
6362 gtk_entry_reset_im_context (GtkEntry *entry)
6364 GtkEntryPrivate *priv = entry->priv;
6366 g_return_if_fail (GTK_IS_ENTRY (entry));
6368 if (priv->need_im_reset)
6370 priv->need_im_reset = FALSE;
6371 gtk_im_context_reset (priv->im_context);
6376 * gtk_entry_im_context_filter_keypress:
6377 * @entry: a #GtkEntry
6378 * @event: (type Gdk.EventKey): the key event
6380 * Allow the #GtkEntry input method to internally handle key press
6381 * and release events. If this function returns %TRUE, then no further
6382 * processing should be done for this key event. See
6383 * gtk_im_context_filter_keypress().
6385 * Note that you are expected to call this function from your handler
6386 * when overriding key event handling. This is needed in the case when
6387 * you need to insert your own key handling between the input method
6388 * and the default key event handling of the #GtkEntry.
6389 * See gtk_text_view_reset_im_context() for an example of use.
6391 * Return value: %TRUE if the input method handled the key event.
6396 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6399 GtkEntryPrivate *priv;
6401 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6405 return gtk_im_context_filter_keypress (priv->im_context, event);
6409 _gtk_entry_get_im_context (GtkEntry *entry)
6411 return entry->priv->im_context;
6415 gtk_entry_find_position (GtkEntry *entry,
6418 GtkEntryPrivate *priv = entry->priv;
6419 PangoLayout *layout;
6420 PangoLayoutLine *line;
6427 layout = gtk_entry_ensure_layout (entry, TRUE);
6428 text = pango_layout_get_text (layout);
6429 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6431 line = pango_layout_get_lines_readonly (layout)->data;
6432 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6434 if (index >= cursor_index && priv->preedit_length)
6436 if (index >= cursor_index + priv->preedit_length)
6437 index -= priv->preedit_length;
6440 index = cursor_index;
6445 pos = g_utf8_pointer_to_offset (text, text + index);
6452 gtk_entry_get_cursor_locations (GtkEntry *entry,
6457 GtkEntryPrivate *priv = entry->priv;
6458 DisplayMode mode = gtk_entry_get_display_mode (entry);
6460 /* Nothing to display at all, so no cursor is relevant */
6461 if (mode == DISPLAY_BLANK)
6471 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6472 const gchar *text = pango_layout_get_text (layout);
6473 PangoRectangle strong_pos, weak_pos;
6476 if (type == CURSOR_STANDARD)
6478 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6480 else /* type == CURSOR_DND */
6482 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6484 if (priv->dnd_position > priv->current_pos)
6486 if (mode == DISPLAY_NORMAL)
6487 index += priv->preedit_length;
6490 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6491 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6496 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6499 *strong_x = strong_pos.x / PANGO_SCALE;
6502 *weak_x = weak_pos.x / PANGO_SCALE;
6507 gtk_entry_get_is_selection_handle_dragged (GtkEntry *entry)
6509 GtkEntryPrivate *priv = entry->priv;
6510 GtkTextHandlePosition pos;
6512 if (_gtk_text_handle_get_mode (priv->text_handle) != GTK_TEXT_HANDLE_MODE_SELECTION)
6515 if (priv->current_pos >= priv->selection_bound)
6516 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
6518 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
6520 return _gtk_text_handle_get_is_dragged (priv->text_handle, pos);
6524 gtk_entry_adjust_scroll (GtkEntry *entry)
6526 GtkEntryPrivate *priv = entry->priv;
6527 gint min_offset, max_offset;
6528 gint text_area_width, text_width;
6529 gint strong_x, weak_x;
6530 gint strong_xoffset, weak_xoffset;
6532 PangoLayout *layout;
6533 PangoLayoutLine *line;
6534 PangoRectangle logical_rect;
6535 GtkTextHandleMode handle_mode;
6537 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6540 text_area_width = gdk_window_get_width (priv->text_area);
6542 if (text_area_width < 0)
6543 text_area_width = 0;
6545 layout = gtk_entry_ensure_layout (entry, TRUE);
6546 line = pango_layout_get_lines_readonly (layout)->data;
6548 pango_layout_line_get_extents (line, NULL, &logical_rect);
6550 /* Display as much text as we can */
6552 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6553 xalign = priv->xalign;
6555 xalign = 1.0 - priv->xalign;
6557 text_width = PANGO_PIXELS(logical_rect.width);
6559 if (text_width > text_area_width)
6562 max_offset = text_width - text_area_width;
6566 min_offset = (text_width - text_area_width) * xalign;
6567 max_offset = min_offset;
6570 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6572 if (gtk_entry_get_is_selection_handle_dragged (entry))
6574 /* The text handle corresponding to the selection bound is
6575 * being dragged, ensure it stays onscreen even if we scroll
6576 * cursors away, this is so both handles can cause content
6579 strong_x = weak_x = gtk_entry_get_selection_bound_location (entry);
6583 /* And make sure cursors are on screen. Note that the cursor is
6584 * actually drawn one pixel into the INNER_BORDER space on
6585 * the right, when the scroll is at the utmost right. This
6586 * looks better to to me than confining the cursor inside the
6587 * border entirely, though it means that the cursor gets one
6588 * pixel closer to the edge of the widget on the right than
6589 * on the left. This might need changing if one changed
6590 * INNER_BORDER from 2 to 1, as one would do on a
6591 * small-screen-real-estate display.
6593 * We always make sure that the strong cursor is on screen, and
6594 * put the weak cursor on screen if possible.
6596 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6599 strong_xoffset = strong_x - priv->scroll_offset;
6601 if (strong_xoffset < 0)
6603 priv->scroll_offset += strong_xoffset;
6606 else if (strong_xoffset > text_area_width)
6608 priv->scroll_offset += strong_xoffset - text_area_width;
6609 strong_xoffset = text_area_width;
6612 weak_xoffset = weak_x - priv->scroll_offset;
6614 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6616 priv->scroll_offset += weak_xoffset;
6618 else if (weak_xoffset > text_area_width &&
6619 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6621 priv->scroll_offset += weak_xoffset - text_area_width;
6624 g_object_notify (G_OBJECT (entry), "scroll-offset");
6626 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
6628 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
6629 gtk_entry_update_handles (entry, handle_mode);
6633 gtk_entry_move_adjustments (GtkEntry *entry)
6635 GtkWidget *widget = GTK_WIDGET (entry);
6636 GtkAllocation allocation;
6637 GtkAdjustment *adjustment;
6638 PangoContext *context;
6639 PangoFontMetrics *metrics;
6644 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6648 gtk_widget_get_allocation (widget, &allocation);
6650 /* Cursor/char position, layout offset, border width, and widget allocation */
6651 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6652 get_layout_position (entry, &layout_x, NULL);
6653 _gtk_entry_get_borders (entry, &borders);
6654 x += allocation.x + layout_x + borders.left;
6656 /* Approximate width of a char, so user can see what is ahead/behind */
6657 context = gtk_widget_get_pango_context (widget);
6659 metrics = pango_context_get_metrics (context,
6660 pango_context_get_font_description (context),
6661 pango_context_get_language (context));
6662 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6665 gtk_adjustment_clamp_page (adjustment,
6666 x - (char_width + 1), /* one char + one pixel before */
6667 x + (char_width + 2)); /* one char + cursor + one pixel after */
6671 gtk_entry_move_visually (GtkEntry *entry,
6675 GtkEntryPrivate *priv = entry->priv;
6677 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6680 text = pango_layout_get_text (layout);
6682 index = g_utf8_offset_to_pointer (text, start) - text;
6686 int new_index, new_trailing;
6687 gboolean split_cursor;
6690 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6691 "gtk-split-cursor", &split_cursor,
6698 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6699 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6701 strong = keymap_direction == priv->resolved_dir;
6706 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6711 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6717 else if (new_index != G_MAXINT)
6720 while (new_trailing--)
6721 index = g_utf8_next_char (text + index) - text;
6724 return g_utf8_pointer_to_offset (text, text + index);
6728 gtk_entry_move_logically (GtkEntry *entry,
6732 gint new_pos = start;
6735 length = gtk_entry_buffer_get_length (get_buffer (entry));
6737 /* Prevent any leak of information */
6738 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6740 new_pos = CLAMP (start + count, 0, length);
6744 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6745 PangoLogAttr *log_attrs;
6748 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6750 while (count > 0 && new_pos < length)
6754 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6758 while (count < 0 && new_pos > 0)
6762 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6774 gtk_entry_move_forward_word (GtkEntry *entry,
6776 gboolean allow_whitespace)
6778 gint new_pos = start;
6781 length = gtk_entry_buffer_get_length (get_buffer (entry));
6783 /* Prevent any leak of information */
6784 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6788 else if (new_pos < length)
6790 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6791 PangoLogAttr *log_attrs;
6794 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6796 /* Find the next word boundary */
6798 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6799 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6810 gtk_entry_move_backward_word (GtkEntry *entry,
6812 gboolean allow_whitespace)
6814 gint new_pos = start;
6816 /* Prevent any leak of information */
6817 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6823 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6824 PangoLogAttr *log_attrs;
6827 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6829 new_pos = start - 1;
6831 /* Find the previous word boundary */
6832 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6833 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6843 gtk_entry_delete_whitespace (GtkEntry *entry)
6845 GtkEntryPrivate *priv = entry->priv;
6846 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6847 PangoLogAttr *log_attrs;
6851 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6853 start = end = priv->current_pos;
6855 while (start > 0 && log_attrs[start-1].is_white)
6858 while (end < n_attrs && log_attrs[end].is_white)
6864 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6869 gtk_entry_select_word (GtkEntry *entry)
6871 GtkEntryPrivate *priv = entry->priv;
6872 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6873 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6875 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6879 gtk_entry_select_line (GtkEntry *entry)
6881 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6885 truncate_multiline (const gchar *text)
6890 text[length] && text[length] != '\n' && text[length] != '\r';
6897 paste_received (GtkClipboard *clipboard,
6901 GtkEntry *entry = GTK_ENTRY (data);
6902 GtkEditable *editable = GTK_EDITABLE (entry);
6903 GtkEntryPrivate *priv = entry->priv;
6905 if (priv->button == GDK_BUTTON_MIDDLE)
6907 gint pos, start, end;
6908 pos = priv->insert_pos;
6909 gtk_editable_get_selection_bounds (editable, &start, &end);
6910 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6911 gtk_editable_select_region (editable, pos, pos);
6916 gint pos, start, end;
6918 gboolean popup_completion;
6919 GtkEntryCompletion *completion;
6921 completion = gtk_entry_get_completion (entry);
6923 if (priv->truncate_multiline)
6924 length = truncate_multiline (text);
6926 /* only complete if the selection is at the end */
6927 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6928 MAX (priv->current_pos, priv->selection_bound));
6932 if (gtk_widget_get_mapped (completion->priv->popup_window))
6933 _gtk_entry_completion_popdown (completion);
6935 if (!popup_completion && completion->priv->changed_id > 0)
6936 g_signal_handler_block (entry, completion->priv->changed_id);
6939 begin_change (entry);
6940 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6941 gtk_editable_delete_text (editable, start, end);
6943 pos = priv->current_pos;
6944 gtk_editable_insert_text (editable, text, length, &pos);
6945 gtk_editable_set_position (editable, pos);
6949 !popup_completion && completion->priv->changed_id > 0)
6950 g_signal_handler_unblock (entry, completion->priv->changed_id);
6953 g_object_unref (entry);
6957 gtk_entry_paste (GtkEntry *entry,
6960 g_object_ref (entry);
6961 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6962 paste_received, entry);
6966 primary_get_cb (GtkClipboard *clipboard,
6967 GtkSelectionData *selection_data,
6971 GtkEntry *entry = GTK_ENTRY (data);
6974 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6976 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6977 gtk_selection_data_set_text (selection_data, str, -1);
6983 primary_clear_cb (GtkClipboard *clipboard,
6986 GtkEntry *entry = GTK_ENTRY (data);
6987 GtkEntryPrivate *priv = entry->priv;
6989 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6993 gtk_entry_update_primary_selection (GtkEntry *entry)
6995 GtkTargetList *list;
6996 GtkTargetEntry *targets;
6997 GtkClipboard *clipboard;
7001 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
7004 list = gtk_target_list_new (NULL, 0);
7005 gtk_target_list_add_text_targets (list, 0);
7007 targets = gtk_target_table_new_from_list (list, &n_targets);
7009 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
7011 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
7013 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
7014 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
7015 primary_clear_cb (clipboard, entry);
7019 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
7020 gtk_clipboard_clear (clipboard);
7023 gtk_target_table_free (targets, n_targets);
7024 gtk_target_list_unref (list);
7028 gtk_entry_clear (GtkEntry *entry,
7029 GtkEntryIconPosition icon_pos)
7031 GtkEntryPrivate *priv = entry->priv;
7032 EntryIconInfo *icon_info = priv->icons[icon_pos];
7033 GtkImageType storage_type;
7035 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
7038 g_object_freeze_notify (G_OBJECT (entry));
7040 /* Explicitly check, as the pointer may become invalidated
7041 * during destruction.
7043 if (GDK_IS_WINDOW (icon_info->window))
7044 gdk_window_hide (icon_info->window);
7046 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
7048 switch (storage_type)
7050 case GTK_IMAGE_PIXBUF:
7051 g_object_notify (G_OBJECT (entry),
7052 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
7055 case GTK_IMAGE_STOCK:
7056 g_object_notify (G_OBJECT (entry),
7057 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
7060 case GTK_IMAGE_ICON_NAME:
7061 g_object_notify (G_OBJECT (entry),
7062 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
7065 case GTK_IMAGE_GICON:
7066 g_object_notify (G_OBJECT (entry),
7067 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
7071 g_assert_not_reached ();
7075 _gtk_icon_helper_clear (icon_info->icon_helper);
7077 g_object_notify (G_OBJECT (entry),
7078 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
7080 g_object_thaw_notify (G_OBJECT (entry));
7084 gtk_entry_ensure_pixbuf (GtkEntry *entry,
7085 GtkEntryIconPosition icon_pos)
7087 GtkEntryPrivate *priv = entry->priv;
7088 EntryIconInfo *icon_info = priv->icons[icon_pos];
7089 GtkStyleContext *context;
7092 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
7093 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
7095 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
7098 gtk_style_context_restore (context);
7109 * Creates a new entry.
7111 * Return value: a new #GtkEntry.
7114 gtk_entry_new (void)
7116 return g_object_new (GTK_TYPE_ENTRY, NULL);
7120 * gtk_entry_new_with_buffer:
7121 * @buffer: The buffer to use for the new #GtkEntry.
7123 * Creates a new entry with the specified text buffer.
7125 * Return value: a new #GtkEntry
7130 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
7132 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
7133 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
7136 static GtkEntryBuffer*
7137 get_buffer (GtkEntry *entry)
7139 GtkEntryPrivate *priv = entry->priv;
7141 if (priv->buffer == NULL)
7143 GtkEntryBuffer *buffer;
7144 buffer = gtk_entry_buffer_new (NULL, 0);
7145 gtk_entry_set_buffer (entry, buffer);
7146 g_object_unref (buffer);
7149 return priv->buffer;
7153 * gtk_entry_get_buffer:
7154 * @entry: a #GtkEntry
7156 * Get the #GtkEntryBuffer object which holds the text for
7161 * Returns: (transfer none): A #GtkEntryBuffer object.
7164 gtk_entry_get_buffer (GtkEntry *entry)
7166 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7168 return get_buffer (entry);
7172 * gtk_entry_set_buffer:
7173 * @entry: a #GtkEntry
7174 * @buffer: a #GtkEntryBuffer
7176 * Set the #GtkEntryBuffer object which holds the text for
7182 gtk_entry_set_buffer (GtkEntry *entry,
7183 GtkEntryBuffer *buffer)
7185 GtkEntryPrivate *priv;
7188 g_return_if_fail (GTK_IS_ENTRY (entry));
7194 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
7195 g_object_ref (buffer);
7200 buffer_disconnect_signals (entry);
7201 g_object_unref (priv->buffer);
7204 priv->buffer = buffer;
7207 buffer_connect_signals (entry);
7209 obj = G_OBJECT (entry);
7210 g_object_freeze_notify (obj);
7211 g_object_notify (obj, "buffer");
7212 g_object_notify (obj, "text");
7213 g_object_notify (obj, "text-length");
7214 g_object_notify (obj, "max-length");
7215 g_object_notify (obj, "visibility");
7216 g_object_notify (obj, "invisible-char");
7217 g_object_notify (obj, "invisible-char-set");
7218 g_object_thaw_notify (obj);
7220 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7221 gtk_entry_recompute (entry);
7225 * gtk_entry_get_text_area:
7226 * @entry: a #GtkEntry
7227 * @text_area: (out): Return location for the text area.
7229 * Gets the area where the entry's text is drawn. This function is
7230 * useful when drawing something to the entry in a draw callback.
7232 * If the entry is not realized, @text_area is filled with zeros.
7234 * See also gtk_entry_get_icon_area().
7239 gtk_entry_get_text_area (GtkEntry *entry,
7240 GdkRectangle *text_area)
7242 GtkEntryPrivate *priv;
7244 g_return_if_fail (GTK_IS_ENTRY (entry));
7245 g_return_if_fail (text_area != NULL);
7249 if (priv->text_area)
7251 GtkAllocation allocation;
7254 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7255 gdk_window_get_position (priv->text_area, &x, &y);
7257 text_area->x = x - allocation.x;
7258 text_area->y = y - allocation.y;
7259 text_area->width = gdk_window_get_width (priv->text_area);
7260 text_area->height = gdk_window_get_height (priv->text_area);
7266 text_area->width = 0;
7267 text_area->height = 0;
7272 * gtk_entry_set_text:
7273 * @entry: a #GtkEntry
7274 * @text: the new text
7276 * Sets the text in the widget to the given
7277 * value, replacing the current contents.
7279 * See gtk_entry_buffer_set_text().
7282 gtk_entry_set_text (GtkEntry *entry,
7286 GtkEntryCompletion *completion;
7288 g_return_if_fail (GTK_IS_ENTRY (entry));
7289 g_return_if_fail (text != NULL);
7291 /* Actually setting the text will affect the cursor and selection;
7292 * if the contents don't actually change, this will look odd to the user.
7294 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7297 completion = gtk_entry_get_completion (entry);
7298 if (completion && completion->priv->changed_id > 0)
7299 g_signal_handler_block (entry, completion->priv->changed_id);
7301 begin_change (entry);
7302 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7304 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7307 if (completion && completion->priv->changed_id > 0)
7308 g_signal_handler_unblock (entry, completion->priv->changed_id);
7312 * gtk_entry_set_visibility:
7313 * @entry: a #GtkEntry
7314 * @visible: %TRUE if the contents of the entry are displayed
7317 * Sets whether the contents of the entry are visible or not.
7318 * When visibility is set to %FALSE, characters are displayed
7319 * as the invisible char, and will also appear that way when
7320 * the text in the entry widget is copied elsewhere.
7322 * By default, GTK+ picks the best invisible character available
7323 * in the current font, but it can be changed with
7324 * gtk_entry_set_invisible_char().
7326 * Note that you probably want to set #GtkEntry:input-purpose
7327 * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
7328 * inform input methods about the purpose of this entry,
7329 * in addition to setting visibility to %FALSE.
7332 gtk_entry_set_visibility (GtkEntry *entry,
7335 GtkEntryPrivate *priv;
7337 g_return_if_fail (GTK_IS_ENTRY (entry));
7341 visible = visible != FALSE;
7343 if (priv->visible != visible)
7345 priv->visible = visible;
7347 g_object_notify (G_OBJECT (entry), "visibility");
7348 gtk_entry_recompute (entry);
7353 * gtk_entry_get_visibility:
7354 * @entry: a #GtkEntry
7356 * Retrieves whether the text in @entry is visible. See
7357 * gtk_entry_set_visibility().
7359 * Return value: %TRUE if the text is currently visible
7362 gtk_entry_get_visibility (GtkEntry *entry)
7364 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7366 return entry->priv->visible;
7370 * gtk_entry_set_invisible_char:
7371 * @entry: a #GtkEntry
7372 * @ch: a Unicode character
7374 * Sets the character to use in place of the actual text when
7375 * gtk_entry_set_visibility() has been called to set text visibility
7376 * to %FALSE. i.e. this is the character used in "password mode" to
7377 * show the user how many characters have been typed. By default, GTK+
7378 * picks the best invisible char available in the current font. If you
7379 * set the invisible char to 0, then the user will get no feedback
7380 * at all; there will be no text on the screen as they type.
7383 gtk_entry_set_invisible_char (GtkEntry *entry,
7386 GtkEntryPrivate *priv;
7388 g_return_if_fail (GTK_IS_ENTRY (entry));
7392 if (!priv->invisible_char_set)
7394 priv->invisible_char_set = TRUE;
7395 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7398 if (ch == priv->invisible_char)
7401 priv->invisible_char = ch;
7402 g_object_notify (G_OBJECT (entry), "invisible-char");
7403 gtk_entry_recompute (entry);
7407 * gtk_entry_get_invisible_char:
7408 * @entry: a #GtkEntry
7410 * Retrieves the character displayed in place of the real characters
7411 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7413 * Return value: the current invisible char, or 0, if the entry does not
7414 * show invisible text at all.
7417 gtk_entry_get_invisible_char (GtkEntry *entry)
7419 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7421 return entry->priv->invisible_char;
7425 * gtk_entry_unset_invisible_char:
7426 * @entry: a #GtkEntry
7428 * Unsets the invisible char previously set with
7429 * gtk_entry_set_invisible_char(). So that the
7430 * default invisible char is used again.
7435 gtk_entry_unset_invisible_char (GtkEntry *entry)
7437 GtkEntryPrivate *priv;
7440 g_return_if_fail (GTK_IS_ENTRY (entry));
7444 if (!priv->invisible_char_set)
7447 priv->invisible_char_set = FALSE;
7448 ch = find_invisible_char (GTK_WIDGET (entry));
7450 if (priv->invisible_char != ch)
7452 priv->invisible_char = ch;
7453 g_object_notify (G_OBJECT (entry), "invisible-char");
7456 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7457 gtk_entry_recompute (entry);
7461 * gtk_entry_set_overwrite_mode:
7462 * @entry: a #GtkEntry
7463 * @overwrite: new value
7465 * Sets whether the text is overwritten when typing in the #GtkEntry.
7470 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7473 GtkEntryPrivate *priv = entry->priv;
7475 g_return_if_fail (GTK_IS_ENTRY (entry));
7477 if (priv->overwrite_mode == overwrite)
7480 gtk_entry_toggle_overwrite (entry);
7482 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7486 * gtk_entry_get_overwrite_mode:
7487 * @entry: a #GtkEntry
7489 * Gets the value set by gtk_entry_set_overwrite_mode().
7491 * Return value: whether the text is overwritten when typing.
7496 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7498 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7500 return entry->priv->overwrite_mode;
7504 * gtk_entry_get_text:
7505 * @entry: a #GtkEntry
7507 * Retrieves the contents of the entry widget.
7508 * See also gtk_editable_get_chars().
7510 * This is equivalent to:
7512 * <informalexample><programlisting>
7513 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7514 * </programlisting></informalexample>
7516 * Return value: a pointer to the contents of the widget as a
7517 * string. This string points to internally allocated
7518 * storage in the widget and must not be freed, modified or
7522 gtk_entry_get_text (GtkEntry *entry)
7524 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7526 return gtk_entry_buffer_get_text (get_buffer (entry));
7530 * gtk_entry_set_max_length:
7531 * @entry: a #GtkEntry
7532 * @max: the maximum length of the entry, or 0 for no maximum.
7533 * (other than the maximum length of entries.) The value passed in will
7534 * be clamped to the range 0-65536.
7536 * Sets the maximum allowed length of the contents of the widget. If
7537 * the current contents are longer than the given length, then they
7538 * will be truncated to fit.
7540 * This is equivalent to:
7542 * <informalexample><programlisting>
7543 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7544 * </programlisting></informalexample>
7547 gtk_entry_set_max_length (GtkEntry *entry,
7550 g_return_if_fail (GTK_IS_ENTRY (entry));
7551 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7555 * gtk_entry_get_max_length:
7556 * @entry: a #GtkEntry
7558 * Retrieves the maximum allowed length of the text in
7559 * @entry. See gtk_entry_set_max_length().
7561 * This is equivalent to:
7563 * <informalexample><programlisting>
7564 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7565 * </programlisting></informalexample>
7567 * Return value: the maximum allowed number of characters
7568 * in #GtkEntry, or 0 if there is no maximum.
7571 gtk_entry_get_max_length (GtkEntry *entry)
7573 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7575 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7579 * gtk_entry_get_text_length:
7580 * @entry: a #GtkEntry
7582 * Retrieves the current length of the text in
7585 * This is equivalent to:
7587 * <informalexample><programlisting>
7588 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7589 * </programlisting></informalexample>
7591 * Return value: the current number of characters
7592 * in #GtkEntry, or 0 if there are none.
7597 gtk_entry_get_text_length (GtkEntry *entry)
7599 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7601 return gtk_entry_buffer_get_length (get_buffer (entry));
7605 * gtk_entry_set_activates_default:
7606 * @entry: a #GtkEntry
7607 * @setting: %TRUE to activate window's default widget on Enter keypress
7609 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7610 * widget for the window containing the entry. This usually means that
7611 * the dialog box containing the entry will be closed, since the default
7612 * widget is usually one of the dialog buttons.
7614 * (For experts: if @setting is %TRUE, the entry calls
7615 * gtk_window_activate_default() on the window containing the entry, in
7616 * the default handler for the #GtkEntry::activate signal.)
7619 gtk_entry_set_activates_default (GtkEntry *entry,
7622 GtkEntryPrivate *priv;
7624 g_return_if_fail (GTK_IS_ENTRY (entry));
7628 setting = setting != FALSE;
7630 if (setting != priv->activates_default)
7632 priv->activates_default = setting;
7633 g_object_notify (G_OBJECT (entry), "activates-default");
7638 * gtk_entry_get_activates_default:
7639 * @entry: a #GtkEntry
7641 * Retrieves the value set by gtk_entry_set_activates_default().
7643 * Return value: %TRUE if the entry will activate the default widget
7646 gtk_entry_get_activates_default (GtkEntry *entry)
7648 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7650 return entry->priv->activates_default;
7654 * gtk_entry_set_width_chars:
7655 * @entry: a #GtkEntry
7656 * @n_chars: width in chars
7658 * Changes the size request of the entry to be about the right size
7659 * for @n_chars characters. Note that it changes the size
7660 * <emphasis>request</emphasis>, the size can still be affected by
7661 * how you pack the widget into containers. If @n_chars is -1, the
7662 * size reverts to the default entry size.
7665 gtk_entry_set_width_chars (GtkEntry *entry,
7668 GtkEntryPrivate *priv;
7670 g_return_if_fail (GTK_IS_ENTRY (entry));
7674 if (priv->width_chars != n_chars)
7676 priv->width_chars = n_chars;
7677 g_object_notify (G_OBJECT (entry), "width-chars");
7678 gtk_widget_queue_resize (GTK_WIDGET (entry));
7683 * gtk_entry_get_width_chars:
7684 * @entry: a #GtkEntry
7686 * Gets the value set by gtk_entry_set_width_chars().
7688 * Return value: number of chars to request space for, or negative if unset
7691 gtk_entry_get_width_chars (GtkEntry *entry)
7693 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7695 return entry->priv->width_chars;
7699 * gtk_entry_set_has_frame:
7700 * @entry: a #GtkEntry
7701 * @setting: new value
7703 * Sets whether the entry has a beveled frame around it.
7706 gtk_entry_set_has_frame (GtkEntry *entry,
7709 GtkEntryPrivate *priv;
7711 g_return_if_fail (GTK_IS_ENTRY (entry));
7715 setting = (setting != FALSE);
7717 if (priv->has_frame == setting)
7720 gtk_widget_queue_resize (GTK_WIDGET (entry));
7721 priv->has_frame = setting;
7722 g_object_notify (G_OBJECT (entry), "has-frame");
7726 * gtk_entry_get_has_frame:
7727 * @entry: a #GtkEntry
7729 * Gets the value set by gtk_entry_set_has_frame().
7731 * Return value: whether the entry has a beveled frame
7734 gtk_entry_get_has_frame (GtkEntry *entry)
7736 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7738 return entry->priv->has_frame;
7742 * gtk_entry_set_inner_border:
7743 * @entry: a #GtkEntry
7744 * @border: (allow-none): a #GtkBorder, or %NULL
7746 * Sets %entry's inner-border property to %border, or clears it if %NULL
7747 * is passed. The inner-border is the area around the entry's text, but
7750 * If set, this property overrides the inner-border style property.
7751 * Overriding the style-provided border is useful when you want to do
7752 * in-place editing of some text in a canvas or list widget, where
7753 * pixel-exact positioning of the entry is important.
7757 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7758 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7759 * this function is ignored by #GtkEntry.
7762 gtk_entry_set_inner_border (GtkEntry *entry,
7763 const GtkBorder *border)
7765 g_return_if_fail (GTK_IS_ENTRY (entry));
7767 gtk_entry_do_set_inner_border (entry, border);
7771 * gtk_entry_get_inner_border:
7772 * @entry: a #GtkEntry
7774 * This function returns the entry's #GtkEntry:inner-border property. See
7775 * gtk_entry_set_inner_border() for more information.
7777 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7781 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7782 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7783 * this function is ignored by #GtkEntry.
7786 gtk_entry_get_inner_border (GtkEntry *entry)
7788 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7790 return gtk_entry_do_get_inner_border (entry);
7794 * gtk_entry_get_layout:
7795 * @entry: a #GtkEntry
7797 * Gets the #PangoLayout used to display the entry.
7798 * The layout is useful to e.g. convert text positions to
7799 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7800 * The returned layout is owned by the entry and must not be
7801 * modified or freed by the caller.
7803 * Keep in mind that the layout text may contain a preedit string, so
7804 * gtk_entry_layout_index_to_text_index() and
7805 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7806 * indices in the layout to byte indices in the entry contents.
7808 * Return value: (transfer none): the #PangoLayout for this entry
7811 gtk_entry_get_layout (GtkEntry *entry)
7813 PangoLayout *layout;
7815 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7817 layout = gtk_entry_ensure_layout (entry, TRUE);
7824 * gtk_entry_layout_index_to_text_index:
7825 * @entry: a #GtkEntry
7826 * @layout_index: byte index into the entry layout text
7828 * Converts from a position in the entry contents (returned
7829 * by gtk_entry_get_text()) to a position in the
7830 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7831 * with text retrieved via pango_layout_get_text()).
7833 * Return value: byte index into the entry contents
7836 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7839 GtkEntryPrivate *priv;
7840 PangoLayout *layout;
7844 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7848 layout = gtk_entry_ensure_layout (entry, TRUE);
7849 text = pango_layout_get_text (layout);
7850 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7852 if (layout_index >= cursor_index && priv->preedit_length)
7854 if (layout_index >= cursor_index + priv->preedit_length)
7855 layout_index -= priv->preedit_length;
7857 layout_index = cursor_index;
7860 return layout_index;
7864 * gtk_entry_text_index_to_layout_index:
7865 * @entry: a #GtkEntry
7866 * @text_index: byte index into the entry contents
7868 * Converts from a position in the entry's #PangoLayout (returned by
7869 * gtk_entry_get_layout()) to a position in the entry contents
7870 * (returned by gtk_entry_get_text()).
7872 * Return value: byte index into the entry layout text
7875 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7878 GtkEntryPrivate *priv;
7879 PangoLayout *layout;
7883 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7887 layout = gtk_entry_ensure_layout (entry, TRUE);
7888 text = pango_layout_get_text (layout);
7889 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7891 if (text_index > cursor_index)
7892 text_index += priv->preedit_length;
7898 * gtk_entry_get_layout_offsets:
7899 * @entry: a #GtkEntry
7900 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7901 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7904 * Obtains the position of the #PangoLayout used to render text
7905 * in the entry, in widget coordinates. Useful if you want to line
7906 * up the text in an entry with some other text, e.g. when using the
7907 * entry to implement editable cells in a sheet widget.
7909 * Also useful to convert mouse events into coordinates inside the
7910 * #PangoLayout, e.g. to take some action if some part of the entry text
7913 * Note that as the user scrolls around in the entry the offsets will
7914 * change; you'll need to connect to the "notify::scroll-offset"
7915 * signal to track this. Remember when using the #PangoLayout
7916 * functions you need to convert to and from pixels using
7917 * PANGO_PIXELS() or #PANGO_SCALE.
7919 * Keep in mind that the layout text may contain a preedit string, so
7920 * gtk_entry_layout_index_to_text_index() and
7921 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7922 * indices in the layout to byte indices in the entry contents.
7925 gtk_entry_get_layout_offsets (GtkEntry *entry,
7929 gint text_area_x, text_area_y;
7931 g_return_if_fail (GTK_IS_ENTRY (entry));
7933 /* this gets coords relative to text area */
7934 get_layout_position (entry, x, y);
7936 /* convert to widget coords */
7937 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7948 * gtk_entry_set_alignment:
7949 * @entry: a #GtkEntry
7950 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7951 * Reversed for RTL layouts
7953 * Sets the alignment for the contents of the entry. This controls
7954 * the horizontal positioning of the contents when the displayed
7955 * text is shorter than the width of the entry.
7960 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7962 GtkEntryPrivate *priv;
7964 g_return_if_fail (GTK_IS_ENTRY (entry));
7970 else if (xalign > 1.0)
7973 if (xalign != priv->xalign)
7975 priv->xalign = xalign;
7977 gtk_entry_recompute (entry);
7979 g_object_notify (G_OBJECT (entry), "xalign");
7984 * gtk_entry_get_alignment:
7985 * @entry: a #GtkEntry
7987 * Gets the value set by gtk_entry_set_alignment().
7989 * Return value: the alignment
7994 gtk_entry_get_alignment (GtkEntry *entry)
7996 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7998 return entry->priv->xalign;
8002 * gtk_entry_set_icon_from_pixbuf:
8003 * @entry: a #GtkEntry
8004 * @icon_pos: Icon position
8005 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
8007 * Sets the icon shown in the specified position using a pixbuf.
8009 * If @pixbuf is %NULL, no icon will be shown in the specified position.
8014 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
8015 GtkEntryIconPosition icon_pos,
8018 GtkEntryPrivate *priv;
8019 EntryIconInfo *icon_info;
8021 g_return_if_fail (GTK_IS_ENTRY (entry));
8022 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8026 if ((icon_info = priv->icons[icon_pos]) == NULL)
8027 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8029 g_object_freeze_notify (G_OBJECT (entry));
8032 g_object_ref (pixbuf);
8034 gtk_entry_clear (entry, icon_pos);
8038 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
8039 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
8040 GTK_ICON_SIZE_MENU);
8042 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8044 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
8045 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8049 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
8050 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8053 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8054 gdk_window_show_unraised (icon_info->window);
8056 g_object_unref (pixbuf);
8059 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8060 gtk_widget_queue_resize (GTK_WIDGET (entry));
8062 g_object_thaw_notify (G_OBJECT (entry));
8066 * gtk_entry_set_icon_from_stock:
8067 * @entry: A #GtkEntry
8068 * @icon_pos: Icon position
8069 * @stock_id: (allow-none): The name of the stock item, or %NULL
8071 * Sets the icon shown in the entry at the specified position from
8074 * If @stock_id is %NULL, no icon will be shown in the specified position.
8079 gtk_entry_set_icon_from_stock (GtkEntry *entry,
8080 GtkEntryIconPosition icon_pos,
8081 const gchar *stock_id)
8083 GtkEntryPrivate *priv;
8084 EntryIconInfo *icon_info;
8087 g_return_if_fail (GTK_IS_ENTRY (entry));
8088 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8092 if ((icon_info = priv->icons[icon_pos]) == NULL)
8093 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8095 g_object_freeze_notify (G_OBJECT (entry));
8097 /* need to dup before clearing */
8098 new_id = g_strdup (stock_id);
8100 gtk_entry_clear (entry, icon_pos);
8104 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
8106 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8108 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
8109 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8113 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
8114 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8117 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8118 gdk_window_show_unraised (icon_info->window);
8123 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8124 gtk_widget_queue_resize (GTK_WIDGET (entry));
8126 g_object_thaw_notify (G_OBJECT (entry));
8130 * gtk_entry_set_icon_from_icon_name:
8131 * @entry: A #GtkEntry
8132 * @icon_pos: The position at which to set the icon
8133 * @icon_name: (allow-none): An icon name, or %NULL
8135 * Sets the icon shown in the entry at the specified position
8136 * from the current icon theme.
8138 * If the icon name isn't known, a "broken image" icon will be displayed
8141 * If @icon_name is %NULL, no icon will be shown in the specified position.
8146 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
8147 GtkEntryIconPosition icon_pos,
8148 const gchar *icon_name)
8150 GtkEntryPrivate *priv;
8151 EntryIconInfo *icon_info;
8154 g_return_if_fail (GTK_IS_ENTRY (entry));
8155 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8159 if ((icon_info = priv->icons[icon_pos]) == NULL)
8160 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8162 g_object_freeze_notify (G_OBJECT (entry));
8164 /* need to dup before clearing */
8165 new_name = g_strdup (icon_name);
8167 gtk_entry_clear (entry, icon_pos);
8169 if (new_name != NULL)
8171 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
8173 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8175 g_object_notify (G_OBJECT (entry), "primary-icon-name");
8176 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8180 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
8181 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8184 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8185 gdk_window_show_unraised (icon_info->window);
8190 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8191 gtk_widget_queue_resize (GTK_WIDGET (entry));
8193 g_object_thaw_notify (G_OBJECT (entry));
8197 * gtk_entry_set_icon_from_gicon:
8198 * @entry: A #GtkEntry
8199 * @icon_pos: The position at which to set the icon
8200 * @icon: (allow-none): The icon to set, or %NULL
8202 * Sets the icon shown in the entry at the specified position
8203 * from the current icon theme.
8204 * If the icon isn't known, a "broken image" icon will be displayed
8207 * If @icon is %NULL, no icon will be shown in the specified position.
8212 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
8213 GtkEntryIconPosition icon_pos,
8216 GtkEntryPrivate *priv;
8217 EntryIconInfo *icon_info;
8219 g_return_if_fail (GTK_IS_ENTRY (entry));
8220 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8224 if ((icon_info = priv->icons[icon_pos]) == NULL)
8225 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8227 g_object_freeze_notify (G_OBJECT (entry));
8229 /* need to ref before clearing */
8231 g_object_ref (icon);
8233 gtk_entry_clear (entry, icon_pos);
8237 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
8239 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8241 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8242 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8246 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8247 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8250 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8251 gdk_window_show_unraised (icon_info->window);
8253 g_object_unref (icon);
8256 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8257 gtk_widget_queue_resize (GTK_WIDGET (entry));
8259 g_object_thaw_notify (G_OBJECT (entry));
8263 * gtk_entry_set_icon_activatable:
8264 * @entry: A #GtkEntry
8265 * @icon_pos: Icon position
8266 * @activatable: %TRUE if the icon should be activatable
8268 * Sets whether the icon is activatable.
8273 gtk_entry_set_icon_activatable (GtkEntry *entry,
8274 GtkEntryIconPosition icon_pos,
8275 gboolean activatable)
8277 GtkEntryPrivate *priv;
8278 EntryIconInfo *icon_info;
8280 g_return_if_fail (GTK_IS_ENTRY (entry));
8281 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8285 if ((icon_info = priv->icons[icon_pos]) == NULL)
8286 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8288 activatable = activatable != FALSE;
8290 if (icon_info->nonactivatable != !activatable)
8292 icon_info->nonactivatable = !activatable;
8294 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8295 update_cursors (GTK_WIDGET (entry));
8297 g_object_notify (G_OBJECT (entry),
8298 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8303 * gtk_entry_get_icon_activatable:
8304 * @entry: a #GtkEntry
8305 * @icon_pos: Icon position
8307 * Returns whether the icon is activatable.
8309 * Returns: %TRUE if the icon is activatable.
8314 gtk_entry_get_icon_activatable (GtkEntry *entry,
8315 GtkEntryIconPosition icon_pos)
8317 GtkEntryPrivate *priv;
8318 EntryIconInfo *icon_info;
8320 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8321 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8324 icon_info = priv->icons[icon_pos];
8326 return (!icon_info || !icon_info->nonactivatable);
8330 * gtk_entry_get_icon_pixbuf:
8331 * @entry: A #GtkEntry
8332 * @icon_pos: Icon position
8334 * Retrieves the image used for the icon.
8336 * Unlike the other methods of setting and getting icon data, this
8337 * method will work regardless of whether the icon was set using a
8338 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8340 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8341 * set for this position.
8346 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8347 GtkEntryIconPosition icon_pos)
8349 GtkEntryPrivate *priv;
8350 EntryIconInfo *icon_info;
8353 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8354 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8358 icon_info = priv->icons[icon_pos];
8363 /* HACK: unfortunately this is transfer none, so we need to return
8364 * the icon helper's cache ref directly.
8366 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
8368 g_object_unref (pixbuf);
8374 * gtk_entry_get_icon_gicon:
8375 * @entry: A #GtkEntry
8376 * @icon_pos: Icon position
8378 * Retrieves the #GIcon used for the icon, or %NULL if there is
8379 * no icon or if the icon was set by some other method (e.g., by
8380 * stock, pixbuf, or icon name).
8382 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8383 * or if the icon is not a #GIcon
8388 gtk_entry_get_icon_gicon (GtkEntry *entry,
8389 GtkEntryIconPosition icon_pos)
8391 GtkEntryPrivate *priv;
8392 EntryIconInfo *icon_info;
8394 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8395 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8398 icon_info = priv->icons[icon_pos];
8403 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
8407 * gtk_entry_get_icon_stock:
8408 * @entry: A #GtkEntry
8409 * @icon_pos: Icon position
8411 * Retrieves the stock id used for the icon, or %NULL if there is
8412 * no icon or if the icon was set by some other method (e.g., by
8413 * pixbuf, icon name or gicon).
8415 * Returns: A stock id, or %NULL if no icon is set or if the icon
8416 * wasn't set from a stock id
8421 gtk_entry_get_icon_stock (GtkEntry *entry,
8422 GtkEntryIconPosition icon_pos)
8424 GtkEntryPrivate *priv;
8425 EntryIconInfo *icon_info;
8427 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8428 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8431 icon_info = priv->icons[icon_pos];
8436 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8440 * gtk_entry_get_icon_name:
8441 * @entry: A #GtkEntry
8442 * @icon_pos: Icon position
8444 * Retrieves the icon name used for the icon, or %NULL if there is
8445 * no icon or if the icon was set by some other method (e.g., by
8446 * pixbuf, stock or gicon).
8448 * Returns: An icon name, or %NULL if no icon is set or if the icon
8449 * wasn't set from an icon name
8454 gtk_entry_get_icon_name (GtkEntry *entry,
8455 GtkEntryIconPosition icon_pos)
8457 GtkEntryPrivate *priv;
8458 EntryIconInfo *icon_info;
8460 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8461 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8464 icon_info = priv->icons[icon_pos];
8469 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8473 * gtk_entry_set_icon_sensitive:
8474 * @entry: A #GtkEntry
8475 * @icon_pos: Icon position
8476 * @sensitive: Specifies whether the icon should appear
8477 * sensitive or insensitive
8479 * Sets the sensitivity for the specified icon.
8484 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8485 GtkEntryIconPosition icon_pos,
8488 GtkEntryPrivate *priv;
8489 EntryIconInfo *icon_info;
8491 g_return_if_fail (GTK_IS_ENTRY (entry));
8492 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8496 if ((icon_info = priv->icons[icon_pos]) == NULL)
8497 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8499 if (icon_info->insensitive != !sensitive)
8501 icon_info->insensitive = !sensitive;
8503 icon_info->pressed = FALSE;
8504 icon_info->prelight = FALSE;
8506 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8507 update_cursors (GTK_WIDGET (entry));
8509 gtk_widget_queue_draw (GTK_WIDGET (entry));
8511 g_object_notify (G_OBJECT (entry),
8512 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8517 * gtk_entry_get_icon_sensitive:
8518 * @entry: a #GtkEntry
8519 * @icon_pos: Icon position
8521 * Returns whether the icon appears sensitive or insensitive.
8523 * Returns: %TRUE if the icon is sensitive.
8528 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8529 GtkEntryIconPosition icon_pos)
8531 GtkEntryPrivate *priv;
8532 EntryIconInfo *icon_info;
8534 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8535 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8539 icon_info = priv->icons[icon_pos];
8541 return (!icon_info || !icon_info->insensitive);
8546 * gtk_entry_get_icon_storage_type:
8547 * @entry: a #GtkEntry
8548 * @icon_pos: Icon position
8550 * Gets the type of representation being used by the icon
8551 * to store image data. If the icon has no image data,
8552 * the return value will be %GTK_IMAGE_EMPTY.
8554 * Return value: image representation being used
8559 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8560 GtkEntryIconPosition icon_pos)
8562 GtkEntryPrivate *priv;
8563 EntryIconInfo *icon_info;
8565 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8566 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8570 icon_info = priv->icons[icon_pos];
8573 return GTK_IMAGE_EMPTY;
8575 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8579 * gtk_entry_get_icon_at_pos:
8580 * @entry: a #GtkEntry
8581 * @x: the x coordinate of the position to find
8582 * @y: the y coordinate of the position to find
8584 * Finds the icon at the given position and return its index. The
8585 * position's coordinates are relative to the @entry's top left corner.
8586 * If @x, @y doesn't lie inside an icon, -1 is returned.
8587 * This function is intended for use in a #GtkWidget::query-tooltip
8590 * Returns: the index of the icon at the given position, or -1
8595 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8599 GtkAllocation primary;
8600 GtkAllocation secondary;
8601 gint frame_x, frame_y;
8603 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8605 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8609 get_icon_allocations (entry, &primary, &secondary);
8611 if (primary.x <= x && x < primary.x + primary.width &&
8612 primary.y <= y && y < primary.y + primary.height)
8613 return GTK_ENTRY_ICON_PRIMARY;
8615 if (secondary.x <= x && x < secondary.x + secondary.width &&
8616 secondary.y <= y && y < secondary.y + secondary.height)
8617 return GTK_ENTRY_ICON_SECONDARY;
8623 * gtk_entry_set_icon_drag_source:
8624 * @entry: a #GtkEntry
8625 * @icon_pos: icon position
8626 * @target_list: the targets (data formats) in which the data can be provided
8627 * @actions: a bitmask of the allowed drag actions
8629 * Sets up the icon at the given position so that GTK+ will start a drag
8630 * operation when the user clicks and drags the icon.
8632 * To handle the drag operation, you need to connect to the usual
8633 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8634 * signal, and use gtk_entry_get_current_icon_drag_source() in
8635 * your signal handler to find out if the drag was started from
8638 * By default, GTK+ uses the icon as the drag icon. You can use the
8639 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8640 * have to use g_signal_connect_after() to ensure that your signal handler
8641 * gets executed after the default handler.
8646 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8647 GtkEntryIconPosition icon_pos,
8648 GtkTargetList *target_list,
8649 GdkDragAction actions)
8651 GtkEntryPrivate *priv;
8652 EntryIconInfo *icon_info;
8654 g_return_if_fail (GTK_IS_ENTRY (entry));
8655 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8659 if ((icon_info = priv->icons[icon_pos]) == NULL)
8660 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8662 if (icon_info->target_list)
8663 gtk_target_list_unref (icon_info->target_list);
8664 icon_info->target_list = target_list;
8665 if (icon_info->target_list)
8666 gtk_target_list_ref (icon_info->target_list);
8668 icon_info->actions = actions;
8672 * gtk_entry_get_current_icon_drag_source:
8673 * @entry: a #GtkIconEntry
8675 * Returns the index of the icon which is the source of the current
8676 * DND operation, or -1.
8678 * This function is meant to be used in a #GtkWidget::drag-data-get
8681 * Returns: index of the icon which is the source of the current
8682 * DND operation, or -1.
8687 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8689 GtkEntryPrivate *priv;
8690 EntryIconInfo *icon_info = NULL;
8693 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8697 for (i = 0; i < MAX_ICONS; i++)
8699 if ((icon_info = priv->icons[i]))
8701 if (icon_info->in_drag)
8710 * gtk_entry_get_icon_area:
8711 * @entry: A #GtkEntry
8712 * @icon_pos: Icon position
8713 * @icon_area: (out): Return location for the icon's area
8715 * Gets the area where entry's icon at @icon_pos is drawn.
8716 * This function is useful when drawing something to the
8717 * entry in a draw callback.
8719 * If the entry is not realized or has no icon at the given position,
8720 * @icon_area is filled with zeros.
8722 * See also gtk_entry_get_text_area()
8727 gtk_entry_get_icon_area (GtkEntry *entry,
8728 GtkEntryIconPosition icon_pos,
8729 GdkRectangle *icon_area)
8731 GtkEntryPrivate *priv;
8732 EntryIconInfo *icon_info;
8734 g_return_if_fail (GTK_IS_ENTRY (entry));
8735 g_return_if_fail (icon_area != NULL);
8739 icon_info = priv->icons[icon_pos];
8743 GtkAllocation primary;
8744 GtkAllocation secondary;
8746 get_icon_allocations (entry, &primary, &secondary);
8748 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8749 *icon_area = primary;
8751 *icon_area = secondary;
8757 icon_area->width = 0;
8758 icon_area->height = 0;
8763 ensure_has_tooltip (GtkEntry *entry)
8765 GtkEntryPrivate *priv;
8766 EntryIconInfo *icon_info;
8768 gboolean has_tooltip = FALSE;
8772 for (i = 0; i < MAX_ICONS; i++)
8774 if ((icon_info = priv->icons[i]) != NULL)
8776 if (icon_info->tooltip != NULL)
8784 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8788 * gtk_entry_get_icon_tooltip_text:
8789 * @entry: a #GtkEntry
8790 * @icon_pos: the icon position
8792 * Gets the contents of the tooltip on the icon at the specified
8793 * position in @entry.
8795 * Returns: the tooltip text, or %NULL. Free the returned string
8796 * with g_free() when done.
8801 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8802 GtkEntryIconPosition icon_pos)
8804 GtkEntryPrivate *priv;
8805 EntryIconInfo *icon_info;
8808 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8809 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8813 icon_info = priv->icons[icon_pos];
8818 if (icon_info->tooltip &&
8819 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8820 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8826 * gtk_entry_set_icon_tooltip_text:
8827 * @entry: a #GtkEntry
8828 * @icon_pos: the icon position
8829 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8831 * Sets @tooltip as the contents of the tooltip for the icon
8832 * at the specified position.
8834 * Use %NULL for @tooltip to remove an existing tooltip.
8836 * See also gtk_widget_set_tooltip_text() and
8837 * gtk_entry_set_icon_tooltip_markup().
8842 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8843 GtkEntryIconPosition icon_pos,
8844 const gchar *tooltip)
8846 GtkEntryPrivate *priv;
8847 EntryIconInfo *icon_info;
8849 g_return_if_fail (GTK_IS_ENTRY (entry));
8850 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8854 if ((icon_info = priv->icons[icon_pos]) == NULL)
8855 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8857 if (icon_info->tooltip)
8858 g_free (icon_info->tooltip);
8860 /* Treat an empty string as a NULL string,
8861 * because an empty string would be useless for a tooltip:
8863 if (tooltip && tooltip[0] == '\0')
8866 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8868 ensure_has_tooltip (entry);
8870 g_object_notify (G_OBJECT (entry),
8871 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-tooltip-text" : "secondary-icon-tooltip-text");
8875 * gtk_entry_get_icon_tooltip_markup:
8876 * @entry: a #GtkEntry
8877 * @icon_pos: the icon position
8879 * Gets the contents of the tooltip on the icon at the specified
8880 * position in @entry.
8882 * Returns: the tooltip text, or %NULL. Free the returned string
8883 * with g_free() when done.
8888 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8889 GtkEntryIconPosition icon_pos)
8891 GtkEntryPrivate *priv;
8892 EntryIconInfo *icon_info;
8894 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8895 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8899 icon_info = priv->icons[icon_pos];
8904 return g_strdup (icon_info->tooltip);
8908 * gtk_entry_set_icon_tooltip_markup:
8909 * @entry: a #GtkEntry
8910 * @icon_pos: the icon position
8911 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8913 * Sets @tooltip as the contents of the tooltip for the icon at
8914 * the specified position. @tooltip is assumed to be marked up with
8915 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8917 * Use %NULL for @tooltip to remove an existing tooltip.
8919 * See also gtk_widget_set_tooltip_markup() and
8920 * gtk_entry_set_icon_tooltip_text().
8925 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8926 GtkEntryIconPosition icon_pos,
8927 const gchar *tooltip)
8929 GtkEntryPrivate *priv;
8930 EntryIconInfo *icon_info;
8932 g_return_if_fail (GTK_IS_ENTRY (entry));
8933 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8937 if ((icon_info = priv->icons[icon_pos]) == NULL)
8938 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8940 if (icon_info->tooltip)
8941 g_free (icon_info->tooltip);
8943 /* Treat an empty string as a NULL string,
8944 * because an empty string would be useless for a tooltip:
8946 if (tooltip && tooltip[0] == '\0')
8949 icon_info->tooltip = g_strdup (tooltip);
8951 ensure_has_tooltip (entry);
8955 gtk_entry_query_tooltip (GtkWidget *widget,
8958 gboolean keyboard_tip,
8959 GtkTooltip *tooltip)
8962 GtkEntryPrivate *priv;
8963 EntryIconInfo *icon_info;
8966 entry = GTK_ENTRY (widget);
8971 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8974 if ((icon_info = priv->icons[icon_pos]) != NULL)
8976 if (icon_info->tooltip)
8978 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8987 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8994 /* Quick hack of a popup menu
8997 activate_cb (GtkWidget *menuitem,
9000 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
9001 g_signal_emit_by_name (entry, signal);
9006 gtk_entry_mnemonic_activate (GtkWidget *widget,
9007 gboolean group_cycling)
9009 gtk_widget_grab_focus (widget);
9014 gtk_entry_grab_notify (GtkWidget *widget,
9015 gboolean was_grabbed)
9017 GtkEntryPrivate *priv;
9019 priv = GTK_ENTRY (widget)->priv;
9022 gtk_widget_device_is_shadowed (widget, priv->device))
9024 /* Unset button so we don't expect
9025 * a button release anymore
9028 priv->device = NULL;
9029 priv->in_drag = FALSE;
9034 append_action_signal (GtkEntry *entry,
9036 const gchar *stock_id,
9037 const gchar *signal,
9040 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
9042 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
9043 g_signal_connect (menuitem, "activate",
9044 G_CALLBACK (activate_cb), entry);
9046 gtk_widget_set_sensitive (menuitem, sensitive);
9048 gtk_widget_show (menuitem);
9049 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
9053 popup_menu_detach (GtkWidget *attach_widget,
9056 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
9057 GtkEntryPrivate *priv_attach = entry_attach->priv;
9059 priv_attach->popup_menu = NULL;
9063 popup_position_func (GtkMenu *menu,
9069 GtkEntry *entry = GTK_ENTRY (user_data);
9070 GtkEntryPrivate *priv = entry->priv;
9071 GtkWidget *widget = GTK_WIDGET (entry);
9073 GtkRequisition menu_req;
9074 GdkRectangle monitor;
9076 gint monitor_num, strong_x, height;
9078 g_return_if_fail (gtk_widget_get_realized (widget));
9080 gdk_window_get_origin (priv->text_area, x, y);
9082 screen = gtk_widget_get_screen (widget);
9083 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
9084 if (monitor_num < 0)
9086 gtk_menu_set_monitor (menu, monitor_num);
9088 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
9089 gtk_widget_get_preferred_size (priv->popup_menu,
9091 height = gdk_window_get_height (priv->text_area);
9092 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
9093 _gtk_entry_get_borders (entry, &borders);
9095 *x += borders.left + strong_x - priv->scroll_offset;
9096 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
9097 *x -= menu_req.width;
9099 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
9101 else if ((*y - menu_req.height) >= monitor.y)
9102 *y -= menu_req.height;
9103 else if (monitor.y + monitor.height - (*y + height) > *y)
9106 *y -= menu_req.height;
9112 unichar_chosen_func (const char *text,
9115 GtkEntry *entry = GTK_ENTRY (data);
9116 GtkEntryPrivate *priv = entry->priv;
9119 gtk_entry_enter_text (entry, text);
9131 popup_targets_received (GtkClipboard *clipboard,
9132 GtkSelectionData *data,
9135 PopupInfo *info = user_data;
9136 GtkEntry *entry = info->entry;
9137 GtkEntryPrivate *info_entry_priv = entry->priv;
9139 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
9142 gboolean clipboard_contains_text;
9143 GtkWidget *menuitem;
9145 gboolean show_input_method_menu;
9146 gboolean show_unicode_menu;
9148 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
9149 if (info_entry_priv->popup_menu)
9150 gtk_widget_destroy (info_entry_priv->popup_menu);
9152 info_entry_priv->popup_menu = gtk_menu_new ();
9154 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
9158 mode = gtk_entry_get_display_mode (entry);
9159 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
9160 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
9161 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9163 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
9164 mode == DISPLAY_NORMAL &&
9165 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9167 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
9168 info_entry_priv->editable && clipboard_contains_text);
9170 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
9171 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
9172 g_signal_connect_swapped (menuitem, "activate",
9173 G_CALLBACK (gtk_entry_delete_cb), entry);
9174 gtk_widget_show (menuitem);
9175 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9177 menuitem = gtk_separator_menu_item_new ();
9178 gtk_widget_show (menuitem);
9179 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9181 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
9182 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
9183 g_signal_connect_swapped (menuitem, "activate",
9184 G_CALLBACK (gtk_entry_select_all), entry);
9185 gtk_widget_show (menuitem);
9186 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9188 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
9189 "gtk-show-input-method-menu", &show_input_method_menu,
9190 "gtk-show-unicode-menu", &show_unicode_menu,
9193 if (show_input_method_menu || show_unicode_menu)
9195 menuitem = gtk_separator_menu_item_new ();
9196 gtk_widget_show (menuitem);
9197 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9200 if (show_input_method_menu)
9202 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
9203 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9204 gtk_widget_show (menuitem);
9205 submenu = gtk_menu_new ();
9206 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9208 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9210 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
9211 GTK_MENU_SHELL (submenu));
9214 if (show_unicode_menu)
9216 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
9217 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9218 gtk_widget_show (menuitem);
9220 submenu = gtk_menu_new ();
9221 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9222 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9224 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
9225 unichar_chosen_func,
9229 g_signal_emit (entry,
9230 signals[POPULATE_POPUP],
9232 info_entry_priv->popup_menu);
9236 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
9237 info->device, NULL, NULL, NULL, NULL, NULL,
9238 info->button, info->time);
9241 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
9242 popup_position_func, entry,
9243 0, gtk_get_current_event_time ());
9244 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9248 g_object_unref (entry);
9249 g_slice_free (PopupInfo, info);
9253 gtk_entry_do_popup (GtkEntry *entry,
9254 GdkEventButton *event)
9256 PopupInfo *info = g_slice_new (PopupInfo);
9258 /* In order to know what entries we should make sensitive, we
9259 * ask for the current targets of the clipboard, and when
9260 * we get them, then we actually pop up the menu.
9262 info->entry = g_object_ref (entry);
9266 info->button = event->button;
9267 info->time = event->time;
9268 info->device = event->device;
9273 info->time = gtk_get_current_event_time ();
9274 info->device = NULL;
9277 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9278 gdk_atom_intern_static_string ("TARGETS"),
9279 popup_targets_received,
9284 gtk_entry_popup_menu (GtkWidget *widget)
9286 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9291 activate_bubble_cb (GtkWidget *item,
9294 const gchar *signal = g_object_get_data (G_OBJECT (item), "gtk-signal");
9295 g_signal_emit_by_name (entry, signal);
9296 _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (entry->priv->selection_bubble));
9300 append_bubble_action (GtkEntry *entry,
9302 const gchar *stock_id,
9303 const gchar *signal,
9306 GtkToolItem *item = gtk_tool_button_new_from_stock (stock_id);
9307 g_object_set_data (G_OBJECT (item), I_("gtk-signal"), (char *)signal);
9308 g_signal_connect (item, "clicked", G_CALLBACK (activate_bubble_cb), entry);
9309 gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive);
9310 gtk_widget_show (GTK_WIDGET (item));
9311 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
9315 bubble_targets_received (GtkClipboard *clipboard,
9316 GtkSelectionData *data,
9319 GtkEntry *entry = user_data;
9320 GtkEntryPrivate *priv = entry->priv;
9321 cairo_rectangle_int_t rect;
9322 GtkAllocation allocation;
9323 gint start_x, end_x;
9324 gboolean has_selection;
9325 gboolean has_clipboard;
9329 has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
9331 if (!has_selection && !priv->editable)
9333 priv->selection_bubble_timeout_id = 0;
9337 if (priv->selection_bubble)
9338 gtk_widget_destroy (priv->selection_bubble);
9340 priv->selection_bubble = _gtk_bubble_window_new ();
9341 toolbar = GTK_WIDGET (gtk_toolbar_new ());
9342 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT);
9343 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
9344 gtk_widget_show (toolbar);
9345 gtk_container_add (GTK_CONTAINER (priv->selection_bubble), toolbar);
9347 has_clipboard = gtk_selection_data_targets_include_text (data);
9348 mode = gtk_entry_get_display_mode (entry);
9350 append_bubble_action (entry, toolbar, GTK_STOCK_CUT, "cut-clipboard",
9351 priv->editable && has_selection && mode == DISPLAY_NORMAL);
9353 append_bubble_action (entry, toolbar, GTK_STOCK_COPY, "copy-clipboard",
9354 has_selection && mode == DISPLAY_NORMAL);
9356 append_bubble_action (entry, toolbar, GTK_STOCK_PASTE, "paste-clipboard",
9357 priv->editable && has_clipboard);
9359 if (priv->populate_toolbar)
9360 g_signal_emit (entry, signals[POPULATE_POPUP], 0, toolbar);
9362 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
9364 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &start_x, NULL);
9366 start_x -= priv->scroll_offset;
9367 start_x = CLAMP (start_x, 0, gdk_window_get_width (priv->text_area));
9370 rect.height = gdk_window_get_height (priv->text_area);
9374 end_x = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
9375 end_x = CLAMP (end_x, 0, gdk_window_get_width (priv->text_area));
9377 rect.x = MIN (start_x, end_x);
9378 rect.width = MAX (start_x, end_x) - rect.x;
9386 _gtk_bubble_window_popup (GTK_BUBBLE_WINDOW (priv->selection_bubble),
9387 priv->text_area, &rect, GTK_POS_TOP);
9389 priv->selection_bubble_timeout_id = 0;
9393 gtk_entry_selection_bubble_popup_cb (gpointer user_data)
9395 GtkEntry *entry = user_data;
9397 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9398 gdk_atom_intern_static_string ("TARGETS"),
9399 bubble_targets_received,
9401 return G_SOURCE_REMOVE;
9405 gtk_entry_selection_bubble_popup_unset (GtkEntry *entry)
9407 GtkEntryPrivate *priv;
9411 if (priv->selection_bubble)
9412 _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
9414 if (priv->selection_bubble_timeout_id)
9416 g_source_remove (priv->selection_bubble_timeout_id);
9417 priv->selection_bubble_timeout_id = 0;
9422 gtk_entry_selection_bubble_popup_set (GtkEntry *entry)
9424 GtkEntryPrivate *priv;
9428 if (priv->selection_bubble_timeout_id)
9429 g_source_remove (priv->selection_bubble_timeout_id);
9431 priv->selection_bubble_timeout_id =
9432 gdk_threads_add_timeout (1000, gtk_entry_selection_bubble_popup_cb, entry);
9436 gtk_entry_drag_begin (GtkWidget *widget,
9437 GdkDragContext *context)
9439 GtkEntry *entry = GTK_ENTRY (widget);
9440 GtkEntryPrivate *priv = entry->priv;
9443 for (i = 0; i < MAX_ICONS; i++)
9445 EntryIconInfo *icon_info = priv->icons[i];
9447 if (icon_info != NULL)
9449 if (icon_info->in_drag)
9453 pix = _gtk_icon_helper_ensure_pixbuf
9454 (icon_info->icon_helper,
9455 gtk_widget_get_style_context (GTK_WIDGET (entry)));
9456 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
9458 g_object_unref (pix);
9465 gtk_entry_drag_end (GtkWidget *widget,
9466 GdkDragContext *context)
9468 GtkEntry *entry = GTK_ENTRY (widget);
9469 GtkEntryPrivate *priv = entry->priv;
9472 for (i = 0; i < MAX_ICONS; i++)
9474 EntryIconInfo *icon_info = priv->icons[i];
9476 if (icon_info != NULL)
9477 icon_info->in_drag = 0;
9482 gtk_entry_drag_leave (GtkWidget *widget,
9483 GdkDragContext *context,
9486 GtkEntry *entry = GTK_ENTRY (widget);
9487 GtkEntryPrivate *priv = entry->priv;
9489 priv->dnd_position = -1;
9490 gtk_widget_queue_draw (widget);
9494 gtk_entry_drag_drop (GtkWidget *widget,
9495 GdkDragContext *context,
9500 GtkEntry *entry = GTK_ENTRY (widget);
9501 GtkEntryPrivate *priv = entry->priv;
9502 GdkAtom target = GDK_NONE;
9505 target = gtk_drag_dest_find_target (widget, context, NULL);
9507 if (target != GDK_NONE)
9508 gtk_drag_get_data (widget, context, target, time);
9510 gtk_drag_finish (context, FALSE, FALSE, time);
9516 gtk_entry_drag_motion (GtkWidget *widget,
9517 GdkDragContext *context,
9522 GtkEntry *entry = GTK_ENTRY (widget);
9523 GtkEntryPrivate *priv = entry->priv;
9524 GtkStyleContext *style_context;
9525 GtkWidget *source_widget;
9526 GdkDragAction suggested_action;
9527 gint new_position, old_position;
9531 style_context = gtk_widget_get_style_context (widget);
9532 gtk_style_context_get_padding (style_context, 0, &padding);
9536 old_position = priv->dnd_position;
9537 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9539 if (priv->editable &&
9540 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9542 source_widget = gtk_drag_get_source_widget (context);
9543 suggested_action = gdk_drag_context_get_suggested_action (context);
9545 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9546 new_position < sel1 || new_position > sel2)
9548 if (source_widget == widget)
9550 /* Default to MOVE, unless the user has
9551 * pressed ctrl or alt to affect available actions
9553 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9554 suggested_action = GDK_ACTION_MOVE;
9557 priv->dnd_position = new_position;
9561 if (source_widget == widget)
9562 suggested_action = 0; /* Can't drop in selection where drag started */
9564 priv->dnd_position = -1;
9569 /* Entry not editable, or no text */
9570 suggested_action = 0;
9571 priv->dnd_position = -1;
9574 gdk_drag_status (context, suggested_action, time);
9576 if (priv->dnd_position != old_position)
9577 gtk_widget_queue_draw (widget);
9583 gtk_entry_drag_data_received (GtkWidget *widget,
9584 GdkDragContext *context,
9587 GtkSelectionData *selection_data,
9591 GtkEntry *entry = GTK_ENTRY (widget);
9592 GtkEntryPrivate *priv = entry->priv;
9593 GtkEditable *editable = GTK_EDITABLE (widget);
9594 GtkStyleContext *style_context;
9598 str = (gchar *) gtk_selection_data_get_text (selection_data);
9600 style_context = gtk_widget_get_style_context (widget);
9601 gtk_style_context_get_padding (style_context, 0, &padding);
9605 if (str && priv->editable)
9611 if (priv->truncate_multiline)
9612 length = truncate_multiline (str);
9614 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9616 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9617 new_position < sel1 || new_position > sel2)
9619 gtk_editable_insert_text (editable, str, length, &new_position);
9623 /* Replacing selection */
9624 begin_change (entry);
9625 gtk_editable_delete_text (editable, sel1, sel2);
9626 gtk_editable_insert_text (editable, str, length, &sel1);
9630 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9634 /* Drag and drop didn't happen! */
9635 gtk_drag_finish (context, FALSE, FALSE, time);
9642 gtk_entry_drag_data_get (GtkWidget *widget,
9643 GdkDragContext *context,
9644 GtkSelectionData *selection_data,
9648 GtkEntry *entry = GTK_ENTRY (widget);
9649 GtkEntryPrivate *priv = entry->priv;
9650 GtkEditable *editable = GTK_EDITABLE (widget);
9651 gint sel_start, sel_end;
9654 /* If there is an icon drag going on, exit early. */
9655 for (i = 0; i < MAX_ICONS; i++)
9657 EntryIconInfo *icon_info = priv->icons[i];
9659 if (icon_info != NULL)
9661 if (icon_info->in_drag)
9666 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9668 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9670 gtk_selection_data_set_text (selection_data, str, -1);
9678 gtk_entry_drag_data_delete (GtkWidget *widget,
9679 GdkDragContext *context)
9681 GtkEntry *entry = GTK_ENTRY (widget);
9682 GtkEntryPrivate *priv = entry->priv;
9683 GtkEditable *editable = GTK_EDITABLE (widget);
9684 gint sel_start, sel_end;
9687 /* If there is an icon drag going on, exit early. */
9688 for (i = 0; i < MAX_ICONS; i++)
9690 EntryIconInfo *icon_info = priv->icons[i];
9692 if (icon_info != NULL)
9694 if (icon_info->in_drag)
9699 if (priv->editable &&
9700 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9701 gtk_editable_delete_text (editable, sel_start, sel_end);
9704 /* We display the cursor when
9706 * - the selection is empty, AND
9707 * - the widget has focus
9710 #define CURSOR_ON_MULTIPLIER 2
9711 #define CURSOR_OFF_MULTIPLIER 1
9712 #define CURSOR_PEND_MULTIPLIER 3
9713 #define CURSOR_DIVIDER 3
9716 cursor_blinks (GtkEntry *entry)
9718 GtkEntryPrivate *priv = entry->priv;
9720 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9722 priv->selection_bound == priv->current_pos)
9724 GtkSettings *settings;
9727 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9728 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9737 get_middle_click_paste (GtkEntry *entry)
9739 GtkSettings *settings;
9742 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9743 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9749 get_cursor_time (GtkEntry *entry)
9751 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9754 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9760 get_cursor_blink_timeout (GtkEntry *entry)
9762 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9765 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9771 show_cursor (GtkEntry *entry)
9773 GtkEntryPrivate *priv = entry->priv;
9776 if (!priv->cursor_visible)
9778 priv->cursor_visible = TRUE;
9780 widget = GTK_WIDGET (entry);
9781 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9782 gtk_widget_queue_draw (widget);
9787 hide_cursor (GtkEntry *entry)
9789 GtkEntryPrivate *priv = entry->priv;
9792 if (priv->cursor_visible)
9794 priv->cursor_visible = FALSE;
9796 widget = GTK_WIDGET (entry);
9797 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9798 gtk_widget_queue_draw (widget);
9806 blink_cb (gpointer data)
9809 GtkEntryPrivate *priv;
9812 entry = GTK_ENTRY (data);
9815 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9817 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9818 "connect a handler to this signal, it must return\n"
9819 "FALSE so the entry gets the event as well");
9821 gtk_entry_check_cursor_blink (entry);
9826 g_assert (priv->selection_bound == priv->current_pos);
9828 blink_timeout = get_cursor_blink_timeout (entry);
9829 if (priv->blink_time > 1000 * blink_timeout &&
9830 blink_timeout < G_MAXINT/1000)
9832 /* we've blinked enough without the user doing anything, stop blinking */
9833 show_cursor (entry);
9834 priv->blink_timeout = 0;
9836 else if (priv->cursor_visible)
9838 hide_cursor (entry);
9839 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9845 show_cursor (entry);
9846 priv->blink_time += get_cursor_time (entry);
9847 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9852 /* Remove ourselves */
9857 gtk_entry_check_cursor_blink (GtkEntry *entry)
9859 GtkEntryPrivate *priv = entry->priv;
9861 if (cursor_blinks (entry))
9863 if (!priv->blink_timeout)
9865 show_cursor (entry);
9866 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9873 if (priv->blink_timeout)
9875 g_source_remove (priv->blink_timeout);
9876 priv->blink_timeout = 0;
9879 priv->cursor_visible = TRUE;
9884 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9886 GtkEntryPrivate *priv = entry->priv;
9888 if (cursor_blinks (entry))
9890 if (priv->blink_timeout != 0)
9891 g_source_remove (priv->blink_timeout);
9893 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9896 show_cursor (entry);
9901 gtk_entry_reset_blink_time (GtkEntry *entry)
9903 GtkEntryPrivate *priv = entry->priv;
9905 priv->blink_time = 0;
9909 * gtk_entry_set_completion:
9910 * @entry: A #GtkEntry
9911 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9913 * Sets @completion to be the auxiliary completion object to use with @entry.
9914 * All further configuration of the completion mechanism is done on
9915 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9916 * @completion is set to %NULL.
9921 gtk_entry_set_completion (GtkEntry *entry,
9922 GtkEntryCompletion *completion)
9924 GtkEntryCompletion *old;
9926 g_return_if_fail (GTK_IS_ENTRY (entry));
9927 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9929 old = gtk_entry_get_completion (entry);
9931 if (old == completion)
9936 _gtk_entry_completion_disconnect (old);
9937 g_object_unref (old);
9942 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9946 /* hook into the entry */
9947 g_object_ref (completion);
9949 _gtk_entry_completion_connect (completion, entry);
9951 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9953 g_object_notify (G_OBJECT (entry), "completion");
9957 * gtk_entry_get_completion:
9958 * @entry: A #GtkEntry
9960 * Returns the auxiliary completion object currently in use by @entry.
9962 * Return value: (transfer none): The auxiliary completion object currently
9967 GtkEntryCompletion *
9968 gtk_entry_get_completion (GtkEntry *entry)
9970 GtkEntryCompletion *completion;
9972 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9974 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9975 GTK_ENTRY_COMPLETION_KEY));
9981 * gtk_entry_set_cursor_hadjustment:
9982 * @entry: a #GtkEntry
9983 * @adjustment: an adjustment which should be adjusted when the cursor
9984 * is moved, or %NULL
9986 * Hooks up an adjustment to the cursor position in an entry, so that when
9987 * the cursor is moved, the adjustment is scrolled to show that position.
9988 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9991 * The adjustment has to be in pixel units and in the same coordinate system
9997 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9998 GtkAdjustment *adjustment)
10000 g_return_if_fail (GTK_IS_ENTRY (entry));
10002 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10005 g_object_ref (adjustment);
10007 g_object_set_qdata_full (G_OBJECT (entry),
10008 quark_cursor_hadjustment,
10014 * gtk_entry_get_cursor_hadjustment:
10015 * @entry: a #GtkEntry
10017 * Retrieves the horizontal cursor adjustment for the entry.
10018 * See gtk_entry_set_cursor_hadjustment().
10020 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10021 * if none has been set.
10026 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10028 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10030 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10034 * gtk_entry_set_progress_fraction:
10035 * @entry: a #GtkEntry
10036 * @fraction: fraction of the task that's been completed
10038 * Causes the entry's progress indicator to "fill in" the given
10039 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10045 gtk_entry_set_progress_fraction (GtkEntry *entry,
10049 GtkEntryPrivate *private;
10050 gdouble old_fraction;
10051 gint x, y, width, height;
10052 gint old_x, old_y, old_width, old_height;
10054 g_return_if_fail (GTK_IS_ENTRY (entry));
10056 widget = GTK_WIDGET (entry);
10057 private = entry->priv;
10059 if (private->progress_pulse_mode)
10062 old_fraction = private->progress_fraction;
10064 if (gtk_widget_is_drawable (widget))
10065 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10067 fraction = CLAMP (fraction, 0.0, 1.0);
10069 private->progress_fraction = fraction;
10070 private->progress_pulse_mode = FALSE;
10071 private->progress_pulse_current = 0.0;
10073 if (gtk_widget_is_drawable (widget))
10075 get_progress_area (widget, &x, &y, &width, &height);
10077 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10078 gtk_widget_queue_draw (widget);
10081 if (fraction != old_fraction)
10082 g_object_notify (G_OBJECT (entry), "progress-fraction");
10086 * gtk_entry_get_progress_fraction:
10087 * @entry: a #GtkEntry
10089 * Returns the current fraction of the task that's been completed.
10090 * See gtk_entry_set_progress_fraction().
10092 * Return value: a fraction from 0.0 to 1.0
10097 gtk_entry_get_progress_fraction (GtkEntry *entry)
10099 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10101 return entry->priv->progress_fraction;
10105 * gtk_entry_set_progress_pulse_step:
10106 * @entry: a #GtkEntry
10107 * @fraction: fraction between 0.0 and 1.0
10109 * Sets the fraction of total entry width to move the progress
10110 * bouncing block for each call to gtk_entry_progress_pulse().
10115 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10118 GtkEntryPrivate *private;
10120 g_return_if_fail (GTK_IS_ENTRY (entry));
10122 private = entry->priv;
10124 fraction = CLAMP (fraction, 0.0, 1.0);
10126 if (fraction != private->progress_pulse_fraction)
10128 private->progress_pulse_fraction = fraction;
10130 gtk_widget_queue_draw (GTK_WIDGET (entry));
10132 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10137 * gtk_entry_get_progress_pulse_step:
10138 * @entry: a #GtkEntry
10140 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10142 * Return value: a fraction from 0.0 to 1.0
10147 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10149 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10151 return entry->priv->progress_pulse_fraction;
10155 * gtk_entry_progress_pulse:
10156 * @entry: a #GtkEntry
10158 * Indicates that some progress is made, but you don't know how much.
10159 * Causes the entry's progress indicator to enter "activity mode,"
10160 * where a block bounces back and forth. Each call to
10161 * gtk_entry_progress_pulse() causes the block to move by a little bit
10162 * (the amount of movement per pulse is determined by
10163 * gtk_entry_set_progress_pulse_step()).
10168 gtk_entry_progress_pulse (GtkEntry *entry)
10170 GtkEntryPrivate *private;
10172 g_return_if_fail (GTK_IS_ENTRY (entry));
10174 private = entry->priv;
10176 if (private->progress_pulse_mode)
10178 if (private->progress_pulse_way_back)
10180 private->progress_pulse_current -= private->progress_pulse_fraction;
10182 if (private->progress_pulse_current < 0.0)
10184 private->progress_pulse_current = 0.0;
10185 private->progress_pulse_way_back = FALSE;
10190 private->progress_pulse_current += private->progress_pulse_fraction;
10192 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10194 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10195 private->progress_pulse_way_back = TRUE;
10201 private->progress_fraction = 0.0;
10202 private->progress_pulse_mode = TRUE;
10203 private->progress_pulse_way_back = FALSE;
10204 private->progress_pulse_current = 0.0;
10207 gtk_widget_queue_draw (GTK_WIDGET (entry));
10211 * gtk_entry_set_placeholder_text:
10212 * @entry: a #GtkEntry
10213 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10215 * Sets text to be displayed in @entry when it is empty and unfocused.
10216 * This can be used to give a visual hint of the expected contents of
10219 * Note that since the placeholder text gets removed when the entry
10220 * received focus, using this feature is a bit problematic if the entry
10221 * is given the initial focus in a window. Sometimes this can be
10222 * worked around by delaying the initial focus setting until the
10223 * first key event arrives.
10228 gtk_entry_set_placeholder_text (GtkEntry *entry,
10231 GtkEntryPrivate *priv;
10233 g_return_if_fail (GTK_IS_ENTRY (entry));
10235 priv = entry->priv;
10237 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10240 g_free (priv->placeholder_text);
10241 priv->placeholder_text = g_strdup (text);
10243 gtk_entry_recompute (entry);
10245 g_object_notify (G_OBJECT (entry), "placeholder-text");
10249 * gtk_entry_get_placeholder_text:
10250 * @entry: a #GtkEntry
10252 * Retrieves the text that will be displayed when @entry is empty and unfocused
10254 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10255 * storage in the widget and must not be freed, modified or stored.
10260 gtk_entry_get_placeholder_text (GtkEntry *entry)
10262 GtkEntryPrivate *priv;
10264 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10266 priv = entry->priv;
10268 return priv->placeholder_text;
10271 /* Caps Lock warning for password entries */
10274 show_capslock_feedback (GtkEntry *entry,
10277 GtkEntryPrivate *priv = entry->priv;
10279 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10281 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10282 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10283 priv->caps_lock_warning_shown = TRUE;
10286 if (priv->caps_lock_warning_shown)
10287 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10289 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10293 remove_capslock_feedback (GtkEntry *entry)
10295 GtkEntryPrivate *priv = entry->priv;
10297 if (priv->caps_lock_warning_shown)
10299 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10300 priv->caps_lock_warning_shown = FALSE;
10305 keymap_state_changed (GdkKeymap *keymap,
10308 GtkEntryPrivate *priv = entry->priv;
10311 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10313 if (gdk_keymap_get_caps_lock_state (keymap))
10314 text = _("Caps Lock is on");
10318 show_capslock_feedback (entry, text);
10320 remove_capslock_feedback (entry);
10324 * _gtk_entry_set_is_cell_renderer:
10325 * @entry: a #GtkEntry
10326 * @is_cell_renderer: new value
10328 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10329 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10331 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10335 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10336 gboolean is_cell_renderer)
10338 entry->priv->is_cell_renderer = is_cell_renderer;
10342 * gtk_entry_set_input_purpose:
10343 * @entry: a #GtkEntry
10344 * @purpose: the purpose
10346 * Sets the #GtkEntry:input-purpose property which
10347 * can be used by on-screen keyboards and other input
10348 * methods to adjust their behaviour.
10353 gtk_entry_set_input_purpose (GtkEntry *entry,
10354 GtkInputPurpose purpose)
10357 g_return_if_fail (GTK_IS_ENTRY (entry));
10359 if (gtk_entry_get_input_purpose (entry) != purpose)
10361 g_object_set (G_OBJECT (entry->priv->im_context),
10362 "input-purpose", purpose,
10365 g_object_notify (G_OBJECT (entry), "input-purpose");
10370 * gtk_entry_get_input_purpose:
10371 * @entry: a #GtkEntry
10373 * Gets the value of the #GtkEntry:input-purpose property.
10378 gtk_entry_get_input_purpose (GtkEntry *entry)
10380 GtkInputPurpose purpose;
10382 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
10384 g_object_get (G_OBJECT (entry->priv->im_context),
10385 "input-purpose", &purpose,
10392 * gtk_entry_set_input_hints:
10393 * @entry: a #GtkEntry
10394 * @hints: the hints
10396 * Sets the #GtkEntry:input-hints property, which
10397 * allows input methods to fine-tune their behaviour.
10402 gtk_entry_set_input_hints (GtkEntry *entry,
10403 GtkInputHints hints)
10406 g_return_if_fail (GTK_IS_ENTRY (entry));
10408 if (gtk_entry_get_input_hints (entry) != hints)
10410 g_object_set (G_OBJECT (entry->priv->im_context),
10411 "input-hints", hints,
10414 g_object_notify (G_OBJECT (entry), "input-hints");
10419 * gtk_entry_get_input_hints:
10420 * @entry: a #GtkEntry
10422 * Gets the value of the #GtkEntry:input-hints property.
10427 gtk_entry_get_input_hints (GtkEntry *entry)
10429 GtkInputHints hints;
10431 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
10433 g_object_get (G_OBJECT (entry->priv->im_context),
10434 "input-hints", &hints,
10441 * gtk_entry_set_attributes:
10442 * @entry: a #GtkEntry
10443 * @attrs: a #PangoAttrList
10445 * Sets a #PangoAttrList; the attributes in the list are applied to the
10451 gtk_entry_set_attributes (GtkEntry *entry,
10452 PangoAttrList *attrs)
10454 GtkEntryPrivate *priv = entry->priv;
10455 g_return_if_fail (GTK_IS_ENTRY (entry));
10458 pango_attr_list_ref (attrs);
10461 pango_attr_list_unref (priv->attrs);
10462 priv->attrs = attrs;
10464 g_object_notify (G_OBJECT (entry), "attributes");
10466 gtk_entry_recompute (entry);
10467 gtk_widget_queue_resize (GTK_WIDGET (entry));
10471 * gtk_entry_get_attributes:
10472 * @entry: a #GtkEntry
10474 * Gets the attribute list that was set on the entry using
10475 * gtk_entry_set_attributes(), if any.
10477 * Return value: (transfer none): the attribute list, or %NULL
10483 gtk_entry_get_attributes (GtkEntry *entry)
10485 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10487 return entry->priv->attrs;