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, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gtkbindings.h"
37 #include "gtkcelleditable.h"
38 #include "gtkclipboard.h"
41 #include "gtkentrybuffer.h"
42 #include "gtkimagemenuitem.h"
43 #include "gtkimcontextsimple.h"
44 #include "gtkimmulticontext.h"
48 #include "gtkmarshalers.h"
50 #include "gtkmenuitem.h"
51 #include "gtkseparatormenuitem.h"
52 #include "gtkselection.h"
53 #include "gtksettings.h"
54 #include "gtkspinbutton.h"
56 #include "gtktextutil.h"
57 #include "gtkwindow.h"
58 #include "gtktreeview.h"
59 #include "gtktreeselection.h"
60 #include "gtktypebuiltins.h"
61 #include "gtkprivate.h"
62 #include "gtkentryprivate.h"
63 #include "gtkcelllayout.h"
64 #include "gtktooltip.h"
65 #include "gtkiconfactory.h"
66 #include "gtkicontheme.h"
67 #include "gtkwidgetprivate.h"
68 #include "gtkstylecontextprivate.h"
70 #include "a11y/gtkentryaccessible.h"
74 * @Short_description: A single line text entry field
76 * @See_also: #GtkTextView, #GtkEntryCompletion
78 * The #GtkEntry widget is a single line text entry
79 * widget. A fairly large set of key bindings are supported
80 * by default. If the entered text is longer than the allocation
81 * of the widget, the widget will scroll so that the cursor
82 * position is visible.
84 * When using an entry for passwords and other sensitive information,
85 * it can be put into "password mode" using gtk_entry_set_visibility().
86 * In this mode, entered text is displayed using a 'invisible' character.
87 * By default, GTK+ picks the best invisible character that is available
88 * in the current font, but it can be changed with
89 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
90 * when Caps Lock or input methods might interfere with entering text in
91 * a password entry. The warning can be turned off with the
92 * #GtkEntry:caps-lock-warning property.
94 * Since 2.16, GtkEntry has the ability to display progress or activity
95 * information behind the text. To make an entry display such information,
96 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
98 * Additionally, GtkEntry can show icons at either side of the entry. These
99 * icons can be activatable by clicking, can be set up as drag source and
100 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
101 * one of the various other functions that set an icon from a stock id, an
102 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
103 * connect to the #GtkEntry::icon-press signal. To allow DND operations
104 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
105 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
108 * Note that functionality or information that is only available by clicking
109 * on an icon in an entry may not be accessible at all to users which are not
110 * able to use a mouse or other pointing device. It is therefore recommended
111 * that any such functionality should also be available by other means, e.g.
112 * via the context menu of the entry.
116 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
118 #define MIN_ENTRY_WIDTH 150
119 #define DRAW_TIMEOUT 20
120 #define COMPLETION_TIMEOUT 300
121 #define PASSWORD_HINT_MAX 8
126 #define IS_VALID_ICON_POSITION(pos) \
127 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
128 (pos) == GTK_ENTRY_ICON_SECONDARY)
130 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
131 static GQuark quark_inner_border = 0;
132 static GQuark quark_password_hint = 0;
133 static GQuark quark_cursor_hadjustment = 0;
134 static GQuark quark_capslock_feedback = 0;
136 typedef struct _EntryIconInfo EntryIconInfo;
137 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
138 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
140 struct _GtkEntryPrivate
142 EntryIconInfo *icons[MAX_ICONS];
144 GtkEntryBuffer *buffer;
145 GtkIMContext *im_context;
146 GtkShadowType shadow_type;
147 GtkWidget *popup_menu;
149 GdkDevice *completion_device;
150 GdkWindow *text_area;
152 PangoLayout *cached_layout;
156 gdouble progress_fraction;
157 gdouble progress_pulse_fraction;
158 gdouble progress_pulse_current;
160 gchar *placeholder_text;
164 gint ascent; /* font ascent in pango units */
166 gint descent; /* font descent in pango units */
167 gint dnd_position; /* In chars, -1 == no DND cursor */
173 gint selection_bound;
179 gunichar invisible_char;
182 guint blink_time; /* time in msec the cursor has blinked since last user event */
184 guint recompute_idle;
186 guint16 x_text_size; /* allocated size, in bytes */
187 guint16 x_n_bytes; /* length in use, in bytes */
189 guint16 preedit_length; /* length of preedit string, in bytes */
190 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
194 guint overwrite_mode : 1;
197 guint activates_default : 1;
198 guint cache_includes_preedit : 1;
199 guint caps_lock_warning : 1;
200 guint caps_lock_warning_shown : 1;
201 guint change_count : 8;
202 guint cursor_visible : 1;
203 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
205 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
206 guint is_cell_renderer : 1;
207 guint invisible_char_set : 1;
208 guint interior_focus : 1;
209 guint mouse_cursor_obscured : 1;
210 guint need_im_reset : 1;
211 guint progress_pulse_mode : 1;
212 guint progress_pulse_way_back : 1;
213 guint real_changed : 1;
214 guint resolved_dir : 4; /* PangoDirection */
215 guint select_words : 1;
216 guint select_lines : 1;
217 guint truncate_multiline : 1;
220 struct _EntryIconInfo
224 guint insensitive : 1;
225 guint nonactivatable : 1;
230 GtkImageType storage_type;
236 GtkStateFlags last_state;
238 GtkTargetList *target_list;
239 GdkDragAction actions;
242 struct _GtkEntryPasswordHint
244 gint position; /* Position (in text) of the last password hint */
245 guint source_id; /* Timeout source id */
248 struct _GtkEntryCapslockFeedback
275 PROP_CURSOR_POSITION,
276 PROP_SELECTION_BOUND,
283 PROP_ACTIVATES_DEFAULT,
288 PROP_TRUNCATE_MULTILINE,
292 PROP_INVISIBLE_CHAR_SET,
293 PROP_CAPS_LOCK_WARNING,
294 PROP_PROGRESS_FRACTION,
295 PROP_PROGRESS_PULSE_STEP,
297 PROP_PIXBUF_SECONDARY,
299 PROP_STOCK_SECONDARY,
300 PROP_ICON_NAME_PRIMARY,
301 PROP_ICON_NAME_SECONDARY,
303 PROP_GICON_SECONDARY,
304 PROP_STORAGE_TYPE_PRIMARY,
305 PROP_STORAGE_TYPE_SECONDARY,
306 PROP_ACTIVATABLE_PRIMARY,
307 PROP_ACTIVATABLE_SECONDARY,
308 PROP_SENSITIVE_PRIMARY,
309 PROP_SENSITIVE_SECONDARY,
310 PROP_TOOLTIP_TEXT_PRIMARY,
311 PROP_TOOLTIP_TEXT_SECONDARY,
312 PROP_TOOLTIP_MARKUP_PRIMARY,
313 PROP_TOOLTIP_MARKUP_SECONDARY,
315 PROP_EDITING_CANCELED,
316 PROP_PLACEHOLDER_TEXT,
320 static guint signals[LAST_SIGNAL] = { 0 };
329 DISPLAY_NORMAL, /* The entry text is being shown */
330 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
331 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
336 static void gtk_entry_editable_init (GtkEditableInterface *iface);
337 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
338 static void gtk_entry_set_property (GObject *object,
342 static void gtk_entry_get_property (GObject *object,
346 static void gtk_entry_finalize (GObject *object);
347 static void gtk_entry_dispose (GObject *object);
351 static void gtk_entry_destroy (GtkWidget *widget);
352 static void gtk_entry_realize (GtkWidget *widget);
353 static void gtk_entry_unrealize (GtkWidget *widget);
354 static void gtk_entry_map (GtkWidget *widget);
355 static void gtk_entry_unmap (GtkWidget *widget);
356 static void gtk_entry_get_preferred_width (GtkWidget *widget,
359 static void gtk_entry_get_preferred_height (GtkWidget *widget,
362 static void gtk_entry_size_allocate (GtkWidget *widget,
363 GtkAllocation *allocation);
364 static void gtk_entry_draw_frame (GtkWidget *widget,
365 GtkStyleContext *context,
367 static void gtk_entry_draw_progress (GtkWidget *widget,
368 GtkStyleContext *context,
370 static gint gtk_entry_draw (GtkWidget *widget,
372 static gint gtk_entry_button_press (GtkWidget *widget,
373 GdkEventButton *event);
374 static gint gtk_entry_button_release (GtkWidget *widget,
375 GdkEventButton *event);
376 static gint gtk_entry_enter_notify (GtkWidget *widget,
377 GdkEventCrossing *event);
378 static gint gtk_entry_leave_notify (GtkWidget *widget,
379 GdkEventCrossing *event);
380 static gint gtk_entry_motion_notify (GtkWidget *widget,
381 GdkEventMotion *event);
382 static gint gtk_entry_key_press (GtkWidget *widget,
384 static gint gtk_entry_key_release (GtkWidget *widget,
386 static gint gtk_entry_focus_in (GtkWidget *widget,
387 GdkEventFocus *event);
388 static gint gtk_entry_focus_out (GtkWidget *widget,
389 GdkEventFocus *event);
390 static void gtk_entry_grab_focus (GtkWidget *widget);
391 static void gtk_entry_style_updated (GtkWidget *widget);
392 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
395 gboolean keyboard_tip,
396 GtkTooltip *tooltip);
397 static void gtk_entry_direction_changed (GtkWidget *widget,
398 GtkTextDirection previous_dir);
399 static void gtk_entry_state_flags_changed (GtkWidget *widget,
400 GtkStateFlags previous_state);
401 static void gtk_entry_screen_changed (GtkWidget *widget,
402 GdkScreen *old_screen);
404 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
405 GdkDragContext *context,
409 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
410 GdkDragContext *context,
414 static void gtk_entry_drag_leave (GtkWidget *widget,
415 GdkDragContext *context,
417 static void gtk_entry_drag_data_received (GtkWidget *widget,
418 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_entry_drag_data_get (GtkWidget *widget,
425 GdkDragContext *context,
426 GtkSelectionData *selection_data,
429 static void gtk_entry_drag_data_delete (GtkWidget *widget,
430 GdkDragContext *context);
431 static void gtk_entry_drag_begin (GtkWidget *widget,
432 GdkDragContext *context);
433 static void gtk_entry_drag_end (GtkWidget *widget,
434 GdkDragContext *context);
437 /* GtkEditable method implementations
439 static void gtk_entry_insert_text (GtkEditable *editable,
440 const gchar *new_text,
441 gint new_text_length,
443 static void gtk_entry_delete_text (GtkEditable *editable,
446 static gchar * gtk_entry_get_chars (GtkEditable *editable,
449 static void gtk_entry_real_set_position (GtkEditable *editable,
451 static gint gtk_entry_get_position (GtkEditable *editable);
452 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
455 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
459 /* GtkCellEditable method implementations
461 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
464 /* Default signal handlers
466 static void gtk_entry_real_insert_text (GtkEditable *editable,
467 const gchar *new_text,
468 gint new_text_length,
470 static void gtk_entry_real_delete_text (GtkEditable *editable,
473 static void gtk_entry_move_cursor (GtkEntry *entry,
474 GtkMovementStep step,
476 gboolean extend_selection);
477 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
479 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
482 static void gtk_entry_backspace (GtkEntry *entry);
483 static void gtk_entry_cut_clipboard (GtkEntry *entry);
484 static void gtk_entry_copy_clipboard (GtkEntry *entry);
485 static void gtk_entry_paste_clipboard (GtkEntry *entry);
486 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
487 static void gtk_entry_select_all (GtkEntry *entry);
488 static void gtk_entry_real_activate (GtkEntry *entry);
489 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
491 static void keymap_direction_changed (GdkKeymap *keymap,
493 static void keymap_state_changed (GdkKeymap *keymap,
495 static void remove_capslock_feedback (GtkEntry *entry);
497 /* IM Context Callbacks
499 static void gtk_entry_commit_cb (GtkIMContext *context,
502 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
504 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
506 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
513 static void gtk_entry_enter_text (GtkEntry *entry,
515 static void gtk_entry_set_positions (GtkEntry *entry,
517 gint selection_bound);
518 static void gtk_entry_draw_text (GtkEntry *entry,
520 static void gtk_entry_draw_cursor (GtkEntry *entry,
523 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
524 gboolean include_preedit);
525 static void gtk_entry_reset_layout (GtkEntry *entry);
526 static void gtk_entry_recompute (GtkEntry *entry);
527 static gint gtk_entry_find_position (GtkEntry *entry,
529 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
533 static void gtk_entry_adjust_scroll (GtkEntry *entry);
534 static gint gtk_entry_move_visually (GtkEntry *editable,
537 static gint gtk_entry_move_logically (GtkEntry *entry,
540 static gint gtk_entry_move_forward_word (GtkEntry *entry,
542 gboolean allow_whitespace);
543 static gint gtk_entry_move_backward_word (GtkEntry *entry,
545 gboolean allow_whitespace);
546 static void gtk_entry_delete_whitespace (GtkEntry *entry);
547 static void gtk_entry_select_word (GtkEntry *entry);
548 static void gtk_entry_select_line (GtkEntry *entry);
549 static void gtk_entry_paste (GtkEntry *entry,
551 static void gtk_entry_update_primary_selection (GtkEntry *entry);
552 static void gtk_entry_do_popup (GtkEntry *entry,
553 GdkEventButton *event);
554 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
555 gboolean group_cycling);
556 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
557 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
558 static void gtk_entry_reset_blink_time (GtkEntry *entry);
559 static void gtk_entry_get_text_area_size (GtkEntry *entry,
564 static void get_text_area_size (GtkEntry *entry,
569 static void get_frame_size (GtkEntry *entry,
570 gboolean relative_to_window,
575 static void gtk_entry_move_adjustments (GtkEntry *entry);
576 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
577 GtkEntryIconPosition icon_pos);
578 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
581 static gint gtk_entry_completion_timeout (gpointer data);
582 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
585 static void gtk_entry_completion_changed (GtkWidget *entry,
587 static gboolean check_completion_callback (GtkEntryCompletion *completion);
588 static void clear_completion_callback (GtkEntry *entry,
590 static gboolean accept_completion_callback (GtkEntry *entry);
591 static void completion_insert_text_callback (GtkEntry *entry,
595 GtkEntryCompletion *completion);
596 static void completion_changed (GtkEntryCompletion *completion,
599 static void disconnect_completion_signals (GtkEntry *entry,
600 GtkEntryCompletion *completion);
601 static void connect_completion_signals (GtkEntry *entry,
602 GtkEntryCompletion *completion);
604 static void begin_change (GtkEntry *entry);
605 static void end_change (GtkEntry *entry);
606 static void emit_changed (GtkEntry *entry);
608 static void buffer_inserted_text (GtkEntryBuffer *buffer,
613 static void buffer_deleted_text (GtkEntryBuffer *buffer,
617 static void buffer_notify_text (GtkEntryBuffer *buffer,
620 static void buffer_notify_length (GtkEntryBuffer *buffer,
623 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
626 static void buffer_connect_signals (GtkEntry *entry);
627 static void buffer_disconnect_signals (GtkEntry *entry);
628 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
630 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
631 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
632 gtk_entry_editable_init)
633 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
634 gtk_entry_cell_editable_init))
637 add_move_binding (GtkBindingSet *binding_set,
640 GtkMovementStep step,
643 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
645 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
649 G_TYPE_BOOLEAN, FALSE);
651 /* Selection-extending version */
652 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
656 G_TYPE_BOOLEAN, TRUE);
660 gtk_entry_class_init (GtkEntryClass *class)
662 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
663 GtkWidgetClass *widget_class;
664 GtkBindingSet *binding_set;
666 widget_class = (GtkWidgetClass*) class;
668 gobject_class->dispose = gtk_entry_dispose;
669 gobject_class->finalize = gtk_entry_finalize;
670 gobject_class->set_property = gtk_entry_set_property;
671 gobject_class->get_property = gtk_entry_get_property;
673 widget_class->destroy = gtk_entry_destroy;
674 widget_class->map = gtk_entry_map;
675 widget_class->unmap = gtk_entry_unmap;
676 widget_class->realize = gtk_entry_realize;
677 widget_class->unrealize = gtk_entry_unrealize;
678 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
679 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
680 widget_class->size_allocate = gtk_entry_size_allocate;
681 widget_class->draw = gtk_entry_draw;
682 widget_class->enter_notify_event = gtk_entry_enter_notify;
683 widget_class->leave_notify_event = gtk_entry_leave_notify;
684 widget_class->button_press_event = gtk_entry_button_press;
685 widget_class->button_release_event = gtk_entry_button_release;
686 widget_class->motion_notify_event = gtk_entry_motion_notify;
687 widget_class->key_press_event = gtk_entry_key_press;
688 widget_class->key_release_event = gtk_entry_key_release;
689 widget_class->focus_in_event = gtk_entry_focus_in;
690 widget_class->focus_out_event = gtk_entry_focus_out;
691 widget_class->grab_focus = gtk_entry_grab_focus;
692 widget_class->style_updated = gtk_entry_style_updated;
693 widget_class->query_tooltip = gtk_entry_query_tooltip;
694 widget_class->drag_begin = gtk_entry_drag_begin;
695 widget_class->drag_end = gtk_entry_drag_end;
696 widget_class->direction_changed = gtk_entry_direction_changed;
697 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
698 widget_class->screen_changed = gtk_entry_screen_changed;
699 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
701 widget_class->drag_drop = gtk_entry_drag_drop;
702 widget_class->drag_motion = gtk_entry_drag_motion;
703 widget_class->drag_leave = gtk_entry_drag_leave;
704 widget_class->drag_data_received = gtk_entry_drag_data_received;
705 widget_class->drag_data_get = gtk_entry_drag_data_get;
706 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
708 widget_class->popup_menu = gtk_entry_popup_menu;
710 class->move_cursor = gtk_entry_move_cursor;
711 class->insert_at_cursor = gtk_entry_insert_at_cursor;
712 class->delete_from_cursor = gtk_entry_delete_from_cursor;
713 class->backspace = gtk_entry_backspace;
714 class->cut_clipboard = gtk_entry_cut_clipboard;
715 class->copy_clipboard = gtk_entry_copy_clipboard;
716 class->paste_clipboard = gtk_entry_paste_clipboard;
717 class->toggle_overwrite = gtk_entry_toggle_overwrite;
718 class->activate = gtk_entry_real_activate;
719 class->get_text_area_size = gtk_entry_get_text_area_size;
721 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
722 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
723 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
724 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
726 g_object_class_override_property (gobject_class,
727 PROP_EDITING_CANCELED,
730 g_object_class_install_property (gobject_class,
732 g_param_spec_object ("buffer",
734 P_("Text buffer object which actually stores entry text"),
735 GTK_TYPE_ENTRY_BUFFER,
736 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
738 g_object_class_install_property (gobject_class,
739 PROP_CURSOR_POSITION,
740 g_param_spec_int ("cursor-position",
741 P_("Cursor Position"),
742 P_("The current position of the insertion cursor in chars"),
744 GTK_ENTRY_BUFFER_MAX_SIZE,
746 GTK_PARAM_READABLE));
748 g_object_class_install_property (gobject_class,
749 PROP_SELECTION_BOUND,
750 g_param_spec_int ("selection-bound",
751 P_("Selection Bound"),
752 P_("The position of the opposite end of the selection from the cursor in chars"),
754 GTK_ENTRY_BUFFER_MAX_SIZE,
756 GTK_PARAM_READABLE));
758 g_object_class_install_property (gobject_class,
760 g_param_spec_boolean ("editable",
762 P_("Whether the entry contents can be edited"),
764 GTK_PARAM_READWRITE));
766 g_object_class_install_property (gobject_class,
768 g_param_spec_int ("max-length",
769 P_("Maximum length"),
770 P_("Maximum number of characters for this entry. Zero if no maximum"),
772 GTK_ENTRY_BUFFER_MAX_SIZE,
774 GTK_PARAM_READWRITE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_boolean ("visibility",
779 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
781 GTK_PARAM_READWRITE));
783 g_object_class_install_property (gobject_class,
785 g_param_spec_boolean ("has-frame",
787 P_("FALSE removes outside bevel from entry"),
789 GTK_PARAM_READWRITE));
791 g_object_class_install_property (gobject_class,
793 g_param_spec_boxed ("inner-border",
795 P_("Border between text and frame. Overrides the inner-border style property"),
797 GTK_PARAM_READWRITE));
799 g_object_class_install_property (gobject_class,
801 g_param_spec_unichar ("invisible-char",
802 P_("Invisible character"),
803 P_("The character to use when masking entry contents (in \"password mode\")"),
805 GTK_PARAM_READWRITE));
807 g_object_class_install_property (gobject_class,
808 PROP_ACTIVATES_DEFAULT,
809 g_param_spec_boolean ("activates-default",
810 P_("Activates default"),
811 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
813 GTK_PARAM_READWRITE));
814 g_object_class_install_property (gobject_class,
816 g_param_spec_int ("width-chars",
817 P_("Width in chars"),
818 P_("Number of characters to leave space for in the entry"),
822 GTK_PARAM_READWRITE));
824 g_object_class_install_property (gobject_class,
826 g_param_spec_int ("scroll-offset",
828 P_("Number of pixels of the entry scrolled off the screen to the left"),
832 GTK_PARAM_READABLE));
834 g_object_class_install_property (gobject_class,
836 g_param_spec_string ("text",
838 P_("The contents of the entry"),
840 GTK_PARAM_READWRITE));
845 * The horizontal alignment, from 0 (left) to 1 (right).
846 * Reversed for RTL layouts.
850 g_object_class_install_property (gobject_class,
852 g_param_spec_float ("xalign",
854 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
858 GTK_PARAM_READWRITE));
861 * GtkEntry:truncate-multiline:
863 * When %TRUE, pasted multi-line text is truncated to the first line.
867 g_object_class_install_property (gobject_class,
868 PROP_TRUNCATE_MULTILINE,
869 g_param_spec_boolean ("truncate-multiline",
870 P_("Truncate multiline"),
871 P_("Whether to truncate multiline pastes to one line."),
873 GTK_PARAM_READWRITE));
876 * GtkEntry:shadow-type:
878 * Which kind of shadow to draw around the entry when
879 * #GtkEntry:has-frame is set to %TRUE.
883 g_object_class_install_property (gobject_class,
885 g_param_spec_enum ("shadow-type",
887 P_("Which kind of shadow to draw around the entry when has-frame is set"),
888 GTK_TYPE_SHADOW_TYPE,
890 GTK_PARAM_READWRITE));
893 * GtkEntry:overwrite-mode:
895 * If text is overwritten when typing in the #GtkEntry.
899 g_object_class_install_property (gobject_class,
901 g_param_spec_boolean ("overwrite-mode",
902 P_("Overwrite mode"),
903 P_("Whether new text overwrites existing text"),
905 GTK_PARAM_READWRITE));
908 * GtkEntry:text-length:
910 * The length of the text in the #GtkEntry.
914 g_object_class_install_property (gobject_class,
916 g_param_spec_uint ("text-length",
918 P_("Length of the text currently in the entry"),
922 GTK_PARAM_READABLE));
924 * GtkEntry:invisible-char-set:
926 * Whether the invisible char has been set for the #GtkEntry.
930 g_object_class_install_property (gobject_class,
931 PROP_INVISIBLE_CHAR_SET,
932 g_param_spec_boolean ("invisible-char-set",
933 P_("Invisible character set"),
934 P_("Whether the invisible character has been set"),
936 GTK_PARAM_READWRITE));
939 * GtkEntry:caps-lock-warning
941 * Whether password entries will show a warning when Caps Lock is on.
943 * Note that the warning is shown using a secondary icon, and thus
944 * does not work if you are using the secondary icon position for some
949 g_object_class_install_property (gobject_class,
950 PROP_CAPS_LOCK_WARNING,
951 g_param_spec_boolean ("caps-lock-warning",
952 P_("Caps Lock warning"),
953 P_("Whether password entries will show a warning when Caps Lock is on"),
955 GTK_PARAM_READWRITE));
958 * GtkEntry:progress-fraction:
960 * The current fraction of the task that's been completed.
964 g_object_class_install_property (gobject_class,
965 PROP_PROGRESS_FRACTION,
966 g_param_spec_double ("progress-fraction",
967 P_("Progress Fraction"),
968 P_("The current fraction of the task that's been completed"),
972 GTK_PARAM_READWRITE));
975 * GtkEntry:progress-pulse-step:
977 * The fraction of total entry width to move the progress
978 * bouncing block for each call to gtk_entry_progress_pulse().
982 g_object_class_install_property (gobject_class,
983 PROP_PROGRESS_PULSE_STEP,
984 g_param_spec_double ("progress-pulse-step",
985 P_("Progress Pulse Step"),
986 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
990 GTK_PARAM_READWRITE));
993 * GtkEntry:placeholder-text:
995 * The text that will be displayed in the #GtkEntry when it is empty and unfocused.
999 g_object_class_install_property (gobject_class,
1000 PROP_PLACEHOLDER_TEXT,
1001 g_param_spec_string ("placeholder-text",
1002 P_("Placeholder text"),
1003 P_("Show text in the entry when it's empty and unfocused"),
1005 GTK_PARAM_READWRITE));
1008 * GtkEntry:primary-icon-pixbuf:
1010 * A pixbuf to use as the primary icon for the entry.
1014 g_object_class_install_property (gobject_class,
1015 PROP_PIXBUF_PRIMARY,
1016 g_param_spec_object ("primary-icon-pixbuf",
1017 P_("Primary pixbuf"),
1018 P_("Primary pixbuf for the entry"),
1020 GTK_PARAM_READWRITE));
1023 * GtkEntry:secondary-icon-pixbuf:
1025 * An pixbuf to use as the secondary icon for the entry.
1029 g_object_class_install_property (gobject_class,
1030 PROP_PIXBUF_SECONDARY,
1031 g_param_spec_object ("secondary-icon-pixbuf",
1032 P_("Secondary pixbuf"),
1033 P_("Secondary pixbuf for the entry"),
1035 GTK_PARAM_READWRITE));
1038 * GtkEntry:primary-icon-stock:
1040 * The stock id to use for the primary icon for the entry.
1044 g_object_class_install_property (gobject_class,
1046 g_param_spec_string ("primary-icon-stock",
1047 P_("Primary stock ID"),
1048 P_("Stock ID for primary icon"),
1050 GTK_PARAM_READWRITE));
1053 * GtkEntry:secondary-icon-stock:
1055 * The stock id to use for the secondary icon for the entry.
1059 g_object_class_install_property (gobject_class,
1060 PROP_STOCK_SECONDARY,
1061 g_param_spec_string ("secondary-icon-stock",
1062 P_("Secondary stock ID"),
1063 P_("Stock ID for secondary icon"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:primary-icon-name:
1070 * The icon name to use for the primary icon for the entry.
1074 g_object_class_install_property (gobject_class,
1075 PROP_ICON_NAME_PRIMARY,
1076 g_param_spec_string ("primary-icon-name",
1077 P_("Primary icon name"),
1078 P_("Icon name for primary icon"),
1080 GTK_PARAM_READWRITE));
1083 * GtkEntry:secondary-icon-name:
1085 * The icon name to use for the secondary icon for the entry.
1089 g_object_class_install_property (gobject_class,
1090 PROP_ICON_NAME_SECONDARY,
1091 g_param_spec_string ("secondary-icon-name",
1092 P_("Secondary icon name"),
1093 P_("Icon name for secondary icon"),
1095 GTK_PARAM_READWRITE));
1098 * GtkEntry:primary-icon-gicon:
1100 * The #GIcon to use for the primary icon for the entry.
1104 g_object_class_install_property (gobject_class,
1106 g_param_spec_object ("primary-icon-gicon",
1107 P_("Primary GIcon"),
1108 P_("GIcon for primary icon"),
1110 GTK_PARAM_READWRITE));
1113 * GtkEntry:secondary-icon-gicon:
1115 * The #GIcon to use for the secondary icon for the entry.
1119 g_object_class_install_property (gobject_class,
1120 PROP_GICON_SECONDARY,
1121 g_param_spec_object ("secondary-icon-gicon",
1122 P_("Secondary GIcon"),
1123 P_("GIcon for secondary icon"),
1125 GTK_PARAM_READWRITE));
1128 * GtkEntry:primary-icon-storage-type:
1130 * The representation which is used for the primary icon of the entry.
1134 g_object_class_install_property (gobject_class,
1135 PROP_STORAGE_TYPE_PRIMARY,
1136 g_param_spec_enum ("primary-icon-storage-type",
1137 P_("Primary storage type"),
1138 P_("The representation being used for primary icon"),
1139 GTK_TYPE_IMAGE_TYPE,
1141 GTK_PARAM_READABLE));
1144 * GtkEntry:secondary-icon-storage-type:
1146 * The representation which is used for the secondary icon of the entry.
1150 g_object_class_install_property (gobject_class,
1151 PROP_STORAGE_TYPE_SECONDARY,
1152 g_param_spec_enum ("secondary-icon-storage-type",
1153 P_("Secondary storage type"),
1154 P_("The representation being used for secondary icon"),
1155 GTK_TYPE_IMAGE_TYPE,
1157 GTK_PARAM_READABLE));
1160 * GtkEntry:primary-icon-activatable:
1162 * Whether the primary icon is activatable.
1164 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1165 * signals only on sensitive, activatable icons.
1167 * Sensitive, but non-activatable icons can be used for purely
1168 * informational purposes.
1172 g_object_class_install_property (gobject_class,
1173 PROP_ACTIVATABLE_PRIMARY,
1174 g_param_spec_boolean ("primary-icon-activatable",
1175 P_("Primary icon activatable"),
1176 P_("Whether the primary icon is activatable"),
1178 GTK_PARAM_READWRITE));
1181 * GtkEntry:secondary-icon-activatable:
1183 * Whether the secondary icon is activatable.
1185 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1186 * signals only on sensitive, activatable icons.
1188 * Sensitive, but non-activatable icons can be used for purely
1189 * informational purposes.
1193 g_object_class_install_property (gobject_class,
1194 PROP_ACTIVATABLE_SECONDARY,
1195 g_param_spec_boolean ("secondary-icon-activatable",
1196 P_("Secondary icon activatable"),
1197 P_("Whether the secondary icon is activatable"),
1199 GTK_PARAM_READWRITE));
1203 * GtkEntry:primary-icon-sensitive:
1205 * Whether the primary icon is sensitive.
1207 * An insensitive icon appears grayed out. GTK+ does not emit the
1208 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1209 * does not allow DND from insensitive icons.
1211 * An icon should be set insensitive if the action that would trigger
1212 * when clicked is currently not available.
1216 g_object_class_install_property (gobject_class,
1217 PROP_SENSITIVE_PRIMARY,
1218 g_param_spec_boolean ("primary-icon-sensitive",
1219 P_("Primary icon sensitive"),
1220 P_("Whether the primary icon is sensitive"),
1222 GTK_PARAM_READWRITE));
1225 * GtkEntry:secondary-icon-sensitive:
1227 * Whether the secondary icon is sensitive.
1229 * An insensitive icon appears grayed out. GTK+ does not emit the
1230 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1231 * does not allow DND from insensitive icons.
1233 * An icon should be set insensitive if the action that would trigger
1234 * when clicked is currently not available.
1238 g_object_class_install_property (gobject_class,
1239 PROP_SENSITIVE_SECONDARY,
1240 g_param_spec_boolean ("secondary-icon-sensitive",
1241 P_("Secondary icon sensitive"),
1242 P_("Whether the secondary icon is sensitive"),
1244 GTK_PARAM_READWRITE));
1247 * GtkEntry:primary-icon-tooltip-text:
1249 * The contents of the tooltip on the primary icon.
1251 * Also see gtk_entry_set_icon_tooltip_text().
1255 g_object_class_install_property (gobject_class,
1256 PROP_TOOLTIP_TEXT_PRIMARY,
1257 g_param_spec_string ("primary-icon-tooltip-text",
1258 P_("Primary icon tooltip text"),
1259 P_("The contents of the tooltip on the primary icon"),
1261 GTK_PARAM_READWRITE));
1264 * GtkEntry:secondary-icon-tooltip-text:
1266 * The contents of the tooltip on the secondary icon.
1268 * Also see gtk_entry_set_icon_tooltip_text().
1272 g_object_class_install_property (gobject_class,
1273 PROP_TOOLTIP_TEXT_SECONDARY,
1274 g_param_spec_string ("secondary-icon-tooltip-text",
1275 P_("Secondary icon tooltip text"),
1276 P_("The contents of the tooltip on the secondary icon"),
1278 GTK_PARAM_READWRITE));
1281 * GtkEntry:primary-icon-tooltip-markup:
1283 * The contents of the tooltip on the primary icon, which is marked up
1284 * with the <link linkend="PangoMarkupFormat">Pango text markup
1287 * Also see gtk_entry_set_icon_tooltip_markup().
1291 g_object_class_install_property (gobject_class,
1292 PROP_TOOLTIP_MARKUP_PRIMARY,
1293 g_param_spec_string ("primary-icon-tooltip-markup",
1294 P_("Primary icon tooltip markup"),
1295 P_("The contents of the tooltip on the primary icon"),
1297 GTK_PARAM_READWRITE));
1300 * GtkEntry:secondary-icon-tooltip-markup:
1302 * The contents of the tooltip on the secondary icon, which is marked up
1303 * with the <link linkend="PangoMarkupFormat">Pango text markup
1306 * Also see gtk_entry_set_icon_tooltip_markup().
1310 g_object_class_install_property (gobject_class,
1311 PROP_TOOLTIP_MARKUP_SECONDARY,
1312 g_param_spec_string ("secondary-icon-tooltip-markup",
1313 P_("Secondary icon tooltip markup"),
1314 P_("The contents of the tooltip on the secondary icon"),
1316 GTK_PARAM_READWRITE));
1319 * GtkEntry:im-module:
1321 * Which IM (input method) module should be used for this entry.
1322 * See #GtkIMContext.
1324 * Setting this to a non-%NULL value overrides the
1325 * system-wide IM module setting. See the GtkSettings
1326 * #GtkSettings:gtk-im-module property.
1330 g_object_class_install_property (gobject_class,
1332 g_param_spec_string ("im-module",
1334 P_("Which IM module should be used"),
1336 GTK_PARAM_READWRITE));
1339 * GtkEntry:completion:
1341 * The auxiliary completion object to use with the entry.
1345 g_object_class_install_property (gobject_class,
1347 g_param_spec_object ("completion",
1349 P_("The auxiliary completion object"),
1350 GTK_TYPE_ENTRY_COMPLETION,
1351 GTK_PARAM_READWRITE));
1354 * GtkEntry:icon-prelight:
1356 * The prelight style property determines whether activatable
1357 * icons prelight on mouseover.
1361 gtk_widget_class_install_style_property (widget_class,
1362 g_param_spec_boolean ("icon-prelight",
1363 P_("Icon Prelight"),
1364 P_("Whether activatable icons should prelight when hovered"),
1366 GTK_PARAM_READABLE));
1369 * GtkEntry:progress-border:
1371 * The border around the progress bar in the entry.
1375 gtk_widget_class_install_style_property (widget_class,
1376 g_param_spec_boxed ("progress-border",
1377 P_("Progress Border"),
1378 P_("Border around the progress bar"),
1380 GTK_PARAM_READABLE));
1383 * GtkEntry:invisible-char:
1385 * The invisible character is used when masking entry contents (in
1386 * \"password mode\")"). When it is not explicitly set with the
1387 * #GtkEntry::invisible-char property, GTK+ determines the character
1388 * to use from a list of possible candidates, depending on availability
1389 * in the current font.
1391 * This style property allows the theme to prepend a character
1392 * to the list of candidates.
1396 gtk_widget_class_install_style_property (widget_class,
1397 g_param_spec_unichar ("invisible-char",
1398 P_("Invisible character"),
1399 P_("The character to use when masking entry contents (in \"password mode\")"),
1401 GTK_PARAM_READABLE));
1404 * GtkEntry::populate-popup:
1405 * @entry: The entry on which the signal is emitted
1406 * @menu: the menu that is being populated
1408 * The ::populate-popup signal gets emitted before showing the
1409 * context menu of the entry.
1411 * If you need to add items to the context menu, connect
1412 * to this signal and append your menuitems to the @menu.
1414 signals[POPULATE_POPUP] =
1415 g_signal_new (I_("populate-popup"),
1416 G_OBJECT_CLASS_TYPE (gobject_class),
1418 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1420 _gtk_marshal_VOID__OBJECT,
1424 /* Action signals */
1427 * GtkEntry::activate:
1428 * @entry: The entry on which the signal is emitted
1430 * A <link linkend="keybinding-signals">keybinding signal</link>
1431 * which gets emitted when the user activates the entry.
1433 * Applications should not connect to it, but may emit it with
1434 * g_signal_emit_by_name() if they need to control activation
1437 * The default bindings for this signal are all forms of the Enter key.
1440 g_signal_new (I_("activate"),
1441 G_OBJECT_CLASS_TYPE (gobject_class),
1442 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1443 G_STRUCT_OFFSET (GtkEntryClass, activate),
1445 _gtk_marshal_VOID__VOID,
1447 widget_class->activate_signal = signals[ACTIVATE];
1450 * GtkEntry::move-cursor:
1451 * @entry: the object which received the signal
1452 * @step: the granularity of the move, as a #GtkMovementStep
1453 * @count: the number of @step units to move
1454 * @extend_selection: %TRUE if the move should extend the selection
1456 * The ::move-cursor signal is a
1457 * <link linkend="keybinding-signals">keybinding signal</link>
1458 * which gets emitted when the user initiates a cursor movement.
1459 * If the cursor is not visible in @entry, this signal causes
1460 * the viewport to be moved instead.
1462 * Applications should not connect to it, but may emit it with
1463 * g_signal_emit_by_name() if they need to control the cursor
1466 * The default bindings for this signal come in two variants,
1467 * the variant with the Shift modifier extends the selection,
1468 * the variant without the Shift modifer does not.
1469 * There are too many key combinations to list them all here.
1471 * <listitem>Arrow keys move by individual characters/lines</listitem>
1472 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1473 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1476 signals[MOVE_CURSOR] =
1477 g_signal_new (I_("move-cursor"),
1478 G_OBJECT_CLASS_TYPE (gobject_class),
1479 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1480 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1482 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1484 GTK_TYPE_MOVEMENT_STEP,
1489 * GtkEntry::insert-at-cursor:
1490 * @entry: the object which received the signal
1491 * @string: the string to insert
1493 * The ::insert-at-cursor signal is a
1494 * <link linkend="keybinding-signals">keybinding signal</link>
1495 * which gets emitted when the user initiates the insertion of a
1496 * fixed string at the cursor.
1498 * This signal has no default bindings.
1500 signals[INSERT_AT_CURSOR] =
1501 g_signal_new (I_("insert-at-cursor"),
1502 G_OBJECT_CLASS_TYPE (gobject_class),
1503 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1504 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1506 _gtk_marshal_VOID__STRING,
1511 * GtkEntry::delete-from-cursor:
1512 * @entry: the object which received the signal
1513 * @type: the granularity of the deletion, as a #GtkDeleteType
1514 * @count: the number of @type units to delete
1516 * The ::delete-from-cursor signal is a
1517 * <link linkend="keybinding-signals">keybinding signal</link>
1518 * which gets emitted when the user initiates a text deletion.
1520 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1521 * if there is one, otherwise it deletes the requested number
1524 * The default bindings for this signal are
1525 * Delete for deleting a character and Ctrl-Delete for
1528 signals[DELETE_FROM_CURSOR] =
1529 g_signal_new (I_("delete-from-cursor"),
1530 G_OBJECT_CLASS_TYPE (gobject_class),
1531 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1532 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1534 _gtk_marshal_VOID__ENUM_INT,
1536 GTK_TYPE_DELETE_TYPE,
1540 * GtkEntry::backspace:
1541 * @entry: the object which received the signal
1543 * The ::backspace signal is a
1544 * <link linkend="keybinding-signals">keybinding signal</link>
1545 * which gets emitted when the user asks for it.
1547 * The default bindings for this signal are
1548 * Backspace and Shift-Backspace.
1550 signals[BACKSPACE] =
1551 g_signal_new (I_("backspace"),
1552 G_OBJECT_CLASS_TYPE (gobject_class),
1553 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1554 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1556 _gtk_marshal_VOID__VOID,
1560 * GtkEntry::cut-clipboard:
1561 * @entry: the object which received the signal
1563 * The ::cut-clipboard signal is a
1564 * <link linkend="keybinding-signals">keybinding signal</link>
1565 * which gets emitted to cut the selection to the clipboard.
1567 * The default bindings for this signal are
1568 * Ctrl-x and Shift-Delete.
1570 signals[CUT_CLIPBOARD] =
1571 g_signal_new (I_("cut-clipboard"),
1572 G_OBJECT_CLASS_TYPE (gobject_class),
1573 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1574 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1576 _gtk_marshal_VOID__VOID,
1580 * GtkEntry::copy-clipboard:
1581 * @entry: the object which received the signal
1583 * The ::copy-clipboard signal is a
1584 * <link linkend="keybinding-signals">keybinding signal</link>
1585 * which gets emitted to copy the selection to the clipboard.
1587 * The default bindings for this signal are
1588 * Ctrl-c and Ctrl-Insert.
1590 signals[COPY_CLIPBOARD] =
1591 g_signal_new (I_("copy-clipboard"),
1592 G_OBJECT_CLASS_TYPE (gobject_class),
1593 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1594 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1596 _gtk_marshal_VOID__VOID,
1600 * GtkEntry::paste-clipboard:
1601 * @entry: the object which received the signal
1603 * The ::paste-clipboard signal is a
1604 * <link linkend="keybinding-signals">keybinding signal</link>
1605 * which gets emitted to paste the contents of the clipboard
1606 * into the text view.
1608 * The default bindings for this signal are
1609 * Ctrl-v and Shift-Insert.
1611 signals[PASTE_CLIPBOARD] =
1612 g_signal_new (I_("paste-clipboard"),
1613 G_OBJECT_CLASS_TYPE (gobject_class),
1614 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1615 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1617 _gtk_marshal_VOID__VOID,
1621 * GtkEntry::toggle-overwrite:
1622 * @entry: the object which received the signal
1624 * The ::toggle-overwrite signal is a
1625 * <link linkend="keybinding-signals">keybinding signal</link>
1626 * which gets emitted to toggle the overwrite mode of the entry.
1628 * The default bindings for this signal is Insert.
1630 signals[TOGGLE_OVERWRITE] =
1631 g_signal_new (I_("toggle-overwrite"),
1632 G_OBJECT_CLASS_TYPE (gobject_class),
1633 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1634 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1636 _gtk_marshal_VOID__VOID,
1640 * GtkEntry::icon-press:
1641 * @entry: The entry on which the signal is emitted
1642 * @icon_pos: The position of the clicked icon
1643 * @event: (type Gdk.EventButton): the button press event
1645 * The ::icon-press signal is emitted when an activatable icon
1650 signals[ICON_PRESS] =
1651 g_signal_new (I_("icon-press"),
1652 G_TYPE_FROM_CLASS (gobject_class),
1656 _gtk_marshal_VOID__ENUM_BOXED,
1658 GTK_TYPE_ENTRY_ICON_POSITION,
1659 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1662 * GtkEntry::icon-release:
1663 * @entry: The entry on which the signal is emitted
1664 * @icon_pos: The position of the clicked icon
1665 * @event: (type Gdk.EventButton): the button release event
1667 * The ::icon-release signal is emitted on the button release from a
1668 * mouse click over an activatable icon.
1672 signals[ICON_RELEASE] =
1673 g_signal_new (I_("icon-release"),
1674 G_TYPE_FROM_CLASS (gobject_class),
1678 _gtk_marshal_VOID__ENUM_BOXED,
1680 GTK_TYPE_ENTRY_ICON_POSITION,
1681 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1684 * GtkEntry::preedit-changed:
1685 * @entry: the object which received the signal
1686 * @preedit: the current preedit string
1688 * If an input method is used, the typed text will not immediately
1689 * be committed to the buffer. So if you are interested in the text,
1690 * connect to this signal.
1694 signals[PREEDIT_CHANGED] =
1695 g_signal_new_class_handler (I_("preedit-changed"),
1696 G_OBJECT_CLASS_TYPE (gobject_class),
1697 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1700 _gtk_marshal_VOID__STRING,
1709 binding_set = gtk_binding_set_by_class (class);
1711 /* Moving the insertion point */
1712 add_move_binding (binding_set, GDK_KEY_Right, 0,
1713 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1715 add_move_binding (binding_set, GDK_KEY_Left, 0,
1716 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1718 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1719 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1721 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1722 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1724 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1725 GTK_MOVEMENT_WORDS, 1);
1727 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1728 GTK_MOVEMENT_WORDS, -1);
1730 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1731 GTK_MOVEMENT_WORDS, 1);
1733 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1734 GTK_MOVEMENT_WORDS, -1);
1736 add_move_binding (binding_set, GDK_KEY_Home, 0,
1737 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1739 add_move_binding (binding_set, GDK_KEY_End, 0,
1740 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1742 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1743 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1745 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1746 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1748 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1749 GTK_MOVEMENT_BUFFER_ENDS, -1);
1751 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1752 GTK_MOVEMENT_BUFFER_ENDS, 1);
1754 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1755 GTK_MOVEMENT_BUFFER_ENDS, -1);
1757 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1758 GTK_MOVEMENT_BUFFER_ENDS, 1);
1762 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1764 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1766 G_TYPE_BOOLEAN, FALSE);
1767 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1769 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1771 G_TYPE_BOOLEAN, TRUE);
1773 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1775 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1777 G_TYPE_BOOLEAN, FALSE);
1778 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1780 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1782 G_TYPE_BOOLEAN, TRUE);
1785 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1787 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1789 G_TYPE_BOOLEAN, FALSE);
1790 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1792 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1794 G_TYPE_BOOLEAN, FALSE);
1798 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1800 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1807 "delete-from-cursor", 2,
1808 G_TYPE_ENUM, GTK_DELETE_CHARS,
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1812 "delete-from-cursor", 2,
1813 G_TYPE_ENUM, GTK_DELETE_CHARS,
1816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1819 /* Make this do the same as Backspace, to help with mis-typing */
1820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1823 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1824 "delete-from-cursor", 2,
1825 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1828 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1829 "delete-from-cursor", 2,
1830 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1833 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1834 "delete-from-cursor", 2,
1835 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1838 /* Cut/copy/paste */
1840 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1841 "cut-clipboard", 0);
1842 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1843 "copy-clipboard", 0);
1844 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1845 "paste-clipboard", 0);
1847 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1848 "cut-clipboard", 0);
1849 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1850 "copy-clipboard", 0);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1852 "paste-clipboard", 0);
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1856 "toggle-overwrite", 0);
1857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1858 "toggle-overwrite", 0);
1861 * GtkEntry:inner-border:
1863 * Sets the text area's border between the text and the frame.
1867 gtk_widget_class_install_style_property (widget_class,
1868 g_param_spec_boxed ("inner-border",
1870 P_("Border between text and frame."),
1872 GTK_PARAM_READABLE));
1874 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1876 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1880 gtk_entry_editable_init (GtkEditableInterface *iface)
1882 iface->do_insert_text = gtk_entry_insert_text;
1883 iface->do_delete_text = gtk_entry_delete_text;
1884 iface->insert_text = gtk_entry_real_insert_text;
1885 iface->delete_text = gtk_entry_real_delete_text;
1886 iface->get_chars = gtk_entry_get_chars;
1887 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1888 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1889 iface->set_position = gtk_entry_real_set_position;
1890 iface->get_position = gtk_entry_get_position;
1894 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1896 iface->start_editing = gtk_entry_start_editing;
1900 gtk_entry_set_property (GObject *object,
1902 const GValue *value,
1905 GtkEntry *entry = GTK_ENTRY (object);
1906 GtkEntryPrivate *priv = entry->priv;
1911 gtk_entry_set_buffer (entry, g_value_get_object (value));
1916 gboolean new_value = g_value_get_boolean (value);
1918 if (new_value != priv->editable)
1920 GtkWidget *widget = GTK_WIDGET (entry);
1924 _gtk_entry_reset_im_context (entry);
1925 if (gtk_widget_has_focus (widget))
1926 gtk_im_context_focus_out (priv->im_context);
1928 priv->preedit_length = 0;
1929 priv->preedit_cursor = 0;
1932 priv->editable = new_value;
1934 if (new_value && gtk_widget_has_focus (widget))
1935 gtk_im_context_focus_in (priv->im_context);
1937 gtk_widget_queue_draw (widget);
1942 case PROP_MAX_LENGTH:
1943 gtk_entry_set_max_length (entry, g_value_get_int (value));
1946 case PROP_VISIBILITY:
1947 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1950 case PROP_HAS_FRAME:
1951 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1954 case PROP_INNER_BORDER:
1955 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1958 case PROP_INVISIBLE_CHAR:
1959 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1962 case PROP_ACTIVATES_DEFAULT:
1963 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1966 case PROP_WIDTH_CHARS:
1967 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1971 gtk_entry_set_text (entry, g_value_get_string (value));
1975 gtk_entry_set_alignment (entry, g_value_get_float (value));
1978 case PROP_TRUNCATE_MULTILINE:
1979 priv->truncate_multiline = g_value_get_boolean (value);
1982 case PROP_SHADOW_TYPE:
1983 priv->shadow_type = g_value_get_enum (value);
1986 case PROP_OVERWRITE_MODE:
1987 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1990 case PROP_INVISIBLE_CHAR_SET:
1991 if (g_value_get_boolean (value))
1992 priv->invisible_char_set = TRUE;
1994 gtk_entry_unset_invisible_char (entry);
1997 case PROP_CAPS_LOCK_WARNING:
1998 priv->caps_lock_warning = g_value_get_boolean (value);
2001 case PROP_PROGRESS_FRACTION:
2002 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2005 case PROP_PROGRESS_PULSE_STEP:
2006 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2009 case PROP_PLACEHOLDER_TEXT:
2010 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2013 case PROP_PIXBUF_PRIMARY:
2014 gtk_entry_set_icon_from_pixbuf (entry,
2015 GTK_ENTRY_ICON_PRIMARY,
2016 g_value_get_object (value));
2019 case PROP_PIXBUF_SECONDARY:
2020 gtk_entry_set_icon_from_pixbuf (entry,
2021 GTK_ENTRY_ICON_SECONDARY,
2022 g_value_get_object (value));
2025 case PROP_STOCK_PRIMARY:
2026 gtk_entry_set_icon_from_stock (entry,
2027 GTK_ENTRY_ICON_PRIMARY,
2028 g_value_get_string (value));
2031 case PROP_STOCK_SECONDARY:
2032 gtk_entry_set_icon_from_stock (entry,
2033 GTK_ENTRY_ICON_SECONDARY,
2034 g_value_get_string (value));
2037 case PROP_ICON_NAME_PRIMARY:
2038 gtk_entry_set_icon_from_icon_name (entry,
2039 GTK_ENTRY_ICON_PRIMARY,
2040 g_value_get_string (value));
2043 case PROP_ICON_NAME_SECONDARY:
2044 gtk_entry_set_icon_from_icon_name (entry,
2045 GTK_ENTRY_ICON_SECONDARY,
2046 g_value_get_string (value));
2049 case PROP_GICON_PRIMARY:
2050 gtk_entry_set_icon_from_gicon (entry,
2051 GTK_ENTRY_ICON_PRIMARY,
2052 g_value_get_object (value));
2055 case PROP_GICON_SECONDARY:
2056 gtk_entry_set_icon_from_gicon (entry,
2057 GTK_ENTRY_ICON_SECONDARY,
2058 g_value_get_object (value));
2061 case PROP_ACTIVATABLE_PRIMARY:
2062 gtk_entry_set_icon_activatable (entry,
2063 GTK_ENTRY_ICON_PRIMARY,
2064 g_value_get_boolean (value));
2067 case PROP_ACTIVATABLE_SECONDARY:
2068 gtk_entry_set_icon_activatable (entry,
2069 GTK_ENTRY_ICON_SECONDARY,
2070 g_value_get_boolean (value));
2073 case PROP_SENSITIVE_PRIMARY:
2074 gtk_entry_set_icon_sensitive (entry,
2075 GTK_ENTRY_ICON_PRIMARY,
2076 g_value_get_boolean (value));
2079 case PROP_SENSITIVE_SECONDARY:
2080 gtk_entry_set_icon_sensitive (entry,
2081 GTK_ENTRY_ICON_SECONDARY,
2082 g_value_get_boolean (value));
2085 case PROP_TOOLTIP_TEXT_PRIMARY:
2086 gtk_entry_set_icon_tooltip_text (entry,
2087 GTK_ENTRY_ICON_PRIMARY,
2088 g_value_get_string (value));
2091 case PROP_TOOLTIP_TEXT_SECONDARY:
2092 gtk_entry_set_icon_tooltip_text (entry,
2093 GTK_ENTRY_ICON_SECONDARY,
2094 g_value_get_string (value));
2097 case PROP_TOOLTIP_MARKUP_PRIMARY:
2098 gtk_entry_set_icon_tooltip_markup (entry,
2099 GTK_ENTRY_ICON_PRIMARY,
2100 g_value_get_string (value));
2103 case PROP_TOOLTIP_MARKUP_SECONDARY:
2104 gtk_entry_set_icon_tooltip_markup (entry,
2105 GTK_ENTRY_ICON_SECONDARY,
2106 g_value_get_string (value));
2109 case PROP_IM_MODULE:
2110 g_free (priv->im_module);
2111 priv->im_module = g_value_dup_string (value);
2112 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2113 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2116 case PROP_EDITING_CANCELED:
2117 priv->editing_canceled = g_value_get_boolean (value);
2120 case PROP_COMPLETION:
2121 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2124 case PROP_SCROLL_OFFSET:
2125 case PROP_CURSOR_POSITION:
2127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2133 gtk_entry_get_property (GObject *object,
2138 GtkEntry *entry = GTK_ENTRY (object);
2139 GtkEntryPrivate *priv = entry->priv;
2144 g_value_set_object (value, gtk_entry_get_buffer (entry));
2147 case PROP_CURSOR_POSITION:
2148 g_value_set_int (value, priv->current_pos);
2151 case PROP_SELECTION_BOUND:
2152 g_value_set_int (value, priv->selection_bound);
2156 g_value_set_boolean (value, priv->editable);
2159 case PROP_MAX_LENGTH:
2160 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2163 case PROP_VISIBILITY:
2164 g_value_set_boolean (value, priv->visible);
2167 case PROP_HAS_FRAME:
2168 g_value_set_boolean (value, priv->has_frame);
2171 case PROP_INNER_BORDER:
2172 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2175 case PROP_INVISIBLE_CHAR:
2176 g_value_set_uint (value, priv->invisible_char);
2179 case PROP_ACTIVATES_DEFAULT:
2180 g_value_set_boolean (value, priv->activates_default);
2183 case PROP_WIDTH_CHARS:
2184 g_value_set_int (value, priv->width_chars);
2187 case PROP_SCROLL_OFFSET:
2188 g_value_set_int (value, priv->scroll_offset);
2192 g_value_set_string (value, gtk_entry_get_text (entry));
2196 g_value_set_float (value, gtk_entry_get_alignment (entry));
2199 case PROP_TRUNCATE_MULTILINE:
2200 g_value_set_boolean (value, priv->truncate_multiline);
2203 case PROP_SHADOW_TYPE:
2204 g_value_set_enum (value, priv->shadow_type);
2207 case PROP_OVERWRITE_MODE:
2208 g_value_set_boolean (value, priv->overwrite_mode);
2211 case PROP_TEXT_LENGTH:
2212 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2215 case PROP_INVISIBLE_CHAR_SET:
2216 g_value_set_boolean (value, priv->invisible_char_set);
2219 case PROP_IM_MODULE:
2220 g_value_set_string (value, priv->im_module);
2223 case PROP_CAPS_LOCK_WARNING:
2224 g_value_set_boolean (value, priv->caps_lock_warning);
2227 case PROP_PROGRESS_FRACTION:
2228 g_value_set_double (value, priv->progress_fraction);
2231 case PROP_PROGRESS_PULSE_STEP:
2232 g_value_set_double (value, priv->progress_pulse_fraction);
2235 case PROP_PLACEHOLDER_TEXT:
2236 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2239 case PROP_PIXBUF_PRIMARY:
2240 g_value_set_object (value,
2241 gtk_entry_get_icon_pixbuf (entry,
2242 GTK_ENTRY_ICON_PRIMARY));
2245 case PROP_PIXBUF_SECONDARY:
2246 g_value_set_object (value,
2247 gtk_entry_get_icon_pixbuf (entry,
2248 GTK_ENTRY_ICON_SECONDARY));
2251 case PROP_STOCK_PRIMARY:
2252 g_value_set_string (value,
2253 gtk_entry_get_icon_stock (entry,
2254 GTK_ENTRY_ICON_PRIMARY));
2257 case PROP_STOCK_SECONDARY:
2258 g_value_set_string (value,
2259 gtk_entry_get_icon_stock (entry,
2260 GTK_ENTRY_ICON_SECONDARY));
2263 case PROP_ICON_NAME_PRIMARY:
2264 g_value_set_string (value,
2265 gtk_entry_get_icon_name (entry,
2266 GTK_ENTRY_ICON_PRIMARY));
2269 case PROP_ICON_NAME_SECONDARY:
2270 g_value_set_string (value,
2271 gtk_entry_get_icon_name (entry,
2272 GTK_ENTRY_ICON_SECONDARY));
2275 case PROP_GICON_PRIMARY:
2276 g_value_set_object (value,
2277 gtk_entry_get_icon_gicon (entry,
2278 GTK_ENTRY_ICON_PRIMARY));
2281 case PROP_GICON_SECONDARY:
2282 g_value_set_object (value,
2283 gtk_entry_get_icon_gicon (entry,
2284 GTK_ENTRY_ICON_SECONDARY));
2287 case PROP_STORAGE_TYPE_PRIMARY:
2288 g_value_set_enum (value,
2289 gtk_entry_get_icon_storage_type (entry,
2290 GTK_ENTRY_ICON_PRIMARY));
2293 case PROP_STORAGE_TYPE_SECONDARY:
2294 g_value_set_enum (value,
2295 gtk_entry_get_icon_storage_type (entry,
2296 GTK_ENTRY_ICON_SECONDARY));
2299 case PROP_ACTIVATABLE_PRIMARY:
2300 g_value_set_boolean (value,
2301 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2304 case PROP_ACTIVATABLE_SECONDARY:
2305 g_value_set_boolean (value,
2306 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2309 case PROP_SENSITIVE_PRIMARY:
2310 g_value_set_boolean (value,
2311 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2314 case PROP_SENSITIVE_SECONDARY:
2315 g_value_set_boolean (value,
2316 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2319 case PROP_TOOLTIP_TEXT_PRIMARY:
2320 g_value_take_string (value,
2321 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2324 case PROP_TOOLTIP_TEXT_SECONDARY:
2325 g_value_take_string (value,
2326 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2329 case PROP_TOOLTIP_MARKUP_PRIMARY:
2330 g_value_take_string (value,
2331 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2334 case PROP_TOOLTIP_MARKUP_SECONDARY:
2335 g_value_take_string (value,
2336 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2339 case PROP_EDITING_CANCELED:
2340 g_value_set_boolean (value,
2341 priv->editing_canceled);
2344 case PROP_COMPLETION:
2345 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2349 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2355 find_invisible_char (GtkWidget *widget)
2357 PangoLayout *layout;
2358 PangoAttrList *attr_list;
2360 gunichar invisible_chars [] = {
2362 0x25cf, /* BLACK CIRCLE */
2363 0x2022, /* BULLET */
2364 0x2731, /* HEAVY ASTERISK */
2365 0x273a /* SIXTEEN POINTED ASTERISK */
2368 gtk_widget_style_get (widget,
2369 "invisible-char", &invisible_chars[0],
2372 layout = gtk_widget_create_pango_layout (widget, NULL);
2374 attr_list = pango_attr_list_new ();
2375 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2377 pango_layout_set_attributes (layout, attr_list);
2378 pango_attr_list_unref (attr_list);
2380 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2382 gchar text[7] = { 0, };
2385 len = g_unichar_to_utf8 (invisible_chars[i], text);
2386 pango_layout_set_text (layout, text, len);
2388 count = pango_layout_get_unknown_glyphs_count (layout);
2392 g_object_unref (layout);
2393 return invisible_chars[i];
2397 g_object_unref (layout);
2403 gtk_entry_init (GtkEntry *entry)
2405 GtkStyleContext *context;
2406 GtkEntryPrivate *priv;
2408 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2413 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2414 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2416 priv->editable = TRUE;
2417 priv->visible = TRUE;
2418 priv->dnd_position = -1;
2419 priv->width_chars = -1;
2420 priv->is_cell_renderer = FALSE;
2421 priv->editing_canceled = FALSE;
2422 priv->has_frame = TRUE;
2423 priv->truncate_multiline = FALSE;
2424 priv->shadow_type = GTK_SHADOW_IN;
2426 priv->caps_lock_warning = TRUE;
2427 priv->caps_lock_warning_shown = FALSE;
2428 priv->progress_fraction = 0.0;
2429 priv->progress_pulse_fraction = 0.1;
2431 gtk_drag_dest_set (GTK_WIDGET (entry),
2432 GTK_DEST_DEFAULT_HIGHLIGHT,
2434 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2435 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2437 /* This object is completely private. No external entity can gain a reference
2438 * to it; so we create it here and destroy it in finalize().
2440 priv->im_context = gtk_im_multicontext_new ();
2442 g_signal_connect (priv->im_context, "commit",
2443 G_CALLBACK (gtk_entry_commit_cb), entry);
2444 g_signal_connect (priv->im_context, "preedit-changed",
2445 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2446 g_signal_connect (priv->im_context, "retrieve-surrounding",
2447 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2448 g_signal_connect (priv->im_context, "delete-surrounding",
2449 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2451 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2452 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2454 gtk_entry_update_cached_style_values (entry);
2458 get_icon_width (GtkEntry *entry,
2459 GtkEntryIconPosition icon_pos)
2461 GtkEntryPrivate *priv = entry->priv;
2462 EntryIconInfo *icon_info = priv->icons[icon_pos];
2464 GtkSettings *settings;
2465 gint menu_icon_width;
2467 if (!icon_info || icon_info->pixbuf == NULL)
2470 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2471 settings = gtk_settings_get_for_screen (screen);
2473 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2474 &menu_icon_width, NULL);
2476 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2480 get_icon_allocations (GtkEntry *entry,
2481 GtkAllocation *primary,
2482 GtkAllocation *secondary)
2485 GtkEntryPrivate *priv = entry->priv;
2486 gint x, y, width, height;
2488 get_text_area_size (entry, &x, &y, &width, &height);
2490 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2491 y += priv->focus_width;
2494 primary->height = height;
2495 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2496 if (primary->width > 0)
2497 primary->width += 2 * priv->icon_margin;
2500 secondary->height = height;
2501 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2502 if (secondary->width > 0)
2503 secondary->width += 2 * priv->icon_margin;
2505 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2507 primary->x = x + width - primary->width;
2513 secondary->x = x + width - secondary->width;
2519 begin_change (GtkEntry *entry)
2521 GtkEntryPrivate *priv = entry->priv;
2523 priv->change_count++;
2527 end_change (GtkEntry *entry)
2529 GtkEditable *editable = GTK_EDITABLE (entry);
2530 GtkEntryPrivate *priv = entry->priv;
2532 g_return_if_fail (priv->change_count > 0);
2534 priv->change_count--;
2536 if (priv->change_count == 0)
2538 if (priv->real_changed)
2540 g_signal_emit_by_name (editable, "changed");
2541 priv->real_changed = FALSE;
2547 emit_changed (GtkEntry *entry)
2549 GtkEditable *editable = GTK_EDITABLE (entry);
2550 GtkEntryPrivate *priv = entry->priv;
2552 if (priv->change_count == 0)
2553 g_signal_emit_by_name (editable, "changed");
2555 priv->real_changed = TRUE;
2559 gtk_entry_destroy (GtkWidget *widget)
2561 GtkEntry *entry = GTK_ENTRY (widget);
2562 GtkEntryPrivate *priv = entry->priv;
2564 priv->current_pos = priv->selection_bound = 0;
2565 _gtk_entry_reset_im_context (entry);
2566 gtk_entry_reset_layout (entry);
2568 if (priv->blink_timeout)
2570 g_source_remove (priv->blink_timeout);
2571 priv->blink_timeout = 0;
2574 if (priv->recompute_idle)
2576 g_source_remove (priv->recompute_idle);
2577 priv->recompute_idle = 0;
2580 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2584 gtk_entry_dispose (GObject *object)
2586 GtkEntry *entry = GTK_ENTRY (object);
2587 GtkEntryPrivate *priv = entry->priv;
2590 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2591 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2592 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2593 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2597 buffer_disconnect_signals (entry);
2598 g_object_unref (priv->buffer);
2599 priv->buffer = NULL;
2602 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2603 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2604 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2605 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2609 gtk_entry_finalize (GObject *object)
2611 GtkEntry *entry = GTK_ENTRY (object);
2612 GtkEntryPrivate *priv = entry->priv;
2613 EntryIconInfo *icon_info = NULL;
2616 for (i = 0; i < MAX_ICONS; i++)
2618 if ((icon_info = priv->icons[i]) != NULL)
2620 if (icon_info->target_list != NULL)
2622 gtk_target_list_unref (icon_info->target_list);
2623 icon_info->target_list = NULL;
2626 g_slice_free (EntryIconInfo, icon_info);
2627 priv->icons[i] = NULL;
2631 gtk_entry_set_completion (entry, NULL);
2633 if (priv->cached_layout)
2634 g_object_unref (priv->cached_layout);
2636 g_object_unref (priv->im_context);
2638 if (priv->blink_timeout)
2639 g_source_remove (priv->blink_timeout);
2641 if (priv->recompute_idle)
2642 g_source_remove (priv->recompute_idle);
2644 g_free (priv->placeholder_text);
2645 g_free (priv->im_module);
2647 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2651 gtk_entry_get_display_mode (GtkEntry *entry)
2653 GtkEntryPrivate *priv = entry->priv;
2656 return DISPLAY_NORMAL;
2658 if (priv->invisible_char == 0 && priv->invisible_char_set)
2659 return DISPLAY_BLANK;
2661 return DISPLAY_INVISIBLE;
2665 gtk_entry_get_display_text (GtkEntry *entry,
2669 GtkEntryPasswordHint *password_hint;
2670 GtkEntryPrivate *priv;
2671 gunichar invisible_char;
2682 text = gtk_entry_buffer_get_text (get_buffer (entry));
2683 length = gtk_entry_buffer_get_length (get_buffer (entry));
2687 if (start_pos > length)
2690 if (end_pos <= start_pos)
2691 return g_strdup ("");
2692 else if (priv->visible)
2694 start = g_utf8_offset_to_pointer (text, start_pos);
2695 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2696 return g_strndup (start, end - start);
2700 str = g_string_sized_new (length * 2);
2702 /* Figure out what our invisible char is and encode it */
2703 if (!priv->invisible_char)
2704 invisible_char = priv->invisible_char_set ? ' ' : '*';
2706 invisible_char = priv->invisible_char;
2707 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2710 * Add hidden characters for each character in the text
2711 * buffer. If there is a password hint, then keep that
2712 * character visible.
2715 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2716 for (i = start_pos; i < end_pos; ++i)
2718 if (password_hint && i == password_hint->position)
2720 start = g_utf8_offset_to_pointer (text, i);
2721 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2725 g_string_append_len (str, char_str, char_len);
2729 return g_string_free (str, FALSE);
2734 update_cursors (GtkWidget *widget)
2736 GtkEntry *entry = GTK_ENTRY (widget);
2737 GtkEntryPrivate *priv = entry->priv;
2738 EntryIconInfo *icon_info = NULL;
2739 GdkDisplay *display;
2743 for (i = 0; i < MAX_ICONS; i++)
2745 if ((icon_info = priv->icons[i]) != NULL)
2747 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2748 gdk_window_show_unraised (icon_info->window);
2750 /* The icon windows are not children of the visible entry window,
2751 * thus we can't just inherit the xterm cursor. Slight complication
2752 * here is that for the entry, insensitive => arrow cursor, but for
2753 * an icon in a sensitive entry, insensitive => xterm cursor.
2755 if (gtk_widget_is_sensitive (widget) &&
2756 (icon_info->insensitive ||
2757 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2759 display = gtk_widget_get_display (widget);
2760 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2761 gdk_window_set_cursor (icon_info->window, cursor);
2762 g_object_unref (cursor);
2766 gdk_window_set_cursor (icon_info->window, NULL);
2773 realize_icon_info (GtkWidget *widget,
2774 GtkEntryIconPosition icon_pos)
2776 GtkEntry *entry = GTK_ENTRY (widget);
2777 GtkEntryPrivate *priv = entry->priv;
2778 EntryIconInfo *icon_info = priv->icons[icon_pos];
2779 GdkWindowAttr attributes;
2780 gint attributes_mask;
2782 g_return_if_fail (icon_info != NULL);
2786 attributes.width = 1;
2787 attributes.height = 1;
2788 attributes.window_type = GDK_WINDOW_CHILD;
2789 attributes.wclass = GDK_INPUT_ONLY;
2790 attributes.event_mask = gtk_widget_get_events (widget);
2791 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2792 GDK_BUTTON_RELEASE_MASK |
2793 GDK_BUTTON1_MOTION_MASK |
2794 GDK_BUTTON3_MOTION_MASK |
2795 GDK_POINTER_MOTION_HINT_MASK |
2796 GDK_POINTER_MOTION_MASK |
2797 GDK_ENTER_NOTIFY_MASK |
2798 GDK_LEAVE_NOTIFY_MASK);
2799 attributes_mask = GDK_WA_X | GDK_WA_Y;
2801 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2804 gdk_window_set_user_data (icon_info->window, widget);
2806 gtk_widget_queue_resize (widget);
2809 static EntryIconInfo*
2810 construct_icon_info (GtkWidget *widget,
2811 GtkEntryIconPosition icon_pos)
2813 GtkEntry *entry = GTK_ENTRY (widget);
2814 GtkEntryPrivate *priv = entry->priv;
2815 EntryIconInfo *icon_info;
2817 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2819 icon_info = g_slice_new0 (EntryIconInfo);
2820 priv->icons[icon_pos] = icon_info;
2822 if (gtk_widget_get_realized (widget))
2823 realize_icon_info (widget, icon_pos);
2829 gtk_entry_map (GtkWidget *widget)
2831 GtkEntry *entry = GTK_ENTRY (widget);
2832 GtkEntryPrivate *priv = entry->priv;
2833 EntryIconInfo *icon_info = NULL;
2836 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2838 gdk_window_show (priv->text_area);
2840 for (i = 0; i < MAX_ICONS; i++)
2842 if ((icon_info = priv->icons[i]) != NULL)
2844 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2845 gdk_window_show (icon_info->window);
2849 update_cursors (widget);
2853 gtk_entry_unmap (GtkWidget *widget)
2855 GtkEntry *entry = GTK_ENTRY (widget);
2856 GtkEntryPrivate *priv = entry->priv;
2857 EntryIconInfo *icon_info = NULL;
2860 for (i = 0; i < MAX_ICONS; i++)
2862 if ((icon_info = priv->icons[i]) != NULL)
2864 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2865 gdk_window_hide (icon_info->window);
2869 gdk_window_hide (priv->text_area);
2871 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2875 gtk_entry_realize (GtkWidget *widget)
2878 GtkEntryPrivate *priv;
2879 EntryIconInfo *icon_info;
2881 GdkWindowAttr attributes;
2882 gint attributes_mask;
2883 gint frame_x, frame_y;
2886 gtk_widget_set_realized (widget, TRUE);
2887 window = gtk_widget_get_parent_window (widget);
2888 gtk_widget_set_window (widget, window);
2889 g_object_ref (window);
2891 entry = GTK_ENTRY (widget);
2894 attributes.window_type = GDK_WINDOW_CHILD;
2895 attributes.wclass = GDK_INPUT_ONLY;
2896 attributes.event_mask = gtk_widget_get_events (widget);
2897 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2898 GDK_BUTTON_RELEASE_MASK |
2899 GDK_BUTTON1_MOTION_MASK |
2900 GDK_BUTTON3_MOTION_MASK |
2901 GDK_POINTER_MOTION_HINT_MASK |
2902 GDK_POINTER_MOTION_MASK |
2903 GDK_ENTER_NOTIFY_MASK |
2904 GDK_LEAVE_NOTIFY_MASK);
2905 attributes_mask = GDK_WA_X | GDK_WA_Y;
2907 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2909 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2910 attributes.x += frame_x;
2911 attributes.y += frame_y;
2913 if (gtk_widget_is_sensitive (widget))
2915 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2916 attributes_mask |= GDK_WA_CURSOR;
2919 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2923 gdk_window_set_user_data (priv->text_area, entry);
2925 if (attributes_mask & GDK_WA_CURSOR)
2926 g_object_unref (attributes.cursor);
2928 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2930 gtk_entry_adjust_scroll (entry);
2931 gtk_entry_update_primary_selection (entry);
2934 /* If the icon positions are already setup, create their windows.
2935 * Otherwise if they don't exist yet, then construct_icon_info()
2936 * will create the windows once the widget is already realized.
2938 for (i = 0; i < MAX_ICONS; i++)
2940 if ((icon_info = priv->icons[i]) != NULL)
2942 if (icon_info->window == NULL)
2943 realize_icon_info (widget, i);
2949 gtk_entry_unrealize (GtkWidget *widget)
2951 GtkEntry *entry = GTK_ENTRY (widget);
2952 GtkEntryPrivate *priv = entry->priv;
2953 GtkClipboard *clipboard;
2954 EntryIconInfo *icon_info;
2957 gtk_entry_reset_layout (entry);
2959 gtk_im_context_set_client_window (priv->im_context, NULL);
2961 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2962 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2963 gtk_clipboard_clear (clipboard);
2965 if (priv->text_area)
2967 gdk_window_set_user_data (priv->text_area, NULL);
2968 gdk_window_destroy (priv->text_area);
2969 priv->text_area = NULL;
2972 if (priv->popup_menu)
2974 gtk_widget_destroy (priv->popup_menu);
2975 priv->popup_menu = NULL;
2978 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2980 for (i = 0; i < MAX_ICONS; i++)
2982 if ((icon_info = priv->icons[i]) != NULL)
2984 if (icon_info->window != NULL)
2986 gdk_window_destroy (icon_info->window);
2987 icon_info->window = NULL;
2994 _gtk_entry_get_borders (GtkEntry *entry,
2998 GtkEntryPrivate *priv = entry->priv;
2999 GtkWidget *widget = GTK_WIDGET (entry);
3001 if (priv->has_frame)
3003 GtkStyleContext *context;
3006 context = gtk_widget_get_style_context (widget);
3007 gtk_style_context_get_padding (context, 0, &padding);
3009 *xborder = padding.left;
3010 *yborder = padding.top;
3018 if (!priv->interior_focus)
3020 *xborder += priv->focus_width;
3021 *yborder += priv->focus_width;
3026 gtk_entry_get_preferred_width (GtkWidget *widget,
3030 GtkEntry *entry = GTK_ENTRY (widget);
3031 GtkEntryPrivate *priv = entry->priv;
3032 PangoFontMetrics *metrics;
3033 gint xborder, yborder;
3034 GtkBorder inner_border;
3035 PangoContext *context;
3036 GtkStyleContext *style_context;
3037 GtkStateFlags state;
3038 gint icon_widths = 0;
3042 context = gtk_widget_get_pango_context (widget);
3044 style_context = gtk_widget_get_style_context (widget);
3045 state = gtk_widget_get_state_flags (widget);
3047 metrics = pango_context_get_metrics (context,
3048 gtk_style_context_get_font (style_context, state),
3049 pango_context_get_language (context));
3051 _gtk_entry_get_borders (entry, &xborder, &yborder);
3052 _gtk_entry_effective_inner_border (entry, &inner_border);
3054 if (priv->width_chars < 0)
3055 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3058 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3059 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3060 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3062 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3065 for (i = 0; i < MAX_ICONS; i++)
3067 icon_width = get_icon_width (entry, i);
3069 icon_widths += icon_width + 2 * priv->icon_margin;
3072 if (icon_widths > width)
3073 width += icon_widths;
3075 pango_font_metrics_unref (metrics);
3082 gtk_entry_get_preferred_height (GtkWidget *widget,
3086 GtkEntry *entry = GTK_ENTRY (widget);
3087 GtkEntryPrivate *priv = entry->priv;
3088 PangoFontMetrics *metrics;
3089 gint xborder, yborder;
3090 GtkBorder inner_border;
3091 GtkStyleContext *style_context;
3092 GtkStateFlags state;
3093 PangoContext *context;
3096 context = gtk_widget_get_pango_context (widget);
3098 style_context = gtk_widget_get_style_context (widget);
3099 state = gtk_widget_get_state_flags (widget);
3101 metrics = pango_context_get_metrics (context,
3102 gtk_style_context_get_font (style_context, state),
3103 pango_context_get_language (context));
3105 priv->ascent = pango_font_metrics_get_ascent (metrics);
3106 priv->descent = pango_font_metrics_get_descent (metrics);
3108 _gtk_entry_get_borders (entry, &xborder, &yborder);
3109 _gtk_entry_effective_inner_border (entry, &inner_border);
3111 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3113 pango_font_metrics_unref (metrics);
3120 place_windows (GtkEntry *entry)
3122 GtkWidget *widget = GTK_WIDGET (entry);
3123 GtkEntryPrivate *priv = entry->priv;
3124 gint x, y, width, height;
3125 gint frame_x, frame_y;
3126 GtkAllocation primary;
3127 GtkAllocation secondary;
3128 EntryIconInfo *icon_info = NULL;
3130 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3131 get_text_area_size (entry, &x, &y, &width, &height);
3132 get_icon_allocations (entry, &primary, &secondary);
3134 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3135 y += priv->focus_width;
3137 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3138 x += secondary.width;
3141 width -= primary.width + secondary.width;
3145 primary.x += frame_x;
3146 primary.y += frame_y;
3147 secondary.x += frame_x;
3148 secondary.y += frame_y;
3150 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3151 gdk_window_move_resize (icon_info->window,
3152 primary.x, primary.y,
3153 primary.width, primary.height);
3155 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3156 gdk_window_move_resize (icon_info->window,
3157 secondary.x, secondary.y,
3158 secondary.width, secondary.height);
3160 gdk_window_move_resize (priv->text_area, x, y, width, height);
3164 gtk_entry_get_text_area_size (GtkEntry *entry,
3170 GtkEntryPrivate *priv = entry->priv;
3171 GtkWidget *widget = GTK_WIDGET (entry);
3172 GtkAllocation allocation;
3173 GtkRequisition requisition;
3176 gint xborder, yborder;
3178 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3179 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3181 gtk_widget_get_allocation (widget, &allocation);
3182 _gtk_entry_get_borders (entry, &xborder, &yborder);
3184 if (gtk_widget_get_realized (widget))
3185 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3187 frame_height = req_height;
3189 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3190 frame_height -= 2 * priv->focus_width;
3196 *y = frame_height / 2 - (req_height - yborder * 2) / 2;
3199 *width = allocation.width - xborder * 2;
3202 *height = req_height - yborder * 2;
3206 get_text_area_size (GtkEntry *entry,
3212 GtkEntryClass *class;
3214 g_return_if_fail (GTK_IS_ENTRY (entry));
3216 class = GTK_ENTRY_GET_CLASS (entry);
3218 if (class->get_text_area_size)
3219 class->get_text_area_size (entry, x, y, width, height);
3224 get_frame_size (GtkEntry *entry,
3225 gboolean relative_to_window,
3231 GtkEntryPrivate *priv = entry->priv;
3232 GtkAllocation allocation;
3233 GtkRequisition requisition;
3234 GtkWidget *widget = GTK_WIDGET (entry);
3237 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3239 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3241 gtk_widget_get_allocation (widget, &allocation);
3244 *x = relative_to_window ? allocation.x : 0;
3248 if (priv->is_cell_renderer)
3251 *y = (allocation.height - req_height) / 2;
3253 if (relative_to_window)
3258 *width = allocation.width;
3262 if (priv->is_cell_renderer)
3263 *height = allocation.height;
3265 *height = req_height;
3270 _gtk_entry_effective_inner_border (GtkEntry *entry,
3273 GtkBorder *tmp_border;
3275 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3279 *border = *tmp_border;
3283 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3287 *border = *tmp_border;
3288 gtk_border_free (tmp_border);
3292 *border = default_inner_border;
3296 gtk_entry_size_allocate (GtkWidget *widget,
3297 GtkAllocation *allocation)
3299 GtkEntry *entry = GTK_ENTRY (widget);
3301 gtk_widget_set_allocation (widget, allocation);
3303 if (gtk_widget_get_realized (widget))
3305 GtkEntryCompletion* completion;
3307 place_windows (entry);
3308 gtk_entry_recompute (entry);
3310 completion = gtk_entry_get_completion (entry);
3311 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3312 _gtk_entry_completion_resize_popup (completion);
3317 should_prelight (GtkEntry *entry,
3318 GtkEntryIconPosition icon_pos)
3320 GtkEntryPrivate *priv = entry->priv;
3321 EntryIconInfo *icon_info = priv->icons[icon_pos];
3327 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3330 if (icon_info->pressed)
3333 gtk_widget_style_get (GTK_WIDGET (entry),
3334 "icon-prelight", &prelight,
3341 draw_icon (GtkWidget *widget,
3343 GtkEntryIconPosition icon_pos)
3345 GtkEntry *entry = GTK_ENTRY (widget);
3346 GtkEntryPrivate *priv = entry->priv;
3347 EntryIconInfo *icon_info = priv->icons[icon_pos];
3349 gint x, y, width, height;
3350 GtkStyleContext *context;
3355 gtk_entry_ensure_pixbuf (entry, icon_pos);
3357 if (icon_info->pixbuf == NULL)
3360 width = gdk_window_get_width (icon_info->window);
3361 height = gdk_window_get_height (icon_info->window);
3363 context = gtk_widget_get_style_context (widget);
3365 /* size_allocate hasn't been called yet. These are the default values.
3367 if (width == 1 || height == 1)
3370 pixbuf = icon_info->pixbuf;
3371 g_object_ref (pixbuf);
3373 if (gdk_pixbuf_get_height (pixbuf) > height)
3375 GdkPixbuf *temp_pixbuf;
3378 scale = height - 2 * priv->icon_margin;
3379 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3380 GDK_INTERP_BILINEAR);
3381 g_object_unref (pixbuf);
3382 pixbuf = temp_pixbuf;
3385 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3386 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3388 gtk_render_icon (context, cr, pixbuf, x, y);
3390 g_object_unref (pixbuf);
3395 gtk_entry_draw_frame (GtkWidget *widget,
3396 GtkStyleContext *context,
3399 GtkEntry *entry = GTK_ENTRY (widget);
3400 GtkEntryPrivate *priv = entry->priv;
3401 gint x = 0, y = 0, width, height;
3402 gint frame_x, frame_y;
3406 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3408 cairo_translate (cr, frame_x, frame_y);
3410 /* Fix a problem with some themes which assume that entry->text_area's
3411 * width equals widget->window's width
3412 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3413 if (GTK_IS_SPIN_BUTTON (widget))
3415 gint xborder, yborder;
3417 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3418 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3421 width += xborder * 2;
3424 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3426 x += priv->focus_width;
3427 y += priv->focus_width;
3428 width -= 2 * priv->focus_width;
3429 height -= 2 * priv->focus_width;
3432 gtk_render_background (context, cr,
3433 x, y, width, height);
3435 if (priv->has_frame)
3436 gtk_render_frame (context, cr,
3437 x, y, width, height);
3439 gtk_entry_draw_progress (widget, context, cr);
3441 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3443 x -= priv->focus_width;
3444 y -= priv->focus_width;
3445 width += 2 * priv->focus_width;
3446 height += 2 * priv->focus_width;
3448 gtk_render_focus (context, cr,
3449 0, 0, width, height);
3456 get_progress_area (GtkWidget *widget,
3462 GtkEntry *entry = GTK_ENTRY (widget);
3463 GtkEntryPrivate *private = entry->priv;
3464 GtkBorder *progress_border;
3466 get_text_area_size (entry, x, y, width, height);
3468 if (!private->interior_focus)
3470 *x -= private->focus_width;
3471 *y -= private->focus_width;
3472 *width += 2 * private->focus_width;
3473 *height += 2 * private->focus_width;
3476 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3478 if (progress_border)
3480 *x += progress_border->left;
3481 *y += progress_border->top;
3482 *width -= progress_border->left + progress_border->right;
3483 *height -= progress_border->top + progress_border->bottom;
3485 gtk_border_free (progress_border);
3488 if (private->progress_pulse_mode)
3490 gdouble value = private->progress_pulse_current;
3492 *x += (gint) floor(value * (*width));
3493 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3495 else if (private->progress_fraction > 0)
3497 gdouble value = private->progress_fraction;
3499 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3503 bar_width = floor(value * (*width) + 0.5);
3504 *x += *width - bar_width;
3509 *width = (gint) floor(value * (*width) + 0.5);
3520 gtk_entry_draw_progress (GtkWidget *widget,
3521 GtkStyleContext *context,
3524 gint x, y, width, height;
3526 get_progress_area (widget, &x, &y, &width, &height);
3528 if ((width <= 0) || (height <= 0))
3531 gtk_style_context_save (context);
3532 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3534 gtk_render_activity (context, cr,
3535 x, y, width, height);
3537 gtk_style_context_restore (context);
3541 gtk_entry_draw (GtkWidget *widget,
3544 GtkEntry *entry = GTK_ENTRY (widget);
3545 GtkStyleContext *context;
3546 GtkStateFlags state;
3547 GtkEntryPrivate *priv = entry->priv;
3550 context = gtk_widget_get_style_context (widget);
3551 state = gtk_widget_get_state_flags (widget);
3553 gtk_style_context_save (context);
3554 gtk_style_context_set_state (context, state);
3556 /* Draw entry_bg, shadow, progress and focus */
3557 gtk_entry_draw_frame (widget, context, cr);
3559 /* Draw text and cursor */
3562 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3564 if (priv->dnd_position != -1)
3565 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3567 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3569 /* When no text is being displayed at all, don't show the cursor */
3570 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3571 gtk_widget_has_focus (widget) &&
3572 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3573 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3578 for (i = 0; i < MAX_ICONS; i++)
3580 EntryIconInfo *icon_info = priv->icons[i];
3582 if (icon_info != NULL)
3586 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3588 draw_icon (widget, cr, i);
3594 gtk_style_context_restore (context);
3600 gtk_entry_enter_notify (GtkWidget *widget,
3601 GdkEventCrossing *event)
3603 GtkEntry *entry = GTK_ENTRY (widget);
3604 GtkEntryPrivate *priv = entry->priv;
3607 for (i = 0; i < MAX_ICONS; i++)
3609 EntryIconInfo *icon_info = priv->icons[i];
3611 if (icon_info != NULL && event->window == icon_info->window)
3613 if (should_prelight (entry, i))
3615 icon_info->prelight = TRUE;
3616 gtk_widget_queue_draw (widget);
3627 gtk_entry_leave_notify (GtkWidget *widget,
3628 GdkEventCrossing *event)
3630 GtkEntry *entry = GTK_ENTRY (widget);
3631 GtkEntryPrivate *priv = entry->priv;
3634 for (i = 0; i < MAX_ICONS; i++)
3636 EntryIconInfo *icon_info = priv->icons[i];
3638 if (icon_info != NULL && event->window == icon_info->window)
3640 /* a grab means that we may never see the button release */
3641 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3642 icon_info->pressed = FALSE;
3644 if (should_prelight (entry, i))
3646 icon_info->prelight = FALSE;
3647 gtk_widget_queue_draw (widget);
3658 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3662 gint start_char, end_char;
3664 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3666 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3667 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3668 const char *text = pango_layout_get_text (layout);
3669 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3670 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3671 gint real_n_ranges, i;
3673 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3679 for (i = 0; i < real_n_ranges; ++i)
3681 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3682 r[2 * i] = r[2 * i] / PANGO_SCALE;
3687 *n_ranges = real_n_ranges;
3699 in_selection (GtkEntry *entry,
3704 gint retval = FALSE;
3706 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3708 for (i = 0; i < n_ranges; ++i)
3710 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3722 gtk_entry_button_press (GtkWidget *widget,
3723 GdkEventButton *event)
3725 GtkEntry *entry = GTK_ENTRY (widget);
3726 GtkEditable *editable = GTK_EDITABLE (widget);
3727 GtkEntryPrivate *priv = entry->priv;
3728 EntryIconInfo *icon_info = NULL;
3730 gint sel_start, sel_end;
3733 for (i = 0; i < MAX_ICONS; i++)
3735 icon_info = priv->icons[i];
3737 if (!icon_info || icon_info->insensitive)
3740 if (event->window == icon_info->window)
3742 if (should_prelight (entry, i))
3744 icon_info->prelight = FALSE;
3745 gtk_widget_queue_draw (widget);
3748 priv->start_x = event->x;
3749 priv->start_y = event->y;
3750 icon_info->pressed = TRUE;
3752 if (!icon_info->nonactivatable)
3753 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3759 if (event->window != priv->text_area ||
3760 (priv->button && event->button != priv->button))
3763 gtk_entry_reset_blink_time (entry);
3765 priv->button = event->button;
3767 if (!gtk_widget_has_focus (widget))
3769 priv->in_click = TRUE;
3770 gtk_widget_grab_focus (widget);
3771 priv->in_click = FALSE;
3774 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3776 if (event->button == 1)
3778 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3780 priv->select_words = FALSE;
3781 priv->select_lines = FALSE;
3783 if (event->state & GDK_SHIFT_MASK)
3785 _gtk_entry_reset_im_context (entry);
3787 if (!have_selection) /* select from the current position to the clicked position */
3788 sel_start = sel_end = priv->current_pos;
3790 if (tmp_pos > sel_start && tmp_pos < sel_end)
3792 /* Truncate current selection, but keep it as big as possible */
3793 if (tmp_pos - sel_start > sel_end - tmp_pos)
3794 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3796 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3800 gboolean extend_to_left;
3803 /* Figure out what click selects and extend current selection */
3804 switch (event->type)
3806 case GDK_BUTTON_PRESS:
3807 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3810 case GDK_2BUTTON_PRESS:
3811 priv->select_words = TRUE;
3812 gtk_entry_select_word (entry);
3815 case GDK_3BUTTON_PRESS:
3816 priv->select_lines = TRUE;
3817 gtk_entry_select_line (entry);
3824 start = MIN (priv->current_pos, priv->selection_bound);
3825 start = MIN (sel_start, start);
3827 end = MAX (priv->current_pos, priv->selection_bound);
3828 end = MAX (sel_end, end);
3830 if (tmp_pos == sel_start || tmp_pos == sel_end)
3831 extend_to_left = (tmp_pos == start);
3833 extend_to_left = (end == sel_end);
3836 gtk_entry_set_positions (entry, start, end);
3838 gtk_entry_set_positions (entry, end, start);
3841 else /* no shift key */
3842 switch (event->type)
3844 case GDK_BUTTON_PRESS:
3845 if (in_selection (entry, event->x + priv->scroll_offset))
3847 /* Click inside the selection - we'll either start a drag, or
3848 * clear the selection
3850 priv->in_drag = TRUE;
3851 priv->drag_start_x = event->x + priv->scroll_offset;
3852 priv->drag_start_y = event->y;
3855 gtk_editable_set_position (editable, tmp_pos);
3858 case GDK_2BUTTON_PRESS:
3859 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3860 * receiving a GDK_2BUTTON_PRESS so we need to reset
3861 * priv->in_drag which may have been set above
3863 priv->in_drag = FALSE;
3864 priv->select_words = TRUE;
3865 gtk_entry_select_word (entry);
3868 case GDK_3BUTTON_PRESS:
3869 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3870 * receiving a GDK_3BUTTON_PRESS so we need to reset
3871 * priv->in_drag which may have been set above
3873 priv->in_drag = FALSE;
3874 priv->select_lines = TRUE;
3875 gtk_entry_select_line (entry);
3884 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3888 priv->insert_pos = tmp_pos;
3889 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3894 gtk_widget_error_bell (widget);
3897 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3899 gtk_entry_do_popup (entry, event);
3900 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3909 gtk_entry_button_release (GtkWidget *widget,
3910 GdkEventButton *event)
3912 GtkEntry *entry = GTK_ENTRY (widget);
3913 GtkEntryPrivate *priv = entry->priv;
3914 EntryIconInfo *icon_info = NULL;
3917 for (i = 0; i < MAX_ICONS; i++)
3919 icon_info = priv->icons[i];
3921 if (!icon_info || icon_info->insensitive)
3924 if (event->window == icon_info->window)
3926 icon_info->pressed = FALSE;
3928 if (should_prelight (entry, i) &&
3929 event->x >= 0 && event->y >= 0 &&
3930 event->x < gdk_window_get_width (icon_info->window) &&
3931 event->y < gdk_window_get_height (icon_info->window))
3933 icon_info->prelight = TRUE;
3934 gtk_widget_queue_draw (widget);
3937 if (!icon_info->nonactivatable)
3938 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3944 if (event->window != priv->text_area || priv->button != event->button)
3949 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3951 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3958 gtk_entry_update_primary_selection (entry);
3964 _gtk_entry_get_selected_text (GtkEntry *entry)
3966 GtkEditable *editable = GTK_EDITABLE (entry);
3967 gint start_text, end_text;
3970 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3971 text = gtk_editable_get_chars (editable, start_text, end_text);
3977 gtk_entry_motion_notify (GtkWidget *widget,
3978 GdkEventMotion *event)
3980 GtkEntry *entry = GTK_ENTRY (widget);
3981 GtkEntryPrivate *priv = entry->priv;
3982 EntryIconInfo *icon_info = NULL;
3986 for (i = 0; i < MAX_ICONS; i++)
3988 icon_info = priv->icons[i];
3990 if (!icon_info || icon_info->insensitive)
3993 if (event->window == icon_info->window)
3995 if (icon_info->pressed &&
3996 icon_info->target_list != NULL &&
3997 gtk_drag_check_threshold (widget,
4003 icon_info->in_drag = TRUE;
4004 icon_info->pressed = FALSE;
4005 gtk_drag_begin (widget,
4006 icon_info->target_list,
4016 if (priv->mouse_cursor_obscured)
4020 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4021 gdk_window_set_cursor (priv->text_area, cursor);
4022 g_object_unref (cursor);
4023 priv->mouse_cursor_obscured = FALSE;
4026 if (event->window != priv->text_area || priv->button != 1)
4029 if (priv->select_lines)
4032 gdk_event_request_motions (event);
4036 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4037 gtk_drag_check_threshold (widget,
4038 priv->drag_start_x, priv->drag_start_y,
4039 event->x + priv->scroll_offset, event->y))
4041 GdkDragContext *context;
4042 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4043 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4045 cairo_surface_t *surface;
4047 gtk_target_list_add_text_targets (target_list, 0);
4049 text = _gtk_entry_get_selected_text (entry);
4050 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4052 context = gtk_drag_begin (widget, target_list, actions,
4053 priv->button, (GdkEvent *)event);
4056 gtk_drag_set_icon_surface (context, surface);
4058 gtk_drag_set_icon_default (context);
4061 cairo_surface_destroy (surface);
4064 priv->in_drag = FALSE;
4067 gtk_target_list_unref (target_list);
4074 else if (event->y >= gdk_window_get_height (priv->text_area))
4075 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4077 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4079 if (priv->select_words)
4082 gint old_min, old_max;
4085 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4086 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4088 pos = priv->current_pos;
4089 bound = priv->selection_bound;
4091 old_min = MIN(priv->current_pos, priv->selection_bound);
4092 old_max = MAX(priv->current_pos, priv->selection_bound);
4099 else if (old_max < max)
4104 else if (pos == old_min)
4106 if (priv->current_pos != min)
4111 if (priv->current_pos != max)
4115 gtk_entry_set_positions (entry, pos, bound);
4118 gtk_entry_set_positions (entry, tmp_pos, -1);
4125 set_invisible_cursor (GdkWindow *window)
4127 GdkDisplay *display;
4130 display = gdk_window_get_display (window);
4131 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4133 gdk_window_set_cursor (window, cursor);
4135 g_object_unref (cursor);
4139 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4141 GtkEntryPrivate *priv = entry->priv;
4143 if (priv->mouse_cursor_obscured)
4146 set_invisible_cursor (priv->text_area);
4148 priv->mouse_cursor_obscured = TRUE;
4152 gtk_entry_key_press (GtkWidget *widget,
4155 GtkEntry *entry = GTK_ENTRY (widget);
4156 GtkEntryPrivate *priv = entry->priv;
4158 gtk_entry_reset_blink_time (entry);
4159 gtk_entry_pend_cursor_blink (entry);
4163 if (gtk_im_context_filter_keypress (priv->im_context, event))
4165 gtk_entry_obscure_mouse_cursor (entry);
4166 priv->need_im_reset = TRUE;
4171 if (event->keyval == GDK_KEY_Return ||
4172 event->keyval == GDK_KEY_KP_Enter ||
4173 event->keyval == GDK_KEY_ISO_Enter ||
4174 event->keyval == GDK_KEY_Escape)
4176 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4178 if (completion && completion->priv->completion_timeout)
4180 g_source_remove (completion->priv->completion_timeout);
4181 completion->priv->completion_timeout = 0;
4184 _gtk_entry_reset_im_context (entry);
4187 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4188 /* Activate key bindings
4192 if (!priv->editable && event->length)
4193 gtk_widget_error_bell (widget);
4199 gtk_entry_key_release (GtkWidget *widget,
4202 GtkEntry *entry = GTK_ENTRY (widget);
4203 GtkEntryPrivate *priv = entry->priv;
4207 if (gtk_im_context_filter_keypress (priv->im_context, event))
4209 priv->need_im_reset = TRUE;
4214 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4218 gtk_entry_focus_in (GtkWidget *widget,
4219 GdkEventFocus *event)
4221 GtkEntry *entry = GTK_ENTRY (widget);
4222 GtkEntryPrivate *priv = entry->priv;
4225 gtk_widget_queue_draw (widget);
4227 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4231 priv->need_im_reset = TRUE;
4232 gtk_im_context_focus_in (priv->im_context);
4233 keymap_state_changed (keymap, entry);
4234 g_signal_connect (keymap, "state-changed",
4235 G_CALLBACK (keymap_state_changed), entry);
4238 g_signal_connect (keymap, "direction-changed",
4239 G_CALLBACK (keymap_direction_changed), entry);
4241 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4242 priv->placeholder_text != NULL)
4244 gtk_entry_recompute (entry);
4248 gtk_entry_reset_blink_time (entry);
4249 gtk_entry_check_cursor_blink (entry);
4256 gtk_entry_focus_out (GtkWidget *widget,
4257 GdkEventFocus *event)
4259 GtkEntry *entry = GTK_ENTRY (widget);
4260 GtkEntryPrivate *priv = entry->priv;
4261 GtkEntryCompletion *completion;
4264 gtk_widget_queue_draw (widget);
4266 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4270 priv->need_im_reset = TRUE;
4271 gtk_im_context_focus_out (priv->im_context);
4272 remove_capslock_feedback (entry);
4275 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4276 priv->placeholder_text != NULL)
4278 gtk_entry_recompute (entry);
4282 gtk_entry_check_cursor_blink (entry);
4285 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4286 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4288 completion = gtk_entry_get_completion (entry);
4290 _gtk_entry_completion_popdown (completion);
4296 gtk_entry_grab_focus (GtkWidget *widget)
4298 GtkEntry *entry = GTK_ENTRY (widget);
4299 GtkEntryPrivate *priv = entry->priv;
4300 gboolean select_on_focus;
4302 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4304 if (priv->editable && !priv->in_click)
4306 g_object_get (gtk_widget_get_settings (widget),
4307 "gtk-entry-select-on-focus",
4311 if (select_on_focus)
4312 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4317 gtk_entry_direction_changed (GtkWidget *widget,
4318 GtkTextDirection previous_dir)
4320 GtkEntry *entry = GTK_ENTRY (widget);
4322 gtk_entry_recompute (entry);
4324 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4328 gtk_entry_state_flags_changed (GtkWidget *widget,
4329 GtkStateFlags previous_state)
4331 GtkEntry *entry = GTK_ENTRY (widget);
4332 GtkEntryPrivate *priv = entry->priv;
4335 if (gtk_widget_get_realized (widget))
4337 if (gtk_widget_is_sensitive (widget))
4338 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4342 gdk_window_set_cursor (priv->text_area, cursor);
4345 g_object_unref (cursor);
4347 priv->mouse_cursor_obscured = FALSE;
4349 update_cursors (widget);
4352 if (!gtk_widget_is_sensitive (widget))
4354 /* Clear any selection */
4355 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4358 gtk_entry_update_cached_style_values (entry);
4362 gtk_entry_screen_changed (GtkWidget *widget,
4363 GdkScreen *old_screen)
4365 gtk_entry_recompute (GTK_ENTRY (widget));
4368 /* GtkEditable method implementations
4371 gtk_entry_insert_text (GtkEditable *editable,
4372 const gchar *new_text,
4373 gint new_text_length,
4376 g_object_ref (editable);
4379 * The incoming text may a password or other secret. We make sure
4380 * not to copy it into temporary buffers.
4383 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4385 g_object_unref (editable);
4389 gtk_entry_delete_text (GtkEditable *editable,
4393 g_object_ref (editable);
4395 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4397 g_object_unref (editable);
4401 gtk_entry_get_chars (GtkEditable *editable,
4405 GtkEntry *entry = GTK_ENTRY (editable);
4408 gint start_index, end_index;
4410 text = gtk_entry_buffer_get_text (get_buffer (entry));
4411 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4414 end_pos = text_length;
4416 start_pos = MIN (text_length, start_pos);
4417 end_pos = MIN (text_length, end_pos);
4419 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4420 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4422 return g_strndup (text + start_index, end_index - start_index);
4426 gtk_entry_real_set_position (GtkEditable *editable,
4429 GtkEntry *entry = GTK_ENTRY (editable);
4430 GtkEntryPrivate *priv = entry->priv;
4434 length = gtk_entry_buffer_get_length (get_buffer (entry));
4435 if (position < 0 || position > length)
4438 if (position != priv->current_pos ||
4439 position != priv->selection_bound)
4441 _gtk_entry_reset_im_context (entry);
4442 gtk_entry_set_positions (entry, position, position);
4447 gtk_entry_get_position (GtkEditable *editable)
4449 GtkEntry *entry = GTK_ENTRY (editable);
4450 GtkEntryPrivate *priv = entry->priv;
4452 return priv->current_pos;
4456 gtk_entry_set_selection_bounds (GtkEditable *editable,
4460 GtkEntry *entry = GTK_ENTRY (editable);
4463 length = gtk_entry_buffer_get_length (get_buffer (entry));
4469 _gtk_entry_reset_im_context (entry);
4471 gtk_entry_set_positions (entry,
4473 MIN (start, length));
4475 gtk_entry_update_primary_selection (entry);
4479 gtk_entry_get_selection_bounds (GtkEditable *editable,
4483 GtkEntry *entry = GTK_ENTRY (editable);
4484 GtkEntryPrivate *priv = entry->priv;
4486 *start = priv->selection_bound;
4487 *end = priv->current_pos;
4489 return (priv->selection_bound != priv->current_pos);
4493 icon_theme_changed (GtkEntry *entry)
4495 GtkEntryPrivate *priv = entry->priv;
4498 for (i = 0; i < MAX_ICONS; i++)
4500 EntryIconInfo *icon_info = priv->icons[i];
4501 if (icon_info != NULL)
4503 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4504 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4505 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4506 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4507 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4508 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4512 gtk_widget_queue_draw (GTK_WIDGET (entry));
4516 icon_margin_changed (GtkEntry *entry)
4518 GtkEntryPrivate *priv = entry->priv;
4521 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4523 priv->icon_margin = border.left;
4527 gtk_entry_update_cached_style_values (GtkEntry *entry)
4529 GtkEntryPrivate *priv = entry->priv;
4531 gboolean interior_focus;
4533 gtk_widget_style_get (GTK_WIDGET (entry),
4534 "focus-line-width", &focus_width,
4535 "interior-focus", &interior_focus,
4537 priv->focus_width = focus_width;
4538 priv->interior_focus = interior_focus;
4540 if (!priv->invisible_char_set)
4542 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4544 if (priv->invisible_char != ch)
4546 priv->invisible_char = ch;
4547 g_object_notify (G_OBJECT (entry), "invisible-char");
4553 gtk_entry_style_updated (GtkWidget *widget)
4555 GtkEntry *entry = GTK_ENTRY (widget);
4557 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4559 gtk_entry_update_cached_style_values (entry);
4561 gtk_entry_recompute (entry);
4563 icon_theme_changed (entry);
4564 icon_margin_changed (entry);
4567 /* GtkCellEditable method implementations
4570 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4572 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4573 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4577 gtk_cell_editable_key_press_event (GtkEntry *entry,
4578 GdkEventKey *key_event,
4581 GtkEntryPrivate *priv = entry->priv;
4583 if (key_event->keyval == GDK_KEY_Escape)
4585 priv->editing_canceled = TRUE;
4586 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4587 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4592 /* override focus */
4593 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4595 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4596 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4605 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4608 GtkEntry *entry = GTK_ENTRY (cell_editable);
4609 GtkEntryPrivate *priv = entry->priv;
4611 priv->is_cell_renderer = TRUE;
4613 g_signal_connect (cell_editable, "activate",
4614 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4615 g_signal_connect (cell_editable, "key-press-event",
4616 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4620 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4622 if (password_hint->source_id)
4623 g_source_remove (password_hint->source_id);
4625 g_slice_free (GtkEntryPasswordHint, password_hint);
4630 gtk_entry_remove_password_hint (gpointer data)
4632 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4633 password_hint->position = -1;
4635 /* Force the string to be redrawn, but now without a visible character */
4636 gtk_entry_recompute (GTK_ENTRY (data));
4640 /* Default signal handlers
4643 gtk_entry_real_insert_text (GtkEditable *editable,
4644 const gchar *new_text,
4645 gint new_text_length,
4651 n_chars = g_utf8_strlen (new_text, new_text_length);
4654 * The actual insertion into the buffer. This will end up firing the
4655 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4656 * buffer_notify_text(), buffer_notify_length()
4658 begin_change (GTK_ENTRY (editable));
4659 g_object_freeze_notify (G_OBJECT (editable));
4661 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4663 g_object_thaw_notify (G_OBJECT (editable));
4664 end_change (GTK_ENTRY (editable));
4666 if (n_inserted != n_chars)
4667 gtk_widget_error_bell (GTK_WIDGET (editable));
4669 *position += n_inserted;
4673 gtk_entry_real_delete_text (GtkEditable *editable,
4678 * The actual deletion from the buffer. This will end up firing the
4679 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4680 * buffer_notify_text(), buffer_notify_length()
4683 begin_change (GTK_ENTRY (editable));
4684 g_object_freeze_notify (G_OBJECT (editable));
4685 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4686 g_object_thaw_notify (G_OBJECT (editable));
4687 end_change (GTK_ENTRY (editable));
4690 /* GtkEntryBuffer signal handlers
4693 buffer_inserted_text (GtkEntryBuffer *buffer,
4699 GtkEntryPrivate *priv = entry->priv;
4700 guint password_hint_timeout;
4702 gint selection_bound;
4704 current_pos = priv->current_pos;
4705 if (current_pos > position)
4706 current_pos += n_chars;
4708 selection_bound = priv->selection_bound;
4709 if (selection_bound > position)
4710 selection_bound += n_chars;
4712 gtk_entry_set_positions (entry, current_pos, selection_bound);
4714 /* Calculate the password hint if it needs to be displayed. */
4715 if (n_chars == 1 && !priv->visible)
4717 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4718 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4721 if (password_hint_timeout > 0)
4723 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4724 quark_password_hint);
4727 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4728 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4729 (GDestroyNotify)gtk_entry_password_hint_free);
4732 password_hint->position = position;
4733 if (password_hint->source_id)
4734 g_source_remove (password_hint->source_id);
4735 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4736 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4742 buffer_deleted_text (GtkEntryBuffer *buffer,
4747 GtkEntryPrivate *priv = entry->priv;
4748 guint end_pos = position + n_chars;
4749 gint selection_bound;
4752 current_pos = priv->current_pos;
4753 if (current_pos > position)
4754 current_pos -= MIN (current_pos, end_pos) - position;
4756 selection_bound = priv->selection_bound;
4757 if (selection_bound > position)
4758 selection_bound -= MIN (selection_bound, end_pos) - position;
4760 gtk_entry_set_positions (entry, current_pos, selection_bound);
4762 /* We might have deleted the selection */
4763 gtk_entry_update_primary_selection (entry);
4765 /* Disable the password hint if one exists. */
4768 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4769 quark_password_hint);
4772 if (password_hint->source_id)
4773 g_source_remove (password_hint->source_id);
4774 password_hint->source_id = 0;
4775 password_hint->position = -1;
4781 buffer_notify_text (GtkEntryBuffer *buffer,
4785 gtk_entry_recompute (entry);
4786 emit_changed (entry);
4787 g_object_notify (G_OBJECT (entry), "text");
4791 buffer_notify_length (GtkEntryBuffer *buffer,
4795 g_object_notify (G_OBJECT (entry), "text-length");
4799 buffer_notify_max_length (GtkEntryBuffer *buffer,
4803 g_object_notify (G_OBJECT (entry), "max-length");
4807 buffer_connect_signals (GtkEntry *entry)
4809 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4810 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4811 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4812 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4813 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4817 buffer_disconnect_signals (GtkEntry *entry)
4819 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4820 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4821 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4822 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4823 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4826 /* Compute the X position for an offset that corresponds to the "more important
4827 * cursor position for that offset. We use this when trying to guess to which
4828 * end of the selection we should go to when the user hits the left or
4832 get_better_cursor_x (GtkEntry *entry,
4835 GtkEntryPrivate *priv = entry->priv;
4836 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4837 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4838 gboolean split_cursor;
4840 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4841 const gchar *text = pango_layout_get_text (layout);
4842 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4844 PangoRectangle strong_pos, weak_pos;
4846 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4847 "gtk-split-cursor", &split_cursor,
4850 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4853 return strong_pos.x / PANGO_SCALE;
4855 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4859 gtk_entry_move_cursor (GtkEntry *entry,
4860 GtkMovementStep step,
4862 gboolean extend_selection)
4864 GtkEntryPrivate *priv = entry->priv;
4865 gint new_pos = priv->current_pos;
4867 _gtk_entry_reset_im_context (entry);
4869 if (priv->current_pos != priv->selection_bound && !extend_selection)
4871 /* If we have a current selection and aren't extending it, move to the
4872 * start/or end of the selection as appropriate
4876 case GTK_MOVEMENT_VISUAL_POSITIONS:
4878 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4879 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4882 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4884 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4887 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4888 case GTK_MOVEMENT_WORDS:
4890 new_pos = MIN (priv->current_pos, priv->selection_bound);
4892 new_pos = MAX (priv->current_pos, priv->selection_bound);
4894 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4895 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4896 case GTK_MOVEMENT_BUFFER_ENDS:
4897 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4899 case GTK_MOVEMENT_DISPLAY_LINES:
4900 case GTK_MOVEMENT_PARAGRAPHS:
4901 case GTK_MOVEMENT_PAGES:
4902 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4910 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4911 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4913 case GTK_MOVEMENT_VISUAL_POSITIONS:
4914 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4915 if (priv->current_pos == new_pos)
4917 if (!extend_selection)
4919 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4921 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4923 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4926 gtk_widget_child_focus (toplevel,
4928 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4933 gtk_widget_error_bell (GTK_WIDGET (entry));
4937 case GTK_MOVEMENT_WORDS:
4940 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4945 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4948 if (priv->current_pos == new_pos)
4949 gtk_widget_error_bell (GTK_WIDGET (entry));
4951 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4952 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4953 case GTK_MOVEMENT_BUFFER_ENDS:
4954 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4955 if (priv->current_pos == new_pos)
4956 gtk_widget_error_bell (GTK_WIDGET (entry));
4958 case GTK_MOVEMENT_DISPLAY_LINES:
4959 case GTK_MOVEMENT_PARAGRAPHS:
4960 case GTK_MOVEMENT_PAGES:
4961 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4966 if (extend_selection)
4967 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4969 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4971 gtk_entry_pend_cursor_blink (entry);
4975 gtk_entry_insert_at_cursor (GtkEntry *entry,
4978 GtkEntryPrivate *priv = entry->priv;
4979 GtkEditable *editable = GTK_EDITABLE (entry);
4980 gint pos = priv->current_pos;
4984 _gtk_entry_reset_im_context (entry);
4986 gtk_editable_insert_text (editable, str, -1, &pos);
4987 gtk_editable_set_position (editable, pos);
4992 gtk_entry_delete_from_cursor (GtkEntry *entry,
4996 GtkEntryPrivate *priv = entry->priv;
4997 GtkEditable *editable = GTK_EDITABLE (entry);
4998 gint start_pos = priv->current_pos;
4999 gint end_pos = priv->current_pos;
5000 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5002 _gtk_entry_reset_im_context (entry);
5004 if (!priv->editable)
5006 gtk_widget_error_bell (GTK_WIDGET (entry));
5010 if (priv->selection_bound != priv->current_pos)
5012 gtk_editable_delete_selection (editable);
5018 case GTK_DELETE_CHARS:
5019 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5020 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5022 case GTK_DELETE_WORDS:
5025 /* Move to end of current word, or if not on a word, end of previous word */
5026 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5027 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5031 /* Move to beginning of current word, or if not on a word, begining of next word */
5032 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5033 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5037 case GTK_DELETE_WORD_ENDS:
5040 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5045 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5048 gtk_editable_delete_text (editable, start_pos, end_pos);
5050 case GTK_DELETE_DISPLAY_LINE_ENDS:
5051 case GTK_DELETE_PARAGRAPH_ENDS:
5053 gtk_editable_delete_text (editable, 0, priv->current_pos);
5055 gtk_editable_delete_text (editable, priv->current_pos, -1);
5057 case GTK_DELETE_DISPLAY_LINES:
5058 case GTK_DELETE_PARAGRAPHS:
5059 gtk_editable_delete_text (editable, 0, -1);
5061 case GTK_DELETE_WHITESPACE:
5062 gtk_entry_delete_whitespace (entry);
5066 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5067 gtk_widget_error_bell (GTK_WIDGET (entry));
5069 gtk_entry_pend_cursor_blink (entry);
5073 gtk_entry_backspace (GtkEntry *entry)
5075 GtkEntryPrivate *priv = entry->priv;
5076 GtkEditable *editable = GTK_EDITABLE (entry);
5079 _gtk_entry_reset_im_context (entry);
5081 if (!priv->editable)
5083 gtk_widget_error_bell (GTK_WIDGET (entry));
5087 if (priv->selection_bound != priv->current_pos)
5089 gtk_editable_delete_selection (editable);
5093 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5095 if (prev_pos < priv->current_pos)
5097 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5098 PangoLogAttr *log_attrs;
5101 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5103 /* Deleting parts of characters */
5104 if (log_attrs[priv->current_pos].backspace_deletes_character)
5106 gchar *cluster_text;
5107 gchar *normalized_text;
5110 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5112 normalized_text = g_utf8_normalize (cluster_text,
5113 strlen (cluster_text),
5115 len = g_utf8_strlen (normalized_text, -1);
5117 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5120 gint pos = priv->current_pos;
5122 gtk_editable_insert_text (editable, normalized_text,
5123 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5125 gtk_editable_set_position (editable, pos);
5128 g_free (normalized_text);
5129 g_free (cluster_text);
5133 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5140 gtk_widget_error_bell (GTK_WIDGET (entry));
5143 gtk_entry_pend_cursor_blink (entry);
5147 gtk_entry_copy_clipboard (GtkEntry *entry)
5149 GtkEntryPrivate *priv = entry->priv;
5150 GtkEditable *editable = GTK_EDITABLE (entry);
5154 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5158 gtk_widget_error_bell (GTK_WIDGET (entry));
5162 str = gtk_entry_get_display_text (entry, start, end);
5163 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5164 GDK_SELECTION_CLIPBOARD),
5171 gtk_entry_cut_clipboard (GtkEntry *entry)
5173 GtkEntryPrivate *priv = entry->priv;
5174 GtkEditable *editable = GTK_EDITABLE (entry);
5179 gtk_widget_error_bell (GTK_WIDGET (entry));
5183 gtk_entry_copy_clipboard (entry);
5187 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5188 gtk_editable_delete_text (editable, start, end);
5192 gtk_widget_error_bell (GTK_WIDGET (entry));
5197 gtk_entry_paste_clipboard (GtkEntry *entry)
5199 GtkEntryPrivate *priv = entry->priv;
5202 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5204 gtk_widget_error_bell (GTK_WIDGET (entry));
5208 gtk_entry_delete_cb (GtkEntry *entry)
5210 GtkEntryPrivate *priv = entry->priv;
5211 GtkEditable *editable = GTK_EDITABLE (entry);
5216 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5217 gtk_editable_delete_text (editable, start, end);
5222 gtk_entry_toggle_overwrite (GtkEntry *entry)
5224 GtkEntryPrivate *priv = entry->priv;
5226 priv->overwrite_mode = !priv->overwrite_mode;
5227 gtk_entry_pend_cursor_blink (entry);
5228 gtk_widget_queue_draw (GTK_WIDGET (entry));
5232 gtk_entry_select_all (GtkEntry *entry)
5234 gtk_entry_select_line (entry);
5238 gtk_entry_real_activate (GtkEntry *entry)
5240 GtkEntryPrivate *priv = entry->priv;
5242 GtkWidget *default_widget, *focus_widget;
5243 GtkWidget *toplevel;
5246 widget = GTK_WIDGET (entry);
5248 if (priv->activates_default)
5250 toplevel = gtk_widget_get_toplevel (widget);
5251 if (GTK_IS_WINDOW (toplevel))
5253 window = GTK_WINDOW (toplevel);
5257 default_widget = gtk_window_get_default_widget (window);
5258 focus_widget = gtk_window_get_focus (window);
5259 if (widget != default_widget &&
5260 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5261 gtk_window_activate_default (window);
5268 keymap_direction_changed (GdkKeymap *keymap,
5271 gtk_entry_recompute (entry);
5274 /* IM Context Callbacks
5278 gtk_entry_commit_cb (GtkIMContext *context,
5282 GtkEntryPrivate *priv = entry->priv;
5285 gtk_entry_enter_text (entry, str);
5289 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5292 GtkEntryPrivate *priv = entry->priv;
5296 gchar *preedit_string;
5299 gtk_im_context_get_preedit_string (priv->im_context,
5300 &preedit_string, NULL,
5302 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5303 priv->preedit_length = strlen (preedit_string);
5304 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5305 priv->preedit_cursor = cursor_pos;
5306 g_free (preedit_string);
5308 gtk_entry_recompute (entry);
5313 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5316 GtkEntryPrivate *priv = entry->priv;
5319 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5320 text = gtk_entry_get_display_text (entry, 0, -1);
5321 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5322 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5329 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5334 GtkEntryPrivate *priv = entry->priv;
5337 gtk_editable_delete_text (GTK_EDITABLE (entry),
5338 priv->current_pos + offset,
5339 priv->current_pos + offset + n_chars);
5344 /* Internal functions
5347 /* Used for im_commit_cb and inserting Unicode chars */
5349 gtk_entry_enter_text (GtkEntry *entry,
5352 GtkEntryPrivate *priv = entry->priv;
5353 GtkEditable *editable = GTK_EDITABLE (entry);
5355 gboolean old_need_im_reset;
5357 old_need_im_reset = priv->need_im_reset;
5358 priv->need_im_reset = FALSE;
5360 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5361 gtk_editable_delete_selection (editable);
5364 if (priv->overwrite_mode)
5365 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5368 tmp_pos = priv->current_pos;
5369 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5370 gtk_editable_set_position (editable, tmp_pos);
5372 priv->need_im_reset = old_need_im_reset;
5375 /* All changes to priv->current_pos and priv->selection_bound
5376 * should go through this function.
5379 gtk_entry_set_positions (GtkEntry *entry,
5381 gint selection_bound)
5383 GtkEntryPrivate *priv = entry->priv;
5384 gboolean changed = FALSE;
5386 g_object_freeze_notify (G_OBJECT (entry));
5388 if (current_pos != -1 &&
5389 priv->current_pos != current_pos)
5391 priv->current_pos = current_pos;
5394 g_object_notify (G_OBJECT (entry), "cursor-position");
5397 if (selection_bound != -1 &&
5398 priv->selection_bound != selection_bound)
5400 priv->selection_bound = selection_bound;
5403 g_object_notify (G_OBJECT (entry), "selection-bound");
5406 g_object_thaw_notify (G_OBJECT (entry));
5410 gtk_entry_move_adjustments (entry);
5411 gtk_entry_recompute (entry);
5416 gtk_entry_reset_layout (GtkEntry *entry)
5418 GtkEntryPrivate *priv = entry->priv;
5420 if (priv->cached_layout)
5422 g_object_unref (priv->cached_layout);
5423 priv->cached_layout = NULL;
5428 update_im_cursor_location (GtkEntry *entry)
5430 GtkEntryPrivate *priv = entry->priv;
5433 gint strong_xoffset;
5434 gint area_width, area_height;
5436 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5437 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5439 strong_xoffset = strong_x - priv->scroll_offset;
5440 if (strong_xoffset < 0)
5444 else if (strong_xoffset > area_width)
5446 strong_xoffset = area_width;
5448 area.x = strong_xoffset;
5451 area.height = area_height;
5453 gtk_im_context_set_cursor_location (priv->im_context, &area);
5457 recompute_idle_func (gpointer data)
5459 GtkEntry *entry = GTK_ENTRY (data);
5460 GtkEntryPrivate *priv = entry->priv;
5462 priv->recompute_idle = 0;
5464 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5466 gtk_entry_adjust_scroll (entry);
5467 gtk_widget_queue_draw (GTK_WIDGET (entry));
5469 update_im_cursor_location (entry);
5476 gtk_entry_recompute (GtkEntry *entry)
5478 GtkEntryPrivate *priv = entry->priv;
5480 gtk_entry_reset_layout (entry);
5481 gtk_entry_check_cursor_blink (entry);
5483 if (!priv->recompute_idle)
5485 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5486 recompute_idle_func, entry, NULL);
5491 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5494 GtkWidget *widget = GTK_WIDGET (entry);
5495 GtkStyleContext *context;
5496 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5498 context = gtk_widget_get_style_context (widget);
5499 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5501 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5502 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5503 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5506 static inline gboolean
5507 show_placeholder_text (GtkEntry *entry)
5509 GtkEntryPrivate *priv = entry->priv;
5511 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5512 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5513 priv->placeholder_text != NULL)
5519 static PangoLayout *
5520 gtk_entry_create_layout (GtkEntry *entry,
5521 gboolean include_preedit)
5523 GtkEntryPrivate *priv = entry->priv;
5524 GtkWidget *widget = GTK_WIDGET (entry);
5525 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5526 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5527 gboolean placeholder_layout = show_placeholder_text (entry);
5529 gchar *preedit_string = NULL;
5530 gint preedit_length = 0;
5531 PangoAttrList *preedit_attrs = NULL;
5536 pango_layout_set_single_paragraph_mode (layout, TRUE);
5538 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5539 n_bytes = strlen (display);
5541 if (!placeholder_layout && include_preedit)
5543 gtk_im_context_get_preedit_string (priv->im_context,
5544 &preedit_string, &preedit_attrs, NULL);
5545 preedit_length = priv->preedit_length;
5547 else if (placeholder_layout)
5550 PangoAttribute *attr;
5552 gtk_entry_get_placeholder_text_color (entry, &color);
5553 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5554 attr->start_index = 0;
5555 attr->end_index = G_MAXINT;
5556 pango_attr_list_insert (tmp_attrs, attr);
5561 GString *tmp_string = g_string_new (display);
5562 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5564 g_string_insert (tmp_string, cursor_index, preedit_string);
5566 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5568 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5569 cursor_index, preedit_length);
5571 g_string_free (tmp_string, TRUE);
5575 PangoDirection pango_dir;
5577 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5578 pango_dir = pango_find_base_dir (display, n_bytes);
5580 pango_dir = PANGO_DIRECTION_NEUTRAL;
5582 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5584 if (gtk_widget_has_focus (widget))
5586 GdkDisplay *display = gtk_widget_get_display (widget);
5587 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5588 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5589 pango_dir = PANGO_DIRECTION_RTL;
5591 pango_dir = PANGO_DIRECTION_LTR;
5595 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5596 pango_dir = PANGO_DIRECTION_RTL;
5598 pango_dir = PANGO_DIRECTION_LTR;
5602 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5605 priv->resolved_dir = pango_dir;
5607 pango_layout_set_text (layout, display, n_bytes);
5610 pango_layout_set_attributes (layout, tmp_attrs);
5612 g_free (preedit_string);
5616 pango_attr_list_unref (preedit_attrs);
5618 pango_attr_list_unref (tmp_attrs);
5623 static PangoLayout *
5624 gtk_entry_ensure_layout (GtkEntry *entry,
5625 gboolean include_preedit)
5627 GtkEntryPrivate *priv = entry->priv;
5629 if (priv->preedit_length > 0 &&
5630 !include_preedit != !priv->cache_includes_preedit)
5631 gtk_entry_reset_layout (entry);
5633 if (!priv->cached_layout)
5635 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5636 priv->cache_includes_preedit = include_preedit;
5639 return priv->cached_layout;
5643 get_layout_position (GtkEntry *entry,
5647 GtkEntryPrivate *priv = entry->priv;
5648 PangoLayout *layout;
5649 PangoRectangle logical_rect;
5650 gint area_width, area_height;
5651 GtkBorder inner_border;
5653 PangoLayoutLine *line;
5655 layout = gtk_entry_ensure_layout (entry, TRUE);
5657 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5658 _gtk_entry_effective_inner_border (entry, &inner_border);
5660 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5662 line = pango_layout_get_lines_readonly (layout)->data;
5663 pango_layout_line_get_extents (line, NULL, &logical_rect);
5665 /* Align primarily for locale's ascent/descent */
5666 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5667 priv->ascent + logical_rect.y);
5669 /* Now see if we need to adjust to fit in actual drawn string */
5670 if (logical_rect.height > area_height)
5671 y_pos = (area_height - logical_rect.height) / 2;
5674 else if (y_pos + logical_rect.height > area_height)
5675 y_pos = area_height - logical_rect.height;
5677 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5680 *x = inner_border.left - priv->scroll_offset;
5687 draw_text_with_color (GtkEntry *entry,
5689 GdkRGBA *default_color)
5691 GtkEntryPrivate *priv = entry->priv;
5692 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5695 gint start_pos, end_pos;
5697 widget = GTK_WIDGET (entry);
5701 get_layout_position (entry, &x, &y);
5703 cairo_move_to (cr, x, y);
5704 gdk_cairo_set_source_rgba (cr, default_color);
5705 pango_cairo_show_layout (cr, layout);
5707 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5711 PangoRectangle logical_rect;
5712 GdkRGBA selection_color, text_color;
5713 GtkBorder inner_border;
5714 GtkStyleContext *context;
5715 GtkStateFlags state;
5717 context = gtk_widget_get_style_context (widget);
5718 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5719 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5721 state = GTK_STATE_FLAG_SELECTED;
5723 if (gtk_widget_has_focus (widget))
5724 state |= GTK_STATE_FLAG_FOCUSED;
5726 gtk_style_context_get_background_color (context, state, &selection_color);
5727 gtk_style_context_get_color (context, state, &text_color);
5729 _gtk_entry_effective_inner_border (entry, &inner_border);
5731 for (i = 0; i < n_ranges; ++i)
5732 cairo_rectangle (cr,
5733 inner_border.left - priv->scroll_offset + ranges[2 * i],
5736 logical_rect.height);
5740 gdk_cairo_set_source_rgba (cr, &selection_color);
5743 cairo_move_to (cr, x, y);
5744 gdk_cairo_set_source_rgba (cr, &text_color);
5745 pango_cairo_show_layout (cr, layout);
5753 gtk_entry_draw_text (GtkEntry *entry,
5756 GtkEntryPrivate *priv = entry->priv;
5757 GtkWidget *widget = GTK_WIDGET (entry);
5758 GtkStateFlags state = 0;
5759 GdkRGBA text_color, bar_text_color;
5760 GtkStyleContext *context;
5762 gint progress_x, progress_y, progress_width, progress_height;
5763 gint clip_width, clip_height;
5765 /* Nothing to display at all */
5766 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5769 state = gtk_widget_get_state_flags (widget);
5770 context = gtk_widget_get_style_context (widget);
5772 gtk_style_context_get_color (context, state, &text_color);
5774 /* Get foreground color for progressbars */
5775 gtk_style_context_save (context);
5776 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5777 gtk_style_context_get_color (context, state, &bar_text_color);
5778 gtk_style_context_restore (context);
5780 get_progress_area (widget,
5781 &progress_x, &progress_y,
5782 &progress_width, &progress_height);
5786 clip_width = gdk_window_get_width (priv->text_area);
5787 clip_height = gdk_window_get_height (priv->text_area);
5788 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5791 /* If the color is the same, or the progress area has a zero
5792 * size, then we only need to draw once. */
5793 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5794 ((progress_width == 0) || (progress_height == 0)))
5796 draw_text_with_color (entry, cr, &text_color);
5800 int frame_x, frame_y, area_x, area_y;
5802 width = gdk_window_get_width (priv->text_area);
5803 height = gdk_window_get_height (priv->text_area);
5807 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5808 cairo_rectangle (cr, 0, 0, width, height);
5810 /* progres area is frame-relative, we need it text-area window
5812 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5813 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5814 progress_x += frame_x - area_x;
5815 progress_y += frame_y - area_y;
5817 cairo_rectangle (cr, progress_x, progress_y,
5818 progress_width, progress_height);
5820 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5822 draw_text_with_color (entry, cr, &text_color);
5827 cairo_rectangle (cr, progress_x, progress_y,
5828 progress_width, progress_height);
5831 draw_text_with_color (entry, cr, &bar_text_color);
5840 draw_insertion_cursor (GtkEntry *entry,
5842 GdkRectangle *cursor_location,
5843 gboolean is_primary,
5844 PangoDirection direction,
5845 gboolean draw_arrow)
5847 GtkWidget *widget = GTK_WIDGET (entry);
5848 GtkTextDirection text_dir;
5850 if (direction == PANGO_DIRECTION_LTR)
5851 text_dir = GTK_TEXT_DIR_LTR;
5853 text_dir = GTK_TEXT_DIR_RTL;
5855 gtk_draw_insertion_cursor (widget, cr,
5857 is_primary, text_dir, draw_arrow);
5861 gtk_entry_draw_cursor (GtkEntry *entry,
5865 GtkEntryPrivate *priv = entry->priv;
5866 GtkWidget *widget = GTK_WIDGET (entry);
5867 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5868 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5869 GdkRectangle cursor_location;
5870 gboolean split_cursor;
5871 PangoRectangle cursor_rect;
5872 GtkBorder inner_border;
5874 gint text_area_height;
5877 gboolean block_at_line_end;
5878 PangoLayout *layout;
5881 _gtk_entry_effective_inner_border (entry, &inner_border);
5883 xoffset = inner_border.left - priv->scroll_offset;
5885 text_area_height = gdk_window_get_height (priv->text_area);
5887 layout = gtk_entry_ensure_layout (entry, TRUE);
5888 text = pango_layout_get_text (layout);
5889 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5890 if (!priv->overwrite_mode)
5893 block = _gtk_text_util_get_block_cursor_location (layout,
5894 cursor_index, &cursor_rect, &block_at_line_end);
5898 gint strong_x, weak_x;
5899 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5900 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5904 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5906 g_object_get (gtk_widget_get_settings (widget),
5907 "gtk-split-cursor", &split_cursor,
5910 dir1 = priv->resolved_dir;
5916 if (weak_x != strong_x)
5918 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5924 if (keymap_direction == priv->resolved_dir)
5930 cursor_location.x = xoffset + x1;
5931 cursor_location.y = inner_border.top;
5932 cursor_location.width = 0;
5933 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5935 draw_insertion_cursor (entry, cr,
5936 &cursor_location, TRUE, dir1,
5937 dir2 != PANGO_DIRECTION_NEUTRAL);
5939 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5941 cursor_location.x = xoffset + x2;
5942 draw_insertion_cursor (entry, cr,
5943 &cursor_location, FALSE, dir2,
5947 else /* overwrite_mode */
5949 GtkStyleContext *context;
5950 GdkRGBA cursor_color;
5956 get_layout_position (entry, &x, &y);
5958 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5959 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5960 rect.width = PANGO_PIXELS (cursor_rect.width);
5961 rect.height = PANGO_PIXELS (cursor_rect.height);
5963 context = gtk_widget_get_style_context (widget);
5965 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5966 gdk_cairo_set_source_rgba (cr, &cursor_color);
5967 gdk_cairo_rectangle (cr, &rect);
5970 if (!block_at_line_end)
5972 GtkStateFlags state;
5975 state = gtk_widget_get_state_flags (widget);
5976 gtk_style_context_get_background_color (context, state, &color);
5978 gdk_cairo_rectangle (cr, &rect);
5980 cairo_move_to (cr, x, y);
5981 gdk_cairo_set_source_rgba (cr, &color);
5982 pango_cairo_show_layout (cr, layout);
5990 _gtk_entry_reset_im_context (GtkEntry *entry)
5992 GtkEntryPrivate *priv = entry->priv;
5994 if (priv->need_im_reset)
5996 priv->need_im_reset = FALSE;
5997 gtk_im_context_reset (priv->im_context);
6002 * gtk_entry_reset_im_context:
6003 * @entry: a #GtkEntry
6005 * Reset the input method context of the entry if needed.
6007 * This can be necessary in the case where modifying the buffer
6008 * would confuse on-going input method behavior.
6013 gtk_entry_reset_im_context (GtkEntry *entry)
6015 g_return_if_fail (GTK_IS_ENTRY (entry));
6017 _gtk_entry_reset_im_context (entry);
6021 * gtk_entry_im_context_filter_keypress:
6022 * @entry: a #GtkEntry
6023 * @event: (type Gdk.EventKey): the key event
6025 * Allow the #GtkEntry input method to internally handle key press
6026 * and release events. If this function returns %TRUE, then no further
6027 * processing should be done for this key event. See
6028 * gtk_im_context_filter_keypress().
6030 * Note that you are expected to call this function from your handler
6031 * when overriding key event handling. This is needed in the case when
6032 * you need to insert your own key handling between the input method
6033 * and the default key event handling of the #GtkEntry.
6034 * See gtk_text_view_reset_im_context() for an example of use.
6036 * Return value: %TRUE if the input method handled the key event.
6041 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6044 GtkEntryPrivate *priv;
6046 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6050 return gtk_im_context_filter_keypress (priv->im_context, event);
6054 _gtk_entry_get_im_context (GtkEntry *entry)
6056 return entry->priv->im_context;
6060 gtk_entry_find_position (GtkEntry *entry,
6063 GtkEntryPrivate *priv = entry->priv;
6064 PangoLayout *layout;
6065 PangoLayoutLine *line;
6072 layout = gtk_entry_ensure_layout (entry, TRUE);
6073 text = pango_layout_get_text (layout);
6074 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6076 line = pango_layout_get_lines_readonly (layout)->data;
6077 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6079 if (index >= cursor_index && priv->preedit_length)
6081 if (index >= cursor_index + priv->preedit_length)
6082 index -= priv->preedit_length;
6085 index = cursor_index;
6090 pos = g_utf8_pointer_to_offset (text, text + index);
6097 gtk_entry_get_cursor_locations (GtkEntry *entry,
6102 GtkEntryPrivate *priv = entry->priv;
6103 DisplayMode mode = gtk_entry_get_display_mode (entry);
6105 /* Nothing to display at all, so no cursor is relevant */
6106 if (mode == DISPLAY_BLANK)
6116 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6117 const gchar *text = pango_layout_get_text (layout);
6118 PangoRectangle strong_pos, weak_pos;
6121 if (type == CURSOR_STANDARD)
6123 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6125 else /* type == CURSOR_DND */
6127 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6129 if (priv->dnd_position > priv->current_pos)
6131 if (mode == DISPLAY_NORMAL)
6132 index += priv->preedit_length;
6135 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6136 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6141 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6144 *strong_x = strong_pos.x / PANGO_SCALE;
6147 *weak_x = weak_pos.x / PANGO_SCALE;
6152 gtk_entry_adjust_scroll (GtkEntry *entry)
6154 GtkEntryPrivate *priv = entry->priv;
6155 gint min_offset, max_offset;
6156 gint text_area_width, text_width;
6157 GtkBorder inner_border;
6158 gint strong_x, weak_x;
6159 gint strong_xoffset, weak_xoffset;
6161 PangoLayout *layout;
6162 PangoLayoutLine *line;
6163 PangoRectangle logical_rect;
6165 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6168 _gtk_entry_effective_inner_border (entry, &inner_border);
6170 text_area_width = gdk_window_get_width (priv->text_area);
6171 text_area_width -= inner_border.left + inner_border.right;
6172 if (text_area_width < 0)
6173 text_area_width = 0;
6175 layout = gtk_entry_ensure_layout (entry, TRUE);
6176 line = pango_layout_get_lines_readonly (layout)->data;
6178 pango_layout_line_get_extents (line, NULL, &logical_rect);
6180 /* Display as much text as we can */
6182 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6183 xalign = priv->xalign;
6185 xalign = 1.0 - priv->xalign;
6187 text_width = PANGO_PIXELS(logical_rect.width);
6189 if (text_width > text_area_width)
6192 max_offset = text_width - text_area_width;
6196 min_offset = (text_width - text_area_width) * xalign;
6197 max_offset = min_offset;
6200 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6202 /* And make sure cursors are on screen. Note that the cursor is
6203 * actually drawn one pixel into the INNER_BORDER space on
6204 * the right, when the scroll is at the utmost right. This
6205 * looks better to to me than confining the cursor inside the
6206 * border entirely, though it means that the cursor gets one
6207 * pixel closer to the edge of the widget on the right than
6208 * on the left. This might need changing if one changed
6209 * INNER_BORDER from 2 to 1, as one would do on a
6210 * small-screen-real-estate display.
6212 * We always make sure that the strong cursor is on screen, and
6213 * put the weak cursor on screen if possible.
6216 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6218 strong_xoffset = strong_x - priv->scroll_offset;
6220 if (strong_xoffset < 0)
6222 priv->scroll_offset += strong_xoffset;
6225 else if (strong_xoffset > text_area_width)
6227 priv->scroll_offset += strong_xoffset - text_area_width;
6228 strong_xoffset = text_area_width;
6231 weak_xoffset = weak_x - priv->scroll_offset;
6233 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6235 priv->scroll_offset += weak_xoffset;
6237 else if (weak_xoffset > text_area_width &&
6238 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6240 priv->scroll_offset += weak_xoffset - text_area_width;
6243 g_object_notify (G_OBJECT (entry), "scroll-offset");
6247 gtk_entry_move_adjustments (GtkEntry *entry)
6249 GtkWidget *widget = GTK_WIDGET (entry);
6250 GtkAllocation allocation;
6251 GtkAdjustment *adjustment;
6252 PangoContext *context;
6253 PangoFontMetrics *metrics;
6254 GtkStyleContext *style_context;
6255 GtkStateFlags state;
6256 gint x, layout_x, border_x, border_y;
6259 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6263 gtk_widget_get_allocation (widget, &allocation);
6265 /* Cursor position, layout offset, border width, and widget allocation */
6266 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6267 get_layout_position (entry, &layout_x, NULL);
6268 _gtk_entry_get_borders (entry, &border_x, &border_y);
6269 x += allocation.x + layout_x + border_x;
6271 /* Approximate width of a char, so user can see what is ahead/behind */
6272 context = gtk_widget_get_pango_context (widget);
6273 style_context = gtk_widget_get_style_context (widget);
6274 state = gtk_widget_get_state_flags (widget);
6276 metrics = pango_context_get_metrics (context,
6277 gtk_style_context_get_font (style_context, state),
6278 pango_context_get_language (context));
6279 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6282 gtk_adjustment_clamp_page (adjustment,
6283 x - (char_width + 1), /* one char + one pixel before */
6284 x + (char_width + 2)); /* one char + cursor + one pixel after */
6288 gtk_entry_move_visually (GtkEntry *entry,
6292 GtkEntryPrivate *priv = entry->priv;
6294 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6297 text = pango_layout_get_text (layout);
6299 index = g_utf8_offset_to_pointer (text, start) - text;
6303 int new_index, new_trailing;
6304 gboolean split_cursor;
6307 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6308 "gtk-split-cursor", &split_cursor,
6315 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6316 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6318 strong = keymap_direction == priv->resolved_dir;
6323 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6328 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6334 else if (new_index != G_MAXINT)
6337 while (new_trailing--)
6338 index = g_utf8_next_char (text + index) - text;
6341 return g_utf8_pointer_to_offset (text, text + index);
6345 gtk_entry_move_logically (GtkEntry *entry,
6349 gint new_pos = start;
6352 length = gtk_entry_buffer_get_length (get_buffer (entry));
6354 /* Prevent any leak of information */
6355 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6357 new_pos = CLAMP (start + count, 0, length);
6361 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6362 PangoLogAttr *log_attrs;
6365 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6367 while (count > 0 && new_pos < length)
6371 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6375 while (count < 0 && new_pos > 0)
6379 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6391 gtk_entry_move_forward_word (GtkEntry *entry,
6393 gboolean allow_whitespace)
6395 gint new_pos = start;
6398 length = gtk_entry_buffer_get_length (get_buffer (entry));
6400 /* Prevent any leak of information */
6401 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6405 else if (new_pos < length)
6407 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6408 PangoLogAttr *log_attrs;
6411 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6413 /* Find the next word boundary */
6415 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6416 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6427 gtk_entry_move_backward_word (GtkEntry *entry,
6429 gboolean allow_whitespace)
6431 gint new_pos = start;
6433 /* Prevent any leak of information */
6434 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6440 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6441 PangoLogAttr *log_attrs;
6444 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6446 new_pos = start - 1;
6448 /* Find the previous word boundary */
6449 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6450 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6460 gtk_entry_delete_whitespace (GtkEntry *entry)
6462 GtkEntryPrivate *priv = entry->priv;
6463 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6464 PangoLogAttr *log_attrs;
6468 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6470 start = end = priv->current_pos;
6472 while (start > 0 && log_attrs[start-1].is_white)
6475 while (end < n_attrs && log_attrs[end].is_white)
6481 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6486 gtk_entry_select_word (GtkEntry *entry)
6488 GtkEntryPrivate *priv = entry->priv;
6489 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6490 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6492 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6496 gtk_entry_select_line (GtkEntry *entry)
6498 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6502 truncate_multiline (const gchar *text)
6507 text[length] && text[length] != '\n' && text[length] != '\r';
6514 paste_received (GtkClipboard *clipboard,
6518 GtkEntry *entry = GTK_ENTRY (data);
6519 GtkEditable *editable = GTK_EDITABLE (entry);
6520 GtkEntryPrivate *priv = entry->priv;
6522 if (priv->button == 2)
6524 gint pos, start, end;
6525 pos = priv->insert_pos;
6526 gtk_editable_get_selection_bounds (editable, &start, &end);
6527 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6528 gtk_editable_select_region (editable, pos, pos);
6533 gint pos, start, end;
6535 gboolean popup_completion;
6536 GtkEntryCompletion *completion;
6538 completion = gtk_entry_get_completion (entry);
6540 if (priv->truncate_multiline)
6541 length = truncate_multiline (text);
6543 /* only complete if the selection is at the end */
6544 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6545 MAX (priv->current_pos, priv->selection_bound));
6549 if (gtk_widget_get_mapped (completion->priv->popup_window))
6550 _gtk_entry_completion_popdown (completion);
6552 if (!popup_completion && completion->priv->changed_id > 0)
6553 g_signal_handler_block (entry, completion->priv->changed_id);
6556 begin_change (entry);
6557 g_object_freeze_notify (G_OBJECT (entry));
6558 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6559 gtk_editable_delete_text (editable, start, end);
6561 pos = priv->current_pos;
6562 gtk_editable_insert_text (editable, text, length, &pos);
6563 gtk_editable_set_position (editable, pos);
6564 g_object_thaw_notify (G_OBJECT (entry));
6568 !popup_completion && completion->priv->changed_id > 0)
6569 g_signal_handler_unblock (entry, completion->priv->changed_id);
6572 g_object_unref (entry);
6576 gtk_entry_paste (GtkEntry *entry,
6579 g_object_ref (entry);
6580 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6581 paste_received, entry);
6585 primary_get_cb (GtkClipboard *clipboard,
6586 GtkSelectionData *selection_data,
6590 GtkEntry *entry = GTK_ENTRY (data);
6593 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6595 gchar *str = gtk_entry_get_display_text (entry, start, end);
6596 gtk_selection_data_set_text (selection_data, str, -1);
6602 primary_clear_cb (GtkClipboard *clipboard,
6605 GtkEntry *entry = GTK_ENTRY (data);
6606 GtkEntryPrivate *priv = entry->priv;
6608 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6612 gtk_entry_update_primary_selection (GtkEntry *entry)
6614 GtkTargetList *list;
6615 GtkTargetEntry *targets;
6616 GtkClipboard *clipboard;
6620 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6623 list = gtk_target_list_new (NULL, 0);
6624 gtk_target_list_add_text_targets (list, 0);
6626 targets = gtk_target_table_new_from_list (list, &n_targets);
6628 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6630 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6632 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6633 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6634 primary_clear_cb (clipboard, entry);
6638 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6639 gtk_clipboard_clear (clipboard);
6642 gtk_target_table_free (targets, n_targets);
6643 gtk_target_list_unref (list);
6647 gtk_entry_clear (GtkEntry *entry,
6648 GtkEntryIconPosition icon_pos)
6650 GtkEntryPrivate *priv = entry->priv;
6651 EntryIconInfo *icon_info = priv->icons[icon_pos];
6653 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6656 g_object_freeze_notify (G_OBJECT (entry));
6658 /* Explicitly check, as the pointer may become invalidated
6659 * during destruction.
6661 if (GDK_IS_WINDOW (icon_info->window))
6662 gdk_window_hide (icon_info->window);
6664 if (icon_info->pixbuf)
6666 g_object_unref (icon_info->pixbuf);
6667 icon_info->pixbuf = NULL;
6670 switch (icon_info->storage_type)
6672 case GTK_IMAGE_PIXBUF:
6673 g_object_notify (G_OBJECT (entry),
6674 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6677 case GTK_IMAGE_STOCK:
6678 g_free (icon_info->stock_id);
6679 icon_info->stock_id = NULL;
6680 g_object_notify (G_OBJECT (entry),
6681 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6684 case GTK_IMAGE_ICON_NAME:
6685 g_free (icon_info->icon_name);
6686 icon_info->icon_name = NULL;
6687 g_object_notify (G_OBJECT (entry),
6688 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6691 case GTK_IMAGE_GICON:
6692 if (icon_info->gicon)
6694 g_object_unref (icon_info->gicon);
6695 icon_info->gicon = NULL;
6697 g_object_notify (G_OBJECT (entry),
6698 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6702 g_assert_not_reached ();
6706 icon_info->storage_type = GTK_IMAGE_EMPTY;
6707 g_object_notify (G_OBJECT (entry),
6708 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6710 g_object_thaw_notify (G_OBJECT (entry));
6714 create_normal_pixbuf (GtkStyleContext *context,
6715 const gchar *stock_id,
6716 GtkIconSize icon_size)
6718 GtkIconSet *icon_set;
6721 gtk_style_context_save (context);
6723 /* Unset any state */
6724 gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
6726 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6727 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6729 gtk_style_context_restore (context);
6735 ensure_stated_icon_from_info (GtkStyleContext *context,
6738 GdkPixbuf *retval = NULL;
6739 gboolean symbolic = FALSE;
6744 gtk_icon_info_load_symbolic_for_context (info,
6753 create_normal_pixbuf (context,
6754 GTK_STOCK_MISSING_IMAGE,
6755 GTK_ICON_SIZE_MENU);
6759 GdkPixbuf *temp_pixbuf;
6760 GtkIconSource *icon_source;
6762 icon_source = gtk_icon_source_new ();
6763 gtk_icon_source_set_pixbuf (icon_source, retval);
6764 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
6766 temp_pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
6768 gtk_icon_source_free (icon_source);
6770 g_object_unref (retval);
6771 retval = temp_pixbuf;
6778 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6779 GtkEntryIconPosition icon_pos)
6781 GtkEntryPrivate *priv = entry->priv;
6782 EntryIconInfo *icon_info = priv->icons[icon_pos];
6783 GtkStyleContext *context;
6785 GtkIconTheme *icon_theme;
6786 GtkSettings *settings;
6790 GtkStateFlags state;
6792 widget = GTK_WIDGET (entry);
6793 context = gtk_widget_get_style_context (widget);
6795 state = GTK_STATE_FLAG_NORMAL;
6797 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
6798 state |= GTK_STATE_FLAG_INSENSITIVE;
6799 else if (icon_info->prelight)
6800 state |= GTK_STATE_FLAG_PRELIGHT;
6802 if ((icon_info == NULL) ||
6803 ((icon_info->pixbuf != NULL) && icon_info->last_state == state))
6806 icon_info->last_state = state;
6808 gtk_style_context_save (context);
6809 gtk_style_context_set_state (context, state);
6810 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
6812 switch (icon_info->storage_type)
6814 case GTK_IMAGE_EMPTY:
6815 case GTK_IMAGE_PIXBUF:
6817 case GTK_IMAGE_STOCK:
6818 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6819 GTK_ICON_SIZE_MENU);
6821 if (!icon_info->pixbuf)
6822 icon_info->pixbuf = create_normal_pixbuf (context,
6823 GTK_STOCK_MISSING_IMAGE,
6824 GTK_ICON_SIZE_MENU);
6827 case GTK_IMAGE_ICON_NAME:
6828 screen = gtk_widget_get_screen (widget);
6831 icon_theme = gtk_icon_theme_get_for_screen (screen);
6832 settings = gtk_settings_get_for_screen (screen);
6834 gtk_icon_size_lookup_for_settings (settings,
6838 info = gtk_icon_theme_lookup_icon (icon_theme,
6839 icon_info->icon_name,
6840 MIN (width, height),
6844 ensure_stated_icon_from_info (context, info);
6847 gtk_icon_info_free (info);
6851 case GTK_IMAGE_GICON:
6852 screen = gtk_widget_get_screen (widget);
6855 icon_theme = gtk_icon_theme_get_for_screen (screen);
6856 settings = gtk_settings_get_for_screen (screen);
6858 gtk_icon_size_lookup_for_settings (settings,
6862 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6864 MIN (width, height),
6865 GTK_ICON_LOOKUP_USE_BUILTIN);
6868 ensure_stated_icon_from_info (context, info);
6871 gtk_icon_info_free (info);
6876 g_assert_not_reached ();
6880 gtk_style_context_restore (context);
6882 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6883 gdk_window_show_unraised (icon_info->window);
6893 * Creates a new entry.
6895 * Return value: a new #GtkEntry.
6898 gtk_entry_new (void)
6900 return g_object_new (GTK_TYPE_ENTRY, NULL);
6904 * gtk_entry_new_with_buffer:
6905 * @buffer: The buffer to use for the new #GtkEntry.
6907 * Creates a new entry with the specified text buffer.
6909 * Return value: a new #GtkEntry
6914 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6916 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6917 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6920 static GtkEntryBuffer*
6921 get_buffer (GtkEntry *entry)
6923 GtkEntryPrivate *priv = entry->priv;
6925 if (priv->buffer == NULL)
6927 GtkEntryBuffer *buffer;
6928 buffer = gtk_entry_buffer_new (NULL, 0);
6929 gtk_entry_set_buffer (entry, buffer);
6930 g_object_unref (buffer);
6933 return priv->buffer;
6937 * gtk_entry_get_buffer:
6938 * @entry: a #GtkEntry
6940 * Get the #GtkEntryBuffer object which holds the text for
6945 * Returns: (transfer none): A #GtkEntryBuffer object.
6948 gtk_entry_get_buffer (GtkEntry *entry)
6950 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6952 return get_buffer (entry);
6956 * gtk_entry_set_buffer:
6957 * @entry: a #GtkEntry
6958 * @buffer: a #GtkEntryBuffer
6960 * Set the #GtkEntryBuffer object which holds the text for
6966 gtk_entry_set_buffer (GtkEntry *entry,
6967 GtkEntryBuffer *buffer)
6969 GtkEntryPrivate *priv;
6972 g_return_if_fail (GTK_IS_ENTRY (entry));
6978 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6979 g_object_ref (buffer);
6984 buffer_disconnect_signals (entry);
6985 g_object_unref (priv->buffer);
6988 priv->buffer = buffer;
6991 buffer_connect_signals (entry);
6993 obj = G_OBJECT (entry);
6994 g_object_freeze_notify (obj);
6995 g_object_notify (obj, "buffer");
6996 g_object_notify (obj, "text");
6997 g_object_notify (obj, "text-length");
6998 g_object_notify (obj, "max-length");
6999 g_object_notify (obj, "visibility");
7000 g_object_notify (obj, "invisible-char");
7001 g_object_notify (obj, "invisible-char-set");
7002 g_object_thaw_notify (obj);
7004 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7005 gtk_entry_recompute (entry);
7009 * gtk_entry_get_text_area:
7010 * @entry: a #GtkEntry
7011 * @text_area: (out): Return location for the text area.
7013 * Gets the area where the entry's text is drawn. This function is
7014 * useful when drawing something to the entry in a draw callback.
7016 * If the entry is not realized, @text_area is filled with zeros.
7018 * See also gtk_entry_get_icon_area().
7023 gtk_entry_get_text_area (GtkEntry *entry,
7024 GdkRectangle *text_area)
7026 GtkEntryPrivate *priv;
7028 g_return_if_fail (GTK_IS_ENTRY (entry));
7029 g_return_if_fail (text_area != NULL);
7033 if (priv->text_area)
7035 GtkAllocation allocation;
7038 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7039 gdk_window_get_position (priv->text_area, &x, &y);
7041 text_area->x = x - allocation.x;
7042 text_area->y = y - allocation.y;
7043 text_area->width = gdk_window_get_width (priv->text_area);
7044 text_area->height = gdk_window_get_height (priv->text_area);
7050 text_area->width = 0;
7051 text_area->height = 0;
7056 * gtk_entry_set_text:
7057 * @entry: a #GtkEntry
7058 * @text: the new text
7060 * Sets the text in the widget to the given
7061 * value, replacing the current contents.
7063 * See gtk_entry_buffer_set_text().
7066 gtk_entry_set_text (GtkEntry *entry,
7070 GtkEntryCompletion *completion;
7072 g_return_if_fail (GTK_IS_ENTRY (entry));
7073 g_return_if_fail (text != NULL);
7075 /* Actually setting the text will affect the cursor and selection;
7076 * if the contents don't actually change, this will look odd to the user.
7078 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7081 completion = gtk_entry_get_completion (entry);
7082 if (completion && completion->priv->changed_id > 0)
7083 g_signal_handler_block (entry, completion->priv->changed_id);
7085 begin_change (entry);
7086 g_object_freeze_notify (G_OBJECT (entry));
7087 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7089 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7090 g_object_thaw_notify (G_OBJECT (entry));
7093 if (completion && completion->priv->changed_id > 0)
7094 g_signal_handler_unblock (entry, completion->priv->changed_id);
7098 * gtk_entry_set_visibility:
7099 * @entry: a #GtkEntry
7100 * @visible: %TRUE if the contents of the entry are displayed
7103 * Sets whether the contents of the entry are visible or not.
7104 * When visibility is set to %FALSE, characters are displayed
7105 * as the invisible char, and will also appear that way when
7106 * the text in the entry widget is copied elsewhere.
7108 * By default, GTK+ picks the best invisible character available
7109 * in the current font, but it can be changed with
7110 * gtk_entry_set_invisible_char().
7113 gtk_entry_set_visibility (GtkEntry *entry,
7116 GtkEntryPrivate *priv;
7118 g_return_if_fail (GTK_IS_ENTRY (entry));
7122 visible = visible != FALSE;
7124 if (priv->visible != visible)
7126 priv->visible = visible;
7128 g_object_notify (G_OBJECT (entry), "visibility");
7129 gtk_entry_recompute (entry);
7134 * gtk_entry_get_visibility:
7135 * @entry: a #GtkEntry
7137 * Retrieves whether the text in @entry is visible. See
7138 * gtk_entry_set_visibility().
7140 * Return value: %TRUE if the text is currently visible
7143 gtk_entry_get_visibility (GtkEntry *entry)
7145 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7147 return entry->priv->visible;
7151 * gtk_entry_set_invisible_char:
7152 * @entry: a #GtkEntry
7153 * @ch: a Unicode character
7155 * Sets the character to use in place of the actual text when
7156 * gtk_entry_set_visibility() has been called to set text visibility
7157 * to %FALSE. i.e. this is the character used in "password mode" to
7158 * show the user how many characters have been typed. By default, GTK+
7159 * picks the best invisible char available in the current font. If you
7160 * set the invisible char to 0, then the user will get no feedback
7161 * at all; there will be no text on the screen as they type.
7164 gtk_entry_set_invisible_char (GtkEntry *entry,
7167 GtkEntryPrivate *priv;
7169 g_return_if_fail (GTK_IS_ENTRY (entry));
7173 if (!priv->invisible_char_set)
7175 priv->invisible_char_set = TRUE;
7176 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7179 if (ch == priv->invisible_char)
7182 priv->invisible_char = ch;
7183 g_object_notify (G_OBJECT (entry), "invisible-char");
7184 gtk_entry_recompute (entry);
7188 * gtk_entry_get_invisible_char:
7189 * @entry: a #GtkEntry
7191 * Retrieves the character displayed in place of the real characters
7192 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7194 * Return value: the current invisible char, or 0, if the entry does not
7195 * show invisible text at all.
7198 gtk_entry_get_invisible_char (GtkEntry *entry)
7200 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7202 return entry->priv->invisible_char;
7206 * gtk_entry_unset_invisible_char:
7207 * @entry: a #GtkEntry
7209 * Unsets the invisible char previously set with
7210 * gtk_entry_set_invisible_char(). So that the
7211 * default invisible char is used again.
7216 gtk_entry_unset_invisible_char (GtkEntry *entry)
7218 GtkEntryPrivate *priv;
7221 g_return_if_fail (GTK_IS_ENTRY (entry));
7225 if (!priv->invisible_char_set)
7228 priv->invisible_char_set = FALSE;
7229 ch = find_invisible_char (GTK_WIDGET (entry));
7231 if (priv->invisible_char != ch)
7233 priv->invisible_char = ch;
7234 g_object_notify (G_OBJECT (entry), "invisible-char");
7237 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7238 gtk_entry_recompute (entry);
7242 * gtk_entry_set_overwrite_mode:
7243 * @entry: a #GtkEntry
7244 * @overwrite: new value
7246 * Sets whether the text is overwritten when typing in the #GtkEntry.
7251 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7254 GtkEntryPrivate *priv = entry->priv;
7256 g_return_if_fail (GTK_IS_ENTRY (entry));
7258 if (priv->overwrite_mode == overwrite)
7261 gtk_entry_toggle_overwrite (entry);
7263 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7267 * gtk_entry_get_overwrite_mode:
7268 * @entry: a #GtkEntry
7270 * Gets the value set by gtk_entry_set_overwrite_mode().
7272 * Return value: whether the text is overwritten when typing.
7277 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7279 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7281 return entry->priv->overwrite_mode;
7285 * gtk_entry_get_text:
7286 * @entry: a #GtkEntry
7288 * Retrieves the contents of the entry widget.
7289 * See also gtk_editable_get_chars().
7291 * This is equivalent to:
7293 * <informalexample><programlisting>
7294 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7295 * </programlisting></informalexample>
7297 * Return value: a pointer to the contents of the widget as a
7298 * string. This string points to internally allocated
7299 * storage in the widget and must not be freed, modified or
7303 gtk_entry_get_text (GtkEntry *entry)
7305 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7307 return gtk_entry_buffer_get_text (get_buffer (entry));
7311 * gtk_entry_set_max_length:
7312 * @entry: a #GtkEntry
7313 * @max: the maximum length of the entry, or 0 for no maximum.
7314 * (other than the maximum length of entries.) The value passed in will
7315 * be clamped to the range 0-65536.
7317 * Sets the maximum allowed length of the contents of the widget. If
7318 * the current contents are longer than the given length, then they
7319 * will be truncated to fit.
7321 * This is equivalent to:
7323 * <informalexample><programlisting>
7324 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7325 * </programlisting></informalexample>
7328 gtk_entry_set_max_length (GtkEntry *entry,
7331 g_return_if_fail (GTK_IS_ENTRY (entry));
7332 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7336 * gtk_entry_get_max_length:
7337 * @entry: a #GtkEntry
7339 * Retrieves the maximum allowed length of the text in
7340 * @entry. See gtk_entry_set_max_length().
7342 * This is equivalent to:
7344 * <informalexample><programlisting>
7345 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7346 * </programlisting></informalexample>
7348 * Return value: the maximum allowed number of characters
7349 * in #GtkEntry, or 0 if there is no maximum.
7352 gtk_entry_get_max_length (GtkEntry *entry)
7354 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7356 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7360 * gtk_entry_get_text_length:
7361 * @entry: a #GtkEntry
7363 * Retrieves the current length of the text in
7366 * This is equivalent to:
7368 * <informalexample><programlisting>
7369 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7370 * </programlisting></informalexample>
7372 * Return value: the current number of characters
7373 * in #GtkEntry, or 0 if there are none.
7378 gtk_entry_get_text_length (GtkEntry *entry)
7380 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7382 return gtk_entry_buffer_get_length (get_buffer (entry));
7386 * gtk_entry_set_activates_default:
7387 * @entry: a #GtkEntry
7388 * @setting: %TRUE to activate window's default widget on Enter keypress
7390 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7391 * widget for the window containing the entry. This usually means that
7392 * the dialog box containing the entry will be closed, since the default
7393 * widget is usually one of the dialog buttons.
7395 * (For experts: if @setting is %TRUE, the entry calls
7396 * gtk_window_activate_default() on the window containing the entry, in
7397 * the default handler for the #GtkWidget::activate signal.)
7400 gtk_entry_set_activates_default (GtkEntry *entry,
7403 GtkEntryPrivate *priv;
7405 g_return_if_fail (GTK_IS_ENTRY (entry));
7409 setting = setting != FALSE;
7411 if (setting != priv->activates_default)
7413 priv->activates_default = setting;
7414 g_object_notify (G_OBJECT (entry), "activates-default");
7419 * gtk_entry_get_activates_default:
7420 * @entry: a #GtkEntry
7422 * Retrieves the value set by gtk_entry_set_activates_default().
7424 * Return value: %TRUE if the entry will activate the default widget
7427 gtk_entry_get_activates_default (GtkEntry *entry)
7429 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7431 return entry->priv->activates_default;
7435 * gtk_entry_set_width_chars:
7436 * @entry: a #GtkEntry
7437 * @n_chars: width in chars
7439 * Changes the size request of the entry to be about the right size
7440 * for @n_chars characters. Note that it changes the size
7441 * <emphasis>request</emphasis>, the size can still be affected by
7442 * how you pack the widget into containers. If @n_chars is -1, the
7443 * size reverts to the default entry size.
7446 gtk_entry_set_width_chars (GtkEntry *entry,
7449 GtkEntryPrivate *priv;
7451 g_return_if_fail (GTK_IS_ENTRY (entry));
7455 if (priv->width_chars != n_chars)
7457 priv->width_chars = n_chars;
7458 g_object_notify (G_OBJECT (entry), "width-chars");
7459 gtk_widget_queue_resize (GTK_WIDGET (entry));
7464 * gtk_entry_get_width_chars:
7465 * @entry: a #GtkEntry
7467 * Gets the value set by gtk_entry_set_width_chars().
7469 * Return value: number of chars to request space for, or negative if unset
7472 gtk_entry_get_width_chars (GtkEntry *entry)
7474 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7476 return entry->priv->width_chars;
7480 * gtk_entry_set_has_frame:
7481 * @entry: a #GtkEntry
7482 * @setting: new value
7484 * Sets whether the entry has a beveled frame around it.
7487 gtk_entry_set_has_frame (GtkEntry *entry,
7490 GtkEntryPrivate *priv;
7492 g_return_if_fail (GTK_IS_ENTRY (entry));
7496 setting = (setting != FALSE);
7498 if (priv->has_frame == setting)
7501 gtk_widget_queue_resize (GTK_WIDGET (entry));
7502 priv->has_frame = setting;
7503 g_object_notify (G_OBJECT (entry), "has-frame");
7507 * gtk_entry_get_has_frame:
7508 * @entry: a #GtkEntry
7510 * Gets the value set by gtk_entry_set_has_frame().
7512 * Return value: whether the entry has a beveled frame
7515 gtk_entry_get_has_frame (GtkEntry *entry)
7517 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7519 return entry->priv->has_frame;
7523 * gtk_entry_set_inner_border:
7524 * @entry: a #GtkEntry
7525 * @border: (allow-none): a #GtkBorder, or %NULL
7527 * Sets %entry's inner-border property to %border, or clears it if %NULL
7528 * is passed. The inner-border is the area around the entry's text, but
7531 * If set, this property overrides the inner-border style property.
7532 * Overriding the style-provided border is useful when you want to do
7533 * in-place editing of some text in a canvas or list widget, where
7534 * pixel-exact positioning of the entry is important.
7539 gtk_entry_set_inner_border (GtkEntry *entry,
7540 const GtkBorder *border)
7542 g_return_if_fail (GTK_IS_ENTRY (entry));
7544 gtk_widget_queue_resize (GTK_WIDGET (entry));
7547 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7548 gtk_border_copy (border),
7549 (GDestroyNotify) gtk_border_free);
7551 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7553 g_object_notify (G_OBJECT (entry), "inner-border");
7557 * gtk_entry_get_inner_border:
7558 * @entry: a #GtkEntry
7560 * This function returns the entry's #GtkEntry:inner-border property. See
7561 * gtk_entry_set_inner_border() for more information.
7563 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7568 gtk_entry_get_inner_border (GtkEntry *entry)
7570 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7572 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7576 * gtk_entry_get_layout:
7577 * @entry: a #GtkEntry
7579 * Gets the #PangoLayout used to display the entry.
7580 * The layout is useful to e.g. convert text positions to
7581 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7582 * The returned layout is owned by the entry and must not be
7583 * modified or freed by the caller.
7585 * Keep in mind that the layout text may contain a preedit string, so
7586 * gtk_entry_layout_index_to_text_index() and
7587 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7588 * indices in the layout to byte indices in the entry contents.
7590 * Return value: (transfer none): the #PangoLayout for this entry
7593 gtk_entry_get_layout (GtkEntry *entry)
7595 PangoLayout *layout;
7597 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7599 layout = gtk_entry_ensure_layout (entry, TRUE);
7606 * gtk_entry_layout_index_to_text_index:
7607 * @entry: a #GtkEntry
7608 * @layout_index: byte index into the entry layout text
7610 * Converts from a position in the entry contents (returned
7611 * by gtk_entry_get_text()) to a position in the
7612 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7613 * with text retrieved via pango_layout_get_text()).
7615 * Return value: byte index into the entry contents
7618 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7621 GtkEntryPrivate *priv;
7622 PangoLayout *layout;
7626 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7630 layout = gtk_entry_ensure_layout (entry, TRUE);
7631 text = pango_layout_get_text (layout);
7632 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7634 if (layout_index >= cursor_index && priv->preedit_length)
7636 if (layout_index >= cursor_index + priv->preedit_length)
7637 layout_index -= priv->preedit_length;
7639 layout_index = cursor_index;
7642 return layout_index;
7646 * gtk_entry_text_index_to_layout_index:
7647 * @entry: a #GtkEntry
7648 * @text_index: byte index into the entry contents
7650 * Converts from a position in the entry's #PangoLayout (returned by
7651 * gtk_entry_get_layout()) to a position in the entry contents
7652 * (returned by gtk_entry_get_text()).
7654 * Return value: byte index into the entry layout text
7657 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7660 GtkEntryPrivate *priv;
7661 PangoLayout *layout;
7665 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7669 layout = gtk_entry_ensure_layout (entry, TRUE);
7670 text = pango_layout_get_text (layout);
7671 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7673 if (text_index > cursor_index)
7674 text_index += priv->preedit_length;
7680 * gtk_entry_get_layout_offsets:
7681 * @entry: a #GtkEntry
7682 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7683 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7686 * Obtains the position of the #PangoLayout used to render text
7687 * in the entry, in widget coordinates. Useful if you want to line
7688 * up the text in an entry with some other text, e.g. when using the
7689 * entry to implement editable cells in a sheet widget.
7691 * Also useful to convert mouse events into coordinates inside the
7692 * #PangoLayout, e.g. to take some action if some part of the entry text
7695 * Note that as the user scrolls around in the entry the offsets will
7696 * change; you'll need to connect to the "notify::scroll-offset"
7697 * signal to track this. Remember when using the #PangoLayout
7698 * functions you need to convert to and from pixels using
7699 * PANGO_PIXELS() or #PANGO_SCALE.
7701 * Keep in mind that the layout text may contain a preedit string, so
7702 * gtk_entry_layout_index_to_text_index() and
7703 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7704 * indices in the layout to byte indices in the entry contents.
7707 gtk_entry_get_layout_offsets (GtkEntry *entry,
7711 gint text_area_x, text_area_y;
7713 g_return_if_fail (GTK_IS_ENTRY (entry));
7715 /* this gets coords relative to text area */
7716 get_layout_position (entry, x, y);
7718 /* convert to widget coords */
7719 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7730 * gtk_entry_set_alignment:
7731 * @entry: a #GtkEntry
7732 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7733 * Reversed for RTL layouts
7735 * Sets the alignment for the contents of the entry. This controls
7736 * the horizontal positioning of the contents when the displayed
7737 * text is shorter than the width of the entry.
7742 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7744 GtkEntryPrivate *priv;
7746 g_return_if_fail (GTK_IS_ENTRY (entry));
7752 else if (xalign > 1.0)
7755 if (xalign != priv->xalign)
7757 priv->xalign = xalign;
7759 gtk_entry_recompute (entry);
7761 g_object_notify (G_OBJECT (entry), "xalign");
7766 * gtk_entry_get_alignment:
7767 * @entry: a #GtkEntry
7769 * Gets the value set by gtk_entry_set_alignment().
7771 * Return value: the alignment
7776 gtk_entry_get_alignment (GtkEntry *entry)
7778 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7780 return entry->priv->xalign;
7784 * gtk_entry_set_icon_from_pixbuf:
7785 * @entry: a #GtkEntry
7786 * @icon_pos: Icon position
7787 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7789 * Sets the icon shown in the specified position using a pixbuf.
7791 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7796 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7797 GtkEntryIconPosition icon_pos,
7800 GtkEntryPrivate *priv;
7801 EntryIconInfo *icon_info;
7803 g_return_if_fail (GTK_IS_ENTRY (entry));
7804 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7808 if ((icon_info = priv->icons[icon_pos]) == NULL)
7809 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7811 g_object_freeze_notify (G_OBJECT (entry));
7814 g_object_ref (pixbuf);
7816 gtk_entry_clear (entry, icon_pos);
7820 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7821 icon_info->pixbuf = pixbuf;
7823 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7825 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7826 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7830 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7831 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7834 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7835 gdk_window_show_unraised (icon_info->window);
7838 gtk_entry_ensure_pixbuf (entry, icon_pos);
7840 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7841 gtk_widget_queue_resize (GTK_WIDGET (entry));
7843 g_object_thaw_notify (G_OBJECT (entry));
7847 * gtk_entry_set_icon_from_stock:
7848 * @entry: A #GtkEntry
7849 * @icon_pos: Icon position
7850 * @stock_id: (allow-none): The name of the stock item, or %NULL
7852 * Sets the icon shown in the entry at the specified position from
7855 * If @stock_id is %NULL, no icon will be shown in the specified position.
7860 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7861 GtkEntryIconPosition icon_pos,
7862 const gchar *stock_id)
7864 GtkEntryPrivate *priv;
7865 EntryIconInfo *icon_info;
7868 g_return_if_fail (GTK_IS_ENTRY (entry));
7869 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7873 if ((icon_info = priv->icons[icon_pos]) == NULL)
7874 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7876 g_object_freeze_notify (G_OBJECT (entry));
7878 /* need to dup before clearing */
7879 new_id = g_strdup (stock_id);
7881 gtk_entry_clear (entry, icon_pos);
7885 icon_info->storage_type = GTK_IMAGE_STOCK;
7886 icon_info->stock_id = new_id;
7888 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7890 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7891 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7895 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7896 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7899 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7900 gdk_window_show_unraised (icon_info->window);
7903 gtk_entry_ensure_pixbuf (entry, icon_pos);
7905 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7906 gtk_widget_queue_resize (GTK_WIDGET (entry));
7908 g_object_thaw_notify (G_OBJECT (entry));
7912 * gtk_entry_set_icon_from_icon_name:
7913 * @entry: A #GtkEntry
7914 * @icon_pos: The position at which to set the icon
7915 * @icon_name: (allow-none): An icon name, or %NULL
7917 * Sets the icon shown in the entry at the specified position
7918 * from the current icon theme.
7920 * If the icon name isn't known, a "broken image" icon will be displayed
7923 * If @icon_name is %NULL, no icon will be shown in the specified position.
7928 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7929 GtkEntryIconPosition icon_pos,
7930 const gchar *icon_name)
7932 GtkEntryPrivate *priv;
7933 EntryIconInfo *icon_info;
7936 g_return_if_fail (GTK_IS_ENTRY (entry));
7937 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7941 if ((icon_info = priv->icons[icon_pos]) == NULL)
7942 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7944 g_object_freeze_notify (G_OBJECT (entry));
7946 /* need to dup before clearing */
7947 new_name = g_strdup (icon_name);
7949 gtk_entry_clear (entry, icon_pos);
7951 if (new_name != NULL)
7953 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7954 icon_info->icon_name = new_name;
7956 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7958 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7959 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7963 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7964 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7967 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7968 gdk_window_show_unraised (icon_info->window);
7971 gtk_entry_ensure_pixbuf (entry, icon_pos);
7973 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7974 gtk_widget_queue_resize (GTK_WIDGET (entry));
7976 g_object_thaw_notify (G_OBJECT (entry));
7980 * gtk_entry_set_icon_from_gicon:
7981 * @entry: A #GtkEntry
7982 * @icon_pos: The position at which to set the icon
7983 * @icon: (allow-none): The icon to set, or %NULL
7985 * Sets the icon shown in the entry at the specified position
7986 * from the current icon theme.
7987 * If the icon isn't known, a "broken image" icon will be displayed
7990 * If @icon is %NULL, no icon will be shown in the specified position.
7995 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7996 GtkEntryIconPosition icon_pos,
7999 GtkEntryPrivate *priv;
8000 EntryIconInfo *icon_info;
8002 g_return_if_fail (GTK_IS_ENTRY (entry));
8003 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8007 if ((icon_info = priv->icons[icon_pos]) == NULL)
8008 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8010 g_object_freeze_notify (G_OBJECT (entry));
8012 /* need to ref before clearing */
8014 g_object_ref (icon);
8016 gtk_entry_clear (entry, icon_pos);
8020 icon_info->storage_type = GTK_IMAGE_GICON;
8021 icon_info->gicon = icon;
8023 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8025 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8026 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8030 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8031 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8034 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8035 gdk_window_show_unraised (icon_info->window);
8038 gtk_entry_ensure_pixbuf (entry, icon_pos);
8040 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8041 gtk_widget_queue_resize (GTK_WIDGET (entry));
8043 g_object_thaw_notify (G_OBJECT (entry));
8047 * gtk_entry_set_icon_activatable:
8048 * @entry: A #GtkEntry
8049 * @icon_pos: Icon position
8050 * @activatable: %TRUE if the icon should be activatable
8052 * Sets whether the icon is activatable.
8057 gtk_entry_set_icon_activatable (GtkEntry *entry,
8058 GtkEntryIconPosition icon_pos,
8059 gboolean activatable)
8061 GtkEntryPrivate *priv;
8062 EntryIconInfo *icon_info;
8064 g_return_if_fail (GTK_IS_ENTRY (entry));
8065 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8069 if ((icon_info = priv->icons[icon_pos]) == NULL)
8070 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8072 activatable = activatable != FALSE;
8074 if (icon_info->nonactivatable != !activatable)
8076 icon_info->nonactivatable = !activatable;
8078 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8079 update_cursors (GTK_WIDGET (entry));
8081 g_object_notify (G_OBJECT (entry),
8082 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8087 * gtk_entry_get_icon_activatable:
8088 * @entry: a #GtkEntry
8089 * @icon_pos: Icon position
8091 * Returns whether the icon is activatable.
8093 * Returns: %TRUE if the icon is activatable.
8098 gtk_entry_get_icon_activatable (GtkEntry *entry,
8099 GtkEntryIconPosition icon_pos)
8101 GtkEntryPrivate *priv;
8102 EntryIconInfo *icon_info;
8104 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8105 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8108 icon_info = priv->icons[icon_pos];
8110 return (!icon_info || !icon_info->nonactivatable);
8114 * gtk_entry_get_icon_pixbuf:
8115 * @entry: A #GtkEntry
8116 * @icon_pos: Icon position
8118 * Retrieves the image used for the icon.
8120 * Unlike the other methods of setting and getting icon data, this
8121 * method will work regardless of whether the icon was set using a
8122 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8124 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8125 * set for this position.
8130 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8131 GtkEntryIconPosition icon_pos)
8133 GtkEntryPrivate *priv;
8134 EntryIconInfo *icon_info;
8136 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8137 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8141 icon_info = priv->icons[icon_pos];
8146 gtk_entry_ensure_pixbuf (entry, icon_pos);
8148 return icon_info->pixbuf;
8152 * gtk_entry_get_icon_gicon:
8153 * @entry: A #GtkEntry
8154 * @icon_pos: Icon position
8156 * Retrieves the #GIcon used for the icon, or %NULL if there is
8157 * no icon or if the icon was set by some other method (e.g., by
8158 * stock, pixbuf, or icon name).
8160 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8161 * or if the icon is not a #GIcon
8166 gtk_entry_get_icon_gicon (GtkEntry *entry,
8167 GtkEntryIconPosition icon_pos)
8169 GtkEntryPrivate *priv;
8170 EntryIconInfo *icon_info;
8172 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8173 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8176 icon_info = priv->icons[icon_pos];
8181 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8185 * gtk_entry_get_icon_stock:
8186 * @entry: A #GtkEntry
8187 * @icon_pos: Icon position
8189 * Retrieves the stock id used for the icon, or %NULL if there is
8190 * no icon or if the icon was set by some other method (e.g., by
8191 * pixbuf, icon name or gicon).
8193 * Returns: A stock id, or %NULL if no icon is set or if the icon
8194 * wasn't set from a stock id
8199 gtk_entry_get_icon_stock (GtkEntry *entry,
8200 GtkEntryIconPosition icon_pos)
8202 GtkEntryPrivate *priv;
8203 EntryIconInfo *icon_info;
8205 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8206 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8209 icon_info = priv->icons[icon_pos];
8214 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8218 * gtk_entry_get_icon_name:
8219 * @entry: A #GtkEntry
8220 * @icon_pos: Icon position
8222 * Retrieves the icon name used for the icon, or %NULL if there is
8223 * no icon or if the icon was set by some other method (e.g., by
8224 * pixbuf, stock or gicon).
8226 * Returns: An icon name, or %NULL if no icon is set or if the icon
8227 * wasn't set from an icon name
8232 gtk_entry_get_icon_name (GtkEntry *entry,
8233 GtkEntryIconPosition icon_pos)
8235 GtkEntryPrivate *priv;
8236 EntryIconInfo *icon_info;
8238 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8239 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8242 icon_info = priv->icons[icon_pos];
8247 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8251 * gtk_entry_set_icon_sensitive:
8252 * @entry: A #GtkEntry
8253 * @icon_pos: Icon position
8254 * @sensitive: Specifies whether the icon should appear
8255 * sensitive or insensitive
8257 * Sets the sensitivity for the specified icon.
8262 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8263 GtkEntryIconPosition icon_pos,
8266 GtkEntryPrivate *priv;
8267 EntryIconInfo *icon_info;
8269 g_return_if_fail (GTK_IS_ENTRY (entry));
8270 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8274 if ((icon_info = priv->icons[icon_pos]) == NULL)
8275 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8277 if (icon_info->insensitive != !sensitive)
8279 icon_info->insensitive = !sensitive;
8281 icon_info->pressed = FALSE;
8282 icon_info->prelight = FALSE;
8284 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8285 update_cursors (GTK_WIDGET (entry));
8287 gtk_widget_queue_draw (GTK_WIDGET (entry));
8289 g_object_notify (G_OBJECT (entry),
8290 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8295 * gtk_entry_get_icon_sensitive:
8296 * @entry: a #GtkEntry
8297 * @icon_pos: Icon position
8299 * Returns whether the icon appears sensitive or insensitive.
8301 * Returns: %TRUE if the icon is sensitive.
8306 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8307 GtkEntryIconPosition icon_pos)
8309 GtkEntryPrivate *priv;
8310 EntryIconInfo *icon_info;
8312 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8313 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8317 icon_info = priv->icons[icon_pos];
8319 return (!icon_info || !icon_info->insensitive);
8324 * gtk_entry_get_icon_storage_type:
8325 * @entry: a #GtkEntry
8326 * @icon_pos: Icon position
8328 * Gets the type of representation being used by the icon
8329 * to store image data. If the icon has no image data,
8330 * the return value will be %GTK_IMAGE_EMPTY.
8332 * Return value: image representation being used
8337 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8338 GtkEntryIconPosition icon_pos)
8340 GtkEntryPrivate *priv;
8341 EntryIconInfo *icon_info;
8343 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8344 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8348 icon_info = priv->icons[icon_pos];
8351 return GTK_IMAGE_EMPTY;
8353 return icon_info->storage_type;
8357 * gtk_entry_get_icon_at_pos:
8358 * @entry: a #GtkEntry
8359 * @x: the x coordinate of the position to find
8360 * @y: the y coordinate of the position to find
8362 * Finds the icon at the given position and return its index. The
8363 * position's coordinates are relative to the @entry's top left corner.
8364 * If @x, @y doesn't lie inside an icon, -1 is returned.
8365 * This function is intended for use in a #GtkWidget::query-tooltip
8368 * Returns: the index of the icon at the given position, or -1
8373 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8377 GtkAllocation primary;
8378 GtkAllocation secondary;
8379 gint frame_x, frame_y;
8381 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8383 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8387 get_icon_allocations (entry, &primary, &secondary);
8389 if (primary.x <= x && x < primary.x + primary.width &&
8390 primary.y <= y && y < primary.y + primary.height)
8391 return GTK_ENTRY_ICON_PRIMARY;
8393 if (secondary.x <= x && x < secondary.x + secondary.width &&
8394 secondary.y <= y && y < secondary.y + secondary.height)
8395 return GTK_ENTRY_ICON_SECONDARY;
8401 * gtk_entry_set_icon_drag_source:
8402 * @entry: a #GtkIconEntry
8403 * @icon_pos: icon position
8404 * @target_list: the targets (data formats) in which the data can be provided
8405 * @actions: a bitmask of the allowed drag actions
8407 * Sets up the icon at the given position so that GTK+ will start a drag
8408 * operation when the user clicks and drags the icon.
8410 * To handle the drag operation, you need to connect to the usual
8411 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8412 * signal, and use gtk_entry_get_current_icon_drag_source() in
8413 * your signal handler to find out if the drag was started from
8416 * By default, GTK+ uses the icon as the drag icon. You can use the
8417 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8418 * have to use g_signal_connect_after() to ensure that your signal handler
8419 * gets executed after the default handler.
8424 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8425 GtkEntryIconPosition icon_pos,
8426 GtkTargetList *target_list,
8427 GdkDragAction actions)
8429 GtkEntryPrivate *priv;
8430 EntryIconInfo *icon_info;
8432 g_return_if_fail (GTK_IS_ENTRY (entry));
8433 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8437 if ((icon_info = priv->icons[icon_pos]) == NULL)
8438 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8440 if (icon_info->target_list)
8441 gtk_target_list_unref (icon_info->target_list);
8442 icon_info->target_list = target_list;
8443 if (icon_info->target_list)
8444 gtk_target_list_ref (icon_info->target_list);
8446 icon_info->actions = actions;
8450 * gtk_entry_get_current_icon_drag_source:
8451 * @entry: a #GtkIconEntry
8453 * Returns the index of the icon which is the source of the current
8454 * DND operation, or -1.
8456 * This function is meant to be used in a #GtkWidget::drag-data-get
8459 * Returns: index of the icon which is the source of the current
8460 * DND operation, or -1.
8465 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8467 GtkEntryPrivate *priv;
8468 EntryIconInfo *icon_info = NULL;
8471 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8475 for (i = 0; i < MAX_ICONS; i++)
8477 if ((icon_info = priv->icons[i]))
8479 if (icon_info->in_drag)
8488 * gtk_entry_get_icon_area:
8489 * @entry: A #GtkEntry
8490 * @icon_pos: Icon position
8491 * @icon_area: (out): Return location for the icon's area
8493 * Gets the area where entry's icon at @icon_pos is drawn.
8494 * This function is useful when drawing something to the
8495 * entry in a draw callback.
8497 * If the entry is not realized or has no icon at the given position,
8498 * @icon_area is filled with zeros.
8500 * See also gtk_entry_get_text_area()
8505 gtk_entry_get_icon_area (GtkEntry *entry,
8506 GtkEntryIconPosition icon_pos,
8507 GdkRectangle *icon_area)
8509 GtkEntryPrivate *priv;
8510 EntryIconInfo *icon_info;
8512 g_return_if_fail (GTK_IS_ENTRY (entry));
8513 g_return_if_fail (icon_area != NULL);
8517 icon_info = priv->icons[icon_pos];
8521 GtkAllocation primary;
8522 GtkAllocation secondary;
8524 get_icon_allocations (entry, &primary, &secondary);
8526 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8527 *icon_area = primary;
8529 *icon_area = secondary;
8535 icon_area->width = 0;
8536 icon_area->height = 0;
8541 ensure_has_tooltip (GtkEntry *entry)
8543 GtkEntryPrivate *priv;
8544 EntryIconInfo *icon_info;
8546 gboolean has_tooltip = FALSE;
8550 for (i = 0; i < MAX_ICONS; i++)
8552 if ((icon_info = priv->icons[i]) != NULL)
8554 if (icon_info->tooltip != NULL)
8562 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8566 * gtk_entry_get_icon_tooltip_text:
8567 * @entry: a #GtkEntry
8568 * @icon_pos: the icon position
8570 * Gets the contents of the tooltip on the icon at the specified
8571 * position in @entry.
8573 * Returns: the tooltip text, or %NULL. Free the returned string
8574 * with g_free() when done.
8579 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8580 GtkEntryIconPosition icon_pos)
8582 GtkEntryPrivate *priv;
8583 EntryIconInfo *icon_info;
8586 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8587 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8591 icon_info = priv->icons[icon_pos];
8596 if (icon_info->tooltip &&
8597 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8598 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8604 * gtk_entry_set_icon_tooltip_text:
8605 * @entry: a #GtkEntry
8606 * @icon_pos: the icon position
8607 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8609 * Sets @tooltip as the contents of the tooltip for the icon
8610 * at the specified position.
8612 * Use %NULL for @tooltip to remove an existing tooltip.
8614 * See also gtk_widget_set_tooltip_text() and
8615 * gtk_entry_set_icon_tooltip_markup().
8620 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8621 GtkEntryIconPosition icon_pos,
8622 const gchar *tooltip)
8624 GtkEntryPrivate *priv;
8625 EntryIconInfo *icon_info;
8627 g_return_if_fail (GTK_IS_ENTRY (entry));
8628 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8632 if ((icon_info = priv->icons[icon_pos]) == NULL)
8633 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8635 if (icon_info->tooltip)
8636 g_free (icon_info->tooltip);
8638 /* Treat an empty string as a NULL string,
8639 * because an empty string would be useless for a tooltip:
8641 if (tooltip && tooltip[0] == '\0')
8644 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8646 ensure_has_tooltip (entry);
8650 * gtk_entry_get_icon_tooltip_markup:
8651 * @entry: a #GtkEntry
8652 * @icon_pos: the icon position
8654 * Gets the contents of the tooltip on the icon at the specified
8655 * position in @entry.
8657 * Returns: the tooltip text, or %NULL. Free the returned string
8658 * with g_free() when done.
8663 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8664 GtkEntryIconPosition icon_pos)
8666 GtkEntryPrivate *priv;
8667 EntryIconInfo *icon_info;
8669 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8670 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8674 icon_info = priv->icons[icon_pos];
8679 return g_strdup (icon_info->tooltip);
8683 * gtk_entry_set_icon_tooltip_markup:
8684 * @entry: a #GtkEntry
8685 * @icon_pos: the icon position
8686 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8688 * Sets @tooltip as the contents of the tooltip for the icon at
8689 * the specified position. @tooltip is assumed to be marked up with
8690 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8692 * Use %NULL for @tooltip to remove an existing tooltip.
8694 * See also gtk_widget_set_tooltip_markup() and
8695 * gtk_enty_set_icon_tooltip_text().
8700 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8701 GtkEntryIconPosition icon_pos,
8702 const gchar *tooltip)
8704 GtkEntryPrivate *priv;
8705 EntryIconInfo *icon_info;
8707 g_return_if_fail (GTK_IS_ENTRY (entry));
8708 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8712 if ((icon_info = priv->icons[icon_pos]) == NULL)
8713 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8715 if (icon_info->tooltip)
8716 g_free (icon_info->tooltip);
8718 /* Treat an empty string as a NULL string,
8719 * because an empty string would be useless for a tooltip:
8721 if (tooltip && tooltip[0] == '\0')
8724 icon_info->tooltip = g_strdup (tooltip);
8726 ensure_has_tooltip (entry);
8730 gtk_entry_query_tooltip (GtkWidget *widget,
8733 gboolean keyboard_tip,
8734 GtkTooltip *tooltip)
8737 GtkEntryPrivate *priv;
8738 EntryIconInfo *icon_info;
8741 entry = GTK_ENTRY (widget);
8746 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8749 if ((icon_info = priv->icons[icon_pos]) != NULL)
8751 if (icon_info->tooltip)
8753 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8762 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8769 /* Quick hack of a popup menu
8772 activate_cb (GtkWidget *menuitem,
8775 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8776 g_signal_emit_by_name (entry, signal);
8781 gtk_entry_mnemonic_activate (GtkWidget *widget,
8782 gboolean group_cycling)
8784 gtk_widget_grab_focus (widget);
8789 append_action_signal (GtkEntry *entry,
8791 const gchar *stock_id,
8792 const gchar *signal,
8795 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8797 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8798 g_signal_connect (menuitem, "activate",
8799 G_CALLBACK (activate_cb), entry);
8801 gtk_widget_set_sensitive (menuitem, sensitive);
8803 gtk_widget_show (menuitem);
8804 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8808 popup_menu_detach (GtkWidget *attach_widget,
8811 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8812 GtkEntryPrivate *priv_attach = entry_attach->priv;
8814 priv_attach->popup_menu = NULL;
8818 popup_position_func (GtkMenu *menu,
8824 GtkEntry *entry = GTK_ENTRY (user_data);
8825 GtkEntryPrivate *priv = entry->priv;
8826 GtkWidget *widget = GTK_WIDGET (entry);
8828 GtkRequisition menu_req;
8829 GdkRectangle monitor;
8830 GtkBorder inner_border;
8831 gint monitor_num, strong_x, height;
8833 g_return_if_fail (gtk_widget_get_realized (widget));
8835 gdk_window_get_origin (priv->text_area, x, y);
8837 screen = gtk_widget_get_screen (widget);
8838 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8839 if (monitor_num < 0)
8841 gtk_menu_set_monitor (menu, monitor_num);
8843 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8844 gtk_widget_get_preferred_size (priv->popup_menu,
8846 height = gdk_window_get_height (priv->text_area);
8847 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8848 _gtk_entry_effective_inner_border (entry, &inner_border);
8850 *x += inner_border.left + strong_x - priv->scroll_offset;
8851 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8852 *x -= menu_req.width;
8854 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8856 else if ((*y - menu_req.height) >= monitor.y)
8857 *y -= menu_req.height;
8858 else if (monitor.y + monitor.height - (*y + height) > *y)
8861 *y -= menu_req.height;
8867 unichar_chosen_func (const char *text,
8870 GtkEntry *entry = GTK_ENTRY (data);
8871 GtkEntryPrivate *priv = entry->priv;
8874 gtk_entry_enter_text (entry, text);
8885 popup_targets_received (GtkClipboard *clipboard,
8886 GtkSelectionData *data,
8889 PopupInfo *info = user_data;
8890 GtkEntry *entry = info->entry;
8891 GtkEntryPrivate *info_entry_priv = entry->priv;
8893 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8896 gboolean clipboard_contains_text;
8897 GtkWidget *menuitem;
8899 gboolean show_input_method_menu;
8900 gboolean show_unicode_menu;
8902 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8903 if (info_entry_priv->popup_menu)
8904 gtk_widget_destroy (info_entry_priv->popup_menu);
8906 info_entry_priv->popup_menu = gtk_menu_new ();
8908 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8912 mode = gtk_entry_get_display_mode (entry);
8913 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8914 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8915 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8917 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8918 mode == DISPLAY_NORMAL &&
8919 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8921 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8922 info_entry_priv->editable && clipboard_contains_text);
8924 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8925 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8926 g_signal_connect_swapped (menuitem, "activate",
8927 G_CALLBACK (gtk_entry_delete_cb), entry);
8928 gtk_widget_show (menuitem);
8929 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8931 menuitem = gtk_separator_menu_item_new ();
8932 gtk_widget_show (menuitem);
8933 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8935 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8936 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8937 g_signal_connect_swapped (menuitem, "activate",
8938 G_CALLBACK (gtk_entry_select_all), entry);
8939 gtk_widget_show (menuitem);
8940 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8942 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8943 "gtk-show-input-method-menu", &show_input_method_menu,
8944 "gtk-show-unicode-menu", &show_unicode_menu,
8947 if (show_input_method_menu || show_unicode_menu)
8949 menuitem = gtk_separator_menu_item_new ();
8950 gtk_widget_show (menuitem);
8951 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8954 if (show_input_method_menu)
8956 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8957 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8958 gtk_widget_show (menuitem);
8959 submenu = gtk_menu_new ();
8960 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8962 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8964 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8965 GTK_MENU_SHELL (submenu));
8968 if (show_unicode_menu)
8970 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8971 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8972 gtk_widget_show (menuitem);
8974 submenu = gtk_menu_new ();
8975 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8976 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8978 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8979 unichar_chosen_func,
8983 g_signal_emit (entry,
8984 signals[POPULATE_POPUP],
8986 info_entry_priv->popup_menu);
8990 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8992 info->button, info->time);
8995 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8996 popup_position_func, entry,
8997 info->button, info->time);
8998 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9002 g_object_unref (entry);
9003 g_slice_free (PopupInfo, info);
9007 gtk_entry_do_popup (GtkEntry *entry,
9008 GdkEventButton *event)
9010 PopupInfo *info = g_slice_new (PopupInfo);
9012 /* In order to know what entries we should make sensitive, we
9013 * ask for the current targets of the clipboard, and when
9014 * we get them, then we actually pop up the menu.
9016 info->entry = g_object_ref (entry);
9020 info->button = event->button;
9021 info->time = event->time;
9026 info->time = gtk_get_current_event_time ();
9029 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9030 gdk_atom_intern_static_string ("TARGETS"),
9031 popup_targets_received,
9036 gtk_entry_popup_menu (GtkWidget *widget)
9038 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9043 gtk_entry_drag_begin (GtkWidget *widget,
9044 GdkDragContext *context)
9046 GtkEntry *entry = GTK_ENTRY (widget);
9047 GtkEntryPrivate *priv = entry->priv;
9050 for (i = 0; i < MAX_ICONS; i++)
9052 EntryIconInfo *icon_info = priv->icons[i];
9054 if (icon_info != NULL)
9056 if (icon_info->in_drag)
9058 switch (icon_info->storage_type)
9060 case GTK_IMAGE_STOCK:
9061 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
9064 case GTK_IMAGE_ICON_NAME:
9065 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
9068 /* FIXME: No GIcon support for dnd icons */
9069 case GTK_IMAGE_GICON:
9070 case GTK_IMAGE_PIXBUF:
9071 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
9074 g_assert_not_reached ();
9082 gtk_entry_drag_end (GtkWidget *widget,
9083 GdkDragContext *context)
9085 GtkEntry *entry = GTK_ENTRY (widget);
9086 GtkEntryPrivate *priv = entry->priv;
9089 for (i = 0; i < MAX_ICONS; i++)
9091 EntryIconInfo *icon_info = priv->icons[i];
9093 if (icon_info != NULL)
9094 icon_info->in_drag = 0;
9099 gtk_entry_drag_leave (GtkWidget *widget,
9100 GdkDragContext *context,
9103 GtkEntry *entry = GTK_ENTRY (widget);
9104 GtkEntryPrivate *priv = entry->priv;
9106 priv->dnd_position = -1;
9107 gtk_widget_queue_draw (widget);
9111 gtk_entry_drag_drop (GtkWidget *widget,
9112 GdkDragContext *context,
9117 GtkEntry *entry = GTK_ENTRY (widget);
9118 GtkEntryPrivate *priv = entry->priv;
9119 GdkAtom target = GDK_NONE;
9122 target = gtk_drag_dest_find_target (widget, context, NULL);
9124 if (target != GDK_NONE)
9125 gtk_drag_get_data (widget, context, target, time);
9127 gtk_drag_finish (context, FALSE, FALSE, time);
9133 gtk_entry_drag_motion (GtkWidget *widget,
9134 GdkDragContext *context,
9139 GtkEntry *entry = GTK_ENTRY (widget);
9140 GtkEntryPrivate *priv = entry->priv;
9141 GtkStyleContext *style_context;
9142 GtkWidget *source_widget;
9143 GdkDragAction suggested_action;
9144 gint new_position, old_position;
9148 style_context = gtk_widget_get_style_context (widget);
9149 gtk_style_context_get_padding (style_context, 0, &padding);
9153 old_position = priv->dnd_position;
9154 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9156 if (priv->editable &&
9157 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9159 source_widget = gtk_drag_get_source_widget (context);
9160 suggested_action = gdk_drag_context_get_suggested_action (context);
9162 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9163 new_position < sel1 || new_position > sel2)
9165 if (source_widget == widget)
9167 /* Default to MOVE, unless the user has
9168 * pressed ctrl or alt to affect available actions
9170 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9171 suggested_action = GDK_ACTION_MOVE;
9174 priv->dnd_position = new_position;
9178 if (source_widget == widget)
9179 suggested_action = 0; /* Can't drop in selection where drag started */
9181 priv->dnd_position = -1;
9186 /* Entry not editable, or no text */
9187 suggested_action = 0;
9188 priv->dnd_position = -1;
9191 gdk_drag_status (context, suggested_action, time);
9193 if (priv->dnd_position != old_position)
9194 gtk_widget_queue_draw (widget);
9200 gtk_entry_drag_data_received (GtkWidget *widget,
9201 GdkDragContext *context,
9204 GtkSelectionData *selection_data,
9208 GtkEntry *entry = GTK_ENTRY (widget);
9209 GtkEntryPrivate *priv = entry->priv;
9210 GtkEditable *editable = GTK_EDITABLE (widget);
9211 GtkStyleContext *style_context;
9215 str = (gchar *) gtk_selection_data_get_text (selection_data);
9217 style_context = gtk_widget_get_style_context (widget);
9218 gtk_style_context_get_padding (style_context, 0, &padding);
9222 if (str && priv->editable)
9228 if (priv->truncate_multiline)
9229 length = truncate_multiline (str);
9231 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9233 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9234 new_position < sel1 || new_position > sel2)
9236 gtk_editable_insert_text (editable, str, length, &new_position);
9240 /* Replacing selection */
9241 begin_change (entry);
9242 g_object_freeze_notify (G_OBJECT (entry));
9243 gtk_editable_delete_text (editable, sel1, sel2);
9244 gtk_editable_insert_text (editable, str, length, &sel1);
9245 g_object_thaw_notify (G_OBJECT (entry));
9249 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9253 /* Drag and drop didn't happen! */
9254 gtk_drag_finish (context, FALSE, FALSE, time);
9261 gtk_entry_drag_data_get (GtkWidget *widget,
9262 GdkDragContext *context,
9263 GtkSelectionData *selection_data,
9267 GtkEntry *entry = GTK_ENTRY (widget);
9268 GtkEntryPrivate *priv = entry->priv;
9269 GtkEditable *editable = GTK_EDITABLE (widget);
9270 gint sel_start, sel_end;
9273 /* If there is an icon drag going on, exit early. */
9274 for (i = 0; i < MAX_ICONS; i++)
9276 EntryIconInfo *icon_info = priv->icons[i];
9278 if (icon_info != NULL)
9280 if (icon_info->in_drag)
9285 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9287 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9289 gtk_selection_data_set_text (selection_data, str, -1);
9297 gtk_entry_drag_data_delete (GtkWidget *widget,
9298 GdkDragContext *context)
9300 GtkEntry *entry = GTK_ENTRY (widget);
9301 GtkEntryPrivate *priv = entry->priv;
9302 GtkEditable *editable = GTK_EDITABLE (widget);
9303 gint sel_start, sel_end;
9306 /* If there is an icon drag going on, exit early. */
9307 for (i = 0; i < MAX_ICONS; i++)
9309 EntryIconInfo *icon_info = priv->icons[i];
9311 if (icon_info != NULL)
9313 if (icon_info->in_drag)
9318 if (priv->editable &&
9319 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9320 gtk_editable_delete_text (editable, sel_start, sel_end);
9323 /* We display the cursor when
9325 * - the selection is empty, AND
9326 * - the widget has focus
9329 #define CURSOR_ON_MULTIPLIER 2
9330 #define CURSOR_OFF_MULTIPLIER 1
9331 #define CURSOR_PEND_MULTIPLIER 3
9332 #define CURSOR_DIVIDER 3
9335 cursor_blinks (GtkEntry *entry)
9337 GtkEntryPrivate *priv = entry->priv;
9339 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9341 priv->selection_bound == priv->current_pos)
9343 GtkSettings *settings;
9346 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9347 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9356 get_cursor_time (GtkEntry *entry)
9358 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9361 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9367 get_cursor_blink_timeout (GtkEntry *entry)
9369 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9372 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9378 show_cursor (GtkEntry *entry)
9380 GtkEntryPrivate *priv = entry->priv;
9383 if (!priv->cursor_visible)
9385 priv->cursor_visible = TRUE;
9387 widget = GTK_WIDGET (entry);
9388 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9389 gtk_widget_queue_draw (widget);
9394 hide_cursor (GtkEntry *entry)
9396 GtkEntryPrivate *priv = entry->priv;
9399 if (priv->cursor_visible)
9401 priv->cursor_visible = FALSE;
9403 widget = GTK_WIDGET (entry);
9404 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9405 gtk_widget_queue_draw (widget);
9413 blink_cb (gpointer data)
9416 GtkEntryPrivate *priv;
9419 entry = GTK_ENTRY (data);
9422 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9424 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9425 "connect a handler to this signal, it must return\n"
9426 "FALSE so the entry gets the event as well");
9428 gtk_entry_check_cursor_blink (entry);
9433 g_assert (priv->selection_bound == priv->current_pos);
9435 blink_timeout = get_cursor_blink_timeout (entry);
9436 if (priv->blink_time > 1000 * blink_timeout &&
9437 blink_timeout < G_MAXINT/1000)
9439 /* we've blinked enough without the user doing anything, stop blinking */
9440 show_cursor (entry);
9441 priv->blink_timeout = 0;
9443 else if (priv->cursor_visible)
9445 hide_cursor (entry);
9446 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9452 show_cursor (entry);
9453 priv->blink_time += get_cursor_time (entry);
9454 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9459 /* Remove ourselves */
9464 gtk_entry_check_cursor_blink (GtkEntry *entry)
9466 GtkEntryPrivate *priv = entry->priv;
9468 if (cursor_blinks (entry))
9470 if (!priv->blink_timeout)
9472 show_cursor (entry);
9473 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9480 if (priv->blink_timeout)
9482 g_source_remove (priv->blink_timeout);
9483 priv->blink_timeout = 0;
9486 priv->cursor_visible = TRUE;
9491 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9493 GtkEntryPrivate *priv = entry->priv;
9495 if (cursor_blinks (entry))
9497 if (priv->blink_timeout != 0)
9498 g_source_remove (priv->blink_timeout);
9500 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9503 show_cursor (entry);
9508 gtk_entry_reset_blink_time (GtkEntry *entry)
9510 GtkEntryPrivate *priv = entry->priv;
9512 priv->blink_time = 0;
9518 gtk_entry_completion_timeout (gpointer data)
9520 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9521 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9523 completion->priv->completion_timeout = 0;
9525 if (completion->priv->filter_model &&
9526 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9527 >= completion->priv->minimum_key_length)
9531 GtkTreeSelection *s;
9532 gboolean popup_single;
9534 gtk_entry_completion_complete (completion);
9535 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9537 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9539 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9541 gtk_tree_selection_unselect_all (s);
9543 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9545 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9546 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9548 if (gtk_widget_get_visible (completion->priv->popup_window))
9549 _gtk_entry_completion_resize_popup (completion);
9551 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9554 _gtk_entry_completion_popdown (completion);
9556 else if (gtk_widget_get_visible (completion->priv->popup_window))
9557 _gtk_entry_completion_popdown (completion);
9562 static inline gboolean
9563 keyval_is_cursor_move (guint keyval)
9565 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9568 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9571 if (keyval == GDK_KEY_Page_Up)
9574 if (keyval == GDK_KEY_Page_Down)
9581 gtk_entry_completion_key_press (GtkWidget *widget,
9585 gint matches, actions = 0;
9586 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9588 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9591 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9593 if (completion->priv->actions)
9594 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9596 if (keyval_is_cursor_move (event->keyval))
9598 GtkTreePath *path = NULL;
9600 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9602 if (completion->priv->current_selected < 0)
9603 completion->priv->current_selected = matches + actions - 1;
9605 completion->priv->current_selected--;
9607 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9609 if (completion->priv->current_selected < matches + actions - 1)
9610 completion->priv->current_selected++;
9612 completion->priv->current_selected = -1;
9614 else if (event->keyval == GDK_KEY_Page_Up)
9616 if (completion->priv->current_selected < 0)
9617 completion->priv->current_selected = matches + actions - 1;
9618 else if (completion->priv->current_selected == 0)
9619 completion->priv->current_selected = -1;
9620 else if (completion->priv->current_selected < matches)
9622 completion->priv->current_selected -= PAGE_STEP;
9623 if (completion->priv->current_selected < 0)
9624 completion->priv->current_selected = 0;
9628 completion->priv->current_selected -= PAGE_STEP;
9629 if (completion->priv->current_selected < matches - 1)
9630 completion->priv->current_selected = matches - 1;
9633 else if (event->keyval == GDK_KEY_Page_Down)
9635 if (completion->priv->current_selected < 0)
9636 completion->priv->current_selected = 0;
9637 else if (completion->priv->current_selected < matches - 1)
9639 completion->priv->current_selected += PAGE_STEP;
9640 if (completion->priv->current_selected > matches - 1)
9641 completion->priv->current_selected = matches - 1;
9643 else if (completion->priv->current_selected == matches + actions - 1)
9645 completion->priv->current_selected = -1;
9649 completion->priv->current_selected += PAGE_STEP;
9650 if (completion->priv->current_selected > matches + actions - 1)
9651 completion->priv->current_selected = matches + actions - 1;
9655 if (completion->priv->current_selected < 0)
9657 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9658 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9660 if (completion->priv->inline_selection &&
9661 completion->priv->completion_prefix)
9663 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9664 completion->priv->completion_prefix);
9665 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9668 else if (completion->priv->current_selected < matches)
9670 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9672 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9673 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9676 if (completion->priv->inline_selection)
9680 GtkTreeIter child_iter;
9681 GtkTreeModel *model = NULL;
9682 GtkTreeSelection *sel;
9685 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9686 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9689 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9690 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9692 if (completion->priv->completion_prefix == NULL)
9693 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9695 g_signal_emit_by_name (completion, "cursor-on-match", model,
9696 &child_iter, &entry_set);
9699 else if (completion->priv->current_selected - matches >= 0)
9701 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9703 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9704 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9707 if (completion->priv->inline_selection &&
9708 completion->priv->completion_prefix)
9710 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9711 completion->priv->completion_prefix);
9712 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9716 gtk_tree_path_free (path);
9720 else if (event->keyval == GDK_KEY_Escape ||
9721 event->keyval == GDK_KEY_Left ||
9722 event->keyval == GDK_KEY_KP_Left ||
9723 event->keyval == GDK_KEY_Right ||
9724 event->keyval == GDK_KEY_KP_Right)
9726 gboolean retval = TRUE;
9728 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9729 _gtk_entry_completion_popdown (completion);
9731 if (completion->priv->current_selected < 0)
9734 goto keypress_completion_out;
9736 else if (completion->priv->inline_selection)
9738 /* Escape rejects the tentative completion */
9739 if (event->keyval == GDK_KEY_Escape)
9741 if (completion->priv->completion_prefix)
9742 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9743 completion->priv->completion_prefix);
9745 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9748 /* Move the cursor to the end for Right/Esc, to the
9749 beginning for Left */
9750 if (event->keyval == GDK_KEY_Right ||
9751 event->keyval == GDK_KEY_KP_Right ||
9752 event->keyval == GDK_KEY_Escape)
9753 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9755 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9758 keypress_completion_out:
9759 if (completion->priv->inline_selection)
9761 g_free (completion->priv->completion_prefix);
9762 completion->priv->completion_prefix = NULL;
9767 else if (event->keyval == GDK_KEY_Tab ||
9768 event->keyval == GDK_KEY_KP_Tab ||
9769 event->keyval == GDK_KEY_ISO_Left_Tab)
9771 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9772 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9774 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9775 _gtk_entry_completion_popdown (completion);
9777 g_free (completion->priv->completion_prefix);
9778 completion->priv->completion_prefix = NULL;
9780 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9784 else if (event->keyval == GDK_KEY_ISO_Enter ||
9785 event->keyval == GDK_KEY_KP_Enter ||
9786 event->keyval == GDK_KEY_Return)
9789 GtkTreeModel *model = NULL;
9790 GtkTreeModel *child_model;
9791 GtkTreeIter child_iter;
9792 GtkTreeSelection *sel;
9793 gboolean retval = TRUE;
9795 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9796 _gtk_entry_completion_popdown (completion);
9798 if (completion->priv->current_selected < matches)
9802 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9803 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9805 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9806 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9807 g_signal_handler_block (widget, completion->priv->changed_id);
9808 g_signal_emit_by_name (completion, "match-selected",
9809 child_model, &child_iter, &entry_set);
9810 g_signal_handler_unblock (widget, completion->priv->changed_id);
9816 gtk_tree_model_get (model, &iter,
9817 completion->priv->text_column, &str,
9820 gtk_entry_set_text (GTK_ENTRY (widget), str);
9822 /* move the cursor to the end */
9823 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9831 else if (completion->priv->current_selected - matches >= 0)
9833 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9834 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9838 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9839 g_signal_emit_by_name (completion, "action-activated",
9840 gtk_tree_path_get_indices (path)[0]);
9841 gtk_tree_path_free (path);
9847 g_free (completion->priv->completion_prefix);
9848 completion->priv->completion_prefix = NULL;
9857 gtk_entry_completion_changed (GtkWidget *widget,
9860 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9861 GtkEntry *entry = GTK_ENTRY (widget);
9862 GtkEntryPrivate *priv = entry->priv;
9865 /* (re)install completion timeout */
9866 if (completion->priv->completion_timeout)
9867 g_source_remove (completion->priv->completion_timeout);
9869 if (!gtk_entry_get_text (entry))
9872 /* no need to normalize for this test */
9873 if (completion->priv->minimum_key_length > 0 &&
9874 strcmp ("", gtk_entry_get_text (entry)) == 0)
9876 if (gtk_widget_get_visible (completion->priv->popup_window))
9877 _gtk_entry_completion_popdown (completion);
9881 device = gtk_get_current_event_device ();
9883 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9884 device = gdk_device_get_associated_device (device);
9887 priv->completion_device = device;
9889 completion->priv->completion_timeout =
9890 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9891 gtk_entry_completion_timeout,
9896 check_completion_callback (GtkEntryCompletion *completion)
9898 completion->priv->check_completion_idle = NULL;
9900 gtk_entry_completion_complete (completion);
9901 gtk_entry_completion_insert_prefix (completion);
9907 clear_completion_callback (GtkEntry *entry,
9910 if (pspec->name == I_("cursor-position") ||
9911 pspec->name == I_("selection-bound"))
9913 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9915 completion->priv->has_completion = FALSE;
9920 accept_completion_callback (GtkEntry *entry)
9922 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9924 if (completion->priv->has_completion)
9925 gtk_editable_set_position (GTK_EDITABLE (entry),
9926 gtk_entry_buffer_get_length (get_buffer (entry)));
9932 completion_insert_text_callback (GtkEntry *entry,
9936 GtkEntryCompletion *completion)
9938 /* idle to update the selection based on the file list */
9939 if (completion->priv->check_completion_idle == NULL)
9941 completion->priv->check_completion_idle = g_idle_source_new ();
9942 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9943 g_source_set_closure (completion->priv->check_completion_idle,
9944 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9945 G_OBJECT (completion)));
9946 g_source_attach (completion->priv->check_completion_idle, NULL);
9951 completion_changed (GtkEntryCompletion *completion,
9955 GtkEntry *entry = GTK_ENTRY (data);
9957 if (pspec->name == I_("popup-completion") ||
9958 pspec->name == I_("inline-completion"))
9960 disconnect_completion_signals (entry, completion);
9961 connect_completion_signals (entry, completion);
9966 disconnect_completion_signals (GtkEntry *entry,
9967 GtkEntryCompletion *completion)
9969 g_signal_handlers_disconnect_by_func (completion,
9970 G_CALLBACK (completion_changed), entry);
9971 if (completion->priv->changed_id > 0 &&
9972 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9974 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9975 completion->priv->changed_id = 0;
9977 g_signal_handlers_disconnect_by_func (entry,
9978 G_CALLBACK (gtk_entry_completion_key_press), completion);
9979 if (completion->priv->insert_text_id > 0 &&
9980 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9982 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9983 completion->priv->insert_text_id = 0;
9985 g_signal_handlers_disconnect_by_func (entry,
9986 G_CALLBACK (completion_insert_text_callback), completion);
9987 g_signal_handlers_disconnect_by_func (entry,
9988 G_CALLBACK (clear_completion_callback), completion);
9989 g_signal_handlers_disconnect_by_func (entry,
9990 G_CALLBACK (accept_completion_callback), completion);
9994 connect_completion_signals (GtkEntry *entry,
9995 GtkEntryCompletion *completion)
9997 if (completion->priv->popup_completion)
9999 completion->priv->changed_id =
10000 g_signal_connect (entry, "changed",
10001 G_CALLBACK (gtk_entry_completion_changed), completion);
10002 g_signal_connect (entry, "key-press-event",
10003 G_CALLBACK (gtk_entry_completion_key_press), completion);
10006 if (completion->priv->inline_completion)
10008 completion->priv->insert_text_id =
10009 g_signal_connect (entry, "insert-text",
10010 G_CALLBACK (completion_insert_text_callback), completion);
10011 g_signal_connect (entry, "notify",
10012 G_CALLBACK (clear_completion_callback), completion);
10013 g_signal_connect (entry, "activate",
10014 G_CALLBACK (accept_completion_callback), completion);
10015 g_signal_connect (entry, "focus-out-event",
10016 G_CALLBACK (accept_completion_callback), completion);
10019 g_signal_connect (completion, "notify",
10020 G_CALLBACK (completion_changed), entry);
10024 * gtk_entry_set_completion:
10025 * @entry: A #GtkEntry
10026 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
10028 * Sets @completion to be the auxiliary completion object to use with @entry.
10029 * All further configuration of the completion mechanism is done on
10030 * @completion using the #GtkEntryCompletion API. Completion is disabled if
10031 * @completion is set to %NULL.
10036 gtk_entry_set_completion (GtkEntry *entry,
10037 GtkEntryCompletion *completion)
10039 GtkEntryCompletion *old;
10041 g_return_if_fail (GTK_IS_ENTRY (entry));
10042 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
10044 old = gtk_entry_get_completion (entry);
10046 if (old == completion)
10051 if (old->priv->completion_timeout)
10053 g_source_remove (old->priv->completion_timeout);
10054 old->priv->completion_timeout = 0;
10057 if (old->priv->check_completion_idle)
10059 g_source_destroy (old->priv->check_completion_idle);
10060 old->priv->check_completion_idle = NULL;
10063 if (gtk_widget_get_mapped (old->priv->popup_window))
10064 _gtk_entry_completion_popdown (old);
10066 disconnect_completion_signals (entry, old);
10067 old->priv->entry = NULL;
10069 g_object_unref (old);
10074 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
10078 /* hook into the entry */
10079 g_object_ref (completion);
10081 connect_completion_signals (entry, completion);
10082 completion->priv->entry = GTK_WIDGET (entry);
10083 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10085 g_object_notify (G_OBJECT (entry), "completion");
10089 * gtk_entry_get_completion:
10090 * @entry: A #GtkEntry
10092 * Returns the auxiliary completion object currently in use by @entry.
10094 * Return value: (transfer none): The auxiliary completion object currently
10095 * in use by @entry.
10099 GtkEntryCompletion *
10100 gtk_entry_get_completion (GtkEntry *entry)
10102 GtkEntryCompletion *completion;
10104 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10106 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10107 GTK_ENTRY_COMPLETION_KEY));
10113 * gtk_entry_set_cursor_hadjustment:
10114 * @entry: a #GtkEntry
10115 * @adjustment: an adjustment which should be adjusted when the cursor
10116 * is moved, or %NULL
10118 * Hooks up an adjustment to the cursor position in an entry, so that when
10119 * the cursor is moved, the adjustment is scrolled to show that position.
10120 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10123 * The adjustment has to be in pixel units and in the same coordinate system
10129 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10130 GtkAdjustment *adjustment)
10132 g_return_if_fail (GTK_IS_ENTRY (entry));
10134 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10137 g_object_ref (adjustment);
10139 g_object_set_qdata_full (G_OBJECT (entry),
10140 quark_cursor_hadjustment,
10146 * gtk_entry_get_cursor_hadjustment:
10147 * @entry: a #GtkEntry
10149 * Retrieves the horizontal cursor adjustment for the entry.
10150 * See gtk_entry_set_cursor_hadjustment().
10152 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10153 * if none has been set.
10158 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10160 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10162 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10166 * gtk_entry_set_progress_fraction:
10167 * @entry: a #GtkEntry
10168 * @fraction: fraction of the task that's been completed
10170 * Causes the entry's progress indicator to "fill in" the given
10171 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10177 gtk_entry_set_progress_fraction (GtkEntry *entry,
10181 GtkEntryPrivate *private;
10182 gdouble old_fraction;
10183 gint x, y, width, height;
10184 gint old_x, old_y, old_width, old_height;
10186 g_return_if_fail (GTK_IS_ENTRY (entry));
10188 widget = GTK_WIDGET (entry);
10189 private = entry->priv;
10191 if (private->progress_pulse_mode)
10194 old_fraction = private->progress_fraction;
10196 if (gtk_widget_is_drawable (widget))
10197 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10199 fraction = CLAMP (fraction, 0.0, 1.0);
10201 private->progress_fraction = fraction;
10202 private->progress_pulse_mode = FALSE;
10203 private->progress_pulse_current = 0.0;
10205 if (gtk_widget_is_drawable (widget))
10207 get_progress_area (widget, &x, &y, &width, &height);
10209 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10210 gtk_widget_queue_draw (widget);
10213 if (fraction != old_fraction)
10214 g_object_notify (G_OBJECT (entry), "progress-fraction");
10218 * gtk_entry_get_progress_fraction:
10219 * @entry: a #GtkEntry
10221 * Returns the current fraction of the task that's been completed.
10222 * See gtk_entry_set_progress_fraction().
10224 * Return value: a fraction from 0.0 to 1.0
10229 gtk_entry_get_progress_fraction (GtkEntry *entry)
10231 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10233 return entry->priv->progress_fraction;
10237 * gtk_entry_set_progress_pulse_step:
10238 * @entry: a #GtkEntry
10239 * @fraction: fraction between 0.0 and 1.0
10241 * Sets the fraction of total entry width to move the progress
10242 * bouncing block for each call to gtk_entry_progress_pulse().
10247 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10250 GtkEntryPrivate *private;
10252 g_return_if_fail (GTK_IS_ENTRY (entry));
10254 private = entry->priv;
10256 fraction = CLAMP (fraction, 0.0, 1.0);
10258 if (fraction != private->progress_pulse_fraction)
10260 private->progress_pulse_fraction = fraction;
10262 gtk_widget_queue_draw (GTK_WIDGET (entry));
10264 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10269 * gtk_entry_get_progress_pulse_step:
10270 * @entry: a #GtkEntry
10272 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10274 * Return value: a fraction from 0.0 to 1.0
10279 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10281 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10283 return entry->priv->progress_pulse_fraction;
10287 * gtk_entry_progress_pulse:
10288 * @entry: a #GtkEntry
10290 * Indicates that some progress is made, but you don't know how much.
10291 * Causes the entry's progress indicator to enter "activity mode,"
10292 * where a block bounces back and forth. Each call to
10293 * gtk_entry_progress_pulse() causes the block to move by a little bit
10294 * (the amount of movement per pulse is determined by
10295 * gtk_entry_set_progress_pulse_step()).
10300 gtk_entry_progress_pulse (GtkEntry *entry)
10302 GtkEntryPrivate *private;
10304 g_return_if_fail (GTK_IS_ENTRY (entry));
10306 private = entry->priv;
10308 if (private->progress_pulse_mode)
10310 if (private->progress_pulse_way_back)
10312 private->progress_pulse_current -= private->progress_pulse_fraction;
10314 if (private->progress_pulse_current < 0.0)
10316 private->progress_pulse_current = 0.0;
10317 private->progress_pulse_way_back = FALSE;
10322 private->progress_pulse_current += private->progress_pulse_fraction;
10324 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10326 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10327 private->progress_pulse_way_back = TRUE;
10333 private->progress_fraction = 0.0;
10334 private->progress_pulse_mode = TRUE;
10335 private->progress_pulse_way_back = FALSE;
10336 private->progress_pulse_current = 0.0;
10339 gtk_widget_queue_draw (GTK_WIDGET (entry));
10343 * gtk_entry_set_placeholder_text:
10344 * @entry: a #GtkEntry
10345 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10347 * Sets text to be displayed in @entry when
10348 * it is empty and unfocused. This can be used to give a visual hint
10349 * of the expected contents of the #GtkEntry.
10354 gtk_entry_set_placeholder_text (GtkEntry *entry,
10357 GtkEntryPrivate *priv;
10359 g_return_if_fail (GTK_IS_ENTRY (entry));
10361 priv = entry->priv;
10363 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10366 g_free (priv->placeholder_text);
10367 priv->placeholder_text = g_strdup (text);
10369 gtk_entry_recompute (entry);
10371 g_object_notify (G_OBJECT (entry), "placeholder-text");
10375 * gtk_entry_get_placeholder_text:
10376 * @entry: a #GtkEntry
10378 * Retrieves the text that will be displayed when @entry is empty and unfocused
10380 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10381 * storage in the widget and must not be freed, modified or stored.
10386 gtk_entry_get_placeholder_text (GtkEntry *entry)
10388 GtkEntryPrivate *priv;
10390 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10392 priv = entry->priv;
10394 return priv->placeholder_text;
10397 /* Caps Lock warning for password entries */
10400 show_capslock_feedback (GtkEntry *entry,
10403 GtkEntryPrivate *priv = entry->priv;
10405 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10407 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10408 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10409 priv->caps_lock_warning_shown = TRUE;
10412 if (priv->caps_lock_warning_shown)
10413 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10415 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10419 remove_capslock_feedback (GtkEntry *entry)
10421 GtkEntryPrivate *priv = entry->priv;
10423 if (priv->caps_lock_warning_shown)
10425 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10426 priv->caps_lock_warning_shown = FALSE;
10431 keymap_state_changed (GdkKeymap *keymap,
10434 GtkEntryPrivate *priv = entry->priv;
10437 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10439 if (gdk_keymap_get_num_lock_state (keymap)
10440 && gdk_keymap_get_caps_lock_state (keymap))
10441 text = _("Caps Lock and Num Lock are on");
10442 else if (gdk_keymap_get_num_lock_state (keymap))
10443 text = _("Num Lock is on");
10444 else if (gdk_keymap_get_caps_lock_state (keymap))
10445 text = _("Caps Lock is on");
10449 show_capslock_feedback (entry, text);
10451 remove_capslock_feedback (entry);
10455 * _gtk_entry_set_is_cell_renderer:
10456 * @entry: a #GtkEntry
10457 * @is_cell_renderer: new value
10459 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10460 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10462 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10466 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10467 gboolean is_cell_renderer)
10469 entry->priv->is_cell_renderer = is_cell_renderer;