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 PASSWORD_HINT_MAX 8
123 #define IS_VALID_ICON_POSITION(pos) \
124 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
125 (pos) == GTK_ENTRY_ICON_SECONDARY)
127 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
128 static GQuark quark_inner_border = 0;
129 static GQuark quark_password_hint = 0;
130 static GQuark quark_cursor_hadjustment = 0;
131 static GQuark quark_capslock_feedback = 0;
133 typedef struct _EntryIconInfo EntryIconInfo;
134 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
135 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
137 struct _GtkEntryPrivate
139 EntryIconInfo *icons[MAX_ICONS];
141 GtkEntryBuffer *buffer;
142 GtkIMContext *im_context;
143 GtkWidget *popup_menu;
147 GdkWindow *text_area;
149 PangoLayout *cached_layout;
153 gdouble progress_fraction;
154 gdouble progress_pulse_fraction;
155 gdouble progress_pulse_current;
157 gchar *placeholder_text;
161 gint ascent; /* font ascent in pango units */
163 gint descent; /* font descent in pango units */
164 gint dnd_position; /* In chars, -1 == no DND cursor */
169 gint selection_bound;
175 gunichar invisible_char;
178 guint blink_time; /* time in msec the cursor has blinked since last user event */
180 guint recompute_idle;
182 guint16 x_text_size; /* allocated size, in bytes */
183 guint16 x_n_bytes; /* length in use, in bytes */
185 guint16 preedit_length; /* length of preedit string, in bytes */
186 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
188 guint shadow_type : 4;
191 guint overwrite_mode : 1;
194 guint activates_default : 1;
195 guint cache_includes_preedit : 1;
196 guint caps_lock_warning : 1;
197 guint caps_lock_warning_shown : 1;
198 guint change_count : 8;
199 guint cursor_visible : 1;
200 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
202 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
203 guint is_cell_renderer : 1;
204 guint invisible_char_set : 1;
205 guint interior_focus : 1;
206 guint mouse_cursor_obscured : 1;
207 guint need_im_reset : 1;
208 guint progress_pulse_mode : 1;
209 guint progress_pulse_way_back : 1;
210 guint real_changed : 1;
211 guint resolved_dir : 4; /* PangoDirection */
212 guint select_words : 1;
213 guint select_lines : 1;
214 guint truncate_multiline : 1;
217 struct _EntryIconInfo
221 guint insensitive : 1;
222 guint nonactivatable : 1;
227 GtkIconHelper *icon_helper;
229 GtkTargetList *target_list;
230 GdkDragAction actions;
233 struct _GtkEntryPasswordHint
235 gint position; /* Position (in text) of the last password hint */
236 guint source_id; /* Timeout source id */
239 struct _GtkEntryCapslockFeedback
266 PROP_CURSOR_POSITION,
267 PROP_SELECTION_BOUND,
274 PROP_ACTIVATES_DEFAULT,
279 PROP_TRUNCATE_MULTILINE,
283 PROP_INVISIBLE_CHAR_SET,
284 PROP_CAPS_LOCK_WARNING,
285 PROP_PROGRESS_FRACTION,
286 PROP_PROGRESS_PULSE_STEP,
288 PROP_PIXBUF_SECONDARY,
290 PROP_STOCK_SECONDARY,
291 PROP_ICON_NAME_PRIMARY,
292 PROP_ICON_NAME_SECONDARY,
294 PROP_GICON_SECONDARY,
295 PROP_STORAGE_TYPE_PRIMARY,
296 PROP_STORAGE_TYPE_SECONDARY,
297 PROP_ACTIVATABLE_PRIMARY,
298 PROP_ACTIVATABLE_SECONDARY,
299 PROP_SENSITIVE_PRIMARY,
300 PROP_SENSITIVE_SECONDARY,
301 PROP_TOOLTIP_TEXT_PRIMARY,
302 PROP_TOOLTIP_TEXT_SECONDARY,
303 PROP_TOOLTIP_MARKUP_PRIMARY,
304 PROP_TOOLTIP_MARKUP_SECONDARY,
306 PROP_EDITING_CANCELED,
307 PROP_PLACEHOLDER_TEXT,
313 static guint signals[LAST_SIGNAL] = { 0 };
322 DISPLAY_NORMAL, /* The entry text is being shown */
323 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
324 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
329 static void gtk_entry_editable_init (GtkEditableInterface *iface);
330 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
331 static void gtk_entry_set_property (GObject *object,
335 static void gtk_entry_get_property (GObject *object,
339 static void gtk_entry_finalize (GObject *object);
340 static void gtk_entry_dispose (GObject *object);
344 static void gtk_entry_destroy (GtkWidget *widget);
345 static void gtk_entry_realize (GtkWidget *widget);
346 static void gtk_entry_unrealize (GtkWidget *widget);
347 static void gtk_entry_map (GtkWidget *widget);
348 static void gtk_entry_unmap (GtkWidget *widget);
349 static void gtk_entry_get_preferred_width (GtkWidget *widget,
352 static void gtk_entry_get_preferred_height (GtkWidget *widget,
355 static void gtk_entry_size_allocate (GtkWidget *widget,
356 GtkAllocation *allocation);
357 static void gtk_entry_draw_frame (GtkWidget *widget,
358 GtkStyleContext *context,
360 static void gtk_entry_draw_progress (GtkWidget *widget,
361 GtkStyleContext *context,
363 static gint gtk_entry_draw (GtkWidget *widget,
365 static gint gtk_entry_button_press (GtkWidget *widget,
366 GdkEventButton *event);
367 static gint gtk_entry_button_release (GtkWidget *widget,
368 GdkEventButton *event);
369 static gint gtk_entry_enter_notify (GtkWidget *widget,
370 GdkEventCrossing *event);
371 static gint gtk_entry_leave_notify (GtkWidget *widget,
372 GdkEventCrossing *event);
373 static gint gtk_entry_motion_notify (GtkWidget *widget,
374 GdkEventMotion *event);
375 static gint gtk_entry_key_press (GtkWidget *widget,
377 static gint gtk_entry_key_release (GtkWidget *widget,
379 static gint gtk_entry_focus_in (GtkWidget *widget,
380 GdkEventFocus *event);
381 static gint gtk_entry_focus_out (GtkWidget *widget,
382 GdkEventFocus *event);
383 static void gtk_entry_grab_focus (GtkWidget *widget);
384 static void gtk_entry_style_updated (GtkWidget *widget);
385 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
388 gboolean keyboard_tip,
389 GtkTooltip *tooltip);
390 static void gtk_entry_direction_changed (GtkWidget *widget,
391 GtkTextDirection previous_dir);
392 static void gtk_entry_state_flags_changed (GtkWidget *widget,
393 GtkStateFlags previous_state);
394 static void gtk_entry_screen_changed (GtkWidget *widget,
395 GdkScreen *old_screen);
397 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
398 GdkDragContext *context,
402 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
403 GdkDragContext *context,
407 static void gtk_entry_drag_leave (GtkWidget *widget,
408 GdkDragContext *context,
410 static void gtk_entry_drag_data_received (GtkWidget *widget,
411 GdkDragContext *context,
414 GtkSelectionData *selection_data,
417 static void gtk_entry_drag_data_get (GtkWidget *widget,
418 GdkDragContext *context,
419 GtkSelectionData *selection_data,
422 static void gtk_entry_drag_data_delete (GtkWidget *widget,
423 GdkDragContext *context);
424 static void gtk_entry_drag_begin (GtkWidget *widget,
425 GdkDragContext *context);
426 static void gtk_entry_drag_end (GtkWidget *widget,
427 GdkDragContext *context);
430 /* GtkEditable method implementations
432 static void gtk_entry_insert_text (GtkEditable *editable,
433 const gchar *new_text,
434 gint new_text_length,
436 static void gtk_entry_delete_text (GtkEditable *editable,
439 static gchar * gtk_entry_get_chars (GtkEditable *editable,
442 static void gtk_entry_real_set_position (GtkEditable *editable,
444 static gint gtk_entry_get_position (GtkEditable *editable);
445 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
448 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
452 /* GtkCellEditable method implementations
454 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
457 /* Default signal handlers
459 static void gtk_entry_real_insert_text (GtkEditable *editable,
460 const gchar *new_text,
461 gint new_text_length,
463 static void gtk_entry_real_delete_text (GtkEditable *editable,
466 static void gtk_entry_move_cursor (GtkEntry *entry,
467 GtkMovementStep step,
469 gboolean extend_selection);
470 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
472 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
475 static void gtk_entry_backspace (GtkEntry *entry);
476 static void gtk_entry_cut_clipboard (GtkEntry *entry);
477 static void gtk_entry_copy_clipboard (GtkEntry *entry);
478 static void gtk_entry_paste_clipboard (GtkEntry *entry);
479 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
480 static void gtk_entry_select_all (GtkEntry *entry);
481 static void gtk_entry_real_activate (GtkEntry *entry);
482 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
484 static void keymap_direction_changed (GdkKeymap *keymap,
486 static void keymap_state_changed (GdkKeymap *keymap,
488 static void remove_capslock_feedback (GtkEntry *entry);
490 /* IM Context Callbacks
492 static void gtk_entry_commit_cb (GtkIMContext *context,
495 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
497 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
499 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
506 static void gtk_entry_enter_text (GtkEntry *entry,
508 static void gtk_entry_set_positions (GtkEntry *entry,
510 gint selection_bound);
511 static void gtk_entry_draw_text (GtkEntry *entry,
513 static void gtk_entry_draw_cursor (GtkEntry *entry,
516 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
517 gboolean include_preedit);
518 static void gtk_entry_reset_layout (GtkEntry *entry);
519 static void gtk_entry_recompute (GtkEntry *entry);
520 static gint gtk_entry_find_position (GtkEntry *entry,
522 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
526 static void gtk_entry_adjust_scroll (GtkEntry *entry);
527 static gint gtk_entry_move_visually (GtkEntry *editable,
530 static gint gtk_entry_move_logically (GtkEntry *entry,
533 static gint gtk_entry_move_forward_word (GtkEntry *entry,
535 gboolean allow_whitespace);
536 static gint gtk_entry_move_backward_word (GtkEntry *entry,
538 gboolean allow_whitespace);
539 static void gtk_entry_delete_whitespace (GtkEntry *entry);
540 static void gtk_entry_select_word (GtkEntry *entry);
541 static void gtk_entry_select_line (GtkEntry *entry);
542 static void gtk_entry_paste (GtkEntry *entry,
544 static void gtk_entry_update_primary_selection (GtkEntry *entry);
545 static void gtk_entry_do_popup (GtkEntry *entry,
546 GdkEventButton *event);
547 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
548 gboolean group_cycling);
549 static void gtk_entry_grab_notify (GtkWidget *widget,
550 gboolean was_grabbed);
551 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
552 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
553 static void gtk_entry_reset_blink_time (GtkEntry *entry);
554 static void gtk_entry_get_text_area_size (GtkEntry *entry,
559 static void get_text_area_size (GtkEntry *entry,
564 static void get_frame_size (GtkEntry *entry,
565 gboolean relative_to_window,
570 static void gtk_entry_move_adjustments (GtkEntry *entry);
571 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
572 GtkEntryIconPosition icon_pos);
573 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
574 static gboolean get_middle_click_paste (GtkEntry *entry);
577 static void begin_change (GtkEntry *entry);
578 static void end_change (GtkEntry *entry);
579 static void emit_changed (GtkEntry *entry);
581 static void buffer_inserted_text (GtkEntryBuffer *buffer,
586 static void buffer_deleted_text (GtkEntryBuffer *buffer,
590 static void buffer_notify_text (GtkEntryBuffer *buffer,
593 static void buffer_notify_length (GtkEntryBuffer *buffer,
596 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
599 static void buffer_connect_signals (GtkEntry *entry);
600 static void buffer_disconnect_signals (GtkEntry *entry);
601 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
603 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
604 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
605 gtk_entry_editable_init)
606 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
607 gtk_entry_cell_editable_init))
610 add_move_binding (GtkBindingSet *binding_set,
613 GtkMovementStep step,
616 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
618 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
622 G_TYPE_BOOLEAN, FALSE);
624 /* Selection-extending version */
625 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
629 G_TYPE_BOOLEAN, TRUE);
633 gtk_entry_class_init (GtkEntryClass *class)
635 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
636 GtkWidgetClass *widget_class;
637 GtkBindingSet *binding_set;
639 widget_class = (GtkWidgetClass*) class;
641 gobject_class->dispose = gtk_entry_dispose;
642 gobject_class->finalize = gtk_entry_finalize;
643 gobject_class->set_property = gtk_entry_set_property;
644 gobject_class->get_property = gtk_entry_get_property;
646 widget_class->destroy = gtk_entry_destroy;
647 widget_class->map = gtk_entry_map;
648 widget_class->unmap = gtk_entry_unmap;
649 widget_class->realize = gtk_entry_realize;
650 widget_class->unrealize = gtk_entry_unrealize;
651 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
652 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
653 widget_class->size_allocate = gtk_entry_size_allocate;
654 widget_class->draw = gtk_entry_draw;
655 widget_class->enter_notify_event = gtk_entry_enter_notify;
656 widget_class->leave_notify_event = gtk_entry_leave_notify;
657 widget_class->button_press_event = gtk_entry_button_press;
658 widget_class->button_release_event = gtk_entry_button_release;
659 widget_class->motion_notify_event = gtk_entry_motion_notify;
660 widget_class->key_press_event = gtk_entry_key_press;
661 widget_class->key_release_event = gtk_entry_key_release;
662 widget_class->focus_in_event = gtk_entry_focus_in;
663 widget_class->focus_out_event = gtk_entry_focus_out;
664 widget_class->grab_focus = gtk_entry_grab_focus;
665 widget_class->style_updated = gtk_entry_style_updated;
666 widget_class->query_tooltip = gtk_entry_query_tooltip;
667 widget_class->drag_begin = gtk_entry_drag_begin;
668 widget_class->drag_end = gtk_entry_drag_end;
669 widget_class->direction_changed = gtk_entry_direction_changed;
670 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
671 widget_class->screen_changed = gtk_entry_screen_changed;
672 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
673 widget_class->grab_notify = gtk_entry_grab_notify;
675 widget_class->drag_drop = gtk_entry_drag_drop;
676 widget_class->drag_motion = gtk_entry_drag_motion;
677 widget_class->drag_leave = gtk_entry_drag_leave;
678 widget_class->drag_data_received = gtk_entry_drag_data_received;
679 widget_class->drag_data_get = gtk_entry_drag_data_get;
680 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
682 widget_class->popup_menu = gtk_entry_popup_menu;
684 class->move_cursor = gtk_entry_move_cursor;
685 class->insert_at_cursor = gtk_entry_insert_at_cursor;
686 class->delete_from_cursor = gtk_entry_delete_from_cursor;
687 class->backspace = gtk_entry_backspace;
688 class->cut_clipboard = gtk_entry_cut_clipboard;
689 class->copy_clipboard = gtk_entry_copy_clipboard;
690 class->paste_clipboard = gtk_entry_paste_clipboard;
691 class->toggle_overwrite = gtk_entry_toggle_overwrite;
692 class->activate = gtk_entry_real_activate;
693 class->get_text_area_size = gtk_entry_get_text_area_size;
695 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
696 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
697 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
698 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
700 g_object_class_override_property (gobject_class,
701 PROP_EDITING_CANCELED,
704 g_object_class_install_property (gobject_class,
706 g_param_spec_object ("buffer",
708 P_("Text buffer object which actually stores entry text"),
709 GTK_TYPE_ENTRY_BUFFER,
710 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
712 g_object_class_install_property (gobject_class,
713 PROP_CURSOR_POSITION,
714 g_param_spec_int ("cursor-position",
715 P_("Cursor Position"),
716 P_("The current position of the insertion cursor in chars"),
718 GTK_ENTRY_BUFFER_MAX_SIZE,
720 GTK_PARAM_READABLE));
722 g_object_class_install_property (gobject_class,
723 PROP_SELECTION_BOUND,
724 g_param_spec_int ("selection-bound",
725 P_("Selection Bound"),
726 P_("The position of the opposite end of the selection from the cursor in chars"),
728 GTK_ENTRY_BUFFER_MAX_SIZE,
730 GTK_PARAM_READABLE));
732 g_object_class_install_property (gobject_class,
734 g_param_spec_boolean ("editable",
736 P_("Whether the entry contents can be edited"),
738 GTK_PARAM_READWRITE));
740 g_object_class_install_property (gobject_class,
742 g_param_spec_int ("max-length",
743 P_("Maximum length"),
744 P_("Maximum number of characters for this entry. Zero if no maximum"),
746 GTK_ENTRY_BUFFER_MAX_SIZE,
748 GTK_PARAM_READWRITE));
749 g_object_class_install_property (gobject_class,
751 g_param_spec_boolean ("visibility",
753 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
755 GTK_PARAM_READWRITE));
757 g_object_class_install_property (gobject_class,
759 g_param_spec_boolean ("has-frame",
761 P_("FALSE removes outside bevel from entry"),
763 GTK_PARAM_READWRITE));
766 * GtkEntry:inner-border:
768 * Sets the text area's border between the text and the frame.
770 * Deprecated: 3.4: Use the standard border and padding CSS properties
771 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
772 * of this style property is ignored.
774 g_object_class_install_property (gobject_class,
776 g_param_spec_boxed ("inner-border",
778 P_("Border between text and frame. Overrides the inner-border style property"),
780 GTK_PARAM_READWRITE |
781 G_PARAM_DEPRECATED));
783 g_object_class_install_property (gobject_class,
785 g_param_spec_unichar ("invisible-char",
786 P_("Invisible character"),
787 P_("The character to use when masking entry contents (in \"password mode\")"),
789 GTK_PARAM_READWRITE));
791 g_object_class_install_property (gobject_class,
792 PROP_ACTIVATES_DEFAULT,
793 g_param_spec_boolean ("activates-default",
794 P_("Activates default"),
795 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
797 GTK_PARAM_READWRITE));
798 g_object_class_install_property (gobject_class,
800 g_param_spec_int ("width-chars",
801 P_("Width in chars"),
802 P_("Number of characters to leave space for in the entry"),
806 GTK_PARAM_READWRITE));
808 g_object_class_install_property (gobject_class,
810 g_param_spec_int ("scroll-offset",
812 P_("Number of pixels of the entry scrolled off the screen to the left"),
816 GTK_PARAM_READABLE));
818 g_object_class_install_property (gobject_class,
820 g_param_spec_string ("text",
822 P_("The contents of the entry"),
824 GTK_PARAM_READWRITE));
829 * The horizontal alignment, from 0 (left) to 1 (right).
830 * Reversed for RTL layouts.
834 g_object_class_install_property (gobject_class,
836 g_param_spec_float ("xalign",
838 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
842 GTK_PARAM_READWRITE));
845 * GtkEntry:truncate-multiline:
847 * When %TRUE, pasted multi-line text is truncated to the first line.
851 g_object_class_install_property (gobject_class,
852 PROP_TRUNCATE_MULTILINE,
853 g_param_spec_boolean ("truncate-multiline",
854 P_("Truncate multiline"),
855 P_("Whether to truncate multiline pastes to one line."),
857 GTK_PARAM_READWRITE));
860 * GtkEntry:shadow-type:
862 * Which kind of shadow to draw around the entry when
863 * #GtkEntry:has-frame is set to %TRUE.
867 g_object_class_install_property (gobject_class,
869 g_param_spec_enum ("shadow-type",
871 P_("Which kind of shadow to draw around the entry when has-frame is set"),
872 GTK_TYPE_SHADOW_TYPE,
874 GTK_PARAM_READWRITE));
877 * GtkEntry:overwrite-mode:
879 * If text is overwritten when typing in the #GtkEntry.
883 g_object_class_install_property (gobject_class,
885 g_param_spec_boolean ("overwrite-mode",
886 P_("Overwrite mode"),
887 P_("Whether new text overwrites existing text"),
889 GTK_PARAM_READWRITE));
892 * GtkEntry:text-length:
894 * The length of the text in the #GtkEntry.
898 g_object_class_install_property (gobject_class,
900 g_param_spec_uint ("text-length",
902 P_("Length of the text currently in the entry"),
906 GTK_PARAM_READABLE));
908 * GtkEntry:invisible-char-set:
910 * Whether the invisible char has been set for the #GtkEntry.
914 g_object_class_install_property (gobject_class,
915 PROP_INVISIBLE_CHAR_SET,
916 g_param_spec_boolean ("invisible-char-set",
917 P_("Invisible character set"),
918 P_("Whether the invisible character has been set"),
920 GTK_PARAM_READWRITE));
923 * GtkEntry:caps-lock-warning:
925 * Whether password entries will show a warning when Caps Lock is on.
927 * Note that the warning is shown using a secondary icon, and thus
928 * does not work if you are using the secondary icon position for some
933 g_object_class_install_property (gobject_class,
934 PROP_CAPS_LOCK_WARNING,
935 g_param_spec_boolean ("caps-lock-warning",
936 P_("Caps Lock warning"),
937 P_("Whether password entries will show a warning when Caps Lock is on"),
939 GTK_PARAM_READWRITE));
942 * GtkEntry:progress-fraction:
944 * The current fraction of the task that's been completed.
948 g_object_class_install_property (gobject_class,
949 PROP_PROGRESS_FRACTION,
950 g_param_spec_double ("progress-fraction",
951 P_("Progress Fraction"),
952 P_("The current fraction of the task that's been completed"),
956 GTK_PARAM_READWRITE));
959 * GtkEntry:progress-pulse-step:
961 * The fraction of total entry width to move the progress
962 * bouncing block for each call to gtk_entry_progress_pulse().
966 g_object_class_install_property (gobject_class,
967 PROP_PROGRESS_PULSE_STEP,
968 g_param_spec_double ("progress-pulse-step",
969 P_("Progress Pulse Step"),
970 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
974 GTK_PARAM_READWRITE));
977 * GtkEntry:placeholder-text:
979 * The text that will be displayed in the #GtkEntry when it is empty
984 g_object_class_install_property (gobject_class,
985 PROP_PLACEHOLDER_TEXT,
986 g_param_spec_string ("placeholder-text",
987 P_("Placeholder text"),
988 P_("Show text in the entry when it's empty and unfocused"),
990 GTK_PARAM_READWRITE));
993 * GtkEntry:primary-icon-pixbuf:
995 * A pixbuf to use as the primary icon for the entry.
999 g_object_class_install_property (gobject_class,
1000 PROP_PIXBUF_PRIMARY,
1001 g_param_spec_object ("primary-icon-pixbuf",
1002 P_("Primary pixbuf"),
1003 P_("Primary pixbuf for the entry"),
1005 GTK_PARAM_READWRITE));
1008 * GtkEntry:secondary-icon-pixbuf:
1010 * An pixbuf to use as the secondary icon for the entry.
1014 g_object_class_install_property (gobject_class,
1015 PROP_PIXBUF_SECONDARY,
1016 g_param_spec_object ("secondary-icon-pixbuf",
1017 P_("Secondary pixbuf"),
1018 P_("Secondary pixbuf for the entry"),
1020 GTK_PARAM_READWRITE));
1023 * GtkEntry:primary-icon-stock:
1025 * The stock id to use for the primary icon for the entry.
1029 g_object_class_install_property (gobject_class,
1031 g_param_spec_string ("primary-icon-stock",
1032 P_("Primary stock ID"),
1033 P_("Stock ID for primary icon"),
1035 GTK_PARAM_READWRITE));
1038 * GtkEntry:secondary-icon-stock:
1040 * The stock id to use for the secondary icon for the entry.
1044 g_object_class_install_property (gobject_class,
1045 PROP_STOCK_SECONDARY,
1046 g_param_spec_string ("secondary-icon-stock",
1047 P_("Secondary stock ID"),
1048 P_("Stock ID for secondary icon"),
1050 GTK_PARAM_READWRITE));
1053 * GtkEntry:primary-icon-name:
1055 * The icon name to use for the primary icon for the entry.
1059 g_object_class_install_property (gobject_class,
1060 PROP_ICON_NAME_PRIMARY,
1061 g_param_spec_string ("primary-icon-name",
1062 P_("Primary icon name"),
1063 P_("Icon name for primary icon"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:secondary-icon-name:
1070 * The icon name to use for the secondary icon for the entry.
1074 g_object_class_install_property (gobject_class,
1075 PROP_ICON_NAME_SECONDARY,
1076 g_param_spec_string ("secondary-icon-name",
1077 P_("Secondary icon name"),
1078 P_("Icon name for secondary icon"),
1080 GTK_PARAM_READWRITE));
1083 * GtkEntry:primary-icon-gicon:
1085 * The #GIcon to use for the primary icon for the entry.
1089 g_object_class_install_property (gobject_class,
1091 g_param_spec_object ("primary-icon-gicon",
1092 P_("Primary GIcon"),
1093 P_("GIcon for primary icon"),
1095 GTK_PARAM_READWRITE));
1098 * GtkEntry:secondary-icon-gicon:
1100 * The #GIcon to use for the secondary icon for the entry.
1104 g_object_class_install_property (gobject_class,
1105 PROP_GICON_SECONDARY,
1106 g_param_spec_object ("secondary-icon-gicon",
1107 P_("Secondary GIcon"),
1108 P_("GIcon for secondary icon"),
1110 GTK_PARAM_READWRITE));
1113 * GtkEntry:primary-icon-storage-type:
1115 * The representation which is used for the primary icon of the entry.
1119 g_object_class_install_property (gobject_class,
1120 PROP_STORAGE_TYPE_PRIMARY,
1121 g_param_spec_enum ("primary-icon-storage-type",
1122 P_("Primary storage type"),
1123 P_("The representation being used for primary icon"),
1124 GTK_TYPE_IMAGE_TYPE,
1126 GTK_PARAM_READABLE));
1129 * GtkEntry:secondary-icon-storage-type:
1131 * The representation which is used for the secondary icon of the entry.
1135 g_object_class_install_property (gobject_class,
1136 PROP_STORAGE_TYPE_SECONDARY,
1137 g_param_spec_enum ("secondary-icon-storage-type",
1138 P_("Secondary storage type"),
1139 P_("The representation being used for secondary icon"),
1140 GTK_TYPE_IMAGE_TYPE,
1142 GTK_PARAM_READABLE));
1145 * GtkEntry:primary-icon-activatable:
1147 * Whether the primary icon is activatable.
1149 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1150 * signals only on sensitive, activatable icons.
1152 * Sensitive, but non-activatable icons can be used for purely
1153 * informational purposes.
1157 g_object_class_install_property (gobject_class,
1158 PROP_ACTIVATABLE_PRIMARY,
1159 g_param_spec_boolean ("primary-icon-activatable",
1160 P_("Primary icon activatable"),
1161 P_("Whether the primary icon is activatable"),
1163 GTK_PARAM_READWRITE));
1166 * GtkEntry:secondary-icon-activatable:
1168 * Whether the secondary icon is activatable.
1170 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1171 * signals only on sensitive, activatable icons.
1173 * Sensitive, but non-activatable icons can be used for purely
1174 * informational purposes.
1178 g_object_class_install_property (gobject_class,
1179 PROP_ACTIVATABLE_SECONDARY,
1180 g_param_spec_boolean ("secondary-icon-activatable",
1181 P_("Secondary icon activatable"),
1182 P_("Whether the secondary icon is activatable"),
1184 GTK_PARAM_READWRITE));
1188 * GtkEntry:primary-icon-sensitive:
1190 * Whether the primary icon is sensitive.
1192 * An insensitive icon appears grayed out. GTK+ does not emit the
1193 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1194 * does not allow DND from insensitive icons.
1196 * An icon should be set insensitive if the action that would trigger
1197 * when clicked is currently not available.
1201 g_object_class_install_property (gobject_class,
1202 PROP_SENSITIVE_PRIMARY,
1203 g_param_spec_boolean ("primary-icon-sensitive",
1204 P_("Primary icon sensitive"),
1205 P_("Whether the primary icon is sensitive"),
1207 GTK_PARAM_READWRITE));
1210 * GtkEntry:secondary-icon-sensitive:
1212 * Whether the secondary icon is sensitive.
1214 * An insensitive icon appears grayed out. GTK+ does not emit the
1215 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1216 * does not allow DND from insensitive icons.
1218 * An icon should be set insensitive if the action that would trigger
1219 * when clicked is currently not available.
1223 g_object_class_install_property (gobject_class,
1224 PROP_SENSITIVE_SECONDARY,
1225 g_param_spec_boolean ("secondary-icon-sensitive",
1226 P_("Secondary icon sensitive"),
1227 P_("Whether the secondary icon is sensitive"),
1229 GTK_PARAM_READWRITE));
1232 * GtkEntry:primary-icon-tooltip-text:
1234 * The contents of the tooltip on the primary icon.
1236 * Also see gtk_entry_set_icon_tooltip_text().
1240 g_object_class_install_property (gobject_class,
1241 PROP_TOOLTIP_TEXT_PRIMARY,
1242 g_param_spec_string ("primary-icon-tooltip-text",
1243 P_("Primary icon tooltip text"),
1244 P_("The contents of the tooltip on the primary icon"),
1246 GTK_PARAM_READWRITE));
1249 * GtkEntry:secondary-icon-tooltip-text:
1251 * The contents of the tooltip on the secondary icon.
1253 * Also see gtk_entry_set_icon_tooltip_text().
1257 g_object_class_install_property (gobject_class,
1258 PROP_TOOLTIP_TEXT_SECONDARY,
1259 g_param_spec_string ("secondary-icon-tooltip-text",
1260 P_("Secondary icon tooltip text"),
1261 P_("The contents of the tooltip on the secondary icon"),
1263 GTK_PARAM_READWRITE));
1266 * GtkEntry:primary-icon-tooltip-markup:
1268 * The contents of the tooltip on the primary icon, which is marked up
1269 * with the <link linkend="PangoMarkupFormat">Pango text markup
1272 * Also see gtk_entry_set_icon_tooltip_markup().
1276 g_object_class_install_property (gobject_class,
1277 PROP_TOOLTIP_MARKUP_PRIMARY,
1278 g_param_spec_string ("primary-icon-tooltip-markup",
1279 P_("Primary icon tooltip markup"),
1280 P_("The contents of the tooltip on the primary icon"),
1282 GTK_PARAM_READWRITE));
1285 * GtkEntry:secondary-icon-tooltip-markup:
1287 * The contents of the tooltip on the secondary icon, which is marked up
1288 * with the <link linkend="PangoMarkupFormat">Pango text markup
1291 * Also see gtk_entry_set_icon_tooltip_markup().
1295 g_object_class_install_property (gobject_class,
1296 PROP_TOOLTIP_MARKUP_SECONDARY,
1297 g_param_spec_string ("secondary-icon-tooltip-markup",
1298 P_("Secondary icon tooltip markup"),
1299 P_("The contents of the tooltip on the secondary icon"),
1301 GTK_PARAM_READWRITE));
1304 * GtkEntry:im-module:
1306 * Which IM (input method) module should be used for this entry.
1307 * See #GtkIMContext.
1309 * Setting this to a non-%NULL value overrides the
1310 * system-wide IM module setting. See the GtkSettings
1311 * #GtkSettings:gtk-im-module property.
1315 g_object_class_install_property (gobject_class,
1317 g_param_spec_string ("im-module",
1319 P_("Which IM module should be used"),
1321 GTK_PARAM_READWRITE));
1324 * GtkEntry:completion:
1326 * The auxiliary completion object to use with the entry.
1330 g_object_class_install_property (gobject_class,
1332 g_param_spec_object ("completion",
1334 P_("The auxiliary completion object"),
1335 GTK_TYPE_ENTRY_COMPLETION,
1336 GTK_PARAM_READWRITE));
1339 * GtkEntry:input-purpose:
1341 * The purpose of this text field.
1343 * This property can be used by on-screen keyboards and other input
1344 * methods to adjust their behaviour.
1346 * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
1347 * %GTK_INPUT_PURPOSE_PIN is independent from setting
1348 * #GtkEntry:visibility.
1352 g_object_class_install_property (gobject_class,
1354 g_param_spec_enum ("input-purpose",
1356 P_("Purpose of the text field"),
1357 GTK_TYPE_INPUT_PURPOSE,
1358 GTK_INPUT_PURPOSE_FREE_FORM,
1359 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1362 * GtkEntry:input-hints:
1364 * Additional hints (beyond #GtkEntry:input-purpose) that
1365 * allow input methods to fine-tune their behaviour.
1369 g_object_class_install_property (gobject_class,
1371 g_param_spec_flags ("input-hints",
1373 P_("Hints for the text field behaviour"),
1374 GTK_TYPE_INPUT_HINTS,
1375 GTK_INPUT_HINT_NONE,
1376 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1380 * GtkEntry:icon-prelight:
1382 * The prelight style property determines whether activatable
1383 * icons prelight on mouseover.
1387 gtk_widget_class_install_style_property (widget_class,
1388 g_param_spec_boolean ("icon-prelight",
1389 P_("Icon Prelight"),
1390 P_("Whether activatable icons should prelight when hovered"),
1392 GTK_PARAM_READABLE));
1395 * GtkEntry:progress-border:
1397 * The border around the progress bar in the entry.
1401 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1402 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1403 * property is ignored.
1405 gtk_widget_class_install_style_property (widget_class,
1406 g_param_spec_boxed ("progress-border",
1407 P_("Progress Border"),
1408 P_("Border around the progress bar"),
1410 GTK_PARAM_READABLE |
1411 G_PARAM_DEPRECATED));
1414 * GtkEntry:invisible-char:
1416 * The invisible character is used when masking entry contents (in
1417 * \"password mode\")"). When it is not explicitly set with the
1418 * #GtkEntry:invisible-char property, GTK+ determines the character
1419 * to use from a list of possible candidates, depending on availability
1420 * in the current font.
1422 * This style property allows the theme to prepend a character
1423 * to the list of candidates.
1427 gtk_widget_class_install_style_property (widget_class,
1428 g_param_spec_unichar ("invisible-char",
1429 P_("Invisible character"),
1430 P_("The character to use when masking entry contents (in \"password mode\")"),
1432 GTK_PARAM_READABLE));
1435 * GtkEntry::populate-popup:
1436 * @entry: The entry on which the signal is emitted
1437 * @menu: the menu that is being populated
1439 * The ::populate-popup signal gets emitted before showing the
1440 * context menu of the entry.
1442 * If you need to add items to the context menu, connect
1443 * to this signal and append your menuitems to the @menu.
1445 signals[POPULATE_POPUP] =
1446 g_signal_new (I_("populate-popup"),
1447 G_OBJECT_CLASS_TYPE (gobject_class),
1449 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1451 _gtk_marshal_VOID__OBJECT,
1455 /* Action signals */
1458 * GtkEntry::activate:
1459 * @entry: The entry on which the signal is emitted
1461 * The ::activate signal is emitted when the user hits
1464 * While this signal is used as a
1465 * <link linkend="keybinding-signals">keybinding signal</link>,
1466 * it is also commonly used by applications to intercept
1467 * activation of entries.
1469 * The default bindings for this signal are all forms of the Enter key.
1472 g_signal_new (I_("activate"),
1473 G_OBJECT_CLASS_TYPE (gobject_class),
1474 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1475 G_STRUCT_OFFSET (GtkEntryClass, activate),
1477 _gtk_marshal_VOID__VOID,
1479 widget_class->activate_signal = signals[ACTIVATE];
1482 * GtkEntry::move-cursor:
1483 * @entry: the object which received the signal
1484 * @step: the granularity of the move, as a #GtkMovementStep
1485 * @count: the number of @step units to move
1486 * @extend_selection: %TRUE if the move should extend the selection
1488 * The ::move-cursor signal is a
1489 * <link linkend="keybinding-signals">keybinding signal</link>
1490 * which gets emitted when the user initiates a cursor movement.
1491 * If the cursor is not visible in @entry, this signal causes
1492 * the viewport to be moved instead.
1494 * Applications should not connect to it, but may emit it with
1495 * g_signal_emit_by_name() if they need to control the cursor
1498 * The default bindings for this signal come in two variants,
1499 * the variant with the Shift modifier extends the selection,
1500 * the variant without the Shift modifer does not.
1501 * There are too many key combinations to list them all here.
1503 * <listitem>Arrow keys move by individual characters/lines</listitem>
1504 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1505 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1508 signals[MOVE_CURSOR] =
1509 g_signal_new (I_("move-cursor"),
1510 G_OBJECT_CLASS_TYPE (gobject_class),
1511 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1512 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1514 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1516 GTK_TYPE_MOVEMENT_STEP,
1521 * GtkEntry::insert-at-cursor:
1522 * @entry: the object which received the signal
1523 * @string: the string to insert
1525 * The ::insert-at-cursor signal is a
1526 * <link linkend="keybinding-signals">keybinding signal</link>
1527 * which gets emitted when the user initiates the insertion of a
1528 * fixed string at the cursor.
1530 * This signal has no default bindings.
1532 signals[INSERT_AT_CURSOR] =
1533 g_signal_new (I_("insert-at-cursor"),
1534 G_OBJECT_CLASS_TYPE (gobject_class),
1535 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1536 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1538 _gtk_marshal_VOID__STRING,
1543 * GtkEntry::delete-from-cursor:
1544 * @entry: the object which received the signal
1545 * @type: the granularity of the deletion, as a #GtkDeleteType
1546 * @count: the number of @type units to delete
1548 * The ::delete-from-cursor signal is a
1549 * <link linkend="keybinding-signals">keybinding signal</link>
1550 * which gets emitted when the user initiates a text deletion.
1552 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1553 * if there is one, otherwise it deletes the requested number
1556 * The default bindings for this signal are
1557 * Delete for deleting a character and Ctrl-Delete for
1560 signals[DELETE_FROM_CURSOR] =
1561 g_signal_new (I_("delete-from-cursor"),
1562 G_OBJECT_CLASS_TYPE (gobject_class),
1563 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1564 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1566 _gtk_marshal_VOID__ENUM_INT,
1568 GTK_TYPE_DELETE_TYPE,
1572 * GtkEntry::backspace:
1573 * @entry: the object which received the signal
1575 * The ::backspace signal is a
1576 * <link linkend="keybinding-signals">keybinding signal</link>
1577 * which gets emitted when the user asks for it.
1579 * The default bindings for this signal are
1580 * Backspace and Shift-Backspace.
1582 signals[BACKSPACE] =
1583 g_signal_new (I_("backspace"),
1584 G_OBJECT_CLASS_TYPE (gobject_class),
1585 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1586 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1588 _gtk_marshal_VOID__VOID,
1592 * GtkEntry::cut-clipboard:
1593 * @entry: the object which received the signal
1595 * The ::cut-clipboard signal is a
1596 * <link linkend="keybinding-signals">keybinding signal</link>
1597 * which gets emitted to cut the selection to the clipboard.
1599 * The default bindings for this signal are
1600 * Ctrl-x and Shift-Delete.
1602 signals[CUT_CLIPBOARD] =
1603 g_signal_new (I_("cut-clipboard"),
1604 G_OBJECT_CLASS_TYPE (gobject_class),
1605 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1606 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1608 _gtk_marshal_VOID__VOID,
1612 * GtkEntry::copy-clipboard:
1613 * @entry: the object which received the signal
1615 * The ::copy-clipboard signal is a
1616 * <link linkend="keybinding-signals">keybinding signal</link>
1617 * which gets emitted to copy the selection to the clipboard.
1619 * The default bindings for this signal are
1620 * Ctrl-c and Ctrl-Insert.
1622 signals[COPY_CLIPBOARD] =
1623 g_signal_new (I_("copy-clipboard"),
1624 G_OBJECT_CLASS_TYPE (gobject_class),
1625 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1626 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1628 _gtk_marshal_VOID__VOID,
1632 * GtkEntry::paste-clipboard:
1633 * @entry: the object which received the signal
1635 * The ::paste-clipboard signal is a
1636 * <link linkend="keybinding-signals">keybinding signal</link>
1637 * which gets emitted to paste the contents of the clipboard
1638 * into the text view.
1640 * The default bindings for this signal are
1641 * Ctrl-v and Shift-Insert.
1643 signals[PASTE_CLIPBOARD] =
1644 g_signal_new (I_("paste-clipboard"),
1645 G_OBJECT_CLASS_TYPE (gobject_class),
1646 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1647 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1649 _gtk_marshal_VOID__VOID,
1653 * GtkEntry::toggle-overwrite:
1654 * @entry: the object which received the signal
1656 * The ::toggle-overwrite signal is a
1657 * <link linkend="keybinding-signals">keybinding signal</link>
1658 * which gets emitted to toggle the overwrite mode of the entry.
1660 * The default bindings for this signal is Insert.
1662 signals[TOGGLE_OVERWRITE] =
1663 g_signal_new (I_("toggle-overwrite"),
1664 G_OBJECT_CLASS_TYPE (gobject_class),
1665 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1666 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1668 _gtk_marshal_VOID__VOID,
1672 * GtkEntry::icon-press:
1673 * @entry: The entry on which the signal is emitted
1674 * @icon_pos: The position of the clicked icon
1675 * @event: (type Gdk.EventButton): the button press event
1677 * The ::icon-press signal is emitted when an activatable icon
1682 signals[ICON_PRESS] =
1683 g_signal_new (I_("icon-press"),
1684 G_TYPE_FROM_CLASS (gobject_class),
1688 _gtk_marshal_VOID__ENUM_BOXED,
1690 GTK_TYPE_ENTRY_ICON_POSITION,
1691 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1694 * GtkEntry::icon-release:
1695 * @entry: The entry on which the signal is emitted
1696 * @icon_pos: The position of the clicked icon
1697 * @event: (type Gdk.EventButton): the button release event
1699 * The ::icon-release signal is emitted on the button release from a
1700 * mouse click over an activatable icon.
1704 signals[ICON_RELEASE] =
1705 g_signal_new (I_("icon-release"),
1706 G_TYPE_FROM_CLASS (gobject_class),
1710 _gtk_marshal_VOID__ENUM_BOXED,
1712 GTK_TYPE_ENTRY_ICON_POSITION,
1713 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1716 * GtkEntry::preedit-changed:
1717 * @entry: the object which received the signal
1718 * @preedit: the current preedit string
1720 * If an input method is used, the typed text will not immediately
1721 * be committed to the buffer. So if you are interested in the text,
1722 * connect to this signal.
1726 signals[PREEDIT_CHANGED] =
1727 g_signal_new_class_handler (I_("preedit-changed"),
1728 G_OBJECT_CLASS_TYPE (gobject_class),
1729 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1732 _gtk_marshal_VOID__STRING,
1741 binding_set = gtk_binding_set_by_class (class);
1743 /* Moving the insertion point */
1744 add_move_binding (binding_set, GDK_KEY_Right, 0,
1745 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1747 add_move_binding (binding_set, GDK_KEY_Left, 0,
1748 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1750 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1751 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1753 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1754 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1756 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1757 GTK_MOVEMENT_WORDS, 1);
1759 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1760 GTK_MOVEMENT_WORDS, -1);
1762 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1763 GTK_MOVEMENT_WORDS, 1);
1765 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1766 GTK_MOVEMENT_WORDS, -1);
1768 add_move_binding (binding_set, GDK_KEY_Home, 0,
1769 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1771 add_move_binding (binding_set, GDK_KEY_End, 0,
1772 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1774 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1775 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1777 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1778 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1780 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1781 GTK_MOVEMENT_BUFFER_ENDS, -1);
1783 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1784 GTK_MOVEMENT_BUFFER_ENDS, 1);
1786 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1787 GTK_MOVEMENT_BUFFER_ENDS, -1);
1789 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1790 GTK_MOVEMENT_BUFFER_ENDS, 1);
1794 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1796 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1798 G_TYPE_BOOLEAN, FALSE);
1799 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1801 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1803 G_TYPE_BOOLEAN, TRUE);
1805 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1807 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1809 G_TYPE_BOOLEAN, FALSE);
1810 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1812 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1814 G_TYPE_BOOLEAN, TRUE);
1817 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1819 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1821 G_TYPE_BOOLEAN, FALSE);
1822 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1824 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1826 G_TYPE_BOOLEAN, FALSE);
1830 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1832 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1834 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1838 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1839 "delete-from-cursor", 2,
1840 G_TYPE_ENUM, GTK_DELETE_CHARS,
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1844 "delete-from-cursor", 2,
1845 G_TYPE_ENUM, GTK_DELETE_CHARS,
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1851 /* Make this do the same as Backspace, to help with mis-typing */
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1856 "delete-from-cursor", 2,
1857 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1860 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1861 "delete-from-cursor", 2,
1862 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1865 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1866 "delete-from-cursor", 2,
1867 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1870 /* Cut/copy/paste */
1872 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1873 "cut-clipboard", 0);
1874 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1875 "copy-clipboard", 0);
1876 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1877 "paste-clipboard", 0);
1879 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1880 "cut-clipboard", 0);
1881 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1882 "copy-clipboard", 0);
1883 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1884 "paste-clipboard", 0);
1887 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1888 "toggle-overwrite", 0);
1889 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1890 "toggle-overwrite", 0);
1893 * GtkEntry:inner-border:
1895 * Sets the text area's border between the text and the frame.
1899 * Deprecated: 3.4: Use the standard border and padding CSS properties
1900 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1901 * of this style property is ignored.
1903 gtk_widget_class_install_style_property (widget_class,
1904 g_param_spec_boxed ("inner-border",
1906 P_("Border between text and frame."),
1908 GTK_PARAM_READABLE |
1909 G_PARAM_DEPRECATED));
1911 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1913 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1917 gtk_entry_editable_init (GtkEditableInterface *iface)
1919 iface->do_insert_text = gtk_entry_insert_text;
1920 iface->do_delete_text = gtk_entry_delete_text;
1921 iface->insert_text = gtk_entry_real_insert_text;
1922 iface->delete_text = gtk_entry_real_delete_text;
1923 iface->get_chars = gtk_entry_get_chars;
1924 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1925 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1926 iface->set_position = gtk_entry_real_set_position;
1927 iface->get_position = gtk_entry_get_position;
1931 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1933 iface->start_editing = gtk_entry_start_editing;
1936 /* for deprecated properties */
1938 gtk_entry_do_set_inner_border (GtkEntry *entry,
1939 const GtkBorder *border)
1942 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1943 gtk_border_copy (border),
1944 (GDestroyNotify) gtk_border_free);
1946 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1948 g_object_notify (G_OBJECT (entry), "inner-border");
1951 static const GtkBorder *
1952 gtk_entry_do_get_inner_border (GtkEntry *entry)
1954 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1958 gtk_entry_set_property (GObject *object,
1960 const GValue *value,
1963 GtkEntry *entry = GTK_ENTRY (object);
1964 GtkEntryPrivate *priv = entry->priv;
1969 gtk_entry_set_buffer (entry, g_value_get_object (value));
1974 gboolean new_value = g_value_get_boolean (value);
1976 if (new_value != priv->editable)
1978 GtkWidget *widget = GTK_WIDGET (entry);
1982 gtk_entry_reset_im_context (entry);
1983 if (gtk_widget_has_focus (widget))
1984 gtk_im_context_focus_out (priv->im_context);
1986 priv->preedit_length = 0;
1987 priv->preedit_cursor = 0;
1990 priv->editable = new_value;
1992 if (new_value && gtk_widget_has_focus (widget))
1993 gtk_im_context_focus_in (priv->im_context);
1995 gtk_widget_queue_draw (widget);
2000 case PROP_MAX_LENGTH:
2001 gtk_entry_set_max_length (entry, g_value_get_int (value));
2004 case PROP_VISIBILITY:
2005 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
2008 case PROP_HAS_FRAME:
2009 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
2012 case PROP_INNER_BORDER:
2013 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
2016 case PROP_INVISIBLE_CHAR:
2017 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2020 case PROP_ACTIVATES_DEFAULT:
2021 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2024 case PROP_WIDTH_CHARS:
2025 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2029 gtk_entry_set_text (entry, g_value_get_string (value));
2033 gtk_entry_set_alignment (entry, g_value_get_float (value));
2036 case PROP_TRUNCATE_MULTILINE:
2037 priv->truncate_multiline = g_value_get_boolean (value);
2040 case PROP_SHADOW_TYPE:
2041 priv->shadow_type = g_value_get_enum (value);
2044 case PROP_OVERWRITE_MODE:
2045 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2048 case PROP_INVISIBLE_CHAR_SET:
2049 if (g_value_get_boolean (value))
2050 priv->invisible_char_set = TRUE;
2052 gtk_entry_unset_invisible_char (entry);
2055 case PROP_CAPS_LOCK_WARNING:
2056 priv->caps_lock_warning = g_value_get_boolean (value);
2059 case PROP_PROGRESS_FRACTION:
2060 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2063 case PROP_PROGRESS_PULSE_STEP:
2064 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2067 case PROP_PLACEHOLDER_TEXT:
2068 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2071 case PROP_PIXBUF_PRIMARY:
2072 gtk_entry_set_icon_from_pixbuf (entry,
2073 GTK_ENTRY_ICON_PRIMARY,
2074 g_value_get_object (value));
2077 case PROP_PIXBUF_SECONDARY:
2078 gtk_entry_set_icon_from_pixbuf (entry,
2079 GTK_ENTRY_ICON_SECONDARY,
2080 g_value_get_object (value));
2083 case PROP_STOCK_PRIMARY:
2084 gtk_entry_set_icon_from_stock (entry,
2085 GTK_ENTRY_ICON_PRIMARY,
2086 g_value_get_string (value));
2089 case PROP_STOCK_SECONDARY:
2090 gtk_entry_set_icon_from_stock (entry,
2091 GTK_ENTRY_ICON_SECONDARY,
2092 g_value_get_string (value));
2095 case PROP_ICON_NAME_PRIMARY:
2096 gtk_entry_set_icon_from_icon_name (entry,
2097 GTK_ENTRY_ICON_PRIMARY,
2098 g_value_get_string (value));
2101 case PROP_ICON_NAME_SECONDARY:
2102 gtk_entry_set_icon_from_icon_name (entry,
2103 GTK_ENTRY_ICON_SECONDARY,
2104 g_value_get_string (value));
2107 case PROP_GICON_PRIMARY:
2108 gtk_entry_set_icon_from_gicon (entry,
2109 GTK_ENTRY_ICON_PRIMARY,
2110 g_value_get_object (value));
2113 case PROP_GICON_SECONDARY:
2114 gtk_entry_set_icon_from_gicon (entry,
2115 GTK_ENTRY_ICON_SECONDARY,
2116 g_value_get_object (value));
2119 case PROP_ACTIVATABLE_PRIMARY:
2120 gtk_entry_set_icon_activatable (entry,
2121 GTK_ENTRY_ICON_PRIMARY,
2122 g_value_get_boolean (value));
2125 case PROP_ACTIVATABLE_SECONDARY:
2126 gtk_entry_set_icon_activatable (entry,
2127 GTK_ENTRY_ICON_SECONDARY,
2128 g_value_get_boolean (value));
2131 case PROP_SENSITIVE_PRIMARY:
2132 gtk_entry_set_icon_sensitive (entry,
2133 GTK_ENTRY_ICON_PRIMARY,
2134 g_value_get_boolean (value));
2137 case PROP_SENSITIVE_SECONDARY:
2138 gtk_entry_set_icon_sensitive (entry,
2139 GTK_ENTRY_ICON_SECONDARY,
2140 g_value_get_boolean (value));
2143 case PROP_TOOLTIP_TEXT_PRIMARY:
2144 gtk_entry_set_icon_tooltip_text (entry,
2145 GTK_ENTRY_ICON_PRIMARY,
2146 g_value_get_string (value));
2149 case PROP_TOOLTIP_TEXT_SECONDARY:
2150 gtk_entry_set_icon_tooltip_text (entry,
2151 GTK_ENTRY_ICON_SECONDARY,
2152 g_value_get_string (value));
2155 case PROP_TOOLTIP_MARKUP_PRIMARY:
2156 gtk_entry_set_icon_tooltip_markup (entry,
2157 GTK_ENTRY_ICON_PRIMARY,
2158 g_value_get_string (value));
2161 case PROP_TOOLTIP_MARKUP_SECONDARY:
2162 gtk_entry_set_icon_tooltip_markup (entry,
2163 GTK_ENTRY_ICON_SECONDARY,
2164 g_value_get_string (value));
2167 case PROP_IM_MODULE:
2168 g_free (priv->im_module);
2169 priv->im_module = g_value_dup_string (value);
2170 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2171 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2174 case PROP_EDITING_CANCELED:
2175 priv->editing_canceled = g_value_get_boolean (value);
2178 case PROP_COMPLETION:
2179 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2182 case PROP_INPUT_PURPOSE:
2183 gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
2186 case PROP_INPUT_HINTS:
2187 gtk_entry_set_input_hints (entry, g_value_get_flags (value));
2190 case PROP_SCROLL_OFFSET:
2191 case PROP_CURSOR_POSITION:
2193 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2199 gtk_entry_get_property (GObject *object,
2204 GtkEntry *entry = GTK_ENTRY (object);
2205 GtkEntryPrivate *priv = entry->priv;
2210 g_value_set_object (value, gtk_entry_get_buffer (entry));
2213 case PROP_CURSOR_POSITION:
2214 g_value_set_int (value, priv->current_pos);
2217 case PROP_SELECTION_BOUND:
2218 g_value_set_int (value, priv->selection_bound);
2222 g_value_set_boolean (value, priv->editable);
2225 case PROP_MAX_LENGTH:
2226 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2229 case PROP_VISIBILITY:
2230 g_value_set_boolean (value, priv->visible);
2233 case PROP_HAS_FRAME:
2234 g_value_set_boolean (value, priv->has_frame);
2237 case PROP_INNER_BORDER:
2238 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2241 case PROP_INVISIBLE_CHAR:
2242 g_value_set_uint (value, priv->invisible_char);
2245 case PROP_ACTIVATES_DEFAULT:
2246 g_value_set_boolean (value, priv->activates_default);
2249 case PROP_WIDTH_CHARS:
2250 g_value_set_int (value, priv->width_chars);
2253 case PROP_SCROLL_OFFSET:
2254 g_value_set_int (value, priv->scroll_offset);
2258 g_value_set_string (value, gtk_entry_get_text (entry));
2262 g_value_set_float (value, gtk_entry_get_alignment (entry));
2265 case PROP_TRUNCATE_MULTILINE:
2266 g_value_set_boolean (value, priv->truncate_multiline);
2269 case PROP_SHADOW_TYPE:
2270 g_value_set_enum (value, priv->shadow_type);
2273 case PROP_OVERWRITE_MODE:
2274 g_value_set_boolean (value, priv->overwrite_mode);
2277 case PROP_TEXT_LENGTH:
2278 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2281 case PROP_INVISIBLE_CHAR_SET:
2282 g_value_set_boolean (value, priv->invisible_char_set);
2285 case PROP_IM_MODULE:
2286 g_value_set_string (value, priv->im_module);
2289 case PROP_CAPS_LOCK_WARNING:
2290 g_value_set_boolean (value, priv->caps_lock_warning);
2293 case PROP_PROGRESS_FRACTION:
2294 g_value_set_double (value, priv->progress_fraction);
2297 case PROP_PROGRESS_PULSE_STEP:
2298 g_value_set_double (value, priv->progress_pulse_fraction);
2301 case PROP_PLACEHOLDER_TEXT:
2302 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2305 case PROP_PIXBUF_PRIMARY:
2306 g_value_set_object (value,
2307 gtk_entry_get_icon_pixbuf (entry,
2308 GTK_ENTRY_ICON_PRIMARY));
2311 case PROP_PIXBUF_SECONDARY:
2312 g_value_set_object (value,
2313 gtk_entry_get_icon_pixbuf (entry,
2314 GTK_ENTRY_ICON_SECONDARY));
2317 case PROP_STOCK_PRIMARY:
2318 g_value_set_string (value,
2319 gtk_entry_get_icon_stock (entry,
2320 GTK_ENTRY_ICON_PRIMARY));
2323 case PROP_STOCK_SECONDARY:
2324 g_value_set_string (value,
2325 gtk_entry_get_icon_stock (entry,
2326 GTK_ENTRY_ICON_SECONDARY));
2329 case PROP_ICON_NAME_PRIMARY:
2330 g_value_set_string (value,
2331 gtk_entry_get_icon_name (entry,
2332 GTK_ENTRY_ICON_PRIMARY));
2335 case PROP_ICON_NAME_SECONDARY:
2336 g_value_set_string (value,
2337 gtk_entry_get_icon_name (entry,
2338 GTK_ENTRY_ICON_SECONDARY));
2341 case PROP_GICON_PRIMARY:
2342 g_value_set_object (value,
2343 gtk_entry_get_icon_gicon (entry,
2344 GTK_ENTRY_ICON_PRIMARY));
2347 case PROP_GICON_SECONDARY:
2348 g_value_set_object (value,
2349 gtk_entry_get_icon_gicon (entry,
2350 GTK_ENTRY_ICON_SECONDARY));
2353 case PROP_STORAGE_TYPE_PRIMARY:
2354 g_value_set_enum (value,
2355 gtk_entry_get_icon_storage_type (entry,
2356 GTK_ENTRY_ICON_PRIMARY));
2359 case PROP_STORAGE_TYPE_SECONDARY:
2360 g_value_set_enum (value,
2361 gtk_entry_get_icon_storage_type (entry,
2362 GTK_ENTRY_ICON_SECONDARY));
2365 case PROP_ACTIVATABLE_PRIMARY:
2366 g_value_set_boolean (value,
2367 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2370 case PROP_ACTIVATABLE_SECONDARY:
2371 g_value_set_boolean (value,
2372 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2375 case PROP_SENSITIVE_PRIMARY:
2376 g_value_set_boolean (value,
2377 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2380 case PROP_SENSITIVE_SECONDARY:
2381 g_value_set_boolean (value,
2382 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2385 case PROP_TOOLTIP_TEXT_PRIMARY:
2386 g_value_take_string (value,
2387 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2390 case PROP_TOOLTIP_TEXT_SECONDARY:
2391 g_value_take_string (value,
2392 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2395 case PROP_TOOLTIP_MARKUP_PRIMARY:
2396 g_value_take_string (value,
2397 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2400 case PROP_TOOLTIP_MARKUP_SECONDARY:
2401 g_value_take_string (value,
2402 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2405 case PROP_EDITING_CANCELED:
2406 g_value_set_boolean (value,
2407 priv->editing_canceled);
2410 case PROP_COMPLETION:
2411 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2414 case PROP_INPUT_PURPOSE:
2415 g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
2418 case PROP_INPUT_HINTS:
2419 g_value_set_flags (value, gtk_entry_get_input_hints (entry));
2423 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2429 find_invisible_char (GtkWidget *widget)
2431 PangoLayout *layout;
2432 PangoAttrList *attr_list;
2434 gunichar invisible_chars [] = {
2436 0x25cf, /* BLACK CIRCLE */
2437 0x2022, /* BULLET */
2438 0x2731, /* HEAVY ASTERISK */
2439 0x273a /* SIXTEEN POINTED ASTERISK */
2442 gtk_widget_style_get (widget,
2443 "invisible-char", &invisible_chars[0],
2446 layout = gtk_widget_create_pango_layout (widget, NULL);
2448 attr_list = pango_attr_list_new ();
2449 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2451 pango_layout_set_attributes (layout, attr_list);
2452 pango_attr_list_unref (attr_list);
2454 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2456 gchar text[7] = { 0, };
2459 len = g_unichar_to_utf8 (invisible_chars[i], text);
2460 pango_layout_set_text (layout, text, len);
2462 count = pango_layout_get_unknown_glyphs_count (layout);
2466 g_object_unref (layout);
2467 return invisible_chars[i];
2471 g_object_unref (layout);
2477 gtk_entry_init (GtkEntry *entry)
2479 GtkStyleContext *context;
2480 GtkEntryPrivate *priv;
2482 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2487 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2488 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2490 priv->editable = TRUE;
2491 priv->visible = TRUE;
2492 priv->dnd_position = -1;
2493 priv->width_chars = -1;
2494 priv->is_cell_renderer = FALSE;
2495 priv->editing_canceled = FALSE;
2496 priv->has_frame = TRUE;
2497 priv->truncate_multiline = FALSE;
2498 priv->shadow_type = GTK_SHADOW_IN;
2500 priv->caps_lock_warning = TRUE;
2501 priv->caps_lock_warning_shown = FALSE;
2502 priv->progress_fraction = 0.0;
2503 priv->progress_pulse_fraction = 0.1;
2505 gtk_drag_dest_set (GTK_WIDGET (entry),
2506 GTK_DEST_DEFAULT_HIGHLIGHT,
2508 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2509 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2511 /* This object is completely private. No external entity can gain a reference
2512 * to it; so we create it here and destroy it in finalize().
2514 priv->im_context = gtk_im_multicontext_new ();
2516 g_signal_connect (priv->im_context, "commit",
2517 G_CALLBACK (gtk_entry_commit_cb), entry);
2518 g_signal_connect (priv->im_context, "preedit-changed",
2519 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2520 g_signal_connect (priv->im_context, "retrieve-surrounding",
2521 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2522 g_signal_connect (priv->im_context, "delete-surrounding",
2523 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2525 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2526 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2528 gtk_entry_update_cached_style_values (entry);
2532 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2533 GtkStyleContext *context,
2534 GtkEntryIconPosition icon_pos)
2536 GtkEntryPrivate *priv = entry->priv;
2537 EntryIconInfo *icon_info = priv->icons[icon_pos];
2539 GtkStateFlags state;
2541 widget = GTK_WIDGET (entry);
2542 state = gtk_widget_get_state_flags (widget);
2544 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2546 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2547 state |= GTK_STATE_FLAG_INSENSITIVE;
2548 else if (icon_info->prelight)
2549 state |= GTK_STATE_FLAG_PRELIGHT;
2551 gtk_style_context_save (context);
2553 gtk_style_context_set_state (context, state);
2554 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2556 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2558 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2559 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2561 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2565 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2566 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2568 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2573 get_icon_width (GtkEntry *entry,
2574 GtkEntryIconPosition icon_pos)
2576 GtkEntryPrivate *priv = entry->priv;
2577 EntryIconInfo *icon_info = priv->icons[icon_pos];
2578 GtkStyleContext *context;
2585 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2586 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2587 gtk_style_context_get_padding (context, 0, &padding);
2589 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2591 gtk_style_context_restore (context);
2594 width += padding.left + padding.right;
2600 get_icon_allocations (GtkEntry *entry,
2601 GtkAllocation *primary,
2602 GtkAllocation *secondary)
2605 GtkEntryPrivate *priv = entry->priv;
2606 gint x, y, width, height;
2608 get_text_area_size (entry, &x, &y, &width, &height);
2610 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2611 y += priv->focus_width;
2614 primary->height = height;
2615 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2618 secondary->height = height;
2619 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2621 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2623 primary->x = x + width - primary->width;
2629 secondary->x = x + width - secondary->width;
2635 begin_change (GtkEntry *entry)
2637 GtkEntryPrivate *priv = entry->priv;
2639 priv->change_count++;
2641 g_object_freeze_notify (G_OBJECT (entry));
2645 end_change (GtkEntry *entry)
2647 GtkEditable *editable = GTK_EDITABLE (entry);
2648 GtkEntryPrivate *priv = entry->priv;
2650 g_return_if_fail (priv->change_count > 0);
2652 g_object_thaw_notify (G_OBJECT (entry));
2654 priv->change_count--;
2656 if (priv->change_count == 0)
2658 if (priv->real_changed)
2660 g_signal_emit_by_name (editable, "changed");
2661 priv->real_changed = FALSE;
2667 emit_changed (GtkEntry *entry)
2669 GtkEditable *editable = GTK_EDITABLE (entry);
2670 GtkEntryPrivate *priv = entry->priv;
2672 if (priv->change_count == 0)
2673 g_signal_emit_by_name (editable, "changed");
2675 priv->real_changed = TRUE;
2679 gtk_entry_destroy (GtkWidget *widget)
2681 GtkEntry *entry = GTK_ENTRY (widget);
2682 GtkEntryPrivate *priv = entry->priv;
2684 priv->current_pos = priv->selection_bound = 0;
2685 gtk_entry_reset_im_context (entry);
2686 gtk_entry_reset_layout (entry);
2688 if (priv->blink_timeout)
2690 g_source_remove (priv->blink_timeout);
2691 priv->blink_timeout = 0;
2694 if (priv->recompute_idle)
2696 g_source_remove (priv->recompute_idle);
2697 priv->recompute_idle = 0;
2700 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2704 gtk_entry_dispose (GObject *object)
2706 GtkEntry *entry = GTK_ENTRY (object);
2707 GtkEntryPrivate *priv = entry->priv;
2710 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2711 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2712 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2713 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2714 gtk_entry_set_completion (entry, NULL);
2718 buffer_disconnect_signals (entry);
2719 g_object_unref (priv->buffer);
2720 priv->buffer = NULL;
2723 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2724 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2725 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2726 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2730 gtk_entry_finalize (GObject *object)
2732 GtkEntry *entry = GTK_ENTRY (object);
2733 GtkEntryPrivate *priv = entry->priv;
2734 EntryIconInfo *icon_info = NULL;
2737 for (i = 0; i < MAX_ICONS; i++)
2739 if ((icon_info = priv->icons[i]) != NULL)
2741 if (icon_info->target_list != NULL)
2743 gtk_target_list_unref (icon_info->target_list);
2744 icon_info->target_list = NULL;
2747 g_clear_object (&icon_info->icon_helper);
2749 g_slice_free (EntryIconInfo, icon_info);
2750 priv->icons[i] = NULL;
2754 if (priv->cached_layout)
2755 g_object_unref (priv->cached_layout);
2757 g_object_unref (priv->im_context);
2759 if (priv->blink_timeout)
2760 g_source_remove (priv->blink_timeout);
2762 if (priv->recompute_idle)
2763 g_source_remove (priv->recompute_idle);
2765 g_free (priv->placeholder_text);
2766 g_free (priv->im_module);
2768 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2772 gtk_entry_get_display_mode (GtkEntry *entry)
2774 GtkEntryPrivate *priv = entry->priv;
2777 return DISPLAY_NORMAL;
2779 if (priv->invisible_char == 0 && priv->invisible_char_set)
2780 return DISPLAY_BLANK;
2782 return DISPLAY_INVISIBLE;
2786 _gtk_entry_get_display_text (GtkEntry *entry,
2790 GtkEntryPasswordHint *password_hint;
2791 GtkEntryPrivate *priv;
2792 gunichar invisible_char;
2803 text = gtk_entry_buffer_get_text (get_buffer (entry));
2804 length = gtk_entry_buffer_get_length (get_buffer (entry));
2808 if (start_pos > length)
2811 if (end_pos <= start_pos)
2812 return g_strdup ("");
2813 else if (priv->visible)
2815 start = g_utf8_offset_to_pointer (text, start_pos);
2816 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2817 return g_strndup (start, end - start);
2821 str = g_string_sized_new (length * 2);
2823 /* Figure out what our invisible char is and encode it */
2824 if (!priv->invisible_char)
2825 invisible_char = priv->invisible_char_set ? ' ' : '*';
2827 invisible_char = priv->invisible_char;
2828 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2831 * Add hidden characters for each character in the text
2832 * buffer. If there is a password hint, then keep that
2833 * character visible.
2836 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2837 for (i = start_pos; i < end_pos; ++i)
2839 if (password_hint && i == password_hint->position)
2841 start = g_utf8_offset_to_pointer (text, i);
2842 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2846 g_string_append_len (str, char_str, char_len);
2850 return g_string_free (str, FALSE);
2855 update_cursors (GtkWidget *widget)
2857 GtkEntry *entry = GTK_ENTRY (widget);
2858 GtkEntryPrivate *priv = entry->priv;
2859 EntryIconInfo *icon_info = NULL;
2860 GdkDisplay *display;
2864 for (i = 0; i < MAX_ICONS; i++)
2866 if ((icon_info = priv->icons[i]) != NULL)
2868 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2869 icon_info->window != NULL)
2870 gdk_window_show_unraised (icon_info->window);
2872 /* The icon windows are not children of the visible entry window,
2873 * thus we can't just inherit the xterm cursor. Slight complication
2874 * here is that for the entry, insensitive => arrow cursor, but for
2875 * an icon in a sensitive entry, insensitive => xterm cursor.
2877 if (gtk_widget_is_sensitive (widget) &&
2878 (icon_info->insensitive ||
2879 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2881 display = gtk_widget_get_display (widget);
2882 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2883 gdk_window_set_cursor (icon_info->window, cursor);
2884 g_object_unref (cursor);
2888 gdk_window_set_cursor (icon_info->window, NULL);
2895 realize_icon_info (GtkWidget *widget,
2896 GtkEntryIconPosition icon_pos)
2898 GtkEntry *entry = GTK_ENTRY (widget);
2899 GtkEntryPrivate *priv = entry->priv;
2900 EntryIconInfo *icon_info = priv->icons[icon_pos];
2901 GdkWindowAttr attributes;
2902 gint attributes_mask;
2904 g_return_if_fail (icon_info != NULL);
2908 attributes.width = 1;
2909 attributes.height = 1;
2910 attributes.window_type = GDK_WINDOW_CHILD;
2911 attributes.wclass = GDK_INPUT_ONLY;
2912 attributes.event_mask = gtk_widget_get_events (widget);
2913 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2914 GDK_BUTTON_RELEASE_MASK |
2915 GDK_BUTTON1_MOTION_MASK |
2916 GDK_BUTTON3_MOTION_MASK |
2917 GDK_POINTER_MOTION_HINT_MASK |
2918 GDK_POINTER_MOTION_MASK |
2919 GDK_ENTER_NOTIFY_MASK |
2920 GDK_LEAVE_NOTIFY_MASK);
2921 attributes_mask = GDK_WA_X | GDK_WA_Y;
2923 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2926 gdk_window_set_user_data (icon_info->window, widget);
2928 gtk_widget_queue_resize (widget);
2931 static EntryIconInfo*
2932 construct_icon_info (GtkWidget *widget,
2933 GtkEntryIconPosition icon_pos)
2935 GtkEntry *entry = GTK_ENTRY (widget);
2936 GtkEntryPrivate *priv = entry->priv;
2937 EntryIconInfo *icon_info;
2939 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2941 icon_info = g_slice_new0 (EntryIconInfo);
2942 priv->icons[icon_pos] = icon_info;
2944 icon_info->icon_helper = _gtk_icon_helper_new ();
2945 _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
2947 if (gtk_widget_get_realized (widget))
2948 realize_icon_info (widget, icon_pos);
2954 gtk_entry_map (GtkWidget *widget)
2956 GtkEntry *entry = GTK_ENTRY (widget);
2957 GtkEntryPrivate *priv = entry->priv;
2958 EntryIconInfo *icon_info = NULL;
2961 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2963 gdk_window_show (priv->text_area);
2965 for (i = 0; i < MAX_ICONS; i++)
2967 if ((icon_info = priv->icons[i]) != NULL)
2969 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2970 icon_info->window != NULL)
2971 gdk_window_show (icon_info->window);
2975 update_cursors (widget);
2979 gtk_entry_unmap (GtkWidget *widget)
2981 GtkEntry *entry = GTK_ENTRY (widget);
2982 GtkEntryPrivate *priv = entry->priv;
2983 EntryIconInfo *icon_info = NULL;
2986 for (i = 0; i < MAX_ICONS; i++)
2988 if ((icon_info = priv->icons[i]) != NULL)
2990 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2991 icon_info->window != NULL)
2992 gdk_window_hide (icon_info->window);
2996 gdk_window_hide (priv->text_area);
2998 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
3002 gtk_entry_realize (GtkWidget *widget)
3005 GtkEntryPrivate *priv;
3006 EntryIconInfo *icon_info;
3008 GdkWindowAttr attributes;
3009 gint attributes_mask;
3010 gint frame_x, frame_y;
3013 gtk_widget_set_realized (widget, TRUE);
3014 window = gtk_widget_get_parent_window (widget);
3015 gtk_widget_set_window (widget, window);
3016 g_object_ref (window);
3018 entry = GTK_ENTRY (widget);
3021 attributes.window_type = GDK_WINDOW_CHILD;
3022 attributes.wclass = GDK_INPUT_ONLY;
3023 attributes.event_mask = gtk_widget_get_events (widget);
3024 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
3025 GDK_BUTTON_RELEASE_MASK |
3026 GDK_BUTTON1_MOTION_MASK |
3027 GDK_BUTTON3_MOTION_MASK |
3028 GDK_POINTER_MOTION_HINT_MASK |
3029 GDK_POINTER_MOTION_MASK |
3030 GDK_ENTER_NOTIFY_MASK |
3031 GDK_LEAVE_NOTIFY_MASK);
3032 attributes_mask = GDK_WA_X | GDK_WA_Y;
3034 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3036 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3037 attributes.x += frame_x;
3038 attributes.y += frame_y;
3040 if (gtk_widget_is_sensitive (widget))
3042 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3043 attributes_mask |= GDK_WA_CURSOR;
3046 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3050 gdk_window_set_user_data (priv->text_area, entry);
3052 if (attributes_mask & GDK_WA_CURSOR)
3053 g_object_unref (attributes.cursor);
3055 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3057 gtk_entry_adjust_scroll (entry);
3058 gtk_entry_update_primary_selection (entry);
3061 /* If the icon positions are already setup, create their windows.
3062 * Otherwise if they don't exist yet, then construct_icon_info()
3063 * will create the windows once the widget is already realized.
3065 for (i = 0; i < MAX_ICONS; i++)
3067 if ((icon_info = priv->icons[i]) != NULL)
3069 if (icon_info->window == NULL)
3070 realize_icon_info (widget, i);
3076 gtk_entry_unrealize (GtkWidget *widget)
3078 GtkEntry *entry = GTK_ENTRY (widget);
3079 GtkEntryPrivate *priv = entry->priv;
3080 GtkClipboard *clipboard;
3081 EntryIconInfo *icon_info;
3084 gtk_entry_reset_layout (entry);
3086 gtk_im_context_set_client_window (priv->im_context, NULL);
3088 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3089 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3090 gtk_clipboard_clear (clipboard);
3092 if (priv->text_area)
3094 gdk_window_set_user_data (priv->text_area, NULL);
3095 gdk_window_destroy (priv->text_area);
3096 priv->text_area = NULL;
3099 if (priv->popup_menu)
3101 gtk_widget_destroy (priv->popup_menu);
3102 priv->popup_menu = NULL;
3105 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3107 for (i = 0; i < MAX_ICONS; i++)
3109 if ((icon_info = priv->icons[i]) != NULL)
3111 if (icon_info->window != NULL)
3113 gdk_window_destroy (icon_info->window);
3114 icon_info->window = NULL;
3121 _gtk_entry_get_borders (GtkEntry *entry,
3122 GtkBorder *border_out)
3124 GtkEntryPrivate *priv = entry->priv;
3125 GtkWidget *widget = GTK_WIDGET (entry);
3126 GtkBorder tmp = { 0, 0, 0, 0 };
3127 GtkStyleContext *context;
3129 context = gtk_widget_get_style_context (widget);
3130 gtk_style_context_get_padding (context, 0, &tmp);
3132 if (priv->has_frame)
3136 gtk_style_context_get_border (context, 0, &border);
3137 tmp.top += border.top;
3138 tmp.right += border.right;
3139 tmp.bottom += border.bottom;
3140 tmp.left += border.left;
3143 if (!priv->interior_focus)
3145 tmp.top += priv->focus_width;
3146 tmp.right += priv->focus_width;
3147 tmp.bottom += priv->focus_width;
3148 tmp.left += priv->focus_width;
3151 if (border_out != NULL)
3156 gtk_entry_get_preferred_width (GtkWidget *widget,
3160 GtkEntry *entry = GTK_ENTRY (widget);
3161 GtkEntryPrivate *priv = entry->priv;
3162 PangoFontMetrics *metrics;
3164 PangoContext *context;
3165 GtkStyleContext *style_context;
3166 GtkStateFlags state;
3167 gint icon_widths = 0;
3171 context = gtk_widget_get_pango_context (widget);
3173 style_context = gtk_widget_get_style_context (widget);
3174 state = gtk_widget_get_state_flags (widget);
3176 metrics = pango_context_get_metrics (context,
3177 gtk_style_context_get_font (style_context, state),
3178 pango_context_get_language (context));
3180 _gtk_entry_get_borders (entry, &borders);
3182 if (priv->width_chars < 0)
3183 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3186 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3187 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3188 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3190 width = char_pixels * priv->width_chars + borders.left + borders.right;
3193 for (i = 0; i < MAX_ICONS; i++)
3195 icon_width = get_icon_width (entry, i);
3197 icon_widths += icon_width;
3200 if (icon_widths > width)
3201 width += icon_widths;
3203 pango_font_metrics_unref (metrics);
3210 gtk_entry_get_preferred_height (GtkWidget *widget,
3214 GtkEntry *entry = GTK_ENTRY (widget);
3215 GtkEntryPrivate *priv = entry->priv;
3216 PangoFontMetrics *metrics;
3218 GtkStyleContext *style_context;
3219 GtkStateFlags state;
3220 PangoContext *context;
3223 context = gtk_widget_get_pango_context (widget);
3225 style_context = gtk_widget_get_style_context (widget);
3226 state = gtk_widget_get_state_flags (widget);
3228 metrics = pango_context_get_metrics (context,
3229 gtk_style_context_get_font (style_context, state),
3230 pango_context_get_language (context));
3232 priv->ascent = pango_font_metrics_get_ascent (metrics);
3233 priv->descent = pango_font_metrics_get_descent (metrics);
3235 _gtk_entry_get_borders (entry, &borders);
3237 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3239 pango_font_metrics_unref (metrics);
3246 place_windows (GtkEntry *entry)
3248 GtkWidget *widget = GTK_WIDGET (entry);
3249 GtkEntryPrivate *priv = entry->priv;
3250 gint x, y, width, height;
3251 gint frame_x, frame_y;
3252 GtkAllocation primary;
3253 GtkAllocation secondary;
3254 EntryIconInfo *icon_info = NULL;
3256 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3257 get_text_area_size (entry, &x, &y, &width, &height);
3258 get_icon_allocations (entry, &primary, &secondary);
3260 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3261 y += priv->focus_width;
3263 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3264 x += secondary.width;
3267 width -= primary.width + secondary.width;
3271 primary.x += frame_x;
3272 primary.y += frame_y;
3273 secondary.x += frame_x;
3274 secondary.y += frame_y;
3276 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3277 gdk_window_move_resize (icon_info->window,
3278 primary.x, primary.y,
3279 primary.width, primary.height);
3281 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3282 gdk_window_move_resize (icon_info->window,
3283 secondary.x, secondary.y,
3284 secondary.width, secondary.height);
3286 gdk_window_move_resize (priv->text_area, x, y, width, height);
3290 gtk_entry_get_text_area_size (GtkEntry *entry,
3296 GtkEntryPrivate *priv = entry->priv;
3297 GtkWidget *widget = GTK_WIDGET (entry);
3298 GtkAllocation allocation;
3299 GtkRequisition requisition;
3304 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3305 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3307 gtk_widget_get_allocation (widget, &allocation);
3308 _gtk_entry_get_borders (entry, &borders);
3310 if (gtk_widget_get_realized (widget))
3311 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3313 frame_height = req_height;
3315 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3316 frame_height -= 2 * priv->focus_width;
3322 *y = floor ((frame_height - req_height) / 2) + borders.top;
3325 *width = allocation.width - borders.left - borders.right;
3328 *height = req_height - borders.top - borders.bottom;
3332 get_text_area_size (GtkEntry *entry,
3338 GtkEntryClass *class;
3340 g_return_if_fail (GTK_IS_ENTRY (entry));
3342 class = GTK_ENTRY_GET_CLASS (entry);
3344 if (class->get_text_area_size)
3345 class->get_text_area_size (entry, x, y, width, height);
3350 get_frame_size (GtkEntry *entry,
3351 gboolean relative_to_window,
3357 GtkEntryPrivate *priv = entry->priv;
3358 GtkAllocation allocation;
3359 GtkRequisition requisition;
3360 GtkWidget *widget = GTK_WIDGET (entry);
3363 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3365 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3367 gtk_widget_get_allocation (widget, &allocation);
3370 *x = relative_to_window ? allocation.x : 0;
3374 if (priv->is_cell_renderer)
3377 *y = (allocation.height - req_height) / 2;
3379 if (relative_to_window)
3384 *width = allocation.width;
3388 if (priv->is_cell_renderer)
3389 *height = allocation.height;
3391 *height = req_height;
3396 gtk_entry_size_allocate (GtkWidget *widget,
3397 GtkAllocation *allocation)
3399 GtkEntry *entry = GTK_ENTRY (widget);
3401 gtk_widget_set_allocation (widget, allocation);
3403 if (gtk_widget_get_realized (widget))
3405 GtkEntryCompletion* completion;
3407 place_windows (entry);
3408 gtk_entry_recompute (entry);
3410 completion = gtk_entry_get_completion (entry);
3412 _gtk_entry_completion_resize_popup (completion);
3417 should_prelight (GtkEntry *entry,
3418 GtkEntryIconPosition icon_pos)
3420 GtkEntryPrivate *priv = entry->priv;
3421 EntryIconInfo *icon_info = priv->icons[icon_pos];
3427 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3430 if (icon_info->pressed)
3433 gtk_widget_style_get (GTK_WIDGET (entry),
3434 "icon-prelight", &prelight,
3441 draw_icon (GtkWidget *widget,
3443 GtkEntryIconPosition icon_pos)
3445 GtkEntry *entry = GTK_ENTRY (widget);
3446 GtkEntryPrivate *priv = entry->priv;
3447 EntryIconInfo *icon_info = priv->icons[icon_pos];
3448 gint x, y, width, height, pix_width, pix_height;
3449 GtkStyleContext *context;
3455 width = gdk_window_get_width (icon_info->window);
3456 height = gdk_window_get_height (icon_info->window);
3458 /* size_allocate hasn't been called yet. These are the default values.
3460 if (width == 1 || height == 1)
3464 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3466 context = gtk_widget_get_style_context (widget);
3467 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3468 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3469 &pix_width, &pix_height);
3470 gtk_style_context_get_padding (context, 0, &padding);
3472 x = MAX (0, padding.left);
3473 y = MAX (0, (height - pix_height) / 2);
3475 _gtk_icon_helper_draw (icon_info->icon_helper,
3479 gtk_style_context_restore (context);
3485 gtk_entry_draw_frame (GtkWidget *widget,
3486 GtkStyleContext *context,
3489 GtkEntry *entry = GTK_ENTRY (widget);
3490 GtkEntryPrivate *priv = entry->priv;
3491 gint x = 0, y = 0, width, height;
3492 gint frame_x, frame_y;
3496 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3498 cairo_translate (cr, frame_x, frame_y);
3500 /* Fix a problem with some themes which assume that entry->text_area's
3501 * width equals widget->window's width
3502 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3503 if (GTK_IS_SPIN_BUTTON (widget))
3507 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3508 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3511 width += borders.left + borders.right;
3514 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3516 x += priv->focus_width;
3517 y += priv->focus_width;
3518 width -= 2 * priv->focus_width;
3519 height -= 2 * priv->focus_width;
3522 gtk_render_background (context, cr,
3523 x, y, width, height);
3525 if (priv->has_frame)
3526 gtk_render_frame (context, cr,
3527 x, y, width, height);
3529 gtk_entry_draw_progress (widget, context, cr);
3531 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3533 x -= priv->focus_width;
3534 y -= priv->focus_width;
3535 width += 2 * priv->focus_width;
3536 height += 2 * priv->focus_width;
3538 gtk_render_focus (context, cr,
3539 0, 0, width, height);
3546 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3547 GtkStyleContext *context)
3549 GtkEntryPrivate *private = entry->priv;
3551 gtk_style_context_save (context);
3552 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3553 if (private->progress_pulse_mode)
3554 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3558 get_progress_area (GtkWidget *widget,
3564 GtkEntry *entry = GTK_ENTRY (widget);
3565 GtkEntryPrivate *private = entry->priv;
3566 GtkStyleContext *context;
3567 GtkBorder margin, border, entry_borders;
3568 gint frame_width, text_area_width, text_area_height;
3570 context = gtk_widget_get_style_context (widget);
3571 _gtk_entry_get_borders (entry, &entry_borders);
3572 get_text_area_size (entry,
3574 &text_area_width, &text_area_height);
3575 get_frame_size (entry, FALSE,
3577 &frame_width, NULL);
3581 *width = text_area_width + entry_borders.left + entry_borders.right;
3582 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3584 /* if the text area got resized by a subclass, subtract the left/right
3585 * border width, so that the progress bar won't extend over the resized
3588 if (frame_width > *width)
3590 gtk_style_context_get_border (context, 0, &border);
3591 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3593 *x = (frame_width - *width) + border.left;
3594 *width -= border.left;
3598 *width -= border.right;
3602 gtk_entry_prepare_context_for_progress (entry, context);
3603 gtk_style_context_get_margin (context, 0, &margin);
3605 gtk_style_context_restore (context);
3609 *width -= margin.left + margin.right;
3610 *height -= margin.top + margin.bottom;
3612 if (private->progress_pulse_mode)
3614 gdouble value = private->progress_pulse_current;
3616 *x += (gint) floor(value * (*width));
3617 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3619 else if (private->progress_fraction > 0)
3621 gdouble value = private->progress_fraction;
3623 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3627 bar_width = floor(value * (*width) + 0.5);
3628 *x += *width - bar_width;
3633 *width = (gint) floor(value * (*width) + 0.5);
3644 gtk_entry_draw_progress (GtkWidget *widget,
3645 GtkStyleContext *context,
3648 GtkEntry *entry = GTK_ENTRY (widget);
3649 gint x, y, width, height;
3651 get_progress_area (widget, &x, &y, &width, &height);
3653 if ((width <= 0) || (height <= 0))
3656 gtk_entry_prepare_context_for_progress (entry, context);
3657 gtk_render_activity (context, cr,
3658 x, y, width, height);
3660 gtk_style_context_restore (context);
3664 gtk_entry_draw (GtkWidget *widget,
3667 GtkEntry *entry = GTK_ENTRY (widget);
3668 GtkStyleContext *context;
3669 GtkEntryPrivate *priv = entry->priv;
3672 context = gtk_widget_get_style_context (widget);
3674 /* Draw entry_bg, shadow, progress and focus */
3675 gtk_entry_draw_frame (widget, context, cr);
3677 /* Draw text and cursor */
3680 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3682 if (priv->dnd_position != -1)
3683 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3685 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3687 /* When no text is being displayed at all, don't show the cursor */
3688 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3689 gtk_widget_has_focus (widget) &&
3690 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3691 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3696 for (i = 0; i < MAX_ICONS; i++)
3698 EntryIconInfo *icon_info = priv->icons[i];
3700 if (icon_info != NULL)
3701 draw_icon (widget, cr, i);
3708 gtk_entry_enter_notify (GtkWidget *widget,
3709 GdkEventCrossing *event)
3711 GtkEntry *entry = GTK_ENTRY (widget);
3712 GtkEntryPrivate *priv = entry->priv;
3715 for (i = 0; i < MAX_ICONS; i++)
3717 EntryIconInfo *icon_info = priv->icons[i];
3719 if (icon_info != NULL && event->window == icon_info->window)
3721 if (should_prelight (entry, i))
3723 icon_info->prelight = TRUE;
3724 gtk_widget_queue_draw (widget);
3735 gtk_entry_leave_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 /* a grab means that we may never see the button release */
3749 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3750 icon_info->pressed = FALSE;
3752 if (should_prelight (entry, i))
3754 icon_info->prelight = FALSE;
3755 gtk_widget_queue_draw (widget);
3766 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3770 gint start_char, end_char;
3772 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3774 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3775 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3776 const char *text = pango_layout_get_text (layout);
3777 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3778 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3779 gint real_n_ranges, i;
3781 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3787 for (i = 0; i < real_n_ranges; ++i)
3789 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3790 r[2 * i] = r[2 * i] / PANGO_SCALE;
3795 *n_ranges = real_n_ranges;
3807 in_selection (GtkEntry *entry,
3812 gint retval = FALSE;
3814 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3816 for (i = 0; i < n_ranges; ++i)
3818 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3830 gtk_entry_button_press (GtkWidget *widget,
3831 GdkEventButton *event)
3833 GtkEntry *entry = GTK_ENTRY (widget);
3834 GtkEditable *editable = GTK_EDITABLE (widget);
3835 GtkEntryPrivate *priv = entry->priv;
3836 EntryIconInfo *icon_info = NULL;
3838 gint sel_start, sel_end;
3841 for (i = 0; i < MAX_ICONS; i++)
3843 icon_info = priv->icons[i];
3845 if (!icon_info || icon_info->insensitive)
3848 if (event->window == icon_info->window)
3850 if (should_prelight (entry, i))
3852 icon_info->prelight = FALSE;
3853 gtk_widget_queue_draw (widget);
3856 priv->start_x = event->x;
3857 priv->start_y = event->y;
3858 icon_info->pressed = TRUE;
3860 if (!icon_info->nonactivatable)
3861 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3867 if (event->window != priv->text_area ||
3868 (priv->button && event->button != priv->button))
3871 gtk_entry_reset_blink_time (entry);
3873 priv->button = event->button;
3874 priv->device = gdk_event_get_device ((GdkEvent *) event);
3876 if (!gtk_widget_has_focus (widget))
3878 priv->in_click = TRUE;
3879 gtk_widget_grab_focus (widget);
3880 priv->in_click = FALSE;
3883 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3885 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3887 gtk_entry_do_popup (entry, event);
3888 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3889 priv->device = NULL;
3893 else if (event->button == GDK_BUTTON_PRIMARY)
3895 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3897 priv->select_words = FALSE;
3898 priv->select_lines = FALSE;
3901 gtk_widget_get_modifier_mask (widget,
3902 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3904 gtk_entry_reset_im_context (entry);
3906 if (!have_selection) /* select from the current position to the clicked position */
3907 sel_start = sel_end = priv->current_pos;
3909 if (tmp_pos > sel_start && tmp_pos < sel_end)
3911 /* Truncate current selection, but keep it as big as possible */
3912 if (tmp_pos - sel_start > sel_end - tmp_pos)
3913 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3915 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3919 gboolean extend_to_left;
3922 /* Figure out what click selects and extend current selection */
3923 switch (event->type)
3925 case GDK_BUTTON_PRESS:
3926 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3929 case GDK_2BUTTON_PRESS:
3930 priv->select_words = TRUE;
3931 gtk_entry_select_word (entry);
3934 case GDK_3BUTTON_PRESS:
3935 priv->select_lines = TRUE;
3936 gtk_entry_select_line (entry);
3943 start = MIN (priv->current_pos, priv->selection_bound);
3944 start = MIN (sel_start, start);
3946 end = MAX (priv->current_pos, priv->selection_bound);
3947 end = MAX (sel_end, end);
3949 if (tmp_pos == sel_start || tmp_pos == sel_end)
3950 extend_to_left = (tmp_pos == start);
3952 extend_to_left = (end == sel_end);
3955 gtk_entry_set_positions (entry, start, end);
3957 gtk_entry_set_positions (entry, end, start);
3960 else /* no shift key */
3961 switch (event->type)
3963 case GDK_BUTTON_PRESS:
3964 if (in_selection (entry, event->x + priv->scroll_offset))
3966 /* Click inside the selection - we'll either start a drag, or
3967 * clear the selection
3969 priv->in_drag = TRUE;
3970 priv->drag_start_x = event->x + priv->scroll_offset;
3971 priv->drag_start_y = event->y;
3974 gtk_editable_set_position (editable, tmp_pos);
3977 case GDK_2BUTTON_PRESS:
3978 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3979 * receiving a GDK_2BUTTON_PRESS so we need to reset
3980 * priv->in_drag which may have been set above
3982 priv->in_drag = FALSE;
3983 priv->select_words = TRUE;
3984 gtk_entry_select_word (entry);
3987 case GDK_3BUTTON_PRESS:
3988 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3989 * receiving a GDK_3BUTTON_PRESS so we need to reset
3990 * priv->in_drag which may have been set above
3992 priv->in_drag = FALSE;
3993 priv->select_lines = TRUE;
3994 gtk_entry_select_line (entry);
4003 else if (event->type == GDK_BUTTON_PRESS &&
4004 event->button == GDK_BUTTON_MIDDLE &&
4005 get_middle_click_paste (entry))
4009 priv->insert_pos = tmp_pos;
4010 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
4015 gtk_widget_error_bell (widget);
4023 gtk_entry_button_release (GtkWidget *widget,
4024 GdkEventButton *event)
4026 GtkEntry *entry = GTK_ENTRY (widget);
4027 GtkEntryPrivate *priv = entry->priv;
4028 EntryIconInfo *icon_info = NULL;
4031 for (i = 0; i < MAX_ICONS; i++)
4033 icon_info = priv->icons[i];
4035 if (!icon_info || icon_info->insensitive)
4038 if (event->window == icon_info->window)
4040 icon_info->pressed = FALSE;
4042 if (should_prelight (entry, i) &&
4043 event->x >= 0 && event->y >= 0 &&
4044 event->x < gdk_window_get_width (icon_info->window) &&
4045 event->y < gdk_window_get_height (icon_info->window))
4047 icon_info->prelight = TRUE;
4048 gtk_widget_queue_draw (widget);
4051 if (!icon_info->nonactivatable)
4052 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4058 if (event->window != priv->text_area || priv->button != event->button)
4063 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4065 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4071 priv->device = NULL;
4073 gtk_entry_update_primary_selection (entry);
4079 _gtk_entry_get_selected_text (GtkEntry *entry)
4081 GtkEditable *editable = GTK_EDITABLE (entry);
4082 gint start_text, end_text;
4085 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4086 text = gtk_editable_get_chars (editable, start_text, end_text);
4092 gtk_entry_motion_notify (GtkWidget *widget,
4093 GdkEventMotion *event)
4095 GtkEntry *entry = GTK_ENTRY (widget);
4096 GtkEntryPrivate *priv = entry->priv;
4097 EntryIconInfo *icon_info = NULL;
4101 for (i = 0; i < MAX_ICONS; i++)
4103 icon_info = priv->icons[i];
4105 if (!icon_info || icon_info->insensitive)
4108 if (event->window == icon_info->window)
4110 if (icon_info->pressed &&
4111 icon_info->target_list != NULL &&
4112 gtk_drag_check_threshold (widget,
4118 icon_info->in_drag = TRUE;
4119 icon_info->pressed = FALSE;
4120 gtk_drag_begin (widget,
4121 icon_info->target_list,
4131 if (priv->mouse_cursor_obscured)
4135 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4136 gdk_window_set_cursor (priv->text_area, cursor);
4137 g_object_unref (cursor);
4138 priv->mouse_cursor_obscured = FALSE;
4141 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4144 if (priv->select_lines)
4147 gdk_event_request_motions (event);
4151 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4152 gtk_drag_check_threshold (widget,
4153 priv->drag_start_x, priv->drag_start_y,
4154 event->x + priv->scroll_offset, event->y))
4156 GdkDragContext *context;
4157 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4158 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4160 cairo_surface_t *surface;
4162 gtk_target_list_add_text_targets (target_list, 0);
4164 text = _gtk_entry_get_selected_text (entry);
4165 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4167 context = gtk_drag_begin (widget, target_list, actions,
4168 priv->button, (GdkEvent *)event);
4171 gtk_drag_set_icon_surface (context, surface);
4173 gtk_drag_set_icon_default (context);
4176 cairo_surface_destroy (surface);
4179 priv->in_drag = FALSE;
4181 priv->device = NULL;
4183 gtk_target_list_unref (target_list);
4190 else if (event->y >= gdk_window_get_height (priv->text_area))
4191 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4193 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4195 if (priv->select_words)
4198 gint old_min, old_max;
4201 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4202 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4204 pos = priv->current_pos;
4205 bound = priv->selection_bound;
4207 old_min = MIN(priv->current_pos, priv->selection_bound);
4208 old_max = MAX(priv->current_pos, priv->selection_bound);
4215 else if (old_max < max)
4220 else if (pos == old_min)
4222 if (priv->current_pos != min)
4227 if (priv->current_pos != max)
4231 gtk_entry_set_positions (entry, pos, bound);
4234 gtk_entry_set_positions (entry, tmp_pos, -1);
4241 set_invisible_cursor (GdkWindow *window)
4243 GdkDisplay *display;
4246 display = gdk_window_get_display (window);
4247 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4249 gdk_window_set_cursor (window, cursor);
4251 g_object_unref (cursor);
4255 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4257 GtkEntryPrivate *priv = entry->priv;
4259 if (priv->mouse_cursor_obscured)
4262 set_invisible_cursor (priv->text_area);
4264 priv->mouse_cursor_obscured = TRUE;
4268 gtk_entry_key_press (GtkWidget *widget,
4271 GtkEntry *entry = GTK_ENTRY (widget);
4272 GtkEntryPrivate *priv = entry->priv;
4274 gtk_entry_reset_blink_time (entry);
4275 gtk_entry_pend_cursor_blink (entry);
4279 if (gtk_im_context_filter_keypress (priv->im_context, event))
4281 gtk_entry_obscure_mouse_cursor (entry);
4282 priv->need_im_reset = TRUE;
4287 if (event->keyval == GDK_KEY_Return ||
4288 event->keyval == GDK_KEY_KP_Enter ||
4289 event->keyval == GDK_KEY_ISO_Enter ||
4290 event->keyval == GDK_KEY_Escape)
4291 gtk_entry_reset_im_context (entry);
4293 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4294 /* Activate key bindings
4298 if (!priv->editable && event->length)
4299 gtk_widget_error_bell (widget);
4305 gtk_entry_key_release (GtkWidget *widget,
4308 GtkEntry *entry = GTK_ENTRY (widget);
4309 GtkEntryPrivate *priv = entry->priv;
4313 if (gtk_im_context_filter_keypress (priv->im_context, event))
4315 priv->need_im_reset = TRUE;
4320 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4324 gtk_entry_focus_in (GtkWidget *widget,
4325 GdkEventFocus *event)
4327 GtkEntry *entry = GTK_ENTRY (widget);
4328 GtkEntryPrivate *priv = entry->priv;
4331 gtk_widget_queue_draw (widget);
4333 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4337 priv->need_im_reset = TRUE;
4338 gtk_im_context_focus_in (priv->im_context);
4339 keymap_state_changed (keymap, entry);
4340 g_signal_connect (keymap, "state-changed",
4341 G_CALLBACK (keymap_state_changed), entry);
4344 g_signal_connect (keymap, "direction-changed",
4345 G_CALLBACK (keymap_direction_changed), entry);
4347 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4348 priv->placeholder_text != NULL)
4350 gtk_entry_recompute (entry);
4354 gtk_entry_reset_blink_time (entry);
4355 gtk_entry_check_cursor_blink (entry);
4362 gtk_entry_focus_out (GtkWidget *widget,
4363 GdkEventFocus *event)
4365 GtkEntry *entry = GTK_ENTRY (widget);
4366 GtkEntryPrivate *priv = entry->priv;
4367 GtkEntryCompletion *completion;
4370 gtk_widget_queue_draw (widget);
4372 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4376 priv->need_im_reset = TRUE;
4377 gtk_im_context_focus_out (priv->im_context);
4378 remove_capslock_feedback (entry);
4381 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4382 priv->placeholder_text != NULL)
4384 gtk_entry_recompute (entry);
4388 gtk_entry_check_cursor_blink (entry);
4391 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4392 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4394 completion = gtk_entry_get_completion (entry);
4396 _gtk_entry_completion_popdown (completion);
4402 gtk_entry_grab_focus (GtkWidget *widget)
4404 GtkEntry *entry = GTK_ENTRY (widget);
4405 GtkEntryPrivate *priv = entry->priv;
4406 gboolean select_on_focus;
4408 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4410 if (priv->editable && !priv->in_click)
4412 g_object_get (gtk_widget_get_settings (widget),
4413 "gtk-entry-select-on-focus",
4417 if (select_on_focus)
4418 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4423 gtk_entry_direction_changed (GtkWidget *widget,
4424 GtkTextDirection previous_dir)
4426 GtkEntry *entry = GTK_ENTRY (widget);
4428 gtk_entry_recompute (entry);
4430 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4434 gtk_entry_state_flags_changed (GtkWidget *widget,
4435 GtkStateFlags previous_state)
4437 GtkEntry *entry = GTK_ENTRY (widget);
4438 GtkEntryPrivate *priv = entry->priv;
4441 if (gtk_widget_get_realized (widget))
4443 if (gtk_widget_is_sensitive (widget))
4444 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4448 gdk_window_set_cursor (priv->text_area, cursor);
4451 g_object_unref (cursor);
4453 priv->mouse_cursor_obscured = FALSE;
4455 update_cursors (widget);
4458 if (!gtk_widget_is_sensitive (widget))
4460 /* Clear any selection */
4461 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4464 gtk_entry_update_cached_style_values (entry);
4468 gtk_entry_screen_changed (GtkWidget *widget,
4469 GdkScreen *old_screen)
4471 gtk_entry_recompute (GTK_ENTRY (widget));
4474 /* GtkEditable method implementations
4477 gtk_entry_insert_text (GtkEditable *editable,
4478 const gchar *new_text,
4479 gint new_text_length,
4482 g_object_ref (editable);
4485 * The incoming text may a password or other secret. We make sure
4486 * not to copy it into temporary buffers.
4489 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4491 g_object_unref (editable);
4495 gtk_entry_delete_text (GtkEditable *editable,
4499 g_object_ref (editable);
4501 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4503 g_object_unref (editable);
4507 gtk_entry_get_chars (GtkEditable *editable,
4511 GtkEntry *entry = GTK_ENTRY (editable);
4514 gint start_index, end_index;
4516 text = gtk_entry_buffer_get_text (get_buffer (entry));
4517 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4520 end_pos = text_length;
4522 start_pos = MIN (text_length, start_pos);
4523 end_pos = MIN (text_length, end_pos);
4525 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4526 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4528 return g_strndup (text + start_index, end_index - start_index);
4532 gtk_entry_real_set_position (GtkEditable *editable,
4535 GtkEntry *entry = GTK_ENTRY (editable);
4536 GtkEntryPrivate *priv = entry->priv;
4540 length = gtk_entry_buffer_get_length (get_buffer (entry));
4541 if (position < 0 || position > length)
4544 if (position != priv->current_pos ||
4545 position != priv->selection_bound)
4547 gtk_entry_reset_im_context (entry);
4548 gtk_entry_set_positions (entry, position, position);
4553 gtk_entry_get_position (GtkEditable *editable)
4555 GtkEntry *entry = GTK_ENTRY (editable);
4556 GtkEntryPrivate *priv = entry->priv;
4558 return priv->current_pos;
4562 gtk_entry_set_selection_bounds (GtkEditable *editable,
4566 GtkEntry *entry = GTK_ENTRY (editable);
4569 length = gtk_entry_buffer_get_length (get_buffer (entry));
4575 gtk_entry_reset_im_context (entry);
4577 gtk_entry_set_positions (entry,
4579 MIN (start, length));
4581 gtk_entry_update_primary_selection (entry);
4585 gtk_entry_get_selection_bounds (GtkEditable *editable,
4589 GtkEntry *entry = GTK_ENTRY (editable);
4590 GtkEntryPrivate *priv = entry->priv;
4592 *start = priv->selection_bound;
4593 *end = priv->current_pos;
4595 return (priv->selection_bound != priv->current_pos);
4599 icon_theme_changed (GtkEntry *entry)
4601 GtkEntryPrivate *priv = entry->priv;
4604 for (i = 0; i < MAX_ICONS; i++)
4606 EntryIconInfo *icon_info = priv->icons[i];
4607 if (icon_info != NULL)
4608 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4611 gtk_widget_queue_draw (GTK_WIDGET (entry));
4615 gtk_entry_update_cached_style_values (GtkEntry *entry)
4617 GtkEntryPrivate *priv = entry->priv;
4619 gboolean interior_focus;
4621 gtk_widget_style_get (GTK_WIDGET (entry),
4622 "focus-line-width", &focus_width,
4623 "interior-focus", &interior_focus,
4625 priv->focus_width = focus_width;
4626 priv->interior_focus = interior_focus;
4628 if (!priv->invisible_char_set)
4630 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4632 if (priv->invisible_char != ch)
4634 priv->invisible_char = ch;
4635 g_object_notify (G_OBJECT (entry), "invisible-char");
4641 gtk_entry_style_updated (GtkWidget *widget)
4643 GtkEntry *entry = GTK_ENTRY (widget);
4645 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4647 gtk_entry_update_cached_style_values (entry);
4649 gtk_entry_recompute (entry);
4651 icon_theme_changed (entry);
4654 /* GtkCellEditable method implementations
4657 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4659 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4660 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4664 gtk_cell_editable_key_press_event (GtkEntry *entry,
4665 GdkEventKey *key_event,
4668 GtkEntryPrivate *priv = entry->priv;
4670 if (key_event->keyval == GDK_KEY_Escape)
4672 priv->editing_canceled = TRUE;
4673 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4674 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4679 /* override focus */
4680 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4682 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4683 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4692 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4695 GtkEntry *entry = GTK_ENTRY (cell_editable);
4696 GtkEntryPrivate *priv = entry->priv;
4698 priv->is_cell_renderer = TRUE;
4700 g_signal_connect (cell_editable, "activate",
4701 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4702 g_signal_connect (cell_editable, "key-press-event",
4703 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4707 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4709 if (password_hint->source_id)
4710 g_source_remove (password_hint->source_id);
4712 g_slice_free (GtkEntryPasswordHint, password_hint);
4717 gtk_entry_remove_password_hint (gpointer data)
4719 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4720 password_hint->position = -1;
4722 /* Force the string to be redrawn, but now without a visible character */
4723 gtk_entry_recompute (GTK_ENTRY (data));
4727 /* Default signal handlers
4730 gtk_entry_real_insert_text (GtkEditable *editable,
4731 const gchar *new_text,
4732 gint new_text_length,
4738 n_chars = g_utf8_strlen (new_text, new_text_length);
4741 * The actual insertion into the buffer. This will end up firing the
4742 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4743 * buffer_notify_text(), buffer_notify_length()
4745 begin_change (GTK_ENTRY (editable));
4747 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4749 end_change (GTK_ENTRY (editable));
4751 if (n_inserted != n_chars)
4752 gtk_widget_error_bell (GTK_WIDGET (editable));
4754 *position += n_inserted;
4758 gtk_entry_real_delete_text (GtkEditable *editable,
4763 * The actual deletion from the buffer. This will end up firing the
4764 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4765 * buffer_notify_text(), buffer_notify_length()
4768 begin_change (GTK_ENTRY (editable));
4770 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4772 end_change (GTK_ENTRY (editable));
4775 /* GtkEntryBuffer signal handlers
4778 buffer_inserted_text (GtkEntryBuffer *buffer,
4784 GtkEntryPrivate *priv = entry->priv;
4785 guint password_hint_timeout;
4787 gint selection_bound;
4789 current_pos = priv->current_pos;
4790 if (current_pos > position)
4791 current_pos += n_chars;
4793 selection_bound = priv->selection_bound;
4794 if (selection_bound > position)
4795 selection_bound += n_chars;
4797 gtk_entry_set_positions (entry, current_pos, selection_bound);
4799 /* Calculate the password hint if it needs to be displayed. */
4800 if (n_chars == 1 && !priv->visible)
4802 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4803 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4806 if (password_hint_timeout > 0)
4808 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4809 quark_password_hint);
4812 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4813 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4814 (GDestroyNotify)gtk_entry_password_hint_free);
4817 password_hint->position = position;
4818 if (password_hint->source_id)
4819 g_source_remove (password_hint->source_id);
4820 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4821 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4827 buffer_deleted_text (GtkEntryBuffer *buffer,
4832 GtkEntryPrivate *priv = entry->priv;
4833 guint end_pos = position + n_chars;
4834 gint selection_bound;
4837 current_pos = priv->current_pos;
4838 if (current_pos > position)
4839 current_pos -= MIN (current_pos, end_pos) - position;
4841 selection_bound = priv->selection_bound;
4842 if (selection_bound > position)
4843 selection_bound -= MIN (selection_bound, end_pos) - position;
4845 gtk_entry_set_positions (entry, current_pos, selection_bound);
4847 /* We might have deleted the selection */
4848 gtk_entry_update_primary_selection (entry);
4850 /* Disable the password hint if one exists. */
4853 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4854 quark_password_hint);
4857 if (password_hint->source_id)
4858 g_source_remove (password_hint->source_id);
4859 password_hint->source_id = 0;
4860 password_hint->position = -1;
4866 buffer_notify_text (GtkEntryBuffer *buffer,
4870 gtk_entry_recompute (entry);
4871 emit_changed (entry);
4872 g_object_notify (G_OBJECT (entry), "text");
4876 buffer_notify_length (GtkEntryBuffer *buffer,
4880 g_object_notify (G_OBJECT (entry), "text-length");
4884 buffer_notify_max_length (GtkEntryBuffer *buffer,
4888 g_object_notify (G_OBJECT (entry), "max-length");
4892 buffer_connect_signals (GtkEntry *entry)
4894 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4895 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4896 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4897 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4898 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4902 buffer_disconnect_signals (GtkEntry *entry)
4904 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4905 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4906 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4907 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4908 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4911 /* Compute the X position for an offset that corresponds to the "more important
4912 * cursor position for that offset. We use this when trying to guess to which
4913 * end of the selection we should go to when the user hits the left or
4917 get_better_cursor_x (GtkEntry *entry,
4920 GtkEntryPrivate *priv = entry->priv;
4921 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4922 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4923 gboolean split_cursor;
4925 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4926 const gchar *text = pango_layout_get_text (layout);
4927 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4929 PangoRectangle strong_pos, weak_pos;
4931 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4932 "gtk-split-cursor", &split_cursor,
4935 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4938 return strong_pos.x / PANGO_SCALE;
4940 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4944 gtk_entry_move_cursor (GtkEntry *entry,
4945 GtkMovementStep step,
4947 gboolean extend_selection)
4949 GtkEntryPrivate *priv = entry->priv;
4950 gint new_pos = priv->current_pos;
4952 gtk_entry_reset_im_context (entry);
4954 if (priv->current_pos != priv->selection_bound && !extend_selection)
4956 /* If we have a current selection and aren't extending it, move to the
4957 * start/or end of the selection as appropriate
4961 case GTK_MOVEMENT_VISUAL_POSITIONS:
4963 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4964 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4967 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4969 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4972 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4973 case GTK_MOVEMENT_WORDS:
4975 new_pos = MIN (priv->current_pos, priv->selection_bound);
4977 new_pos = MAX (priv->current_pos, priv->selection_bound);
4979 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4980 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4981 case GTK_MOVEMENT_BUFFER_ENDS:
4982 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4984 case GTK_MOVEMENT_DISPLAY_LINES:
4985 case GTK_MOVEMENT_PARAGRAPHS:
4986 case GTK_MOVEMENT_PAGES:
4987 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4995 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4996 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4998 case GTK_MOVEMENT_VISUAL_POSITIONS:
4999 new_pos = gtk_entry_move_visually (entry, new_pos, count);
5000 if (priv->current_pos == new_pos)
5002 if (!extend_selection)
5004 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
5006 GTK_DIR_RIGHT : GTK_DIR_LEFT))
5008 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
5011 gtk_widget_child_focus (toplevel,
5013 GTK_DIR_RIGHT : GTK_DIR_LEFT);
5018 gtk_widget_error_bell (GTK_WIDGET (entry));
5022 case GTK_MOVEMENT_WORDS:
5025 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5030 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5033 if (priv->current_pos == new_pos)
5034 gtk_widget_error_bell (GTK_WIDGET (entry));
5036 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5037 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5038 case GTK_MOVEMENT_BUFFER_ENDS:
5039 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5040 if (priv->current_pos == new_pos)
5041 gtk_widget_error_bell (GTK_WIDGET (entry));
5043 case GTK_MOVEMENT_DISPLAY_LINES:
5044 case GTK_MOVEMENT_PARAGRAPHS:
5045 case GTK_MOVEMENT_PAGES:
5046 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5051 if (extend_selection)
5052 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5054 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5056 gtk_entry_pend_cursor_blink (entry);
5060 gtk_entry_insert_at_cursor (GtkEntry *entry,
5063 GtkEntryPrivate *priv = entry->priv;
5064 GtkEditable *editable = GTK_EDITABLE (entry);
5065 gint pos = priv->current_pos;
5069 gtk_entry_reset_im_context (entry);
5070 gtk_editable_insert_text (editable, str, -1, &pos);
5071 gtk_editable_set_position (editable, pos);
5076 gtk_entry_delete_from_cursor (GtkEntry *entry,
5080 GtkEntryPrivate *priv = entry->priv;
5081 GtkEditable *editable = GTK_EDITABLE (entry);
5082 gint start_pos = priv->current_pos;
5083 gint end_pos = priv->current_pos;
5084 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5086 gtk_entry_reset_im_context (entry);
5088 if (!priv->editable)
5090 gtk_widget_error_bell (GTK_WIDGET (entry));
5094 if (priv->selection_bound != priv->current_pos)
5096 gtk_editable_delete_selection (editable);
5102 case GTK_DELETE_CHARS:
5103 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5104 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5106 case GTK_DELETE_WORDS:
5109 /* Move to end of current word, or if not on a word, end of previous word */
5110 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5111 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5115 /* Move to beginning of current word, or if not on a word, begining of next word */
5116 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5117 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5121 case GTK_DELETE_WORD_ENDS:
5124 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5129 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5132 gtk_editable_delete_text (editable, start_pos, end_pos);
5134 case GTK_DELETE_DISPLAY_LINE_ENDS:
5135 case GTK_DELETE_PARAGRAPH_ENDS:
5137 gtk_editable_delete_text (editable, 0, priv->current_pos);
5139 gtk_editable_delete_text (editable, priv->current_pos, -1);
5141 case GTK_DELETE_DISPLAY_LINES:
5142 case GTK_DELETE_PARAGRAPHS:
5143 gtk_editable_delete_text (editable, 0, -1);
5145 case GTK_DELETE_WHITESPACE:
5146 gtk_entry_delete_whitespace (entry);
5150 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5151 gtk_widget_error_bell (GTK_WIDGET (entry));
5153 gtk_entry_pend_cursor_blink (entry);
5157 gtk_entry_backspace (GtkEntry *entry)
5159 GtkEntryPrivate *priv = entry->priv;
5160 GtkEditable *editable = GTK_EDITABLE (entry);
5163 gtk_entry_reset_im_context (entry);
5165 if (!priv->editable)
5167 gtk_widget_error_bell (GTK_WIDGET (entry));
5171 if (priv->selection_bound != priv->current_pos)
5173 gtk_editable_delete_selection (editable);
5177 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5179 if (prev_pos < priv->current_pos)
5181 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5182 PangoLogAttr *log_attrs;
5185 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5187 /* Deleting parts of characters */
5188 if (log_attrs[priv->current_pos].backspace_deletes_character)
5190 gchar *cluster_text;
5191 gchar *normalized_text;
5194 cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
5196 normalized_text = g_utf8_normalize (cluster_text,
5197 strlen (cluster_text),
5199 len = g_utf8_strlen (normalized_text, -1);
5201 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5204 gint pos = priv->current_pos;
5206 gtk_editable_insert_text (editable, normalized_text,
5207 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5209 gtk_editable_set_position (editable, pos);
5212 g_free (normalized_text);
5213 g_free (cluster_text);
5217 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5224 gtk_widget_error_bell (GTK_WIDGET (entry));
5227 gtk_entry_pend_cursor_blink (entry);
5231 gtk_entry_copy_clipboard (GtkEntry *entry)
5233 GtkEntryPrivate *priv = entry->priv;
5234 GtkEditable *editable = GTK_EDITABLE (entry);
5238 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5242 gtk_widget_error_bell (GTK_WIDGET (entry));
5246 str = _gtk_entry_get_display_text (entry, start, end);
5247 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5248 GDK_SELECTION_CLIPBOARD),
5255 gtk_entry_cut_clipboard (GtkEntry *entry)
5257 GtkEntryPrivate *priv = entry->priv;
5258 GtkEditable *editable = GTK_EDITABLE (entry);
5263 gtk_widget_error_bell (GTK_WIDGET (entry));
5267 gtk_entry_copy_clipboard (entry);
5271 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5272 gtk_editable_delete_text (editable, start, end);
5276 gtk_widget_error_bell (GTK_WIDGET (entry));
5281 gtk_entry_paste_clipboard (GtkEntry *entry)
5283 GtkEntryPrivate *priv = entry->priv;
5286 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5288 gtk_widget_error_bell (GTK_WIDGET (entry));
5292 gtk_entry_delete_cb (GtkEntry *entry)
5294 GtkEntryPrivate *priv = entry->priv;
5295 GtkEditable *editable = GTK_EDITABLE (entry);
5300 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5301 gtk_editable_delete_text (editable, start, end);
5306 gtk_entry_toggle_overwrite (GtkEntry *entry)
5308 GtkEntryPrivate *priv = entry->priv;
5310 priv->overwrite_mode = !priv->overwrite_mode;
5311 gtk_entry_pend_cursor_blink (entry);
5312 gtk_widget_queue_draw (GTK_WIDGET (entry));
5316 gtk_entry_select_all (GtkEntry *entry)
5318 gtk_entry_select_line (entry);
5322 gtk_entry_real_activate (GtkEntry *entry)
5324 GtkEntryPrivate *priv = entry->priv;
5326 GtkWidget *default_widget, *focus_widget;
5327 GtkWidget *toplevel;
5330 widget = GTK_WIDGET (entry);
5332 if (priv->activates_default)
5334 toplevel = gtk_widget_get_toplevel (widget);
5335 if (GTK_IS_WINDOW (toplevel))
5337 window = GTK_WINDOW (toplevel);
5341 default_widget = gtk_window_get_default_widget (window);
5342 focus_widget = gtk_window_get_focus (window);
5343 if (widget != default_widget &&
5344 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5345 gtk_window_activate_default (window);
5352 keymap_direction_changed (GdkKeymap *keymap,
5355 gtk_entry_recompute (entry);
5358 /* IM Context Callbacks
5362 gtk_entry_commit_cb (GtkIMContext *context,
5366 GtkEntryPrivate *priv = entry->priv;
5369 gtk_entry_enter_text (entry, str);
5373 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5376 GtkEntryPrivate *priv = entry->priv;
5380 gchar *preedit_string;
5383 gtk_im_context_get_preedit_string (priv->im_context,
5384 &preedit_string, NULL,
5386 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5387 priv->preedit_length = strlen (preedit_string);
5388 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5389 priv->preedit_cursor = cursor_pos;
5390 g_free (preedit_string);
5392 gtk_entry_recompute (entry);
5397 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5400 GtkEntryPrivate *priv = entry->priv;
5403 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5404 text = _gtk_entry_get_display_text (entry, 0, -1);
5405 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5406 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5413 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5418 GtkEntryPrivate *priv = entry->priv;
5421 gtk_editable_delete_text (GTK_EDITABLE (entry),
5422 priv->current_pos + offset,
5423 priv->current_pos + offset + n_chars);
5428 /* Internal functions
5431 /* Used for im_commit_cb and inserting Unicode chars */
5433 gtk_entry_enter_text (GtkEntry *entry,
5436 GtkEntryPrivate *priv = entry->priv;
5437 GtkEditable *editable = GTK_EDITABLE (entry);
5439 gboolean old_need_im_reset;
5441 old_need_im_reset = priv->need_im_reset;
5442 priv->need_im_reset = FALSE;
5444 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5445 gtk_editable_delete_selection (editable);
5448 if (priv->overwrite_mode)
5449 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5452 tmp_pos = priv->current_pos;
5453 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5454 gtk_editable_set_position (editable, tmp_pos);
5456 priv->need_im_reset = old_need_im_reset;
5459 /* All changes to priv->current_pos and priv->selection_bound
5460 * should go through this function.
5463 gtk_entry_set_positions (GtkEntry *entry,
5465 gint selection_bound)
5467 GtkEntryPrivate *priv = entry->priv;
5468 gboolean changed = FALSE;
5470 g_object_freeze_notify (G_OBJECT (entry));
5472 if (current_pos != -1 &&
5473 priv->current_pos != current_pos)
5475 priv->current_pos = current_pos;
5478 g_object_notify (G_OBJECT (entry), "cursor-position");
5481 if (selection_bound != -1 &&
5482 priv->selection_bound != selection_bound)
5484 priv->selection_bound = selection_bound;
5487 g_object_notify (G_OBJECT (entry), "selection-bound");
5490 g_object_thaw_notify (G_OBJECT (entry));
5494 gtk_entry_move_adjustments (entry);
5495 gtk_entry_recompute (entry);
5500 gtk_entry_reset_layout (GtkEntry *entry)
5502 GtkEntryPrivate *priv = entry->priv;
5504 if (priv->cached_layout)
5506 g_object_unref (priv->cached_layout);
5507 priv->cached_layout = NULL;
5512 update_im_cursor_location (GtkEntry *entry)
5514 GtkEntryPrivate *priv = entry->priv;
5517 gint strong_xoffset;
5518 gint area_width, area_height;
5520 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5521 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5523 strong_xoffset = strong_x - priv->scroll_offset;
5524 if (strong_xoffset < 0)
5528 else if (strong_xoffset > area_width)
5530 strong_xoffset = area_width;
5532 area.x = strong_xoffset;
5535 area.height = area_height;
5537 gtk_im_context_set_cursor_location (priv->im_context, &area);
5541 recompute_idle_func (gpointer data)
5543 GtkEntry *entry = GTK_ENTRY (data);
5544 GtkEntryPrivate *priv = entry->priv;
5546 priv->recompute_idle = 0;
5548 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5550 gtk_entry_adjust_scroll (entry);
5551 gtk_widget_queue_draw (GTK_WIDGET (entry));
5553 update_im_cursor_location (entry);
5560 gtk_entry_recompute (GtkEntry *entry)
5562 GtkEntryPrivate *priv = entry->priv;
5564 gtk_entry_reset_layout (entry);
5565 gtk_entry_check_cursor_blink (entry);
5567 if (!priv->recompute_idle)
5569 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5570 recompute_idle_func, entry, NULL);
5575 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5578 GtkWidget *widget = GTK_WIDGET (entry);
5579 GtkStyleContext *context;
5580 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5582 context = gtk_widget_get_style_context (widget);
5583 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5585 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5586 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5587 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5590 static inline gboolean
5591 show_placeholder_text (GtkEntry *entry)
5593 GtkEntryPrivate *priv = entry->priv;
5595 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5596 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5597 priv->placeholder_text != NULL)
5603 static PangoLayout *
5604 gtk_entry_create_layout (GtkEntry *entry,
5605 gboolean include_preedit)
5607 GtkEntryPrivate *priv = entry->priv;
5608 GtkWidget *widget = GTK_WIDGET (entry);
5609 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5610 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5611 gboolean placeholder_layout = show_placeholder_text (entry);
5613 gchar *preedit_string = NULL;
5614 gint preedit_length = 0;
5615 PangoAttrList *preedit_attrs = NULL;
5620 pango_layout_set_single_paragraph_mode (layout, TRUE);
5622 display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
5623 n_bytes = strlen (display);
5625 if (!placeholder_layout && include_preedit)
5627 gtk_im_context_get_preedit_string (priv->im_context,
5628 &preedit_string, &preedit_attrs, NULL);
5629 preedit_length = priv->preedit_length;
5631 else if (placeholder_layout)
5634 PangoAttribute *attr;
5636 gtk_entry_get_placeholder_text_color (entry, &color);
5637 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5638 attr->start_index = 0;
5639 attr->end_index = G_MAXINT;
5640 pango_attr_list_insert (tmp_attrs, attr);
5645 GString *tmp_string = g_string_new (display);
5646 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5648 g_string_insert (tmp_string, cursor_index, preedit_string);
5650 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5652 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5653 cursor_index, preedit_length);
5655 g_string_free (tmp_string, TRUE);
5659 PangoDirection pango_dir;
5661 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5662 pango_dir = pango_find_base_dir (display, n_bytes);
5664 pango_dir = PANGO_DIRECTION_NEUTRAL;
5666 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5668 if (gtk_widget_has_focus (widget))
5670 GdkDisplay *display = gtk_widget_get_display (widget);
5671 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5672 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5673 pango_dir = PANGO_DIRECTION_RTL;
5675 pango_dir = PANGO_DIRECTION_LTR;
5679 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5680 pango_dir = PANGO_DIRECTION_RTL;
5682 pango_dir = PANGO_DIRECTION_LTR;
5686 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5689 priv->resolved_dir = pango_dir;
5691 pango_layout_set_text (layout, display, n_bytes);
5694 pango_layout_set_attributes (layout, tmp_attrs);
5696 g_free (preedit_string);
5700 pango_attr_list_unref (preedit_attrs);
5702 pango_attr_list_unref (tmp_attrs);
5707 static PangoLayout *
5708 gtk_entry_ensure_layout (GtkEntry *entry,
5709 gboolean include_preedit)
5711 GtkEntryPrivate *priv = entry->priv;
5713 if (priv->preedit_length > 0 &&
5714 !include_preedit != !priv->cache_includes_preedit)
5715 gtk_entry_reset_layout (entry);
5717 if (!priv->cached_layout)
5719 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5720 priv->cache_includes_preedit = include_preedit;
5723 return priv->cached_layout;
5727 get_layout_position (GtkEntry *entry,
5731 GtkEntryPrivate *priv = entry->priv;
5732 PangoLayout *layout;
5733 PangoRectangle logical_rect;
5734 gint area_width, area_height;
5736 PangoLayoutLine *line;
5738 layout = gtk_entry_ensure_layout (entry, TRUE);
5740 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5741 area_height = PANGO_SCALE * area_height;
5743 line = pango_layout_get_lines_readonly (layout)->data;
5744 pango_layout_line_get_extents (line, NULL, &logical_rect);
5746 /* Align primarily for locale's ascent/descent */
5747 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5748 priv->ascent + logical_rect.y);
5750 /* Now see if we need to adjust to fit in actual drawn string */
5751 if (logical_rect.height > area_height)
5752 y_pos = (area_height - logical_rect.height) / 2;
5755 else if (y_pos + logical_rect.height > area_height)
5756 y_pos = area_height - logical_rect.height;
5758 y_pos = y_pos / PANGO_SCALE;
5761 *x = - priv->scroll_offset;
5768 draw_text_with_color (GtkEntry *entry,
5770 GdkRGBA *default_color)
5772 GtkEntryPrivate *priv = entry->priv;
5773 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5776 gint start_pos, end_pos;
5778 widget = GTK_WIDGET (entry);
5782 get_layout_position (entry, &x, &y);
5784 cairo_move_to (cr, x, y);
5785 gdk_cairo_set_source_rgba (cr, default_color);
5786 pango_cairo_show_layout (cr, layout);
5788 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5792 PangoRectangle logical_rect;
5793 GdkRGBA selection_color, text_color;
5794 GtkStyleContext *context;
5795 GtkStateFlags state;
5797 context = gtk_widget_get_style_context (widget);
5798 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5799 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5801 state = gtk_widget_get_state_flags (widget);
5802 state |= GTK_STATE_FLAG_SELECTED;
5804 gtk_style_context_get_background_color (context, state, &selection_color);
5805 gtk_style_context_get_color (context, state, &text_color);
5807 for (i = 0; i < n_ranges; ++i)
5808 cairo_rectangle (cr,
5809 - priv->scroll_offset + ranges[2 * i],
5812 logical_rect.height);
5816 gdk_cairo_set_source_rgba (cr, &selection_color);
5819 cairo_move_to (cr, x, y);
5820 gdk_cairo_set_source_rgba (cr, &text_color);
5821 pango_cairo_show_layout (cr, layout);
5829 gtk_entry_draw_text (GtkEntry *entry,
5832 GtkEntryPrivate *priv = entry->priv;
5833 GtkWidget *widget = GTK_WIDGET (entry);
5834 GtkStateFlags state = 0;
5835 GdkRGBA text_color, bar_text_color;
5836 GtkStyleContext *context;
5838 gint progress_x, progress_y, progress_width, progress_height;
5839 gint clip_width, clip_height;
5841 /* Nothing to display at all */
5842 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5845 state = gtk_widget_get_state_flags (widget);
5846 context = gtk_widget_get_style_context (widget);
5848 gtk_style_context_get_color (context, state, &text_color);
5850 /* Get foreground color for progressbars */
5851 gtk_entry_prepare_context_for_progress (entry, context);
5852 gtk_style_context_get_color (context, state, &bar_text_color);
5853 gtk_style_context_restore (context);
5855 get_progress_area (widget,
5856 &progress_x, &progress_y,
5857 &progress_width, &progress_height);
5861 clip_width = gdk_window_get_width (priv->text_area);
5862 clip_height = gdk_window_get_height (priv->text_area);
5863 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5866 /* If the color is the same, or the progress area has a zero
5867 * size, then we only need to draw once. */
5868 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5869 ((progress_width == 0) || (progress_height == 0)))
5871 draw_text_with_color (entry, cr, &text_color);
5875 int frame_x, frame_y, area_x, area_y;
5877 width = gdk_window_get_width (priv->text_area);
5878 height = gdk_window_get_height (priv->text_area);
5882 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5883 cairo_rectangle (cr, 0, 0, width, height);
5885 /* progres area is frame-relative, we need it text-area window
5887 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5888 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5889 progress_x += frame_x - area_x;
5890 progress_y += frame_y - area_y;
5892 cairo_rectangle (cr, progress_x, progress_y,
5893 progress_width, progress_height);
5895 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5897 draw_text_with_color (entry, cr, &text_color);
5902 cairo_rectangle (cr, progress_x, progress_y,
5903 progress_width, progress_height);
5906 draw_text_with_color (entry, cr, &bar_text_color);
5915 gtk_entry_draw_cursor (GtkEntry *entry,
5919 GtkEntryPrivate *priv = entry->priv;
5920 GtkWidget *widget = GTK_WIDGET (entry);
5921 GtkStyleContext *context;
5922 PangoRectangle cursor_rect;
5925 gboolean block_at_line_end;
5926 PangoLayout *layout;
5930 context = gtk_widget_get_style_context (widget);
5932 layout = gtk_entry_ensure_layout (entry, TRUE);
5933 text = pango_layout_get_text (layout);
5934 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5935 get_layout_position (entry, &x, &y);
5937 if (!priv->overwrite_mode)
5940 block = _gtk_text_util_get_block_cursor_location (layout,
5941 cursor_index, &cursor_rect, &block_at_line_end);
5945 gtk_render_insertion_cursor (context, cr,
5947 layout, cursor_index, priv->resolved_dir);
5949 else /* overwrite_mode */
5951 GdkRGBA cursor_color;
5956 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5957 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5958 rect.width = PANGO_PIXELS (cursor_rect.width);
5959 rect.height = PANGO_PIXELS (cursor_rect.height);
5961 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5962 gdk_cairo_set_source_rgba (cr, &cursor_color);
5963 gdk_cairo_rectangle (cr, &rect);
5966 if (!block_at_line_end)
5968 GtkStateFlags state;
5971 state = gtk_widget_get_state_flags (widget);
5972 gtk_style_context_get_background_color (context, state, &color);
5974 gdk_cairo_rectangle (cr, &rect);
5976 cairo_move_to (cr, x, y);
5977 gdk_cairo_set_source_rgba (cr, &color);
5978 pango_cairo_show_layout (cr, layout);
5986 * gtk_entry_reset_im_context:
5987 * @entry: a #GtkEntry
5989 * Reset the input method context of the entry if needed.
5991 * This can be necessary in the case where modifying the buffer
5992 * would confuse on-going input method behavior.
5997 gtk_entry_reset_im_context (GtkEntry *entry)
5999 GtkEntryPrivate *priv = entry->priv;
6001 g_return_if_fail (GTK_IS_ENTRY (entry));
6003 if (priv->need_im_reset)
6005 priv->need_im_reset = FALSE;
6006 gtk_im_context_reset (priv->im_context);
6011 * gtk_entry_im_context_filter_keypress:
6012 * @entry: a #GtkEntry
6013 * @event: (type Gdk.EventKey): the key event
6015 * Allow the #GtkEntry input method to internally handle key press
6016 * and release events. If this function returns %TRUE, then no further
6017 * processing should be done for this key event. See
6018 * gtk_im_context_filter_keypress().
6020 * Note that you are expected to call this function from your handler
6021 * when overriding key event handling. This is needed in the case when
6022 * you need to insert your own key handling between the input method
6023 * and the default key event handling of the #GtkEntry.
6024 * See gtk_text_view_reset_im_context() for an example of use.
6026 * Return value: %TRUE if the input method handled the key event.
6031 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6034 GtkEntryPrivate *priv;
6036 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6040 return gtk_im_context_filter_keypress (priv->im_context, event);
6044 _gtk_entry_get_im_context (GtkEntry *entry)
6046 return entry->priv->im_context;
6050 gtk_entry_find_position (GtkEntry *entry,
6053 GtkEntryPrivate *priv = entry->priv;
6054 PangoLayout *layout;
6055 PangoLayoutLine *line;
6062 layout = gtk_entry_ensure_layout (entry, TRUE);
6063 text = pango_layout_get_text (layout);
6064 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6066 line = pango_layout_get_lines_readonly (layout)->data;
6067 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6069 if (index >= cursor_index && priv->preedit_length)
6071 if (index >= cursor_index + priv->preedit_length)
6072 index -= priv->preedit_length;
6075 index = cursor_index;
6080 pos = g_utf8_pointer_to_offset (text, text + index);
6087 gtk_entry_get_cursor_locations (GtkEntry *entry,
6092 GtkEntryPrivate *priv = entry->priv;
6093 DisplayMode mode = gtk_entry_get_display_mode (entry);
6095 /* Nothing to display at all, so no cursor is relevant */
6096 if (mode == DISPLAY_BLANK)
6106 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6107 const gchar *text = pango_layout_get_text (layout);
6108 PangoRectangle strong_pos, weak_pos;
6111 if (type == CURSOR_STANDARD)
6113 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6115 else /* type == CURSOR_DND */
6117 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6119 if (priv->dnd_position > priv->current_pos)
6121 if (mode == DISPLAY_NORMAL)
6122 index += priv->preedit_length;
6125 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6126 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6131 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6134 *strong_x = strong_pos.x / PANGO_SCALE;
6137 *weak_x = weak_pos.x / PANGO_SCALE;
6142 gtk_entry_adjust_scroll (GtkEntry *entry)
6144 GtkEntryPrivate *priv = entry->priv;
6145 gint min_offset, max_offset;
6146 gint text_area_width, text_width;
6147 gint strong_x, weak_x;
6148 gint strong_xoffset, weak_xoffset;
6150 PangoLayout *layout;
6151 PangoLayoutLine *line;
6152 PangoRectangle logical_rect;
6154 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6157 text_area_width = gdk_window_get_width (priv->text_area);
6159 if (text_area_width < 0)
6160 text_area_width = 0;
6162 layout = gtk_entry_ensure_layout (entry, TRUE);
6163 line = pango_layout_get_lines_readonly (layout)->data;
6165 pango_layout_line_get_extents (line, NULL, &logical_rect);
6167 /* Display as much text as we can */
6169 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6170 xalign = priv->xalign;
6172 xalign = 1.0 - priv->xalign;
6174 text_width = PANGO_PIXELS(logical_rect.width);
6176 if (text_width > text_area_width)
6179 max_offset = text_width - text_area_width;
6183 min_offset = (text_width - text_area_width) * xalign;
6184 max_offset = min_offset;
6187 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6189 /* And make sure cursors are on screen. Note that the cursor is
6190 * actually drawn one pixel into the INNER_BORDER space on
6191 * the right, when the scroll is at the utmost right. This
6192 * looks better to to me than confining the cursor inside the
6193 * border entirely, though it means that the cursor gets one
6194 * pixel closer to the edge of the widget on the right than
6195 * on the left. This might need changing if one changed
6196 * INNER_BORDER from 2 to 1, as one would do on a
6197 * small-screen-real-estate display.
6199 * We always make sure that the strong cursor is on screen, and
6200 * put the weak cursor on screen if possible.
6203 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6205 strong_xoffset = strong_x - priv->scroll_offset;
6207 if (strong_xoffset < 0)
6209 priv->scroll_offset += strong_xoffset;
6212 else if (strong_xoffset > text_area_width)
6214 priv->scroll_offset += strong_xoffset - text_area_width;
6215 strong_xoffset = text_area_width;
6218 weak_xoffset = weak_x - priv->scroll_offset;
6220 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6222 priv->scroll_offset += weak_xoffset;
6224 else if (weak_xoffset > text_area_width &&
6225 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6227 priv->scroll_offset += weak_xoffset - text_area_width;
6230 g_object_notify (G_OBJECT (entry), "scroll-offset");
6234 gtk_entry_move_adjustments (GtkEntry *entry)
6236 GtkWidget *widget = GTK_WIDGET (entry);
6237 GtkAllocation allocation;
6238 GtkAdjustment *adjustment;
6239 PangoContext *context;
6240 PangoFontMetrics *metrics;
6241 GtkStyleContext *style_context;
6242 GtkStateFlags state;
6247 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6251 gtk_widget_get_allocation (widget, &allocation);
6253 /* Cursor position, layout offset, border width, and widget allocation */
6254 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6255 get_layout_position (entry, &layout_x, NULL);
6256 _gtk_entry_get_borders (entry, &borders);
6257 x += allocation.x + layout_x + borders.left;
6259 /* Approximate width of a char, so user can see what is ahead/behind */
6260 context = gtk_widget_get_pango_context (widget);
6261 style_context = gtk_widget_get_style_context (widget);
6262 state = gtk_widget_get_state_flags (widget);
6264 metrics = pango_context_get_metrics (context,
6265 gtk_style_context_get_font (style_context, state),
6266 pango_context_get_language (context));
6267 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6270 gtk_adjustment_clamp_page (adjustment,
6271 x - (char_width + 1), /* one char + one pixel before */
6272 x + (char_width + 2)); /* one char + cursor + one pixel after */
6276 gtk_entry_move_visually (GtkEntry *entry,
6280 GtkEntryPrivate *priv = entry->priv;
6282 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6285 text = pango_layout_get_text (layout);
6287 index = g_utf8_offset_to_pointer (text, start) - text;
6291 int new_index, new_trailing;
6292 gboolean split_cursor;
6295 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6296 "gtk-split-cursor", &split_cursor,
6303 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6304 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6306 strong = keymap_direction == priv->resolved_dir;
6311 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6316 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6322 else if (new_index != G_MAXINT)
6325 while (new_trailing--)
6326 index = g_utf8_next_char (text + index) - text;
6329 return g_utf8_pointer_to_offset (text, text + index);
6333 gtk_entry_move_logically (GtkEntry *entry,
6337 gint new_pos = start;
6340 length = gtk_entry_buffer_get_length (get_buffer (entry));
6342 /* Prevent any leak of information */
6343 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6345 new_pos = CLAMP (start + count, 0, length);
6349 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6350 PangoLogAttr *log_attrs;
6353 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6355 while (count > 0 && new_pos < length)
6359 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6363 while (count < 0 && new_pos > 0)
6367 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6379 gtk_entry_move_forward_word (GtkEntry *entry,
6381 gboolean allow_whitespace)
6383 gint new_pos = start;
6386 length = gtk_entry_buffer_get_length (get_buffer (entry));
6388 /* Prevent any leak of information */
6389 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6393 else if (new_pos < length)
6395 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6396 PangoLogAttr *log_attrs;
6399 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6401 /* Find the next word boundary */
6403 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6404 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6415 gtk_entry_move_backward_word (GtkEntry *entry,
6417 gboolean allow_whitespace)
6419 gint new_pos = start;
6421 /* Prevent any leak of information */
6422 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6428 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6429 PangoLogAttr *log_attrs;
6432 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6434 new_pos = start - 1;
6436 /* Find the previous word boundary */
6437 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6438 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6448 gtk_entry_delete_whitespace (GtkEntry *entry)
6450 GtkEntryPrivate *priv = entry->priv;
6451 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6452 PangoLogAttr *log_attrs;
6456 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6458 start = end = priv->current_pos;
6460 while (start > 0 && log_attrs[start-1].is_white)
6463 while (end < n_attrs && log_attrs[end].is_white)
6469 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6474 gtk_entry_select_word (GtkEntry *entry)
6476 GtkEntryPrivate *priv = entry->priv;
6477 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6478 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6480 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6484 gtk_entry_select_line (GtkEntry *entry)
6486 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6490 truncate_multiline (const gchar *text)
6495 text[length] && text[length] != '\n' && text[length] != '\r';
6502 paste_received (GtkClipboard *clipboard,
6506 GtkEntry *entry = GTK_ENTRY (data);
6507 GtkEditable *editable = GTK_EDITABLE (entry);
6508 GtkEntryPrivate *priv = entry->priv;
6510 if (priv->button == GDK_BUTTON_MIDDLE)
6512 gint pos, start, end;
6513 pos = priv->insert_pos;
6514 gtk_editable_get_selection_bounds (editable, &start, &end);
6515 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6516 gtk_editable_select_region (editable, pos, pos);
6521 gint pos, start, end;
6523 gboolean popup_completion;
6524 GtkEntryCompletion *completion;
6526 completion = gtk_entry_get_completion (entry);
6528 if (priv->truncate_multiline)
6529 length = truncate_multiline (text);
6531 /* only complete if the selection is at the end */
6532 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6533 MAX (priv->current_pos, priv->selection_bound));
6537 if (gtk_widget_get_mapped (completion->priv->popup_window))
6538 _gtk_entry_completion_popdown (completion);
6540 if (!popup_completion && completion->priv->changed_id > 0)
6541 g_signal_handler_block (entry, completion->priv->changed_id);
6544 begin_change (entry);
6545 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6546 gtk_editable_delete_text (editable, start, end);
6548 pos = priv->current_pos;
6549 gtk_editable_insert_text (editable, text, length, &pos);
6550 gtk_editable_set_position (editable, pos);
6554 !popup_completion && completion->priv->changed_id > 0)
6555 g_signal_handler_unblock (entry, completion->priv->changed_id);
6558 g_object_unref (entry);
6562 gtk_entry_paste (GtkEntry *entry,
6565 g_object_ref (entry);
6566 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6567 paste_received, entry);
6571 primary_get_cb (GtkClipboard *clipboard,
6572 GtkSelectionData *selection_data,
6576 GtkEntry *entry = GTK_ENTRY (data);
6579 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6581 gchar *str = _gtk_entry_get_display_text (entry, start, end);
6582 gtk_selection_data_set_text (selection_data, str, -1);
6588 primary_clear_cb (GtkClipboard *clipboard,
6591 GtkEntry *entry = GTK_ENTRY (data);
6592 GtkEntryPrivate *priv = entry->priv;
6594 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6598 gtk_entry_update_primary_selection (GtkEntry *entry)
6600 GtkTargetList *list;
6601 GtkTargetEntry *targets;
6602 GtkClipboard *clipboard;
6606 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6609 list = gtk_target_list_new (NULL, 0);
6610 gtk_target_list_add_text_targets (list, 0);
6612 targets = gtk_target_table_new_from_list (list, &n_targets);
6614 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6616 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6618 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6619 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6620 primary_clear_cb (clipboard, entry);
6624 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6625 gtk_clipboard_clear (clipboard);
6628 gtk_target_table_free (targets, n_targets);
6629 gtk_target_list_unref (list);
6633 gtk_entry_clear (GtkEntry *entry,
6634 GtkEntryIconPosition icon_pos)
6636 GtkEntryPrivate *priv = entry->priv;
6637 EntryIconInfo *icon_info = priv->icons[icon_pos];
6638 GtkImageType storage_type;
6640 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6643 g_object_freeze_notify (G_OBJECT (entry));
6645 /* Explicitly check, as the pointer may become invalidated
6646 * during destruction.
6648 if (GDK_IS_WINDOW (icon_info->window))
6649 gdk_window_hide (icon_info->window);
6651 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6653 switch (storage_type)
6655 case GTK_IMAGE_PIXBUF:
6656 g_object_notify (G_OBJECT (entry),
6657 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6660 case GTK_IMAGE_STOCK:
6661 g_object_notify (G_OBJECT (entry),
6662 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6665 case GTK_IMAGE_ICON_NAME:
6666 g_object_notify (G_OBJECT (entry),
6667 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6670 case GTK_IMAGE_GICON:
6671 g_object_notify (G_OBJECT (entry),
6672 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6676 g_assert_not_reached ();
6680 _gtk_icon_helper_clear (icon_info->icon_helper);
6682 g_object_notify (G_OBJECT (entry),
6683 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6685 g_object_thaw_notify (G_OBJECT (entry));
6689 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6690 GtkEntryIconPosition icon_pos)
6692 GtkEntryPrivate *priv = entry->priv;
6693 EntryIconInfo *icon_info = priv->icons[icon_pos];
6694 GtkStyleContext *context;
6697 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6698 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6700 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6703 gtk_style_context_restore (context);
6714 * Creates a new entry.
6716 * Return value: a new #GtkEntry.
6719 gtk_entry_new (void)
6721 return g_object_new (GTK_TYPE_ENTRY, NULL);
6725 * gtk_entry_new_with_buffer:
6726 * @buffer: The buffer to use for the new #GtkEntry.
6728 * Creates a new entry with the specified text buffer.
6730 * Return value: a new #GtkEntry
6735 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6737 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6738 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6741 static GtkEntryBuffer*
6742 get_buffer (GtkEntry *entry)
6744 GtkEntryPrivate *priv = entry->priv;
6746 if (priv->buffer == NULL)
6748 GtkEntryBuffer *buffer;
6749 buffer = gtk_entry_buffer_new (NULL, 0);
6750 gtk_entry_set_buffer (entry, buffer);
6751 g_object_unref (buffer);
6754 return priv->buffer;
6758 * gtk_entry_get_buffer:
6759 * @entry: a #GtkEntry
6761 * Get the #GtkEntryBuffer object which holds the text for
6766 * Returns: (transfer none): A #GtkEntryBuffer object.
6769 gtk_entry_get_buffer (GtkEntry *entry)
6771 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6773 return get_buffer (entry);
6777 * gtk_entry_set_buffer:
6778 * @entry: a #GtkEntry
6779 * @buffer: a #GtkEntryBuffer
6781 * Set the #GtkEntryBuffer object which holds the text for
6787 gtk_entry_set_buffer (GtkEntry *entry,
6788 GtkEntryBuffer *buffer)
6790 GtkEntryPrivate *priv;
6793 g_return_if_fail (GTK_IS_ENTRY (entry));
6799 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6800 g_object_ref (buffer);
6805 buffer_disconnect_signals (entry);
6806 g_object_unref (priv->buffer);
6809 priv->buffer = buffer;
6812 buffer_connect_signals (entry);
6814 obj = G_OBJECT (entry);
6815 g_object_freeze_notify (obj);
6816 g_object_notify (obj, "buffer");
6817 g_object_notify (obj, "text");
6818 g_object_notify (obj, "text-length");
6819 g_object_notify (obj, "max-length");
6820 g_object_notify (obj, "visibility");
6821 g_object_notify (obj, "invisible-char");
6822 g_object_notify (obj, "invisible-char-set");
6823 g_object_thaw_notify (obj);
6825 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6826 gtk_entry_recompute (entry);
6830 * gtk_entry_get_text_area:
6831 * @entry: a #GtkEntry
6832 * @text_area: (out): Return location for the text area.
6834 * Gets the area where the entry's text is drawn. This function is
6835 * useful when drawing something to the entry in a draw callback.
6837 * If the entry is not realized, @text_area is filled with zeros.
6839 * See also gtk_entry_get_icon_area().
6844 gtk_entry_get_text_area (GtkEntry *entry,
6845 GdkRectangle *text_area)
6847 GtkEntryPrivate *priv;
6849 g_return_if_fail (GTK_IS_ENTRY (entry));
6850 g_return_if_fail (text_area != NULL);
6854 if (priv->text_area)
6856 GtkAllocation allocation;
6859 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6860 gdk_window_get_position (priv->text_area, &x, &y);
6862 text_area->x = x - allocation.x;
6863 text_area->y = y - allocation.y;
6864 text_area->width = gdk_window_get_width (priv->text_area);
6865 text_area->height = gdk_window_get_height (priv->text_area);
6871 text_area->width = 0;
6872 text_area->height = 0;
6877 * gtk_entry_set_text:
6878 * @entry: a #GtkEntry
6879 * @text: the new text
6881 * Sets the text in the widget to the given
6882 * value, replacing the current contents.
6884 * See gtk_entry_buffer_set_text().
6887 gtk_entry_set_text (GtkEntry *entry,
6891 GtkEntryCompletion *completion;
6893 g_return_if_fail (GTK_IS_ENTRY (entry));
6894 g_return_if_fail (text != NULL);
6896 /* Actually setting the text will affect the cursor and selection;
6897 * if the contents don't actually change, this will look odd to the user.
6899 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6902 completion = gtk_entry_get_completion (entry);
6903 if (completion && completion->priv->changed_id > 0)
6904 g_signal_handler_block (entry, completion->priv->changed_id);
6906 begin_change (entry);
6907 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6909 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6912 if (completion && completion->priv->changed_id > 0)
6913 g_signal_handler_unblock (entry, completion->priv->changed_id);
6917 * gtk_entry_set_visibility:
6918 * @entry: a #GtkEntry
6919 * @visible: %TRUE if the contents of the entry are displayed
6922 * Sets whether the contents of the entry are visible or not.
6923 * When visibility is set to %FALSE, characters are displayed
6924 * as the invisible char, and will also appear that way when
6925 * the text in the entry widget is copied elsewhere.
6927 * By default, GTK+ picks the best invisible character available
6928 * in the current font, but it can be changed with
6929 * gtk_entry_set_invisible_char().
6931 * Note that you probably want to set #GtkEntry:input-purpose
6932 * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
6933 * inform input methods about the purpose of this entry,
6934 * in addition to setting visibility to %FALSE.
6937 gtk_entry_set_visibility (GtkEntry *entry,
6940 GtkEntryPrivate *priv;
6942 g_return_if_fail (GTK_IS_ENTRY (entry));
6946 visible = visible != FALSE;
6948 if (priv->visible != visible)
6950 priv->visible = visible;
6952 g_object_notify (G_OBJECT (entry), "visibility");
6953 gtk_entry_recompute (entry);
6958 * gtk_entry_get_visibility:
6959 * @entry: a #GtkEntry
6961 * Retrieves whether the text in @entry is visible. See
6962 * gtk_entry_set_visibility().
6964 * Return value: %TRUE if the text is currently visible
6967 gtk_entry_get_visibility (GtkEntry *entry)
6969 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6971 return entry->priv->visible;
6975 * gtk_entry_set_invisible_char:
6976 * @entry: a #GtkEntry
6977 * @ch: a Unicode character
6979 * Sets the character to use in place of the actual text when
6980 * gtk_entry_set_visibility() has been called to set text visibility
6981 * to %FALSE. i.e. this is the character used in "password mode" to
6982 * show the user how many characters have been typed. By default, GTK+
6983 * picks the best invisible char available in the current font. If you
6984 * set the invisible char to 0, then the user will get no feedback
6985 * at all; there will be no text on the screen as they type.
6988 gtk_entry_set_invisible_char (GtkEntry *entry,
6991 GtkEntryPrivate *priv;
6993 g_return_if_fail (GTK_IS_ENTRY (entry));
6997 if (!priv->invisible_char_set)
6999 priv->invisible_char_set = TRUE;
7000 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7003 if (ch == priv->invisible_char)
7006 priv->invisible_char = ch;
7007 g_object_notify (G_OBJECT (entry), "invisible-char");
7008 gtk_entry_recompute (entry);
7012 * gtk_entry_get_invisible_char:
7013 * @entry: a #GtkEntry
7015 * Retrieves the character displayed in place of the real characters
7016 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7018 * Return value: the current invisible char, or 0, if the entry does not
7019 * show invisible text at all.
7022 gtk_entry_get_invisible_char (GtkEntry *entry)
7024 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7026 return entry->priv->invisible_char;
7030 * gtk_entry_unset_invisible_char:
7031 * @entry: a #GtkEntry
7033 * Unsets the invisible char previously set with
7034 * gtk_entry_set_invisible_char(). So that the
7035 * default invisible char is used again.
7040 gtk_entry_unset_invisible_char (GtkEntry *entry)
7042 GtkEntryPrivate *priv;
7045 g_return_if_fail (GTK_IS_ENTRY (entry));
7049 if (!priv->invisible_char_set)
7052 priv->invisible_char_set = FALSE;
7053 ch = find_invisible_char (GTK_WIDGET (entry));
7055 if (priv->invisible_char != ch)
7057 priv->invisible_char = ch;
7058 g_object_notify (G_OBJECT (entry), "invisible-char");
7061 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7062 gtk_entry_recompute (entry);
7066 * gtk_entry_set_overwrite_mode:
7067 * @entry: a #GtkEntry
7068 * @overwrite: new value
7070 * Sets whether the text is overwritten when typing in the #GtkEntry.
7075 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7078 GtkEntryPrivate *priv = entry->priv;
7080 g_return_if_fail (GTK_IS_ENTRY (entry));
7082 if (priv->overwrite_mode == overwrite)
7085 gtk_entry_toggle_overwrite (entry);
7087 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7091 * gtk_entry_get_overwrite_mode:
7092 * @entry: a #GtkEntry
7094 * Gets the value set by gtk_entry_set_overwrite_mode().
7096 * Return value: whether the text is overwritten when typing.
7101 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7103 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7105 return entry->priv->overwrite_mode;
7109 * gtk_entry_get_text:
7110 * @entry: a #GtkEntry
7112 * Retrieves the contents of the entry widget.
7113 * See also gtk_editable_get_chars().
7115 * This is equivalent to:
7117 * <informalexample><programlisting>
7118 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7119 * </programlisting></informalexample>
7121 * Return value: a pointer to the contents of the widget as a
7122 * string. This string points to internally allocated
7123 * storage in the widget and must not be freed, modified or
7127 gtk_entry_get_text (GtkEntry *entry)
7129 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7131 return gtk_entry_buffer_get_text (get_buffer (entry));
7135 * gtk_entry_set_max_length:
7136 * @entry: a #GtkEntry
7137 * @max: the maximum length of the entry, or 0 for no maximum.
7138 * (other than the maximum length of entries.) The value passed in will
7139 * be clamped to the range 0-65536.
7141 * Sets the maximum allowed length of the contents of the widget. If
7142 * the current contents are longer than the given length, then they
7143 * will be truncated to fit.
7145 * This is equivalent to:
7147 * <informalexample><programlisting>
7148 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7149 * </programlisting></informalexample>
7152 gtk_entry_set_max_length (GtkEntry *entry,
7155 g_return_if_fail (GTK_IS_ENTRY (entry));
7156 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7160 * gtk_entry_get_max_length:
7161 * @entry: a #GtkEntry
7163 * Retrieves the maximum allowed length of the text in
7164 * @entry. See gtk_entry_set_max_length().
7166 * This is equivalent to:
7168 * <informalexample><programlisting>
7169 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7170 * </programlisting></informalexample>
7172 * Return value: the maximum allowed number of characters
7173 * in #GtkEntry, or 0 if there is no maximum.
7176 gtk_entry_get_max_length (GtkEntry *entry)
7178 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7180 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7184 * gtk_entry_get_text_length:
7185 * @entry: a #GtkEntry
7187 * Retrieves the current length of the text in
7190 * This is equivalent to:
7192 * <informalexample><programlisting>
7193 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7194 * </programlisting></informalexample>
7196 * Return value: the current number of characters
7197 * in #GtkEntry, or 0 if there are none.
7202 gtk_entry_get_text_length (GtkEntry *entry)
7204 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7206 return gtk_entry_buffer_get_length (get_buffer (entry));
7210 * gtk_entry_set_activates_default:
7211 * @entry: a #GtkEntry
7212 * @setting: %TRUE to activate window's default widget on Enter keypress
7214 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7215 * widget for the window containing the entry. This usually means that
7216 * the dialog box containing the entry will be closed, since the default
7217 * widget is usually one of the dialog buttons.
7219 * (For experts: if @setting is %TRUE, the entry calls
7220 * gtk_window_activate_default() on the window containing the entry, in
7221 * the default handler for the #GtkEntry::activate signal.)
7224 gtk_entry_set_activates_default (GtkEntry *entry,
7227 GtkEntryPrivate *priv;
7229 g_return_if_fail (GTK_IS_ENTRY (entry));
7233 setting = setting != FALSE;
7235 if (setting != priv->activates_default)
7237 priv->activates_default = setting;
7238 g_object_notify (G_OBJECT (entry), "activates-default");
7243 * gtk_entry_get_activates_default:
7244 * @entry: a #GtkEntry
7246 * Retrieves the value set by gtk_entry_set_activates_default().
7248 * Return value: %TRUE if the entry will activate the default widget
7251 gtk_entry_get_activates_default (GtkEntry *entry)
7253 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7255 return entry->priv->activates_default;
7259 * gtk_entry_set_width_chars:
7260 * @entry: a #GtkEntry
7261 * @n_chars: width in chars
7263 * Changes the size request of the entry to be about the right size
7264 * for @n_chars characters. Note that it changes the size
7265 * <emphasis>request</emphasis>, the size can still be affected by
7266 * how you pack the widget into containers. If @n_chars is -1, the
7267 * size reverts to the default entry size.
7270 gtk_entry_set_width_chars (GtkEntry *entry,
7273 GtkEntryPrivate *priv;
7275 g_return_if_fail (GTK_IS_ENTRY (entry));
7279 if (priv->width_chars != n_chars)
7281 priv->width_chars = n_chars;
7282 g_object_notify (G_OBJECT (entry), "width-chars");
7283 gtk_widget_queue_resize (GTK_WIDGET (entry));
7288 * gtk_entry_get_width_chars:
7289 * @entry: a #GtkEntry
7291 * Gets the value set by gtk_entry_set_width_chars().
7293 * Return value: number of chars to request space for, or negative if unset
7296 gtk_entry_get_width_chars (GtkEntry *entry)
7298 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7300 return entry->priv->width_chars;
7304 * gtk_entry_set_has_frame:
7305 * @entry: a #GtkEntry
7306 * @setting: new value
7308 * Sets whether the entry has a beveled frame around it.
7311 gtk_entry_set_has_frame (GtkEntry *entry,
7314 GtkEntryPrivate *priv;
7316 g_return_if_fail (GTK_IS_ENTRY (entry));
7320 setting = (setting != FALSE);
7322 if (priv->has_frame == setting)
7325 gtk_widget_queue_resize (GTK_WIDGET (entry));
7326 priv->has_frame = setting;
7327 g_object_notify (G_OBJECT (entry), "has-frame");
7331 * gtk_entry_get_has_frame:
7332 * @entry: a #GtkEntry
7334 * Gets the value set by gtk_entry_set_has_frame().
7336 * Return value: whether the entry has a beveled frame
7339 gtk_entry_get_has_frame (GtkEntry *entry)
7341 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7343 return entry->priv->has_frame;
7347 * gtk_entry_set_inner_border:
7348 * @entry: a #GtkEntry
7349 * @border: (allow-none): a #GtkBorder, or %NULL
7351 * Sets %entry's inner-border property to %border, or clears it if %NULL
7352 * is passed. The inner-border is the area around the entry's text, but
7355 * If set, this property overrides the inner-border style property.
7356 * Overriding the style-provided border is useful when you want to do
7357 * in-place editing of some text in a canvas or list widget, where
7358 * pixel-exact positioning of the entry is important.
7362 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7363 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7364 * this function is ignored by #GtkEntry.
7367 gtk_entry_set_inner_border (GtkEntry *entry,
7368 const GtkBorder *border)
7370 g_return_if_fail (GTK_IS_ENTRY (entry));
7372 gtk_entry_do_set_inner_border (entry, border);
7376 * gtk_entry_get_inner_border:
7377 * @entry: a #GtkEntry
7379 * This function returns the entry's #GtkEntry:inner-border property. See
7380 * gtk_entry_set_inner_border() for more information.
7382 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7386 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7387 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7388 * this function is ignored by #GtkEntry.
7391 gtk_entry_get_inner_border (GtkEntry *entry)
7393 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7395 return gtk_entry_do_get_inner_border (entry);
7399 * gtk_entry_get_layout:
7400 * @entry: a #GtkEntry
7402 * Gets the #PangoLayout used to display the entry.
7403 * The layout is useful to e.g. convert text positions to
7404 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7405 * The returned layout is owned by the entry and must not be
7406 * modified or freed by the caller.
7408 * Keep in mind that the layout text may contain a preedit string, so
7409 * gtk_entry_layout_index_to_text_index() and
7410 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7411 * indices in the layout to byte indices in the entry contents.
7413 * Return value: (transfer none): the #PangoLayout for this entry
7416 gtk_entry_get_layout (GtkEntry *entry)
7418 PangoLayout *layout;
7420 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7422 layout = gtk_entry_ensure_layout (entry, TRUE);
7429 * gtk_entry_layout_index_to_text_index:
7430 * @entry: a #GtkEntry
7431 * @layout_index: byte index into the entry layout text
7433 * Converts from a position in the entry contents (returned
7434 * by gtk_entry_get_text()) to a position in the
7435 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7436 * with text retrieved via pango_layout_get_text()).
7438 * Return value: byte index into the entry contents
7441 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7444 GtkEntryPrivate *priv;
7445 PangoLayout *layout;
7449 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7453 layout = gtk_entry_ensure_layout (entry, TRUE);
7454 text = pango_layout_get_text (layout);
7455 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7457 if (layout_index >= cursor_index && priv->preedit_length)
7459 if (layout_index >= cursor_index + priv->preedit_length)
7460 layout_index -= priv->preedit_length;
7462 layout_index = cursor_index;
7465 return layout_index;
7469 * gtk_entry_text_index_to_layout_index:
7470 * @entry: a #GtkEntry
7471 * @text_index: byte index into the entry contents
7473 * Converts from a position in the entry's #PangoLayout (returned by
7474 * gtk_entry_get_layout()) to a position in the entry contents
7475 * (returned by gtk_entry_get_text()).
7477 * Return value: byte index into the entry layout text
7480 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7483 GtkEntryPrivate *priv;
7484 PangoLayout *layout;
7488 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7492 layout = gtk_entry_ensure_layout (entry, TRUE);
7493 text = pango_layout_get_text (layout);
7494 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7496 if (text_index > cursor_index)
7497 text_index += priv->preedit_length;
7503 * gtk_entry_get_layout_offsets:
7504 * @entry: a #GtkEntry
7505 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7506 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7509 * Obtains the position of the #PangoLayout used to render text
7510 * in the entry, in widget coordinates. Useful if you want to line
7511 * up the text in an entry with some other text, e.g. when using the
7512 * entry to implement editable cells in a sheet widget.
7514 * Also useful to convert mouse events into coordinates inside the
7515 * #PangoLayout, e.g. to take some action if some part of the entry text
7518 * Note that as the user scrolls around in the entry the offsets will
7519 * change; you'll need to connect to the "notify::scroll-offset"
7520 * signal to track this. Remember when using the #PangoLayout
7521 * functions you need to convert to and from pixels using
7522 * PANGO_PIXELS() or #PANGO_SCALE.
7524 * Keep in mind that the layout text may contain a preedit string, so
7525 * gtk_entry_layout_index_to_text_index() and
7526 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7527 * indices in the layout to byte indices in the entry contents.
7530 gtk_entry_get_layout_offsets (GtkEntry *entry,
7534 gint text_area_x, text_area_y;
7536 g_return_if_fail (GTK_IS_ENTRY (entry));
7538 /* this gets coords relative to text area */
7539 get_layout_position (entry, x, y);
7541 /* convert to widget coords */
7542 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7553 * gtk_entry_set_alignment:
7554 * @entry: a #GtkEntry
7555 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7556 * Reversed for RTL layouts
7558 * Sets the alignment for the contents of the entry. This controls
7559 * the horizontal positioning of the contents when the displayed
7560 * text is shorter than the width of the entry.
7565 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7567 GtkEntryPrivate *priv;
7569 g_return_if_fail (GTK_IS_ENTRY (entry));
7575 else if (xalign > 1.0)
7578 if (xalign != priv->xalign)
7580 priv->xalign = xalign;
7582 gtk_entry_recompute (entry);
7584 g_object_notify (G_OBJECT (entry), "xalign");
7589 * gtk_entry_get_alignment:
7590 * @entry: a #GtkEntry
7592 * Gets the value set by gtk_entry_set_alignment().
7594 * Return value: the alignment
7599 gtk_entry_get_alignment (GtkEntry *entry)
7601 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7603 return entry->priv->xalign;
7607 * gtk_entry_set_icon_from_pixbuf:
7608 * @entry: a #GtkEntry
7609 * @icon_pos: Icon position
7610 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7612 * Sets the icon shown in the specified position using a pixbuf.
7614 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7619 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7620 GtkEntryIconPosition icon_pos,
7623 GtkEntryPrivate *priv;
7624 EntryIconInfo *icon_info;
7626 g_return_if_fail (GTK_IS_ENTRY (entry));
7627 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7631 if ((icon_info = priv->icons[icon_pos]) == NULL)
7632 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7634 g_object_freeze_notify (G_OBJECT (entry));
7637 g_object_ref (pixbuf);
7639 gtk_entry_clear (entry, icon_pos);
7643 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7644 _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
7645 GTK_ICON_SIZE_MENU);
7647 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7649 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7650 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7654 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7655 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7658 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7659 gdk_window_show_unraised (icon_info->window);
7661 g_object_unref (pixbuf);
7664 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7665 gtk_widget_queue_resize (GTK_WIDGET (entry));
7667 g_object_thaw_notify (G_OBJECT (entry));
7671 * gtk_entry_set_icon_from_stock:
7672 * @entry: A #GtkEntry
7673 * @icon_pos: Icon position
7674 * @stock_id: (allow-none): The name of the stock item, or %NULL
7676 * Sets the icon shown in the entry at the specified position from
7679 * If @stock_id is %NULL, no icon will be shown in the specified position.
7684 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7685 GtkEntryIconPosition icon_pos,
7686 const gchar *stock_id)
7688 GtkEntryPrivate *priv;
7689 EntryIconInfo *icon_info;
7692 g_return_if_fail (GTK_IS_ENTRY (entry));
7693 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7697 if ((icon_info = priv->icons[icon_pos]) == NULL)
7698 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7700 g_object_freeze_notify (G_OBJECT (entry));
7702 /* need to dup before clearing */
7703 new_id = g_strdup (stock_id);
7705 gtk_entry_clear (entry, icon_pos);
7709 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7711 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7713 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7714 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7718 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7719 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7722 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7723 gdk_window_show_unraised (icon_info->window);
7728 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7729 gtk_widget_queue_resize (GTK_WIDGET (entry));
7731 g_object_thaw_notify (G_OBJECT (entry));
7735 * gtk_entry_set_icon_from_icon_name:
7736 * @entry: A #GtkEntry
7737 * @icon_pos: The position at which to set the icon
7738 * @icon_name: (allow-none): An icon name, or %NULL
7740 * Sets the icon shown in the entry at the specified position
7741 * from the current icon theme.
7743 * If the icon name isn't known, a "broken image" icon will be displayed
7746 * If @icon_name is %NULL, no icon will be shown in the specified position.
7751 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7752 GtkEntryIconPosition icon_pos,
7753 const gchar *icon_name)
7755 GtkEntryPrivate *priv;
7756 EntryIconInfo *icon_info;
7759 g_return_if_fail (GTK_IS_ENTRY (entry));
7760 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7764 if ((icon_info = priv->icons[icon_pos]) == NULL)
7765 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7767 g_object_freeze_notify (G_OBJECT (entry));
7769 /* need to dup before clearing */
7770 new_name = g_strdup (icon_name);
7772 gtk_entry_clear (entry, icon_pos);
7774 if (new_name != NULL)
7776 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7778 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7780 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7781 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7785 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7786 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7789 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7790 gdk_window_show_unraised (icon_info->window);
7795 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7796 gtk_widget_queue_resize (GTK_WIDGET (entry));
7798 g_object_thaw_notify (G_OBJECT (entry));
7802 * gtk_entry_set_icon_from_gicon:
7803 * @entry: A #GtkEntry
7804 * @icon_pos: The position at which to set the icon
7805 * @icon: (allow-none): The icon to set, or %NULL
7807 * Sets the icon shown in the entry at the specified position
7808 * from the current icon theme.
7809 * If the icon isn't known, a "broken image" icon will be displayed
7812 * If @icon is %NULL, no icon will be shown in the specified position.
7817 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7818 GtkEntryIconPosition icon_pos,
7821 GtkEntryPrivate *priv;
7822 EntryIconInfo *icon_info;
7824 g_return_if_fail (GTK_IS_ENTRY (entry));
7825 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7829 if ((icon_info = priv->icons[icon_pos]) == NULL)
7830 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7832 g_object_freeze_notify (G_OBJECT (entry));
7834 /* need to ref before clearing */
7836 g_object_ref (icon);
7838 gtk_entry_clear (entry, icon_pos);
7842 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7844 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7846 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7847 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7851 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7852 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7855 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7856 gdk_window_show_unraised (icon_info->window);
7858 g_object_unref (icon);
7861 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7862 gtk_widget_queue_resize (GTK_WIDGET (entry));
7864 g_object_thaw_notify (G_OBJECT (entry));
7868 * gtk_entry_set_icon_activatable:
7869 * @entry: A #GtkEntry
7870 * @icon_pos: Icon position
7871 * @activatable: %TRUE if the icon should be activatable
7873 * Sets whether the icon is activatable.
7878 gtk_entry_set_icon_activatable (GtkEntry *entry,
7879 GtkEntryIconPosition icon_pos,
7880 gboolean activatable)
7882 GtkEntryPrivate *priv;
7883 EntryIconInfo *icon_info;
7885 g_return_if_fail (GTK_IS_ENTRY (entry));
7886 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7890 if ((icon_info = priv->icons[icon_pos]) == NULL)
7891 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7893 activatable = activatable != FALSE;
7895 if (icon_info->nonactivatable != !activatable)
7897 icon_info->nonactivatable = !activatable;
7899 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7900 update_cursors (GTK_WIDGET (entry));
7902 g_object_notify (G_OBJECT (entry),
7903 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7908 * gtk_entry_get_icon_activatable:
7909 * @entry: a #GtkEntry
7910 * @icon_pos: Icon position
7912 * Returns whether the icon is activatable.
7914 * Returns: %TRUE if the icon is activatable.
7919 gtk_entry_get_icon_activatable (GtkEntry *entry,
7920 GtkEntryIconPosition icon_pos)
7922 GtkEntryPrivate *priv;
7923 EntryIconInfo *icon_info;
7925 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7926 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7929 icon_info = priv->icons[icon_pos];
7931 return (!icon_info || !icon_info->nonactivatable);
7935 * gtk_entry_get_icon_pixbuf:
7936 * @entry: A #GtkEntry
7937 * @icon_pos: Icon position
7939 * Retrieves the image used for the icon.
7941 * Unlike the other methods of setting and getting icon data, this
7942 * method will work regardless of whether the icon was set using a
7943 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7945 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7946 * set for this position.
7951 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7952 GtkEntryIconPosition icon_pos)
7954 GtkEntryPrivate *priv;
7955 EntryIconInfo *icon_info;
7958 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7959 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7963 icon_info = priv->icons[icon_pos];
7968 /* HACK: unfortunately this is transfer none, so we need to return
7969 * the icon helper's cache ref directly.
7971 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7973 g_object_unref (pixbuf);
7979 * gtk_entry_get_icon_gicon:
7980 * @entry: A #GtkEntry
7981 * @icon_pos: Icon position
7983 * Retrieves the #GIcon used for the icon, or %NULL if there is
7984 * no icon or if the icon was set by some other method (e.g., by
7985 * stock, pixbuf, or icon name).
7987 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7988 * or if the icon is not a #GIcon
7993 gtk_entry_get_icon_gicon (GtkEntry *entry,
7994 GtkEntryIconPosition icon_pos)
7996 GtkEntryPrivate *priv;
7997 EntryIconInfo *icon_info;
7999 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8000 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8003 icon_info = priv->icons[icon_pos];
8008 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
8012 * gtk_entry_get_icon_stock:
8013 * @entry: A #GtkEntry
8014 * @icon_pos: Icon position
8016 * Retrieves the stock id used for the icon, or %NULL if there is
8017 * no icon or if the icon was set by some other method (e.g., by
8018 * pixbuf, icon name or gicon).
8020 * Returns: A stock id, or %NULL if no icon is set or if the icon
8021 * wasn't set from a stock id
8026 gtk_entry_get_icon_stock (GtkEntry *entry,
8027 GtkEntryIconPosition icon_pos)
8029 GtkEntryPrivate *priv;
8030 EntryIconInfo *icon_info;
8032 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8033 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8036 icon_info = priv->icons[icon_pos];
8041 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8045 * gtk_entry_get_icon_name:
8046 * @entry: A #GtkEntry
8047 * @icon_pos: Icon position
8049 * Retrieves the icon name used for the icon, or %NULL if there is
8050 * no icon or if the icon was set by some other method (e.g., by
8051 * pixbuf, stock or gicon).
8053 * Returns: An icon name, or %NULL if no icon is set or if the icon
8054 * wasn't set from an icon name
8059 gtk_entry_get_icon_name (GtkEntry *entry,
8060 GtkEntryIconPosition icon_pos)
8062 GtkEntryPrivate *priv;
8063 EntryIconInfo *icon_info;
8065 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8066 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8069 icon_info = priv->icons[icon_pos];
8074 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8078 * gtk_entry_set_icon_sensitive:
8079 * @entry: A #GtkEntry
8080 * @icon_pos: Icon position
8081 * @sensitive: Specifies whether the icon should appear
8082 * sensitive or insensitive
8084 * Sets the sensitivity for the specified icon.
8089 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8090 GtkEntryIconPosition icon_pos,
8093 GtkEntryPrivate *priv;
8094 EntryIconInfo *icon_info;
8096 g_return_if_fail (GTK_IS_ENTRY (entry));
8097 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8101 if ((icon_info = priv->icons[icon_pos]) == NULL)
8102 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8104 if (icon_info->insensitive != !sensitive)
8106 icon_info->insensitive = !sensitive;
8108 icon_info->pressed = FALSE;
8109 icon_info->prelight = FALSE;
8111 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8112 update_cursors (GTK_WIDGET (entry));
8114 gtk_widget_queue_draw (GTK_WIDGET (entry));
8116 g_object_notify (G_OBJECT (entry),
8117 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8122 * gtk_entry_get_icon_sensitive:
8123 * @entry: a #GtkEntry
8124 * @icon_pos: Icon position
8126 * Returns whether the icon appears sensitive or insensitive.
8128 * Returns: %TRUE if the icon is sensitive.
8133 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8134 GtkEntryIconPosition icon_pos)
8136 GtkEntryPrivate *priv;
8137 EntryIconInfo *icon_info;
8139 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8140 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8144 icon_info = priv->icons[icon_pos];
8146 return (!icon_info || !icon_info->insensitive);
8151 * gtk_entry_get_icon_storage_type:
8152 * @entry: a #GtkEntry
8153 * @icon_pos: Icon position
8155 * Gets the type of representation being used by the icon
8156 * to store image data. If the icon has no image data,
8157 * the return value will be %GTK_IMAGE_EMPTY.
8159 * Return value: image representation being used
8164 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8165 GtkEntryIconPosition icon_pos)
8167 GtkEntryPrivate *priv;
8168 EntryIconInfo *icon_info;
8170 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8171 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8175 icon_info = priv->icons[icon_pos];
8178 return GTK_IMAGE_EMPTY;
8180 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8184 * gtk_entry_get_icon_at_pos:
8185 * @entry: a #GtkEntry
8186 * @x: the x coordinate of the position to find
8187 * @y: the y coordinate of the position to find
8189 * Finds the icon at the given position and return its index. The
8190 * position's coordinates are relative to the @entry's top left corner.
8191 * If @x, @y doesn't lie inside an icon, -1 is returned.
8192 * This function is intended for use in a #GtkWidget::query-tooltip
8195 * Returns: the index of the icon at the given position, or -1
8200 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8204 GtkAllocation primary;
8205 GtkAllocation secondary;
8206 gint frame_x, frame_y;
8208 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8210 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8214 get_icon_allocations (entry, &primary, &secondary);
8216 if (primary.x <= x && x < primary.x + primary.width &&
8217 primary.y <= y && y < primary.y + primary.height)
8218 return GTK_ENTRY_ICON_PRIMARY;
8220 if (secondary.x <= x && x < secondary.x + secondary.width &&
8221 secondary.y <= y && y < secondary.y + secondary.height)
8222 return GTK_ENTRY_ICON_SECONDARY;
8228 * gtk_entry_set_icon_drag_source:
8229 * @entry: a #GtkEntry
8230 * @icon_pos: icon position
8231 * @target_list: the targets (data formats) in which the data can be provided
8232 * @actions: a bitmask of the allowed drag actions
8234 * Sets up the icon at the given position so that GTK+ will start a drag
8235 * operation when the user clicks and drags the icon.
8237 * To handle the drag operation, you need to connect to the usual
8238 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8239 * signal, and use gtk_entry_get_current_icon_drag_source() in
8240 * your signal handler to find out if the drag was started from
8243 * By default, GTK+ uses the icon as the drag icon. You can use the
8244 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8245 * have to use g_signal_connect_after() to ensure that your signal handler
8246 * gets executed after the default handler.
8251 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8252 GtkEntryIconPosition icon_pos,
8253 GtkTargetList *target_list,
8254 GdkDragAction actions)
8256 GtkEntryPrivate *priv;
8257 EntryIconInfo *icon_info;
8259 g_return_if_fail (GTK_IS_ENTRY (entry));
8260 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8264 if ((icon_info = priv->icons[icon_pos]) == NULL)
8265 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8267 if (icon_info->target_list)
8268 gtk_target_list_unref (icon_info->target_list);
8269 icon_info->target_list = target_list;
8270 if (icon_info->target_list)
8271 gtk_target_list_ref (icon_info->target_list);
8273 icon_info->actions = actions;
8277 * gtk_entry_get_current_icon_drag_source:
8278 * @entry: a #GtkIconEntry
8280 * Returns the index of the icon which is the source of the current
8281 * DND operation, or -1.
8283 * This function is meant to be used in a #GtkWidget::drag-data-get
8286 * Returns: index of the icon which is the source of the current
8287 * DND operation, or -1.
8292 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8294 GtkEntryPrivate *priv;
8295 EntryIconInfo *icon_info = NULL;
8298 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8302 for (i = 0; i < MAX_ICONS; i++)
8304 if ((icon_info = priv->icons[i]))
8306 if (icon_info->in_drag)
8315 * gtk_entry_get_icon_area:
8316 * @entry: A #GtkEntry
8317 * @icon_pos: Icon position
8318 * @icon_area: (out): Return location for the icon's area
8320 * Gets the area where entry's icon at @icon_pos is drawn.
8321 * This function is useful when drawing something to the
8322 * entry in a draw callback.
8324 * If the entry is not realized or has no icon at the given position,
8325 * @icon_area is filled with zeros.
8327 * See also gtk_entry_get_text_area()
8332 gtk_entry_get_icon_area (GtkEntry *entry,
8333 GtkEntryIconPosition icon_pos,
8334 GdkRectangle *icon_area)
8336 GtkEntryPrivate *priv;
8337 EntryIconInfo *icon_info;
8339 g_return_if_fail (GTK_IS_ENTRY (entry));
8340 g_return_if_fail (icon_area != NULL);
8344 icon_info = priv->icons[icon_pos];
8348 GtkAllocation primary;
8349 GtkAllocation secondary;
8351 get_icon_allocations (entry, &primary, &secondary);
8353 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8354 *icon_area = primary;
8356 *icon_area = secondary;
8362 icon_area->width = 0;
8363 icon_area->height = 0;
8368 ensure_has_tooltip (GtkEntry *entry)
8370 GtkEntryPrivate *priv;
8371 EntryIconInfo *icon_info;
8373 gboolean has_tooltip = FALSE;
8377 for (i = 0; i < MAX_ICONS; i++)
8379 if ((icon_info = priv->icons[i]) != NULL)
8381 if (icon_info->tooltip != NULL)
8389 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8393 * gtk_entry_get_icon_tooltip_text:
8394 * @entry: a #GtkEntry
8395 * @icon_pos: the icon position
8397 * Gets the contents of the tooltip on the icon at the specified
8398 * position in @entry.
8400 * Returns: the tooltip text, or %NULL. Free the returned string
8401 * with g_free() when done.
8406 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8407 GtkEntryIconPosition icon_pos)
8409 GtkEntryPrivate *priv;
8410 EntryIconInfo *icon_info;
8413 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8414 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8418 icon_info = priv->icons[icon_pos];
8423 if (icon_info->tooltip &&
8424 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8425 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8431 * gtk_entry_set_icon_tooltip_text:
8432 * @entry: a #GtkEntry
8433 * @icon_pos: the icon position
8434 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8436 * Sets @tooltip as the contents of the tooltip for the icon
8437 * at the specified position.
8439 * Use %NULL for @tooltip to remove an existing tooltip.
8441 * See also gtk_widget_set_tooltip_text() and
8442 * gtk_entry_set_icon_tooltip_markup().
8447 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8448 GtkEntryIconPosition icon_pos,
8449 const gchar *tooltip)
8451 GtkEntryPrivate *priv;
8452 EntryIconInfo *icon_info;
8454 g_return_if_fail (GTK_IS_ENTRY (entry));
8455 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8459 if ((icon_info = priv->icons[icon_pos]) == NULL)
8460 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8462 if (icon_info->tooltip)
8463 g_free (icon_info->tooltip);
8465 /* Treat an empty string as a NULL string,
8466 * because an empty string would be useless for a tooltip:
8468 if (tooltip && tooltip[0] == '\0')
8471 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8473 ensure_has_tooltip (entry);
8477 * gtk_entry_get_icon_tooltip_markup:
8478 * @entry: a #GtkEntry
8479 * @icon_pos: the icon position
8481 * Gets the contents of the tooltip on the icon at the specified
8482 * position in @entry.
8484 * Returns: the tooltip text, or %NULL. Free the returned string
8485 * with g_free() when done.
8490 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8491 GtkEntryIconPosition icon_pos)
8493 GtkEntryPrivate *priv;
8494 EntryIconInfo *icon_info;
8496 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8497 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8501 icon_info = priv->icons[icon_pos];
8506 return g_strdup (icon_info->tooltip);
8510 * gtk_entry_set_icon_tooltip_markup:
8511 * @entry: a #GtkEntry
8512 * @icon_pos: the icon position
8513 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8515 * Sets @tooltip as the contents of the tooltip for the icon at
8516 * the specified position. @tooltip is assumed to be marked up with
8517 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8519 * Use %NULL for @tooltip to remove an existing tooltip.
8521 * See also gtk_widget_set_tooltip_markup() and
8522 * gtk_entry_set_icon_tooltip_text().
8527 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8528 GtkEntryIconPosition icon_pos,
8529 const gchar *tooltip)
8531 GtkEntryPrivate *priv;
8532 EntryIconInfo *icon_info;
8534 g_return_if_fail (GTK_IS_ENTRY (entry));
8535 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8539 if ((icon_info = priv->icons[icon_pos]) == NULL)
8540 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8542 if (icon_info->tooltip)
8543 g_free (icon_info->tooltip);
8545 /* Treat an empty string as a NULL string,
8546 * because an empty string would be useless for a tooltip:
8548 if (tooltip && tooltip[0] == '\0')
8551 icon_info->tooltip = g_strdup (tooltip);
8553 ensure_has_tooltip (entry);
8557 gtk_entry_query_tooltip (GtkWidget *widget,
8560 gboolean keyboard_tip,
8561 GtkTooltip *tooltip)
8564 GtkEntryPrivate *priv;
8565 EntryIconInfo *icon_info;
8568 entry = GTK_ENTRY (widget);
8573 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8576 if ((icon_info = priv->icons[icon_pos]) != NULL)
8578 if (icon_info->tooltip)
8580 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8589 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8596 /* Quick hack of a popup menu
8599 activate_cb (GtkWidget *menuitem,
8602 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8603 g_signal_emit_by_name (entry, signal);
8608 gtk_entry_mnemonic_activate (GtkWidget *widget,
8609 gboolean group_cycling)
8611 gtk_widget_grab_focus (widget);
8616 gtk_entry_grab_notify (GtkWidget *widget,
8617 gboolean was_grabbed)
8619 GtkEntryPrivate *priv;
8621 priv = GTK_ENTRY (widget)->priv;
8624 gtk_widget_device_is_shadowed (widget, priv->device))
8626 /* Unset button so we don't expect
8627 * a button release anymore
8630 priv->device = NULL;
8631 priv->in_drag = FALSE;
8636 append_action_signal (GtkEntry *entry,
8638 const gchar *stock_id,
8639 const gchar *signal,
8642 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8644 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8645 g_signal_connect (menuitem, "activate",
8646 G_CALLBACK (activate_cb), entry);
8648 gtk_widget_set_sensitive (menuitem, sensitive);
8650 gtk_widget_show (menuitem);
8651 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8655 popup_menu_detach (GtkWidget *attach_widget,
8658 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8659 GtkEntryPrivate *priv_attach = entry_attach->priv;
8661 priv_attach->popup_menu = NULL;
8665 popup_position_func (GtkMenu *menu,
8671 GtkEntry *entry = GTK_ENTRY (user_data);
8672 GtkEntryPrivate *priv = entry->priv;
8673 GtkWidget *widget = GTK_WIDGET (entry);
8675 GtkRequisition menu_req;
8676 GdkRectangle monitor;
8678 gint monitor_num, strong_x, height;
8680 g_return_if_fail (gtk_widget_get_realized (widget));
8682 gdk_window_get_origin (priv->text_area, x, y);
8684 screen = gtk_widget_get_screen (widget);
8685 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8686 if (monitor_num < 0)
8688 gtk_menu_set_monitor (menu, monitor_num);
8690 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8691 gtk_widget_get_preferred_size (priv->popup_menu,
8693 height = gdk_window_get_height (priv->text_area);
8694 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8695 _gtk_entry_get_borders (entry, &borders);
8697 *x += borders.left + strong_x - priv->scroll_offset;
8698 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8699 *x -= menu_req.width;
8701 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8703 else if ((*y - menu_req.height) >= monitor.y)
8704 *y -= menu_req.height;
8705 else if (monitor.y + monitor.height - (*y + height) > *y)
8708 *y -= menu_req.height;
8714 unichar_chosen_func (const char *text,
8717 GtkEntry *entry = GTK_ENTRY (data);
8718 GtkEntryPrivate *priv = entry->priv;
8721 gtk_entry_enter_text (entry, text);
8733 popup_targets_received (GtkClipboard *clipboard,
8734 GtkSelectionData *data,
8737 PopupInfo *info = user_data;
8738 GtkEntry *entry = info->entry;
8739 GtkEntryPrivate *info_entry_priv = entry->priv;
8741 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8744 gboolean clipboard_contains_text;
8745 GtkWidget *menuitem;
8747 gboolean show_input_method_menu;
8748 gboolean show_unicode_menu;
8750 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8751 if (info_entry_priv->popup_menu)
8752 gtk_widget_destroy (info_entry_priv->popup_menu);
8754 info_entry_priv->popup_menu = gtk_menu_new ();
8756 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8760 mode = gtk_entry_get_display_mode (entry);
8761 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8762 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8763 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8765 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8766 mode == DISPLAY_NORMAL &&
8767 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8769 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8770 info_entry_priv->editable && clipboard_contains_text);
8772 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8773 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8774 g_signal_connect_swapped (menuitem, "activate",
8775 G_CALLBACK (gtk_entry_delete_cb), entry);
8776 gtk_widget_show (menuitem);
8777 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8779 menuitem = gtk_separator_menu_item_new ();
8780 gtk_widget_show (menuitem);
8781 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8783 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8784 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8785 g_signal_connect_swapped (menuitem, "activate",
8786 G_CALLBACK (gtk_entry_select_all), entry);
8787 gtk_widget_show (menuitem);
8788 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8790 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8791 "gtk-show-input-method-menu", &show_input_method_menu,
8792 "gtk-show-unicode-menu", &show_unicode_menu,
8795 if (show_input_method_menu || show_unicode_menu)
8797 menuitem = gtk_separator_menu_item_new ();
8798 gtk_widget_show (menuitem);
8799 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8802 if (show_input_method_menu)
8804 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8805 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8806 gtk_widget_show (menuitem);
8807 submenu = gtk_menu_new ();
8808 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8810 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8812 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8813 GTK_MENU_SHELL (submenu));
8816 if (show_unicode_menu)
8818 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8819 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8820 gtk_widget_show (menuitem);
8822 submenu = gtk_menu_new ();
8823 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8824 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8826 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8827 unichar_chosen_func,
8831 g_signal_emit (entry,
8832 signals[POPULATE_POPUP],
8834 info_entry_priv->popup_menu);
8838 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8839 info->device, NULL, NULL, NULL, NULL, NULL,
8840 info->button, info->time);
8843 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8844 popup_position_func, entry,
8845 0, gtk_get_current_event_time ());
8846 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8850 g_object_unref (entry);
8851 g_slice_free (PopupInfo, info);
8855 gtk_entry_do_popup (GtkEntry *entry,
8856 GdkEventButton *event)
8858 PopupInfo *info = g_slice_new (PopupInfo);
8860 /* In order to know what entries we should make sensitive, we
8861 * ask for the current targets of the clipboard, and when
8862 * we get them, then we actually pop up the menu.
8864 info->entry = g_object_ref (entry);
8868 info->button = event->button;
8869 info->time = event->time;
8870 info->device = event->device;
8875 info->time = gtk_get_current_event_time ();
8876 info->device = NULL;
8879 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8880 gdk_atom_intern_static_string ("TARGETS"),
8881 popup_targets_received,
8886 gtk_entry_popup_menu (GtkWidget *widget)
8888 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8893 gtk_entry_drag_begin (GtkWidget *widget,
8894 GdkDragContext *context)
8896 GtkEntry *entry = GTK_ENTRY (widget);
8897 GtkEntryPrivate *priv = entry->priv;
8900 for (i = 0; i < MAX_ICONS; i++)
8902 EntryIconInfo *icon_info = priv->icons[i];
8904 if (icon_info != NULL)
8906 if (icon_info->in_drag)
8910 pix = _gtk_icon_helper_ensure_pixbuf
8911 (icon_info->icon_helper,
8912 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8913 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8915 g_object_unref (pix);
8922 gtk_entry_drag_end (GtkWidget *widget,
8923 GdkDragContext *context)
8925 GtkEntry *entry = GTK_ENTRY (widget);
8926 GtkEntryPrivate *priv = entry->priv;
8929 for (i = 0; i < MAX_ICONS; i++)
8931 EntryIconInfo *icon_info = priv->icons[i];
8933 if (icon_info != NULL)
8934 icon_info->in_drag = 0;
8939 gtk_entry_drag_leave (GtkWidget *widget,
8940 GdkDragContext *context,
8943 GtkEntry *entry = GTK_ENTRY (widget);
8944 GtkEntryPrivate *priv = entry->priv;
8946 priv->dnd_position = -1;
8947 gtk_widget_queue_draw (widget);
8951 gtk_entry_drag_drop (GtkWidget *widget,
8952 GdkDragContext *context,
8957 GtkEntry *entry = GTK_ENTRY (widget);
8958 GtkEntryPrivate *priv = entry->priv;
8959 GdkAtom target = GDK_NONE;
8962 target = gtk_drag_dest_find_target (widget, context, NULL);
8964 if (target != GDK_NONE)
8965 gtk_drag_get_data (widget, context, target, time);
8967 gtk_drag_finish (context, FALSE, FALSE, time);
8973 gtk_entry_drag_motion (GtkWidget *widget,
8974 GdkDragContext *context,
8979 GtkEntry *entry = GTK_ENTRY (widget);
8980 GtkEntryPrivate *priv = entry->priv;
8981 GtkStyleContext *style_context;
8982 GtkWidget *source_widget;
8983 GdkDragAction suggested_action;
8984 gint new_position, old_position;
8988 style_context = gtk_widget_get_style_context (widget);
8989 gtk_style_context_get_padding (style_context, 0, &padding);
8993 old_position = priv->dnd_position;
8994 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8996 if (priv->editable &&
8997 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8999 source_widget = gtk_drag_get_source_widget (context);
9000 suggested_action = gdk_drag_context_get_suggested_action (context);
9002 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9003 new_position < sel1 || new_position > sel2)
9005 if (source_widget == widget)
9007 /* Default to MOVE, unless the user has
9008 * pressed ctrl or alt to affect available actions
9010 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9011 suggested_action = GDK_ACTION_MOVE;
9014 priv->dnd_position = new_position;
9018 if (source_widget == widget)
9019 suggested_action = 0; /* Can't drop in selection where drag started */
9021 priv->dnd_position = -1;
9026 /* Entry not editable, or no text */
9027 suggested_action = 0;
9028 priv->dnd_position = -1;
9031 gdk_drag_status (context, suggested_action, time);
9033 if (priv->dnd_position != old_position)
9034 gtk_widget_queue_draw (widget);
9040 gtk_entry_drag_data_received (GtkWidget *widget,
9041 GdkDragContext *context,
9044 GtkSelectionData *selection_data,
9048 GtkEntry *entry = GTK_ENTRY (widget);
9049 GtkEntryPrivate *priv = entry->priv;
9050 GtkEditable *editable = GTK_EDITABLE (widget);
9051 GtkStyleContext *style_context;
9055 str = (gchar *) gtk_selection_data_get_text (selection_data);
9057 style_context = gtk_widget_get_style_context (widget);
9058 gtk_style_context_get_padding (style_context, 0, &padding);
9062 if (str && priv->editable)
9068 if (priv->truncate_multiline)
9069 length = truncate_multiline (str);
9071 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9073 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9074 new_position < sel1 || new_position > sel2)
9076 gtk_editable_insert_text (editable, str, length, &new_position);
9080 /* Replacing selection */
9081 begin_change (entry);
9082 gtk_editable_delete_text (editable, sel1, sel2);
9083 gtk_editable_insert_text (editable, str, length, &sel1);
9087 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9091 /* Drag and drop didn't happen! */
9092 gtk_drag_finish (context, FALSE, FALSE, time);
9099 gtk_entry_drag_data_get (GtkWidget *widget,
9100 GdkDragContext *context,
9101 GtkSelectionData *selection_data,
9105 GtkEntry *entry = GTK_ENTRY (widget);
9106 GtkEntryPrivate *priv = entry->priv;
9107 GtkEditable *editable = GTK_EDITABLE (widget);
9108 gint sel_start, sel_end;
9111 /* If there is an icon drag going on, exit early. */
9112 for (i = 0; i < MAX_ICONS; i++)
9114 EntryIconInfo *icon_info = priv->icons[i];
9116 if (icon_info != NULL)
9118 if (icon_info->in_drag)
9123 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9125 gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9127 gtk_selection_data_set_text (selection_data, str, -1);
9135 gtk_entry_drag_data_delete (GtkWidget *widget,
9136 GdkDragContext *context)
9138 GtkEntry *entry = GTK_ENTRY (widget);
9139 GtkEntryPrivate *priv = entry->priv;
9140 GtkEditable *editable = GTK_EDITABLE (widget);
9141 gint sel_start, sel_end;
9144 /* If there is an icon drag going on, exit early. */
9145 for (i = 0; i < MAX_ICONS; i++)
9147 EntryIconInfo *icon_info = priv->icons[i];
9149 if (icon_info != NULL)
9151 if (icon_info->in_drag)
9156 if (priv->editable &&
9157 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9158 gtk_editable_delete_text (editable, sel_start, sel_end);
9161 /* We display the cursor when
9163 * - the selection is empty, AND
9164 * - the widget has focus
9167 #define CURSOR_ON_MULTIPLIER 2
9168 #define CURSOR_OFF_MULTIPLIER 1
9169 #define CURSOR_PEND_MULTIPLIER 3
9170 #define CURSOR_DIVIDER 3
9173 cursor_blinks (GtkEntry *entry)
9175 GtkEntryPrivate *priv = entry->priv;
9177 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9179 priv->selection_bound == priv->current_pos)
9181 GtkSettings *settings;
9184 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9185 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9194 get_middle_click_paste (GtkEntry *entry)
9196 GtkSettings *settings;
9199 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9200 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9206 get_cursor_time (GtkEntry *entry)
9208 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9211 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9217 get_cursor_blink_timeout (GtkEntry *entry)
9219 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9222 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9228 show_cursor (GtkEntry *entry)
9230 GtkEntryPrivate *priv = entry->priv;
9233 if (!priv->cursor_visible)
9235 priv->cursor_visible = TRUE;
9237 widget = GTK_WIDGET (entry);
9238 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9239 gtk_widget_queue_draw (widget);
9244 hide_cursor (GtkEntry *entry)
9246 GtkEntryPrivate *priv = entry->priv;
9249 if (priv->cursor_visible)
9251 priv->cursor_visible = FALSE;
9253 widget = GTK_WIDGET (entry);
9254 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9255 gtk_widget_queue_draw (widget);
9263 blink_cb (gpointer data)
9266 GtkEntryPrivate *priv;
9269 entry = GTK_ENTRY (data);
9272 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9274 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9275 "connect a handler to this signal, it must return\n"
9276 "FALSE so the entry gets the event as well");
9278 gtk_entry_check_cursor_blink (entry);
9283 g_assert (priv->selection_bound == priv->current_pos);
9285 blink_timeout = get_cursor_blink_timeout (entry);
9286 if (priv->blink_time > 1000 * blink_timeout &&
9287 blink_timeout < G_MAXINT/1000)
9289 /* we've blinked enough without the user doing anything, stop blinking */
9290 show_cursor (entry);
9291 priv->blink_timeout = 0;
9293 else if (priv->cursor_visible)
9295 hide_cursor (entry);
9296 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9302 show_cursor (entry);
9303 priv->blink_time += get_cursor_time (entry);
9304 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9309 /* Remove ourselves */
9314 gtk_entry_check_cursor_blink (GtkEntry *entry)
9316 GtkEntryPrivate *priv = entry->priv;
9318 if (cursor_blinks (entry))
9320 if (!priv->blink_timeout)
9322 show_cursor (entry);
9323 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9330 if (priv->blink_timeout)
9332 g_source_remove (priv->blink_timeout);
9333 priv->blink_timeout = 0;
9336 priv->cursor_visible = TRUE;
9341 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9343 GtkEntryPrivate *priv = entry->priv;
9345 if (cursor_blinks (entry))
9347 if (priv->blink_timeout != 0)
9348 g_source_remove (priv->blink_timeout);
9350 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9353 show_cursor (entry);
9358 gtk_entry_reset_blink_time (GtkEntry *entry)
9360 GtkEntryPrivate *priv = entry->priv;
9362 priv->blink_time = 0;
9366 * gtk_entry_set_completion:
9367 * @entry: A #GtkEntry
9368 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9370 * Sets @completion to be the auxiliary completion object to use with @entry.
9371 * All further configuration of the completion mechanism is done on
9372 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9373 * @completion is set to %NULL.
9378 gtk_entry_set_completion (GtkEntry *entry,
9379 GtkEntryCompletion *completion)
9381 GtkEntryCompletion *old;
9383 g_return_if_fail (GTK_IS_ENTRY (entry));
9384 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9386 old = gtk_entry_get_completion (entry);
9388 if (old == completion)
9393 _gtk_entry_completion_disconnect (old);
9394 g_object_unref (old);
9399 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9403 /* hook into the entry */
9404 g_object_ref (completion);
9406 _gtk_entry_completion_connect (completion, entry);
9408 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9410 g_object_notify (G_OBJECT (entry), "completion");
9414 * gtk_entry_get_completion:
9415 * @entry: A #GtkEntry
9417 * Returns the auxiliary completion object currently in use by @entry.
9419 * Return value: (transfer none): The auxiliary completion object currently
9424 GtkEntryCompletion *
9425 gtk_entry_get_completion (GtkEntry *entry)
9427 GtkEntryCompletion *completion;
9429 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9431 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9432 GTK_ENTRY_COMPLETION_KEY));
9438 * gtk_entry_set_cursor_hadjustment:
9439 * @entry: a #GtkEntry
9440 * @adjustment: an adjustment which should be adjusted when the cursor
9441 * is moved, or %NULL
9443 * Hooks up an adjustment to the cursor position in an entry, so that when
9444 * the cursor is moved, the adjustment is scrolled to show that position.
9445 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9448 * The adjustment has to be in pixel units and in the same coordinate system
9454 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9455 GtkAdjustment *adjustment)
9457 g_return_if_fail (GTK_IS_ENTRY (entry));
9459 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9462 g_object_ref (adjustment);
9464 g_object_set_qdata_full (G_OBJECT (entry),
9465 quark_cursor_hadjustment,
9471 * gtk_entry_get_cursor_hadjustment:
9472 * @entry: a #GtkEntry
9474 * Retrieves the horizontal cursor adjustment for the entry.
9475 * See gtk_entry_set_cursor_hadjustment().
9477 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9478 * if none has been set.
9483 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9485 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9487 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9491 * gtk_entry_set_progress_fraction:
9492 * @entry: a #GtkEntry
9493 * @fraction: fraction of the task that's been completed
9495 * Causes the entry's progress indicator to "fill in" the given
9496 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9502 gtk_entry_set_progress_fraction (GtkEntry *entry,
9506 GtkEntryPrivate *private;
9507 gdouble old_fraction;
9508 gint x, y, width, height;
9509 gint old_x, old_y, old_width, old_height;
9511 g_return_if_fail (GTK_IS_ENTRY (entry));
9513 widget = GTK_WIDGET (entry);
9514 private = entry->priv;
9516 if (private->progress_pulse_mode)
9519 old_fraction = private->progress_fraction;
9521 if (gtk_widget_is_drawable (widget))
9522 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9524 fraction = CLAMP (fraction, 0.0, 1.0);
9526 private->progress_fraction = fraction;
9527 private->progress_pulse_mode = FALSE;
9528 private->progress_pulse_current = 0.0;
9530 if (gtk_widget_is_drawable (widget))
9532 get_progress_area (widget, &x, &y, &width, &height);
9534 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9535 gtk_widget_queue_draw (widget);
9538 if (fraction != old_fraction)
9539 g_object_notify (G_OBJECT (entry), "progress-fraction");
9543 * gtk_entry_get_progress_fraction:
9544 * @entry: a #GtkEntry
9546 * Returns the current fraction of the task that's been completed.
9547 * See gtk_entry_set_progress_fraction().
9549 * Return value: a fraction from 0.0 to 1.0
9554 gtk_entry_get_progress_fraction (GtkEntry *entry)
9556 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9558 return entry->priv->progress_fraction;
9562 * gtk_entry_set_progress_pulse_step:
9563 * @entry: a #GtkEntry
9564 * @fraction: fraction between 0.0 and 1.0
9566 * Sets the fraction of total entry width to move the progress
9567 * bouncing block for each call to gtk_entry_progress_pulse().
9572 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9575 GtkEntryPrivate *private;
9577 g_return_if_fail (GTK_IS_ENTRY (entry));
9579 private = entry->priv;
9581 fraction = CLAMP (fraction, 0.0, 1.0);
9583 if (fraction != private->progress_pulse_fraction)
9585 private->progress_pulse_fraction = fraction;
9587 gtk_widget_queue_draw (GTK_WIDGET (entry));
9589 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9594 * gtk_entry_get_progress_pulse_step:
9595 * @entry: a #GtkEntry
9597 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9599 * Return value: a fraction from 0.0 to 1.0
9604 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9606 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9608 return entry->priv->progress_pulse_fraction;
9612 * gtk_entry_progress_pulse:
9613 * @entry: a #GtkEntry
9615 * Indicates that some progress is made, but you don't know how much.
9616 * Causes the entry's progress indicator to enter "activity mode,"
9617 * where a block bounces back and forth. Each call to
9618 * gtk_entry_progress_pulse() causes the block to move by a little bit
9619 * (the amount of movement per pulse is determined by
9620 * gtk_entry_set_progress_pulse_step()).
9625 gtk_entry_progress_pulse (GtkEntry *entry)
9627 GtkEntryPrivate *private;
9629 g_return_if_fail (GTK_IS_ENTRY (entry));
9631 private = entry->priv;
9633 if (private->progress_pulse_mode)
9635 if (private->progress_pulse_way_back)
9637 private->progress_pulse_current -= private->progress_pulse_fraction;
9639 if (private->progress_pulse_current < 0.0)
9641 private->progress_pulse_current = 0.0;
9642 private->progress_pulse_way_back = FALSE;
9647 private->progress_pulse_current += private->progress_pulse_fraction;
9649 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9651 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9652 private->progress_pulse_way_back = TRUE;
9658 private->progress_fraction = 0.0;
9659 private->progress_pulse_mode = TRUE;
9660 private->progress_pulse_way_back = FALSE;
9661 private->progress_pulse_current = 0.0;
9664 gtk_widget_queue_draw (GTK_WIDGET (entry));
9668 * gtk_entry_set_placeholder_text:
9669 * @entry: a #GtkEntry
9670 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
9672 * Sets text to be displayed in @entry when it is empty and unfocused.
9673 * This can be used to give a visual hint of the expected contents of
9676 * Note that since the placeholder text gets removed when the entry
9677 * received focus, using this feature is a bit problematic if the entry
9678 * is given the initial focus in a window. Sometimes this can be
9679 * worked around by delaying the initial focus setting until the
9680 * first key event arrives.
9685 gtk_entry_set_placeholder_text (GtkEntry *entry,
9688 GtkEntryPrivate *priv;
9690 g_return_if_fail (GTK_IS_ENTRY (entry));
9694 if (g_strcmp0 (priv->placeholder_text, text) == 0)
9697 g_free (priv->placeholder_text);
9698 priv->placeholder_text = g_strdup (text);
9700 gtk_entry_recompute (entry);
9702 g_object_notify (G_OBJECT (entry), "placeholder-text");
9706 * gtk_entry_get_placeholder_text:
9707 * @entry: a #GtkEntry
9709 * Retrieves the text that will be displayed when @entry is empty and unfocused
9711 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
9712 * storage in the widget and must not be freed, modified or stored.
9717 gtk_entry_get_placeholder_text (GtkEntry *entry)
9719 GtkEntryPrivate *priv;
9721 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9725 return priv->placeholder_text;
9728 /* Caps Lock warning for password entries */
9731 show_capslock_feedback (GtkEntry *entry,
9734 GtkEntryPrivate *priv = entry->priv;
9736 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9738 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9739 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9740 priv->caps_lock_warning_shown = TRUE;
9743 if (priv->caps_lock_warning_shown)
9744 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9746 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9750 remove_capslock_feedback (GtkEntry *entry)
9752 GtkEntryPrivate *priv = entry->priv;
9754 if (priv->caps_lock_warning_shown)
9756 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9757 priv->caps_lock_warning_shown = FALSE;
9762 keymap_state_changed (GdkKeymap *keymap,
9765 GtkEntryPrivate *priv = entry->priv;
9768 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
9770 if (gdk_keymap_get_caps_lock_state (keymap))
9771 text = _("Caps Lock is on");
9775 show_capslock_feedback (entry, text);
9777 remove_capslock_feedback (entry);
9781 * _gtk_entry_set_is_cell_renderer:
9782 * @entry: a #GtkEntry
9783 * @is_cell_renderer: new value
9785 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
9786 * is supposed to behave like a GtkCellEditable when placed in a combo box.
9788 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
9792 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
9793 gboolean is_cell_renderer)
9795 entry->priv->is_cell_renderer = is_cell_renderer;
9799 * gtk_entry_set_input_purpose:
9800 * @entry: a #GtkEntry
9801 * @purpose: the purpose
9803 * Sets the #GtkEntry:input-purpose property which
9804 * can be used by on-screen keyboards and other input
9805 * methods to adjust their behaviour.
9810 gtk_entry_set_input_purpose (GtkEntry *entry,
9811 GtkInputPurpose purpose)
9814 g_return_if_fail (GTK_IS_ENTRY (entry));
9816 if (gtk_entry_get_input_purpose (entry) != purpose)
9818 g_object_set (G_OBJECT (entry->priv->im_context),
9819 "input-purpose", purpose,
9822 g_object_notify (G_OBJECT (entry), "input-purpose");
9827 * gtk_entry_get_input_purpose:
9828 * @entry: a #GtkEntry
9830 * Gets the value of the #GtkEntry:input-purpose property.
9835 gtk_entry_get_input_purpose (GtkEntry *entry)
9837 GtkInputPurpose purpose;
9839 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
9841 g_object_get (G_OBJECT (entry->priv->im_context),
9842 "input-purpose", &purpose,
9849 * gtk_entry_set_input_hints:
9850 * @entry: a #GtkEntry
9853 * Sets the #GtkEntry:input-hints property, which
9854 * allows input methods to fine-tune their behaviour.
9859 gtk_entry_set_input_hints (GtkEntry *entry,
9860 GtkInputHints hints)
9863 g_return_if_fail (GTK_IS_ENTRY (entry));
9865 if (gtk_entry_get_input_hints (entry) != hints)
9867 g_object_set (G_OBJECT (entry->priv->im_context),
9868 "input-hints", hints,
9871 g_object_notify (G_OBJECT (entry), "input-hints");
9876 * gtk_entry_get_input_hints:
9877 * @entry: a #GtkEntry
9879 * Gets the value of the #GtkEntry:input-hints property.
9884 gtk_entry_get_input_hints (GtkEntry *entry)
9886 GtkInputHints hints;
9888 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
9890 g_object_get (G_OBJECT (entry->priv->im_context),
9891 "input-hints", &hints,