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"
69 #include "a11y/gtkentryaccessible.h"
73 * @Short_description: A single line text entry field
75 * @See_also: #GtkTextView, #GtkEntryCompletion
77 * The #GtkEntry widget is a single line text entry
78 * widget. A fairly large set of key bindings are supported
79 * by default. If the entered text is longer than the allocation
80 * of the widget, the widget will scroll so that the cursor
81 * position is visible.
83 * When using an entry for passwords and other sensitive information,
84 * it can be put into "password mode" using gtk_entry_set_visibility().
85 * In this mode, entered text is displayed using a 'invisible' character.
86 * By default, GTK+ picks the best invisible character that is available
87 * in the current font, but it can be changed with
88 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
89 * when Caps Lock or input methods might interfere with entering text in
90 * a password entry. The warning can be turned off with the
91 * #GtkEntry:caps-lock-warning property.
93 * Since 2.16, GtkEntry has the ability to display progress or activity
94 * information behind the text. To make an entry display such information,
95 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
97 * Additionally, GtkEntry can show icons at either side of the entry. These
98 * icons can be activatable by clicking, can be set up as drag source and
99 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
100 * one of the various other functions that set an icon from a stock id, an
101 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
102 * connect to the #GtkEntry::icon-press signal. To allow DND operations
103 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
104 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
107 * Note that functionality or information that is only available by clicking
108 * on an icon in an entry may not be accessible at all to users which are not
109 * able to use a mouse or other pointing device. It is therefore recommended
110 * that any such functionality should also be available by other means, e.g.
111 * via the context menu of the entry.
115 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
117 #define MIN_ENTRY_WIDTH 150
118 #define DRAW_TIMEOUT 20
119 #define COMPLETION_TIMEOUT 300
120 #define PASSWORD_HINT_MAX 8
125 #define IS_VALID_ICON_POSITION(pos) \
126 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
127 (pos) == GTK_ENTRY_ICON_SECONDARY)
129 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
130 static GQuark quark_inner_border = 0;
131 static GQuark quark_password_hint = 0;
132 static GQuark quark_cursor_hadjustment = 0;
133 static GQuark quark_capslock_feedback = 0;
135 typedef struct _EntryIconInfo EntryIconInfo;
136 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
137 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
139 struct _GtkEntryPrivate
141 EntryIconInfo *icons[MAX_ICONS];
143 GtkEntryBuffer *buffer;
144 GtkIMContext *im_context;
145 GtkShadowType shadow_type;
146 GtkWidget *popup_menu;
150 GdkDevice *completion_device;
151 GdkWindow *text_area;
153 PangoLayout *cached_layout;
157 gdouble progress_fraction;
158 gdouble progress_pulse_fraction;
159 gdouble progress_pulse_current;
161 gchar *placeholder_text;
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 */
194 guint overwrite_mode : 1;
197 guint activates_default : 1;
198 guint cache_includes_preedit : 1;
199 guint caps_lock_warning : 1;
200 guint caps_lock_warning_shown : 1;
201 guint change_count : 8;
202 guint cursor_visible : 1;
203 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
205 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
206 guint is_cell_renderer : 1;
207 guint invisible_char_set : 1;
208 guint interior_focus : 1;
209 guint mouse_cursor_obscured : 1;
210 guint need_im_reset : 1;
211 guint progress_pulse_mode : 1;
212 guint progress_pulse_way_back : 1;
213 guint real_changed : 1;
214 guint resolved_dir : 4; /* PangoDirection */
215 guint select_words : 1;
216 guint select_lines : 1;
217 guint truncate_multiline : 1;
220 struct _EntryIconInfo
224 guint insensitive : 1;
225 guint nonactivatable : 1;
230 GtkIconHelper *icon_helper;
232 GtkTargetList *target_list;
233 GdkDragAction actions;
236 struct _GtkEntryPasswordHint
238 gint position; /* Position (in text) of the last password hint */
239 guint source_id; /* Timeout source id */
242 struct _GtkEntryCapslockFeedback
269 PROP_CURSOR_POSITION,
270 PROP_SELECTION_BOUND,
277 PROP_ACTIVATES_DEFAULT,
282 PROP_TRUNCATE_MULTILINE,
286 PROP_INVISIBLE_CHAR_SET,
287 PROP_CAPS_LOCK_WARNING,
288 PROP_PROGRESS_FRACTION,
289 PROP_PROGRESS_PULSE_STEP,
291 PROP_PIXBUF_SECONDARY,
293 PROP_STOCK_SECONDARY,
294 PROP_ICON_NAME_PRIMARY,
295 PROP_ICON_NAME_SECONDARY,
297 PROP_GICON_SECONDARY,
298 PROP_STORAGE_TYPE_PRIMARY,
299 PROP_STORAGE_TYPE_SECONDARY,
300 PROP_ACTIVATABLE_PRIMARY,
301 PROP_ACTIVATABLE_SECONDARY,
302 PROP_SENSITIVE_PRIMARY,
303 PROP_SENSITIVE_SECONDARY,
304 PROP_TOOLTIP_TEXT_PRIMARY,
305 PROP_TOOLTIP_TEXT_SECONDARY,
306 PROP_TOOLTIP_MARKUP_PRIMARY,
307 PROP_TOOLTIP_MARKUP_SECONDARY,
309 PROP_EDITING_CANCELED,
310 PROP_PLACEHOLDER_TEXT,
316 static guint signals[LAST_SIGNAL] = { 0 };
325 DISPLAY_NORMAL, /* The entry text is being shown */
326 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
327 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
332 static void gtk_entry_editable_init (GtkEditableInterface *iface);
333 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
334 static void gtk_entry_set_property (GObject *object,
338 static void gtk_entry_get_property (GObject *object,
342 static void gtk_entry_finalize (GObject *object);
343 static void gtk_entry_dispose (GObject *object);
347 static void gtk_entry_destroy (GtkWidget *widget);
348 static void gtk_entry_realize (GtkWidget *widget);
349 static void gtk_entry_unrealize (GtkWidget *widget);
350 static void gtk_entry_map (GtkWidget *widget);
351 static void gtk_entry_unmap (GtkWidget *widget);
352 static void gtk_entry_get_preferred_width (GtkWidget *widget,
355 static void gtk_entry_get_preferred_height (GtkWidget *widget,
358 static void gtk_entry_size_allocate (GtkWidget *widget,
359 GtkAllocation *allocation);
360 static void gtk_entry_draw_frame (GtkWidget *widget,
361 GtkStyleContext *context,
363 static void gtk_entry_draw_progress (GtkWidget *widget,
364 GtkStyleContext *context,
366 static gint gtk_entry_draw (GtkWidget *widget,
368 static gint gtk_entry_button_press (GtkWidget *widget,
369 GdkEventButton *event);
370 static gint gtk_entry_button_release (GtkWidget *widget,
371 GdkEventButton *event);
372 static gint gtk_entry_enter_notify (GtkWidget *widget,
373 GdkEventCrossing *event);
374 static gint gtk_entry_leave_notify (GtkWidget *widget,
375 GdkEventCrossing *event);
376 static gint gtk_entry_motion_notify (GtkWidget *widget,
377 GdkEventMotion *event);
378 static gint gtk_entry_key_press (GtkWidget *widget,
380 static gint gtk_entry_key_release (GtkWidget *widget,
382 static gint gtk_entry_focus_in (GtkWidget *widget,
383 GdkEventFocus *event);
384 static gint gtk_entry_focus_out (GtkWidget *widget,
385 GdkEventFocus *event);
386 static void gtk_entry_grab_focus (GtkWidget *widget);
387 static void gtk_entry_style_updated (GtkWidget *widget);
388 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
391 gboolean keyboard_tip,
392 GtkTooltip *tooltip);
393 static void gtk_entry_direction_changed (GtkWidget *widget,
394 GtkTextDirection previous_dir);
395 static void gtk_entry_state_flags_changed (GtkWidget *widget,
396 GtkStateFlags previous_state);
397 static void gtk_entry_screen_changed (GtkWidget *widget,
398 GdkScreen *old_screen);
400 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
401 GdkDragContext *context,
405 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
406 GdkDragContext *context,
410 static void gtk_entry_drag_leave (GtkWidget *widget,
411 GdkDragContext *context,
413 static void gtk_entry_drag_data_received (GtkWidget *widget,
414 GdkDragContext *context,
417 GtkSelectionData *selection_data,
420 static void gtk_entry_drag_data_get (GtkWidget *widget,
421 GdkDragContext *context,
422 GtkSelectionData *selection_data,
425 static void gtk_entry_drag_data_delete (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_entry_drag_begin (GtkWidget *widget,
428 GdkDragContext *context);
429 static void gtk_entry_drag_end (GtkWidget *widget,
430 GdkDragContext *context);
433 /* GtkEditable method implementations
435 static void gtk_entry_insert_text (GtkEditable *editable,
436 const gchar *new_text,
437 gint new_text_length,
439 static void gtk_entry_delete_text (GtkEditable *editable,
442 static gchar * gtk_entry_get_chars (GtkEditable *editable,
445 static void gtk_entry_real_set_position (GtkEditable *editable,
447 static gint gtk_entry_get_position (GtkEditable *editable);
448 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
451 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
455 /* GtkCellEditable method implementations
457 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
460 /* Default signal handlers
462 static void gtk_entry_real_insert_text (GtkEditable *editable,
463 const gchar *new_text,
464 gint new_text_length,
466 static void gtk_entry_real_delete_text (GtkEditable *editable,
469 static void gtk_entry_move_cursor (GtkEntry *entry,
470 GtkMovementStep step,
472 gboolean extend_selection);
473 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
475 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
478 static void gtk_entry_backspace (GtkEntry *entry);
479 static void gtk_entry_cut_clipboard (GtkEntry *entry);
480 static void gtk_entry_copy_clipboard (GtkEntry *entry);
481 static void gtk_entry_paste_clipboard (GtkEntry *entry);
482 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
483 static void gtk_entry_select_all (GtkEntry *entry);
484 static void gtk_entry_real_activate (GtkEntry *entry);
485 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
487 static void keymap_direction_changed (GdkKeymap *keymap,
489 static void keymap_state_changed (GdkKeymap *keymap,
491 static void remove_capslock_feedback (GtkEntry *entry);
493 /* IM Context Callbacks
495 static void gtk_entry_commit_cb (GtkIMContext *context,
498 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
500 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
502 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
509 static void gtk_entry_enter_text (GtkEntry *entry,
511 static void gtk_entry_set_positions (GtkEntry *entry,
513 gint selection_bound);
514 static void gtk_entry_draw_text (GtkEntry *entry,
516 static void gtk_entry_draw_cursor (GtkEntry *entry,
519 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
520 gboolean include_preedit);
521 static void gtk_entry_reset_layout (GtkEntry *entry);
522 static void gtk_entry_recompute (GtkEntry *entry);
523 static gint gtk_entry_find_position (GtkEntry *entry,
525 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
529 static void gtk_entry_adjust_scroll (GtkEntry *entry);
530 static gint gtk_entry_move_visually (GtkEntry *editable,
533 static gint gtk_entry_move_logically (GtkEntry *entry,
536 static gint gtk_entry_move_forward_word (GtkEntry *entry,
538 gboolean allow_whitespace);
539 static gint gtk_entry_move_backward_word (GtkEntry *entry,
541 gboolean allow_whitespace);
542 static void gtk_entry_delete_whitespace (GtkEntry *entry);
543 static void gtk_entry_select_word (GtkEntry *entry);
544 static void gtk_entry_select_line (GtkEntry *entry);
545 static void gtk_entry_paste (GtkEntry *entry,
547 static void gtk_entry_update_primary_selection (GtkEntry *entry);
548 static void gtk_entry_do_popup (GtkEntry *entry,
549 GdkEventButton *event);
550 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
551 gboolean group_cycling);
552 static void gtk_entry_grab_notify (GtkWidget *widget,
553 gboolean was_grabbed);
554 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
555 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
556 static void gtk_entry_reset_blink_time (GtkEntry *entry);
557 static void gtk_entry_get_text_area_size (GtkEntry *entry,
562 static void get_text_area_size (GtkEntry *entry,
567 static void get_frame_size (GtkEntry *entry,
568 gboolean relative_to_window,
573 static void gtk_entry_move_adjustments (GtkEntry *entry);
574 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
575 GtkEntryIconPosition icon_pos);
576 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
577 static gboolean get_middle_click_paste (GtkEntry *entry);
580 static gint gtk_entry_completion_timeout (gpointer data);
581 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
584 static void gtk_entry_completion_changed (GtkWidget *entry,
586 static gboolean check_completion_callback (GtkEntryCompletion *completion);
587 static void clear_completion_callback (GtkEntry *entry,
589 static gboolean accept_completion_callback (GtkEntry *entry);
590 static void completion_insert_text_callback (GtkEntry *entry,
594 GtkEntryCompletion *completion);
595 static void completion_changed (GtkEntryCompletion *completion,
598 static void disconnect_completion_signals (GtkEntry *entry,
599 GtkEntryCompletion *completion);
600 static void connect_completion_signals (GtkEntry *entry,
601 GtkEntryCompletion *completion);
603 static void begin_change (GtkEntry *entry);
604 static void end_change (GtkEntry *entry);
605 static void emit_changed (GtkEntry *entry);
607 static void buffer_inserted_text (GtkEntryBuffer *buffer,
612 static void buffer_deleted_text (GtkEntryBuffer *buffer,
616 static void buffer_notify_text (GtkEntryBuffer *buffer,
619 static void buffer_notify_length (GtkEntryBuffer *buffer,
622 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
625 static void buffer_connect_signals (GtkEntry *entry);
626 static void buffer_disconnect_signals (GtkEntry *entry);
627 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
629 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
630 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
631 gtk_entry_editable_init)
632 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
633 gtk_entry_cell_editable_init))
636 add_move_binding (GtkBindingSet *binding_set,
639 GtkMovementStep step,
642 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
644 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
648 G_TYPE_BOOLEAN, FALSE);
650 /* Selection-extending version */
651 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
655 G_TYPE_BOOLEAN, TRUE);
659 gtk_entry_class_init (GtkEntryClass *class)
661 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
662 GtkWidgetClass *widget_class;
663 GtkBindingSet *binding_set;
665 widget_class = (GtkWidgetClass*) class;
667 gobject_class->dispose = gtk_entry_dispose;
668 gobject_class->finalize = gtk_entry_finalize;
669 gobject_class->set_property = gtk_entry_set_property;
670 gobject_class->get_property = gtk_entry_get_property;
672 widget_class->destroy = gtk_entry_destroy;
673 widget_class->map = gtk_entry_map;
674 widget_class->unmap = gtk_entry_unmap;
675 widget_class->realize = gtk_entry_realize;
676 widget_class->unrealize = gtk_entry_unrealize;
677 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
678 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
679 widget_class->size_allocate = gtk_entry_size_allocate;
680 widget_class->draw = gtk_entry_draw;
681 widget_class->enter_notify_event = gtk_entry_enter_notify;
682 widget_class->leave_notify_event = gtk_entry_leave_notify;
683 widget_class->button_press_event = gtk_entry_button_press;
684 widget_class->button_release_event = gtk_entry_button_release;
685 widget_class->motion_notify_event = gtk_entry_motion_notify;
686 widget_class->key_press_event = gtk_entry_key_press;
687 widget_class->key_release_event = gtk_entry_key_release;
688 widget_class->focus_in_event = gtk_entry_focus_in;
689 widget_class->focus_out_event = gtk_entry_focus_out;
690 widget_class->grab_focus = gtk_entry_grab_focus;
691 widget_class->style_updated = gtk_entry_style_updated;
692 widget_class->query_tooltip = gtk_entry_query_tooltip;
693 widget_class->drag_begin = gtk_entry_drag_begin;
694 widget_class->drag_end = gtk_entry_drag_end;
695 widget_class->direction_changed = gtk_entry_direction_changed;
696 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
697 widget_class->screen_changed = gtk_entry_screen_changed;
698 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
699 widget_class->grab_notify = gtk_entry_grab_notify;
701 widget_class->drag_drop = gtk_entry_drag_drop;
702 widget_class->drag_motion = gtk_entry_drag_motion;
703 widget_class->drag_leave = gtk_entry_drag_leave;
704 widget_class->drag_data_received = gtk_entry_drag_data_received;
705 widget_class->drag_data_get = gtk_entry_drag_data_get;
706 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
708 widget_class->popup_menu = gtk_entry_popup_menu;
710 class->move_cursor = gtk_entry_move_cursor;
711 class->insert_at_cursor = gtk_entry_insert_at_cursor;
712 class->delete_from_cursor = gtk_entry_delete_from_cursor;
713 class->backspace = gtk_entry_backspace;
714 class->cut_clipboard = gtk_entry_cut_clipboard;
715 class->copy_clipboard = gtk_entry_copy_clipboard;
716 class->paste_clipboard = gtk_entry_paste_clipboard;
717 class->toggle_overwrite = gtk_entry_toggle_overwrite;
718 class->activate = gtk_entry_real_activate;
719 class->get_text_area_size = gtk_entry_get_text_area_size;
721 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
722 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
723 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
724 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
726 g_object_class_override_property (gobject_class,
727 PROP_EDITING_CANCELED,
730 g_object_class_install_property (gobject_class,
732 g_param_spec_object ("buffer",
734 P_("Text buffer object which actually stores entry text"),
735 GTK_TYPE_ENTRY_BUFFER,
736 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
738 g_object_class_install_property (gobject_class,
739 PROP_CURSOR_POSITION,
740 g_param_spec_int ("cursor-position",
741 P_("Cursor Position"),
742 P_("The current position of the insertion cursor in chars"),
744 GTK_ENTRY_BUFFER_MAX_SIZE,
746 GTK_PARAM_READABLE));
748 g_object_class_install_property (gobject_class,
749 PROP_SELECTION_BOUND,
750 g_param_spec_int ("selection-bound",
751 P_("Selection Bound"),
752 P_("The position of the opposite end of the selection from the cursor in chars"),
754 GTK_ENTRY_BUFFER_MAX_SIZE,
756 GTK_PARAM_READABLE));
758 g_object_class_install_property (gobject_class,
760 g_param_spec_boolean ("editable",
762 P_("Whether the entry contents can be edited"),
764 GTK_PARAM_READWRITE));
766 g_object_class_install_property (gobject_class,
768 g_param_spec_int ("max-length",
769 P_("Maximum length"),
770 P_("Maximum number of characters for this entry. Zero if no maximum"),
772 GTK_ENTRY_BUFFER_MAX_SIZE,
774 GTK_PARAM_READWRITE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_boolean ("visibility",
779 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
781 GTK_PARAM_READWRITE));
783 g_object_class_install_property (gobject_class,
785 g_param_spec_boolean ("has-frame",
787 P_("FALSE removes outside bevel from entry"),
789 GTK_PARAM_READWRITE));
792 * GtkEntry:inner-border:
794 * Sets the text area's border between the text and the frame.
796 * Deprecated: 3.4: Use the standard border and padding CSS properties
797 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
798 * of this style property is ignored.
800 g_object_class_install_property (gobject_class,
802 g_param_spec_boxed ("inner-border",
804 P_("Border between text and frame. Overrides the inner-border style property"),
806 GTK_PARAM_READWRITE |
807 G_PARAM_DEPRECATED));
809 g_object_class_install_property (gobject_class,
811 g_param_spec_unichar ("invisible-char",
812 P_("Invisible character"),
813 P_("The character to use when masking entry contents (in \"password mode\")"),
815 GTK_PARAM_READWRITE));
817 g_object_class_install_property (gobject_class,
818 PROP_ACTIVATES_DEFAULT,
819 g_param_spec_boolean ("activates-default",
820 P_("Activates default"),
821 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
823 GTK_PARAM_READWRITE));
824 g_object_class_install_property (gobject_class,
826 g_param_spec_int ("width-chars",
827 P_("Width in chars"),
828 P_("Number of characters to leave space for in the entry"),
832 GTK_PARAM_READWRITE));
834 g_object_class_install_property (gobject_class,
836 g_param_spec_int ("scroll-offset",
838 P_("Number of pixels of the entry scrolled off the screen to the left"),
842 GTK_PARAM_READABLE));
844 g_object_class_install_property (gobject_class,
846 g_param_spec_string ("text",
848 P_("The contents of the entry"),
850 GTK_PARAM_READWRITE));
855 * The horizontal alignment, from 0 (left) to 1 (right).
856 * Reversed for RTL layouts.
860 g_object_class_install_property (gobject_class,
862 g_param_spec_float ("xalign",
864 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
868 GTK_PARAM_READWRITE));
871 * GtkEntry:truncate-multiline:
873 * When %TRUE, pasted multi-line text is truncated to the first line.
877 g_object_class_install_property (gobject_class,
878 PROP_TRUNCATE_MULTILINE,
879 g_param_spec_boolean ("truncate-multiline",
880 P_("Truncate multiline"),
881 P_("Whether to truncate multiline pastes to one line."),
883 GTK_PARAM_READWRITE));
886 * GtkEntry:shadow-type:
888 * Which kind of shadow to draw around the entry when
889 * #GtkEntry:has-frame is set to %TRUE.
893 g_object_class_install_property (gobject_class,
895 g_param_spec_enum ("shadow-type",
897 P_("Which kind of shadow to draw around the entry when has-frame is set"),
898 GTK_TYPE_SHADOW_TYPE,
900 GTK_PARAM_READWRITE));
903 * GtkEntry:overwrite-mode:
905 * If text is overwritten when typing in the #GtkEntry.
909 g_object_class_install_property (gobject_class,
911 g_param_spec_boolean ("overwrite-mode",
912 P_("Overwrite mode"),
913 P_("Whether new text overwrites existing text"),
915 GTK_PARAM_READWRITE));
918 * GtkEntry:text-length:
920 * The length of the text in the #GtkEntry.
924 g_object_class_install_property (gobject_class,
926 g_param_spec_uint ("text-length",
928 P_("Length of the text currently in the entry"),
932 GTK_PARAM_READABLE));
934 * GtkEntry:invisible-char-set:
936 * Whether the invisible char has been set for the #GtkEntry.
940 g_object_class_install_property (gobject_class,
941 PROP_INVISIBLE_CHAR_SET,
942 g_param_spec_boolean ("invisible-char-set",
943 P_("Invisible character set"),
944 P_("Whether the invisible character has been set"),
946 GTK_PARAM_READWRITE));
949 * GtkEntry:caps-lock-warning:
951 * Whether password entries will show a warning when Caps Lock is on.
953 * Note that the warning is shown using a secondary icon, and thus
954 * does not work if you are using the secondary icon position for some
959 g_object_class_install_property (gobject_class,
960 PROP_CAPS_LOCK_WARNING,
961 g_param_spec_boolean ("caps-lock-warning",
962 P_("Caps Lock warning"),
963 P_("Whether password entries will show a warning when Caps Lock is on"),
965 GTK_PARAM_READWRITE));
968 * GtkEntry:progress-fraction:
970 * The current fraction of the task that's been completed.
974 g_object_class_install_property (gobject_class,
975 PROP_PROGRESS_FRACTION,
976 g_param_spec_double ("progress-fraction",
977 P_("Progress Fraction"),
978 P_("The current fraction of the task that's been completed"),
982 GTK_PARAM_READWRITE));
985 * GtkEntry:progress-pulse-step:
987 * The fraction of total entry width to move the progress
988 * bouncing block for each call to gtk_entry_progress_pulse().
992 g_object_class_install_property (gobject_class,
993 PROP_PROGRESS_PULSE_STEP,
994 g_param_spec_double ("progress-pulse-step",
995 P_("Progress Pulse Step"),
996 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
1000 GTK_PARAM_READWRITE));
1003 * GtkEntry:placeholder-text:
1005 * The text that will be displayed in the #GtkEntry when it is empty
1010 g_object_class_install_property (gobject_class,
1011 PROP_PLACEHOLDER_TEXT,
1012 g_param_spec_string ("placeholder-text",
1013 P_("Placeholder text"),
1014 P_("Show text in the entry when it's empty and unfocused"),
1016 GTK_PARAM_READWRITE));
1019 * GtkEntry:primary-icon-pixbuf:
1021 * A pixbuf to use as the primary icon for the entry.
1025 g_object_class_install_property (gobject_class,
1026 PROP_PIXBUF_PRIMARY,
1027 g_param_spec_object ("primary-icon-pixbuf",
1028 P_("Primary pixbuf"),
1029 P_("Primary pixbuf for the entry"),
1031 GTK_PARAM_READWRITE));
1034 * GtkEntry:secondary-icon-pixbuf:
1036 * An pixbuf to use as the secondary icon for the entry.
1040 g_object_class_install_property (gobject_class,
1041 PROP_PIXBUF_SECONDARY,
1042 g_param_spec_object ("secondary-icon-pixbuf",
1043 P_("Secondary pixbuf"),
1044 P_("Secondary pixbuf for the entry"),
1046 GTK_PARAM_READWRITE));
1049 * GtkEntry:primary-icon-stock:
1051 * The stock id to use for the primary icon for the entry.
1055 g_object_class_install_property (gobject_class,
1057 g_param_spec_string ("primary-icon-stock",
1058 P_("Primary stock ID"),
1059 P_("Stock ID for primary icon"),
1061 GTK_PARAM_READWRITE));
1064 * GtkEntry:secondary-icon-stock:
1066 * The stock id to use for the secondary icon for the entry.
1070 g_object_class_install_property (gobject_class,
1071 PROP_STOCK_SECONDARY,
1072 g_param_spec_string ("secondary-icon-stock",
1073 P_("Secondary stock ID"),
1074 P_("Stock ID for secondary icon"),
1076 GTK_PARAM_READWRITE));
1079 * GtkEntry:primary-icon-name:
1081 * The icon name to use for the primary icon for the entry.
1085 g_object_class_install_property (gobject_class,
1086 PROP_ICON_NAME_PRIMARY,
1087 g_param_spec_string ("primary-icon-name",
1088 P_("Primary icon name"),
1089 P_("Icon name for primary icon"),
1091 GTK_PARAM_READWRITE));
1094 * GtkEntry:secondary-icon-name:
1096 * The icon name to use for the secondary icon for the entry.
1100 g_object_class_install_property (gobject_class,
1101 PROP_ICON_NAME_SECONDARY,
1102 g_param_spec_string ("secondary-icon-name",
1103 P_("Secondary icon name"),
1104 P_("Icon name for secondary icon"),
1106 GTK_PARAM_READWRITE));
1109 * GtkEntry:primary-icon-gicon:
1111 * The #GIcon to use for the primary icon for the entry.
1115 g_object_class_install_property (gobject_class,
1117 g_param_spec_object ("primary-icon-gicon",
1118 P_("Primary GIcon"),
1119 P_("GIcon for primary icon"),
1121 GTK_PARAM_READWRITE));
1124 * GtkEntry:secondary-icon-gicon:
1126 * The #GIcon to use for the secondary icon for the entry.
1130 g_object_class_install_property (gobject_class,
1131 PROP_GICON_SECONDARY,
1132 g_param_spec_object ("secondary-icon-gicon",
1133 P_("Secondary GIcon"),
1134 P_("GIcon for secondary icon"),
1136 GTK_PARAM_READWRITE));
1139 * GtkEntry:primary-icon-storage-type:
1141 * The representation which is used for the primary icon of the entry.
1145 g_object_class_install_property (gobject_class,
1146 PROP_STORAGE_TYPE_PRIMARY,
1147 g_param_spec_enum ("primary-icon-storage-type",
1148 P_("Primary storage type"),
1149 P_("The representation being used for primary icon"),
1150 GTK_TYPE_IMAGE_TYPE,
1152 GTK_PARAM_READABLE));
1155 * GtkEntry:secondary-icon-storage-type:
1157 * The representation which is used for the secondary icon of the entry.
1161 g_object_class_install_property (gobject_class,
1162 PROP_STORAGE_TYPE_SECONDARY,
1163 g_param_spec_enum ("secondary-icon-storage-type",
1164 P_("Secondary storage type"),
1165 P_("The representation being used for secondary icon"),
1166 GTK_TYPE_IMAGE_TYPE,
1168 GTK_PARAM_READABLE));
1171 * GtkEntry:primary-icon-activatable:
1173 * Whether the primary icon is activatable.
1175 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1176 * signals only on sensitive, activatable icons.
1178 * Sensitive, but non-activatable icons can be used for purely
1179 * informational purposes.
1183 g_object_class_install_property (gobject_class,
1184 PROP_ACTIVATABLE_PRIMARY,
1185 g_param_spec_boolean ("primary-icon-activatable",
1186 P_("Primary icon activatable"),
1187 P_("Whether the primary icon is activatable"),
1189 GTK_PARAM_READWRITE));
1192 * GtkEntry:secondary-icon-activatable:
1194 * Whether the secondary icon is activatable.
1196 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1197 * signals only on sensitive, activatable icons.
1199 * Sensitive, but non-activatable icons can be used for purely
1200 * informational purposes.
1204 g_object_class_install_property (gobject_class,
1205 PROP_ACTIVATABLE_SECONDARY,
1206 g_param_spec_boolean ("secondary-icon-activatable",
1207 P_("Secondary icon activatable"),
1208 P_("Whether the secondary icon is activatable"),
1210 GTK_PARAM_READWRITE));
1214 * GtkEntry:primary-icon-sensitive:
1216 * Whether the primary icon is sensitive.
1218 * An insensitive icon appears grayed out. GTK+ does not emit the
1219 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1220 * does not allow DND from insensitive icons.
1222 * An icon should be set insensitive if the action that would trigger
1223 * when clicked is currently not available.
1227 g_object_class_install_property (gobject_class,
1228 PROP_SENSITIVE_PRIMARY,
1229 g_param_spec_boolean ("primary-icon-sensitive",
1230 P_("Primary icon sensitive"),
1231 P_("Whether the primary icon is sensitive"),
1233 GTK_PARAM_READWRITE));
1236 * GtkEntry:secondary-icon-sensitive:
1238 * Whether the secondary icon is sensitive.
1240 * An insensitive icon appears grayed out. GTK+ does not emit the
1241 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1242 * does not allow DND from insensitive icons.
1244 * An icon should be set insensitive if the action that would trigger
1245 * when clicked is currently not available.
1249 g_object_class_install_property (gobject_class,
1250 PROP_SENSITIVE_SECONDARY,
1251 g_param_spec_boolean ("secondary-icon-sensitive",
1252 P_("Secondary icon sensitive"),
1253 P_("Whether the secondary icon is sensitive"),
1255 GTK_PARAM_READWRITE));
1258 * GtkEntry:primary-icon-tooltip-text:
1260 * The contents of the tooltip on the primary icon.
1262 * Also see gtk_entry_set_icon_tooltip_text().
1266 g_object_class_install_property (gobject_class,
1267 PROP_TOOLTIP_TEXT_PRIMARY,
1268 g_param_spec_string ("primary-icon-tooltip-text",
1269 P_("Primary icon tooltip text"),
1270 P_("The contents of the tooltip on the primary icon"),
1272 GTK_PARAM_READWRITE));
1275 * GtkEntry:secondary-icon-tooltip-text:
1277 * The contents of the tooltip on the secondary icon.
1279 * Also see gtk_entry_set_icon_tooltip_text().
1283 g_object_class_install_property (gobject_class,
1284 PROP_TOOLTIP_TEXT_SECONDARY,
1285 g_param_spec_string ("secondary-icon-tooltip-text",
1286 P_("Secondary icon tooltip text"),
1287 P_("The contents of the tooltip on the secondary icon"),
1289 GTK_PARAM_READWRITE));
1292 * GtkEntry:primary-icon-tooltip-markup:
1294 * The contents of the tooltip on the primary icon, which is marked up
1295 * with the <link linkend="PangoMarkupFormat">Pango text markup
1298 * Also see gtk_entry_set_icon_tooltip_markup().
1302 g_object_class_install_property (gobject_class,
1303 PROP_TOOLTIP_MARKUP_PRIMARY,
1304 g_param_spec_string ("primary-icon-tooltip-markup",
1305 P_("Primary icon tooltip markup"),
1306 P_("The contents of the tooltip on the primary icon"),
1308 GTK_PARAM_READWRITE));
1311 * GtkEntry:secondary-icon-tooltip-markup:
1313 * The contents of the tooltip on the secondary icon, which is marked up
1314 * with the <link linkend="PangoMarkupFormat">Pango text markup
1317 * Also see gtk_entry_set_icon_tooltip_markup().
1321 g_object_class_install_property (gobject_class,
1322 PROP_TOOLTIP_MARKUP_SECONDARY,
1323 g_param_spec_string ("secondary-icon-tooltip-markup",
1324 P_("Secondary icon tooltip markup"),
1325 P_("The contents of the tooltip on the secondary icon"),
1327 GTK_PARAM_READWRITE));
1330 * GtkEntry:im-module:
1332 * Which IM (input method) module should be used for this entry.
1333 * See #GtkIMContext.
1335 * Setting this to a non-%NULL value overrides the
1336 * system-wide IM module setting. See the GtkSettings
1337 * #GtkSettings:gtk-im-module property.
1341 g_object_class_install_property (gobject_class,
1343 g_param_spec_string ("im-module",
1345 P_("Which IM module should be used"),
1347 GTK_PARAM_READWRITE));
1350 * GtkEntry:completion:
1352 * The auxiliary completion object to use with the entry.
1356 g_object_class_install_property (gobject_class,
1358 g_param_spec_object ("completion",
1360 P_("The auxiliary completion object"),
1361 GTK_TYPE_ENTRY_COMPLETION,
1362 GTK_PARAM_READWRITE));
1365 * GtkEntry:input-purpose:
1367 * The purpose of this text field.
1369 * This property can be used by on-screen keyboards and other input
1370 * methods to adjust their behaviour.
1372 * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
1373 * %GTK_INPUT_PURPOSE_PIN is independent from setting
1374 * #GtkEntry:visibility.
1378 g_object_class_install_property (gobject_class,
1380 g_param_spec_enum ("input-purpose",
1382 P_("Purpose of the text field"),
1383 GTK_TYPE_INPUT_PURPOSE,
1384 GTK_INPUT_PURPOSE_FREE_FORM,
1385 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1388 * GtkEntry:input-hints:
1390 * Additional hints (beyond #GtkEntry:input-purpose) that
1391 * allow input methods to fine-tune their behaviour.
1395 g_object_class_install_property (gobject_class,
1397 g_param_spec_flags ("input-hints",
1399 P_("Hints for the text field behaviour"),
1400 GTK_TYPE_INPUT_HINTS,
1401 GTK_INPUT_HINT_NONE,
1402 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1406 * GtkEntry:icon-prelight:
1408 * The prelight style property determines whether activatable
1409 * icons prelight on mouseover.
1413 gtk_widget_class_install_style_property (widget_class,
1414 g_param_spec_boolean ("icon-prelight",
1415 P_("Icon Prelight"),
1416 P_("Whether activatable icons should prelight when hovered"),
1418 GTK_PARAM_READABLE));
1421 * GtkEntry:progress-border:
1423 * The border around the progress bar in the entry.
1427 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1428 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1429 * property is ignored.
1431 gtk_widget_class_install_style_property (widget_class,
1432 g_param_spec_boxed ("progress-border",
1433 P_("Progress Border"),
1434 P_("Border around the progress bar"),
1436 GTK_PARAM_READABLE |
1437 G_PARAM_DEPRECATED));
1440 * GtkEntry:invisible-char:
1442 * The invisible character is used when masking entry contents (in
1443 * \"password mode\")"). When it is not explicitly set with the
1444 * #GtkEntry:invisible-char property, GTK+ determines the character
1445 * to use from a list of possible candidates, depending on availability
1446 * in the current font.
1448 * This style property allows the theme to prepend a character
1449 * to the list of candidates.
1453 gtk_widget_class_install_style_property (widget_class,
1454 g_param_spec_unichar ("invisible-char",
1455 P_("Invisible character"),
1456 P_("The character to use when masking entry contents (in \"password mode\")"),
1458 GTK_PARAM_READABLE));
1461 * GtkEntry::populate-popup:
1462 * @entry: The entry on which the signal is emitted
1463 * @menu: the menu that is being populated
1465 * The ::populate-popup signal gets emitted before showing the
1466 * context menu of the entry.
1468 * If you need to add items to the context menu, connect
1469 * to this signal and append your menuitems to the @menu.
1471 signals[POPULATE_POPUP] =
1472 g_signal_new (I_("populate-popup"),
1473 G_OBJECT_CLASS_TYPE (gobject_class),
1475 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1477 _gtk_marshal_VOID__OBJECT,
1481 /* Action signals */
1484 * GtkEntry::activate:
1485 * @entry: The entry on which the signal is emitted
1487 * The ::activate signal is emitted when the user hits
1490 * While this signal is used as a
1491 * <link linkend="keybinding-signals">keybinding signal</link>,
1492 * it is also commonly used by applications to intercept
1493 * activation of entries.
1495 * The default bindings for this signal are all forms of the Enter key.
1498 g_signal_new (I_("activate"),
1499 G_OBJECT_CLASS_TYPE (gobject_class),
1500 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1501 G_STRUCT_OFFSET (GtkEntryClass, activate),
1503 _gtk_marshal_VOID__VOID,
1505 widget_class->activate_signal = signals[ACTIVATE];
1508 * GtkEntry::move-cursor:
1509 * @entry: the object which received the signal
1510 * @step: the granularity of the move, as a #GtkMovementStep
1511 * @count: the number of @step units to move
1512 * @extend_selection: %TRUE if the move should extend the selection
1514 * The ::move-cursor signal is a
1515 * <link linkend="keybinding-signals">keybinding signal</link>
1516 * which gets emitted when the user initiates a cursor movement.
1517 * If the cursor is not visible in @entry, this signal causes
1518 * the viewport to be moved instead.
1520 * Applications should not connect to it, but may emit it with
1521 * g_signal_emit_by_name() if they need to control the cursor
1524 * The default bindings for this signal come in two variants,
1525 * the variant with the Shift modifier extends the selection,
1526 * the variant without the Shift modifer does not.
1527 * There are too many key combinations to list them all here.
1529 * <listitem>Arrow keys move by individual characters/lines</listitem>
1530 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1531 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1534 signals[MOVE_CURSOR] =
1535 g_signal_new (I_("move-cursor"),
1536 G_OBJECT_CLASS_TYPE (gobject_class),
1537 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1538 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1540 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1542 GTK_TYPE_MOVEMENT_STEP,
1547 * GtkEntry::insert-at-cursor:
1548 * @entry: the object which received the signal
1549 * @string: the string to insert
1551 * The ::insert-at-cursor signal is a
1552 * <link linkend="keybinding-signals">keybinding signal</link>
1553 * which gets emitted when the user initiates the insertion of a
1554 * fixed string at the cursor.
1556 * This signal has no default bindings.
1558 signals[INSERT_AT_CURSOR] =
1559 g_signal_new (I_("insert-at-cursor"),
1560 G_OBJECT_CLASS_TYPE (gobject_class),
1561 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1562 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1564 _gtk_marshal_VOID__STRING,
1569 * GtkEntry::delete-from-cursor:
1570 * @entry: the object which received the signal
1571 * @type: the granularity of the deletion, as a #GtkDeleteType
1572 * @count: the number of @type units to delete
1574 * The ::delete-from-cursor signal is a
1575 * <link linkend="keybinding-signals">keybinding signal</link>
1576 * which gets emitted when the user initiates a text deletion.
1578 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1579 * if there is one, otherwise it deletes the requested number
1582 * The default bindings for this signal are
1583 * Delete for deleting a character and Ctrl-Delete for
1586 signals[DELETE_FROM_CURSOR] =
1587 g_signal_new (I_("delete-from-cursor"),
1588 G_OBJECT_CLASS_TYPE (gobject_class),
1589 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1590 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1592 _gtk_marshal_VOID__ENUM_INT,
1594 GTK_TYPE_DELETE_TYPE,
1598 * GtkEntry::backspace:
1599 * @entry: the object which received the signal
1601 * The ::backspace signal is a
1602 * <link linkend="keybinding-signals">keybinding signal</link>
1603 * which gets emitted when the user asks for it.
1605 * The default bindings for this signal are
1606 * Backspace and Shift-Backspace.
1608 signals[BACKSPACE] =
1609 g_signal_new (I_("backspace"),
1610 G_OBJECT_CLASS_TYPE (gobject_class),
1611 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1612 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1614 _gtk_marshal_VOID__VOID,
1618 * GtkEntry::cut-clipboard:
1619 * @entry: the object which received the signal
1621 * The ::cut-clipboard signal is a
1622 * <link linkend="keybinding-signals">keybinding signal</link>
1623 * which gets emitted to cut the selection to the clipboard.
1625 * The default bindings for this signal are
1626 * Ctrl-x and Shift-Delete.
1628 signals[CUT_CLIPBOARD] =
1629 g_signal_new (I_("cut-clipboard"),
1630 G_OBJECT_CLASS_TYPE (gobject_class),
1631 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1632 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1634 _gtk_marshal_VOID__VOID,
1638 * GtkEntry::copy-clipboard:
1639 * @entry: the object which received the signal
1641 * The ::copy-clipboard signal is a
1642 * <link linkend="keybinding-signals">keybinding signal</link>
1643 * which gets emitted to copy the selection to the clipboard.
1645 * The default bindings for this signal are
1646 * Ctrl-c and Ctrl-Insert.
1648 signals[COPY_CLIPBOARD] =
1649 g_signal_new (I_("copy-clipboard"),
1650 G_OBJECT_CLASS_TYPE (gobject_class),
1651 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1652 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1654 _gtk_marshal_VOID__VOID,
1658 * GtkEntry::paste-clipboard:
1659 * @entry: the object which received the signal
1661 * The ::paste-clipboard signal is a
1662 * <link linkend="keybinding-signals">keybinding signal</link>
1663 * which gets emitted to paste the contents of the clipboard
1664 * into the text view.
1666 * The default bindings for this signal are
1667 * Ctrl-v and Shift-Insert.
1669 signals[PASTE_CLIPBOARD] =
1670 g_signal_new (I_("paste-clipboard"),
1671 G_OBJECT_CLASS_TYPE (gobject_class),
1672 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1673 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1675 _gtk_marshal_VOID__VOID,
1679 * GtkEntry::toggle-overwrite:
1680 * @entry: the object which received the signal
1682 * The ::toggle-overwrite signal is a
1683 * <link linkend="keybinding-signals">keybinding signal</link>
1684 * which gets emitted to toggle the overwrite mode of the entry.
1686 * The default bindings for this signal is Insert.
1688 signals[TOGGLE_OVERWRITE] =
1689 g_signal_new (I_("toggle-overwrite"),
1690 G_OBJECT_CLASS_TYPE (gobject_class),
1691 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1692 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1694 _gtk_marshal_VOID__VOID,
1698 * GtkEntry::icon-press:
1699 * @entry: The entry on which the signal is emitted
1700 * @icon_pos: The position of the clicked icon
1701 * @event: (type Gdk.EventButton): the button press event
1703 * The ::icon-press signal is emitted when an activatable icon
1708 signals[ICON_PRESS] =
1709 g_signal_new (I_("icon-press"),
1710 G_TYPE_FROM_CLASS (gobject_class),
1714 _gtk_marshal_VOID__ENUM_BOXED,
1716 GTK_TYPE_ENTRY_ICON_POSITION,
1717 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1720 * GtkEntry::icon-release:
1721 * @entry: The entry on which the signal is emitted
1722 * @icon_pos: The position of the clicked icon
1723 * @event: (type Gdk.EventButton): the button release event
1725 * The ::icon-release signal is emitted on the button release from a
1726 * mouse click over an activatable icon.
1730 signals[ICON_RELEASE] =
1731 g_signal_new (I_("icon-release"),
1732 G_TYPE_FROM_CLASS (gobject_class),
1736 _gtk_marshal_VOID__ENUM_BOXED,
1738 GTK_TYPE_ENTRY_ICON_POSITION,
1739 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1742 * GtkEntry::preedit-changed:
1743 * @entry: the object which received the signal
1744 * @preedit: the current preedit string
1746 * If an input method is used, the typed text will not immediately
1747 * be committed to the buffer. So if you are interested in the text,
1748 * connect to this signal.
1752 signals[PREEDIT_CHANGED] =
1753 g_signal_new_class_handler (I_("preedit-changed"),
1754 G_OBJECT_CLASS_TYPE (gobject_class),
1755 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1758 _gtk_marshal_VOID__STRING,
1767 binding_set = gtk_binding_set_by_class (class);
1769 /* Moving the insertion point */
1770 add_move_binding (binding_set, GDK_KEY_Right, 0,
1771 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1773 add_move_binding (binding_set, GDK_KEY_Left, 0,
1774 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1776 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1777 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1779 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1780 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1782 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1783 GTK_MOVEMENT_WORDS, 1);
1785 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1786 GTK_MOVEMENT_WORDS, -1);
1788 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1789 GTK_MOVEMENT_WORDS, 1);
1791 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1792 GTK_MOVEMENT_WORDS, -1);
1794 add_move_binding (binding_set, GDK_KEY_Home, 0,
1795 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1797 add_move_binding (binding_set, GDK_KEY_End, 0,
1798 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1800 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1801 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1803 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1804 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1806 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1807 GTK_MOVEMENT_BUFFER_ENDS, -1);
1809 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1810 GTK_MOVEMENT_BUFFER_ENDS, 1);
1812 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1813 GTK_MOVEMENT_BUFFER_ENDS, -1);
1815 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1816 GTK_MOVEMENT_BUFFER_ENDS, 1);
1820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1822 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1824 G_TYPE_BOOLEAN, FALSE);
1825 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1827 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1829 G_TYPE_BOOLEAN, TRUE);
1831 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1833 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1835 G_TYPE_BOOLEAN, FALSE);
1836 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1838 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1840 G_TYPE_BOOLEAN, TRUE);
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1845 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1847 G_TYPE_BOOLEAN, FALSE);
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1850 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1852 G_TYPE_BOOLEAN, FALSE);
1856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1858 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1860 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1864 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1865 "delete-from-cursor", 2,
1866 G_TYPE_ENUM, GTK_DELETE_CHARS,
1869 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1870 "delete-from-cursor", 2,
1871 G_TYPE_ENUM, GTK_DELETE_CHARS,
1874 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1877 /* Make this do the same as Backspace, to help with mis-typing */
1878 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1881 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1882 "delete-from-cursor", 2,
1883 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1886 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1887 "delete-from-cursor", 2,
1888 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1891 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1892 "delete-from-cursor", 2,
1893 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1896 /* Cut/copy/paste */
1898 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1899 "cut-clipboard", 0);
1900 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1901 "copy-clipboard", 0);
1902 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1903 "paste-clipboard", 0);
1905 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1906 "cut-clipboard", 0);
1907 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1908 "copy-clipboard", 0);
1909 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1910 "paste-clipboard", 0);
1913 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1914 "toggle-overwrite", 0);
1915 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1916 "toggle-overwrite", 0);
1919 * GtkEntry:inner-border:
1921 * Sets the text area's border between the text and the frame.
1925 * Deprecated: 3.4: Use the standard border and padding CSS properties
1926 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1927 * of this style property is ignored.
1929 gtk_widget_class_install_style_property (widget_class,
1930 g_param_spec_boxed ("inner-border",
1932 P_("Border between text and frame."),
1934 GTK_PARAM_READABLE |
1935 G_PARAM_DEPRECATED));
1937 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1939 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1943 gtk_entry_editable_init (GtkEditableInterface *iface)
1945 iface->do_insert_text = gtk_entry_insert_text;
1946 iface->do_delete_text = gtk_entry_delete_text;
1947 iface->insert_text = gtk_entry_real_insert_text;
1948 iface->delete_text = gtk_entry_real_delete_text;
1949 iface->get_chars = gtk_entry_get_chars;
1950 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1951 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1952 iface->set_position = gtk_entry_real_set_position;
1953 iface->get_position = gtk_entry_get_position;
1957 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1959 iface->start_editing = gtk_entry_start_editing;
1962 /* for deprecated properties */
1964 gtk_entry_do_set_inner_border (GtkEntry *entry,
1965 const GtkBorder *border)
1968 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1969 gtk_border_copy (border),
1970 (GDestroyNotify) gtk_border_free);
1972 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1974 g_object_notify (G_OBJECT (entry), "inner-border");
1977 static const GtkBorder *
1978 gtk_entry_do_get_inner_border (GtkEntry *entry)
1980 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1984 gtk_entry_set_property (GObject *object,
1986 const GValue *value,
1989 GtkEntry *entry = GTK_ENTRY (object);
1990 GtkEntryPrivate *priv = entry->priv;
1995 gtk_entry_set_buffer (entry, g_value_get_object (value));
2000 gboolean new_value = g_value_get_boolean (value);
2002 if (new_value != priv->editable)
2004 GtkWidget *widget = GTK_WIDGET (entry);
2008 _gtk_entry_reset_im_context (entry);
2009 if (gtk_widget_has_focus (widget))
2010 gtk_im_context_focus_out (priv->im_context);
2012 priv->preedit_length = 0;
2013 priv->preedit_cursor = 0;
2016 priv->editable = new_value;
2018 if (new_value && gtk_widget_has_focus (widget))
2019 gtk_im_context_focus_in (priv->im_context);
2021 gtk_widget_queue_draw (widget);
2026 case PROP_MAX_LENGTH:
2027 gtk_entry_set_max_length (entry, g_value_get_int (value));
2030 case PROP_VISIBILITY:
2031 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
2034 case PROP_HAS_FRAME:
2035 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
2038 case PROP_INNER_BORDER:
2039 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
2042 case PROP_INVISIBLE_CHAR:
2043 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2046 case PROP_ACTIVATES_DEFAULT:
2047 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2050 case PROP_WIDTH_CHARS:
2051 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2055 gtk_entry_set_text (entry, g_value_get_string (value));
2059 gtk_entry_set_alignment (entry, g_value_get_float (value));
2062 case PROP_TRUNCATE_MULTILINE:
2063 priv->truncate_multiline = g_value_get_boolean (value);
2066 case PROP_SHADOW_TYPE:
2067 priv->shadow_type = g_value_get_enum (value);
2070 case PROP_OVERWRITE_MODE:
2071 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2074 case PROP_INVISIBLE_CHAR_SET:
2075 if (g_value_get_boolean (value))
2076 priv->invisible_char_set = TRUE;
2078 gtk_entry_unset_invisible_char (entry);
2081 case PROP_CAPS_LOCK_WARNING:
2082 priv->caps_lock_warning = g_value_get_boolean (value);
2085 case PROP_PROGRESS_FRACTION:
2086 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2089 case PROP_PROGRESS_PULSE_STEP:
2090 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2093 case PROP_PLACEHOLDER_TEXT:
2094 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2097 case PROP_PIXBUF_PRIMARY:
2098 gtk_entry_set_icon_from_pixbuf (entry,
2099 GTK_ENTRY_ICON_PRIMARY,
2100 g_value_get_object (value));
2103 case PROP_PIXBUF_SECONDARY:
2104 gtk_entry_set_icon_from_pixbuf (entry,
2105 GTK_ENTRY_ICON_SECONDARY,
2106 g_value_get_object (value));
2109 case PROP_STOCK_PRIMARY:
2110 gtk_entry_set_icon_from_stock (entry,
2111 GTK_ENTRY_ICON_PRIMARY,
2112 g_value_get_string (value));
2115 case PROP_STOCK_SECONDARY:
2116 gtk_entry_set_icon_from_stock (entry,
2117 GTK_ENTRY_ICON_SECONDARY,
2118 g_value_get_string (value));
2121 case PROP_ICON_NAME_PRIMARY:
2122 gtk_entry_set_icon_from_icon_name (entry,
2123 GTK_ENTRY_ICON_PRIMARY,
2124 g_value_get_string (value));
2127 case PROP_ICON_NAME_SECONDARY:
2128 gtk_entry_set_icon_from_icon_name (entry,
2129 GTK_ENTRY_ICON_SECONDARY,
2130 g_value_get_string (value));
2133 case PROP_GICON_PRIMARY:
2134 gtk_entry_set_icon_from_gicon (entry,
2135 GTK_ENTRY_ICON_PRIMARY,
2136 g_value_get_object (value));
2139 case PROP_GICON_SECONDARY:
2140 gtk_entry_set_icon_from_gicon (entry,
2141 GTK_ENTRY_ICON_SECONDARY,
2142 g_value_get_object (value));
2145 case PROP_ACTIVATABLE_PRIMARY:
2146 gtk_entry_set_icon_activatable (entry,
2147 GTK_ENTRY_ICON_PRIMARY,
2148 g_value_get_boolean (value));
2151 case PROP_ACTIVATABLE_SECONDARY:
2152 gtk_entry_set_icon_activatable (entry,
2153 GTK_ENTRY_ICON_SECONDARY,
2154 g_value_get_boolean (value));
2157 case PROP_SENSITIVE_PRIMARY:
2158 gtk_entry_set_icon_sensitive (entry,
2159 GTK_ENTRY_ICON_PRIMARY,
2160 g_value_get_boolean (value));
2163 case PROP_SENSITIVE_SECONDARY:
2164 gtk_entry_set_icon_sensitive (entry,
2165 GTK_ENTRY_ICON_SECONDARY,
2166 g_value_get_boolean (value));
2169 case PROP_TOOLTIP_TEXT_PRIMARY:
2170 gtk_entry_set_icon_tooltip_text (entry,
2171 GTK_ENTRY_ICON_PRIMARY,
2172 g_value_get_string (value));
2175 case PROP_TOOLTIP_TEXT_SECONDARY:
2176 gtk_entry_set_icon_tooltip_text (entry,
2177 GTK_ENTRY_ICON_SECONDARY,
2178 g_value_get_string (value));
2181 case PROP_TOOLTIP_MARKUP_PRIMARY:
2182 gtk_entry_set_icon_tooltip_markup (entry,
2183 GTK_ENTRY_ICON_PRIMARY,
2184 g_value_get_string (value));
2187 case PROP_TOOLTIP_MARKUP_SECONDARY:
2188 gtk_entry_set_icon_tooltip_markup (entry,
2189 GTK_ENTRY_ICON_SECONDARY,
2190 g_value_get_string (value));
2193 case PROP_IM_MODULE:
2194 g_free (priv->im_module);
2195 priv->im_module = g_value_dup_string (value);
2196 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2197 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2200 case PROP_EDITING_CANCELED:
2201 priv->editing_canceled = g_value_get_boolean (value);
2204 case PROP_COMPLETION:
2205 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2208 case PROP_INPUT_PURPOSE:
2209 gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
2212 case PROP_INPUT_HINTS:
2213 gtk_entry_set_input_hints (entry, g_value_get_flags (value));
2216 case PROP_SCROLL_OFFSET:
2217 case PROP_CURSOR_POSITION:
2219 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2225 gtk_entry_get_property (GObject *object,
2230 GtkEntry *entry = GTK_ENTRY (object);
2231 GtkEntryPrivate *priv = entry->priv;
2236 g_value_set_object (value, gtk_entry_get_buffer (entry));
2239 case PROP_CURSOR_POSITION:
2240 g_value_set_int (value, priv->current_pos);
2243 case PROP_SELECTION_BOUND:
2244 g_value_set_int (value, priv->selection_bound);
2248 g_value_set_boolean (value, priv->editable);
2251 case PROP_MAX_LENGTH:
2252 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2255 case PROP_VISIBILITY:
2256 g_value_set_boolean (value, priv->visible);
2259 case PROP_HAS_FRAME:
2260 g_value_set_boolean (value, priv->has_frame);
2263 case PROP_INNER_BORDER:
2264 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2267 case PROP_INVISIBLE_CHAR:
2268 g_value_set_uint (value, priv->invisible_char);
2271 case PROP_ACTIVATES_DEFAULT:
2272 g_value_set_boolean (value, priv->activates_default);
2275 case PROP_WIDTH_CHARS:
2276 g_value_set_int (value, priv->width_chars);
2279 case PROP_SCROLL_OFFSET:
2280 g_value_set_int (value, priv->scroll_offset);
2284 g_value_set_string (value, gtk_entry_get_text (entry));
2288 g_value_set_float (value, gtk_entry_get_alignment (entry));
2291 case PROP_TRUNCATE_MULTILINE:
2292 g_value_set_boolean (value, priv->truncate_multiline);
2295 case PROP_SHADOW_TYPE:
2296 g_value_set_enum (value, priv->shadow_type);
2299 case PROP_OVERWRITE_MODE:
2300 g_value_set_boolean (value, priv->overwrite_mode);
2303 case PROP_TEXT_LENGTH:
2304 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2307 case PROP_INVISIBLE_CHAR_SET:
2308 g_value_set_boolean (value, priv->invisible_char_set);
2311 case PROP_IM_MODULE:
2312 g_value_set_string (value, priv->im_module);
2315 case PROP_CAPS_LOCK_WARNING:
2316 g_value_set_boolean (value, priv->caps_lock_warning);
2319 case PROP_PROGRESS_FRACTION:
2320 g_value_set_double (value, priv->progress_fraction);
2323 case PROP_PROGRESS_PULSE_STEP:
2324 g_value_set_double (value, priv->progress_pulse_fraction);
2327 case PROP_PLACEHOLDER_TEXT:
2328 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2331 case PROP_PIXBUF_PRIMARY:
2332 g_value_set_object (value,
2333 gtk_entry_get_icon_pixbuf (entry,
2334 GTK_ENTRY_ICON_PRIMARY));
2337 case PROP_PIXBUF_SECONDARY:
2338 g_value_set_object (value,
2339 gtk_entry_get_icon_pixbuf (entry,
2340 GTK_ENTRY_ICON_SECONDARY));
2343 case PROP_STOCK_PRIMARY:
2344 g_value_set_string (value,
2345 gtk_entry_get_icon_stock (entry,
2346 GTK_ENTRY_ICON_PRIMARY));
2349 case PROP_STOCK_SECONDARY:
2350 g_value_set_string (value,
2351 gtk_entry_get_icon_stock (entry,
2352 GTK_ENTRY_ICON_SECONDARY));
2355 case PROP_ICON_NAME_PRIMARY:
2356 g_value_set_string (value,
2357 gtk_entry_get_icon_name (entry,
2358 GTK_ENTRY_ICON_PRIMARY));
2361 case PROP_ICON_NAME_SECONDARY:
2362 g_value_set_string (value,
2363 gtk_entry_get_icon_name (entry,
2364 GTK_ENTRY_ICON_SECONDARY));
2367 case PROP_GICON_PRIMARY:
2368 g_value_set_object (value,
2369 gtk_entry_get_icon_gicon (entry,
2370 GTK_ENTRY_ICON_PRIMARY));
2373 case PROP_GICON_SECONDARY:
2374 g_value_set_object (value,
2375 gtk_entry_get_icon_gicon (entry,
2376 GTK_ENTRY_ICON_SECONDARY));
2379 case PROP_STORAGE_TYPE_PRIMARY:
2380 g_value_set_enum (value,
2381 gtk_entry_get_icon_storage_type (entry,
2382 GTK_ENTRY_ICON_PRIMARY));
2385 case PROP_STORAGE_TYPE_SECONDARY:
2386 g_value_set_enum (value,
2387 gtk_entry_get_icon_storage_type (entry,
2388 GTK_ENTRY_ICON_SECONDARY));
2391 case PROP_ACTIVATABLE_PRIMARY:
2392 g_value_set_boolean (value,
2393 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2396 case PROP_ACTIVATABLE_SECONDARY:
2397 g_value_set_boolean (value,
2398 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2401 case PROP_SENSITIVE_PRIMARY:
2402 g_value_set_boolean (value,
2403 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2406 case PROP_SENSITIVE_SECONDARY:
2407 g_value_set_boolean (value,
2408 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2411 case PROP_TOOLTIP_TEXT_PRIMARY:
2412 g_value_take_string (value,
2413 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2416 case PROP_TOOLTIP_TEXT_SECONDARY:
2417 g_value_take_string (value,
2418 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2421 case PROP_TOOLTIP_MARKUP_PRIMARY:
2422 g_value_take_string (value,
2423 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2426 case PROP_TOOLTIP_MARKUP_SECONDARY:
2427 g_value_take_string (value,
2428 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2431 case PROP_EDITING_CANCELED:
2432 g_value_set_boolean (value,
2433 priv->editing_canceled);
2436 case PROP_COMPLETION:
2437 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2440 case PROP_INPUT_PURPOSE:
2441 g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
2444 case PROP_INPUT_HINTS:
2445 g_value_set_flags (value, gtk_entry_get_input_hints (entry));
2449 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2455 find_invisible_char (GtkWidget *widget)
2457 PangoLayout *layout;
2458 PangoAttrList *attr_list;
2460 gunichar invisible_chars [] = {
2462 0x25cf, /* BLACK CIRCLE */
2463 0x2022, /* BULLET */
2464 0x2731, /* HEAVY ASTERISK */
2465 0x273a /* SIXTEEN POINTED ASTERISK */
2468 gtk_widget_style_get (widget,
2469 "invisible-char", &invisible_chars[0],
2472 layout = gtk_widget_create_pango_layout (widget, NULL);
2474 attr_list = pango_attr_list_new ();
2475 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2477 pango_layout_set_attributes (layout, attr_list);
2478 pango_attr_list_unref (attr_list);
2480 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2482 gchar text[7] = { 0, };
2485 len = g_unichar_to_utf8 (invisible_chars[i], text);
2486 pango_layout_set_text (layout, text, len);
2488 count = pango_layout_get_unknown_glyphs_count (layout);
2492 g_object_unref (layout);
2493 return invisible_chars[i];
2497 g_object_unref (layout);
2503 gtk_entry_init (GtkEntry *entry)
2505 GtkStyleContext *context;
2506 GtkEntryPrivate *priv;
2508 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2513 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2514 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2516 priv->editable = TRUE;
2517 priv->visible = TRUE;
2518 priv->dnd_position = -1;
2519 priv->width_chars = -1;
2520 priv->is_cell_renderer = FALSE;
2521 priv->editing_canceled = FALSE;
2522 priv->has_frame = TRUE;
2523 priv->truncate_multiline = FALSE;
2524 priv->shadow_type = GTK_SHADOW_IN;
2526 priv->caps_lock_warning = TRUE;
2527 priv->caps_lock_warning_shown = FALSE;
2528 priv->progress_fraction = 0.0;
2529 priv->progress_pulse_fraction = 0.1;
2531 gtk_drag_dest_set (GTK_WIDGET (entry),
2532 GTK_DEST_DEFAULT_HIGHLIGHT,
2534 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2535 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2537 /* This object is completely private. No external entity can gain a reference
2538 * to it; so we create it here and destroy it in finalize().
2540 priv->im_context = gtk_im_multicontext_new ();
2542 g_signal_connect (priv->im_context, "commit",
2543 G_CALLBACK (gtk_entry_commit_cb), entry);
2544 g_signal_connect (priv->im_context, "preedit-changed",
2545 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2546 g_signal_connect (priv->im_context, "retrieve-surrounding",
2547 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2548 g_signal_connect (priv->im_context, "delete-surrounding",
2549 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2551 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2552 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2554 gtk_entry_update_cached_style_values (entry);
2558 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2559 GtkStyleContext *context,
2560 GtkEntryIconPosition icon_pos)
2562 GtkEntryPrivate *priv = entry->priv;
2563 EntryIconInfo *icon_info = priv->icons[icon_pos];
2565 GtkStateFlags state;
2567 widget = GTK_WIDGET (entry);
2568 state = gtk_widget_get_state_flags (widget);
2570 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2572 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2573 state |= GTK_STATE_FLAG_INSENSITIVE;
2574 else if (icon_info->prelight)
2575 state |= GTK_STATE_FLAG_PRELIGHT;
2577 gtk_style_context_save (context);
2579 gtk_style_context_set_state (context, state);
2580 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2582 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2584 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2585 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2587 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2591 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2592 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2594 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2599 get_icon_width (GtkEntry *entry,
2600 GtkEntryIconPosition icon_pos)
2602 GtkEntryPrivate *priv = entry->priv;
2603 EntryIconInfo *icon_info = priv->icons[icon_pos];
2604 GtkStyleContext *context;
2611 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2612 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2613 gtk_style_context_get_padding (context, 0, &padding);
2615 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2617 gtk_style_context_restore (context);
2620 width += padding.left + padding.right;
2626 get_icon_allocations (GtkEntry *entry,
2627 GtkAllocation *primary,
2628 GtkAllocation *secondary)
2631 GtkEntryPrivate *priv = entry->priv;
2632 gint x, y, width, height;
2634 get_text_area_size (entry, &x, &y, &width, &height);
2636 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2637 y += priv->focus_width;
2640 primary->height = height;
2641 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2644 secondary->height = height;
2645 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2647 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2649 primary->x = x + width - primary->width;
2655 secondary->x = x + width - secondary->width;
2661 begin_change (GtkEntry *entry)
2663 GtkEntryPrivate *priv = entry->priv;
2665 priv->change_count++;
2667 g_object_freeze_notify (G_OBJECT (entry));
2671 end_change (GtkEntry *entry)
2673 GtkEditable *editable = GTK_EDITABLE (entry);
2674 GtkEntryPrivate *priv = entry->priv;
2676 g_return_if_fail (priv->change_count > 0);
2678 g_object_thaw_notify (G_OBJECT (entry));
2680 priv->change_count--;
2682 if (priv->change_count == 0)
2684 if (priv->real_changed)
2686 g_signal_emit_by_name (editable, "changed");
2687 priv->real_changed = FALSE;
2693 emit_changed (GtkEntry *entry)
2695 GtkEditable *editable = GTK_EDITABLE (entry);
2696 GtkEntryPrivate *priv = entry->priv;
2698 if (priv->change_count == 0)
2699 g_signal_emit_by_name (editable, "changed");
2701 priv->real_changed = TRUE;
2705 gtk_entry_destroy (GtkWidget *widget)
2707 GtkEntry *entry = GTK_ENTRY (widget);
2708 GtkEntryPrivate *priv = entry->priv;
2710 priv->current_pos = priv->selection_bound = 0;
2711 _gtk_entry_reset_im_context (entry);
2712 gtk_entry_reset_layout (entry);
2714 if (priv->blink_timeout)
2716 g_source_remove (priv->blink_timeout);
2717 priv->blink_timeout = 0;
2720 if (priv->recompute_idle)
2722 g_source_remove (priv->recompute_idle);
2723 priv->recompute_idle = 0;
2726 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2730 gtk_entry_dispose (GObject *object)
2732 GtkEntry *entry = GTK_ENTRY (object);
2733 GtkEntryPrivate *priv = entry->priv;
2736 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2737 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2738 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2739 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2743 buffer_disconnect_signals (entry);
2744 g_object_unref (priv->buffer);
2745 priv->buffer = NULL;
2748 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2749 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2750 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2751 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2755 gtk_entry_finalize (GObject *object)
2757 GtkEntry *entry = GTK_ENTRY (object);
2758 GtkEntryPrivate *priv = entry->priv;
2759 EntryIconInfo *icon_info = NULL;
2762 for (i = 0; i < MAX_ICONS; i++)
2764 if ((icon_info = priv->icons[i]) != NULL)
2766 if (icon_info->target_list != NULL)
2768 gtk_target_list_unref (icon_info->target_list);
2769 icon_info->target_list = NULL;
2772 g_clear_object (&icon_info->icon_helper);
2774 g_slice_free (EntryIconInfo, icon_info);
2775 priv->icons[i] = NULL;
2779 gtk_entry_set_completion (entry, NULL);
2781 if (priv->cached_layout)
2782 g_object_unref (priv->cached_layout);
2784 g_object_unref (priv->im_context);
2786 if (priv->blink_timeout)
2787 g_source_remove (priv->blink_timeout);
2789 if (priv->recompute_idle)
2790 g_source_remove (priv->recompute_idle);
2792 g_free (priv->placeholder_text);
2793 g_free (priv->im_module);
2795 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2799 gtk_entry_get_display_mode (GtkEntry *entry)
2801 GtkEntryPrivate *priv = entry->priv;
2804 return DISPLAY_NORMAL;
2806 if (priv->invisible_char == 0 && priv->invisible_char_set)
2807 return DISPLAY_BLANK;
2809 return DISPLAY_INVISIBLE;
2813 _gtk_entry_get_display_text (GtkEntry *entry,
2817 GtkEntryPasswordHint *password_hint;
2818 GtkEntryPrivate *priv;
2819 gunichar invisible_char;
2830 text = gtk_entry_buffer_get_text (get_buffer (entry));
2831 length = gtk_entry_buffer_get_length (get_buffer (entry));
2835 if (start_pos > length)
2838 if (end_pos <= start_pos)
2839 return g_strdup ("");
2840 else if (priv->visible)
2842 start = g_utf8_offset_to_pointer (text, start_pos);
2843 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2844 return g_strndup (start, end - start);
2848 str = g_string_sized_new (length * 2);
2850 /* Figure out what our invisible char is and encode it */
2851 if (!priv->invisible_char)
2852 invisible_char = priv->invisible_char_set ? ' ' : '*';
2854 invisible_char = priv->invisible_char;
2855 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2858 * Add hidden characters for each character in the text
2859 * buffer. If there is a password hint, then keep that
2860 * character visible.
2863 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2864 for (i = start_pos; i < end_pos; ++i)
2866 if (password_hint && i == password_hint->position)
2868 start = g_utf8_offset_to_pointer (text, i);
2869 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2873 g_string_append_len (str, char_str, char_len);
2877 return g_string_free (str, FALSE);
2882 update_cursors (GtkWidget *widget)
2884 GtkEntry *entry = GTK_ENTRY (widget);
2885 GtkEntryPrivate *priv = entry->priv;
2886 EntryIconInfo *icon_info = NULL;
2887 GdkDisplay *display;
2891 for (i = 0; i < MAX_ICONS; i++)
2893 if ((icon_info = priv->icons[i]) != NULL)
2895 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2896 icon_info->window != NULL)
2897 gdk_window_show_unraised (icon_info->window);
2899 /* The icon windows are not children of the visible entry window,
2900 * thus we can't just inherit the xterm cursor. Slight complication
2901 * here is that for the entry, insensitive => arrow cursor, but for
2902 * an icon in a sensitive entry, insensitive => xterm cursor.
2904 if (gtk_widget_is_sensitive (widget) &&
2905 (icon_info->insensitive ||
2906 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2908 display = gtk_widget_get_display (widget);
2909 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2910 gdk_window_set_cursor (icon_info->window, cursor);
2911 g_object_unref (cursor);
2915 gdk_window_set_cursor (icon_info->window, NULL);
2922 realize_icon_info (GtkWidget *widget,
2923 GtkEntryIconPosition icon_pos)
2925 GtkEntry *entry = GTK_ENTRY (widget);
2926 GtkEntryPrivate *priv = entry->priv;
2927 EntryIconInfo *icon_info = priv->icons[icon_pos];
2928 GdkWindowAttr attributes;
2929 gint attributes_mask;
2931 g_return_if_fail (icon_info != NULL);
2935 attributes.width = 1;
2936 attributes.height = 1;
2937 attributes.window_type = GDK_WINDOW_CHILD;
2938 attributes.wclass = GDK_INPUT_ONLY;
2939 attributes.event_mask = gtk_widget_get_events (widget);
2940 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2941 GDK_BUTTON_RELEASE_MASK |
2942 GDK_BUTTON1_MOTION_MASK |
2943 GDK_BUTTON3_MOTION_MASK |
2944 GDK_POINTER_MOTION_HINT_MASK |
2945 GDK_POINTER_MOTION_MASK |
2946 GDK_ENTER_NOTIFY_MASK |
2947 GDK_LEAVE_NOTIFY_MASK);
2948 attributes_mask = GDK_WA_X | GDK_WA_Y;
2950 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2953 gdk_window_set_user_data (icon_info->window, widget);
2955 gtk_widget_queue_resize (widget);
2958 static EntryIconInfo*
2959 construct_icon_info (GtkWidget *widget,
2960 GtkEntryIconPosition icon_pos)
2962 GtkEntry *entry = GTK_ENTRY (widget);
2963 GtkEntryPrivate *priv = entry->priv;
2964 EntryIconInfo *icon_info;
2966 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2968 icon_info = g_slice_new0 (EntryIconInfo);
2969 priv->icons[icon_pos] = icon_info;
2971 icon_info->icon_helper = _gtk_icon_helper_new ();
2972 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
2974 if (gtk_widget_get_realized (widget))
2975 realize_icon_info (widget, icon_pos);
2981 gtk_entry_map (GtkWidget *widget)
2983 GtkEntry *entry = GTK_ENTRY (widget);
2984 GtkEntryPrivate *priv = entry->priv;
2985 EntryIconInfo *icon_info = NULL;
2988 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2990 gdk_window_show (priv->text_area);
2992 for (i = 0; i < MAX_ICONS; i++)
2994 if ((icon_info = priv->icons[i]) != NULL)
2996 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2997 icon_info->window != NULL)
2998 gdk_window_show (icon_info->window);
3002 update_cursors (widget);
3006 gtk_entry_unmap (GtkWidget *widget)
3008 GtkEntry *entry = GTK_ENTRY (widget);
3009 GtkEntryPrivate *priv = entry->priv;
3010 EntryIconInfo *icon_info = NULL;
3013 for (i = 0; i < MAX_ICONS; i++)
3015 if ((icon_info = priv->icons[i]) != NULL)
3017 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
3018 icon_info->window != NULL)
3019 gdk_window_hide (icon_info->window);
3023 gdk_window_hide (priv->text_area);
3025 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
3029 gtk_entry_realize (GtkWidget *widget)
3032 GtkEntryPrivate *priv;
3033 EntryIconInfo *icon_info;
3035 GdkWindowAttr attributes;
3036 gint attributes_mask;
3037 gint frame_x, frame_y;
3040 gtk_widget_set_realized (widget, TRUE);
3041 window = gtk_widget_get_parent_window (widget);
3042 gtk_widget_set_window (widget, window);
3043 g_object_ref (window);
3045 entry = GTK_ENTRY (widget);
3048 attributes.window_type = GDK_WINDOW_CHILD;
3049 attributes.wclass = GDK_INPUT_ONLY;
3050 attributes.event_mask = gtk_widget_get_events (widget);
3051 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3052 GDK_BUTTON_RELEASE_MASK |
3053 GDK_BUTTON1_MOTION_MASK |
3054 GDK_BUTTON3_MOTION_MASK |
3055 GDK_POINTER_MOTION_HINT_MASK |
3056 GDK_POINTER_MOTION_MASK |
3057 GDK_ENTER_NOTIFY_MASK |
3058 GDK_LEAVE_NOTIFY_MASK);
3059 attributes_mask = GDK_WA_X | GDK_WA_Y;
3061 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3063 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3064 attributes.x += frame_x;
3065 attributes.y += frame_y;
3067 if (gtk_widget_is_sensitive (widget))
3069 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3070 attributes_mask |= GDK_WA_CURSOR;
3073 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3077 gdk_window_set_user_data (priv->text_area, entry);
3079 if (attributes_mask & GDK_WA_CURSOR)
3080 g_object_unref (attributes.cursor);
3082 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3084 gtk_entry_adjust_scroll (entry);
3085 gtk_entry_update_primary_selection (entry);
3088 /* If the icon positions are already setup, create their windows.
3089 * Otherwise if they don't exist yet, then construct_icon_info()
3090 * will create the windows once the widget is already realized.
3092 for (i = 0; i < MAX_ICONS; i++)
3094 if ((icon_info = priv->icons[i]) != NULL)
3096 if (icon_info->window == NULL)
3097 realize_icon_info (widget, i);
3103 gtk_entry_unrealize (GtkWidget *widget)
3105 GtkEntry *entry = GTK_ENTRY (widget);
3106 GtkEntryPrivate *priv = entry->priv;
3107 GtkClipboard *clipboard;
3108 EntryIconInfo *icon_info;
3111 gtk_entry_reset_layout (entry);
3113 gtk_im_context_set_client_window (priv->im_context, NULL);
3115 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3116 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3117 gtk_clipboard_clear (clipboard);
3119 if (priv->text_area)
3121 gdk_window_set_user_data (priv->text_area, NULL);
3122 gdk_window_destroy (priv->text_area);
3123 priv->text_area = NULL;
3126 if (priv->popup_menu)
3128 gtk_widget_destroy (priv->popup_menu);
3129 priv->popup_menu = NULL;
3132 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3134 for (i = 0; i < MAX_ICONS; i++)
3136 if ((icon_info = priv->icons[i]) != NULL)
3138 if (icon_info->window != NULL)
3140 gdk_window_destroy (icon_info->window);
3141 icon_info->window = NULL;
3148 _gtk_entry_get_borders (GtkEntry *entry,
3149 GtkBorder *border_out)
3151 GtkEntryPrivate *priv = entry->priv;
3152 GtkWidget *widget = GTK_WIDGET (entry);
3153 GtkBorder tmp = { 0, 0, 0, 0 };
3154 GtkStyleContext *context;
3156 context = gtk_widget_get_style_context (widget);
3157 gtk_style_context_get_padding (context, 0, &tmp);
3159 if (priv->has_frame)
3163 gtk_style_context_get_border (context, 0, &border);
3164 tmp.top += border.top;
3165 tmp.right += border.right;
3166 tmp.bottom += border.bottom;
3167 tmp.left += border.left;
3170 if (!priv->interior_focus)
3172 tmp.top += priv->focus_width;
3173 tmp.right += priv->focus_width;
3174 tmp.bottom += priv->focus_width;
3175 tmp.left += priv->focus_width;
3178 if (border_out != NULL)
3183 gtk_entry_get_preferred_width (GtkWidget *widget,
3187 GtkEntry *entry = GTK_ENTRY (widget);
3188 GtkEntryPrivate *priv = entry->priv;
3189 PangoFontMetrics *metrics;
3191 PangoContext *context;
3192 GtkStyleContext *style_context;
3193 GtkStateFlags state;
3194 gint icon_widths = 0;
3198 context = gtk_widget_get_pango_context (widget);
3200 style_context = gtk_widget_get_style_context (widget);
3201 state = gtk_widget_get_state_flags (widget);
3203 metrics = pango_context_get_metrics (context,
3204 gtk_style_context_get_font (style_context, state),
3205 pango_context_get_language (context));
3207 _gtk_entry_get_borders (entry, &borders);
3209 if (priv->width_chars < 0)
3210 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3213 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3214 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3215 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3217 width = char_pixels * priv->width_chars + borders.left + borders.right;
3220 for (i = 0; i < MAX_ICONS; i++)
3222 icon_width = get_icon_width (entry, i);
3224 icon_widths += icon_width;
3227 if (icon_widths > width)
3228 width += icon_widths;
3230 pango_font_metrics_unref (metrics);
3237 gtk_entry_get_preferred_height (GtkWidget *widget,
3241 GtkEntry *entry = GTK_ENTRY (widget);
3242 GtkEntryPrivate *priv = entry->priv;
3243 PangoFontMetrics *metrics;
3245 GtkStyleContext *style_context;
3246 GtkStateFlags state;
3247 PangoContext *context;
3250 context = gtk_widget_get_pango_context (widget);
3252 style_context = gtk_widget_get_style_context (widget);
3253 state = gtk_widget_get_state_flags (widget);
3255 metrics = pango_context_get_metrics (context,
3256 gtk_style_context_get_font (style_context, state),
3257 pango_context_get_language (context));
3259 priv->ascent = pango_font_metrics_get_ascent (metrics);
3260 priv->descent = pango_font_metrics_get_descent (metrics);
3262 _gtk_entry_get_borders (entry, &borders);
3264 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3266 pango_font_metrics_unref (metrics);
3273 place_windows (GtkEntry *entry)
3275 GtkWidget *widget = GTK_WIDGET (entry);
3276 GtkEntryPrivate *priv = entry->priv;
3277 gint x, y, width, height;
3278 gint frame_x, frame_y;
3279 GtkAllocation primary;
3280 GtkAllocation secondary;
3281 EntryIconInfo *icon_info = NULL;
3283 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3284 get_text_area_size (entry, &x, &y, &width, &height);
3285 get_icon_allocations (entry, &primary, &secondary);
3287 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3288 y += priv->focus_width;
3290 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3291 x += secondary.width;
3294 width -= primary.width + secondary.width;
3298 primary.x += frame_x;
3299 primary.y += frame_y;
3300 secondary.x += frame_x;
3301 secondary.y += frame_y;
3303 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3304 gdk_window_move_resize (icon_info->window,
3305 primary.x, primary.y,
3306 primary.width, primary.height);
3308 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3309 gdk_window_move_resize (icon_info->window,
3310 secondary.x, secondary.y,
3311 secondary.width, secondary.height);
3313 gdk_window_move_resize (priv->text_area, x, y, width, height);
3317 gtk_entry_get_text_area_size (GtkEntry *entry,
3323 GtkEntryPrivate *priv = entry->priv;
3324 GtkWidget *widget = GTK_WIDGET (entry);
3325 GtkAllocation allocation;
3326 GtkRequisition requisition;
3331 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3332 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3334 gtk_widget_get_allocation (widget, &allocation);
3335 _gtk_entry_get_borders (entry, &borders);
3337 if (gtk_widget_get_realized (widget))
3338 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3340 frame_height = req_height;
3342 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3343 frame_height -= 2 * priv->focus_width;
3349 *y = floor ((frame_height - req_height) / 2) + borders.top;
3352 *width = allocation.width - borders.left - borders.right;
3355 *height = req_height - borders.top - borders.bottom;
3359 get_text_area_size (GtkEntry *entry,
3365 GtkEntryClass *class;
3367 g_return_if_fail (GTK_IS_ENTRY (entry));
3369 class = GTK_ENTRY_GET_CLASS (entry);
3371 if (class->get_text_area_size)
3372 class->get_text_area_size (entry, x, y, width, height);
3377 get_frame_size (GtkEntry *entry,
3378 gboolean relative_to_window,
3384 GtkEntryPrivate *priv = entry->priv;
3385 GtkAllocation allocation;
3386 GtkRequisition requisition;
3387 GtkWidget *widget = GTK_WIDGET (entry);
3390 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3392 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3394 gtk_widget_get_allocation (widget, &allocation);
3397 *x = relative_to_window ? allocation.x : 0;
3401 if (priv->is_cell_renderer)
3404 *y = (allocation.height - req_height) / 2;
3406 if (relative_to_window)
3411 *width = allocation.width;
3415 if (priv->is_cell_renderer)
3416 *height = allocation.height;
3418 *height = req_height;
3423 gtk_entry_size_allocate (GtkWidget *widget,
3424 GtkAllocation *allocation)
3426 GtkEntry *entry = GTK_ENTRY (widget);
3428 gtk_widget_set_allocation (widget, allocation);
3430 if (gtk_widget_get_realized (widget))
3432 GtkEntryCompletion* completion;
3434 place_windows (entry);
3435 gtk_entry_recompute (entry);
3437 completion = gtk_entry_get_completion (entry);
3438 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3439 _gtk_entry_completion_resize_popup (completion);
3444 should_prelight (GtkEntry *entry,
3445 GtkEntryIconPosition icon_pos)
3447 GtkEntryPrivate *priv = entry->priv;
3448 EntryIconInfo *icon_info = priv->icons[icon_pos];
3454 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3457 if (icon_info->pressed)
3460 gtk_widget_style_get (GTK_WIDGET (entry),
3461 "icon-prelight", &prelight,
3468 draw_icon (GtkWidget *widget,
3470 GtkEntryIconPosition icon_pos)
3472 GtkEntry *entry = GTK_ENTRY (widget);
3473 GtkEntryPrivate *priv = entry->priv;
3474 EntryIconInfo *icon_info = priv->icons[icon_pos];
3475 gint x, y, width, height, pix_width, pix_height;
3476 GtkStyleContext *context;
3482 width = gdk_window_get_width (icon_info->window);
3483 height = gdk_window_get_height (icon_info->window);
3485 /* size_allocate hasn't been called yet. These are the default values.
3487 if (width == 1 || height == 1)
3491 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3493 context = gtk_widget_get_style_context (widget);
3494 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3495 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3496 &pix_width, &pix_height);
3497 gtk_style_context_get_padding (context, 0, &padding);
3499 x = MAX (0, padding.left);
3500 y = MAX (0, (height - pix_height) / 2);
3502 _gtk_icon_helper_draw (icon_info->icon_helper,
3506 gtk_style_context_restore (context);
3512 gtk_entry_draw_frame (GtkWidget *widget,
3513 GtkStyleContext *context,
3516 GtkEntry *entry = GTK_ENTRY (widget);
3517 GtkEntryPrivate *priv = entry->priv;
3518 gint x = 0, y = 0, width, height;
3519 gint frame_x, frame_y;
3523 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3525 cairo_translate (cr, frame_x, frame_y);
3527 /* Fix a problem with some themes which assume that entry->text_area's
3528 * width equals widget->window's width
3529 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3530 if (GTK_IS_SPIN_BUTTON (widget))
3534 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3535 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3538 width += borders.left + borders.right;
3541 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3543 x += priv->focus_width;
3544 y += priv->focus_width;
3545 width -= 2 * priv->focus_width;
3546 height -= 2 * priv->focus_width;
3549 gtk_render_background (context, cr,
3550 x, y, width, height);
3552 if (priv->has_frame)
3553 gtk_render_frame (context, cr,
3554 x, y, width, height);
3556 gtk_entry_draw_progress (widget, context, cr);
3558 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3560 x -= priv->focus_width;
3561 y -= priv->focus_width;
3562 width += 2 * priv->focus_width;
3563 height += 2 * priv->focus_width;
3565 gtk_render_focus (context, cr,
3566 0, 0, width, height);
3573 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3574 GtkStyleContext *context)
3576 GtkEntryPrivate *private = entry->priv;
3578 gtk_style_context_save (context);
3579 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3580 if (private->progress_pulse_mode)
3581 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3585 get_progress_area (GtkWidget *widget,
3591 GtkEntry *entry = GTK_ENTRY (widget);
3592 GtkEntryPrivate *private = entry->priv;
3593 GtkStyleContext *context;
3594 GtkBorder margin, border, entry_borders;
3595 gint frame_width, text_area_width, text_area_height;
3597 context = gtk_widget_get_style_context (widget);
3598 _gtk_entry_get_borders (entry, &entry_borders);
3599 get_text_area_size (entry,
3601 &text_area_width, &text_area_height);
3602 get_frame_size (entry, FALSE,
3604 &frame_width, NULL);
3608 *width = text_area_width + entry_borders.left + entry_borders.right;
3609 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3611 /* if the text area got resized by a subclass, subtract the left/right
3612 * border width, so that the progress bar won't extend over the resized
3615 if (frame_width > *width)
3617 gtk_style_context_get_border (context, 0, &border);
3618 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3620 *x = (frame_width - *width) + border.left;
3621 *width -= border.left;
3625 *width -= border.right;
3629 gtk_entry_prepare_context_for_progress (entry, context);
3630 gtk_style_context_get_margin (context, 0, &margin);
3632 gtk_style_context_restore (context);
3636 *width -= margin.left + margin.right;
3637 *height -= margin.top + margin.bottom;
3639 if (private->progress_pulse_mode)
3641 gdouble value = private->progress_pulse_current;
3643 *x += (gint) floor(value * (*width));
3644 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3646 else if (private->progress_fraction > 0)
3648 gdouble value = private->progress_fraction;
3650 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3654 bar_width = floor(value * (*width) + 0.5);
3655 *x += *width - bar_width;
3660 *width = (gint) floor(value * (*width) + 0.5);
3671 gtk_entry_draw_progress (GtkWidget *widget,
3672 GtkStyleContext *context,
3675 GtkEntry *entry = GTK_ENTRY (widget);
3676 gint x, y, width, height;
3678 get_progress_area (widget, &x, &y, &width, &height);
3680 if ((width <= 0) || (height <= 0))
3683 gtk_entry_prepare_context_for_progress (entry, context);
3684 gtk_render_activity (context, cr,
3685 x, y, width, height);
3687 gtk_style_context_restore (context);
3691 gtk_entry_draw (GtkWidget *widget,
3694 GtkEntry *entry = GTK_ENTRY (widget);
3695 GtkStyleContext *context;
3696 GtkEntryPrivate *priv = entry->priv;
3699 context = gtk_widget_get_style_context (widget);
3701 /* Draw entry_bg, shadow, progress and focus */
3702 gtk_entry_draw_frame (widget, context, cr);
3704 /* Draw text and cursor */
3707 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3709 if (priv->dnd_position != -1)
3710 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3712 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3714 /* When no text is being displayed at all, don't show the cursor */
3715 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3716 gtk_widget_has_focus (widget) &&
3717 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3718 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3723 for (i = 0; i < MAX_ICONS; i++)
3725 EntryIconInfo *icon_info = priv->icons[i];
3727 if (icon_info != NULL)
3728 draw_icon (widget, cr, i);
3735 gtk_entry_enter_notify (GtkWidget *widget,
3736 GdkEventCrossing *event)
3738 GtkEntry *entry = GTK_ENTRY (widget);
3739 GtkEntryPrivate *priv = entry->priv;
3742 for (i = 0; i < MAX_ICONS; i++)
3744 EntryIconInfo *icon_info = priv->icons[i];
3746 if (icon_info != NULL && event->window == icon_info->window)
3748 if (should_prelight (entry, i))
3750 icon_info->prelight = TRUE;
3751 gtk_widget_queue_draw (widget);
3762 gtk_entry_leave_notify (GtkWidget *widget,
3763 GdkEventCrossing *event)
3765 GtkEntry *entry = GTK_ENTRY (widget);
3766 GtkEntryPrivate *priv = entry->priv;
3769 for (i = 0; i < MAX_ICONS; i++)
3771 EntryIconInfo *icon_info = priv->icons[i];
3773 if (icon_info != NULL && event->window == icon_info->window)
3775 /* a grab means that we may never see the button release */
3776 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3777 icon_info->pressed = FALSE;
3779 if (should_prelight (entry, i))
3781 icon_info->prelight = FALSE;
3782 gtk_widget_queue_draw (widget);
3793 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3797 gint start_char, end_char;
3799 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3801 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3802 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3803 const char *text = pango_layout_get_text (layout);
3804 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3805 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3806 gint real_n_ranges, i;
3808 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3814 for (i = 0; i < real_n_ranges; ++i)
3816 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3817 r[2 * i] = r[2 * i] / PANGO_SCALE;
3822 *n_ranges = real_n_ranges;
3834 in_selection (GtkEntry *entry,
3839 gint retval = FALSE;
3841 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3843 for (i = 0; i < n_ranges; ++i)
3845 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3857 gtk_entry_button_press (GtkWidget *widget,
3858 GdkEventButton *event)
3860 GtkEntry *entry = GTK_ENTRY (widget);
3861 GtkEditable *editable = GTK_EDITABLE (widget);
3862 GtkEntryPrivate *priv = entry->priv;
3863 EntryIconInfo *icon_info = NULL;
3865 gint sel_start, sel_end;
3868 for (i = 0; i < MAX_ICONS; i++)
3870 icon_info = priv->icons[i];
3872 if (!icon_info || icon_info->insensitive)
3875 if (event->window == icon_info->window)
3877 if (should_prelight (entry, i))
3879 icon_info->prelight = FALSE;
3880 gtk_widget_queue_draw (widget);
3883 priv->start_x = event->x;
3884 priv->start_y = event->y;
3885 icon_info->pressed = TRUE;
3887 if (!icon_info->nonactivatable)
3888 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3894 if (event->window != priv->text_area ||
3895 (priv->button && event->button != priv->button))
3898 gtk_entry_reset_blink_time (entry);
3900 priv->button = event->button;
3901 priv->device = gdk_event_get_device ((GdkEvent *) event);
3903 if (!gtk_widget_has_focus (widget))
3905 priv->in_click = TRUE;
3906 gtk_widget_grab_focus (widget);
3907 priv->in_click = FALSE;
3910 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3912 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3914 gtk_entry_do_popup (entry, event);
3915 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3916 priv->device = NULL;
3920 else if (event->button == GDK_BUTTON_PRIMARY)
3922 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3924 priv->select_words = FALSE;
3925 priv->select_lines = FALSE;
3928 gtk_widget_get_modifier_mask (widget,
3929 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3931 _gtk_entry_reset_im_context (entry);
3933 if (!have_selection) /* select from the current position to the clicked position */
3934 sel_start = sel_end = priv->current_pos;
3936 if (tmp_pos > sel_start && tmp_pos < sel_end)
3938 /* Truncate current selection, but keep it as big as possible */
3939 if (tmp_pos - sel_start > sel_end - tmp_pos)
3940 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3942 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3946 gboolean extend_to_left;
3949 /* Figure out what click selects and extend current selection */
3950 switch (event->type)
3952 case GDK_BUTTON_PRESS:
3953 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3956 case GDK_2BUTTON_PRESS:
3957 priv->select_words = TRUE;
3958 gtk_entry_select_word (entry);
3961 case GDK_3BUTTON_PRESS:
3962 priv->select_lines = TRUE;
3963 gtk_entry_select_line (entry);
3970 start = MIN (priv->current_pos, priv->selection_bound);
3971 start = MIN (sel_start, start);
3973 end = MAX (priv->current_pos, priv->selection_bound);
3974 end = MAX (sel_end, end);
3976 if (tmp_pos == sel_start || tmp_pos == sel_end)
3977 extend_to_left = (tmp_pos == start);
3979 extend_to_left = (end == sel_end);
3982 gtk_entry_set_positions (entry, start, end);
3984 gtk_entry_set_positions (entry, end, start);
3987 else /* no shift key */
3988 switch (event->type)
3990 case GDK_BUTTON_PRESS:
3991 if (in_selection (entry, event->x + priv->scroll_offset))
3993 /* Click inside the selection - we'll either start a drag, or
3994 * clear the selection
3996 priv->in_drag = TRUE;
3997 priv->drag_start_x = event->x + priv->scroll_offset;
3998 priv->drag_start_y = event->y;
4001 gtk_editable_set_position (editable, tmp_pos);
4004 case GDK_2BUTTON_PRESS:
4005 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4006 * receiving a GDK_2BUTTON_PRESS so we need to reset
4007 * priv->in_drag which may have been set above
4009 priv->in_drag = FALSE;
4010 priv->select_words = TRUE;
4011 gtk_entry_select_word (entry);
4014 case GDK_3BUTTON_PRESS:
4015 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
4016 * receiving a GDK_3BUTTON_PRESS so we need to reset
4017 * priv->in_drag which may have been set above
4019 priv->in_drag = FALSE;
4020 priv->select_lines = TRUE;
4021 gtk_entry_select_line (entry);
4030 else if (event->type == GDK_BUTTON_PRESS &&
4031 event->button == GDK_BUTTON_MIDDLE &&
4032 get_middle_click_paste (entry))
4036 priv->insert_pos = tmp_pos;
4037 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
4042 gtk_widget_error_bell (widget);
4050 gtk_entry_button_release (GtkWidget *widget,
4051 GdkEventButton *event)
4053 GtkEntry *entry = GTK_ENTRY (widget);
4054 GtkEntryPrivate *priv = entry->priv;
4055 EntryIconInfo *icon_info = NULL;
4058 for (i = 0; i < MAX_ICONS; i++)
4060 icon_info = priv->icons[i];
4062 if (!icon_info || icon_info->insensitive)
4065 if (event->window == icon_info->window)
4067 icon_info->pressed = FALSE;
4069 if (should_prelight (entry, i) &&
4070 event->x >= 0 && event->y >= 0 &&
4071 event->x < gdk_window_get_width (icon_info->window) &&
4072 event->y < gdk_window_get_height (icon_info->window))
4074 icon_info->prelight = TRUE;
4075 gtk_widget_queue_draw (widget);
4078 if (!icon_info->nonactivatable)
4079 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4085 if (event->window != priv->text_area || priv->button != event->button)
4090 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4092 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4098 priv->device = NULL;
4100 gtk_entry_update_primary_selection (entry);
4106 _gtk_entry_get_selected_text (GtkEntry *entry)
4108 GtkEditable *editable = GTK_EDITABLE (entry);
4109 gint start_text, end_text;
4112 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4113 text = gtk_editable_get_chars (editable, start_text, end_text);
4119 gtk_entry_motion_notify (GtkWidget *widget,
4120 GdkEventMotion *event)
4122 GtkEntry *entry = GTK_ENTRY (widget);
4123 GtkEntryPrivate *priv = entry->priv;
4124 EntryIconInfo *icon_info = NULL;
4128 for (i = 0; i < MAX_ICONS; i++)
4130 icon_info = priv->icons[i];
4132 if (!icon_info || icon_info->insensitive)
4135 if (event->window == icon_info->window)
4137 if (icon_info->pressed &&
4138 icon_info->target_list != NULL &&
4139 gtk_drag_check_threshold (widget,
4145 icon_info->in_drag = TRUE;
4146 icon_info->pressed = FALSE;
4147 gtk_drag_begin (widget,
4148 icon_info->target_list,
4158 if (priv->mouse_cursor_obscured)
4162 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4163 gdk_window_set_cursor (priv->text_area, cursor);
4164 g_object_unref (cursor);
4165 priv->mouse_cursor_obscured = FALSE;
4168 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4171 if (priv->select_lines)
4174 gdk_event_request_motions (event);
4178 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4179 gtk_drag_check_threshold (widget,
4180 priv->drag_start_x, priv->drag_start_y,
4181 event->x + priv->scroll_offset, event->y))
4183 GdkDragContext *context;
4184 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4185 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4187 cairo_surface_t *surface;
4189 gtk_target_list_add_text_targets (target_list, 0);
4191 text = _gtk_entry_get_selected_text (entry);
4192 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4194 context = gtk_drag_begin (widget, target_list, actions,
4195 priv->button, (GdkEvent *)event);
4198 gtk_drag_set_icon_surface (context, surface);
4200 gtk_drag_set_icon_default (context);
4203 cairo_surface_destroy (surface);
4206 priv->in_drag = FALSE;
4208 priv->device = NULL;
4210 gtk_target_list_unref (target_list);
4217 else if (event->y >= gdk_window_get_height (priv->text_area))
4218 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4220 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4222 if (priv->select_words)
4225 gint old_min, old_max;
4228 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4229 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4231 pos = priv->current_pos;
4232 bound = priv->selection_bound;
4234 old_min = MIN(priv->current_pos, priv->selection_bound);
4235 old_max = MAX(priv->current_pos, priv->selection_bound);
4242 else if (old_max < max)
4247 else if (pos == old_min)
4249 if (priv->current_pos != min)
4254 if (priv->current_pos != max)
4258 gtk_entry_set_positions (entry, pos, bound);
4261 gtk_entry_set_positions (entry, tmp_pos, -1);
4268 set_invisible_cursor (GdkWindow *window)
4270 GdkDisplay *display;
4273 display = gdk_window_get_display (window);
4274 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4276 gdk_window_set_cursor (window, cursor);
4278 g_object_unref (cursor);
4282 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4284 GtkEntryPrivate *priv = entry->priv;
4286 if (priv->mouse_cursor_obscured)
4289 set_invisible_cursor (priv->text_area);
4291 priv->mouse_cursor_obscured = TRUE;
4295 gtk_entry_key_press (GtkWidget *widget,
4298 GtkEntry *entry = GTK_ENTRY (widget);
4299 GtkEntryPrivate *priv = entry->priv;
4301 gtk_entry_reset_blink_time (entry);
4302 gtk_entry_pend_cursor_blink (entry);
4306 if (gtk_im_context_filter_keypress (priv->im_context, event))
4308 gtk_entry_obscure_mouse_cursor (entry);
4309 priv->need_im_reset = TRUE;
4314 if (event->keyval == GDK_KEY_Return ||
4315 event->keyval == GDK_KEY_KP_Enter ||
4316 event->keyval == GDK_KEY_ISO_Enter ||
4317 event->keyval == GDK_KEY_Escape)
4319 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4321 if (completion && completion->priv->completion_timeout)
4323 g_source_remove (completion->priv->completion_timeout);
4324 completion->priv->completion_timeout = 0;
4327 _gtk_entry_reset_im_context (entry);
4330 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4331 /* Activate key bindings
4335 if (!priv->editable && event->length)
4336 gtk_widget_error_bell (widget);
4342 gtk_entry_key_release (GtkWidget *widget,
4345 GtkEntry *entry = GTK_ENTRY (widget);
4346 GtkEntryPrivate *priv = entry->priv;
4350 if (gtk_im_context_filter_keypress (priv->im_context, event))
4352 priv->need_im_reset = TRUE;
4357 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4361 gtk_entry_focus_in (GtkWidget *widget,
4362 GdkEventFocus *event)
4364 GtkEntry *entry = GTK_ENTRY (widget);
4365 GtkEntryPrivate *priv = entry->priv;
4368 gtk_widget_queue_draw (widget);
4370 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4374 priv->need_im_reset = TRUE;
4375 gtk_im_context_focus_in (priv->im_context);
4376 keymap_state_changed (keymap, entry);
4377 g_signal_connect (keymap, "state-changed",
4378 G_CALLBACK (keymap_state_changed), entry);
4381 g_signal_connect (keymap, "direction-changed",
4382 G_CALLBACK (keymap_direction_changed), entry);
4384 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4385 priv->placeholder_text != NULL)
4387 gtk_entry_recompute (entry);
4391 gtk_entry_reset_blink_time (entry);
4392 gtk_entry_check_cursor_blink (entry);
4399 gtk_entry_focus_out (GtkWidget *widget,
4400 GdkEventFocus *event)
4402 GtkEntry *entry = GTK_ENTRY (widget);
4403 GtkEntryPrivate *priv = entry->priv;
4404 GtkEntryCompletion *completion;
4407 gtk_widget_queue_draw (widget);
4409 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4413 priv->need_im_reset = TRUE;
4414 gtk_im_context_focus_out (priv->im_context);
4415 remove_capslock_feedback (entry);
4418 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4419 priv->placeholder_text != NULL)
4421 gtk_entry_recompute (entry);
4425 gtk_entry_check_cursor_blink (entry);
4428 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4429 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4431 completion = gtk_entry_get_completion (entry);
4433 _gtk_entry_completion_popdown (completion);
4439 gtk_entry_grab_focus (GtkWidget *widget)
4441 GtkEntry *entry = GTK_ENTRY (widget);
4442 GtkEntryPrivate *priv = entry->priv;
4443 gboolean select_on_focus;
4445 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4447 if (priv->editable && !priv->in_click)
4449 g_object_get (gtk_widget_get_settings (widget),
4450 "gtk-entry-select-on-focus",
4454 if (select_on_focus)
4455 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4460 gtk_entry_direction_changed (GtkWidget *widget,
4461 GtkTextDirection previous_dir)
4463 GtkEntry *entry = GTK_ENTRY (widget);
4465 gtk_entry_recompute (entry);
4467 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4471 gtk_entry_state_flags_changed (GtkWidget *widget,
4472 GtkStateFlags previous_state)
4474 GtkEntry *entry = GTK_ENTRY (widget);
4475 GtkEntryPrivate *priv = entry->priv;
4478 if (gtk_widget_get_realized (widget))
4480 if (gtk_widget_is_sensitive (widget))
4481 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4485 gdk_window_set_cursor (priv->text_area, cursor);
4488 g_object_unref (cursor);
4490 priv->mouse_cursor_obscured = FALSE;
4492 update_cursors (widget);
4495 if (!gtk_widget_is_sensitive (widget))
4497 /* Clear any selection */
4498 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4501 gtk_entry_update_cached_style_values (entry);
4505 gtk_entry_screen_changed (GtkWidget *widget,
4506 GdkScreen *old_screen)
4508 gtk_entry_recompute (GTK_ENTRY (widget));
4511 /* GtkEditable method implementations
4514 gtk_entry_insert_text (GtkEditable *editable,
4515 const gchar *new_text,
4516 gint new_text_length,
4519 g_object_ref (editable);
4522 * The incoming text may a password or other secret. We make sure
4523 * not to copy it into temporary buffers.
4526 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4528 g_object_unref (editable);
4532 gtk_entry_delete_text (GtkEditable *editable,
4536 g_object_ref (editable);
4538 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4540 g_object_unref (editable);
4544 gtk_entry_get_chars (GtkEditable *editable,
4548 GtkEntry *entry = GTK_ENTRY (editable);
4551 gint start_index, end_index;
4553 text = gtk_entry_buffer_get_text (get_buffer (entry));
4554 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4557 end_pos = text_length;
4559 start_pos = MIN (text_length, start_pos);
4560 end_pos = MIN (text_length, end_pos);
4562 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4563 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4565 return g_strndup (text + start_index, end_index - start_index);
4569 gtk_entry_real_set_position (GtkEditable *editable,
4572 GtkEntry *entry = GTK_ENTRY (editable);
4573 GtkEntryPrivate *priv = entry->priv;
4577 length = gtk_entry_buffer_get_length (get_buffer (entry));
4578 if (position < 0 || position > length)
4581 if (position != priv->current_pos ||
4582 position != priv->selection_bound)
4584 _gtk_entry_reset_im_context (entry);
4585 gtk_entry_set_positions (entry, position, position);
4590 gtk_entry_get_position (GtkEditable *editable)
4592 GtkEntry *entry = GTK_ENTRY (editable);
4593 GtkEntryPrivate *priv = entry->priv;
4595 return priv->current_pos;
4599 gtk_entry_set_selection_bounds (GtkEditable *editable,
4603 GtkEntry *entry = GTK_ENTRY (editable);
4606 length = gtk_entry_buffer_get_length (get_buffer (entry));
4612 _gtk_entry_reset_im_context (entry);
4614 gtk_entry_set_positions (entry,
4616 MIN (start, length));
4618 gtk_entry_update_primary_selection (entry);
4622 gtk_entry_get_selection_bounds (GtkEditable *editable,
4626 GtkEntry *entry = GTK_ENTRY (editable);
4627 GtkEntryPrivate *priv = entry->priv;
4629 *start = priv->selection_bound;
4630 *end = priv->current_pos;
4632 return (priv->selection_bound != priv->current_pos);
4636 icon_theme_changed (GtkEntry *entry)
4638 GtkEntryPrivate *priv = entry->priv;
4641 for (i = 0; i < MAX_ICONS; i++)
4643 EntryIconInfo *icon_info = priv->icons[i];
4644 if (icon_info != NULL)
4645 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4648 gtk_widget_queue_draw (GTK_WIDGET (entry));
4652 gtk_entry_update_cached_style_values (GtkEntry *entry)
4654 GtkEntryPrivate *priv = entry->priv;
4656 gboolean interior_focus;
4658 gtk_widget_style_get (GTK_WIDGET (entry),
4659 "focus-line-width", &focus_width,
4660 "interior-focus", &interior_focus,
4662 priv->focus_width = focus_width;
4663 priv->interior_focus = interior_focus;
4665 if (!priv->invisible_char_set)
4667 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4669 if (priv->invisible_char != ch)
4671 priv->invisible_char = ch;
4672 g_object_notify (G_OBJECT (entry), "invisible-char");
4678 gtk_entry_style_updated (GtkWidget *widget)
4680 GtkEntry *entry = GTK_ENTRY (widget);
4682 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4684 gtk_entry_update_cached_style_values (entry);
4686 gtk_entry_recompute (entry);
4688 icon_theme_changed (entry);
4691 /* GtkCellEditable method implementations
4694 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4696 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4697 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4701 gtk_cell_editable_key_press_event (GtkEntry *entry,
4702 GdkEventKey *key_event,
4705 GtkEntryPrivate *priv = entry->priv;
4707 if (key_event->keyval == GDK_KEY_Escape)
4709 priv->editing_canceled = TRUE;
4710 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4711 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4716 /* override focus */
4717 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4719 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4720 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4729 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4732 GtkEntry *entry = GTK_ENTRY (cell_editable);
4733 GtkEntryPrivate *priv = entry->priv;
4735 priv->is_cell_renderer = TRUE;
4737 g_signal_connect (cell_editable, "activate",
4738 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4739 g_signal_connect (cell_editable, "key-press-event",
4740 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4744 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4746 if (password_hint->source_id)
4747 g_source_remove (password_hint->source_id);
4749 g_slice_free (GtkEntryPasswordHint, password_hint);
4754 gtk_entry_remove_password_hint (gpointer data)
4756 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4757 password_hint->position = -1;
4759 /* Force the string to be redrawn, but now without a visible character */
4760 gtk_entry_recompute (GTK_ENTRY (data));
4764 /* Default signal handlers
4767 gtk_entry_real_insert_text (GtkEditable *editable,
4768 const gchar *new_text,
4769 gint new_text_length,
4775 n_chars = g_utf8_strlen (new_text, new_text_length);
4778 * The actual insertion into the buffer. This will end up firing the
4779 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4780 * buffer_notify_text(), buffer_notify_length()
4782 begin_change (GTK_ENTRY (editable));
4784 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4786 end_change (GTK_ENTRY (editable));
4788 if (n_inserted != n_chars)
4789 gtk_widget_error_bell (GTK_WIDGET (editable));
4791 *position += n_inserted;
4795 gtk_entry_real_delete_text (GtkEditable *editable,
4800 * The actual deletion from the buffer. This will end up firing the
4801 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4802 * buffer_notify_text(), buffer_notify_length()
4805 begin_change (GTK_ENTRY (editable));
4807 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4809 end_change (GTK_ENTRY (editable));
4812 /* GtkEntryBuffer signal handlers
4815 buffer_inserted_text (GtkEntryBuffer *buffer,
4821 GtkEntryPrivate *priv = entry->priv;
4822 guint password_hint_timeout;
4824 gint selection_bound;
4826 current_pos = priv->current_pos;
4827 if (current_pos > position)
4828 current_pos += n_chars;
4830 selection_bound = priv->selection_bound;
4831 if (selection_bound > position)
4832 selection_bound += n_chars;
4834 gtk_entry_set_positions (entry, current_pos, selection_bound);
4836 /* Calculate the password hint if it needs to be displayed. */
4837 if (n_chars == 1 && !priv->visible)
4839 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4840 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4843 if (password_hint_timeout > 0)
4845 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4846 quark_password_hint);
4849 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4850 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4851 (GDestroyNotify)gtk_entry_password_hint_free);
4854 password_hint->position = position;
4855 if (password_hint->source_id)
4856 g_source_remove (password_hint->source_id);
4857 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4858 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4864 buffer_deleted_text (GtkEntryBuffer *buffer,
4869 GtkEntryPrivate *priv = entry->priv;
4870 guint end_pos = position + n_chars;
4871 gint selection_bound;
4874 current_pos = priv->current_pos;
4875 if (current_pos > position)
4876 current_pos -= MIN (current_pos, end_pos) - position;
4878 selection_bound = priv->selection_bound;
4879 if (selection_bound > position)
4880 selection_bound -= MIN (selection_bound, end_pos) - position;
4882 gtk_entry_set_positions (entry, current_pos, selection_bound);
4884 /* We might have deleted the selection */
4885 gtk_entry_update_primary_selection (entry);
4887 /* Disable the password hint if one exists. */
4890 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4891 quark_password_hint);
4894 if (password_hint->source_id)
4895 g_source_remove (password_hint->source_id);
4896 password_hint->source_id = 0;
4897 password_hint->position = -1;
4903 buffer_notify_text (GtkEntryBuffer *buffer,
4907 gtk_entry_recompute (entry);
4908 emit_changed (entry);
4909 g_object_notify (G_OBJECT (entry), "text");
4913 buffer_notify_length (GtkEntryBuffer *buffer,
4917 g_object_notify (G_OBJECT (entry), "text-length");
4921 buffer_notify_max_length (GtkEntryBuffer *buffer,
4925 g_object_notify (G_OBJECT (entry), "max-length");
4929 buffer_connect_signals (GtkEntry *entry)
4931 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4932 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4933 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4934 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4935 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4939 buffer_disconnect_signals (GtkEntry *entry)
4941 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4942 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4943 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4944 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4945 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4948 /* Compute the X position for an offset that corresponds to the "more important
4949 * cursor position for that offset. We use this when trying to guess to which
4950 * end of the selection we should go to when the user hits the left or
4954 get_better_cursor_x (GtkEntry *entry,
4957 GtkEntryPrivate *priv = entry->priv;
4958 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4959 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4960 gboolean split_cursor;
4962 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4963 const gchar *text = pango_layout_get_text (layout);
4964 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4966 PangoRectangle strong_pos, weak_pos;
4968 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4969 "gtk-split-cursor", &split_cursor,
4972 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4975 return strong_pos.x / PANGO_SCALE;
4977 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4981 gtk_entry_move_cursor (GtkEntry *entry,
4982 GtkMovementStep step,
4984 gboolean extend_selection)
4986 GtkEntryPrivate *priv = entry->priv;
4987 gint new_pos = priv->current_pos;
4989 _gtk_entry_reset_im_context (entry);
4991 if (priv->current_pos != priv->selection_bound && !extend_selection)
4993 /* If we have a current selection and aren't extending it, move to the
4994 * start/or end of the selection as appropriate
4998 case GTK_MOVEMENT_VISUAL_POSITIONS:
5000 gint current_x = get_better_cursor_x (entry, priv->current_pos);
5001 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
5004 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
5006 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
5009 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5010 case GTK_MOVEMENT_WORDS:
5012 new_pos = MIN (priv->current_pos, priv->selection_bound);
5014 new_pos = MAX (priv->current_pos, priv->selection_bound);
5016 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5017 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5018 case GTK_MOVEMENT_BUFFER_ENDS:
5019 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5021 case GTK_MOVEMENT_DISPLAY_LINES:
5022 case GTK_MOVEMENT_PARAGRAPHS:
5023 case GTK_MOVEMENT_PAGES:
5024 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5032 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5033 new_pos = gtk_entry_move_logically (entry, new_pos, count);
5035 case GTK_MOVEMENT_VISUAL_POSITIONS:
5036 new_pos = gtk_entry_move_visually (entry, new_pos, count);
5037 if (priv->current_pos == new_pos)
5039 if (!extend_selection)
5041 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
5043 GTK_DIR_RIGHT : GTK_DIR_LEFT))
5045 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
5048 gtk_widget_child_focus (toplevel,
5050 GTK_DIR_RIGHT : GTK_DIR_LEFT);
5055 gtk_widget_error_bell (GTK_WIDGET (entry));
5059 case GTK_MOVEMENT_WORDS:
5062 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5067 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5070 if (priv->current_pos == new_pos)
5071 gtk_widget_error_bell (GTK_WIDGET (entry));
5073 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5074 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5075 case GTK_MOVEMENT_BUFFER_ENDS:
5076 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5077 if (priv->current_pos == new_pos)
5078 gtk_widget_error_bell (GTK_WIDGET (entry));
5080 case GTK_MOVEMENT_DISPLAY_LINES:
5081 case GTK_MOVEMENT_PARAGRAPHS:
5082 case GTK_MOVEMENT_PAGES:
5083 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5088 if (extend_selection)
5089 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5091 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5093 gtk_entry_pend_cursor_blink (entry);
5097 gtk_entry_insert_at_cursor (GtkEntry *entry,
5100 GtkEntryPrivate *priv = entry->priv;
5101 GtkEditable *editable = GTK_EDITABLE (entry);
5102 gint pos = priv->current_pos;
5106 _gtk_entry_reset_im_context (entry);
5108 gtk_editable_insert_text (editable, str, -1, &pos);
5109 gtk_editable_set_position (editable, pos);
5114 gtk_entry_delete_from_cursor (GtkEntry *entry,
5118 GtkEntryPrivate *priv = entry->priv;
5119 GtkEditable *editable = GTK_EDITABLE (entry);
5120 gint start_pos = priv->current_pos;
5121 gint end_pos = priv->current_pos;
5122 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5124 _gtk_entry_reset_im_context (entry);
5126 if (!priv->editable)
5128 gtk_widget_error_bell (GTK_WIDGET (entry));
5132 if (priv->selection_bound != priv->current_pos)
5134 gtk_editable_delete_selection (editable);
5140 case GTK_DELETE_CHARS:
5141 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5142 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5144 case GTK_DELETE_WORDS:
5147 /* Move to end of current word, or if not on a word, end of previous word */
5148 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5149 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5153 /* Move to beginning of current word, or if not on a word, begining of next word */
5154 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5155 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5159 case GTK_DELETE_WORD_ENDS:
5162 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5167 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5170 gtk_editable_delete_text (editable, start_pos, end_pos);
5172 case GTK_DELETE_DISPLAY_LINE_ENDS:
5173 case GTK_DELETE_PARAGRAPH_ENDS:
5175 gtk_editable_delete_text (editable, 0, priv->current_pos);
5177 gtk_editable_delete_text (editable, priv->current_pos, -1);
5179 case GTK_DELETE_DISPLAY_LINES:
5180 case GTK_DELETE_PARAGRAPHS:
5181 gtk_editable_delete_text (editable, 0, -1);
5183 case GTK_DELETE_WHITESPACE:
5184 gtk_entry_delete_whitespace (entry);
5188 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5189 gtk_widget_error_bell (GTK_WIDGET (entry));
5191 gtk_entry_pend_cursor_blink (entry);
5195 gtk_entry_backspace (GtkEntry *entry)
5197 GtkEntryPrivate *priv = entry->priv;
5198 GtkEditable *editable = GTK_EDITABLE (entry);
5201 _gtk_entry_reset_im_context (entry);
5203 if (!priv->editable)
5205 gtk_widget_error_bell (GTK_WIDGET (entry));
5209 if (priv->selection_bound != priv->current_pos)
5211 gtk_editable_delete_selection (editable);
5215 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5217 if (prev_pos < priv->current_pos)
5219 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5220 PangoLogAttr *log_attrs;
5223 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5225 /* Deleting parts of characters */
5226 if (log_attrs[priv->current_pos].backspace_deletes_character)
5228 gchar *cluster_text;
5229 gchar *normalized_text;
5232 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5234 normalized_text = g_utf8_normalize (cluster_text,
5235 strlen (cluster_text),
5237 len = g_utf8_strlen (normalized_text, -1);
5239 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5242 gint pos = priv->current_pos;
5244 gtk_editable_insert_text (editable, normalized_text,
5245 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5247 gtk_editable_set_position (editable, pos);
5250 g_free (normalized_text);
5251 g_free (cluster_text);
5255 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5262 gtk_widget_error_bell (GTK_WIDGET (entry));
5265 gtk_entry_pend_cursor_blink (entry);
5269 gtk_entry_copy_clipboard (GtkEntry *entry)
5271 GtkEntryPrivate *priv = entry->priv;
5272 GtkEditable *editable = GTK_EDITABLE (entry);
5276 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5280 gtk_widget_error_bell (GTK_WIDGET (entry));
5284 str = _gtk_entry_get_display_text (entry, start, end);
5285 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5286 GDK_SELECTION_CLIPBOARD),
5293 gtk_entry_cut_clipboard (GtkEntry *entry)
5295 GtkEntryPrivate *priv = entry->priv;
5296 GtkEditable *editable = GTK_EDITABLE (entry);
5301 gtk_widget_error_bell (GTK_WIDGET (entry));
5305 gtk_entry_copy_clipboard (entry);
5309 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5310 gtk_editable_delete_text (editable, start, end);
5314 gtk_widget_error_bell (GTK_WIDGET (entry));
5319 gtk_entry_paste_clipboard (GtkEntry *entry)
5321 GtkEntryPrivate *priv = entry->priv;
5324 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5326 gtk_widget_error_bell (GTK_WIDGET (entry));
5330 gtk_entry_delete_cb (GtkEntry *entry)
5332 GtkEntryPrivate *priv = entry->priv;
5333 GtkEditable *editable = GTK_EDITABLE (entry);
5338 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5339 gtk_editable_delete_text (editable, start, end);
5344 gtk_entry_toggle_overwrite (GtkEntry *entry)
5346 GtkEntryPrivate *priv = entry->priv;
5348 priv->overwrite_mode = !priv->overwrite_mode;
5349 gtk_entry_pend_cursor_blink (entry);
5350 gtk_widget_queue_draw (GTK_WIDGET (entry));
5354 gtk_entry_select_all (GtkEntry *entry)
5356 gtk_entry_select_line (entry);
5360 gtk_entry_real_activate (GtkEntry *entry)
5362 GtkEntryPrivate *priv = entry->priv;
5364 GtkWidget *default_widget, *focus_widget;
5365 GtkWidget *toplevel;
5368 widget = GTK_WIDGET (entry);
5370 if (priv->activates_default)
5372 toplevel = gtk_widget_get_toplevel (widget);
5373 if (GTK_IS_WINDOW (toplevel))
5375 window = GTK_WINDOW (toplevel);
5379 default_widget = gtk_window_get_default_widget (window);
5380 focus_widget = gtk_window_get_focus (window);
5381 if (widget != default_widget &&
5382 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5383 gtk_window_activate_default (window);
5390 keymap_direction_changed (GdkKeymap *keymap,
5393 gtk_entry_recompute (entry);
5396 /* IM Context Callbacks
5400 gtk_entry_commit_cb (GtkIMContext *context,
5404 GtkEntryPrivate *priv = entry->priv;
5407 gtk_entry_enter_text (entry, str);
5411 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5414 GtkEntryPrivate *priv = entry->priv;
5418 gchar *preedit_string;
5421 gtk_im_context_get_preedit_string (priv->im_context,
5422 &preedit_string, NULL,
5424 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5425 priv->preedit_length = strlen (preedit_string);
5426 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5427 priv->preedit_cursor = cursor_pos;
5428 g_free (preedit_string);
5430 gtk_entry_recompute (entry);
5435 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5438 GtkEntryPrivate *priv = entry->priv;
5441 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5442 text = _gtk_entry_get_display_text (entry, 0, -1);
5443 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5444 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5451 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5456 GtkEntryPrivate *priv = entry->priv;
5459 gtk_editable_delete_text (GTK_EDITABLE (entry),
5460 priv->current_pos + offset,
5461 priv->current_pos + offset + n_chars);
5466 /* Internal functions
5469 /* Used for im_commit_cb and inserting Unicode chars */
5471 gtk_entry_enter_text (GtkEntry *entry,
5474 GtkEntryPrivate *priv = entry->priv;
5475 GtkEditable *editable = GTK_EDITABLE (entry);
5477 gboolean old_need_im_reset;
5479 old_need_im_reset = priv->need_im_reset;
5480 priv->need_im_reset = FALSE;
5482 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5483 gtk_editable_delete_selection (editable);
5486 if (priv->overwrite_mode)
5487 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5490 tmp_pos = priv->current_pos;
5491 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5492 gtk_editable_set_position (editable, tmp_pos);
5494 priv->need_im_reset = old_need_im_reset;
5497 /* All changes to priv->current_pos and priv->selection_bound
5498 * should go through this function.
5501 gtk_entry_set_positions (GtkEntry *entry,
5503 gint selection_bound)
5505 GtkEntryPrivate *priv = entry->priv;
5506 gboolean changed = FALSE;
5508 g_object_freeze_notify (G_OBJECT (entry));
5510 if (current_pos != -1 &&
5511 priv->current_pos != current_pos)
5513 priv->current_pos = current_pos;
5516 g_object_notify (G_OBJECT (entry), "cursor-position");
5519 if (selection_bound != -1 &&
5520 priv->selection_bound != selection_bound)
5522 priv->selection_bound = selection_bound;
5525 g_object_notify (G_OBJECT (entry), "selection-bound");
5528 g_object_thaw_notify (G_OBJECT (entry));
5532 gtk_entry_move_adjustments (entry);
5533 gtk_entry_recompute (entry);
5538 gtk_entry_reset_layout (GtkEntry *entry)
5540 GtkEntryPrivate *priv = entry->priv;
5542 if (priv->cached_layout)
5544 g_object_unref (priv->cached_layout);
5545 priv->cached_layout = NULL;
5550 update_im_cursor_location (GtkEntry *entry)
5552 GtkEntryPrivate *priv = entry->priv;
5555 gint strong_xoffset;
5556 gint area_width, area_height;
5558 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5559 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5561 strong_xoffset = strong_x - priv->scroll_offset;
5562 if (strong_xoffset < 0)
5566 else if (strong_xoffset > area_width)
5568 strong_xoffset = area_width;
5570 area.x = strong_xoffset;
5573 area.height = area_height;
5575 gtk_im_context_set_cursor_location (priv->im_context, &area);
5579 recompute_idle_func (gpointer data)
5581 GtkEntry *entry = GTK_ENTRY (data);
5582 GtkEntryPrivate *priv = entry->priv;
5584 priv->recompute_idle = 0;
5586 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5588 gtk_entry_adjust_scroll (entry);
5589 gtk_widget_queue_draw (GTK_WIDGET (entry));
5591 update_im_cursor_location (entry);
5598 gtk_entry_recompute (GtkEntry *entry)
5600 GtkEntryPrivate *priv = entry->priv;
5602 gtk_entry_reset_layout (entry);
5603 gtk_entry_check_cursor_blink (entry);
5605 if (!priv->recompute_idle)
5607 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5608 recompute_idle_func, entry, NULL);
5613 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5616 GtkWidget *widget = GTK_WIDGET (entry);
5617 GtkStyleContext *context;
5618 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5620 context = gtk_widget_get_style_context (widget);
5621 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5623 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5624 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5625 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5628 static inline gboolean
5629 show_placeholder_text (GtkEntry *entry)
5631 GtkEntryPrivate *priv = entry->priv;
5633 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5634 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5635 priv->placeholder_text != NULL)
5641 static PangoLayout *
5642 gtk_entry_create_layout (GtkEntry *entry,
5643 gboolean include_preedit)
5645 GtkEntryPrivate *priv = entry->priv;
5646 GtkWidget *widget = GTK_WIDGET (entry);
5647 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5648 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5649 gboolean placeholder_layout = show_placeholder_text (entry);
5651 gchar *preedit_string = NULL;
5652 gint preedit_length = 0;
5653 PangoAttrList *preedit_attrs = NULL;
5658 pango_layout_set_single_paragraph_mode (layout, TRUE);
5660 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5661 n_bytes = strlen (display);
5663 if (!placeholder_layout && include_preedit)
5665 gtk_im_context_get_preedit_string (priv->im_context,
5666 &preedit_string, &preedit_attrs, NULL);
5667 preedit_length = priv->preedit_length;
5669 else if (placeholder_layout)
5672 PangoAttribute *attr;
5674 gtk_entry_get_placeholder_text_color (entry, &color);
5675 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5676 attr->start_index = 0;
5677 attr->end_index = G_MAXINT;
5678 pango_attr_list_insert (tmp_attrs, attr);
5683 GString *tmp_string = g_string_new (display);
5684 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5686 g_string_insert (tmp_string, cursor_index, preedit_string);
5688 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5690 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5691 cursor_index, preedit_length);
5693 g_string_free (tmp_string, TRUE);
5697 PangoDirection pango_dir;
5699 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5700 pango_dir = pango_find_base_dir (display, n_bytes);
5702 pango_dir = PANGO_DIRECTION_NEUTRAL;
5704 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5706 if (gtk_widget_has_focus (widget))
5708 GdkDisplay *display = gtk_widget_get_display (widget);
5709 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5710 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5711 pango_dir = PANGO_DIRECTION_RTL;
5713 pango_dir = PANGO_DIRECTION_LTR;
5717 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5718 pango_dir = PANGO_DIRECTION_RTL;
5720 pango_dir = PANGO_DIRECTION_LTR;
5724 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5727 priv->resolved_dir = pango_dir;
5729 pango_layout_set_text (layout, display, n_bytes);
5732 pango_layout_set_attributes (layout, tmp_attrs);
5734 g_free (preedit_string);
5738 pango_attr_list_unref (preedit_attrs);
5740 pango_attr_list_unref (tmp_attrs);
5745 static PangoLayout *
5746 gtk_entry_ensure_layout (GtkEntry *entry,
5747 gboolean include_preedit)
5749 GtkEntryPrivate *priv = entry->priv;
5751 if (priv->preedit_length > 0 &&
5752 !include_preedit != !priv->cache_includes_preedit)
5753 gtk_entry_reset_layout (entry);
5755 if (!priv->cached_layout)
5757 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5758 priv->cache_includes_preedit = include_preedit;
5761 return priv->cached_layout;
5765 get_layout_position (GtkEntry *entry,
5769 GtkEntryPrivate *priv = entry->priv;
5770 PangoLayout *layout;
5771 PangoRectangle logical_rect;
5772 gint area_width, area_height;
5774 PangoLayoutLine *line;
5776 layout = gtk_entry_ensure_layout (entry, TRUE);
5778 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5779 area_height = PANGO_SCALE * area_height;
5781 line = pango_layout_get_lines_readonly (layout)->data;
5782 pango_layout_line_get_extents (line, NULL, &logical_rect);
5784 /* Align primarily for locale's ascent/descent */
5785 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5786 priv->ascent + logical_rect.y);
5788 /* Now see if we need to adjust to fit in actual drawn string */
5789 if (logical_rect.height > area_height)
5790 y_pos = (area_height - logical_rect.height) / 2;
5793 else if (y_pos + logical_rect.height > area_height)
5794 y_pos = area_height - logical_rect.height;
5796 y_pos = y_pos / PANGO_SCALE;
5799 *x = - priv->scroll_offset;
5806 draw_text_with_color (GtkEntry *entry,
5808 GdkRGBA *default_color)
5810 GtkEntryPrivate *priv = entry->priv;
5811 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5814 gint start_pos, end_pos;
5816 widget = GTK_WIDGET (entry);
5820 get_layout_position (entry, &x, &y);
5822 cairo_move_to (cr, x, y);
5823 gdk_cairo_set_source_rgba (cr, default_color);
5824 pango_cairo_show_layout (cr, layout);
5826 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5830 PangoRectangle logical_rect;
5831 GdkRGBA selection_color, text_color;
5832 GtkStyleContext *context;
5833 GtkStateFlags state;
5835 context = gtk_widget_get_style_context (widget);
5836 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5837 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5839 state = gtk_widget_get_state_flags (widget);
5840 state |= GTK_STATE_FLAG_SELECTED;
5842 gtk_style_context_get_background_color (context, state, &selection_color);
5843 gtk_style_context_get_color (context, state, &text_color);
5845 for (i = 0; i < n_ranges; ++i)
5846 cairo_rectangle (cr,
5847 - priv->scroll_offset + ranges[2 * i],
5850 logical_rect.height);
5854 gdk_cairo_set_source_rgba (cr, &selection_color);
5857 cairo_move_to (cr, x, y);
5858 gdk_cairo_set_source_rgba (cr, &text_color);
5859 pango_cairo_show_layout (cr, layout);
5867 gtk_entry_draw_text (GtkEntry *entry,
5870 GtkEntryPrivate *priv = entry->priv;
5871 GtkWidget *widget = GTK_WIDGET (entry);
5872 GtkStateFlags state = 0;
5873 GdkRGBA text_color, bar_text_color;
5874 GtkStyleContext *context;
5876 gint progress_x, progress_y, progress_width, progress_height;
5877 gint clip_width, clip_height;
5879 /* Nothing to display at all */
5880 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5883 state = gtk_widget_get_state_flags (widget);
5884 context = gtk_widget_get_style_context (widget);
5886 gtk_style_context_get_color (context, state, &text_color);
5888 /* Get foreground color for progressbars */
5889 gtk_entry_prepare_context_for_progress (entry, context);
5890 gtk_style_context_get_color (context, state, &bar_text_color);
5891 gtk_style_context_restore (context);
5893 get_progress_area (widget,
5894 &progress_x, &progress_y,
5895 &progress_width, &progress_height);
5899 clip_width = gdk_window_get_width (priv->text_area);
5900 clip_height = gdk_window_get_height (priv->text_area);
5901 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5904 /* If the color is the same, or the progress area has a zero
5905 * size, then we only need to draw once. */
5906 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5907 ((progress_width == 0) || (progress_height == 0)))
5909 draw_text_with_color (entry, cr, &text_color);
5913 int frame_x, frame_y, area_x, area_y;
5915 width = gdk_window_get_width (priv->text_area);
5916 height = gdk_window_get_height (priv->text_area);
5920 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5921 cairo_rectangle (cr, 0, 0, width, height);
5923 /* progres area is frame-relative, we need it text-area window
5925 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5926 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5927 progress_x += frame_x - area_x;
5928 progress_y += frame_y - area_y;
5930 cairo_rectangle (cr, progress_x, progress_y,
5931 progress_width, progress_height);
5933 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5935 draw_text_with_color (entry, cr, &text_color);
5940 cairo_rectangle (cr, progress_x, progress_y,
5941 progress_width, progress_height);
5944 draw_text_with_color (entry, cr, &bar_text_color);
5953 gtk_entry_draw_cursor (GtkEntry *entry,
5957 GtkEntryPrivate *priv = entry->priv;
5958 GtkWidget *widget = GTK_WIDGET (entry);
5959 GtkStyleContext *context;
5960 PangoRectangle cursor_rect;
5963 gboolean block_at_line_end;
5964 PangoLayout *layout;
5968 context = gtk_widget_get_style_context (widget);
5970 layout = gtk_entry_ensure_layout (entry, TRUE);
5971 text = pango_layout_get_text (layout);
5972 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5973 get_layout_position (entry, &x, &y);
5975 if (!priv->overwrite_mode)
5978 block = _gtk_text_util_get_block_cursor_location (layout,
5979 cursor_index, &cursor_rect, &block_at_line_end);
5983 gtk_render_insertion_cursor (context, cr,
5985 layout, cursor_index, priv->resolved_dir);
5987 else /* overwrite_mode */
5989 GdkRGBA cursor_color;
5994 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5995 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5996 rect.width = PANGO_PIXELS (cursor_rect.width);
5997 rect.height = PANGO_PIXELS (cursor_rect.height);
5999 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
6000 gdk_cairo_set_source_rgba (cr, &cursor_color);
6001 gdk_cairo_rectangle (cr, &rect);
6004 if (!block_at_line_end)
6006 GtkStateFlags state;
6009 state = gtk_widget_get_state_flags (widget);
6010 gtk_style_context_get_background_color (context, state, &color);
6012 gdk_cairo_rectangle (cr, &rect);
6014 cairo_move_to (cr, x, y);
6015 gdk_cairo_set_source_rgba (cr, &color);
6016 pango_cairo_show_layout (cr, layout);
6024 _gtk_entry_reset_im_context (GtkEntry *entry)
6026 GtkEntryPrivate *priv = entry->priv;
6028 if (priv->need_im_reset)
6030 priv->need_im_reset = FALSE;
6031 gtk_im_context_reset (priv->im_context);
6036 * gtk_entry_reset_im_context:
6037 * @entry: a #GtkEntry
6039 * Reset the input method context of the entry if needed.
6041 * This can be necessary in the case where modifying the buffer
6042 * would confuse on-going input method behavior.
6047 gtk_entry_reset_im_context (GtkEntry *entry)
6049 g_return_if_fail (GTK_IS_ENTRY (entry));
6051 _gtk_entry_reset_im_context (entry);
6055 * gtk_entry_im_context_filter_keypress:
6056 * @entry: a #GtkEntry
6057 * @event: (type Gdk.EventKey): the key event
6059 * Allow the #GtkEntry input method to internally handle key press
6060 * and release events. If this function returns %TRUE, then no further
6061 * processing should be done for this key event. See
6062 * gtk_im_context_filter_keypress().
6064 * Note that you are expected to call this function from your handler
6065 * when overriding key event handling. This is needed in the case when
6066 * you need to insert your own key handling between the input method
6067 * and the default key event handling of the #GtkEntry.
6068 * See gtk_text_view_reset_im_context() for an example of use.
6070 * Return value: %TRUE if the input method handled the key event.
6075 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6078 GtkEntryPrivate *priv;
6080 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6084 return gtk_im_context_filter_keypress (priv->im_context, event);
6088 _gtk_entry_get_im_context (GtkEntry *entry)
6090 return entry->priv->im_context;
6094 gtk_entry_find_position (GtkEntry *entry,
6097 GtkEntryPrivate *priv = entry->priv;
6098 PangoLayout *layout;
6099 PangoLayoutLine *line;
6106 layout = gtk_entry_ensure_layout (entry, TRUE);
6107 text = pango_layout_get_text (layout);
6108 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6110 line = pango_layout_get_lines_readonly (layout)->data;
6111 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6113 if (index >= cursor_index && priv->preedit_length)
6115 if (index >= cursor_index + priv->preedit_length)
6116 index -= priv->preedit_length;
6119 index = cursor_index;
6124 pos = g_utf8_pointer_to_offset (text, text + index);
6131 gtk_entry_get_cursor_locations (GtkEntry *entry,
6136 GtkEntryPrivate *priv = entry->priv;
6137 DisplayMode mode = gtk_entry_get_display_mode (entry);
6139 /* Nothing to display at all, so no cursor is relevant */
6140 if (mode == DISPLAY_BLANK)
6150 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6151 const gchar *text = pango_layout_get_text (layout);
6152 PangoRectangle strong_pos, weak_pos;
6155 if (type == CURSOR_STANDARD)
6157 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6159 else /* type == CURSOR_DND */
6161 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6163 if (priv->dnd_position > priv->current_pos)
6165 if (mode == DISPLAY_NORMAL)
6166 index += priv->preedit_length;
6169 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6170 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6175 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6178 *strong_x = strong_pos.x / PANGO_SCALE;
6181 *weak_x = weak_pos.x / PANGO_SCALE;
6186 gtk_entry_adjust_scroll (GtkEntry *entry)
6188 GtkEntryPrivate *priv = entry->priv;
6189 gint min_offset, max_offset;
6190 gint text_area_width, text_width;
6191 gint strong_x, weak_x;
6192 gint strong_xoffset, weak_xoffset;
6194 PangoLayout *layout;
6195 PangoLayoutLine *line;
6196 PangoRectangle logical_rect;
6198 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6201 text_area_width = gdk_window_get_width (priv->text_area);
6203 if (text_area_width < 0)
6204 text_area_width = 0;
6206 layout = gtk_entry_ensure_layout (entry, TRUE);
6207 line = pango_layout_get_lines_readonly (layout)->data;
6209 pango_layout_line_get_extents (line, NULL, &logical_rect);
6211 /* Display as much text as we can */
6213 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6214 xalign = priv->xalign;
6216 xalign = 1.0 - priv->xalign;
6218 text_width = PANGO_PIXELS(logical_rect.width);
6220 if (text_width > text_area_width)
6223 max_offset = text_width - text_area_width;
6227 min_offset = (text_width - text_area_width) * xalign;
6228 max_offset = min_offset;
6231 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6233 /* And make sure cursors are on screen. Note that the cursor is
6234 * actually drawn one pixel into the INNER_BORDER space on
6235 * the right, when the scroll is at the utmost right. This
6236 * looks better to to me than confining the cursor inside the
6237 * border entirely, though it means that the cursor gets one
6238 * pixel closer to the edge of the widget on the right than
6239 * on the left. This might need changing if one changed
6240 * INNER_BORDER from 2 to 1, as one would do on a
6241 * small-screen-real-estate display.
6243 * We always make sure that the strong cursor is on screen, and
6244 * put the weak cursor on screen if possible.
6247 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6249 strong_xoffset = strong_x - priv->scroll_offset;
6251 if (strong_xoffset < 0)
6253 priv->scroll_offset += strong_xoffset;
6256 else if (strong_xoffset > text_area_width)
6258 priv->scroll_offset += strong_xoffset - text_area_width;
6259 strong_xoffset = text_area_width;
6262 weak_xoffset = weak_x - priv->scroll_offset;
6264 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6266 priv->scroll_offset += weak_xoffset;
6268 else if (weak_xoffset > text_area_width &&
6269 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6271 priv->scroll_offset += weak_xoffset - text_area_width;
6274 g_object_notify (G_OBJECT (entry), "scroll-offset");
6278 gtk_entry_move_adjustments (GtkEntry *entry)
6280 GtkWidget *widget = GTK_WIDGET (entry);
6281 GtkAllocation allocation;
6282 GtkAdjustment *adjustment;
6283 PangoContext *context;
6284 PangoFontMetrics *metrics;
6285 GtkStyleContext *style_context;
6286 GtkStateFlags state;
6291 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6295 gtk_widget_get_allocation (widget, &allocation);
6297 /* Cursor position, layout offset, border width, and widget allocation */
6298 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6299 get_layout_position (entry, &layout_x, NULL);
6300 _gtk_entry_get_borders (entry, &borders);
6301 x += allocation.x + layout_x + borders.left;
6303 /* Approximate width of a char, so user can see what is ahead/behind */
6304 context = gtk_widget_get_pango_context (widget);
6305 style_context = gtk_widget_get_style_context (widget);
6306 state = gtk_widget_get_state_flags (widget);
6308 metrics = pango_context_get_metrics (context,
6309 gtk_style_context_get_font (style_context, state),
6310 pango_context_get_language (context));
6311 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6314 gtk_adjustment_clamp_page (adjustment,
6315 x - (char_width + 1), /* one char + one pixel before */
6316 x + (char_width + 2)); /* one char + cursor + one pixel after */
6320 gtk_entry_move_visually (GtkEntry *entry,
6324 GtkEntryPrivate *priv = entry->priv;
6326 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6329 text = pango_layout_get_text (layout);
6331 index = g_utf8_offset_to_pointer (text, start) - text;
6335 int new_index, new_trailing;
6336 gboolean split_cursor;
6339 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6340 "gtk-split-cursor", &split_cursor,
6347 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6348 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6350 strong = keymap_direction == priv->resolved_dir;
6355 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6360 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6366 else if (new_index != G_MAXINT)
6369 while (new_trailing--)
6370 index = g_utf8_next_char (text + index) - text;
6373 return g_utf8_pointer_to_offset (text, text + index);
6377 gtk_entry_move_logically (GtkEntry *entry,
6381 gint new_pos = start;
6384 length = gtk_entry_buffer_get_length (get_buffer (entry));
6386 /* Prevent any leak of information */
6387 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6389 new_pos = CLAMP (start + count, 0, length);
6393 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6394 PangoLogAttr *log_attrs;
6397 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6399 while (count > 0 && new_pos < length)
6403 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6407 while (count < 0 && new_pos > 0)
6411 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6423 gtk_entry_move_forward_word (GtkEntry *entry,
6425 gboolean allow_whitespace)
6427 gint new_pos = start;
6430 length = gtk_entry_buffer_get_length (get_buffer (entry));
6432 /* Prevent any leak of information */
6433 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6437 else if (new_pos < length)
6439 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6440 PangoLogAttr *log_attrs;
6443 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6445 /* Find the next word boundary */
6447 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6448 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6459 gtk_entry_move_backward_word (GtkEntry *entry,
6461 gboolean allow_whitespace)
6463 gint new_pos = start;
6465 /* Prevent any leak of information */
6466 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6472 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6473 PangoLogAttr *log_attrs;
6476 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6478 new_pos = start - 1;
6480 /* Find the previous word boundary */
6481 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6482 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6492 gtk_entry_delete_whitespace (GtkEntry *entry)
6494 GtkEntryPrivate *priv = entry->priv;
6495 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6496 PangoLogAttr *log_attrs;
6500 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6502 start = end = priv->current_pos;
6504 while (start > 0 && log_attrs[start-1].is_white)
6507 while (end < n_attrs && log_attrs[end].is_white)
6513 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6518 gtk_entry_select_word (GtkEntry *entry)
6520 GtkEntryPrivate *priv = entry->priv;
6521 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6522 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6524 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6528 gtk_entry_select_line (GtkEntry *entry)
6530 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6534 truncate_multiline (const gchar *text)
6539 text[length] && text[length] != '\n' && text[length] != '\r';
6546 paste_received (GtkClipboard *clipboard,
6550 GtkEntry *entry = GTK_ENTRY (data);
6551 GtkEditable *editable = GTK_EDITABLE (entry);
6552 GtkEntryPrivate *priv = entry->priv;
6554 if (priv->button == GDK_BUTTON_MIDDLE)
6556 gint pos, start, end;
6557 pos = priv->insert_pos;
6558 gtk_editable_get_selection_bounds (editable, &start, &end);
6559 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6560 gtk_editable_select_region (editable, pos, pos);
6565 gint pos, start, end;
6567 gboolean popup_completion;
6568 GtkEntryCompletion *completion;
6570 completion = gtk_entry_get_completion (entry);
6572 if (priv->truncate_multiline)
6573 length = truncate_multiline (text);
6575 /* only complete if the selection is at the end */
6576 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6577 MAX (priv->current_pos, priv->selection_bound));
6581 if (gtk_widget_get_mapped (completion->priv->popup_window))
6582 _gtk_entry_completion_popdown (completion);
6584 if (!popup_completion && completion->priv->changed_id > 0)
6585 g_signal_handler_block (entry, completion->priv->changed_id);
6588 begin_change (entry);
6589 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6590 gtk_editable_delete_text (editable, start, end);
6592 pos = priv->current_pos;
6593 gtk_editable_insert_text (editable, text, length, &pos);
6594 gtk_editable_set_position (editable, pos);
6598 !popup_completion && completion->priv->changed_id > 0)
6599 g_signal_handler_unblock (entry, completion->priv->changed_id);
6602 g_object_unref (entry);
6606 gtk_entry_paste (GtkEntry *entry,
6609 g_object_ref (entry);
6610 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6611 paste_received, entry);
6615 primary_get_cb (GtkClipboard *clipboard,
6616 GtkSelectionData *selection_data,
6620 GtkEntry *entry = GTK_ENTRY (data);
6623 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6625 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6626 gtk_selection_data_set_text (selection_data, str, -1);
6632 primary_clear_cb (GtkClipboard *clipboard,
6635 GtkEntry *entry = GTK_ENTRY (data);
6636 GtkEntryPrivate *priv = entry->priv;
6638 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6642 gtk_entry_update_primary_selection (GtkEntry *entry)
6644 GtkTargetList *list;
6645 GtkTargetEntry *targets;
6646 GtkClipboard *clipboard;
6650 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6653 list = gtk_target_list_new (NULL, 0);
6654 gtk_target_list_add_text_targets (list, 0);
6656 targets = gtk_target_table_new_from_list (list, &n_targets);
6658 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6660 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6662 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6663 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6664 primary_clear_cb (clipboard, entry);
6668 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6669 gtk_clipboard_clear (clipboard);
6672 gtk_target_table_free (targets, n_targets);
6673 gtk_target_list_unref (list);
6677 gtk_entry_clear (GtkEntry *entry,
6678 GtkEntryIconPosition icon_pos)
6680 GtkEntryPrivate *priv = entry->priv;
6681 EntryIconInfo *icon_info = priv->icons[icon_pos];
6682 GtkImageType storage_type;
6684 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6687 g_object_freeze_notify (G_OBJECT (entry));
6689 /* Explicitly check, as the pointer may become invalidated
6690 * during destruction.
6692 if (GDK_IS_WINDOW (icon_info->window))
6693 gdk_window_hide (icon_info->window);
6695 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6697 switch (storage_type)
6699 case GTK_IMAGE_PIXBUF:
6700 g_object_notify (G_OBJECT (entry),
6701 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6704 case GTK_IMAGE_STOCK:
6705 g_object_notify (G_OBJECT (entry),
6706 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6709 case GTK_IMAGE_ICON_NAME:
6710 g_object_notify (G_OBJECT (entry),
6711 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6714 case GTK_IMAGE_GICON:
6715 g_object_notify (G_OBJECT (entry),
6716 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6720 g_assert_not_reached ();
6724 _gtk_icon_helper_clear (icon_info->icon_helper);
6726 g_object_notify (G_OBJECT (entry),
6727 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6729 g_object_thaw_notify (G_OBJECT (entry));
6733 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6734 GtkEntryIconPosition icon_pos)
6736 GtkEntryPrivate *priv = entry->priv;
6737 EntryIconInfo *icon_info = priv->icons[icon_pos];
6738 GtkStyleContext *context;
6741 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6742 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6744 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6747 gtk_style_context_restore (context);
6758 * Creates a new entry.
6760 * Return value: a new #GtkEntry.
6763 gtk_entry_new (void)
6765 return g_object_new (GTK_TYPE_ENTRY, NULL);
6769 * gtk_entry_new_with_buffer:
6770 * @buffer: The buffer to use for the new #GtkEntry.
6772 * Creates a new entry with the specified text buffer.
6774 * Return value: a new #GtkEntry
6779 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6781 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6782 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6785 static GtkEntryBuffer*
6786 get_buffer (GtkEntry *entry)
6788 GtkEntryPrivate *priv = entry->priv;
6790 if (priv->buffer == NULL)
6792 GtkEntryBuffer *buffer;
6793 buffer = gtk_entry_buffer_new (NULL, 0);
6794 gtk_entry_set_buffer (entry, buffer);
6795 g_object_unref (buffer);
6798 return priv->buffer;
6802 * gtk_entry_get_buffer:
6803 * @entry: a #GtkEntry
6805 * Get the #GtkEntryBuffer object which holds the text for
6810 * Returns: (transfer none): A #GtkEntryBuffer object.
6813 gtk_entry_get_buffer (GtkEntry *entry)
6815 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6817 return get_buffer (entry);
6821 * gtk_entry_set_buffer:
6822 * @entry: a #GtkEntry
6823 * @buffer: a #GtkEntryBuffer
6825 * Set the #GtkEntryBuffer object which holds the text for
6831 gtk_entry_set_buffer (GtkEntry *entry,
6832 GtkEntryBuffer *buffer)
6834 GtkEntryPrivate *priv;
6837 g_return_if_fail (GTK_IS_ENTRY (entry));
6843 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6844 g_object_ref (buffer);
6849 buffer_disconnect_signals (entry);
6850 g_object_unref (priv->buffer);
6853 priv->buffer = buffer;
6856 buffer_connect_signals (entry);
6858 obj = G_OBJECT (entry);
6859 g_object_freeze_notify (obj);
6860 g_object_notify (obj, "buffer");
6861 g_object_notify (obj, "text");
6862 g_object_notify (obj, "text-length");
6863 g_object_notify (obj, "max-length");
6864 g_object_notify (obj, "visibility");
6865 g_object_notify (obj, "invisible-char");
6866 g_object_notify (obj, "invisible-char-set");
6867 g_object_thaw_notify (obj);
6869 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6870 gtk_entry_recompute (entry);
6874 * gtk_entry_get_text_area:
6875 * @entry: a #GtkEntry
6876 * @text_area: (out): Return location for the text area.
6878 * Gets the area where the entry's text is drawn. This function is
6879 * useful when drawing something to the entry in a draw callback.
6881 * If the entry is not realized, @text_area is filled with zeros.
6883 * See also gtk_entry_get_icon_area().
6888 gtk_entry_get_text_area (GtkEntry *entry,
6889 GdkRectangle *text_area)
6891 GtkEntryPrivate *priv;
6893 g_return_if_fail (GTK_IS_ENTRY (entry));
6894 g_return_if_fail (text_area != NULL);
6898 if (priv->text_area)
6900 GtkAllocation allocation;
6903 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6904 gdk_window_get_position (priv->text_area, &x, &y);
6906 text_area->x = x - allocation.x;
6907 text_area->y = y - allocation.y;
6908 text_area->width = gdk_window_get_width (priv->text_area);
6909 text_area->height = gdk_window_get_height (priv->text_area);
6915 text_area->width = 0;
6916 text_area->height = 0;
6921 * gtk_entry_set_text:
6922 * @entry: a #GtkEntry
6923 * @text: the new text
6925 * Sets the text in the widget to the given
6926 * value, replacing the current contents.
6928 * See gtk_entry_buffer_set_text().
6931 gtk_entry_set_text (GtkEntry *entry,
6935 GtkEntryCompletion *completion;
6937 g_return_if_fail (GTK_IS_ENTRY (entry));
6938 g_return_if_fail (text != NULL);
6940 /* Actually setting the text will affect the cursor and selection;
6941 * if the contents don't actually change, this will look odd to the user.
6943 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6946 completion = gtk_entry_get_completion (entry);
6947 if (completion && completion->priv->changed_id > 0)
6948 g_signal_handler_block (entry, completion->priv->changed_id);
6950 begin_change (entry);
6951 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6953 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6956 if (completion && completion->priv->changed_id > 0)
6957 g_signal_handler_unblock (entry, completion->priv->changed_id);
6961 * gtk_entry_set_visibility:
6962 * @entry: a #GtkEntry
6963 * @visible: %TRUE if the contents of the entry are displayed
6966 * Sets whether the contents of the entry are visible or not.
6967 * When visibility is set to %FALSE, characters are displayed
6968 * as the invisible char, and will also appear that way when
6969 * the text in the entry widget is copied elsewhere.
6971 * By default, GTK+ picks the best invisible character available
6972 * in the current font, but it can be changed with
6973 * gtk_entry_set_invisible_char().
6975 * Note that you probably want to set #GtkEntry:input-purpose
6976 * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
6977 * inform input methods about the purpose of this entry,
6978 * in addition to setting visibility to %FALSE.
6981 gtk_entry_set_visibility (GtkEntry *entry,
6984 GtkEntryPrivate *priv;
6986 g_return_if_fail (GTK_IS_ENTRY (entry));
6990 visible = visible != FALSE;
6992 if (priv->visible != visible)
6994 priv->visible = visible;
6996 g_object_notify (G_OBJECT (entry), "visibility");
6997 gtk_entry_recompute (entry);
7002 * gtk_entry_get_visibility:
7003 * @entry: a #GtkEntry
7005 * Retrieves whether the text in @entry is visible. See
7006 * gtk_entry_set_visibility().
7008 * Return value: %TRUE if the text is currently visible
7011 gtk_entry_get_visibility (GtkEntry *entry)
7013 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7015 return entry->priv->visible;
7019 * gtk_entry_set_invisible_char:
7020 * @entry: a #GtkEntry
7021 * @ch: a Unicode character
7023 * Sets the character to use in place of the actual text when
7024 * gtk_entry_set_visibility() has been called to set text visibility
7025 * to %FALSE. i.e. this is the character used in "password mode" to
7026 * show the user how many characters have been typed. By default, GTK+
7027 * picks the best invisible char available in the current font. If you
7028 * set the invisible char to 0, then the user will get no feedback
7029 * at all; there will be no text on the screen as they type.
7032 gtk_entry_set_invisible_char (GtkEntry *entry,
7035 GtkEntryPrivate *priv;
7037 g_return_if_fail (GTK_IS_ENTRY (entry));
7041 if (!priv->invisible_char_set)
7043 priv->invisible_char_set = TRUE;
7044 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7047 if (ch == priv->invisible_char)
7050 priv->invisible_char = ch;
7051 g_object_notify (G_OBJECT (entry), "invisible-char");
7052 gtk_entry_recompute (entry);
7056 * gtk_entry_get_invisible_char:
7057 * @entry: a #GtkEntry
7059 * Retrieves the character displayed in place of the real characters
7060 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7062 * Return value: the current invisible char, or 0, if the entry does not
7063 * show invisible text at all.
7066 gtk_entry_get_invisible_char (GtkEntry *entry)
7068 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7070 return entry->priv->invisible_char;
7074 * gtk_entry_unset_invisible_char:
7075 * @entry: a #GtkEntry
7077 * Unsets the invisible char previously set with
7078 * gtk_entry_set_invisible_char(). So that the
7079 * default invisible char is used again.
7084 gtk_entry_unset_invisible_char (GtkEntry *entry)
7086 GtkEntryPrivate *priv;
7089 g_return_if_fail (GTK_IS_ENTRY (entry));
7093 if (!priv->invisible_char_set)
7096 priv->invisible_char_set = FALSE;
7097 ch = find_invisible_char (GTK_WIDGET (entry));
7099 if (priv->invisible_char != ch)
7101 priv->invisible_char = ch;
7102 g_object_notify (G_OBJECT (entry), "invisible-char");
7105 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7106 gtk_entry_recompute (entry);
7110 * gtk_entry_set_overwrite_mode:
7111 * @entry: a #GtkEntry
7112 * @overwrite: new value
7114 * Sets whether the text is overwritten when typing in the #GtkEntry.
7119 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7122 GtkEntryPrivate *priv = entry->priv;
7124 g_return_if_fail (GTK_IS_ENTRY (entry));
7126 if (priv->overwrite_mode == overwrite)
7129 gtk_entry_toggle_overwrite (entry);
7131 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7135 * gtk_entry_get_overwrite_mode:
7136 * @entry: a #GtkEntry
7138 * Gets the value set by gtk_entry_set_overwrite_mode().
7140 * Return value: whether the text is overwritten when typing.
7145 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7147 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7149 return entry->priv->overwrite_mode;
7153 * gtk_entry_get_text:
7154 * @entry: a #GtkEntry
7156 * Retrieves the contents of the entry widget.
7157 * See also gtk_editable_get_chars().
7159 * This is equivalent to:
7161 * <informalexample><programlisting>
7162 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7163 * </programlisting></informalexample>
7165 * Return value: a pointer to the contents of the widget as a
7166 * string. This string points to internally allocated
7167 * storage in the widget and must not be freed, modified or
7171 gtk_entry_get_text (GtkEntry *entry)
7173 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7175 return gtk_entry_buffer_get_text (get_buffer (entry));
7179 * gtk_entry_set_max_length:
7180 * @entry: a #GtkEntry
7181 * @max: the maximum length of the entry, or 0 for no maximum.
7182 * (other than the maximum length of entries.) The value passed in will
7183 * be clamped to the range 0-65536.
7185 * Sets the maximum allowed length of the contents of the widget. If
7186 * the current contents are longer than the given length, then they
7187 * will be truncated to fit.
7189 * This is equivalent to:
7191 * <informalexample><programlisting>
7192 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7193 * </programlisting></informalexample>
7196 gtk_entry_set_max_length (GtkEntry *entry,
7199 g_return_if_fail (GTK_IS_ENTRY (entry));
7200 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7204 * gtk_entry_get_max_length:
7205 * @entry: a #GtkEntry
7207 * Retrieves the maximum allowed length of the text in
7208 * @entry. See gtk_entry_set_max_length().
7210 * This is equivalent to:
7212 * <informalexample><programlisting>
7213 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7214 * </programlisting></informalexample>
7216 * Return value: the maximum allowed number of characters
7217 * in #GtkEntry, or 0 if there is no maximum.
7220 gtk_entry_get_max_length (GtkEntry *entry)
7222 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7224 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7228 * gtk_entry_get_text_length:
7229 * @entry: a #GtkEntry
7231 * Retrieves the current length of the text in
7234 * This is equivalent to:
7236 * <informalexample><programlisting>
7237 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7238 * </programlisting></informalexample>
7240 * Return value: the current number of characters
7241 * in #GtkEntry, or 0 if there are none.
7246 gtk_entry_get_text_length (GtkEntry *entry)
7248 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7250 return gtk_entry_buffer_get_length (get_buffer (entry));
7254 * gtk_entry_set_activates_default:
7255 * @entry: a #GtkEntry
7256 * @setting: %TRUE to activate window's default widget on Enter keypress
7258 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7259 * widget for the window containing the entry. This usually means that
7260 * the dialog box containing the entry will be closed, since the default
7261 * widget is usually one of the dialog buttons.
7263 * (For experts: if @setting is %TRUE, the entry calls
7264 * gtk_window_activate_default() on the window containing the entry, in
7265 * the default handler for the #GtkEntry::activate signal.)
7268 gtk_entry_set_activates_default (GtkEntry *entry,
7271 GtkEntryPrivate *priv;
7273 g_return_if_fail (GTK_IS_ENTRY (entry));
7277 setting = setting != FALSE;
7279 if (setting != priv->activates_default)
7281 priv->activates_default = setting;
7282 g_object_notify (G_OBJECT (entry), "activates-default");
7287 * gtk_entry_get_activates_default:
7288 * @entry: a #GtkEntry
7290 * Retrieves the value set by gtk_entry_set_activates_default().
7292 * Return value: %TRUE if the entry will activate the default widget
7295 gtk_entry_get_activates_default (GtkEntry *entry)
7297 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7299 return entry->priv->activates_default;
7303 * gtk_entry_set_width_chars:
7304 * @entry: a #GtkEntry
7305 * @n_chars: width in chars
7307 * Changes the size request of the entry to be about the right size
7308 * for @n_chars characters. Note that it changes the size
7309 * <emphasis>request</emphasis>, the size can still be affected by
7310 * how you pack the widget into containers. If @n_chars is -1, the
7311 * size reverts to the default entry size.
7314 gtk_entry_set_width_chars (GtkEntry *entry,
7317 GtkEntryPrivate *priv;
7319 g_return_if_fail (GTK_IS_ENTRY (entry));
7323 if (priv->width_chars != n_chars)
7325 priv->width_chars = n_chars;
7326 g_object_notify (G_OBJECT (entry), "width-chars");
7327 gtk_widget_queue_resize (GTK_WIDGET (entry));
7332 * gtk_entry_get_width_chars:
7333 * @entry: a #GtkEntry
7335 * Gets the value set by gtk_entry_set_width_chars().
7337 * Return value: number of chars to request space for, or negative if unset
7340 gtk_entry_get_width_chars (GtkEntry *entry)
7342 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7344 return entry->priv->width_chars;
7348 * gtk_entry_set_has_frame:
7349 * @entry: a #GtkEntry
7350 * @setting: new value
7352 * Sets whether the entry has a beveled frame around it.
7355 gtk_entry_set_has_frame (GtkEntry *entry,
7358 GtkEntryPrivate *priv;
7360 g_return_if_fail (GTK_IS_ENTRY (entry));
7364 setting = (setting != FALSE);
7366 if (priv->has_frame == setting)
7369 gtk_widget_queue_resize (GTK_WIDGET (entry));
7370 priv->has_frame = setting;
7371 g_object_notify (G_OBJECT (entry), "has-frame");
7375 * gtk_entry_get_has_frame:
7376 * @entry: a #GtkEntry
7378 * Gets the value set by gtk_entry_set_has_frame().
7380 * Return value: whether the entry has a beveled frame
7383 gtk_entry_get_has_frame (GtkEntry *entry)
7385 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7387 return entry->priv->has_frame;
7391 * gtk_entry_set_inner_border:
7392 * @entry: a #GtkEntry
7393 * @border: (allow-none): a #GtkBorder, or %NULL
7395 * Sets %entry's inner-border property to %border, or clears it if %NULL
7396 * is passed. The inner-border is the area around the entry's text, but
7399 * If set, this property overrides the inner-border style property.
7400 * Overriding the style-provided border is useful when you want to do
7401 * in-place editing of some text in a canvas or list widget, where
7402 * pixel-exact positioning of the entry is important.
7406 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7407 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7408 * this function is ignored by #GtkEntry.
7411 gtk_entry_set_inner_border (GtkEntry *entry,
7412 const GtkBorder *border)
7414 g_return_if_fail (GTK_IS_ENTRY (entry));
7416 gtk_entry_do_set_inner_border (entry, border);
7420 * gtk_entry_get_inner_border:
7421 * @entry: a #GtkEntry
7423 * This function returns the entry's #GtkEntry:inner-border property. See
7424 * gtk_entry_set_inner_border() for more information.
7426 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7430 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7431 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7432 * this function is ignored by #GtkEntry.
7435 gtk_entry_get_inner_border (GtkEntry *entry)
7437 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7439 return gtk_entry_do_get_inner_border (entry);
7443 * gtk_entry_get_layout:
7444 * @entry: a #GtkEntry
7446 * Gets the #PangoLayout used to display the entry.
7447 * The layout is useful to e.g. convert text positions to
7448 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7449 * The returned layout is owned by the entry and must not be
7450 * modified or freed by the caller.
7452 * Keep in mind that the layout text may contain a preedit string, so
7453 * gtk_entry_layout_index_to_text_index() and
7454 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7455 * indices in the layout to byte indices in the entry contents.
7457 * Return value: (transfer none): the #PangoLayout for this entry
7460 gtk_entry_get_layout (GtkEntry *entry)
7462 PangoLayout *layout;
7464 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7466 layout = gtk_entry_ensure_layout (entry, TRUE);
7473 * gtk_entry_layout_index_to_text_index:
7474 * @entry: a #GtkEntry
7475 * @layout_index: byte index into the entry layout text
7477 * Converts from a position in the entry contents (returned
7478 * by gtk_entry_get_text()) to a position in the
7479 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7480 * with text retrieved via pango_layout_get_text()).
7482 * Return value: byte index into the entry contents
7485 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7488 GtkEntryPrivate *priv;
7489 PangoLayout *layout;
7493 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7497 layout = gtk_entry_ensure_layout (entry, TRUE);
7498 text = pango_layout_get_text (layout);
7499 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7501 if (layout_index >= cursor_index && priv->preedit_length)
7503 if (layout_index >= cursor_index + priv->preedit_length)
7504 layout_index -= priv->preedit_length;
7506 layout_index = cursor_index;
7509 return layout_index;
7513 * gtk_entry_text_index_to_layout_index:
7514 * @entry: a #GtkEntry
7515 * @text_index: byte index into the entry contents
7517 * Converts from a position in the entry's #PangoLayout (returned by
7518 * gtk_entry_get_layout()) to a position in the entry contents
7519 * (returned by gtk_entry_get_text()).
7521 * Return value: byte index into the entry layout text
7524 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7527 GtkEntryPrivate *priv;
7528 PangoLayout *layout;
7532 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7536 layout = gtk_entry_ensure_layout (entry, TRUE);
7537 text = pango_layout_get_text (layout);
7538 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7540 if (text_index > cursor_index)
7541 text_index += priv->preedit_length;
7547 * gtk_entry_get_layout_offsets:
7548 * @entry: a #GtkEntry
7549 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7550 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7553 * Obtains the position of the #PangoLayout used to render text
7554 * in the entry, in widget coordinates. Useful if you want to line
7555 * up the text in an entry with some other text, e.g. when using the
7556 * entry to implement editable cells in a sheet widget.
7558 * Also useful to convert mouse events into coordinates inside the
7559 * #PangoLayout, e.g. to take some action if some part of the entry text
7562 * Note that as the user scrolls around in the entry the offsets will
7563 * change; you'll need to connect to the "notify::scroll-offset"
7564 * signal to track this. Remember when using the #PangoLayout
7565 * functions you need to convert to and from pixels using
7566 * PANGO_PIXELS() or #PANGO_SCALE.
7568 * Keep in mind that the layout text may contain a preedit string, so
7569 * gtk_entry_layout_index_to_text_index() and
7570 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7571 * indices in the layout to byte indices in the entry contents.
7574 gtk_entry_get_layout_offsets (GtkEntry *entry,
7578 gint text_area_x, text_area_y;
7580 g_return_if_fail (GTK_IS_ENTRY (entry));
7582 /* this gets coords relative to text area */
7583 get_layout_position (entry, x, y);
7585 /* convert to widget coords */
7586 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7597 * gtk_entry_set_alignment:
7598 * @entry: a #GtkEntry
7599 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7600 * Reversed for RTL layouts
7602 * Sets the alignment for the contents of the entry. This controls
7603 * the horizontal positioning of the contents when the displayed
7604 * text is shorter than the width of the entry.
7609 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7611 GtkEntryPrivate *priv;
7613 g_return_if_fail (GTK_IS_ENTRY (entry));
7619 else if (xalign > 1.0)
7622 if (xalign != priv->xalign)
7624 priv->xalign = xalign;
7626 gtk_entry_recompute (entry);
7628 g_object_notify (G_OBJECT (entry), "xalign");
7633 * gtk_entry_get_alignment:
7634 * @entry: a #GtkEntry
7636 * Gets the value set by gtk_entry_set_alignment().
7638 * Return value: the alignment
7643 gtk_entry_get_alignment (GtkEntry *entry)
7645 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7647 return entry->priv->xalign;
7651 * gtk_entry_set_icon_from_pixbuf:
7652 * @entry: a #GtkEntry
7653 * @icon_pos: Icon position
7654 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7656 * Sets the icon shown in the specified position using a pixbuf.
7658 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7663 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7664 GtkEntryIconPosition icon_pos,
7667 GtkEntryPrivate *priv;
7668 EntryIconInfo *icon_info;
7670 g_return_if_fail (GTK_IS_ENTRY (entry));
7671 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7675 if ((icon_info = priv->icons[icon_pos]) == NULL)
7676 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7678 g_object_freeze_notify (G_OBJECT (entry));
7681 g_object_ref (pixbuf);
7683 gtk_entry_clear (entry, icon_pos);
7687 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7688 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
7689 GTK_ICON_SIZE_MENU);
7691 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7693 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7694 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7698 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7699 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7702 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7703 gdk_window_show_unraised (icon_info->window);
7705 g_object_unref (pixbuf);
7708 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7709 gtk_widget_queue_resize (GTK_WIDGET (entry));
7711 g_object_thaw_notify (G_OBJECT (entry));
7715 * gtk_entry_set_icon_from_stock:
7716 * @entry: A #GtkEntry
7717 * @icon_pos: Icon position
7718 * @stock_id: (allow-none): The name of the stock item, or %NULL
7720 * Sets the icon shown in the entry at the specified position from
7723 * If @stock_id is %NULL, no icon will be shown in the specified position.
7728 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7729 GtkEntryIconPosition icon_pos,
7730 const gchar *stock_id)
7732 GtkEntryPrivate *priv;
7733 EntryIconInfo *icon_info;
7736 g_return_if_fail (GTK_IS_ENTRY (entry));
7737 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7741 if ((icon_info = priv->icons[icon_pos]) == NULL)
7742 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7744 g_object_freeze_notify (G_OBJECT (entry));
7746 /* need to dup before clearing */
7747 new_id = g_strdup (stock_id);
7749 gtk_entry_clear (entry, icon_pos);
7753 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7755 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7757 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7758 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7762 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7763 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7766 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7767 gdk_window_show_unraised (icon_info->window);
7772 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7773 gtk_widget_queue_resize (GTK_WIDGET (entry));
7775 g_object_thaw_notify (G_OBJECT (entry));
7779 * gtk_entry_set_icon_from_icon_name:
7780 * @entry: A #GtkEntry
7781 * @icon_pos: The position at which to set the icon
7782 * @icon_name: (allow-none): An icon name, or %NULL
7784 * Sets the icon shown in the entry at the specified position
7785 * from the current icon theme.
7787 * If the icon name isn't known, a "broken image" icon will be displayed
7790 * If @icon_name is %NULL, no icon will be shown in the specified position.
7795 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7796 GtkEntryIconPosition icon_pos,
7797 const gchar *icon_name)
7799 GtkEntryPrivate *priv;
7800 EntryIconInfo *icon_info;
7803 g_return_if_fail (GTK_IS_ENTRY (entry));
7804 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7808 if ((icon_info = priv->icons[icon_pos]) == NULL)
7809 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7811 g_object_freeze_notify (G_OBJECT (entry));
7813 /* need to dup before clearing */
7814 new_name = g_strdup (icon_name);
7816 gtk_entry_clear (entry, icon_pos);
7818 if (new_name != NULL)
7820 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7822 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7824 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7825 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7829 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7830 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7833 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7834 gdk_window_show_unraised (icon_info->window);
7839 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7840 gtk_widget_queue_resize (GTK_WIDGET (entry));
7842 g_object_thaw_notify (G_OBJECT (entry));
7846 * gtk_entry_set_icon_from_gicon:
7847 * @entry: A #GtkEntry
7848 * @icon_pos: The position at which to set the icon
7849 * @icon: (allow-none): The icon to set, or %NULL
7851 * Sets the icon shown in the entry at the specified position
7852 * from the current icon theme.
7853 * If the icon isn't known, a "broken image" icon will be displayed
7856 * If @icon is %NULL, no icon will be shown in the specified position.
7861 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7862 GtkEntryIconPosition icon_pos,
7865 GtkEntryPrivate *priv;
7866 EntryIconInfo *icon_info;
7868 g_return_if_fail (GTK_IS_ENTRY (entry));
7869 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7873 if ((icon_info = priv->icons[icon_pos]) == NULL)
7874 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7876 g_object_freeze_notify (G_OBJECT (entry));
7878 /* need to ref before clearing */
7880 g_object_ref (icon);
7882 gtk_entry_clear (entry, icon_pos);
7886 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7888 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7890 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7891 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7895 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7896 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7899 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7900 gdk_window_show_unraised (icon_info->window);
7902 g_object_unref (icon);
7905 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7906 gtk_widget_queue_resize (GTK_WIDGET (entry));
7908 g_object_thaw_notify (G_OBJECT (entry));
7912 * gtk_entry_set_icon_activatable:
7913 * @entry: A #GtkEntry
7914 * @icon_pos: Icon position
7915 * @activatable: %TRUE if the icon should be activatable
7917 * Sets whether the icon is activatable.
7922 gtk_entry_set_icon_activatable (GtkEntry *entry,
7923 GtkEntryIconPosition icon_pos,
7924 gboolean activatable)
7926 GtkEntryPrivate *priv;
7927 EntryIconInfo *icon_info;
7929 g_return_if_fail (GTK_IS_ENTRY (entry));
7930 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7934 if ((icon_info = priv->icons[icon_pos]) == NULL)
7935 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7937 activatable = activatable != FALSE;
7939 if (icon_info->nonactivatable != !activatable)
7941 icon_info->nonactivatable = !activatable;
7943 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7944 update_cursors (GTK_WIDGET (entry));
7946 g_object_notify (G_OBJECT (entry),
7947 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7952 * gtk_entry_get_icon_activatable:
7953 * @entry: a #GtkEntry
7954 * @icon_pos: Icon position
7956 * Returns whether the icon is activatable.
7958 * Returns: %TRUE if the icon is activatable.
7963 gtk_entry_get_icon_activatable (GtkEntry *entry,
7964 GtkEntryIconPosition icon_pos)
7966 GtkEntryPrivate *priv;
7967 EntryIconInfo *icon_info;
7969 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7970 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7973 icon_info = priv->icons[icon_pos];
7975 return (!icon_info || !icon_info->nonactivatable);
7979 * gtk_entry_get_icon_pixbuf:
7980 * @entry: A #GtkEntry
7981 * @icon_pos: Icon position
7983 * Retrieves the image used for the icon.
7985 * Unlike the other methods of setting and getting icon data, this
7986 * method will work regardless of whether the icon was set using a
7987 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7989 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7990 * set for this position.
7995 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7996 GtkEntryIconPosition icon_pos)
7998 GtkEntryPrivate *priv;
7999 EntryIconInfo *icon_info;
8002 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8003 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8007 icon_info = priv->icons[icon_pos];
8012 /* HACK: unfortunately this is transfer none, so we need to return
8013 * the icon helper's cache ref directly.
8015 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
8017 g_object_unref (pixbuf);
8023 * gtk_entry_get_icon_gicon:
8024 * @entry: A #GtkEntry
8025 * @icon_pos: Icon position
8027 * Retrieves the #GIcon used for the icon, or %NULL if there is
8028 * no icon or if the icon was set by some other method (e.g., by
8029 * stock, pixbuf, or icon name).
8031 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8032 * or if the icon is not a #GIcon
8037 gtk_entry_get_icon_gicon (GtkEntry *entry,
8038 GtkEntryIconPosition icon_pos)
8040 GtkEntryPrivate *priv;
8041 EntryIconInfo *icon_info;
8043 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8044 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8047 icon_info = priv->icons[icon_pos];
8052 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
8056 * gtk_entry_get_icon_stock:
8057 * @entry: A #GtkEntry
8058 * @icon_pos: Icon position
8060 * Retrieves the stock id used for the icon, or %NULL if there is
8061 * no icon or if the icon was set by some other method (e.g., by
8062 * pixbuf, icon name or gicon).
8064 * Returns: A stock id, or %NULL if no icon is set or if the icon
8065 * wasn't set from a stock id
8070 gtk_entry_get_icon_stock (GtkEntry *entry,
8071 GtkEntryIconPosition icon_pos)
8073 GtkEntryPrivate *priv;
8074 EntryIconInfo *icon_info;
8076 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8077 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8080 icon_info = priv->icons[icon_pos];
8085 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8089 * gtk_entry_get_icon_name:
8090 * @entry: A #GtkEntry
8091 * @icon_pos: Icon position
8093 * Retrieves the icon name used for the icon, or %NULL if there is
8094 * no icon or if the icon was set by some other method (e.g., by
8095 * pixbuf, stock or gicon).
8097 * Returns: An icon name, or %NULL if no icon is set or if the icon
8098 * wasn't set from an icon name
8103 gtk_entry_get_icon_name (GtkEntry *entry,
8104 GtkEntryIconPosition icon_pos)
8106 GtkEntryPrivate *priv;
8107 EntryIconInfo *icon_info;
8109 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8110 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8113 icon_info = priv->icons[icon_pos];
8118 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8122 * gtk_entry_set_icon_sensitive:
8123 * @entry: A #GtkEntry
8124 * @icon_pos: Icon position
8125 * @sensitive: Specifies whether the icon should appear
8126 * sensitive or insensitive
8128 * Sets the sensitivity for the specified icon.
8133 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8134 GtkEntryIconPosition icon_pos,
8137 GtkEntryPrivate *priv;
8138 EntryIconInfo *icon_info;
8140 g_return_if_fail (GTK_IS_ENTRY (entry));
8141 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8145 if ((icon_info = priv->icons[icon_pos]) == NULL)
8146 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8148 if (icon_info->insensitive != !sensitive)
8150 icon_info->insensitive = !sensitive;
8152 icon_info->pressed = FALSE;
8153 icon_info->prelight = FALSE;
8155 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8156 update_cursors (GTK_WIDGET (entry));
8158 gtk_widget_queue_draw (GTK_WIDGET (entry));
8160 g_object_notify (G_OBJECT (entry),
8161 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8166 * gtk_entry_get_icon_sensitive:
8167 * @entry: a #GtkEntry
8168 * @icon_pos: Icon position
8170 * Returns whether the icon appears sensitive or insensitive.
8172 * Returns: %TRUE if the icon is sensitive.
8177 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8178 GtkEntryIconPosition icon_pos)
8180 GtkEntryPrivate *priv;
8181 EntryIconInfo *icon_info;
8183 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8184 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8188 icon_info = priv->icons[icon_pos];
8190 return (!icon_info || !icon_info->insensitive);
8195 * gtk_entry_get_icon_storage_type:
8196 * @entry: a #GtkEntry
8197 * @icon_pos: Icon position
8199 * Gets the type of representation being used by the icon
8200 * to store image data. If the icon has no image data,
8201 * the return value will be %GTK_IMAGE_EMPTY.
8203 * Return value: image representation being used
8208 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8209 GtkEntryIconPosition icon_pos)
8211 GtkEntryPrivate *priv;
8212 EntryIconInfo *icon_info;
8214 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8215 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8219 icon_info = priv->icons[icon_pos];
8222 return GTK_IMAGE_EMPTY;
8224 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8228 * gtk_entry_get_icon_at_pos:
8229 * @entry: a #GtkEntry
8230 * @x: the x coordinate of the position to find
8231 * @y: the y coordinate of the position to find
8233 * Finds the icon at the given position and return its index. The
8234 * position's coordinates are relative to the @entry's top left corner.
8235 * If @x, @y doesn't lie inside an icon, -1 is returned.
8236 * This function is intended for use in a #GtkWidget::query-tooltip
8239 * Returns: the index of the icon at the given position, or -1
8244 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8248 GtkAllocation primary;
8249 GtkAllocation secondary;
8250 gint frame_x, frame_y;
8252 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8254 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8258 get_icon_allocations (entry, &primary, &secondary);
8260 if (primary.x <= x && x < primary.x + primary.width &&
8261 primary.y <= y && y < primary.y + primary.height)
8262 return GTK_ENTRY_ICON_PRIMARY;
8264 if (secondary.x <= x && x < secondary.x + secondary.width &&
8265 secondary.y <= y && y < secondary.y + secondary.height)
8266 return GTK_ENTRY_ICON_SECONDARY;
8272 * gtk_entry_set_icon_drag_source:
8273 * @entry: a #GtkEntry
8274 * @icon_pos: icon position
8275 * @target_list: the targets (data formats) in which the data can be provided
8276 * @actions: a bitmask of the allowed drag actions
8278 * Sets up the icon at the given position so that GTK+ will start a drag
8279 * operation when the user clicks and drags the icon.
8281 * To handle the drag operation, you need to connect to the usual
8282 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8283 * signal, and use gtk_entry_get_current_icon_drag_source() in
8284 * your signal handler to find out if the drag was started from
8287 * By default, GTK+ uses the icon as the drag icon. You can use the
8288 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8289 * have to use g_signal_connect_after() to ensure that your signal handler
8290 * gets executed after the default handler.
8295 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8296 GtkEntryIconPosition icon_pos,
8297 GtkTargetList *target_list,
8298 GdkDragAction actions)
8300 GtkEntryPrivate *priv;
8301 EntryIconInfo *icon_info;
8303 g_return_if_fail (GTK_IS_ENTRY (entry));
8304 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8308 if ((icon_info = priv->icons[icon_pos]) == NULL)
8309 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8311 if (icon_info->target_list)
8312 gtk_target_list_unref (icon_info->target_list);
8313 icon_info->target_list = target_list;
8314 if (icon_info->target_list)
8315 gtk_target_list_ref (icon_info->target_list);
8317 icon_info->actions = actions;
8321 * gtk_entry_get_current_icon_drag_source:
8322 * @entry: a #GtkIconEntry
8324 * Returns the index of the icon which is the source of the current
8325 * DND operation, or -1.
8327 * This function is meant to be used in a #GtkWidget::drag-data-get
8330 * Returns: index of the icon which is the source of the current
8331 * DND operation, or -1.
8336 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8338 GtkEntryPrivate *priv;
8339 EntryIconInfo *icon_info = NULL;
8342 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8346 for (i = 0; i < MAX_ICONS; i++)
8348 if ((icon_info = priv->icons[i]))
8350 if (icon_info->in_drag)
8359 * gtk_entry_get_icon_area:
8360 * @entry: A #GtkEntry
8361 * @icon_pos: Icon position
8362 * @icon_area: (out): Return location for the icon's area
8364 * Gets the area where entry's icon at @icon_pos is drawn.
8365 * This function is useful when drawing something to the
8366 * entry in a draw callback.
8368 * If the entry is not realized or has no icon at the given position,
8369 * @icon_area is filled with zeros.
8371 * See also gtk_entry_get_text_area()
8376 gtk_entry_get_icon_area (GtkEntry *entry,
8377 GtkEntryIconPosition icon_pos,
8378 GdkRectangle *icon_area)
8380 GtkEntryPrivate *priv;
8381 EntryIconInfo *icon_info;
8383 g_return_if_fail (GTK_IS_ENTRY (entry));
8384 g_return_if_fail (icon_area != NULL);
8388 icon_info = priv->icons[icon_pos];
8392 GtkAllocation primary;
8393 GtkAllocation secondary;
8395 get_icon_allocations (entry, &primary, &secondary);
8397 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8398 *icon_area = primary;
8400 *icon_area = secondary;
8406 icon_area->width = 0;
8407 icon_area->height = 0;
8412 ensure_has_tooltip (GtkEntry *entry)
8414 GtkEntryPrivate *priv;
8415 EntryIconInfo *icon_info;
8417 gboolean has_tooltip = FALSE;
8421 for (i = 0; i < MAX_ICONS; i++)
8423 if ((icon_info = priv->icons[i]) != NULL)
8425 if (icon_info->tooltip != NULL)
8433 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8437 * gtk_entry_get_icon_tooltip_text:
8438 * @entry: a #GtkEntry
8439 * @icon_pos: the icon position
8441 * Gets the contents of the tooltip on the icon at the specified
8442 * position in @entry.
8444 * Returns: the tooltip text, or %NULL. Free the returned string
8445 * with g_free() when done.
8450 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8451 GtkEntryIconPosition icon_pos)
8453 GtkEntryPrivate *priv;
8454 EntryIconInfo *icon_info;
8457 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8458 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8462 icon_info = priv->icons[icon_pos];
8467 if (icon_info->tooltip &&
8468 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8469 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8475 * gtk_entry_set_icon_tooltip_text:
8476 * @entry: a #GtkEntry
8477 * @icon_pos: the icon position
8478 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8480 * Sets @tooltip as the contents of the tooltip for the icon
8481 * at the specified position.
8483 * Use %NULL for @tooltip to remove an existing tooltip.
8485 * See also gtk_widget_set_tooltip_text() and
8486 * gtk_entry_set_icon_tooltip_markup().
8491 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8492 GtkEntryIconPosition icon_pos,
8493 const gchar *tooltip)
8495 GtkEntryPrivate *priv;
8496 EntryIconInfo *icon_info;
8498 g_return_if_fail (GTK_IS_ENTRY (entry));
8499 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8503 if ((icon_info = priv->icons[icon_pos]) == NULL)
8504 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8506 if (icon_info->tooltip)
8507 g_free (icon_info->tooltip);
8509 /* Treat an empty string as a NULL string,
8510 * because an empty string would be useless for a tooltip:
8512 if (tooltip && tooltip[0] == '\0')
8515 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8517 ensure_has_tooltip (entry);
8521 * gtk_entry_get_icon_tooltip_markup:
8522 * @entry: a #GtkEntry
8523 * @icon_pos: the icon position
8525 * Gets the contents of the tooltip on the icon at the specified
8526 * position in @entry.
8528 * Returns: the tooltip text, or %NULL. Free the returned string
8529 * with g_free() when done.
8534 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8535 GtkEntryIconPosition icon_pos)
8537 GtkEntryPrivate *priv;
8538 EntryIconInfo *icon_info;
8540 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8541 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8545 icon_info = priv->icons[icon_pos];
8550 return g_strdup (icon_info->tooltip);
8554 * gtk_entry_set_icon_tooltip_markup:
8555 * @entry: a #GtkEntry
8556 * @icon_pos: the icon position
8557 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8559 * Sets @tooltip as the contents of the tooltip for the icon at
8560 * the specified position. @tooltip is assumed to be marked up with
8561 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8563 * Use %NULL for @tooltip to remove an existing tooltip.
8565 * See also gtk_widget_set_tooltip_markup() and
8566 * gtk_entry_set_icon_tooltip_text().
8571 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8572 GtkEntryIconPosition icon_pos,
8573 const gchar *tooltip)
8575 GtkEntryPrivate *priv;
8576 EntryIconInfo *icon_info;
8578 g_return_if_fail (GTK_IS_ENTRY (entry));
8579 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8583 if ((icon_info = priv->icons[icon_pos]) == NULL)
8584 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8586 if (icon_info->tooltip)
8587 g_free (icon_info->tooltip);
8589 /* Treat an empty string as a NULL string,
8590 * because an empty string would be useless for a tooltip:
8592 if (tooltip && tooltip[0] == '\0')
8595 icon_info->tooltip = g_strdup (tooltip);
8597 ensure_has_tooltip (entry);
8601 gtk_entry_query_tooltip (GtkWidget *widget,
8604 gboolean keyboard_tip,
8605 GtkTooltip *tooltip)
8608 GtkEntryPrivate *priv;
8609 EntryIconInfo *icon_info;
8612 entry = GTK_ENTRY (widget);
8617 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8620 if ((icon_info = priv->icons[icon_pos]) != NULL)
8622 if (icon_info->tooltip)
8624 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8633 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8640 /* Quick hack of a popup menu
8643 activate_cb (GtkWidget *menuitem,
8646 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8647 g_signal_emit_by_name (entry, signal);
8652 gtk_entry_mnemonic_activate (GtkWidget *widget,
8653 gboolean group_cycling)
8655 gtk_widget_grab_focus (widget);
8660 gtk_entry_grab_notify (GtkWidget *widget,
8661 gboolean was_grabbed)
8663 GtkEntryPrivate *priv;
8665 priv = GTK_ENTRY (widget)->priv;
8668 gtk_widget_device_is_shadowed (widget, priv->device))
8670 /* Unset button so we don't expect
8671 * a button release anymore
8674 priv->device = NULL;
8675 priv->in_drag = FALSE;
8680 append_action_signal (GtkEntry *entry,
8682 const gchar *stock_id,
8683 const gchar *signal,
8686 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8688 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8689 g_signal_connect (menuitem, "activate",
8690 G_CALLBACK (activate_cb), entry);
8692 gtk_widget_set_sensitive (menuitem, sensitive);
8694 gtk_widget_show (menuitem);
8695 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8699 popup_menu_detach (GtkWidget *attach_widget,
8702 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8703 GtkEntryPrivate *priv_attach = entry_attach->priv;
8705 priv_attach->popup_menu = NULL;
8709 popup_position_func (GtkMenu *menu,
8715 GtkEntry *entry = GTK_ENTRY (user_data);
8716 GtkEntryPrivate *priv = entry->priv;
8717 GtkWidget *widget = GTK_WIDGET (entry);
8719 GtkRequisition menu_req;
8720 GdkRectangle monitor;
8722 gint monitor_num, strong_x, height;
8724 g_return_if_fail (gtk_widget_get_realized (widget));
8726 gdk_window_get_origin (priv->text_area, x, y);
8728 screen = gtk_widget_get_screen (widget);
8729 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8730 if (monitor_num < 0)
8732 gtk_menu_set_monitor (menu, monitor_num);
8734 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8735 gtk_widget_get_preferred_size (priv->popup_menu,
8737 height = gdk_window_get_height (priv->text_area);
8738 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8739 _gtk_entry_get_borders (entry, &borders);
8741 *x += borders.left + strong_x - priv->scroll_offset;
8742 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8743 *x -= menu_req.width;
8745 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8747 else if ((*y - menu_req.height) >= monitor.y)
8748 *y -= menu_req.height;
8749 else if (monitor.y + monitor.height - (*y + height) > *y)
8752 *y -= menu_req.height;
8758 unichar_chosen_func (const char *text,
8761 GtkEntry *entry = GTK_ENTRY (data);
8762 GtkEntryPrivate *priv = entry->priv;
8765 gtk_entry_enter_text (entry, text);
8777 popup_targets_received (GtkClipboard *clipboard,
8778 GtkSelectionData *data,
8781 PopupInfo *info = user_data;
8782 GtkEntry *entry = info->entry;
8783 GtkEntryPrivate *info_entry_priv = entry->priv;
8785 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8788 gboolean clipboard_contains_text;
8789 GtkWidget *menuitem;
8791 gboolean show_input_method_menu;
8792 gboolean show_unicode_menu;
8794 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8795 if (info_entry_priv->popup_menu)
8796 gtk_widget_destroy (info_entry_priv->popup_menu);
8798 info_entry_priv->popup_menu = gtk_menu_new ();
8800 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8804 mode = gtk_entry_get_display_mode (entry);
8805 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8806 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8807 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8809 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8810 mode == DISPLAY_NORMAL &&
8811 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8813 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8814 info_entry_priv->editable && clipboard_contains_text);
8816 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8817 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8818 g_signal_connect_swapped (menuitem, "activate",
8819 G_CALLBACK (gtk_entry_delete_cb), entry);
8820 gtk_widget_show (menuitem);
8821 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8823 menuitem = gtk_separator_menu_item_new ();
8824 gtk_widget_show (menuitem);
8825 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8827 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8828 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8829 g_signal_connect_swapped (menuitem, "activate",
8830 G_CALLBACK (gtk_entry_select_all), entry);
8831 gtk_widget_show (menuitem);
8832 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8834 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8835 "gtk-show-input-method-menu", &show_input_method_menu,
8836 "gtk-show-unicode-menu", &show_unicode_menu,
8839 if (show_input_method_menu || show_unicode_menu)
8841 menuitem = gtk_separator_menu_item_new ();
8842 gtk_widget_show (menuitem);
8843 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8846 if (show_input_method_menu)
8848 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8849 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8850 gtk_widget_show (menuitem);
8851 submenu = gtk_menu_new ();
8852 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8854 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8856 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8857 GTK_MENU_SHELL (submenu));
8860 if (show_unicode_menu)
8862 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8863 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8864 gtk_widget_show (menuitem);
8866 submenu = gtk_menu_new ();
8867 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8868 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8870 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8871 unichar_chosen_func,
8875 g_signal_emit (entry,
8876 signals[POPULATE_POPUP],
8878 info_entry_priv->popup_menu);
8882 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8883 info->device, NULL, NULL, NULL, NULL, NULL,
8884 info->button, info->time);
8887 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8888 popup_position_func, entry,
8889 0, gtk_get_current_event_time ());
8890 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8894 g_object_unref (entry);
8895 g_slice_free (PopupInfo, info);
8899 gtk_entry_do_popup (GtkEntry *entry,
8900 GdkEventButton *event)
8902 PopupInfo *info = g_slice_new (PopupInfo);
8904 /* In order to know what entries we should make sensitive, we
8905 * ask for the current targets of the clipboard, and when
8906 * we get them, then we actually pop up the menu.
8908 info->entry = g_object_ref (entry);
8912 info->button = event->button;
8913 info->time = event->time;
8914 info->device = event->device;
8919 info->time = gtk_get_current_event_time ();
8920 info->device = NULL;
8923 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8924 gdk_atom_intern_static_string ("TARGETS"),
8925 popup_targets_received,
8930 gtk_entry_popup_menu (GtkWidget *widget)
8932 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8937 gtk_entry_drag_begin (GtkWidget *widget,
8938 GdkDragContext *context)
8940 GtkEntry *entry = GTK_ENTRY (widget);
8941 GtkEntryPrivate *priv = entry->priv;
8944 for (i = 0; i < MAX_ICONS; i++)
8946 EntryIconInfo *icon_info = priv->icons[i];
8948 if (icon_info != NULL)
8950 if (icon_info->in_drag)
8954 pix = _gtk_icon_helper_ensure_pixbuf
8955 (icon_info->icon_helper,
8956 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8957 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8959 g_object_unref (pix);
8966 gtk_entry_drag_end (GtkWidget *widget,
8967 GdkDragContext *context)
8969 GtkEntry *entry = GTK_ENTRY (widget);
8970 GtkEntryPrivate *priv = entry->priv;
8973 for (i = 0; i < MAX_ICONS; i++)
8975 EntryIconInfo *icon_info = priv->icons[i];
8977 if (icon_info != NULL)
8978 icon_info->in_drag = 0;
8983 gtk_entry_drag_leave (GtkWidget *widget,
8984 GdkDragContext *context,
8987 GtkEntry *entry = GTK_ENTRY (widget);
8988 GtkEntryPrivate *priv = entry->priv;
8990 priv->dnd_position = -1;
8991 gtk_widget_queue_draw (widget);
8995 gtk_entry_drag_drop (GtkWidget *widget,
8996 GdkDragContext *context,
9001 GtkEntry *entry = GTK_ENTRY (widget);
9002 GtkEntryPrivate *priv = entry->priv;
9003 GdkAtom target = GDK_NONE;
9006 target = gtk_drag_dest_find_target (widget, context, NULL);
9008 if (target != GDK_NONE)
9009 gtk_drag_get_data (widget, context, target, time);
9011 gtk_drag_finish (context, FALSE, FALSE, time);
9017 gtk_entry_drag_motion (GtkWidget *widget,
9018 GdkDragContext *context,
9023 GtkEntry *entry = GTK_ENTRY (widget);
9024 GtkEntryPrivate *priv = entry->priv;
9025 GtkStyleContext *style_context;
9026 GtkWidget *source_widget;
9027 GdkDragAction suggested_action;
9028 gint new_position, old_position;
9032 style_context = gtk_widget_get_style_context (widget);
9033 gtk_style_context_get_padding (style_context, 0, &padding);
9037 old_position = priv->dnd_position;
9038 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9040 if (priv->editable &&
9041 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9043 source_widget = gtk_drag_get_source_widget (context);
9044 suggested_action = gdk_drag_context_get_suggested_action (context);
9046 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9047 new_position < sel1 || new_position > sel2)
9049 if (source_widget == widget)
9051 /* Default to MOVE, unless the user has
9052 * pressed ctrl or alt to affect available actions
9054 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9055 suggested_action = GDK_ACTION_MOVE;
9058 priv->dnd_position = new_position;
9062 if (source_widget == widget)
9063 suggested_action = 0; /* Can't drop in selection where drag started */
9065 priv->dnd_position = -1;
9070 /* Entry not editable, or no text */
9071 suggested_action = 0;
9072 priv->dnd_position = -1;
9075 gdk_drag_status (context, suggested_action, time);
9077 if (priv->dnd_position != old_position)
9078 gtk_widget_queue_draw (widget);
9084 gtk_entry_drag_data_received (GtkWidget *widget,
9085 GdkDragContext *context,
9088 GtkSelectionData *selection_data,
9092 GtkEntry *entry = GTK_ENTRY (widget);
9093 GtkEntryPrivate *priv = entry->priv;
9094 GtkEditable *editable = GTK_EDITABLE (widget);
9095 GtkStyleContext *style_context;
9099 str = (gchar *) gtk_selection_data_get_text (selection_data);
9101 style_context = gtk_widget_get_style_context (widget);
9102 gtk_style_context_get_padding (style_context, 0, &padding);
9106 if (str && priv->editable)
9112 if (priv->truncate_multiline)
9113 length = truncate_multiline (str);
9115 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9117 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9118 new_position < sel1 || new_position > sel2)
9120 gtk_editable_insert_text (editable, str, length, &new_position);
9124 /* Replacing selection */
9125 begin_change (entry);
9126 gtk_editable_delete_text (editable, sel1, sel2);
9127 gtk_editable_insert_text (editable, str, length, &sel1);
9131 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9135 /* Drag and drop didn't happen! */
9136 gtk_drag_finish (context, FALSE, FALSE, time);
9143 gtk_entry_drag_data_get (GtkWidget *widget,
9144 GdkDragContext *context,
9145 GtkSelectionData *selection_data,
9149 GtkEntry *entry = GTK_ENTRY (widget);
9150 GtkEntryPrivate *priv = entry->priv;
9151 GtkEditable *editable = GTK_EDITABLE (widget);
9152 gint sel_start, sel_end;
9155 /* If there is an icon drag going on, exit early. */
9156 for (i = 0; i < MAX_ICONS; i++)
9158 EntryIconInfo *icon_info = priv->icons[i];
9160 if (icon_info != NULL)
9162 if (icon_info->in_drag)
9167 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9169 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9171 gtk_selection_data_set_text (selection_data, str, -1);
9179 gtk_entry_drag_data_delete (GtkWidget *widget,
9180 GdkDragContext *context)
9182 GtkEntry *entry = GTK_ENTRY (widget);
9183 GtkEntryPrivate *priv = entry->priv;
9184 GtkEditable *editable = GTK_EDITABLE (widget);
9185 gint sel_start, sel_end;
9188 /* If there is an icon drag going on, exit early. */
9189 for (i = 0; i < MAX_ICONS; i++)
9191 EntryIconInfo *icon_info = priv->icons[i];
9193 if (icon_info != NULL)
9195 if (icon_info->in_drag)
9200 if (priv->editable &&
9201 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9202 gtk_editable_delete_text (editable, sel_start, sel_end);
9205 /* We display the cursor when
9207 * - the selection is empty, AND
9208 * - the widget has focus
9211 #define CURSOR_ON_MULTIPLIER 2
9212 #define CURSOR_OFF_MULTIPLIER 1
9213 #define CURSOR_PEND_MULTIPLIER 3
9214 #define CURSOR_DIVIDER 3
9217 cursor_blinks (GtkEntry *entry)
9219 GtkEntryPrivate *priv = entry->priv;
9221 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9223 priv->selection_bound == priv->current_pos)
9225 GtkSettings *settings;
9228 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9229 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9238 get_middle_click_paste (GtkEntry *entry)
9240 GtkSettings *settings;
9243 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9244 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9250 get_cursor_time (GtkEntry *entry)
9252 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9255 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9261 get_cursor_blink_timeout (GtkEntry *entry)
9263 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9266 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9272 show_cursor (GtkEntry *entry)
9274 GtkEntryPrivate *priv = entry->priv;
9277 if (!priv->cursor_visible)
9279 priv->cursor_visible = TRUE;
9281 widget = GTK_WIDGET (entry);
9282 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9283 gtk_widget_queue_draw (widget);
9288 hide_cursor (GtkEntry *entry)
9290 GtkEntryPrivate *priv = entry->priv;
9293 if (priv->cursor_visible)
9295 priv->cursor_visible = FALSE;
9297 widget = GTK_WIDGET (entry);
9298 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9299 gtk_widget_queue_draw (widget);
9307 blink_cb (gpointer data)
9310 GtkEntryPrivate *priv;
9313 entry = GTK_ENTRY (data);
9316 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9318 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9319 "connect a handler to this signal, it must return\n"
9320 "FALSE so the entry gets the event as well");
9322 gtk_entry_check_cursor_blink (entry);
9327 g_assert (priv->selection_bound == priv->current_pos);
9329 blink_timeout = get_cursor_blink_timeout (entry);
9330 if (priv->blink_time > 1000 * blink_timeout &&
9331 blink_timeout < G_MAXINT/1000)
9333 /* we've blinked enough without the user doing anything, stop blinking */
9334 show_cursor (entry);
9335 priv->blink_timeout = 0;
9337 else if (priv->cursor_visible)
9339 hide_cursor (entry);
9340 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9346 show_cursor (entry);
9347 priv->blink_time += get_cursor_time (entry);
9348 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9353 /* Remove ourselves */
9358 gtk_entry_check_cursor_blink (GtkEntry *entry)
9360 GtkEntryPrivate *priv = entry->priv;
9362 if (cursor_blinks (entry))
9364 if (!priv->blink_timeout)
9366 show_cursor (entry);
9367 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9374 if (priv->blink_timeout)
9376 g_source_remove (priv->blink_timeout);
9377 priv->blink_timeout = 0;
9380 priv->cursor_visible = TRUE;
9385 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9387 GtkEntryPrivate *priv = entry->priv;
9389 if (cursor_blinks (entry))
9391 if (priv->blink_timeout != 0)
9392 g_source_remove (priv->blink_timeout);
9394 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9397 show_cursor (entry);
9402 gtk_entry_reset_blink_time (GtkEntry *entry)
9404 GtkEntryPrivate *priv = entry->priv;
9406 priv->blink_time = 0;
9412 gtk_entry_completion_timeout (gpointer data)
9414 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9415 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9417 completion->priv->completion_timeout = 0;
9419 if (completion->priv->filter_model &&
9420 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9421 >= completion->priv->minimum_key_length)
9425 GtkTreeSelection *s;
9426 gboolean popup_single;
9428 gtk_entry_completion_complete (completion);
9429 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9431 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9433 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9435 gtk_tree_selection_unselect_all (s);
9437 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9439 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9440 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9442 if (gtk_widget_get_visible (completion->priv->popup_window))
9443 _gtk_entry_completion_resize_popup (completion);
9445 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9448 _gtk_entry_completion_popdown (completion);
9450 else if (gtk_widget_get_visible (completion->priv->popup_window))
9451 _gtk_entry_completion_popdown (completion);
9456 static inline gboolean
9457 keyval_is_cursor_move (guint keyval)
9459 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9462 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9465 if (keyval == GDK_KEY_Page_Up)
9468 if (keyval == GDK_KEY_Page_Down)
9475 gtk_entry_completion_key_press (GtkWidget *widget,
9479 gint matches, actions = 0;
9480 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9482 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9485 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9487 if (completion->priv->actions)
9488 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9490 if (keyval_is_cursor_move (event->keyval))
9492 GtkTreePath *path = NULL;
9494 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9496 if (completion->priv->current_selected < 0)
9497 completion->priv->current_selected = matches + actions - 1;
9499 completion->priv->current_selected--;
9501 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9503 if (completion->priv->current_selected < matches + actions - 1)
9504 completion->priv->current_selected++;
9506 completion->priv->current_selected = -1;
9508 else if (event->keyval == GDK_KEY_Page_Up)
9510 if (completion->priv->current_selected < 0)
9511 completion->priv->current_selected = matches + actions - 1;
9512 else if (completion->priv->current_selected == 0)
9513 completion->priv->current_selected = -1;
9514 else if (completion->priv->current_selected < matches)
9516 completion->priv->current_selected -= PAGE_STEP;
9517 if (completion->priv->current_selected < 0)
9518 completion->priv->current_selected = 0;
9522 completion->priv->current_selected -= PAGE_STEP;
9523 if (completion->priv->current_selected < matches - 1)
9524 completion->priv->current_selected = matches - 1;
9527 else if (event->keyval == GDK_KEY_Page_Down)
9529 if (completion->priv->current_selected < 0)
9530 completion->priv->current_selected = 0;
9531 else if (completion->priv->current_selected < matches - 1)
9533 completion->priv->current_selected += PAGE_STEP;
9534 if (completion->priv->current_selected > matches - 1)
9535 completion->priv->current_selected = matches - 1;
9537 else if (completion->priv->current_selected == matches + actions - 1)
9539 completion->priv->current_selected = -1;
9543 completion->priv->current_selected += PAGE_STEP;
9544 if (completion->priv->current_selected > matches + actions - 1)
9545 completion->priv->current_selected = matches + actions - 1;
9549 if (completion->priv->current_selected < 0)
9551 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9552 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9554 if (completion->priv->inline_selection &&
9555 completion->priv->completion_prefix)
9557 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9558 completion->priv->completion_prefix);
9559 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9562 else if (completion->priv->current_selected < matches)
9564 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9566 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9567 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9570 if (completion->priv->inline_selection)
9574 GtkTreeIter child_iter;
9575 GtkTreeModel *model = NULL;
9576 GtkTreeSelection *sel;
9579 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9580 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9583 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9584 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9586 if (completion->priv->completion_prefix == NULL)
9587 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9589 g_signal_emit_by_name (completion, "cursor-on-match", model,
9590 &child_iter, &entry_set);
9593 else if (completion->priv->current_selected - matches >= 0)
9595 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9597 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9598 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9601 if (completion->priv->inline_selection &&
9602 completion->priv->completion_prefix)
9604 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9605 completion->priv->completion_prefix);
9606 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9610 gtk_tree_path_free (path);
9614 else if (event->keyval == GDK_KEY_Escape ||
9615 event->keyval == GDK_KEY_Left ||
9616 event->keyval == GDK_KEY_KP_Left ||
9617 event->keyval == GDK_KEY_Right ||
9618 event->keyval == GDK_KEY_KP_Right)
9620 gboolean retval = TRUE;
9622 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9623 _gtk_entry_completion_popdown (completion);
9625 if (completion->priv->current_selected < 0)
9628 goto keypress_completion_out;
9630 else if (completion->priv->inline_selection)
9632 /* Escape rejects the tentative completion */
9633 if (event->keyval == GDK_KEY_Escape)
9635 if (completion->priv->completion_prefix)
9636 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9637 completion->priv->completion_prefix);
9639 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9642 /* Move the cursor to the end for Right/Esc */
9643 if (event->keyval == GDK_KEY_Right ||
9644 event->keyval == GDK_KEY_KP_Right ||
9645 event->keyval == GDK_KEY_Escape)
9646 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9647 /* Let the default keybindings run for Left, i.e. either move to the
9648 * previous character or select word if a modifier is used */
9653 keypress_completion_out:
9654 if (completion->priv->inline_selection)
9656 g_free (completion->priv->completion_prefix);
9657 completion->priv->completion_prefix = NULL;
9662 else if (event->keyval == GDK_KEY_Tab ||
9663 event->keyval == GDK_KEY_KP_Tab ||
9664 event->keyval == GDK_KEY_ISO_Left_Tab)
9666 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9667 _gtk_entry_completion_popdown (completion);
9669 g_free (completion->priv->completion_prefix);
9670 completion->priv->completion_prefix = NULL;
9674 else if (event->keyval == GDK_KEY_ISO_Enter ||
9675 event->keyval == GDK_KEY_KP_Enter ||
9676 event->keyval == GDK_KEY_Return)
9679 GtkTreeModel *model = NULL;
9680 GtkTreeModel *child_model;
9681 GtkTreeIter child_iter;
9682 GtkTreeSelection *sel;
9683 gboolean retval = TRUE;
9685 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9686 _gtk_entry_completion_popdown (completion);
9688 if (completion->priv->current_selected < matches)
9692 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9693 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9695 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9696 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9697 g_signal_handler_block (widget, completion->priv->changed_id);
9698 g_signal_emit_by_name (completion, "match-selected",
9699 child_model, &child_iter, &entry_set);
9700 g_signal_handler_unblock (widget, completion->priv->changed_id);
9706 gtk_tree_model_get (model, &iter,
9707 completion->priv->text_column, &str,
9710 gtk_entry_set_text (GTK_ENTRY (widget), str);
9712 /* move the cursor to the end */
9713 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9721 else if (completion->priv->current_selected - matches >= 0)
9723 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9724 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9728 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9729 g_signal_emit_by_name (completion, "action-activated",
9730 gtk_tree_path_get_indices (path)[0]);
9731 gtk_tree_path_free (path);
9737 g_free (completion->priv->completion_prefix);
9738 completion->priv->completion_prefix = NULL;
9747 gtk_entry_completion_changed (GtkWidget *widget,
9750 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9751 GtkEntry *entry = GTK_ENTRY (widget);
9752 GtkEntryPrivate *priv = entry->priv;
9755 /* (re)install completion timeout */
9756 if (completion->priv->completion_timeout)
9757 g_source_remove (completion->priv->completion_timeout);
9759 if (!gtk_entry_get_text (entry))
9762 /* no need to normalize for this test */
9763 if (completion->priv->minimum_key_length > 0 &&
9764 strcmp ("", gtk_entry_get_text (entry)) == 0)
9766 if (gtk_widget_get_visible (completion->priv->popup_window))
9767 _gtk_entry_completion_popdown (completion);
9771 device = gtk_get_current_event_device ();
9773 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9774 device = gdk_device_get_associated_device (device);
9777 priv->completion_device = device;
9779 completion->priv->completion_timeout =
9780 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9781 gtk_entry_completion_timeout,
9786 check_completion_callback (GtkEntryCompletion *completion)
9788 completion->priv->check_completion_idle = NULL;
9790 gtk_entry_completion_complete (completion);
9791 gtk_entry_completion_insert_prefix (completion);
9797 clear_completion_callback (GtkEntry *entry,
9800 if (pspec->name == I_("cursor-position") ||
9801 pspec->name == I_("selection-bound"))
9803 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9805 completion->priv->has_completion = FALSE;
9810 accept_completion_callback (GtkEntry *entry)
9812 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9814 if (completion->priv->has_completion)
9815 gtk_editable_set_position (GTK_EDITABLE (entry),
9816 gtk_entry_buffer_get_length (get_buffer (entry)));
9822 completion_insert_text_callback (GtkEntry *entry,
9826 GtkEntryCompletion *completion)
9828 /* idle to update the selection based on the file list */
9829 if (completion->priv->check_completion_idle == NULL)
9831 completion->priv->check_completion_idle = g_idle_source_new ();
9832 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9833 g_source_set_closure (completion->priv->check_completion_idle,
9834 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9835 G_OBJECT (completion)));
9836 g_source_attach (completion->priv->check_completion_idle, NULL);
9841 completion_changed (GtkEntryCompletion *completion,
9845 GtkEntry *entry = GTK_ENTRY (data);
9847 if (pspec->name == I_("popup-completion") ||
9848 pspec->name == I_("inline-completion"))
9850 disconnect_completion_signals (entry, completion);
9851 connect_completion_signals (entry, completion);
9856 disconnect_completion_signals (GtkEntry *entry,
9857 GtkEntryCompletion *completion)
9859 g_signal_handlers_disconnect_by_func (completion,
9860 G_CALLBACK (completion_changed), entry);
9861 if (completion->priv->changed_id > 0 &&
9862 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9864 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9865 completion->priv->changed_id = 0;
9867 g_signal_handlers_disconnect_by_func (entry,
9868 G_CALLBACK (gtk_entry_completion_key_press), completion);
9869 if (completion->priv->insert_text_id > 0 &&
9870 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9872 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9873 completion->priv->insert_text_id = 0;
9875 g_signal_handlers_disconnect_by_func (entry,
9876 G_CALLBACK (completion_insert_text_callback), completion);
9877 g_signal_handlers_disconnect_by_func (entry,
9878 G_CALLBACK (clear_completion_callback), completion);
9879 g_signal_handlers_disconnect_by_func (entry,
9880 G_CALLBACK (accept_completion_callback), completion);
9884 connect_completion_signals (GtkEntry *entry,
9885 GtkEntryCompletion *completion)
9887 if (completion->priv->popup_completion)
9889 completion->priv->changed_id =
9890 g_signal_connect (entry, "changed",
9891 G_CALLBACK (gtk_entry_completion_changed), completion);
9892 g_signal_connect (entry, "key-press-event",
9893 G_CALLBACK (gtk_entry_completion_key_press), completion);
9896 if (completion->priv->inline_completion)
9898 completion->priv->insert_text_id =
9899 g_signal_connect (entry, "insert-text",
9900 G_CALLBACK (completion_insert_text_callback), completion);
9901 g_signal_connect (entry, "notify",
9902 G_CALLBACK (clear_completion_callback), completion);
9903 g_signal_connect (entry, "activate",
9904 G_CALLBACK (accept_completion_callback), completion);
9905 g_signal_connect (entry, "focus-out-event",
9906 G_CALLBACK (accept_completion_callback), completion);
9909 g_signal_connect (completion, "notify",
9910 G_CALLBACK (completion_changed), entry);
9914 * gtk_entry_set_completion:
9915 * @entry: A #GtkEntry
9916 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9918 * Sets @completion to be the auxiliary completion object to use with @entry.
9919 * All further configuration of the completion mechanism is done on
9920 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9921 * @completion is set to %NULL.
9926 gtk_entry_set_completion (GtkEntry *entry,
9927 GtkEntryCompletion *completion)
9929 GtkEntryCompletion *old;
9931 g_return_if_fail (GTK_IS_ENTRY (entry));
9932 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9934 old = gtk_entry_get_completion (entry);
9936 if (old == completion)
9941 if (old->priv->completion_timeout)
9943 g_source_remove (old->priv->completion_timeout);
9944 old->priv->completion_timeout = 0;
9947 if (old->priv->check_completion_idle)
9949 g_source_destroy (old->priv->check_completion_idle);
9950 old->priv->check_completion_idle = NULL;
9953 if (gtk_widget_get_mapped (old->priv->popup_window))
9954 _gtk_entry_completion_popdown (old);
9956 disconnect_completion_signals (entry, old);
9957 old->priv->entry = NULL;
9959 g_object_unref (old);
9964 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9968 /* hook into the entry */
9969 g_object_ref (completion);
9971 connect_completion_signals (entry, completion);
9972 completion->priv->entry = GTK_WIDGET (entry);
9973 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9975 g_object_notify (G_OBJECT (entry), "completion");
9979 * gtk_entry_get_completion:
9980 * @entry: A #GtkEntry
9982 * Returns the auxiliary completion object currently in use by @entry.
9984 * Return value: (transfer none): The auxiliary completion object currently
9989 GtkEntryCompletion *
9990 gtk_entry_get_completion (GtkEntry *entry)
9992 GtkEntryCompletion *completion;
9994 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9996 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9997 GTK_ENTRY_COMPLETION_KEY));
10003 * gtk_entry_set_cursor_hadjustment:
10004 * @entry: a #GtkEntry
10005 * @adjustment: an adjustment which should be adjusted when the cursor
10006 * is moved, or %NULL
10008 * Hooks up an adjustment to the cursor position in an entry, so that when
10009 * the cursor is moved, the adjustment is scrolled to show that position.
10010 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10013 * The adjustment has to be in pixel units and in the same coordinate system
10019 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10020 GtkAdjustment *adjustment)
10022 g_return_if_fail (GTK_IS_ENTRY (entry));
10024 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10027 g_object_ref (adjustment);
10029 g_object_set_qdata_full (G_OBJECT (entry),
10030 quark_cursor_hadjustment,
10036 * gtk_entry_get_cursor_hadjustment:
10037 * @entry: a #GtkEntry
10039 * Retrieves the horizontal cursor adjustment for the entry.
10040 * See gtk_entry_set_cursor_hadjustment().
10042 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10043 * if none has been set.
10048 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10050 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10052 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10056 * gtk_entry_set_progress_fraction:
10057 * @entry: a #GtkEntry
10058 * @fraction: fraction of the task that's been completed
10060 * Causes the entry's progress indicator to "fill in" the given
10061 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10067 gtk_entry_set_progress_fraction (GtkEntry *entry,
10071 GtkEntryPrivate *private;
10072 gdouble old_fraction;
10073 gint x, y, width, height;
10074 gint old_x, old_y, old_width, old_height;
10076 g_return_if_fail (GTK_IS_ENTRY (entry));
10078 widget = GTK_WIDGET (entry);
10079 private = entry->priv;
10081 if (private->progress_pulse_mode)
10084 old_fraction = private->progress_fraction;
10086 if (gtk_widget_is_drawable (widget))
10087 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10089 fraction = CLAMP (fraction, 0.0, 1.0);
10091 private->progress_fraction = fraction;
10092 private->progress_pulse_mode = FALSE;
10093 private->progress_pulse_current = 0.0;
10095 if (gtk_widget_is_drawable (widget))
10097 get_progress_area (widget, &x, &y, &width, &height);
10099 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10100 gtk_widget_queue_draw (widget);
10103 if (fraction != old_fraction)
10104 g_object_notify (G_OBJECT (entry), "progress-fraction");
10108 * gtk_entry_get_progress_fraction:
10109 * @entry: a #GtkEntry
10111 * Returns the current fraction of the task that's been completed.
10112 * See gtk_entry_set_progress_fraction().
10114 * Return value: a fraction from 0.0 to 1.0
10119 gtk_entry_get_progress_fraction (GtkEntry *entry)
10121 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10123 return entry->priv->progress_fraction;
10127 * gtk_entry_set_progress_pulse_step:
10128 * @entry: a #GtkEntry
10129 * @fraction: fraction between 0.0 and 1.0
10131 * Sets the fraction of total entry width to move the progress
10132 * bouncing block for each call to gtk_entry_progress_pulse().
10137 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10140 GtkEntryPrivate *private;
10142 g_return_if_fail (GTK_IS_ENTRY (entry));
10144 private = entry->priv;
10146 fraction = CLAMP (fraction, 0.0, 1.0);
10148 if (fraction != private->progress_pulse_fraction)
10150 private->progress_pulse_fraction = fraction;
10152 gtk_widget_queue_draw (GTK_WIDGET (entry));
10154 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10159 * gtk_entry_get_progress_pulse_step:
10160 * @entry: a #GtkEntry
10162 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10164 * Return value: a fraction from 0.0 to 1.0
10169 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10171 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10173 return entry->priv->progress_pulse_fraction;
10177 * gtk_entry_progress_pulse:
10178 * @entry: a #GtkEntry
10180 * Indicates that some progress is made, but you don't know how much.
10181 * Causes the entry's progress indicator to enter "activity mode,"
10182 * where a block bounces back and forth. Each call to
10183 * gtk_entry_progress_pulse() causes the block to move by a little bit
10184 * (the amount of movement per pulse is determined by
10185 * gtk_entry_set_progress_pulse_step()).
10190 gtk_entry_progress_pulse (GtkEntry *entry)
10192 GtkEntryPrivate *private;
10194 g_return_if_fail (GTK_IS_ENTRY (entry));
10196 private = entry->priv;
10198 if (private->progress_pulse_mode)
10200 if (private->progress_pulse_way_back)
10202 private->progress_pulse_current -= private->progress_pulse_fraction;
10204 if (private->progress_pulse_current < 0.0)
10206 private->progress_pulse_current = 0.0;
10207 private->progress_pulse_way_back = FALSE;
10212 private->progress_pulse_current += private->progress_pulse_fraction;
10214 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10216 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10217 private->progress_pulse_way_back = TRUE;
10223 private->progress_fraction = 0.0;
10224 private->progress_pulse_mode = TRUE;
10225 private->progress_pulse_way_back = FALSE;
10226 private->progress_pulse_current = 0.0;
10229 gtk_widget_queue_draw (GTK_WIDGET (entry));
10233 * gtk_entry_set_placeholder_text:
10234 * @entry: a #GtkEntry
10235 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10237 * Sets text to be displayed in @entry when it is empty and unfocused.
10238 * This can be used to give a visual hint of the expected contents of
10241 * Note that since the placeholder text gets removed when the entry
10242 * received focus, using this feature is a bit problematic if the entry
10243 * is given the initial focus in a window. Sometimes this can be
10244 * worked around by delaying the initial focus setting until the
10245 * first key event arrives.
10250 gtk_entry_set_placeholder_text (GtkEntry *entry,
10253 GtkEntryPrivate *priv;
10255 g_return_if_fail (GTK_IS_ENTRY (entry));
10257 priv = entry->priv;
10259 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10262 g_free (priv->placeholder_text);
10263 priv->placeholder_text = g_strdup (text);
10265 gtk_entry_recompute (entry);
10267 g_object_notify (G_OBJECT (entry), "placeholder-text");
10271 * gtk_entry_get_placeholder_text:
10272 * @entry: a #GtkEntry
10274 * Retrieves the text that will be displayed when @entry is empty and unfocused
10276 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10277 * storage in the widget and must not be freed, modified or stored.
10282 gtk_entry_get_placeholder_text (GtkEntry *entry)
10284 GtkEntryPrivate *priv;
10286 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10288 priv = entry->priv;
10290 return priv->placeholder_text;
10293 /* Caps Lock warning for password entries */
10296 show_capslock_feedback (GtkEntry *entry,
10299 GtkEntryPrivate *priv = entry->priv;
10301 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10303 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10304 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10305 priv->caps_lock_warning_shown = TRUE;
10308 if (priv->caps_lock_warning_shown)
10309 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10311 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10315 remove_capslock_feedback (GtkEntry *entry)
10317 GtkEntryPrivate *priv = entry->priv;
10319 if (priv->caps_lock_warning_shown)
10321 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10322 priv->caps_lock_warning_shown = FALSE;
10327 keymap_state_changed (GdkKeymap *keymap,
10330 GtkEntryPrivate *priv = entry->priv;
10333 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10335 if (gdk_keymap_get_caps_lock_state (keymap))
10336 text = _("Caps Lock is on");
10340 show_capslock_feedback (entry, text);
10342 remove_capslock_feedback (entry);
10346 * _gtk_entry_set_is_cell_renderer:
10347 * @entry: a #GtkEntry
10348 * @is_cell_renderer: new value
10350 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10351 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10353 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10357 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10358 gboolean is_cell_renderer)
10360 entry->priv->is_cell_renderer = is_cell_renderer;
10364 * gtk_entry_set_input_purpose:
10365 * @entry: a #GtkEntry
10366 * @purpose: the purpose
10368 * Sets the #GtkEntry:input-purpose property which
10369 * can be used by on-screen keyboards and other input
10370 * methods to adjust their behaviour.
10375 gtk_entry_set_input_purpose (GtkEntry *entry,
10376 GtkInputPurpose purpose)
10379 g_return_if_fail (GTK_IS_ENTRY (entry));
10381 if (gtk_entry_get_input_purpose (entry) != purpose)
10383 g_object_set (G_OBJECT (entry->priv->im_context),
10384 "input-purpose", purpose,
10387 g_object_notify (G_OBJECT (entry), "input-purpose");
10392 * gtk_entry_get_input_purpose:
10393 * @entry: a #GtkEntry
10395 * Gets the value of the #GtkEntry:input-purpose property.
10400 gtk_entry_get_input_purpose (GtkEntry *entry)
10402 GtkInputPurpose purpose;
10404 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
10406 g_object_get (G_OBJECT (entry->priv->im_context),
10407 "input-purpose", &purpose,
10414 * gtk_entry_set_input_hints:
10415 * @entry: a #GtkEntry
10416 * @hints: the hints
10418 * Sets the #GtkEntry:input-hints property, which
10419 * allows input methods to fine-tune their behaviour.
10424 gtk_entry_set_input_hints (GtkEntry *entry,
10425 GtkInputHints hints)
10428 g_return_if_fail (GTK_IS_ENTRY (entry));
10430 if (gtk_entry_get_input_hints (entry) != hints)
10432 g_object_set (G_OBJECT (entry->priv->im_context),
10433 "input-hints", hints,
10436 g_object_notify (G_OBJECT (entry), "input-hints");
10441 * gtk_entry_get_input_hints:
10442 * @entry: a #GtkEntry
10444 * Gets the value of the #GtkEntry:input-hints property.
10449 gtk_entry_get_input_hints (GtkEntry *entry)
10451 GtkInputHints hints;
10453 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
10455 g_object_get (G_OBJECT (entry->priv->im_context),
10456 "input-hints", &hints,