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"
70 #include "a11y/gtkentryaccessible.h"
74 * @Short_description: A single line text entry field
76 * @See_also: #GtkTextView, #GtkEntryCompletion
78 * The #GtkEntry widget is a single line text entry
79 * widget. A fairly large set of key bindings are supported
80 * by default. If the entered text is longer than the allocation
81 * of the widget, the widget will scroll so that the cursor
82 * position is visible.
84 * When using an entry for passwords and other sensitive information,
85 * it can be put into "password mode" using gtk_entry_set_visibility().
86 * In this mode, entered text is displayed using a 'invisible' character.
87 * By default, GTK+ picks the best invisible character that is available
88 * in the current font, but it can be changed with
89 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
90 * when Caps Lock or input methods might interfere with entering text in
91 * a password entry. The warning can be turned off with the
92 * #GtkEntry:caps-lock-warning property.
94 * Since 2.16, GtkEntry has the ability to display progress or activity
95 * information behind the text. To make an entry display such information,
96 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
98 * Additionally, GtkEntry can show icons at either side of the entry. These
99 * icons can be activatable by clicking, can be set up as drag source and
100 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
101 * one of the various other functions that set an icon from a stock id, an
102 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
103 * connect to the #GtkEntry::icon-press signal. To allow DND operations
104 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
105 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
108 * Note that functionality or information that is only available by clicking
109 * on an icon in an entry may not be accessible at all to users which are not
110 * able to use a mouse or other pointing device. It is therefore recommended
111 * that any such functionality should also be available by other means, e.g.
112 * via the context menu of the entry.
116 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
118 #define MIN_ENTRY_WIDTH 150
119 #define DRAW_TIMEOUT 20
120 #define PASSWORD_HINT_MAX 8
124 #define IS_VALID_ICON_POSITION(pos) \
125 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
126 (pos) == GTK_ENTRY_ICON_SECONDARY)
128 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
129 static GQuark quark_inner_border = 0;
130 static GQuark quark_password_hint = 0;
131 static GQuark quark_cursor_hadjustment = 0;
132 static GQuark quark_capslock_feedback = 0;
134 typedef struct _EntryIconInfo EntryIconInfo;
135 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
136 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
138 struct _GtkEntryPrivate
140 EntryIconInfo *icons[MAX_ICONS];
142 GtkEntryBuffer *buffer;
143 GtkIMContext *im_context;
144 GtkWidget *popup_menu;
148 GdkWindow *text_area;
150 PangoLayout *cached_layout;
151 PangoAttrList *attrs;
155 gdouble progress_fraction;
156 gdouble progress_pulse_fraction;
157 gdouble progress_pulse_current;
159 gchar *placeholder_text;
161 GtkTextHandle *text_handle;
165 gint ascent; /* font ascent in pango units */
167 gint descent; /* font descent in pango units */
168 gint dnd_position; /* In chars, -1 == no DND cursor */
173 gint selection_bound;
179 gunichar invisible_char;
182 guint blink_time; /* time in msec the cursor has blinked since last user event */
184 guint recompute_idle;
186 guint16 x_text_size; /* allocated size, in bytes */
187 guint16 x_n_bytes; /* length in use, in bytes */
189 guint16 preedit_length; /* length of preedit string, in bytes */
190 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
192 guint shadow_type : 4;
195 guint overwrite_mode : 1;
198 guint activates_default : 1;
199 guint cache_includes_preedit : 1;
200 guint caps_lock_warning : 1;
201 guint caps_lock_warning_shown : 1;
202 guint change_count : 8;
203 guint cursor_visible : 1;
204 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
206 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
207 guint is_cell_renderer : 1;
208 guint invisible_char_set : 1;
209 guint interior_focus : 1;
210 guint mouse_cursor_obscured : 1;
211 guint need_im_reset : 1;
212 guint progress_pulse_mode : 1;
213 guint progress_pulse_way_back : 1;
214 guint real_changed : 1;
215 guint resolved_dir : 4; /* PangoDirection */
216 guint select_words : 1;
217 guint select_lines : 1;
218 guint truncate_multiline : 1;
219 guint cursor_handle_dragged : 1;
220 guint selection_handle_dragged : 1;
223 struct _EntryIconInfo
227 guint insensitive : 1;
228 guint nonactivatable : 1;
233 GtkIconHelper *icon_helper;
235 GtkTargetList *target_list;
236 GdkDragAction actions;
239 struct _GtkEntryPasswordHint
241 gint position; /* Position (in text) of the last password hint */
242 guint source_id; /* Timeout source id */
245 struct _GtkEntryCapslockFeedback
272 PROP_CURSOR_POSITION,
273 PROP_SELECTION_BOUND,
280 PROP_ACTIVATES_DEFAULT,
285 PROP_TRUNCATE_MULTILINE,
289 PROP_INVISIBLE_CHAR_SET,
290 PROP_CAPS_LOCK_WARNING,
291 PROP_PROGRESS_FRACTION,
292 PROP_PROGRESS_PULSE_STEP,
294 PROP_PIXBUF_SECONDARY,
296 PROP_STOCK_SECONDARY,
297 PROP_ICON_NAME_PRIMARY,
298 PROP_ICON_NAME_SECONDARY,
300 PROP_GICON_SECONDARY,
301 PROP_STORAGE_TYPE_PRIMARY,
302 PROP_STORAGE_TYPE_SECONDARY,
303 PROP_ACTIVATABLE_PRIMARY,
304 PROP_ACTIVATABLE_SECONDARY,
305 PROP_SENSITIVE_PRIMARY,
306 PROP_SENSITIVE_SECONDARY,
307 PROP_TOOLTIP_TEXT_PRIMARY,
308 PROP_TOOLTIP_TEXT_SECONDARY,
309 PROP_TOOLTIP_MARKUP_PRIMARY,
310 PROP_TOOLTIP_MARKUP_SECONDARY,
312 PROP_EDITING_CANCELED,
313 PROP_PLACEHOLDER_TEXT,
320 static guint signals[LAST_SIGNAL] = { 0 };
329 DISPLAY_NORMAL, /* The entry text is being shown */
330 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
331 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
336 static void gtk_entry_editable_init (GtkEditableInterface *iface);
337 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
338 static void gtk_entry_set_property (GObject *object,
342 static void gtk_entry_get_property (GObject *object,
346 static void gtk_entry_finalize (GObject *object);
347 static void gtk_entry_dispose (GObject *object);
351 static void gtk_entry_destroy (GtkWidget *widget);
352 static void gtk_entry_realize (GtkWidget *widget);
353 static void gtk_entry_unrealize (GtkWidget *widget);
354 static void gtk_entry_map (GtkWidget *widget);
355 static void gtk_entry_unmap (GtkWidget *widget);
356 static void gtk_entry_get_preferred_width (GtkWidget *widget,
359 static void gtk_entry_get_preferred_height (GtkWidget *widget,
362 static void gtk_entry_size_allocate (GtkWidget *widget,
363 GtkAllocation *allocation);
364 static void gtk_entry_draw_frame (GtkWidget *widget,
365 GtkStyleContext *context,
367 static void gtk_entry_draw_progress (GtkWidget *widget,
368 GtkStyleContext *context,
370 static gint gtk_entry_draw (GtkWidget *widget,
372 static gint gtk_entry_button_press (GtkWidget *widget,
373 GdkEventButton *event);
374 static gint gtk_entry_button_release (GtkWidget *widget,
375 GdkEventButton *event);
376 static gint gtk_entry_enter_notify (GtkWidget *widget,
377 GdkEventCrossing *event);
378 static gint gtk_entry_leave_notify (GtkWidget *widget,
379 GdkEventCrossing *event);
380 static gint gtk_entry_motion_notify (GtkWidget *widget,
381 GdkEventMotion *event);
382 static gint gtk_entry_key_press (GtkWidget *widget,
384 static gint gtk_entry_key_release (GtkWidget *widget,
386 static gint gtk_entry_focus_in (GtkWidget *widget,
387 GdkEventFocus *event);
388 static gint gtk_entry_focus_out (GtkWidget *widget,
389 GdkEventFocus *event);
390 static void gtk_entry_grab_focus (GtkWidget *widget);
391 static void gtk_entry_style_updated (GtkWidget *widget);
392 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
395 gboolean keyboard_tip,
396 GtkTooltip *tooltip);
397 static void gtk_entry_direction_changed (GtkWidget *widget,
398 GtkTextDirection previous_dir);
399 static void gtk_entry_state_flags_changed (GtkWidget *widget,
400 GtkStateFlags previous_state);
401 static void gtk_entry_screen_changed (GtkWidget *widget,
402 GdkScreen *old_screen);
404 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
405 GdkDragContext *context,
409 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
410 GdkDragContext *context,
414 static void gtk_entry_drag_leave (GtkWidget *widget,
415 GdkDragContext *context,
417 static void gtk_entry_drag_data_received (GtkWidget *widget,
418 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_entry_drag_data_get (GtkWidget *widget,
425 GdkDragContext *context,
426 GtkSelectionData *selection_data,
429 static void gtk_entry_drag_data_delete (GtkWidget *widget,
430 GdkDragContext *context);
431 static void gtk_entry_drag_begin (GtkWidget *widget,
432 GdkDragContext *context);
433 static void gtk_entry_drag_end (GtkWidget *widget,
434 GdkDragContext *context);
437 /* GtkEditable method implementations
439 static void gtk_entry_insert_text (GtkEditable *editable,
440 const gchar *new_text,
441 gint new_text_length,
443 static void gtk_entry_delete_text (GtkEditable *editable,
446 static gchar * gtk_entry_get_chars (GtkEditable *editable,
449 static void gtk_entry_real_set_position (GtkEditable *editable,
451 static gint gtk_entry_get_position (GtkEditable *editable);
452 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
455 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
459 /* GtkCellEditable method implementations
461 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
464 /* Default signal handlers
466 static void gtk_entry_real_insert_text (GtkEditable *editable,
467 const gchar *new_text,
468 gint new_text_length,
470 static void gtk_entry_real_delete_text (GtkEditable *editable,
473 static void gtk_entry_move_cursor (GtkEntry *entry,
474 GtkMovementStep step,
476 gboolean extend_selection);
477 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
479 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
482 static void gtk_entry_backspace (GtkEntry *entry);
483 static void gtk_entry_cut_clipboard (GtkEntry *entry);
484 static void gtk_entry_copy_clipboard (GtkEntry *entry);
485 static void gtk_entry_paste_clipboard (GtkEntry *entry);
486 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
487 static void gtk_entry_select_all (GtkEntry *entry);
488 static void gtk_entry_real_activate (GtkEntry *entry);
489 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
491 static void keymap_direction_changed (GdkKeymap *keymap,
493 static void keymap_state_changed (GdkKeymap *keymap,
495 static void remove_capslock_feedback (GtkEntry *entry);
497 /* IM Context Callbacks
499 static void gtk_entry_commit_cb (GtkIMContext *context,
502 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
504 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
506 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
513 static void gtk_entry_enter_text (GtkEntry *entry,
515 static void gtk_entry_set_positions (GtkEntry *entry,
517 gint selection_bound);
518 static void gtk_entry_draw_text (GtkEntry *entry,
520 static void gtk_entry_draw_cursor (GtkEntry *entry,
523 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
524 gboolean include_preedit);
525 static void gtk_entry_reset_layout (GtkEntry *entry);
526 static void gtk_entry_recompute (GtkEntry *entry);
527 static gint gtk_entry_find_position (GtkEntry *entry,
529 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
533 static void gtk_entry_adjust_scroll (GtkEntry *entry);
534 static gint gtk_entry_move_visually (GtkEntry *editable,
537 static gint gtk_entry_move_logically (GtkEntry *entry,
540 static gint gtk_entry_move_forward_word (GtkEntry *entry,
542 gboolean allow_whitespace);
543 static gint gtk_entry_move_backward_word (GtkEntry *entry,
545 gboolean allow_whitespace);
546 static void gtk_entry_delete_whitespace (GtkEntry *entry);
547 static void gtk_entry_select_word (GtkEntry *entry);
548 static void gtk_entry_select_line (GtkEntry *entry);
549 static void gtk_entry_paste (GtkEntry *entry,
551 static void gtk_entry_update_primary_selection (GtkEntry *entry);
552 static void gtk_entry_do_popup (GtkEntry *entry,
553 GdkEventButton *event);
554 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
555 gboolean group_cycling);
556 static void gtk_entry_grab_notify (GtkWidget *widget,
557 gboolean was_grabbed);
558 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
559 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
560 static void gtk_entry_reset_blink_time (GtkEntry *entry);
561 static void gtk_entry_get_text_area_size (GtkEntry *entry,
566 static void get_text_area_size (GtkEntry *entry,
571 static void get_frame_size (GtkEntry *entry,
572 gboolean relative_to_window,
577 static void gtk_entry_move_adjustments (GtkEntry *entry);
578 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
579 GtkEntryIconPosition icon_pos);
580 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
581 static gboolean get_middle_click_paste (GtkEntry *entry);
583 /* GtkTextHandle handlers */
584 static void gtk_entry_handle_dragged (GtkTextHandle *handle,
585 GtkTextHandlePosition pos,
590 static void begin_change (GtkEntry *entry);
591 static void end_change (GtkEntry *entry);
592 static void emit_changed (GtkEntry *entry);
594 static void buffer_inserted_text (GtkEntryBuffer *buffer,
599 static void buffer_deleted_text (GtkEntryBuffer *buffer,
603 static void buffer_notify_text (GtkEntryBuffer *buffer,
606 static void buffer_notify_length (GtkEntryBuffer *buffer,
609 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
612 static void buffer_connect_signals (GtkEntry *entry);
613 static void buffer_disconnect_signals (GtkEntry *entry);
614 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
616 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
617 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
618 gtk_entry_editable_init)
619 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
620 gtk_entry_cell_editable_init))
623 add_move_binding (GtkBindingSet *binding_set,
626 GtkMovementStep step,
629 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
631 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
635 G_TYPE_BOOLEAN, FALSE);
637 /* Selection-extending version */
638 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
642 G_TYPE_BOOLEAN, TRUE);
646 gtk_entry_class_init (GtkEntryClass *class)
648 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
649 GtkWidgetClass *widget_class;
650 GtkBindingSet *binding_set;
652 widget_class = (GtkWidgetClass*) class;
654 gobject_class->dispose = gtk_entry_dispose;
655 gobject_class->finalize = gtk_entry_finalize;
656 gobject_class->set_property = gtk_entry_set_property;
657 gobject_class->get_property = gtk_entry_get_property;
659 widget_class->destroy = gtk_entry_destroy;
660 widget_class->map = gtk_entry_map;
661 widget_class->unmap = gtk_entry_unmap;
662 widget_class->realize = gtk_entry_realize;
663 widget_class->unrealize = gtk_entry_unrealize;
664 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
665 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
666 widget_class->size_allocate = gtk_entry_size_allocate;
667 widget_class->draw = gtk_entry_draw;
668 widget_class->enter_notify_event = gtk_entry_enter_notify;
669 widget_class->leave_notify_event = gtk_entry_leave_notify;
670 widget_class->button_press_event = gtk_entry_button_press;
671 widget_class->button_release_event = gtk_entry_button_release;
672 widget_class->motion_notify_event = gtk_entry_motion_notify;
673 widget_class->key_press_event = gtk_entry_key_press;
674 widget_class->key_release_event = gtk_entry_key_release;
675 widget_class->focus_in_event = gtk_entry_focus_in;
676 widget_class->focus_out_event = gtk_entry_focus_out;
677 widget_class->grab_focus = gtk_entry_grab_focus;
678 widget_class->style_updated = gtk_entry_style_updated;
679 widget_class->query_tooltip = gtk_entry_query_tooltip;
680 widget_class->drag_begin = gtk_entry_drag_begin;
681 widget_class->drag_end = gtk_entry_drag_end;
682 widget_class->direction_changed = gtk_entry_direction_changed;
683 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
684 widget_class->screen_changed = gtk_entry_screen_changed;
685 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
686 widget_class->grab_notify = gtk_entry_grab_notify;
688 widget_class->drag_drop = gtk_entry_drag_drop;
689 widget_class->drag_motion = gtk_entry_drag_motion;
690 widget_class->drag_leave = gtk_entry_drag_leave;
691 widget_class->drag_data_received = gtk_entry_drag_data_received;
692 widget_class->drag_data_get = gtk_entry_drag_data_get;
693 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
695 widget_class->popup_menu = gtk_entry_popup_menu;
697 class->move_cursor = gtk_entry_move_cursor;
698 class->insert_at_cursor = gtk_entry_insert_at_cursor;
699 class->delete_from_cursor = gtk_entry_delete_from_cursor;
700 class->backspace = gtk_entry_backspace;
701 class->cut_clipboard = gtk_entry_cut_clipboard;
702 class->copy_clipboard = gtk_entry_copy_clipboard;
703 class->paste_clipboard = gtk_entry_paste_clipboard;
704 class->toggle_overwrite = gtk_entry_toggle_overwrite;
705 class->activate = gtk_entry_real_activate;
706 class->get_text_area_size = gtk_entry_get_text_area_size;
708 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
709 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
710 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
711 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
713 g_object_class_override_property (gobject_class,
714 PROP_EDITING_CANCELED,
717 g_object_class_install_property (gobject_class,
719 g_param_spec_object ("buffer",
721 P_("Text buffer object which actually stores entry text"),
722 GTK_TYPE_ENTRY_BUFFER,
723 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
725 g_object_class_install_property (gobject_class,
726 PROP_CURSOR_POSITION,
727 g_param_spec_int ("cursor-position",
728 P_("Cursor Position"),
729 P_("The current position of the insertion cursor in chars"),
731 GTK_ENTRY_BUFFER_MAX_SIZE,
733 GTK_PARAM_READABLE));
735 g_object_class_install_property (gobject_class,
736 PROP_SELECTION_BOUND,
737 g_param_spec_int ("selection-bound",
738 P_("Selection Bound"),
739 P_("The position of the opposite end of the selection from the cursor in chars"),
741 GTK_ENTRY_BUFFER_MAX_SIZE,
743 GTK_PARAM_READABLE));
745 g_object_class_install_property (gobject_class,
747 g_param_spec_boolean ("editable",
749 P_("Whether the entry contents can be edited"),
751 GTK_PARAM_READWRITE));
753 g_object_class_install_property (gobject_class,
755 g_param_spec_int ("max-length",
756 P_("Maximum length"),
757 P_("Maximum number of characters for this entry. Zero if no maximum"),
759 GTK_ENTRY_BUFFER_MAX_SIZE,
761 GTK_PARAM_READWRITE));
762 g_object_class_install_property (gobject_class,
764 g_param_spec_boolean ("visibility",
766 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
768 GTK_PARAM_READWRITE));
770 g_object_class_install_property (gobject_class,
772 g_param_spec_boolean ("has-frame",
774 P_("FALSE removes outside bevel from entry"),
776 GTK_PARAM_READWRITE));
779 * GtkEntry:inner-border:
781 * Sets the text area's border between the text and the frame.
783 * Deprecated: 3.4: Use the standard border and padding CSS properties
784 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
785 * of this style property is ignored.
787 g_object_class_install_property (gobject_class,
789 g_param_spec_boxed ("inner-border",
791 P_("Border between text and frame. Overrides the inner-border style property"),
793 GTK_PARAM_READWRITE |
794 G_PARAM_DEPRECATED));
796 g_object_class_install_property (gobject_class,
798 g_param_spec_unichar ("invisible-char",
799 P_("Invisible character"),
800 P_("The character to use when masking entry contents (in \"password mode\")"),
802 GTK_PARAM_READWRITE));
804 g_object_class_install_property (gobject_class,
805 PROP_ACTIVATES_DEFAULT,
806 g_param_spec_boolean ("activates-default",
807 P_("Activates default"),
808 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
810 GTK_PARAM_READWRITE));
811 g_object_class_install_property (gobject_class,
813 g_param_spec_int ("width-chars",
814 P_("Width in chars"),
815 P_("Number of characters to leave space for in the entry"),
819 GTK_PARAM_READWRITE));
821 g_object_class_install_property (gobject_class,
823 g_param_spec_int ("scroll-offset",
825 P_("Number of pixels of the entry scrolled off the screen to the left"),
829 GTK_PARAM_READABLE));
831 g_object_class_install_property (gobject_class,
833 g_param_spec_string ("text",
835 P_("The contents of the entry"),
837 GTK_PARAM_READWRITE));
842 * The horizontal alignment, from 0 (left) to 1 (right).
843 * Reversed for RTL layouts.
847 g_object_class_install_property (gobject_class,
849 g_param_spec_float ("xalign",
851 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
855 GTK_PARAM_READWRITE));
858 * GtkEntry:truncate-multiline:
860 * When %TRUE, pasted multi-line text is truncated to the first line.
864 g_object_class_install_property (gobject_class,
865 PROP_TRUNCATE_MULTILINE,
866 g_param_spec_boolean ("truncate-multiline",
867 P_("Truncate multiline"),
868 P_("Whether to truncate multiline pastes to one line."),
870 GTK_PARAM_READWRITE));
873 * GtkEntry:shadow-type:
875 * Which kind of shadow to draw around the entry when
876 * #GtkEntry:has-frame is set to %TRUE.
880 g_object_class_install_property (gobject_class,
882 g_param_spec_enum ("shadow-type",
884 P_("Which kind of shadow to draw around the entry when has-frame is set"),
885 GTK_TYPE_SHADOW_TYPE,
887 GTK_PARAM_READWRITE));
890 * GtkEntry:overwrite-mode:
892 * If text is overwritten when typing in the #GtkEntry.
896 g_object_class_install_property (gobject_class,
898 g_param_spec_boolean ("overwrite-mode",
899 P_("Overwrite mode"),
900 P_("Whether new text overwrites existing text"),
902 GTK_PARAM_READWRITE));
905 * GtkEntry:text-length:
907 * The length of the text in the #GtkEntry.
911 g_object_class_install_property (gobject_class,
913 g_param_spec_uint ("text-length",
915 P_("Length of the text currently in the entry"),
919 GTK_PARAM_READABLE));
921 * GtkEntry:invisible-char-set:
923 * Whether the invisible char has been set for the #GtkEntry.
927 g_object_class_install_property (gobject_class,
928 PROP_INVISIBLE_CHAR_SET,
929 g_param_spec_boolean ("invisible-char-set",
930 P_("Invisible character set"),
931 P_("Whether the invisible character has been set"),
933 GTK_PARAM_READWRITE));
936 * GtkEntry:caps-lock-warning:
938 * Whether password entries will show a warning when Caps Lock is on.
940 * Note that the warning is shown using a secondary icon, and thus
941 * does not work if you are using the secondary icon position for some
946 g_object_class_install_property (gobject_class,
947 PROP_CAPS_LOCK_WARNING,
948 g_param_spec_boolean ("caps-lock-warning",
949 P_("Caps Lock warning"),
950 P_("Whether password entries will show a warning when Caps Lock is on"),
952 GTK_PARAM_READWRITE));
955 * GtkEntry:progress-fraction:
957 * The current fraction of the task that's been completed.
961 g_object_class_install_property (gobject_class,
962 PROP_PROGRESS_FRACTION,
963 g_param_spec_double ("progress-fraction",
964 P_("Progress Fraction"),
965 P_("The current fraction of the task that's been completed"),
969 GTK_PARAM_READWRITE));
972 * GtkEntry:progress-pulse-step:
974 * The fraction of total entry width to move the progress
975 * bouncing block for each call to gtk_entry_progress_pulse().
979 g_object_class_install_property (gobject_class,
980 PROP_PROGRESS_PULSE_STEP,
981 g_param_spec_double ("progress-pulse-step",
982 P_("Progress Pulse Step"),
983 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
987 GTK_PARAM_READWRITE));
990 * GtkEntry:placeholder-text:
992 * The text that will be displayed in the #GtkEntry when it is empty
997 g_object_class_install_property (gobject_class,
998 PROP_PLACEHOLDER_TEXT,
999 g_param_spec_string ("placeholder-text",
1000 P_("Placeholder text"),
1001 P_("Show text in the entry when it's empty and unfocused"),
1003 GTK_PARAM_READWRITE));
1006 * GtkEntry:primary-icon-pixbuf:
1008 * A pixbuf to use as the primary icon for the entry.
1012 g_object_class_install_property (gobject_class,
1013 PROP_PIXBUF_PRIMARY,
1014 g_param_spec_object ("primary-icon-pixbuf",
1015 P_("Primary pixbuf"),
1016 P_("Primary pixbuf for the entry"),
1018 GTK_PARAM_READWRITE));
1021 * GtkEntry:secondary-icon-pixbuf:
1023 * An pixbuf to use as the secondary icon for the entry.
1027 g_object_class_install_property (gobject_class,
1028 PROP_PIXBUF_SECONDARY,
1029 g_param_spec_object ("secondary-icon-pixbuf",
1030 P_("Secondary pixbuf"),
1031 P_("Secondary pixbuf for the entry"),
1033 GTK_PARAM_READWRITE));
1036 * GtkEntry:primary-icon-stock:
1038 * The stock id to use for the primary icon for the entry.
1042 g_object_class_install_property (gobject_class,
1044 g_param_spec_string ("primary-icon-stock",
1045 P_("Primary stock ID"),
1046 P_("Stock ID for primary icon"),
1048 GTK_PARAM_READWRITE));
1051 * GtkEntry:secondary-icon-stock:
1053 * The stock id to use for the secondary icon for the entry.
1057 g_object_class_install_property (gobject_class,
1058 PROP_STOCK_SECONDARY,
1059 g_param_spec_string ("secondary-icon-stock",
1060 P_("Secondary stock ID"),
1061 P_("Stock ID for secondary icon"),
1063 GTK_PARAM_READWRITE));
1066 * GtkEntry:primary-icon-name:
1068 * The icon name to use for the primary icon for the entry.
1072 g_object_class_install_property (gobject_class,
1073 PROP_ICON_NAME_PRIMARY,
1074 g_param_spec_string ("primary-icon-name",
1075 P_("Primary icon name"),
1076 P_("Icon name for primary icon"),
1078 GTK_PARAM_READWRITE));
1081 * GtkEntry:secondary-icon-name:
1083 * The icon name to use for the secondary icon for the entry.
1087 g_object_class_install_property (gobject_class,
1088 PROP_ICON_NAME_SECONDARY,
1089 g_param_spec_string ("secondary-icon-name",
1090 P_("Secondary icon name"),
1091 P_("Icon name for secondary icon"),
1093 GTK_PARAM_READWRITE));
1096 * GtkEntry:primary-icon-gicon:
1098 * The #GIcon to use for the primary icon for the entry.
1102 g_object_class_install_property (gobject_class,
1104 g_param_spec_object ("primary-icon-gicon",
1105 P_("Primary GIcon"),
1106 P_("GIcon for primary icon"),
1108 GTK_PARAM_READWRITE));
1111 * GtkEntry:secondary-icon-gicon:
1113 * The #GIcon to use for the secondary icon for the entry.
1117 g_object_class_install_property (gobject_class,
1118 PROP_GICON_SECONDARY,
1119 g_param_spec_object ("secondary-icon-gicon",
1120 P_("Secondary GIcon"),
1121 P_("GIcon for secondary icon"),
1123 GTK_PARAM_READWRITE));
1126 * GtkEntry:primary-icon-storage-type:
1128 * The representation which is used for the primary icon of the entry.
1132 g_object_class_install_property (gobject_class,
1133 PROP_STORAGE_TYPE_PRIMARY,
1134 g_param_spec_enum ("primary-icon-storage-type",
1135 P_("Primary storage type"),
1136 P_("The representation being used for primary icon"),
1137 GTK_TYPE_IMAGE_TYPE,
1139 GTK_PARAM_READABLE));
1142 * GtkEntry:secondary-icon-storage-type:
1144 * The representation which is used for the secondary icon of the entry.
1148 g_object_class_install_property (gobject_class,
1149 PROP_STORAGE_TYPE_SECONDARY,
1150 g_param_spec_enum ("secondary-icon-storage-type",
1151 P_("Secondary storage type"),
1152 P_("The representation being used for secondary icon"),
1153 GTK_TYPE_IMAGE_TYPE,
1155 GTK_PARAM_READABLE));
1158 * GtkEntry:primary-icon-activatable:
1160 * Whether the primary icon is activatable.
1162 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1163 * signals only on sensitive, activatable icons.
1165 * Sensitive, but non-activatable icons can be used for purely
1166 * informational purposes.
1170 g_object_class_install_property (gobject_class,
1171 PROP_ACTIVATABLE_PRIMARY,
1172 g_param_spec_boolean ("primary-icon-activatable",
1173 P_("Primary icon activatable"),
1174 P_("Whether the primary icon is activatable"),
1176 GTK_PARAM_READWRITE));
1179 * GtkEntry:secondary-icon-activatable:
1181 * Whether the secondary icon is activatable.
1183 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1184 * signals only on sensitive, activatable icons.
1186 * Sensitive, but non-activatable icons can be used for purely
1187 * informational purposes.
1191 g_object_class_install_property (gobject_class,
1192 PROP_ACTIVATABLE_SECONDARY,
1193 g_param_spec_boolean ("secondary-icon-activatable",
1194 P_("Secondary icon activatable"),
1195 P_("Whether the secondary icon is activatable"),
1197 GTK_PARAM_READWRITE));
1201 * GtkEntry:primary-icon-sensitive:
1203 * Whether the primary icon is sensitive.
1205 * An insensitive icon appears grayed out. GTK+ does not emit the
1206 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1207 * does not allow DND from insensitive icons.
1209 * An icon should be set insensitive if the action that would trigger
1210 * when clicked is currently not available.
1214 g_object_class_install_property (gobject_class,
1215 PROP_SENSITIVE_PRIMARY,
1216 g_param_spec_boolean ("primary-icon-sensitive",
1217 P_("Primary icon sensitive"),
1218 P_("Whether the primary icon is sensitive"),
1220 GTK_PARAM_READWRITE));
1223 * GtkEntry:secondary-icon-sensitive:
1225 * Whether the secondary icon is sensitive.
1227 * An insensitive icon appears grayed out. GTK+ does not emit the
1228 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1229 * does not allow DND from insensitive icons.
1231 * An icon should be set insensitive if the action that would trigger
1232 * when clicked is currently not available.
1236 g_object_class_install_property (gobject_class,
1237 PROP_SENSITIVE_SECONDARY,
1238 g_param_spec_boolean ("secondary-icon-sensitive",
1239 P_("Secondary icon sensitive"),
1240 P_("Whether the secondary icon is sensitive"),
1242 GTK_PARAM_READWRITE));
1245 * GtkEntry:primary-icon-tooltip-text:
1247 * The contents of the tooltip on the primary icon.
1249 * Also see gtk_entry_set_icon_tooltip_text().
1253 g_object_class_install_property (gobject_class,
1254 PROP_TOOLTIP_TEXT_PRIMARY,
1255 g_param_spec_string ("primary-icon-tooltip-text",
1256 P_("Primary icon tooltip text"),
1257 P_("The contents of the tooltip on the primary icon"),
1259 GTK_PARAM_READWRITE));
1262 * GtkEntry:secondary-icon-tooltip-text:
1264 * The contents of the tooltip on the secondary icon.
1266 * Also see gtk_entry_set_icon_tooltip_text().
1270 g_object_class_install_property (gobject_class,
1271 PROP_TOOLTIP_TEXT_SECONDARY,
1272 g_param_spec_string ("secondary-icon-tooltip-text",
1273 P_("Secondary icon tooltip text"),
1274 P_("The contents of the tooltip on the secondary icon"),
1276 GTK_PARAM_READWRITE));
1279 * GtkEntry:primary-icon-tooltip-markup:
1281 * The contents of the tooltip on the primary icon, which is marked up
1282 * with the <link linkend="PangoMarkupFormat">Pango text markup
1285 * Also see gtk_entry_set_icon_tooltip_markup().
1289 g_object_class_install_property (gobject_class,
1290 PROP_TOOLTIP_MARKUP_PRIMARY,
1291 g_param_spec_string ("primary-icon-tooltip-markup",
1292 P_("Primary icon tooltip markup"),
1293 P_("The contents of the tooltip on the primary icon"),
1295 GTK_PARAM_READWRITE));
1298 * GtkEntry:secondary-icon-tooltip-markup:
1300 * The contents of the tooltip on the secondary icon, which is marked up
1301 * with the <link linkend="PangoMarkupFormat">Pango text markup
1304 * Also see gtk_entry_set_icon_tooltip_markup().
1308 g_object_class_install_property (gobject_class,
1309 PROP_TOOLTIP_MARKUP_SECONDARY,
1310 g_param_spec_string ("secondary-icon-tooltip-markup",
1311 P_("Secondary icon tooltip markup"),
1312 P_("The contents of the tooltip on the secondary icon"),
1314 GTK_PARAM_READWRITE));
1317 * GtkEntry:im-module:
1319 * Which IM (input method) module should be used for this entry.
1320 * See #GtkIMContext.
1322 * Setting this to a non-%NULL value overrides the
1323 * system-wide IM module setting. See the GtkSettings
1324 * #GtkSettings:gtk-im-module property.
1328 g_object_class_install_property (gobject_class,
1330 g_param_spec_string ("im-module",
1332 P_("Which IM module should be used"),
1334 GTK_PARAM_READWRITE));
1337 * GtkEntry:completion:
1339 * The auxiliary completion object to use with the entry.
1343 g_object_class_install_property (gobject_class,
1345 g_param_spec_object ("completion",
1347 P_("The auxiliary completion object"),
1348 GTK_TYPE_ENTRY_COMPLETION,
1349 GTK_PARAM_READWRITE));
1352 * GtkEntry:input-purpose:
1354 * The purpose of this text field.
1356 * This property can be used by on-screen keyboards and other input
1357 * methods to adjust their behaviour.
1359 * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
1360 * %GTK_INPUT_PURPOSE_PIN is independent from setting
1361 * #GtkEntry:visibility.
1365 g_object_class_install_property (gobject_class,
1367 g_param_spec_enum ("input-purpose",
1369 P_("Purpose of the text field"),
1370 GTK_TYPE_INPUT_PURPOSE,
1371 GTK_INPUT_PURPOSE_FREE_FORM,
1372 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1375 * GtkEntry:input-hints:
1377 * Additional hints (beyond #GtkEntry:input-purpose) that
1378 * allow input methods to fine-tune their behaviour.
1382 g_object_class_install_property (gobject_class,
1384 g_param_spec_flags ("input-hints",
1386 P_("Hints for the text field behaviour"),
1387 GTK_TYPE_INPUT_HINTS,
1388 GTK_INPUT_HINT_NONE,
1389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1392 * GtkEntry:attributes:
1394 * A list of Pango attributes to apply to the text of the entry.
1396 * This is mainly useful to change the size or weight of the text.
1400 g_object_class_install_property (gobject_class,
1402 g_param_spec_boxed ("attributes",
1404 P_("A list of style attributes to apply to the text of the label"),
1405 PANGO_TYPE_ATTR_LIST,
1406 GTK_PARAM_READWRITE));
1409 * GtkEntry:icon-prelight:
1411 * The prelight style property determines whether activatable
1412 * icons prelight on mouseover.
1416 gtk_widget_class_install_style_property (widget_class,
1417 g_param_spec_boolean ("icon-prelight",
1418 P_("Icon Prelight"),
1419 P_("Whether activatable icons should prelight when hovered"),
1421 GTK_PARAM_READABLE));
1424 * GtkEntry:progress-border:
1426 * The border around the progress bar in the entry.
1430 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1431 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1432 * property is ignored.
1434 gtk_widget_class_install_style_property (widget_class,
1435 g_param_spec_boxed ("progress-border",
1436 P_("Progress Border"),
1437 P_("Border around the progress bar"),
1439 GTK_PARAM_READABLE |
1440 G_PARAM_DEPRECATED));
1443 * GtkEntry:invisible-char:
1445 * The invisible character is used when masking entry contents (in
1446 * \"password mode\")"). When it is not explicitly set with the
1447 * #GtkEntry:invisible-char property, GTK+ determines the character
1448 * to use from a list of possible candidates, depending on availability
1449 * in the current font.
1451 * This style property allows the theme to prepend a character
1452 * to the list of candidates.
1456 gtk_widget_class_install_style_property (widget_class,
1457 g_param_spec_unichar ("invisible-char",
1458 P_("Invisible character"),
1459 P_("The character to use when masking entry contents (in \"password mode\")"),
1461 GTK_PARAM_READABLE));
1464 * GtkEntry::populate-popup:
1465 * @entry: The entry on which the signal is emitted
1466 * @menu: the menu that is being populated
1468 * The ::populate-popup signal gets emitted before showing the
1469 * context menu of the entry.
1471 * If you need to add items to the context menu, connect
1472 * to this signal and append your menuitems to the @menu.
1474 signals[POPULATE_POPUP] =
1475 g_signal_new (I_("populate-popup"),
1476 G_OBJECT_CLASS_TYPE (gobject_class),
1478 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1480 _gtk_marshal_VOID__OBJECT,
1484 /* Action signals */
1487 * GtkEntry::activate:
1488 * @entry: The entry on which the signal is emitted
1490 * The ::activate signal is emitted when the user hits
1493 * While this signal is used as a
1494 * <link linkend="keybinding-signals">keybinding signal</link>,
1495 * it is also commonly used by applications to intercept
1496 * activation of entries.
1498 * The default bindings for this signal are all forms of the Enter key.
1501 g_signal_new (I_("activate"),
1502 G_OBJECT_CLASS_TYPE (gobject_class),
1503 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1504 G_STRUCT_OFFSET (GtkEntryClass, activate),
1506 _gtk_marshal_VOID__VOID,
1508 widget_class->activate_signal = signals[ACTIVATE];
1511 * GtkEntry::move-cursor:
1512 * @entry: the object which received the signal
1513 * @step: the granularity of the move, as a #GtkMovementStep
1514 * @count: the number of @step units to move
1515 * @extend_selection: %TRUE if the move should extend the selection
1517 * The ::move-cursor signal is a
1518 * <link linkend="keybinding-signals">keybinding signal</link>
1519 * which gets emitted when the user initiates a cursor movement.
1520 * If the cursor is not visible in @entry, this signal causes
1521 * the viewport to be moved instead.
1523 * Applications should not connect to it, but may emit it with
1524 * g_signal_emit_by_name() if they need to control the cursor
1527 * The default bindings for this signal come in two variants,
1528 * the variant with the Shift modifier extends the selection,
1529 * the variant without the Shift modifer does not.
1530 * There are too many key combinations to list them all here.
1532 * <listitem>Arrow keys move by individual characters/lines</listitem>
1533 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1534 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1537 signals[MOVE_CURSOR] =
1538 g_signal_new (I_("move-cursor"),
1539 G_OBJECT_CLASS_TYPE (gobject_class),
1540 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1541 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1543 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1545 GTK_TYPE_MOVEMENT_STEP,
1550 * GtkEntry::insert-at-cursor:
1551 * @entry: the object which received the signal
1552 * @string: the string to insert
1554 * The ::insert-at-cursor signal is a
1555 * <link linkend="keybinding-signals">keybinding signal</link>
1556 * which gets emitted when the user initiates the insertion of a
1557 * fixed string at the cursor.
1559 * This signal has no default bindings.
1561 signals[INSERT_AT_CURSOR] =
1562 g_signal_new (I_("insert-at-cursor"),
1563 G_OBJECT_CLASS_TYPE (gobject_class),
1564 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1565 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1567 _gtk_marshal_VOID__STRING,
1572 * GtkEntry::delete-from-cursor:
1573 * @entry: the object which received the signal
1574 * @type: the granularity of the deletion, as a #GtkDeleteType
1575 * @count: the number of @type units to delete
1577 * The ::delete-from-cursor signal is a
1578 * <link linkend="keybinding-signals">keybinding signal</link>
1579 * which gets emitted when the user initiates a text deletion.
1581 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1582 * if there is one, otherwise it deletes the requested number
1585 * The default bindings for this signal are
1586 * Delete for deleting a character and Ctrl-Delete for
1589 signals[DELETE_FROM_CURSOR] =
1590 g_signal_new (I_("delete-from-cursor"),
1591 G_OBJECT_CLASS_TYPE (gobject_class),
1592 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1593 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1595 _gtk_marshal_VOID__ENUM_INT,
1597 GTK_TYPE_DELETE_TYPE,
1601 * GtkEntry::backspace:
1602 * @entry: the object which received the signal
1604 * The ::backspace signal is a
1605 * <link linkend="keybinding-signals">keybinding signal</link>
1606 * which gets emitted when the user asks for it.
1608 * The default bindings for this signal are
1609 * Backspace and Shift-Backspace.
1611 signals[BACKSPACE] =
1612 g_signal_new (I_("backspace"),
1613 G_OBJECT_CLASS_TYPE (gobject_class),
1614 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1615 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1617 _gtk_marshal_VOID__VOID,
1621 * GtkEntry::cut-clipboard:
1622 * @entry: the object which received the signal
1624 * The ::cut-clipboard signal is a
1625 * <link linkend="keybinding-signals">keybinding signal</link>
1626 * which gets emitted to cut the selection to the clipboard.
1628 * The default bindings for this signal are
1629 * Ctrl-x and Shift-Delete.
1631 signals[CUT_CLIPBOARD] =
1632 g_signal_new (I_("cut-clipboard"),
1633 G_OBJECT_CLASS_TYPE (gobject_class),
1634 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1635 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1637 _gtk_marshal_VOID__VOID,
1641 * GtkEntry::copy-clipboard:
1642 * @entry: the object which received the signal
1644 * The ::copy-clipboard signal is a
1645 * <link linkend="keybinding-signals">keybinding signal</link>
1646 * which gets emitted to copy the selection to the clipboard.
1648 * The default bindings for this signal are
1649 * Ctrl-c and Ctrl-Insert.
1651 signals[COPY_CLIPBOARD] =
1652 g_signal_new (I_("copy-clipboard"),
1653 G_OBJECT_CLASS_TYPE (gobject_class),
1654 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1655 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1657 _gtk_marshal_VOID__VOID,
1661 * GtkEntry::paste-clipboard:
1662 * @entry: the object which received the signal
1664 * The ::paste-clipboard signal is a
1665 * <link linkend="keybinding-signals">keybinding signal</link>
1666 * which gets emitted to paste the contents of the clipboard
1667 * into the text view.
1669 * The default bindings for this signal are
1670 * Ctrl-v and Shift-Insert.
1672 signals[PASTE_CLIPBOARD] =
1673 g_signal_new (I_("paste-clipboard"),
1674 G_OBJECT_CLASS_TYPE (gobject_class),
1675 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1676 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1678 _gtk_marshal_VOID__VOID,
1682 * GtkEntry::toggle-overwrite:
1683 * @entry: the object which received the signal
1685 * The ::toggle-overwrite signal is a
1686 * <link linkend="keybinding-signals">keybinding signal</link>
1687 * which gets emitted to toggle the overwrite mode of the entry.
1689 * The default bindings for this signal is Insert.
1691 signals[TOGGLE_OVERWRITE] =
1692 g_signal_new (I_("toggle-overwrite"),
1693 G_OBJECT_CLASS_TYPE (gobject_class),
1694 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1695 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1697 _gtk_marshal_VOID__VOID,
1701 * GtkEntry::icon-press:
1702 * @entry: The entry on which the signal is emitted
1703 * @icon_pos: The position of the clicked icon
1704 * @event: (type Gdk.EventButton): the button press event
1706 * The ::icon-press signal is emitted when an activatable icon
1711 signals[ICON_PRESS] =
1712 g_signal_new (I_("icon-press"),
1713 G_TYPE_FROM_CLASS (gobject_class),
1717 _gtk_marshal_VOID__ENUM_BOXED,
1719 GTK_TYPE_ENTRY_ICON_POSITION,
1720 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1723 * GtkEntry::icon-release:
1724 * @entry: The entry on which the signal is emitted
1725 * @icon_pos: The position of the clicked icon
1726 * @event: (type Gdk.EventButton): the button release event
1728 * The ::icon-release signal is emitted on the button release from a
1729 * mouse click over an activatable icon.
1733 signals[ICON_RELEASE] =
1734 g_signal_new (I_("icon-release"),
1735 G_TYPE_FROM_CLASS (gobject_class),
1739 _gtk_marshal_VOID__ENUM_BOXED,
1741 GTK_TYPE_ENTRY_ICON_POSITION,
1742 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1745 * GtkEntry::preedit-changed:
1746 * @entry: the object which received the signal
1747 * @preedit: the current preedit string
1749 * If an input method is used, the typed text will not immediately
1750 * be committed to the buffer. So if you are interested in the text,
1751 * connect to this signal.
1755 signals[PREEDIT_CHANGED] =
1756 g_signal_new_class_handler (I_("preedit-changed"),
1757 G_OBJECT_CLASS_TYPE (gobject_class),
1758 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1761 _gtk_marshal_VOID__STRING,
1770 binding_set = gtk_binding_set_by_class (class);
1772 /* Moving the insertion point */
1773 add_move_binding (binding_set, GDK_KEY_Right, 0,
1774 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1776 add_move_binding (binding_set, GDK_KEY_Left, 0,
1777 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1779 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1780 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1782 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1783 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1785 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1786 GTK_MOVEMENT_WORDS, 1);
1788 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1789 GTK_MOVEMENT_WORDS, -1);
1791 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1792 GTK_MOVEMENT_WORDS, 1);
1794 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1795 GTK_MOVEMENT_WORDS, -1);
1797 add_move_binding (binding_set, GDK_KEY_Home, 0,
1798 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1800 add_move_binding (binding_set, GDK_KEY_End, 0,
1801 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1803 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1804 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1806 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1807 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1809 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1810 GTK_MOVEMENT_BUFFER_ENDS, -1);
1812 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1813 GTK_MOVEMENT_BUFFER_ENDS, 1);
1815 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1816 GTK_MOVEMENT_BUFFER_ENDS, -1);
1818 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1819 GTK_MOVEMENT_BUFFER_ENDS, 1);
1823 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1825 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1827 G_TYPE_BOOLEAN, FALSE);
1828 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1830 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1832 G_TYPE_BOOLEAN, TRUE);
1834 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1836 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1838 G_TYPE_BOOLEAN, FALSE);
1839 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1841 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1843 G_TYPE_BOOLEAN, TRUE);
1846 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1848 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1850 G_TYPE_BOOLEAN, FALSE);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1853 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1855 G_TYPE_BOOLEAN, FALSE);
1859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1867 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1868 "delete-from-cursor", 2,
1869 G_TYPE_ENUM, GTK_DELETE_CHARS,
1872 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1873 "delete-from-cursor", 2,
1874 G_TYPE_ENUM, GTK_DELETE_CHARS,
1877 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1880 /* Make this do the same as Backspace, to help with mis-typing */
1881 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1884 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1885 "delete-from-cursor", 2,
1886 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1889 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1890 "delete-from-cursor", 2,
1891 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1894 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1895 "delete-from-cursor", 2,
1896 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1899 /* Cut/copy/paste */
1901 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1902 "cut-clipboard", 0);
1903 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1904 "copy-clipboard", 0);
1905 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1906 "paste-clipboard", 0);
1908 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1909 "cut-clipboard", 0);
1910 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1911 "copy-clipboard", 0);
1912 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1913 "paste-clipboard", 0);
1916 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1917 "toggle-overwrite", 0);
1918 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1919 "toggle-overwrite", 0);
1922 * GtkEntry:inner-border:
1924 * Sets the text area's border between the text and the frame.
1928 * Deprecated: 3.4: Use the standard border and padding CSS properties
1929 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1930 * of this style property is ignored.
1932 gtk_widget_class_install_style_property (widget_class,
1933 g_param_spec_boxed ("inner-border",
1935 P_("Border between text and frame."),
1937 GTK_PARAM_READABLE |
1938 G_PARAM_DEPRECATED));
1940 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1942 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1946 gtk_entry_editable_init (GtkEditableInterface *iface)
1948 iface->do_insert_text = gtk_entry_insert_text;
1949 iface->do_delete_text = gtk_entry_delete_text;
1950 iface->insert_text = gtk_entry_real_insert_text;
1951 iface->delete_text = gtk_entry_real_delete_text;
1952 iface->get_chars = gtk_entry_get_chars;
1953 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1954 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1955 iface->set_position = gtk_entry_real_set_position;
1956 iface->get_position = gtk_entry_get_position;
1960 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1962 iface->start_editing = gtk_entry_start_editing;
1965 /* for deprecated properties */
1967 gtk_entry_do_set_inner_border (GtkEntry *entry,
1968 const GtkBorder *border)
1971 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1972 gtk_border_copy (border),
1973 (GDestroyNotify) gtk_border_free);
1975 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1977 g_object_notify (G_OBJECT (entry), "inner-border");
1980 static const GtkBorder *
1981 gtk_entry_do_get_inner_border (GtkEntry *entry)
1983 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1987 gtk_entry_set_property (GObject *object,
1989 const GValue *value,
1992 GtkEntry *entry = GTK_ENTRY (object);
1993 GtkEntryPrivate *priv = entry->priv;
1998 gtk_entry_set_buffer (entry, g_value_get_object (value));
2003 gboolean new_value = g_value_get_boolean (value);
2005 if (new_value != priv->editable)
2007 GtkWidget *widget = GTK_WIDGET (entry);
2011 gtk_entry_reset_im_context (entry);
2012 if (gtk_widget_has_focus (widget))
2013 gtk_im_context_focus_out (priv->im_context);
2015 priv->preedit_length = 0;
2016 priv->preedit_cursor = 0;
2019 priv->editable = new_value;
2021 if (new_value && gtk_widget_has_focus (widget))
2022 gtk_im_context_focus_in (priv->im_context);
2024 gtk_widget_queue_draw (widget);
2029 case PROP_MAX_LENGTH:
2030 gtk_entry_set_max_length (entry, g_value_get_int (value));
2033 case PROP_VISIBILITY:
2034 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
2037 case PROP_HAS_FRAME:
2038 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
2041 case PROP_INNER_BORDER:
2042 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
2045 case PROP_INVISIBLE_CHAR:
2046 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2049 case PROP_ACTIVATES_DEFAULT:
2050 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2053 case PROP_WIDTH_CHARS:
2054 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2058 gtk_entry_set_text (entry, g_value_get_string (value));
2062 gtk_entry_set_alignment (entry, g_value_get_float (value));
2065 case PROP_TRUNCATE_MULTILINE:
2066 priv->truncate_multiline = g_value_get_boolean (value);
2069 case PROP_SHADOW_TYPE:
2070 priv->shadow_type = g_value_get_enum (value);
2073 case PROP_OVERWRITE_MODE:
2074 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2077 case PROP_INVISIBLE_CHAR_SET:
2078 if (g_value_get_boolean (value))
2079 priv->invisible_char_set = TRUE;
2081 gtk_entry_unset_invisible_char (entry);
2084 case PROP_CAPS_LOCK_WARNING:
2085 priv->caps_lock_warning = g_value_get_boolean (value);
2088 case PROP_PROGRESS_FRACTION:
2089 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2092 case PROP_PROGRESS_PULSE_STEP:
2093 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2096 case PROP_PLACEHOLDER_TEXT:
2097 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2100 case PROP_PIXBUF_PRIMARY:
2101 gtk_entry_set_icon_from_pixbuf (entry,
2102 GTK_ENTRY_ICON_PRIMARY,
2103 g_value_get_object (value));
2106 case PROP_PIXBUF_SECONDARY:
2107 gtk_entry_set_icon_from_pixbuf (entry,
2108 GTK_ENTRY_ICON_SECONDARY,
2109 g_value_get_object (value));
2112 case PROP_STOCK_PRIMARY:
2113 gtk_entry_set_icon_from_stock (entry,
2114 GTK_ENTRY_ICON_PRIMARY,
2115 g_value_get_string (value));
2118 case PROP_STOCK_SECONDARY:
2119 gtk_entry_set_icon_from_stock (entry,
2120 GTK_ENTRY_ICON_SECONDARY,
2121 g_value_get_string (value));
2124 case PROP_ICON_NAME_PRIMARY:
2125 gtk_entry_set_icon_from_icon_name (entry,
2126 GTK_ENTRY_ICON_PRIMARY,
2127 g_value_get_string (value));
2130 case PROP_ICON_NAME_SECONDARY:
2131 gtk_entry_set_icon_from_icon_name (entry,
2132 GTK_ENTRY_ICON_SECONDARY,
2133 g_value_get_string (value));
2136 case PROP_GICON_PRIMARY:
2137 gtk_entry_set_icon_from_gicon (entry,
2138 GTK_ENTRY_ICON_PRIMARY,
2139 g_value_get_object (value));
2142 case PROP_GICON_SECONDARY:
2143 gtk_entry_set_icon_from_gicon (entry,
2144 GTK_ENTRY_ICON_SECONDARY,
2145 g_value_get_object (value));
2148 case PROP_ACTIVATABLE_PRIMARY:
2149 gtk_entry_set_icon_activatable (entry,
2150 GTK_ENTRY_ICON_PRIMARY,
2151 g_value_get_boolean (value));
2154 case PROP_ACTIVATABLE_SECONDARY:
2155 gtk_entry_set_icon_activatable (entry,
2156 GTK_ENTRY_ICON_SECONDARY,
2157 g_value_get_boolean (value));
2160 case PROP_SENSITIVE_PRIMARY:
2161 gtk_entry_set_icon_sensitive (entry,
2162 GTK_ENTRY_ICON_PRIMARY,
2163 g_value_get_boolean (value));
2166 case PROP_SENSITIVE_SECONDARY:
2167 gtk_entry_set_icon_sensitive (entry,
2168 GTK_ENTRY_ICON_SECONDARY,
2169 g_value_get_boolean (value));
2172 case PROP_TOOLTIP_TEXT_PRIMARY:
2173 gtk_entry_set_icon_tooltip_text (entry,
2174 GTK_ENTRY_ICON_PRIMARY,
2175 g_value_get_string (value));
2178 case PROP_TOOLTIP_TEXT_SECONDARY:
2179 gtk_entry_set_icon_tooltip_text (entry,
2180 GTK_ENTRY_ICON_SECONDARY,
2181 g_value_get_string (value));
2184 case PROP_TOOLTIP_MARKUP_PRIMARY:
2185 gtk_entry_set_icon_tooltip_markup (entry,
2186 GTK_ENTRY_ICON_PRIMARY,
2187 g_value_get_string (value));
2190 case PROP_TOOLTIP_MARKUP_SECONDARY:
2191 gtk_entry_set_icon_tooltip_markup (entry,
2192 GTK_ENTRY_ICON_SECONDARY,
2193 g_value_get_string (value));
2196 case PROP_IM_MODULE:
2197 g_free (priv->im_module);
2198 priv->im_module = g_value_dup_string (value);
2199 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2200 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2203 case PROP_EDITING_CANCELED:
2204 priv->editing_canceled = g_value_get_boolean (value);
2207 case PROP_COMPLETION:
2208 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2211 case PROP_INPUT_PURPOSE:
2212 gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
2215 case PROP_INPUT_HINTS:
2216 gtk_entry_set_input_hints (entry, g_value_get_flags (value));
2219 case PROP_ATTRIBUTES:
2220 gtk_entry_set_attributes (entry, g_value_get_boxed (value));
2223 case PROP_SCROLL_OFFSET:
2224 case PROP_CURSOR_POSITION:
2226 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2232 gtk_entry_get_property (GObject *object,
2237 GtkEntry *entry = GTK_ENTRY (object);
2238 GtkEntryPrivate *priv = entry->priv;
2243 g_value_set_object (value, gtk_entry_get_buffer (entry));
2246 case PROP_CURSOR_POSITION:
2247 g_value_set_int (value, priv->current_pos);
2250 case PROP_SELECTION_BOUND:
2251 g_value_set_int (value, priv->selection_bound);
2255 g_value_set_boolean (value, priv->editable);
2258 case PROP_MAX_LENGTH:
2259 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2262 case PROP_VISIBILITY:
2263 g_value_set_boolean (value, priv->visible);
2266 case PROP_HAS_FRAME:
2267 g_value_set_boolean (value, priv->has_frame);
2270 case PROP_INNER_BORDER:
2271 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2274 case PROP_INVISIBLE_CHAR:
2275 g_value_set_uint (value, priv->invisible_char);
2278 case PROP_ACTIVATES_DEFAULT:
2279 g_value_set_boolean (value, priv->activates_default);
2282 case PROP_WIDTH_CHARS:
2283 g_value_set_int (value, priv->width_chars);
2286 case PROP_SCROLL_OFFSET:
2287 g_value_set_int (value, priv->scroll_offset);
2291 g_value_set_string (value, gtk_entry_get_text (entry));
2295 g_value_set_float (value, gtk_entry_get_alignment (entry));
2298 case PROP_TRUNCATE_MULTILINE:
2299 g_value_set_boolean (value, priv->truncate_multiline);
2302 case PROP_SHADOW_TYPE:
2303 g_value_set_enum (value, priv->shadow_type);
2306 case PROP_OVERWRITE_MODE:
2307 g_value_set_boolean (value, priv->overwrite_mode);
2310 case PROP_TEXT_LENGTH:
2311 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2314 case PROP_INVISIBLE_CHAR_SET:
2315 g_value_set_boolean (value, priv->invisible_char_set);
2318 case PROP_IM_MODULE:
2319 g_value_set_string (value, priv->im_module);
2322 case PROP_CAPS_LOCK_WARNING:
2323 g_value_set_boolean (value, priv->caps_lock_warning);
2326 case PROP_PROGRESS_FRACTION:
2327 g_value_set_double (value, priv->progress_fraction);
2330 case PROP_PROGRESS_PULSE_STEP:
2331 g_value_set_double (value, priv->progress_pulse_fraction);
2334 case PROP_PLACEHOLDER_TEXT:
2335 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2338 case PROP_PIXBUF_PRIMARY:
2339 g_value_set_object (value,
2340 gtk_entry_get_icon_pixbuf (entry,
2341 GTK_ENTRY_ICON_PRIMARY));
2344 case PROP_PIXBUF_SECONDARY:
2345 g_value_set_object (value,
2346 gtk_entry_get_icon_pixbuf (entry,
2347 GTK_ENTRY_ICON_SECONDARY));
2350 case PROP_STOCK_PRIMARY:
2351 g_value_set_string (value,
2352 gtk_entry_get_icon_stock (entry,
2353 GTK_ENTRY_ICON_PRIMARY));
2356 case PROP_STOCK_SECONDARY:
2357 g_value_set_string (value,
2358 gtk_entry_get_icon_stock (entry,
2359 GTK_ENTRY_ICON_SECONDARY));
2362 case PROP_ICON_NAME_PRIMARY:
2363 g_value_set_string (value,
2364 gtk_entry_get_icon_name (entry,
2365 GTK_ENTRY_ICON_PRIMARY));
2368 case PROP_ICON_NAME_SECONDARY:
2369 g_value_set_string (value,
2370 gtk_entry_get_icon_name (entry,
2371 GTK_ENTRY_ICON_SECONDARY));
2374 case PROP_GICON_PRIMARY:
2375 g_value_set_object (value,
2376 gtk_entry_get_icon_gicon (entry,
2377 GTK_ENTRY_ICON_PRIMARY));
2380 case PROP_GICON_SECONDARY:
2381 g_value_set_object (value,
2382 gtk_entry_get_icon_gicon (entry,
2383 GTK_ENTRY_ICON_SECONDARY));
2386 case PROP_STORAGE_TYPE_PRIMARY:
2387 g_value_set_enum (value,
2388 gtk_entry_get_icon_storage_type (entry,
2389 GTK_ENTRY_ICON_PRIMARY));
2392 case PROP_STORAGE_TYPE_SECONDARY:
2393 g_value_set_enum (value,
2394 gtk_entry_get_icon_storage_type (entry,
2395 GTK_ENTRY_ICON_SECONDARY));
2398 case PROP_ACTIVATABLE_PRIMARY:
2399 g_value_set_boolean (value,
2400 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2403 case PROP_ACTIVATABLE_SECONDARY:
2404 g_value_set_boolean (value,
2405 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2408 case PROP_SENSITIVE_PRIMARY:
2409 g_value_set_boolean (value,
2410 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2413 case PROP_SENSITIVE_SECONDARY:
2414 g_value_set_boolean (value,
2415 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2418 case PROP_TOOLTIP_TEXT_PRIMARY:
2419 g_value_take_string (value,
2420 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2423 case PROP_TOOLTIP_TEXT_SECONDARY:
2424 g_value_take_string (value,
2425 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2428 case PROP_TOOLTIP_MARKUP_PRIMARY:
2429 g_value_take_string (value,
2430 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2433 case PROP_TOOLTIP_MARKUP_SECONDARY:
2434 g_value_take_string (value,
2435 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2438 case PROP_EDITING_CANCELED:
2439 g_value_set_boolean (value,
2440 priv->editing_canceled);
2443 case PROP_COMPLETION:
2444 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2447 case PROP_INPUT_PURPOSE:
2448 g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
2451 case PROP_INPUT_HINTS:
2452 g_value_set_flags (value, gtk_entry_get_input_hints (entry));
2455 case PROP_ATTRIBUTES:
2456 g_value_set_boxed (value, priv->attrs);
2460 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2466 find_invisible_char (GtkWidget *widget)
2468 PangoLayout *layout;
2469 PangoAttrList *attr_list;
2471 gunichar invisible_chars [] = {
2473 0x25cf, /* BLACK CIRCLE */
2474 0x2022, /* BULLET */
2475 0x2731, /* HEAVY ASTERISK */
2476 0x273a /* SIXTEEN POINTED ASTERISK */
2479 gtk_widget_style_get (widget,
2480 "invisible-char", &invisible_chars[0],
2483 layout = gtk_widget_create_pango_layout (widget, NULL);
2485 attr_list = pango_attr_list_new ();
2486 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2488 pango_layout_set_attributes (layout, attr_list);
2489 pango_attr_list_unref (attr_list);
2491 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2493 gchar text[7] = { 0, };
2496 len = g_unichar_to_utf8 (invisible_chars[i], text);
2497 pango_layout_set_text (layout, text, len);
2499 count = pango_layout_get_unknown_glyphs_count (layout);
2503 g_object_unref (layout);
2504 return invisible_chars[i];
2508 g_object_unref (layout);
2514 gtk_entry_init (GtkEntry *entry)
2516 GtkStyleContext *context;
2517 GtkEntryPrivate *priv;
2519 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2524 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2525 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2527 priv->editable = TRUE;
2528 priv->visible = TRUE;
2529 priv->dnd_position = -1;
2530 priv->width_chars = -1;
2531 priv->is_cell_renderer = FALSE;
2532 priv->editing_canceled = FALSE;
2533 priv->has_frame = TRUE;
2534 priv->truncate_multiline = FALSE;
2535 priv->shadow_type = GTK_SHADOW_IN;
2537 priv->caps_lock_warning = TRUE;
2538 priv->caps_lock_warning_shown = FALSE;
2539 priv->progress_fraction = 0.0;
2540 priv->progress_pulse_fraction = 0.1;
2542 gtk_drag_dest_set (GTK_WIDGET (entry),
2543 GTK_DEST_DEFAULT_HIGHLIGHT,
2545 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2546 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2548 /* This object is completely private. No external entity can gain a reference
2549 * to it; so we create it here and destroy it in finalize().
2551 priv->im_context = gtk_im_multicontext_new ();
2553 g_signal_connect (priv->im_context, "commit",
2554 G_CALLBACK (gtk_entry_commit_cb), entry);
2555 g_signal_connect (priv->im_context, "preedit-changed",
2556 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2557 g_signal_connect (priv->im_context, "retrieve-surrounding",
2558 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2559 g_signal_connect (priv->im_context, "delete-surrounding",
2560 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2562 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2563 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2565 gtk_entry_update_cached_style_values (entry);
2567 priv->text_handle = _gtk_text_handle_new (GTK_WIDGET (entry));
2568 g_signal_connect (priv->text_handle, "handle-dragged",
2569 G_CALLBACK (gtk_entry_handle_dragged), entry);
2573 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2574 GtkStyleContext *context,
2575 GtkEntryIconPosition icon_pos)
2577 GtkEntryPrivate *priv = entry->priv;
2578 EntryIconInfo *icon_info = priv->icons[icon_pos];
2580 GtkStateFlags state;
2582 widget = GTK_WIDGET (entry);
2583 state = gtk_widget_get_state_flags (widget);
2585 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2587 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2588 state |= GTK_STATE_FLAG_INSENSITIVE;
2589 else if (icon_info->prelight)
2590 state |= GTK_STATE_FLAG_PRELIGHT;
2592 gtk_style_context_save (context);
2594 gtk_style_context_set_state (context, state);
2595 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2597 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2599 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2600 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2602 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2606 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2607 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2609 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2614 get_icon_width (GtkEntry *entry,
2615 GtkEntryIconPosition icon_pos)
2617 GtkEntryPrivate *priv = entry->priv;
2618 EntryIconInfo *icon_info = priv->icons[icon_pos];
2619 GtkStyleContext *context;
2626 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2627 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2628 gtk_style_context_get_padding (context, 0, &padding);
2630 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2632 gtk_style_context_restore (context);
2635 width += padding.left + padding.right;
2641 get_icon_allocations (GtkEntry *entry,
2642 GtkAllocation *primary,
2643 GtkAllocation *secondary)
2646 GtkEntryPrivate *priv = entry->priv;
2647 gint x, y, width, height;
2649 get_text_area_size (entry, &x, &y, &width, &height);
2651 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2652 y += priv->focus_width;
2655 primary->height = height;
2656 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2659 secondary->height = height;
2660 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2662 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2664 primary->x = x + width - primary->width;
2670 secondary->x = x + width - secondary->width;
2676 begin_change (GtkEntry *entry)
2678 GtkEntryPrivate *priv = entry->priv;
2680 priv->change_count++;
2682 g_object_freeze_notify (G_OBJECT (entry));
2686 end_change (GtkEntry *entry)
2688 GtkEditable *editable = GTK_EDITABLE (entry);
2689 GtkEntryPrivate *priv = entry->priv;
2691 g_return_if_fail (priv->change_count > 0);
2693 g_object_thaw_notify (G_OBJECT (entry));
2695 priv->change_count--;
2697 if (priv->change_count == 0)
2699 if (priv->real_changed)
2701 g_signal_emit_by_name (editable, "changed");
2702 priv->real_changed = FALSE;
2708 emit_changed (GtkEntry *entry)
2710 GtkEditable *editable = GTK_EDITABLE (entry);
2711 GtkEntryPrivate *priv = entry->priv;
2713 if (priv->change_count == 0)
2714 g_signal_emit_by_name (editable, "changed");
2716 priv->real_changed = TRUE;
2720 gtk_entry_destroy (GtkWidget *widget)
2722 GtkEntry *entry = GTK_ENTRY (widget);
2723 GtkEntryPrivate *priv = entry->priv;
2725 priv->current_pos = priv->selection_bound = 0;
2726 gtk_entry_reset_im_context (entry);
2727 gtk_entry_reset_layout (entry);
2729 if (priv->blink_timeout)
2731 g_source_remove (priv->blink_timeout);
2732 priv->blink_timeout = 0;
2735 if (priv->recompute_idle)
2737 g_source_remove (priv->recompute_idle);
2738 priv->recompute_idle = 0;
2741 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2745 gtk_entry_dispose (GObject *object)
2747 GtkEntry *entry = GTK_ENTRY (object);
2748 GtkEntryPrivate *priv = entry->priv;
2751 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2752 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2753 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2754 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2755 gtk_entry_set_completion (entry, NULL);
2759 buffer_disconnect_signals (entry);
2760 g_object_unref (priv->buffer);
2761 priv->buffer = NULL;
2764 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2765 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2766 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2767 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2771 gtk_entry_finalize (GObject *object)
2773 GtkEntry *entry = GTK_ENTRY (object);
2774 GtkEntryPrivate *priv = entry->priv;
2775 EntryIconInfo *icon_info = NULL;
2778 for (i = 0; i < MAX_ICONS; i++)
2780 if ((icon_info = priv->icons[i]) != NULL)
2782 if (icon_info->target_list != NULL)
2784 gtk_target_list_unref (icon_info->target_list);
2785 icon_info->target_list = NULL;
2788 g_clear_object (&icon_info->icon_helper);
2790 g_slice_free (EntryIconInfo, icon_info);
2791 priv->icons[i] = NULL;
2795 if (priv->cached_layout)
2796 g_object_unref (priv->cached_layout);
2798 g_object_unref (priv->im_context);
2800 if (priv->blink_timeout)
2801 g_source_remove (priv->blink_timeout);
2803 if (priv->recompute_idle)
2804 g_source_remove (priv->recompute_idle);
2806 g_object_unref (priv->text_handle);
2807 g_free (priv->placeholder_text);
2808 g_free (priv->im_module);
2810 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2814 gtk_entry_get_display_mode (GtkEntry *entry)
2816 GtkEntryPrivate *priv = entry->priv;
2819 return DISPLAY_NORMAL;
2821 if (priv->invisible_char == 0 && priv->invisible_char_set)
2822 return DISPLAY_BLANK;
2824 return DISPLAY_INVISIBLE;
2828 _gtk_entry_get_display_text (GtkEntry *entry,
2832 GtkEntryPasswordHint *password_hint;
2833 GtkEntryPrivate *priv;
2834 gunichar invisible_char;
2845 text = gtk_entry_buffer_get_text (get_buffer (entry));
2846 length = gtk_entry_buffer_get_length (get_buffer (entry));
2850 if (start_pos > length)
2853 if (end_pos <= start_pos)
2854 return g_strdup ("");
2855 else if (priv->visible)
2857 start = g_utf8_offset_to_pointer (text, start_pos);
2858 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2859 return g_strndup (start, end - start);
2863 str = g_string_sized_new (length * 2);
2865 /* Figure out what our invisible char is and encode it */
2866 if (!priv->invisible_char)
2867 invisible_char = priv->invisible_char_set ? ' ' : '*';
2869 invisible_char = priv->invisible_char;
2870 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2873 * Add hidden characters for each character in the text
2874 * buffer. If there is a password hint, then keep that
2875 * character visible.
2878 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2879 for (i = start_pos; i < end_pos; ++i)
2881 if (password_hint && i == password_hint->position)
2883 start = g_utf8_offset_to_pointer (text, i);
2884 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2888 g_string_append_len (str, char_str, char_len);
2892 return g_string_free (str, FALSE);
2897 update_cursors (GtkWidget *widget)
2899 GtkEntry *entry = GTK_ENTRY (widget);
2900 GtkEntryPrivate *priv = entry->priv;
2901 EntryIconInfo *icon_info = NULL;
2902 GdkDisplay *display;
2906 for (i = 0; i < MAX_ICONS; i++)
2908 if ((icon_info = priv->icons[i]) != NULL)
2910 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2911 icon_info->window != NULL)
2912 gdk_window_show_unraised (icon_info->window);
2914 /* The icon windows are not children of the visible entry window,
2915 * thus we can't just inherit the xterm cursor. Slight complication
2916 * here is that for the entry, insensitive => arrow cursor, but for
2917 * an icon in a sensitive entry, insensitive => xterm cursor.
2919 if (gtk_widget_is_sensitive (widget) &&
2920 (icon_info->insensitive ||
2921 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2923 display = gtk_widget_get_display (widget);
2924 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2925 gdk_window_set_cursor (icon_info->window, cursor);
2926 g_object_unref (cursor);
2930 gdk_window_set_cursor (icon_info->window, NULL);
2937 realize_icon_info (GtkWidget *widget,
2938 GtkEntryIconPosition icon_pos)
2940 GtkEntry *entry = GTK_ENTRY (widget);
2941 GtkEntryPrivate *priv = entry->priv;
2942 EntryIconInfo *icon_info = priv->icons[icon_pos];
2943 GdkWindowAttr attributes;
2944 gint attributes_mask;
2946 g_return_if_fail (icon_info != NULL);
2950 attributes.width = 1;
2951 attributes.height = 1;
2952 attributes.window_type = GDK_WINDOW_CHILD;
2953 attributes.wclass = GDK_INPUT_ONLY;
2954 attributes.event_mask = gtk_widget_get_events (widget);
2955 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2956 GDK_BUTTON_RELEASE_MASK |
2957 GDK_BUTTON1_MOTION_MASK |
2958 GDK_BUTTON3_MOTION_MASK |
2959 GDK_POINTER_MOTION_HINT_MASK |
2960 GDK_POINTER_MOTION_MASK |
2961 GDK_ENTER_NOTIFY_MASK |
2962 GDK_LEAVE_NOTIFY_MASK);
2963 attributes_mask = GDK_WA_X | GDK_WA_Y;
2965 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2968 gdk_window_set_user_data (icon_info->window, widget);
2970 gtk_widget_queue_resize (widget);
2973 static EntryIconInfo*
2974 construct_icon_info (GtkWidget *widget,
2975 GtkEntryIconPosition icon_pos)
2977 GtkEntry *entry = GTK_ENTRY (widget);
2978 GtkEntryPrivate *priv = entry->priv;
2979 EntryIconInfo *icon_info;
2981 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2983 icon_info = g_slice_new0 (EntryIconInfo);
2984 priv->icons[icon_pos] = icon_info;
2986 icon_info->icon_helper = _gtk_icon_helper_new ();
2987 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
2989 if (gtk_widget_get_realized (widget))
2990 realize_icon_info (widget, icon_pos);
2996 gtk_entry_map (GtkWidget *widget)
2998 GtkEntry *entry = GTK_ENTRY (widget);
2999 GtkEntryPrivate *priv = entry->priv;
3000 EntryIconInfo *icon_info = NULL;
3003 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
3005 gdk_window_show (priv->text_area);
3007 for (i = 0; i < MAX_ICONS; i++)
3009 if ((icon_info = priv->icons[i]) != NULL)
3011 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3012 icon_info->window != NULL)
3013 gdk_window_show (icon_info->window);
3017 update_cursors (widget);
3021 gtk_entry_unmap (GtkWidget *widget)
3023 GtkEntry *entry = GTK_ENTRY (widget);
3024 GtkEntryPrivate *priv = entry->priv;
3025 EntryIconInfo *icon_info = NULL;
3028 _gtk_text_handle_set_mode (priv->text_handle,
3029 GTK_TEXT_HANDLE_MODE_NONE);
3031 for (i = 0; i < MAX_ICONS; i++)
3033 if ((icon_info = priv->icons[i]) != NULL)
3035 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3036 icon_info->window != NULL)
3037 gdk_window_hide (icon_info->window);
3041 gdk_window_hide (priv->text_area);
3043 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
3047 gtk_entry_realize (GtkWidget *widget)
3050 GtkEntryPrivate *priv;
3051 EntryIconInfo *icon_info;
3053 GdkWindowAttr attributes;
3054 gint attributes_mask;
3055 gint frame_x, frame_y;
3058 gtk_widget_set_realized (widget, TRUE);
3059 window = gtk_widget_get_parent_window (widget);
3060 gtk_widget_set_window (widget, window);
3061 g_object_ref (window);
3063 entry = GTK_ENTRY (widget);
3066 attributes.window_type = GDK_WINDOW_CHILD;
3067 attributes.wclass = GDK_INPUT_ONLY;
3068 attributes.event_mask = gtk_widget_get_events (widget);
3069 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3070 GDK_BUTTON_RELEASE_MASK |
3071 GDK_BUTTON1_MOTION_MASK |
3072 GDK_BUTTON3_MOTION_MASK |
3073 GDK_POINTER_MOTION_HINT_MASK |
3074 GDK_POINTER_MOTION_MASK |
3075 GDK_ENTER_NOTIFY_MASK |
3076 GDK_LEAVE_NOTIFY_MASK);
3077 attributes_mask = GDK_WA_X | GDK_WA_Y;
3079 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3081 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3082 attributes.x += frame_x;
3083 attributes.y += frame_y;
3085 if (gtk_widget_is_sensitive (widget))
3087 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3088 attributes_mask |= GDK_WA_CURSOR;
3091 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3095 gdk_window_set_user_data (priv->text_area, entry);
3097 if (attributes_mask & GDK_WA_CURSOR)
3098 g_object_unref (attributes.cursor);
3100 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3102 gtk_entry_adjust_scroll (entry);
3103 gtk_entry_update_primary_selection (entry);
3104 _gtk_text_handle_set_relative_to (priv->text_handle, priv->text_area);
3106 /* If the icon positions are already setup, create their windows.
3107 * Otherwise if they don't exist yet, then construct_icon_info()
3108 * will create the windows once the widget is already realized.
3110 for (i = 0; i < MAX_ICONS; i++)
3112 if ((icon_info = priv->icons[i]) != NULL)
3114 if (icon_info->window == NULL)
3115 realize_icon_info (widget, i);
3121 gtk_entry_unrealize (GtkWidget *widget)
3123 GtkEntry *entry = GTK_ENTRY (widget);
3124 GtkEntryPrivate *priv = entry->priv;
3125 GtkClipboard *clipboard;
3126 EntryIconInfo *icon_info;
3129 gtk_entry_reset_layout (entry);
3131 gtk_im_context_set_client_window (priv->im_context, NULL);
3132 _gtk_text_handle_set_relative_to (priv->text_handle, NULL);
3134 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3135 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3136 gtk_clipboard_clear (clipboard);
3138 if (priv->text_area)
3140 gdk_window_set_user_data (priv->text_area, NULL);
3141 gdk_window_destroy (priv->text_area);
3142 priv->text_area = NULL;
3145 if (priv->popup_menu)
3147 gtk_widget_destroy (priv->popup_menu);
3148 priv->popup_menu = NULL;
3151 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3153 for (i = 0; i < MAX_ICONS; i++)
3155 if ((icon_info = priv->icons[i]) != NULL)
3157 if (icon_info->window != NULL)
3159 gdk_window_destroy (icon_info->window);
3160 icon_info->window = NULL;
3167 _gtk_entry_get_borders (GtkEntry *entry,
3168 GtkBorder *border_out)
3170 GtkEntryPrivate *priv = entry->priv;
3171 GtkWidget *widget = GTK_WIDGET (entry);
3172 GtkBorder tmp = { 0, 0, 0, 0 };
3173 GtkStyleContext *context;
3175 context = gtk_widget_get_style_context (widget);
3176 gtk_style_context_get_padding (context, 0, &tmp);
3178 if (priv->has_frame)
3182 gtk_style_context_get_border (context, 0, &border);
3183 tmp.top += border.top;
3184 tmp.right += border.right;
3185 tmp.bottom += border.bottom;
3186 tmp.left += border.left;
3189 if (!priv->interior_focus)
3191 tmp.top += priv->focus_width;
3192 tmp.right += priv->focus_width;
3193 tmp.bottom += priv->focus_width;
3194 tmp.left += priv->focus_width;
3197 if (border_out != NULL)
3202 gtk_entry_get_preferred_width (GtkWidget *widget,
3206 GtkEntry *entry = GTK_ENTRY (widget);
3207 GtkEntryPrivate *priv = entry->priv;
3208 PangoFontMetrics *metrics;
3210 PangoContext *context;
3211 GtkStyleContext *style_context;
3212 GtkStateFlags state;
3213 gint icon_widths = 0;
3217 context = gtk_widget_get_pango_context (widget);
3219 style_context = gtk_widget_get_style_context (widget);
3220 state = gtk_widget_get_state_flags (widget);
3222 metrics = pango_context_get_metrics (context,
3223 gtk_style_context_get_font (style_context, state),
3224 pango_context_get_language (context));
3226 _gtk_entry_get_borders (entry, &borders);
3228 if (priv->width_chars < 0)
3229 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3232 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3233 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3234 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3236 width = char_pixels * priv->width_chars + borders.left + borders.right;
3239 for (i = 0; i < MAX_ICONS; i++)
3241 icon_width = get_icon_width (entry, i);
3243 icon_widths += icon_width;
3246 if (icon_widths > width)
3247 width += icon_widths;
3249 pango_font_metrics_unref (metrics);
3256 gtk_entry_get_preferred_height (GtkWidget *widget,
3260 GtkEntry *entry = GTK_ENTRY (widget);
3261 GtkEntryPrivate *priv = entry->priv;
3262 PangoFontMetrics *metrics;
3264 GtkStyleContext *style_context;
3265 GtkStateFlags state;
3266 PangoContext *context;
3269 context = gtk_widget_get_pango_context (widget);
3271 style_context = gtk_widget_get_style_context (widget);
3272 state = gtk_widget_get_state_flags (widget);
3274 metrics = pango_context_get_metrics (context,
3275 gtk_style_context_get_font (style_context, state),
3276 pango_context_get_language (context));
3278 priv->ascent = pango_font_metrics_get_ascent (metrics);
3279 priv->descent = pango_font_metrics_get_descent (metrics);
3281 _gtk_entry_get_borders (entry, &borders);
3283 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3285 pango_font_metrics_unref (metrics);
3292 place_windows (GtkEntry *entry)
3294 GtkWidget *widget = GTK_WIDGET (entry);
3295 GtkEntryPrivate *priv = entry->priv;
3296 gint x, y, width, height;
3297 gint frame_x, frame_y;
3298 GtkAllocation primary;
3299 GtkAllocation secondary;
3300 EntryIconInfo *icon_info = NULL;
3302 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3303 get_text_area_size (entry, &x, &y, &width, &height);
3304 get_icon_allocations (entry, &primary, &secondary);
3306 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3307 y += priv->focus_width;
3309 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3310 x += secondary.width;
3313 width -= primary.width + secondary.width;
3317 primary.x += frame_x;
3318 primary.y += frame_y;
3319 secondary.x += frame_x;
3320 secondary.y += frame_y;
3322 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3323 gdk_window_move_resize (icon_info->window,
3324 primary.x, primary.y,
3325 primary.width, primary.height);
3327 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3328 gdk_window_move_resize (icon_info->window,
3329 secondary.x, secondary.y,
3330 secondary.width, secondary.height);
3332 gdk_window_move_resize (priv->text_area, x, y, width, height);
3336 gtk_entry_get_text_area_size (GtkEntry *entry,
3342 GtkEntryPrivate *priv = entry->priv;
3343 GtkWidget *widget = GTK_WIDGET (entry);
3344 GtkAllocation allocation;
3345 GtkRequisition requisition;
3350 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3351 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3353 gtk_widget_get_allocation (widget, &allocation);
3354 _gtk_entry_get_borders (entry, &borders);
3356 if (gtk_widget_get_realized (widget))
3357 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3359 frame_height = req_height;
3361 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3362 frame_height -= 2 * priv->focus_width;
3368 *y = floor ((frame_height - req_height) / 2) + borders.top;
3371 *width = allocation.width - borders.left - borders.right;
3374 *height = req_height - borders.top - borders.bottom;
3378 get_text_area_size (GtkEntry *entry,
3384 GtkEntryClass *class;
3386 g_return_if_fail (GTK_IS_ENTRY (entry));
3388 class = GTK_ENTRY_GET_CLASS (entry);
3390 if (class->get_text_area_size)
3391 class->get_text_area_size (entry, x, y, width, height);
3396 get_frame_size (GtkEntry *entry,
3397 gboolean relative_to_window,
3403 GtkEntryPrivate *priv = entry->priv;
3404 GtkAllocation allocation;
3405 GtkRequisition requisition;
3406 GtkWidget *widget = GTK_WIDGET (entry);
3409 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3411 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3413 gtk_widget_get_allocation (widget, &allocation);
3416 *x = relative_to_window ? allocation.x : 0;
3420 if (priv->is_cell_renderer)
3423 *y = (allocation.height - req_height) / 2;
3425 if (relative_to_window)
3430 *width = allocation.width;
3434 if (priv->is_cell_renderer)
3435 *height = allocation.height;
3437 *height = req_height;
3442 gtk_entry_size_allocate (GtkWidget *widget,
3443 GtkAllocation *allocation)
3445 GtkEntry *entry = GTK_ENTRY (widget);
3447 gtk_widget_set_allocation (widget, allocation);
3449 if (gtk_widget_get_realized (widget))
3451 GtkEntryCompletion* completion;
3453 place_windows (entry);
3454 gtk_entry_recompute (entry);
3456 completion = gtk_entry_get_completion (entry);
3458 _gtk_entry_completion_resize_popup (completion);
3463 should_prelight (GtkEntry *entry,
3464 GtkEntryIconPosition icon_pos)
3466 GtkEntryPrivate *priv = entry->priv;
3467 EntryIconInfo *icon_info = priv->icons[icon_pos];
3473 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3476 if (icon_info->pressed)
3479 gtk_widget_style_get (GTK_WIDGET (entry),
3480 "icon-prelight", &prelight,
3487 draw_icon (GtkWidget *widget,
3489 GtkEntryIconPosition icon_pos)
3491 GtkEntry *entry = GTK_ENTRY (widget);
3492 GtkEntryPrivate *priv = entry->priv;
3493 EntryIconInfo *icon_info = priv->icons[icon_pos];
3494 gint x, y, width, height, pix_width, pix_height;
3495 GtkStyleContext *context;
3501 width = gdk_window_get_width (icon_info->window);
3502 height = gdk_window_get_height (icon_info->window);
3504 /* size_allocate hasn't been called yet. These are the default values.
3506 if (width == 1 || height == 1)
3510 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3512 context = gtk_widget_get_style_context (widget);
3513 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3514 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3515 &pix_width, &pix_height);
3516 gtk_style_context_get_padding (context, 0, &padding);
3518 x = MAX (0, padding.left);
3519 y = MAX (0, (height - pix_height) / 2);
3521 _gtk_icon_helper_draw (icon_info->icon_helper,
3525 gtk_style_context_restore (context);
3531 gtk_entry_draw_frame (GtkWidget *widget,
3532 GtkStyleContext *context,
3535 GtkEntry *entry = GTK_ENTRY (widget);
3536 GtkEntryPrivate *priv = entry->priv;
3537 gint x = 0, y = 0, width, height;
3538 gint frame_x, frame_y;
3542 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3544 cairo_translate (cr, frame_x, frame_y);
3546 /* Fix a problem with some themes which assume that entry->text_area's
3547 * width equals widget->window's width
3548 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3549 if (GTK_IS_SPIN_BUTTON (widget))
3553 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3554 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3557 width += borders.left + borders.right;
3560 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3562 x += priv->focus_width;
3563 y += priv->focus_width;
3564 width -= 2 * priv->focus_width;
3565 height -= 2 * priv->focus_width;
3568 gtk_render_background (context, cr,
3569 x, y, width, height);
3571 if (priv->has_frame)
3572 gtk_render_frame (context, cr,
3573 x, y, width, height);
3575 gtk_entry_draw_progress (widget, context, cr);
3577 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3579 x -= priv->focus_width;
3580 y -= priv->focus_width;
3581 width += 2 * priv->focus_width;
3582 height += 2 * priv->focus_width;
3584 gtk_render_focus (context, cr,
3585 0, 0, width, height);
3592 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3593 GtkStyleContext *context)
3595 GtkEntryPrivate *private = entry->priv;
3597 gtk_style_context_save (context);
3598 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3599 if (private->progress_pulse_mode)
3600 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3604 get_progress_area (GtkWidget *widget,
3610 GtkEntry *entry = GTK_ENTRY (widget);
3611 GtkEntryPrivate *private = entry->priv;
3612 GtkStyleContext *context;
3613 GtkBorder margin, border, entry_borders;
3614 gint frame_width, text_area_width, text_area_height;
3616 context = gtk_widget_get_style_context (widget);
3617 _gtk_entry_get_borders (entry, &entry_borders);
3618 get_text_area_size (entry,
3620 &text_area_width, &text_area_height);
3621 get_frame_size (entry, FALSE,
3623 &frame_width, NULL);
3627 *width = text_area_width + entry_borders.left + entry_borders.right;
3628 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3630 /* if the text area got resized by a subclass, subtract the left/right
3631 * border width, so that the progress bar won't extend over the resized
3634 if (frame_width > *width)
3636 gtk_style_context_get_border (context, 0, &border);
3637 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3639 *x = (frame_width - *width) + border.left;
3640 *width -= border.left;
3644 *width -= border.right;
3648 gtk_entry_prepare_context_for_progress (entry, context);
3649 gtk_style_context_get_margin (context, 0, &margin);
3651 gtk_style_context_restore (context);
3655 *width -= margin.left + margin.right;
3656 *height -= margin.top + margin.bottom;
3658 if (private->progress_pulse_mode)
3660 gdouble value = private->progress_pulse_current;
3662 *x += (gint) floor(value * (*width));
3663 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3665 else if (private->progress_fraction > 0)
3667 gdouble value = private->progress_fraction;
3669 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3673 bar_width = floor(value * (*width) + 0.5);
3674 *x += *width - bar_width;
3679 *width = (gint) floor(value * (*width) + 0.5);
3690 gtk_entry_draw_progress (GtkWidget *widget,
3691 GtkStyleContext *context,
3694 GtkEntry *entry = GTK_ENTRY (widget);
3695 gint x, y, width, height;
3697 get_progress_area (widget, &x, &y, &width, &height);
3699 if ((width <= 0) || (height <= 0))
3702 gtk_entry_prepare_context_for_progress (entry, context);
3703 gtk_render_activity (context, cr,
3704 x, y, width, height);
3706 gtk_style_context_restore (context);
3710 gtk_entry_draw (GtkWidget *widget,
3713 GtkEntry *entry = GTK_ENTRY (widget);
3714 GtkStyleContext *context;
3715 GtkEntryPrivate *priv = entry->priv;
3718 context = gtk_widget_get_style_context (widget);
3720 /* Draw entry_bg, shadow, progress and focus */
3721 gtk_entry_draw_frame (widget, context, cr);
3723 /* Draw text and cursor */
3726 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3728 if (priv->dnd_position != -1)
3729 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3731 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3733 /* When no text is being displayed at all, don't show the cursor */
3734 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3735 gtk_widget_has_focus (widget) &&
3736 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3737 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3742 for (i = 0; i < MAX_ICONS; i++)
3744 EntryIconInfo *icon_info = priv->icons[i];
3746 if (icon_info != NULL)
3747 draw_icon (widget, cr, i);
3754 gtk_entry_enter_notify (GtkWidget *widget,
3755 GdkEventCrossing *event)
3757 GtkEntry *entry = GTK_ENTRY (widget);
3758 GtkEntryPrivate *priv = entry->priv;
3761 for (i = 0; i < MAX_ICONS; i++)
3763 EntryIconInfo *icon_info = priv->icons[i];
3765 if (icon_info != NULL && event->window == icon_info->window)
3767 if (should_prelight (entry, i))
3769 icon_info->prelight = TRUE;
3770 gtk_widget_queue_draw (widget);
3781 gtk_entry_leave_notify (GtkWidget *widget,
3782 GdkEventCrossing *event)
3784 GtkEntry *entry = GTK_ENTRY (widget);
3785 GtkEntryPrivate *priv = entry->priv;
3788 for (i = 0; i < MAX_ICONS; i++)
3790 EntryIconInfo *icon_info = priv->icons[i];
3792 if (icon_info != NULL && event->window == icon_info->window)
3794 /* a grab means that we may never see the button release */
3795 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3796 icon_info->pressed = FALSE;
3798 if (should_prelight (entry, i))
3800 icon_info->prelight = FALSE;
3801 gtk_widget_queue_draw (widget);
3812 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3816 gint start_char, end_char;
3818 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3820 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3821 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3822 const char *text = pango_layout_get_text (layout);
3823 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3824 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3825 gint real_n_ranges, i;
3827 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3833 for (i = 0; i < real_n_ranges; ++i)
3835 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3836 r[2 * i] = r[2 * i] / PANGO_SCALE;
3841 *n_ranges = real_n_ranges;
3853 in_selection (GtkEntry *entry,
3858 gint retval = FALSE;
3860 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3862 for (i = 0; i < n_ranges; ++i)
3864 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3876 gtk_entry_move_handle (GtkEntry *entry,
3877 GtkTextHandlePosition pos,
3882 GtkEntryPrivate *priv = entry->priv;
3884 if (!_gtk_text_handle_get_is_dragged (priv->text_handle, pos) &&
3885 (x < 0 || x > gdk_window_get_width (priv->text_area)))
3887 /* Hide the handle if it's not being manipulated
3888 * and fell outside of the visible text area.
3890 _gtk_text_handle_set_visible (priv->text_handle, pos, FALSE);
3896 rect.x = CLAMP (x, 0, gdk_window_get_width (priv->text_area));
3899 rect.height = height;
3901 _gtk_text_handle_set_visible (priv->text_handle, pos, TRUE);
3902 _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
3907 gtk_entry_get_selection_bound_location (GtkEntry *entry)
3909 GtkEntryPrivate *priv = entry->priv;
3910 PangoLayout *layout;
3916 layout = gtk_entry_ensure_layout (entry, FALSE);
3917 text = pango_layout_get_text (layout);
3918 index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text;
3919 pango_layout_index_to_pos (layout, index, &pos);
3921 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3922 x = (pos.x + pos.width) / PANGO_SCALE;
3924 x = pos.x / PANGO_SCALE;
3930 gtk_entry_update_handles (GtkEntry *entry,
3931 GtkTextHandleMode mode)
3933 GtkEntryPrivate *priv = entry->priv;
3934 gint strong_x, height;
3937 _gtk_text_handle_set_mode (priv->text_handle, mode);
3939 /* Wait for recomputation before repositioning */
3940 if (priv->recompute_idle != 0)
3943 height = gdk_window_get_height (priv->text_area);
3945 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
3946 cursor = strong_x - priv->scroll_offset;
3948 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
3952 bound = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
3954 if (priv->selection_bound > priv->current_pos)
3965 /* Update start selection bound */
3966 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_START,
3968 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_END,
3972 gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_CURSOR,
3977 gtk_entry_button_press (GtkWidget *widget,
3978 GdkEventButton *event)
3980 GtkEntry *entry = GTK_ENTRY (widget);
3981 GtkEditable *editable = GTK_EDITABLE (widget);
3982 GtkEntryPrivate *priv = entry->priv;
3983 EntryIconInfo *icon_info = NULL;
3985 gint sel_start, sel_end;
3988 for (i = 0; i < MAX_ICONS; i++)
3990 icon_info = priv->icons[i];
3992 if (!icon_info || icon_info->insensitive)
3995 if (event->window == icon_info->window)
3997 if (should_prelight (entry, i))
3999 icon_info->prelight = FALSE;
4000 gtk_widget_queue_draw (widget);
4003 priv->start_x = event->x;
4004 priv->start_y = event->y;
4005 icon_info->pressed = TRUE;
4007 if (!icon_info->nonactivatable)
4008 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
4014 if (event->window != priv->text_area ||
4015 (priv->button && event->button != priv->button))
4018 gtk_entry_reset_blink_time (entry);
4020 priv->button = event->button;
4021 priv->device = gdk_event_get_device ((GdkEvent *) event);
4023 if (!gtk_widget_has_focus (widget))
4025 priv->in_click = TRUE;
4026 gtk_widget_grab_focus (widget);
4027 priv->in_click = FALSE;
4030 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4032 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
4034 gtk_entry_do_popup (entry, event);
4035 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
4036 priv->device = NULL;
4040 else if (event->button == GDK_BUTTON_PRIMARY)
4042 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
4043 gboolean is_touchscreen;
4046 source = gdk_event_get_source_device ((GdkEvent *) event);
4047 is_touchscreen = gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN;
4049 priv->select_words = FALSE;
4050 priv->select_lines = FALSE;
4053 gtk_widget_get_modifier_mask (widget,
4054 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
4056 gtk_entry_reset_im_context (entry);
4058 if (!have_selection) /* select from the current position to the clicked position */
4059 sel_start = sel_end = priv->current_pos;
4061 if (tmp_pos > sel_start && tmp_pos < sel_end)
4063 /* Truncate current selection, but keep it as big as possible */
4064 if (tmp_pos - sel_start > sel_end - tmp_pos)
4065 gtk_entry_set_positions (entry, sel_start, tmp_pos);
4067 gtk_entry_set_positions (entry, tmp_pos, sel_end);
4071 gboolean extend_to_left;
4074 /* Figure out what click selects and extend current selection */
4075 switch (event->type)
4077 case GDK_BUTTON_PRESS:
4078 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
4081 case GDK_2BUTTON_PRESS:
4082 priv->select_words = TRUE;
4083 gtk_entry_select_word (entry);
4086 case GDK_3BUTTON_PRESS:
4087 priv->select_lines = TRUE;
4088 gtk_entry_select_line (entry);
4095 start = MIN (priv->current_pos, priv->selection_bound);
4096 start = MIN (sel_start, start);
4098 end = MAX (priv->current_pos, priv->selection_bound);
4099 end = MAX (sel_end, end);
4101 if (tmp_pos == sel_start || tmp_pos == sel_end)
4102 extend_to_left = (tmp_pos == start);
4104 extend_to_left = (end == sel_end);
4107 gtk_entry_set_positions (entry, start, end);
4109 gtk_entry_set_positions (entry, end, start);
4112 else /* no shift key */
4113 switch (event->type)
4115 case GDK_BUTTON_PRESS:
4116 if (in_selection (entry, event->x + priv->scroll_offset))
4118 /* Click inside the selection - we'll either start a drag, or
4119 * clear the selection
4121 priv->in_drag = TRUE;
4122 priv->drag_start_x = event->x + priv->scroll_offset;
4123 priv->drag_start_y = event->y;
4127 gtk_editable_set_position (editable, tmp_pos);
4130 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4134 case GDK_2BUTTON_PRESS:
4135 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4136 * receiving a GDK_2BUTTON_PRESS so we need to reset
4137 * priv->in_drag which may have been set above
4139 priv->in_drag = FALSE;
4140 priv->select_words = TRUE;
4141 gtk_entry_select_word (entry);
4144 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4147 case GDK_3BUTTON_PRESS:
4148 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4149 * receiving a GDK_3BUTTON_PRESS so we need to reset
4150 * priv->in_drag which may have been set above
4152 priv->in_drag = FALSE;
4153 priv->select_lines = TRUE;
4154 gtk_entry_select_line (entry);
4156 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
4165 else if (event->type == GDK_BUTTON_PRESS &&
4166 event->button == GDK_BUTTON_MIDDLE &&
4167 get_middle_click_paste (entry))
4171 priv->insert_pos = tmp_pos;
4172 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
4177 gtk_widget_error_bell (widget);
4185 gtk_entry_button_release (GtkWidget *widget,
4186 GdkEventButton *event)
4188 GtkEntry *entry = GTK_ENTRY (widget);
4189 GtkEntryPrivate *priv = entry->priv;
4190 EntryIconInfo *icon_info = NULL;
4193 for (i = 0; i < MAX_ICONS; i++)
4195 icon_info = priv->icons[i];
4197 if (!icon_info || icon_info->insensitive)
4200 if (event->window == icon_info->window)
4202 icon_info->pressed = FALSE;
4204 if (should_prelight (entry, i) &&
4205 event->x >= 0 && event->y >= 0 &&
4206 event->x < gdk_window_get_width (icon_info->window) &&
4207 event->y < gdk_window_get_height (icon_info->window))
4209 icon_info->prelight = TRUE;
4210 gtk_widget_queue_draw (widget);
4213 if (!icon_info->nonactivatable)
4214 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4220 if (event->window != priv->text_area || priv->button != event->button)
4225 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4228 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4230 source = gdk_event_get_source_device ((GdkEvent *) event);
4232 if (gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN)
4233 gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
4239 priv->device = NULL;
4241 gtk_entry_update_primary_selection (entry);
4247 _gtk_entry_get_selected_text (GtkEntry *entry)
4249 GtkEditable *editable = GTK_EDITABLE (entry);
4250 gint start_text, end_text;
4253 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4254 text = gtk_editable_get_chars (editable, start_text, end_text);
4260 gtk_entry_motion_notify (GtkWidget *widget,
4261 GdkEventMotion *event)
4263 GtkEntry *entry = GTK_ENTRY (widget);
4264 GtkEntryPrivate *priv = entry->priv;
4265 EntryIconInfo *icon_info = NULL;
4269 for (i = 0; i < MAX_ICONS; i++)
4271 icon_info = priv->icons[i];
4273 if (!icon_info || icon_info->insensitive)
4276 if (event->window == icon_info->window)
4278 if (icon_info->pressed &&
4279 icon_info->target_list != NULL &&
4280 gtk_drag_check_threshold (widget,
4286 icon_info->in_drag = TRUE;
4287 icon_info->pressed = FALSE;
4288 gtk_drag_begin (widget,
4289 icon_info->target_list,
4299 if (priv->mouse_cursor_obscured)
4303 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4304 gdk_window_set_cursor (priv->text_area, cursor);
4305 g_object_unref (cursor);
4306 priv->mouse_cursor_obscured = FALSE;
4309 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4312 if (priv->select_lines)
4315 gdk_event_request_motions (event);
4319 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4320 gtk_drag_check_threshold (widget,
4321 priv->drag_start_x, priv->drag_start_y,
4322 event->x + priv->scroll_offset, event->y))
4324 GdkDragContext *context;
4325 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4326 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4328 cairo_surface_t *surface;
4330 gtk_target_list_add_text_targets (target_list, 0);
4332 text = _gtk_entry_get_selected_text (entry);
4333 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4335 context = gtk_drag_begin (widget, target_list, actions,
4336 priv->button, (GdkEvent *)event);
4339 gtk_drag_set_icon_surface (context, surface);
4341 gtk_drag_set_icon_default (context);
4344 cairo_surface_destroy (surface);
4347 priv->in_drag = FALSE;
4349 priv->device = NULL;
4351 gtk_target_list_unref (target_list);
4356 GdkInputSource input_source;
4360 length = gtk_entry_buffer_get_length (get_buffer (entry));
4364 else if (event->y >= gdk_window_get_height (priv->text_area))
4367 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4369 source = gdk_event_get_source_device ((GdkEvent *) event);
4370 input_source = gdk_device_get_source (source);
4372 if (priv->select_words)
4375 gint old_min, old_max;
4378 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4379 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4381 pos = priv->current_pos;
4382 bound = priv->selection_bound;
4384 old_min = MIN(priv->current_pos, priv->selection_bound);
4385 old_max = MAX(priv->current_pos, priv->selection_bound);
4392 else if (old_max < max)
4397 else if (pos == old_min)
4399 if (priv->current_pos != min)
4404 if (priv->current_pos != max)
4408 gtk_entry_set_positions (entry, pos, bound);
4411 gtk_entry_set_positions (entry, tmp_pos, -1);
4413 /* Update touch handles' position */
4414 if (input_source == GDK_SOURCE_TOUCHSCREEN)
4415 gtk_entry_update_handles (entry,
4416 (priv->current_pos == priv->selection_bound) ?
4417 GTK_TEXT_HANDLE_MODE_CURSOR :
4418 GTK_TEXT_HANDLE_MODE_SELECTION);
4425 set_invisible_cursor (GdkWindow *window)
4427 GdkDisplay *display;
4430 display = gdk_window_get_display (window);
4431 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4433 gdk_window_set_cursor (window, cursor);
4435 g_object_unref (cursor);
4439 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4441 GtkEntryPrivate *priv = entry->priv;
4443 if (priv->mouse_cursor_obscured)
4446 set_invisible_cursor (priv->text_area);
4448 priv->mouse_cursor_obscured = TRUE;
4452 gtk_entry_key_press (GtkWidget *widget,
4455 GtkEntry *entry = GTK_ENTRY (widget);
4456 GtkEntryPrivate *priv = entry->priv;
4458 gtk_entry_reset_blink_time (entry);
4459 gtk_entry_pend_cursor_blink (entry);
4460 _gtk_text_handle_set_mode (priv->text_handle,
4461 GTK_TEXT_HANDLE_MODE_NONE);
4465 if (gtk_im_context_filter_keypress (priv->im_context, event))
4467 gtk_entry_obscure_mouse_cursor (entry);
4468 priv->need_im_reset = TRUE;
4473 if (event->keyval == GDK_KEY_Return ||
4474 event->keyval == GDK_KEY_KP_Enter ||
4475 event->keyval == GDK_KEY_ISO_Enter ||
4476 event->keyval == GDK_KEY_Escape)
4477 gtk_entry_reset_im_context (entry);
4479 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4480 /* Activate key bindings
4484 if (!priv->editable && event->length)
4485 gtk_widget_error_bell (widget);
4491 gtk_entry_key_release (GtkWidget *widget,
4494 GtkEntry *entry = GTK_ENTRY (widget);
4495 GtkEntryPrivate *priv = entry->priv;
4499 if (gtk_im_context_filter_keypress (priv->im_context, event))
4501 priv->need_im_reset = TRUE;
4506 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4510 gtk_entry_focus_in (GtkWidget *widget,
4511 GdkEventFocus *event)
4513 GtkEntry *entry = GTK_ENTRY (widget);
4514 GtkEntryPrivate *priv = entry->priv;
4517 gtk_widget_queue_draw (widget);
4519 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4523 priv->need_im_reset = TRUE;
4524 gtk_im_context_focus_in (priv->im_context);
4525 keymap_state_changed (keymap, entry);
4526 g_signal_connect (keymap, "state-changed",
4527 G_CALLBACK (keymap_state_changed), entry);
4530 g_signal_connect (keymap, "direction-changed",
4531 G_CALLBACK (keymap_direction_changed), entry);
4533 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4534 priv->placeholder_text != NULL)
4536 gtk_entry_recompute (entry);
4540 gtk_entry_reset_blink_time (entry);
4541 gtk_entry_check_cursor_blink (entry);
4548 gtk_entry_focus_out (GtkWidget *widget,
4549 GdkEventFocus *event)
4551 GtkEntry *entry = GTK_ENTRY (widget);
4552 GtkEntryPrivate *priv = entry->priv;
4553 GtkEntryCompletion *completion;
4556 _gtk_text_handle_set_mode (priv->text_handle,
4557 GTK_TEXT_HANDLE_MODE_NONE);
4559 gtk_widget_queue_draw (widget);
4561 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4565 priv->need_im_reset = TRUE;
4566 gtk_im_context_focus_out (priv->im_context);
4567 remove_capslock_feedback (entry);
4570 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4571 priv->placeholder_text != NULL)
4573 gtk_entry_recompute (entry);
4577 gtk_entry_check_cursor_blink (entry);
4580 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4581 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4583 completion = gtk_entry_get_completion (entry);
4585 _gtk_entry_completion_popdown (completion);
4591 gtk_entry_grab_focus (GtkWidget *widget)
4593 GtkEntry *entry = GTK_ENTRY (widget);
4594 GtkEntryPrivate *priv = entry->priv;
4595 gboolean select_on_focus;
4597 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4599 if (priv->editable && !priv->in_click)
4601 g_object_get (gtk_widget_get_settings (widget),
4602 "gtk-entry-select-on-focus",
4606 if (select_on_focus)
4607 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4612 gtk_entry_direction_changed (GtkWidget *widget,
4613 GtkTextDirection previous_dir)
4615 GtkEntry *entry = GTK_ENTRY (widget);
4617 gtk_entry_recompute (entry);
4619 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4623 gtk_entry_state_flags_changed (GtkWidget *widget,
4624 GtkStateFlags previous_state)
4626 GtkEntry *entry = GTK_ENTRY (widget);
4627 GtkEntryPrivate *priv = entry->priv;
4630 if (gtk_widget_get_realized (widget))
4632 if (gtk_widget_is_sensitive (widget))
4633 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4637 gdk_window_set_cursor (priv->text_area, cursor);
4640 g_object_unref (cursor);
4642 priv->mouse_cursor_obscured = FALSE;
4644 update_cursors (widget);
4647 if (!gtk_widget_is_sensitive (widget))
4649 /* Clear any selection */
4650 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4653 gtk_entry_update_cached_style_values (entry);
4657 gtk_entry_screen_changed (GtkWidget *widget,
4658 GdkScreen *old_screen)
4660 gtk_entry_recompute (GTK_ENTRY (widget));
4663 /* GtkEditable method implementations
4666 gtk_entry_insert_text (GtkEditable *editable,
4667 const gchar *new_text,
4668 gint new_text_length,
4671 g_object_ref (editable);
4674 * The incoming text may a password or other secret. We make sure
4675 * not to copy it into temporary buffers.
4678 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4680 g_object_unref (editable);
4684 gtk_entry_delete_text (GtkEditable *editable,
4688 g_object_ref (editable);
4690 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4692 g_object_unref (editable);
4696 gtk_entry_get_chars (GtkEditable *editable,
4700 GtkEntry *entry = GTK_ENTRY (editable);
4703 gint start_index, end_index;
4705 text = gtk_entry_buffer_get_text (get_buffer (entry));
4706 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4709 end_pos = text_length;
4711 start_pos = MIN (text_length, start_pos);
4712 end_pos = MIN (text_length, end_pos);
4714 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4715 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4717 return g_strndup (text + start_index, end_index - start_index);
4721 gtk_entry_real_set_position (GtkEditable *editable,
4724 GtkEntry *entry = GTK_ENTRY (editable);
4725 GtkEntryPrivate *priv = entry->priv;
4729 length = gtk_entry_buffer_get_length (get_buffer (entry));
4730 if (position < 0 || position > length)
4733 if (position != priv->current_pos ||
4734 position != priv->selection_bound)
4736 gtk_entry_reset_im_context (entry);
4737 gtk_entry_set_positions (entry, position, position);
4742 gtk_entry_get_position (GtkEditable *editable)
4744 GtkEntry *entry = GTK_ENTRY (editable);
4745 GtkEntryPrivate *priv = entry->priv;
4747 return priv->current_pos;
4751 gtk_entry_set_selection_bounds (GtkEditable *editable,
4755 GtkEntry *entry = GTK_ENTRY (editable);
4758 length = gtk_entry_buffer_get_length (get_buffer (entry));
4764 gtk_entry_reset_im_context (entry);
4766 gtk_entry_set_positions (entry,
4768 MIN (start, length));
4770 gtk_entry_update_primary_selection (entry);
4774 gtk_entry_get_selection_bounds (GtkEditable *editable,
4778 GtkEntry *entry = GTK_ENTRY (editable);
4779 GtkEntryPrivate *priv = entry->priv;
4781 *start = priv->selection_bound;
4782 *end = priv->current_pos;
4784 return (priv->selection_bound != priv->current_pos);
4788 icon_theme_changed (GtkEntry *entry)
4790 GtkEntryPrivate *priv = entry->priv;
4793 for (i = 0; i < MAX_ICONS; i++)
4795 EntryIconInfo *icon_info = priv->icons[i];
4796 if (icon_info != NULL)
4797 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4800 gtk_widget_queue_draw (GTK_WIDGET (entry));
4804 gtk_entry_update_cached_style_values (GtkEntry *entry)
4806 GtkEntryPrivate *priv = entry->priv;
4808 gboolean interior_focus;
4810 gtk_widget_style_get (GTK_WIDGET (entry),
4811 "focus-line-width", &focus_width,
4812 "interior-focus", &interior_focus,
4814 priv->focus_width = focus_width;
4815 priv->interior_focus = interior_focus;
4817 if (!priv->invisible_char_set)
4819 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4821 if (priv->invisible_char != ch)
4823 priv->invisible_char = ch;
4824 g_object_notify (G_OBJECT (entry), "invisible-char");
4830 gtk_entry_style_updated (GtkWidget *widget)
4832 GtkEntry *entry = GTK_ENTRY (widget);
4834 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4836 gtk_entry_update_cached_style_values (entry);
4838 gtk_entry_recompute (entry);
4840 icon_theme_changed (entry);
4843 /* GtkCellEditable method implementations
4846 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4848 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4849 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4853 gtk_cell_editable_key_press_event (GtkEntry *entry,
4854 GdkEventKey *key_event,
4857 GtkEntryPrivate *priv = entry->priv;
4859 if (key_event->keyval == GDK_KEY_Escape)
4861 priv->editing_canceled = TRUE;
4862 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4863 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4868 /* override focus */
4869 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4871 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4872 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4881 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4884 GtkEntry *entry = GTK_ENTRY (cell_editable);
4885 GtkEntryPrivate *priv = entry->priv;
4887 priv->is_cell_renderer = TRUE;
4889 g_signal_connect (cell_editable, "activate",
4890 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4891 g_signal_connect (cell_editable, "key-press-event",
4892 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4896 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4898 if (password_hint->source_id)
4899 g_source_remove (password_hint->source_id);
4901 g_slice_free (GtkEntryPasswordHint, password_hint);
4906 gtk_entry_remove_password_hint (gpointer data)
4908 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4909 password_hint->position = -1;
4911 /* Force the string to be redrawn, but now without a visible character */
4912 gtk_entry_recompute (GTK_ENTRY (data));
4916 /* Default signal handlers
4919 gtk_entry_real_insert_text (GtkEditable *editable,
4920 const gchar *new_text,
4921 gint new_text_length,
4927 n_chars = g_utf8_strlen (new_text, new_text_length);
4930 * The actual insertion into the buffer. This will end up firing the
4931 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4932 * buffer_notify_text(), buffer_notify_length()
4934 begin_change (GTK_ENTRY (editable));
4936 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4938 end_change (GTK_ENTRY (editable));
4940 if (n_inserted != n_chars)
4941 gtk_widget_error_bell (GTK_WIDGET (editable));
4943 *position += n_inserted;
4947 gtk_entry_real_delete_text (GtkEditable *editable,
4952 * The actual deletion from the buffer. This will end up firing the
4953 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4954 * buffer_notify_text(), buffer_notify_length()
4957 begin_change (GTK_ENTRY (editable));
4959 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4961 end_change (GTK_ENTRY (editable));
4964 /* GtkEntryBuffer signal handlers
4967 buffer_inserted_text (GtkEntryBuffer *buffer,
4973 GtkEntryPrivate *priv = entry->priv;
4974 guint password_hint_timeout;
4976 gint selection_bound;
4978 current_pos = priv->current_pos;
4979 if (current_pos > position)
4980 current_pos += n_chars;
4982 selection_bound = priv->selection_bound;
4983 if (selection_bound > position)
4984 selection_bound += n_chars;
4986 gtk_entry_set_positions (entry, current_pos, selection_bound);
4988 /* Calculate the password hint if it needs to be displayed. */
4989 if (n_chars == 1 && !priv->visible)
4991 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4992 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4995 if (password_hint_timeout > 0)
4997 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4998 quark_password_hint);
5001 password_hint = g_slice_new0 (GtkEntryPasswordHint);
5002 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
5003 (GDestroyNotify)gtk_entry_password_hint_free);
5006 password_hint->position = position;
5007 if (password_hint->source_id)
5008 g_source_remove (password_hint->source_id);
5009 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
5010 (GSourceFunc)gtk_entry_remove_password_hint, entry);
5016 buffer_deleted_text (GtkEntryBuffer *buffer,
5021 GtkEntryPrivate *priv = entry->priv;
5022 guint end_pos = position + n_chars;
5023 gint selection_bound;
5026 current_pos = priv->current_pos;
5027 if (current_pos > position)
5028 current_pos -= MIN (current_pos, end_pos) - position;
5030 selection_bound = priv->selection_bound;
5031 if (selection_bound > position)
5032 selection_bound -= MIN (selection_bound, end_pos) - position;
5034 gtk_entry_set_positions (entry, current_pos, selection_bound);
5036 /* We might have deleted the selection */
5037 gtk_entry_update_primary_selection (entry);
5039 /* Disable the password hint if one exists. */
5042 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
5043 quark_password_hint);
5046 if (password_hint->source_id)
5047 g_source_remove (password_hint->source_id);
5048 password_hint->source_id = 0;
5049 password_hint->position = -1;
5055 buffer_notify_text (GtkEntryBuffer *buffer,
5059 gtk_entry_recompute (entry);
5060 emit_changed (entry);
5061 g_object_notify (G_OBJECT (entry), "text");
5065 buffer_notify_length (GtkEntryBuffer *buffer,
5069 g_object_notify (G_OBJECT (entry), "text-length");
5073 buffer_notify_max_length (GtkEntryBuffer *buffer,
5077 g_object_notify (G_OBJECT (entry), "max-length");
5081 buffer_connect_signals (GtkEntry *entry)
5083 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
5084 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
5085 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
5086 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
5087 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
5091 buffer_disconnect_signals (GtkEntry *entry)
5093 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
5094 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
5095 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
5096 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
5097 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
5100 /* Compute the X position for an offset that corresponds to the "more important
5101 * cursor position for that offset. We use this when trying to guess to which
5102 * end of the selection we should go to when the user hits the left or
5106 get_better_cursor_x (GtkEntry *entry,
5109 GtkEntryPrivate *priv = entry->priv;
5110 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5111 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5112 gboolean split_cursor;
5114 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5115 const gchar *text = pango_layout_get_text (layout);
5116 gint index = g_utf8_offset_to_pointer (text, offset) - text;
5118 PangoRectangle strong_pos, weak_pos;
5120 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5121 "gtk-split-cursor", &split_cursor,
5124 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5127 return strong_pos.x / PANGO_SCALE;
5129 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
5133 gtk_entry_move_cursor (GtkEntry *entry,
5134 GtkMovementStep step,
5136 gboolean extend_selection)
5138 GtkEntryPrivate *priv = entry->priv;
5139 gint new_pos = priv->current_pos;
5141 gtk_entry_reset_im_context (entry);
5143 if (priv->current_pos != priv->selection_bound && !extend_selection)
5145 /* If we have a current selection and aren't extending it, move to the
5146 * start/or end of the selection as appropriate
5150 case GTK_MOVEMENT_VISUAL_POSITIONS:
5152 gint current_x = get_better_cursor_x (entry, priv->current_pos);
5153 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
5156 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
5158 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
5161 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5162 case GTK_MOVEMENT_WORDS:
5164 new_pos = MIN (priv->current_pos, priv->selection_bound);
5166 new_pos = MAX (priv->current_pos, priv->selection_bound);
5168 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5169 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5170 case GTK_MOVEMENT_BUFFER_ENDS:
5171 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5173 case GTK_MOVEMENT_DISPLAY_LINES:
5174 case GTK_MOVEMENT_PARAGRAPHS:
5175 case GTK_MOVEMENT_PAGES:
5176 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5184 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5185 new_pos = gtk_entry_move_logically (entry, new_pos, count);
5187 case GTK_MOVEMENT_VISUAL_POSITIONS:
5188 new_pos = gtk_entry_move_visually (entry, new_pos, count);
5189 if (priv->current_pos == new_pos)
5191 if (!extend_selection)
5193 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
5195 GTK_DIR_RIGHT : GTK_DIR_LEFT))
5197 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
5200 gtk_widget_child_focus (toplevel,
5202 GTK_DIR_RIGHT : GTK_DIR_LEFT);
5207 gtk_widget_error_bell (GTK_WIDGET (entry));
5211 case GTK_MOVEMENT_WORDS:
5214 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5219 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5222 if (priv->current_pos == new_pos)
5223 gtk_widget_error_bell (GTK_WIDGET (entry));
5225 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5226 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5227 case GTK_MOVEMENT_BUFFER_ENDS:
5228 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5229 if (priv->current_pos == new_pos)
5230 gtk_widget_error_bell (GTK_WIDGET (entry));
5232 case GTK_MOVEMENT_DISPLAY_LINES:
5233 case GTK_MOVEMENT_PARAGRAPHS:
5234 case GTK_MOVEMENT_PAGES:
5235 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5240 if (extend_selection)
5241 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5243 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5245 gtk_entry_pend_cursor_blink (entry);
5249 gtk_entry_insert_at_cursor (GtkEntry *entry,
5252 GtkEntryPrivate *priv = entry->priv;
5253 GtkEditable *editable = GTK_EDITABLE (entry);
5254 gint pos = priv->current_pos;
5258 gtk_entry_reset_im_context (entry);
5259 gtk_editable_insert_text (editable, str, -1, &pos);
5260 gtk_editable_set_position (editable, pos);
5265 gtk_entry_delete_from_cursor (GtkEntry *entry,
5269 GtkEntryPrivate *priv = entry->priv;
5270 GtkEditable *editable = GTK_EDITABLE (entry);
5271 gint start_pos = priv->current_pos;
5272 gint end_pos = priv->current_pos;
5273 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5275 gtk_entry_reset_im_context (entry);
5277 if (!priv->editable)
5279 gtk_widget_error_bell (GTK_WIDGET (entry));
5283 if (priv->selection_bound != priv->current_pos)
5285 gtk_editable_delete_selection (editable);
5291 case GTK_DELETE_CHARS:
5292 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5293 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5295 case GTK_DELETE_WORDS:
5298 /* Move to end of current word, or if not on a word, end of previous word */
5299 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5300 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5304 /* Move to beginning of current word, or if not on a word, begining of next word */
5305 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5306 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5310 case GTK_DELETE_WORD_ENDS:
5313 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5318 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5321 gtk_editable_delete_text (editable, start_pos, end_pos);
5323 case GTK_DELETE_DISPLAY_LINE_ENDS:
5324 case GTK_DELETE_PARAGRAPH_ENDS:
5326 gtk_editable_delete_text (editable, 0, priv->current_pos);
5328 gtk_editable_delete_text (editable, priv->current_pos, -1);
5330 case GTK_DELETE_DISPLAY_LINES:
5331 case GTK_DELETE_PARAGRAPHS:
5332 gtk_editable_delete_text (editable, 0, -1);
5334 case GTK_DELETE_WHITESPACE:
5335 gtk_entry_delete_whitespace (entry);
5339 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5340 gtk_widget_error_bell (GTK_WIDGET (entry));
5342 gtk_entry_pend_cursor_blink (entry);
5346 gtk_entry_backspace (GtkEntry *entry)
5348 GtkEntryPrivate *priv = entry->priv;
5349 GtkEditable *editable = GTK_EDITABLE (entry);
5352 gtk_entry_reset_im_context (entry);
5354 if (!priv->editable)
5356 gtk_widget_error_bell (GTK_WIDGET (entry));
5360 if (priv->selection_bound != priv->current_pos)
5362 gtk_editable_delete_selection (editable);
5366 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5368 if (prev_pos < priv->current_pos)
5370 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5371 PangoLogAttr *log_attrs;
5374 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5376 /* Deleting parts of characters */
5377 if (log_attrs[priv->current_pos].backspace_deletes_character)
5379 gchar *cluster_text;
5380 gchar *normalized_text;
5383 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5385 normalized_text = g_utf8_normalize (cluster_text,
5386 strlen (cluster_text),
5388 len = g_utf8_strlen (normalized_text, -1);
5390 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5393 gint pos = priv->current_pos;
5395 gtk_editable_insert_text (editable, normalized_text,
5396 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5398 gtk_editable_set_position (editable, pos);
5401 g_free (normalized_text);
5402 g_free (cluster_text);
5406 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5413 gtk_widget_error_bell (GTK_WIDGET (entry));
5416 gtk_entry_pend_cursor_blink (entry);
5420 gtk_entry_copy_clipboard (GtkEntry *entry)
5422 GtkEntryPrivate *priv = entry->priv;
5423 GtkEditable *editable = GTK_EDITABLE (entry);
5427 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5431 gtk_widget_error_bell (GTK_WIDGET (entry));
5435 str = _gtk_entry_get_display_text (entry, start, end);
5436 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5437 GDK_SELECTION_CLIPBOARD),
5444 gtk_entry_cut_clipboard (GtkEntry *entry)
5446 GtkEntryPrivate *priv = entry->priv;
5447 GtkEditable *editable = GTK_EDITABLE (entry);
5452 gtk_widget_error_bell (GTK_WIDGET (entry));
5456 gtk_entry_copy_clipboard (entry);
5460 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5461 gtk_editable_delete_text (editable, start, end);
5465 gtk_widget_error_bell (GTK_WIDGET (entry));
5470 gtk_entry_paste_clipboard (GtkEntry *entry)
5472 GtkEntryPrivate *priv = entry->priv;
5475 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5477 gtk_widget_error_bell (GTK_WIDGET (entry));
5481 gtk_entry_delete_cb (GtkEntry *entry)
5483 GtkEntryPrivate *priv = entry->priv;
5484 GtkEditable *editable = GTK_EDITABLE (entry);
5489 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5490 gtk_editable_delete_text (editable, start, end);
5495 gtk_entry_toggle_overwrite (GtkEntry *entry)
5497 GtkEntryPrivate *priv = entry->priv;
5499 priv->overwrite_mode = !priv->overwrite_mode;
5500 gtk_entry_pend_cursor_blink (entry);
5501 gtk_widget_queue_draw (GTK_WIDGET (entry));
5505 gtk_entry_select_all (GtkEntry *entry)
5507 gtk_entry_select_line (entry);
5511 gtk_entry_real_activate (GtkEntry *entry)
5513 GtkEntryPrivate *priv = entry->priv;
5515 GtkWidget *default_widget, *focus_widget;
5516 GtkWidget *toplevel;
5519 widget = GTK_WIDGET (entry);
5521 if (priv->activates_default)
5523 toplevel = gtk_widget_get_toplevel (widget);
5524 if (GTK_IS_WINDOW (toplevel))
5526 window = GTK_WINDOW (toplevel);
5530 default_widget = gtk_window_get_default_widget (window);
5531 focus_widget = gtk_window_get_focus (window);
5532 if (widget != default_widget &&
5533 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5534 gtk_window_activate_default (window);
5541 keymap_direction_changed (GdkKeymap *keymap,
5544 gtk_entry_recompute (entry);
5547 /* IM Context Callbacks
5551 gtk_entry_commit_cb (GtkIMContext *context,
5555 GtkEntryPrivate *priv = entry->priv;
5558 gtk_entry_enter_text (entry, str);
5562 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5565 GtkEntryPrivate *priv = entry->priv;
5569 gchar *preedit_string;
5572 gtk_im_context_get_preedit_string (priv->im_context,
5573 &preedit_string, NULL,
5575 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5576 priv->preedit_length = strlen (preedit_string);
5577 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5578 priv->preedit_cursor = cursor_pos;
5579 g_free (preedit_string);
5581 gtk_entry_recompute (entry);
5586 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5589 GtkEntryPrivate *priv = entry->priv;
5592 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5593 text = _gtk_entry_get_display_text (entry, 0, -1);
5594 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5595 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5602 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5607 GtkEntryPrivate *priv = entry->priv;
5610 gtk_editable_delete_text (GTK_EDITABLE (entry),
5611 priv->current_pos + offset,
5612 priv->current_pos + offset + n_chars);
5617 /* Internal functions
5620 /* Used for im_commit_cb and inserting Unicode chars */
5622 gtk_entry_enter_text (GtkEntry *entry,
5625 GtkEntryPrivate *priv = entry->priv;
5626 GtkEditable *editable = GTK_EDITABLE (entry);
5628 gboolean old_need_im_reset;
5630 old_need_im_reset = priv->need_im_reset;
5631 priv->need_im_reset = FALSE;
5633 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5634 gtk_editable_delete_selection (editable);
5637 if (priv->overwrite_mode)
5638 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5641 tmp_pos = priv->current_pos;
5642 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5643 gtk_editable_set_position (editable, tmp_pos);
5645 priv->need_im_reset = old_need_im_reset;
5648 /* All changes to priv->current_pos and priv->selection_bound
5649 * should go through this function.
5652 gtk_entry_set_positions (GtkEntry *entry,
5654 gint selection_bound)
5656 GtkEntryPrivate *priv = entry->priv;
5657 gboolean changed = FALSE;
5659 g_object_freeze_notify (G_OBJECT (entry));
5661 if (current_pos != -1 &&
5662 priv->current_pos != current_pos)
5664 priv->current_pos = current_pos;
5667 g_object_notify (G_OBJECT (entry), "cursor-position");
5670 if (selection_bound != -1 &&
5671 priv->selection_bound != selection_bound)
5673 priv->selection_bound = selection_bound;
5676 g_object_notify (G_OBJECT (entry), "selection-bound");
5679 g_object_thaw_notify (G_OBJECT (entry));
5683 gtk_entry_move_adjustments (entry);
5684 gtk_entry_recompute (entry);
5689 gtk_entry_reset_layout (GtkEntry *entry)
5691 GtkEntryPrivate *priv = entry->priv;
5693 if (priv->cached_layout)
5695 g_object_unref (priv->cached_layout);
5696 priv->cached_layout = NULL;
5701 update_im_cursor_location (GtkEntry *entry)
5703 GtkEntryPrivate *priv = entry->priv;
5706 gint strong_xoffset;
5707 gint area_width, area_height;
5709 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5710 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5712 strong_xoffset = strong_x - priv->scroll_offset;
5713 if (strong_xoffset < 0)
5717 else if (strong_xoffset > area_width)
5719 strong_xoffset = area_width;
5721 area.x = strong_xoffset;
5724 area.height = area_height;
5726 gtk_im_context_set_cursor_location (priv->im_context, &area);
5730 recompute_idle_func (gpointer data)
5732 GtkEntry *entry = GTK_ENTRY (data);
5733 GtkEntryPrivate *priv = entry->priv;
5735 priv->recompute_idle = 0;
5737 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5739 GtkTextHandleMode handle_mode;
5741 gtk_entry_adjust_scroll (entry);
5742 gtk_widget_queue_draw (GTK_WIDGET (entry));
5744 update_im_cursor_location (entry);
5746 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
5748 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
5749 gtk_entry_update_handles (entry, handle_mode);
5756 gtk_entry_recompute (GtkEntry *entry)
5758 GtkEntryPrivate *priv = entry->priv;
5760 gtk_entry_reset_layout (entry);
5761 gtk_entry_check_cursor_blink (entry);
5763 if (!priv->recompute_idle)
5765 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5766 recompute_idle_func, entry, NULL);
5771 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5774 GtkWidget *widget = GTK_WIDGET (entry);
5775 GtkStyleContext *context;
5776 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5778 context = gtk_widget_get_style_context (widget);
5779 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5781 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5782 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5783 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5786 static inline gboolean
5787 show_placeholder_text (GtkEntry *entry)
5789 GtkEntryPrivate *priv = entry->priv;
5791 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5792 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5793 priv->placeholder_text != NULL)
5799 static PangoLayout *
5800 gtk_entry_create_layout (GtkEntry *entry,
5801 gboolean include_preedit)
5803 GtkEntryPrivate *priv = entry->priv;
5804 GtkWidget *widget = GTK_WIDGET (entry);
5805 PangoLayout *layout;
5806 PangoAttrList *tmp_attrs;
5807 gboolean placeholder_layout;
5809 gchar *preedit_string = NULL;
5810 gint preedit_length = 0;
5811 PangoAttrList *preedit_attrs = NULL;
5816 layout = gtk_widget_create_pango_layout (widget, NULL);
5817 pango_layout_set_single_paragraph_mode (layout, TRUE);
5819 tmp_attrs = priv->attrs ? pango_attr_list_ref (priv->attrs)
5820 : pango_attr_list_new ();
5822 placeholder_layout = show_placeholder_text (entry);
5823 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5824 n_bytes = strlen (display);
5826 if (!placeholder_layout && include_preedit)
5828 gtk_im_context_get_preedit_string (priv->im_context,
5829 &preedit_string, &preedit_attrs, NULL);
5830 preedit_length = priv->preedit_length;
5832 else if (placeholder_layout)
5835 PangoAttribute *attr;
5837 gtk_entry_get_placeholder_text_color (entry, &color);
5838 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5839 attr->start_index = 0;
5840 attr->end_index = G_MAXINT;
5841 pango_attr_list_insert (tmp_attrs, attr);
5846 GString *tmp_string = g_string_new (display);
5847 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5849 g_string_insert (tmp_string, cursor_index, preedit_string);
5850 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5851 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5852 cursor_index, preedit_length);
5853 g_string_free (tmp_string, TRUE);
5857 PangoDirection pango_dir;
5859 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5860 pango_dir = pango_find_base_dir (display, n_bytes);
5862 pango_dir = PANGO_DIRECTION_NEUTRAL;
5864 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5866 if (gtk_widget_has_focus (widget))
5868 GdkDisplay *display = gtk_widget_get_display (widget);
5869 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5870 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5871 pango_dir = PANGO_DIRECTION_RTL;
5873 pango_dir = PANGO_DIRECTION_LTR;
5877 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5878 pango_dir = PANGO_DIRECTION_RTL;
5880 pango_dir = PANGO_DIRECTION_LTR;
5884 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5887 priv->resolved_dir = pango_dir;
5889 pango_layout_set_text (layout, display, n_bytes);
5892 pango_layout_set_attributes (layout, tmp_attrs);
5894 g_free (preedit_string);
5898 pango_attr_list_unref (preedit_attrs);
5900 pango_attr_list_unref (tmp_attrs);
5905 static PangoLayout *
5906 gtk_entry_ensure_layout (GtkEntry *entry,
5907 gboolean include_preedit)
5909 GtkEntryPrivate *priv = entry->priv;
5911 if (priv->preedit_length > 0 &&
5912 !include_preedit != !priv->cache_includes_preedit)
5913 gtk_entry_reset_layout (entry);
5915 if (!priv->cached_layout)
5917 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5918 priv->cache_includes_preedit = include_preedit;
5921 return priv->cached_layout;
5925 get_layout_position (GtkEntry *entry,
5929 GtkEntryPrivate *priv = entry->priv;
5930 PangoLayout *layout;
5931 PangoRectangle logical_rect;
5932 gint area_width, area_height;
5934 PangoLayoutLine *line;
5936 layout = gtk_entry_ensure_layout (entry, TRUE);
5938 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5939 area_height = PANGO_SCALE * area_height;
5941 line = pango_layout_get_lines_readonly (layout)->data;
5942 pango_layout_line_get_extents (line, NULL, &logical_rect);
5944 /* Align primarily for locale's ascent/descent */
5945 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5946 priv->ascent + logical_rect.y);
5948 /* Now see if we need to adjust to fit in actual drawn string */
5949 if (logical_rect.height > area_height)
5950 y_pos = (area_height - logical_rect.height) / 2;
5953 else if (y_pos + logical_rect.height > area_height)
5954 y_pos = area_height - logical_rect.height;
5956 y_pos = y_pos / PANGO_SCALE;
5959 *x = - priv->scroll_offset;
5966 draw_text_with_color (GtkEntry *entry,
5968 GdkRGBA *default_color)
5970 GtkEntryPrivate *priv = entry->priv;
5971 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5974 gint start_pos, end_pos;
5976 widget = GTK_WIDGET (entry);
5980 get_layout_position (entry, &x, &y);
5982 cairo_move_to (cr, x, y);
5983 gdk_cairo_set_source_rgba (cr, default_color);
5984 pango_cairo_show_layout (cr, layout);
5986 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5990 PangoRectangle logical_rect;
5991 GdkRGBA selection_color, text_color;
5992 GtkStyleContext *context;
5993 GtkStateFlags state;
5995 context = gtk_widget_get_style_context (widget);
5996 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5997 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5999 state = gtk_widget_get_state_flags (widget);
6000 state |= GTK_STATE_FLAG_SELECTED;
6002 gtk_style_context_get_background_color (context, state, &selection_color);
6003 gtk_style_context_get_color (context, state, &text_color);
6005 for (i = 0; i < n_ranges; ++i)
6006 cairo_rectangle (cr,
6007 - priv->scroll_offset + ranges[2 * i],
6010 logical_rect.height);
6014 gdk_cairo_set_source_rgba (cr, &selection_color);
6017 cairo_move_to (cr, x, y);
6018 gdk_cairo_set_source_rgba (cr, &text_color);
6019 pango_cairo_show_layout (cr, layout);
6027 gtk_entry_draw_text (GtkEntry *entry,
6030 GtkEntryPrivate *priv = entry->priv;
6031 GtkWidget *widget = GTK_WIDGET (entry);
6032 GtkStateFlags state = 0;
6033 GdkRGBA text_color, bar_text_color;
6034 GtkStyleContext *context;
6036 gint progress_x, progress_y, progress_width, progress_height;
6037 gint clip_width, clip_height;
6039 /* Nothing to display at all */
6040 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
6043 state = gtk_widget_get_state_flags (widget);
6044 context = gtk_widget_get_style_context (widget);
6046 gtk_style_context_get_color (context, state, &text_color);
6048 /* Get foreground color for progressbars */
6049 gtk_entry_prepare_context_for_progress (entry, context);
6050 gtk_style_context_get_color (context, state, &bar_text_color);
6051 gtk_style_context_restore (context);
6053 get_progress_area (widget,
6054 &progress_x, &progress_y,
6055 &progress_width, &progress_height);
6059 clip_width = gdk_window_get_width (priv->text_area);
6060 clip_height = gdk_window_get_height (priv->text_area);
6061 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
6064 /* If the color is the same, or the progress area has a zero
6065 * size, then we only need to draw once. */
6066 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
6067 ((progress_width == 0) || (progress_height == 0)))
6069 draw_text_with_color (entry, cr, &text_color);
6073 int frame_x, frame_y, area_x, area_y;
6075 width = gdk_window_get_width (priv->text_area);
6076 height = gdk_window_get_height (priv->text_area);
6080 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
6081 cairo_rectangle (cr, 0, 0, width, height);
6083 /* progres area is frame-relative, we need it text-area window
6085 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
6086 gdk_window_get_position (priv->text_area, &area_x, &area_y);
6087 progress_x += frame_x - area_x;
6088 progress_y += frame_y - area_y;
6090 cairo_rectangle (cr, progress_x, progress_y,
6091 progress_width, progress_height);
6093 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
6095 draw_text_with_color (entry, cr, &text_color);
6100 cairo_rectangle (cr, progress_x, progress_y,
6101 progress_width, progress_height);
6104 draw_text_with_color (entry, cr, &bar_text_color);
6113 gtk_entry_draw_cursor (GtkEntry *entry,
6117 GtkEntryPrivate *priv = entry->priv;
6118 GtkWidget *widget = GTK_WIDGET (entry);
6119 GtkStyleContext *context;
6120 PangoRectangle cursor_rect;
6123 gboolean block_at_line_end;
6124 PangoLayout *layout;
6128 context = gtk_widget_get_style_context (widget);
6130 layout = gtk_entry_ensure_layout (entry, TRUE);
6131 text = pango_layout_get_text (layout);
6132 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6133 get_layout_position (entry, &x, &y);
6135 if (!priv->overwrite_mode)
6138 block = _gtk_text_util_get_block_cursor_location (layout,
6139 cursor_index, &cursor_rect, &block_at_line_end);
6143 gtk_render_insertion_cursor (context, cr,
6145 layout, cursor_index, priv->resolved_dir);
6147 else /* overwrite_mode */
6149 GdkRGBA cursor_color;
6154 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
6155 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
6156 rect.width = PANGO_PIXELS (cursor_rect.width);
6157 rect.height = PANGO_PIXELS (cursor_rect.height);
6159 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
6160 gdk_cairo_set_source_rgba (cr, &cursor_color);
6161 gdk_cairo_rectangle (cr, &rect);
6164 if (!block_at_line_end)
6166 GtkStateFlags state;
6169 state = gtk_widget_get_state_flags (widget);
6170 gtk_style_context_get_background_color (context, state, &color);
6172 gdk_cairo_rectangle (cr, &rect);
6174 cairo_move_to (cr, x, y);
6175 gdk_cairo_set_source_rgba (cr, &color);
6176 pango_cairo_show_layout (cr, layout);
6184 gtk_entry_handle_dragged (GtkTextHandle *handle,
6185 GtkTextHandlePosition pos,
6190 gint cursor_pos, selection_bound_pos, tmp_pos;
6191 GtkEntryPrivate *priv = entry->priv;
6192 GtkTextHandleMode mode;
6195 cursor_pos = priv->current_pos;
6196 selection_bound_pos = priv->selection_bound;
6197 mode = _gtk_text_handle_get_mode (handle);
6198 tmp_pos = gtk_entry_find_position (entry, x + priv->scroll_offset);
6200 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR ||
6201 cursor_pos >= selection_bound_pos)
6204 min = &selection_bound_pos;
6208 max = &selection_bound_pos;
6212 if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
6214 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6218 min_pos = MAX (*min + 1, 0);
6219 tmp_pos = MAX (tmp_pos, min_pos);
6226 if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
6231 *min = MIN (tmp_pos, max_pos);
6235 if (cursor_pos != priv->current_pos ||
6236 selection_bound_pos != priv->selection_bound)
6238 if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
6239 gtk_entry_set_positions (entry, cursor_pos, cursor_pos);
6241 gtk_entry_set_positions (entry, cursor_pos, selection_bound_pos);
6243 gtk_entry_update_handles (entry, mode);
6248 * gtk_entry_reset_im_context:
6249 * @entry: a #GtkEntry
6251 * Reset the input method context of the entry if needed.
6253 * This can be necessary in the case where modifying the buffer
6254 * would confuse on-going input method behavior.
6259 gtk_entry_reset_im_context (GtkEntry *entry)
6261 GtkEntryPrivate *priv = entry->priv;
6263 g_return_if_fail (GTK_IS_ENTRY (entry));
6265 if (priv->need_im_reset)
6267 priv->need_im_reset = FALSE;
6268 gtk_im_context_reset (priv->im_context);
6273 * gtk_entry_im_context_filter_keypress:
6274 * @entry: a #GtkEntry
6275 * @event: (type Gdk.EventKey): the key event
6277 * Allow the #GtkEntry input method to internally handle key press
6278 * and release events. If this function returns %TRUE, then no further
6279 * processing should be done for this key event. See
6280 * gtk_im_context_filter_keypress().
6282 * Note that you are expected to call this function from your handler
6283 * when overriding key event handling. This is needed in the case when
6284 * you need to insert your own key handling between the input method
6285 * and the default key event handling of the #GtkEntry.
6286 * See gtk_text_view_reset_im_context() for an example of use.
6288 * Return value: %TRUE if the input method handled the key event.
6293 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6296 GtkEntryPrivate *priv;
6298 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6302 return gtk_im_context_filter_keypress (priv->im_context, event);
6306 _gtk_entry_get_im_context (GtkEntry *entry)
6308 return entry->priv->im_context;
6312 gtk_entry_find_position (GtkEntry *entry,
6315 GtkEntryPrivate *priv = entry->priv;
6316 PangoLayout *layout;
6317 PangoLayoutLine *line;
6324 layout = gtk_entry_ensure_layout (entry, TRUE);
6325 text = pango_layout_get_text (layout);
6326 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6328 line = pango_layout_get_lines_readonly (layout)->data;
6329 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6331 if (index >= cursor_index && priv->preedit_length)
6333 if (index >= cursor_index + priv->preedit_length)
6334 index -= priv->preedit_length;
6337 index = cursor_index;
6342 pos = g_utf8_pointer_to_offset (text, text + index);
6349 gtk_entry_get_cursor_locations (GtkEntry *entry,
6354 GtkEntryPrivate *priv = entry->priv;
6355 DisplayMode mode = gtk_entry_get_display_mode (entry);
6357 /* Nothing to display at all, so no cursor is relevant */
6358 if (mode == DISPLAY_BLANK)
6368 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6369 const gchar *text = pango_layout_get_text (layout);
6370 PangoRectangle strong_pos, weak_pos;
6373 if (type == CURSOR_STANDARD)
6375 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6377 else /* type == CURSOR_DND */
6379 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6381 if (priv->dnd_position > priv->current_pos)
6383 if (mode == DISPLAY_NORMAL)
6384 index += priv->preedit_length;
6387 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6388 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6393 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6396 *strong_x = strong_pos.x / PANGO_SCALE;
6399 *weak_x = weak_pos.x / PANGO_SCALE;
6404 gtk_entry_get_is_selection_handle_dragged (GtkEntry *entry)
6406 GtkEntryPrivate *priv = entry->priv;
6407 GtkTextHandlePosition pos;
6409 if (_gtk_text_handle_get_mode (priv->text_handle) != GTK_TEXT_HANDLE_MODE_SELECTION)
6412 if (priv->current_pos >= priv->selection_bound)
6413 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
6415 pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
6417 return _gtk_text_handle_get_is_dragged (priv->text_handle, pos);
6421 gtk_entry_adjust_scroll (GtkEntry *entry)
6423 GtkEntryPrivate *priv = entry->priv;
6424 gint min_offset, max_offset;
6425 gint text_area_width, text_width;
6426 gint strong_x, weak_x;
6427 gint strong_xoffset, weak_xoffset;
6429 PangoLayout *layout;
6430 PangoLayoutLine *line;
6431 PangoRectangle logical_rect;
6432 GtkTextHandleMode handle_mode;
6434 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6437 text_area_width = gdk_window_get_width (priv->text_area);
6439 if (text_area_width < 0)
6440 text_area_width = 0;
6442 layout = gtk_entry_ensure_layout (entry, TRUE);
6443 line = pango_layout_get_lines_readonly (layout)->data;
6445 pango_layout_line_get_extents (line, NULL, &logical_rect);
6447 /* Display as much text as we can */
6449 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6450 xalign = priv->xalign;
6452 xalign = 1.0 - priv->xalign;
6454 text_width = PANGO_PIXELS(logical_rect.width);
6456 if (text_width > text_area_width)
6459 max_offset = text_width - text_area_width;
6463 min_offset = (text_width - text_area_width) * xalign;
6464 max_offset = min_offset;
6467 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6469 if (gtk_entry_get_is_selection_handle_dragged (entry))
6471 /* The text handle corresponding to the selection bound is
6472 * being dragged, ensure it stays onscreen even if we scroll
6473 * cursors away, this is so both handles can cause content
6476 strong_x = weak_x = gtk_entry_get_selection_bound_location (entry);
6480 /* And make sure cursors are on screen. Note that the cursor is
6481 * actually drawn one pixel into the INNER_BORDER space on
6482 * the right, when the scroll is at the utmost right. This
6483 * looks better to to me than confining the cursor inside the
6484 * border entirely, though it means that the cursor gets one
6485 * pixel closer to the edge of the widget on the right than
6486 * on the left. This might need changing if one changed
6487 * INNER_BORDER from 2 to 1, as one would do on a
6488 * small-screen-real-estate display.
6490 * We always make sure that the strong cursor is on screen, and
6491 * put the weak cursor on screen if possible.
6493 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6496 strong_xoffset = strong_x - priv->scroll_offset;
6498 if (strong_xoffset < 0)
6500 priv->scroll_offset += strong_xoffset;
6503 else if (strong_xoffset > text_area_width)
6505 priv->scroll_offset += strong_xoffset - text_area_width;
6506 strong_xoffset = text_area_width;
6509 weak_xoffset = weak_x - priv->scroll_offset;
6511 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6513 priv->scroll_offset += weak_xoffset;
6515 else if (weak_xoffset > text_area_width &&
6516 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6518 priv->scroll_offset += weak_xoffset - text_area_width;
6521 g_object_notify (G_OBJECT (entry), "scroll-offset");
6523 handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
6525 if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
6526 gtk_entry_update_handles (entry, handle_mode);
6530 gtk_entry_move_adjustments (GtkEntry *entry)
6532 GtkWidget *widget = GTK_WIDGET (entry);
6533 GtkAllocation allocation;
6534 GtkAdjustment *adjustment;
6535 PangoContext *context;
6536 PangoFontMetrics *metrics;
6537 GtkStyleContext *style_context;
6538 GtkStateFlags state;
6543 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6547 gtk_widget_get_allocation (widget, &allocation);
6549 /* Cursor/char position, layout offset, border width, and widget allocation */
6550 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6551 get_layout_position (entry, &layout_x, NULL);
6552 _gtk_entry_get_borders (entry, &borders);
6553 x += allocation.x + layout_x + borders.left;
6555 /* Approximate width of a char, so user can see what is ahead/behind */
6556 context = gtk_widget_get_pango_context (widget);
6557 style_context = gtk_widget_get_style_context (widget);
6558 state = gtk_widget_get_state_flags (widget);
6560 metrics = pango_context_get_metrics (context,
6561 gtk_style_context_get_font (style_context, state),
6562 pango_context_get_language (context));
6563 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6566 gtk_adjustment_clamp_page (adjustment,
6567 x - (char_width + 1), /* one char + one pixel before */
6568 x + (char_width + 2)); /* one char + cursor + one pixel after */
6572 gtk_entry_move_visually (GtkEntry *entry,
6576 GtkEntryPrivate *priv = entry->priv;
6578 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6581 text = pango_layout_get_text (layout);
6583 index = g_utf8_offset_to_pointer (text, start) - text;
6587 int new_index, new_trailing;
6588 gboolean split_cursor;
6591 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6592 "gtk-split-cursor", &split_cursor,
6599 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6600 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6602 strong = keymap_direction == priv->resolved_dir;
6607 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6612 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6618 else if (new_index != G_MAXINT)
6621 while (new_trailing--)
6622 index = g_utf8_next_char (text + index) - text;
6625 return g_utf8_pointer_to_offset (text, text + index);
6629 gtk_entry_move_logically (GtkEntry *entry,
6633 gint new_pos = start;
6636 length = gtk_entry_buffer_get_length (get_buffer (entry));
6638 /* Prevent any leak of information */
6639 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6641 new_pos = CLAMP (start + count, 0, length);
6645 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6646 PangoLogAttr *log_attrs;
6649 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6651 while (count > 0 && new_pos < length)
6655 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6659 while (count < 0 && new_pos > 0)
6663 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6675 gtk_entry_move_forward_word (GtkEntry *entry,
6677 gboolean allow_whitespace)
6679 gint new_pos = start;
6682 length = gtk_entry_buffer_get_length (get_buffer (entry));
6684 /* Prevent any leak of information */
6685 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6689 else if (new_pos < length)
6691 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6692 PangoLogAttr *log_attrs;
6695 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6697 /* Find the next word boundary */
6699 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6700 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6711 gtk_entry_move_backward_word (GtkEntry *entry,
6713 gboolean allow_whitespace)
6715 gint new_pos = start;
6717 /* Prevent any leak of information */
6718 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6724 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6725 PangoLogAttr *log_attrs;
6728 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6730 new_pos = start - 1;
6732 /* Find the previous word boundary */
6733 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6734 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6744 gtk_entry_delete_whitespace (GtkEntry *entry)
6746 GtkEntryPrivate *priv = entry->priv;
6747 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6748 PangoLogAttr *log_attrs;
6752 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6754 start = end = priv->current_pos;
6756 while (start > 0 && log_attrs[start-1].is_white)
6759 while (end < n_attrs && log_attrs[end].is_white)
6765 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6770 gtk_entry_select_word (GtkEntry *entry)
6772 GtkEntryPrivate *priv = entry->priv;
6773 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6774 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6776 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6780 gtk_entry_select_line (GtkEntry *entry)
6782 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6786 truncate_multiline (const gchar *text)
6791 text[length] && text[length] != '\n' && text[length] != '\r';
6798 paste_received (GtkClipboard *clipboard,
6802 GtkEntry *entry = GTK_ENTRY (data);
6803 GtkEditable *editable = GTK_EDITABLE (entry);
6804 GtkEntryPrivate *priv = entry->priv;
6806 if (priv->button == GDK_BUTTON_MIDDLE)
6808 gint pos, start, end;
6809 pos = priv->insert_pos;
6810 gtk_editable_get_selection_bounds (editable, &start, &end);
6811 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6812 gtk_editable_select_region (editable, pos, pos);
6817 gint pos, start, end;
6819 gboolean popup_completion;
6820 GtkEntryCompletion *completion;
6822 completion = gtk_entry_get_completion (entry);
6824 if (priv->truncate_multiline)
6825 length = truncate_multiline (text);
6827 /* only complete if the selection is at the end */
6828 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6829 MAX (priv->current_pos, priv->selection_bound));
6833 if (gtk_widget_get_mapped (completion->priv->popup_window))
6834 _gtk_entry_completion_popdown (completion);
6836 if (!popup_completion && completion->priv->changed_id > 0)
6837 g_signal_handler_block (entry, completion->priv->changed_id);
6840 begin_change (entry);
6841 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6842 gtk_editable_delete_text (editable, start, end);
6844 pos = priv->current_pos;
6845 gtk_editable_insert_text (editable, text, length, &pos);
6846 gtk_editable_set_position (editable, pos);
6850 !popup_completion && completion->priv->changed_id > 0)
6851 g_signal_handler_unblock (entry, completion->priv->changed_id);
6854 g_object_unref (entry);
6858 gtk_entry_paste (GtkEntry *entry,
6861 g_object_ref (entry);
6862 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6863 paste_received, entry);
6867 primary_get_cb (GtkClipboard *clipboard,
6868 GtkSelectionData *selection_data,
6872 GtkEntry *entry = GTK_ENTRY (data);
6875 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6877 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6878 gtk_selection_data_set_text (selection_data, str, -1);
6884 primary_clear_cb (GtkClipboard *clipboard,
6887 GtkEntry *entry = GTK_ENTRY (data);
6888 GtkEntryPrivate *priv = entry->priv;
6890 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6894 gtk_entry_update_primary_selection (GtkEntry *entry)
6896 GtkTargetList *list;
6897 GtkTargetEntry *targets;
6898 GtkClipboard *clipboard;
6902 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6905 list = gtk_target_list_new (NULL, 0);
6906 gtk_target_list_add_text_targets (list, 0);
6908 targets = gtk_target_table_new_from_list (list, &n_targets);
6910 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6912 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6914 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6915 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6916 primary_clear_cb (clipboard, entry);
6920 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6921 gtk_clipboard_clear (clipboard);
6924 gtk_target_table_free (targets, n_targets);
6925 gtk_target_list_unref (list);
6929 gtk_entry_clear (GtkEntry *entry,
6930 GtkEntryIconPosition icon_pos)
6932 GtkEntryPrivate *priv = entry->priv;
6933 EntryIconInfo *icon_info = priv->icons[icon_pos];
6934 GtkImageType storage_type;
6936 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6939 g_object_freeze_notify (G_OBJECT (entry));
6941 /* Explicitly check, as the pointer may become invalidated
6942 * during destruction.
6944 if (GDK_IS_WINDOW (icon_info->window))
6945 gdk_window_hide (icon_info->window);
6947 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6949 switch (storage_type)
6951 case GTK_IMAGE_PIXBUF:
6952 g_object_notify (G_OBJECT (entry),
6953 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6956 case GTK_IMAGE_STOCK:
6957 g_object_notify (G_OBJECT (entry),
6958 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6961 case GTK_IMAGE_ICON_NAME:
6962 g_object_notify (G_OBJECT (entry),
6963 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6966 case GTK_IMAGE_GICON:
6967 g_object_notify (G_OBJECT (entry),
6968 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6972 g_assert_not_reached ();
6976 _gtk_icon_helper_clear (icon_info->icon_helper);
6978 g_object_notify (G_OBJECT (entry),
6979 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6981 g_object_thaw_notify (G_OBJECT (entry));
6985 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6986 GtkEntryIconPosition icon_pos)
6988 GtkEntryPrivate *priv = entry->priv;
6989 EntryIconInfo *icon_info = priv->icons[icon_pos];
6990 GtkStyleContext *context;
6993 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6994 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6996 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6999 gtk_style_context_restore (context);
7010 * Creates a new entry.
7012 * Return value: a new #GtkEntry.
7015 gtk_entry_new (void)
7017 return g_object_new (GTK_TYPE_ENTRY, NULL);
7021 * gtk_entry_new_with_buffer:
7022 * @buffer: The buffer to use for the new #GtkEntry.
7024 * Creates a new entry with the specified text buffer.
7026 * Return value: a new #GtkEntry
7031 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
7033 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
7034 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
7037 static GtkEntryBuffer*
7038 get_buffer (GtkEntry *entry)
7040 GtkEntryPrivate *priv = entry->priv;
7042 if (priv->buffer == NULL)
7044 GtkEntryBuffer *buffer;
7045 buffer = gtk_entry_buffer_new (NULL, 0);
7046 gtk_entry_set_buffer (entry, buffer);
7047 g_object_unref (buffer);
7050 return priv->buffer;
7054 * gtk_entry_get_buffer:
7055 * @entry: a #GtkEntry
7057 * Get the #GtkEntryBuffer object which holds the text for
7062 * Returns: (transfer none): A #GtkEntryBuffer object.
7065 gtk_entry_get_buffer (GtkEntry *entry)
7067 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7069 return get_buffer (entry);
7073 * gtk_entry_set_buffer:
7074 * @entry: a #GtkEntry
7075 * @buffer: a #GtkEntryBuffer
7077 * Set the #GtkEntryBuffer object which holds the text for
7083 gtk_entry_set_buffer (GtkEntry *entry,
7084 GtkEntryBuffer *buffer)
7086 GtkEntryPrivate *priv;
7089 g_return_if_fail (GTK_IS_ENTRY (entry));
7095 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
7096 g_object_ref (buffer);
7101 buffer_disconnect_signals (entry);
7102 g_object_unref (priv->buffer);
7105 priv->buffer = buffer;
7108 buffer_connect_signals (entry);
7110 obj = G_OBJECT (entry);
7111 g_object_freeze_notify (obj);
7112 g_object_notify (obj, "buffer");
7113 g_object_notify (obj, "text");
7114 g_object_notify (obj, "text-length");
7115 g_object_notify (obj, "max-length");
7116 g_object_notify (obj, "visibility");
7117 g_object_notify (obj, "invisible-char");
7118 g_object_notify (obj, "invisible-char-set");
7119 g_object_thaw_notify (obj);
7121 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7122 gtk_entry_recompute (entry);
7126 * gtk_entry_get_text_area:
7127 * @entry: a #GtkEntry
7128 * @text_area: (out): Return location for the text area.
7130 * Gets the area where the entry's text is drawn. This function is
7131 * useful when drawing something to the entry in a draw callback.
7133 * If the entry is not realized, @text_area is filled with zeros.
7135 * See also gtk_entry_get_icon_area().
7140 gtk_entry_get_text_area (GtkEntry *entry,
7141 GdkRectangle *text_area)
7143 GtkEntryPrivate *priv;
7145 g_return_if_fail (GTK_IS_ENTRY (entry));
7146 g_return_if_fail (text_area != NULL);
7150 if (priv->text_area)
7152 GtkAllocation allocation;
7155 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7156 gdk_window_get_position (priv->text_area, &x, &y);
7158 text_area->x = x - allocation.x;
7159 text_area->y = y - allocation.y;
7160 text_area->width = gdk_window_get_width (priv->text_area);
7161 text_area->height = gdk_window_get_height (priv->text_area);
7167 text_area->width = 0;
7168 text_area->height = 0;
7173 * gtk_entry_set_text:
7174 * @entry: a #GtkEntry
7175 * @text: the new text
7177 * Sets the text in the widget to the given
7178 * value, replacing the current contents.
7180 * See gtk_entry_buffer_set_text().
7183 gtk_entry_set_text (GtkEntry *entry,
7187 GtkEntryCompletion *completion;
7189 g_return_if_fail (GTK_IS_ENTRY (entry));
7190 g_return_if_fail (text != NULL);
7192 /* Actually setting the text will affect the cursor and selection;
7193 * if the contents don't actually change, this will look odd to the user.
7195 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7198 completion = gtk_entry_get_completion (entry);
7199 if (completion && completion->priv->changed_id > 0)
7200 g_signal_handler_block (entry, completion->priv->changed_id);
7202 begin_change (entry);
7203 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7205 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7208 if (completion && completion->priv->changed_id > 0)
7209 g_signal_handler_unblock (entry, completion->priv->changed_id);
7213 * gtk_entry_set_visibility:
7214 * @entry: a #GtkEntry
7215 * @visible: %TRUE if the contents of the entry are displayed
7218 * Sets whether the contents of the entry are visible or not.
7219 * When visibility is set to %FALSE, characters are displayed
7220 * as the invisible char, and will also appear that way when
7221 * the text in the entry widget is copied elsewhere.
7223 * By default, GTK+ picks the best invisible character available
7224 * in the current font, but it can be changed with
7225 * gtk_entry_set_invisible_char().
7227 * Note that you probably want to set #GtkEntry:input-purpose
7228 * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
7229 * inform input methods about the purpose of this entry,
7230 * in addition to setting visibility to %FALSE.
7233 gtk_entry_set_visibility (GtkEntry *entry,
7236 GtkEntryPrivate *priv;
7238 g_return_if_fail (GTK_IS_ENTRY (entry));
7242 visible = visible != FALSE;
7244 if (priv->visible != visible)
7246 priv->visible = visible;
7248 g_object_notify (G_OBJECT (entry), "visibility");
7249 gtk_entry_recompute (entry);
7254 * gtk_entry_get_visibility:
7255 * @entry: a #GtkEntry
7257 * Retrieves whether the text in @entry is visible. See
7258 * gtk_entry_set_visibility().
7260 * Return value: %TRUE if the text is currently visible
7263 gtk_entry_get_visibility (GtkEntry *entry)
7265 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7267 return entry->priv->visible;
7271 * gtk_entry_set_invisible_char:
7272 * @entry: a #GtkEntry
7273 * @ch: a Unicode character
7275 * Sets the character to use in place of the actual text when
7276 * gtk_entry_set_visibility() has been called to set text visibility
7277 * to %FALSE. i.e. this is the character used in "password mode" to
7278 * show the user how many characters have been typed. By default, GTK+
7279 * picks the best invisible char available in the current font. If you
7280 * set the invisible char to 0, then the user will get no feedback
7281 * at all; there will be no text on the screen as they type.
7284 gtk_entry_set_invisible_char (GtkEntry *entry,
7287 GtkEntryPrivate *priv;
7289 g_return_if_fail (GTK_IS_ENTRY (entry));
7293 if (!priv->invisible_char_set)
7295 priv->invisible_char_set = TRUE;
7296 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7299 if (ch == priv->invisible_char)
7302 priv->invisible_char = ch;
7303 g_object_notify (G_OBJECT (entry), "invisible-char");
7304 gtk_entry_recompute (entry);
7308 * gtk_entry_get_invisible_char:
7309 * @entry: a #GtkEntry
7311 * Retrieves the character displayed in place of the real characters
7312 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7314 * Return value: the current invisible char, or 0, if the entry does not
7315 * show invisible text at all.
7318 gtk_entry_get_invisible_char (GtkEntry *entry)
7320 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7322 return entry->priv->invisible_char;
7326 * gtk_entry_unset_invisible_char:
7327 * @entry: a #GtkEntry
7329 * Unsets the invisible char previously set with
7330 * gtk_entry_set_invisible_char(). So that the
7331 * default invisible char is used again.
7336 gtk_entry_unset_invisible_char (GtkEntry *entry)
7338 GtkEntryPrivate *priv;
7341 g_return_if_fail (GTK_IS_ENTRY (entry));
7345 if (!priv->invisible_char_set)
7348 priv->invisible_char_set = FALSE;
7349 ch = find_invisible_char (GTK_WIDGET (entry));
7351 if (priv->invisible_char != ch)
7353 priv->invisible_char = ch;
7354 g_object_notify (G_OBJECT (entry), "invisible-char");
7357 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7358 gtk_entry_recompute (entry);
7362 * gtk_entry_set_overwrite_mode:
7363 * @entry: a #GtkEntry
7364 * @overwrite: new value
7366 * Sets whether the text is overwritten when typing in the #GtkEntry.
7371 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7374 GtkEntryPrivate *priv = entry->priv;
7376 g_return_if_fail (GTK_IS_ENTRY (entry));
7378 if (priv->overwrite_mode == overwrite)
7381 gtk_entry_toggle_overwrite (entry);
7383 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7387 * gtk_entry_get_overwrite_mode:
7388 * @entry: a #GtkEntry
7390 * Gets the value set by gtk_entry_set_overwrite_mode().
7392 * Return value: whether the text is overwritten when typing.
7397 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7399 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7401 return entry->priv->overwrite_mode;
7405 * gtk_entry_get_text:
7406 * @entry: a #GtkEntry
7408 * Retrieves the contents of the entry widget.
7409 * See also gtk_editable_get_chars().
7411 * This is equivalent to:
7413 * <informalexample><programlisting>
7414 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7415 * </programlisting></informalexample>
7417 * Return value: a pointer to the contents of the widget as a
7418 * string. This string points to internally allocated
7419 * storage in the widget and must not be freed, modified or
7423 gtk_entry_get_text (GtkEntry *entry)
7425 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7427 return gtk_entry_buffer_get_text (get_buffer (entry));
7431 * gtk_entry_set_max_length:
7432 * @entry: a #GtkEntry
7433 * @max: the maximum length of the entry, or 0 for no maximum.
7434 * (other than the maximum length of entries.) The value passed in will
7435 * be clamped to the range 0-65536.
7437 * Sets the maximum allowed length of the contents of the widget. If
7438 * the current contents are longer than the given length, then they
7439 * will be truncated to fit.
7441 * This is equivalent to:
7443 * <informalexample><programlisting>
7444 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7445 * </programlisting></informalexample>
7448 gtk_entry_set_max_length (GtkEntry *entry,
7451 g_return_if_fail (GTK_IS_ENTRY (entry));
7452 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7456 * gtk_entry_get_max_length:
7457 * @entry: a #GtkEntry
7459 * Retrieves the maximum allowed length of the text in
7460 * @entry. See gtk_entry_set_max_length().
7462 * This is equivalent to:
7464 * <informalexample><programlisting>
7465 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7466 * </programlisting></informalexample>
7468 * Return value: the maximum allowed number of characters
7469 * in #GtkEntry, or 0 if there is no maximum.
7472 gtk_entry_get_max_length (GtkEntry *entry)
7474 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7476 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7480 * gtk_entry_get_text_length:
7481 * @entry: a #GtkEntry
7483 * Retrieves the current length of the text in
7486 * This is equivalent to:
7488 * <informalexample><programlisting>
7489 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7490 * </programlisting></informalexample>
7492 * Return value: the current number of characters
7493 * in #GtkEntry, or 0 if there are none.
7498 gtk_entry_get_text_length (GtkEntry *entry)
7500 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7502 return gtk_entry_buffer_get_length (get_buffer (entry));
7506 * gtk_entry_set_activates_default:
7507 * @entry: a #GtkEntry
7508 * @setting: %TRUE to activate window's default widget on Enter keypress
7510 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7511 * widget for the window containing the entry. This usually means that
7512 * the dialog box containing the entry will be closed, since the default
7513 * widget is usually one of the dialog buttons.
7515 * (For experts: if @setting is %TRUE, the entry calls
7516 * gtk_window_activate_default() on the window containing the entry, in
7517 * the default handler for the #GtkEntry::activate signal.)
7520 gtk_entry_set_activates_default (GtkEntry *entry,
7523 GtkEntryPrivate *priv;
7525 g_return_if_fail (GTK_IS_ENTRY (entry));
7529 setting = setting != FALSE;
7531 if (setting != priv->activates_default)
7533 priv->activates_default = setting;
7534 g_object_notify (G_OBJECT (entry), "activates-default");
7539 * gtk_entry_get_activates_default:
7540 * @entry: a #GtkEntry
7542 * Retrieves the value set by gtk_entry_set_activates_default().
7544 * Return value: %TRUE if the entry will activate the default widget
7547 gtk_entry_get_activates_default (GtkEntry *entry)
7549 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7551 return entry->priv->activates_default;
7555 * gtk_entry_set_width_chars:
7556 * @entry: a #GtkEntry
7557 * @n_chars: width in chars
7559 * Changes the size request of the entry to be about the right size
7560 * for @n_chars characters. Note that it changes the size
7561 * <emphasis>request</emphasis>, the size can still be affected by
7562 * how you pack the widget into containers. If @n_chars is -1, the
7563 * size reverts to the default entry size.
7566 gtk_entry_set_width_chars (GtkEntry *entry,
7569 GtkEntryPrivate *priv;
7571 g_return_if_fail (GTK_IS_ENTRY (entry));
7575 if (priv->width_chars != n_chars)
7577 priv->width_chars = n_chars;
7578 g_object_notify (G_OBJECT (entry), "width-chars");
7579 gtk_widget_queue_resize (GTK_WIDGET (entry));
7584 * gtk_entry_get_width_chars:
7585 * @entry: a #GtkEntry
7587 * Gets the value set by gtk_entry_set_width_chars().
7589 * Return value: number of chars to request space for, or negative if unset
7592 gtk_entry_get_width_chars (GtkEntry *entry)
7594 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7596 return entry->priv->width_chars;
7600 * gtk_entry_set_has_frame:
7601 * @entry: a #GtkEntry
7602 * @setting: new value
7604 * Sets whether the entry has a beveled frame around it.
7607 gtk_entry_set_has_frame (GtkEntry *entry,
7610 GtkEntryPrivate *priv;
7612 g_return_if_fail (GTK_IS_ENTRY (entry));
7616 setting = (setting != FALSE);
7618 if (priv->has_frame == setting)
7621 gtk_widget_queue_resize (GTK_WIDGET (entry));
7622 priv->has_frame = setting;
7623 g_object_notify (G_OBJECT (entry), "has-frame");
7627 * gtk_entry_get_has_frame:
7628 * @entry: a #GtkEntry
7630 * Gets the value set by gtk_entry_set_has_frame().
7632 * Return value: whether the entry has a beveled frame
7635 gtk_entry_get_has_frame (GtkEntry *entry)
7637 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7639 return entry->priv->has_frame;
7643 * gtk_entry_set_inner_border:
7644 * @entry: a #GtkEntry
7645 * @border: (allow-none): a #GtkBorder, or %NULL
7647 * Sets %entry's inner-border property to %border, or clears it if %NULL
7648 * is passed. The inner-border is the area around the entry's text, but
7651 * If set, this property overrides the inner-border style property.
7652 * Overriding the style-provided border is useful when you want to do
7653 * in-place editing of some text in a canvas or list widget, where
7654 * pixel-exact positioning of the entry is important.
7658 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7659 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7660 * this function is ignored by #GtkEntry.
7663 gtk_entry_set_inner_border (GtkEntry *entry,
7664 const GtkBorder *border)
7666 g_return_if_fail (GTK_IS_ENTRY (entry));
7668 gtk_entry_do_set_inner_border (entry, border);
7672 * gtk_entry_get_inner_border:
7673 * @entry: a #GtkEntry
7675 * This function returns the entry's #GtkEntry:inner-border property. See
7676 * gtk_entry_set_inner_border() for more information.
7678 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7682 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7683 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7684 * this function is ignored by #GtkEntry.
7687 gtk_entry_get_inner_border (GtkEntry *entry)
7689 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7691 return gtk_entry_do_get_inner_border (entry);
7695 * gtk_entry_get_layout:
7696 * @entry: a #GtkEntry
7698 * Gets the #PangoLayout used to display the entry.
7699 * The layout is useful to e.g. convert text positions to
7700 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7701 * The returned layout is owned by the entry and must not be
7702 * modified or freed by the caller.
7704 * Keep in mind that the layout text may contain a preedit string, so
7705 * gtk_entry_layout_index_to_text_index() and
7706 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7707 * indices in the layout to byte indices in the entry contents.
7709 * Return value: (transfer none): the #PangoLayout for this entry
7712 gtk_entry_get_layout (GtkEntry *entry)
7714 PangoLayout *layout;
7716 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7718 layout = gtk_entry_ensure_layout (entry, TRUE);
7725 * gtk_entry_layout_index_to_text_index:
7726 * @entry: a #GtkEntry
7727 * @layout_index: byte index into the entry layout text
7729 * Converts from a position in the entry contents (returned
7730 * by gtk_entry_get_text()) to a position in the
7731 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7732 * with text retrieved via pango_layout_get_text()).
7734 * Return value: byte index into the entry contents
7737 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7740 GtkEntryPrivate *priv;
7741 PangoLayout *layout;
7745 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7749 layout = gtk_entry_ensure_layout (entry, TRUE);
7750 text = pango_layout_get_text (layout);
7751 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7753 if (layout_index >= cursor_index && priv->preedit_length)
7755 if (layout_index >= cursor_index + priv->preedit_length)
7756 layout_index -= priv->preedit_length;
7758 layout_index = cursor_index;
7761 return layout_index;
7765 * gtk_entry_text_index_to_layout_index:
7766 * @entry: a #GtkEntry
7767 * @text_index: byte index into the entry contents
7769 * Converts from a position in the entry's #PangoLayout (returned by
7770 * gtk_entry_get_layout()) to a position in the entry contents
7771 * (returned by gtk_entry_get_text()).
7773 * Return value: byte index into the entry layout text
7776 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7779 GtkEntryPrivate *priv;
7780 PangoLayout *layout;
7784 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7788 layout = gtk_entry_ensure_layout (entry, TRUE);
7789 text = pango_layout_get_text (layout);
7790 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7792 if (text_index > cursor_index)
7793 text_index += priv->preedit_length;
7799 * gtk_entry_get_layout_offsets:
7800 * @entry: a #GtkEntry
7801 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7802 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7805 * Obtains the position of the #PangoLayout used to render text
7806 * in the entry, in widget coordinates. Useful if you want to line
7807 * up the text in an entry with some other text, e.g. when using the
7808 * entry to implement editable cells in a sheet widget.
7810 * Also useful to convert mouse events into coordinates inside the
7811 * #PangoLayout, e.g. to take some action if some part of the entry text
7814 * Note that as the user scrolls around in the entry the offsets will
7815 * change; you'll need to connect to the "notify::scroll-offset"
7816 * signal to track this. Remember when using the #PangoLayout
7817 * functions you need to convert to and from pixels using
7818 * PANGO_PIXELS() or #PANGO_SCALE.
7820 * Keep in mind that the layout text may contain a preedit string, so
7821 * gtk_entry_layout_index_to_text_index() and
7822 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7823 * indices in the layout to byte indices in the entry contents.
7826 gtk_entry_get_layout_offsets (GtkEntry *entry,
7830 gint text_area_x, text_area_y;
7832 g_return_if_fail (GTK_IS_ENTRY (entry));
7834 /* this gets coords relative to text area */
7835 get_layout_position (entry, x, y);
7837 /* convert to widget coords */
7838 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7849 * gtk_entry_set_alignment:
7850 * @entry: a #GtkEntry
7851 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7852 * Reversed for RTL layouts
7854 * Sets the alignment for the contents of the entry. This controls
7855 * the horizontal positioning of the contents when the displayed
7856 * text is shorter than the width of the entry.
7861 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7863 GtkEntryPrivate *priv;
7865 g_return_if_fail (GTK_IS_ENTRY (entry));
7871 else if (xalign > 1.0)
7874 if (xalign != priv->xalign)
7876 priv->xalign = xalign;
7878 gtk_entry_recompute (entry);
7880 g_object_notify (G_OBJECT (entry), "xalign");
7885 * gtk_entry_get_alignment:
7886 * @entry: a #GtkEntry
7888 * Gets the value set by gtk_entry_set_alignment().
7890 * Return value: the alignment
7895 gtk_entry_get_alignment (GtkEntry *entry)
7897 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7899 return entry->priv->xalign;
7903 * gtk_entry_set_icon_from_pixbuf:
7904 * @entry: a #GtkEntry
7905 * @icon_pos: Icon position
7906 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7908 * Sets the icon shown in the specified position using a pixbuf.
7910 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7915 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7916 GtkEntryIconPosition icon_pos,
7919 GtkEntryPrivate *priv;
7920 EntryIconInfo *icon_info;
7922 g_return_if_fail (GTK_IS_ENTRY (entry));
7923 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7927 if ((icon_info = priv->icons[icon_pos]) == NULL)
7928 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7930 g_object_freeze_notify (G_OBJECT (entry));
7933 g_object_ref (pixbuf);
7935 gtk_entry_clear (entry, icon_pos);
7939 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7940 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
7941 GTK_ICON_SIZE_MENU);
7943 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7945 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7946 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7950 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7951 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7954 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7955 gdk_window_show_unraised (icon_info->window);
7957 g_object_unref (pixbuf);
7960 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7961 gtk_widget_queue_resize (GTK_WIDGET (entry));
7963 g_object_thaw_notify (G_OBJECT (entry));
7967 * gtk_entry_set_icon_from_stock:
7968 * @entry: A #GtkEntry
7969 * @icon_pos: Icon position
7970 * @stock_id: (allow-none): The name of the stock item, or %NULL
7972 * Sets the icon shown in the entry at the specified position from
7975 * If @stock_id is %NULL, no icon will be shown in the specified position.
7980 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7981 GtkEntryIconPosition icon_pos,
7982 const gchar *stock_id)
7984 GtkEntryPrivate *priv;
7985 EntryIconInfo *icon_info;
7988 g_return_if_fail (GTK_IS_ENTRY (entry));
7989 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7993 if ((icon_info = priv->icons[icon_pos]) == NULL)
7994 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7996 g_object_freeze_notify (G_OBJECT (entry));
7998 /* need to dup before clearing */
7999 new_id = g_strdup (stock_id);
8001 gtk_entry_clear (entry, icon_pos);
8005 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
8007 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8009 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
8010 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8014 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
8015 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8018 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8019 gdk_window_show_unraised (icon_info->window);
8024 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8025 gtk_widget_queue_resize (GTK_WIDGET (entry));
8027 g_object_thaw_notify (G_OBJECT (entry));
8031 * gtk_entry_set_icon_from_icon_name:
8032 * @entry: A #GtkEntry
8033 * @icon_pos: The position at which to set the icon
8034 * @icon_name: (allow-none): An icon name, or %NULL
8036 * Sets the icon shown in the entry at the specified position
8037 * from the current icon theme.
8039 * If the icon name isn't known, a "broken image" icon will be displayed
8042 * If @icon_name is %NULL, no icon will be shown in the specified position.
8047 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
8048 GtkEntryIconPosition icon_pos,
8049 const gchar *icon_name)
8051 GtkEntryPrivate *priv;
8052 EntryIconInfo *icon_info;
8055 g_return_if_fail (GTK_IS_ENTRY (entry));
8056 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8060 if ((icon_info = priv->icons[icon_pos]) == NULL)
8061 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8063 g_object_freeze_notify (G_OBJECT (entry));
8065 /* need to dup before clearing */
8066 new_name = g_strdup (icon_name);
8068 gtk_entry_clear (entry, icon_pos);
8070 if (new_name != NULL)
8072 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
8074 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8076 g_object_notify (G_OBJECT (entry), "primary-icon-name");
8077 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8081 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
8082 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8085 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8086 gdk_window_show_unraised (icon_info->window);
8091 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8092 gtk_widget_queue_resize (GTK_WIDGET (entry));
8094 g_object_thaw_notify (G_OBJECT (entry));
8098 * gtk_entry_set_icon_from_gicon:
8099 * @entry: A #GtkEntry
8100 * @icon_pos: The position at which to set the icon
8101 * @icon: (allow-none): The icon to set, or %NULL
8103 * Sets the icon shown in the entry at the specified position
8104 * from the current icon theme.
8105 * If the icon isn't known, a "broken image" icon will be displayed
8108 * If @icon is %NULL, no icon will be shown in the specified position.
8113 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
8114 GtkEntryIconPosition icon_pos,
8117 GtkEntryPrivate *priv;
8118 EntryIconInfo *icon_info;
8120 g_return_if_fail (GTK_IS_ENTRY (entry));
8121 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8125 if ((icon_info = priv->icons[icon_pos]) == NULL)
8126 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8128 g_object_freeze_notify (G_OBJECT (entry));
8130 /* need to ref before clearing */
8132 g_object_ref (icon);
8134 gtk_entry_clear (entry, icon_pos);
8138 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
8140 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8142 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8143 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8147 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8148 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8151 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8152 gdk_window_show_unraised (icon_info->window);
8154 g_object_unref (icon);
8157 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8158 gtk_widget_queue_resize (GTK_WIDGET (entry));
8160 g_object_thaw_notify (G_OBJECT (entry));
8164 * gtk_entry_set_icon_activatable:
8165 * @entry: A #GtkEntry
8166 * @icon_pos: Icon position
8167 * @activatable: %TRUE if the icon should be activatable
8169 * Sets whether the icon is activatable.
8174 gtk_entry_set_icon_activatable (GtkEntry *entry,
8175 GtkEntryIconPosition icon_pos,
8176 gboolean activatable)
8178 GtkEntryPrivate *priv;
8179 EntryIconInfo *icon_info;
8181 g_return_if_fail (GTK_IS_ENTRY (entry));
8182 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8186 if ((icon_info = priv->icons[icon_pos]) == NULL)
8187 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8189 activatable = activatable != FALSE;
8191 if (icon_info->nonactivatable != !activatable)
8193 icon_info->nonactivatable = !activatable;
8195 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8196 update_cursors (GTK_WIDGET (entry));
8198 g_object_notify (G_OBJECT (entry),
8199 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8204 * gtk_entry_get_icon_activatable:
8205 * @entry: a #GtkEntry
8206 * @icon_pos: Icon position
8208 * Returns whether the icon is activatable.
8210 * Returns: %TRUE if the icon is activatable.
8215 gtk_entry_get_icon_activatable (GtkEntry *entry,
8216 GtkEntryIconPosition icon_pos)
8218 GtkEntryPrivate *priv;
8219 EntryIconInfo *icon_info;
8221 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8222 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8225 icon_info = priv->icons[icon_pos];
8227 return (!icon_info || !icon_info->nonactivatable);
8231 * gtk_entry_get_icon_pixbuf:
8232 * @entry: A #GtkEntry
8233 * @icon_pos: Icon position
8235 * Retrieves the image used for the icon.
8237 * Unlike the other methods of setting and getting icon data, this
8238 * method will work regardless of whether the icon was set using a
8239 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8241 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8242 * set for this position.
8247 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8248 GtkEntryIconPosition icon_pos)
8250 GtkEntryPrivate *priv;
8251 EntryIconInfo *icon_info;
8254 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8255 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8259 icon_info = priv->icons[icon_pos];
8264 /* HACK: unfortunately this is transfer none, so we need to return
8265 * the icon helper's cache ref directly.
8267 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
8269 g_object_unref (pixbuf);
8275 * gtk_entry_get_icon_gicon:
8276 * @entry: A #GtkEntry
8277 * @icon_pos: Icon position
8279 * Retrieves the #GIcon used for the icon, or %NULL if there is
8280 * no icon or if the icon was set by some other method (e.g., by
8281 * stock, pixbuf, or icon name).
8283 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8284 * or if the icon is not a #GIcon
8289 gtk_entry_get_icon_gicon (GtkEntry *entry,
8290 GtkEntryIconPosition icon_pos)
8292 GtkEntryPrivate *priv;
8293 EntryIconInfo *icon_info;
8295 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8296 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8299 icon_info = priv->icons[icon_pos];
8304 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
8308 * gtk_entry_get_icon_stock:
8309 * @entry: A #GtkEntry
8310 * @icon_pos: Icon position
8312 * Retrieves the stock id used for the icon, or %NULL if there is
8313 * no icon or if the icon was set by some other method (e.g., by
8314 * pixbuf, icon name or gicon).
8316 * Returns: A stock id, or %NULL if no icon is set or if the icon
8317 * wasn't set from a stock id
8322 gtk_entry_get_icon_stock (GtkEntry *entry,
8323 GtkEntryIconPosition icon_pos)
8325 GtkEntryPrivate *priv;
8326 EntryIconInfo *icon_info;
8328 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8329 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8332 icon_info = priv->icons[icon_pos];
8337 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8341 * gtk_entry_get_icon_name:
8342 * @entry: A #GtkEntry
8343 * @icon_pos: Icon position
8345 * Retrieves the icon name used for the icon, or %NULL if there is
8346 * no icon or if the icon was set by some other method (e.g., by
8347 * pixbuf, stock or gicon).
8349 * Returns: An icon name, or %NULL if no icon is set or if the icon
8350 * wasn't set from an icon name
8355 gtk_entry_get_icon_name (GtkEntry *entry,
8356 GtkEntryIconPosition icon_pos)
8358 GtkEntryPrivate *priv;
8359 EntryIconInfo *icon_info;
8361 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8362 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8365 icon_info = priv->icons[icon_pos];
8370 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8374 * gtk_entry_set_icon_sensitive:
8375 * @entry: A #GtkEntry
8376 * @icon_pos: Icon position
8377 * @sensitive: Specifies whether the icon should appear
8378 * sensitive or insensitive
8380 * Sets the sensitivity for the specified icon.
8385 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8386 GtkEntryIconPosition icon_pos,
8389 GtkEntryPrivate *priv;
8390 EntryIconInfo *icon_info;
8392 g_return_if_fail (GTK_IS_ENTRY (entry));
8393 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8397 if ((icon_info = priv->icons[icon_pos]) == NULL)
8398 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8400 if (icon_info->insensitive != !sensitive)
8402 icon_info->insensitive = !sensitive;
8404 icon_info->pressed = FALSE;
8405 icon_info->prelight = FALSE;
8407 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8408 update_cursors (GTK_WIDGET (entry));
8410 gtk_widget_queue_draw (GTK_WIDGET (entry));
8412 g_object_notify (G_OBJECT (entry),
8413 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8418 * gtk_entry_get_icon_sensitive:
8419 * @entry: a #GtkEntry
8420 * @icon_pos: Icon position
8422 * Returns whether the icon appears sensitive or insensitive.
8424 * Returns: %TRUE if the icon is sensitive.
8429 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8430 GtkEntryIconPosition icon_pos)
8432 GtkEntryPrivate *priv;
8433 EntryIconInfo *icon_info;
8435 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8436 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8440 icon_info = priv->icons[icon_pos];
8442 return (!icon_info || !icon_info->insensitive);
8447 * gtk_entry_get_icon_storage_type:
8448 * @entry: a #GtkEntry
8449 * @icon_pos: Icon position
8451 * Gets the type of representation being used by the icon
8452 * to store image data. If the icon has no image data,
8453 * the return value will be %GTK_IMAGE_EMPTY.
8455 * Return value: image representation being used
8460 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8461 GtkEntryIconPosition icon_pos)
8463 GtkEntryPrivate *priv;
8464 EntryIconInfo *icon_info;
8466 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8467 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8471 icon_info = priv->icons[icon_pos];
8474 return GTK_IMAGE_EMPTY;
8476 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8480 * gtk_entry_get_icon_at_pos:
8481 * @entry: a #GtkEntry
8482 * @x: the x coordinate of the position to find
8483 * @y: the y coordinate of the position to find
8485 * Finds the icon at the given position and return its index. The
8486 * position's coordinates are relative to the @entry's top left corner.
8487 * If @x, @y doesn't lie inside an icon, -1 is returned.
8488 * This function is intended for use in a #GtkWidget::query-tooltip
8491 * Returns: the index of the icon at the given position, or -1
8496 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8500 GtkAllocation primary;
8501 GtkAllocation secondary;
8502 gint frame_x, frame_y;
8504 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8506 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8510 get_icon_allocations (entry, &primary, &secondary);
8512 if (primary.x <= x && x < primary.x + primary.width &&
8513 primary.y <= y && y < primary.y + primary.height)
8514 return GTK_ENTRY_ICON_PRIMARY;
8516 if (secondary.x <= x && x < secondary.x + secondary.width &&
8517 secondary.y <= y && y < secondary.y + secondary.height)
8518 return GTK_ENTRY_ICON_SECONDARY;
8524 * gtk_entry_set_icon_drag_source:
8525 * @entry: a #GtkEntry
8526 * @icon_pos: icon position
8527 * @target_list: the targets (data formats) in which the data can be provided
8528 * @actions: a bitmask of the allowed drag actions
8530 * Sets up the icon at the given position so that GTK+ will start a drag
8531 * operation when the user clicks and drags the icon.
8533 * To handle the drag operation, you need to connect to the usual
8534 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8535 * signal, and use gtk_entry_get_current_icon_drag_source() in
8536 * your signal handler to find out if the drag was started from
8539 * By default, GTK+ uses the icon as the drag icon. You can use the
8540 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8541 * have to use g_signal_connect_after() to ensure that your signal handler
8542 * gets executed after the default handler.
8547 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8548 GtkEntryIconPosition icon_pos,
8549 GtkTargetList *target_list,
8550 GdkDragAction actions)
8552 GtkEntryPrivate *priv;
8553 EntryIconInfo *icon_info;
8555 g_return_if_fail (GTK_IS_ENTRY (entry));
8556 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8560 if ((icon_info = priv->icons[icon_pos]) == NULL)
8561 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8563 if (icon_info->target_list)
8564 gtk_target_list_unref (icon_info->target_list);
8565 icon_info->target_list = target_list;
8566 if (icon_info->target_list)
8567 gtk_target_list_ref (icon_info->target_list);
8569 icon_info->actions = actions;
8573 * gtk_entry_get_current_icon_drag_source:
8574 * @entry: a #GtkIconEntry
8576 * Returns the index of the icon which is the source of the current
8577 * DND operation, or -1.
8579 * This function is meant to be used in a #GtkWidget::drag-data-get
8582 * Returns: index of the icon which is the source of the current
8583 * DND operation, or -1.
8588 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8590 GtkEntryPrivate *priv;
8591 EntryIconInfo *icon_info = NULL;
8594 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8598 for (i = 0; i < MAX_ICONS; i++)
8600 if ((icon_info = priv->icons[i]))
8602 if (icon_info->in_drag)
8611 * gtk_entry_get_icon_area:
8612 * @entry: A #GtkEntry
8613 * @icon_pos: Icon position
8614 * @icon_area: (out): Return location for the icon's area
8616 * Gets the area where entry's icon at @icon_pos is drawn.
8617 * This function is useful when drawing something to the
8618 * entry in a draw callback.
8620 * If the entry is not realized or has no icon at the given position,
8621 * @icon_area is filled with zeros.
8623 * See also gtk_entry_get_text_area()
8628 gtk_entry_get_icon_area (GtkEntry *entry,
8629 GtkEntryIconPosition icon_pos,
8630 GdkRectangle *icon_area)
8632 GtkEntryPrivate *priv;
8633 EntryIconInfo *icon_info;
8635 g_return_if_fail (GTK_IS_ENTRY (entry));
8636 g_return_if_fail (icon_area != NULL);
8640 icon_info = priv->icons[icon_pos];
8644 GtkAllocation primary;
8645 GtkAllocation secondary;
8647 get_icon_allocations (entry, &primary, &secondary);
8649 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8650 *icon_area = primary;
8652 *icon_area = secondary;
8658 icon_area->width = 0;
8659 icon_area->height = 0;
8664 ensure_has_tooltip (GtkEntry *entry)
8666 GtkEntryPrivate *priv;
8667 EntryIconInfo *icon_info;
8669 gboolean has_tooltip = FALSE;
8673 for (i = 0; i < MAX_ICONS; i++)
8675 if ((icon_info = priv->icons[i]) != NULL)
8677 if (icon_info->tooltip != NULL)
8685 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8689 * gtk_entry_get_icon_tooltip_text:
8690 * @entry: a #GtkEntry
8691 * @icon_pos: the icon position
8693 * Gets the contents of the tooltip on the icon at the specified
8694 * position in @entry.
8696 * Returns: the tooltip text, or %NULL. Free the returned string
8697 * with g_free() when done.
8702 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8703 GtkEntryIconPosition icon_pos)
8705 GtkEntryPrivate *priv;
8706 EntryIconInfo *icon_info;
8709 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8710 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8714 icon_info = priv->icons[icon_pos];
8719 if (icon_info->tooltip &&
8720 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8721 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8727 * gtk_entry_set_icon_tooltip_text:
8728 * @entry: a #GtkEntry
8729 * @icon_pos: the icon position
8730 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8732 * Sets @tooltip as the contents of the tooltip for the icon
8733 * at the specified position.
8735 * Use %NULL for @tooltip to remove an existing tooltip.
8737 * See also gtk_widget_set_tooltip_text() and
8738 * gtk_entry_set_icon_tooltip_markup().
8743 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8744 GtkEntryIconPosition icon_pos,
8745 const gchar *tooltip)
8747 GtkEntryPrivate *priv;
8748 EntryIconInfo *icon_info;
8750 g_return_if_fail (GTK_IS_ENTRY (entry));
8751 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8755 if ((icon_info = priv->icons[icon_pos]) == NULL)
8756 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8758 if (icon_info->tooltip)
8759 g_free (icon_info->tooltip);
8761 /* Treat an empty string as a NULL string,
8762 * because an empty string would be useless for a tooltip:
8764 if (tooltip && tooltip[0] == '\0')
8767 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8769 ensure_has_tooltip (entry);
8773 * gtk_entry_get_icon_tooltip_markup:
8774 * @entry: a #GtkEntry
8775 * @icon_pos: the icon position
8777 * Gets the contents of the tooltip on the icon at the specified
8778 * position in @entry.
8780 * Returns: the tooltip text, or %NULL. Free the returned string
8781 * with g_free() when done.
8786 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8787 GtkEntryIconPosition icon_pos)
8789 GtkEntryPrivate *priv;
8790 EntryIconInfo *icon_info;
8792 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8793 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8797 icon_info = priv->icons[icon_pos];
8802 return g_strdup (icon_info->tooltip);
8806 * gtk_entry_set_icon_tooltip_markup:
8807 * @entry: a #GtkEntry
8808 * @icon_pos: the icon position
8809 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8811 * Sets @tooltip as the contents of the tooltip for the icon at
8812 * the specified position. @tooltip is assumed to be marked up with
8813 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8815 * Use %NULL for @tooltip to remove an existing tooltip.
8817 * See also gtk_widget_set_tooltip_markup() and
8818 * gtk_entry_set_icon_tooltip_text().
8823 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8824 GtkEntryIconPosition icon_pos,
8825 const gchar *tooltip)
8827 GtkEntryPrivate *priv;
8828 EntryIconInfo *icon_info;
8830 g_return_if_fail (GTK_IS_ENTRY (entry));
8831 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8835 if ((icon_info = priv->icons[icon_pos]) == NULL)
8836 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8838 if (icon_info->tooltip)
8839 g_free (icon_info->tooltip);
8841 /* Treat an empty string as a NULL string,
8842 * because an empty string would be useless for a tooltip:
8844 if (tooltip && tooltip[0] == '\0')
8847 icon_info->tooltip = g_strdup (tooltip);
8849 ensure_has_tooltip (entry);
8853 gtk_entry_query_tooltip (GtkWidget *widget,
8856 gboolean keyboard_tip,
8857 GtkTooltip *tooltip)
8860 GtkEntryPrivate *priv;
8861 EntryIconInfo *icon_info;
8864 entry = GTK_ENTRY (widget);
8869 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8872 if ((icon_info = priv->icons[icon_pos]) != NULL)
8874 if (icon_info->tooltip)
8876 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8885 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8892 /* Quick hack of a popup menu
8895 activate_cb (GtkWidget *menuitem,
8898 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8899 g_signal_emit_by_name (entry, signal);
8904 gtk_entry_mnemonic_activate (GtkWidget *widget,
8905 gboolean group_cycling)
8907 gtk_widget_grab_focus (widget);
8912 gtk_entry_grab_notify (GtkWidget *widget,
8913 gboolean was_grabbed)
8915 GtkEntryPrivate *priv;
8917 priv = GTK_ENTRY (widget)->priv;
8920 gtk_widget_device_is_shadowed (widget, priv->device))
8922 /* Unset button so we don't expect
8923 * a button release anymore
8926 priv->device = NULL;
8927 priv->in_drag = FALSE;
8932 append_action_signal (GtkEntry *entry,
8934 const gchar *stock_id,
8935 const gchar *signal,
8938 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8940 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8941 g_signal_connect (menuitem, "activate",
8942 G_CALLBACK (activate_cb), entry);
8944 gtk_widget_set_sensitive (menuitem, sensitive);
8946 gtk_widget_show (menuitem);
8947 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8951 popup_menu_detach (GtkWidget *attach_widget,
8954 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8955 GtkEntryPrivate *priv_attach = entry_attach->priv;
8957 priv_attach->popup_menu = NULL;
8961 popup_position_func (GtkMenu *menu,
8967 GtkEntry *entry = GTK_ENTRY (user_data);
8968 GtkEntryPrivate *priv = entry->priv;
8969 GtkWidget *widget = GTK_WIDGET (entry);
8971 GtkRequisition menu_req;
8972 GdkRectangle monitor;
8974 gint monitor_num, strong_x, height;
8976 g_return_if_fail (gtk_widget_get_realized (widget));
8978 gdk_window_get_origin (priv->text_area, x, y);
8980 screen = gtk_widget_get_screen (widget);
8981 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8982 if (monitor_num < 0)
8984 gtk_menu_set_monitor (menu, monitor_num);
8986 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8987 gtk_widget_get_preferred_size (priv->popup_menu,
8989 height = gdk_window_get_height (priv->text_area);
8990 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8991 _gtk_entry_get_borders (entry, &borders);
8993 *x += borders.left + strong_x - priv->scroll_offset;
8994 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8995 *x -= menu_req.width;
8997 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8999 else if ((*y - menu_req.height) >= monitor.y)
9000 *y -= menu_req.height;
9001 else if (monitor.y + monitor.height - (*y + height) > *y)
9004 *y -= menu_req.height;
9010 unichar_chosen_func (const char *text,
9013 GtkEntry *entry = GTK_ENTRY (data);
9014 GtkEntryPrivate *priv = entry->priv;
9017 gtk_entry_enter_text (entry, text);
9029 popup_targets_received (GtkClipboard *clipboard,
9030 GtkSelectionData *data,
9033 PopupInfo *info = user_data;
9034 GtkEntry *entry = info->entry;
9035 GtkEntryPrivate *info_entry_priv = entry->priv;
9037 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
9040 gboolean clipboard_contains_text;
9041 GtkWidget *menuitem;
9043 gboolean show_input_method_menu;
9044 gboolean show_unicode_menu;
9046 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
9047 if (info_entry_priv->popup_menu)
9048 gtk_widget_destroy (info_entry_priv->popup_menu);
9050 info_entry_priv->popup_menu = gtk_menu_new ();
9052 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
9056 mode = gtk_entry_get_display_mode (entry);
9057 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
9058 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
9059 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9061 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
9062 mode == DISPLAY_NORMAL &&
9063 info_entry_priv->current_pos != info_entry_priv->selection_bound);
9065 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
9066 info_entry_priv->editable && clipboard_contains_text);
9068 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
9069 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
9070 g_signal_connect_swapped (menuitem, "activate",
9071 G_CALLBACK (gtk_entry_delete_cb), entry);
9072 gtk_widget_show (menuitem);
9073 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9075 menuitem = gtk_separator_menu_item_new ();
9076 gtk_widget_show (menuitem);
9077 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9079 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
9080 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
9081 g_signal_connect_swapped (menuitem, "activate",
9082 G_CALLBACK (gtk_entry_select_all), entry);
9083 gtk_widget_show (menuitem);
9084 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9086 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
9087 "gtk-show-input-method-menu", &show_input_method_menu,
9088 "gtk-show-unicode-menu", &show_unicode_menu,
9091 if (show_input_method_menu || show_unicode_menu)
9093 menuitem = gtk_separator_menu_item_new ();
9094 gtk_widget_show (menuitem);
9095 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9098 if (show_input_method_menu)
9100 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
9101 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9102 gtk_widget_show (menuitem);
9103 submenu = gtk_menu_new ();
9104 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9106 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9108 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
9109 GTK_MENU_SHELL (submenu));
9112 if (show_unicode_menu)
9114 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
9115 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
9116 gtk_widget_show (menuitem);
9118 submenu = gtk_menu_new ();
9119 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
9120 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
9122 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
9123 unichar_chosen_func,
9127 g_signal_emit (entry,
9128 signals[POPULATE_POPUP],
9130 info_entry_priv->popup_menu);
9134 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
9135 info->device, NULL, NULL, NULL, NULL, NULL,
9136 info->button, info->time);
9139 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
9140 popup_position_func, entry,
9141 0, gtk_get_current_event_time ());
9142 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9146 g_object_unref (entry);
9147 g_slice_free (PopupInfo, info);
9151 gtk_entry_do_popup (GtkEntry *entry,
9152 GdkEventButton *event)
9154 PopupInfo *info = g_slice_new (PopupInfo);
9156 /* In order to know what entries we should make sensitive, we
9157 * ask for the current targets of the clipboard, and when
9158 * we get them, then we actually pop up the menu.
9160 info->entry = g_object_ref (entry);
9164 info->button = event->button;
9165 info->time = event->time;
9166 info->device = event->device;
9171 info->time = gtk_get_current_event_time ();
9172 info->device = NULL;
9175 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9176 gdk_atom_intern_static_string ("TARGETS"),
9177 popup_targets_received,
9182 gtk_entry_popup_menu (GtkWidget *widget)
9184 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9189 gtk_entry_drag_begin (GtkWidget *widget,
9190 GdkDragContext *context)
9192 GtkEntry *entry = GTK_ENTRY (widget);
9193 GtkEntryPrivate *priv = entry->priv;
9196 for (i = 0; i < MAX_ICONS; i++)
9198 EntryIconInfo *icon_info = priv->icons[i];
9200 if (icon_info != NULL)
9202 if (icon_info->in_drag)
9206 pix = _gtk_icon_helper_ensure_pixbuf
9207 (icon_info->icon_helper,
9208 gtk_widget_get_style_context (GTK_WIDGET (entry)));
9209 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
9211 g_object_unref (pix);
9218 gtk_entry_drag_end (GtkWidget *widget,
9219 GdkDragContext *context)
9221 GtkEntry *entry = GTK_ENTRY (widget);
9222 GtkEntryPrivate *priv = entry->priv;
9225 for (i = 0; i < MAX_ICONS; i++)
9227 EntryIconInfo *icon_info = priv->icons[i];
9229 if (icon_info != NULL)
9230 icon_info->in_drag = 0;
9235 gtk_entry_drag_leave (GtkWidget *widget,
9236 GdkDragContext *context,
9239 GtkEntry *entry = GTK_ENTRY (widget);
9240 GtkEntryPrivate *priv = entry->priv;
9242 priv->dnd_position = -1;
9243 gtk_widget_queue_draw (widget);
9247 gtk_entry_drag_drop (GtkWidget *widget,
9248 GdkDragContext *context,
9253 GtkEntry *entry = GTK_ENTRY (widget);
9254 GtkEntryPrivate *priv = entry->priv;
9255 GdkAtom target = GDK_NONE;
9258 target = gtk_drag_dest_find_target (widget, context, NULL);
9260 if (target != GDK_NONE)
9261 gtk_drag_get_data (widget, context, target, time);
9263 gtk_drag_finish (context, FALSE, FALSE, time);
9269 gtk_entry_drag_motion (GtkWidget *widget,
9270 GdkDragContext *context,
9275 GtkEntry *entry = GTK_ENTRY (widget);
9276 GtkEntryPrivate *priv = entry->priv;
9277 GtkStyleContext *style_context;
9278 GtkWidget *source_widget;
9279 GdkDragAction suggested_action;
9280 gint new_position, old_position;
9284 style_context = gtk_widget_get_style_context (widget);
9285 gtk_style_context_get_padding (style_context, 0, &padding);
9289 old_position = priv->dnd_position;
9290 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9292 if (priv->editable &&
9293 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9295 source_widget = gtk_drag_get_source_widget (context);
9296 suggested_action = gdk_drag_context_get_suggested_action (context);
9298 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9299 new_position < sel1 || new_position > sel2)
9301 if (source_widget == widget)
9303 /* Default to MOVE, unless the user has
9304 * pressed ctrl or alt to affect available actions
9306 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9307 suggested_action = GDK_ACTION_MOVE;
9310 priv->dnd_position = new_position;
9314 if (source_widget == widget)
9315 suggested_action = 0; /* Can't drop in selection where drag started */
9317 priv->dnd_position = -1;
9322 /* Entry not editable, or no text */
9323 suggested_action = 0;
9324 priv->dnd_position = -1;
9327 gdk_drag_status (context, suggested_action, time);
9329 if (priv->dnd_position != old_position)
9330 gtk_widget_queue_draw (widget);
9336 gtk_entry_drag_data_received (GtkWidget *widget,
9337 GdkDragContext *context,
9340 GtkSelectionData *selection_data,
9344 GtkEntry *entry = GTK_ENTRY (widget);
9345 GtkEntryPrivate *priv = entry->priv;
9346 GtkEditable *editable = GTK_EDITABLE (widget);
9347 GtkStyleContext *style_context;
9351 str = (gchar *) gtk_selection_data_get_text (selection_data);
9353 style_context = gtk_widget_get_style_context (widget);
9354 gtk_style_context_get_padding (style_context, 0, &padding);
9358 if (str && priv->editable)
9364 if (priv->truncate_multiline)
9365 length = truncate_multiline (str);
9367 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9369 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9370 new_position < sel1 || new_position > sel2)
9372 gtk_editable_insert_text (editable, str, length, &new_position);
9376 /* Replacing selection */
9377 begin_change (entry);
9378 gtk_editable_delete_text (editable, sel1, sel2);
9379 gtk_editable_insert_text (editable, str, length, &sel1);
9383 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9387 /* Drag and drop didn't happen! */
9388 gtk_drag_finish (context, FALSE, FALSE, time);
9395 gtk_entry_drag_data_get (GtkWidget *widget,
9396 GdkDragContext *context,
9397 GtkSelectionData *selection_data,
9401 GtkEntry *entry = GTK_ENTRY (widget);
9402 GtkEntryPrivate *priv = entry->priv;
9403 GtkEditable *editable = GTK_EDITABLE (widget);
9404 gint sel_start, sel_end;
9407 /* If there is an icon drag going on, exit early. */
9408 for (i = 0; i < MAX_ICONS; i++)
9410 EntryIconInfo *icon_info = priv->icons[i];
9412 if (icon_info != NULL)
9414 if (icon_info->in_drag)
9419 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9421 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9423 gtk_selection_data_set_text (selection_data, str, -1);
9431 gtk_entry_drag_data_delete (GtkWidget *widget,
9432 GdkDragContext *context)
9434 GtkEntry *entry = GTK_ENTRY (widget);
9435 GtkEntryPrivate *priv = entry->priv;
9436 GtkEditable *editable = GTK_EDITABLE (widget);
9437 gint sel_start, sel_end;
9440 /* If there is an icon drag going on, exit early. */
9441 for (i = 0; i < MAX_ICONS; i++)
9443 EntryIconInfo *icon_info = priv->icons[i];
9445 if (icon_info != NULL)
9447 if (icon_info->in_drag)
9452 if (priv->editable &&
9453 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9454 gtk_editable_delete_text (editable, sel_start, sel_end);
9457 /* We display the cursor when
9459 * - the selection is empty, AND
9460 * - the widget has focus
9463 #define CURSOR_ON_MULTIPLIER 2
9464 #define CURSOR_OFF_MULTIPLIER 1
9465 #define CURSOR_PEND_MULTIPLIER 3
9466 #define CURSOR_DIVIDER 3
9469 cursor_blinks (GtkEntry *entry)
9471 GtkEntryPrivate *priv = entry->priv;
9473 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9475 priv->selection_bound == priv->current_pos)
9477 GtkSettings *settings;
9480 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9481 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9490 get_middle_click_paste (GtkEntry *entry)
9492 GtkSettings *settings;
9495 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9496 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9502 get_cursor_time (GtkEntry *entry)
9504 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9507 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9513 get_cursor_blink_timeout (GtkEntry *entry)
9515 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9518 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9524 show_cursor (GtkEntry *entry)
9526 GtkEntryPrivate *priv = entry->priv;
9529 if (!priv->cursor_visible)
9531 priv->cursor_visible = TRUE;
9533 widget = GTK_WIDGET (entry);
9534 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9535 gtk_widget_queue_draw (widget);
9540 hide_cursor (GtkEntry *entry)
9542 GtkEntryPrivate *priv = entry->priv;
9545 if (priv->cursor_visible)
9547 priv->cursor_visible = FALSE;
9549 widget = GTK_WIDGET (entry);
9550 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9551 gtk_widget_queue_draw (widget);
9559 blink_cb (gpointer data)
9562 GtkEntryPrivate *priv;
9565 entry = GTK_ENTRY (data);
9568 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9570 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9571 "connect a handler to this signal, it must return\n"
9572 "FALSE so the entry gets the event as well");
9574 gtk_entry_check_cursor_blink (entry);
9579 g_assert (priv->selection_bound == priv->current_pos);
9581 blink_timeout = get_cursor_blink_timeout (entry);
9582 if (priv->blink_time > 1000 * blink_timeout &&
9583 blink_timeout < G_MAXINT/1000)
9585 /* we've blinked enough without the user doing anything, stop blinking */
9586 show_cursor (entry);
9587 priv->blink_timeout = 0;
9589 else if (priv->cursor_visible)
9591 hide_cursor (entry);
9592 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9598 show_cursor (entry);
9599 priv->blink_time += get_cursor_time (entry);
9600 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9605 /* Remove ourselves */
9610 gtk_entry_check_cursor_blink (GtkEntry *entry)
9612 GtkEntryPrivate *priv = entry->priv;
9614 if (cursor_blinks (entry))
9616 if (!priv->blink_timeout)
9618 show_cursor (entry);
9619 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9626 if (priv->blink_timeout)
9628 g_source_remove (priv->blink_timeout);
9629 priv->blink_timeout = 0;
9632 priv->cursor_visible = TRUE;
9637 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9639 GtkEntryPrivate *priv = entry->priv;
9641 if (cursor_blinks (entry))
9643 if (priv->blink_timeout != 0)
9644 g_source_remove (priv->blink_timeout);
9646 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9649 show_cursor (entry);
9654 gtk_entry_reset_blink_time (GtkEntry *entry)
9656 GtkEntryPrivate *priv = entry->priv;
9658 priv->blink_time = 0;
9662 * gtk_entry_set_completion:
9663 * @entry: A #GtkEntry
9664 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9666 * Sets @completion to be the auxiliary completion object to use with @entry.
9667 * All further configuration of the completion mechanism is done on
9668 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9669 * @completion is set to %NULL.
9674 gtk_entry_set_completion (GtkEntry *entry,
9675 GtkEntryCompletion *completion)
9677 GtkEntryCompletion *old;
9679 g_return_if_fail (GTK_IS_ENTRY (entry));
9680 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9682 old = gtk_entry_get_completion (entry);
9684 if (old == completion)
9689 _gtk_entry_completion_disconnect (old);
9690 g_object_unref (old);
9695 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9699 /* hook into the entry */
9700 g_object_ref (completion);
9702 _gtk_entry_completion_connect (completion, entry);
9704 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9706 g_object_notify (G_OBJECT (entry), "completion");
9710 * gtk_entry_get_completion:
9711 * @entry: A #GtkEntry
9713 * Returns the auxiliary completion object currently in use by @entry.
9715 * Return value: (transfer none): The auxiliary completion object currently
9720 GtkEntryCompletion *
9721 gtk_entry_get_completion (GtkEntry *entry)
9723 GtkEntryCompletion *completion;
9725 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9727 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9728 GTK_ENTRY_COMPLETION_KEY));
9734 * gtk_entry_set_cursor_hadjustment:
9735 * @entry: a #GtkEntry
9736 * @adjustment: an adjustment which should be adjusted when the cursor
9737 * is moved, or %NULL
9739 * Hooks up an adjustment to the cursor position in an entry, so that when
9740 * the cursor is moved, the adjustment is scrolled to show that position.
9741 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9744 * The adjustment has to be in pixel units and in the same coordinate system
9750 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9751 GtkAdjustment *adjustment)
9753 g_return_if_fail (GTK_IS_ENTRY (entry));
9755 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9758 g_object_ref (adjustment);
9760 g_object_set_qdata_full (G_OBJECT (entry),
9761 quark_cursor_hadjustment,
9767 * gtk_entry_get_cursor_hadjustment:
9768 * @entry: a #GtkEntry
9770 * Retrieves the horizontal cursor adjustment for the entry.
9771 * See gtk_entry_set_cursor_hadjustment().
9773 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9774 * if none has been set.
9779 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9781 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9783 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9787 * gtk_entry_set_progress_fraction:
9788 * @entry: a #GtkEntry
9789 * @fraction: fraction of the task that's been completed
9791 * Causes the entry's progress indicator to "fill in" the given
9792 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9798 gtk_entry_set_progress_fraction (GtkEntry *entry,
9802 GtkEntryPrivate *private;
9803 gdouble old_fraction;
9804 gint x, y, width, height;
9805 gint old_x, old_y, old_width, old_height;
9807 g_return_if_fail (GTK_IS_ENTRY (entry));
9809 widget = GTK_WIDGET (entry);
9810 private = entry->priv;
9812 if (private->progress_pulse_mode)
9815 old_fraction = private->progress_fraction;
9817 if (gtk_widget_is_drawable (widget))
9818 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9820 fraction = CLAMP (fraction, 0.0, 1.0);
9822 private->progress_fraction = fraction;
9823 private->progress_pulse_mode = FALSE;
9824 private->progress_pulse_current = 0.0;
9826 if (gtk_widget_is_drawable (widget))
9828 get_progress_area (widget, &x, &y, &width, &height);
9830 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9831 gtk_widget_queue_draw (widget);
9834 if (fraction != old_fraction)
9835 g_object_notify (G_OBJECT (entry), "progress-fraction");
9839 * gtk_entry_get_progress_fraction:
9840 * @entry: a #GtkEntry
9842 * Returns the current fraction of the task that's been completed.
9843 * See gtk_entry_set_progress_fraction().
9845 * Return value: a fraction from 0.0 to 1.0
9850 gtk_entry_get_progress_fraction (GtkEntry *entry)
9852 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9854 return entry->priv->progress_fraction;
9858 * gtk_entry_set_progress_pulse_step:
9859 * @entry: a #GtkEntry
9860 * @fraction: fraction between 0.0 and 1.0
9862 * Sets the fraction of total entry width to move the progress
9863 * bouncing block for each call to gtk_entry_progress_pulse().
9868 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9871 GtkEntryPrivate *private;
9873 g_return_if_fail (GTK_IS_ENTRY (entry));
9875 private = entry->priv;
9877 fraction = CLAMP (fraction, 0.0, 1.0);
9879 if (fraction != private->progress_pulse_fraction)
9881 private->progress_pulse_fraction = fraction;
9883 gtk_widget_queue_draw (GTK_WIDGET (entry));
9885 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9890 * gtk_entry_get_progress_pulse_step:
9891 * @entry: a #GtkEntry
9893 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9895 * Return value: a fraction from 0.0 to 1.0
9900 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9902 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9904 return entry->priv->progress_pulse_fraction;
9908 * gtk_entry_progress_pulse:
9909 * @entry: a #GtkEntry
9911 * Indicates that some progress is made, but you don't know how much.
9912 * Causes the entry's progress indicator to enter "activity mode,"
9913 * where a block bounces back and forth. Each call to
9914 * gtk_entry_progress_pulse() causes the block to move by a little bit
9915 * (the amount of movement per pulse is determined by
9916 * gtk_entry_set_progress_pulse_step()).
9921 gtk_entry_progress_pulse (GtkEntry *entry)
9923 GtkEntryPrivate *private;
9925 g_return_if_fail (GTK_IS_ENTRY (entry));
9927 private = entry->priv;
9929 if (private->progress_pulse_mode)
9931 if (private->progress_pulse_way_back)
9933 private->progress_pulse_current -= private->progress_pulse_fraction;
9935 if (private->progress_pulse_current < 0.0)
9937 private->progress_pulse_current = 0.0;
9938 private->progress_pulse_way_back = FALSE;
9943 private->progress_pulse_current += private->progress_pulse_fraction;
9945 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9947 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9948 private->progress_pulse_way_back = TRUE;
9954 private->progress_fraction = 0.0;
9955 private->progress_pulse_mode = TRUE;
9956 private->progress_pulse_way_back = FALSE;
9957 private->progress_pulse_current = 0.0;
9960 gtk_widget_queue_draw (GTK_WIDGET (entry));
9964 * gtk_entry_set_placeholder_text:
9965 * @entry: a #GtkEntry
9966 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
9968 * Sets text to be displayed in @entry when it is empty and unfocused.
9969 * This can be used to give a visual hint of the expected contents of
9972 * Note that since the placeholder text gets removed when the entry
9973 * received focus, using this feature is a bit problematic if the entry
9974 * is given the initial focus in a window. Sometimes this can be
9975 * worked around by delaying the initial focus setting until the
9976 * first key event arrives.
9981 gtk_entry_set_placeholder_text (GtkEntry *entry,
9984 GtkEntryPrivate *priv;
9986 g_return_if_fail (GTK_IS_ENTRY (entry));
9990 if (g_strcmp0 (priv->placeholder_text, text) == 0)
9993 g_free (priv->placeholder_text);
9994 priv->placeholder_text = g_strdup (text);
9996 gtk_entry_recompute (entry);
9998 g_object_notify (G_OBJECT (entry), "placeholder-text");
10002 * gtk_entry_get_placeholder_text:
10003 * @entry: a #GtkEntry
10005 * Retrieves the text that will be displayed when @entry is empty and unfocused
10007 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10008 * storage in the widget and must not be freed, modified or stored.
10013 gtk_entry_get_placeholder_text (GtkEntry *entry)
10015 GtkEntryPrivate *priv;
10017 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10019 priv = entry->priv;
10021 return priv->placeholder_text;
10024 /* Caps Lock warning for password entries */
10027 show_capslock_feedback (GtkEntry *entry,
10030 GtkEntryPrivate *priv = entry->priv;
10032 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10034 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10035 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10036 priv->caps_lock_warning_shown = TRUE;
10039 if (priv->caps_lock_warning_shown)
10040 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10042 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10046 remove_capslock_feedback (GtkEntry *entry)
10048 GtkEntryPrivate *priv = entry->priv;
10050 if (priv->caps_lock_warning_shown)
10052 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10053 priv->caps_lock_warning_shown = FALSE;
10058 keymap_state_changed (GdkKeymap *keymap,
10061 GtkEntryPrivate *priv = entry->priv;
10064 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10066 if (gdk_keymap_get_caps_lock_state (keymap))
10067 text = _("Caps Lock is on");
10071 show_capslock_feedback (entry, text);
10073 remove_capslock_feedback (entry);
10077 * _gtk_entry_set_is_cell_renderer:
10078 * @entry: a #GtkEntry
10079 * @is_cell_renderer: new value
10081 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10082 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10084 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10088 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10089 gboolean is_cell_renderer)
10091 entry->priv->is_cell_renderer = is_cell_renderer;
10095 * gtk_entry_set_input_purpose:
10096 * @entry: a #GtkEntry
10097 * @purpose: the purpose
10099 * Sets the #GtkEntry:input-purpose property which
10100 * can be used by on-screen keyboards and other input
10101 * methods to adjust their behaviour.
10106 gtk_entry_set_input_purpose (GtkEntry *entry,
10107 GtkInputPurpose purpose)
10110 g_return_if_fail (GTK_IS_ENTRY (entry));
10112 if (gtk_entry_get_input_purpose (entry) != purpose)
10114 g_object_set (G_OBJECT (entry->priv->im_context),
10115 "input-purpose", purpose,
10118 g_object_notify (G_OBJECT (entry), "input-purpose");
10123 * gtk_entry_get_input_purpose:
10124 * @entry: a #GtkEntry
10126 * Gets the value of the #GtkEntry:input-purpose property.
10131 gtk_entry_get_input_purpose (GtkEntry *entry)
10133 GtkInputPurpose purpose;
10135 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
10137 g_object_get (G_OBJECT (entry->priv->im_context),
10138 "input-purpose", &purpose,
10145 * gtk_entry_set_input_hints:
10146 * @entry: a #GtkEntry
10147 * @hints: the hints
10149 * Sets the #GtkEntry:input-hints property, which
10150 * allows input methods to fine-tune their behaviour.
10155 gtk_entry_set_input_hints (GtkEntry *entry,
10156 GtkInputHints hints)
10159 g_return_if_fail (GTK_IS_ENTRY (entry));
10161 if (gtk_entry_get_input_hints (entry) != hints)
10163 g_object_set (G_OBJECT (entry->priv->im_context),
10164 "input-hints", hints,
10167 g_object_notify (G_OBJECT (entry), "input-hints");
10172 * gtk_entry_get_input_hints:
10173 * @entry: a #GtkEntry
10175 * Gets the value of the #GtkEntry:input-hints property.
10180 gtk_entry_get_input_hints (GtkEntry *entry)
10182 GtkInputHints hints;
10184 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
10186 g_object_get (G_OBJECT (entry->priv->im_context),
10187 "input-hints", &hints,
10194 * gtk_entry_set_attributes:
10195 * @entry: a #GtkEntry
10196 * @attrs: a #PangoAttrList
10198 * Sets a #PangoAttrList; the attributes in the list are applied to the
10204 gtk_entry_set_attributes (GtkEntry *entry,
10205 PangoAttrList *attrs)
10207 GtkEntryPrivate *priv = entry->priv;
10208 g_return_if_fail (GTK_IS_ENTRY (entry));
10211 pango_attr_list_ref (attrs);
10214 pango_attr_list_unref (priv->attrs);
10215 priv->attrs = attrs;
10217 g_object_notify (G_OBJECT (entry), "attributes");
10219 gtk_entry_recompute (entry);
10220 gtk_widget_queue_resize (GTK_WIDGET (entry));
10224 * gtk_entry_get_attributes:
10225 * @entry: a #GtkEntry
10227 * Gets the attribute list that was set on the entry using
10228 * gtk_entry_set_attributes(), if any.
10230 * Return value: (transfer none): the attribute list, or %NULL
10236 gtk_entry_get_attributes (GtkEntry *entry)
10238 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10240 return entry->priv->attrs;