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
1000 g_object_class_install_property (gobject_class,
1001 PROP_PLACEHOLDER_TEXT,
1002 g_param_spec_string ("placeholder-text",
1003 P_("Placeholder text"),
1004 P_("Show text in the entry when it's empty and unfocused"),
1006 GTK_PARAM_READWRITE));
1009 * GtkEntry:primary-icon-pixbuf:
1011 * A pixbuf to use as the primary icon for the entry.
1015 g_object_class_install_property (gobject_class,
1016 PROP_PIXBUF_PRIMARY,
1017 g_param_spec_object ("primary-icon-pixbuf",
1018 P_("Primary pixbuf"),
1019 P_("Primary pixbuf for the entry"),
1021 GTK_PARAM_READWRITE));
1024 * GtkEntry:secondary-icon-pixbuf:
1026 * An pixbuf to use as the secondary icon for the entry.
1030 g_object_class_install_property (gobject_class,
1031 PROP_PIXBUF_SECONDARY,
1032 g_param_spec_object ("secondary-icon-pixbuf",
1033 P_("Secondary pixbuf"),
1034 P_("Secondary pixbuf for the entry"),
1036 GTK_PARAM_READWRITE));
1039 * GtkEntry:primary-icon-stock:
1041 * The stock id to use for the primary icon for the entry.
1045 g_object_class_install_property (gobject_class,
1047 g_param_spec_string ("primary-icon-stock",
1048 P_("Primary stock ID"),
1049 P_("Stock ID for primary icon"),
1051 GTK_PARAM_READWRITE));
1054 * GtkEntry:secondary-icon-stock:
1056 * The stock id to use for the secondary icon for the entry.
1060 g_object_class_install_property (gobject_class,
1061 PROP_STOCK_SECONDARY,
1062 g_param_spec_string ("secondary-icon-stock",
1063 P_("Secondary stock ID"),
1064 P_("Stock ID for secondary icon"),
1066 GTK_PARAM_READWRITE));
1069 * GtkEntry:primary-icon-name:
1071 * The icon name to use for the primary icon for the entry.
1075 g_object_class_install_property (gobject_class,
1076 PROP_ICON_NAME_PRIMARY,
1077 g_param_spec_string ("primary-icon-name",
1078 P_("Primary icon name"),
1079 P_("Icon name for primary icon"),
1081 GTK_PARAM_READWRITE));
1084 * GtkEntry:secondary-icon-name:
1086 * The icon name to use for the secondary icon for the entry.
1090 g_object_class_install_property (gobject_class,
1091 PROP_ICON_NAME_SECONDARY,
1092 g_param_spec_string ("secondary-icon-name",
1093 P_("Secondary icon name"),
1094 P_("Icon name for secondary icon"),
1096 GTK_PARAM_READWRITE));
1099 * GtkEntry:primary-icon-gicon:
1101 * The #GIcon to use for the primary icon for the entry.
1105 g_object_class_install_property (gobject_class,
1107 g_param_spec_object ("primary-icon-gicon",
1108 P_("Primary GIcon"),
1109 P_("GIcon for primary icon"),
1111 GTK_PARAM_READWRITE));
1114 * GtkEntry:secondary-icon-gicon:
1116 * The #GIcon to use for the secondary icon for the entry.
1120 g_object_class_install_property (gobject_class,
1121 PROP_GICON_SECONDARY,
1122 g_param_spec_object ("secondary-icon-gicon",
1123 P_("Secondary GIcon"),
1124 P_("GIcon for secondary icon"),
1126 GTK_PARAM_READWRITE));
1129 * GtkEntry:primary-icon-storage-type:
1131 * The representation which is used for the primary icon of the entry.
1135 g_object_class_install_property (gobject_class,
1136 PROP_STORAGE_TYPE_PRIMARY,
1137 g_param_spec_enum ("primary-icon-storage-type",
1138 P_("Primary storage type"),
1139 P_("The representation being used for primary icon"),
1140 GTK_TYPE_IMAGE_TYPE,
1142 GTK_PARAM_READABLE));
1145 * GtkEntry:secondary-icon-storage-type:
1147 * The representation which is used for the secondary icon of the entry.
1151 g_object_class_install_property (gobject_class,
1152 PROP_STORAGE_TYPE_SECONDARY,
1153 g_param_spec_enum ("secondary-icon-storage-type",
1154 P_("Secondary storage type"),
1155 P_("The representation being used for secondary icon"),
1156 GTK_TYPE_IMAGE_TYPE,
1158 GTK_PARAM_READABLE));
1161 * GtkEntry:primary-icon-activatable:
1163 * Whether the primary icon is activatable.
1165 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1166 * signals only on sensitive, activatable icons.
1168 * Sensitive, but non-activatable icons can be used for purely
1169 * informational purposes.
1173 g_object_class_install_property (gobject_class,
1174 PROP_ACTIVATABLE_PRIMARY,
1175 g_param_spec_boolean ("primary-icon-activatable",
1176 P_("Primary icon activatable"),
1177 P_("Whether the primary icon is activatable"),
1179 GTK_PARAM_READWRITE));
1182 * GtkEntry:secondary-icon-activatable:
1184 * Whether the secondary icon is activatable.
1186 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1187 * signals only on sensitive, activatable icons.
1189 * Sensitive, but non-activatable icons can be used for purely
1190 * informational purposes.
1194 g_object_class_install_property (gobject_class,
1195 PROP_ACTIVATABLE_SECONDARY,
1196 g_param_spec_boolean ("secondary-icon-activatable",
1197 P_("Secondary icon activatable"),
1198 P_("Whether the secondary icon is activatable"),
1200 GTK_PARAM_READWRITE));
1204 * GtkEntry:primary-icon-sensitive:
1206 * Whether the primary icon is sensitive.
1208 * An insensitive icon appears grayed out. GTK+ does not emit the
1209 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1210 * does not allow DND from insensitive icons.
1212 * An icon should be set insensitive if the action that would trigger
1213 * when clicked is currently not available.
1217 g_object_class_install_property (gobject_class,
1218 PROP_SENSITIVE_PRIMARY,
1219 g_param_spec_boolean ("primary-icon-sensitive",
1220 P_("Primary icon sensitive"),
1221 P_("Whether the primary icon is sensitive"),
1223 GTK_PARAM_READWRITE));
1226 * GtkEntry:secondary-icon-sensitive:
1228 * Whether the secondary icon is sensitive.
1230 * An insensitive icon appears grayed out. GTK+ does not emit the
1231 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1232 * does not allow DND from insensitive icons.
1234 * An icon should be set insensitive if the action that would trigger
1235 * when clicked is currently not available.
1239 g_object_class_install_property (gobject_class,
1240 PROP_SENSITIVE_SECONDARY,
1241 g_param_spec_boolean ("secondary-icon-sensitive",
1242 P_("Secondary icon sensitive"),
1243 P_("Whether the secondary icon is sensitive"),
1245 GTK_PARAM_READWRITE));
1248 * GtkEntry:primary-icon-tooltip-text:
1250 * The contents of the tooltip on the primary icon.
1252 * Also see gtk_entry_set_icon_tooltip_text().
1256 g_object_class_install_property (gobject_class,
1257 PROP_TOOLTIP_TEXT_PRIMARY,
1258 g_param_spec_string ("primary-icon-tooltip-text",
1259 P_("Primary icon tooltip text"),
1260 P_("The contents of the tooltip on the primary icon"),
1262 GTK_PARAM_READWRITE));
1265 * GtkEntry:secondary-icon-tooltip-text:
1267 * The contents of the tooltip on the secondary icon.
1269 * Also see gtk_entry_set_icon_tooltip_text().
1273 g_object_class_install_property (gobject_class,
1274 PROP_TOOLTIP_TEXT_SECONDARY,
1275 g_param_spec_string ("secondary-icon-tooltip-text",
1276 P_("Secondary icon tooltip text"),
1277 P_("The contents of the tooltip on the secondary icon"),
1279 GTK_PARAM_READWRITE));
1282 * GtkEntry:primary-icon-tooltip-markup:
1284 * The contents of the tooltip on the primary icon, which is marked up
1285 * with the <link linkend="PangoMarkupFormat">Pango text markup
1288 * Also see gtk_entry_set_icon_tooltip_markup().
1292 g_object_class_install_property (gobject_class,
1293 PROP_TOOLTIP_MARKUP_PRIMARY,
1294 g_param_spec_string ("primary-icon-tooltip-markup",
1295 P_("Primary icon tooltip markup"),
1296 P_("The contents of the tooltip on the primary icon"),
1298 GTK_PARAM_READWRITE));
1301 * GtkEntry:secondary-icon-tooltip-markup:
1303 * The contents of the tooltip on the secondary icon, which is marked up
1304 * with the <link linkend="PangoMarkupFormat">Pango text markup
1307 * Also see gtk_entry_set_icon_tooltip_markup().
1311 g_object_class_install_property (gobject_class,
1312 PROP_TOOLTIP_MARKUP_SECONDARY,
1313 g_param_spec_string ("secondary-icon-tooltip-markup",
1314 P_("Secondary icon tooltip markup"),
1315 P_("The contents of the tooltip on the secondary icon"),
1317 GTK_PARAM_READWRITE));
1320 * GtkEntry:im-module:
1322 * Which IM (input method) module should be used for this entry.
1323 * See #GtkIMContext.
1325 * Setting this to a non-%NULL value overrides the
1326 * system-wide IM module setting. See the GtkSettings
1327 * #GtkSettings:gtk-im-module property.
1331 g_object_class_install_property (gobject_class,
1333 g_param_spec_string ("im-module",
1335 P_("Which IM module should be used"),
1337 GTK_PARAM_READWRITE));
1340 * GtkEntry:completion:
1342 * The auxiliary completion object to use with the entry.
1346 g_object_class_install_property (gobject_class,
1348 g_param_spec_object ("completion",
1350 P_("The auxiliary completion object"),
1351 GTK_TYPE_ENTRY_COMPLETION,
1352 GTK_PARAM_READWRITE));
1355 * GtkEntry:icon-prelight:
1357 * The prelight style property determines whether activatable
1358 * icons prelight on mouseover.
1362 gtk_widget_class_install_style_property (widget_class,
1363 g_param_spec_boolean ("icon-prelight",
1364 P_("Icon Prelight"),
1365 P_("Whether activatable icons should prelight when hovered"),
1367 GTK_PARAM_READABLE));
1370 * GtkEntry:progress-border:
1372 * The border around the progress bar in the entry.
1376 gtk_widget_class_install_style_property (widget_class,
1377 g_param_spec_boxed ("progress-border",
1378 P_("Progress Border"),
1379 P_("Border around the progress bar"),
1381 GTK_PARAM_READABLE));
1384 * GtkEntry:invisible-char:
1386 * The invisible character is used when masking entry contents (in
1387 * \"password mode\")"). When it is not explicitly set with the
1388 * #GtkEntry::invisible-char property, GTK+ determines the character
1389 * to use from a list of possible candidates, depending on availability
1390 * in the current font.
1392 * This style property allows the theme to prepend a character
1393 * to the list of candidates.
1397 gtk_widget_class_install_style_property (widget_class,
1398 g_param_spec_unichar ("invisible-char",
1399 P_("Invisible character"),
1400 P_("The character to use when masking entry contents (in \"password mode\")"),
1402 GTK_PARAM_READABLE));
1405 * GtkEntry::populate-popup:
1406 * @entry: The entry on which the signal is emitted
1407 * @menu: the menu that is being populated
1409 * The ::populate-popup signal gets emitted before showing the
1410 * context menu of the entry.
1412 * If you need to add items to the context menu, connect
1413 * to this signal and append your menuitems to the @menu.
1415 signals[POPULATE_POPUP] =
1416 g_signal_new (I_("populate-popup"),
1417 G_OBJECT_CLASS_TYPE (gobject_class),
1419 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1421 _gtk_marshal_VOID__OBJECT,
1425 /* Action signals */
1428 * GtkEntry::activate:
1429 * @entry: The entry on which the signal is emitted
1431 * A <link linkend="keybinding-signals">keybinding signal</link>
1432 * which gets emitted when the user activates the entry.
1434 * Applications should not connect to it, but may emit it with
1435 * g_signal_emit_by_name() if they need to control activation
1438 * The default bindings for this signal are all forms of the Enter key.
1441 g_signal_new (I_("activate"),
1442 G_OBJECT_CLASS_TYPE (gobject_class),
1443 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1444 G_STRUCT_OFFSET (GtkEntryClass, activate),
1446 _gtk_marshal_VOID__VOID,
1448 widget_class->activate_signal = signals[ACTIVATE];
1451 * GtkEntry::move-cursor:
1452 * @entry: the object which received the signal
1453 * @step: the granularity of the move, as a #GtkMovementStep
1454 * @count: the number of @step units to move
1455 * @extend_selection: %TRUE if the move should extend the selection
1457 * The ::move-cursor signal is a
1458 * <link linkend="keybinding-signals">keybinding signal</link>
1459 * which gets emitted when the user initiates a cursor movement.
1460 * If the cursor is not visible in @entry, this signal causes
1461 * the viewport to be moved instead.
1463 * Applications should not connect to it, but may emit it with
1464 * g_signal_emit_by_name() if they need to control the cursor
1467 * The default bindings for this signal come in two variants,
1468 * the variant with the Shift modifier extends the selection,
1469 * the variant without the Shift modifer does not.
1470 * There are too many key combinations to list them all here.
1472 * <listitem>Arrow keys move by individual characters/lines</listitem>
1473 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1474 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1477 signals[MOVE_CURSOR] =
1478 g_signal_new (I_("move-cursor"),
1479 G_OBJECT_CLASS_TYPE (gobject_class),
1480 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1481 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1483 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1485 GTK_TYPE_MOVEMENT_STEP,
1490 * GtkEntry::insert-at-cursor:
1491 * @entry: the object which received the signal
1492 * @string: the string to insert
1494 * The ::insert-at-cursor signal is a
1495 * <link linkend="keybinding-signals">keybinding signal</link>
1496 * which gets emitted when the user initiates the insertion of a
1497 * fixed string at the cursor.
1499 * This signal has no default bindings.
1501 signals[INSERT_AT_CURSOR] =
1502 g_signal_new (I_("insert-at-cursor"),
1503 G_OBJECT_CLASS_TYPE (gobject_class),
1504 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1505 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1507 _gtk_marshal_VOID__STRING,
1512 * GtkEntry::delete-from-cursor:
1513 * @entry: the object which received the signal
1514 * @type: the granularity of the deletion, as a #GtkDeleteType
1515 * @count: the number of @type units to delete
1517 * The ::delete-from-cursor signal is a
1518 * <link linkend="keybinding-signals">keybinding signal</link>
1519 * which gets emitted when the user initiates a text deletion.
1521 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1522 * if there is one, otherwise it deletes the requested number
1525 * The default bindings for this signal are
1526 * Delete for deleting a character and Ctrl-Delete for
1529 signals[DELETE_FROM_CURSOR] =
1530 g_signal_new (I_("delete-from-cursor"),
1531 G_OBJECT_CLASS_TYPE (gobject_class),
1532 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1533 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1535 _gtk_marshal_VOID__ENUM_INT,
1537 GTK_TYPE_DELETE_TYPE,
1541 * GtkEntry::backspace:
1542 * @entry: the object which received the signal
1544 * The ::backspace signal is a
1545 * <link linkend="keybinding-signals">keybinding signal</link>
1546 * which gets emitted when the user asks for it.
1548 * The default bindings for this signal are
1549 * Backspace and Shift-Backspace.
1551 signals[BACKSPACE] =
1552 g_signal_new (I_("backspace"),
1553 G_OBJECT_CLASS_TYPE (gobject_class),
1554 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1555 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1557 _gtk_marshal_VOID__VOID,
1561 * GtkEntry::cut-clipboard:
1562 * @entry: the object which received the signal
1564 * The ::cut-clipboard signal is a
1565 * <link linkend="keybinding-signals">keybinding signal</link>
1566 * which gets emitted to cut the selection to the clipboard.
1568 * The default bindings for this signal are
1569 * Ctrl-x and Shift-Delete.
1571 signals[CUT_CLIPBOARD] =
1572 g_signal_new (I_("cut-clipboard"),
1573 G_OBJECT_CLASS_TYPE (gobject_class),
1574 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1575 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1577 _gtk_marshal_VOID__VOID,
1581 * GtkEntry::copy-clipboard:
1582 * @entry: the object which received the signal
1584 * The ::copy-clipboard signal is a
1585 * <link linkend="keybinding-signals">keybinding signal</link>
1586 * which gets emitted to copy the selection to the clipboard.
1588 * The default bindings for this signal are
1589 * Ctrl-c and Ctrl-Insert.
1591 signals[COPY_CLIPBOARD] =
1592 g_signal_new (I_("copy-clipboard"),
1593 G_OBJECT_CLASS_TYPE (gobject_class),
1594 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1595 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1597 _gtk_marshal_VOID__VOID,
1601 * GtkEntry::paste-clipboard:
1602 * @entry: the object which received the signal
1604 * The ::paste-clipboard signal is a
1605 * <link linkend="keybinding-signals">keybinding signal</link>
1606 * which gets emitted to paste the contents of the clipboard
1607 * into the text view.
1609 * The default bindings for this signal are
1610 * Ctrl-v and Shift-Insert.
1612 signals[PASTE_CLIPBOARD] =
1613 g_signal_new (I_("paste-clipboard"),
1614 G_OBJECT_CLASS_TYPE (gobject_class),
1615 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1616 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1618 _gtk_marshal_VOID__VOID,
1622 * GtkEntry::toggle-overwrite:
1623 * @entry: the object which received the signal
1625 * The ::toggle-overwrite signal is a
1626 * <link linkend="keybinding-signals">keybinding signal</link>
1627 * which gets emitted to toggle the overwrite mode of the entry.
1629 * The default bindings for this signal is Insert.
1631 signals[TOGGLE_OVERWRITE] =
1632 g_signal_new (I_("toggle-overwrite"),
1633 G_OBJECT_CLASS_TYPE (gobject_class),
1634 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1635 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1637 _gtk_marshal_VOID__VOID,
1641 * GtkEntry::icon-press:
1642 * @entry: The entry on which the signal is emitted
1643 * @icon_pos: The position of the clicked icon
1644 * @event: (type Gdk.EventButton): the button press event
1646 * The ::icon-press signal is emitted when an activatable icon
1651 signals[ICON_PRESS] =
1652 g_signal_new (I_("icon-press"),
1653 G_TYPE_FROM_CLASS (gobject_class),
1657 _gtk_marshal_VOID__ENUM_BOXED,
1659 GTK_TYPE_ENTRY_ICON_POSITION,
1660 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1663 * GtkEntry::icon-release:
1664 * @entry: The entry on which the signal is emitted
1665 * @icon_pos: The position of the clicked icon
1666 * @event: (type Gdk.EventButton): the button release event
1668 * The ::icon-release signal is emitted on the button release from a
1669 * mouse click over an activatable icon.
1673 signals[ICON_RELEASE] =
1674 g_signal_new (I_("icon-release"),
1675 G_TYPE_FROM_CLASS (gobject_class),
1679 _gtk_marshal_VOID__ENUM_BOXED,
1681 GTK_TYPE_ENTRY_ICON_POSITION,
1682 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1685 * GtkEntry::preedit-changed:
1686 * @entry: the object which received the signal
1687 * @preedit: the current preedit string
1689 * If an input method is used, the typed text will not immediately
1690 * be committed to the buffer. So if you are interested in the text,
1691 * connect to this signal.
1695 signals[PREEDIT_CHANGED] =
1696 g_signal_new_class_handler (I_("preedit-changed"),
1697 G_OBJECT_CLASS_TYPE (gobject_class),
1698 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1701 _gtk_marshal_VOID__STRING,
1710 binding_set = gtk_binding_set_by_class (class);
1712 /* Moving the insertion point */
1713 add_move_binding (binding_set, GDK_KEY_Right, 0,
1714 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1716 add_move_binding (binding_set, GDK_KEY_Left, 0,
1717 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1719 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1720 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1722 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1723 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1725 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1726 GTK_MOVEMENT_WORDS, 1);
1728 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1729 GTK_MOVEMENT_WORDS, -1);
1731 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1732 GTK_MOVEMENT_WORDS, 1);
1734 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1735 GTK_MOVEMENT_WORDS, -1);
1737 add_move_binding (binding_set, GDK_KEY_Home, 0,
1738 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1740 add_move_binding (binding_set, GDK_KEY_End, 0,
1741 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1743 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1744 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1746 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1747 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1749 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1750 GTK_MOVEMENT_BUFFER_ENDS, -1);
1752 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1753 GTK_MOVEMENT_BUFFER_ENDS, 1);
1755 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1756 GTK_MOVEMENT_BUFFER_ENDS, -1);
1758 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1759 GTK_MOVEMENT_BUFFER_ENDS, 1);
1763 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1765 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1767 G_TYPE_BOOLEAN, FALSE);
1768 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1770 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1772 G_TYPE_BOOLEAN, TRUE);
1774 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1776 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1778 G_TYPE_BOOLEAN, FALSE);
1779 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1781 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1783 G_TYPE_BOOLEAN, TRUE);
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1788 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1790 G_TYPE_BOOLEAN, FALSE);
1791 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1793 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1795 G_TYPE_BOOLEAN, FALSE);
1799 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1801 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1803 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1808 "delete-from-cursor", 2,
1809 G_TYPE_ENUM, GTK_DELETE_CHARS,
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1813 "delete-from-cursor", 2,
1814 G_TYPE_ENUM, GTK_DELETE_CHARS,
1817 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1820 /* Make this do the same as Backspace, to help with mis-typing */
1821 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1825 "delete-from-cursor", 2,
1826 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1829 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1830 "delete-from-cursor", 2,
1831 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1834 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1835 "delete-from-cursor", 2,
1836 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1839 /* Cut/copy/paste */
1841 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1842 "cut-clipboard", 0);
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1844 "copy-clipboard", 0);
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1846 "paste-clipboard", 0);
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1849 "cut-clipboard", 0);
1850 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1851 "copy-clipboard", 0);
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1853 "paste-clipboard", 0);
1856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1857 "toggle-overwrite", 0);
1858 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1859 "toggle-overwrite", 0);
1862 * GtkEntry:inner-border:
1864 * Sets the text area's border between the text and the frame.
1868 gtk_widget_class_install_style_property (widget_class,
1869 g_param_spec_boxed ("inner-border",
1871 P_("Border between text and frame."),
1873 GTK_PARAM_READABLE));
1875 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1877 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1881 gtk_entry_editable_init (GtkEditableInterface *iface)
1883 iface->do_insert_text = gtk_entry_insert_text;
1884 iface->do_delete_text = gtk_entry_delete_text;
1885 iface->insert_text = gtk_entry_real_insert_text;
1886 iface->delete_text = gtk_entry_real_delete_text;
1887 iface->get_chars = gtk_entry_get_chars;
1888 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1889 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1890 iface->set_position = gtk_entry_real_set_position;
1891 iface->get_position = gtk_entry_get_position;
1895 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1897 iface->start_editing = gtk_entry_start_editing;
1901 gtk_entry_set_property (GObject *object,
1903 const GValue *value,
1906 GtkEntry *entry = GTK_ENTRY (object);
1907 GtkEntryPrivate *priv = entry->priv;
1912 gtk_entry_set_buffer (entry, g_value_get_object (value));
1917 gboolean new_value = g_value_get_boolean (value);
1919 if (new_value != priv->editable)
1921 GtkWidget *widget = GTK_WIDGET (entry);
1925 _gtk_entry_reset_im_context (entry);
1926 if (gtk_widget_has_focus (widget))
1927 gtk_im_context_focus_out (priv->im_context);
1929 priv->preedit_length = 0;
1930 priv->preedit_cursor = 0;
1933 priv->editable = new_value;
1935 if (new_value && gtk_widget_has_focus (widget))
1936 gtk_im_context_focus_in (priv->im_context);
1938 gtk_widget_queue_draw (widget);
1943 case PROP_MAX_LENGTH:
1944 gtk_entry_set_max_length (entry, g_value_get_int (value));
1947 case PROP_VISIBILITY:
1948 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1951 case PROP_HAS_FRAME:
1952 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1955 case PROP_INNER_BORDER:
1956 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1959 case PROP_INVISIBLE_CHAR:
1960 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1963 case PROP_ACTIVATES_DEFAULT:
1964 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1967 case PROP_WIDTH_CHARS:
1968 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1972 gtk_entry_set_text (entry, g_value_get_string (value));
1976 gtk_entry_set_alignment (entry, g_value_get_float (value));
1979 case PROP_TRUNCATE_MULTILINE:
1980 priv->truncate_multiline = g_value_get_boolean (value);
1983 case PROP_SHADOW_TYPE:
1984 priv->shadow_type = g_value_get_enum (value);
1987 case PROP_OVERWRITE_MODE:
1988 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1991 case PROP_INVISIBLE_CHAR_SET:
1992 if (g_value_get_boolean (value))
1993 priv->invisible_char_set = TRUE;
1995 gtk_entry_unset_invisible_char (entry);
1998 case PROP_CAPS_LOCK_WARNING:
1999 priv->caps_lock_warning = g_value_get_boolean (value);
2002 case PROP_PROGRESS_FRACTION:
2003 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2006 case PROP_PROGRESS_PULSE_STEP:
2007 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2010 case PROP_PLACEHOLDER_TEXT:
2011 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2014 case PROP_PIXBUF_PRIMARY:
2015 gtk_entry_set_icon_from_pixbuf (entry,
2016 GTK_ENTRY_ICON_PRIMARY,
2017 g_value_get_object (value));
2020 case PROP_PIXBUF_SECONDARY:
2021 gtk_entry_set_icon_from_pixbuf (entry,
2022 GTK_ENTRY_ICON_SECONDARY,
2023 g_value_get_object (value));
2026 case PROP_STOCK_PRIMARY:
2027 gtk_entry_set_icon_from_stock (entry,
2028 GTK_ENTRY_ICON_PRIMARY,
2029 g_value_get_string (value));
2032 case PROP_STOCK_SECONDARY:
2033 gtk_entry_set_icon_from_stock (entry,
2034 GTK_ENTRY_ICON_SECONDARY,
2035 g_value_get_string (value));
2038 case PROP_ICON_NAME_PRIMARY:
2039 gtk_entry_set_icon_from_icon_name (entry,
2040 GTK_ENTRY_ICON_PRIMARY,
2041 g_value_get_string (value));
2044 case PROP_ICON_NAME_SECONDARY:
2045 gtk_entry_set_icon_from_icon_name (entry,
2046 GTK_ENTRY_ICON_SECONDARY,
2047 g_value_get_string (value));
2050 case PROP_GICON_PRIMARY:
2051 gtk_entry_set_icon_from_gicon (entry,
2052 GTK_ENTRY_ICON_PRIMARY,
2053 g_value_get_object (value));
2056 case PROP_GICON_SECONDARY:
2057 gtk_entry_set_icon_from_gicon (entry,
2058 GTK_ENTRY_ICON_SECONDARY,
2059 g_value_get_object (value));
2062 case PROP_ACTIVATABLE_PRIMARY:
2063 gtk_entry_set_icon_activatable (entry,
2064 GTK_ENTRY_ICON_PRIMARY,
2065 g_value_get_boolean (value));
2068 case PROP_ACTIVATABLE_SECONDARY:
2069 gtk_entry_set_icon_activatable (entry,
2070 GTK_ENTRY_ICON_SECONDARY,
2071 g_value_get_boolean (value));
2074 case PROP_SENSITIVE_PRIMARY:
2075 gtk_entry_set_icon_sensitive (entry,
2076 GTK_ENTRY_ICON_PRIMARY,
2077 g_value_get_boolean (value));
2080 case PROP_SENSITIVE_SECONDARY:
2081 gtk_entry_set_icon_sensitive (entry,
2082 GTK_ENTRY_ICON_SECONDARY,
2083 g_value_get_boolean (value));
2086 case PROP_TOOLTIP_TEXT_PRIMARY:
2087 gtk_entry_set_icon_tooltip_text (entry,
2088 GTK_ENTRY_ICON_PRIMARY,
2089 g_value_get_string (value));
2092 case PROP_TOOLTIP_TEXT_SECONDARY:
2093 gtk_entry_set_icon_tooltip_text (entry,
2094 GTK_ENTRY_ICON_SECONDARY,
2095 g_value_get_string (value));
2098 case PROP_TOOLTIP_MARKUP_PRIMARY:
2099 gtk_entry_set_icon_tooltip_markup (entry,
2100 GTK_ENTRY_ICON_PRIMARY,
2101 g_value_get_string (value));
2104 case PROP_TOOLTIP_MARKUP_SECONDARY:
2105 gtk_entry_set_icon_tooltip_markup (entry,
2106 GTK_ENTRY_ICON_SECONDARY,
2107 g_value_get_string (value));
2110 case PROP_IM_MODULE:
2111 g_free (priv->im_module);
2112 priv->im_module = g_value_dup_string (value);
2113 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2114 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2117 case PROP_EDITING_CANCELED:
2118 priv->editing_canceled = g_value_get_boolean (value);
2121 case PROP_COMPLETION:
2122 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2125 case PROP_SCROLL_OFFSET:
2126 case PROP_CURSOR_POSITION:
2128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2134 gtk_entry_get_property (GObject *object,
2139 GtkEntry *entry = GTK_ENTRY (object);
2140 GtkEntryPrivate *priv = entry->priv;
2145 g_value_set_object (value, gtk_entry_get_buffer (entry));
2148 case PROP_CURSOR_POSITION:
2149 g_value_set_int (value, priv->current_pos);
2152 case PROP_SELECTION_BOUND:
2153 g_value_set_int (value, priv->selection_bound);
2157 g_value_set_boolean (value, priv->editable);
2160 case PROP_MAX_LENGTH:
2161 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2164 case PROP_VISIBILITY:
2165 g_value_set_boolean (value, priv->visible);
2168 case PROP_HAS_FRAME:
2169 g_value_set_boolean (value, priv->has_frame);
2172 case PROP_INNER_BORDER:
2173 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2176 case PROP_INVISIBLE_CHAR:
2177 g_value_set_uint (value, priv->invisible_char);
2180 case PROP_ACTIVATES_DEFAULT:
2181 g_value_set_boolean (value, priv->activates_default);
2184 case PROP_WIDTH_CHARS:
2185 g_value_set_int (value, priv->width_chars);
2188 case PROP_SCROLL_OFFSET:
2189 g_value_set_int (value, priv->scroll_offset);
2193 g_value_set_string (value, gtk_entry_get_text (entry));
2197 g_value_set_float (value, gtk_entry_get_alignment (entry));
2200 case PROP_TRUNCATE_MULTILINE:
2201 g_value_set_boolean (value, priv->truncate_multiline);
2204 case PROP_SHADOW_TYPE:
2205 g_value_set_enum (value, priv->shadow_type);
2208 case PROP_OVERWRITE_MODE:
2209 g_value_set_boolean (value, priv->overwrite_mode);
2212 case PROP_TEXT_LENGTH:
2213 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2216 case PROP_INVISIBLE_CHAR_SET:
2217 g_value_set_boolean (value, priv->invisible_char_set);
2220 case PROP_IM_MODULE:
2221 g_value_set_string (value, priv->im_module);
2224 case PROP_CAPS_LOCK_WARNING:
2225 g_value_set_boolean (value, priv->caps_lock_warning);
2228 case PROP_PROGRESS_FRACTION:
2229 g_value_set_double (value, priv->progress_fraction);
2232 case PROP_PROGRESS_PULSE_STEP:
2233 g_value_set_double (value, priv->progress_pulse_fraction);
2236 case PROP_PLACEHOLDER_TEXT:
2237 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2240 case PROP_PIXBUF_PRIMARY:
2241 g_value_set_object (value,
2242 gtk_entry_get_icon_pixbuf (entry,
2243 GTK_ENTRY_ICON_PRIMARY));
2246 case PROP_PIXBUF_SECONDARY:
2247 g_value_set_object (value,
2248 gtk_entry_get_icon_pixbuf (entry,
2249 GTK_ENTRY_ICON_SECONDARY));
2252 case PROP_STOCK_PRIMARY:
2253 g_value_set_string (value,
2254 gtk_entry_get_icon_stock (entry,
2255 GTK_ENTRY_ICON_PRIMARY));
2258 case PROP_STOCK_SECONDARY:
2259 g_value_set_string (value,
2260 gtk_entry_get_icon_stock (entry,
2261 GTK_ENTRY_ICON_SECONDARY));
2264 case PROP_ICON_NAME_PRIMARY:
2265 g_value_set_string (value,
2266 gtk_entry_get_icon_name (entry,
2267 GTK_ENTRY_ICON_PRIMARY));
2270 case PROP_ICON_NAME_SECONDARY:
2271 g_value_set_string (value,
2272 gtk_entry_get_icon_name (entry,
2273 GTK_ENTRY_ICON_SECONDARY));
2276 case PROP_GICON_PRIMARY:
2277 g_value_set_object (value,
2278 gtk_entry_get_icon_gicon (entry,
2279 GTK_ENTRY_ICON_PRIMARY));
2282 case PROP_GICON_SECONDARY:
2283 g_value_set_object (value,
2284 gtk_entry_get_icon_gicon (entry,
2285 GTK_ENTRY_ICON_SECONDARY));
2288 case PROP_STORAGE_TYPE_PRIMARY:
2289 g_value_set_enum (value,
2290 gtk_entry_get_icon_storage_type (entry,
2291 GTK_ENTRY_ICON_PRIMARY));
2294 case PROP_STORAGE_TYPE_SECONDARY:
2295 g_value_set_enum (value,
2296 gtk_entry_get_icon_storage_type (entry,
2297 GTK_ENTRY_ICON_SECONDARY));
2300 case PROP_ACTIVATABLE_PRIMARY:
2301 g_value_set_boolean (value,
2302 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2305 case PROP_ACTIVATABLE_SECONDARY:
2306 g_value_set_boolean (value,
2307 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2310 case PROP_SENSITIVE_PRIMARY:
2311 g_value_set_boolean (value,
2312 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2315 case PROP_SENSITIVE_SECONDARY:
2316 g_value_set_boolean (value,
2317 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2320 case PROP_TOOLTIP_TEXT_PRIMARY:
2321 g_value_take_string (value,
2322 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2325 case PROP_TOOLTIP_TEXT_SECONDARY:
2326 g_value_take_string (value,
2327 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2330 case PROP_TOOLTIP_MARKUP_PRIMARY:
2331 g_value_take_string (value,
2332 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2335 case PROP_TOOLTIP_MARKUP_SECONDARY:
2336 g_value_take_string (value,
2337 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2340 case PROP_EDITING_CANCELED:
2341 g_value_set_boolean (value,
2342 priv->editing_canceled);
2345 case PROP_COMPLETION:
2346 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2350 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2356 find_invisible_char (GtkWidget *widget)
2358 PangoLayout *layout;
2359 PangoAttrList *attr_list;
2361 gunichar invisible_chars [] = {
2363 0x25cf, /* BLACK CIRCLE */
2364 0x2022, /* BULLET */
2365 0x2731, /* HEAVY ASTERISK */
2366 0x273a /* SIXTEEN POINTED ASTERISK */
2369 gtk_widget_style_get (widget,
2370 "invisible-char", &invisible_chars[0],
2373 layout = gtk_widget_create_pango_layout (widget, NULL);
2375 attr_list = pango_attr_list_new ();
2376 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2378 pango_layout_set_attributes (layout, attr_list);
2379 pango_attr_list_unref (attr_list);
2381 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2383 gchar text[7] = { 0, };
2386 len = g_unichar_to_utf8 (invisible_chars[i], text);
2387 pango_layout_set_text (layout, text, len);
2389 count = pango_layout_get_unknown_glyphs_count (layout);
2393 g_object_unref (layout);
2394 return invisible_chars[i];
2398 g_object_unref (layout);
2404 gtk_entry_init (GtkEntry *entry)
2406 GtkStyleContext *context;
2407 GtkEntryPrivate *priv;
2409 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2414 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2415 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2417 priv->editable = TRUE;
2418 priv->visible = TRUE;
2419 priv->dnd_position = -1;
2420 priv->width_chars = -1;
2421 priv->is_cell_renderer = FALSE;
2422 priv->editing_canceled = FALSE;
2423 priv->has_frame = TRUE;
2424 priv->truncate_multiline = FALSE;
2425 priv->shadow_type = GTK_SHADOW_IN;
2427 priv->caps_lock_warning = TRUE;
2428 priv->caps_lock_warning_shown = FALSE;
2429 priv->progress_fraction = 0.0;
2430 priv->progress_pulse_fraction = 0.1;
2432 gtk_drag_dest_set (GTK_WIDGET (entry),
2433 GTK_DEST_DEFAULT_HIGHLIGHT,
2435 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2436 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2438 /* This object is completely private. No external entity can gain a reference
2439 * to it; so we create it here and destroy it in finalize().
2441 priv->im_context = gtk_im_multicontext_new ();
2443 g_signal_connect (priv->im_context, "commit",
2444 G_CALLBACK (gtk_entry_commit_cb), entry);
2445 g_signal_connect (priv->im_context, "preedit-changed",
2446 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2447 g_signal_connect (priv->im_context, "retrieve-surrounding",
2448 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2449 g_signal_connect (priv->im_context, "delete-surrounding",
2450 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2452 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2453 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2455 gtk_entry_update_cached_style_values (entry);
2459 get_icon_width (GtkEntry *entry,
2460 GtkEntryIconPosition icon_pos)
2462 GtkEntryPrivate *priv = entry->priv;
2463 EntryIconInfo *icon_info = priv->icons[icon_pos];
2465 GtkSettings *settings;
2466 gint menu_icon_width;
2468 if (!icon_info || icon_info->pixbuf == NULL)
2471 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2472 settings = gtk_settings_get_for_screen (screen);
2474 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2475 &menu_icon_width, NULL);
2477 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2481 get_icon_allocations (GtkEntry *entry,
2482 GtkAllocation *primary,
2483 GtkAllocation *secondary)
2486 GtkEntryPrivate *priv = entry->priv;
2487 gint x, y, width, height;
2489 get_text_area_size (entry, &x, &y, &width, &height);
2491 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2492 y += priv->focus_width;
2495 primary->height = height;
2496 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2497 if (primary->width > 0)
2498 primary->width += 2 * priv->icon_margin;
2501 secondary->height = height;
2502 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2503 if (secondary->width > 0)
2504 secondary->width += 2 * priv->icon_margin;
2506 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2508 primary->x = x + width - primary->width;
2514 secondary->x = x + width - secondary->width;
2520 begin_change (GtkEntry *entry)
2522 GtkEntryPrivate *priv = entry->priv;
2524 priv->change_count++;
2528 end_change (GtkEntry *entry)
2530 GtkEditable *editable = GTK_EDITABLE (entry);
2531 GtkEntryPrivate *priv = entry->priv;
2533 g_return_if_fail (priv->change_count > 0);
2535 priv->change_count--;
2537 if (priv->change_count == 0)
2539 if (priv->real_changed)
2541 g_signal_emit_by_name (editable, "changed");
2542 priv->real_changed = FALSE;
2548 emit_changed (GtkEntry *entry)
2550 GtkEditable *editable = GTK_EDITABLE (entry);
2551 GtkEntryPrivate *priv = entry->priv;
2553 if (priv->change_count == 0)
2554 g_signal_emit_by_name (editable, "changed");
2556 priv->real_changed = TRUE;
2560 gtk_entry_destroy (GtkWidget *widget)
2562 GtkEntry *entry = GTK_ENTRY (widget);
2563 GtkEntryPrivate *priv = entry->priv;
2565 priv->current_pos = priv->selection_bound = 0;
2566 _gtk_entry_reset_im_context (entry);
2567 gtk_entry_reset_layout (entry);
2569 if (priv->blink_timeout)
2571 g_source_remove (priv->blink_timeout);
2572 priv->blink_timeout = 0;
2575 if (priv->recompute_idle)
2577 g_source_remove (priv->recompute_idle);
2578 priv->recompute_idle = 0;
2581 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2585 gtk_entry_dispose (GObject *object)
2587 GtkEntry *entry = GTK_ENTRY (object);
2588 GtkEntryPrivate *priv = entry->priv;
2591 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2592 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2593 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2594 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2598 buffer_disconnect_signals (entry);
2599 g_object_unref (priv->buffer);
2600 priv->buffer = NULL;
2603 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2604 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2605 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2606 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2610 gtk_entry_finalize (GObject *object)
2612 GtkEntry *entry = GTK_ENTRY (object);
2613 GtkEntryPrivate *priv = entry->priv;
2614 EntryIconInfo *icon_info = NULL;
2617 for (i = 0; i < MAX_ICONS; i++)
2619 if ((icon_info = priv->icons[i]) != NULL)
2621 if (icon_info->target_list != NULL)
2623 gtk_target_list_unref (icon_info->target_list);
2624 icon_info->target_list = NULL;
2627 g_slice_free (EntryIconInfo, icon_info);
2628 priv->icons[i] = NULL;
2632 gtk_entry_set_completion (entry, NULL);
2634 if (priv->cached_layout)
2635 g_object_unref (priv->cached_layout);
2637 g_object_unref (priv->im_context);
2639 if (priv->blink_timeout)
2640 g_source_remove (priv->blink_timeout);
2642 if (priv->recompute_idle)
2643 g_source_remove (priv->recompute_idle);
2645 g_free (priv->placeholder_text);
2646 g_free (priv->im_module);
2648 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2652 gtk_entry_get_display_mode (GtkEntry *entry)
2654 GtkEntryPrivate *priv = entry->priv;
2657 return DISPLAY_NORMAL;
2659 if (priv->invisible_char == 0 && priv->invisible_char_set)
2660 return DISPLAY_BLANK;
2662 return DISPLAY_INVISIBLE;
2666 gtk_entry_get_display_text (GtkEntry *entry,
2670 GtkEntryPasswordHint *password_hint;
2671 GtkEntryPrivate *priv;
2672 gunichar invisible_char;
2683 text = gtk_entry_buffer_get_text (get_buffer (entry));
2684 length = gtk_entry_buffer_get_length (get_buffer (entry));
2688 if (start_pos > length)
2691 if (end_pos <= start_pos)
2692 return g_strdup ("");
2693 else if (priv->visible)
2695 start = g_utf8_offset_to_pointer (text, start_pos);
2696 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2697 return g_strndup (start, end - start);
2701 str = g_string_sized_new (length * 2);
2703 /* Figure out what our invisible char is and encode it */
2704 if (!priv->invisible_char)
2705 invisible_char = priv->invisible_char_set ? ' ' : '*';
2707 invisible_char = priv->invisible_char;
2708 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2711 * Add hidden characters for each character in the text
2712 * buffer. If there is a password hint, then keep that
2713 * character visible.
2716 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2717 for (i = start_pos; i < end_pos; ++i)
2719 if (password_hint && i == password_hint->position)
2721 start = g_utf8_offset_to_pointer (text, i);
2722 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2726 g_string_append_len (str, char_str, char_len);
2730 return g_string_free (str, FALSE);
2735 update_cursors (GtkWidget *widget)
2737 GtkEntry *entry = GTK_ENTRY (widget);
2738 GtkEntryPrivate *priv = entry->priv;
2739 EntryIconInfo *icon_info = NULL;
2740 GdkDisplay *display;
2744 for (i = 0; i < MAX_ICONS; i++)
2746 if ((icon_info = priv->icons[i]) != NULL)
2748 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2749 gdk_window_show_unraised (icon_info->window);
2751 /* The icon windows are not children of the visible entry window,
2752 * thus we can't just inherit the xterm cursor. Slight complication
2753 * here is that for the entry, insensitive => arrow cursor, but for
2754 * an icon in a sensitive entry, insensitive => xterm cursor.
2756 if (gtk_widget_is_sensitive (widget) &&
2757 (icon_info->insensitive ||
2758 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2760 display = gtk_widget_get_display (widget);
2761 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2762 gdk_window_set_cursor (icon_info->window, cursor);
2763 g_object_unref (cursor);
2767 gdk_window_set_cursor (icon_info->window, NULL);
2774 realize_icon_info (GtkWidget *widget,
2775 GtkEntryIconPosition icon_pos)
2777 GtkEntry *entry = GTK_ENTRY (widget);
2778 GtkEntryPrivate *priv = entry->priv;
2779 EntryIconInfo *icon_info = priv->icons[icon_pos];
2780 GdkWindowAttr attributes;
2781 gint attributes_mask;
2783 g_return_if_fail (icon_info != NULL);
2787 attributes.width = 1;
2788 attributes.height = 1;
2789 attributes.window_type = GDK_WINDOW_CHILD;
2790 attributes.wclass = GDK_INPUT_ONLY;
2791 attributes.event_mask = gtk_widget_get_events (widget);
2792 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2793 GDK_BUTTON_RELEASE_MASK |
2794 GDK_BUTTON1_MOTION_MASK |
2795 GDK_BUTTON3_MOTION_MASK |
2796 GDK_POINTER_MOTION_HINT_MASK |
2797 GDK_POINTER_MOTION_MASK |
2798 GDK_ENTER_NOTIFY_MASK |
2799 GDK_LEAVE_NOTIFY_MASK);
2800 attributes_mask = GDK_WA_X | GDK_WA_Y;
2802 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2805 gdk_window_set_user_data (icon_info->window, widget);
2807 gtk_widget_queue_resize (widget);
2810 static EntryIconInfo*
2811 construct_icon_info (GtkWidget *widget,
2812 GtkEntryIconPosition icon_pos)
2814 GtkEntry *entry = GTK_ENTRY (widget);
2815 GtkEntryPrivate *priv = entry->priv;
2816 EntryIconInfo *icon_info;
2818 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2820 icon_info = g_slice_new0 (EntryIconInfo);
2821 priv->icons[icon_pos] = icon_info;
2823 if (gtk_widget_get_realized (widget))
2824 realize_icon_info (widget, icon_pos);
2830 gtk_entry_map (GtkWidget *widget)
2832 GtkEntry *entry = GTK_ENTRY (widget);
2833 GtkEntryPrivate *priv = entry->priv;
2834 EntryIconInfo *icon_info = NULL;
2837 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2839 gdk_window_show (priv->text_area);
2841 for (i = 0; i < MAX_ICONS; i++)
2843 if ((icon_info = priv->icons[i]) != NULL)
2845 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2846 gdk_window_show (icon_info->window);
2850 update_cursors (widget);
2854 gtk_entry_unmap (GtkWidget *widget)
2856 GtkEntry *entry = GTK_ENTRY (widget);
2857 GtkEntryPrivate *priv = entry->priv;
2858 EntryIconInfo *icon_info = NULL;
2861 for (i = 0; i < MAX_ICONS; i++)
2863 if ((icon_info = priv->icons[i]) != NULL)
2865 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2866 gdk_window_hide (icon_info->window);
2870 gdk_window_hide (priv->text_area);
2872 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2876 gtk_entry_realize (GtkWidget *widget)
2879 GtkEntryPrivate *priv;
2880 EntryIconInfo *icon_info;
2882 GdkWindowAttr attributes;
2883 gint attributes_mask;
2884 gint frame_x, frame_y;
2887 gtk_widget_set_realized (widget, TRUE);
2888 window = gtk_widget_get_parent_window (widget);
2889 gtk_widget_set_window (widget, window);
2890 g_object_ref (window);
2892 entry = GTK_ENTRY (widget);
2895 attributes.window_type = GDK_WINDOW_CHILD;
2896 attributes.wclass = GDK_INPUT_ONLY;
2897 attributes.event_mask = gtk_widget_get_events (widget);
2898 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2899 GDK_BUTTON_RELEASE_MASK |
2900 GDK_BUTTON1_MOTION_MASK |
2901 GDK_BUTTON3_MOTION_MASK |
2902 GDK_POINTER_MOTION_HINT_MASK |
2903 GDK_POINTER_MOTION_MASK |
2904 GDK_ENTER_NOTIFY_MASK |
2905 GDK_LEAVE_NOTIFY_MASK);
2906 attributes_mask = GDK_WA_X | GDK_WA_Y;
2908 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2910 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2911 attributes.x += frame_x;
2912 attributes.y += frame_y;
2914 if (gtk_widget_is_sensitive (widget))
2916 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2917 attributes_mask |= GDK_WA_CURSOR;
2920 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2924 gdk_window_set_user_data (priv->text_area, entry);
2926 if (attributes_mask & GDK_WA_CURSOR)
2927 g_object_unref (attributes.cursor);
2929 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2931 gtk_entry_adjust_scroll (entry);
2932 gtk_entry_update_primary_selection (entry);
2935 /* If the icon positions are already setup, create their windows.
2936 * Otherwise if they don't exist yet, then construct_icon_info()
2937 * will create the windows once the widget is already realized.
2939 for (i = 0; i < MAX_ICONS; i++)
2941 if ((icon_info = priv->icons[i]) != NULL)
2943 if (icon_info->window == NULL)
2944 realize_icon_info (widget, i);
2950 gtk_entry_unrealize (GtkWidget *widget)
2952 GtkEntry *entry = GTK_ENTRY (widget);
2953 GtkEntryPrivate *priv = entry->priv;
2954 GtkClipboard *clipboard;
2955 EntryIconInfo *icon_info;
2958 gtk_entry_reset_layout (entry);
2960 gtk_im_context_set_client_window (priv->im_context, NULL);
2962 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2963 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2964 gtk_clipboard_clear (clipboard);
2966 if (priv->text_area)
2968 gdk_window_set_user_data (priv->text_area, NULL);
2969 gdk_window_destroy (priv->text_area);
2970 priv->text_area = NULL;
2973 if (priv->popup_menu)
2975 gtk_widget_destroy (priv->popup_menu);
2976 priv->popup_menu = NULL;
2979 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2981 for (i = 0; i < MAX_ICONS; i++)
2983 if ((icon_info = priv->icons[i]) != NULL)
2985 if (icon_info->window != NULL)
2987 gdk_window_destroy (icon_info->window);
2988 icon_info->window = NULL;
2995 _gtk_entry_get_borders (GtkEntry *entry,
2999 GtkEntryPrivate *priv = entry->priv;
3000 GtkWidget *widget = GTK_WIDGET (entry);
3002 if (priv->has_frame)
3004 GtkStyleContext *context;
3007 context = gtk_widget_get_style_context (widget);
3008 gtk_style_context_get_padding (context, 0, &padding);
3010 *xborder = padding.left;
3011 *yborder = padding.top;
3019 if (!priv->interior_focus)
3021 *xborder += priv->focus_width;
3022 *yborder += priv->focus_width;
3027 gtk_entry_get_preferred_width (GtkWidget *widget,
3031 GtkEntry *entry = GTK_ENTRY (widget);
3032 GtkEntryPrivate *priv = entry->priv;
3033 PangoFontMetrics *metrics;
3034 gint xborder, yborder;
3035 GtkBorder inner_border;
3036 PangoContext *context;
3037 GtkStyleContext *style_context;
3038 GtkStateFlags state;
3039 gint icon_widths = 0;
3043 context = gtk_widget_get_pango_context (widget);
3045 style_context = gtk_widget_get_style_context (widget);
3046 state = gtk_widget_get_state_flags (widget);
3048 metrics = pango_context_get_metrics (context,
3049 gtk_style_context_get_font (style_context, state),
3050 pango_context_get_language (context));
3052 _gtk_entry_get_borders (entry, &xborder, &yborder);
3053 _gtk_entry_effective_inner_border (entry, &inner_border);
3055 if (priv->width_chars < 0)
3056 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3059 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3060 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3061 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3063 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3066 for (i = 0; i < MAX_ICONS; i++)
3068 icon_width = get_icon_width (entry, i);
3070 icon_widths += icon_width + 2 * priv->icon_margin;
3073 if (icon_widths > width)
3074 width += icon_widths;
3076 pango_font_metrics_unref (metrics);
3083 gtk_entry_get_preferred_height (GtkWidget *widget,
3087 GtkEntry *entry = GTK_ENTRY (widget);
3088 GtkEntryPrivate *priv = entry->priv;
3089 PangoFontMetrics *metrics;
3090 gint xborder, yborder;
3091 GtkBorder inner_border;
3092 GtkStyleContext *style_context;
3093 GtkStateFlags state;
3094 PangoContext *context;
3097 context = gtk_widget_get_pango_context (widget);
3099 style_context = gtk_widget_get_style_context (widget);
3100 state = gtk_widget_get_state_flags (widget);
3102 metrics = pango_context_get_metrics (context,
3103 gtk_style_context_get_font (style_context, state),
3104 pango_context_get_language (context));
3106 priv->ascent = pango_font_metrics_get_ascent (metrics);
3107 priv->descent = pango_font_metrics_get_descent (metrics);
3109 _gtk_entry_get_borders (entry, &xborder, &yborder);
3110 _gtk_entry_effective_inner_border (entry, &inner_border);
3112 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3114 pango_font_metrics_unref (metrics);
3121 place_windows (GtkEntry *entry)
3123 GtkWidget *widget = GTK_WIDGET (entry);
3124 GtkEntryPrivate *priv = entry->priv;
3125 gint x, y, width, height;
3126 gint frame_x, frame_y;
3127 GtkAllocation primary;
3128 GtkAllocation secondary;
3129 EntryIconInfo *icon_info = NULL;
3131 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3132 get_text_area_size (entry, &x, &y, &width, &height);
3133 get_icon_allocations (entry, &primary, &secondary);
3135 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3136 y += priv->focus_width;
3138 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3139 x += secondary.width;
3142 width -= primary.width + secondary.width;
3146 primary.x += frame_x;
3147 primary.y += frame_y;
3148 secondary.x += frame_x;
3149 secondary.y += frame_y;
3151 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3152 gdk_window_move_resize (icon_info->window,
3153 primary.x, primary.y,
3154 primary.width, primary.height);
3156 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3157 gdk_window_move_resize (icon_info->window,
3158 secondary.x, secondary.y,
3159 secondary.width, secondary.height);
3161 gdk_window_move_resize (priv->text_area, x, y, width, height);
3165 gtk_entry_get_text_area_size (GtkEntry *entry,
3171 GtkEntryPrivate *priv = entry->priv;
3172 GtkWidget *widget = GTK_WIDGET (entry);
3173 GtkAllocation allocation;
3174 GtkRequisition requisition;
3177 gint xborder, yborder;
3179 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3180 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3182 gtk_widget_get_allocation (widget, &allocation);
3183 _gtk_entry_get_borders (entry, &xborder, &yborder);
3185 if (gtk_widget_get_realized (widget))
3186 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3188 frame_height = req_height;
3190 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3191 frame_height -= 2 * priv->focus_width;
3197 *y = frame_height / 2 - (req_height - yborder * 2) / 2;
3200 *width = allocation.width - xborder * 2;
3203 *height = req_height - yborder * 2;
3207 get_text_area_size (GtkEntry *entry,
3213 GtkEntryClass *class;
3215 g_return_if_fail (GTK_IS_ENTRY (entry));
3217 class = GTK_ENTRY_GET_CLASS (entry);
3219 if (class->get_text_area_size)
3220 class->get_text_area_size (entry, x, y, width, height);
3225 get_frame_size (GtkEntry *entry,
3226 gboolean relative_to_window,
3232 GtkEntryPrivate *priv = entry->priv;
3233 GtkAllocation allocation;
3234 GtkRequisition requisition;
3235 GtkWidget *widget = GTK_WIDGET (entry);
3238 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3240 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3242 gtk_widget_get_allocation (widget, &allocation);
3245 *x = relative_to_window ? allocation.x : 0;
3249 if (priv->is_cell_renderer)
3252 *y = (allocation.height - req_height) / 2;
3254 if (relative_to_window)
3259 *width = allocation.width;
3263 if (priv->is_cell_renderer)
3264 *height = allocation.height;
3266 *height = req_height;
3271 _gtk_entry_effective_inner_border (GtkEntry *entry,
3274 GtkBorder *tmp_border;
3276 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3280 *border = *tmp_border;
3284 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3288 *border = *tmp_border;
3289 gtk_border_free (tmp_border);
3293 *border = default_inner_border;
3297 gtk_entry_size_allocate (GtkWidget *widget,
3298 GtkAllocation *allocation)
3300 GtkEntry *entry = GTK_ENTRY (widget);
3302 gtk_widget_set_allocation (widget, allocation);
3304 if (gtk_widget_get_realized (widget))
3306 GtkEntryCompletion* completion;
3308 place_windows (entry);
3309 gtk_entry_recompute (entry);
3311 completion = gtk_entry_get_completion (entry);
3312 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3313 _gtk_entry_completion_resize_popup (completion);
3318 should_prelight (GtkEntry *entry,
3319 GtkEntryIconPosition icon_pos)
3321 GtkEntryPrivate *priv = entry->priv;
3322 EntryIconInfo *icon_info = priv->icons[icon_pos];
3328 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3331 if (icon_info->pressed)
3334 gtk_widget_style_get (GTK_WIDGET (entry),
3335 "icon-prelight", &prelight,
3342 draw_icon (GtkWidget *widget,
3344 GtkEntryIconPosition icon_pos)
3346 GtkEntry *entry = GTK_ENTRY (widget);
3347 GtkEntryPrivate *priv = entry->priv;
3348 EntryIconInfo *icon_info = priv->icons[icon_pos];
3350 gint x, y, width, height;
3351 GtkStyleContext *context;
3356 gtk_entry_ensure_pixbuf (entry, icon_pos);
3358 if (icon_info->pixbuf == NULL)
3361 width = gdk_window_get_width (icon_info->window);
3362 height = gdk_window_get_height (icon_info->window);
3364 context = gtk_widget_get_style_context (widget);
3366 /* size_allocate hasn't been called yet. These are the default values.
3368 if (width == 1 || height == 1)
3371 pixbuf = icon_info->pixbuf;
3372 g_object_ref (pixbuf);
3374 if (gdk_pixbuf_get_height (pixbuf) > height)
3376 GdkPixbuf *temp_pixbuf;
3379 scale = height - 2 * priv->icon_margin;
3380 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3381 GDK_INTERP_BILINEAR);
3382 g_object_unref (pixbuf);
3383 pixbuf = temp_pixbuf;
3386 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3387 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3389 gtk_render_icon (context, cr, pixbuf, x, y);
3391 g_object_unref (pixbuf);
3396 gtk_entry_draw_frame (GtkWidget *widget,
3397 GtkStyleContext *context,
3400 GtkEntry *entry = GTK_ENTRY (widget);
3401 GtkEntryPrivate *priv = entry->priv;
3402 gint x = 0, y = 0, width, height;
3403 gint frame_x, frame_y;
3407 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3409 cairo_translate (cr, frame_x, frame_y);
3411 /* Fix a problem with some themes which assume that entry->text_area's
3412 * width equals widget->window's width
3413 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3414 if (GTK_IS_SPIN_BUTTON (widget))
3416 gint xborder, yborder;
3418 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3419 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3422 width += xborder * 2;
3425 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3427 x += priv->focus_width;
3428 y += priv->focus_width;
3429 width -= 2 * priv->focus_width;
3430 height -= 2 * priv->focus_width;
3433 gtk_render_background (context, cr,
3434 x, y, width, height);
3436 if (priv->has_frame)
3437 gtk_render_frame (context, cr,
3438 x, y, width, height);
3440 gtk_entry_draw_progress (widget, context, cr);
3442 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3444 x -= priv->focus_width;
3445 y -= priv->focus_width;
3446 width += 2 * priv->focus_width;
3447 height += 2 * priv->focus_width;
3449 gtk_render_focus (context, cr,
3450 0, 0, width, height);
3457 get_progress_area (GtkWidget *widget,
3463 GtkEntry *entry = GTK_ENTRY (widget);
3464 GtkEntryPrivate *private = entry->priv;
3465 GtkBorder *progress_border;
3467 get_text_area_size (entry, x, y, width, height);
3469 if (!private->interior_focus)
3471 *x -= private->focus_width;
3472 *y -= private->focus_width;
3473 *width += 2 * private->focus_width;
3474 *height += 2 * private->focus_width;
3477 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3479 if (progress_border)
3481 *x += progress_border->left;
3482 *y += progress_border->top;
3483 *width -= progress_border->left + progress_border->right;
3484 *height -= progress_border->top + progress_border->bottom;
3486 gtk_border_free (progress_border);
3489 if (private->progress_pulse_mode)
3491 gdouble value = private->progress_pulse_current;
3493 *x += (gint) floor(value * (*width));
3494 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3496 else if (private->progress_fraction > 0)
3498 gdouble value = private->progress_fraction;
3500 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3504 bar_width = floor(value * (*width) + 0.5);
3505 *x += *width - bar_width;
3510 *width = (gint) floor(value * (*width) + 0.5);
3521 gtk_entry_draw_progress (GtkWidget *widget,
3522 GtkStyleContext *context,
3525 gint x, y, width, height;
3527 get_progress_area (widget, &x, &y, &width, &height);
3529 if ((width <= 0) || (height <= 0))
3532 gtk_style_context_save (context);
3533 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3535 gtk_render_activity (context, cr,
3536 x, y, width, height);
3538 gtk_style_context_restore (context);
3542 gtk_entry_draw (GtkWidget *widget,
3545 GtkEntry *entry = GTK_ENTRY (widget);
3546 GtkStyleContext *context;
3547 GtkStateFlags state;
3548 GtkEntryPrivate *priv = entry->priv;
3551 context = gtk_widget_get_style_context (widget);
3552 state = gtk_widget_get_state_flags (widget);
3554 gtk_style_context_save (context);
3555 gtk_style_context_set_state (context, state);
3557 /* Draw entry_bg, shadow, progress and focus */
3558 gtk_entry_draw_frame (widget, context, cr);
3560 /* Draw text and cursor */
3563 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3565 if (priv->dnd_position != -1)
3566 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3568 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3570 /* When no text is being displayed at all, don't show the cursor */
3571 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3572 gtk_widget_has_focus (widget) &&
3573 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3574 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3579 for (i = 0; i < MAX_ICONS; i++)
3581 EntryIconInfo *icon_info = priv->icons[i];
3583 if (icon_info != NULL)
3587 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3589 draw_icon (widget, cr, i);
3595 gtk_style_context_restore (context);
3601 gtk_entry_enter_notify (GtkWidget *widget,
3602 GdkEventCrossing *event)
3604 GtkEntry *entry = GTK_ENTRY (widget);
3605 GtkEntryPrivate *priv = entry->priv;
3608 for (i = 0; i < MAX_ICONS; i++)
3610 EntryIconInfo *icon_info = priv->icons[i];
3612 if (icon_info != NULL && event->window == icon_info->window)
3614 if (should_prelight (entry, i))
3616 icon_info->prelight = TRUE;
3617 gtk_widget_queue_draw (widget);
3628 gtk_entry_leave_notify (GtkWidget *widget,
3629 GdkEventCrossing *event)
3631 GtkEntry *entry = GTK_ENTRY (widget);
3632 GtkEntryPrivate *priv = entry->priv;
3635 for (i = 0; i < MAX_ICONS; i++)
3637 EntryIconInfo *icon_info = priv->icons[i];
3639 if (icon_info != NULL && event->window == icon_info->window)
3641 /* a grab means that we may never see the button release */
3642 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3643 icon_info->pressed = FALSE;
3645 if (should_prelight (entry, i))
3647 icon_info->prelight = FALSE;
3648 gtk_widget_queue_draw (widget);
3659 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3663 gint start_char, end_char;
3665 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3667 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3668 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3669 const char *text = pango_layout_get_text (layout);
3670 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3671 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3672 gint real_n_ranges, i;
3674 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3680 for (i = 0; i < real_n_ranges; ++i)
3682 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3683 r[2 * i] = r[2 * i] / PANGO_SCALE;
3688 *n_ranges = real_n_ranges;
3700 in_selection (GtkEntry *entry,
3705 gint retval = FALSE;
3707 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3709 for (i = 0; i < n_ranges; ++i)
3711 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3723 gtk_entry_button_press (GtkWidget *widget,
3724 GdkEventButton *event)
3726 GtkEntry *entry = GTK_ENTRY (widget);
3727 GtkEditable *editable = GTK_EDITABLE (widget);
3728 GtkEntryPrivate *priv = entry->priv;
3729 EntryIconInfo *icon_info = NULL;
3731 gint sel_start, sel_end;
3734 for (i = 0; i < MAX_ICONS; i++)
3736 icon_info = priv->icons[i];
3738 if (!icon_info || icon_info->insensitive)
3741 if (event->window == icon_info->window)
3743 if (should_prelight (entry, i))
3745 icon_info->prelight = FALSE;
3746 gtk_widget_queue_draw (widget);
3749 priv->start_x = event->x;
3750 priv->start_y = event->y;
3751 icon_info->pressed = TRUE;
3753 if (!icon_info->nonactivatable)
3754 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3760 if (event->window != priv->text_area ||
3761 (priv->button && event->button != priv->button))
3764 gtk_entry_reset_blink_time (entry);
3766 priv->button = event->button;
3768 if (!gtk_widget_has_focus (widget))
3770 priv->in_click = TRUE;
3771 gtk_widget_grab_focus (widget);
3772 priv->in_click = FALSE;
3775 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3777 if (event->button == 1)
3779 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3781 priv->select_words = FALSE;
3782 priv->select_lines = FALSE;
3784 if (event->state & GDK_SHIFT_MASK)
3786 _gtk_entry_reset_im_context (entry);
3788 if (!have_selection) /* select from the current position to the clicked position */
3789 sel_start = sel_end = priv->current_pos;
3791 if (tmp_pos > sel_start && tmp_pos < sel_end)
3793 /* Truncate current selection, but keep it as big as possible */
3794 if (tmp_pos - sel_start > sel_end - tmp_pos)
3795 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3797 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3801 gboolean extend_to_left;
3804 /* Figure out what click selects and extend current selection */
3805 switch (event->type)
3807 case GDK_BUTTON_PRESS:
3808 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3811 case GDK_2BUTTON_PRESS:
3812 priv->select_words = TRUE;
3813 gtk_entry_select_word (entry);
3816 case GDK_3BUTTON_PRESS:
3817 priv->select_lines = TRUE;
3818 gtk_entry_select_line (entry);
3825 start = MIN (priv->current_pos, priv->selection_bound);
3826 start = MIN (sel_start, start);
3828 end = MAX (priv->current_pos, priv->selection_bound);
3829 end = MAX (sel_end, end);
3831 if (tmp_pos == sel_start || tmp_pos == sel_end)
3832 extend_to_left = (tmp_pos == start);
3834 extend_to_left = (end == sel_end);
3837 gtk_entry_set_positions (entry, start, end);
3839 gtk_entry_set_positions (entry, end, start);
3842 else /* no shift key */
3843 switch (event->type)
3845 case GDK_BUTTON_PRESS:
3846 if (in_selection (entry, event->x + priv->scroll_offset))
3848 /* Click inside the selection - we'll either start a drag, or
3849 * clear the selection
3851 priv->in_drag = TRUE;
3852 priv->drag_start_x = event->x + priv->scroll_offset;
3853 priv->drag_start_y = event->y;
3856 gtk_editable_set_position (editable, tmp_pos);
3859 case GDK_2BUTTON_PRESS:
3860 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3861 * receiving a GDK_2BUTTON_PRESS so we need to reset
3862 * priv->in_drag which may have been set above
3864 priv->in_drag = FALSE;
3865 priv->select_words = TRUE;
3866 gtk_entry_select_word (entry);
3869 case GDK_3BUTTON_PRESS:
3870 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3871 * receiving a GDK_3BUTTON_PRESS so we need to reset
3872 * priv->in_drag which may have been set above
3874 priv->in_drag = FALSE;
3875 priv->select_lines = TRUE;
3876 gtk_entry_select_line (entry);
3885 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3889 priv->insert_pos = tmp_pos;
3890 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3895 gtk_widget_error_bell (widget);
3898 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3900 gtk_entry_do_popup (entry, event);
3901 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3910 gtk_entry_button_release (GtkWidget *widget,
3911 GdkEventButton *event)
3913 GtkEntry *entry = GTK_ENTRY (widget);
3914 GtkEntryPrivate *priv = entry->priv;
3915 EntryIconInfo *icon_info = NULL;
3918 for (i = 0; i < MAX_ICONS; i++)
3920 icon_info = priv->icons[i];
3922 if (!icon_info || icon_info->insensitive)
3925 if (event->window == icon_info->window)
3927 icon_info->pressed = FALSE;
3929 if (should_prelight (entry, i) &&
3930 event->x >= 0 && event->y >= 0 &&
3931 event->x < gdk_window_get_width (icon_info->window) &&
3932 event->y < gdk_window_get_height (icon_info->window))
3934 icon_info->prelight = TRUE;
3935 gtk_widget_queue_draw (widget);
3938 if (!icon_info->nonactivatable)
3939 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3945 if (event->window != priv->text_area || priv->button != event->button)
3950 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3952 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3959 gtk_entry_update_primary_selection (entry);
3965 _gtk_entry_get_selected_text (GtkEntry *entry)
3967 GtkEditable *editable = GTK_EDITABLE (entry);
3968 gint start_text, end_text;
3971 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3972 text = gtk_editable_get_chars (editable, start_text, end_text);
3978 gtk_entry_motion_notify (GtkWidget *widget,
3979 GdkEventMotion *event)
3981 GtkEntry *entry = GTK_ENTRY (widget);
3982 GtkEntryPrivate *priv = entry->priv;
3983 EntryIconInfo *icon_info = NULL;
3987 for (i = 0; i < MAX_ICONS; i++)
3989 icon_info = priv->icons[i];
3991 if (!icon_info || icon_info->insensitive)
3994 if (event->window == icon_info->window)
3996 if (icon_info->pressed &&
3997 icon_info->target_list != NULL &&
3998 gtk_drag_check_threshold (widget,
4004 icon_info->in_drag = TRUE;
4005 icon_info->pressed = FALSE;
4006 gtk_drag_begin (widget,
4007 icon_info->target_list,
4017 if (priv->mouse_cursor_obscured)
4021 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4022 gdk_window_set_cursor (priv->text_area, cursor);
4023 g_object_unref (cursor);
4024 priv->mouse_cursor_obscured = FALSE;
4027 if (event->window != priv->text_area || priv->button != 1)
4030 if (priv->select_lines)
4033 gdk_event_request_motions (event);
4037 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4038 gtk_drag_check_threshold (widget,
4039 priv->drag_start_x, priv->drag_start_y,
4040 event->x + priv->scroll_offset, event->y))
4042 GdkDragContext *context;
4043 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4044 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4046 cairo_surface_t *surface;
4048 gtk_target_list_add_text_targets (target_list, 0);
4050 text = _gtk_entry_get_selected_text (entry);
4051 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4053 context = gtk_drag_begin (widget, target_list, actions,
4054 priv->button, (GdkEvent *)event);
4057 gtk_drag_set_icon_surface (context, surface);
4059 gtk_drag_set_icon_default (context);
4062 cairo_surface_destroy (surface);
4065 priv->in_drag = FALSE;
4068 gtk_target_list_unref (target_list);
4075 else if (event->y >= gdk_window_get_height (priv->text_area))
4076 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4078 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4080 if (priv->select_words)
4083 gint old_min, old_max;
4086 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4087 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4089 pos = priv->current_pos;
4090 bound = priv->selection_bound;
4092 old_min = MIN(priv->current_pos, priv->selection_bound);
4093 old_max = MAX(priv->current_pos, priv->selection_bound);
4100 else if (old_max < max)
4105 else if (pos == old_min)
4107 if (priv->current_pos != min)
4112 if (priv->current_pos != max)
4116 gtk_entry_set_positions (entry, pos, bound);
4119 gtk_entry_set_positions (entry, tmp_pos, -1);
4126 set_invisible_cursor (GdkWindow *window)
4128 GdkDisplay *display;
4131 display = gdk_window_get_display (window);
4132 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4134 gdk_window_set_cursor (window, cursor);
4136 g_object_unref (cursor);
4140 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4142 GtkEntryPrivate *priv = entry->priv;
4144 if (priv->mouse_cursor_obscured)
4147 set_invisible_cursor (priv->text_area);
4149 priv->mouse_cursor_obscured = TRUE;
4153 gtk_entry_key_press (GtkWidget *widget,
4156 GtkEntry *entry = GTK_ENTRY (widget);
4157 GtkEntryPrivate *priv = entry->priv;
4159 gtk_entry_reset_blink_time (entry);
4160 gtk_entry_pend_cursor_blink (entry);
4164 if (gtk_im_context_filter_keypress (priv->im_context, event))
4166 gtk_entry_obscure_mouse_cursor (entry);
4167 priv->need_im_reset = TRUE;
4172 if (event->keyval == GDK_KEY_Return ||
4173 event->keyval == GDK_KEY_KP_Enter ||
4174 event->keyval == GDK_KEY_ISO_Enter ||
4175 event->keyval == GDK_KEY_Escape)
4177 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4179 if (completion && completion->priv->completion_timeout)
4181 g_source_remove (completion->priv->completion_timeout);
4182 completion->priv->completion_timeout = 0;
4185 _gtk_entry_reset_im_context (entry);
4188 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4189 /* Activate key bindings
4193 if (!priv->editable && event->length)
4194 gtk_widget_error_bell (widget);
4200 gtk_entry_key_release (GtkWidget *widget,
4203 GtkEntry *entry = GTK_ENTRY (widget);
4204 GtkEntryPrivate *priv = entry->priv;
4208 if (gtk_im_context_filter_keypress (priv->im_context, event))
4210 priv->need_im_reset = TRUE;
4215 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4219 gtk_entry_focus_in (GtkWidget *widget,
4220 GdkEventFocus *event)
4222 GtkEntry *entry = GTK_ENTRY (widget);
4223 GtkEntryPrivate *priv = entry->priv;
4226 gtk_widget_queue_draw (widget);
4228 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4232 priv->need_im_reset = TRUE;
4233 gtk_im_context_focus_in (priv->im_context);
4234 keymap_state_changed (keymap, entry);
4235 g_signal_connect (keymap, "state-changed",
4236 G_CALLBACK (keymap_state_changed), entry);
4239 g_signal_connect (keymap, "direction-changed",
4240 G_CALLBACK (keymap_direction_changed), entry);
4242 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4243 priv->placeholder_text != NULL)
4245 gtk_entry_recompute (entry);
4249 gtk_entry_reset_blink_time (entry);
4250 gtk_entry_check_cursor_blink (entry);
4257 gtk_entry_focus_out (GtkWidget *widget,
4258 GdkEventFocus *event)
4260 GtkEntry *entry = GTK_ENTRY (widget);
4261 GtkEntryPrivate *priv = entry->priv;
4262 GtkEntryCompletion *completion;
4265 gtk_widget_queue_draw (widget);
4267 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4271 priv->need_im_reset = TRUE;
4272 gtk_im_context_focus_out (priv->im_context);
4273 remove_capslock_feedback (entry);
4276 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4277 priv->placeholder_text != NULL)
4279 gtk_entry_recompute (entry);
4283 gtk_entry_check_cursor_blink (entry);
4286 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4287 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4289 completion = gtk_entry_get_completion (entry);
4291 _gtk_entry_completion_popdown (completion);
4297 gtk_entry_grab_focus (GtkWidget *widget)
4299 GtkEntry *entry = GTK_ENTRY (widget);
4300 GtkEntryPrivate *priv = entry->priv;
4301 gboolean select_on_focus;
4303 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4305 if (priv->editable && !priv->in_click)
4307 g_object_get (gtk_widget_get_settings (widget),
4308 "gtk-entry-select-on-focus",
4312 if (select_on_focus)
4313 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4318 gtk_entry_direction_changed (GtkWidget *widget,
4319 GtkTextDirection previous_dir)
4321 GtkEntry *entry = GTK_ENTRY (widget);
4323 gtk_entry_recompute (entry);
4325 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4329 gtk_entry_state_flags_changed (GtkWidget *widget,
4330 GtkStateFlags previous_state)
4332 GtkEntry *entry = GTK_ENTRY (widget);
4333 GtkEntryPrivate *priv = entry->priv;
4336 if (gtk_widget_get_realized (widget))
4338 if (gtk_widget_is_sensitive (widget))
4339 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4343 gdk_window_set_cursor (priv->text_area, cursor);
4346 g_object_unref (cursor);
4348 priv->mouse_cursor_obscured = FALSE;
4350 update_cursors (widget);
4353 if (!gtk_widget_is_sensitive (widget))
4355 /* Clear any selection */
4356 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4359 gtk_entry_update_cached_style_values (entry);
4363 gtk_entry_screen_changed (GtkWidget *widget,
4364 GdkScreen *old_screen)
4366 gtk_entry_recompute (GTK_ENTRY (widget));
4369 /* GtkEditable method implementations
4372 gtk_entry_insert_text (GtkEditable *editable,
4373 const gchar *new_text,
4374 gint new_text_length,
4377 g_object_ref (editable);
4380 * The incoming text may a password or other secret. We make sure
4381 * not to copy it into temporary buffers.
4384 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4386 g_object_unref (editable);
4390 gtk_entry_delete_text (GtkEditable *editable,
4394 g_object_ref (editable);
4396 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4398 g_object_unref (editable);
4402 gtk_entry_get_chars (GtkEditable *editable,
4406 GtkEntry *entry = GTK_ENTRY (editable);
4409 gint start_index, end_index;
4411 text = gtk_entry_buffer_get_text (get_buffer (entry));
4412 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4415 end_pos = text_length;
4417 start_pos = MIN (text_length, start_pos);
4418 end_pos = MIN (text_length, end_pos);
4420 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4421 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4423 return g_strndup (text + start_index, end_index - start_index);
4427 gtk_entry_real_set_position (GtkEditable *editable,
4430 GtkEntry *entry = GTK_ENTRY (editable);
4431 GtkEntryPrivate *priv = entry->priv;
4435 length = gtk_entry_buffer_get_length (get_buffer (entry));
4436 if (position < 0 || position > length)
4439 if (position != priv->current_pos ||
4440 position != priv->selection_bound)
4442 _gtk_entry_reset_im_context (entry);
4443 gtk_entry_set_positions (entry, position, position);
4448 gtk_entry_get_position (GtkEditable *editable)
4450 GtkEntry *entry = GTK_ENTRY (editable);
4451 GtkEntryPrivate *priv = entry->priv;
4453 return priv->current_pos;
4457 gtk_entry_set_selection_bounds (GtkEditable *editable,
4461 GtkEntry *entry = GTK_ENTRY (editable);
4464 length = gtk_entry_buffer_get_length (get_buffer (entry));
4470 _gtk_entry_reset_im_context (entry);
4472 gtk_entry_set_positions (entry,
4474 MIN (start, length));
4476 gtk_entry_update_primary_selection (entry);
4480 gtk_entry_get_selection_bounds (GtkEditable *editable,
4484 GtkEntry *entry = GTK_ENTRY (editable);
4485 GtkEntryPrivate *priv = entry->priv;
4487 *start = priv->selection_bound;
4488 *end = priv->current_pos;
4490 return (priv->selection_bound != priv->current_pos);
4494 icon_theme_changed (GtkEntry *entry)
4496 GtkEntryPrivate *priv = entry->priv;
4499 for (i = 0; i < MAX_ICONS; i++)
4501 EntryIconInfo *icon_info = priv->icons[i];
4502 if (icon_info != NULL)
4504 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4505 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4506 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4507 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4508 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4509 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4513 gtk_widget_queue_draw (GTK_WIDGET (entry));
4517 icon_margin_changed (GtkEntry *entry)
4519 GtkEntryPrivate *priv = entry->priv;
4522 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4524 priv->icon_margin = border.left;
4528 gtk_entry_update_cached_style_values (GtkEntry *entry)
4530 GtkEntryPrivate *priv = entry->priv;
4532 gboolean interior_focus;
4534 gtk_widget_style_get (GTK_WIDGET (entry),
4535 "focus-line-width", &focus_width,
4536 "interior-focus", &interior_focus,
4538 priv->focus_width = focus_width;
4539 priv->interior_focus = interior_focus;
4541 if (!priv->invisible_char_set)
4543 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4545 if (priv->invisible_char != ch)
4547 priv->invisible_char = ch;
4548 g_object_notify (G_OBJECT (entry), "invisible-char");
4554 gtk_entry_style_updated (GtkWidget *widget)
4556 GtkEntry *entry = GTK_ENTRY (widget);
4558 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4560 gtk_entry_update_cached_style_values (entry);
4562 gtk_entry_recompute (entry);
4564 icon_theme_changed (entry);
4565 icon_margin_changed (entry);
4568 /* GtkCellEditable method implementations
4571 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4573 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4574 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4578 gtk_cell_editable_key_press_event (GtkEntry *entry,
4579 GdkEventKey *key_event,
4582 GtkEntryPrivate *priv = entry->priv;
4584 if (key_event->keyval == GDK_KEY_Escape)
4586 priv->editing_canceled = TRUE;
4587 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4588 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4593 /* override focus */
4594 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4596 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4597 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4606 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4609 GtkEntry *entry = GTK_ENTRY (cell_editable);
4610 GtkEntryPrivate *priv = entry->priv;
4612 priv->is_cell_renderer = TRUE;
4614 g_signal_connect (cell_editable, "activate",
4615 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4616 g_signal_connect (cell_editable, "key-press-event",
4617 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4621 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4623 if (password_hint->source_id)
4624 g_source_remove (password_hint->source_id);
4626 g_slice_free (GtkEntryPasswordHint, password_hint);
4631 gtk_entry_remove_password_hint (gpointer data)
4633 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4634 password_hint->position = -1;
4636 /* Force the string to be redrawn, but now without a visible character */
4637 gtk_entry_recompute (GTK_ENTRY (data));
4641 /* Default signal handlers
4644 gtk_entry_real_insert_text (GtkEditable *editable,
4645 const gchar *new_text,
4646 gint new_text_length,
4652 n_chars = g_utf8_strlen (new_text, new_text_length);
4655 * The actual insertion into the buffer. This will end up firing the
4656 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4657 * buffer_notify_text(), buffer_notify_length()
4659 begin_change (GTK_ENTRY (editable));
4660 g_object_freeze_notify (G_OBJECT (editable));
4662 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4664 g_object_thaw_notify (G_OBJECT (editable));
4665 end_change (GTK_ENTRY (editable));
4667 if (n_inserted != n_chars)
4668 gtk_widget_error_bell (GTK_WIDGET (editable));
4670 *position += n_inserted;
4674 gtk_entry_real_delete_text (GtkEditable *editable,
4679 * The actual deletion from the buffer. This will end up firing the
4680 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4681 * buffer_notify_text(), buffer_notify_length()
4684 begin_change (GTK_ENTRY (editable));
4685 g_object_freeze_notify (G_OBJECT (editable));
4686 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4687 g_object_thaw_notify (G_OBJECT (editable));
4688 end_change (GTK_ENTRY (editable));
4691 /* GtkEntryBuffer signal handlers
4694 buffer_inserted_text (GtkEntryBuffer *buffer,
4700 GtkEntryPrivate *priv = entry->priv;
4701 guint password_hint_timeout;
4703 gint selection_bound;
4705 current_pos = priv->current_pos;
4706 if (current_pos > position)
4707 current_pos += n_chars;
4709 selection_bound = priv->selection_bound;
4710 if (selection_bound > position)
4711 selection_bound += n_chars;
4713 gtk_entry_set_positions (entry, current_pos, selection_bound);
4715 /* Calculate the password hint if it needs to be displayed. */
4716 if (n_chars == 1 && !priv->visible)
4718 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4719 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4722 if (password_hint_timeout > 0)
4724 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4725 quark_password_hint);
4728 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4729 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4730 (GDestroyNotify)gtk_entry_password_hint_free);
4733 password_hint->position = position;
4734 if (password_hint->source_id)
4735 g_source_remove (password_hint->source_id);
4736 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4737 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4743 buffer_deleted_text (GtkEntryBuffer *buffer,
4748 GtkEntryPrivate *priv = entry->priv;
4749 guint end_pos = position + n_chars;
4750 gint selection_bound;
4753 current_pos = priv->current_pos;
4754 if (current_pos > position)
4755 current_pos -= MIN (current_pos, end_pos) - position;
4757 selection_bound = priv->selection_bound;
4758 if (selection_bound > position)
4759 selection_bound -= MIN (selection_bound, end_pos) - position;
4761 gtk_entry_set_positions (entry, current_pos, selection_bound);
4763 /* We might have deleted the selection */
4764 gtk_entry_update_primary_selection (entry);
4766 /* Disable the password hint if one exists. */
4769 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4770 quark_password_hint);
4773 if (password_hint->source_id)
4774 g_source_remove (password_hint->source_id);
4775 password_hint->source_id = 0;
4776 password_hint->position = -1;
4782 buffer_notify_text (GtkEntryBuffer *buffer,
4786 gtk_entry_recompute (entry);
4787 emit_changed (entry);
4788 g_object_notify (G_OBJECT (entry), "text");
4792 buffer_notify_length (GtkEntryBuffer *buffer,
4796 g_object_notify (G_OBJECT (entry), "text-length");
4800 buffer_notify_max_length (GtkEntryBuffer *buffer,
4804 g_object_notify (G_OBJECT (entry), "max-length");
4808 buffer_connect_signals (GtkEntry *entry)
4810 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4811 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4812 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4813 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4814 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4818 buffer_disconnect_signals (GtkEntry *entry)
4820 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4821 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4822 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4823 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4824 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4827 /* Compute the X position for an offset that corresponds to the "more important
4828 * cursor position for that offset. We use this when trying to guess to which
4829 * end of the selection we should go to when the user hits the left or
4833 get_better_cursor_x (GtkEntry *entry,
4836 GtkEntryPrivate *priv = entry->priv;
4837 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4838 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4839 gboolean split_cursor;
4841 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4842 const gchar *text = pango_layout_get_text (layout);
4843 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4845 PangoRectangle strong_pos, weak_pos;
4847 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4848 "gtk-split-cursor", &split_cursor,
4851 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4854 return strong_pos.x / PANGO_SCALE;
4856 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4860 gtk_entry_move_cursor (GtkEntry *entry,
4861 GtkMovementStep step,
4863 gboolean extend_selection)
4865 GtkEntryPrivate *priv = entry->priv;
4866 gint new_pos = priv->current_pos;
4868 _gtk_entry_reset_im_context (entry);
4870 if (priv->current_pos != priv->selection_bound && !extend_selection)
4872 /* If we have a current selection and aren't extending it, move to the
4873 * start/or end of the selection as appropriate
4877 case GTK_MOVEMENT_VISUAL_POSITIONS:
4879 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4880 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4883 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4885 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4888 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4889 case GTK_MOVEMENT_WORDS:
4891 new_pos = MIN (priv->current_pos, priv->selection_bound);
4893 new_pos = MAX (priv->current_pos, priv->selection_bound);
4895 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4896 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4897 case GTK_MOVEMENT_BUFFER_ENDS:
4898 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4900 case GTK_MOVEMENT_DISPLAY_LINES:
4901 case GTK_MOVEMENT_PARAGRAPHS:
4902 case GTK_MOVEMENT_PAGES:
4903 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4911 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4912 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4914 case GTK_MOVEMENT_VISUAL_POSITIONS:
4915 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4916 if (priv->current_pos == new_pos)
4918 if (!extend_selection)
4920 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4922 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4924 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4927 gtk_widget_child_focus (toplevel,
4929 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4934 gtk_widget_error_bell (GTK_WIDGET (entry));
4938 case GTK_MOVEMENT_WORDS:
4941 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4946 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4949 if (priv->current_pos == new_pos)
4950 gtk_widget_error_bell (GTK_WIDGET (entry));
4952 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4953 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4954 case GTK_MOVEMENT_BUFFER_ENDS:
4955 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4956 if (priv->current_pos == new_pos)
4957 gtk_widget_error_bell (GTK_WIDGET (entry));
4959 case GTK_MOVEMENT_DISPLAY_LINES:
4960 case GTK_MOVEMENT_PARAGRAPHS:
4961 case GTK_MOVEMENT_PAGES:
4962 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4967 if (extend_selection)
4968 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4970 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4972 gtk_entry_pend_cursor_blink (entry);
4976 gtk_entry_insert_at_cursor (GtkEntry *entry,
4979 GtkEntryPrivate *priv = entry->priv;
4980 GtkEditable *editable = GTK_EDITABLE (entry);
4981 gint pos = priv->current_pos;
4985 _gtk_entry_reset_im_context (entry);
4987 gtk_editable_insert_text (editable, str, -1, &pos);
4988 gtk_editable_set_position (editable, pos);
4993 gtk_entry_delete_from_cursor (GtkEntry *entry,
4997 GtkEntryPrivate *priv = entry->priv;
4998 GtkEditable *editable = GTK_EDITABLE (entry);
4999 gint start_pos = priv->current_pos;
5000 gint end_pos = priv->current_pos;
5001 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5003 _gtk_entry_reset_im_context (entry);
5005 if (!priv->editable)
5007 gtk_widget_error_bell (GTK_WIDGET (entry));
5011 if (priv->selection_bound != priv->current_pos)
5013 gtk_editable_delete_selection (editable);
5019 case GTK_DELETE_CHARS:
5020 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5021 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5023 case GTK_DELETE_WORDS:
5026 /* Move to end of current word, or if not on a word, end of previous word */
5027 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5028 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5032 /* Move to beginning of current word, or if not on a word, begining of next word */
5033 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5034 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5038 case GTK_DELETE_WORD_ENDS:
5041 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5046 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5049 gtk_editable_delete_text (editable, start_pos, end_pos);
5051 case GTK_DELETE_DISPLAY_LINE_ENDS:
5052 case GTK_DELETE_PARAGRAPH_ENDS:
5054 gtk_editable_delete_text (editable, 0, priv->current_pos);
5056 gtk_editable_delete_text (editable, priv->current_pos, -1);
5058 case GTK_DELETE_DISPLAY_LINES:
5059 case GTK_DELETE_PARAGRAPHS:
5060 gtk_editable_delete_text (editable, 0, -1);
5062 case GTK_DELETE_WHITESPACE:
5063 gtk_entry_delete_whitespace (entry);
5067 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5068 gtk_widget_error_bell (GTK_WIDGET (entry));
5070 gtk_entry_pend_cursor_blink (entry);
5074 gtk_entry_backspace (GtkEntry *entry)
5076 GtkEntryPrivate *priv = entry->priv;
5077 GtkEditable *editable = GTK_EDITABLE (entry);
5080 _gtk_entry_reset_im_context (entry);
5082 if (!priv->editable)
5084 gtk_widget_error_bell (GTK_WIDGET (entry));
5088 if (priv->selection_bound != priv->current_pos)
5090 gtk_editable_delete_selection (editable);
5094 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5096 if (prev_pos < priv->current_pos)
5098 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5099 PangoLogAttr *log_attrs;
5102 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5104 /* Deleting parts of characters */
5105 if (log_attrs[priv->current_pos].backspace_deletes_character)
5107 gchar *cluster_text;
5108 gchar *normalized_text;
5111 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5113 normalized_text = g_utf8_normalize (cluster_text,
5114 strlen (cluster_text),
5116 len = g_utf8_strlen (normalized_text, -1);
5118 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5121 gint pos = priv->current_pos;
5123 gtk_editable_insert_text (editable, normalized_text,
5124 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5126 gtk_editable_set_position (editable, pos);
5129 g_free (normalized_text);
5130 g_free (cluster_text);
5134 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5141 gtk_widget_error_bell (GTK_WIDGET (entry));
5144 gtk_entry_pend_cursor_blink (entry);
5148 gtk_entry_copy_clipboard (GtkEntry *entry)
5150 GtkEntryPrivate *priv = entry->priv;
5151 GtkEditable *editable = GTK_EDITABLE (entry);
5155 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5159 gtk_widget_error_bell (GTK_WIDGET (entry));
5163 str = gtk_entry_get_display_text (entry, start, end);
5164 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5165 GDK_SELECTION_CLIPBOARD),
5172 gtk_entry_cut_clipboard (GtkEntry *entry)
5174 GtkEntryPrivate *priv = entry->priv;
5175 GtkEditable *editable = GTK_EDITABLE (entry);
5180 gtk_widget_error_bell (GTK_WIDGET (entry));
5184 gtk_entry_copy_clipboard (entry);
5188 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5189 gtk_editable_delete_text (editable, start, end);
5193 gtk_widget_error_bell (GTK_WIDGET (entry));
5198 gtk_entry_paste_clipboard (GtkEntry *entry)
5200 GtkEntryPrivate *priv = entry->priv;
5203 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5205 gtk_widget_error_bell (GTK_WIDGET (entry));
5209 gtk_entry_delete_cb (GtkEntry *entry)
5211 GtkEntryPrivate *priv = entry->priv;
5212 GtkEditable *editable = GTK_EDITABLE (entry);
5217 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5218 gtk_editable_delete_text (editable, start, end);
5223 gtk_entry_toggle_overwrite (GtkEntry *entry)
5225 GtkEntryPrivate *priv = entry->priv;
5227 priv->overwrite_mode = !priv->overwrite_mode;
5228 gtk_entry_pend_cursor_blink (entry);
5229 gtk_widget_queue_draw (GTK_WIDGET (entry));
5233 gtk_entry_select_all (GtkEntry *entry)
5235 gtk_entry_select_line (entry);
5239 gtk_entry_real_activate (GtkEntry *entry)
5241 GtkEntryPrivate *priv = entry->priv;
5243 GtkWidget *default_widget, *focus_widget;
5244 GtkWidget *toplevel;
5247 widget = GTK_WIDGET (entry);
5249 if (priv->activates_default)
5251 toplevel = gtk_widget_get_toplevel (widget);
5252 if (GTK_IS_WINDOW (toplevel))
5254 window = GTK_WINDOW (toplevel);
5258 default_widget = gtk_window_get_default_widget (window);
5259 focus_widget = gtk_window_get_focus (window);
5260 if (widget != default_widget &&
5261 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5262 gtk_window_activate_default (window);
5269 keymap_direction_changed (GdkKeymap *keymap,
5272 gtk_entry_recompute (entry);
5275 /* IM Context Callbacks
5279 gtk_entry_commit_cb (GtkIMContext *context,
5283 GtkEntryPrivate *priv = entry->priv;
5286 gtk_entry_enter_text (entry, str);
5290 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5293 GtkEntryPrivate *priv = entry->priv;
5297 gchar *preedit_string;
5300 gtk_im_context_get_preedit_string (priv->im_context,
5301 &preedit_string, NULL,
5303 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5304 priv->preedit_length = strlen (preedit_string);
5305 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5306 priv->preedit_cursor = cursor_pos;
5307 g_free (preedit_string);
5309 gtk_entry_recompute (entry);
5314 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5317 GtkEntryPrivate *priv = entry->priv;
5320 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5321 text = gtk_entry_get_display_text (entry, 0, -1);
5322 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5323 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5330 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5335 GtkEntryPrivate *priv = entry->priv;
5338 gtk_editable_delete_text (GTK_EDITABLE (entry),
5339 priv->current_pos + offset,
5340 priv->current_pos + offset + n_chars);
5345 /* Internal functions
5348 /* Used for im_commit_cb and inserting Unicode chars */
5350 gtk_entry_enter_text (GtkEntry *entry,
5353 GtkEntryPrivate *priv = entry->priv;
5354 GtkEditable *editable = GTK_EDITABLE (entry);
5356 gboolean old_need_im_reset;
5358 old_need_im_reset = priv->need_im_reset;
5359 priv->need_im_reset = FALSE;
5361 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5362 gtk_editable_delete_selection (editable);
5365 if (priv->overwrite_mode)
5366 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5369 tmp_pos = priv->current_pos;
5370 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5371 gtk_editable_set_position (editable, tmp_pos);
5373 priv->need_im_reset = old_need_im_reset;
5376 /* All changes to priv->current_pos and priv->selection_bound
5377 * should go through this function.
5380 gtk_entry_set_positions (GtkEntry *entry,
5382 gint selection_bound)
5384 GtkEntryPrivate *priv = entry->priv;
5385 gboolean changed = FALSE;
5387 g_object_freeze_notify (G_OBJECT (entry));
5389 if (current_pos != -1 &&
5390 priv->current_pos != current_pos)
5392 priv->current_pos = current_pos;
5395 g_object_notify (G_OBJECT (entry), "cursor-position");
5398 if (selection_bound != -1 &&
5399 priv->selection_bound != selection_bound)
5401 priv->selection_bound = selection_bound;
5404 g_object_notify (G_OBJECT (entry), "selection-bound");
5407 g_object_thaw_notify (G_OBJECT (entry));
5411 gtk_entry_move_adjustments (entry);
5412 gtk_entry_recompute (entry);
5417 gtk_entry_reset_layout (GtkEntry *entry)
5419 GtkEntryPrivate *priv = entry->priv;
5421 if (priv->cached_layout)
5423 g_object_unref (priv->cached_layout);
5424 priv->cached_layout = NULL;
5429 update_im_cursor_location (GtkEntry *entry)
5431 GtkEntryPrivate *priv = entry->priv;
5434 gint strong_xoffset;
5435 gint area_width, area_height;
5437 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5438 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5440 strong_xoffset = strong_x - priv->scroll_offset;
5441 if (strong_xoffset < 0)
5445 else if (strong_xoffset > area_width)
5447 strong_xoffset = area_width;
5449 area.x = strong_xoffset;
5452 area.height = area_height;
5454 gtk_im_context_set_cursor_location (priv->im_context, &area);
5458 recompute_idle_func (gpointer data)
5460 GtkEntry *entry = GTK_ENTRY (data);
5461 GtkEntryPrivate *priv = entry->priv;
5463 priv->recompute_idle = 0;
5465 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5467 gtk_entry_adjust_scroll (entry);
5468 gtk_widget_queue_draw (GTK_WIDGET (entry));
5470 update_im_cursor_location (entry);
5477 gtk_entry_recompute (GtkEntry *entry)
5479 GtkEntryPrivate *priv = entry->priv;
5481 gtk_entry_reset_layout (entry);
5482 gtk_entry_check_cursor_blink (entry);
5484 if (!priv->recompute_idle)
5486 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5487 recompute_idle_func, entry, NULL);
5492 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5495 GtkWidget *widget = GTK_WIDGET (entry);
5496 GtkStyleContext *context;
5497 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5499 context = gtk_widget_get_style_context (widget);
5500 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5502 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5503 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5504 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5507 static inline gboolean
5508 show_placeholder_text (GtkEntry *entry)
5510 GtkEntryPrivate *priv = entry->priv;
5512 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5513 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5514 priv->placeholder_text != NULL)
5520 static PangoLayout *
5521 gtk_entry_create_layout (GtkEntry *entry,
5522 gboolean include_preedit)
5524 GtkEntryPrivate *priv = entry->priv;
5525 GtkWidget *widget = GTK_WIDGET (entry);
5526 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5527 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5528 gboolean placeholder_layout = show_placeholder_text (entry);
5530 gchar *preedit_string = NULL;
5531 gint preedit_length = 0;
5532 PangoAttrList *preedit_attrs = NULL;
5537 pango_layout_set_single_paragraph_mode (layout, TRUE);
5539 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5540 n_bytes = strlen (display);
5542 if (!placeholder_layout && include_preedit)
5544 gtk_im_context_get_preedit_string (priv->im_context,
5545 &preedit_string, &preedit_attrs, NULL);
5546 preedit_length = priv->preedit_length;
5548 else if (placeholder_layout)
5551 PangoAttribute *attr;
5553 gtk_entry_get_placeholder_text_color (entry, &color);
5554 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5555 attr->start_index = 0;
5556 attr->end_index = G_MAXINT;
5557 pango_attr_list_insert (tmp_attrs, attr);
5562 GString *tmp_string = g_string_new (display);
5563 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5565 g_string_insert (tmp_string, cursor_index, preedit_string);
5567 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5569 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5570 cursor_index, preedit_length);
5572 g_string_free (tmp_string, TRUE);
5576 PangoDirection pango_dir;
5578 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5579 pango_dir = pango_find_base_dir (display, n_bytes);
5581 pango_dir = PANGO_DIRECTION_NEUTRAL;
5583 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5585 if (gtk_widget_has_focus (widget))
5587 GdkDisplay *display = gtk_widget_get_display (widget);
5588 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5589 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5590 pango_dir = PANGO_DIRECTION_RTL;
5592 pango_dir = PANGO_DIRECTION_LTR;
5596 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5597 pango_dir = PANGO_DIRECTION_RTL;
5599 pango_dir = PANGO_DIRECTION_LTR;
5603 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5606 priv->resolved_dir = pango_dir;
5608 pango_layout_set_text (layout, display, n_bytes);
5611 pango_layout_set_attributes (layout, tmp_attrs);
5613 g_free (preedit_string);
5617 pango_attr_list_unref (preedit_attrs);
5619 pango_attr_list_unref (tmp_attrs);
5624 static PangoLayout *
5625 gtk_entry_ensure_layout (GtkEntry *entry,
5626 gboolean include_preedit)
5628 GtkEntryPrivate *priv = entry->priv;
5630 if (priv->preedit_length > 0 &&
5631 !include_preedit != !priv->cache_includes_preedit)
5632 gtk_entry_reset_layout (entry);
5634 if (!priv->cached_layout)
5636 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5637 priv->cache_includes_preedit = include_preedit;
5640 return priv->cached_layout;
5644 get_layout_position (GtkEntry *entry,
5648 GtkEntryPrivate *priv = entry->priv;
5649 PangoLayout *layout;
5650 PangoRectangle logical_rect;
5651 gint area_width, area_height;
5652 GtkBorder inner_border;
5654 PangoLayoutLine *line;
5656 layout = gtk_entry_ensure_layout (entry, TRUE);
5658 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5659 _gtk_entry_effective_inner_border (entry, &inner_border);
5661 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5663 line = pango_layout_get_lines_readonly (layout)->data;
5664 pango_layout_line_get_extents (line, NULL, &logical_rect);
5666 /* Align primarily for locale's ascent/descent */
5667 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5668 priv->ascent + logical_rect.y);
5670 /* Now see if we need to adjust to fit in actual drawn string */
5671 if (logical_rect.height > area_height)
5672 y_pos = (area_height - logical_rect.height) / 2;
5675 else if (y_pos + logical_rect.height > area_height)
5676 y_pos = area_height - logical_rect.height;
5678 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5681 *x = inner_border.left - priv->scroll_offset;
5688 draw_text_with_color (GtkEntry *entry,
5690 GdkRGBA *default_color)
5692 GtkEntryPrivate *priv = entry->priv;
5693 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5696 gint start_pos, end_pos;
5698 widget = GTK_WIDGET (entry);
5702 get_layout_position (entry, &x, &y);
5704 cairo_move_to (cr, x, y);
5705 gdk_cairo_set_source_rgba (cr, default_color);
5706 pango_cairo_show_layout (cr, layout);
5708 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5712 PangoRectangle logical_rect;
5713 GdkRGBA selection_color, text_color;
5714 GtkBorder inner_border;
5715 GtkStyleContext *context;
5716 GtkStateFlags state;
5718 context = gtk_widget_get_style_context (widget);
5719 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5720 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5722 state = GTK_STATE_FLAG_SELECTED;
5724 if (gtk_widget_has_focus (widget))
5725 state |= GTK_STATE_FLAG_FOCUSED;
5727 gtk_style_context_get_background_color (context, state, &selection_color);
5728 gtk_style_context_get_color (context, state, &text_color);
5730 _gtk_entry_effective_inner_border (entry, &inner_border);
5732 for (i = 0; i < n_ranges; ++i)
5733 cairo_rectangle (cr,
5734 inner_border.left - priv->scroll_offset + ranges[2 * i],
5737 logical_rect.height);
5741 gdk_cairo_set_source_rgba (cr, &selection_color);
5744 cairo_move_to (cr, x, y);
5745 gdk_cairo_set_source_rgba (cr, &text_color);
5746 pango_cairo_show_layout (cr, layout);
5754 gtk_entry_draw_text (GtkEntry *entry,
5757 GtkEntryPrivate *priv = entry->priv;
5758 GtkWidget *widget = GTK_WIDGET (entry);
5759 GtkStateFlags state = 0;
5760 GdkRGBA text_color, bar_text_color;
5761 GtkStyleContext *context;
5763 gint progress_x, progress_y, progress_width, progress_height;
5764 gint clip_width, clip_height;
5766 /* Nothing to display at all */
5767 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5770 state = gtk_widget_get_state_flags (widget);
5771 context = gtk_widget_get_style_context (widget);
5773 gtk_style_context_get_color (context, state, &text_color);
5775 /* Get foreground color for progressbars */
5776 gtk_style_context_save (context);
5777 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5778 gtk_style_context_get_color (context, state, &bar_text_color);
5779 gtk_style_context_restore (context);
5781 get_progress_area (widget,
5782 &progress_x, &progress_y,
5783 &progress_width, &progress_height);
5787 clip_width = gdk_window_get_width (priv->text_area);
5788 clip_height = gdk_window_get_height (priv->text_area);
5789 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5792 /* If the color is the same, or the progress area has a zero
5793 * size, then we only need to draw once. */
5794 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5795 ((progress_width == 0) || (progress_height == 0)))
5797 draw_text_with_color (entry, cr, &text_color);
5801 int frame_x, frame_y, area_x, area_y;
5803 width = gdk_window_get_width (priv->text_area);
5804 height = gdk_window_get_height (priv->text_area);
5808 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5809 cairo_rectangle (cr, 0, 0, width, height);
5811 /* progres area is frame-relative, we need it text-area window
5813 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5814 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5815 progress_x += frame_x - area_x;
5816 progress_y += frame_y - area_y;
5818 cairo_rectangle (cr, progress_x, progress_y,
5819 progress_width, progress_height);
5821 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5823 draw_text_with_color (entry, cr, &text_color);
5828 cairo_rectangle (cr, progress_x, progress_y,
5829 progress_width, progress_height);
5832 draw_text_with_color (entry, cr, &bar_text_color);
5841 draw_insertion_cursor (GtkEntry *entry,
5843 GdkRectangle *cursor_location,
5844 gboolean is_primary,
5845 PangoDirection direction,
5846 gboolean draw_arrow)
5848 GtkWidget *widget = GTK_WIDGET (entry);
5849 GtkTextDirection text_dir;
5851 if (direction == PANGO_DIRECTION_LTR)
5852 text_dir = GTK_TEXT_DIR_LTR;
5854 text_dir = GTK_TEXT_DIR_RTL;
5856 gtk_draw_insertion_cursor (widget, cr,
5858 is_primary, text_dir, draw_arrow);
5862 gtk_entry_draw_cursor (GtkEntry *entry,
5866 GtkEntryPrivate *priv = entry->priv;
5867 GtkWidget *widget = GTK_WIDGET (entry);
5868 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5869 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5870 GdkRectangle cursor_location;
5871 gboolean split_cursor;
5872 PangoRectangle cursor_rect;
5873 GtkBorder inner_border;
5875 gint text_area_height;
5878 gboolean block_at_line_end;
5879 PangoLayout *layout;
5882 _gtk_entry_effective_inner_border (entry, &inner_border);
5884 xoffset = inner_border.left - priv->scroll_offset;
5886 text_area_height = gdk_window_get_height (priv->text_area);
5888 layout = gtk_entry_ensure_layout (entry, TRUE);
5889 text = pango_layout_get_text (layout);
5890 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5891 if (!priv->overwrite_mode)
5894 block = _gtk_text_util_get_block_cursor_location (layout,
5895 cursor_index, &cursor_rect, &block_at_line_end);
5899 gint strong_x, weak_x;
5900 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5901 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5905 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5907 g_object_get (gtk_widget_get_settings (widget),
5908 "gtk-split-cursor", &split_cursor,
5911 dir1 = priv->resolved_dir;
5917 if (weak_x != strong_x)
5919 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5925 if (keymap_direction == priv->resolved_dir)
5931 cursor_location.x = xoffset + x1;
5932 cursor_location.y = inner_border.top;
5933 cursor_location.width = 0;
5934 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5936 draw_insertion_cursor (entry, cr,
5937 &cursor_location, TRUE, dir1,
5938 dir2 != PANGO_DIRECTION_NEUTRAL);
5940 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5942 cursor_location.x = xoffset + x2;
5943 draw_insertion_cursor (entry, cr,
5944 &cursor_location, FALSE, dir2,
5948 else /* overwrite_mode */
5950 GtkStyleContext *context;
5951 GdkRGBA cursor_color;
5957 get_layout_position (entry, &x, &y);
5959 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5960 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5961 rect.width = PANGO_PIXELS (cursor_rect.width);
5962 rect.height = PANGO_PIXELS (cursor_rect.height);
5964 context = gtk_widget_get_style_context (widget);
5966 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5967 gdk_cairo_set_source_rgba (cr, &cursor_color);
5968 gdk_cairo_rectangle (cr, &rect);
5971 if (!block_at_line_end)
5973 GtkStateFlags state;
5976 state = gtk_widget_get_state_flags (widget);
5977 gtk_style_context_get_background_color (context, state, &color);
5979 gdk_cairo_rectangle (cr, &rect);
5981 cairo_move_to (cr, x, y);
5982 gdk_cairo_set_source_rgba (cr, &color);
5983 pango_cairo_show_layout (cr, layout);
5991 _gtk_entry_reset_im_context (GtkEntry *entry)
5993 GtkEntryPrivate *priv = entry->priv;
5995 if (priv->need_im_reset)
5997 priv->need_im_reset = FALSE;
5998 gtk_im_context_reset (priv->im_context);
6003 * gtk_entry_reset_im_context:
6004 * @entry: a #GtkEntry
6006 * Reset the input method context of the entry if needed.
6008 * This can be necessary in the case where modifying the buffer
6009 * would confuse on-going input method behavior.
6014 gtk_entry_reset_im_context (GtkEntry *entry)
6016 g_return_if_fail (GTK_IS_ENTRY (entry));
6018 _gtk_entry_reset_im_context (entry);
6022 * gtk_entry_im_context_filter_keypress:
6023 * @entry: a #GtkEntry
6024 * @event: (type Gdk.EventKey): the key event
6026 * Allow the #GtkEntry input method to internally handle key press
6027 * and release events. If this function returns %TRUE, then no further
6028 * processing should be done for this key event. See
6029 * gtk_im_context_filter_keypress().
6031 * Note that you are expected to call this function from your handler
6032 * when overriding key event handling. This is needed in the case when
6033 * you need to insert your own key handling between the input method
6034 * and the default key event handling of the #GtkEntry.
6035 * See gtk_text_view_reset_im_context() for an example of use.
6037 * Return value: %TRUE if the input method handled the key event.
6042 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6045 GtkEntryPrivate *priv;
6047 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6051 return gtk_im_context_filter_keypress (priv->im_context, event);
6055 _gtk_entry_get_im_context (GtkEntry *entry)
6057 return entry->priv->im_context;
6061 gtk_entry_find_position (GtkEntry *entry,
6064 GtkEntryPrivate *priv = entry->priv;
6065 PangoLayout *layout;
6066 PangoLayoutLine *line;
6073 layout = gtk_entry_ensure_layout (entry, TRUE);
6074 text = pango_layout_get_text (layout);
6075 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6077 line = pango_layout_get_lines_readonly (layout)->data;
6078 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6080 if (index >= cursor_index && priv->preedit_length)
6082 if (index >= cursor_index + priv->preedit_length)
6083 index -= priv->preedit_length;
6086 index = cursor_index;
6091 pos = g_utf8_pointer_to_offset (text, text + index);
6098 gtk_entry_get_cursor_locations (GtkEntry *entry,
6103 GtkEntryPrivate *priv = entry->priv;
6104 DisplayMode mode = gtk_entry_get_display_mode (entry);
6106 /* Nothing to display at all, so no cursor is relevant */
6107 if (mode == DISPLAY_BLANK)
6117 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6118 const gchar *text = pango_layout_get_text (layout);
6119 PangoRectangle strong_pos, weak_pos;
6122 if (type == CURSOR_STANDARD)
6124 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6126 else /* type == CURSOR_DND */
6128 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6130 if (priv->dnd_position > priv->current_pos)
6132 if (mode == DISPLAY_NORMAL)
6133 index += priv->preedit_length;
6136 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6137 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6142 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6145 *strong_x = strong_pos.x / PANGO_SCALE;
6148 *weak_x = weak_pos.x / PANGO_SCALE;
6153 gtk_entry_adjust_scroll (GtkEntry *entry)
6155 GtkEntryPrivate *priv = entry->priv;
6156 gint min_offset, max_offset;
6157 gint text_area_width, text_width;
6158 GtkBorder inner_border;
6159 gint strong_x, weak_x;
6160 gint strong_xoffset, weak_xoffset;
6162 PangoLayout *layout;
6163 PangoLayoutLine *line;
6164 PangoRectangle logical_rect;
6166 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6169 _gtk_entry_effective_inner_border (entry, &inner_border);
6171 text_area_width = gdk_window_get_width (priv->text_area);
6172 text_area_width -= inner_border.left + inner_border.right;
6173 if (text_area_width < 0)
6174 text_area_width = 0;
6176 layout = gtk_entry_ensure_layout (entry, TRUE);
6177 line = pango_layout_get_lines_readonly (layout)->data;
6179 pango_layout_line_get_extents (line, NULL, &logical_rect);
6181 /* Display as much text as we can */
6183 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6184 xalign = priv->xalign;
6186 xalign = 1.0 - priv->xalign;
6188 text_width = PANGO_PIXELS(logical_rect.width);
6190 if (text_width > text_area_width)
6193 max_offset = text_width - text_area_width;
6197 min_offset = (text_width - text_area_width) * xalign;
6198 max_offset = min_offset;
6201 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6203 /* And make sure cursors are on screen. Note that the cursor is
6204 * actually drawn one pixel into the INNER_BORDER space on
6205 * the right, when the scroll is at the utmost right. This
6206 * looks better to to me than confining the cursor inside the
6207 * border entirely, though it means that the cursor gets one
6208 * pixel closer to the edge of the widget on the right than
6209 * on the left. This might need changing if one changed
6210 * INNER_BORDER from 2 to 1, as one would do on a
6211 * small-screen-real-estate display.
6213 * We always make sure that the strong cursor is on screen, and
6214 * put the weak cursor on screen if possible.
6217 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6219 strong_xoffset = strong_x - priv->scroll_offset;
6221 if (strong_xoffset < 0)
6223 priv->scroll_offset += strong_xoffset;
6226 else if (strong_xoffset > text_area_width)
6228 priv->scroll_offset += strong_xoffset - text_area_width;
6229 strong_xoffset = text_area_width;
6232 weak_xoffset = weak_x - priv->scroll_offset;
6234 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6236 priv->scroll_offset += weak_xoffset;
6238 else if (weak_xoffset > text_area_width &&
6239 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6241 priv->scroll_offset += weak_xoffset - text_area_width;
6244 g_object_notify (G_OBJECT (entry), "scroll-offset");
6248 gtk_entry_move_adjustments (GtkEntry *entry)
6250 GtkWidget *widget = GTK_WIDGET (entry);
6251 GtkAllocation allocation;
6252 GtkAdjustment *adjustment;
6253 PangoContext *context;
6254 PangoFontMetrics *metrics;
6255 GtkStyleContext *style_context;
6256 GtkStateFlags state;
6257 gint x, layout_x, border_x, border_y;
6260 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6264 gtk_widget_get_allocation (widget, &allocation);
6266 /* Cursor position, layout offset, border width, and widget allocation */
6267 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6268 get_layout_position (entry, &layout_x, NULL);
6269 _gtk_entry_get_borders (entry, &border_x, &border_y);
6270 x += allocation.x + layout_x + border_x;
6272 /* Approximate width of a char, so user can see what is ahead/behind */
6273 context = gtk_widget_get_pango_context (widget);
6274 style_context = gtk_widget_get_style_context (widget);
6275 state = gtk_widget_get_state_flags (widget);
6277 metrics = pango_context_get_metrics (context,
6278 gtk_style_context_get_font (style_context, state),
6279 pango_context_get_language (context));
6280 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6283 gtk_adjustment_clamp_page (adjustment,
6284 x - (char_width + 1), /* one char + one pixel before */
6285 x + (char_width + 2)); /* one char + cursor + one pixel after */
6289 gtk_entry_move_visually (GtkEntry *entry,
6293 GtkEntryPrivate *priv = entry->priv;
6295 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6298 text = pango_layout_get_text (layout);
6300 index = g_utf8_offset_to_pointer (text, start) - text;
6304 int new_index, new_trailing;
6305 gboolean split_cursor;
6308 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6309 "gtk-split-cursor", &split_cursor,
6316 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6317 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6319 strong = keymap_direction == priv->resolved_dir;
6324 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6329 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6335 else if (new_index != G_MAXINT)
6338 while (new_trailing--)
6339 index = g_utf8_next_char (text + index) - text;
6342 return g_utf8_pointer_to_offset (text, text + index);
6346 gtk_entry_move_logically (GtkEntry *entry,
6350 gint new_pos = start;
6353 length = gtk_entry_buffer_get_length (get_buffer (entry));
6355 /* Prevent any leak of information */
6356 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6358 new_pos = CLAMP (start + count, 0, length);
6362 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6363 PangoLogAttr *log_attrs;
6366 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6368 while (count > 0 && new_pos < length)
6372 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6376 while (count < 0 && new_pos > 0)
6380 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6392 gtk_entry_move_forward_word (GtkEntry *entry,
6394 gboolean allow_whitespace)
6396 gint new_pos = start;
6399 length = gtk_entry_buffer_get_length (get_buffer (entry));
6401 /* Prevent any leak of information */
6402 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6406 else if (new_pos < length)
6408 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6409 PangoLogAttr *log_attrs;
6412 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6414 /* Find the next word boundary */
6416 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6417 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6428 gtk_entry_move_backward_word (GtkEntry *entry,
6430 gboolean allow_whitespace)
6432 gint new_pos = start;
6434 /* Prevent any leak of information */
6435 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6441 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6442 PangoLogAttr *log_attrs;
6445 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6447 new_pos = start - 1;
6449 /* Find the previous word boundary */
6450 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6451 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6461 gtk_entry_delete_whitespace (GtkEntry *entry)
6463 GtkEntryPrivate *priv = entry->priv;
6464 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6465 PangoLogAttr *log_attrs;
6469 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6471 start = end = priv->current_pos;
6473 while (start > 0 && log_attrs[start-1].is_white)
6476 while (end < n_attrs && log_attrs[end].is_white)
6482 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6487 gtk_entry_select_word (GtkEntry *entry)
6489 GtkEntryPrivate *priv = entry->priv;
6490 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6491 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6493 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6497 gtk_entry_select_line (GtkEntry *entry)
6499 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6503 truncate_multiline (const gchar *text)
6508 text[length] && text[length] != '\n' && text[length] != '\r';
6515 paste_received (GtkClipboard *clipboard,
6519 GtkEntry *entry = GTK_ENTRY (data);
6520 GtkEditable *editable = GTK_EDITABLE (entry);
6521 GtkEntryPrivate *priv = entry->priv;
6523 if (priv->button == 2)
6525 gint pos, start, end;
6526 pos = priv->insert_pos;
6527 gtk_editable_get_selection_bounds (editable, &start, &end);
6528 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6529 gtk_editable_select_region (editable, pos, pos);
6534 gint pos, start, end;
6536 gboolean popup_completion;
6537 GtkEntryCompletion *completion;
6539 completion = gtk_entry_get_completion (entry);
6541 if (priv->truncate_multiline)
6542 length = truncate_multiline (text);
6544 /* only complete if the selection is at the end */
6545 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6546 MAX (priv->current_pos, priv->selection_bound));
6550 if (gtk_widget_get_mapped (completion->priv->popup_window))
6551 _gtk_entry_completion_popdown (completion);
6553 if (!popup_completion && completion->priv->changed_id > 0)
6554 g_signal_handler_block (entry, completion->priv->changed_id);
6557 begin_change (entry);
6558 g_object_freeze_notify (G_OBJECT (entry));
6559 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6560 gtk_editable_delete_text (editable, start, end);
6562 pos = priv->current_pos;
6563 gtk_editable_insert_text (editable, text, length, &pos);
6564 gtk_editable_set_position (editable, pos);
6565 g_object_thaw_notify (G_OBJECT (entry));
6569 !popup_completion && completion->priv->changed_id > 0)
6570 g_signal_handler_unblock (entry, completion->priv->changed_id);
6573 g_object_unref (entry);
6577 gtk_entry_paste (GtkEntry *entry,
6580 g_object_ref (entry);
6581 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6582 paste_received, entry);
6586 primary_get_cb (GtkClipboard *clipboard,
6587 GtkSelectionData *selection_data,
6591 GtkEntry *entry = GTK_ENTRY (data);
6594 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6596 gchar *str = gtk_entry_get_display_text (entry, start, end);
6597 gtk_selection_data_set_text (selection_data, str, -1);
6603 primary_clear_cb (GtkClipboard *clipboard,
6606 GtkEntry *entry = GTK_ENTRY (data);
6607 GtkEntryPrivate *priv = entry->priv;
6609 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6613 gtk_entry_update_primary_selection (GtkEntry *entry)
6615 GtkTargetList *list;
6616 GtkTargetEntry *targets;
6617 GtkClipboard *clipboard;
6621 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6624 list = gtk_target_list_new (NULL, 0);
6625 gtk_target_list_add_text_targets (list, 0);
6627 targets = gtk_target_table_new_from_list (list, &n_targets);
6629 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6631 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6633 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6634 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6635 primary_clear_cb (clipboard, entry);
6639 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6640 gtk_clipboard_clear (clipboard);
6643 gtk_target_table_free (targets, n_targets);
6644 gtk_target_list_unref (list);
6648 gtk_entry_clear (GtkEntry *entry,
6649 GtkEntryIconPosition icon_pos)
6651 GtkEntryPrivate *priv = entry->priv;
6652 EntryIconInfo *icon_info = priv->icons[icon_pos];
6654 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6657 g_object_freeze_notify (G_OBJECT (entry));
6659 /* Explicitly check, as the pointer may become invalidated
6660 * during destruction.
6662 if (GDK_IS_WINDOW (icon_info->window))
6663 gdk_window_hide (icon_info->window);
6665 if (icon_info->pixbuf)
6667 g_object_unref (icon_info->pixbuf);
6668 icon_info->pixbuf = NULL;
6671 switch (icon_info->storage_type)
6673 case GTK_IMAGE_PIXBUF:
6674 g_object_notify (G_OBJECT (entry),
6675 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6678 case GTK_IMAGE_STOCK:
6679 g_free (icon_info->stock_id);
6680 icon_info->stock_id = NULL;
6681 g_object_notify (G_OBJECT (entry),
6682 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6685 case GTK_IMAGE_ICON_NAME:
6686 g_free (icon_info->icon_name);
6687 icon_info->icon_name = NULL;
6688 g_object_notify (G_OBJECT (entry),
6689 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6692 case GTK_IMAGE_GICON:
6693 if (icon_info->gicon)
6695 g_object_unref (icon_info->gicon);
6696 icon_info->gicon = NULL;
6698 g_object_notify (G_OBJECT (entry),
6699 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6703 g_assert_not_reached ();
6707 icon_info->storage_type = GTK_IMAGE_EMPTY;
6708 g_object_notify (G_OBJECT (entry),
6709 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6711 g_object_thaw_notify (G_OBJECT (entry));
6715 create_normal_pixbuf (GtkStyleContext *context,
6716 const gchar *stock_id,
6717 GtkIconSize icon_size)
6719 GtkIconSet *icon_set;
6722 gtk_style_context_save (context);
6724 /* Unset any state */
6725 gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
6727 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6728 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6730 gtk_style_context_restore (context);
6736 ensure_stated_icon_from_info (GtkStyleContext *context,
6739 GdkPixbuf *retval = NULL;
6740 gboolean symbolic = FALSE;
6745 gtk_icon_info_load_symbolic_for_context (info,
6754 create_normal_pixbuf (context,
6755 GTK_STOCK_MISSING_IMAGE,
6756 GTK_ICON_SIZE_MENU);
6760 GdkPixbuf *temp_pixbuf;
6761 GtkIconSource *icon_source;
6763 icon_source = gtk_icon_source_new ();
6764 gtk_icon_source_set_pixbuf (icon_source, retval);
6765 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
6767 temp_pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
6769 gtk_icon_source_free (icon_source);
6771 g_object_unref (retval);
6772 retval = temp_pixbuf;
6779 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6780 GtkEntryIconPosition icon_pos)
6782 GtkEntryPrivate *priv = entry->priv;
6783 EntryIconInfo *icon_info = priv->icons[icon_pos];
6784 GtkStyleContext *context;
6786 GtkIconTheme *icon_theme;
6787 GtkSettings *settings;
6791 GtkStateFlags state;
6793 widget = GTK_WIDGET (entry);
6794 context = gtk_widget_get_style_context (widget);
6796 state = GTK_STATE_FLAG_NORMAL;
6798 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
6799 state |= GTK_STATE_FLAG_INSENSITIVE;
6800 else if (icon_info->prelight)
6801 state |= GTK_STATE_FLAG_PRELIGHT;
6803 if ((icon_info == NULL) ||
6804 ((icon_info->pixbuf != NULL) && icon_info->last_state == state))
6807 icon_info->last_state = state;
6809 gtk_style_context_save (context);
6810 gtk_style_context_set_state (context, state);
6811 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
6813 switch (icon_info->storage_type)
6815 case GTK_IMAGE_EMPTY:
6816 case GTK_IMAGE_PIXBUF:
6818 case GTK_IMAGE_STOCK:
6819 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6820 GTK_ICON_SIZE_MENU);
6822 if (!icon_info->pixbuf)
6823 icon_info->pixbuf = create_normal_pixbuf (context,
6824 GTK_STOCK_MISSING_IMAGE,
6825 GTK_ICON_SIZE_MENU);
6828 case GTK_IMAGE_ICON_NAME:
6829 screen = gtk_widget_get_screen (widget);
6832 icon_theme = gtk_icon_theme_get_for_screen (screen);
6833 settings = gtk_settings_get_for_screen (screen);
6835 gtk_icon_size_lookup_for_settings (settings,
6839 info = gtk_icon_theme_lookup_icon (icon_theme,
6840 icon_info->icon_name,
6841 MIN (width, height),
6845 ensure_stated_icon_from_info (context, info);
6848 gtk_icon_info_free (info);
6852 case GTK_IMAGE_GICON:
6853 screen = gtk_widget_get_screen (widget);
6856 icon_theme = gtk_icon_theme_get_for_screen (screen);
6857 settings = gtk_settings_get_for_screen (screen);
6859 gtk_icon_size_lookup_for_settings (settings,
6863 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6865 MIN (width, height),
6866 GTK_ICON_LOOKUP_USE_BUILTIN);
6869 ensure_stated_icon_from_info (context, info);
6872 gtk_icon_info_free (info);
6877 g_assert_not_reached ();
6881 gtk_style_context_restore (context);
6883 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6884 gdk_window_show_unraised (icon_info->window);
6894 * Creates a new entry.
6896 * Return value: a new #GtkEntry.
6899 gtk_entry_new (void)
6901 return g_object_new (GTK_TYPE_ENTRY, NULL);
6905 * gtk_entry_new_with_buffer:
6906 * @buffer: The buffer to use for the new #GtkEntry.
6908 * Creates a new entry with the specified text buffer.
6910 * Return value: a new #GtkEntry
6915 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6917 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6918 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6921 static GtkEntryBuffer*
6922 get_buffer (GtkEntry *entry)
6924 GtkEntryPrivate *priv = entry->priv;
6926 if (priv->buffer == NULL)
6928 GtkEntryBuffer *buffer;
6929 buffer = gtk_entry_buffer_new (NULL, 0);
6930 gtk_entry_set_buffer (entry, buffer);
6931 g_object_unref (buffer);
6934 return priv->buffer;
6938 * gtk_entry_get_buffer:
6939 * @entry: a #GtkEntry
6941 * Get the #GtkEntryBuffer object which holds the text for
6946 * Returns: (transfer none): A #GtkEntryBuffer object.
6949 gtk_entry_get_buffer (GtkEntry *entry)
6951 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6953 return get_buffer (entry);
6957 * gtk_entry_set_buffer:
6958 * @entry: a #GtkEntry
6959 * @buffer: a #GtkEntryBuffer
6961 * Set the #GtkEntryBuffer object which holds the text for
6967 gtk_entry_set_buffer (GtkEntry *entry,
6968 GtkEntryBuffer *buffer)
6970 GtkEntryPrivate *priv;
6973 g_return_if_fail (GTK_IS_ENTRY (entry));
6979 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6980 g_object_ref (buffer);
6985 buffer_disconnect_signals (entry);
6986 g_object_unref (priv->buffer);
6989 priv->buffer = buffer;
6992 buffer_connect_signals (entry);
6994 obj = G_OBJECT (entry);
6995 g_object_freeze_notify (obj);
6996 g_object_notify (obj, "buffer");
6997 g_object_notify (obj, "text");
6998 g_object_notify (obj, "text-length");
6999 g_object_notify (obj, "max-length");
7000 g_object_notify (obj, "visibility");
7001 g_object_notify (obj, "invisible-char");
7002 g_object_notify (obj, "invisible-char-set");
7003 g_object_thaw_notify (obj);
7005 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7006 gtk_entry_recompute (entry);
7010 * gtk_entry_get_text_area:
7011 * @entry: a #GtkEntry
7012 * @text_area: (out): Return location for the text area.
7014 * Gets the area where the entry's text is drawn. This function is
7015 * useful when drawing something to the entry in a draw callback.
7017 * If the entry is not realized, @text_area is filled with zeros.
7019 * See also gtk_entry_get_icon_area().
7024 gtk_entry_get_text_area (GtkEntry *entry,
7025 GdkRectangle *text_area)
7027 GtkEntryPrivate *priv;
7029 g_return_if_fail (GTK_IS_ENTRY (entry));
7030 g_return_if_fail (text_area != NULL);
7034 if (priv->text_area)
7036 GtkAllocation allocation;
7039 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7040 gdk_window_get_position (priv->text_area, &x, &y);
7042 text_area->x = x - allocation.x;
7043 text_area->y = y - allocation.y;
7044 text_area->width = gdk_window_get_width (priv->text_area);
7045 text_area->height = gdk_window_get_height (priv->text_area);
7051 text_area->width = 0;
7052 text_area->height = 0;
7057 * gtk_entry_set_text:
7058 * @entry: a #GtkEntry
7059 * @text: the new text
7061 * Sets the text in the widget to the given
7062 * value, replacing the current contents.
7064 * See gtk_entry_buffer_set_text().
7067 gtk_entry_set_text (GtkEntry *entry,
7071 GtkEntryCompletion *completion;
7073 g_return_if_fail (GTK_IS_ENTRY (entry));
7074 g_return_if_fail (text != NULL);
7076 /* Actually setting the text will affect the cursor and selection;
7077 * if the contents don't actually change, this will look odd to the user.
7079 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7082 completion = gtk_entry_get_completion (entry);
7083 if (completion && completion->priv->changed_id > 0)
7084 g_signal_handler_block (entry, completion->priv->changed_id);
7086 begin_change (entry);
7087 g_object_freeze_notify (G_OBJECT (entry));
7088 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7090 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7091 g_object_thaw_notify (G_OBJECT (entry));
7094 if (completion && completion->priv->changed_id > 0)
7095 g_signal_handler_unblock (entry, completion->priv->changed_id);
7099 * gtk_entry_set_visibility:
7100 * @entry: a #GtkEntry
7101 * @visible: %TRUE if the contents of the entry are displayed
7104 * Sets whether the contents of the entry are visible or not.
7105 * When visibility is set to %FALSE, characters are displayed
7106 * as the invisible char, and will also appear that way when
7107 * the text in the entry widget is copied elsewhere.
7109 * By default, GTK+ picks the best invisible character available
7110 * in the current font, but it can be changed with
7111 * gtk_entry_set_invisible_char().
7114 gtk_entry_set_visibility (GtkEntry *entry,
7117 GtkEntryPrivate *priv;
7119 g_return_if_fail (GTK_IS_ENTRY (entry));
7123 visible = visible != FALSE;
7125 if (priv->visible != visible)
7127 priv->visible = visible;
7129 g_object_notify (G_OBJECT (entry), "visibility");
7130 gtk_entry_recompute (entry);
7135 * gtk_entry_get_visibility:
7136 * @entry: a #GtkEntry
7138 * Retrieves whether the text in @entry is visible. See
7139 * gtk_entry_set_visibility().
7141 * Return value: %TRUE if the text is currently visible
7144 gtk_entry_get_visibility (GtkEntry *entry)
7146 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7148 return entry->priv->visible;
7152 * gtk_entry_set_invisible_char:
7153 * @entry: a #GtkEntry
7154 * @ch: a Unicode character
7156 * Sets the character to use in place of the actual text when
7157 * gtk_entry_set_visibility() has been called to set text visibility
7158 * to %FALSE. i.e. this is the character used in "password mode" to
7159 * show the user how many characters have been typed. By default, GTK+
7160 * picks the best invisible char available in the current font. If you
7161 * set the invisible char to 0, then the user will get no feedback
7162 * at all; there will be no text on the screen as they type.
7165 gtk_entry_set_invisible_char (GtkEntry *entry,
7168 GtkEntryPrivate *priv;
7170 g_return_if_fail (GTK_IS_ENTRY (entry));
7174 if (!priv->invisible_char_set)
7176 priv->invisible_char_set = TRUE;
7177 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7180 if (ch == priv->invisible_char)
7183 priv->invisible_char = ch;
7184 g_object_notify (G_OBJECT (entry), "invisible-char");
7185 gtk_entry_recompute (entry);
7189 * gtk_entry_get_invisible_char:
7190 * @entry: a #GtkEntry
7192 * Retrieves the character displayed in place of the real characters
7193 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7195 * Return value: the current invisible char, or 0, if the entry does not
7196 * show invisible text at all.
7199 gtk_entry_get_invisible_char (GtkEntry *entry)
7201 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7203 return entry->priv->invisible_char;
7207 * gtk_entry_unset_invisible_char:
7208 * @entry: a #GtkEntry
7210 * Unsets the invisible char previously set with
7211 * gtk_entry_set_invisible_char(). So that the
7212 * default invisible char is used again.
7217 gtk_entry_unset_invisible_char (GtkEntry *entry)
7219 GtkEntryPrivate *priv;
7222 g_return_if_fail (GTK_IS_ENTRY (entry));
7226 if (!priv->invisible_char_set)
7229 priv->invisible_char_set = FALSE;
7230 ch = find_invisible_char (GTK_WIDGET (entry));
7232 if (priv->invisible_char != ch)
7234 priv->invisible_char = ch;
7235 g_object_notify (G_OBJECT (entry), "invisible-char");
7238 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7239 gtk_entry_recompute (entry);
7243 * gtk_entry_set_overwrite_mode:
7244 * @entry: a #GtkEntry
7245 * @overwrite: new value
7247 * Sets whether the text is overwritten when typing in the #GtkEntry.
7252 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7255 GtkEntryPrivate *priv = entry->priv;
7257 g_return_if_fail (GTK_IS_ENTRY (entry));
7259 if (priv->overwrite_mode == overwrite)
7262 gtk_entry_toggle_overwrite (entry);
7264 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7268 * gtk_entry_get_overwrite_mode:
7269 * @entry: a #GtkEntry
7271 * Gets the value set by gtk_entry_set_overwrite_mode().
7273 * Return value: whether the text is overwritten when typing.
7278 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7280 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7282 return entry->priv->overwrite_mode;
7286 * gtk_entry_get_text:
7287 * @entry: a #GtkEntry
7289 * Retrieves the contents of the entry widget.
7290 * See also gtk_editable_get_chars().
7292 * This is equivalent to:
7294 * <informalexample><programlisting>
7295 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7296 * </programlisting></informalexample>
7298 * Return value: a pointer to the contents of the widget as a
7299 * string. This string points to internally allocated
7300 * storage in the widget and must not be freed, modified or
7304 gtk_entry_get_text (GtkEntry *entry)
7306 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7308 return gtk_entry_buffer_get_text (get_buffer (entry));
7312 * gtk_entry_set_max_length:
7313 * @entry: a #GtkEntry
7314 * @max: the maximum length of the entry, or 0 for no maximum.
7315 * (other than the maximum length of entries.) The value passed in will
7316 * be clamped to the range 0-65536.
7318 * Sets the maximum allowed length of the contents of the widget. If
7319 * the current contents are longer than the given length, then they
7320 * will be truncated to fit.
7322 * This is equivalent to:
7324 * <informalexample><programlisting>
7325 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7326 * </programlisting></informalexample>
7329 gtk_entry_set_max_length (GtkEntry *entry,
7332 g_return_if_fail (GTK_IS_ENTRY (entry));
7333 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7337 * gtk_entry_get_max_length:
7338 * @entry: a #GtkEntry
7340 * Retrieves the maximum allowed length of the text in
7341 * @entry. See gtk_entry_set_max_length().
7343 * This is equivalent to:
7345 * <informalexample><programlisting>
7346 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7347 * </programlisting></informalexample>
7349 * Return value: the maximum allowed number of characters
7350 * in #GtkEntry, or 0 if there is no maximum.
7353 gtk_entry_get_max_length (GtkEntry *entry)
7355 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7357 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7361 * gtk_entry_get_text_length:
7362 * @entry: a #GtkEntry
7364 * Retrieves the current length of the text in
7367 * This is equivalent to:
7369 * <informalexample><programlisting>
7370 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7371 * </programlisting></informalexample>
7373 * Return value: the current number of characters
7374 * in #GtkEntry, or 0 if there are none.
7379 gtk_entry_get_text_length (GtkEntry *entry)
7381 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7383 return gtk_entry_buffer_get_length (get_buffer (entry));
7387 * gtk_entry_set_activates_default:
7388 * @entry: a #GtkEntry
7389 * @setting: %TRUE to activate window's default widget on Enter keypress
7391 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7392 * widget for the window containing the entry. This usually means that
7393 * the dialog box containing the entry will be closed, since the default
7394 * widget is usually one of the dialog buttons.
7396 * (For experts: if @setting is %TRUE, the entry calls
7397 * gtk_window_activate_default() on the window containing the entry, in
7398 * the default handler for the #GtkWidget::activate signal.)
7401 gtk_entry_set_activates_default (GtkEntry *entry,
7404 GtkEntryPrivate *priv;
7406 g_return_if_fail (GTK_IS_ENTRY (entry));
7410 setting = setting != FALSE;
7412 if (setting != priv->activates_default)
7414 priv->activates_default = setting;
7415 g_object_notify (G_OBJECT (entry), "activates-default");
7420 * gtk_entry_get_activates_default:
7421 * @entry: a #GtkEntry
7423 * Retrieves the value set by gtk_entry_set_activates_default().
7425 * Return value: %TRUE if the entry will activate the default widget
7428 gtk_entry_get_activates_default (GtkEntry *entry)
7430 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7432 return entry->priv->activates_default;
7436 * gtk_entry_set_width_chars:
7437 * @entry: a #GtkEntry
7438 * @n_chars: width in chars
7440 * Changes the size request of the entry to be about the right size
7441 * for @n_chars characters. Note that it changes the size
7442 * <emphasis>request</emphasis>, the size can still be affected by
7443 * how you pack the widget into containers. If @n_chars is -1, the
7444 * size reverts to the default entry size.
7447 gtk_entry_set_width_chars (GtkEntry *entry,
7450 GtkEntryPrivate *priv;
7452 g_return_if_fail (GTK_IS_ENTRY (entry));
7456 if (priv->width_chars != n_chars)
7458 priv->width_chars = n_chars;
7459 g_object_notify (G_OBJECT (entry), "width-chars");
7460 gtk_widget_queue_resize (GTK_WIDGET (entry));
7465 * gtk_entry_get_width_chars:
7466 * @entry: a #GtkEntry
7468 * Gets the value set by gtk_entry_set_width_chars().
7470 * Return value: number of chars to request space for, or negative if unset
7473 gtk_entry_get_width_chars (GtkEntry *entry)
7475 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7477 return entry->priv->width_chars;
7481 * gtk_entry_set_has_frame:
7482 * @entry: a #GtkEntry
7483 * @setting: new value
7485 * Sets whether the entry has a beveled frame around it.
7488 gtk_entry_set_has_frame (GtkEntry *entry,
7491 GtkEntryPrivate *priv;
7493 g_return_if_fail (GTK_IS_ENTRY (entry));
7497 setting = (setting != FALSE);
7499 if (priv->has_frame == setting)
7502 gtk_widget_queue_resize (GTK_WIDGET (entry));
7503 priv->has_frame = setting;
7504 g_object_notify (G_OBJECT (entry), "has-frame");
7508 * gtk_entry_get_has_frame:
7509 * @entry: a #GtkEntry
7511 * Gets the value set by gtk_entry_set_has_frame().
7513 * Return value: whether the entry has a beveled frame
7516 gtk_entry_get_has_frame (GtkEntry *entry)
7518 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7520 return entry->priv->has_frame;
7524 * gtk_entry_set_inner_border:
7525 * @entry: a #GtkEntry
7526 * @border: (allow-none): a #GtkBorder, or %NULL
7528 * Sets %entry's inner-border property to %border, or clears it if %NULL
7529 * is passed. The inner-border is the area around the entry's text, but
7532 * If set, this property overrides the inner-border style property.
7533 * Overriding the style-provided border is useful when you want to do
7534 * in-place editing of some text in a canvas or list widget, where
7535 * pixel-exact positioning of the entry is important.
7540 gtk_entry_set_inner_border (GtkEntry *entry,
7541 const GtkBorder *border)
7543 g_return_if_fail (GTK_IS_ENTRY (entry));
7545 gtk_widget_queue_resize (GTK_WIDGET (entry));
7548 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7549 gtk_border_copy (border),
7550 (GDestroyNotify) gtk_border_free);
7552 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7554 g_object_notify (G_OBJECT (entry), "inner-border");
7558 * gtk_entry_get_inner_border:
7559 * @entry: a #GtkEntry
7561 * This function returns the entry's #GtkEntry:inner-border property. See
7562 * gtk_entry_set_inner_border() for more information.
7564 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7569 gtk_entry_get_inner_border (GtkEntry *entry)
7571 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7573 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7577 * gtk_entry_get_layout:
7578 * @entry: a #GtkEntry
7580 * Gets the #PangoLayout used to display the entry.
7581 * The layout is useful to e.g. convert text positions to
7582 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7583 * The returned layout is owned by the entry and must not be
7584 * modified or freed by the caller.
7586 * Keep in mind that the layout text may contain a preedit string, so
7587 * gtk_entry_layout_index_to_text_index() and
7588 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7589 * indices in the layout to byte indices in the entry contents.
7591 * Return value: (transfer none): the #PangoLayout for this entry
7594 gtk_entry_get_layout (GtkEntry *entry)
7596 PangoLayout *layout;
7598 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7600 layout = gtk_entry_ensure_layout (entry, TRUE);
7607 * gtk_entry_layout_index_to_text_index:
7608 * @entry: a #GtkEntry
7609 * @layout_index: byte index into the entry layout text
7611 * Converts from a position in the entry contents (returned
7612 * by gtk_entry_get_text()) to a position in the
7613 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7614 * with text retrieved via pango_layout_get_text()).
7616 * Return value: byte index into the entry contents
7619 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7622 GtkEntryPrivate *priv;
7623 PangoLayout *layout;
7627 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7631 layout = gtk_entry_ensure_layout (entry, TRUE);
7632 text = pango_layout_get_text (layout);
7633 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7635 if (layout_index >= cursor_index && priv->preedit_length)
7637 if (layout_index >= cursor_index + priv->preedit_length)
7638 layout_index -= priv->preedit_length;
7640 layout_index = cursor_index;
7643 return layout_index;
7647 * gtk_entry_text_index_to_layout_index:
7648 * @entry: a #GtkEntry
7649 * @text_index: byte index into the entry contents
7651 * Converts from a position in the entry's #PangoLayout (returned by
7652 * gtk_entry_get_layout()) to a position in the entry contents
7653 * (returned by gtk_entry_get_text()).
7655 * Return value: byte index into the entry layout text
7658 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7661 GtkEntryPrivate *priv;
7662 PangoLayout *layout;
7666 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7670 layout = gtk_entry_ensure_layout (entry, TRUE);
7671 text = pango_layout_get_text (layout);
7672 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7674 if (text_index > cursor_index)
7675 text_index += priv->preedit_length;
7681 * gtk_entry_get_layout_offsets:
7682 * @entry: a #GtkEntry
7683 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7684 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7687 * Obtains the position of the #PangoLayout used to render text
7688 * in the entry, in widget coordinates. Useful if you want to line
7689 * up the text in an entry with some other text, e.g. when using the
7690 * entry to implement editable cells in a sheet widget.
7692 * Also useful to convert mouse events into coordinates inside the
7693 * #PangoLayout, e.g. to take some action if some part of the entry text
7696 * Note that as the user scrolls around in the entry the offsets will
7697 * change; you'll need to connect to the "notify::scroll-offset"
7698 * signal to track this. Remember when using the #PangoLayout
7699 * functions you need to convert to and from pixels using
7700 * PANGO_PIXELS() or #PANGO_SCALE.
7702 * Keep in mind that the layout text may contain a preedit string, so
7703 * gtk_entry_layout_index_to_text_index() and
7704 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7705 * indices in the layout to byte indices in the entry contents.
7708 gtk_entry_get_layout_offsets (GtkEntry *entry,
7712 gint text_area_x, text_area_y;
7714 g_return_if_fail (GTK_IS_ENTRY (entry));
7716 /* this gets coords relative to text area */
7717 get_layout_position (entry, x, y);
7719 /* convert to widget coords */
7720 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7731 * gtk_entry_set_alignment:
7732 * @entry: a #GtkEntry
7733 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7734 * Reversed for RTL layouts
7736 * Sets the alignment for the contents of the entry. This controls
7737 * the horizontal positioning of the contents when the displayed
7738 * text is shorter than the width of the entry.
7743 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7745 GtkEntryPrivate *priv;
7747 g_return_if_fail (GTK_IS_ENTRY (entry));
7753 else if (xalign > 1.0)
7756 if (xalign != priv->xalign)
7758 priv->xalign = xalign;
7760 gtk_entry_recompute (entry);
7762 g_object_notify (G_OBJECT (entry), "xalign");
7767 * gtk_entry_get_alignment:
7768 * @entry: a #GtkEntry
7770 * Gets the value set by gtk_entry_set_alignment().
7772 * Return value: the alignment
7777 gtk_entry_get_alignment (GtkEntry *entry)
7779 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7781 return entry->priv->xalign;
7785 * gtk_entry_set_icon_from_pixbuf:
7786 * @entry: a #GtkEntry
7787 * @icon_pos: Icon position
7788 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7790 * Sets the icon shown in the specified position using a pixbuf.
7792 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7797 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7798 GtkEntryIconPosition icon_pos,
7801 GtkEntryPrivate *priv;
7802 EntryIconInfo *icon_info;
7804 g_return_if_fail (GTK_IS_ENTRY (entry));
7805 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7809 if ((icon_info = priv->icons[icon_pos]) == NULL)
7810 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7812 g_object_freeze_notify (G_OBJECT (entry));
7815 g_object_ref (pixbuf);
7817 gtk_entry_clear (entry, icon_pos);
7821 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7822 icon_info->pixbuf = pixbuf;
7824 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7826 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7827 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7831 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7832 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7835 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7836 gdk_window_show_unraised (icon_info->window);
7839 gtk_entry_ensure_pixbuf (entry, icon_pos);
7841 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7842 gtk_widget_queue_resize (GTK_WIDGET (entry));
7844 g_object_thaw_notify (G_OBJECT (entry));
7848 * gtk_entry_set_icon_from_stock:
7849 * @entry: A #GtkEntry
7850 * @icon_pos: Icon position
7851 * @stock_id: (allow-none): The name of the stock item, or %NULL
7853 * Sets the icon shown in the entry at the specified position from
7856 * If @stock_id is %NULL, no icon will be shown in the specified position.
7861 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7862 GtkEntryIconPosition icon_pos,
7863 const gchar *stock_id)
7865 GtkEntryPrivate *priv;
7866 EntryIconInfo *icon_info;
7869 g_return_if_fail (GTK_IS_ENTRY (entry));
7870 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7874 if ((icon_info = priv->icons[icon_pos]) == NULL)
7875 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7877 g_object_freeze_notify (G_OBJECT (entry));
7879 /* need to dup before clearing */
7880 new_id = g_strdup (stock_id);
7882 gtk_entry_clear (entry, icon_pos);
7886 icon_info->storage_type = GTK_IMAGE_STOCK;
7887 icon_info->stock_id = new_id;
7889 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7891 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7892 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7896 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7897 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7900 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7901 gdk_window_show_unraised (icon_info->window);
7904 gtk_entry_ensure_pixbuf (entry, icon_pos);
7906 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7907 gtk_widget_queue_resize (GTK_WIDGET (entry));
7909 g_object_thaw_notify (G_OBJECT (entry));
7913 * gtk_entry_set_icon_from_icon_name:
7914 * @entry: A #GtkEntry
7915 * @icon_pos: The position at which to set the icon
7916 * @icon_name: (allow-none): An icon name, or %NULL
7918 * Sets the icon shown in the entry at the specified position
7919 * from the current icon theme.
7921 * If the icon name isn't known, a "broken image" icon will be displayed
7924 * If @icon_name is %NULL, no icon will be shown in the specified position.
7929 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7930 GtkEntryIconPosition icon_pos,
7931 const gchar *icon_name)
7933 GtkEntryPrivate *priv;
7934 EntryIconInfo *icon_info;
7937 g_return_if_fail (GTK_IS_ENTRY (entry));
7938 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7942 if ((icon_info = priv->icons[icon_pos]) == NULL)
7943 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7945 g_object_freeze_notify (G_OBJECT (entry));
7947 /* need to dup before clearing */
7948 new_name = g_strdup (icon_name);
7950 gtk_entry_clear (entry, icon_pos);
7952 if (new_name != NULL)
7954 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7955 icon_info->icon_name = new_name;
7957 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7959 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7960 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7964 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7965 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7968 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7969 gdk_window_show_unraised (icon_info->window);
7972 gtk_entry_ensure_pixbuf (entry, icon_pos);
7974 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7975 gtk_widget_queue_resize (GTK_WIDGET (entry));
7977 g_object_thaw_notify (G_OBJECT (entry));
7981 * gtk_entry_set_icon_from_gicon:
7982 * @entry: A #GtkEntry
7983 * @icon_pos: The position at which to set the icon
7984 * @icon: (allow-none): The icon to set, or %NULL
7986 * Sets the icon shown in the entry at the specified position
7987 * from the current icon theme.
7988 * If the icon isn't known, a "broken image" icon will be displayed
7991 * If @icon is %NULL, no icon will be shown in the specified position.
7996 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7997 GtkEntryIconPosition icon_pos,
8000 GtkEntryPrivate *priv;
8001 EntryIconInfo *icon_info;
8003 g_return_if_fail (GTK_IS_ENTRY (entry));
8004 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8008 if ((icon_info = priv->icons[icon_pos]) == NULL)
8009 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8011 g_object_freeze_notify (G_OBJECT (entry));
8013 /* need to ref before clearing */
8015 g_object_ref (icon);
8017 gtk_entry_clear (entry, icon_pos);
8021 icon_info->storage_type = GTK_IMAGE_GICON;
8022 icon_info->gicon = icon;
8024 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8026 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8027 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8031 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8032 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8035 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8036 gdk_window_show_unraised (icon_info->window);
8039 gtk_entry_ensure_pixbuf (entry, icon_pos);
8041 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8042 gtk_widget_queue_resize (GTK_WIDGET (entry));
8044 g_object_thaw_notify (G_OBJECT (entry));
8048 * gtk_entry_set_icon_activatable:
8049 * @entry: A #GtkEntry
8050 * @icon_pos: Icon position
8051 * @activatable: %TRUE if the icon should be activatable
8053 * Sets whether the icon is activatable.
8058 gtk_entry_set_icon_activatable (GtkEntry *entry,
8059 GtkEntryIconPosition icon_pos,
8060 gboolean activatable)
8062 GtkEntryPrivate *priv;
8063 EntryIconInfo *icon_info;
8065 g_return_if_fail (GTK_IS_ENTRY (entry));
8066 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8070 if ((icon_info = priv->icons[icon_pos]) == NULL)
8071 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8073 activatable = activatable != FALSE;
8075 if (icon_info->nonactivatable != !activatable)
8077 icon_info->nonactivatable = !activatable;
8079 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8080 update_cursors (GTK_WIDGET (entry));
8082 g_object_notify (G_OBJECT (entry),
8083 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8088 * gtk_entry_get_icon_activatable:
8089 * @entry: a #GtkEntry
8090 * @icon_pos: Icon position
8092 * Returns whether the icon is activatable.
8094 * Returns: %TRUE if the icon is activatable.
8099 gtk_entry_get_icon_activatable (GtkEntry *entry,
8100 GtkEntryIconPosition icon_pos)
8102 GtkEntryPrivate *priv;
8103 EntryIconInfo *icon_info;
8105 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8106 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8109 icon_info = priv->icons[icon_pos];
8111 return (!icon_info || !icon_info->nonactivatable);
8115 * gtk_entry_get_icon_pixbuf:
8116 * @entry: A #GtkEntry
8117 * @icon_pos: Icon position
8119 * Retrieves the image used for the icon.
8121 * Unlike the other methods of setting and getting icon data, this
8122 * method will work regardless of whether the icon was set using a
8123 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8125 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8126 * set for this position.
8131 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8132 GtkEntryIconPosition icon_pos)
8134 GtkEntryPrivate *priv;
8135 EntryIconInfo *icon_info;
8137 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8138 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8142 icon_info = priv->icons[icon_pos];
8147 gtk_entry_ensure_pixbuf (entry, icon_pos);
8149 return icon_info->pixbuf;
8153 * gtk_entry_get_icon_gicon:
8154 * @entry: A #GtkEntry
8155 * @icon_pos: Icon position
8157 * Retrieves the #GIcon used for the icon, or %NULL if there is
8158 * no icon or if the icon was set by some other method (e.g., by
8159 * stock, pixbuf, or icon name).
8161 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8162 * or if the icon is not a #GIcon
8167 gtk_entry_get_icon_gicon (GtkEntry *entry,
8168 GtkEntryIconPosition icon_pos)
8170 GtkEntryPrivate *priv;
8171 EntryIconInfo *icon_info;
8173 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8174 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8177 icon_info = priv->icons[icon_pos];
8182 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8186 * gtk_entry_get_icon_stock:
8187 * @entry: A #GtkEntry
8188 * @icon_pos: Icon position
8190 * Retrieves the stock id used for the icon, or %NULL if there is
8191 * no icon or if the icon was set by some other method (e.g., by
8192 * pixbuf, icon name or gicon).
8194 * Returns: A stock id, or %NULL if no icon is set or if the icon
8195 * wasn't set from a stock id
8200 gtk_entry_get_icon_stock (GtkEntry *entry,
8201 GtkEntryIconPosition icon_pos)
8203 GtkEntryPrivate *priv;
8204 EntryIconInfo *icon_info;
8206 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8207 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8210 icon_info = priv->icons[icon_pos];
8215 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8219 * gtk_entry_get_icon_name:
8220 * @entry: A #GtkEntry
8221 * @icon_pos: Icon position
8223 * Retrieves the icon name used for the icon, or %NULL if there is
8224 * no icon or if the icon was set by some other method (e.g., by
8225 * pixbuf, stock or gicon).
8227 * Returns: An icon name, or %NULL if no icon is set or if the icon
8228 * wasn't set from an icon name
8233 gtk_entry_get_icon_name (GtkEntry *entry,
8234 GtkEntryIconPosition icon_pos)
8236 GtkEntryPrivate *priv;
8237 EntryIconInfo *icon_info;
8239 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8240 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8243 icon_info = priv->icons[icon_pos];
8248 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8252 * gtk_entry_set_icon_sensitive:
8253 * @entry: A #GtkEntry
8254 * @icon_pos: Icon position
8255 * @sensitive: Specifies whether the icon should appear
8256 * sensitive or insensitive
8258 * Sets the sensitivity for the specified icon.
8263 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8264 GtkEntryIconPosition icon_pos,
8267 GtkEntryPrivate *priv;
8268 EntryIconInfo *icon_info;
8270 g_return_if_fail (GTK_IS_ENTRY (entry));
8271 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8275 if ((icon_info = priv->icons[icon_pos]) == NULL)
8276 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8278 if (icon_info->insensitive != !sensitive)
8280 icon_info->insensitive = !sensitive;
8282 icon_info->pressed = FALSE;
8283 icon_info->prelight = FALSE;
8285 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8286 update_cursors (GTK_WIDGET (entry));
8288 gtk_widget_queue_draw (GTK_WIDGET (entry));
8290 g_object_notify (G_OBJECT (entry),
8291 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8296 * gtk_entry_get_icon_sensitive:
8297 * @entry: a #GtkEntry
8298 * @icon_pos: Icon position
8300 * Returns whether the icon appears sensitive or insensitive.
8302 * Returns: %TRUE if the icon is sensitive.
8307 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8308 GtkEntryIconPosition icon_pos)
8310 GtkEntryPrivate *priv;
8311 EntryIconInfo *icon_info;
8313 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8314 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8318 icon_info = priv->icons[icon_pos];
8320 return (!icon_info || !icon_info->insensitive);
8325 * gtk_entry_get_icon_storage_type:
8326 * @entry: a #GtkEntry
8327 * @icon_pos: Icon position
8329 * Gets the type of representation being used by the icon
8330 * to store image data. If the icon has no image data,
8331 * the return value will be %GTK_IMAGE_EMPTY.
8333 * Return value: image representation being used
8338 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8339 GtkEntryIconPosition icon_pos)
8341 GtkEntryPrivate *priv;
8342 EntryIconInfo *icon_info;
8344 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8345 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8349 icon_info = priv->icons[icon_pos];
8352 return GTK_IMAGE_EMPTY;
8354 return icon_info->storage_type;
8358 * gtk_entry_get_icon_at_pos:
8359 * @entry: a #GtkEntry
8360 * @x: the x coordinate of the position to find
8361 * @y: the y coordinate of the position to find
8363 * Finds the icon at the given position and return its index. The
8364 * position's coordinates are relative to the @entry's top left corner.
8365 * If @x, @y doesn't lie inside an icon, -1 is returned.
8366 * This function is intended for use in a #GtkWidget::query-tooltip
8369 * Returns: the index of the icon at the given position, or -1
8374 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8378 GtkAllocation primary;
8379 GtkAllocation secondary;
8380 gint frame_x, frame_y;
8382 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8384 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8388 get_icon_allocations (entry, &primary, &secondary);
8390 if (primary.x <= x && x < primary.x + primary.width &&
8391 primary.y <= y && y < primary.y + primary.height)
8392 return GTK_ENTRY_ICON_PRIMARY;
8394 if (secondary.x <= x && x < secondary.x + secondary.width &&
8395 secondary.y <= y && y < secondary.y + secondary.height)
8396 return GTK_ENTRY_ICON_SECONDARY;
8402 * gtk_entry_set_icon_drag_source:
8403 * @entry: a #GtkIconEntry
8404 * @icon_pos: icon position
8405 * @target_list: the targets (data formats) in which the data can be provided
8406 * @actions: a bitmask of the allowed drag actions
8408 * Sets up the icon at the given position so that GTK+ will start a drag
8409 * operation when the user clicks and drags the icon.
8411 * To handle the drag operation, you need to connect to the usual
8412 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8413 * signal, and use gtk_entry_get_current_icon_drag_source() in
8414 * your signal handler to find out if the drag was started from
8417 * By default, GTK+ uses the icon as the drag icon. You can use the
8418 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8419 * have to use g_signal_connect_after() to ensure that your signal handler
8420 * gets executed after the default handler.
8425 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8426 GtkEntryIconPosition icon_pos,
8427 GtkTargetList *target_list,
8428 GdkDragAction actions)
8430 GtkEntryPrivate *priv;
8431 EntryIconInfo *icon_info;
8433 g_return_if_fail (GTK_IS_ENTRY (entry));
8434 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8438 if ((icon_info = priv->icons[icon_pos]) == NULL)
8439 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8441 if (icon_info->target_list)
8442 gtk_target_list_unref (icon_info->target_list);
8443 icon_info->target_list = target_list;
8444 if (icon_info->target_list)
8445 gtk_target_list_ref (icon_info->target_list);
8447 icon_info->actions = actions;
8451 * gtk_entry_get_current_icon_drag_source:
8452 * @entry: a #GtkIconEntry
8454 * Returns the index of the icon which is the source of the current
8455 * DND operation, or -1.
8457 * This function is meant to be used in a #GtkWidget::drag-data-get
8460 * Returns: index of the icon which is the source of the current
8461 * DND operation, or -1.
8466 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8468 GtkEntryPrivate *priv;
8469 EntryIconInfo *icon_info = NULL;
8472 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8476 for (i = 0; i < MAX_ICONS; i++)
8478 if ((icon_info = priv->icons[i]))
8480 if (icon_info->in_drag)
8489 * gtk_entry_get_icon_area:
8490 * @entry: A #GtkEntry
8491 * @icon_pos: Icon position
8492 * @icon_area: (out): Return location for the icon's area
8494 * Gets the area where entry's icon at @icon_pos is drawn.
8495 * This function is useful when drawing something to the
8496 * entry in a draw callback.
8498 * If the entry is not realized or has no icon at the given position,
8499 * @icon_area is filled with zeros.
8501 * See also gtk_entry_get_text_area()
8506 gtk_entry_get_icon_area (GtkEntry *entry,
8507 GtkEntryIconPosition icon_pos,
8508 GdkRectangle *icon_area)
8510 GtkEntryPrivate *priv;
8511 EntryIconInfo *icon_info;
8513 g_return_if_fail (GTK_IS_ENTRY (entry));
8514 g_return_if_fail (icon_area != NULL);
8518 icon_info = priv->icons[icon_pos];
8522 GtkAllocation primary;
8523 GtkAllocation secondary;
8525 get_icon_allocations (entry, &primary, &secondary);
8527 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8528 *icon_area = primary;
8530 *icon_area = secondary;
8536 icon_area->width = 0;
8537 icon_area->height = 0;
8542 ensure_has_tooltip (GtkEntry *entry)
8544 GtkEntryPrivate *priv;
8545 EntryIconInfo *icon_info;
8547 gboolean has_tooltip = FALSE;
8551 for (i = 0; i < MAX_ICONS; i++)
8553 if ((icon_info = priv->icons[i]) != NULL)
8555 if (icon_info->tooltip != NULL)
8563 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8567 * gtk_entry_get_icon_tooltip_text:
8568 * @entry: a #GtkEntry
8569 * @icon_pos: the icon position
8571 * Gets the contents of the tooltip on the icon at the specified
8572 * position in @entry.
8574 * Returns: the tooltip text, or %NULL. Free the returned string
8575 * with g_free() when done.
8580 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8581 GtkEntryIconPosition icon_pos)
8583 GtkEntryPrivate *priv;
8584 EntryIconInfo *icon_info;
8587 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8588 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8592 icon_info = priv->icons[icon_pos];
8597 if (icon_info->tooltip &&
8598 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8599 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8605 * gtk_entry_set_icon_tooltip_text:
8606 * @entry: a #GtkEntry
8607 * @icon_pos: the icon position
8608 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8610 * Sets @tooltip as the contents of the tooltip for the icon
8611 * at the specified position.
8613 * Use %NULL for @tooltip to remove an existing tooltip.
8615 * See also gtk_widget_set_tooltip_text() and
8616 * gtk_entry_set_icon_tooltip_markup().
8621 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8622 GtkEntryIconPosition icon_pos,
8623 const gchar *tooltip)
8625 GtkEntryPrivate *priv;
8626 EntryIconInfo *icon_info;
8628 g_return_if_fail (GTK_IS_ENTRY (entry));
8629 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8633 if ((icon_info = priv->icons[icon_pos]) == NULL)
8634 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8636 if (icon_info->tooltip)
8637 g_free (icon_info->tooltip);
8639 /* Treat an empty string as a NULL string,
8640 * because an empty string would be useless for a tooltip:
8642 if (tooltip && tooltip[0] == '\0')
8645 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8647 ensure_has_tooltip (entry);
8651 * gtk_entry_get_icon_tooltip_markup:
8652 * @entry: a #GtkEntry
8653 * @icon_pos: the icon position
8655 * Gets the contents of the tooltip on the icon at the specified
8656 * position in @entry.
8658 * Returns: the tooltip text, or %NULL. Free the returned string
8659 * with g_free() when done.
8664 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8665 GtkEntryIconPosition icon_pos)
8667 GtkEntryPrivate *priv;
8668 EntryIconInfo *icon_info;
8670 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8671 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8675 icon_info = priv->icons[icon_pos];
8680 return g_strdup (icon_info->tooltip);
8684 * gtk_entry_set_icon_tooltip_markup:
8685 * @entry: a #GtkEntry
8686 * @icon_pos: the icon position
8687 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8689 * Sets @tooltip as the contents of the tooltip for the icon at
8690 * the specified position. @tooltip is assumed to be marked up with
8691 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8693 * Use %NULL for @tooltip to remove an existing tooltip.
8695 * See also gtk_widget_set_tooltip_markup() and
8696 * gtk_enty_set_icon_tooltip_text().
8701 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8702 GtkEntryIconPosition icon_pos,
8703 const gchar *tooltip)
8705 GtkEntryPrivate *priv;
8706 EntryIconInfo *icon_info;
8708 g_return_if_fail (GTK_IS_ENTRY (entry));
8709 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8713 if ((icon_info = priv->icons[icon_pos]) == NULL)
8714 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8716 if (icon_info->tooltip)
8717 g_free (icon_info->tooltip);
8719 /* Treat an empty string as a NULL string,
8720 * because an empty string would be useless for a tooltip:
8722 if (tooltip && tooltip[0] == '\0')
8725 icon_info->tooltip = g_strdup (tooltip);
8727 ensure_has_tooltip (entry);
8731 gtk_entry_query_tooltip (GtkWidget *widget,
8734 gboolean keyboard_tip,
8735 GtkTooltip *tooltip)
8738 GtkEntryPrivate *priv;
8739 EntryIconInfo *icon_info;
8742 entry = GTK_ENTRY (widget);
8747 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8750 if ((icon_info = priv->icons[icon_pos]) != NULL)
8752 if (icon_info->tooltip)
8754 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8763 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8770 /* Quick hack of a popup menu
8773 activate_cb (GtkWidget *menuitem,
8776 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8777 g_signal_emit_by_name (entry, signal);
8782 gtk_entry_mnemonic_activate (GtkWidget *widget,
8783 gboolean group_cycling)
8785 gtk_widget_grab_focus (widget);
8790 append_action_signal (GtkEntry *entry,
8792 const gchar *stock_id,
8793 const gchar *signal,
8796 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8798 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8799 g_signal_connect (menuitem, "activate",
8800 G_CALLBACK (activate_cb), entry);
8802 gtk_widget_set_sensitive (menuitem, sensitive);
8804 gtk_widget_show (menuitem);
8805 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8809 popup_menu_detach (GtkWidget *attach_widget,
8812 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8813 GtkEntryPrivate *priv_attach = entry_attach->priv;
8815 priv_attach->popup_menu = NULL;
8819 popup_position_func (GtkMenu *menu,
8825 GtkEntry *entry = GTK_ENTRY (user_data);
8826 GtkEntryPrivate *priv = entry->priv;
8827 GtkWidget *widget = GTK_WIDGET (entry);
8829 GtkRequisition menu_req;
8830 GdkRectangle monitor;
8831 GtkBorder inner_border;
8832 gint monitor_num, strong_x, height;
8834 g_return_if_fail (gtk_widget_get_realized (widget));
8836 gdk_window_get_origin (priv->text_area, x, y);
8838 screen = gtk_widget_get_screen (widget);
8839 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8840 if (monitor_num < 0)
8842 gtk_menu_set_monitor (menu, monitor_num);
8844 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8845 gtk_widget_get_preferred_size (priv->popup_menu,
8847 height = gdk_window_get_height (priv->text_area);
8848 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8849 _gtk_entry_effective_inner_border (entry, &inner_border);
8851 *x += inner_border.left + strong_x - priv->scroll_offset;
8852 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8853 *x -= menu_req.width;
8855 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8857 else if ((*y - menu_req.height) >= monitor.y)
8858 *y -= menu_req.height;
8859 else if (monitor.y + monitor.height - (*y + height) > *y)
8862 *y -= menu_req.height;
8868 unichar_chosen_func (const char *text,
8871 GtkEntry *entry = GTK_ENTRY (data);
8872 GtkEntryPrivate *priv = entry->priv;
8875 gtk_entry_enter_text (entry, text);
8886 popup_targets_received (GtkClipboard *clipboard,
8887 GtkSelectionData *data,
8890 PopupInfo *info = user_data;
8891 GtkEntry *entry = info->entry;
8892 GtkEntryPrivate *info_entry_priv = entry->priv;
8894 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8897 gboolean clipboard_contains_text;
8898 GtkWidget *menuitem;
8900 gboolean show_input_method_menu;
8901 gboolean show_unicode_menu;
8903 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8904 if (info_entry_priv->popup_menu)
8905 gtk_widget_destroy (info_entry_priv->popup_menu);
8907 info_entry_priv->popup_menu = gtk_menu_new ();
8909 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8913 mode = gtk_entry_get_display_mode (entry);
8914 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8915 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8916 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8918 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8919 mode == DISPLAY_NORMAL &&
8920 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8922 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8923 info_entry_priv->editable && clipboard_contains_text);
8925 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8926 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8927 g_signal_connect_swapped (menuitem, "activate",
8928 G_CALLBACK (gtk_entry_delete_cb), entry);
8929 gtk_widget_show (menuitem);
8930 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8932 menuitem = gtk_separator_menu_item_new ();
8933 gtk_widget_show (menuitem);
8934 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8936 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8937 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8938 g_signal_connect_swapped (menuitem, "activate",
8939 G_CALLBACK (gtk_entry_select_all), entry);
8940 gtk_widget_show (menuitem);
8941 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8943 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8944 "gtk-show-input-method-menu", &show_input_method_menu,
8945 "gtk-show-unicode-menu", &show_unicode_menu,
8948 if (show_input_method_menu || show_unicode_menu)
8950 menuitem = gtk_separator_menu_item_new ();
8951 gtk_widget_show (menuitem);
8952 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8955 if (show_input_method_menu)
8957 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8958 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8959 gtk_widget_show (menuitem);
8960 submenu = gtk_menu_new ();
8961 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8963 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8965 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8966 GTK_MENU_SHELL (submenu));
8969 if (show_unicode_menu)
8971 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8972 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8973 gtk_widget_show (menuitem);
8975 submenu = gtk_menu_new ();
8976 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8977 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8979 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8980 unichar_chosen_func,
8984 g_signal_emit (entry,
8985 signals[POPULATE_POPUP],
8987 info_entry_priv->popup_menu);
8991 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8993 info->button, info->time);
8996 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8997 popup_position_func, entry,
8998 info->button, info->time);
8999 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9003 g_object_unref (entry);
9004 g_slice_free (PopupInfo, info);
9008 gtk_entry_do_popup (GtkEntry *entry,
9009 GdkEventButton *event)
9011 PopupInfo *info = g_slice_new (PopupInfo);
9013 /* In order to know what entries we should make sensitive, we
9014 * ask for the current targets of the clipboard, and when
9015 * we get them, then we actually pop up the menu.
9017 info->entry = g_object_ref (entry);
9021 info->button = event->button;
9022 info->time = event->time;
9027 info->time = gtk_get_current_event_time ();
9030 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9031 gdk_atom_intern_static_string ("TARGETS"),
9032 popup_targets_received,
9037 gtk_entry_popup_menu (GtkWidget *widget)
9039 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9044 gtk_entry_drag_begin (GtkWidget *widget,
9045 GdkDragContext *context)
9047 GtkEntry *entry = GTK_ENTRY (widget);
9048 GtkEntryPrivate *priv = entry->priv;
9051 for (i = 0; i < MAX_ICONS; i++)
9053 EntryIconInfo *icon_info = priv->icons[i];
9055 if (icon_info != NULL)
9057 if (icon_info->in_drag)
9059 switch (icon_info->storage_type)
9061 case GTK_IMAGE_STOCK:
9062 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
9065 case GTK_IMAGE_ICON_NAME:
9066 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
9069 /* FIXME: No GIcon support for dnd icons */
9070 case GTK_IMAGE_GICON:
9071 case GTK_IMAGE_PIXBUF:
9072 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
9075 g_assert_not_reached ();
9083 gtk_entry_drag_end (GtkWidget *widget,
9084 GdkDragContext *context)
9086 GtkEntry *entry = GTK_ENTRY (widget);
9087 GtkEntryPrivate *priv = entry->priv;
9090 for (i = 0; i < MAX_ICONS; i++)
9092 EntryIconInfo *icon_info = priv->icons[i];
9094 if (icon_info != NULL)
9095 icon_info->in_drag = 0;
9100 gtk_entry_drag_leave (GtkWidget *widget,
9101 GdkDragContext *context,
9104 GtkEntry *entry = GTK_ENTRY (widget);
9105 GtkEntryPrivate *priv = entry->priv;
9107 priv->dnd_position = -1;
9108 gtk_widget_queue_draw (widget);
9112 gtk_entry_drag_drop (GtkWidget *widget,
9113 GdkDragContext *context,
9118 GtkEntry *entry = GTK_ENTRY (widget);
9119 GtkEntryPrivate *priv = entry->priv;
9120 GdkAtom target = GDK_NONE;
9123 target = gtk_drag_dest_find_target (widget, context, NULL);
9125 if (target != GDK_NONE)
9126 gtk_drag_get_data (widget, context, target, time);
9128 gtk_drag_finish (context, FALSE, FALSE, time);
9134 gtk_entry_drag_motion (GtkWidget *widget,
9135 GdkDragContext *context,
9140 GtkEntry *entry = GTK_ENTRY (widget);
9141 GtkEntryPrivate *priv = entry->priv;
9142 GtkStyleContext *style_context;
9143 GtkWidget *source_widget;
9144 GdkDragAction suggested_action;
9145 gint new_position, old_position;
9149 style_context = gtk_widget_get_style_context (widget);
9150 gtk_style_context_get_padding (style_context, 0, &padding);
9154 old_position = priv->dnd_position;
9155 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9157 if (priv->editable &&
9158 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9160 source_widget = gtk_drag_get_source_widget (context);
9161 suggested_action = gdk_drag_context_get_suggested_action (context);
9163 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9164 new_position < sel1 || new_position > sel2)
9166 if (source_widget == widget)
9168 /* Default to MOVE, unless the user has
9169 * pressed ctrl or alt to affect available actions
9171 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9172 suggested_action = GDK_ACTION_MOVE;
9175 priv->dnd_position = new_position;
9179 if (source_widget == widget)
9180 suggested_action = 0; /* Can't drop in selection where drag started */
9182 priv->dnd_position = -1;
9187 /* Entry not editable, or no text */
9188 suggested_action = 0;
9189 priv->dnd_position = -1;
9192 gdk_drag_status (context, suggested_action, time);
9194 if (priv->dnd_position != old_position)
9195 gtk_widget_queue_draw (widget);
9201 gtk_entry_drag_data_received (GtkWidget *widget,
9202 GdkDragContext *context,
9205 GtkSelectionData *selection_data,
9209 GtkEntry *entry = GTK_ENTRY (widget);
9210 GtkEntryPrivate *priv = entry->priv;
9211 GtkEditable *editable = GTK_EDITABLE (widget);
9212 GtkStyleContext *style_context;
9216 str = (gchar *) gtk_selection_data_get_text (selection_data);
9218 style_context = gtk_widget_get_style_context (widget);
9219 gtk_style_context_get_padding (style_context, 0, &padding);
9223 if (str && priv->editable)
9229 if (priv->truncate_multiline)
9230 length = truncate_multiline (str);
9232 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9234 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9235 new_position < sel1 || new_position > sel2)
9237 gtk_editable_insert_text (editable, str, length, &new_position);
9241 /* Replacing selection */
9242 begin_change (entry);
9243 g_object_freeze_notify (G_OBJECT (entry));
9244 gtk_editable_delete_text (editable, sel1, sel2);
9245 gtk_editable_insert_text (editable, str, length, &sel1);
9246 g_object_thaw_notify (G_OBJECT (entry));
9250 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9254 /* Drag and drop didn't happen! */
9255 gtk_drag_finish (context, FALSE, FALSE, time);
9262 gtk_entry_drag_data_get (GtkWidget *widget,
9263 GdkDragContext *context,
9264 GtkSelectionData *selection_data,
9268 GtkEntry *entry = GTK_ENTRY (widget);
9269 GtkEntryPrivate *priv = entry->priv;
9270 GtkEditable *editable = GTK_EDITABLE (widget);
9271 gint sel_start, sel_end;
9274 /* If there is an icon drag going on, exit early. */
9275 for (i = 0; i < MAX_ICONS; i++)
9277 EntryIconInfo *icon_info = priv->icons[i];
9279 if (icon_info != NULL)
9281 if (icon_info->in_drag)
9286 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9288 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9290 gtk_selection_data_set_text (selection_data, str, -1);
9298 gtk_entry_drag_data_delete (GtkWidget *widget,
9299 GdkDragContext *context)
9301 GtkEntry *entry = GTK_ENTRY (widget);
9302 GtkEntryPrivate *priv = entry->priv;
9303 GtkEditable *editable = GTK_EDITABLE (widget);
9304 gint sel_start, sel_end;
9307 /* If there is an icon drag going on, exit early. */
9308 for (i = 0; i < MAX_ICONS; i++)
9310 EntryIconInfo *icon_info = priv->icons[i];
9312 if (icon_info != NULL)
9314 if (icon_info->in_drag)
9319 if (priv->editable &&
9320 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9321 gtk_editable_delete_text (editable, sel_start, sel_end);
9324 /* We display the cursor when
9326 * - the selection is empty, AND
9327 * - the widget has focus
9330 #define CURSOR_ON_MULTIPLIER 2
9331 #define CURSOR_OFF_MULTIPLIER 1
9332 #define CURSOR_PEND_MULTIPLIER 3
9333 #define CURSOR_DIVIDER 3
9336 cursor_blinks (GtkEntry *entry)
9338 GtkEntryPrivate *priv = entry->priv;
9340 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9342 priv->selection_bound == priv->current_pos)
9344 GtkSettings *settings;
9347 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9348 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9357 get_cursor_time (GtkEntry *entry)
9359 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9362 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9368 get_cursor_blink_timeout (GtkEntry *entry)
9370 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9373 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9379 show_cursor (GtkEntry *entry)
9381 GtkEntryPrivate *priv = entry->priv;
9384 if (!priv->cursor_visible)
9386 priv->cursor_visible = TRUE;
9388 widget = GTK_WIDGET (entry);
9389 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9390 gtk_widget_queue_draw (widget);
9395 hide_cursor (GtkEntry *entry)
9397 GtkEntryPrivate *priv = entry->priv;
9400 if (priv->cursor_visible)
9402 priv->cursor_visible = FALSE;
9404 widget = GTK_WIDGET (entry);
9405 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9406 gtk_widget_queue_draw (widget);
9414 blink_cb (gpointer data)
9417 GtkEntryPrivate *priv;
9420 entry = GTK_ENTRY (data);
9423 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9425 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9426 "connect a handler to this signal, it must return\n"
9427 "FALSE so the entry gets the event as well");
9429 gtk_entry_check_cursor_blink (entry);
9434 g_assert (priv->selection_bound == priv->current_pos);
9436 blink_timeout = get_cursor_blink_timeout (entry);
9437 if (priv->blink_time > 1000 * blink_timeout &&
9438 blink_timeout < G_MAXINT/1000)
9440 /* we've blinked enough without the user doing anything, stop blinking */
9441 show_cursor (entry);
9442 priv->blink_timeout = 0;
9444 else if (priv->cursor_visible)
9446 hide_cursor (entry);
9447 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9453 show_cursor (entry);
9454 priv->blink_time += get_cursor_time (entry);
9455 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9460 /* Remove ourselves */
9465 gtk_entry_check_cursor_blink (GtkEntry *entry)
9467 GtkEntryPrivate *priv = entry->priv;
9469 if (cursor_blinks (entry))
9471 if (!priv->blink_timeout)
9473 show_cursor (entry);
9474 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9481 if (priv->blink_timeout)
9483 g_source_remove (priv->blink_timeout);
9484 priv->blink_timeout = 0;
9487 priv->cursor_visible = TRUE;
9492 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9494 GtkEntryPrivate *priv = entry->priv;
9496 if (cursor_blinks (entry))
9498 if (priv->blink_timeout != 0)
9499 g_source_remove (priv->blink_timeout);
9501 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9504 show_cursor (entry);
9509 gtk_entry_reset_blink_time (GtkEntry *entry)
9511 GtkEntryPrivate *priv = entry->priv;
9513 priv->blink_time = 0;
9519 gtk_entry_completion_timeout (gpointer data)
9521 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9522 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9524 completion->priv->completion_timeout = 0;
9526 if (completion->priv->filter_model &&
9527 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9528 >= completion->priv->minimum_key_length)
9532 GtkTreeSelection *s;
9533 gboolean popup_single;
9535 gtk_entry_completion_complete (completion);
9536 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9538 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9540 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9542 gtk_tree_selection_unselect_all (s);
9544 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9546 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9547 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9549 if (gtk_widget_get_visible (completion->priv->popup_window))
9550 _gtk_entry_completion_resize_popup (completion);
9552 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9555 _gtk_entry_completion_popdown (completion);
9557 else if (gtk_widget_get_visible (completion->priv->popup_window))
9558 _gtk_entry_completion_popdown (completion);
9563 static inline gboolean
9564 keyval_is_cursor_move (guint keyval)
9566 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9569 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9572 if (keyval == GDK_KEY_Page_Up)
9575 if (keyval == GDK_KEY_Page_Down)
9582 gtk_entry_completion_key_press (GtkWidget *widget,
9586 gint matches, actions = 0;
9587 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9589 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9592 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9594 if (completion->priv->actions)
9595 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9597 if (keyval_is_cursor_move (event->keyval))
9599 GtkTreePath *path = NULL;
9601 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9603 if (completion->priv->current_selected < 0)
9604 completion->priv->current_selected = matches + actions - 1;
9606 completion->priv->current_selected--;
9608 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9610 if (completion->priv->current_selected < matches + actions - 1)
9611 completion->priv->current_selected++;
9613 completion->priv->current_selected = -1;
9615 else if (event->keyval == GDK_KEY_Page_Up)
9617 if (completion->priv->current_selected < 0)
9618 completion->priv->current_selected = matches + actions - 1;
9619 else if (completion->priv->current_selected == 0)
9620 completion->priv->current_selected = -1;
9621 else if (completion->priv->current_selected < matches)
9623 completion->priv->current_selected -= PAGE_STEP;
9624 if (completion->priv->current_selected < 0)
9625 completion->priv->current_selected = 0;
9629 completion->priv->current_selected -= PAGE_STEP;
9630 if (completion->priv->current_selected < matches - 1)
9631 completion->priv->current_selected = matches - 1;
9634 else if (event->keyval == GDK_KEY_Page_Down)
9636 if (completion->priv->current_selected < 0)
9637 completion->priv->current_selected = 0;
9638 else if (completion->priv->current_selected < matches - 1)
9640 completion->priv->current_selected += PAGE_STEP;
9641 if (completion->priv->current_selected > matches - 1)
9642 completion->priv->current_selected = matches - 1;
9644 else if (completion->priv->current_selected == matches + actions - 1)
9646 completion->priv->current_selected = -1;
9650 completion->priv->current_selected += PAGE_STEP;
9651 if (completion->priv->current_selected > matches + actions - 1)
9652 completion->priv->current_selected = matches + actions - 1;
9656 if (completion->priv->current_selected < 0)
9658 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9659 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9661 if (completion->priv->inline_selection &&
9662 completion->priv->completion_prefix)
9664 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9665 completion->priv->completion_prefix);
9666 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9669 else if (completion->priv->current_selected < matches)
9671 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9673 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9674 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9677 if (completion->priv->inline_selection)
9681 GtkTreeIter child_iter;
9682 GtkTreeModel *model = NULL;
9683 GtkTreeSelection *sel;
9686 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9687 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9690 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9691 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9693 if (completion->priv->completion_prefix == NULL)
9694 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9696 g_signal_emit_by_name (completion, "cursor-on-match", model,
9697 &child_iter, &entry_set);
9700 else if (completion->priv->current_selected - matches >= 0)
9702 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9704 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9705 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9708 if (completion->priv->inline_selection &&
9709 completion->priv->completion_prefix)
9711 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9712 completion->priv->completion_prefix);
9713 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9717 gtk_tree_path_free (path);
9721 else if (event->keyval == GDK_KEY_Escape ||
9722 event->keyval == GDK_KEY_Left ||
9723 event->keyval == GDK_KEY_KP_Left ||
9724 event->keyval == GDK_KEY_Right ||
9725 event->keyval == GDK_KEY_KP_Right)
9727 gboolean retval = TRUE;
9729 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9730 _gtk_entry_completion_popdown (completion);
9732 if (completion->priv->current_selected < 0)
9735 goto keypress_completion_out;
9737 else if (completion->priv->inline_selection)
9739 /* Escape rejects the tentative completion */
9740 if (event->keyval == GDK_KEY_Escape)
9742 if (completion->priv->completion_prefix)
9743 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9744 completion->priv->completion_prefix);
9746 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9749 /* Move the cursor to the end for Right/Esc, to the
9750 beginning for Left */
9751 if (event->keyval == GDK_KEY_Right ||
9752 event->keyval == GDK_KEY_KP_Right ||
9753 event->keyval == GDK_KEY_Escape)
9754 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9756 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9759 keypress_completion_out:
9760 if (completion->priv->inline_selection)
9762 g_free (completion->priv->completion_prefix);
9763 completion->priv->completion_prefix = NULL;
9768 else if (event->keyval == GDK_KEY_Tab ||
9769 event->keyval == GDK_KEY_KP_Tab ||
9770 event->keyval == GDK_KEY_ISO_Left_Tab)
9772 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9773 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9775 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9776 _gtk_entry_completion_popdown (completion);
9778 g_free (completion->priv->completion_prefix);
9779 completion->priv->completion_prefix = NULL;
9781 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9785 else if (event->keyval == GDK_KEY_ISO_Enter ||
9786 event->keyval == GDK_KEY_KP_Enter ||
9787 event->keyval == GDK_KEY_Return)
9790 GtkTreeModel *model = NULL;
9791 GtkTreeModel *child_model;
9792 GtkTreeIter child_iter;
9793 GtkTreeSelection *sel;
9794 gboolean retval = TRUE;
9796 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9797 _gtk_entry_completion_popdown (completion);
9799 if (completion->priv->current_selected < matches)
9803 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9804 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9806 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9807 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9808 g_signal_handler_block (widget, completion->priv->changed_id);
9809 g_signal_emit_by_name (completion, "match-selected",
9810 child_model, &child_iter, &entry_set);
9811 g_signal_handler_unblock (widget, completion->priv->changed_id);
9817 gtk_tree_model_get (model, &iter,
9818 completion->priv->text_column, &str,
9821 gtk_entry_set_text (GTK_ENTRY (widget), str);
9823 /* move the cursor to the end */
9824 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9832 else if (completion->priv->current_selected - matches >= 0)
9834 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9835 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9839 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9840 g_signal_emit_by_name (completion, "action-activated",
9841 gtk_tree_path_get_indices (path)[0]);
9842 gtk_tree_path_free (path);
9848 g_free (completion->priv->completion_prefix);
9849 completion->priv->completion_prefix = NULL;
9858 gtk_entry_completion_changed (GtkWidget *widget,
9861 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9862 GtkEntry *entry = GTK_ENTRY (widget);
9863 GtkEntryPrivate *priv = entry->priv;
9866 /* (re)install completion timeout */
9867 if (completion->priv->completion_timeout)
9868 g_source_remove (completion->priv->completion_timeout);
9870 if (!gtk_entry_get_text (entry))
9873 /* no need to normalize for this test */
9874 if (completion->priv->minimum_key_length > 0 &&
9875 strcmp ("", gtk_entry_get_text (entry)) == 0)
9877 if (gtk_widget_get_visible (completion->priv->popup_window))
9878 _gtk_entry_completion_popdown (completion);
9882 device = gtk_get_current_event_device ();
9884 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9885 device = gdk_device_get_associated_device (device);
9888 priv->completion_device = device;
9890 completion->priv->completion_timeout =
9891 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9892 gtk_entry_completion_timeout,
9897 check_completion_callback (GtkEntryCompletion *completion)
9899 completion->priv->check_completion_idle = NULL;
9901 gtk_entry_completion_complete (completion);
9902 gtk_entry_completion_insert_prefix (completion);
9908 clear_completion_callback (GtkEntry *entry,
9911 if (pspec->name == I_("cursor-position") ||
9912 pspec->name == I_("selection-bound"))
9914 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9916 completion->priv->has_completion = FALSE;
9921 accept_completion_callback (GtkEntry *entry)
9923 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9925 if (completion->priv->has_completion)
9926 gtk_editable_set_position (GTK_EDITABLE (entry),
9927 gtk_entry_buffer_get_length (get_buffer (entry)));
9933 completion_insert_text_callback (GtkEntry *entry,
9937 GtkEntryCompletion *completion)
9939 /* idle to update the selection based on the file list */
9940 if (completion->priv->check_completion_idle == NULL)
9942 completion->priv->check_completion_idle = g_idle_source_new ();
9943 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9944 g_source_set_closure (completion->priv->check_completion_idle,
9945 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9946 G_OBJECT (completion)));
9947 g_source_attach (completion->priv->check_completion_idle, NULL);
9952 completion_changed (GtkEntryCompletion *completion,
9956 GtkEntry *entry = GTK_ENTRY (data);
9958 if (pspec->name == I_("popup-completion") ||
9959 pspec->name == I_("inline-completion"))
9961 disconnect_completion_signals (entry, completion);
9962 connect_completion_signals (entry, completion);
9967 disconnect_completion_signals (GtkEntry *entry,
9968 GtkEntryCompletion *completion)
9970 g_signal_handlers_disconnect_by_func (completion,
9971 G_CALLBACK (completion_changed), entry);
9972 if (completion->priv->changed_id > 0 &&
9973 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9975 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9976 completion->priv->changed_id = 0;
9978 g_signal_handlers_disconnect_by_func (entry,
9979 G_CALLBACK (gtk_entry_completion_key_press), completion);
9980 if (completion->priv->insert_text_id > 0 &&
9981 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9983 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9984 completion->priv->insert_text_id = 0;
9986 g_signal_handlers_disconnect_by_func (entry,
9987 G_CALLBACK (completion_insert_text_callback), completion);
9988 g_signal_handlers_disconnect_by_func (entry,
9989 G_CALLBACK (clear_completion_callback), completion);
9990 g_signal_handlers_disconnect_by_func (entry,
9991 G_CALLBACK (accept_completion_callback), completion);
9995 connect_completion_signals (GtkEntry *entry,
9996 GtkEntryCompletion *completion)
9998 if (completion->priv->popup_completion)
10000 completion->priv->changed_id =
10001 g_signal_connect (entry, "changed",
10002 G_CALLBACK (gtk_entry_completion_changed), completion);
10003 g_signal_connect (entry, "key-press-event",
10004 G_CALLBACK (gtk_entry_completion_key_press), completion);
10007 if (completion->priv->inline_completion)
10009 completion->priv->insert_text_id =
10010 g_signal_connect (entry, "insert-text",
10011 G_CALLBACK (completion_insert_text_callback), completion);
10012 g_signal_connect (entry, "notify",
10013 G_CALLBACK (clear_completion_callback), completion);
10014 g_signal_connect (entry, "activate",
10015 G_CALLBACK (accept_completion_callback), completion);
10016 g_signal_connect (entry, "focus-out-event",
10017 G_CALLBACK (accept_completion_callback), completion);
10020 g_signal_connect (completion, "notify",
10021 G_CALLBACK (completion_changed), entry);
10025 * gtk_entry_set_completion:
10026 * @entry: A #GtkEntry
10027 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
10029 * Sets @completion to be the auxiliary completion object to use with @entry.
10030 * All further configuration of the completion mechanism is done on
10031 * @completion using the #GtkEntryCompletion API. Completion is disabled if
10032 * @completion is set to %NULL.
10037 gtk_entry_set_completion (GtkEntry *entry,
10038 GtkEntryCompletion *completion)
10040 GtkEntryCompletion *old;
10042 g_return_if_fail (GTK_IS_ENTRY (entry));
10043 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
10045 old = gtk_entry_get_completion (entry);
10047 if (old == completion)
10052 if (old->priv->completion_timeout)
10054 g_source_remove (old->priv->completion_timeout);
10055 old->priv->completion_timeout = 0;
10058 if (old->priv->check_completion_idle)
10060 g_source_destroy (old->priv->check_completion_idle);
10061 old->priv->check_completion_idle = NULL;
10064 if (gtk_widget_get_mapped (old->priv->popup_window))
10065 _gtk_entry_completion_popdown (old);
10067 disconnect_completion_signals (entry, old);
10068 old->priv->entry = NULL;
10070 g_object_unref (old);
10075 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
10079 /* hook into the entry */
10080 g_object_ref (completion);
10082 connect_completion_signals (entry, completion);
10083 completion->priv->entry = GTK_WIDGET (entry);
10084 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10086 g_object_notify (G_OBJECT (entry), "completion");
10090 * gtk_entry_get_completion:
10091 * @entry: A #GtkEntry
10093 * Returns the auxiliary completion object currently in use by @entry.
10095 * Return value: (transfer none): The auxiliary completion object currently
10096 * in use by @entry.
10100 GtkEntryCompletion *
10101 gtk_entry_get_completion (GtkEntry *entry)
10103 GtkEntryCompletion *completion;
10105 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10107 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10108 GTK_ENTRY_COMPLETION_KEY));
10114 * gtk_entry_set_cursor_hadjustment:
10115 * @entry: a #GtkEntry
10116 * @adjustment: an adjustment which should be adjusted when the cursor
10117 * is moved, or %NULL
10119 * Hooks up an adjustment to the cursor position in an entry, so that when
10120 * the cursor is moved, the adjustment is scrolled to show that position.
10121 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10124 * The adjustment has to be in pixel units and in the same coordinate system
10130 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10131 GtkAdjustment *adjustment)
10133 g_return_if_fail (GTK_IS_ENTRY (entry));
10135 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10138 g_object_ref (adjustment);
10140 g_object_set_qdata_full (G_OBJECT (entry),
10141 quark_cursor_hadjustment,
10147 * gtk_entry_get_cursor_hadjustment:
10148 * @entry: a #GtkEntry
10150 * Retrieves the horizontal cursor adjustment for the entry.
10151 * See gtk_entry_set_cursor_hadjustment().
10153 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10154 * if none has been set.
10159 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10161 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10163 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10167 * gtk_entry_set_progress_fraction:
10168 * @entry: a #GtkEntry
10169 * @fraction: fraction of the task that's been completed
10171 * Causes the entry's progress indicator to "fill in" the given
10172 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10178 gtk_entry_set_progress_fraction (GtkEntry *entry,
10182 GtkEntryPrivate *private;
10183 gdouble old_fraction;
10184 gint x, y, width, height;
10185 gint old_x, old_y, old_width, old_height;
10187 g_return_if_fail (GTK_IS_ENTRY (entry));
10189 widget = GTK_WIDGET (entry);
10190 private = entry->priv;
10192 if (private->progress_pulse_mode)
10195 old_fraction = private->progress_fraction;
10197 if (gtk_widget_is_drawable (widget))
10198 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10200 fraction = CLAMP (fraction, 0.0, 1.0);
10202 private->progress_fraction = fraction;
10203 private->progress_pulse_mode = FALSE;
10204 private->progress_pulse_current = 0.0;
10206 if (gtk_widget_is_drawable (widget))
10208 get_progress_area (widget, &x, &y, &width, &height);
10210 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10211 gtk_widget_queue_draw (widget);
10214 if (fraction != old_fraction)
10215 g_object_notify (G_OBJECT (entry), "progress-fraction");
10219 * gtk_entry_get_progress_fraction:
10220 * @entry: a #GtkEntry
10222 * Returns the current fraction of the task that's been completed.
10223 * See gtk_entry_set_progress_fraction().
10225 * Return value: a fraction from 0.0 to 1.0
10230 gtk_entry_get_progress_fraction (GtkEntry *entry)
10232 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10234 return entry->priv->progress_fraction;
10238 * gtk_entry_set_progress_pulse_step:
10239 * @entry: a #GtkEntry
10240 * @fraction: fraction between 0.0 and 1.0
10242 * Sets the fraction of total entry width to move the progress
10243 * bouncing block for each call to gtk_entry_progress_pulse().
10248 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10251 GtkEntryPrivate *private;
10253 g_return_if_fail (GTK_IS_ENTRY (entry));
10255 private = entry->priv;
10257 fraction = CLAMP (fraction, 0.0, 1.0);
10259 if (fraction != private->progress_pulse_fraction)
10261 private->progress_pulse_fraction = fraction;
10263 gtk_widget_queue_draw (GTK_WIDGET (entry));
10265 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10270 * gtk_entry_get_progress_pulse_step:
10271 * @entry: a #GtkEntry
10273 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10275 * Return value: a fraction from 0.0 to 1.0
10280 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10282 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10284 return entry->priv->progress_pulse_fraction;
10288 * gtk_entry_progress_pulse:
10289 * @entry: a #GtkEntry
10291 * Indicates that some progress is made, but you don't know how much.
10292 * Causes the entry's progress indicator to enter "activity mode,"
10293 * where a block bounces back and forth. Each call to
10294 * gtk_entry_progress_pulse() causes the block to move by a little bit
10295 * (the amount of movement per pulse is determined by
10296 * gtk_entry_set_progress_pulse_step()).
10301 gtk_entry_progress_pulse (GtkEntry *entry)
10303 GtkEntryPrivate *private;
10305 g_return_if_fail (GTK_IS_ENTRY (entry));
10307 private = entry->priv;
10309 if (private->progress_pulse_mode)
10311 if (private->progress_pulse_way_back)
10313 private->progress_pulse_current -= private->progress_pulse_fraction;
10315 if (private->progress_pulse_current < 0.0)
10317 private->progress_pulse_current = 0.0;
10318 private->progress_pulse_way_back = FALSE;
10323 private->progress_pulse_current += private->progress_pulse_fraction;
10325 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10327 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10328 private->progress_pulse_way_back = TRUE;
10334 private->progress_fraction = 0.0;
10335 private->progress_pulse_mode = TRUE;
10336 private->progress_pulse_way_back = FALSE;
10337 private->progress_pulse_current = 0.0;
10340 gtk_widget_queue_draw (GTK_WIDGET (entry));
10344 * gtk_entry_set_placeholder_text:
10345 * @entry: a #GtkEntry
10346 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10348 * Sets text to be displayed in @entry when it is empty and unfocused.
10349 * This can be used to give a visual hint of the expected contents of
10352 * Note that since the placeholder text gets removed when the entry
10353 * received focus, using this feature is a bit problematic if the entry
10354 * is given the initial focus in a window. Sometimes this can be
10355 * worked around by delaying the initial focus setting until the
10356 * first key event arrives.
10361 gtk_entry_set_placeholder_text (GtkEntry *entry,
10364 GtkEntryPrivate *priv;
10366 g_return_if_fail (GTK_IS_ENTRY (entry));
10368 priv = entry->priv;
10370 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10373 g_free (priv->placeholder_text);
10374 priv->placeholder_text = g_strdup (text);
10376 gtk_entry_recompute (entry);
10378 g_object_notify (G_OBJECT (entry), "placeholder-text");
10382 * gtk_entry_get_placeholder_text:
10383 * @entry: a #GtkEntry
10385 * Retrieves the text that will be displayed when @entry is empty and unfocused
10387 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10388 * storage in the widget and must not be freed, modified or stored.
10393 gtk_entry_get_placeholder_text (GtkEntry *entry)
10395 GtkEntryPrivate *priv;
10397 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10399 priv = entry->priv;
10401 return priv->placeholder_text;
10404 /* Caps Lock warning for password entries */
10407 show_capslock_feedback (GtkEntry *entry,
10410 GtkEntryPrivate *priv = entry->priv;
10412 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10414 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10415 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10416 priv->caps_lock_warning_shown = TRUE;
10419 if (priv->caps_lock_warning_shown)
10420 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10422 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10426 remove_capslock_feedback (GtkEntry *entry)
10428 GtkEntryPrivate *priv = entry->priv;
10430 if (priv->caps_lock_warning_shown)
10432 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10433 priv->caps_lock_warning_shown = FALSE;
10438 keymap_state_changed (GdkKeymap *keymap,
10441 GtkEntryPrivate *priv = entry->priv;
10444 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10446 if (gdk_keymap_get_num_lock_state (keymap)
10447 && gdk_keymap_get_caps_lock_state (keymap))
10448 text = _("Caps Lock and Num Lock are on");
10449 else if (gdk_keymap_get_num_lock_state (keymap))
10450 text = _("Num Lock is on");
10451 else if (gdk_keymap_get_caps_lock_state (keymap))
10452 text = _("Caps Lock is on");
10456 show_capslock_feedback (entry, text);
10458 remove_capslock_feedback (entry);
10462 * _gtk_entry_set_is_cell_renderer:
10463 * @entry: a #GtkEntry
10464 * @is_cell_renderer: new value
10466 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10467 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10469 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10473 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10474 gboolean is_cell_renderer)
10476 entry->priv->is_cell_renderer = is_cell_renderer;